Skip to content

Commit 1568ae0

Browse files
committed
keybindings: Clean up captured-event handler, use ActionModes for
built-in keybindings. This gets rid of a big mess in Main._stageEventHandler and makes keybinding handling more consistent. - Add setBuiltinHandler in KeybindingManager to replace muffin's Meta.keybindings_set_custom_handler() and allow specifying an ActionMode. - Update windowManager.js to use the new method. - Update workspace keybinding handling to incorporate special behavior during POPUP modes. - Update expo to handle special key handling behavior while active. - Remove unused LOGIN action mode, add EXPO. - Add ActionMode enum to docs.
1 parent 56dd281 commit 1568ae0

7 files changed

Lines changed: 89 additions & 82 deletions

File tree

docs/reference/cinnamon/cinnamon-docs.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<xi:include href="xml/cinnamon-global.xml"/>
4141
<xi:include href="xml/cinnamon-wm.xml"/>
4242
<xi:include href="xml/cinnamon-util.xml"/>
43+
<xi:include href="xml/cinnamon-action-mode.xml"/>
4344
</chapter>
4445
<chapter id="object-tree">
4546
<title>Object Hierarchy</title>

js/ui/expo.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ Expo.prototype = {
173173
}
174174
return true;
175175
}
176+
if (symbol === Clutter.KEY_Super_L || symbol === Clutter.KEY_Super_R) {
177+
this.hide();
178+
return true;
179+
}
176180
}
177181
return false;
178182
}));
@@ -267,7 +271,7 @@ Expo.prototype = {
267271
return;
268272
this.beforeShow();
269273
// Do this manually instead of using _syncInputMode, to handle failure
270-
if (!Main.pushModal(this._group, undefined, undefined, Cinnamon.ActionMode.OVERVIEW))
274+
if (!Main.pushModal(this._group, undefined, undefined, Cinnamon.ActionMode.EXPO))
271275
return;
272276
this._modal = true;
273277
this._animateVisible();
@@ -389,7 +393,7 @@ Expo.prototype = {
389393

390394
if (this._shown) {
391395
if (!this._modal) {
392-
if (Main.pushModal(this._group, undefined, undefined, Cinnamon.ActionMode.OVERVIEW))
396+
if (Main.pushModal(this._group, undefined, undefined, Cinnamon.ActionMode.EXPO))
393397
this._modal = true;
394398
else
395399
this.hide();

js/ui/keybindings.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,32 @@ KeybindingManager.prototype = {
426426
this._proxy.HandleKeybindingRemote(action);
427427
},
428428

429+
_onBuiltinKeyPressed: function(display, window, binding, actionId) {
430+
let entry = this.bindings.get(actionId);
431+
432+
if (entry === undefined || Main._shouldFilterKeybinding(entry))
433+
return;
434+
435+
entry.callback(display, window, binding);
436+
},
437+
438+
setBuiltinHandler: function(name, actionId, callback, allowedModes=Cinnamon.ActionMode.NORMAL) {
439+
Meta.keybindings_set_custom_handler(name,
440+
(display, window, binding) => this._onBuiltinKeyPressed(display, window, binding, actionId)
441+
);
442+
443+
this.bindings.set(actionId, {
444+
name: name,
445+
bindings: [],
446+
callback: callback,
447+
allowedModes: allowedModes
448+
});
449+
},
450+
429451
invoke_keybinding_action_by_id: function(id) {
430-
const binding = this.bindings.get(id);
431-
if (binding !== undefined) {
432-
// log(`invoke_keybinding_action_by_id: ${binding.name}, bindings: ${binding.bindings} - action id: ${id}`);
433-
binding.callback(null, null, null);
452+
const entry = this.bindings.get(id);
453+
if (entry !== undefined) {
454+
entry.callback(null, null, { get_name: () => entry.name });
434455
}
435456
}
436457
};

js/ui/main.js

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,12 @@ function _initUserSession() {
263263

264264
systrayManager = new Systray.SystrayManager();
265265

266-
Meta.keybindings_set_custom_handler('panel-run-dialog', function() {
267-
if (!lockdownSettings.get_boolean('disable-command-line')) {
268-
getRunDialog().open();
269-
}
270-
});
266+
keybindingManager.setBuiltinHandler('panel-run-dialog', Meta.KeyBindingAction.PANEL_RUN_DIALOG,
267+
function() {
268+
if (!lockdownSettings.get_boolean('disable-command-line')) {
269+
getRunDialog().open();
270+
}
271+
}, Cinnamon.ActionMode.NORMAL);
271272
}
272273

273274
function _loadOskLayouts() {
@@ -1251,71 +1252,27 @@ function _shouldFilterKeybinding(entry) {
12511252
function _stageEventHandler(actor, event) {
12521253
if (modalCount == 0)
12531254
return false;
1254-
// log("Stage event handler........." + event.type() + "..." + event.get_source() + "...flags: "+event.get_flags());
12551255

12561256
if (event.type() != Clutter.EventType.KEY_PRESS) {
12571257
if(!popup_rendering_actor || event.type() != Clutter.EventType.BUTTON_RELEASE)
12581258
return false;
12591259
return (event.get_source() && popup_rendering_actor.contains(event.get_source()));
12601260
}
12611261

1262-
let symbol = event.get_key_symbol();
12631262
let keyCode = event.get_key_code();
12641263
let modifierState = Cinnamon.get_event_state(event);
12651264

12661265
let action = global.display.get_keybinding_action(keyCode, modifierState);
12671266
if (!(event.get_source() instanceof Clutter.Text && (event.get_flags() & Clutter.EventFlags.INPUT_METHOD))) {
1268-
// This relies on the fact that Clutter.ModifierType is the same as Gdk.ModifierType
12691267
if (action > 0) {
1270-
// Check if this keybinding should be filtered based on ActionMode
12711268
let entry = keybindingManager.getBindingById(action);
12721269
if (!_shouldFilterKeybinding(entry)) {
12731270
keybindingManager.invoke_keybinding_action_by_id(action);
1271+
return true;
12741272
}
12751273
}
12761274
}
12771275

1278-
// Other bindings are only available when the overview is up and no modal dialog is present
1279-
if (((!overview.visible && !expo.visible) || modalCount > 1))
1280-
return false;
1281-
1282-
// This isn't a Meta.KeyBindingAction yet
1283-
if (symbol === Clutter.KEY_Super_L || symbol === Clutter.KEY_Super_R) {
1284-
if (expo.visible) {
1285-
expo.hide();
1286-
return true;
1287-
}
1288-
}
1289-
1290-
if (action == Meta.KeyBindingAction.SWITCH_PANELS) {
1291-
//Used to call the ctrlalttabmanager in Gnome Shell
1292-
return true;
1293-
}
1294-
1295-
switch (action) {
1296-
// left/right would effectively act as synonyms for up/down if we enabled them;
1297-
// but that could be considered confusing; we also disable them in the main view.
1298-
case Meta.KeyBindingAction.WORKSPACE_LEFT:
1299-
wm.actionMoveWorkspaceLeft();
1300-
return true;
1301-
case Meta.KeyBindingAction.WORKSPACE_RIGHT:
1302-
wm.actionMoveWorkspaceRight();
1303-
return true;
1304-
case Meta.KeyBindingAction.WORKSPACE_UP:
1305-
overview.hide();
1306-
expo.hide();
1307-
return true;
1308-
case Meta.KeyBindingAction.WORKSPACE_DOWN:
1309-
overview.hide();
1310-
expo.hide();
1311-
return true;
1312-
case Meta.KeyBindingAction.PANEL_RUN_DIALOG:
1313-
if (!lockdownSettings.get_boolean('disable-command-line')) {
1314-
getRunDialog().open();
1315-
}
1316-
return true;
1317-
}
1318-
13191276
return false;
13201277
}
13211278

js/ui/screenRecorder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var ScreenRecorder = class ScreenRecorder {
1111
this.recorder = null;
1212
this.recorderSettings = new Gio.Settings({ schema_id: 'org.cinnamon.recorder' });
1313

14-
Meta.keybindings_set_custom_handler('toggle-recording', () => this.toggle_recording());
14+
Main.keybindingManager.setBuiltinHandler('toggle-recording', Meta.KeyBindingAction.TOGGLE_RECORDING,
15+
() => this.toggle_recording(), Cinnamon.ActionMode.NORMAL);
1516
}
1617

1718
get recording() {

js/ui/windowManager.js

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,36 @@ var WindowManager = class WindowManager {
357357
this._cinnamonwm.connect('filter-keybinding', this._filterKeybinding.bind(this));
358358
global.window_manager.connect('switch-workspace', (c, f, t, d) => this._switchWorkspace(c, f, t, d));
359359

360-
Meta.keybindings_set_custom_handler('move-to-workspace-left', (d, w, b) => this._moveWindowToWorkspaceLeft(d, w, b));
361-
Meta.keybindings_set_custom_handler('move-to-workspace-right', (d, w, b) => this._moveWindowToWorkspaceRight(d, w, b));
362-
363-
Meta.keybindings_set_custom_handler('switch-to-workspace-left', (d, w, b) => this._showWorkspaceSwitcher(d, w, b));
364-
Meta.keybindings_set_custom_handler('switch-to-workspace-right', (d, w, b) => this._showWorkspaceSwitcher(d, w, b));
365-
Meta.keybindings_set_custom_handler('switch-to-workspace-up', (d, w, b) => this._showWorkspaceSwitcher(d, w, b));
366-
Meta.keybindings_set_custom_handler('switch-to-workspace-down', (d, w, b) => this._showWorkspaceSwitcher(d, w, b));
367-
Meta.keybindings_set_custom_handler('switch-windows', (d, w, b) => this._startAppSwitcher(d, w, b));
368-
Meta.keybindings_set_custom_handler('switch-group', (d, w, b) => this._startAppSwitcher(d, w, b));
369-
Meta.keybindings_set_custom_handler('switch-windows-backward', (d, w, b) => this._startAppSwitcher(d, w, b));
370-
Meta.keybindings_set_custom_handler('switch-group-backward', (d, w, b) => this._startAppSwitcher(d, w, b));
371-
Meta.keybindings_set_custom_handler('switch-panels', (d, w, b) => this._startAppSwitcher(d, w, b));
372-
Meta.keybindings_set_custom_handler('switch-panels-backward', (d, w, b) => this._startAppSwitcher(d, w, b));
360+
let kbm = Main.keybindingManager;
361+
let WORKSPACE_MODES = Cinnamon.ActionMode.NORMAL |
362+
Cinnamon.ActionMode.OVERVIEW |
363+
Cinnamon.ActionMode.EXPO;
364+
365+
kbm.setBuiltinHandler('move-to-workspace-left', Meta.KeyBindingAction.MOVE_TO_WORKSPACE_LEFT,
366+
(d, w, b) => this._moveWindowToWorkspaceLeft(d, w, b), Cinnamon.ActionMode.NORMAL);
367+
kbm.setBuiltinHandler('move-to-workspace-right', Meta.KeyBindingAction.MOVE_TO_WORKSPACE_RIGHT,
368+
(d, w, b) => this._moveWindowToWorkspaceRight(d, w, b), Cinnamon.ActionMode.NORMAL);
369+
370+
kbm.setBuiltinHandler('switch-to-workspace-left', Meta.KeyBindingAction.WORKSPACE_LEFT,
371+
(d, w, b) => this._showWorkspaceSwitcher(d, w, b), WORKSPACE_MODES);
372+
kbm.setBuiltinHandler('switch-to-workspace-right', Meta.KeyBindingAction.WORKSPACE_RIGHT,
373+
(d, w, b) => this._showWorkspaceSwitcher(d, w, b), WORKSPACE_MODES);
374+
kbm.setBuiltinHandler('switch-to-workspace-up', Meta.KeyBindingAction.WORKSPACE_UP,
375+
(d, w, b) => this._showWorkspaceSwitcher(d, w, b), WORKSPACE_MODES);
376+
kbm.setBuiltinHandler('switch-to-workspace-down', Meta.KeyBindingAction.WORKSPACE_DOWN,
377+
(d, w, b) => this._showWorkspaceSwitcher(d, w, b), WORKSPACE_MODES);
378+
kbm.setBuiltinHandler('switch-windows', Meta.KeyBindingAction.SWITCH_WINDOWS,
379+
(d, w, b) => this._startAppSwitcher(d, w, b), Cinnamon.ActionMode.NORMAL);
380+
kbm.setBuiltinHandler('switch-group', Meta.KeyBindingAction.SWITCH_GROUP,
381+
(d, w, b) => this._startAppSwitcher(d, w, b), Cinnamon.ActionMode.NORMAL);
382+
kbm.setBuiltinHandler('switch-windows-backward', Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD,
383+
(d, w, b) => this._startAppSwitcher(d, w, b), Cinnamon.ActionMode.NORMAL);
384+
kbm.setBuiltinHandler('switch-group-backward', Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD,
385+
(d, w, b) => this._startAppSwitcher(d, w, b), Cinnamon.ActionMode.NORMAL);
386+
kbm.setBuiltinHandler('switch-panels', Meta.KeyBindingAction.SWITCH_PANELS,
387+
(d, w, b) => this._startAppSwitcher(d, w, b), Cinnamon.ActionMode.NORMAL);
388+
kbm.setBuiltinHandler('switch-panels-backward', Meta.KeyBindingAction.SWITCH_PANELS_BACKWARD,
389+
(d, w, b) => this._startAppSwitcher(d, w, b), Cinnamon.ActionMode.NORMAL);
373390

374391
global.display.connect('show-resize-popup', this._showResizePopup.bind(this));
375392
this._cinnamonwm.connect('create-close-dialog', this._createCloseDialog.bind(this));
@@ -835,15 +852,9 @@ var WindowManager = class WindowManager {
835852
}
836853

837854
_filterKeybinding(shellwm, binding) {
838-
// Builtin keybindings (defined by Muffin) work in NORMAL mode by default
839-
if (Main.actionMode == Cinnamon.ActionMode.NORMAL && binding.is_builtin())
840-
return false;
841-
842-
// Look up the binding in our keybinding manager
843855
let bindingName = binding.get_name();
844-
let [action_id, entry] = Main.keybindingManager._lookupEntry(bindingName);
856+
let [, entry] = Main.keybindingManager._lookupEntry(bindingName);
845857

846-
// Use the common filtering logic from main.js
847858
return Main._shouldFilterKeybinding(entry);
848859
}
849860

@@ -1382,12 +1393,23 @@ var WindowManager = class WindowManager {
13821393

13831394
_showWorkspaceSwitcher(display, window, binding) {
13841395
let bindingName = binding.get_name();
1396+
13851397
if (bindingName === 'switch-to-workspace-up') {
1386-
Main.expo.toggle();
1398+
if (Main.overview.visible || Main.expo.visible) {
1399+
Main.overview.hide();
1400+
Main.expo.hide();
1401+
} else {
1402+
Main.expo.toggle();
1403+
}
13871404
return;
13881405
}
13891406
if (bindingName === 'switch-to-workspace-down') {
1390-
Main.overview.toggle();
1407+
if (Main.overview.visible || Main.expo.visible) {
1408+
Main.overview.hide();
1409+
Main.expo.hide();
1410+
} else {
1411+
Main.overview.toggle();
1412+
}
13911413
return;
13921414
}
13931415

src/cinnamon-action-mode.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* dialog (e.g. authentication or session dialogs) is open
1515
* @CINNAMON_ACTION_MODE_LOOKING_GLASS: allow action in looking glass
1616
* @CINNAMON_ACTION_MODE_POPUP: allow action while a shell menu is open
17+
* @CINNAMON_ACTION_MODE_EXPO: allow action while the expo is active
1718
* @CINNAMON_ACTION_MODE_ALL: always allow action
1819
*
1920
* Controls in which Cinnamon states an action (like keybindings and gestures)
@@ -23,9 +24,9 @@ typedef enum {
2324
CINNAMON_ACTION_MODE_NONE = 0,
2425
CINNAMON_ACTION_MODE_NORMAL = 1 << 0,
2526
CINNAMON_ACTION_MODE_OVERVIEW = 1 << 1,
26-
CINNAMON_ACTION_MODE_LOCK_SCREEN = 1 << 2,
27-
CINNAMON_ACTION_MODE_UNLOCK_SCREEN = 1 << 3,
28-
CINNAMON_ACTION_MODE_LOGIN_SCREEN = 1 << 4,
27+
CINNAMON_ACTION_MODE_EXPO = 1 << 2,
28+
CINNAMON_ACTION_MODE_LOCK_SCREEN = 1 << 3,
29+
CINNAMON_ACTION_MODE_UNLOCK_SCREEN = 1 << 4,
2930
CINNAMON_ACTION_MODE_SYSTEM_MODAL = 1 << 5,
3031
CINNAMON_ACTION_MODE_LOOKING_GLASS = 1 << 6,
3132
CINNAMON_ACTION_MODE_POPUP = 1 << 7,

0 commit comments

Comments
 (0)