Skip to content

Commit

Permalink
[Gtk4Prep]KeyUtils: Merge into AbstractDirectoryView (#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypw authored Jan 23, 2024
1 parent a918194 commit 2e0aa6c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 81 deletions.
79 changes: 0 additions & 79 deletions src/Utils/KeyUtils.vala

This file was deleted.

56 changes: 55 additions & 1 deletion src/View/AbstractDirectoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3006,7 +3006,7 @@ namespace Files {
cancel_hover ();

Gdk.ModifierType consumed_mods;
var keyval = KeyUtils.map_key (original_keyval, keycode, out consumed_mods);
var keyval = map_key (original_keyval, keycode, out consumed_mods);

var mods = (state & ~consumed_mods) & Gtk.accelerator_get_default_mod_mask ();
bool no_mods = (mods == 0);
Expand Down Expand Up @@ -3997,6 +3997,60 @@ namespace Files {
scroll_to_path (path, scroll_to_top);
}

//TODO Needs complete rewrite for Gtk4 so leaving some direct access of event struct
protected static uint map_key (uint original_keyval, uint keycode, out Gdk.ModifierType consumed_mods) {
uint keyval = original_keyval;
consumed_mods = 0;

if (keyval > 127) {
int eff_grp, level;
var event = (Gdk.EventKey)(Gtk.get_current_event ());
var display = Gtk.get_current_event_device ().get_display ();
var keymap = Gdk.Keymap.get_for_display (display);
if (!keymap.translate_keyboard_state (
event.hardware_keycode,
event.state, event.group,
out keyval, out eff_grp,
out level, out consumed_mods)) {

warning ("translate keyboard state failed");
keyval = original_keyval;
consumed_mods = 0;
} else {
keyval = 0;
for (uint key = 32; key < 128; key++) {
if (match_keycode (keymap, key, event.hardware_keycode, level)) {
keyval = key;
break;
}
}

if (keyval == 0) {
debug ("Could not match hardware code to ASCII hotkey");
keyval = original_keyval;
consumed_mods = 0;
}
}
}

return keyval;
}

/** Returns true if the code parameter matches the keycode of the keyval parameter for
* any keyboard group or level (in order to allow for non-QWERTY keyboards) **/
protected static bool match_keycode (Gdk.Keymap keymap, uint keyval, uint code, int level) {
Gdk.KeymapKey [] keys;
if (keymap.get_entries_for_keyval (keyval, out keys)) {
foreach (var key in keys) {
if (code == key.keycode && level == key.level) {
return true;
}
}
}

return false;
}

/** Abstract methods - must be overridden*/
public abstract GLib.List<Gtk.TreePath> get_selected_paths () ;
public abstract Gtk.TreePath? get_path_at_pos (int x, int win);
Expand Down
1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pantheon_files_exec = executable (
'Utils/MimeActions.vala',
'Utils/Permissions.vala',
'Utils/AppUtils.vala',
'Utils/KeyUtils.vala',

'View/AbstractDirectoryView.vala',
'View/AbstractTreeView.vala',
Expand Down

0 comments on commit 2e0aa6c

Please sign in to comment.