aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/drm/backend.c2
-rw-r--r--backend/drm/drm.c2
-rw-r--r--include/backend/drm/drm.h1
-rw-r--r--include/rootston/config.h27
-rw-r--r--include/rootston/view.h3
-rw-r--r--rootston/config.c81
-rw-r--r--rootston/cursor.c14
-rw-r--r--rootston/desktop.c16
-rw-r--r--rootston/keyboard.c46
-rw-r--r--rootston/wl_shell.c3
-rw-r--r--rootston/xdg_shell_v6.c3
-rw-r--r--rootston/xwayland.c3
-rw-r--r--xwayland/xwm.c2
13 files changed, 171 insertions, 32 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index 40b559e2..af2619ff 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -76,7 +76,7 @@ static void session_signal(struct wl_listener *listener, void *data) {
struct wlr_drm_plane *plane = conn->crtc->cursor;
drm->iface->crtc_set_cursor(drm, conn->crtc,
- plane ? plane->cursor_bo : NULL);
+ (plane && plane->cursor_enabled) ? plane->cursor_bo : NULL);
}
} else {
wlr_log(L_INFO, "DRM fd paused");
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 441ba24e..a3594bb0 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -505,8 +505,10 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
if (!buf && update_pixels) {
// Hide the cursor
+ plane->cursor_enabled = false;
return drm->iface->crtc_set_cursor(drm, crtc, NULL);
}
+ plane->cursor_enabled = true;
// We don't have a real cursor plane, so we make a fake one
if (!plane) {
diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h
index 4d23f963..a6dd247c 100644
--- a/include/backend/drm/drm.h
+++ b/include/backend/drm/drm.h
@@ -33,6 +33,7 @@ struct wlr_drm_plane {
float matrix[16];
struct wlr_texture *wlr_tex;
struct gbm_bo *cursor_bo;
+ bool cursor_enabled;
union wlr_drm_plane_props props;
};
diff --git a/include/rootston/config.h b/include/rootston/config.h
index 5fa4890f..ecbdd88b 100644
--- a/include/rootston/config.h
+++ b/include/rootston/config.h
@@ -26,6 +26,17 @@ struct binding_config {
struct wl_list link;
};
+struct keyboard_config {
+ char *name;
+ uint32_t meta_key;
+ char *rules;
+ char *model;
+ char *layout;
+ char *variant;
+ char *options;
+ struct wl_list link;
+};
+
struct roots_config {
bool xwayland;
// TODO: Multiple cursors, multiseat
@@ -34,13 +45,10 @@ struct roots_config {
struct wlr_box *mapped_box;
} cursor;
- struct {
- uint32_t meta_key;
- } keyboard;
-
struct wl_list outputs;
struct wl_list devices;
struct wl_list bindings;
+ struct wl_list keyboards;
char *config_path;
char *startup_cmd;
};
@@ -54,13 +62,20 @@ void roots_config_destroy(struct roots_config *config);
* NULL.
*/
struct output_config *config_get_output(struct roots_config *config,
- struct wlr_output *output);
+ struct wlr_output *output);
/**
* Get configuration for the device. If the device is not configured, returns
* NULL.
*/
struct device_config *config_get_device(struct roots_config *config,
- struct wlr_input_device *device);
+ struct wlr_input_device *device);
+
+/**
+ * Get configuration for the keyboard. If the keyboard is not configured,
+ * returns NULL. A NULL device returns the default config for keyboards.
+ */
+struct keyboard_config *config_get_keyboard(struct roots_config *config,
+ struct wlr_input_device *device);
#endif
diff --git a/include/rootston/view.h b/include/rootston/view.h
index 7d297329..9eb7065d 100644
--- a/include/rootston/view.h
+++ b/include/rootston/view.h
@@ -80,6 +80,7 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
void view_set_position(struct roots_view *view, double x, double y);
void view_close(struct roots_view *view);
bool view_center(struct roots_view *view);
-void view_initialize(struct roots_view *view);
+void view_setup(struct roots_view *view);
+void view_teardown(struct roots_view *view);
#endif
diff --git a/rootston/config.c b/rootston/config.c
index c9c892f9..6f81170b 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -147,8 +147,46 @@ void add_binding_config(struct wl_list *bindings, const char* combination,
}
}
+static void config_handle_keyboard(struct roots_config *config,
+ const char *device_name, const char *name, const char *value) {
+ struct keyboard_config *kc;
+ bool found = false;
+ wl_list_for_each(kc, &config->keyboards, link) {
+ if (strcmp(kc->name, device_name) == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ kc = calloc(1, sizeof(struct keyboard_config));
+ kc->name = strdup(device_name);
+ wl_list_insert(&config->keyboards, &kc->link);
+ }
+
+ if (strcmp(name, "meta-key") == 0) {
+ kc->meta_key = parse_modifier(value);
+ if (kc->meta_key == 0) {
+ wlr_log(L_ERROR, "got unknown meta key: %s", name);
+ }
+ } else if (strcmp(name, "rules") == 0) {
+ kc->rules = strdup(value);
+ } else if (strcmp(name, "model") == 0) {
+ kc->model = strdup(value);
+ } else if (strcmp(name, "layout") == 0) {
+ kc->layout = strdup(value);
+ } else if (strcmp(name, "variant") == 0) {
+ kc->variant = strdup(value);
+ } else if (strcmp(name, "options") == 0) {
+ kc->options = strdup(value);
+ } else {
+ wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
+ }
+}
+
static const char *output_prefix = "output:";
static const char *device_prefix = "device:";
+static const char *keyboard_prefix = "keyboard:";
static int config_ini_handler(void *user, const char *section, const char *name,
const char *value) {
@@ -219,9 +257,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
}
} else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) {
const char *device_name = section + strlen(device_prefix);
+
struct device_config *dc;
bool found = false;
-
wl_list_for_each(dc, &config->devices, link) {
if (strcmp(dc->name, device_name) == 0) {
found = true;
@@ -245,14 +283,10 @@ static int config_ini_handler(void *user, const char *section, const char *name,
wlr_log(L_ERROR, "got unknown device config: %s", name);
}
} else if (strcmp(section, "keyboard") == 0) {
- if (strcmp(name, "meta-key") == 0) {
- config->keyboard.meta_key = parse_modifier(value);
- if (config->keyboard.meta_key == 0) {
- wlr_log(L_ERROR, "got unknown meta key: %s", name);
- }
- } else {
- wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
- }
+ config_handle_keyboard(config, "", name, value);
+ } else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) {
+ const char *device_name = section + strlen(keyboard_prefix);
+ config_handle_keyboard(config, device_name, name, value);
} else if (strcmp(section, "bindings") == 0) {
add_binding_config(&config->bindings, name, value);
} else {
@@ -271,6 +305,7 @@ struct roots_config *parse_args(int argc, char *argv[]) {
config->xwayland = true;
wl_list_init(&config->outputs);
wl_list_init(&config->devices);
+ wl_list_init(&config->keyboards);
wl_list_init(&config->bindings);
int c;
@@ -305,10 +340,12 @@ struct roots_config *parse_args(int argc, char *argv[]) {
if (result == -1) {
wlr_log(L_DEBUG, "No config file found. Using sensible defaults.");
- config->keyboard.meta_key = WLR_MODIFIER_LOGO;
add_binding_config(&config->bindings, "Logo+Shift+E", "exit");
add_binding_config(&config->bindings, "Ctrl+q", "close");
add_binding_config(&config->bindings, "Alt+Tab", "next_window");
+ struct keyboard_config *kc = calloc(1, sizeof(struct keyboard_config));
+ kc->meta_key = WLR_MODIFIER_LOGO;
+ wl_list_insert(&config->keyboards, &kc->link);
} else if (result == -2) {
wlr_log(L_ERROR, "Could not allocate memory to parse config file");
exit(1);
@@ -335,6 +372,17 @@ void roots_config_destroy(struct roots_config *config) {
free(dc);
}
+ struct keyboard_config *kc, *ktmp = NULL;
+ wl_list_for_each_safe(kc, ktmp, &config->bindings, link) {
+ free(kc->name);
+ free(kc->rules);
+ free(kc->model);
+ free(kc->layout);
+ free(kc->variant);
+ free(kc->options);
+ free(kc);
+ }
+
struct binding_config *bc, *btmp = NULL;
wl_list_for_each_safe(bc, btmp, &config->bindings, link) {
free(bc->keysyms);
@@ -371,3 +419,16 @@ struct device_config *config_get_device(struct roots_config *config,
return NULL;
}
+
+struct keyboard_config *config_get_keyboard(struct roots_config *config,
+ struct wlr_input_device *device) {
+ struct keyboard_config *kc;
+ wl_list_for_each(kc, &config->keyboards, link) {
+ if ((device != NULL && strcmp(kc->name, device->name) == 0) ||
+ (device == NULL && strcmp(kc->name, "") == 0)) {
+ return kc;
+ }
+ }
+
+ return NULL;
+}
diff --git a/rootston/cursor.c b/rootston/cursor.c
index b55eab3f..7d2548eb 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -215,8 +215,16 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
event->orientation, event->delta);
}
-static bool is_meta_pressed(struct roots_input *input) {
- uint32_t meta_key = input->server->config->keyboard.meta_key;
+static bool is_meta_pressed(struct roots_input *input,
+ struct wlr_input_device *device) {
+ uint32_t meta_key = 0;
+ struct keyboard_config *config;
+ if ((config = config_get_keyboard(input->server->config, device))) {
+ meta_key = config->meta_key;
+ } else if (!meta_key && (config = config_get_keyboard(input->server->config,
+ NULL))) {
+ meta_key = config->meta_key;
+ }
if (meta_key == 0) {
return false;
}
@@ -241,7 +249,7 @@ static void do_cursor_button_press(struct roots_input *input,
struct roots_view *view = view_at(desktop,
input->cursor->x, input->cursor->y, &surface, &sx, &sy);
- if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input)) {
+ if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input, device)) {
set_view_focus(input, desktop, view);
switch (button) {
diff --git a/rootston/desktop.c b/rootston/desktop.c
index a9d38353..df92f0ba 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -109,14 +109,26 @@ bool view_center(struct roots_view *view) {
return true;
}
-void view_initialize(struct roots_view *view) {
+void view_setup(struct roots_view *view) {
view_center(view);
- struct roots_input *input = view->desktop->server->input;
+ struct roots_input *input = view->desktop->server->input;
set_view_focus(input, view->desktop, view);
wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
}
+void view_teardown(struct roots_view *view) {
+ struct wlr_list *views = view->desktop->views;
+ if (views->length < 2 || views->items[views->length-1] != view) {
+ return;
+ }
+
+ struct roots_view *prev_view = views->items[views->length-2];
+ struct roots_input *input = prev_view->desktop->server->input;
+ set_view_focus(input, prev_view->desktop, prev_view);
+ wlr_seat_keyboard_notify_enter(input->wl_seat, prev_view->wlr_surface);
+}
+
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) {
for (int i = desktop->views->length - 1; i >= 0; --i) {
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index 61604da0..142e9c71 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -125,6 +125,28 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
}
}
+static void keyboard_config_merge(struct keyboard_config *config,
+ struct keyboard_config *fallback) {
+ if (fallback == NULL) {
+ return;
+ }
+ if (config->rules == NULL) {
+ config->rules = fallback->rules;
+ }
+ if (config->model == NULL) {
+ config->model = fallback->model;
+ }
+ if (config->layout == NULL) {
+ config->layout = fallback->layout;
+ }
+ if (config->variant == NULL) {
+ config->variant = fallback->variant;
+ }
+ if (config->options == NULL) {
+ config->options = fallback->options;
+ }
+}
+
void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1);
if (keyboard == NULL) {
@@ -137,13 +159,27 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
wl_list_insert(&input->keyboards, &keyboard->link);
+ struct keyboard_config config;
+ memset(&config, 0, sizeof(config));
+ keyboard_config_merge(&config, config_get_keyboard(input->config, device));
+ keyboard_config_merge(&config, config_get_keyboard(input->config, NULL));
+
+ struct keyboard_config env_config = {
+ .rules = getenv("XKB_DEFAULT_RULES"),
+ .model = getenv("XKB_DEFAULT_MODEL"),
+ .layout = getenv("XKB_DEFAULT_LAYOUT"),
+ .variant = getenv("XKB_DEFAULT_VARIANT"),
+ .options = getenv("XKB_DEFAULT_OPTIONS"),
+ };
+ keyboard_config_merge(&config, &env_config);
+
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");
+ rules.rules = config.rules;
+ rules.model = config.model;
+ rules.layout = config.layout;
+ rules.variant = config.variant;
+ rules.options = config.options;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (context == NULL) {
wlr_log(L_ERROR, "Cannot create XKB context");
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 88397af8..e5366672 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -56,6 +56,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
+ view_teardown(roots_surface->view);
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link);
@@ -111,7 +112,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop;
roots_surface->view = view;
wlr_list_add(desktop->views, view);
- view_initialize(view);
+ view_setup(view);
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
// we need to map it relative to the parent
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index 95b20a8b..85871144 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -74,6 +74,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, destroy);
+ view_teardown(roots_xdg_surface->view);
wl_list_remove(&roots_xdg_surface->commit.link);
wl_list_remove(&roots_xdg_surface->destroy.link);
wl_list_remove(&roots_xdg_surface->request_move.link);
@@ -126,5 +127,5 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->view = view;
wlr_list_add(desktop->views, view);
- view_initialize(view);
+ view_setup(view);
}
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index 1149b966..8b7c32f4 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -43,6 +43,7 @@ static void close(struct roots_view *view) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
+ view_teardown(roots_surface->view);
wl_list_remove(&roots_surface->destroy.link);
view_destroy(roots_surface->view);
free(roots_surface);
@@ -101,6 +102,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
wlr_list_add(desktop->views, view);
if (!surface->override_redirect) {
- view_initialize(view);
+ view_setup(view);
}
}
diff --git a/xwayland/xwm.c b/xwayland/xwm.c
index 935fcd96..499d0bbf 100644
--- a/xwayland/xwm.c
+++ b/xwayland/xwm.c
@@ -16,8 +16,8 @@
const char *atom_map[ATOM_LAST] = {
"WL_SURFACE_ID",
"WM_DELETE_WINDOW",
- "WM_HINTS",
"WM_PROTOCOLS",
+ "WM_HINTS",
"WM_NORMAL_HINTS",
"WM_SIZE_HINTS",
"_MOTIF_WM_HINTS",