Skip to content

Commit eb82f87

Browse files
committed
ShellClients: Use GestureController and GestureTarget
1 parent 751baee commit eb82f87

File tree

3 files changed

+92
-71
lines changed

3 files changed

+92
-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 (GESTURE_ID, NONE, 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, string id, 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, id, 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, id, progress);
210202
}
211203
}
212204

src/ShellClients/ShellWindow.vala

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,107 @@
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 const string GESTURE_ID = "shell-window";
10+
11+
public Clutter.Actor? actor { get { return window_actor; } }
1512

16-
private const State HIDING_STATES = CUSTOM_HIDDEN | MULTITASKING_VIEW;
13+
private Meta.WindowActor window_actor;
14+
private double custom_progress = 0;
15+
private double multitasking_view_progress = 0;
1716

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

22-
private bool gesture_ongoing = false;
19+
private PropertyTarget property_target;
2320

2421
public ShellWindow (Meta.Window window, Position position, Variant? position_data = null) {
2522
base (window, position, position_data);
2623
}
2724

2825
construct {
29-
actor = (Meta.WindowActor) window.get_compositor_private ();
26+
window_actor = (Meta.WindowActor) window.get_compositor_private ();
27+
28+
window_actor.notify["height"].connect (update_target);
29+
notify["position"].connect (update_target);
30+
update_target ();
3031
}
3132

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);
33+
private void update_target () {
34+
property_target = new PropertyTarget (
35+
GESTURE_ID, window_actor,
36+
get_animation_property (),
37+
get_property_type (),
38+
calculate_value (false),
39+
calculate_value (true)
40+
);
3541
}
3642

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);
43+
private void update_property () {
44+
var hidden_progress = double.max (custom_progress, multitasking_view_progress);
45+
property_target.propagate (UPDATE, GESTURE_ID, hidden_progress);
4046
}
4147

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

47-
gesture_ongoing = true;
55+
case UPDATE:
56+
on_update (id, progress);
57+
break;
4858

49-
update_visibility (true);
59+
case END:
60+
animations_ongoing--;
61+
update_visibility ();
62+
break;
5063

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));
64+
default:
65+
break;
66+
}
67+
}
5468

55-
gesture_tracker.add_end_callback (with_gesture, (percentage, completions) => {
56-
gesture_ongoing = false;
69+
private void on_update (string id, double progress) {
70+
switch (id) {
71+
case MultitaskingView.GESTURE_ID:
72+
multitasking_view_progress = progress;
73+
break;
5774

58-
if (completions != 0) {
59-
current_state = new_state;
60-
}
75+
case GESTURE_ID:
76+
custom_progress = progress;
77+
break;
6178

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-
}
79+
default:
80+
break;
81+
}
6982

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-
});
83+
update_property ();
7684
}
7785

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

81-
actor.visible = animating || visible;
98+
window_actor.visible = animating || visible;
8299

83100
unowned var manager = ShellClientsManager.get_instance ();
84101
window.foreach_transient ((transient) => {
85102
if (manager.is_itself_positioned (transient)) {
86103
return true;
87104
}
88105

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

91-
actor.visible = visible && !animating;
108+
window_actor.visible = visible && !animating;
92109

93110
return true;
94111
});
@@ -104,12 +121,22 @@ public class Gala.ShellWindow : PositionedWindow {
104121
}
105122
}
106123

124+
private Type get_property_type () {
125+
switch (position) {
126+
case TOP:
127+
case BOTTOM:
128+
return typeof (float);
129+
default:
130+
return typeof (uint);
131+
}
132+
}
133+
107134
private Value calculate_value (bool hidden) {
108135
switch (position) {
109136
case TOP:
110-
return hidden ? -actor.height : 0f;
137+
return hidden ? -window_actor.height : 0f;
111138
case BOTTOM:
112-
return hidden ? actor.height : 0f;
139+
return hidden ? window_actor.height : 0f;
113140
default:
114141
return hidden ? 0u : 255u;
115142
}

0 commit comments

Comments
 (0)