Extend wlsc_binding to cover buttons too

dev
Kristian Høgsberg 14 years ago
parent f512d07e2d
commit a8ec86395d
  1. 121
      compositor/compositor.c
  2. 5
      compositor/compositor.h

@ -1008,33 +1008,28 @@ wlsc_surface_activate(struct wlsc_surface *surface,
time);
}
void
notify_button(struct wl_input_device *device,
uint32_t time, int32_t button, int32_t state)
static void
move_binding(struct wl_input_device *device, uint32_t time,
uint32_t key, uint32_t button, uint32_t state, void *data)
{
struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
struct wlsc_surface *surface;
struct wlsc_compositor *compositor =
(struct wlsc_compositor *) device->compositor;
surface = (struct wlsc_surface *) device->pointer_focus;
uint32_t edges = 0;
int32_t x, y;
if (state && surface && device->grab == NULL) {
wlsc_surface_activate(surface, wd, time);
wl_input_device_start_grab(device,
&device->motion_grab,
button, time);
}
struct wlsc_compositor *compositor = data;
struct wlsc_surface *surface =
(struct wlsc_surface *) device->pointer_focus;
if (state && surface && button == BTN_LEFT &&
(wd->modifier_state & MODIFIER_SUPER))
shell_move(NULL,
(struct wl_shell *) &compositor->shell,
&surface->surface, device, time);
else if (state && surface && button == BTN_MIDDLE &&
(wd->modifier_state & MODIFIER_SUPER)) {
}
static void
resize_binding(struct wl_input_device *device, uint32_t time,
uint32_t key, uint32_t button, uint32_t state, void *data)
{
struct wlsc_compositor *compositor = data;
struct wlsc_surface *surface =
(struct wlsc_surface *) device->pointer_focus;
uint32_t edges = 0;
int32_t x, y;
x = device->grab_x - surface->x;
y = device->grab_y - surface->y;
@ -1056,6 +1051,42 @@ notify_button(struct wl_input_device *device,
shell_resize(NULL,
(struct wl_shell *) &compositor->shell,
&surface->surface, device, time, edges);
}
struct wlsc_binding {
uint32_t key;
uint32_t button;
uint32_t modifier;
wlsc_binding_handler_t handler;
void *data;
struct wl_list link;
};
void
notify_button(struct wl_input_device *device,
uint32_t time, int32_t button, int32_t state)
{
struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
struct wlsc_compositor *compositor =
(struct wlsc_compositor *) device->compositor;
struct wlsc_binding *b;
struct wlsc_surface *surface =
(struct wlsc_surface *) device->pointer_focus;
if (state && surface && device->grab == NULL) {
wlsc_surface_activate(surface, wd, time);
wl_input_device_start_grab(device,
&device->motion_grab,
button, time);
}
wl_list_for_each(b, &compositor->binding_list, link) {
if (b->button == button &&
b->modifier == wd->modifier_state && state) {
b->handler(&wd->input_device,
time, 0, button, state, b->data);
break;
}
}
if (device->grab)
@ -1115,8 +1146,9 @@ wlsc_switcher_destroy(struct wlsc_switcher *switcher)
}
static void
switcher_next_binding(struct wlsc_input_device *device,
uint32_t time, uint32_t key, uint32_t state, void *data)
switcher_next_binding(struct wl_input_device *device, uint32_t time,
uint32_t key, uint32_t button,
uint32_t state, void *data)
{
struct wlsc_compositor *compositor = data;
@ -1131,31 +1163,23 @@ switcher_next_binding(struct wlsc_input_device *device,
}
static void
switcher_terminate_binding(struct wlsc_input_device *device,
uint32_t time, uint32_t key, uint32_t state,
void *data)
switcher_terminate_binding(struct wl_input_device *device,
uint32_t time, uint32_t key, uint32_t button,
uint32_t state, void *data)
{
struct wlsc_compositor *compositor = data;
struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
if (compositor->switcher && !state) {
wlsc_surface_activate(compositor->switcher->current,
device, time);
wlsc_surface_activate(compositor->switcher->current, wd, time);
wlsc_switcher_destroy(compositor->switcher);
compositor->switcher = NULL;
}
}
struct wlsc_binding {
uint32_t key;
uint32_t modifier;
wlsc_binding_handler_t handler;
void *data;
struct wl_list link;
};
static void
terminate_binding(struct wlsc_input_device *device,
uint32_t time, uint32_t key, uint32_t state, void *data)
terminate_binding(struct wl_input_device *device, uint32_t time,
uint32_t key, uint32_t button, uint32_t state, void *data)
{
struct wlsc_compositor *compositor = data;
@ -1164,7 +1188,7 @@ terminate_binding(struct wlsc_input_device *device,
struct wlsc_binding *
wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
uint32_t key, uint32_t modifier,
uint32_t key, uint32_t button, uint32_t modifier,
wlsc_binding_handler_t handler, void *data)
{
struct wlsc_binding *binding;
@ -1174,6 +1198,7 @@ wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
return NULL;
binding->key = key;
binding->button = button;
binding->modifier = modifier;
binding->handler = handler;
binding->data = data;
@ -1235,7 +1260,8 @@ notify_key(struct wl_input_device *device,
wl_list_for_each(b, &compositor->binding_list, link) {
if (b->key == key &&
b->modifier == wd->modifier_state && state) {
b->handler(wd, time, key, state, b->data);
b->handler(&wd->input_device,
time, key, 0, state, b->data);
break;
}
}
@ -1373,6 +1399,7 @@ wlsc_input_device_init(struct wlsc_input_device *device,
device->input_device.y, 32, 32);
device->hotspot_x = 16;
device->hotspot_y = 16;
device->modifier_state = 0;
device->input_device.motion_grab.interface = &motion_grab_interface;
@ -1545,15 +1572,19 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
wl_list_init(&ec->output_list);
wl_list_init(&ec->binding_list);
wlsc_compositor_add_binding(ec, KEY_BACKSPACE,
wlsc_compositor_add_binding(ec, KEY_BACKSPACE, 0,
MODIFIER_CTRL | MODIFIER_ALT,
terminate_binding, ec);
wlsc_compositor_add_binding(ec, KEY_TAB, MODIFIER_SUPER,
wlsc_compositor_add_binding(ec, KEY_TAB, MODIFIER_SUPER, 0,
switcher_next_binding, ec);
wlsc_compositor_add_binding(ec, KEY_LEFTMETA, MODIFIER_SUPER,
wlsc_compositor_add_binding(ec, KEY_LEFTMETA, MODIFIER_SUPER, 0,
switcher_terminate_binding, ec);
wlsc_compositor_add_binding(ec, KEY_RIGHTMETA, MODIFIER_SUPER,
wlsc_compositor_add_binding(ec, KEY_RIGHTMETA, MODIFIER_SUPER, 0,
switcher_terminate_binding, ec);
wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
move_binding, ec);
wlsc_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
resize_binding, ec);
create_pointer_images(ec);

@ -188,12 +188,13 @@ void
wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
struct wlsc_binding;
typedef void (*wlsc_binding_handler_t)(struct wlsc_input_device *device,
typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
uint32_t time, uint32_t key,
uint32_t button,
uint32_t state, void *data);
struct wlsc_binding *
wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
uint32_t key, uint32_t modifier,
uint32_t key, uint32_t button, uint32_t modifier,
wlsc_binding_handler_t binding, void *data);
void
wlsc_binding_destroy(struct wlsc_binding *binding);

Loading…
Cancel
Save