From 60861a4c701d6318fcbed428988cf06f08c2b936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 21 Apr 2022 22:28:36 +0000 Subject: [PATCH] Update to latest mutter bindings and use Transition objects (#1406) This allows for a better transition handling than setting properties. --- src/ScreenshotManager.vala | 2 +- src/Widgets/DwellClickTimer.vala | 2 +- src/Widgets/PointerLocator.vala | 67 +++++++++++++++----------------- vapi/libmutter.vapi | 40 +++++++++---------- 4 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/ScreenshotManager.vala b/src/ScreenshotManager.vala index 388fee1a8..19f294cd8 100644 --- a/src/ScreenshotManager.vala +++ b/src/ScreenshotManager.vala @@ -418,7 +418,7 @@ namespace Gala { unowned Meta.CursorTracker cursor_tracker = wm.get_display ().get_cursor_tracker (); Graphene.Point coords = {}; #if HAS_MUTTER40 - cursor_tracker.get_pointer (coords, null); + cursor_tracker.get_pointer (out coords, null); #else cursor_tracker.get_pointer (out coords.x, out coords.y, null); #endif diff --git a/src/Widgets/DwellClickTimer.vala b/src/Widgets/DwellClickTimer.vala index 8100295c9..ec64ca833 100644 --- a/src/Widgets/DwellClickTimer.vala +++ b/src/Widgets/DwellClickTimer.vala @@ -75,7 +75,7 @@ namespace Gala { var tracker = wm.get_display ().get_cursor_tracker (); Graphene.Point coords = {}; #if HAS_MUTTER40 - tracker.get_pointer (coords, null); + tracker.get_pointer (out coords, null); #else tracker.get_pointer (out coords.x, out coords.y, null); #endif diff --git a/src/Widgets/PointerLocator.vala b/src/Widgets/PointerLocator.vala index f7e508a90..77efef132 100644 --- a/src/Widgets/PointerLocator.vala +++ b/src/Widgets/PointerLocator.vala @@ -37,8 +37,6 @@ namespace Gala { private Cairo.Pattern stroke_color; private Cairo.Pattern fill_color; - private uint timeout_id; - public PointerLocator (WindowManager wm) { Object (wm: wm); } @@ -53,6 +51,10 @@ namespace Gala { update_surface (); set_size (WIDTH_PX * scaling_factor, HEIGHT_PX * scaling_factor); + var pivot = Graphene.Point (); + pivot.init (0.5f, 0.5f); + pivot_point = pivot; + Meta.MonitorManager.@get ().monitors_changed.connect (update_surface); } @@ -114,23 +116,41 @@ namespace Gala { return; } + unowned var old_transition = get_transition ("circle"); + if (old_transition != null) { + old_transition.stop (); + } + + var transition = new Clutter.TransitionGroup (); + transition.remove_on_complete = true; + var transition_x = new Clutter.PropertyTransition ("scale-x"); + var transition_y = new Clutter.PropertyTransition ("scale-y"); + var start_val = Value (typeof (double)); + start_val.set_double (1); + var stop_val = Value (typeof (double)); + stop_val.set_double (0); + transition_x.set_from_value (start_val); + transition_y.set_from_value (start_val); + transition_x.set_to_value (stop_val); + transition_y.set_to_value (stop_val); + transition.progress_mode = Clutter.AnimationMode.EASE_OUT_QUAD; + transition.duration = ANIMATION_TIME_MS; + transition.add_transition (transition_x); + transition.add_transition (transition_y); + transition.stopped.connect (() => { visible = false; }); + transition.started.connect (() => { visible = true; }); + add_transition ("circle", transition); + var rgba = InternalUtils.get_theme_accent_color (); /* Don't use alpha from the stylesheet to ensure contrast */ stroke_color = new Cairo.Pattern.rgb (rgba.red, rgba.green, rgba.blue); fill_color = new Cairo.Pattern.rgba (rgba.red, rgba.green, rgba.blue, BACKGROUND_OPACITY); - if (timeout_id != 0) { - GLib.Source.remove (timeout_id); - timeout_id = 0; - visible = false; - restore_easing_state (); - } - - var tracker = wm.get_display ().get_cursor_tracker (); + unowned var tracker = wm.get_display ().get_cursor_tracker (); Graphene.Point coords = {}; #if HAS_MUTTER40 - tracker.get_pointer (coords, null); + tracker.get_pointer (out coords, null); #else tracker.get_pointer (out coords.x, out coords.y, null); #endif @@ -138,30 +158,7 @@ namespace Gala { x = coords.x - (width / 2); y = coords.y - (width / 2); - var pivot = Graphene.Point (); - pivot.x = 0.5f; - pivot.y = 0.5f; - pivot_point = pivot; - - scale_x = 1; - scale_y = 1; - - visible = true; - - save_easing_state (); - set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD); - set_easing_duration (ANIMATION_TIME_MS); - - timeout_id = Timeout.add (ANIMATION_TIME_MS, () => { - timeout_id = 0; - - restore_easing_state (); - - return GLib.Source.REMOVE; - }); - - scale_x = 0; - scale_y = 0; + transition.start (); } } } diff --git a/vapi/libmutter.vapi b/vapi/libmutter.vapi index 619476858..5edcddb19 100644 --- a/vapi/libmutter.vapi +++ b/vapi/libmutter.vapi @@ -383,7 +383,7 @@ namespace Meta { protected CursorTracker (); public void get_hot (out int x, out int y); #if HAS_MUTTER40 - public void get_pointer (Graphene.Point coords, out Clutter.ModifierType mods); + public void get_pointer (out Graphene.Point coords, out Clutter.ModifierType mods); #else public void get_pointer (out int x, out int y, out Clutter.ModifierType mods); #endif @@ -789,19 +789,19 @@ namespace Meta { public unowned GLib.SList get_sequences (); [NoAccessorMethod] public Meta.Display display { owned get; construct; } - public signal void changed ([CCode (type = "gpointer")] Meta.StartupSequence object); + public signal void changed (Meta.StartupSequence object); } [CCode (cheader_filename = "meta/meta-startup-notification.h", type_id = "meta_startup_sequence_get_type ()")] public class StartupSequence : GLib.Object { [CCode (has_construct_function = false)] protected StartupSequence (); - public unowned string get_application_id (); + public unowned string? get_application_id (); public bool get_completed (); - public unowned string get_icon_name (); + public unowned string? get_icon_name (); public unowned string get_id (); public unowned string get_name (); public uint64 get_timestamp (); - public unowned string get_wmclass (); + public unowned string? get_wmclass (); public int get_workspace (); public string application_id { get; construct; } public string icon_name { get; construct; } @@ -862,7 +862,7 @@ namespace Meta { public void foreach_transient (Meta.WindowForeachFunc func); public Meta.Rectangle frame_rect_to_client_rect (Meta.Rectangle frame_rect); public Meta.Rectangle get_buffer_rect (); - public unowned string get_client_machine (); + public unowned string? get_client_machine (); public Meta.WindowClientType get_client_type (); public unowned GLib.Object get_compositor_private (); public unowned string get_description (); @@ -871,32 +871,32 @@ namespace Meta { public unowned Cairo.Region? get_frame_bounds (); public Meta.Rectangle get_frame_rect (); public Meta.FrameType get_frame_type (); - public unowned Meta.Group get_group (); - public unowned string get_gtk_app_menu_object_path (); - public unowned string get_gtk_application_id (); - public unowned string get_gtk_application_object_path (); - public unowned string get_gtk_menubar_object_path (); - public unowned string get_gtk_theme_variant (); - public unowned string get_gtk_unique_bus_name (); - public unowned string get_gtk_window_object_path (); + public unowned Meta.Group? get_group (); + public unowned string? get_gtk_app_menu_object_path (); + public unowned string? get_gtk_application_id (); + public unowned string? get_gtk_application_object_path (); + public unowned string? get_gtk_menubar_object_path (); + public unowned string? get_gtk_theme_variant (); + public unowned string? get_gtk_unique_bus_name (); + public unowned string? get_gtk_window_object_path (); public bool get_icon_geometry (out Meta.Rectangle rect); public uint64 get_id (); public Meta.StackLayer get_layer (); public Meta.MaximizeFlags get_maximized (); public int get_monitor (); - public unowned string get_mutter_hints (); + public unowned string? get_mutter_hints (); public int get_pid (); public unowned string get_role (); - public unowned string get_sandboxed_app_id (); + public unowned string? get_sandboxed_app_id (); public uint get_stable_sequence (); - public unowned string get_startup_id (); + public unowned string? get_startup_id (); public unowned Meta.Window? get_tile_match (); public unowned string get_title (); - public unowned Meta.Window get_transient_for (); + public unowned Meta.Window? get_transient_for (); public uint32 get_user_time (); public Meta.WindowType get_window_type (); - public unowned string get_wm_class (); - public unowned string get_wm_class_instance (); + public unowned string? get_wm_class (); + public unowned string? get_wm_class_instance (); public Meta.Rectangle get_work_area_all_monitors (); public Meta.Rectangle get_work_area_current_monitor (); public Meta.Rectangle get_work_area_for_monitor (int which_monitor);