Skip to content

Commit 89ef729

Browse files
authored
Introduce an action filter (#2301)
1 parent 6065aa2 commit 89ef729

File tree

10 files changed

+104
-58
lines changed

10 files changed

+104
-58
lines changed

lib/Constants.vala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ namespace Gala {
3535
NUDGE = 360,
3636
}
3737

38+
public enum GestureAction {
39+
NONE,
40+
SWITCH_WORKSPACE,
41+
SWITCH_WINDOWS,
42+
MULTITASKING_VIEW,
43+
DOCK,
44+
ZOOM,
45+
N_ACTIONS
46+
}
47+
3848
/**
3949
* Used as a key for Object.set_data<bool> on Meta.Windows that should be
4050
* treated as notifications. Has to be set before the window is mapped.

lib/WindowManager.vala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ namespace Gala {
7070
*/
7171
public class ModalProxy : Object {
7272
public Clutter.Grab? grab { get; set; }
73+
74+
private GestureAction[] allowed_actions;
75+
7376
/**
7477
* A function which is called whenever a keybinding is pressed. If you supply a custom
7578
* one you can filter out those that'd you like to be passed through and block all others.
@@ -94,6 +97,14 @@ namespace Gala {
9497
public void allow_all_keybindings () {
9598
_keybinding_filter = null;
9699
}
100+
101+
public void allow_actions (GestureAction[] actions) {
102+
allowed_actions = actions;
103+
}
104+
105+
public bool filter_action (GestureAction action) {
106+
return !(action in allowed_actions);
107+
}
97108
}
98109

99110
public interface WindowManager : Meta.Plugin {
@@ -185,5 +196,11 @@ namespace Gala {
185196
* @param action_key The gsettings key of action. Available keys are stored in ActionKeys
186197
*/
187198
public abstract void launch_action (string action_key);
199+
200+
/**
201+
* Checks whether the action should currently be prohibited.
202+
* @return true if the action should be prohibited, false otherwise
203+
*/
204+
public abstract bool filter_action (GestureAction action);
188205
}
189206
}

src/Gestures/Gesture.vala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ namespace Gala {
3434
OUT = 6,
3535
}
3636

37-
public enum GestureAction {
38-
NONE,
39-
SWITCH_WORKSPACE,
40-
SWITCH_WINDOWS,
41-
MULTITASKING_VIEW,
42-
DOCK,
43-
ZOOM,
44-
N_ACTIONS
45-
}
46-
4737
public class Gesture {
4838
public const float INVALID_COORD = float.MAX;
4939

src/Gestures/GestureController.vala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Gala.GestureController : Object {
3333
private const double MAX_VELOCITY = 0.01;
3434

3535
public GestureAction action { get; construct; }
36+
public WindowManager wm { get; construct; }
3637

3738
private GestureTarget? _target;
3839
public GestureTarget target {
@@ -89,8 +90,8 @@ public class Gala.GestureController : Object {
8990

9091
private SpringTimeline? timeline;
9192

92-
public GestureController (GestureAction action, GestureTarget target) {
93-
Object (action: action, target: target);
93+
public GestureController (GestureAction action, GestureTarget target, WindowManager wm) {
94+
Object (action: action, target: target, wm: wm);
9495
}
9596

9697
public void enable_touchpad () {
@@ -119,8 +120,9 @@ public class Gala.GestureController : Object {
119120
}
120121

121122
private bool gesture_detected (GestureBackend backend, Gesture gesture, uint32 timestamp) {
122-
recognizing = enabled && (GestureSettings.get_action (gesture, out _action_info) == action
123-
|| backend == scroll_backend && GestureSettings.get_action (gesture) == NONE);
123+
var recognized_action = GestureSettings.get_action (gesture, out _action_info);
124+
recognizing = enabled && (!wm.filter_action (recognized_action) && recognized_action == action ||
125+
backend == scroll_backend && recognized_action == NONE);
124126

125127
if (recognizing) {
126128
if (gesture.direction == UP || gesture.direction == RIGHT || gesture.direction == OUT) {

src/ShellClients/PanelWindow.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class Gala.PanelWindow : ShellWindow {
6363
window.size_changed.connect (update_strut);
6464
window.position_changed.connect (update_strut);
6565

66-
gesture_controller = new GestureController (DOCK, this);
66+
gesture_controller = new GestureController (DOCK, this, wm);
6767

6868
window.display.in_fullscreen_changed.connect (() => {
6969
if (wm.get_display ().get_monitor_in_fullscreen (window.get_monitor ())) {

src/Widgets/MultitaskingView/MultitaskingView.vala

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace Gala {
2323
*/
2424
public class MultitaskingView : ActorTarget, ActivatableComponent {
2525
public const int ANIMATION_DURATION = 250;
26-
private const string OPEN_MULTITASKING_VIEW = "dbus-send --session --dest=org.pantheon.gala --print-reply /org/pantheon/gala org.pantheon.gala.PerformAction int32:1";
2726

2827
private GestureController workspaces_gesture_controller;
2928
private GestureController multitasking_gesture_controller;
@@ -59,14 +58,14 @@ namespace Gala {
5958
opened = false;
6059
display = wm.get_display ();
6160

62-
multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, this);
61+
multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, this, wm);
6362
multitasking_gesture_controller.enable_touchpad ();
6463

6564
add_target (ShellClientsManager.get_instance ()); // For hiding the panels
6665

6766
workspaces = new WorkspaceRow (display);
6867

69-
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, this) {
68+
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, this, wm) {
7069
overshoot_upper_clamp = 0.1
7170
};
7271
workspaces_gesture_controller.enable_touchpad ();
@@ -248,6 +247,7 @@ namespace Gala {
248247

249248
modal_proxy = wm.push_modal (this);
250249
modal_proxy.set_keybinding_filter (keybinding_filter);
250+
modal_proxy.allow_actions ({ MULTITASKING_VIEW, SWITCH_WORKSPACE, ZOOM });
251251

252252
var scale = display.get_monitor_scale (display.get_primary_monitor ());
253253
icon_groups.force_reposition ();
@@ -490,28 +490,7 @@ namespace Gala {
490490
private bool keybinding_filter (Meta.KeyBinding binding) {
491491
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());
492492

493-
// allow super key only when it toggles multitasking view
494-
if (action == Meta.KeyBindingAction.OVERLAY_KEY &&
495-
gala_behavior_settings.get_string ("overlay-action") == OPEN_MULTITASKING_VIEW) {
496-
return false;
497-
}
498-
499493
switch (action) {
500-
case Meta.KeyBindingAction.WORKSPACE_1:
501-
case Meta.KeyBindingAction.WORKSPACE_2:
502-
case Meta.KeyBindingAction.WORKSPACE_3:
503-
case Meta.KeyBindingAction.WORKSPACE_4:
504-
case Meta.KeyBindingAction.WORKSPACE_5:
505-
case Meta.KeyBindingAction.WORKSPACE_6:
506-
case Meta.KeyBindingAction.WORKSPACE_7:
507-
case Meta.KeyBindingAction.WORKSPACE_8:
508-
case Meta.KeyBindingAction.WORKSPACE_9:
509-
case Meta.KeyBindingAction.WORKSPACE_10:
510-
case Meta.KeyBindingAction.WORKSPACE_11:
511-
case Meta.KeyBindingAction.WORKSPACE_12:
512-
case Meta.KeyBindingAction.WORKSPACE_LEFT:
513-
case Meta.KeyBindingAction.WORKSPACE_RIGHT:
514-
case Meta.KeyBindingAction.SHOW_DESKTOP:
515494
case Meta.KeyBindingAction.NONE:
516495
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
517496
return false;
@@ -520,12 +499,6 @@ namespace Gala {
520499
}
521500

522501
switch (binding.get_name ()) {
523-
case "cycle-workspaces-next":
524-
case "cycle-workspaces-previous":
525-
case "switch-to-workspace-first":
526-
case "switch-to-workspace-last":
527-
case "zoom-in":
528-
case "zoom-out":
529502
case "screenshot":
530503
case "screenshot-clip":
531504
return false;

src/Widgets/WindowOverview.vala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Gala.WindowOverview : ActorTarget, ActivatableComponent {
2626
construct {
2727
visible = false;
2828
reactive = true;
29-
gesture_controller = new GestureController (MULTITASKING_VIEW, this) {
29+
gesture_controller = new GestureController (MULTITASKING_VIEW, this, wm) {
3030
enabled = false
3131
};
3232
}
@@ -113,6 +113,7 @@ public class Gala.WindowOverview : ActorTarget, ActivatableComponent {
113113

114114
modal_proxy = wm.push_modal (this);
115115
modal_proxy.set_keybinding_filter (keybinding_filter);
116+
modal_proxy.allow_actions ({ ZOOM });
116117

117118
unowned var display = wm.get_display ();
118119

@@ -166,8 +167,6 @@ public class Gala.WindowOverview : ActorTarget, ActivatableComponent {
166167

167168
switch (binding.get_name ()) {
168169
case "expose-all-windows":
169-
case "zoom-in":
170-
case "zoom-out":
171170
return false;
172171
default:
173172
break;

src/Widgets/WindowSwitcher/WindowSwitcher.vala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget {
6060
construct {
6161
style_manager = Drawing.StyleManager.get_instance ();
6262

63-
gesture_controller = new GestureController (SWITCH_WINDOWS, this) {
63+
gesture_controller = new GestureController (SWITCH_WINDOWS, this, wm) {
6464
overshoot_upper_clamp = int.MAX,
6565
overshoot_lower_clamp = int.MIN,
6666
snap = false
@@ -447,18 +447,13 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget {
447447

448448
private void push_modal () {
449449
modal_proxy = wm.push_modal (this);
450+
modal_proxy.allow_actions ({ SWITCH_WINDOWS });
450451
modal_proxy.set_keybinding_filter ((binding) => {
451452
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());
452453

453454
switch (action) {
454455
case Meta.KeyBindingAction.NONE:
455456
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
456-
case Meta.KeyBindingAction.SWITCH_APPLICATIONS:
457-
case Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD:
458-
case Meta.KeyBindingAction.SWITCH_WINDOWS:
459-
case Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD:
460-
case Meta.KeyBindingAction.SWITCH_GROUP:
461-
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
462457
return false;
463458
default:
464459
break;

src/WindowManager.vala

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
namespace Gala {
2020
public class WindowManagerGala : Meta.Plugin, WindowManager {
21+
private const string OPEN_MULTITASKING_VIEW = "dbus-send --session --dest=org.pantheon.gala --print-reply /org/pantheon/gala org.pantheon.gala.PerformAction int32:1";
22+
2123
/**
2224
* {@inheritDoc}
2325
*/
@@ -1680,22 +1682,80 @@ namespace Gala {
16801682
}
16811683

16821684
public override bool keybinding_filter (Meta.KeyBinding binding) {
1683-
if (!is_modal ())
1685+
if (!is_modal ()) {
16841686
return false;
1687+
}
1688+
1689+
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());
1690+
1691+
switch (action) {
1692+
case Meta.KeyBindingAction.OVERLAY_KEY:
1693+
if (behavior_settings.get_string ("overlay-action") == OPEN_MULTITASKING_VIEW) {
1694+
return filter_action (MULTITASKING_VIEW);
1695+
}
1696+
break;
1697+
case Meta.KeyBindingAction.WORKSPACE_1:
1698+
case Meta.KeyBindingAction.WORKSPACE_2:
1699+
case Meta.KeyBindingAction.WORKSPACE_3:
1700+
case Meta.KeyBindingAction.WORKSPACE_4:
1701+
case Meta.KeyBindingAction.WORKSPACE_5:
1702+
case Meta.KeyBindingAction.WORKSPACE_6:
1703+
case Meta.KeyBindingAction.WORKSPACE_7:
1704+
case Meta.KeyBindingAction.WORKSPACE_8:
1705+
case Meta.KeyBindingAction.WORKSPACE_9:
1706+
case Meta.KeyBindingAction.WORKSPACE_10:
1707+
case Meta.KeyBindingAction.WORKSPACE_11:
1708+
case Meta.KeyBindingAction.WORKSPACE_12:
1709+
case Meta.KeyBindingAction.WORKSPACE_LEFT:
1710+
case Meta.KeyBindingAction.WORKSPACE_RIGHT:
1711+
return filter_action (SWITCH_WORKSPACE);
1712+
case Meta.KeyBindingAction.SHOW_DESKTOP:
1713+
return filter_action (MULTITASKING_VIEW);
1714+
case Meta.KeyBindingAction.SWITCH_APPLICATIONS:
1715+
case Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD:
1716+
case Meta.KeyBindingAction.SWITCH_WINDOWS:
1717+
case Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD:
1718+
case Meta.KeyBindingAction.SWITCH_GROUP:
1719+
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
1720+
return filter_action (SWITCH_WINDOWS);
1721+
default:
1722+
break;
1723+
}
1724+
1725+
switch (binding.get_name ()) {
1726+
case "cycle-workspaces-next":
1727+
case "cycle-workspaces-previous":
1728+
case "switch-to-workspace-first":
1729+
case "switch-to-workspace-last":
1730+
return filter_action (SWITCH_WORKSPACE);
1731+
case "zoom-in":
1732+
case "zoom-out":
1733+
return filter_action (ZOOM);
1734+
default:
1735+
break;
1736+
}
16851737

16861738
var modal_proxy = modal_stack.peek_head ();
16871739
if (modal_proxy == null) {
16881740
return false;
16891741
}
16901742

1691-
unowned var filter = modal_proxy.get_keybinding_filter ();
1743+
unowned var filter = modal_proxy.get_keybinding_filter ();
16921744
if (filter == null) {
16931745
return false;
16941746
}
16951747

16961748
return filter (binding);
16971749
}
16981750

1751+
public bool filter_action (GestureAction action) {
1752+
if (!is_modal ()) {
1753+
return false;
1754+
}
1755+
1756+
return modal_stack.peek_head ().filter_action (action);
1757+
}
1758+
16991759
public override void confirm_display_change () {
17001760
unowned var monitor_manager = get_display ().get_context ().get_backend ().get_monitor_manager ();
17011761
var timeout = monitor_manager.get_display_configuration_timeout ();

src/Zoom.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Gala.Zoom : Object, GestureTarget {
3434
display.add_keybinding ("zoom-in", schema, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) zoom_in);
3535
display.add_keybinding ("zoom-out", schema, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) zoom_out);
3636

37-
gesture_controller = new GestureController (ZOOM, this) {
37+
gesture_controller = new GestureController (ZOOM, this, wm) {
3838
snap = false
3939
};
4040
gesture_controller.enable_touchpad ();

0 commit comments

Comments
 (0)