Skip to content

Commit 3dea417

Browse files
committed
ShellClients: Use GestureController and GestureTarget
1 parent 4b48924 commit 3dea417

File tree

3 files changed

+94
-64
lines changed

3 files changed

+94
-64
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: 19 additions & 7 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,33 @@ 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) {
195+
public override void start (string id) {
196+
foreach (var window in positioned_windows.get_values ()) {
197+
window.start (id);
198+
}
199+
200+
foreach (var window in panel_windows.get_values ()) {
201+
window.start (id);
202+
}
203+
}
204+
205+
public override void update (string id, double progress) {
194206
foreach (var window in positioned_windows.get_values ()) {
195-
window.add_state (state, gesture_tracker, with_gesture);
207+
window.update (id, progress);
196208
}
197209

198210
foreach (var window in panel_windows.get_values ()) {
199-
window.add_state (state, gesture_tracker, with_gesture);
211+
window.update (id, progress);
200212
}
201213
}
202214

203-
public void remove_state (ShellWindow.State state, GestureTracker gesture_tracker, bool with_gesture) {
215+
public override void end (string id) {
204216
foreach (var window in positioned_windows.get_values ()) {
205-
window.remove_state (state, gesture_tracker, with_gesture);
217+
window.end (id);
206218
}
207219

208220
foreach (var window in panel_windows.get_values ()) {
209-
window.remove_state (state, gesture_tracker, with_gesture);
221+
window.end (id);
210222
}
211223
}
212224

src/ShellClients/ShellWindow.vala

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,96 @@
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.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 start (string id) {
49+
animations_ongoing++;
50+
update_visibility ();
51+
}
4652

47-
gesture_ongoing = true;
53+
public override void update (string id, double progress) {
54+
switch (id) {
55+
case MultitaskingView.GESTURE_ID:
56+
multitasking_view_progress = progress;
57+
break;
4858

49-
update_visibility (true);
59+
case GESTURE_ID:
60+
custom_progress = progress;
61+
break;
5062

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));
63+
default:
64+
break;
65+
}
5466

55-
gesture_tracker.add_end_callback (with_gesture, (percentage, completions) => {
56-
gesture_ongoing = false;
67+
update_property ();
68+
}
5769

58-
if (completions != 0) {
59-
current_state = new_state;
60-
}
70+
public override void end (string id) {
71+
animations_ongoing--;
72+
update_visibility ();
73+
}
6174

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-
}
75+
private void update_visibility () {
76+
var visible = double.max (multitasking_view_progress, custom_progress) < 0.1;
77+
var animating = animations_ongoing > 0;
6978

70-
if (pending_state != new_state) { // We have received new state while animating
71-
animate (pending_state, gesture_tracker, false);
79+
if (!Meta.Util.is_wayland_compositor ()) {
80+
if (!visible) {
81+
Utils.x11_set_window_pass_through (window);
7282
} else {
73-
pending_state = current_state;
83+
Utils.x11_unset_window_pass_through (window);
7484
}
75-
});
76-
}
77-
78-
private void update_visibility (bool animating) {
79-
var visible = (current_state & HIDING_STATES) == 0;
85+
}
8086

81-
actor.visible = animating || visible;
87+
window_actor.visible = animating || visible;
8288

8389
unowned var manager = ShellClientsManager.get_instance ();
8490
window.foreach_transient ((transient) => {
8591
if (manager.is_itself_positioned (transient)) {
8692
return true;
8793
}
8894

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

91-
actor.visible = visible && !animating;
97+
window_actor.visible = visible && !animating;
9298

9399
return true;
94100
});
@@ -104,12 +110,22 @@ public class Gala.ShellWindow : PositionedWindow {
104110
}
105111
}
106112

113+
private Type get_property_type () {
114+
switch (position) {
115+
case TOP:
116+
case BOTTOM:
117+
return typeof (float);
118+
default:
119+
return typeof (uint);
120+
}
121+
}
122+
107123
private Value calculate_value (bool hidden) {
108124
switch (position) {
109125
case TOP:
110-
return hidden ? -actor.height : 0f;
126+
return hidden ? -window_actor.height : 0f;
111127
case BOTTOM:
112-
return hidden ? actor.height : 0f;
128+
return hidden ? window_actor.height : 0f;
113129
default:
114130
return hidden ? 0u : 255u;
115131
}

0 commit comments

Comments
 (0)