Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ namespace Scratch {
plugins = new Scratch.Services.PluginsManager (this);

key_controller = new Gtk.EventControllerKey (this) {
propagation_phase = CAPTURE
propagation_phase = TARGET
};
key_controller.key_pressed.connect (on_key_pressed);

Expand Down
41 changes: 40 additions & 1 deletion src/Widgets/Terminal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Code.Terminal : Gtk.Box {
private const string SETTINGS_SCHEMA = "io.elementary.terminal.settings";

public Vte.Terminal terminal { get; construct; }
private Gtk.EventControllerKey key_controller;
private Settings pantheon_terminal_settings;

public SimpleActionGroup actions { get; construct; }

private GLib.Pid child_pid;
Expand Down Expand Up @@ -63,6 +66,11 @@ public class Code.Terminal : Gtk.Box {
menu.insert_action_group (ACTION_GROUP, actions);
menu.show_all ();

key_controller = new Gtk.EventControllerKey (terminal) {
propagation_phase = BUBBLE
};
key_controller.key_pressed.connect (key_pressed);

terminal.button_press_event.connect ((event) => {
if (event.button == 3) {
paste_action.set_enabled (current_clipboard.wait_is_text_available ());
Expand Down Expand Up @@ -130,7 +138,7 @@ public class Code.Terminal : Gtk.Box {
}

private void update_terminal_settings (string settings_schema) {
var pantheon_terminal_settings = new GLib.Settings (settings_schema);
pantheon_terminal_settings = new GLib.Settings (settings_schema);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this key comes from another app, we should really check and make sure it exists before reading from it so we don't introduce a new crash

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but pantheon_terminal_settings is already being used at several other places unrelated to this PR (getting "font", "audible-bell", "cursor-shape", "background", "foreground" and "palette" keys) so maybe dealing with the case that the Terminal schema has been uninstalled can be left to a separate PR covering all these cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair!


var font_name = pantheon_terminal_settings.get_string ("font");
if (font_name == "") {
Expand Down Expand Up @@ -207,4 +215,35 @@ public class Code.Terminal : Gtk.Box {
public void set_default_font_size () {
terminal.font_scale = 1.0;
}

private bool key_pressed (uint keyval, uint keycode, Gdk.ModifierType modifiers) {
// Use hardware keycodes so the key used is unaffected by internationalized layout
bool match_keycode (uint keyval, uint code) {
Gdk.KeymapKey[] keys;

var keymap = Gdk.Keymap.get_for_display (get_display ());
if (keymap.get_entries_for_keyval (keyval, out keys)) {
foreach (var key in keys) {
if (code == key.keycode) {
return Gdk.EVENT_STOP;
}
}
}

return Gdk.EVENT_PROPAGATE;
}

if (CONTROL_MASK in modifiers && pantheon_terminal_settings.get_boolean ("natural-copy-paste")) {
if (match_keycode (Gdk.Key.c, keycode)) {
actions.activate_action (ACTION_COPY, null);
return Gdk.EVENT_STOP;
} else if (match_keycode (Gdk.Key.v, keycode)) {
actions.activate_action (ACTION_PASTE, null);
return Gdk.EVENT_STOP;
}
}


return Gdk.EVENT_PROPAGATE;
}
}