Skip to content

Commit

Permalink
Merge pull request #50 from migueldeoleiros/bugfix/uppercase-keybinds…
Browse files Browse the repository at this point in the history
…-#49

Fix keybinds with shift not working
  • Loading branch information
migueldeoleiros authored Nov 12, 2024
2 parents 7e93853 + de7fe2b commit 72f725a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <string.h>
#include <assert.h>
#include <libconfig.h>
#include <xkbcommon/xkbcommon.h>

// Global configuration instance
static turtile_config_t *config_instance = NULL;
Expand Down Expand Up @@ -79,8 +80,7 @@ void load_keybinds(config_t *cfg, const char *value) {
config_setting_t *mod_setting = config_setting_lookup(keybind_setting, "mod");
uint32_t mods = 0;
if (mod_setting) {
int mod_count = config_setting_length(mod_setting);
for (int j = 0; j < mod_count; j++) {
for (int j = 0; j < config_setting_length(mod_setting); j++) {
const char *mod_str = config_setting_get_string_elem(mod_setting, j);
if (!mod_str) {
wlr_log(WLR_ERROR, "Invalid modifier string in configuration");
Expand All @@ -96,6 +96,8 @@ void load_keybinds(config_t *cfg, const char *value) {
mods |= WLR_MODIFIER_ALT;
} else if (strstr(mod_str, "mod4")) {
mods |= WLR_MODIFIER_LOGO;
} else if (strstr(mod_str, "super")) {
mods |= WLR_MODIFIER_LOGO;
} else if (strstr(mod_str, "mod2")) {
mods |= WLR_MODIFIER_MOD2;
} else {
Expand All @@ -115,7 +117,7 @@ void load_keybinds(config_t *cfg, const char *value) {
}

// Convert key string to keysym
xkb_keysym_t key = xkb_keysym_from_name(key_str, XKB_KEYSYM_CASE_INSENSITIVE);
xkb_keysym_t key = xkb_keysym_from_name(key_str, XKB_KEYSYM_NO_FLAGS);
if (key == XKB_KEY_NoSymbol) {
wlr_log(WLR_ERROR, "Invalid key name '%s' in configuration", key_str);
continue;
Expand Down
5 changes: 2 additions & 3 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ void keyboard_handle_modifiers(
bool handle_keybinding(struct turtile_server *server, uint32_t modifiers,
xkb_keysym_t sym) {
turtile_keybind_t *keybind;
/* wlr_log(WLR_INFO, "key event: %d %d", modifiers, sym); */
wl_list_for_each(keybind, &config_get_instance()->keybinds, link) {
// Check if both the key and the modifiers match
wlr_log(WLR_INFO, "keybind: %d %d", keybind->mods, keybind->key);
wlr_log(WLR_INFO, "mods: %d", modifiers);
wlr_log(WLR_INFO, "key: %d", sym);
/* wlr_log(WLR_INFO, "keybind: %d %d", keybind->mods, keybind->key); */
if ((keybind->mods == modifiers) && (keybind->key == sym)) {
wlr_log(WLR_INFO, "Executing command: %s", keybind->cmd);
if (fork() == 0)
Expand Down
2 changes: 0 additions & 2 deletions src/toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#define TURTILE_TOPLEVEL_H

#include "cursor.h"
#include "src/output.h"
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <uuid/uuid.h>

Expand Down
4 changes: 2 additions & 2 deletions tests/test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ workspaces = (
);

keybinds = (
{mod = ["mod4", "shift"], key = "f3", cmd = "./build/ttcli workspace switch main"},
{mod = ["mod4", "shift"], key = "f4", cmd = "./build/ttcli workspace switch test"}
{mod = ["mod4", "shift"], key = "F3", cmd = "./build/ttcli workspace switch main"},
{mod = ["mod4", "shift"], key = "F4", cmd = "./build/ttcli workspace switch test"}
);

0 comments on commit 72f725a

Please sign in to comment.