[PATCH 2/2] compositor: add a way to change the keyboard leds
Giulio Camuffo
giuliocamuffo at gmail.com
Tue Aug 19 11:25:21 PDT 2014
This adds a function weston_keyboard_set_leds() which can be used
to change the state of the num lock and the caps lock leds.
Only the evdev backend supports this, since it doesn't make sense
for embedded sessions.
---
src/compositor.h | 3 +++
src/input.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/src/compositor.h b/src/compositor.h
index c0fc0a6..0c5c98a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -393,6 +393,9 @@ weston_keyboard_start_grab(struct weston_keyboard *device,
struct weston_keyboard_grab *grab);
void
weston_keyboard_end_grab(struct weston_keyboard *keyboard);
+int
+weston_keyboard_set_leds(struct weston_keyboard *keyboard,
+ enum weston_led leds, enum weston_led active);
struct weston_touch *
weston_touch_create(void);
diff --git a/src/input.c b/src/input.c
index 1ab55ce..d0637b8 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1064,6 +1064,49 @@ notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
value);
}
+WL_EXPORT int
+weston_keyboard_set_leds(struct weston_keyboard *keyboard,
+ enum weston_led leds, enum weston_led active)
+{
+ /* We don't want the leds to go out of sync with the actual state
+ * so if the backend has no way to change the leds don't try to
+ * change the state */
+ if (!keyboard->seat->led_update)
+ return -1;
+
+ uint32_t mods_depressed, mods_latched, mods_locked, group;
+ uint32_t serial;
+ int num, caps;
+ mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state,
+ XKB_STATE_DEPRESSED);
+ mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state,
+ XKB_STATE_LATCHED);
+ mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state,
+ XKB_STATE_LOCKED);
+ group = xkb_state_serialize_group(keyboard->xkb_state.state,
+ XKB_STATE_EFFECTIVE);
+
+ num = (1 << keyboard->xkb_info->mod2_mod);
+ caps = (1 << keyboard->xkb_info->caps_mod);
+ if (leds & LED_NUM_LOCK)
+ mods_locked = (active & LED_NUM_LOCK) ? mods_locked | num
+ : mods_locked & ~num;
+ if (leds & LED_CAPS_LOCK)
+ mods_locked = (active & LED_CAPS_LOCK) ? mods_locked | caps
+ : mods_locked & ~caps;
+ if (leds & LED_SCROLL_LOCK)
+ weston_log("Changing the LED_SCROLL_LOCK value is not supported.");
+
+ xkb_state_update_mask(keyboard->xkb_state.state, mods_depressed,
+ mods_latched, mods_locked, 0, 0, group);
+
+ serial = wl_display_next_serial(
+ keyboard->seat->compositor->wl_display);
+ notify_modifiers(keyboard->seat, serial);
+
+ return 0;
+}
+
#ifdef ENABLE_XKBCOMMON
WL_EXPORT void
notify_modifiers(struct weston_seat *seat, uint32_t serial)
--
2.0.4
More information about the wayland-devel
mailing list