Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/Gestures/Gesture.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ namespace Gala {
MULTITASKING_VIEW,
ZOOM,
CUSTOM,
N_ACTIONS
N_ACTIONS;

public ModalActions to_modal_action () {
switch (this) {
case SWITCH_WORKSPACE:
return ModalActions.SWITCH_WORKSPACE;
case SWITCH_WINDOWS:
return ModalActions.SWITCH_WINDOWS;
case MULTITASKING_VIEW:
return ModalActions.MULTITASKING_VIEW;
case ZOOM:
return ModalActions.ZOOM;
default:
return ModalActions.NONE;
}
}
}

private class Gesture {
Expand Down
6 changes: 4 additions & 2 deletions lib/Gestures/GestureController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ public class Gala.GestureController : Object {
}

var recognized_action = GestureSettings.get_action (gesture, out _action_info);
recognizing = !wm.filter_action (recognized_action) && recognized_action == action ||
backend == scroll_backend && recognized_action == NONE;
recognizing = (
recognized_action == action && !wm.filter_action (recognized_action.to_modal_action ()) ||
backend == scroll_backend && recognized_action == NONE
);

if (recognizing) {
if (gesture.direction == UP || gesture.direction == RIGHT || gesture.direction == OUT) {
Expand Down
48 changes: 18 additions & 30 deletions lib/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ namespace Gala {
public const string TOGGLE_RECORDING_ACTION = "toggle-recording-action";
}

/**
* Function that should return true if the given shortcut should be blocked.
*/
public delegate bool KeybindingFilter (Meta.KeyBinding binding);
[Flags]
public enum ModalActions {
NONE = 0,
SWITCH_WORKSPACE,
SWITCH_WINDOWS,
MULTITASKING_VIEW,
WINDOW_OVERVIEW,
ZOOM,
LOCATE_POINTER,
SCREENSHOT,
SCREENSHOT_AREA,
SCREENSHOT_WINDOW,
MEDIA_KEYS
}

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

private GestureAction[] allowed_actions;

/**
* A function which is called whenever a keybinding is pressed. If you supply a custom
* one you can filter out those that'd you like to be passed through and block all others.
* Defaults to blocking all.
* @see KeybindingFilter
*/
private KeybindingFilter? _keybinding_filter = () => true;
public unowned KeybindingFilter? get_keybinding_filter () {
return _keybinding_filter;
}

public void set_keybinding_filter (KeybindingFilter? filter) {
_keybinding_filter = filter;
}
private ModalActions allowed_actions;

public ModalProxy () {
}

/**
* Small utility to allow all keybindings
*/
public void allow_all_keybindings () {
_keybinding_filter = null;
}

public void allow_actions (GestureAction[] actions) {
public void allow_actions (ModalActions actions) {
allowed_actions = actions;
}

public bool filter_action (GestureAction action) {
public bool filter_action (ModalActions action) {
return !(action in allowed_actions);
}
}
Expand Down Expand Up @@ -172,6 +160,6 @@ namespace Gala {
* Checks whether the action should currently be prohibited.
* @return true if the action should be prohibited, false otherwise
*/
public abstract bool filter_action (GestureAction action);
public abstract bool filter_action (ModalActions action);
}
}
2 changes: 1 addition & 1 deletion src/Widgets/ModalGroup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class Gala.ModalGroup : Clutter.Actor {

visible = true;
modal_proxy = wm.push_modal (this, false);
modal_proxy.allow_actions ({ ZOOM });
modal_proxy.allow_actions (ZOOM | LOCATE_POINTER | SCREENSHOT | SCREENSHOT_AREA | SCREENSHOT_WINDOW);
}

if (dimmed.size == 1) {
Expand Down
25 changes: 1 addition & 24 deletions src/Widgets/MultitaskingView/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
grab_key_focus ();

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

private bool keybinding_filter (Meta.KeyBinding binding) {
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());

switch (action) {
case Meta.KeyBindingAction.NONE:
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
return false;
default:
break;
}

switch (binding.get_name ()) {
case "screenshot":
case "screenshot-clip":
return false;
default:
break;
}

return true;
}

public override bool captured_event (Clutter.Event event) {
/* If we aren't open but receive events this means we are animating closed
* or we are finishing a workspace switch animation. In any case we want to
Expand Down
24 changes: 1 addition & 23 deletions src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public class Gala.WindowOverview : ActorTarget, RootTarget, ActivatableComponent
grab_key_focus ();

modal_proxy = wm.push_modal (this, true);
modal_proxy.set_keybinding_filter (keybinding_filter);
modal_proxy.allow_actions ({ ZOOM });
modal_proxy.allow_actions (WINDOW_OVERVIEW | ZOOM | LOCATE_POINTER | MEDIA_KEYS | SCREENSHOT | SCREENSHOT_AREA);

unowned var display = wm.get_display ();

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

private bool keybinding_filter (Meta.KeyBinding binding) {
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());

switch (action) {
case Meta.KeyBindingAction.NONE:
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
return false;
default:
break;
}

switch (binding.get_name ()) {
case "expose-all-windows":
return false;
default:
break;
}

return true;
}

private bool window_filter_func (Object obj) requires (obj is Meta.Window) {
var window = (Meta.Window) obj;
return window_ids == null || (window.get_id () in window_ids);
Expand Down
16 changes: 1 addition & 15 deletions src/Widgets/WindowSwitcher/WindowSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {

private void push_modal () {
modal_proxy = wm.push_modal (get_stage (), true);
modal_proxy.allow_actions ({ SWITCH_WINDOWS });
modal_proxy.set_keybinding_filter ((binding) => {
var action = Meta.Prefs.get_keybinding_action (binding.get_name ());

switch (action) {
case Meta.KeyBindingAction.NONE:
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
return false;
default:
break;
}

return true;
});

modal_proxy.allow_actions (SWITCH_WINDOWS | LOCATE_POINTER | MEDIA_KEYS);
}

private void close_switcher (uint32 time, bool cancel = false) {
Expand Down
30 changes: 18 additions & 12 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,10 @@ namespace Gala {
case Meta.KeyBindingAction.SWITCH_GROUP:
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
return filter_action (SWITCH_WINDOWS);
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
return filter_action (LOCATE_POINTER);
case Meta.KeyBindingAction.NONE:
return filter_action (MEDIA_KEYS);
default:
break;
}
Expand All @@ -1665,24 +1669,26 @@ namespace Gala {
return filter_action (ZOOM);
case "toggle-multitasking-view":
return filter_action (MULTITASKING_VIEW);
case "expose-all-windows":
return filter_action (WINDOW_OVERVIEW);
case "screenshot":
case "screenshot-clip":
case "interactive-screenshot":
return filter_action (SCREENSHOT);
case "area-screenshot":
case "area-screenshot-clip":
return filter_action (SCREENSHOT_AREA);
case "window-screenshot":
case "window-screenshot-clip":
return filter_action (SCREENSHOT_WINDOW);
default:
break;
}

var modal_proxy = modal_stack.peek_head ();
if (modal_proxy == null) {
return false;
}

unowned var filter = modal_proxy.get_keybinding_filter ();
if (filter == null) {
return false;
}

return filter (binding);
return false;
}

public bool filter_action (GestureAction action) {
public bool filter_action (ModalActions action) {
if (!is_modal ()) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
lib_test_sources = files(
meson.project_source_root() / 'lib' / 'CommonEnums.vala',
meson.project_source_root() / 'lib' / 'WindowManager.vala',
meson.project_source_root() / 'lib' / 'Gestures' / 'Gesture.vala',
meson.project_source_root() / 'lib' / 'Gestures' / 'GestureTarget.vala',
meson.project_source_root() / 'lib' / 'Gestures' / 'PropertyTarget.vala',
Expand Down