Extend wlsc_binding to cover buttons too
This commit is contained in:
+76
-45
@@ -1008,33 +1008,28 @@ wlsc_surface_activate(struct wlsc_surface *surface,
|
|||||||
time);
|
time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
notify_button(struct wl_input_device *device,
|
move_binding(struct wl_input_device *device, uint32_t time,
|
||||||
uint32_t time, int32_t button, int32_t state)
|
uint32_t key, uint32_t button, uint32_t state, void *data)
|
||||||
{
|
{
|
||||||
struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
|
struct wlsc_compositor *compositor = data;
|
||||||
struct wlsc_surface *surface;
|
struct wlsc_surface *surface =
|
||||||
struct wlsc_compositor *compositor =
|
(struct wlsc_surface *) device->pointer_focus;
|
||||||
(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state && surface && button == BTN_LEFT &&
|
|
||||||
(wd->modifier_state & MODIFIER_SUPER))
|
|
||||||
shell_move(NULL,
|
shell_move(NULL,
|
||||||
(struct wl_shell *) &compositor->shell,
|
(struct wl_shell *) &compositor->shell,
|
||||||
&surface->surface, device, time);
|
&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;
|
x = device->grab_x - surface->x;
|
||||||
y = device->grab_y - surface->y;
|
y = device->grab_y - surface->y;
|
||||||
@@ -1058,6 +1053,42 @@ notify_button(struct wl_input_device *device,
|
|||||||
&surface->surface, device, time, edges);
|
&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)
|
if (device->grab)
|
||||||
device->grab->interface->button(device->grab, time,
|
device->grab->interface->button(device->grab, time,
|
||||||
button, state);
|
button, state);
|
||||||
@@ -1115,8 +1146,9 @@ wlsc_switcher_destroy(struct wlsc_switcher *switcher)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
switcher_next_binding(struct wlsc_input_device *device,
|
switcher_next_binding(struct wl_input_device *device, uint32_t time,
|
||||||
uint32_t time, uint32_t key, uint32_t state, void *data)
|
uint32_t key, uint32_t button,
|
||||||
|
uint32_t state, void *data)
|
||||||
{
|
{
|
||||||
struct wlsc_compositor *compositor = data;
|
struct wlsc_compositor *compositor = data;
|
||||||
|
|
||||||
@@ -1131,31 +1163,23 @@ switcher_next_binding(struct wlsc_input_device *device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
switcher_terminate_binding(struct wlsc_input_device *device,
|
switcher_terminate_binding(struct wl_input_device *device,
|
||||||
uint32_t time, uint32_t key, uint32_t state,
|
uint32_t time, uint32_t key, uint32_t button,
|
||||||
void *data)
|
uint32_t state, void *data)
|
||||||
{
|
{
|
||||||
struct wlsc_compositor *compositor = data;
|
struct wlsc_compositor *compositor = data;
|
||||||
|
struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
|
||||||
|
|
||||||
if (compositor->switcher && !state) {
|
if (compositor->switcher && !state) {
|
||||||
wlsc_surface_activate(compositor->switcher->current,
|
wlsc_surface_activate(compositor->switcher->current, wd, time);
|
||||||
device, time);
|
|
||||||
wlsc_switcher_destroy(compositor->switcher);
|
wlsc_switcher_destroy(compositor->switcher);
|
||||||
compositor->switcher = NULL;
|
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
|
static void
|
||||||
terminate_binding(struct wlsc_input_device *device,
|
terminate_binding(struct wl_input_device *device, uint32_t time,
|
||||||
uint32_t time, uint32_t key, uint32_t state, void *data)
|
uint32_t key, uint32_t button, uint32_t state, void *data)
|
||||||
{
|
{
|
||||||
struct wlsc_compositor *compositor = data;
|
struct wlsc_compositor *compositor = data;
|
||||||
|
|
||||||
@@ -1164,7 +1188,7 @@ terminate_binding(struct wlsc_input_device *device,
|
|||||||
|
|
||||||
struct wlsc_binding *
|
struct wlsc_binding *
|
||||||
wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
|
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)
|
wlsc_binding_handler_t handler, void *data)
|
||||||
{
|
{
|
||||||
struct wlsc_binding *binding;
|
struct wlsc_binding *binding;
|
||||||
@@ -1174,6 +1198,7 @@ wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
binding->key = key;
|
binding->key = key;
|
||||||
|
binding->button = button;
|
||||||
binding->modifier = modifier;
|
binding->modifier = modifier;
|
||||||
binding->handler = handler;
|
binding->handler = handler;
|
||||||
binding->data = data;
|
binding->data = data;
|
||||||
@@ -1235,7 +1260,8 @@ notify_key(struct wl_input_device *device,
|
|||||||
wl_list_for_each(b, &compositor->binding_list, link) {
|
wl_list_for_each(b, &compositor->binding_list, link) {
|
||||||
if (b->key == key &&
|
if (b->key == key &&
|
||||||
b->modifier == wd->modifier_state && state) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1373,6 +1399,7 @@ wlsc_input_device_init(struct wlsc_input_device *device,
|
|||||||
device->input_device.y, 32, 32);
|
device->input_device.y, 32, 32);
|
||||||
device->hotspot_x = 16;
|
device->hotspot_x = 16;
|
||||||
device->hotspot_y = 16;
|
device->hotspot_y = 16;
|
||||||
|
device->modifier_state = 0;
|
||||||
|
|
||||||
device->input_device.motion_grab.interface = &motion_grab_interface;
|
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->output_list);
|
||||||
wl_list_init(&ec->binding_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,
|
MODIFIER_CTRL | MODIFIER_ALT,
|
||||||
terminate_binding, ec);
|
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);
|
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);
|
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);
|
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);
|
create_pointer_images(ec);
|
||||||
|
|
||||||
|
|||||||
@@ -188,12 +188,13 @@ void
|
|||||||
wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
|
wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
|
||||||
|
|
||||||
struct wlsc_binding;
|
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 time, uint32_t key,
|
||||||
|
uint32_t button,
|
||||||
uint32_t state, void *data);
|
uint32_t state, void *data);
|
||||||
struct wlsc_binding *
|
struct wlsc_binding *
|
||||||
wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
|
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);
|
wlsc_binding_handler_t binding, void *data);
|
||||||
void
|
void
|
||||||
wlsc_binding_destroy(struct wlsc_binding *binding);
|
wlsc_binding_destroy(struct wlsc_binding *binding);
|
||||||
|
|||||||
Reference in New Issue
Block a user