From 232dd2f5be2df4236a61b2389e7d8e7f9ed38101 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 19 Jun 2026 10:34:23 +0100 Subject: [PATCH 1/3] Use button controller --- src/Widgets/Terminal.vala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala index 7b445eaab..4cedcf418 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -35,6 +35,7 @@ public class Code.Terminal : Gtk.Box { private GLib.Pid child_pid; private Gtk.Clipboard current_clipboard; + private Gtk.GestureMultiPress secondary_button_controller; private Scratch.Application application; @@ -150,13 +151,14 @@ public class Code.Terminal : Gtk.Box { } }); - terminal.button_press_event.connect ((event) => { - if (event.button == 3) { - paste_action.set_enabled (current_clipboard.wait_is_text_available ()); - menu.select_first (false); - menu.popup_at_pointer (event); - } - return false; + secondary_button_controller = new Gtk.GestureMultiPress (terminal) { + propagation_phase = CAPTURE, + button = Gdk.BUTTON_SECONDARY + }; + secondary_button_controller.pressed.connect ((n, x, y) => { + paste_action.set_enabled (current_clipboard.wait_is_text_available ()); + menu.select_first (false); + menu.popup_at_pointer (secondary_button_controller.get_last_event (null)); }); realize.connect (() => { From bb5934303f34164048ce8419d5cd59b03e4dfefa Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 19 Jun 2026 10:54:58 +0100 Subject: [PATCH 2/3] Gtk.Menu => Gtk.PopoverMenu --- src/Widgets/Terminal.vala | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala index 4cedcf418..a94925454 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -6,7 +6,6 @@ public class Code.Terminal : Gtk.Box { public const string ACTION_GROUP = "term"; - public const string ACTION_PREFIX = ACTION_GROUP + "."; public const string ACTION_COPY = "action-copy"; public const string ACTION_PASTE = "action-paste"; @@ -36,6 +35,7 @@ public class Code.Terminal : Gtk.Box { private GLib.Pid child_pid; private Gtk.Clipboard current_clipboard; private Gtk.GestureMultiPress secondary_button_controller; + private Menu menu_model; private Scratch.Application application; @@ -129,14 +129,17 @@ public class Code.Terminal : Gtk.Box { actions = new SimpleActionGroup (); actions.add_action (copy_action); actions.add_action (paste_action); + terminal.insert_action_group (ACTION_GROUP, actions); - var menu_model = new GLib.Menu (); - menu_model.append (_("Copy"), ACTION_PREFIX + ACTION_COPY); - menu_model.append (_("Paste"), ACTION_PREFIX + ACTION_PASTE); + menu_model = new GLib.Menu (); + menu_model.append (_("Copy"), ACTION_COPY); + menu_model.append (_("Paste"), ACTION_PASTE); - var menu = new Gtk.Menu.from_model (menu_model); - menu.insert_action_group (ACTION_GROUP, actions); - menu.show_all (); + var menu = new Gtk.PopoverMenu () { + modal = true, + relative_to = terminal + }; + menu.bind_model (menu_model, ACTION_GROUP); key_controller = new Gtk.EventControllerKey (terminal) { propagation_phase = BUBBLE @@ -147,7 +150,6 @@ public class Code.Terminal : Gtk.Box { terminal.enter_notify_event.connect (() => { if (!terminal.has_focus) { terminal.grab_focus (); - } }); @@ -157,8 +159,8 @@ public class Code.Terminal : Gtk.Box { }; secondary_button_controller.pressed.connect ((n, x, y) => { paste_action.set_enabled (current_clipboard.wait_is_text_available ()); - menu.select_first (false); - menu.popup_at_pointer (secondary_button_controller.get_last_event (null)); + menu.pointing_to = Gdk.Rectangle () {x = (int)x, y = (int)y, height = 1, width = 1}; + menu.popup (); }); realize.connect (() => { From 3425ede8b7e5c297d8c4a06344777bdcfcee25fd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 19 Jun 2026 11:05:45 +0100 Subject: [PATCH 3/3] Menu on right of pointer --- src/Widgets/Terminal.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala index a94925454..5ad91bec9 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -137,7 +137,8 @@ public class Code.Terminal : Gtk.Box { var menu = new Gtk.PopoverMenu () { modal = true, - relative_to = terminal + relative_to = terminal, + position = RIGHT }; menu.bind_model (menu_model, ACTION_GROUP);