Use enum wl_keyboard_key_state instead of integer
Instead of using a uint32_t for state everywhere (except on the wire, where that's still the call signature), use the new wl_keyboard_key_state enum, and explicit comparisons. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
committed by
Kristian Høgsberg
parent
4dbadb1556
commit
c9785eacca
+3
-2
@@ -180,11 +180,12 @@ keyboard_focus_handler(struct window *window,
|
||||
|
||||
static void
|
||||
key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
uint32_t key, uint32_t sym, uint32_t state, void *data)
|
||||
uint32_t key, uint32_t sym,
|
||||
enum wl_keyboard_key_state state, void *data)
|
||||
{
|
||||
struct clickdot *clickdot = data;
|
||||
|
||||
if (state == 0)
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
||||
return;
|
||||
|
||||
switch (sym) {
|
||||
|
||||
+7
-3
@@ -188,15 +188,19 @@ keyboard_focus_handler(struct window *window,
|
||||
*/
|
||||
static void
|
||||
key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
uint32_t key, uint32_t unicode, uint32_t state, void *data)
|
||||
uint32_t key, uint32_t unicode, enum wl_keyboard_key_state state,
|
||||
void *data)
|
||||
{
|
||||
uint32_t modifiers = input_get_modifiers(input);
|
||||
|
||||
if(!log_key)
|
||||
return;
|
||||
|
||||
printf("key key: %d, unicode: %d, state: %d, modifiers: %d\n",
|
||||
key, unicode, state, modifiers);
|
||||
printf("key key: %d, unicode: %d, state: %s, modifiers: 0x%x\n",
|
||||
key, unicode,
|
||||
(state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "pressed" :
|
||||
"released",
|
||||
modifiers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -139,12 +139,13 @@ keyboard_focus_handler(struct window *window,
|
||||
|
||||
static void
|
||||
key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
uint32_t key, uint32_t sym, uint32_t state, void *data)
|
||||
uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
|
||||
void *data)
|
||||
{
|
||||
struct resizor *resizor = data;
|
||||
struct rectangle allocation;
|
||||
|
||||
if (state == 0)
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
||||
return;
|
||||
|
||||
window_get_allocation(resizor->window, &allocation);
|
||||
|
||||
+6
-4
@@ -2079,7 +2079,8 @@ handle_bound_key(struct terminal *terminal,
|
||||
|
||||
static void
|
||||
key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
uint32_t key, uint32_t sym, uint32_t state, void *data)
|
||||
uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
|
||||
void *data)
|
||||
{
|
||||
struct terminal *terminal = data;
|
||||
char ch[MAX_RESPONSE];
|
||||
@@ -2089,12 +2090,13 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
modifiers = input_get_modifiers(input);
|
||||
if ((modifiers & MOD_CONTROL_MASK) &&
|
||||
(modifiers & MOD_SHIFT_MASK) &&
|
||||
state && handle_bound_key(terminal, input, sym, time))
|
||||
state == WL_KEYBOARD_KEY_STATE_PRESSED &&
|
||||
handle_bound_key(terminal, input, sym, time))
|
||||
return;
|
||||
|
||||
switch (sym) {
|
||||
case XKB_KEY_F11:
|
||||
if (!state)
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
||||
break;
|
||||
terminal->fullscreen ^= 1;
|
||||
window_set_fullscreen(window, terminal->fullscreen);
|
||||
@@ -2205,7 +2207,7 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
break;
|
||||
}
|
||||
|
||||
if (state && len > 0)
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED && len > 0)
|
||||
terminal_write(terminal, ch, len);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -160,11 +160,12 @@ button_handler(struct widget *widget, struct input *input, uint32_t time,
|
||||
|
||||
static void
|
||||
key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
uint32_t key, uint32_t unicode, uint32_t state, void *data)
|
||||
uint32_t key, uint32_t unicode,
|
||||
enum wl_keyboard_key_state state, void *data)
|
||||
{
|
||||
struct view *view = data;
|
||||
|
||||
if(!state)
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
||||
return;
|
||||
|
||||
switch (key) {
|
||||
|
||||
+4
-2
@@ -1819,12 +1819,14 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
||||
|
||||
static void
|
||||
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
||||
uint32_t serial, uint32_t time, uint32_t key,
|
||||
uint32_t state_w)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct window *window = input->keyboard_focus;
|
||||
struct display *d = input->display;
|
||||
uint32_t code, num_syms;
|
||||
enum wl_keyboard_key_state state = state_w;
|
||||
const xkb_keysym_t *syms;
|
||||
xkb_keysym_t sym;
|
||||
xkb_mod_mask_t mask;
|
||||
@@ -1852,7 +1854,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
||||
|
||||
if (num_syms == 1 && syms[0] == XKB_KEY_F5 &&
|
||||
input->modifiers == MOD_ALT_MASK) {
|
||||
if (state)
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||
window_set_maximized(window,
|
||||
window->type != TYPE_MAXIMIZED);
|
||||
} else if (window->key_handler) {
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ enum cursor_type {
|
||||
|
||||
typedef void (*window_key_handler_t)(struct window *window, struct input *input,
|
||||
uint32_t time, uint32_t key, uint32_t unicode,
|
||||
uint32_t state, void *data);
|
||||
enum wl_keyboard_key_state state, void *data);
|
||||
|
||||
typedef void (*window_keyboard_focus_handler_t)(struct window *window,
|
||||
struct input *device, void *data);
|
||||
|
||||
Reference in New Issue
Block a user