Commit 71106a75 authored by sichem's avatar sichem

input: add general input hooks

parent 182d3771
Pipeline #13976 passed with stage
in 3 minutes
......@@ -82,6 +82,7 @@ weston_compositor_add_key_binding(struct weston_compositor *compositor,
return binding;
}
WL_EXPORT struct weston_binding *
weston_compositor_add_modifier_binding(struct weston_compositor *compositor,
uint32_t modifier,
......@@ -300,6 +301,16 @@ weston_compositor_run_key_binding(struct weston_compositor *compositor,
wl_list_for_each(b, &compositor->modifier_binding_list, link)
b->key = key;
if (compositor->key_listener.notify &&
compositor->key_listener.notify(keyboard, time, key,
compositor->key_listener.data) &&
keyboard->grab == &keyboard->default_grab) {
install_binding_grab(keyboard,
time,
key,
keyboard->focus);
}
wl_list_for_each_safe(b, tmp, &compositor->key_binding_list, link) {
if (b->key == key && b->modifier == seat->modifier_state) {
weston_key_binding_handler_t handler = b->handler;
......@@ -330,6 +341,12 @@ weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
if (keyboard->grab != &keyboard->default_grab)
return;
if (state == WL_KEYBOARD_KEY_STATE_PRESSED &&
compositor->modifier_listener.notify)
compositor->modifier_listener.notify(
keyboard, modifier,
compositor->modifier_listener.data);
wl_list_for_each_safe(b, tmp, &compositor->modifier_binding_list, link) {
weston_modifier_binding_handler_t handler = b->handler;
......@@ -362,6 +379,11 @@ weston_compositor_run_button_binding(struct weston_compositor *compositor,
if (state == WL_POINTER_BUTTON_STATE_RELEASED)
return;
if (compositor->button_listener.notify)
compositor->button_listener.notify(
pointer, time, button,
compositor->button_listener.data);
/* Invalidate all active modifier bindings. */
wl_list_for_each(b, &compositor->modifier_binding_list, link)
b->key = button;
......@@ -386,6 +408,11 @@ weston_compositor_run_touch_binding(struct weston_compositor *compositor,
if (touch->num_tp != 1 || touch_type != WL_TOUCH_DOWN)
return;
if (compositor->touch_listener.notify)
compositor->touch_listener.notify(
touch, time,
compositor->touch_listener.data);
wl_list_for_each_safe(b, tmp, &compositor->touch_binding_list, link) {
if (b->modifier == touch->seat->modifier_state) {
weston_touch_binding_handler_t handler = b->handler;
......@@ -406,6 +433,11 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
wl_list_for_each(b, &compositor->modifier_binding_list, link)
b->key = event->axis;
if (compositor->axis_listener.notify)
compositor->axis_listener.notify(
pointer, time, event,
compositor->axis_listener.data);
wl_list_for_each_safe(b, tmp, &compositor->axis_binding_list, link) {
if (b->axis == event->axis &&
b->modifier == pointer->seat->modifier_state) {
......
......@@ -769,6 +769,41 @@ struct weston_keyboard {
struct wl_list timestamps_list;
};
struct weston_key_listener {
bool (*notify)(struct weston_keyboard *keyboard,
const struct timespec *time, uint32_t key,
void *data);
void *data;
};
struct weston_modifier_listener {
bool (*notify)(struct weston_keyboard *keyboard,
enum weston_keyboard_modifier mod,
void *data);
void *data;
};
struct weston_button_listener {
bool (*notify)(struct weston_pointer *pointer,
const struct timespec *time, uint32_t btn, void *data);
void *data;
};
struct weston_axis_listener {
bool (*notify)(struct weston_pointer *touch,
const struct timespec *time,
struct weston_pointer_axis_event *event,
void *data);
void *data;
};
struct weston_touch_listener {
bool (*notify)(struct weston_touch *touch,
const struct timespec *time, void *data);
void *data;
};
struct weston_seat {
struct wl_list base_resource_list;
......@@ -808,7 +843,7 @@ enum {
WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
WESTON_COMPOSITOR_OFFSCREEN, /* no rendering, no frame events */
WESTON_COMPOSITOR_SLEEPING /* same as offscreen, but also set dpms
* to off */
* to off */
};
struct weston_layer_entry {
......@@ -1102,6 +1137,12 @@ struct weston_compositor {
struct wl_list axis_binding_list;
struct wl_list debug_binding_list;
struct weston_key_listener key_listener;
struct weston_modifier_listener modifier_listener;
struct weston_button_listener button_listener;
struct weston_axis_listener axis_listener;
struct weston_touch_listener touch_listener;
uint32_t state;
struct wl_event_source *idle_source;
uint32_t idle_inhibit;
......@@ -1747,8 +1788,8 @@ weston_compositor_add_key_binding(struct weston_compositor *compositor,
void *data);
typedef void (*weston_modifier_binding_handler_t)(struct weston_keyboard *keyboard,
enum weston_keyboard_modifier modifier,
void *data);
enum weston_keyboard_modifier modifier,
void *data);
struct weston_binding *
weston_compositor_add_modifier_binding(struct weston_compositor *compositor,
enum weston_keyboard_modifier modifier,
......@@ -1781,9 +1822,9 @@ typedef void (*weston_axis_binding_handler_t)(struct weston_pointer *pointer,
void *data);
struct weston_binding *
weston_compositor_add_axis_binding(struct weston_compositor *compositor,
uint32_t axis,
enum weston_keyboard_modifier modifier,
weston_axis_binding_handler_t binding,
uint32_t axis,
enum weston_keyboard_modifier modifier,
weston_axis_binding_handler_t binding,
void *data);
struct weston_binding *
weston_compositor_add_debug_binding(struct weston_compositor *compositor,
......@@ -2167,8 +2208,8 @@ weston_transformed_rect(int width, int height,
pixman_box32_t rect);
void
weston_matrix_transform_region(pixman_region32_t *dest,
struct weston_matrix *matrix,
pixman_region32_t *src);
struct weston_matrix *matrix,
pixman_region32_t *src);
void
weston_transformed_region(int width, int height,
enum wl_output_transform transform,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment