@@ -16,6 +16,9 @@ public class Code.Terminal : Gtk.Box {
1616 private const string SETTINGS_SCHEMA = " io.elementary.terminal.settings" ;
1717
1818 public Vte . Terminal terminal { get ; construct; }
19+ private Gtk . EventControllerKey key_controller;
20+ private Settings pantheon_terminal_settings;
21+
1922 public SimpleActionGroup actions { get ; construct; }
2023
2124 private GLib . Pid child_pid;
@@ -63,6 +66,11 @@ public class Code.Terminal : Gtk.Box {
6366 menu. insert_action_group (ACTION_GROUP , actions);
6467 menu. show_all ();
6568
69+ key_controller = new Gtk .EventControllerKey (terminal) {
70+ propagation_phase = BUBBLE
71+ };
72+ key_controller. key_pressed. connect (key_pressed);
73+
6674 terminal. button_press_event. connect ((event) = > {
6775 if (event. button == 3 ) {
6876 paste_action. set_enabled (current_clipboard. wait_is_text_available ());
@@ -130,7 +138,7 @@ public class Code.Terminal : Gtk.Box {
130138 }
131139
132140 private void update_terminal_settings (string settings_schema ) {
133- var pantheon_terminal_settings = new GLib .Settings (settings_schema);
141+ pantheon_terminal_settings = new GLib .Settings (settings_schema);
134142
135143 var font_name = pantheon_terminal_settings. get_string (" font" );
136144 if (font_name == " " ) {
@@ -207,4 +215,35 @@ public class Code.Terminal : Gtk.Box {
207215 public void set_default_font_size () {
208216 terminal. font_scale = 1.0 ;
209217 }
218+
219+ private bool key_pressed (uint keyval , uint keycode , Gdk .ModifierType modifiers ) {
220+ // Use hardware keycodes so the key used is unaffected by internationalized layout
221+ bool match_keycode (uint keyval, uint code) {
222+ Gdk . KeymapKey [] keys;
223+
224+ var keymap = Gdk . Keymap . get_for_display (get_display ());
225+ if (keymap. get_entries_for_keyval (keyval, out keys)) {
226+ foreach (var key in keys) {
227+ if (code == key. keycode) {
228+ return Gdk . EVENT_STOP ;
229+ }
230+ }
231+ }
232+
233+ return Gdk . EVENT_PROPAGATE ;
234+ }
235+
236+ if (CONTROL_MASK in modifiers && pantheon_terminal_settings. get_boolean (" natural-copy-paste" )) {
237+ if (match_keycode (Gdk . Key . c, keycode)) {
238+ actions. activate_action (ACTION_COPY , null );
239+ return Gdk . EVENT_STOP ;
240+ } else if (match_keycode (Gdk . Key . v, keycode)) {
241+ actions. activate_action (ACTION_PASTE , null );
242+ return Gdk . EVENT_STOP ;
243+ }
244+ }
245+
246+
247+ return Gdk . EVENT_PROPAGATE ;
248+ }
210249}
0 commit comments