diff --git a/plugins/pip/Main.vala b/plugins/pip/Main.vala index c5976e7e2..b0fedd1ff 100644 --- a/plugins/pip/Main.vala +++ b/plugins/pip/Main.vala @@ -97,33 +97,31 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin { return; } - var popup_window = new PopupWindow (wm.get_display (), active); + var popup_window = new PopupWindow (wm, active); popup_window.set_container_clip (rect); - popup_window.show.connect (on_popup_window_show); - popup_window.hide.connect (on_popup_window_hide); add_window (popup_window); } - private void on_popup_window_show (Clutter.Actor popup_window) { - track_actor (popup_window); - update_region (); - } - - private void on_popup_window_hide (Clutter.Actor popup_window) { - untrack_actor (popup_window); - update_region (); - } - private void select_window_at (int x, int y) { var selected = get_window_actor_at (x, y); if (selected != null) { - var popup_window = new PopupWindow (wm.get_display (), selected); - popup_window.show.connect (on_popup_window_show); - popup_window.hide.connect (on_popup_window_hide); + var popup_window = new PopupWindow (wm, selected); add_window (popup_window); } } + private void popup_window_reactive_changed (GLib.Object obj, GLib.ParamSpec pspec) requires (obj is PopupWindow) { + var popup_window = (PopupWindow) obj; + + if (popup_window.reactive) { + track_actor (popup_window); + } else { + untrack_actor (popup_window); + } + + update_region (); + } + private void clear_selection_area () { if (selection_area != null) { untrack_actor (selection_area); @@ -189,6 +187,8 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin { } private void add_window (PopupWindow popup_window) { + track_actor (popup_window); + popup_window.notify["reactive"].connect (popup_window_reactive_changed); popup_window.closed.connect (() => remove_window (popup_window)); windows.add (popup_window); wm.ui_group.add_child (popup_window); diff --git a/plugins/pip/PopupWindow.vala b/plugins/pip/PopupWindow.vala index ebb7f8549..ce0e9cc28 100644 --- a/plugins/pip/PopupWindow.vala +++ b/plugins/pip/PopupWindow.vala @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { +public class Gala.Plugins.PIP.PopupWindow : RootTarget, ActorTarget { private int button_size; private int container_margin; private const uint FADE_OUT_TIMEOUT = 200; @@ -16,7 +16,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { public signal void closed (); - public Meta.Display display { get; construct; } + public WindowManager wm { get; construct; } public Meta.WindowActor window_actor { get; construct; } private Clutter.Clone clone; // clone itself @@ -26,6 +26,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { private Gala.CloseButton close_button; private Clutter.Actor resize_button; private DragDropAction move_action; + private GestureController gesture_controller; private float begin_resize_width = 0.0f; private float begin_resize_height = 0.0f; @@ -46,11 +47,13 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { height = src_height * ratio; } - public PopupWindow (Meta.Display display, Meta.WindowActor window_actor) { - Object (display: display, window_actor: window_actor); + public PopupWindow (WindowManager wm, Meta.WindowActor window_actor) { + Object (wm: wm, window_actor: window_actor); } construct { + unowned var display = wm.get_display (); + var scale = display.get_monitor_scale (display.get_current_monitor ()); button_size = Gala.Utils.scale_to_int (36, scale); @@ -127,37 +130,28 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { unowned var workspace_manager = display.get_workspace_manager (); workspace_manager.active_workspace_changed.connect (update_window_focus); - } - - public override void show () { - base.show (); - - opacity = 0; - save_easing_state (); - set_easing_duration (Utils.get_animation_duration (200)); - opacity = 255; - restore_easing_state (); + gesture_controller = new GestureController (CUSTOM, wm); + add_gesture_controller (gesture_controller); + add_target (new PropertyTarget (CUSTOM, this, "opacity", typeof (uint), 255u, 0u)); } - public override void hide () { - opacity = 255; + public override void start_progress (GestureAction action) { + if (action != CUSTOM) { + return; + } - var duration = Utils.get_animation_duration (200); - save_easing_state (); - set_easing_duration (duration); - opacity = 0; - restore_easing_state (); + reactive = false; + visible = true; + } - if (duration == 0) { - base.hide (); - } else { - ulong completed_id = 0; - completed_id = transitions_completed.connect (() => { - disconnect (completed_id); - base.hide (); - }); + public override void end_progress (GestureAction action) { + if (action != CUSTOM) { + return; } + + reactive = true; + visible = get_current_progress (CUSTOM) < 0.5; } public override bool enter_event (Clutter.Event event) { @@ -200,9 +194,9 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { private Clutter.Actor on_move_begin () { #if HAS_MUTTER48 - display.set_cursor (Meta.Cursor.MOVE); + wm.get_display ().set_cursor (Meta.Cursor.MOVE); #else - display.set_cursor (Meta.Cursor.DND_IN_DRAG); + wm.get_display ().set_cursor (Meta.Cursor.DND_IN_DRAG); #endif return this; @@ -211,7 +205,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { private void on_move_end () { reactive = true; update_screen_position (); - display.set_cursor (Meta.Cursor.DEFAULT); + wm.get_display ().set_cursor (Meta.Cursor.DEFAULT); } private bool on_resize_button_press (Clutter.Event event) { @@ -229,7 +223,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { grab = resize_button.get_stage ().grab (resize_button); resize_button.event.connect (on_resize_event); - display.set_cursor (Meta.Cursor.SE_RESIZE); + wm.get_display ().set_cursor (Meta.Cursor.SE_RESIZE); return Clutter.EVENT_PROPAGATE; } @@ -290,7 +284,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { update_screen_position (); - display.set_cursor (Meta.Cursor.DEFAULT); + wm.get_display ().set_cursor (Meta.Cursor.DEFAULT); } private void on_allocation_changed () { @@ -317,6 +311,8 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { } private void update_window_focus () { + unowned var display = wm.get_display (); + unowned Meta.Window focus_window = display.get_focus_window (); if ((focus_window != null && !Utils.get_window_is_normal (focus_window)) || (previous_focus != null && !Utils.get_window_is_normal (previous_focus))) { @@ -329,9 +325,9 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { unowned var window = window_actor.get_meta_window (); if (window.appears_focused && window.located_on_workspace (active_workspace)) { - hide (); + gesture_controller.goto (1.0); } else if (!window_actor.is_destroyed ()) { - show (); + gesture_controller.goto (0.0); } previous_focus = focus_window; @@ -423,7 +419,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { private void place_window_in_screen () { off_screen = false; - var workarea_rect = display.get_workspace_manager ().get_active_workspace ().get_work_area_all_monitors (); + var workarea_rect = wm.get_display ().get_workspace_manager ().get_active_workspace ().get_work_area_all_monitors (); var screen_limit_start_x = workarea_rect.x + SCREEN_MARGIN; var screen_limit_end_x = workarea_rect.x + workarea_rect.width - SCREEN_MARGIN - width; @@ -449,6 +445,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK); set_easing_duration (duration); + unowned var display = wm.get_display (); var monitor_rect = display.get_monitor_geometry (display.get_current_monitor ()); int monitor_x = monitor_rect.x; @@ -496,6 +493,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor { } private bool coord_is_in_other_monitor (float coord, Clutter.Orientation axis) { + unowned var display = wm.get_display (); int n_monitors = display.get_n_monitors (); if (n_monitors == 1) {