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
10 changes: 10 additions & 0 deletions lib/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ namespace Gala {
NUDGE = 360,
}

public enum GestureAction {
NONE,
SWITCH_WORKSPACE,
SWITCH_WINDOWS,
MULTITASKING_VIEW,
DOCK,
ZOOM,
N_ACTIONS
}

/**
* Used as a key for Object.set_data<bool> on Meta.Windows that should be
* treated as notifications. Has to be set before the window is mapped.
Expand Down
17 changes: 17 additions & 0 deletions lib/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ 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.
Expand All @@ -94,6 +97,14 @@ namespace Gala {
public void allow_all_keybindings () {
_keybinding_filter = null;
}

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

public bool filter_action (GestureAction action) {
return !(action in allowed_actions);
}
}

public interface WindowManager : Meta.Plugin {
Expand Down Expand Up @@ -185,5 +196,11 @@ namespace Gala {
* @param action_key The gsettings key of action. Available keys are stored in ActionKeys
*/
public abstract void launch_action (string action_key);

/**
* 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);
}
}
10 changes: 0 additions & 10 deletions src/Gestures/Gesture.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ namespace Gala {
OUT = 6,
}

public enum GestureAction {
NONE,
SWITCH_WORKSPACE,
SWITCH_WINDOWS,
MULTITASKING_VIEW,
DOCK,
ZOOM,
N_ACTIONS
}

public class Gesture {
public const float INVALID_COORD = float.MAX;

Expand Down
10 changes: 6 additions & 4 deletions src/Gestures/GestureController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Gala.GestureController : Object {
private const double MAX_VELOCITY = 0.01;

public GestureAction action { get; construct; }
public WindowManager wm { get; construct; }

private GestureTarget? _target;
public GestureTarget target {
Expand Down Expand Up @@ -89,8 +90,8 @@ public class Gala.GestureController : Object {

private SpringTimeline? timeline;

public GestureController (GestureAction action, GestureTarget target) {
Object (action: action, target: target);
public GestureController (GestureAction action, GestureTarget target, WindowManager wm) {
Object (action: action, target: target, wm: wm);
}

public void enable_touchpad () {
Expand Down Expand Up @@ -119,8 +120,9 @@ public class Gala.GestureController : Object {
}

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

if (recognizing) {
if (gesture.direction == UP || gesture.direction == RIGHT || gesture.direction == OUT) {
Expand Down
2 changes: 1 addition & 1 deletion src/ShellClients/PanelWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class Gala.PanelWindow : ShellWindow {
window.size_changed.connect (update_strut);
window.position_changed.connect (update_strut);

gesture_controller = new GestureController (DOCK, this);
gesture_controller = new GestureController (DOCK, this, wm);

window.display.in_fullscreen_changed.connect (() => {
if (wm.get_display ().get_monitor_in_fullscreen (window.get_monitor ())) {
Expand Down
33 changes: 3 additions & 30 deletions src/Widgets/MultitaskingView/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace Gala {
*/
public class MultitaskingView : ActorTarget, ActivatableComponent {
public const int ANIMATION_DURATION = 250;
private const string OPEN_MULTITASKING_VIEW = "dbus-send --session --dest=org.pantheon.gala --print-reply /org/pantheon/gala org.pantheon.gala.PerformAction int32:1";

private GestureController workspaces_gesture_controller;
private GestureController multitasking_gesture_controller;
Expand Down Expand Up @@ -59,14 +58,14 @@ namespace Gala {
opened = false;
display = wm.get_display ();

multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, this);
multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, this, wm);
multitasking_gesture_controller.enable_touchpad ();

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

workspaces = new WorkspaceRow (display);

workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, this) {
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, this, wm) {
overshoot_upper_clamp = 0.1
};
workspaces_gesture_controller.enable_touchpad ();
Expand Down Expand Up @@ -248,6 +247,7 @@ namespace Gala {

modal_proxy = wm.push_modal (this);
modal_proxy.set_keybinding_filter (keybinding_filter);
modal_proxy.allow_actions ({ MULTITASKING_VIEW, SWITCH_WORKSPACE, ZOOM });

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

// allow super key only when it toggles multitasking view
if (action == Meta.KeyBindingAction.OVERLAY_KEY &&
gala_behavior_settings.get_string ("overlay-action") == OPEN_MULTITASKING_VIEW) {
return false;
}

switch (action) {
case Meta.KeyBindingAction.WORKSPACE_1:
case Meta.KeyBindingAction.WORKSPACE_2:
case Meta.KeyBindingAction.WORKSPACE_3:
case Meta.KeyBindingAction.WORKSPACE_4:
case Meta.KeyBindingAction.WORKSPACE_5:
case Meta.KeyBindingAction.WORKSPACE_6:
case Meta.KeyBindingAction.WORKSPACE_7:
case Meta.KeyBindingAction.WORKSPACE_8:
case Meta.KeyBindingAction.WORKSPACE_9:
case Meta.KeyBindingAction.WORKSPACE_10:
case Meta.KeyBindingAction.WORKSPACE_11:
case Meta.KeyBindingAction.WORKSPACE_12:
case Meta.KeyBindingAction.WORKSPACE_LEFT:
case Meta.KeyBindingAction.WORKSPACE_RIGHT:
case Meta.KeyBindingAction.SHOW_DESKTOP:
case Meta.KeyBindingAction.NONE:
case Meta.KeyBindingAction.LOCATE_POINTER_KEY:
return false;
Expand All @@ -520,12 +499,6 @@ namespace Gala {
}

switch (binding.get_name ()) {
case "cycle-workspaces-next":
case "cycle-workspaces-previous":
case "switch-to-workspace-first":
case "switch-to-workspace-last":
case "zoom-in":
case "zoom-out":
case "screenshot":
case "screenshot-clip":
return false;
Expand Down
5 changes: 2 additions & 3 deletions src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Gala.WindowOverview : ActorTarget, ActivatableComponent {
construct {
visible = false;
reactive = true;
gesture_controller = new GestureController (MULTITASKING_VIEW, this) {
gesture_controller = new GestureController (MULTITASKING_VIEW, this, wm) {
enabled = false
};
}
Expand Down Expand Up @@ -113,6 +113,7 @@ public class Gala.WindowOverview : ActorTarget, ActivatableComponent {

modal_proxy = wm.push_modal (this);
modal_proxy.set_keybinding_filter (keybinding_filter);
modal_proxy.allow_actions ({ ZOOM });

unowned var display = wm.get_display ();

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

switch (binding.get_name ()) {
case "expose-all-windows":
case "zoom-in":
case "zoom-out":
return false;
default:
break;
Expand Down
9 changes: 2 additions & 7 deletions src/Widgets/WindowSwitcher/WindowSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget {
construct {
style_manager = Drawing.StyleManager.get_instance ();

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

private void push_modal () {
modal_proxy = wm.push_modal (this);
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:
case Meta.KeyBindingAction.SWITCH_APPLICATIONS:
case Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD:
case Meta.KeyBindingAction.SWITCH_WINDOWS:
case Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD:
case Meta.KeyBindingAction.SWITCH_GROUP:
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
return false;
default:
break;
Expand Down
64 changes: 62 additions & 2 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace Gala {
public class WindowManagerGala : Meta.Plugin, WindowManager {
private const string OPEN_MULTITASKING_VIEW = "dbus-send --session --dest=org.pantheon.gala --print-reply /org/pantheon/gala org.pantheon.gala.PerformAction int32:1";

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1680,22 +1682,80 @@ namespace Gala {
}

public override bool keybinding_filter (Meta.KeyBinding binding) {
if (!is_modal ())
if (!is_modal ()) {
return false;
}

var action = Meta.Prefs.get_keybinding_action (binding.get_name ());

switch (action) {
case Meta.KeyBindingAction.OVERLAY_KEY:
if (behavior_settings.get_string ("overlay-action") == OPEN_MULTITASKING_VIEW) {
return filter_action (MULTITASKING_VIEW);
}
break;
case Meta.KeyBindingAction.WORKSPACE_1:
case Meta.KeyBindingAction.WORKSPACE_2:
case Meta.KeyBindingAction.WORKSPACE_3:
case Meta.KeyBindingAction.WORKSPACE_4:
case Meta.KeyBindingAction.WORKSPACE_5:
case Meta.KeyBindingAction.WORKSPACE_6:
case Meta.KeyBindingAction.WORKSPACE_7:
case Meta.KeyBindingAction.WORKSPACE_8:
case Meta.KeyBindingAction.WORKSPACE_9:
case Meta.KeyBindingAction.WORKSPACE_10:
case Meta.KeyBindingAction.WORKSPACE_11:
case Meta.KeyBindingAction.WORKSPACE_12:
case Meta.KeyBindingAction.WORKSPACE_LEFT:
case Meta.KeyBindingAction.WORKSPACE_RIGHT:
return filter_action (SWITCH_WORKSPACE);
case Meta.KeyBindingAction.SHOW_DESKTOP:
return filter_action (MULTITASKING_VIEW);
case Meta.KeyBindingAction.SWITCH_APPLICATIONS:
case Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD:
case Meta.KeyBindingAction.SWITCH_WINDOWS:
case Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD:
case Meta.KeyBindingAction.SWITCH_GROUP:
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
return filter_action (SWITCH_WINDOWS);
default:
break;
}

switch (binding.get_name ()) {
case "cycle-workspaces-next":
case "cycle-workspaces-previous":
case "switch-to-workspace-first":
case "switch-to-workspace-last":
return filter_action (SWITCH_WORKSPACE);
case "zoom-in":
case "zoom-out":
return filter_action (ZOOM);
default:
break;
}

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

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

return filter (binding);
}

public bool filter_action (GestureAction action) {
if (!is_modal ()) {
return false;
}

return modal_stack.peek_head ().filter_action (action);
}

public override void confirm_display_change () {
unowned var monitor_manager = get_display ().get_context ().get_backend ().get_monitor_manager ();
var timeout = monitor_manager.get_display_configuration_timeout ();
Expand Down
2 changes: 1 addition & 1 deletion src/Zoom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Gala.Zoom : Object, GestureTarget {
display.add_keybinding ("zoom-in", schema, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) zoom_in);
display.add_keybinding ("zoom-out", schema, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) zoom_out);

gesture_controller = new GestureController (ZOOM, this) {
gesture_controller = new GestureController (ZOOM, this, wm) {
snap = false
};
gesture_controller.enable_touchpad ();
Expand Down