Skip to content

Commit b9b9dde

Browse files
authored
Rework modal actions (#2739)
We currently have duplicate keybinding filters across multiple components. This PR removes keybinding filter capabilities from modal proxies and instead introduces ModalActions flags. Then WindowManager filters keybindings based on these flags
1 parent 91a53ec commit b9b9dde

File tree

9 files changed

+62
-108
lines changed

9 files changed

+62
-108
lines changed

lib/Gestures/Gesture.vala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,22 @@ namespace Gala {
4141
MULTITASKING_VIEW,
4242
ZOOM,
4343
CUSTOM,
44-
N_ACTIONS
44+
N_ACTIONS;
45+
46+
public ModalActions to_modal_action () {
47+
switch (this) {
48+
case SWITCH_WORKSPACE:
49+
return ModalActions.SWITCH_WORKSPACE;
50+
case SWITCH_WINDOWS:
51+
return ModalActions.SWITCH_WINDOWS;
52+
case MULTITASKING_VIEW:
53+
return ModalActions.MULTITASKING_VIEW;
54+
case ZOOM:
55+
return ModalActions.ZOOM;
56+
default:
57+
return ModalActions.NONE;
58+
}
59+
}
4560
}
4661

4762
private class Gesture {

lib/Gestures/GestureController.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ public class Gala.GestureController : Object {
156156
}
157157

158158
var recognized_action = GestureSettings.get_action (gesture, out _action_info);
159-
recognizing = !wm.filter_action (recognized_action) && recognized_action == action ||
160-
backend == scroll_backend && recognized_action == NONE;
159+
recognizing = (
160+
recognized_action == action && !wm.filter_action (recognized_action.to_modal_action ()) ||
161+
backend == scroll_backend && recognized_action == NONE
162+
);
161163

162164
if (recognizing) {
163165
if (gesture.direction == UP || gesture.direction == RIGHT || gesture.direction == OUT) {

lib/WindowManager.vala

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ namespace Gala {
2323
public const string TOGGLE_RECORDING_ACTION = "toggle-recording-action";
2424
}
2525

26-
/**
27-
* Function that should return true if the given shortcut should be blocked.
28-
*/
29-
public delegate bool KeybindingFilter (Meta.KeyBinding binding);
26+
[Flags]
27+
public enum ModalActions {
28+
NONE = 0,
29+
SWITCH_WORKSPACE,
30+
SWITCH_WINDOWS,
31+
MULTITASKING_VIEW,
32+
WINDOW_OVERVIEW,
33+
ZOOM,
34+
LOCATE_POINTER,
35+
SCREENSHOT,
36+
SCREENSHOT_AREA,
37+
SCREENSHOT_WINDOW,
38+
MEDIA_KEYS
39+
}
3040

3141
/**
3242
* A minimal class mostly used to identify your call to {@link WindowManager.push_modal} and used
@@ -35,38 +45,16 @@ namespace Gala {
3545
public class ModalProxy : Object {
3646
public Clutter.Grab? grab { get; set; }
3747

38-
private GestureAction[] allowed_actions;
39-
40-
/**
41-
* A function which is called whenever a keybinding is pressed. If you supply a custom
42-
* one you can filter out those that'd you like to be passed through and block all others.
43-
* Defaults to blocking all.
44-
* @see KeybindingFilter
45-
*/
46-
private KeybindingFilter? _keybinding_filter = () => true;
47-
public unowned KeybindingFilter? get_keybinding_filter () {
48-
return _keybinding_filter;
49-
}
50-
51-
public void set_keybinding_filter (KeybindingFilter? filter) {
52-
_keybinding_filter = filter;
53-
}
48+
private ModalActions allowed_actions;
5449

5550
public ModalProxy () {
5651
}
5752

58-
/**
59-
* Small utility to allow all keybindings
60-
*/
61-
public void allow_all_keybindings () {
62-
_keybinding_filter = null;
63-
}
64-
65-
public void allow_actions (GestureAction[] actions) {
53+
public void allow_actions (ModalActions actions) {
6654
allowed_actions = actions;
6755
}
6856

69-
public bool filter_action (GestureAction action) {
57+
public bool filter_action (ModalActions action) {
7058
return !(action in allowed_actions);
7159
}
7260
}
@@ -172,6 +160,6 @@ namespace Gala {
172160
* Checks whether the action should currently be prohibited.
173161
* @return true if the action should be prohibited, false otherwise
174162
*/
175-
public abstract bool filter_action (GestureAction action);
163+
public abstract bool filter_action (ModalActions action);
176164
}
177165
}

src/Widgets/ModalGroup.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class Gala.ModalGroup : Clutter.Actor {
7070

7171
visible = true;
7272
modal_proxy = wm.push_modal (this, false);
73-
modal_proxy.allow_actions ({ ZOOM });
73+
modal_proxy.allow_actions (ZOOM | LOCATE_POINTER | SCREENSHOT | SCREENSHOT_AREA | SCREENSHOT_WINDOW);
7474
}
7575

7676
if (dimmed.size == 1) {

src/Widgets/MultitaskingView/MultitaskingView.vala

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
249249
grab_key_focus ();
250250

251251
modal_proxy = wm.push_modal (get_stage (), false);
252-
modal_proxy.set_keybinding_filter (keybinding_filter);
253-
modal_proxy.allow_actions ({ MULTITASKING_VIEW, SWITCH_WORKSPACE, ZOOM });
252+
modal_proxy.allow_actions (MULTITASKING_VIEW | SWITCH_WORKSPACE | ZOOM | LOCATE_POINTER | MEDIA_KEYS | SCREENSHOT | SCREENSHOT_AREA);
254253
} else if (action == MULTITASKING_VIEW) {
255254
DragDropAction.cancel_all_by_id ("multitaskingview-window");
256255
}
@@ -432,28 +431,6 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
432431
multitasking_gesture_controller.goto (0);
433432
}
434433

435-
private bool keybinding_filter (Meta.KeyBinding binding) {
436-
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());
437-
438-
switch (action) {
439-
case Meta.KeyBindingAction.NONE:
440-
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
441-
return false;
442-
default:
443-
break;
444-
}
445-
446-
switch (binding.get_name ()) {
447-
case "screenshot":
448-
case "screenshot-clip":
449-
return false;
450-
default:
451-
break;
452-
}
453-
454-
return true;
455-
}
456-
457434
public override bool captured_event (Clutter.Event event) {
458435
/* If we aren't open but receive events this means we are animating closed
459436
* or we are finishing a workspace switch animation. In any case we want to

src/Widgets/WindowOverview.vala

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ public class Gala.WindowOverview : ActorTarget, RootTarget, ActivatableComponent
106106
grab_key_focus ();
107107

108108
modal_proxy = wm.push_modal (this, true);
109-
modal_proxy.set_keybinding_filter (keybinding_filter);
110-
modal_proxy.allow_actions ({ ZOOM });
109+
modal_proxy.allow_actions (WINDOW_OVERVIEW | ZOOM | LOCATE_POINTER | MEDIA_KEYS | SCREENSHOT | SCREENSHOT_AREA);
111110

112111
unowned var display = wm.get_display ();
113112

@@ -147,27 +146,6 @@ public class Gala.WindowOverview : ActorTarget, RootTarget, ActivatableComponent
147146
gesture_controller.goto (1);
148147
}
149148

150-
private bool keybinding_filter (Meta.KeyBinding binding) {
151-
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());
152-
153-
switch (action) {
154-
case Meta.KeyBindingAction.NONE:
155-
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
156-
return false;
157-
default:
158-
break;
159-
}
160-
161-
switch (binding.get_name ()) {
162-
case "expose-all-windows":
163-
return false;
164-
default:
165-
break;
166-
}
167-
168-
return true;
169-
}
170-
171149
private bool window_filter_func (Object obj) requires (obj is Meta.Window) {
172150
var window = (Meta.Window) obj;
173151
return window_ids == null || (window.get_id () in window_ids);

src/Widgets/WindowSwitcher/WindowSwitcher.vala

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
443443

444444
private void push_modal () {
445445
modal_proxy = wm.push_modal (get_stage (), true);
446-
modal_proxy.allow_actions ({ SWITCH_WINDOWS });
447-
modal_proxy.set_keybinding_filter ((binding) => {
448-
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());
449-
450-
switch (action) {
451-
case Meta.KeyBindingAction.NONE:
452-
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
453-
return false;
454-
default:
455-
break;
456-
}
457-
458-
return true;
459-
});
460-
446+
modal_proxy.allow_actions (SWITCH_WINDOWS | LOCATE_POINTER | MEDIA_KEYS);
461447
}
462448

463449
private void close_switcher (uint32 time, bool cancel = false) {

src/WindowManager.vala

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,10 @@ namespace Gala {
16501650
case Meta.KeyBindingAction.SWITCH_GROUP:
16511651
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
16521652
return filter_action (SWITCH_WINDOWS);
1653+
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
1654+
return filter_action (LOCATE_POINTER);
1655+
case Meta.KeyBindingAction.NONE:
1656+
return filter_action (MEDIA_KEYS);
16531657
default:
16541658
break;
16551659
}
@@ -1665,24 +1669,26 @@ namespace Gala {
16651669
return filter_action (ZOOM);
16661670
case "toggle-multitasking-view":
16671671
return filter_action (MULTITASKING_VIEW);
1672+
case "expose-all-windows":
1673+
return filter_action (WINDOW_OVERVIEW);
1674+
case "screenshot":
1675+
case "screenshot-clip":
1676+
case "interactive-screenshot":
1677+
return filter_action (SCREENSHOT);
1678+
case "area-screenshot":
1679+
case "area-screenshot-clip":
1680+
return filter_action (SCREENSHOT_AREA);
1681+
case "window-screenshot":
1682+
case "window-screenshot-clip":
1683+
return filter_action (SCREENSHOT_WINDOW);
16681684
default:
16691685
break;
16701686
}
16711687

1672-
var modal_proxy = modal_stack.peek_head ();
1673-
if (modal_proxy == null) {
1674-
return false;
1675-
}
1676-
1677-
unowned var filter = modal_proxy.get_keybinding_filter ();
1678-
if (filter == null) {
1679-
return false;
1680-
}
1681-
1682-
return filter (binding);
1688+
return false;
16831689
}
16841690

1685-
public bool filter_action (GestureAction action) {
1691+
public bool filter_action (ModalActions action) {
16861692
if (!is_modal ()) {
16871693
return false;
16881694
}

tests/lib/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
lib_test_sources = files(
2+
meson.project_source_root() / 'lib' / 'CommonEnums.vala',
3+
meson.project_source_root() / 'lib' / 'WindowManager.vala',
24
meson.project_source_root() / 'lib' / 'Gestures' / 'Gesture.vala',
35
meson.project_source_root() / 'lib' / 'Gestures' / 'GestureTarget.vala',
46
meson.project_source_root() / 'lib' / 'Gestures' / 'PropertyTarget.vala',

0 commit comments

Comments
 (0)