libweston: Use struct timespec for key events
Change code related to key events to use struct timespec to represent time. This commit is part of a larger effort to transition the Weston codebase to struct timespec. Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
committed by
Pekka Paalanen
parent
80321942e7
commit
47e79c860b
+15
-9
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "compositor.h"
|
||||
#include "shared/helpers.h"
|
||||
#include "shared/timespec-util.h"
|
||||
|
||||
struct weston_binding {
|
||||
uint32_t key;
|
||||
@@ -192,7 +193,7 @@ struct binding_keyboard_grab {
|
||||
|
||||
static void
|
||||
binding_key(struct weston_keyboard_grab *grab,
|
||||
uint32_t time, uint32_t key, uint32_t state_w)
|
||||
const struct timespec *time, uint32_t key, uint32_t state_w)
|
||||
{
|
||||
struct binding_keyboard_grab *b =
|
||||
container_of(grab, struct binding_keyboard_grab, grab);
|
||||
@@ -201,6 +202,7 @@ binding_key(struct weston_keyboard_grab *grab,
|
||||
uint32_t serial;
|
||||
struct weston_keyboard *keyboard = grab->keyboard;
|
||||
struct wl_display *display = keyboard->seat->compositor->wl_display;
|
||||
uint32_t msecs;
|
||||
|
||||
if (key == b->key) {
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||
@@ -215,10 +217,11 @@ binding_key(struct weston_keyboard_grab *grab,
|
||||
}
|
||||
if (!wl_list_empty(&keyboard->focus_resource_list)) {
|
||||
serial = wl_display_next_serial(display);
|
||||
msecs = timespec_to_msec(time);
|
||||
wl_resource_for_each(resource, &keyboard->focus_resource_list) {
|
||||
wl_keyboard_send_key(resource,
|
||||
serial,
|
||||
time,
|
||||
msecs,
|
||||
key,
|
||||
state);
|
||||
}
|
||||
@@ -255,8 +258,9 @@ static const struct weston_keyboard_grab_interface binding_grab = {
|
||||
};
|
||||
|
||||
static void
|
||||
install_binding_grab(struct weston_keyboard *keyboard, uint32_t time,
|
||||
uint32_t key, struct weston_surface *focus)
|
||||
install_binding_grab(struct weston_keyboard *keyboard,
|
||||
const struct timespec *time, uint32_t key,
|
||||
struct weston_surface *focus)
|
||||
{
|
||||
struct binding_keyboard_grab *grab;
|
||||
|
||||
@@ -282,7 +286,7 @@ install_binding_grab(struct weston_keyboard *keyboard, uint32_t time,
|
||||
void
|
||||
weston_compositor_run_key_binding(struct weston_compositor *compositor,
|
||||
struct weston_keyboard *keyboard,
|
||||
uint32_t time, uint32_t key,
|
||||
const struct timespec *time, uint32_t key,
|
||||
enum wl_keyboard_key_state state)
|
||||
{
|
||||
struct weston_binding *b, *tmp;
|
||||
@@ -416,7 +420,7 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
|
||||
int
|
||||
weston_compositor_run_debug_binding(struct weston_compositor *compositor,
|
||||
struct weston_keyboard *keyboard,
|
||||
uint32_t time, uint32_t key,
|
||||
const struct timespec *time, uint32_t key,
|
||||
enum wl_keyboard_key_state state)
|
||||
{
|
||||
weston_key_binding_handler_t handler;
|
||||
@@ -443,7 +447,7 @@ struct debug_binding_grab {
|
||||
};
|
||||
|
||||
static void
|
||||
debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
|
||||
debug_binding_key(struct weston_keyboard_grab *grab, const struct timespec *time,
|
||||
uint32_t key, uint32_t state)
|
||||
{
|
||||
struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
|
||||
@@ -455,6 +459,7 @@ debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
|
||||
int check_binding = 1;
|
||||
int i;
|
||||
struct wl_list *resource_list;
|
||||
uint32_t msecs;
|
||||
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||
/* Do not run bindings on key releases */
|
||||
@@ -503,8 +508,9 @@ debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
|
||||
if (send) {
|
||||
serial = wl_display_next_serial(display);
|
||||
resource_list = &grab->keyboard->focus_resource_list;
|
||||
msecs = timespec_to_msec(time);
|
||||
wl_resource_for_each(resource, resource_list) {
|
||||
wl_keyboard_send_key(resource, serial, time, key, state);
|
||||
wl_keyboard_send_key(resource, serial, msecs, key, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,7 +554,7 @@ struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
|
||||
};
|
||||
|
||||
static void
|
||||
debug_binding(struct weston_keyboard *keyboard, uint32_t time,
|
||||
debug_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
struct debug_binding_grab *grab;
|
||||
|
||||
@@ -3804,8 +3804,8 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
|
||||
}
|
||||
|
||||
static void
|
||||
planes_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
||||
void *data)
|
||||
planes_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
struct drm_backend *b = data;
|
||||
|
||||
@@ -3885,8 +3885,8 @@ create_recorder(struct drm_backend *b, int width, int height,
|
||||
}
|
||||
|
||||
static void
|
||||
recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
||||
void *data)
|
||||
recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
struct drm_backend *b = data;
|
||||
struct drm_output *output;
|
||||
@@ -3927,8 +3927,8 @@ recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
||||
}
|
||||
#else
|
||||
static void
|
||||
recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
||||
void *data)
|
||||
recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
weston_log("Compiled without libva support\n");
|
||||
}
|
||||
@@ -3979,8 +3979,8 @@ switch_to_gl_renderer(struct drm_backend *b)
|
||||
}
|
||||
|
||||
static void
|
||||
renderer_switch_binding(struct weston_keyboard *keyboard, uint32_t time,
|
||||
uint32_t key, void *data)
|
||||
renderer_switch_binding(struct weston_keyboard *keyboard,
|
||||
const struct timespec *time, uint32_t key, void *data)
|
||||
{
|
||||
struct drm_backend *b =
|
||||
to_drm_backend(keyboard->seat->compositor);
|
||||
|
||||
@@ -1135,6 +1135,7 @@ xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
|
||||
enum wl_keyboard_key_state keyState;
|
||||
RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
|
||||
int notify = 0;
|
||||
struct timespec time;
|
||||
|
||||
if (!(peerContext->item.flags & RDP_PEER_ACTIVATED))
|
||||
FREERDP_CB_RETURN(TRUE);
|
||||
@@ -1160,7 +1161,8 @@ xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
|
||||
|
||||
/*weston_log("code=%x ext=%d vk_code=%x scan_code=%x\n", code, (flags & KBD_FLAGS_EXTENDED) ? 1 : 0,
|
||||
vk_code, scan_code);*/
|
||||
notify_key(peerContext->item.seat, weston_compositor_get_time(),
|
||||
timespec_from_msec(&time, weston_compositor_get_time());
|
||||
notify_key(peerContext->item.seat, &time,
|
||||
scan_code - 8, keyState, STATE_UPDATE_AUTOMATIC);
|
||||
}
|
||||
|
||||
|
||||
@@ -1905,9 +1905,12 @@ input_handle_key(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
||||
{
|
||||
struct wayland_input *input = data;
|
||||
struct timespec ts;
|
||||
|
||||
timespec_from_msec(&ts, time);
|
||||
|
||||
input->key_serial = serial;
|
||||
notify_key(&input->base, time, key,
|
||||
notify_key(&input->base, &ts, key,
|
||||
state ? WL_KEYBOARD_KEY_STATE_PRESSED :
|
||||
WL_KEYBOARD_KEY_STATE_RELEASED,
|
||||
input->keyboard_state_update);
|
||||
@@ -2515,8 +2518,8 @@ create_cursor(struct wayland_backend *b,
|
||||
}
|
||||
|
||||
static void
|
||||
fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time,
|
||||
uint32_t key, void *data)
|
||||
fullscreen_binding(struct weston_keyboard *keyboard,
|
||||
const struct timespec *time, uint32_t key, void *data)
|
||||
{
|
||||
struct wayland_backend *b = data;
|
||||
struct wayland_input *input = NULL;
|
||||
|
||||
@@ -1325,6 +1325,7 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
|
||||
uint32_t i, set;
|
||||
uint8_t response_type;
|
||||
int count;
|
||||
struct timespec time;
|
||||
|
||||
prev = NULL;
|
||||
count = 0;
|
||||
@@ -1351,8 +1352,10 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
|
||||
* and fall through and handle the new
|
||||
* event below. */
|
||||
update_xkb_state_from_core(b, key_release->state);
|
||||
timespec_from_msec(&time,
|
||||
weston_compositor_get_time());
|
||||
notify_key(&b->core_seat,
|
||||
weston_compositor_get_time(),
|
||||
&time,
|
||||
key_release->detail - 8,
|
||||
WL_KEYBOARD_KEY_STATE_RELEASED,
|
||||
STATE_UPDATE_AUTOMATIC);
|
||||
@@ -1395,8 +1398,9 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
|
||||
key_press = (xcb_key_press_event_t *) event;
|
||||
if (!b->has_xkb)
|
||||
update_xkb_state_from_core(b, key_press->state);
|
||||
timespec_from_msec(&time, weston_compositor_get_time());
|
||||
notify_key(&b->core_seat,
|
||||
weston_compositor_get_time(),
|
||||
&time,
|
||||
key_press->detail - 8,
|
||||
WL_KEYBOARD_KEY_STATE_PRESSED,
|
||||
b->has_xkb ? STATE_UPDATE_NONE :
|
||||
@@ -1410,8 +1414,9 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
|
||||
break;
|
||||
}
|
||||
key_release = (xcb_key_press_event_t *) event;
|
||||
timespec_from_msec(&time, weston_compositor_get_time());
|
||||
notify_key(&b->core_seat,
|
||||
weston_compositor_get_time(),
|
||||
&time,
|
||||
key_release->detail - 8,
|
||||
WL_KEYBOARD_KEY_STATE_RELEASED,
|
||||
STATE_UPDATE_NONE);
|
||||
@@ -1517,8 +1522,9 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
|
||||
case XCB_KEY_RELEASE:
|
||||
key_release = (xcb_key_press_event_t *) prev;
|
||||
update_xkb_state_from_core(b, key_release->state);
|
||||
timespec_from_msec(&time, weston_compositor_get_time());
|
||||
notify_key(&b->core_seat,
|
||||
weston_compositor_get_time(),
|
||||
&time,
|
||||
key_release->detail - 8,
|
||||
WL_KEYBOARD_KEY_STATE_RELEASED,
|
||||
STATE_UPDATE_AUTOMATIC);
|
||||
|
||||
@@ -5241,8 +5241,9 @@ weston_environment_get_fd(const char *env)
|
||||
}
|
||||
|
||||
static void
|
||||
timeline_key_binding_handler(struct weston_keyboard *keyboard, uint32_t time,
|
||||
uint32_t key, void *data)
|
||||
timeline_key_binding_handler(struct weston_keyboard *keyboard,
|
||||
const struct timespec *time, uint32_t key,
|
||||
void *data)
|
||||
{
|
||||
struct weston_compositor *compositor = data;
|
||||
|
||||
|
||||
+10
-8
@@ -289,8 +289,8 @@ struct weston_pointer_grab {
|
||||
|
||||
struct weston_keyboard_grab;
|
||||
struct weston_keyboard_grab_interface {
|
||||
void (*key)(struct weston_keyboard_grab *grab, uint32_t time,
|
||||
uint32_t key, uint32_t state);
|
||||
void (*key)(struct weston_keyboard_grab *grab,
|
||||
const struct timespec *time, uint32_t key, uint32_t state);
|
||||
void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial,
|
||||
uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group);
|
||||
@@ -492,7 +492,7 @@ bool
|
||||
weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard);
|
||||
void
|
||||
weston_keyboard_send_key(struct weston_keyboard *keyboard,
|
||||
uint32_t time, uint32_t key,
|
||||
const struct timespec *time, uint32_t key,
|
||||
enum wl_keyboard_key_state state);
|
||||
void
|
||||
weston_keyboard_send_modifiers(struct weston_keyboard *keyboard,
|
||||
@@ -583,7 +583,7 @@ struct weston_keyboard {
|
||||
struct weston_keyboard_grab default_grab;
|
||||
uint32_t grab_key;
|
||||
uint32_t grab_serial;
|
||||
uint32_t grab_time;
|
||||
struct timespec grab_time;
|
||||
|
||||
struct wl_array keys;
|
||||
|
||||
@@ -1385,7 +1385,7 @@ void
|
||||
notify_pointer_frame(struct weston_seat *seat);
|
||||
|
||||
void
|
||||
notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
|
||||
notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key,
|
||||
enum wl_keyboard_key_state state,
|
||||
enum weston_key_state_update update_state);
|
||||
void
|
||||
@@ -1475,7 +1475,8 @@ weston_compositor_pick_view(struct weston_compositor *compositor,
|
||||
|
||||
struct weston_binding;
|
||||
typedef void (*weston_key_binding_handler_t)(struct weston_keyboard *keyboard,
|
||||
uint32_t time, uint32_t key,
|
||||
const struct timespec *time,
|
||||
uint32_t key,
|
||||
void *data);
|
||||
struct weston_binding *
|
||||
weston_compositor_add_key_binding(struct weston_compositor *compositor,
|
||||
@@ -1541,7 +1542,7 @@ weston_binding_list_destroy_all(struct wl_list *list);
|
||||
void
|
||||
weston_compositor_run_key_binding(struct weston_compositor *compositor,
|
||||
struct weston_keyboard *keyboard,
|
||||
uint32_t time,
|
||||
const struct timespec *time,
|
||||
uint32_t key,
|
||||
enum wl_keyboard_key_state state);
|
||||
|
||||
@@ -1567,7 +1568,8 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
|
||||
struct weston_pointer_axis_event *event);
|
||||
int
|
||||
weston_compositor_run_debug_binding(struct weston_compositor *compositor,
|
||||
struct weston_keyboard *keyboard, uint32_t time,
|
||||
struct weston_keyboard *keyboard,
|
||||
const struct timespec *time,
|
||||
uint32_t key,
|
||||
enum wl_keyboard_key_state state);
|
||||
|
||||
|
||||
@@ -824,7 +824,7 @@ static const struct weston_touch_grab_interface touch_drag_grab_interface = {
|
||||
|
||||
static void
|
||||
drag_grab_keyboard_key(struct weston_keyboard_grab *grab,
|
||||
uint32_t time, uint32_t key, uint32_t state)
|
||||
const struct timespec *time, uint32_t key, uint32_t state)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -3534,7 +3534,8 @@ compile_shaders(struct weston_compositor *ec)
|
||||
}
|
||||
|
||||
static void
|
||||
fragment_debug_binding(struct weston_keyboard *keyboard, uint32_t time,
|
||||
fragment_debug_binding(struct weston_keyboard *keyboard,
|
||||
const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
struct weston_compositor *ec = data;
|
||||
@@ -3560,7 +3561,8 @@ fragment_debug_binding(struct weston_keyboard *keyboard, uint32_t time,
|
||||
}
|
||||
|
||||
static void
|
||||
fan_debug_repaint_binding(struct weston_keyboard *keyboard, uint32_t time,
|
||||
fan_debug_repaint_binding(struct weston_keyboard *keyboard,
|
||||
const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
struct weston_compositor *compositor = data;
|
||||
|
||||
+8
-5
@@ -842,26 +842,29 @@ weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard)
|
||||
*/
|
||||
WL_EXPORT void
|
||||
weston_keyboard_send_key(struct weston_keyboard *keyboard,
|
||||
uint32_t time, uint32_t key,
|
||||
const struct timespec *time, uint32_t key,
|
||||
enum wl_keyboard_key_state state)
|
||||
{
|
||||
struct wl_resource *resource;
|
||||
struct wl_display *display = keyboard->seat->compositor->wl_display;
|
||||
uint32_t serial;
|
||||
struct wl_list *resource_list;
|
||||
uint32_t msecs;
|
||||
|
||||
if (!weston_keyboard_has_focus_resource(keyboard))
|
||||
return;
|
||||
|
||||
resource_list = &keyboard->focus_resource_list;
|
||||
serial = wl_display_next_serial(display);
|
||||
msecs = timespec_to_msec(time);
|
||||
wl_resource_for_each(resource, resource_list)
|
||||
wl_keyboard_send_key(resource, serial, time, key, state);
|
||||
wl_keyboard_send_key(resource, serial, msecs, key, state);
|
||||
};
|
||||
|
||||
static void
|
||||
default_grab_keyboard_key(struct weston_keyboard_grab *grab,
|
||||
uint32_t time, uint32_t key, uint32_t state)
|
||||
const struct timespec *time, uint32_t key,
|
||||
uint32_t state)
|
||||
{
|
||||
weston_keyboard_send_key(grab->keyboard, time, key, state);
|
||||
}
|
||||
@@ -1944,7 +1947,7 @@ update_keymap(struct weston_seat *seat)
|
||||
}
|
||||
|
||||
WL_EXPORT void
|
||||
notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
|
||||
notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key,
|
||||
enum wl_keyboard_key_state state,
|
||||
enum weston_key_state_update update_state)
|
||||
{
|
||||
@@ -1996,7 +1999,7 @@ notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
|
||||
|
||||
keyboard->grab_serial = wl_display_get_serial(compositor->wl_display);
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
keyboard->grab_time = time;
|
||||
keyboard->grab_time = *time;
|
||||
keyboard->grab_key = key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ weston_launcher_restore(struct weston_launcher *launcher)
|
||||
|
||||
static void
|
||||
switch_vt_binding(struct weston_keyboard *keyboard,
|
||||
uint32_t time, uint32_t key, void *data)
|
||||
const struct timespec *time, uint32_t key, void *data)
|
||||
{
|
||||
struct weston_compositor *compositor = data;
|
||||
struct weston_launcher *launcher = compositor->launcher;
|
||||
|
||||
@@ -66,6 +66,7 @@ handle_keyboard_key(struct libinput_device *libinput_device,
|
||||
libinput_event_keyboard_get_key_state(keyboard_event);
|
||||
int seat_key_count =
|
||||
libinput_event_keyboard_get_seat_key_count(keyboard_event);
|
||||
struct timespec time;
|
||||
|
||||
/* Ignore key events that are not seat wide state changes. */
|
||||
if ((key_state == LIBINPUT_KEY_STATE_PRESSED &&
|
||||
@@ -74,8 +75,10 @@ handle_keyboard_key(struct libinput_device *libinput_device,
|
||||
seat_key_count != 0))
|
||||
return;
|
||||
|
||||
notify_key(device->seat,
|
||||
libinput_event_keyboard_get_time(keyboard_event),
|
||||
timespec_from_usec(&time,
|
||||
libinput_event_keyboard_get_time_usec(keyboard_event));
|
||||
|
||||
notify_key(device->seat, &time,
|
||||
libinput_event_keyboard_get_key(keyboard_event),
|
||||
key_state, STATE_UPDATE_AUTOMATIC);
|
||||
}
|
||||
|
||||
@@ -804,8 +804,8 @@ pixman_renderer_surface_copy_content(struct weston_surface *surface,
|
||||
}
|
||||
|
||||
static void
|
||||
debug_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
||||
void *data)
|
||||
debug_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
||||
uint32_t key, void *data)
|
||||
{
|
||||
struct weston_compositor *ec = data;
|
||||
struct pixman_renderer *pr = (struct pixman_renderer *) ec->renderer;
|
||||
|
||||
Reference in New Issue
Block a user