Skip to content

Commit 976dc59

Browse files
committed
TODO SUQASH THIS SHIT
1 parent ef5fba2 commit 976dc59

File tree

6 files changed

+50
-58
lines changed

6 files changed

+50
-58
lines changed

lib/Utils.vala

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,6 @@
1717

1818
namespace Gala {
1919
public class Utils {
20-
/**
21-
* Represents a size as an object in order for it to be updatable.
22-
* Additionally it has some utilities like {@link Gala.Utils.Size.actor_tracking}.
23-
*/
24-
public class Size {
25-
public float width;
26-
public float height;
27-
28-
public Size (float width, float height) {
29-
this.width = width;
30-
this.height = height;
31-
}
32-
33-
/**
34-
* Constructs a new size that will keep in sync with the width and height of an actor.
35-
*/
36-
public Size.actor_tracking (Clutter.Actor actor) {
37-
actor.notify["width"].connect ((obj, pspec) => width = ((Clutter.Actor) obj).width);
38-
actor.notify["height"].connect ((obj, pspec) => height = ((Clutter.Actor) obj).height);
39-
40-
width = actor.width;
41-
height = actor.height;
42-
}
43-
44-
private Meta.Display? display;
45-
46-
public Size.primary_monitor_tracking (Meta.Display _display) {
47-
display = _display;
48-
49-
set_size_from_monitor (display, display.get_primary_monitor ());
50-
display.get_context ().get_backend ().get_monitor_manager ().monitors_changed.connect (() =>
51-
set_size_from_monitor (display, display.get_primary_monitor ()));
52-
}
53-
54-
public void set_size_from_monitor (Meta.Display display, int monitor_index) {
55-
var rect = display.get_monitor_geometry (monitor_index);
56-
width = rect.width;
57-
height = rect.height;
58-
}
59-
}
60-
6120
private struct CachedIcon {
6221
public Gdk.Pixbuf icon;
6322
public int icon_size;

src/Gestures/GestureTracker.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public class Gala.GestureTracker : Object {
154154
* (height for {@link GestureDirection.UP} or DOWN, width for LEFT or RIGHT). If set to null the size of the
155155
* actor will be used. If the values change those changes will apply.
156156
*/
157-
public void enable_pan (Clutter.Actor actor, Utils.Size? travel_distances) {
158-
pan_backend = new PanBackend (actor, travel_distances);
157+
public void enable_pan (Clutter.Actor actor, owned PanBackend.GetTravelDistance travel_distance_func) {
158+
pan_backend = new PanBackend (actor, (owned) travel_distance_func);
159159
pan_backend.on_gesture_detected.connect (gesture_detected);
160160
pan_backend.on_begin.connect ((percentage, time) => {
161161
gesture_begin (percentage, time);

src/Gestures/PanBackend.vala

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
*/
77

88
public class Gala.PanBackend : Object {
9+
public delegate float GetTravelDistance ();
10+
911
public signal bool on_gesture_detected (Gesture gesture);
1012
public signal void on_begin (double delta, uint64 time);
1113
public signal void on_update (double delta, uint64 time);
1214
public signal void on_end (double delta, uint64 time);
1315

1416
public Clutter.Actor actor { get; construct; }
15-
public Utils.Size? travel_distances { get; construct; }
17+
18+
private GetTravelDistance get_travel_distance_func;
1619

1720
private Clutter.PanAxis pan_axis;
1821
private Clutter.PanAction pan_action;
@@ -22,8 +25,12 @@ public class Gala.PanBackend : Object {
2225
private float origin_x;
2326
private float origin_y;
2427

25-
public PanBackend (Clutter.Actor actor, Utils.Size? travel_distances) {
26-
Object (actor: actor, travel_distances: travel_distances);
28+
private float travel_distance;
29+
30+
public PanBackend (Clutter.Actor actor, owned GetTravelDistance get_travel_distance_func) {
31+
Object (actor: actor);
32+
33+
this.get_travel_distance_func = (owned) get_travel_distance_func;
2734
}
2835

2936
construct {
@@ -36,6 +43,11 @@ public class Gala.PanBackend : Object {
3643
pan_action.gesture_begin.connect (on_gesture_begin);
3744
pan_action.pan.connect (on_pan);
3845
pan_action.gesture_end.connect (on_gesture_end);
46+
pan_action.gesture_cancel.connect (on_gesture_end);
47+
}
48+
49+
~PanBackend () {
50+
actor.remove_action (pan_action);
3951
}
4052

4153
private bool on_gesture_begin () {
@@ -51,6 +63,8 @@ public class Gala.PanBackend : Object {
5163
return false;
5264
}
5365

66+
travel_distance = get_travel_distance_func ();
67+
5468
on_begin (0, pan_action.get_last_event (0).get_time ());
5569

5670
return true;
@@ -76,18 +90,16 @@ public class Gala.PanBackend : Object {
7690
}
7791

7892
private double calculate_percentage (float current_x, float current_y) {
79-
float current, origin, size;
93+
float current, origin;
8094
if (pan_axis == X_AXIS) {
8195
current = direction == RIGHT ? float.max (current_x, origin_x) : float.min (current_x, origin_x);
8296
origin = origin_x;
83-
size = travel_distances != null ? travel_distances.width : actor.width;
8497
} else {
8598
current = direction == DOWN ? float.max (current_y, origin_y) : float.min (current_y, origin_y);
8699
origin = origin_y;
87-
size = travel_distances != null ? travel_distances.height : actor.height;
88100
}
89101

90-
return (current - origin).abs () / size;
102+
return (current - origin).abs () / travel_distance;
91103
}
92104

93105
private Gesture build_gesture () {

src/InternalUtils.vala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,5 +336,14 @@ namespace Gala {
336336
return { 0, 0, (int) screen_width, (int) screen_height };
337337
}
338338
}
339+
340+
public static float travel_distance_from_primary (Meta.Display display, Clutter.Orientation orientation) {
341+
var geom = display.get_monitor_geometry (display.get_primary_monitor ());
342+
if (orientation == HORIZONTAL) {
343+
return geom.width;
344+
} else {
345+
return geom.height;
346+
}
347+
}
339348
}
340349
}

src/Widgets/MultitaskingView.vala

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace Gala {
5353
}
5454
}
5555

56+
private float workspaces_travel_distance;
57+
5658
public MultitaskingView (WindowManager wm) {
5759
Object (wm: wm);
5860
}
@@ -70,10 +72,12 @@ namespace Gala {
7072

7173
multitasking_gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
7274
multitasking_gesture_tracker.enable_touchpad ();
75+
multitasking_gesture_tracker.enable_pan (display.get_stage (), () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
7376
multitasking_gesture_tracker.on_gesture_detected.connect (on_multitasking_gesture_detected);
7477

7578
workspace_gesture_tracker = new GestureTracker (AnimationDuration.WORKSPACE_SWITCH_MIN, AnimationDuration.WORKSPACE_SWITCH);
7679
workspace_gesture_tracker.enable_touchpad ();
80+
workspace_gesture_tracker.enable_pan (this, () => workspaces_travel_distance);
7781
workspace_gesture_tracker.enable_scroll (this, Clutter.Orientation.HORIZONTAL);
7882
workspace_gesture_tracker.on_gesture_detected.connect (on_workspace_gesture_detected);
7983

@@ -90,16 +94,17 @@ namespace Gala {
9094
blurred_bg.add_effect (new BlurEffect (blurred_bg, 18));
9195
blurred_bg.add_effect (brightness_effect);
9296

93-
add_child (blurred_bg);
94-
9597
// Create a child container that will be sized to fit the primary monitor, to contain the "main"
9698
// multitasking view UI. The Clutter.Actor of this class has to be allowed to grow to the size of the
9799
// stage as it contains MonitorClones for each monitor.
98-
primary_monitor_container = new Clutter.Actor ();
100+
primary_monitor_container = new Clutter.Actor () {
101+
reactive = true
102+
};
103+
primary_monitor_container.add_child (blurred_bg);
99104
primary_monitor_container.add_child (icon_groups);
100105
primary_monitor_container.add_child (workspaces);
106+
primary_monitor_container.add_child (dock_clones);
101107
add_child (primary_monitor_container);
102-
add_child (dock_clones);
103108

104109
unowned var manager = display.get_workspace_manager ();
105110
manager.workspace_added.connect (add_workspace);
@@ -310,6 +315,7 @@ namespace Gala {
310315
}
311316

312317
private bool on_workspace_gesture_detected (Gesture gesture) {
318+
warning ("DETECTED");
313319
if (!opened) {
314320
return false;
315321
}
@@ -323,6 +329,7 @@ namespace Gala {
323329
if (gesture.type == Clutter.EventType.SCROLL || (can_handle_swipe && fingers)) {
324330
var direction = workspace_gesture_tracker.settings.get_natural_scroll_direction (gesture);
325331
switch_workspace_with_gesture (direction);
332+
warning ("GO");
326333
return true;
327334
}
328335

@@ -370,6 +377,8 @@ namespace Gala {
370377
}
371378
}
372379

380+
workspaces_travel_distance = (initial_x - target_x).abs ();
381+
373382
if (!is_nudge_animation && active_icon_group.get_transition ("backdrop-opacity") != null) {
374383
active_icon_group.remove_transition ("backdrop-opacity");
375384
}
@@ -699,9 +708,6 @@ namespace Gala {
699708
}
700709

701710
if (opening) {
702-
modal_proxy = wm.push_modal (this);
703-
modal_proxy.set_keybinding_filter (keybinding_filter);
704-
705711
wm.background_group.hide ();
706712
wm.window_group.hide ();
707713
wm.top_window_group.hide ();
@@ -771,6 +777,12 @@ namespace Gala {
771777
dock_clones.destroy_all_children ();
772778

773779
wm.pop_modal (modal_proxy);
780+
781+
multitasking_gesture_tracker.enable_pan (wm.get_display ().get_stage (), () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
782+
} else {
783+
modal_proxy = wm.push_modal (this);
784+
modal_proxy.set_keybinding_filter (keybinding_filter);
785+
multitasking_gesture_tracker.enable_pan (primary_monitor_container, () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
774786
}
775787

776788
animating = false;

src/WindowManager.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ namespace Gala {
185185

186186
stage = display.get_stage () as Clutter.Stage;
187187

188-
gesture_tracker.enable_pan (stage, new Utils.Size.primary_monitor_tracking (display));
188+
gesture_tracker.enable_pan (stage, () => InternalUtils.travel_distance_from_primary (get_display (), HORIZONTAL));
189189

190190
var background_settings = new GLib.Settings ("org.gnome.desktop.background");
191191
var color = background_settings.get_string ("primary-color");

0 commit comments

Comments
 (0)