Merge pull request #763 from emersion/x11-backend-kbd-modifiers

backend/x11: correctly update keyboard modifiers
This commit is contained in:
Drew DeVault 2018-03-28 12:51:08 -04:00 committed by GitHub
commit 52d621e097
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 21 deletions

View file

@ -51,6 +51,7 @@ endif
if conf_data.get('WLR_HAS_X11_BACKEND', false)
backend_files += files('x11/backend.c')
backend_deps += xcb_xkb
endif
if conf_data.get('WLR_HAS_ELOGIND', false)

View file

@ -7,6 +7,7 @@
#include <wayland-server.h>
#include <wlr/backend/interface.h>
#include <wlr/backend/x11.h>
#include <wlr/config.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_output.h>
@ -21,6 +22,9 @@
#elif __FreeBSD__
#include <dev/evdev/input-event-codes.h>
#endif
#ifdef WLR_HAS_XCB_XKB
#include <xcb/xkb.h>
#endif
#include "backend/x11.h"
#include "util/signal.h"
@ -157,6 +161,14 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
break;
}
default:
#ifdef WLR_HAS_XCB_XKB
if (x11->xkb_supported && event->response_type == x11->xkb_base_event) {
xcb_xkb_state_notify_event_t *ev =
(xcb_xkb_state_notify_event_t *)event;
wlr_keyboard_notify_modifiers(&x11->keyboard, ev->baseMods,
ev->latchedMods, ev->lockedMods, ev->lockedGroup);
}
#endif
break;
}
@ -282,6 +294,32 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) {
strlen(title), title);
}
#ifdef WLR_HAS_XCB_XKB
const xcb_query_extension_reply_t *reply =
xcb_get_extension_data(x11->xcb_conn, &xcb_xkb_id);
if (reply != NULL && reply->present) {
x11->xkb_base_event = reply->first_event;
x11->xkb_base_error = reply->first_error;
xcb_xkb_use_extension_cookie_t cookie = xcb_xkb_use_extension(
x11->xcb_conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION);
xcb_xkb_use_extension_reply_t *reply =
xcb_xkb_use_extension_reply(x11->xcb_conn, cookie, NULL);
if (reply != NULL && reply->supported) {
x11->xkb_supported = true;
xcb_xkb_select_events(x11->xcb_conn,
XCB_XKB_ID_USE_CORE_KBD,
XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
0,
XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
0,
0,
0);
}
}
#endif
xcb_map_window(x11->xcb_conn, output->win);
xcb_flush(x11->xcb_conn);
wlr_output_update_enabled(&output->wlr_output, true);

View file

@ -48,6 +48,12 @@ struct wlr_x11_backend {
// The time we last received an event
xcb_timestamp_t time;
#ifdef WLR_HAS_XCB_XKB
bool xkb_supported;
uint8_t xkb_base_event;
uint8_t xkb_base_error;
#endif
struct wl_listener display_destroy;
};

View file

@ -90,12 +90,17 @@ if get_option('enable_x11_backend') or get_option('enable_xwayland')
x11_xcb = dependency('x11-xcb')
xcb_icccm = dependency('xcb-icccm', required: false)
xcb_xkb = dependency('xcb-xkb', required: false)
xcb_errors = dependency('xcb-errors', required: get_option('enable_xcb_errors') == 'true')
if xcb_icccm.found()
conf_data.set('WLR_HAS_XCB_ICCCM', true)
endif
if xcb_xkb.found()
conf_data.set('WLR_HAS_XCB_XKB', true)
endif
if xcb_errors.found() and get_option('enable_xcb_errors') != 'false'
conf_data.set('WLR_HAS_XCB_ERRORS', true)
endif