shell-wm: Remove takeover_keybinding()

Introspection support is now good enough to set a custom keybinding
handler directly from JS.

https://bugzilla.gnome.org/show_bug.cgi?id=663584
This commit is contained in:
Florian Müllner 2011-11-07 02:16:15 +01:00
parent b1064cbe50
commit d714dfd82e
4 changed files with 34 additions and 104 deletions

View File

@ -132,15 +132,11 @@ function _initUserSession() {
ExtensionSystem.init(); ExtensionSystem.init();
ExtensionSystem.loadExtensions(); ExtensionSystem.loadExtensions();
let shellwm = global.window_manager; Meta.keybindings_set_custom_handler('panel-run-dialog', function() {
shellwm.takeover_keybinding('panel-run-dialog');
shellwm.connect('keybinding::panel-run-dialog', function () {
getRunDialog().open(); getRunDialog().open();
}); });
shellwm.takeover_keybinding('panel-main-menu'); Meta.keybindings_set_custom_handler('panel-main-menu', function () {
shellwm.connect('keybinding::panel-main-menu', function () {
overview.toggle(); overview.toggle();
}); });

View File

@ -92,7 +92,6 @@ WindowManager.prototype = {
_init : function() { _init : function() {
this._shellwm = global.window_manager; this._shellwm = global.window_manager;
this._keyBindingHandlers = [];
this._minimizing = []; this._minimizing = [];
this._maximizing = []; this._maximizing = [];
this._unmaximizing = []; this._unmaximizing = [];
@ -121,15 +120,24 @@ WindowManager.prototype = {
this._shellwm.connect('destroy', Lang.bind(this, this._destroyWindow)); this._shellwm.connect('destroy', Lang.bind(this, this._destroyWindow));
this._workspaceSwitcherPopup = null; this._workspaceSwitcherPopup = null;
this.setKeybindingHandler('switch-to-workspace-left', Lang.bind(this, this._showWorkspaceSwitcher)); Meta.keybindings_set_custom_handler('switch-to-workspace-left',
this.setKeybindingHandler('switch-to-workspace-right', Lang.bind(this, this._showWorkspaceSwitcher)); Lang.bind(this, this._showWorkspaceSwitcher));
this.setKeybindingHandler('switch-to-workspace-up', Lang.bind(this, this._showWorkspaceSwitcher)); Meta.keybindings_set_custom_handler('switch-to-workspace-right',
this.setKeybindingHandler('switch-to-workspace-down', Lang.bind(this, this._showWorkspaceSwitcher)); Lang.bind(this, this._showWorkspaceSwitcher));
this.setKeybindingHandler('switch-windows', Lang.bind(this, this._startAppSwitcher)); Meta.keybindings_set_custom_handler('switch-to-workspace-up',
this.setKeybindingHandler('switch-group', Lang.bind(this, this._startAppSwitcher)); Lang.bind(this, this._showWorkspaceSwitcher));
this.setKeybindingHandler('switch-windows-backward', Lang.bind(this, this._startAppSwitcher)); Meta.keybindings_set_custom_handler('switch-to-workspace-down',
this.setKeybindingHandler('switch-group-backward', Lang.bind(this, this._startAppSwitcher)); Lang.bind(this, this._showWorkspaceSwitcher));
this.setKeybindingHandler('switch-panels', Lang.bind(this, this._startA11ySwitcher)); Meta.keybindings_set_custom_handler('switch-windows',
Lang.bind(this, this._startAppSwitcher));
Meta.keybindings_set_custom_handler('switch-group',
Lang.bind(this, this._startAppSwitcher));
Meta.keybindings_set_custom_handler('switch-windows-backward',
Lang.bind(this, this._startAppSwitcher));
Meta.keybindings_set_custom_handler('switch-group-backward',
Lang.bind(this, this._startAppSwitcher));
Meta.keybindings_set_custom_handler('switch-panels',
Lang.bind(this, this._startA11ySwitcher));
Main.overview.connect('showing', Lang.bind(this, function() { Main.overview.connect('showing', Lang.bind(this, function() {
for (let i = 0; i < this._dimmedWindows.length; i++) for (let i = 0; i < this._dimmedWindows.length; i++)
@ -141,16 +149,6 @@ WindowManager.prototype = {
})); }));
}, },
setKeybindingHandler: function(keybinding, handler){
if (this._keyBindingHandlers[keybinding])
this._shellwm.disconnect(this._keyBindingHandlers[keybinding]);
else
this._shellwm.takeover_keybinding(keybinding);
this._keyBindingHandlers[keybinding] =
this._shellwm.connect('keybinding::' + keybinding, handler);
},
blockAnimations: function() { blockAnimations: function() {
this._animationBlockCount++; this._animationBlockCount++;
}, },
@ -534,37 +532,41 @@ WindowManager.prototype = {
shellwm.completed_switch_workspace(); shellwm.completed_switch_workspace();
}, },
_startAppSwitcher : function(shellwm, binding, mask, window, backwards) { _startAppSwitcher : function(display, screen, window, binding) {
/* prevent a corner case where both popups show up at once */ /* prevent a corner case where both popups show up at once */
if (this._workspaceSwitcherPopup != null) if (this._workspaceSwitcherPopup != null)
this._workspaceSwitcherPopup.actor.hide(); this._workspaceSwitcherPopup.actor.hide();
let tabPopup = new AltTab.AltTabPopup(); let tabPopup = new AltTab.AltTabPopup();
if (!tabPopup.show(backwards, binding, mask)) let modifiers = binding.get_modifiers();
let backwards = modifiers & Meta.VirtualModifier.SHIFT_MASK;
if (!tabPopup.show(backwards, binding.get_name(), binding.get_mask()))
tabPopup.destroy(); tabPopup.destroy();
}, },
_startA11ySwitcher : function(shellwm, binding, mask, window, backwards) { _startA11ySwitcher : function(display, screen, window, binding) {
Main.ctrlAltTabManager.popup(backwards, mask); let modifiers = binding.get_modifiers();
let backwards = modifiers & Meta.VirtualModifier.SHIFT_MASK;
Main.ctrlAltTabManager.popup(backwards, binding.get_mask());
}, },
_showWorkspaceSwitcher : function(shellwm, binding, mask, window, backwards) { _showWorkspaceSwitcher : function(display, screen, window, binding) {
if (global.screen.n_workspaces == 1) if (screen.n_workspaces == 1)
return; return;
if (this._workspaceSwitcherPopup == null) if (this._workspaceSwitcherPopup == null)
this._workspaceSwitcherPopup = new WorkspaceSwitcherPopup.WorkspaceSwitcherPopup(); this._workspaceSwitcherPopup = new WorkspaceSwitcherPopup.WorkspaceSwitcherPopup();
if (binding == 'switch-to-workspace-up') if (binding.get_name() == 'switch-to-workspace-up')
this.actionMoveWorkspaceUp(); this.actionMoveWorkspaceUp();
else if (binding == 'switch-to-workspace-down') else if (binding.get_name() == 'switch-to-workspace-down')
this.actionMoveWorkspaceDown(); this.actionMoveWorkspaceDown();
// left/right would effectively act as synonyms for up/down if we enabled them; // left/right would effectively act as synonyms for up/down if we enabled them;
// but that could be considered confusing. // but that could be considered confusing.
// else if (binding == 'switch-to-workspace-left') // else if (binding.get_name() == 'switch-to-workspace-left')
// this.actionMoveWorkspaceLeft(); // this.actionMoveWorkspaceLeft();
// else if (binding == 'switch-to-workspace-right') // else if (binding.get_name() == 'switch-to-workspace-right')
// this.actionMoveWorkspaceRight(); // this.actionMoveWorkspaceRight();
}, },

View File

@ -28,8 +28,6 @@ enum
KILL_SWITCH_WORKSPACE, KILL_SWITCH_WORKSPACE,
KILL_WINDOW_EFFECTS, KILL_WINDOW_EFFECTS,
KEYBINDING,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -126,34 +124,6 @@ shell_wm_class_init (ShellWMClass *klass)
g_cclosure_marshal_VOID__OBJECT, g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
META_TYPE_WINDOW_ACTOR); META_TYPE_WINDOW_ACTOR);
/**
* ShellWM::keybinding:
* @shellwm: the #ShellWM
* @binding: the keybinding name
* @mask: the modifier mask used
* @window: for window keybindings, the #MetaWindow
* @backwards: for "reversible" keybindings, whether or not
* the backwards (Shifted) variant was invoked
*
* Emitted when a keybinding captured via
* shell_wm_takeover_keybinding() is invoked. The keybinding name
* (which has underscores, not hyphens) is also included as the
* detail of the signal name, so you can connect just specific
* keybindings.
*/
shell_wm_signals[KEYBINDING] =
g_signal_new ("keybinding",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
_shell_marshal_VOID__STRING_UINT_OBJECT_BOOLEAN,
G_TYPE_NONE, 4,
G_TYPE_STRING,
G_TYPE_UINT,
META_TYPE_WINDOW,
G_TYPE_BOOLEAN);
} }
void void
@ -324,37 +294,3 @@ shell_wm_new (MetaPlugin *plugin)
return wm; return wm;
} }
static void
shell_wm_key_handler (MetaDisplay *display,
MetaScreen *screen,
MetaWindow *window,
XEvent *event,
MetaKeyBinding *binding,
gpointer data)
{
ShellWM *wm = data;
gboolean backwards = (event->xkey.state & ShiftMask);
g_signal_emit (wm, shell_wm_signals[KEYBINDING],
g_quark_from_string (binding->name),
binding->name, binding->mask, window, backwards);
}
/**
* shell_wm_takeover_keybinding:
* @wm: the #ShellWM
* @binding_name: a meta keybinding name
*
* Tells mutter to forward keypresses for @binding_name to the shell
* rather than processing them internally. This will cause a
* #ShellWM::keybinding signal to be emitted when that key is pressed.
*/
void
shell_wm_takeover_keybinding (ShellWM *wm,
const char *binding_name)
{
meta_keybindings_set_custom_handler (binding_name,
shell_wm_key_handler,
wm, NULL);
}

View File

@ -39,10 +39,6 @@ void shell_wm_completed_destroy (ShellWM *wm,
MetaWindowActor *actor); MetaWindowActor *actor);
void shell_wm_completed_switch_workspace (ShellWM *wm); void shell_wm_completed_switch_workspace (ShellWM *wm);
/* Keybinding stuff */
void shell_wm_takeover_keybinding (ShellWM *wm,
const char *binding_name);
G_END_DECLS G_END_DECLS
#endif /* __SHELL_WM_H__ */ #endif /* __SHELL_WM_H__ */