[PATCH weston 11/14] Rename modifier_state_changed to notify_modifiers
Daniel Stone
daniel at fooishbar.org
Fri Jun 22 05:21:38 PDT 2012
notify_modifiers will now synchronise Weston's internal state with the
XKB state, and send a modifier event if necessary. This eliminates the
need for update_modifier_state to have a return value at all.
Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
src/compositor.c | 47 ++++++++++++++++++++++++++++-------------------
src/compositor.h | 2 ++
2 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/compositor.c b/src/compositor.c
index 5362a67..b57d10b 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1756,13 +1756,16 @@ notify_axis(struct wl_seat *seat, uint32_t time, uint32_t axis,
value);
}
-static int
-modifier_state_changed(struct weston_seat *seat)
+WL_EXPORT void
+notify_modifiers(struct wl_seat *wl_seat, uint32_t serial)
{
+ struct weston_seat *seat = (struct weston_seat *) wl_seat;
+ struct wl_keyboard *keyboard = &seat->keyboard;
+ struct wl_keyboard_grab *grab = keyboard->grab;
uint32_t mods_depressed, mods_latched, mods_locked, group;
uint32_t mods_lookup;
enum weston_led leds = 0;
- int ret = 0;
+ int changed = 0;
/* Serialize and update our internal state, checking to see if it's
* different to the previous state. */
@@ -1779,7 +1782,7 @@ modifier_state_changed(struct weston_seat *seat)
mods_latched != seat->seat.keyboard->modifiers.mods_latched ||
mods_locked != seat->seat.keyboard->modifiers.mods_locked ||
group != seat->seat.keyboard->modifiers.group)
- ret = 1;
+ changed = 1;
seat->seat.keyboard->modifiers.mods_depressed = mods_depressed;
seat->seat.keyboard->modifiers.mods_latched = mods_latched;
@@ -1810,11 +1813,18 @@ modifier_state_changed(struct weston_seat *seat)
seat->led_update(seat, leds);
seat->xkb_state.leds = leds;
- return ret;
+ if (changed) {
+ grab->interface->modifiers(grab,
+ serial,
+ keyboard->modifiers.mods_depressed,
+ keyboard->modifiers.mods_latched,
+ keyboard->modifiers.mods_locked,
+ keyboard->modifiers.group);
+ }
}
-static int
-update_modifier_state(struct weston_seat *seat, uint32_t key,
+static void
+update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key,
enum wl_keyboard_key_state state)
{
enum xkb_key_direction direction;
@@ -1828,7 +1838,7 @@ update_modifier_state(struct weston_seat *seat, uint32_t key,
* broken keycode system, which starts at 8. */
xkb_state_update_key(seat->xkb_state.state, key + 8, direction);
- return modifier_state_changed(seat);
+ notify_modifiers(&seat->seat, serial);
}
WL_EXPORT void
@@ -1843,7 +1853,6 @@ notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
struct wl_keyboard_grab *grab = seat->keyboard->grab;
uint32_t serial = wl_display_next_serial(compositor->wl_display);
uint32_t *k, *end;
- int mods = 0;
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
if (compositor->ping_handler && focus)
@@ -1856,8 +1865,6 @@ notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
weston_compositor_idle_release(compositor);
}
- if (update_state == STATE_UPDATE_AUTOMATIC)
- mods = update_modifier_state(ws, key, state);
end = seat->keyboard->keys.data + seat->keyboard->keys.size;
for (k = seat->keyboard->keys.data; k < end; k++) {
if (*k == key) {
@@ -1880,13 +1887,13 @@ notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
}
grab->interface->key(grab, time, key, state);
- if (mods)
- grab->interface->modifiers(grab,
- wl_display_get_serial(compositor->wl_display),
- seat->keyboard->modifiers.mods_depressed,
- seat->keyboard->modifiers.mods_latched,
- seat->keyboard->modifiers.mods_locked,
- seat->keyboard->modifiers.group);
+
+ if (update_state == STATE_UPDATE_AUTOMATIC) {
+ update_modifier_state(ws,
+ wl_display_get_serial(compositor->wl_display),
+ key,
+ state);
+ }
}
WL_EXPORT void
@@ -1935,7 +1942,9 @@ notify_keyboard_focus_in(struct wl_seat *seat, struct wl_array *keys,
wl_array_for_each(k, &seat->keyboard->keys) {
weston_compositor_idle_inhibit(compositor);
if (update_state == STATE_UPDATE_AUTOMATIC)
- update_modifier_state(ws, *k,
+ update_modifier_state(ws,
+ wl_display_next_serial(compositor->wl_display),
+ *k,
WL_KEYBOARD_KEY_STATE_PRESSED);
}
diff --git a/src/compositor.h b/src/compositor.h
index 6e981f2..14420c5 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -511,6 +511,8 @@ void
notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
enum wl_keyboard_key_state state,
enum weston_key_state_update update_state);
+void
+notify_modifiers(struct wl_seat *seat, uint32_t serial);
void
notify_pointer_focus(struct wl_seat *seat, struct weston_output *output,
--
1.7.10
More information about the wayland-devel
mailing list