Skip to content

Commit dfaa34d

Browse files
committed
ShellClients: Use GestureController and GestureTarget
1 parent 02b0790 commit dfaa34d

File tree

3 files changed

+90
-71
lines changed

3 files changed

+90
-71
lines changed

src/ShellClients/PanelWindow.vala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Gala.PanelWindow : ShellWindow {
3535
}
3636
}
3737

38-
private GestureTracker default_gesture_tracker;
38+
private GestureController gesture_controller;
3939
private HideTracker? hide_tracker;
4040

4141
private int width = -1;
@@ -50,6 +50,8 @@ public class Gala.PanelWindow : ShellWindow {
5050
if (window_struts.remove (window)) {
5151
update_struts ();
5252
}
53+
54+
gesture_controller = null; // make it release its reference on us
5355
});
5456

5557
notify["anchor"].connect (() => position = Position.from_anchor (anchor));
@@ -61,7 +63,7 @@ public class Gala.PanelWindow : ShellWindow {
6163
window.size_changed.connect (update_strut);
6264
window.position_changed.connect (update_strut);
6365

64-
default_gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
66+
gesture_controller = new GestureController (DOCK, this);
6567

6668
window.display.in_fullscreen_changed.connect (() => {
6769
if (wm.get_display ().get_monitor_in_fullscreen (window.get_monitor ())) {
@@ -105,15 +107,15 @@ public class Gala.PanelWindow : ShellWindow {
105107
}
106108

107109
private void hide () {
108-
add_state (CUSTOM_HIDDEN, default_gesture_tracker, false);
110+
gesture_controller.goto (1);
109111
}
110112

111113
private void show () {
112114
if (window.display.get_monitor_in_fullscreen (window.get_monitor ())) {
113115
return;
114116
}
115117

116-
remove_state (CUSTOM_HIDDEN, default_gesture_tracker, false);
118+
gesture_controller.goto (0);
117119
}
118120

119121
private void make_exclusive () {

src/ShellClients/ShellClientsManager.vala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Authored by: Leonhard Kargl <[email protected]>
66
*/
77

8-
public class Gala.ShellClientsManager : Object {
8+
public class Gala.ShellClientsManager : Object, GestureTarget {
99
private static ShellClientsManager instance;
1010

1111
public static void init (WindowManager wm) {
@@ -20,6 +20,8 @@ public class Gala.ShellClientsManager : Object {
2020
return instance;
2121
}
2222

23+
public Clutter.Actor? actor { get { return wm.stage; } }
24+
2325
public WindowManager wm { get; construct; }
2426

2527
private NotificationsClient notifications_client;
@@ -190,23 +192,13 @@ public class Gala.ShellClientsManager : Object {
190192
window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window));
191193
}
192194

193-
public void add_state (ShellWindow.State state, GestureTracker gesture_tracker, bool with_gesture) {
194-
foreach (var window in positioned_windows.get_values ()) {
195-
window.add_state (state, gesture_tracker, with_gesture);
196-
}
197-
198-
foreach (var window in panel_windows.get_values ()) {
199-
window.add_state (state, gesture_tracker, with_gesture);
200-
}
201-
}
202-
203-
public void remove_state (ShellWindow.State state, GestureTracker gesture_tracker, bool with_gesture) {
195+
public override void propagate (UpdateType update_type, GestureAction action, double progress) {
204196
foreach (var window in positioned_windows.get_values ()) {
205-
window.remove_state (state, gesture_tracker, with_gesture);
197+
window.propagate (update_type, action, progress);
206198
}
207199

208200
foreach (var window in panel_windows.get_values ()) {
209-
window.remove_state (state, gesture_tracker, with_gesture);
201+
window.propagate (update_type, action, progress);
210202
}
211203
}
212204

src/ShellClients/ShellWindow.vala

Lines changed: 78 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,105 @@
55
* Authored by: Leonhard Kargl <[email protected]>
66
*/
77

8-
public class Gala.ShellWindow : PositionedWindow {
9-
[Flags]
10-
public enum State {
11-
CUSTOM_HIDDEN,
12-
MULTITASKING_VIEW,
13-
DESKTOP
14-
}
8+
public class Gala.ShellWindow : PositionedWindow, GestureTarget {
9+
public Clutter.Actor? actor { get { return window_actor; } }
1510

16-
private const State HIDING_STATES = CUSTOM_HIDDEN | MULTITASKING_VIEW;
11+
private Meta.WindowActor window_actor;
12+
private double custom_progress = 0;
13+
private double multitasking_view_progress = 0;
1714

18-
private Meta.WindowActor actor;
19-
private State pending_state = DESKTOP;
20-
private State current_state = DESKTOP;
15+
private int animations_ongoing = 0;
2116

22-
private bool gesture_ongoing = false;
17+
private PropertyTarget property_target;
2318

2419
public ShellWindow (Meta.Window window, Position position, Variant? position_data = null) {
2520
base (window, position, position_data);
2621
}
2722

2823
construct {
29-
actor = (Meta.WindowActor) window.get_compositor_private ();
24+
window_actor = (Meta.WindowActor) window.get_compositor_private ();
25+
26+
window_actor.notify["height"].connect (update_target);
27+
notify["position"].connect (update_target);
28+
update_target ();
3029
}
3130

32-
public void add_state (State state, GestureTracker gesture_tracker, bool with_gesture) {
33-
pending_state |= state;
34-
animate (pending_state, gesture_tracker, with_gesture);
31+
private void update_target () {
32+
property_target = new PropertyTarget (
33+
DOCK, window_actor,
34+
get_animation_property (),
35+
get_property_type (),
36+
calculate_value (false),
37+
calculate_value (true)
38+
);
3539
}
3640

37-
public void remove_state (State state, GestureTracker gesture_tracker, bool with_gesture) {
38-
pending_state &= ~state;
39-
animate (pending_state, gesture_tracker, with_gesture);
41+
private void update_property () {
42+
var hidden_progress = double.max (custom_progress, multitasking_view_progress);
43+
property_target.propagate (UPDATE, DOCK, hidden_progress);
4044
}
4145

42-
private void animate (State new_state, GestureTracker gesture_tracker, bool with_gesture) {
43-
if (new_state == current_state || gesture_ongoing) {
44-
return;
45-
}
46+
public override void propagate (UpdateType update_type, GestureAction action, double progress) {
47+
switch (update_type) {
48+
case START:
49+
animations_ongoing++;
50+
update_visibility ();
51+
break;
4652

47-
gesture_ongoing = true;
53+
case UPDATE:
54+
on_update (action, progress);
55+
break;
4856

49-
update_visibility (true);
57+
case END:
58+
animations_ongoing--;
59+
update_visibility ();
60+
break;
5061

51-
new GesturePropertyTransition (
52-
actor, gesture_tracker, get_animation_property (), null, calculate_value ((new_state & HIDING_STATES) != 0)
53-
).start (with_gesture, () => update_visibility (false));
62+
default:
63+
break;
64+
}
65+
}
5466

55-
gesture_tracker.add_end_callback (with_gesture, (percentage, completions) => {
56-
gesture_ongoing = false;
67+
private void on_update (GestureAction action, double progress) {
68+
switch (action) {
69+
case MULTITASKING_VIEW:
70+
multitasking_view_progress = progress;
71+
break;
5772

58-
if (completions != 0) {
59-
current_state = new_state;
60-
}
73+
case DOCK:
74+
custom_progress = progress;
75+
break;
6176

62-
if (!Meta.Util.is_wayland_compositor ()) {
63-
if ((current_state & HIDING_STATES) != 0) {
64-
Utils.x11_set_window_pass_through (window);
65-
} else {
66-
Utils.x11_unset_window_pass_through (window);
67-
}
68-
}
77+
default:
78+
break;
79+
}
6980

70-
if (pending_state != new_state) { // We have received new state while animating
71-
animate (pending_state, gesture_tracker, false);
72-
} else {
73-
pending_state = current_state;
74-
}
75-
});
81+
update_property ();
7682
}
7783

78-
private void update_visibility (bool animating) {
79-
var visible = (current_state & HIDING_STATES) == 0;
84+
private void update_visibility () {
85+
var visible = double.max (multitasking_view_progress, custom_progress) < 0.1;
86+
var animating = animations_ongoing > 0;
87+
88+
if (!Meta.Util.is_wayland_compositor ()) {
89+
if (!visible) {
90+
Utils.x11_set_window_pass_through (window);
91+
} else {
92+
Utils.x11_unset_window_pass_through (window);
93+
}
94+
}
8095

81-
actor.visible = animating || visible;
96+
window_actor.visible = animating || visible;
8297

8398
unowned var manager = ShellClientsManager.get_instance ();
8499
window.foreach_transient ((transient) => {
85100
if (manager.is_itself_positioned (transient)) {
86101
return true;
87102
}
88103

89-
unowned var actor = (Meta.WindowActor) transient.get_compositor_private ();
104+
unowned var window_actor = (Meta.WindowActor) transient.get_compositor_private ();
90105

91-
actor.visible = visible && !animating;
106+
window_actor.visible = visible && !animating;
92107

93108
return true;
94109
});
@@ -104,12 +119,22 @@ public class Gala.ShellWindow : PositionedWindow {
104119
}
105120
}
106121

122+
private Type get_property_type () {
123+
switch (position) {
124+
case TOP:
125+
case BOTTOM:
126+
return typeof (float);
127+
default:
128+
return typeof (uint);
129+
}
130+
}
131+
107132
private Value calculate_value (bool hidden) {
108133
switch (position) {
109134
case TOP:
110-
return hidden ? -actor.height : 0f;
135+
return hidden ? -window_actor.height : 0f;
111136
case BOTTOM:
112-
return hidden ? actor.height : 0f;
137+
return hidden ? window_actor.height : 0f;
113138
default:
114139
return hidden ? 0u : 255u;
115140
}

0 commit comments

Comments
 (0)