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 ) {
0 commit comments