Skip to content

Commit 138e7c7

Browse files
committed
Use enum and name it group
1 parent 466926b commit 138e7c7

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

lib/Gestures/GestureController.vala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
* it will be a hard boundary, if they are fractional it will slow the gesture progress when over the
2020
* limit simulating a kind of spring that pushes against it.
2121
* Note that the progress snaps to full integer values after a gesture ends.
22-
* Events are always shared between all GestureControllers with the same id.
22+
* Events are always shared between all GestureControllers in the same group (except for the group NONE).
2323
* This means that two gestures that can be done in one motion (e.g. horizontal and vertical swipe)
24-
* can be done simultaneously if each of two GestureControllers with the same id handle one of
24+
* can be done simultaneously if each of two GestureControllers in the same group handle one of
2525
* the gestures.
2626
*/
2727
public class Gala.GestureController : Object {
28+
public enum Group {
29+
NONE,
30+
MULTITASKING_VIEW,
31+
}
32+
2833
/**
2934
* When a gesture ends with a velocity greater than this constant, the action is not cancelled,
3035
* even if the animation threshold has not been reached.
@@ -38,7 +43,7 @@ public class Gala.GestureController : Object {
3843

3944
public GestureAction action { get; construct; }
4045
public WindowManager wm { get; construct; }
41-
public string? id { get; construct; }
46+
public Group group { get; construct; }
4247

4348
private unowned RootTarget? _target;
4449
public RootTarget target {
@@ -96,8 +101,8 @@ public class Gala.GestureController : Object {
96101

97102
private SpringTimeline? timeline;
98103

99-
public GestureController (GestureAction action, WindowManager wm, string? id = null) {
100-
Object (action: action, wm: wm, id: id);
104+
public GestureController (GestureAction action, WindowManager wm, Group group = NONE) {
105+
Object (action: action, wm: wm, group: group);
101106
}
102107

103108
/**
@@ -115,7 +120,7 @@ public class Gala.GestureController : Object {
115120

116121
public void enable_touchpad (Clutter.Actor actor) {
117122
if (Meta.Util.is_wayland_compositor ()) {
118-
touchpad_backend = new TouchpadBackend (actor, id);
123+
touchpad_backend = new TouchpadBackend (actor, group);
119124
touchpad_backend.on_gesture_detected.connect (gesture_detected);
120125
touchpad_backend.on_begin.connect (gesture_begin);
121126
touchpad_backend.on_update.connect (gesture_update);

lib/Gestures/TouchpadBackend.vala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ private class Gala.TouchpadBackend : Object, GestureBackend {
1919
}
2020

2121
public Clutter.Actor actor { get; construct; }
22-
public string? id { get; construct; }
22+
public GestureController.Group group { get; construct; }
2323

2424
private static List<TouchpadBackend> instances = new List<TouchpadBackend> ();
25+
2526
private State state = NONE;
2627
private GestureDirection direction = UNKNOWN;
2728
private double distance_x = 0;
2829
private double distance_y = 0;
2930
private double distance = 0;
3031

31-
public TouchpadBackend (Clutter.Actor actor, string? id) {
32-
Object (actor: actor, id: id);
32+
public TouchpadBackend (Clutter.Actor actor, GestureController.Group group) {
33+
Object (actor: actor, group: group);
3334
}
3435

3536
~TouchpadBackend () {
@@ -102,9 +103,9 @@ private class Gala.TouchpadBackend : Object, GestureBackend {
102103

103104
state = ONGOING;
104105
on_begin (0, event.get_time ());
105-
} else if (main_handler && id != null) {
106+
} else if (main_handler && group != NONE) {
106107
foreach (var instance in instances) {
107-
if (instance != this && instance.id == id) {
108+
if (instance != this && instance.group == group) {
108109
instance.handle_event (event, false);
109110
}
110111
}

src/Widgets/MultitaskingView/MultitaskingView.vala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableComponent {
2424
public const int ANIMATION_DURATION = 250;
2525

26-
private const string GESTURE_CONTROLLER_ID = "multitaskingview";
27-
2826
private GestureController workspaces_gesture_controller;
2927
private GestureController multitasking_gesture_controller;
3028

@@ -60,15 +58,15 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
6058
opened = false;
6159
display = wm.get_display ();
6260

63-
multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, wm, GESTURE_CONTROLLER_ID);
61+
multitasking_gesture_controller = new GestureController (MULTITASKING_VIEW, wm, MULTITASKING_VIEW);
6462
multitasking_gesture_controller.enable_touchpad (wm.stage);
6563
add_gesture_controller (multitasking_gesture_controller);
6664

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

6967
workspaces = new WorkspaceRow (display);
7068

71-
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, wm, GESTURE_CONTROLLER_ID) {
69+
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, wm, MULTITASKING_VIEW) {
7270
overshoot_upper_clamp = 0.1
7371
};
7472
workspaces_gesture_controller.enable_touchpad (wm.stage);

0 commit comments

Comments
 (0)