From 12bb4c9566689b85048b6969624fa1c9f2426a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 19 Oct 2023 15:22:14 -0700 Subject: [PATCH 1/2] WallpaperContainer: Use gesture for secondary click --- src/Widgets/WallpaperContainer.vala | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Widgets/WallpaperContainer.vala b/src/Widgets/WallpaperContainer.vala index ee7d6192c..9a6d6376e 100644 --- a/src/Widgets/WallpaperContainer.vala +++ b/src/Widgets/WallpaperContainer.vala @@ -25,7 +25,6 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { private const int THUMB_HEIGHT = 100; private Gtk.Grid card_box; - private Gtk.Menu context_menu; private Gtk.Revealer check_revealer; private Granite.AsyncImage image; @@ -35,6 +34,8 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { public Gdk.Pixbuf thumb { get; set; } public uint64 creation_date = 0; + private Gtk.GestureMultiPress secondary_click_gesture; + private int scale; public bool checked { @@ -109,13 +110,11 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { overlay.add (card_box); overlay.add_overlay (check_revealer); - var event_box = new Gtk.EventBox (); - event_box.add (overlay); - halign = Gtk.Align.CENTER; valign = Gtk.Align.CENTER; margin = 6; - add (event_box); + + child = overlay; if (uri != null) { var move_to_trash = new Gtk.MenuItem.with_label (_("Remove")); @@ -130,17 +129,21 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { critical (e.message); } - context_menu = new Gtk.Menu (); + var context_menu = new Gtk.Menu (); context_menu.append (move_to_trash); context_menu.show_all (); + + secondary_click_gesture = new Gtk.GestureMultiPress (overlay) { + button = Gdk.BUTTON_SECONDARY + }; + secondary_click_gesture.released.connect (() => { + context_menu.popup_at_pointer (null); + }); } activate.connect (() => { checked = true; }); - - event_box.button_press_event.connect (show_context_menu); - try { if (uri != null) { if (thumb_path != null && thumb_valid) { @@ -193,14 +196,6 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { } } - private bool show_context_menu (Gtk.Widget sender, Gdk.EventButton evt) { - if (evt.type == Gdk.EventType.BUTTON_PRESS && evt.button == 3) { - context_menu.popup_at_pointer (null); - return Gdk.EVENT_STOP; - } - return Gdk.EVENT_PROPAGATE; - } - private async void update_thumb () { if (thumb_path == null) { return; From 881c3bbfbabc67bfd649749f67348cec738a618b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 19 Oct 2023 16:11:41 -0700 Subject: [PATCH 2/2] Use GLib.Menu --- src/Widgets/WallpaperContainer.vala | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Widgets/WallpaperContainer.vala b/src/Widgets/WallpaperContainer.vala index 9a6d6376e..1c333aa92 100644 --- a/src/Widgets/WallpaperContainer.vala +++ b/src/Widgets/WallpaperContainer.vala @@ -117,20 +117,29 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { child = overlay; if (uri != null) { - var move_to_trash = new Gtk.MenuItem.with_label (_("Remove")); - move_to_trash.activate.connect (() => trash ()); + var remove_wallpaper_action = new SimpleAction ("trash", null); + remove_wallpaper_action.activate.connect (() => trash ()); + + var action_group = new SimpleActionGroup (); + action_group.add_action (remove_wallpaper_action); + + insert_action_group ("wallpaper", action_group); var file = File.new_for_uri (uri); try { var info = file.query_info ("*", FileQueryInfoFlags.NONE); creation_date = info.get_attribute_uint64 (GLib.FileAttribute.TIME_CREATED); - move_to_trash.sensitive = info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE); + remove_wallpaper_action.set_enabled (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE)); } catch (Error e) { critical (e.message); } - var context_menu = new Gtk.Menu (); - context_menu.append (move_to_trash); + var menu_model = new Menu (); + menu_model.append (_("Remove"), "wallpaper.trash"); + + var context_menu = new Gtk.Menu.from_model (menu_model) { + attach_widget = this + }; context_menu.show_all (); secondary_click_gesture = new Gtk.GestureMultiPress (overlay) {