aboutsummaryrefslogtreecommitdiff
path: root/examples/compositor.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/compositor.c')
-rw-r--r--examples/compositor.c72
1 files changed, 27 insertions, 45 deletions
diff --git a/examples/compositor.c b/examples/compositor.c
index 8154c2e3..ae21697a 100644
--- a/examples/compositor.c
+++ b/examples/compositor.c
@@ -32,9 +32,6 @@
#include "shared.h"
#include <assert.h>
-// TODO: move to common header?
-int os_create_anonymous_file(off_t size);
-
struct sample_state;
struct example_xdg_surface_v6 {
@@ -75,13 +72,9 @@ struct sample_state {
struct wlr_xdg_shell_v6 *xdg_shell;
struct wlr_data_device_manager *data_device_manager;
struct wl_resource *focus;
- struct wl_listener keyboard_bound;
struct wlr_xwayland *xwayland;
struct wlr_gamma_control_manager *gamma_control_manager;
bool mod_down;
- int keymap_fd;
- size_t keymap_size;
- uint32_t serial;
struct motion_context motion_context;
@@ -129,10 +122,7 @@ static void example_set_focused_surface(struct sample_state *sample,
}
if (surface) {
- // TODO: send array of currently pressed keys
- struct wl_array keys;
- wl_array_init(&keys);
- wlr_seat_keyboard_enter(sample->wl_seat, surface->surface, keys);
+ wlr_seat_keyboard_enter(sample->wl_seat, surface->surface);
} else {
wlr_seat_keyboard_clear_focus(sample->wl_seat);
}
@@ -300,7 +290,7 @@ static void handle_output_frame(struct output_state *output,
struct wlr_wl_shell_surface *wl_shell_surface;
wl_list_for_each(wl_shell_surface, &sample->wl_shell->surfaces, link) {
output_frame_handle_surface(sample, wlr_output, ts,
- wl_shell_surface->surface, 200, 200);
+ wl_shell_surface->surface->resource, 200, 200);
}
struct wlr_xdg_surface_v6 *xdg_surface;
struct wlr_xdg_client_v6 *xdg_client;
@@ -345,21 +335,6 @@ static void handle_keyboard_key(struct keyboard_state *keyboard,
uint64_t time_usec) {
struct compositor_state *state = keyboard->compositor;
struct sample_state *sample = state->data;
-
- uint32_t depressed = xkb_state_serialize_mods(keyboard->xkb_state,
- XKB_STATE_MODS_DEPRESSED);
- uint32_t latched = xkb_state_serialize_mods(keyboard->xkb_state,
- XKB_STATE_MODS_LATCHED);
- uint32_t locked = xkb_state_serialize_mods(keyboard->xkb_state,
- XKB_STATE_MODS_LOCKED);
- uint32_t group = xkb_state_serialize_layout(keyboard->xkb_state,
- XKB_STATE_LAYOUT_EFFECTIVE);
-
- wlr_seat_keyboard_send_modifiers(sample->wl_seat, depressed, latched,
- locked, group);
- wlr_seat_keyboard_send_key(sample->wl_seat, (uint32_t)time_usec, keycode,
- key_state);
-
if (sym == XKB_KEY_Super_L || sym == XKB_KEY_Super_R) {
sample->mod_down = key_state == WLR_KEY_PRESSED;
}
@@ -525,6 +500,25 @@ static void handle_input_add(struct compositor_state *state,
example_config_configure_cursor(sample->config, sample->cursor,
sample->compositor);
}
+
+ if (device->type == WLR_INPUT_DEVICE_KEYBOARD) {
+ struct xkb_rule_names rules;
+ memset(&rules, 0, sizeof(rules));
+ rules.rules = getenv("XKB_DEFAULT_RULES");
+ rules.model = getenv("XKB_DEFAULT_MODEL");
+ rules.layout = getenv("XKB_DEFAULT_LAYOUT");
+ rules.variant = getenv("XKB_DEFAULT_VARIANT");
+ rules.options = getenv("XKB_DEFAULT_OPTIONS");
+ struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ if (!context) {
+ wlr_log(L_ERROR, "Failed to create XKB context");
+ exit(1);
+ }
+ wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(
+ context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
+ xkb_context_unref(context);
+ wlr_seat_attach_keyboard(sample->wl_seat, device);
+ }
}
static void handle_output_add(struct output_state *ostate) {
@@ -647,34 +641,22 @@ int main(int argc, char *argv[]) {
wlr_seat_set_capabilities(state.wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
| WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
- struct keyboard_state *kbstate;
- wl_list_for_each(kbstate, &compositor.keyboards, link) {
- char *keymap = xkb_keymap_get_as_string(kbstate->keymap,
- XKB_KEYMAP_FORMAT_TEXT_V1);
- state.keymap_size = strlen(keymap);
- state.keymap_fd = os_create_anonymous_file(state.keymap_size);
- void *ptr =
- mmap(NULL, state.keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
- state.keymap_fd, 0);
- strcpy(ptr, keymap);
- free(keymap);
- break;
- }
-
- wlr_seat_keyboard_set_keymap(state.wl_seat, state.keymap_fd,
- state.keymap_size);
-
state.xwayland = wlr_xwayland_create(compositor.display,
state.wlr_compositor);
compositor.keyboard_key_cb = handle_keyboard_key;
+ if (!wlr_backend_start(compositor.backend)) {
+ wlr_log(L_ERROR, "Failed to start backend");
+ wlr_backend_destroy(compositor.backend);
+ exit(1);
+ }
+
wl_display_run(compositor.display);
wl_list_remove(&state.new_xdg_surface_v6.link);
wlr_xwayland_destroy(state.xwayland);
- close(state.keymap_fd);
wlr_seat_destroy(state.wl_seat);
wlr_gamma_control_manager_destroy(state.gamma_control_manager);
wlr_data_device_manager_destroy(state.data_device_manager);