From bef52d1423a93f96d157dd94cbda8a00594d3f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Fri, 11 May 2012 11:24:29 -0400 Subject: [PATCH] Update to new libxkbcommon API We no longer depend on xproto, we use xkbcommon keycodes now. Yay! --- clients/clickdot.c | 4 +- clients/resizor.c | 12 ++--- clients/terminal.c | 110 +++++++++++++++++++++---------------------- clients/window.c | 11 ++--- src/compositor-x11.c | 2 +- src/compositor.c | 14 +++--- 6 files changed, 72 insertions(+), 81 deletions(-) diff --git a/clients/clickdot.c b/clients/clickdot.c index d1f8e2ef..b9669d19 100644 --- a/clients/clickdot.c +++ b/clients/clickdot.c @@ -35,8 +35,6 @@ #include "window.h" -#include - struct clickdot { struct display *display; struct window *window; @@ -190,7 +188,7 @@ key_handler(struct window *window, struct input *input, uint32_t time, return; switch (sym) { - case XK_Escape: + case XKB_KEY_Escape: display_exit(clickdot->display); break; } diff --git a/clients/resizor.c b/clients/resizor.c index 31396d93..58b4d5fa 100644 --- a/clients/resizor.c +++ b/clients/resizor.c @@ -33,8 +33,6 @@ #include "window.h" -#include - struct spring { double current; double target; @@ -158,35 +156,35 @@ key_handler(struct window *window, struct input *input, uint32_t time, resizor->height.target = allocation.height; switch (sym) { - case XK_Up: + case XKB_KEY_Up: if (allocation.height < 400) break; resizor->height.target = allocation.height - 200; break; - case XK_Down: + case XKB_KEY_Down: if (allocation.height > 1000) break; resizor->height.target = allocation.height + 200; break; - case XK_Left: + case XKB_KEY_Left: if (allocation.width < 400) break; resizor->width.target = allocation.width - 200; break; - case XK_Right: + case XKB_KEY_Right: if (allocation.width > 1000) break; resizor->width.target = allocation.width + 200; break; - case XK_Escape: + case XKB_KEY_Escape: display_exit(resizor->display); break; } diff --git a/clients/terminal.c b/clients/terminal.c index 52aed845..d59442cd 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -34,8 +34,6 @@ #include #include -#include - #include #include "window.h" @@ -241,28 +239,28 @@ struct key_map { typedef struct key_map *keyboard_mode; static struct key_map KM_NORMAL[] = { - {XK_Left, 1, '[', 'D'}, - {XK_Right, 1, '[', 'C'}, - {XK_Up, 1, '[', 'A'}, - {XK_Down, 1, '[', 'B'}, - {XK_Home, 1, '[', 'H'}, - {XK_End, 1, '[', 'F'}, - {0, 0, 0, 0} + { XKB_KEY_Left, 1, '[', 'D' }, + { XKB_KEY_Right, 1, '[', 'C' }, + { XKB_KEY_Up, 1, '[', 'A' }, + { XKB_KEY_Down, 1, '[', 'B' }, + { XKB_KEY_Home, 1, '[', 'H' }, + { XKB_KEY_End, 1, '[', 'F' }, + { 0, 0, 0, 0 } }; static struct key_map KM_APPLICATION[] = { - {XK_Left, 1, 'O', 'D'}, - {XK_Right, 1, 'O', 'C'}, - {XK_Up, 1, 'O', 'A'}, - {XK_Down, 1, 'O', 'B'}, - {XK_Home, 1, 'O', 'H'}, - {XK_End, 1, 'O', 'F'}, - {XK_KP_Enter, 1, 'O', 'M'}, - {XK_KP_Multiply, 1, 'O', 'j'}, - {XK_KP_Add, 1, 'O', 'k'}, - {XK_KP_Separator, 1, 'O', 'l'}, - {XK_KP_Subtract, 1, 'O', 'm'}, - {XK_KP_Divide, 1, 'O', 'o'}, - {0, 0, 0, 0} + { XKB_KEY_Left, 1, 'O', 'D' }, + { XKB_KEY_Right, 1, 'O', 'C' }, + { XKB_KEY_Up, 1, 'O', 'A' }, + { XKB_KEY_Down, 1, 'O', 'B' }, + { XKB_KEY_Home, 1, 'O', 'H' }, + { XKB_KEY_End, 1, 'O', 'F' }, + { XKB_KEY_KP_Enter, 1, 'O', 'M' }, + { XKB_KEY_KP_Multiply, 1, 'O', 'j' }, + { XKB_KEY_KP_Add, 1, 'O', 'k' }, + { XKB_KEY_KP_Separator, 1, 'O', 'l' }, + { XKB_KEY_KP_Subtract, 1, 'O', 'm' }, + { XKB_KEY_KP_Divide, 1, 'O', 'o' }, + { 0, 0, 0, 0 } }; static int @@ -2045,10 +2043,10 @@ handle_bound_key(struct terminal *terminal, struct input *input, uint32_t sym, uint32_t time) { switch (sym) { - case XK_X: + case XKB_KEY_X: /* Cut selection; terminal doesn't do cut, fall * through to copy. */ - case XK_C: + case XKB_KEY_C: terminal->selection = display_create_data_source(terminal->display); wl_data_source_offer(terminal->selection, @@ -2057,7 +2055,7 @@ handle_bound_key(struct terminal *terminal, &data_source_listener, terminal); input_set_selection(input, terminal->selection, time); return 1; - case XK_V: + case XKB_KEY_V: input_receive_selection_data_to_fd(input, "text/plain;charset=utf-8", terminal->master); @@ -2084,25 +2082,25 @@ key_handler(struct window *window, struct input *input, uint32_t time, return; switch (sym) { - case XK_F11: + case XKB_KEY_F11: if (!state) break; terminal->fullscreen ^= 1; window_set_fullscreen(window, terminal->fullscreen); break; - case XK_BackSpace: - case XK_Tab: - case XK_Linefeed: - case XK_Clear: - case XK_Pause: - case XK_Scroll_Lock: - case XK_Sys_Req: - case XK_Escape: + case XKB_KEY_BackSpace: + case XKB_KEY_Tab: + case XKB_KEY_Linefeed: + case XKB_KEY_Clear: + case XKB_KEY_Pause: + case XKB_KEY_Scroll_Lock: + case XKB_KEY_Sys_Req: + case XKB_KEY_Escape: ch[len++] = sym & 0x7f; break; - case XK_Return: + case XKB_KEY_Return: if (terminal->mode & MODE_LF_NEWLINE) { ch[len++] = 0x0D; ch[len++] = 0x0A; @@ -2111,61 +2109,61 @@ key_handler(struct window *window, struct input *input, uint32_t time, } break; - case XK_Shift_L: - case XK_Shift_R: - case XK_Control_L: - case XK_Control_R: - case XK_Alt_L: - case XK_Alt_R: + case XKB_KEY_Shift_L: + case XKB_KEY_Shift_R: + case XKB_KEY_Control_L: + case XKB_KEY_Control_R: + case XKB_KEY_Alt_L: + case XKB_KEY_Alt_R: break; - case XK_Insert: + case XKB_KEY_Insert: len = function_key_response('[', 2, modifiers, '~', ch); break; - case XK_Delete: + case XKB_KEY_Delete: if (terminal->mode & MODE_DELETE_SENDS_DEL) { ch[len++] = '\x04'; } else { len = function_key_response('[', 3, modifiers, '~', ch); } break; - case XK_Page_Up: + case XKB_KEY_Page_Up: len = function_key_response('[', 5, modifiers, '~', ch); break; - case XK_Page_Down: + case XKB_KEY_Page_Down: len = function_key_response('[', 6, modifiers, '~', ch); break; - case XK_F1: + case XKB_KEY_F1: len = function_key_response('O', 1, modifiers, 'P', ch); break; - case XK_F2: + case XKB_KEY_F2: len = function_key_response('O', 1, modifiers, 'Q', ch); break; - case XK_F3: + case XKB_KEY_F3: len = function_key_response('O', 1, modifiers, 'R', ch); break; - case XK_F4: + case XKB_KEY_F4: len = function_key_response('O', 1, modifiers, 'S', ch); break; - case XK_F5: + case XKB_KEY_F5: len = function_key_response('[', 15, modifiers, '~', ch); break; - case XK_F6: + case XKB_KEY_F6: len = function_key_response('[', 17, modifiers, '~', ch); break; - case XK_F7: + case XKB_KEY_F7: len = function_key_response('[', 18, modifiers, '~', ch); break; - case XK_F8: + case XKB_KEY_F8: len = function_key_response('[', 19, modifiers, '~', ch); break; - case XK_F9: + case XKB_KEY_F9: len = function_key_response('[', 20, modifiers, '~', ch); break; - case XK_F10: + case XKB_KEY_F10: len = function_key_response('[', 21, modifiers, '~', ch); break; - case XK_F12: + case XKB_KEY_F12: len = function_key_response('[', 24, modifiers, '~', ch); break; default: diff --git a/clients/window.c b/clients/window.c index 652447f3..599cb674 100644 --- a/clients/window.c +++ b/clients/window.c @@ -56,8 +56,6 @@ #endif #include -#include -#include #include #include @@ -1833,7 +1831,7 @@ input_handle_key(void *data, struct wl_input_device *input_device, xkb_state_update_key(d->xkb.state, code, state ? XKB_KEY_DOWN : XKB_KEY_UP); - mask = xkb_state_serialise_mods(d->xkb.state, + mask = xkb_state_serialize_mods(d->xkb.state, XKB_STATE_DEPRESSED | XKB_STATE_LATCHED); input->modifiers = 0; @@ -1844,7 +1842,7 @@ input_handle_key(void *data, struct wl_input_device *input_device, if (mask & input->display->xkb.shift_mask) input->modifiers |= MOD_SHIFT_MASK; - if (num_syms == 1 && syms[0] == XK_F5 && + if (num_syms == 1 && syms[0] == XKB_KEY_F5 && input->modifiers == MOD_ALT_MASK) { if (state) window_set_maximized(window, @@ -3121,14 +3119,13 @@ init_xkb(struct display *d) d->xkb.names.variant = (char *) option_xkb_variant; d->xkb.names.options = (char *) option_xkb_options; - d->xkb.context = xkb_context_new(); + d->xkb.context = xkb_context_new(0); if (!d->xkb.context) { fprintf(stderr, "Failed to create XKB context\n"); exit(1); } - d->xkb.keymap = - xkb_map_new_from_names(d->xkb.context, &d->xkb.names); + d->xkb.keymap = xkb_map_new_from_names(d->xkb.context, &d->xkb.names, 0); if (!d->xkb.keymap) { fprintf(stderr, "Failed to compile keymap\n"); exit(1); diff --git a/src/compositor-x11.c b/src/compositor-x11.c index dca2324c..0777d77c 100644 --- a/src/compositor-x11.c +++ b/src/compositor-x11.c @@ -737,7 +737,7 @@ x11_compositor_get_keymap(struct x11_compositor *c) length_part = strlen(value_part); \ if (value_part + length_part > (value_all + length_all) && \ length_part > 0 && c->base.xkb_info.names.to == NULL) { \ - free(c->base.xkb_info.names.to); \ + free((char *) c->base.xkb_info.names.to); \ c->base.xkb_info.names.to = strdup(value_part); \ } \ value_part += length_part + 1; diff --git a/src/compositor.c b/src/compositor.c index 4cb117a9..e0e0beeb 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -2614,7 +2614,7 @@ weston_compositor_shutdown(struct weston_compositor *ec) static int weston_compositor_xkb_init(struct weston_compositor *ec, struct xkb_rule_names *names) { - ec->xkb_info.context = xkb_context_new(); + ec->xkb_info.context = xkb_context_new(0); if (ec->xkb_info.context == NULL) { fprintf(stderr, "failed to create XKB context\n"); return -1; @@ -2629,7 +2629,7 @@ static int weston_compositor_xkb_init(struct weston_compositor *ec, ec->xkb_info.names.layout = strdup("us"); ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_info.context, - &ec->xkb_info.names); + &ec->xkb_info.names, 0); if (ec->xkb_info.keymap == NULL) { fprintf(stderr, "failed to compile XKB keymap\n"); return -1; @@ -2650,11 +2650,11 @@ static void weston_compositor_xkb_destroy(struct weston_compositor *ec) xkb_map_unref(ec->xkb_info.keymap); xkb_context_unref(ec->xkb_info.context); - free(ec->xkb_info.names.rules); - free(ec->xkb_info.names.model); - free(ec->xkb_info.names.layout); - free(ec->xkb_info.names.variant); - free(ec->xkb_info.names.options); + free((char *) ec->xkb_info.names.rules); + free((char *) ec->xkb_info.names.model); + free((char *) ec->xkb_info.names.layout); + free((char *) ec->xkb_info.names.variant); + free((char *) ec->xkb_info.names.options); } static int on_term_signal(int signal_number, void *data)