Skip to content

Commit e71c030

Browse files
committed
PiP: Use WorkspaceHideTracker for hiding
1 parent 293b1d9 commit e71c030

File tree

4 files changed

+76
-70
lines changed

4 files changed

+76
-70
lines changed

lib/WindowManager.vala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,13 @@ namespace Gala {
173173
* @return true if the action should be prohibited, false otherwise
174174
*/
175175
public abstract bool filter_action (GestureAction action);
176+
177+
/**
178+
* Adds target to the multitasking view and window overview so the target responds to the multitasking view
179+
* close/open gesture and shortcuts.
180+
*
181+
* @param target Target to add to multitasking view and window overview
182+
*/
183+
public abstract void add_multitasking_view_target (GestureTarget target);
176184
}
177185
}

plugins/pip/Main.vala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,31 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
9797
return;
9898
}
9999

100-
var popup_window = new PopupWindow (wm.get_display (), active);
100+
var popup_window = new PopupWindow (wm, active);
101101
popup_window.set_container_clip (rect);
102-
popup_window.show.connect (on_popup_window_show);
103-
popup_window.hide.connect (on_popup_window_hide);
104102
add_window (popup_window);
105103
}
106104

107-
private void on_popup_window_show (Clutter.Actor popup_window) {
108-
track_actor (popup_window);
109-
update_region ();
110-
}
111-
112-
private void on_popup_window_hide (Clutter.Actor popup_window) {
113-
untrack_actor (popup_window);
114-
update_region ();
115-
}
116-
117105
private void select_window_at (int x, int y) {
118106
var selected = get_window_actor_at (x, y);
119107
if (selected != null) {
120-
var popup_window = new PopupWindow (wm.get_display (), selected);
121-
popup_window.show.connect (on_popup_window_show);
122-
popup_window.hide.connect (on_popup_window_hide);
108+
var popup_window = new PopupWindow (wm, selected);
123109
add_window (popup_window);
124110
}
125111
}
126112

113+
private void popup_window_reactive_changed (GLib.Object obj, GLib.ParamSpec pspec) requires (obj is PopupWindow) {
114+
var popup_window = (PopupWindow) obj;
115+
116+
if (popup_window.reactive) {
117+
track_actor (popup_window);
118+
} else {
119+
untrack_actor (popup_window);
120+
}
121+
122+
update_region ();
123+
}
124+
127125
private void clear_selection_area () {
128126
if (selection_area != null) {
129127
untrack_actor (selection_area);
@@ -189,6 +187,8 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
189187
}
190188

191189
private void add_window (PopupWindow popup_window) {
190+
track_actor (popup_window);
191+
popup_window.notify["reactive"].connect (popup_window_reactive_changed);
192192
popup_window.closed.connect (() => remove_window (popup_window));
193193
windows.add (popup_window);
194194
wm.ui_group.add_child (popup_window);

plugins/pip/PopupWindow.vala

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: GPL-3.0-or-later
55
*/
66

7-
public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
7+
public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor, GestureTarget, RootTarget {
88
private int button_size;
99
private int container_margin;
1010
private const uint FADE_OUT_TIMEOUT = 200;
@@ -15,7 +15,9 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
1515

1616
public signal void closed ();
1717

18-
public Meta.Display display { get; construct; }
18+
public Clutter.Actor? actor { get { return this; } }
19+
20+
public WindowManager wm { get; construct; }
1921
public Meta.WindowActor window_actor { get; construct; }
2022

2123
private Clutter.Clone clone; // clone itself
@@ -34,8 +36,10 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
3436
private bool resizing = false;
3537
private bool off_screen = false;
3638
private Clutter.Grab? grab = null;
37-
38-
private static unowned Meta.Window? previous_focus = null;
39+
40+
private GestureController gesture_controller;
41+
private WorkspaceHideTracker workspace_hide_tracker;
42+
private PropertyTarget property_target;
3943

4044
// From https://opensourcehacker.com/2011/12/01/calculate-aspect-ratio-conserving-resize-for-images-in-javascript/
4145
private static void calculate_aspect_ratio_size_fit (float src_width, float src_height, float max_width, float max_height,
@@ -45,11 +49,12 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
4549
height = src_height * ratio;
4650
}
4751

48-
public PopupWindow (Meta.Display display, Meta.WindowActor window_actor) {
49-
Object (display: display, window_actor: window_actor);
52+
public PopupWindow (WindowManager wm, Meta.WindowActor window_actor) {
53+
Object (wm: wm, window_actor: window_actor);
5054
}
5155

5256
construct {
57+
unowned var display = wm.get_display ();
5358
var scale = display.get_monitor_scale (display.get_current_monitor ());
5459

5560
button_size = Gala.Utils.scale_to_int (36, scale);
@@ -122,41 +127,35 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
122127

123128
unowned var window = window_actor.get_meta_window ();
124129
window.unmanaged.connect (on_close_click_clicked);
125-
window.notify["appears-focused"].connect (update_window_focus);
126130

127-
unowned var workspace_manager = display.get_workspace_manager ();
128-
workspace_manager.active_workspace_changed.connect (update_window_focus);
129-
}
131+
wm.add_multitasking_view_target (this);
130132

131-
public override void show () {
132-
base.show ();
133+
gesture_controller = new GestureController (CUSTOM, wm) {
134+
progress = 0.0
135+
};
136+
add_gesture_controller (gesture_controller);
133137

134-
opacity = 0;
138+
workspace_hide_tracker = new WorkspaceHideTracker (display, this);
139+
workspace_hide_tracker.compute_progress.connect (calculate_progress);
140+
workspace_hide_tracker.switching_workspace_progress_updated.connect ((value) => gesture_controller.progress = value);
141+
workspace_hide_tracker.window_state_changed_progress_updated.connect (gesture_controller.goto);
135142

136-
save_easing_state ();
137-
set_easing_duration (Utils.get_animation_duration (200));
138-
opacity = 255;
139-
restore_easing_state ();
143+
property_target = new PropertyTarget (CUSTOM, this, "opacity", typeof (uint), 255u, 0u);
140144
}
141145

142-
public override void hide () {
143-
opacity = 255;
146+
public override void propagate (UpdateType update_type, GestureAction action, double progress) {
147+
warning ("%s %s %f", update_type.to_string (), action.to_string (), progress);
144148

145-
var duration = Utils.get_animation_duration (200);
146-
save_easing_state ();
147-
set_easing_duration (duration);
148-
opacity = 0;
149-
restore_easing_state ();
149+
workspace_hide_tracker.propagate (update_type, action, progress);
150150

151-
if (duration == 0) {
152-
base.hide ();
153-
} else {
154-
ulong completed_id = 0;
155-
completed_id = transitions_completed.connect (() => {
156-
disconnect (completed_id);
157-
base.hide ();
158-
});
151+
if (action != CUSTOM || update_type == COMMIT) {
152+
return;
159153
}
154+
155+
// warning ("Setting progress to %f", progress);
156+
property_target.propagate (UPDATE, CUSTOM, progress);
157+
158+
reactive = update_type == END;
160159
}
161160

162161
public override bool enter_event (Clutter.Event event) {
@@ -199,9 +198,9 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
199198

200199
private Clutter.Actor on_move_begin () {
201200
#if HAS_MUTTER48
202-
display.set_cursor (Meta.Cursor.MOVE);
201+
wm.get_display ().set_cursor (Meta.Cursor.MOVE);
203202
#else
204-
display.set_cursor (Meta.Cursor.DND_IN_DRAG);
203+
wm.get_display ().set_cursor (Meta.Cursor.DND_IN_DRAG);
205204
#endif
206205

207206
return this;
@@ -210,7 +209,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
210209
private void on_move_end () {
211210
reactive = true;
212211
update_screen_position ();
213-
display.set_cursor (Meta.Cursor.DEFAULT);
212+
wm.get_display ().set_cursor (Meta.Cursor.DEFAULT);
214213
}
215214

216215
private bool on_resize_button_press (Clutter.Event event) {
@@ -228,7 +227,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
228227
grab = resize_button.get_stage ().grab (resize_button);
229228
resize_button.event.connect (on_resize_event);
230229

231-
display.set_cursor (Meta.Cursor.SE_RESIZE);
230+
wm.get_display ().set_cursor (Meta.Cursor.SE_RESIZE);
232231

233232
return Clutter.EVENT_PROPAGATE;
234233
}
@@ -289,7 +288,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
289288

290289
update_screen_position ();
291290

292-
display.set_cursor (Meta.Cursor.DEFAULT);
291+
wm.get_display ().set_cursor (Meta.Cursor.DEFAULT);
293292
}
294293

295294
private void on_allocation_changed () {
@@ -315,25 +314,14 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
315314
});
316315
}
317316

318-
private void update_window_focus () {
319-
unowned Meta.Window focus_window = display.get_focus_window ();
320-
if ((focus_window != null && !Utils.get_window_is_normal (focus_window))
321-
|| (previous_focus != null && !Utils.get_window_is_normal (previous_focus))) {
322-
previous_focus = focus_window;
323-
return;
324-
}
325-
326-
unowned var workspace_manager = display.get_workspace_manager ();
327-
unowned var active_workspace = workspace_manager.get_active_workspace ();
317+
private double calculate_progress (Meta.Workspace workspace) {
328318
unowned var window = window_actor.get_meta_window ();
329319

330-
if (window.appears_focused && window.located_on_workspace (active_workspace)) {
331-
hide ();
332-
} else if (!window_actor.is_destroyed ()) {
333-
show ();
320+
if (window.has_focus () && window.get_workspace () == workspace) {
321+
return 1.0;
322+
} else {
323+
return 0.0;
334324
}
335-
336-
previous_focus = focus_window;
337325
}
338326

339327
private void update_size () {
@@ -422,7 +410,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
422410
private void place_window_in_screen () {
423411
off_screen = false;
424412

425-
var workarea_rect = display.get_workspace_manager ().get_active_workspace ().get_work_area_all_monitors ();
413+
var workarea_rect = wm.get_display ().get_workspace_manager ().get_active_workspace ().get_work_area_all_monitors ();
426414

427415
var screen_limit_start_x = workarea_rect.x;
428416
var screen_limit_end_x = workarea_rect.x + workarea_rect.width - width;
@@ -448,6 +436,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
448436
set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK);
449437
set_easing_duration (duration);
450438

439+
unowned var display = wm.get_display ();
451440
var monitor_rect = display.get_monitor_geometry (display.get_current_monitor ());
452441

453442
int monitor_x = monitor_rect.x;
@@ -495,6 +484,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
495484
}
496485

497486
private bool coord_is_in_other_monitor (float coord, Clutter.Orientation axis) {
487+
unowned var display = wm.get_display ();
498488
int n_monitors = display.get_n_monitors ();
499489

500490
if (n_monitors == 1) {

src/WindowManager.vala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,14 @@ namespace Gala {
17271727
return modal_stack.peek_head ().filter_action (action);
17281728
}
17291729

1730+
public void add_multitasking_view_target (GestureTarget target) {
1731+
multitasking_view.add_target (target);
1732+
1733+
if (window_overview is WindowOverview) {
1734+
((WindowOverview) window_overview).add_target (target);
1735+
}
1736+
}
1737+
17301738
public override void confirm_display_change () {
17311739
unowned var monitor_manager = get_display ().get_context ().get_backend ().get_monitor_manager ();
17321740
var timeout = monitor_manager.get_display_configuration_timeout ();

0 commit comments

Comments
 (0)