summaryrefslogtreecommitdiff
path: root/src/bindings.c
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2013-11-19 11:37:12 +0100
committerKristian Høgsberg <krh@bitplanet.net>2013-11-19 11:49:25 -0800
commit96d47c0ef7c8fa7824cd0f3bebb7e152bfc06418 (patch)
tree24bf9aa0bfb47aa45830a89b2b55c8f805d6ffd5 /src/bindings.c
parentb482dbd7eb3033e12115047967cbff07ef6e2a96 (diff)
Add modifier-only binding
Add the ability to bind to modifiers; the binding is armed when a key which sets the requested modifier is pressed, and triggered if the key is released with no other keys having been pressed in the meantime, as well as mouse buttons or scroll axes. This only works for direct modifiers (e.g. Shift and Alt), not modifiers which latch or lock. [pochu: rebased]
Diffstat (limited to 'src/bindings.c')
-rw-r--r--src/bindings.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/bindings.c b/src/bindings.c
index 7cbded92..fb758d12 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -76,6 +76,24 @@ weston_compositor_add_key_binding(struct weston_compositor *compositor,
}
WL_EXPORT struct weston_binding *
+weston_compositor_add_modifier_binding(struct weston_compositor *compositor,
+ uint32_t modifier,
+ weston_modifier_binding_handler_t handler,
+ void *data)
+{
+ struct weston_binding *binding;
+
+ binding = weston_compositor_add_binding(compositor, 0, 0, 0,
+ modifier, handler, data);
+ if (binding == NULL)
+ return NULL;
+
+ wl_list_insert(compositor->modifier_binding_list.prev, &binding->link);
+
+ return binding;
+}
+
+WL_EXPORT struct weston_binding *
weston_compositor_add_button_binding(struct weston_compositor *compositor,
uint32_t button, uint32_t modifier,
weston_button_binding_handler_t handler,
@@ -248,6 +266,10 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return;
+ /* Invalidate all active modifier bindings. */
+ wl_list_for_each(b, &compositor->modifier_binding_list, link)
+ b->key = key;
+
wl_list_for_each(b, &compositor->key_binding_list, link) {
if (b->key == key && b->modifier == seat->modifier_state) {
weston_key_binding_handler_t handler = b->handler;
@@ -264,6 +286,34 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
}
WL_EXPORT void
+weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
+ struct weston_seat *seat,
+ enum weston_keyboard_modifier modifier,
+ enum wl_keyboard_key_state state)
+{
+ struct weston_binding *b;
+
+ wl_list_for_each(b, &compositor->modifier_binding_list, link) {
+ weston_modifier_binding_handler_t handler = b->handler;
+
+ if (b->modifier != modifier)
+ continue;
+
+ /* Prime the modifier binding. */
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
+ b->key = 0;
+ continue;
+ }
+ /* Ignore the binding if a key was pressed in between. */
+ else if (b->key != 0) {
+ return;
+ }
+
+ handler(seat, modifier, b->data);
+ }
+}
+
+WL_EXPORT void
weston_compositor_run_button_binding(struct weston_compositor *compositor,
struct weston_seat *seat,
uint32_t time, uint32_t button,
@@ -274,6 +324,10 @@ weston_compositor_run_button_binding(struct weston_compositor *compositor,
if (state == WL_POINTER_BUTTON_STATE_RELEASED)
return;
+ /* Invalidate all active modifier bindings. */
+ wl_list_for_each(b, &compositor->modifier_binding_list, link)
+ b->key = button;
+
wl_list_for_each(b, &compositor->button_binding_list, link) {
if (b->button == button && b->modifier == seat->modifier_state) {
weston_button_binding_handler_t handler = b->handler;
@@ -308,6 +362,10 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
{
struct weston_binding *b;
+ /* Invalidate all active modifier bindings. */
+ wl_list_for_each(b, &compositor->modifier_binding_list, link)
+ b->key = axis;
+
wl_list_for_each(b, &compositor->axis_binding_list, link) {
if (b->axis == axis && b->modifier == seat->modifier_state) {
weston_axis_binding_handler_t handler = b->handler;