Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage CAPS_LOCK and NUM_LOCK keys #588

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions platform/gtk4/cog-platform-gtk4.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,18 @@ on_scroll(GtkEventControllerScroll* controller, double dx,
return TRUE;
}

static gboolean
is_pressed_key(guint keyval)
Copy link
Member

Choose a reason for hiding this comment

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

Small nit: naming this is_key_pressed() would read more naturally.

{
static bool initialized = false;

if (!initialized) {
GUniqueOutPtr<GdkKeymapKey> keys;
Copy link
Member

Choose a reason for hiding this comment

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

This won't work on a plain C source. It looks like you were picking from C++ code from elsewhere, so this will need adapting to compile as C99.

int entriesCount;
}
return gdk_display_map_keyval(gdk_display_get_default(), keyval, &keys.outPtr(), &entriesCount) && entriesCount;
}

static gboolean
dispatch_key_event(struct platform_window* win, guint keycode, guint hardware_keycode, gboolean pressed, GdkModifierType state)
{
Expand All @@ -351,6 +363,10 @@ dispatch_key_event(struct platform_window* win, guint keycode, guint hardware_ke
modifiers |= wpe_input_keyboard_modifier_alt;
if (state & GDK_SHIFT_MASK)
modifiers |= wpe_input_keyboard_modifier_shift;
if (is_pressed_key(GDK_KEY_Caps_Lock))
modifiers |= wpe_input_keyboard_modifier_capslock;
if (is_pressed_key(GDK_KEY_Num_Lock))
modifiers |= wpe_input_keyboard_modifier_numlock;

struct wpe_input_keyboard_event wpe_event = {
.key_code = keycode,
Expand Down
16 changes: 16 additions & 0 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ static struct {
xkb_mod_index_t control;
xkb_mod_index_t alt;
xkb_mod_index_t shift;
xkb_mod_index_t capslock;
xkb_mod_index_t numlock;
} indexes;
uint8_t modifiers;
} xkb_data = {NULL, };
Expand Down Expand Up @@ -1072,6 +1074,10 @@ keyboard_on_keymap (void *data,
XKB_MOD_NAME_ALT);
xkb_data.indexes.shift = xkb_keymap_mod_get_index (xkb_data.keymap,
XKB_MOD_NAME_SHIFT);
xkb_data.indexes.capslock = xkb_state_led_name_is_active (xkb_data.state,
XKB_LED_NAME_CAPS);
xkb_data.indexes.numlock = xkb_state_led_name_is_active (xkb_data.state,
XKB_LED_NAME_NUM);
}

static void
Expand Down Expand Up @@ -1232,6 +1238,16 @@ keyboard_on_modifiers (void *data,
component)) {
xkb_data.modifiers |= wpe_input_keyboard_modifier_shift;
}
if (xkb_state_mod_index_is_active (xkb_data.state,
xkb_data.indexes.capslock,
component)) {
xkb_data.modifiers |= wpe_input_keyboard_modifier_capslock;
}
if (xkb_state_mod_index_is_active (xkb_data.state,
xkb_data.indexes.numlock,
component)) {
xkb_data.modifiers |= wpe_input_keyboard_modifier_numlock;
}
}

static void
Expand Down
8 changes: 6 additions & 2 deletions platform/x11/cog-platform-x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ xcb_update_xkb_modifiers(uint32_t event_state)
wpe_modifiers |= wpe_input_keyboard_modifier_alt;
}

if (event_state & XCB_MOD_MASK_LOCK)
if (event_state & XCB_MOD_MASK_LOCK) {
locked_mods |= s_display->xkb.caps_lock;
if (event_state & XCB_MOD_MASK_2)
wpe_modifiers |= wpe_input_keyboard_modifier_capslock;
}
if (event_state & XCB_MOD_MASK_2) {
locked_mods |= s_display->xkb.num_lock;
wpe_modifiers |= wpe_input_keyboard_modifier_numlock;
}
xkb_state_update_mask(s_display->xkb.state, depressed_mods, 0, locked_mods, 0, 0, 0);
return wpe_modifiers;
}
Expand Down