main: Add optional keybindingMode parameter to pushModal()

For now we just use it to assign an identifier to modal modes in
which we want to allow some keybindings, but we don't use it for
any actual filtering; we'll start doing this shortly.

https://bugzilla.gnome.org/show_bug.cgi?id=688202
This commit is contained in:
Florian Müllner 2012-08-10 20:35:59 +02:00
parent 5f367248c5
commit b58f502dd6
8 changed files with 40 additions and 9 deletions

View File

@ -660,6 +660,7 @@ const LoginDialog = new Lang.Class({
this.parent({ shellReactive: true, this.parent({ shellReactive: true,
styleClass: 'login-dialog', styleClass: 'login-dialog',
parentActor: parentActor, parentActor: parentActor,
keybindingMode: Main.KeybindingMode.LOGIN_SCREEN,
shouldFadeIn: false }); shouldFadeIn: false });
this.connect('destroy', this.connect('destroy',
Lang.bind(this, this._onDestroy)); Lang.bind(this, this._onDestroy));

View File

@ -1129,7 +1129,7 @@ const LookingGlass = new Lang.Class({
if (this._open) if (this._open)
return; return;
if (!Main.pushModal(this._entry)) if (!Main.pushModal(this._entry, { keybindingMode: Main.KeybindingMode.LOOKING_GLASS }))
return; return;
this._notebook.selectIndex(0); this._notebook.selectIndex(0);

View File

@ -40,6 +40,18 @@ const Util = imports.misc.util;
const OVERRIDES_SCHEMA = 'org.gnome.shell.overrides'; const OVERRIDES_SCHEMA = 'org.gnome.shell.overrides';
const DEFAULT_BACKGROUND_COLOR = Clutter.Color.from_pixel(0x2e3436ff); const DEFAULT_BACKGROUND_COLOR = Clutter.Color.from_pixel(0x2e3436ff);
const KeybindingMode = {
NONE: 0, // block all keybindings
NORMAL: 1 << 0, // window mode
OVERVIEW: 1 << 1,
LOCK_SCREEN: 1 << 2,
UNLOCK_SCREEN: 1 << 3,
LOGIN_SCREEN: 1 << 4,
MESSAGE_TRAY: 1 << 5,
SYSTEM_MODAL: 1 << 6,
LOOKING_GLASS: 1 << 7
};
let componentManager = null; let componentManager = null;
let panel = null; let panel = null;
let overview = null; let overview = null;
@ -56,6 +68,7 @@ let shellDBusService = null;
let shellMountOpDBusService = null; let shellMountOpDBusService = null;
let screenSaverDBus = null; let screenSaverDBus = null;
let modalCount = 0; let modalCount = 0;
let keybindingMode = KeybindingMode.NORMAL;
let modalActorFocusStack = []; let modalActorFocusStack = [];
let uiGroup = null; let uiGroup = null;
let magnifier = null; let magnifier = null;
@ -498,11 +511,16 @@ function isInModalStack(actor) {
* - options: Meta.ModalOptions flags to indicate that the pointer is * - options: Meta.ModalOptions flags to indicate that the pointer is
* already grabbed * already grabbed
* *
* - keybindingMode: used to set the current Main.KeybindingMode to filter
* global keybindings; the default of NONE will filter
* out all keybindings
*
* Returns: true iff we successfully acquired a grab or already had one * Returns: true iff we successfully acquired a grab or already had one
*/ */
function pushModal(actor, params) { function pushModal(actor, params) {
params = Params.parse(params, { timestamp: global.get_current_time(), params = Params.parse(params, { timestamp: global.get_current_time(),
options: 0 }); options: 0,
keybindingMode: KeybindingMode.NONE });
if (modalCount == 0) { if (modalCount == 0) {
if (!global.begin_modal(params.timestamp, params.options)) { if (!global.begin_modal(params.timestamp, params.options)) {
@ -532,8 +550,10 @@ function pushModal(actor, params) {
modalActorFocusStack.push({ actor: actor, modalActorFocusStack.push({ actor: actor,
focus: curFocus, focus: curFocus,
destroyId: actorDestroyId, destroyId: actorDestroyId,
focusDestroyId: curFocusDestroyId }); focusDestroyId: curFocusDestroyId,
keybindingMode: keybindingMode });
keybindingMode = params.keybindingMode;
global.stage.set_key_focus(actor); global.stage.set_key_focus(actor);
return true; return true;
} }
@ -560,6 +580,7 @@ function popModal(actor, timestamp) {
global.stage.set_key_focus(null); global.stage.set_key_focus(null);
global.end_modal(timestamp); global.end_modal(timestamp);
global.set_stage_input_mode(Shell.StageInputMode.NORMAL); global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
keybindingMode = KeybindingMode.NORMAL;
throw new Error('incorrect pop'); throw new Error('incorrect pop');
} }
@ -572,6 +593,7 @@ function popModal(actor, timestamp) {
if (focusIndex == modalActorFocusStack.length - 1) { if (focusIndex == modalActorFocusStack.length - 1) {
if (record.focus) if (record.focus)
record.focus.disconnect(record.focusDestroyId); record.focus.disconnect(record.focusDestroyId);
keybindingMode = record.keybindingMode;
global.stage.set_key_focus(record.focus); global.stage.set_key_focus(record.focus);
} else { } else {
let t = modalActorFocusStack[modalActorFocusStack.length - 1]; let t = modalActorFocusStack[modalActorFocusStack.length - 1];
@ -581,6 +603,7 @@ function popModal(actor, timestamp) {
for (let i = modalActorFocusStack.length - 1; i > focusIndex; i--) { for (let i = modalActorFocusStack.length - 1; i > focusIndex; i--) {
modalActorFocusStack[i].focus = modalActorFocusStack[i - 1].focus; modalActorFocusStack[i].focus = modalActorFocusStack[i - 1].focus;
modalActorFocusStack[i].focusDestroyId = modalActorFocusStack[i - 1].focusDestroyId; modalActorFocusStack[i].focusDestroyId = modalActorFocusStack[i - 1].focusDestroyId;
modalActorFocusStack[i].keybindingMode = modalActorFocusStack[i - 1].keybindingMode;
} }
} }
modalActorFocusStack.splice(focusIndex, 1); modalActorFocusStack.splice(focusIndex, 1);
@ -591,6 +614,7 @@ function popModal(actor, timestamp) {
global.end_modal(timestamp); global.end_modal(timestamp);
global.set_stage_input_mode(Shell.StageInputMode.NORMAL); global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
Meta.enable_unredirect_for_screen(global.screen); Meta.enable_unredirect_for_screen(global.screen);
keybindingMode = KeybindingMode.NORMAL;
} }
function createLookingGlass() { function createLookingGlass() {

View File

@ -1453,7 +1453,8 @@ const MessageTray = new Lang.Class({
this.idleMonitor = new GnomeDesktop.IdleMonitor(); this.idleMonitor = new GnomeDesktop.IdleMonitor();
this._grabHelper = new GrabHelper.GrabHelper(this.actor); this._grabHelper = new GrabHelper.GrabHelper(this.actor,
{ keybindingMode: Main.KeybindingMode.MESSAGE_TRAY });
this._grabHelper.addActor(this._summaryBoxPointer.actor); this._grabHelper.addActor(this._summaryBoxPointer.actor);
this._grabHelper.addActor(this.actor); this._grabHelper.addActor(this.actor);
if (Main.panel.statusArea.activities) if (Main.panel.statusArea.activities)

View File

@ -37,10 +37,12 @@ const ModalDialog = new Lang.Class({
params = Params.parse(params, { shellReactive: false, params = Params.parse(params, { shellReactive: false,
styleClass: null, styleClass: null,
parentActor: Main.uiGroup, parentActor: Main.uiGroup,
keybindingMode: Main.KeybindingMode.SYSTEM_MODAL,
shouldFadeIn: true }); shouldFadeIn: true });
this.state = State.CLOSED; this.state = State.CLOSED;
this._hasModal = false; this._hasModal = false;
this._keybindingMode = params.keybindingMode;
this._shellReactive = params.shellReactive; this._shellReactive = params.shellReactive;
this._shouldFadeIn = params.shouldFadeIn; this._shouldFadeIn = params.shouldFadeIn;
@ -276,7 +278,8 @@ const ModalDialog = new Lang.Class({
pushModal: function (timestamp) { pushModal: function (timestamp) {
if (this._hasModal) if (this._hasModal)
return true; return true;
if (!Main.pushModal(this._group, { timestamp: timestamp })) if (!Main.pushModal(this._group, { timestamp: timestamp,
keybindingMode: this._keybindingMode }))
return false; return false;
this._hasModal = true; this._hasModal = true;

View File

@ -591,7 +591,7 @@ const Overview = new Lang.Class({
if (this._shown) if (this._shown)
return; return;
// Do this manually instead of using _syncInputMode, to handle failure // Do this manually instead of using _syncInputMode, to handle failure
if (!Main.pushModal(this._group)) if (!Main.pushModal(this._group, { keybindingMode: Main.KeybindingMode.OVERVIEW }))
return; return;
this._modal = true; this._modal = true;
this._animateVisible(); this._animateVisible();
@ -742,7 +742,8 @@ const Overview = new Lang.Class({
if (this._shown) { if (this._shown) {
if (!this._modal) { if (!this._modal) {
if (Main.pushModal(this._group)) if (Main.pushModal(this._group,
{ keybindingMode: Main.KeybindingMode.OVERVIEW }))
this._modal = true; this._modal = true;
else else
this.hide(); this.hide();

View File

@ -611,7 +611,7 @@ const ScreenShield = new Lang.Class({
} }
if (!this._isModal) { if (!this._isModal) {
Main.pushModal(this.actor); Main.pushModal(this.actor, { keybindingMode: Main.KeybindingMode.LOCK_SCREEN });
this._isModal = true; this._isModal = true;
} }
@ -920,7 +920,7 @@ const ScreenShield = new Lang.Class({
lock: function(animate) { lock: function(animate) {
if (!this._isModal) { if (!this._isModal) {
Main.pushModal(this.actor); Main.pushModal(this.actor, { keybindingMode: Main.KeybindingMode.LOCK_SCREEN });
this._isModal = true; this._isModal = true;
} }

View File

@ -113,6 +113,7 @@ const UnlockDialog = new Lang.Class({
_init: function(parentActor) { _init: function(parentActor) {
this.parent({ shellReactive: true, this.parent({ shellReactive: true,
styleClass: 'login-dialog', styleClass: 'login-dialog',
keybindingMode: Main.KeybindingMode.UNLOCK_SCREEN,
parentActor: parentActor parentActor: parentActor
}); });