Rewrite gesture schemas (#1108)

This commit is contained in:
Daniel Foré 2021-04-21 08:42:56 -07:00 committed by GitHub
parent 9f6b6a35c3
commit dab8325b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 83 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<enum id="GalaActionType">
<value nick='none' value="0" />
<value nick="none" value="0" />
<value nick="show-workspace-view" value="1" />
<value nick="maximize-current" value="2" />
<value nick="minimize-current" value="3" />
@ -26,7 +26,7 @@
<schema path="/org/pantheon/desktop/gala/behavior/" id="org.pantheon.desktop.gala.behavior">
<key enum="GalaActionType" name="hotcorner-topleft">
<default>'none'</default>
<default>"none"</default>
<summary>Action for the top left corner</summary>
<description></description>
</key>
@ -36,17 +36,17 @@
<description>Choose the algorithm used for exposing the windows.</description>
</key>
<key enum="GalaActionType" name="hotcorner-topright">
<default>'none'</default>
<default>"none"</default>
<summary>Action for the top right corner</summary>
<description></description>
</key>
<key enum="GalaActionType" name="hotcorner-bottomleft">
<default>'none'</default>
<default>"none"</default>
<summary>Action for the bottom left corner</summary>
<description></description>
</key>
<key enum="GalaActionType" name="hotcorner-bottomright">
<default>'none'</default>
<default>"none"</default>
<summary>Action for the bottom right corner</summary>
<description></description>
</key>
@ -314,39 +314,50 @@
</key>
</schema>
<enum id="GesturePinch">
<value nick="none" value="0" />
<value nick="zoom" value="1" />
</enum>
<enum id="GestureSwipeHorizontal">
<value nick="none" value="0" />
<value nick="switch-to-workspace" value="1" />
</enum>
<enum id="GestureSwipeUp">
<value nick="none" value="0" />
<value nick="multitasking-view" value="1" />
<value nick="toggle-maximized" value="2" />
</enum>
<schema path="/io/elementary/desktop/wm/gestures/" id="io.elementary.desktop.wm.gestures">
<key type="b" name="multitasking-gesture-enabled">
<default>true</default>
<summary>Multitasking view gesture</summary>
<description>If enabled, swipe up with the number of fingers set in io.elementary.desktop.wm.gestures.multitasking-gesture-fingers to show the multitasking view</description>
<key name="three-finger-pinch" enum="GesturePinch">
<default>"none"</default>
<summary>Three-finger pinch gesture</summary>
<description>The action that corresponds to performing a pinch gesture with three fingers</description>
</key>
<key type="i" name="multitasking-gesture-fingers">
<default>3</default>
<range min="3" max="4"/>
<summary>Multitasking view gesture fingers</summary>
<description>Number of fingers used in the multitasking view gesture</description>
<key name="four-finger-pinch" enum="GesturePinch">
<default>"none"</default>
<summary>Four-finger pinch gesture</summary>
<description>The action that corresponds to performing a pinch gesture with four fingers</description>
</key>
<key type="b" name="workspaces-gesture-enabled">
<default>true</default>
<summary>Switch workspace gesture</summary>
<description>If enabled, swipe left/right with the number of fingers set in io.elementary.desktop.wm.gestures.workspaces-gesture-fingers to switch between workspaces</description>
<key name="three-finger-swipe-up" enum="GestureSwipeUp">
<default>"multitasking-view"</default>
<summary>Three-finger up-swipe gesture</summary>
<description>The action that corresponds to swiping up with three fingers</description>
</key>
<key type="i" name="workspaces-gesture-fingers">
<default>3</default>
<range min="3" max="4"/>
<summary>Switch workspace gesture fingers</summary>
<description>Number of fingers used in the switch workspaces gesture</description>
<key name="four-finger-swipe-up" enum="GestureSwipeUp">
<default>"none"</default>
<summary>Four-finger up-swipe gesture</summary>
<description>The action that corresponds to swiping up with four fingers</description>
</key>
<key type="b" name="zoom-gesture-enabled">
<default>false</default>
<summary>Zoom gesture</summary>
<description>If enabled, pinch with the number of fingers set in io.elementary.desktop.wm.gestures.multitasking-gesture-fingers to zoom in/out the entire desktop</description>
<key name="three-finger-swipe-horizontal" enum="GestureSwipeHorizontal">
<default>"switch-to-workspace"</default>
<summary>Three-finger horizontal swipe gesture</summary>
<description>The action that corresponds to performing a horizontal swipe gesture with three fingers</description>
</key>
<key type="i" name="zoom-gesture-fingers">
<default>3</default>
<range min="3" max="4"/>
<summary>Zoom gesture fingers</summary>
<description>Number of fingers used in the zoom gesture</description>
<key name="four-finger-swipe-horizontal" enum="GestureSwipeHorizontal">
<default>"none"</default>
<summary>Four-finger horizontal swipe gesture</summary>
<description>The action that corresponds to performing a horizontal swipe gesture with four fingers</description>
</key>
</schema>
</schemalist>

View File

@ -23,15 +23,6 @@ public class Gala.GestureSettings : Object {
private static GLib.Settings gala_settings;
private static GLib.Settings touchpad_settings;
public const string MULTITASKING_ENABLED = "multitasking-gesture-enabled";
public const string MULTITASKING_FINGERS = "multitasking-gesture-fingers";
public const string WORKSPACE_ENABLED = "workspaces-gesture-enabled";
public const string WORKSPACE_FINGERS = "workspaces-gesture-fingers";
public const string ZOOM_ENABLED = "zoom-gesture-enabled";
public const string ZOOM_FINGERS = "zoom-gesture-fingers";
static construct {
gala_settings = new GLib.Settings ("io.elementary.desktop.wm.gestures");
touchpad_settings = new GLib.Settings ("org.gnome.desktop.peripherals.touchpad");
@ -75,11 +66,7 @@ public class Gala.GestureSettings : Object {
}
}
public bool is_gesture_enabled (string setting_id) {
return gala_settings.get_boolean (setting_id);
}
public int gesture_fingers (string setting_id) {
return gala_settings.get_int (setting_id);
public static string get_string (string setting_id) {
return gala_settings.get_string (setting_id);
}
}

View File

@ -207,22 +207,17 @@ namespace Gala {
}
private void on_multitasking_gesture_detected (Gesture gesture) {
var enabled = workspace_gesture_tracker.settings.is_gesture_enabled (GestureSettings.MULTITASKING_ENABLED);
var fingers = workspace_gesture_tracker.settings.gesture_fingers (GestureSettings.MULTITASKING_FINGERS);
if (gesture.type != Gdk.EventType.TOUCHPAD_SWIPE ||
(gesture.fingers == 3 && GestureSettings.get_string ("three-finger-swipe-up") != "multitasking-view") ||
(gesture.fingers == 4 && GestureSettings.get_string ("four-finger-swipe-up") != "multitasking-view")
) {
return;
}
bool up = gesture.direction == GestureDirection.UP;
bool down = gesture.direction == GestureDirection.DOWN;
bool can_handle_swipe = gesture.type == Gdk.EventType.TOUCHPAD_SWIPE
&& (up || down)
&& gesture.fingers == fingers;
bool can_handle_gesture = enabled && can_handle_swipe;
if (can_handle_gesture) {
if (up && !opened) {
toggle (true, false);
} else if (down && opened) {
toggle (true, false);
}
if (gesture.direction == GestureDirection.UP && !opened) {
toggle (true, false);
} else if (gesture.direction == GestureDirection.DOWN && opened) {
toggle (true, false);
}
}
@ -231,16 +226,13 @@ namespace Gala {
return;
}
var enabled = workspace_gesture_tracker.settings.is_gesture_enabled (GestureSettings.WORKSPACE_ENABLED);
var fingers = workspace_gesture_tracker.settings.gesture_fingers (GestureSettings.WORKSPACE_FINGERS);
var can_handle_swipe = gesture.type == Gdk.EventType.TOUCHPAD_SWIPE &&
(gesture.direction == GestureDirection.LEFT || gesture.direction == GestureDirection.RIGHT);
bool can_handle_scroll = gesture.type == Gdk.EventType.SCROLL;
bool can_handle_swipe = gesture.type == Gdk.EventType.TOUCHPAD_SWIPE
&& (gesture.direction == GestureDirection.LEFT || gesture.direction == GestureDirection.RIGHT)
&& gesture.fingers == fingers;
bool can_handle_gesture = enabled && (can_handle_scroll || can_handle_swipe);
var fingers = (gesture.fingers == 3 && Gala.GestureSettings.get_string ("three-finger-swipe-horizontal") == "switch-to-workspace") ||
(gesture.fingers == 4 && Gala.GestureSettings.get_string ("four-finger-swipe-horizontal") == "switch-to-workspace");
if (can_handle_gesture) {
if (gesture.type == Gdk.EventType.SCROLL || (can_handle_swipe && fingers)) {
var direction = workspace_gesture_tracker.settings.get_natural_scroll_direction (gesture);
switch_workspace_with_gesture (direction);
}

View File

@ -481,14 +481,13 @@ namespace Gala {
return;
}
var enabled = gesture_tracker.settings.is_gesture_enabled (GestureSettings.WORKSPACE_ENABLED);
var fingers = gesture_tracker.settings.gesture_fingers (GestureSettings.WORKSPACE_FINGERS);
var can_handle_swipe = gesture.type == Gdk.EventType.TOUCHPAD_SWIPE &&
(gesture.direction == GestureDirection.LEFT || gesture.direction == GestureDirection.RIGHT);
bool can_handle_gesture = gesture.type == Gdk.EventType.TOUCHPAD_SWIPE
&& (gesture.direction == GestureDirection.LEFT || gesture.direction == GestureDirection.RIGHT)
&& gesture.fingers == fingers;
var fingers = (gesture.fingers == 3 && GestureSettings.get_string ("three-finger-swipe-horizontal") == "switch-to-workspace") ||
(gesture.fingers == 4 && GestureSettings.get_string ("four-finger-swipe-horizontal") == "switch-to-workspace");
switch_workspace_with_gesture = enabled && can_handle_gesture;
switch_workspace_with_gesture = can_handle_swipe && fingers;
if (switch_workspace_with_gesture) {
var direction = gesture_tracker.settings.get_natural_scroll_direction (gesture);
switch_to_next_workspace (direction);

View File

@ -71,14 +71,15 @@ namespace Gala {
}
private void on_gesture_detected (Gesture gesture) {
var enabled = gesture_tracker.settings.is_gesture_enabled (GestureSettings.ZOOM_ENABLED);
var fingers = gesture_tracker.settings.gesture_fingers (GestureSettings.ZOOM_FINGERS);
if (gesture.type != Gdk.EventType.TOUCHPAD_PINCH ||
(gesture.direction != GestureDirection.IN && gesture.direction != GestureDirection.OUT)
) {
return;
}
bool can_handle_gesture = gesture.type == Gdk.EventType.TOUCHPAD_PINCH
&& (gesture.direction == GestureDirection.IN || gesture.direction == GestureDirection.OUT)
&& gesture.fingers == fingers;
if (enabled && can_handle_gesture) {
if ((gesture.fingers == 3 && GestureSettings.get_string ("three-finger-pinch") == "zoom") ||
(gesture.fingers == 4 && GestureSettings.get_string ("four-finger-pinch") == "zoom")
) {
zoom_with_gesture (gesture.direction);
}
}