mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-16 06:59:47 -05:00
Move pointer and keyboard focus tracking into libwayland-server
This commit is contained in:
parent
06bc26401c
commit
2643707391
4 changed files with 107 additions and 101 deletions
|
|
@ -55,13 +55,6 @@ static const GOptionEntry option_entries[] = {
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
wlsc_input_device_set_pointer_focus(struct wlsc_input_device *device,
|
|
||||||
struct wlsc_surface *surface,
|
|
||||||
uint32_t time,
|
|
||||||
int32_t x, int32_t y,
|
|
||||||
int32_t sx, int32_t sy);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wlsc_matrix_init(struct wlsc_matrix *matrix)
|
wlsc_matrix_init(struct wlsc_matrix *matrix)
|
||||||
{
|
{
|
||||||
|
|
@ -492,16 +485,18 @@ wlsc_input_device_start_grab(struct wlsc_input_device *device,
|
||||||
uint32_t time,
|
uint32_t time,
|
||||||
enum wlsc_grab_type grab)
|
enum wlsc_grab_type grab)
|
||||||
{
|
{
|
||||||
device->grab = grab;
|
struct wlsc_surface *focus =
|
||||||
device->grab_surface = device->pointer_focus;
|
(struct wlsc_surface *) device->base.pointer_focus;
|
||||||
device->grab_dx = device->pointer_focus->x - device->grab_x;
|
|
||||||
device->grab_dy = device->pointer_focus->y - device->grab_y;
|
|
||||||
device->grab_width = device->pointer_focus->width;
|
|
||||||
device->grab_height = device->pointer_focus->height;
|
|
||||||
|
|
||||||
wlsc_input_device_set_pointer_focus(device,
|
device->grab = grab;
|
||||||
(struct wlsc_surface *) &wl_grab_surface,
|
device->grab_surface = focus;
|
||||||
time, 0, 0, 0, 0);
|
device->grab_dx = focus->x - device->grab_x;
|
||||||
|
device->grab_dy = focus->y - device->grab_y;
|
||||||
|
device->grab_width = focus->width;
|
||||||
|
device->grab_height = focus->height;
|
||||||
|
|
||||||
|
wl_input_device_set_pointer_focus(&device->base,
|
||||||
|
&wl_grab_surface, time, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -513,7 +508,7 @@ shell_move(struct wl_client *client, struct wl_shell *shell,
|
||||||
|
|
||||||
if (wd->grab != WLSC_DEVICE_GRAB_MOTION ||
|
if (wd->grab != WLSC_DEVICE_GRAB_MOTION ||
|
||||||
wd->grab_time != time ||
|
wd->grab_time != time ||
|
||||||
&wd->pointer_focus->base != surface)
|
wd->base.pointer_focus != surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wlsc_input_device_start_grab(wd, time, WLSC_DEVICE_GRAB_MOVE);
|
wlsc_input_device_start_grab(wd, time, WLSC_DEVICE_GRAB_MOVE);
|
||||||
|
|
@ -534,7 +529,7 @@ shell_resize(struct wl_client *client, struct wl_shell *shell,
|
||||||
|
|
||||||
if (wd->grab != WLSC_DEVICE_GRAB_MOTION ||
|
if (wd->grab != WLSC_DEVICE_GRAB_MOTION ||
|
||||||
wd->grab_time != time ||
|
wd->grab_time != time ||
|
||||||
&wd->pointer_focus->base != surface)
|
wd->base.pointer_focus != surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (edges) {
|
switch (edges) {
|
||||||
|
|
@ -688,61 +683,6 @@ wlsc_surface_transform(struct wlsc_surface *surface,
|
||||||
*sy = v.f[1] * surface->height;
|
*sy = v.f[1] * surface->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
wlsc_input_device_set_keyboard_focus(struct wlsc_input_device *device,
|
|
||||||
struct wlsc_surface *surface,
|
|
||||||
uint32_t time)
|
|
||||||
{
|
|
||||||
if (device->keyboard_focus == surface)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (device->keyboard_focus &&
|
|
||||||
(!surface || device->keyboard_focus->base.client != surface->base.client))
|
|
||||||
wl_client_post_event(device->keyboard_focus->base.client,
|
|
||||||
&device->base.base,
|
|
||||||
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
|
||||||
time, NULL, &device->keys);
|
|
||||||
|
|
||||||
if (surface)
|
|
||||||
wl_client_post_event(surface->base.client,
|
|
||||||
&device->base.base,
|
|
||||||
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
|
||||||
time, &surface->base, &device->keys);
|
|
||||||
|
|
||||||
device->keyboard_focus = surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
wlsc_input_device_set_pointer_focus(struct wlsc_input_device *device,
|
|
||||||
struct wlsc_surface *surface,
|
|
||||||
uint32_t time,
|
|
||||||
int32_t x, int32_t y,
|
|
||||||
int32_t sx, int32_t sy)
|
|
||||||
{
|
|
||||||
if (device->pointer_focus == surface)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (device->pointer_focus &&
|
|
||||||
(!surface || device->pointer_focus->base.client != surface->base.client))
|
|
||||||
wl_client_post_event(device->pointer_focus->base.client,
|
|
||||||
&device->base.base,
|
|
||||||
WL_INPUT_DEVICE_POINTER_FOCUS,
|
|
||||||
time, NULL, 0, 0, 0, 0);
|
|
||||||
if (surface)
|
|
||||||
wl_client_post_event(surface->base.client,
|
|
||||||
&device->base.base,
|
|
||||||
WL_INPUT_DEVICE_POINTER_FOCUS,
|
|
||||||
time, &surface->base,
|
|
||||||
x, y, sx, sy);
|
|
||||||
|
|
||||||
if (!surface)
|
|
||||||
wlsc_input_device_set_pointer_image(device,
|
|
||||||
WLSC_POINTER_LEFT_PTR);
|
|
||||||
|
|
||||||
device->pointer_focus = surface;
|
|
||||||
device->pointer_focus_time = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlsc_surface *
|
static struct wlsc_surface *
|
||||||
pick_surface(struct wlsc_input_device *device, int32_t *sx, int32_t *sy)
|
pick_surface(struct wlsc_input_device *device, int32_t *sx, int32_t *sy)
|
||||||
{
|
{
|
||||||
|
|
@ -784,7 +724,7 @@ notify_motion(struct wlsc_input_device *device, uint32_t time, int x, int y)
|
||||||
switch (device->grab) {
|
switch (device->grab) {
|
||||||
case WLSC_DEVICE_GRAB_NONE:
|
case WLSC_DEVICE_GRAB_NONE:
|
||||||
es = pick_surface(device, &sx, &sy);
|
es = pick_surface(device, &sx, &sy);
|
||||||
wlsc_input_device_set_pointer_focus(device, es,
|
wl_input_device_set_pointer_focus(&device->base, &es->base,
|
||||||
time, x, y, sx, sy);
|
time, x, y, sx, sy);
|
||||||
if (es)
|
if (es)
|
||||||
wl_client_post_event(es->base.client,
|
wl_client_post_event(es->base.client,
|
||||||
|
|
@ -794,7 +734,7 @@ notify_motion(struct wlsc_input_device *device, uint32_t time, int x, int y)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WLSC_DEVICE_GRAB_MOTION:
|
case WLSC_DEVICE_GRAB_MOTION:
|
||||||
es = device->pointer_focus;
|
es = (struct wlsc_surface *) device->base.pointer_focus;
|
||||||
wlsc_surface_transform(es, x, y, &sx, &sy);
|
wlsc_surface_transform(es, x, y, &sx, &sy);
|
||||||
wl_client_post_event(es->base.client,
|
wl_client_post_event(es->base.client,
|
||||||
&device->base.base,
|
&device->base.base,
|
||||||
|
|
@ -898,7 +838,7 @@ wlsc_input_device_end_grab(struct wlsc_input_device *device, uint32_t time)
|
||||||
|
|
||||||
device->grab = WLSC_DEVICE_GRAB_NONE;
|
device->grab = WLSC_DEVICE_GRAB_NONE;
|
||||||
es = pick_surface(device, &sx, &sy);
|
es = pick_surface(device, &sx, &sy);
|
||||||
wlsc_input_device_set_pointer_focus(device, es, time,
|
wl_input_device_set_pointer_focus(&device->base, &es->base, time,
|
||||||
device->x, device->y, sx, sy);
|
device->x, device->y, sx, sy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -909,7 +849,7 @@ notify_button(struct wlsc_input_device *device,
|
||||||
struct wlsc_surface *surface;
|
struct wlsc_surface *surface;
|
||||||
struct wlsc_compositor *compositor = device->ec;
|
struct wlsc_compositor *compositor = device->ec;
|
||||||
|
|
||||||
surface = device->pointer_focus;
|
surface = (struct wlsc_surface *) device->base.pointer_focus;
|
||||||
if (surface) {
|
if (surface) {
|
||||||
if (state && device->grab == WLSC_DEVICE_GRAB_NONE) {
|
if (state && device->grab == WLSC_DEVICE_GRAB_NONE) {
|
||||||
wlsc_surface_raise(surface);
|
wlsc_surface_raise(surface);
|
||||||
|
|
@ -918,8 +858,9 @@ notify_button(struct wlsc_input_device *device,
|
||||||
device->grab_time = time;
|
device->grab_time = time;
|
||||||
device->grab_x = device->x;
|
device->grab_x = device->x;
|
||||||
device->grab_y = device->y;
|
device->grab_y = device->y;
|
||||||
wlsc_input_device_set_keyboard_focus(device,
|
wl_input_device_set_keyboard_focus(&device->base,
|
||||||
surface, time);
|
&surface->base,
|
||||||
|
time);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state && button == BTN_LEFT &&
|
if (state && button == BTN_LEFT &&
|
||||||
|
|
@ -990,19 +931,19 @@ notify_key(struct wlsc_input_device *device,
|
||||||
else
|
else
|
||||||
device->modifier_state &= ~modifier;
|
device->modifier_state &= ~modifier;
|
||||||
|
|
||||||
end = device->keys.data + device->keys.size;
|
end = device->base.keys.data + device->base.keys.size;
|
||||||
for (k = device->keys.data; k < end; k++) {
|
for (k = device->base.keys.data; k < end; k++) {
|
||||||
if (*k == key)
|
if (*k == key)
|
||||||
*k = *--end;
|
*k = *--end;
|
||||||
}
|
}
|
||||||
device->keys.size = (void *) end - device->keys.data;
|
device->base.keys.size = (void *) end - device->base.keys.data;
|
||||||
if (state) {
|
if (state) {
|
||||||
k = wl_array_add(&device->keys, sizeof *k);
|
k = wl_array_add(&device->base.keys, sizeof *k);
|
||||||
*k = key;
|
*k = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device->keyboard_focus != NULL)
|
if (device->base.keyboard_focus != NULL)
|
||||||
wl_client_post_event(device->keyboard_focus->base.client,
|
wl_client_post_event(device->base.keyboard_focus->client,
|
||||||
&device->base.base,
|
&device->base.base,
|
||||||
WL_INPUT_DEVICE_KEY, time, key, state);
|
WL_INPUT_DEVICE_KEY, time, key, state);
|
||||||
}
|
}
|
||||||
|
|
@ -1016,13 +957,13 @@ input_device_attach(struct wl_client *client,
|
||||||
struct wlsc_input_device *device =
|
struct wlsc_input_device *device =
|
||||||
(struct wlsc_input_device *) device_base;
|
(struct wlsc_input_device *) device_base;
|
||||||
|
|
||||||
if (time < device->pointer_focus_time)
|
if (time < device->base.pointer_focus_time)
|
||||||
return;
|
return;
|
||||||
if (device->pointer_focus == NULL)
|
if (device->base.pointer_focus == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (device->pointer_focus->base.client != client &&
|
if (device->base.pointer_focus->client != client &&
|
||||||
!(&device->pointer_focus->base == &wl_grab_surface &&
|
!(device->base.pointer_focus == &wl_grab_surface &&
|
||||||
device->grab_surface->base.client == client))
|
device->grab_surface->base.client == client))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -1047,13 +988,13 @@ handle_surface_destroy(struct wlsc_listener *listener,
|
||||||
container_of(listener, struct wlsc_input_device, listener);
|
container_of(listener, struct wlsc_input_device, listener);
|
||||||
uint32_t time = get_time();
|
uint32_t time = get_time();
|
||||||
|
|
||||||
if (device->keyboard_focus == surface)
|
if (device->base.keyboard_focus == &surface->base)
|
||||||
wlsc_input_device_set_keyboard_focus(device, NULL, time);
|
wl_input_device_set_keyboard_focus(&device->base, NULL, time);
|
||||||
if (device->pointer_focus == surface)
|
if (device->base.pointer_focus == &surface->base)
|
||||||
wlsc_input_device_set_pointer_focus(device, NULL, time,
|
wl_input_device_set_pointer_focus(&device->base, NULL, time,
|
||||||
0, 0, 0, 0);
|
0, 0, 0, 0);
|
||||||
if (device->pointer_focus == surface ||
|
if (device->base.pointer_focus == &surface->base ||
|
||||||
(&device->pointer_focus->base == &wl_grab_surface &&
|
(device->base.pointer_focus == &wl_grab_surface &&
|
||||||
device->grab_surface == surface))
|
device->grab_surface == surface))
|
||||||
wlsc_input_device_end_grab(device, time);
|
wlsc_input_device_end_grab(device, time);
|
||||||
}
|
}
|
||||||
|
|
@ -1179,7 +1120,7 @@ drag_activate(struct wl_client *client,
|
||||||
int32_t sx, sy;
|
int32_t sx, sy;
|
||||||
|
|
||||||
if (device->grab != WLSC_DEVICE_GRAB_MOTION ||
|
if (device->grab != WLSC_DEVICE_GRAB_MOTION ||
|
||||||
&device->pointer_focus->base != surface ||
|
device->base.pointer_focus != surface ||
|
||||||
device->grab_time != time)
|
device->grab_time != time)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,7 @@ struct wlsc_input_device {
|
||||||
int32_t hotspot_x, hotspot_y;
|
int32_t hotspot_x, hotspot_y;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
|
|
||||||
struct wlsc_surface *pointer_focus;
|
|
||||||
struct wlsc_surface *keyboard_focus;
|
|
||||||
struct wl_array keys;
|
|
||||||
uint32_t modifier_state;
|
uint32_t modifier_state;
|
||||||
uint32_t pointer_focus_time;
|
|
||||||
|
|
||||||
enum wlsc_grab_type grab;
|
enum wlsc_grab_type grab;
|
||||||
struct wlsc_surface *grab_surface;
|
struct wlsc_surface *grab_surface;
|
||||||
|
|
|
||||||
|
|
@ -301,6 +301,57 @@ wl_client_destroy(struct wl_client *client)
|
||||||
free(client);
|
free(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WL_EXPORT void
|
||||||
|
wl_input_device_set_pointer_focus(struct wl_input_device *device,
|
||||||
|
struct wl_surface *surface,
|
||||||
|
uint32_t time,
|
||||||
|
int32_t x, int32_t y,
|
||||||
|
int32_t sx, int32_t sy)
|
||||||
|
{
|
||||||
|
if (device->pointer_focus == surface)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (device->pointer_focus &&
|
||||||
|
(!surface || device->pointer_focus->client != surface->client))
|
||||||
|
wl_client_post_event(device->pointer_focus->client,
|
||||||
|
&device->base,
|
||||||
|
WL_INPUT_DEVICE_POINTER_FOCUS,
|
||||||
|
time, NULL, 0, 0, 0, 0);
|
||||||
|
if (surface)
|
||||||
|
wl_client_post_event(surface->client,
|
||||||
|
&device->base,
|
||||||
|
WL_INPUT_DEVICE_POINTER_FOCUS,
|
||||||
|
time, surface, x, y, sx, sy);
|
||||||
|
|
||||||
|
device->pointer_focus = surface;
|
||||||
|
device->pointer_focus_time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
WL_EXPORT void
|
||||||
|
wl_input_device_set_keyboard_focus(struct wl_input_device *device,
|
||||||
|
struct wl_surface *surface,
|
||||||
|
uint32_t time)
|
||||||
|
{
|
||||||
|
if (device->keyboard_focus == surface)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (device->keyboard_focus &&
|
||||||
|
(!surface || device->keyboard_focus->client != surface->client))
|
||||||
|
wl_client_post_event(device->keyboard_focus->client,
|
||||||
|
&device->base,
|
||||||
|
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
||||||
|
time, NULL, &device->keys);
|
||||||
|
|
||||||
|
if (surface)
|
||||||
|
wl_client_post_event(surface->client,
|
||||||
|
&device->base,
|
||||||
|
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
||||||
|
time, surface, &device->keys);
|
||||||
|
|
||||||
|
device->keyboard_focus = surface;
|
||||||
|
device->keyboard_focus_time = time;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
display_sync(struct wl_client *client,
|
display_sync(struct wl_client *client,
|
||||||
struct wl_display *display, uint32_t key)
|
struct wl_display *display, uint32_t key)
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,11 @@ struct wl_shell {
|
||||||
|
|
||||||
struct wl_input_device {
|
struct wl_input_device {
|
||||||
struct wl_object base;
|
struct wl_object base;
|
||||||
|
struct wl_surface *pointer_focus;
|
||||||
|
struct wl_surface *keyboard_focus;
|
||||||
|
struct wl_array keys;
|
||||||
|
uint32_t pointer_focus_time;
|
||||||
|
uint32_t keyboard_focus_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_visual {
|
struct wl_visual {
|
||||||
|
|
@ -174,6 +179,19 @@ wl_client_get_display(struct wl_client *client);
|
||||||
void
|
void
|
||||||
wl_resource_destroy(struct wl_resource *resource, struct wl_client *client);
|
wl_resource_destroy(struct wl_resource *resource, struct wl_client *client);
|
||||||
|
|
||||||
|
void
|
||||||
|
wl_input_device_set_pointer_focus(struct wl_input_device *device,
|
||||||
|
struct wl_surface *surface,
|
||||||
|
uint32_t time,
|
||||||
|
int32_t x, int32_t y,
|
||||||
|
int32_t sx, int32_t sy);
|
||||||
|
|
||||||
|
void
|
||||||
|
wl_input_device_set_keyboard_focus(struct wl_input_device *device,
|
||||||
|
struct wl_surface *surface,
|
||||||
|
uint32_t time);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue