Delegate mode information to a dedicated object

Rather than accessing global.session_type / global.session_mode
all over the place, delegate mode information to a dedicated
sessionMode object. While not very useful for now, we will replace
checks for a particular mode with checks for particular properties
that sessionMode defines based on global.session_mode.

https://bugzilla.gnome.org/show_bug.cgi?id=676156
This commit is contained in:
Florian Müllner 2012-05-17 00:26:44 +02:00
parent 940ddb104c
commit 3d26224180
6 changed files with 41 additions and 12 deletions

View File

@ -67,6 +67,7 @@ nobase_dist_js_DATA = \
ui/messageTray.js \ ui/messageTray.js \
ui/modalDialog.js \ ui/modalDialog.js \
ui/networkAgent.js \ ui/networkAgent.js \
ui/sessionMode.js \
ui/shellEntry.js \ ui/shellEntry.js \
ui/shellMountOperation.js \ ui/shellMountOperation.js \
ui/notificationDaemon.js \ ui/notificationDaemon.js \

View File

@ -30,6 +30,7 @@ const NetworkAgent = imports.ui.networkAgent;
const NotificationDaemon = imports.ui.notificationDaemon; const NotificationDaemon = imports.ui.notificationDaemon;
const WindowAttentionHandler = imports.ui.windowAttentionHandler; const WindowAttentionHandler = imports.ui.windowAttentionHandler;
const Scripting = imports.ui.scripting; const Scripting = imports.ui.scripting;
const SessionMode = imports.ui.sessionMode;
const ShellDBus = imports.ui.shellDBus; const ShellDBus = imports.ui.shellDBus;
const TelepathyClient = imports.ui.telepathyClient; const TelepathyClient = imports.ui.telepathyClient;
const WindowManager = imports.ui.windowManager; const WindowManager = imports.ui.windowManager;
@ -56,6 +57,7 @@ let windowAttentionHandler = null;
let telepathyClient = null; let telepathyClient = null;
let ctrlAltTabManager = null; let ctrlAltTabManager = null;
let recorder = null; let recorder = null;
let sessionMode = null;
let shellDBusService = null; let shellDBusService = null;
let modalCount = 0; let modalCount = 0;
let modalActorFocusStack = []; let modalActorFocusStack = [];
@ -159,6 +161,7 @@ function start() {
Gio.DesktopAppInfo.set_desktop_env('GNOME'); Gio.DesktopAppInfo.set_desktop_env('GNOME');
sessionMode = new SessionMode.SessionMode();
shellDBusService = new ShellDBus.GnomeShell(); shellDBusService = new ShellDBus.GnomeShell();
// Ensure ShellWindowTracker and ShellAppUsage are initialized; this will // Ensure ShellWindowTracker and ShellAppUsage are initialized; this will
@ -210,7 +213,7 @@ function start() {
xdndHandler = new XdndHandler.XdndHandler(); xdndHandler = new XdndHandler.XdndHandler();
ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager(); ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager();
// This overview object is just a stub for non-user sessions // This overview object is just a stub for non-user sessions
overview = new Overview.Overview({ isDummy: global.session_type != Shell.SessionType.USER }); overview = new Overview.Overview({ isDummy: sessionMode.sessionType != Shell.SessionType.USER });
magnifier = new Magnifier.Magnifier(); magnifier = new Magnifier.Magnifier();
statusIconDispatcher = new StatusIconDispatcher.StatusIconDispatcher(); statusIconDispatcher = new StatusIconDispatcher.StatusIconDispatcher();
panel = new Panel.Panel(); panel = new Panel.Panel();
@ -220,9 +223,9 @@ function start() {
notificationDaemon = new NotificationDaemon.NotificationDaemon(); notificationDaemon = new NotificationDaemon.NotificationDaemon();
windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler(); windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler();
if (global.session_type == Shell.SessionType.USER) if (sessionMode.sessionType == Shell.SessionType.USER)
_createUserSession(); _createUserSession();
else if (global.session_type == Shell.SessionType.GDM) else if (sessionMode.sessionType == Shell.SessionType.GDM)
_createGDMSession(); _createGDMSession();
panel.startStatusArea(); panel.startStatusArea();
@ -231,7 +234,7 @@ function start() {
keyboard.init(); keyboard.init();
overview.init(); overview.init();
if (global.session_type == Shell.SessionType.USER) if (sessionMode.sessionType == Shell.SessionType.USER)
_initUserSession(); _initUserSession();
statusIconDispatcher.start(messageTray.actor); statusIconDispatcher.start(messageTray.actor);
@ -491,7 +494,7 @@ function loadTheme() {
let theme = new St.Theme ({ application_stylesheet: cssStylesheet }); let theme = new St.Theme ({ application_stylesheet: cssStylesheet });
if (global.session_type == Shell.SessionType.GDM) if (sessionMode.sessionType == Shell.SessionType.GDM)
theme.load_stylesheet(_gdmCssStylesheet); theme.load_stylesheet(_gdmCssStylesheet);
if (previousTheme) { if (previousTheme) {
@ -566,7 +569,7 @@ function _globalKeyPressHandler(actor, event) {
// Other bindings are only available to the user session when the overview is up and // Other bindings are only available to the user session when the overview is up and
// no modal dialog is present. // no modal dialog is present.
if (global.session_type == Shell.SessionType.USER && (!overview.visible || modalCount > 1)) if (sessionMode.sessionType == Shell.SessionType.USER && (!overview.visible || modalCount > 1))
return false; return false;
// This isn't a Meta.KeyBindingAction yet // This isn't a Meta.KeyBindingAction yet
@ -582,7 +585,7 @@ function _globalKeyPressHandler(actor, event) {
} }
// None of the other bindings are relevant outside of the user's session // None of the other bindings are relevant outside of the user's session
if (global.session_type != Shell.SessionType.USER) if (sessionMode.sessionType != Shell.SessionType.USER)
return false; return false;
switch (action) { switch (action) {

View File

@ -962,7 +962,7 @@ const Panel = new Lang.Class({
this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress)); this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
/* Button on the left side of the panel. */ /* Button on the left side of the panel. */
if (global.session_type == Shell.SessionType.USER) { if (Main.sessionMode.sessionType == Shell.SessionType.USER) {
this._activitiesButton = new ActivitiesButton(); this._activitiesButton = new ActivitiesButton();
this._activities = this._activitiesButton.actor; this._activities = this._activitiesButton.actor;
this._leftBox.add(this._activities); this._leftBox.add(this._activities);
@ -976,7 +976,7 @@ const Panel = new Lang.Class({
} }
/* center */ /* center */
if (global.session_type == Shell.SessionType.USER) if (Main.sessionMode.sessionType == Shell.SessionType.USER)
this._dateMenu = new DateMenu.DateMenuButton({ showEvents: true }); this._dateMenu = new DateMenu.DateMenuButton({ showEvents: true });
else else
this._dateMenu = new DateMenu.DateMenuButton({ showEvents: false }); this._dateMenu = new DateMenu.DateMenuButton({ showEvents: false });
@ -984,7 +984,7 @@ const Panel = new Lang.Class({
this._menus.addMenu(this._dateMenu.menu); this._menus.addMenu(this._dateMenu.menu);
/* right */ /* right */
if (global.session_type == Shell.SessionType.GDM) { if (Main.sessionMode.sessionType == Shell.SessionType.GDM) {
this._status_area_order = GDM_STATUS_AREA_ORDER; this._status_area_order = GDM_STATUS_AREA_ORDER;
this._status_area_shell_implementation = GDM_STATUS_AREA_SHELL_IMPLEMENTATION; this._status_area_shell_implementation = GDM_STATUS_AREA_SHELL_IMPLEMENTATION;
} else { } else {

View File

@ -889,7 +889,7 @@ const PopupMenuBase = new Lang.Class({
addSettingsAction: function(title, desktopFile) { addSettingsAction: function(title, desktopFile) {
// Don't allow user settings to get edited unless we're in a user session // Don't allow user settings to get edited unless we're in a user session
if (global.session_type != Shell.SessionType.USER) if (Main.sessionMode.sessionType != Shell.SessionType.USER)
return null; return null;
let menuItem = this.addAction(title, function() { let menuItem = this.addAction(title, function() {

25
js/ui/sessionMode.js Normal file
View File

@ -0,0 +1,25 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang;
const Shell = imports.gi.Shell;
const Params = imports.misc.params;
const DEFAULT_MODE = 'user';
const _modes = {
'gdm': { sessionType: Shell.SessionType.GDM },
'user': { sessionType: Shell.SessionType.USER }
};
const SessionMode = new Lang.Class({
Name: 'SessionMode',
_init: function() {
let params = _modes[global.session_mode];
params = Params.parse(params, _modes[DEFAULT_MODE]);
Lang.copyProperties(params, this);
}
});

View File

@ -63,7 +63,7 @@ const XKBIndicator = new Lang.Class({
this._syncConfig(); this._syncConfig();
if (global.session_type == Shell.SessionType.USER) { if (Main.sessionMode.sessionType == Shell.SessionType.USER) {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addAction(_("Show Keyboard Layout"), Lang.bind(this, function() { this.menu.addAction(_("Show Keyboard Layout"), Lang.bind(this, function() {
Main.overview.hide(); Main.overview.hide();