aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2017-11-17 23:29:47 +0100
committeremersion <contact@emersion.fr>2017-11-17 23:29:47 +0100
commit27937add762bb2594828ac678859bfdde4275f1e (patch)
treeaa9813fd534d019a5e967ffad31d153d30ae7fa1 /rootston
parent3e3209cba22c9a5a562acc5e543946408a36e2f4 (diff)
parentbf5640db128b930b38ebca2b1d8a79e028ad9f39 (diff)
Merge branch 'master' into laggy-move-resize
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c79
-rw-r--r--rootston/cursor.c581
-rw-r--r--rootston/desktop.c186
-rw-r--r--rootston/input.c144
-rw-r--r--rootston/keyboard.c277
-rw-r--r--rootston/main.c33
-rw-r--r--rootston/meson.build4
-rw-r--r--rootston/output.c165
-rw-r--r--rootston/pointer.c23
-rw-r--r--rootston/rootston.ini.example2
-rw-r--r--rootston/seat.c579
-rw-r--r--rootston/tablet_tool.c24
-rw-r--r--rootston/touch.c26
-rw-r--r--rootston/wl_shell.c41
-rw-r--r--rootston/xcursor.c24
-rw-r--r--rootston/xdg_shell_v6.c54
-rw-r--r--rootston/xwayland.c73
17 files changed, 1465 insertions, 850 deletions
diff --git a/rootston/config.c b/rootston/config.c
index dc7a4b1d..727b52d0 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -13,6 +13,7 @@
#include <wlr/types/wlr_box.h>
#include "rootston/config.h"
#include "rootston/input.h"
+#include "rootston/keyboard.h"
#include "rootston/ini.h"
static void usage(const char *name, int ret) {
@@ -114,7 +115,8 @@ static uint32_t parse_modifier(const char *symname) {
void add_binding_config(struct wl_list *bindings, const char* combination,
const char* command) {
- struct binding_config *bc = calloc(1, sizeof(struct binding_config));
+ struct roots_binding_config *bc =
+ calloc(1, sizeof(struct roots_binding_config));
xkb_keysym_t keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
char *symnames = strdup(combination);
@@ -150,7 +152,7 @@ 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;
+ struct roots_keyboard_config *kc;
bool found = false;
wl_list_for_each(kc, &config->keyboards, link) {
if (strcmp(kc->name, device_name) == 0) {
@@ -160,7 +162,7 @@ static void config_handle_keyboard(struct roots_config *config,
}
if (!found) {
- kc = calloc(1, sizeof(struct keyboard_config));
+ kc = calloc(1, sizeof(struct roots_keyboard_config));
kc->name = strdup(device_name);
wl_list_insert(&config->keyboards, &kc->link);
}
@@ -193,20 +195,20 @@ static int config_ini_handler(void *user, const char *section, const char *name,
const char *value) {
struct roots_config *config = user;
if (strcmp(section, "core") == 0) {
- if (strcmp(name, "xwayland") == 0) {
- if (strcasecmp(value, "true") == 0) {
- config->xwayland = true;
- } else if (strcasecmp(value, "false") == 0) {
- config->xwayland = false;
- } else {
- wlr_log(L_ERROR, "got unknown xwayland value: %s", value);
- }
- } else {
- wlr_log(L_ERROR, "got unknown core config: %s", name);
- }
+ if (strcmp(name, "xwayland") == 0) {
+ if (strcasecmp(value, "true") == 0) {
+ config->xwayland = true;
+ } else if (strcasecmp(value, "false") == 0) {
+ config->xwayland = false;
+ } else {
+ wlr_log(L_ERROR, "got unknown xwayland value: %s", value);
+ }
+ } else {
+ wlr_log(L_ERROR, "got unknown core config: %s", name);
+ }
} else if (strncmp(output_prefix, section, strlen(output_prefix)) == 0) {
const char *output_name = section + strlen(output_prefix);
- struct output_config *oc;
+ struct roots_output_config *oc;
bool found = false;
wl_list_for_each(oc, &config->outputs, link) {
@@ -217,9 +219,10 @@ static int config_ini_handler(void *user, const char *section, const char *name,
}
if (!found) {
- oc = calloc(1, sizeof(struct output_config));
+ oc = calloc(1, sizeof(struct roots_output_config));
oc->name = strdup(output_name);
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ oc->scale = 1;
wl_list_insert(&config->outputs, &oc->link);
}
@@ -227,6 +230,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
oc->x = strtol(value, NULL, 10);
} else if (strcmp(name, "y") == 0) {
oc->y = strtol(value, NULL, 10);
+ } else if (strcmp(name, "scale") == 0) {
+ oc->scale = strtol(value, NULL, 10);
+ assert(oc->scale >= 1);
} else if (strcmp(name, "rotate") == 0) {
if (strcmp(value, "normal") == 0) {
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
@@ -276,7 +282,7 @@ 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;
+ struct roots_device_config *dc;
bool found = false;
wl_list_for_each(dc, &config->devices, link) {
if (strcmp(dc->name, device_name) == 0) {
@@ -286,8 +292,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
}
if (!found) {
- dc = calloc(1, sizeof(struct device_config));
+ dc = calloc(1, sizeof(struct roots_device_config));
dc->name = strdup(device_name);
+ dc->seat = strdup("seat0");
wl_list_insert(&config->devices, &dc->link);
}
@@ -297,12 +304,16 @@ static int config_ini_handler(void *user, const char *section, const char *name,
} else if (strcmp(name, "geometry") == 0) {
free(dc->mapped_box);
dc->mapped_box = parse_geometry(value);
+ } else if (strcmp(name, "seat") == 0) {
+ free(dc->seat);
+ dc->seat = strdup(value);
} else {
wlr_log(L_ERROR, "got unknown device config: %s", name);
}
} else if (strcmp(section, "keyboard") == 0) {
config_handle_keyboard(config, "", name, value);
- } else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) {
+ } 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) {
@@ -314,7 +325,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
return 1;
}
-struct roots_config *parse_args(int argc, char *argv[]) {
+struct roots_config *roots_config_create_from_args(int argc, char *argv[]) {
struct roots_config *config = calloc(1, sizeof(struct roots_config));
if (config == NULL) {
return NULL;
@@ -361,7 +372,8 @@ struct roots_config *parse_args(int argc, char *argv[]) {
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));
+ struct roots_keyboard_config *kc =
+ calloc(1, sizeof(struct roots_keyboard_config));
kc->meta_key = WLR_MODIFIER_LOGO;
kc->name = strdup("");
wl_list_insert(&config->keyboards, &kc->link);
@@ -377,22 +389,23 @@ struct roots_config *parse_args(int argc, char *argv[]) {
}
void roots_config_destroy(struct roots_config *config) {
- struct output_config *oc, *otmp = NULL;
+ struct roots_output_config *oc, *otmp = NULL;
wl_list_for_each_safe(oc, otmp, &config->outputs, link) {
free(oc->name);
free(oc);
}
- struct device_config *dc, *dtmp = NULL;
+ struct roots_device_config *dc, *dtmp = NULL;
wl_list_for_each_safe(dc, dtmp, &config->devices, link) {
free(dc->name);
+ free(dc->seat);
free(dc->mapped_output);
free(dc->mapped_box);
free(dc);
}
- struct keyboard_config *kc, *ktmp = NULL;
- wl_list_for_each_safe(kc, ktmp, &config->bindings, link) {
+ struct roots_keyboard_config *kc, *ktmp = NULL;
+ wl_list_for_each_safe(kc, ktmp, &config->keyboards, link) {
free(kc->name);
free(kc->rules);
free(kc->model);
@@ -402,7 +415,7 @@ void roots_config_destroy(struct roots_config *config) {
free(kc);
}
- struct binding_config *bc, *btmp = NULL;
+ struct roots_binding_config *bc, *btmp = NULL;
wl_list_for_each_safe(bc, btmp, &config->bindings, link) {
free(bc->keysyms);
free(bc->command);
@@ -415,9 +428,9 @@ void roots_config_destroy(struct roots_config *config) {
free(config);
}
-struct output_config *config_get_output(struct roots_config *config,
+struct roots_output_config *roots_config_get_output(struct roots_config *config,
struct wlr_output *output) {
- struct output_config *o_config;
+ struct roots_output_config *o_config;
wl_list_for_each(o_config, &config->outputs, link) {
if (strcmp(o_config->name, output->name) == 0) {
return o_config;
@@ -427,9 +440,9 @@ struct output_config *config_get_output(struct roots_config *config,
return NULL;
}
-struct device_config *config_get_device(struct roots_config *config,
+struct roots_device_config *roots_config_get_device(struct roots_config *config,
struct wlr_input_device *device) {
- struct device_config *d_config;
+ struct roots_device_config *d_config;
wl_list_for_each(d_config, &config->devices, link) {
if (strcmp(d_config->name, device->name) == 0) {
return d_config;
@@ -439,9 +452,9 @@ 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;
+struct roots_keyboard_config *roots_config_get_keyboard(
+ struct roots_config *config, struct wlr_input_device *device) {
+ struct roots_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)) {
diff --git a/rootston/cursor.c b/rootston/cursor.c
index b153e8c8..5949a364 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -1,150 +1,93 @@
#define _XOPEN_SOURCE 700
#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
#include <math.h>
-#include <assert.h>
#ifdef __linux__
#include <linux/input-event-codes.h>
#elif __FreeBSD__
#include <dev/evdev/input-event-codes.h>
#endif
-#include <wayland-server.h>
-#include <wlr/types/wlr_cursor.h>
+#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/util/log.h>
-#include <wlr/types/wlr_data_device.h>
-#include "rootston/config.h"
-#include "rootston/input.h"
-#include "rootston/desktop.h"
-#include "rootston/view.h"
+#include "rootston/xcursor.h"
+#include "rootston/cursor.h"
-const struct roots_input_event *get_input_event(struct roots_input *input,
- uint32_t serial) {
- size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
- for (size_t i = 0; i < len; ++i) {
- if (input->input_events[i].cursor
- && input->input_events[i].serial == serial) {
- return &input->input_events[i];
- }
- }
- return NULL;
-}
-
-static void cursor_set_xcursor_image(struct roots_input *input,
- struct wlr_xcursor_image *image) {
- wlr_cursor_set_image(input->cursor, image->buffer, image->width,
- image->width, image->height, image->hotspot_x, image->hotspot_y);
-}
-
-void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
- struct roots_view *view) {
- input->mode = ROOTS_CURSOR_MOVE;
- input->offs_x = cursor->x;
- input->offs_y = cursor->y;
- input->view_x = view->x;
- input->view_y = view->y;
- wlr_seat_pointer_clear_focus(input->wl_seat);
-
- struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme);
- if (xcursor != NULL) {
- cursor_set_xcursor_image(input, xcursor->images[0]);
+struct roots_cursor *roots_cursor_create(struct roots_seat *seat) {
+ struct roots_cursor *cursor = calloc(1, sizeof(struct roots_cursor));
+ if (!cursor) {
+ return NULL;
}
-}
-
-void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
- struct roots_view *view, uint32_t edges) {
- input->mode = ROOTS_CURSOR_RESIZE;
- input->offs_x = cursor->x;
- input->offs_y = cursor->y;
- input->view_x = view->x;
- input->view_y = view->y;
- struct wlr_box size;
- view_get_size(view, &size);
- input->view_width = size.width;
- input->view_height = size.height;
- input->resize_edges = edges;
- wlr_seat_pointer_clear_focus(input->wl_seat);
-
- struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges);
- if (xcursor != NULL) {
- cursor_set_xcursor_image(input, xcursor->images[0]);
+ cursor->cursor = wlr_cursor_create();
+ if (!cursor->cursor) {
+ free(cursor);
+ return NULL;
}
+ return cursor;
}
-void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor,
- struct roots_view *view) {
- input->mode = ROOTS_CURSOR_ROTATE;
- input->offs_x = cursor->x;
- input->offs_y = cursor->y;
- input->view_rotation = view->rotation;
- wlr_seat_pointer_clear_focus(input->wl_seat);
-
- struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme);
- if (xcursor != NULL) {
- cursor_set_xcursor_image(input, xcursor->images[0]);
- }
+void roots_cursor_destroy(struct roots_cursor *cursor) {
+ // TODO
}
-void cursor_update_position(struct roots_input *input, uint32_t time) {
- struct roots_desktop *desktop = input->server->desktop;
+static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) {
+ struct roots_desktop *desktop = cursor->seat->input->server->desktop;
+ struct roots_seat *seat = cursor->seat;
struct roots_view *view;
struct wlr_surface *surface;
double sx, sy;
- switch (input->mode) {
+ switch (cursor->mode) {
case ROOTS_CURSOR_PASSTHROUGH:
- view = view_at(desktop, input->cursor->x, input->cursor->y,
+ view = view_at(desktop, cursor->cursor->x, cursor->cursor->y,
&surface, &sx, &sy);
- bool set_compositor_cursor = !view && input->cursor_client;
+ bool set_compositor_cursor = !view && cursor->cursor_client;
if (view) {
struct wl_client *view_client =
wl_resource_get_client(view->wlr_surface->resource);
- set_compositor_cursor = view_client != input->cursor_client;
+ set_compositor_cursor = view_client != cursor->cursor_client;
}
if (set_compositor_cursor) {
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
- cursor_set_xcursor_image(input, xcursor->images[0]);
- input->cursor_client = NULL;
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ ROOTS_XCURSOR_DEFAULT, cursor->cursor);
+ cursor->cursor_client = NULL;
}
if (view) {
- wlr_seat_pointer_notify_enter(input->wl_seat, surface, sx, sy);
- wlr_seat_pointer_notify_motion(input->wl_seat, time, sx, sy);
+ wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy);
+ wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy);
} else {
- wlr_seat_pointer_clear_focus(input->wl_seat);
+ wlr_seat_pointer_clear_focus(seat->seat);
}
break;
case ROOTS_CURSOR_MOVE:
- if (input->active_view) {
- double dx = input->cursor->x - input->offs_x;
- double dy = input->cursor->y - input->offs_y;
- view_move(input->active_view, input->view_x + dx,
- input->view_y + dy);
+ if (seat->focus) {
+ double dx = cursor->cursor->x - cursor->offs_x;
+ double dy = cursor->cursor->y - cursor->offs_y;
+ view_move(seat->focus, cursor->view_x + dx,
+ cursor->view_y + dy);
}
break;
case ROOTS_CURSOR_RESIZE:
- if (input->active_view) {
- double dx = input->cursor->x - input->offs_x;
- double dy = input->cursor->y - input->offs_y;
- double active_x = input->active_view->x;
- double active_y = input->active_view->y;
- int width = input->view_width;
- int height = input->view_height;
- if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
- active_y = input->view_y + dy;
+ if (seat->focus) {
+ double dx = cursor->cursor->x - cursor->offs_x;
+ double dy = cursor->cursor->y - cursor->offs_y;
+ double active_x = seat->focus->x;
+ double active_y = seat->focus->y;
+ int width = cursor->view_width;
+ int height = cursor->view_height;
+ if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
+ active_y = cursor->view_y + dy;
height -= dy;
if (height < 0) {
active_y += height;
}
- } else if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
+ } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
height += dy;
}
- if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
- active_x = input->view_x + dx;
+ if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
+ active_x = cursor->view_x + dx;
width -= dx;
if (width < 0) {
active_x += width;
}
- } else if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
+ } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
width += dx;
}
@@ -155,132 +98,51 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
height = 0;
}
- if (active_x != input->active_view->x ||
- active_y != input->active_view->y) {
- view_move_resize(input->active_view, active_x, active_y,
+ if (active_x != seat->focus->x ||
+ active_y != seat->focus->y) {
+ view_move_resize(seat->focus, active_x, active_y,
width, height);
} else {
- view_resize(input->active_view, width, height);
+ view_resize(seat->focus, width, height);
}
}
break;
case ROOTS_CURSOR_ROTATE:
- if (input->active_view) {
- struct roots_view *view = input->active_view;
+ if (seat->focus) {
+ struct roots_view *view = seat->focus;
int ox = view->x + view->wlr_surface->current->width/2,
oy = view->y + view->wlr_surface->current->height/2;
- int ux = input->offs_x - ox,
- uy = input->offs_y - oy;
- int vx = input->cursor->x - ox,
- vy = input->cursor->y - oy;
+ int ux = cursor->offs_x - ox,
+ uy = cursor->offs_y - oy;
+ int vx = cursor->cursor->x - ox,
+ vy = cursor->cursor->y - oy;
float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy);
int steps = 12;
angle = round(angle/M_PI*steps) / (steps/M_PI);
- view->rotation = input->view_rotation + angle;
+ view->rotation = cursor->view_rotation + angle;
}
break;
}
-}
-
-void set_view_focus(struct roots_input *input, struct roots_desktop *desktop,
- struct roots_view *view) {
- if (input->active_view == view) {
- return;
- }
- input->active_view = view;
- input->mode = ROOTS_CURSOR_PASSTHROUGH;
- if (!view) {
- return;
- }
-
- if (view->type == ROOTS_XWAYLAND_VIEW &&
- view->xwayland_surface->override_redirect) {
- return;
- }
-
- size_t index = 0;
- for (size_t i = 0; i < desktop->views->length; ++i) {
- struct roots_view *_view = desktop->views->items[i];
- if (_view != view) {
- view_activate(_view, false);
- } else {
- index = i;
- }
- }
- view_activate(view, true);
- // TODO: list_swap
- wlr_list_del(desktop->views, index);
- wlr_list_add(desktop->views, view);
- wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
-}
-
-static void handle_cursor_motion(struct wl_listener *listener, void *data) {
- struct roots_input *input = wl_container_of(listener, input, cursor_motion);
- struct wlr_event_pointer_motion *event = data;
- wlr_cursor_move(input->cursor, event->device,
- event->delta_x, event->delta_y);
- cursor_update_position(input, event->time_msec);
-}
-
-static void handle_cursor_motion_absolute(struct wl_listener *listener,
- void *data) {
- struct roots_input *input = wl_container_of(listener,
- input, cursor_motion_absolute);
- struct wlr_event_pointer_motion_absolute *event = data;
- wlr_cursor_warp_absolute(input->cursor, event->device,
- event->x_mm / event->width_mm, event->y_mm / event->height_mm);
- cursor_update_position(input, event->time_msec);
-}
-
-static void handle_cursor_axis(struct wl_listener *listener, void *data) {
- struct roots_input *input =
- wl_container_of(listener, input, cursor_axis);
- struct wlr_event_pointer_axis *event = data;
- wlr_seat_pointer_notify_axis(input->wl_seat, event->time_msec,
- event->orientation, event->delta);
-}
-
-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;
- }
- struct roots_keyboard *keyboard;
- wl_list_for_each(keyboard, &input->keyboards, link) {
- uint32_t modifiers =
- wlr_keyboard_get_modifiers(keyboard->device->keyboard);
- if ((modifiers ^ meta_key) == 0) {
- return true;
- }
- }
- return false;
}
-static void do_cursor_button_press(struct roots_input *input,
- struct wlr_cursor *cursor, struct wlr_input_device *device,
- uint32_t time, uint32_t button, uint32_t state) {
- struct roots_desktop *desktop = input->server->desktop;
+static void roots_cursor_press_button(struct roots_cursor *cursor,
+ struct wlr_input_device *device, uint32_t time, uint32_t button,
+ uint32_t state) {
+ struct roots_seat *seat = cursor->seat;
+ struct roots_desktop *desktop = seat->input->server->desktop;
struct wlr_surface *surface;
double sx, sy;
struct roots_view *view = view_at(desktop,
- input->cursor->x, input->cursor->y, &surface, &sx, &sy);
+ cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
- if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input, device)) {
- set_view_focus(input, desktop, view);
+ if (state == WLR_BUTTON_PRESSED && view && roots_seat_has_meta_pressed(seat)) {
+ roots_seat_focus_view(seat, view);
uint32_t edges;
switch (button) {
case BTN_LEFT:
- view_begin_move(input, cursor, view);
+ roots_seat_begin_move(seat, view);
break;
case BTN_RIGHT:
edges = 0;
@@ -294,117 +156,154 @@ static void do_cursor_button_press(struct roots_input *input,
} else {
edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM;
}
- view_begin_resize(input, cursor, view, edges);
+ roots_seat_begin_resize(seat, view, edges);
break;
case BTN_MIDDLE:
- view_begin_rotate(input, cursor, view);
+ roots_seat_begin_rotate(seat, view);
break;
}
return;
}
- uint32_t serial = wlr_seat_pointer_notify_button(input->wl_seat, time, button,
- state);
+ uint32_t serial =
+ wlr_seat_pointer_notify_button(seat->seat, time, button, state);
int i;
switch (state) {
case WLR_BUTTON_RELEASED:
- set_view_focus(input, desktop, NULL);
- cursor_update_position(input, time);
+ seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
+ roots_cursor_update_position(cursor, time);
break;
case WLR_BUTTON_PRESSED:
- i = input->input_events_idx;
- input->input_events[i].serial = serial;
- input->input_events[i].cursor = cursor;
- input->input_events[i].device = device;
- input->input_events_idx = (i + 1)
- % (sizeof(input->input_events) / sizeof(input->input_events[0]));
- set_view_focus(input, desktop, view);
+ i = cursor->input_events_idx;
+ cursor->input_events[i].serial = serial;
+ cursor->input_events[i].cursor = cursor->cursor;
+ cursor->input_events[i].device = device;
+ cursor->input_events_idx = (i + 1)
+ % (sizeof(cursor->input_events) / sizeof(cursor->input_events[0]));
+ roots_seat_focus_view(seat, view);
break;
}
}
-static void handle_cursor_button(struct wl_listener *listener, void *data) {
- struct roots_input *input = wl_container_of(listener, input, cursor_button);
- struct wlr_event_pointer_button *event = data;
- do_cursor_button_press(input, input->cursor, event->device,
- event->time_msec, event->button, event->state);
+void roots_cursor_handle_motion(struct roots_cursor *cursor,
+ struct wlr_event_pointer_motion *event) {
+ wlr_cursor_move(cursor->cursor, event->device,
+ event->delta_x, event->delta_y);
+ roots_cursor_update_position(cursor, event->time_msec);
+}
+
+void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
+ struct wlr_event_pointer_motion_absolute *event) {
+ wlr_cursor_warp_absolute(cursor->cursor, event->device,
+ event->x_mm / event->width_mm, event->y_mm / event->height_mm);
+ roots_cursor_update_position(cursor, event->time_msec);
+}
+
+void roots_cursor_handle_button(struct roots_cursor *cursor,
+ struct wlr_event_pointer_button *event) {
+ roots_cursor_press_button(cursor, event->device, event->time_msec,
+ event->button, event->state);
}
-static void handle_touch_down(struct wl_listener *listener, void *data) {
- struct wlr_event_touch_down *event = data;
- struct roots_input *input =
- wl_container_of(listener, input, cursor_touch_down);
+void roots_cursor_handle_axis(struct roots_cursor *cursor,
+ struct wlr_event_pointer_axis *event) {
+ wlr_seat_pointer_notify_axis(cursor->seat->seat, event->time_msec,
+ event->orientation, event->delta);
+}
+
+void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
+ struct wlr_event_touch_down *event) {
struct roots_touch_point *point =
calloc(1, sizeof(struct roots_touch_point));
+ if (!point) {
+ wlr_log(L_ERROR, "could not allocate memory for touch point");
+ return;
+ }
+
point->device = event->device->data;
point->slot = event->slot;
point->x = event->x_mm / event->width_mm;
point->y = event->y_mm / event->height_mm;
- wlr_cursor_warp_absolute(input->cursor, event->device, point->x, point->y);
- cursor_update_position(input, event->time_msec);
- wl_list_insert(&input->touch_points, &point->link);
- do_cursor_button_press(input, input->cursor, event->device,
+ wlr_cursor_warp_absolute(cursor->cursor, event->device, point->x, point->y);
+ roots_cursor_update_position(cursor, event->time_msec);
+ wl_list_insert(&cursor->touch_points, &point->link);
+ roots_cursor_press_button(cursor, event->device,
event->time_msec, BTN_LEFT, 1);
}
-static void handle_touch_up(struct wl_listener *listener, void *data) {
- struct wlr_event_touch_up *event = data;
- struct roots_input *input =
- wl_container_of(listener, input, cursor_touch_up);
+void roots_cursor_handle_touch_up(struct roots_cursor *cursor,
+ struct wlr_event_touch_up *event) {
struct roots_touch_point *point;
- wl_list_for_each(point, &input->touch_points, link) {
+ wl_list_for_each(point, &cursor->touch_points, link) {
if (point->slot == event->slot) {
wl_list_remove(&point->link);
+ free(point);
break;
}
}
- do_cursor_button_press(input, input->cursor, event->device,
+ roots_cursor_press_button(cursor, event->device,
event->time_msec, BTN_LEFT, 0);
}
-static void handle_touch_motion(struct wl_listener *listener, void *data) {
- struct wlr_event_touch_motion *event = data;
- struct roots_input *input =
- wl_container_of(listener, input, cursor_touch_motion);
+void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
+ struct wlr_event_touch_motion *event) {
struct roots_touch_point *point;
- wl_list_for_each(point, &input->touch_points, link) {
+ wl_list_for_each(point, &cursor->touch_points, link) {
if (point->slot == event->slot) {
point->x = event->x_mm / event->width_mm;
point->y = event->y_mm / event->height_mm;
- wlr_cursor_warp_absolute(input->cursor, event->device,
+ wlr_cursor_warp_absolute(cursor->cursor, event->device,
point->x, point->y);
- cursor_update_position(input, event->time_msec);
+ roots_cursor_update_position(cursor, event->time_msec);
break;
}
}
}
-static void handle_tool_axis(struct wl_listener *listener, void *data) {
- struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis);
- struct wlr_event_tablet_tool_axis *event = data;
+void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
+ struct wlr_event_tablet_tool_axis *event) {
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
- wlr_cursor_warp_absolute(input->cursor, event->device,
+ wlr_cursor_warp_absolute(cursor->cursor, event->device,
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
- cursor_update_position(input, event->time_msec);
+ roots_cursor_update_position(cursor, event->time_msec);
+ } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
+ wlr_cursor_warp_absolute(cursor->cursor, event->device,
+ event->x_mm / event->width_mm, -1);
+ roots_cursor_update_position(cursor, event->time_msec);
+ } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
+ wlr_cursor_warp_absolute(cursor->cursor, event->device,
+ -1, event->y_mm / event->height_mm);
+ roots_cursor_update_position(cursor, event->time_msec);
}
}
-static void handle_tool_tip(struct wl_listener *listener, void *data) {
- struct roots_input *input = wl_container_of(listener, input, cursor_tool_tip);
- struct wlr_event_tablet_tool_tip *event = data;
- do_cursor_button_press(input, input->cursor, event->device,
+void roots_cursor_handle_tool_tip(struct roots_cursor *cursor,
+ struct wlr_event_tablet_tool_tip *event) {
+ roots_cursor_press_button(cursor, event->device,
event->time_msec, BTN_LEFT, event->state);
}
-static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) {
- struct roots_drag_icon *drag_icon =
- wl_container_of(listener, drag_icon, surface_destroy);
- wl_list_remove(&drag_icon->link);
- wl_list_remove(&drag_icon->surface_destroy.link);
- wl_list_remove(&drag_icon->surface_commit.link);
- free(drag_icon);
+void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,
+ struct wlr_seat_pointer_request_set_cursor_event *event) {
+ struct wlr_surface *focused_surface =
+ event->seat_client->seat->pointer_state.focused_surface;
+ bool has_focused = focused_surface != NULL && focused_surface->resource != NULL;
+ struct wl_client *focused_client = NULL;
+ if (has_focused) {
+ focused_client = wl_resource_get_client(focused_surface->resource);
+ }
+ if (event->seat_client->client != focused_client ||
+ cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client");
+ return;
+ }
+
+ wlr_log(L_DEBUG, "Setting client cursor");
+ wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x,
+ event->hotspot_y);
+ cursor->cursor_client = event->seat_client->client;
}
static void handle_drag_icon_commit(struct wl_listener *listener, void *data) {
@@ -414,17 +313,23 @@ static void handle_drag_icon_commit(struct wl_listener *listener, void *data) {
drag_icon->sy += drag_icon->surface->current->sy;
}
-static void handle_pointer_grab_begin(struct wl_listener *listener,
- void *data) {
- struct roots_input *input =
- wl_container_of(listener, input, pointer_grab_begin);
- struct wlr_seat_pointer_grab *grab = data;
+static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) {
+ struct roots_drag_icon *drag_icon =
+ wl_container_of(listener, drag_icon, surface_destroy);
+ wl_list_remove(&drag_icon->link);
+ wl_list_remove(&drag_icon->surface_destroy.link);
+ wl_list_remove(&drag_icon->surface_commit.link);
+ free(drag_icon);
+}
+void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor,
+ struct wlr_seat_pointer_grab *grab) {
+ struct roots_seat *seat = cursor->seat;
if (grab->interface == &wlr_data_device_pointer_drag_interface) {
struct wlr_drag *drag = grab->data;
if (drag->icon) {
struct roots_drag_icon *iter_icon;
- wl_list_for_each(iter_icon, &input->drag_icons, link) {
+ wl_list_for_each(iter_icon, &seat->drag_icons, link) {
if (iter_icon->surface == drag->icon) {
// already in the list
return;
@@ -435,7 +340,7 @@ static void handle_pointer_grab_begin(struct wl_listener *listener,
calloc(1, sizeof(struct roots_drag_icon));
drag_icon->mapped = true;
drag_icon->surface = drag->icon;
- wl_list_insert(&input->drag_icons, &drag_icon->link);
+ wl_list_insert(&seat->drag_icons, &drag_icon->link);
wl_signal_add(&drag->icon->events.destroy,
&drag_icon->surface_destroy);
@@ -448,155 +353,17 @@ static void handle_pointer_grab_begin(struct wl_listener *listener,
}
}
-static void handle_pointer_grab_end(struct wl_listener *listener, void *data) {
- struct roots_input *input =
- wl_container_of(listener, input, pointer_grab_end);
- struct wlr_seat_pointer_grab *grab = data;
-
+void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor,
+ struct wlr_seat_pointer_grab *grab) {
if (grab->interface == &wlr_data_device_pointer_drag_interface) {
struct wlr_drag *drag = grab->data;
struct roots_drag_icon *icon;
- wl_list_for_each(icon, &input->drag_icons, link) {
+ wl_list_for_each(icon, &cursor->seat->drag_icons, link) {
if (icon->surface == drag->icon) {
icon->mapped = false;
}
}
}
- cursor_update_position(input, 0);
-}
-
-static void handle_request_set_cursor(struct wl_listener *listener,
- void *data) {
- struct roots_input *input = wl_container_of(listener, input,
- request_set_cursor);
- struct wlr_seat_pointer_request_set_cursor_event *event = data;
-
- struct wlr_surface *focused_surface =
- event->seat_client->seat->pointer_state.focused_surface;
- bool ok = focused_surface != NULL && focused_surface->resource != NULL;
- if (ok) {
- struct wl_client *focused_client =
- wl_resource_get_client(focused_surface->resource);
- ok = event->seat_client->client == focused_client;
- }
- if (!ok || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
- wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client");
- return;
- }
-
- wlr_log(L_DEBUG, "Setting client cursor");
- wlr_cursor_set_surface(input->cursor, event->surface, event->hotspot_x,
- event->hotspot_y);
- input->cursor_client = event->seat_client->client;
-}
-
-void cursor_initialize(struct roots_input *input) {
- struct wlr_cursor *cursor = input->cursor;
-
- // TODO: Does this belong here
- wl_list_init(&input->touch_points);
-
- wl_signal_add(&cursor->events.motion, &input->cursor_motion);
- input->cursor_motion.notify = handle_cursor_motion;
-
- wl_signal_add(&cursor->events.motion_absolute,
- &input->cursor_motion_absolute);
- input->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
-
- wl_signal_add(&cursor->events.button, &input->cursor_button);
- input->cursor_button.notify = handle_cursor_button;
-
- wl_signal_add(&cursor->events.axis, &input->cursor_axis);
- input->cursor_axis.notify = handle_cursor_axis;
-
- wl_signal_add(&cursor->events.touch_down, &input->cursor_touch_down);
- input->cursor_touch_down.notify = handle_touch_down;
-
- wl_signal_add(&cursor->events.touch_up, &input->cursor_touch_up);
- input->cursor_touch_up.notify = handle_touch_up;
-
- wl_signal_add(&cursor->events.touch_motion, &input->cursor_touch_motion);
- input->cursor_touch_motion.notify = handle_touch_motion;
-
- wl_signal_add(&cursor->events.tablet_tool_axis, &input->cursor_tool_axis);
- input->cursor_tool_axis.notify = handle_tool_axis;
-
- wl_signal_add(&cursor->events.tablet_tool_tip, &input->cursor_tool_tip);
- input->cursor_tool_tip.notify = handle_tool_tip;
-
- wl_signal_add(&input->wl_seat->events.pointer_grab_end, &input->pointer_grab_end);
- input->pointer_grab_end.notify = handle_pointer_grab_end;
-
- wl_signal_add(&input->wl_seat->events.pointer_grab_begin, &input->pointer_grab_begin);
- input->pointer_grab_begin.notify = handle_pointer_grab_begin;
-
- wl_list_init(&input->request_set_cursor.link);
-
- wl_signal_add(&input->wl_seat->events.request_set_cursor,
- &input->request_set_cursor);
- input->request_set_cursor.notify = handle_request_set_cursor;
-}
-
-static void reset_device_mappings(struct roots_config *config,
- struct wlr_cursor *cursor, struct wlr_input_device *device) {
- wlr_cursor_map_input_to_output(cursor, device, NULL);
- struct device_config *dconfig;
- if ((dconfig = config_get_device(config, device))) {
- wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box);
- }
-}
-
-static void set_device_output_mappings(struct roots_config *config,
- struct wlr_cursor *cursor, struct wlr_output *output,
- struct wlr_input_device *device) {
- struct device_config *dconfig;
- dconfig = config_get_device(config, device);
- if (dconfig && dconfig->mapped_output &&
- strcmp(dconfig->mapped_output, output->name) == 0) {
- wlr_cursor_map_input_to_output(cursor, device, output);
- }
-}
-
-void cursor_load_config(struct roots_config *config,
- struct wlr_cursor *cursor,
- struct roots_input *input,
- struct roots_desktop *desktop) {
- struct roots_pointer *pointer;
- struct roots_touch *touch;
- struct roots_tablet_tool *tablet_tool;
- struct roots_output *output;
-
- // reset mappings
- wlr_cursor_map_to_output(cursor, NULL);
- wl_list_for_each(pointer, &input->pointers, link) {
- reset_device_mappings(config, cursor, pointer->device);
- }
- wl_list_for_each(touch, &input->touch, link) {
- reset_device_mappings(config, cursor, touch->device);
- }
- wl_list_for_each(tablet_tool, &input->tablet_tools, link) {
- reset_device_mappings(config, cursor, tablet_tool->device);
- }
-
- // configure device to output mappings
- const char *mapped_output = config->cursor.mapped_output;
- wl_list_for_each(output, &desktop->outputs, link) {
- if (mapped_output && strcmp(mapped_output, output->wlr_output->name) == 0) {
- wlr_cursor_map_to_output(cursor, output->wlr_output);
- }
-
- wl_list_for_each(pointer, &input->pointers, link) {
- set_device_output_mappings(config, cursor, output->wlr_output,
- pointer->device);
- }
- wl_list_for_each(tablet_tool, &input->tablet_tools, link) {
- set_device_output_mappings(config, cursor, output->wlr_output,
- tablet_tool->device);
- }
- wl_list_for_each(touch, &input->touch, link) {
- set_device_output_mappings(config, cursor, output->wlr_output,
- touch->device);
- }
- }
+ roots_cursor_update_position(cursor, 0);
}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 29f78ac7..1695d007 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -10,19 +10,25 @@
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_wl_shell.h>
+#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/util/log.h>
#include <server-decoration-protocol.h>
#include "rootston/server.h"
-#include "rootston/server.h"
+#include "rootston/seat.h"
+#include "rootston/xcursor.h"
+// TODO replace me with a signal
void view_destroy(struct roots_view *view) {
struct roots_desktop *desktop = view->desktop;
struct roots_input *input = desktop->server->input;
- if (input->active_view == view) {
- input->active_view = NULL;
- input->mode = ROOTS_CURSOR_PASSTHROUGH;
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (seat->focus == view) {
+ seat->focus = NULL;
+ seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
+ }
}
for (size_t i = 0; i < desktop->views->length; ++i) {
@@ -35,36 +41,64 @@ void view_destroy(struct roots_view *view) {
free(view);
}
-void view_get_size(struct roots_view *view, struct wlr_box *box) {
+void view_get_box(const struct roots_view *view, struct wlr_box *box) {
+ box->x = view->x;
+ box->y = view->y;
if (view->get_size) {
view->get_size(view, box);
- return;
+ } else {
+ box->width = view->wlr_surface->current->width;
+ box->height = view->wlr_surface->current->height;
}
- box->x = box->y = 0;
- box->width = view->wlr_surface->current->width;
- box->height = view->wlr_surface->current->height;
}
-void view_activate(struct roots_view *view, bool activate) {
- if (view->activate) {
- view->activate(view, activate);
+static void view_update_output(const struct roots_view *view,
+ const struct wlr_box *before) {
+ struct roots_desktop *desktop = view->desktop;
+ struct roots_output *output;
+ struct wlr_box box;
+ view_get_box(view, &box);
+ wl_list_for_each(output, &desktop->outputs, link) {
+ bool intersected = before->x != -1 && wlr_output_layout_intersects(
+ desktop->layout, output->wlr_output,
+ before->x, before->y, before->x + before->width,
+ before->y + before->height);
+ bool intersects = wlr_output_layout_intersects(
+ desktop->layout, output->wlr_output,
+ view->x, view->y, view->x + box.width, view->y + box.height);
+ if (intersected && !intersects) {
+ wlr_surface_send_leave(view->wlr_surface, output->wlr_output);
+ }
+ if (!intersected && intersects) {
+ wlr_surface_send_enter(view->wlr_surface, output->wlr_output);
+ }
}
}
void view_move(struct roots_view *view, double x, double y) {
+ struct wlr_box before;
+ view_get_box(view, &before);
if (view->move) {
view->move(view, x, y);
- return;
+ } else {
+ view->x = x;
+ view->y = y;
}
+}
- view->x = x;
- view->y = y;
+void view_activate(struct roots_view *view, bool activate) {
+ if (view->activate) {
+ view->activate(view, activate);
+ }
}
void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
+ struct wlr_box before;
+ view_get_box(view, &before);
if (view->resize) {
view->resize(view, width, height);
}
+ view_update_output(view, &before);
}
void view_move_resize(struct roots_view *view, double x, double y,
@@ -78,6 +112,50 @@ void view_move_resize(struct roots_view *view, double x, double y,
view_resize(view, width, height);
}
+void view_maximize(struct roots_view *view, bool maximized) {
+ if (view->maximized == maximized) {
+ return;
+ }
+
+ if (view->maximize) {
+ view->maximize(view, maximized);
+ }
+
+ if (!view->maximized && maximized) {
+ struct wlr_box view_box;
+ view_get_box(view, &view_box);
+
+ view->maximized = true;
+ view->saved.x = view->x;
+ view->saved.y = view->y;
+ view->saved.rotation = view->rotation;
+ view->saved.width = view_box.width;
+ view->saved.height = view_box.height;
+
+ double output_x, output_y;
+ wlr_output_layout_closest_point(view->desktop->layout, NULL,
+ view->x + (double)view_box.width/2,
+ view->y + (double)view_box.height/2,
+ &output_x, &output_y);
+ struct wlr_output *output = wlr_output_layout_output_at(
+ view->desktop->layout, output_x, output_y);
+ struct wlr_box *output_box =
+ wlr_output_layout_get_box(view->desktop->layout, output);
+
+ view_move_resize(view, output_box->x, output_box->y, output_box->width,
+ output_box->height);
+ view->rotation = 0;
+ }
+
+ if (view->maximized && !maximized) {
+ view->maximized = false;
+
+ view_move_resize(view, view->saved.x, view->saved.y, view->saved.width,
+ view->saved.height);
+ view->rotation = view->saved.rotation;
+ }
+}
+
void view_close(struct roots_view *view) {
if (view->close) {
view->close(view);
@@ -85,19 +163,26 @@ void view_close(struct roots_view *view) {
}
bool view_center(struct roots_view *view) {
- struct wlr_box size;
- view_get_size(view, &size);
+ struct wlr_box box;
+ view_get_box(view, &box);
struct roots_desktop *desktop = view->desktop;
- struct wlr_cursor *cursor = desktop->server->input->cursor;
-
- struct wlr_output *output =
- wlr_output_layout_output_at(desktop->layout, cursor->x, cursor->y);
-
- if (!output) {
- output = wlr_output_layout_get_center_output(desktop->layout);
+ struct roots_input *input = desktop->server->input;
+ struct roots_seat *seat = NULL, *_seat;
+ wl_list_for_each(_seat, &input->seats, link) {
+ if (!seat || (seat->seat->last_event.tv_sec > _seat->seat->last_event.tv_sec &&
+ seat->seat->last_event.tv_nsec > _seat->seat->last_event.tv_nsec)) {
+ seat = _seat;
+ }
+ }
+ if (!seat) {
+ return false;
}
+ struct wlr_output *output =
+ wlr_output_layout_output_at(desktop->layout,
+ seat->cursor->cursor->x,
+ seat->cursor->cursor->y);
if (!output) {
// empty layout
return false;
@@ -109,22 +194,30 @@ bool view_center(struct roots_view *view) {
int width, height;
wlr_output_effective_resolution(output, &width, &height);
- double view_x = (double)(width - size.width) / 2 + l_output->x;
- double view_y = (double)(height - size.height) / 2 + l_output->y;
-
+ double view_x = (double)(width - box.width) / 2 + l_output->x;
+ double view_y = (double)(height - box.height) / 2 + l_output->y;
view_move(view, view_x, view_y);
return true;
}
void view_setup(struct roots_view *view) {
- view_center(view);
-
struct roots_input *input = view->desktop->server->input;
- set_view_focus(input, view->desktop, view);
+ // TODO what seat gets focus? the one with the last input event?
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ roots_seat_focus_view(seat, view);
+ }
+
+ view_center(view);
+ struct wlr_box before;
+ view_get_box(view, &before);
+ view_update_output(view, &before);
}
void view_teardown(struct roots_view *view) {
+ // TODO replace me with a signal
+ /*
struct wlr_list *views = view->desktop->views;
if (views->length < 2 || views->items[views->length-1] != view) {
return;
@@ -133,12 +226,12 @@ void view_teardown(struct roots_view *view) {
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) {
+ for (ssize_t i = desktop->views->length - 1; i >= 0; --i) {
struct roots_view *view = desktop->views->items[i];
if (view->type == ROOTS_WL_SHELL_VIEW &&
@@ -150,11 +243,12 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
double view_sx = lx - view->x;
double view_sy = ly - view->y;
+ struct wlr_surface_state *state = view->wlr_surface->current;
struct wlr_box box = {
.x = 0,
.y = 0,
- .width = view->wlr_surface->current->buffer_width,
- .height = view->wlr_surface->current->buffer_height,
+ .width = state->buffer_width / state->scale,
+ .height = state->buffer_height / state->scale,
};
if (view->rotation != 0.0) {
// Coordinates relative to the center of the view
@@ -168,7 +262,6 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
}
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) {
- // TODO: test if this works with rotated views
double popup_sx, popup_sy;
struct wlr_xdg_surface_v6 *popup =
wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6,
@@ -183,7 +276,6 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
}
if (view->type == ROOTS_WL_SHELL_VIEW) {
- // TODO: test if this works with rotated views
double popup_sx, popup_sy;
struct wlr_wl_shell_surface *popup =
wlr_wl_shell_surface_popup_at(view->wl_shell_surface,
@@ -245,6 +337,16 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->server = server;
desktop->config = config;
+
+ desktop->xcursor_manager = wlr_xcursor_manager_create(NULL,
+ ROOTS_XCURSOR_SIZE);
+ if (desktop->xcursor_manager == NULL) {
+ wlr_log(L_ERROR, "Cannot create XCursor manager");
+ wlr_list_free(desktop->views);
+ free(desktop);
+ return NULL;
+ }
+
desktop->layout = wlr_output_layout_create();
desktop->compositor = wlr_compositor_create(server->wl_display,
server->renderer);
@@ -266,6 +368,18 @@ struct roots_desktop *desktop_create(struct roots_server *server,
wl_signal_add(&desktop->xwayland->events.new_surface,
&desktop->xwayland_surface);
desktop->xwayland_surface.notify = handle_xwayland_surface;
+
+ if (wlr_xcursor_manager_load(desktop->xcursor_manager, 1)) {
+ wlr_log(L_ERROR, "Cannot load XWayland XCursor theme");
+ }
+ struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(
+ desktop->xcursor_manager, ROOTS_XCURSOR_DEFAULT, 1);
+ if (xcursor != NULL) {
+ struct wlr_xcursor_image *image = xcursor->images[0];
+ wlr_xwayland_set_cursor(desktop->xwayland, image->buffer,
+ image->width, image->width, image->height, image->hotspot_x,
+ image->hotspot_y);
+ }
}
#endif
diff --git a/rootston/input.c b/rootston/input.c
index 5d367a5e..35a5af97 100644
--- a/rootston/input.c
+++ b/rootston/input.c
@@ -8,6 +8,8 @@
#include "rootston/server.h"
#include "rootston/config.h"
#include "rootston/input.h"
+#include "rootston/keyboard.h"
+#include "rootston/seat.h"
static const char *device_type(enum wlr_input_device_type type) {
switch (type) {
@@ -25,47 +27,48 @@ static const char *device_type(enum wlr_input_device_type type) {
return NULL;
}
+static struct roots_seat *input_get_seat(struct roots_input *input, char *name) {
+ struct roots_seat *seat = NULL;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (strcmp(seat->seat->name, name) == 0) {
+ return seat;
+ }
+ }
+
+ seat = roots_seat_create(input, name);
+ return seat;
+}
+
static void input_add_notify(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data;
struct roots_input *input = wl_container_of(listener, input, input_add);
- wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s", device->name,
- device->vendor, device->product, device_type(device->type));
- switch (device->type) {
- case WLR_INPUT_DEVICE_KEYBOARD:
- keyboard_add(device, input);
- break;
- case WLR_INPUT_DEVICE_POINTER:
- pointer_add(device, input);
- break;
- case WLR_INPUT_DEVICE_TOUCH:
- touch_add(device, input);
- break;
- case WLR_INPUT_DEVICE_TABLET_TOOL:
- tablet_tool_add(device, input);
- break;
- default:
- break;
+
+ char *seat_name = "seat0";
+ struct roots_device_config *dc =
+ roots_config_get_device(input->config, device);
+ if (dc) {
+ seat_name = dc->seat;
+ }
+
+ struct roots_seat *seat = input_get_seat(input, seat_name);
+ if (!seat) {
+ wlr_log(L_ERROR, "could not create roots seat");
+ return;
}
+
+ wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s seat:%s", device->name,
+ device->vendor, device->product, device_type(device->type), seat_name);
+
+ roots_seat_add_device(seat, device);
}
static void input_remove_notify(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data;
struct roots_input *input = wl_container_of(listener, input, input_remove);
- switch (device->type) {
- case WLR_INPUT_DEVICE_KEYBOARD:
- keyboard_remove(device, input);
- break;
- case WLR_INPUT_DEVICE_POINTER:
- pointer_remove(device, input);
- break;
- case WLR_INPUT_DEVICE_TOUCH:
- touch_remove(device, input);
- break;
- case WLR_INPUT_DEVICE_TABLET_TOOL:
- tablet_tool_remove(device, input);
- break;
- default:
- break;
+
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ roots_seat_remove_device(seat, device);
}
}
@@ -82,66 +85,41 @@ struct roots_input *input_create(struct roots_server *server,
input->config = config;
input->server = server;
- input->xcursor_theme = wlr_xcursor_theme_load("default", 16);
- if (input->xcursor_theme == NULL) {
- wlr_log(L_ERROR, "Cannot load xcursor theme");
- free(input);
- return NULL;
- }
-
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
- if (xcursor == NULL) {
- wlr_log(L_ERROR, "Cannot load xcursor from theme");
- wlr_xcursor_theme_destroy(input->xcursor_theme);
- free(input);
- return NULL;
- }
-
- if (server->desktop->xwayland != NULL) {
- struct wlr_xcursor_image *xcursor_image = xcursor->images[0];
- wlr_xwayland_set_cursor(server->desktop->xwayland,
- xcursor_image->buffer, xcursor_image->width, xcursor_image->width,
- xcursor_image->height, xcursor_image->hotspot_x,
- xcursor_image->hotspot_y);
- }
-
- input->wl_seat = wlr_seat_create(server->wl_display, "seat0");
- if (input->wl_seat == NULL) {
- wlr_log(L_ERROR, "Cannot create seat");
- wlr_xcursor_theme_destroy(input->xcursor_theme);
- free(input);
- return NULL;
- }
- wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
- | WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
-
- wl_list_init(&input->keyboards);
- wl_list_init(&input->pointers);
- wl_list_init(&input->touch);
- wl_list_init(&input->tablet_tools);
+ wl_list_init(&input->seats);
input->input_add.notify = input_add_notify;
wl_signal_add(&server->backend->events.input_add, &input->input_add);
input->input_remove.notify = input_remove_notify;
wl_signal_add(&server->backend->events.input_remove, &input->input_remove);
- input->cursor = wlr_cursor_create();
- cursor_initialize(input);
-
- struct wlr_xcursor_image *image = xcursor->images[0];
- wlr_cursor_set_image(input->cursor, image->buffer, image->width,
- image->width, image->height, image->hotspot_x, image->hotspot_y);
-
- wlr_cursor_attach_output_layout(input->cursor, server->desktop->layout);
- wlr_cursor_map_to_region(input->cursor, config->cursor.mapped_box);
- cursor_load_config(config, input->cursor,
- input, server->desktop);
-
- wl_list_init(&input->drag_icons);
-
return input;
}
void input_destroy(struct roots_input *input) {
// TODO
}
+
+struct roots_seat *input_seat_from_wlr_seat(struct roots_input *input,
+ struct wlr_seat *wlr_seat) {
+ struct roots_seat *seat = NULL;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (seat->seat == wlr_seat) {
+ return seat;
+ }
+ }
+ return seat;
+}
+
+bool input_view_has_focus(struct roots_input *input, struct roots_view *view) {
+ if (!view) {
+ return false;
+ }
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (seat->focus == view) {
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index e174b731..39f46a32 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -10,17 +10,79 @@
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
#include "rootston/input.h"
+#include "rootston/seat.h"
+#include "rootston/keyboard.h"
-static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard,
+static ssize_t pressed_keysyms_index(xkb_keysym_t *pressed_keysyms,
xkb_keysym_t keysym) {
- for (size_t i = 0; i < ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP; i++) {
- if (keyboard->pressed_keysyms[i] == keysym) {
+ for (size_t i = 0; i < ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP; ++i) {
+ if (pressed_keysyms[i] == keysym) {
return i;
}
}
return -1;
}
+static size_t pressed_keysyms_length(xkb_keysym_t *pressed_keysyms) {
+ size_t n = 0;
+ for (size_t i = 0; i < ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP; ++i) {
+ if (pressed_keysyms[i] != XKB_KEY_NoSymbol) {
+ ++n;
+ }
+ }
+ return n;
+}
+
+static void pressed_keysyms_add(xkb_keysym_t *pressed_keysyms,
+ xkb_keysym_t keysym) {
+ ssize_t i = pressed_keysyms_index(pressed_keysyms, keysym);
+ if (i < 0) {
+ i = pressed_keysyms_index(pressed_keysyms, XKB_KEY_NoSymbol);
+ if (i >= 0) {
+ pressed_keysyms[i] = keysym;
+ }
+ }
+}
+
+static void pressed_keysyms_remove(xkb_keysym_t *pressed_keysyms,
+ xkb_keysym_t keysym) {
+ ssize_t i = pressed_keysyms_index(pressed_keysyms, keysym);
+ if (i >= 0) {
+ pressed_keysyms[i] = XKB_KEY_NoSymbol;
+ }
+}
+
+static bool keysym_is_modifier(xkb_keysym_t keysym) {
+ switch (keysym) {
+ case XKB_KEY_Shift_L: case XKB_KEY_Shift_R:
+ case XKB_KEY_Control_L: case XKB_KEY_Control_R:
+ case XKB_KEY_Caps_Lock:
+ case XKB_KEY_Shift_Lock:
+ case XKB_KEY_Meta_L: case XKB_KEY_Meta_R:
+ case XKB_KEY_Alt_L: case XKB_KEY_Alt_R:
+ case XKB_KEY_Super_L: case XKB_KEY_Super_R:
+ case XKB_KEY_Hyper_L: case XKB_KEY_Hyper_R:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static void pressed_keysyms_update(xkb_keysym_t *pressed_keysyms,
+ const xkb_keysym_t *keysyms, size_t keysyms_len,
+ enum wlr_key_state state) {
+ for (size_t i = 0; i < keysyms_len; ++i) {
+ if (keysym_is_modifier(keysyms[i])) {
+ continue;
+ }
+ if (state == WLR_KEY_PRESSED) {
+ pressed_keysyms_add(pressed_keysyms, keysyms[i]);
+ } else { // WLR_KEY_RELEASED
+ pressed_keysyms_remove(pressed_keysyms, keysyms[i]);
+ }
+ }
+}
+
static const char *exec_prefix = "exec ";
static void keyboard_binding_execute(struct roots_keyboard *keyboard,
@@ -37,7 +99,7 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
} else if (strcmp(command, "next_window") == 0) {
if (server->desktop->views->length > 0) {
struct roots_view *view = server->desktop->views->items[0];
- set_view_focus(keyboard->input, server->desktop, view);
+ roots_seat_focus_view(keyboard->seat, view);
}
} else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) {
const char *shell_cmd = command + strlen(exec_prefix);
@@ -54,21 +116,14 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
}
/**
- * Process a keypress from the keyboard.
+ * Execute a built-in, hardcoded compositor binding. These are triggered from a
+ * single keysym.
*
* Returns true if the keysym was handled by a binding and false if the event
* should be propagated to clients.
*/
-static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
+static bool keyboard_execute_compositor_binding(struct roots_keyboard *keyboard,
xkb_keysym_t keysym) {
- ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
- if (i < 0) {
- i = keyboard_pressed_keysym_index(keyboard, XKB_KEY_NoSymbol);
- if (i >= 0) {
- keyboard->pressed_keysyms[i] = keysym;
- }
- }
-
if (keysym >= XKB_KEY_XF86Switch_VT_1 &&
keysym <= XKB_KEY_XF86Switch_VT_12) {
struct roots_server *server = keyboard->input->server;
@@ -84,21 +139,41 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
}
if (keysym == XKB_KEY_Escape) {
- wlr_seat_pointer_end_grab(keyboard->input->wl_seat);
- wlr_seat_keyboard_end_grab(keyboard->input->wl_seat);
+ wlr_seat_pointer_end_grab(keyboard->seat->seat);
+ wlr_seat_keyboard_end_grab(keyboard->seat->seat);
+ }
+
+ return false;
+}
+
+/**
+ * Execute keyboard bindings. These include compositor bindings and user-defined
+ * bindings.
+ *
+ * Returns true if the keysym was handled by a binding and false if the event
+ * should be propagated to clients.
+ */
+static bool keyboard_execute_binding(struct roots_keyboard *keyboard,
+ xkb_keysym_t *pressed_keysyms, uint32_t modifiers,
+ const xkb_keysym_t *keysyms, size_t keysyms_len) {
+ for (size_t i = 0; i < keysyms_len; ++i) {
+ if (keyboard_execute_compositor_binding(keyboard, keysyms[i])) {
+ return true;
+ }
}
- uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+ // User-defined bindings
+ size_t n = pressed_keysyms_length(pressed_keysyms);
struct wl_list *bindings = &keyboard->input->server->config->bindings;
- struct binding_config *bc;
+ struct roots_binding_config *bc;
wl_list_for_each(bc, bindings, link) {
- if (modifiers ^ bc->modifiers) {
+ if (modifiers ^ bc->modifiers || n != bc->keysyms_len) {
continue;
}
bool ok = true;
for (size_t i = 0; i < bc->keysyms_len; i++) {
- ssize_t j = keyboard_pressed_keysym_index(keyboard, bc->keysyms[i]);
+ ssize_t j = pressed_keysyms_index(pressed_keysyms, bc->keysyms[i]);
if (j < 0) {
ok = false;
break;
@@ -114,56 +189,92 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
return false;
}
-static void keyboard_keysym_release(struct roots_keyboard *keyboard,
- xkb_keysym_t keysym) {
- ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
- if (i >= 0) {
- keyboard->pressed_keysyms[i] = XKB_KEY_NoSymbol;
- }
+/*
+ * Get keysyms and modifiers from the keyboard as xkb sees them.
+ *
+ * This uses the xkb keysyms translation based on pressed modifiers and clears
+ * the consumed modifiers from the list of modifiers passed to keybind
+ * detection.
+ *
+ * On US layout, pressing Alt+Shift+2 will trigger Alt+@.
+ */
+static size_t keyboard_keysyms_translated(struct roots_keyboard *keyboard,
+ xkb_keycode_t keycode, const xkb_keysym_t **keysyms,
+ uint32_t *modifiers) {
+ *modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+ xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods2(
+ keyboard->device->keyboard->xkb_state, keycode, XKB_CONSUMED_MODE_XKB);
+ *modifiers = *modifiers & ~consumed;
+
+ return xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state,
+ keycode, keysyms);
}
-static void keyboard_key_notify(struct wl_listener *listener, void *data) {
- struct wlr_event_keyboard_key *event = data;
- struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, key);
+/*
+ * Get keysyms and modifiers from the keyboard as if modifiers didn't change
+ * keysyms.
+ *
+ * This avoids the xkb keysym translation based on modifiers considered pressed
+ * in the state.
+ *
+ * This will trigger keybinds such as Alt+Shift+2.
+ */
+static size_t keyboard_keysyms_raw(struct roots_keyboard *keyboard,
+ xkb_keycode_t keycode, const xkb_keysym_t **keysyms,
+ uint32_t *modifiers) {
+ *modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+
+ xkb_layout_index_t layout_index = xkb_state_key_get_layout(
+ keyboard->device->keyboard->xkb_state, keycode);
+ return xkb_keymap_key_get_syms_by_level(keyboard->device->keyboard->keymap,
+ keycode, layout_index, 0, keysyms);
+}
- uint32_t keycode = event->keycode + 8;
- const xkb_keysym_t *syms;
- int syms_len = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state,
- keycode, &syms);
+void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
+ struct wlr_event_keyboard_key *event) {
+ xkb_keycode_t keycode = event->keycode + 8;
bool handled = false;
- for (int i = 0; i < syms_len; i++) {
- if (event->state == WLR_KEY_PRESSED) {
- bool keysym_handled = keyboard_keysym_press(keyboard, syms[i]);
- handled = handled || keysym_handled;
- } else { // WLR_KEY_RELEASED
- keyboard_keysym_release(keyboard, syms[i]);
- }
+ uint32_t modifiers;
+ const xkb_keysym_t *keysyms;
+ size_t keysyms_len;
+
+ // Handle translated keysyms
+
+ keysyms_len = keyboard_keysyms_translated(keyboard, keycode, &keysyms,
+ &modifiers);
+ pressed_keysyms_update(keyboard->pressed_keysyms_translated, keysyms,
+ keysyms_len, event->state);
+ if (event->state == WLR_KEY_PRESSED) {
+ handled = keyboard_execute_binding(keyboard,
+ keyboard->pressed_keysyms_translated, modifiers, keysyms,
+ keysyms_len);
+ }
+
+ // Handle raw keysyms
+ keysyms_len = keyboard_keysyms_raw(keyboard, keycode, &keysyms, &modifiers);
+ pressed_keysyms_update(keyboard->pressed_keysyms_raw, keysyms, keysyms_len,
+ event->state);
+ if (event->state == WLR_KEY_PRESSED && !handled) {
+ handled = keyboard_execute_binding(keyboard,
+ keyboard->pressed_keysyms_raw, modifiers, keysyms, keysyms_len);
}
if (!handled) {
- wlr_seat_set_keyboard(keyboard->input->wl_seat, keyboard->device);
- wlr_seat_keyboard_notify_key(keyboard->input->wl_seat, event->time_msec,
+ wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device);
+ wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec,
event->keycode, event->state);
}
}
-static void keyboard_modifiers_notify(struct wl_listener *listener, void *data) {
- struct roots_keyboard *r_keyboard =
- wl_container_of(listener, r_keyboard, modifiers);
- struct wlr_seat *seat = r_keyboard->input->wl_seat;
- struct wlr_keyboard *keyboard = r_keyboard->device->keyboard;
+void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) {
+ struct wlr_seat *seat = r_keyboard->seat->seat;
wlr_seat_set_keyboard(seat, r_keyboard->device);
- wlr_seat_keyboard_notify_modifiers(seat,
- keyboard->modifiers.depressed,
- keyboard->modifiers.latched,
- keyboard->modifiers.locked,
- keyboard->modifiers.group);
-
+ wlr_seat_keyboard_notify_modifiers(seat);
}
-static void keyboard_config_merge(struct keyboard_config *config,
- struct keyboard_config *fallback) {
+static void keyboard_config_merge(struct roots_keyboard_config *config,
+ struct roots_keyboard_config *fallback) {
if (fallback == NULL) {
return;
}
@@ -182,60 +293,64 @@ static void keyboard_config_merge(struct keyboard_config *config,
if (config->options == NULL) {
config->options = fallback->options;
}
+ if (config->meta_key == 0) {
+ config->meta_key = fallback->meta_key;
+ }
+ if (config->name == NULL) {
+ config->name = fallback->name;
+ }
}
-void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
+struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
+ struct roots_input *input) {
struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1);
if (keyboard == NULL) {
- return;
+ return NULL;
}
device->data = keyboard;
keyboard->device = device;
keyboard->input = input;
- keyboard->key.notify = keyboard_key_notify;
- wl_signal_add(&device->keyboard->events.key, &keyboard->key);
-
- keyboard->modifiers.notify = keyboard_modifiers_notify;
- wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
-
- 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 roots_keyboard_config *config =
+ calloc(1, sizeof(struct roots_keyboard_config));
+ if (config == NULL) {
+ free(keyboard);
+ return NULL;
+ }
+ keyboard_config_merge(config, roots_config_get_keyboard(input->config, device));
+ keyboard_config_merge(config, roots_config_get_keyboard(input->config, NULL));
- struct keyboard_config env_config = {
+ struct roots_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);
+ keyboard_config_merge(config, &env_config);
+ keyboard->config = config;
struct xkb_rule_names rules;
memset(&rules, 0, sizeof(rules));
- rules.rules = config.rules;
- rules.model = config.model;
- rules.layout = config.layout;
- rules.variant = config.variant;
- rules.options = config.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");
- return;
+ return NULL;
}
wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context,
&rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
xkb_context_unref(context);
+
+ return keyboard;
}
-void keyboard_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_keyboard *keyboard = device->data;
- wl_list_remove(&keyboard->key.link);
- wl_list_remove(&keyboard->modifiers.link);
+void roots_keyboard_destroy(struct roots_keyboard *keyboard) {
wl_list_remove(&keyboard->link);
+ free(keyboard->config);
free(keyboard);
}
diff --git a/rootston/main.c b/rootston/main.c
index 2a054e6c..814d3aef 100644
--- a/rootston/main.c
+++ b/rootston/main.c
@@ -12,8 +12,20 @@
struct roots_server server = { 0 };
+static void ready(struct wl_listener *listener, void *data) {
+ if (server.config->startup_cmd != NULL) {
+ const char *cmd = server.config->startup_cmd;
+ pid_t pid = fork();
+ if (pid < 0) {
+ wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
+ } else if (pid == 0) {
+ execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
+ }
+ }
+}
+
int main(int argc, char **argv) {
- assert(server.config = parse_args(argc, argv));
+ assert(server.config = roots_config_create_from_args(argc, argv));
assert(server.wl_display = wl_display_create());
assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display));
@@ -43,17 +55,16 @@ int main(int argc, char **argv) {
}
setenv("WAYLAND_DISPLAY", socket, true);
-
- if (server.config->startup_cmd != NULL) {
- const char *cmd = server.config->startup_cmd;
- pid_t pid = fork();
- if (pid < 0) {
- wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
- return 1;
- } else if (pid == 0) {
- execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
- }
+#ifndef HAS_XWAYLAND
+ ready(NULL, NULL);
+#else
+ if (server.desktop->xwayland != NULL) {
+ struct wl_listener xwayland_ready = { .notify = ready };
+ wl_signal_add(&server.desktop->xwayland->events.ready, &xwayland_ready);
+ } else {
+ ready(NULL, NULL);
}
+#endif
wl_display_run(server.wl_display);
wlr_backend_destroy(server.backend);
diff --git a/rootston/meson.build b/rootston/meson.build
index d84422d8..9c543c4f 100644
--- a/rootston/meson.build
+++ b/rootston/meson.build
@@ -7,9 +7,7 @@ sources = [
'keyboard.c',
'main.c',
'output.c',
- 'pointer.c',
- 'tablet_tool.c',
- 'touch.c',
+ 'seat.c',
'xcursor.c',
'xdg_shell_v6.c',
'wl_shell.c',
diff --git a/rootston/output.c b/rootston/output.c
index baa7b6cc..28312c2c 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -5,6 +5,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h>
+#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/render/matrix.h>
#include <wlr/util/log.h>
@@ -16,37 +17,67 @@ static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
}
+/**
+ * Rotate a child's position relative to a parent. The parent size is (pw, ph),
+ * the child position is (*sx, *sy) and its size is (sw, sh).
+ */
+static void rotate_child_position(double *sx, double *sy, double sw, double sh,
+ double pw, double ph, float rotation) {
+ if (rotation != 0.0) {
+ // Coordinates relative to the center of the subsurface
+ double ox = *sx - pw/2 + sw/2,
+ oy = *sy - ph/2 + sh/2;
+ // Rotated coordinates
+ double rx = cos(-rotation)*ox - sin(-rotation)*oy,
+ ry = cos(-rotation)*oy + sin(-rotation)*ox;
+ *sx = rx + pw/2 - sw/2;
+ *sy = ry + ph/2 - sh/2;
+ }
+}
+
static void render_surface(struct wlr_surface *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double lx, double ly, float rotation) {
if (surface->texture->valid) {
- int width = surface->current->buffer_width;
- int height = surface->current->buffer_height;
+ int width = surface->current->width;
+ int height = surface->current->height;
+ int render_width = width * wlr_output->scale;
+ int render_height = height * wlr_output->scale;
double ox = lx, oy = ly;
wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
+ ox *= wlr_output->scale;
+ oy *= wlr_output->scale;
if (wlr_output_layout_intersects(desktop->layout, wlr_output,
- lx, ly, lx + width, ly + height)) {
+ lx, ly, lx + render_width, ly + render_height)) {
float matrix[16];
float translate_origin[16];
wlr_matrix_translate(&translate_origin,
- (int)ox + width / 2, (int)oy + height / 2, 0);
+ (int)ox + render_width / 2, (int)oy + render_height / 2, 0);
+
float rotate[16];
wlr_matrix_rotate(&rotate, rotation);
+
float translate_center[16];
- wlr_matrix_translate(&translate_center, -width / 2, -height / 2, 0);
+ wlr_matrix_translate(&translate_center, -render_width / 2,
+ -render_height / 2, 0);
+
+ float scale[16];
+ wlr_matrix_scale(&scale, render_width, render_height, 1);
+
float transform[16];
wlr_matrix_mul(&translate_origin, &rotate, &transform);
wlr_matrix_mul(&transform, &translate_center, &transform);
- wlr_surface_get_matrix(surface, &matrix,
- &wlr_output->transform_matrix, &transform);
- wlr_render_with_matrix(desktop->server->renderer,
- surface->texture, &matrix);
+ wlr_matrix_mul(&transform, &scale, &transform);
+ wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
+
+ wlr_render_with_matrix(desktop->server->renderer, surface->texture,
+ &matrix);
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext,
- &surface->current->frame_callback_list, link) {
+ &surface->current->frame_callback_list, link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
}
@@ -54,20 +85,12 @@ static void render_surface(struct wlr_surface *surface,
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
- double sx = subsurface->surface->current->subsurface_position.x,
- sy = subsurface->surface->current->subsurface_position.y;
- double sw = subsurface->surface->current->buffer_width,
- sh = subsurface->surface->current->buffer_height;
- if (rotation != 0.0) {
- // Coordinates relative to the center of the subsurface
- double ox = sx - (double)width/2 + sw/2,
- oy = sy - (double)height/2 + sh/2;
- // Rotated coordinates
- double rx = cos(-rotation)*ox - sin(-rotation)*oy,
- ry = cos(-rotation)*oy + sin(-rotation)*ox;
- sx = rx + (double)width/2 - sw/2;
- sy = ry + (double)height/2 - sh/2;
- }
+ struct wlr_surface_state *state = subsurface->surface->current;
+ double sx = state->subsurface_position.x;
+ double sy = state->subsurface_position.y;
+ double sw = state->buffer_width / state->scale;
+ double sh = state->buffer_height / state->scale;
+ rotate_child_position(&sx, &sy, sw, sh, width, height, rotation);
render_surface(subsurface->surface, desktop, wlr_output, when,
lx + sx,
@@ -80,35 +103,53 @@ static void render_surface(struct wlr_surface *surface,
static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double base_x, double base_y, float rotation) {
- // TODO: make sure this works with view rotation
+ double width = surface->surface->current->width;
+ double height = surface->surface->current->height;
+
struct wlr_xdg_surface_v6 *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
if (!popup->configured) {
continue;
}
- double popup_x = base_x + surface->geometry->x +
- popup->popup_state->geometry.x - popup->geometry->x;
- double popup_y = base_y + surface->geometry->y +
- popup->popup_state->geometry.y - popup->geometry->y;
- render_surface(popup->surface, desktop, wlr_output, when, popup_x,
- popup_y, rotation);
- render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y, rotation);
+ double popup_width = popup->surface->current->width;
+ double popup_height = popup->surface->current->height;
+
+ double popup_sx, popup_sy;
+ wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy);
+ rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height,
+ width, height, rotation);
+
+ render_surface(popup->surface, desktop, wlr_output, when,
+ base_x + popup_sx, base_y + popup_sy, rotation);
+ render_xdg_v6_popups(popup, desktop, wlr_output, when,
+ base_x + popup_sx, base_y + popup_sy, rotation);
}
}
-static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, struct roots_desktop *desktop,
- struct wlr_output *wlr_output, struct timespec *when, double lx,
- double ly, float rotation, bool is_child) {
+static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface,
+ struct roots_desktop *desktop, struct wlr_output *wlr_output,
+ struct timespec *when, double lx, double ly, float rotation,
+ bool is_child) {
if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) {
render_surface(surface->surface, desktop, wlr_output, when,
lx, ly, rotation);
+
+ double width = surface->surface->current->width;
+ double height = surface->surface->current->height;
+
struct wlr_wl_shell_surface *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
+ double popup_width = popup->surface->current->width;
+ double popup_height = popup->surface->current->height;
+
+ double popup_x = popup->transient_state->x;
+ double popup_y = popup->transient_state->y;
+ rotate_child_position(&popup_x, &popup_y, popup_width, popup_height,
+ width, height, rotation);
+
render_wl_shell_surface(popup, desktop, wlr_output, when,
- lx + popup->transient_state->x,
- ly + popup->transient_state->y,
- rotation, true);
+ lx + popup_x, ly + popup_y, rotation, true);
}
}
}
@@ -151,15 +192,18 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
}
struct roots_drag_icon *drag_icon = NULL;
- wl_list_for_each(drag_icon, &server->input->drag_icons, link) {
- if (!drag_icon->mapped) {
- continue;
+ struct roots_seat *seat = NULL;
+ wl_list_for_each(seat, &server->input->seats, link) {
+ wl_list_for_each(drag_icon, &seat->drag_icons, link) {
+ if (!drag_icon->mapped) {
+ continue;
+ }
+ struct wlr_surface *icon = drag_icon->surface;
+ struct wlr_cursor *cursor = seat->cursor->cursor;
+ double icon_x = cursor->x + drag_icon->sx;
+ double icon_y = cursor->y + drag_icon->sy;
+ render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0);
}
- struct wlr_surface *icon = drag_icon->surface;
- struct wlr_cursor *cursor = server->input->cursor;
- double icon_x = cursor->x + drag_icon->sx;
- double icon_y = cursor->y + drag_icon->sy;
- render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0);
}
wlr_renderer_end(server->renderer);
@@ -168,7 +212,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
output->last_frame = desktop->last_frame = now;
}
-static void set_mode(struct wlr_output *output, struct output_config *oc) {
+static void set_mode(struct wlr_output *output,
+ struct roots_output_config *oc) {
struct wlr_output_mode *mode, *best = NULL;
int mhz = (int)(oc->mode.refresh_rate * 1000);
wl_list_for_each(mode, &output->modes, link) {
@@ -196,8 +241,9 @@ void output_add_notify(struct wl_listener *listener, void *data) {
struct roots_config *config = desktop->config;
wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name);
- wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make,
- wlr_output->model, wlr_output->phys_width, wlr_output->phys_height);
+ wlr_log(L_DEBUG, "%s %s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make,
+ wlr_output->model, wlr_output->serial, wlr_output->phys_width,
+ wlr_output->phys_height);
if (wl_list_length(&wlr_output->modes) > 0) {
struct wlr_output_mode *mode = NULL;
mode = wl_container_of((&wlr_output->modes)->prev, mode, link);
@@ -212,11 +258,13 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&desktop->outputs, &output->link);
- struct output_config *output_config = config_get_output(config, wlr_output);
+ struct roots_output_config *output_config =
+ roots_config_get_output(config, wlr_output);
if (output_config) {
if (output_config->mode.width) {
set_mode(wlr_output, output_config);
}
+ wlr_output->scale = output_config->scale;
wlr_output_transform(wlr_output, output_config->transform);
wlr_output_layout_add(desktop->layout,
wlr_output, output_config->x, output_config->y);
@@ -224,14 +272,17 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wlr_output_layout_add_auto(desktop->layout, wlr_output);
}
- cursor_load_config(config, input->cursor, input, desktop);
-
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
- struct wlr_xcursor_image *image = xcursor->images[0];
- wlr_cursor_set_image(input->cursor, image->buffer, image->width,
- image->width, image->height, image->hotspot_x, image->hotspot_y);
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
+ wlr_output->scale)) {
+ wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' "
+ "with scale %d", wlr_output->name, wlr_output->scale);
+ }
- wlr_cursor_warp(input->cursor, NULL, input->cursor->x, input->cursor->y);
+ roots_seat_configure_cursor(seat);
+ roots_seat_configure_xcursor(seat);
+ }
}
void output_remove_notify(struct wl_listener *listener, void *data) {
diff --git a/rootston/pointer.c b/rootston/pointer.c
deleted file mode 100644
index 299ecdfc..00000000
--- a/rootston/pointer.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <stdlib.h>
-#include <wayland-server.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/types/wlr_pointer.h>
-#include "rootston/input.h"
-
-void pointer_add(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1);
- device->data = pointer;
- pointer->device = device;
- pointer->input = input;
- wl_list_insert(&input->pointers, &pointer->link);
- wlr_cursor_attach_input_device(input->cursor, device);
- cursor_load_config(input->server->config, input->cursor,
- input, input->server->desktop);
-}
-
-void pointer_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_pointer *pointer = device->data;
- wlr_cursor_detach_input_device(input->cursor, device);
- wl_list_remove(&pointer->link);
- free(pointer);
-}
diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example
index 433dc78f..c33b0f04 100644
--- a/rootston/rootston.ini.example
+++ b/rootston/rootston.ini.example
@@ -40,6 +40,6 @@ meta-key = Logo
# - "close" to close the current view
# - "next_window" to cycle through windows
[bindings]
-Logo+Shift+E = exit
+Logo+Shift+e = exit
Logo+q = close
Alt+Tab = next_window
diff --git a/rootston/seat.c b/rootston/seat.c
new file mode 100644
index 00000000..1fa37c44
--- /dev/null
+++ b/rootston/seat.c
@@ -0,0 +1,579 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wayland-server.h>
+#include <wlr/types/wlr_xcursor_manager.h>
+#include <wlr/util/log.h>
+#include "rootston/xcursor.h"
+#include "rootston/input.h"
+#include "rootston/seat.h"
+#include "rootston/keyboard.h"
+#include "rootston/cursor.h"
+
+static void handle_keyboard_key(struct wl_listener *listener, void *data) {
+ struct roots_keyboard *keyboard =
+ wl_container_of(listener, keyboard, keyboard_key);
+ struct wlr_event_keyboard_key *event = data;
+ roots_keyboard_handle_key(keyboard, event);
+}
+
+static void handle_keyboard_modifiers(struct wl_listener *listener,
+ void *data) {
+ struct roots_keyboard *keyboard =
+ wl_container_of(listener, keyboard, keyboard_modifiers);
+ roots_keyboard_handle_modifiers(keyboard);
+}
+
+static void handle_cursor_motion(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, motion);
+ struct wlr_event_pointer_motion *event = data;
+ roots_cursor_handle_motion(cursor, event);
+}
+
+static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, motion_absolute);
+ struct wlr_event_pointer_motion_absolute *event = data;
+ roots_cursor_handle_motion_absolute(cursor, event);
+}
+
+static void handle_cursor_button(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, button);
+ struct wlr_event_pointer_button *event = data;
+ roots_cursor_handle_button(cursor, event);
+}
+
+static void handle_cursor_axis(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, axis);
+ struct wlr_event_pointer_axis *event = data;
+ roots_cursor_handle_axis(cursor, event);
+}
+
+static void handle_touch_down(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, touch_down);
+ struct wlr_event_touch_down *event = data;
+ roots_cursor_handle_touch_down(cursor, event);
+}
+
+static void handle_touch_up(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, touch_up);
+ struct wlr_event_touch_up *event = data;
+ roots_cursor_handle_touch_up(cursor, event);
+}
+
+static void handle_touch_motion(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, touch_motion);
+ struct wlr_event_touch_motion *event = data;
+ roots_cursor_handle_touch_motion(cursor, event);
+}
+
+static void handle_tool_axis(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, tool_axis);
+ struct wlr_event_tablet_tool_axis *event = data;
+ roots_cursor_handle_tool_axis(cursor, event);
+}
+
+static void handle_tool_tip(struct wl_listener *listener, void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, tool_tip);
+ struct wlr_event_tablet_tool_tip *event = data;
+ roots_cursor_handle_tool_tip(cursor, event);
+}
+
+static void handle_request_set_cursor(struct wl_listener *listener,
+ void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, request_set_cursor);
+ struct wlr_seat_pointer_request_set_cursor_event *event = data;
+ roots_cursor_handle_request_set_cursor(cursor, event);
+}
+
+static void handle_pointer_grab_begin(struct wl_listener *listener,
+ void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, pointer_grab_begin);
+ struct wlr_seat_pointer_grab *grab = data;
+ roots_cursor_handle_pointer_grab_begin(cursor, grab);
+}
+
+static void handle_pointer_grab_end(struct wl_listener *listener,
+ void *data) {
+ struct roots_cursor *cursor =
+ wl_container_of(listener, cursor, pointer_grab_end);
+ struct wlr_seat_pointer_grab *grab = data;
+ roots_cursor_handle_pointer_grab_end(cursor, grab);
+}
+
+static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct wlr_cursor *cursor = seat->cursor->cursor;
+ struct roots_config *config = seat->input->config;
+
+ wlr_cursor_map_input_to_output(cursor, device, NULL);
+ struct roots_device_config *dconfig;
+ if ((dconfig = roots_config_get_device(config, device))) {
+ wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box);
+ }
+}
+
+static void seat_set_device_output_mappings(struct roots_seat *seat,
+ struct wlr_input_device *device, struct wlr_output *output) {
+ struct wlr_cursor *cursor = seat->cursor->cursor;
+ struct roots_config *config = seat->input->config;
+ struct roots_device_config *dconfig;
+ dconfig = roots_config_get_device(config, device);
+ if (dconfig && dconfig->mapped_output &&
+ strcmp(dconfig->mapped_output, output->name) == 0) {
+ wlr_cursor_map_input_to_output(cursor, device, output);
+ }
+}
+
+void roots_seat_configure_cursor(struct roots_seat *seat) {
+ struct roots_config *config = seat->input->config;
+ struct roots_desktop *desktop = seat->input->server->desktop;
+ struct wlr_cursor *cursor = seat->cursor->cursor;
+
+ struct roots_pointer *pointer;
+ struct roots_touch *touch;
+ struct roots_tablet_tool *tablet_tool;
+ struct roots_output *output;
+
+ // reset mappings
+ wlr_cursor_map_to_output(cursor, NULL);
+ wl_list_for_each(pointer, &seat->pointers, link) {
+ seat_reset_device_mappings(seat, pointer->device);
+ }
+ wl_list_for_each(touch, &seat->touch, link) {
+ seat_reset_device_mappings(seat, touch->device);
+ }
+ wl_list_for_each(tablet_tool, &seat->tablet_tools, link) {
+ seat_reset_device_mappings(seat, tablet_tool->device);
+ }
+
+ // configure device to output mappings
+ const char *mapped_output = config->cursor.mapped_output;
+ wl_list_for_each(output, &desktop->outputs, link) {
+ if (mapped_output && strcmp(mapped_output, output->wlr_output->name) == 0) {
+ wlr_cursor_map_to_output(cursor, output->wlr_output);
+ }
+
+ wl_list_for_each(pointer, &seat->pointers, link) {
+ seat_set_device_output_mappings(seat, pointer->device, output->wlr_output);
+ }
+ wl_list_for_each(tablet_tool, &seat->tablet_tools, link) {
+ seat_set_device_output_mappings(seat, tablet_tool->device, output->wlr_output);
+ }
+ wl_list_for_each(touch, &seat->touch, link) {
+ seat_set_device_output_mappings(seat, touch->device, output->wlr_output);
+ }
+ }
+}
+
+static void roots_seat_init_cursor(struct roots_seat *seat) {
+ seat->cursor = roots_cursor_create(seat);
+ if (!seat->cursor) {
+ return;
+ }
+ seat->cursor->seat = seat;
+ struct wlr_cursor *wlr_cursor = seat->cursor->cursor;
+ struct roots_desktop *desktop = seat->input->server->desktop;
+ wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout);
+
+ // TODO: be able to configure per-seat cursor themes
+ seat->cursor->xcursor_manager = desktop->xcursor_manager;
+
+ wl_list_init(&seat->cursor->touch_points);
+
+ roots_seat_configure_cursor(seat);
+ roots_seat_configure_xcursor(seat);
+
+ // add input signals
+ wl_signal_add(&wlr_cursor->events.motion, &seat->cursor->motion);
+ seat->cursor->motion.notify = handle_cursor_motion;
+
+ wl_signal_add(&wlr_cursor->events.motion_absolute,
+ &seat->cursor->motion_absolute);
+ seat->cursor->motion_absolute.notify = handle_cursor_motion_absolute;
+
+ wl_signal_add(&wlr_cursor->events.button, &seat->cursor->button);
+ seat->cursor->button.notify = handle_cursor_button;
+
+ wl_signal_add(&wlr_cursor->events.axis, &seat->cursor->axis);
+ seat->cursor->axis.notify = handle_cursor_axis;
+
+ wl_signal_add(&wlr_cursor->events.touch_down, &seat->cursor->touch_down);
+ seat->cursor->touch_down.notify = handle_touch_down;
+
+ wl_signal_add(&wlr_cursor->events.touch_up, &seat->cursor->touch_up);
+ seat->cursor->touch_up.notify = handle_touch_up;
+
+ wl_signal_add(&wlr_cursor->events.touch_motion, &seat->cursor->touch_motion);
+ seat->cursor->touch_motion.notify = handle_touch_motion;
+
+ wl_signal_add(&wlr_cursor->events.tablet_tool_axis, &seat->cursor->tool_axis);
+ seat->cursor->tool_axis.notify = handle_tool_axis;
+
+ wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &seat->cursor->tool_tip);
+ seat->cursor->tool_tip.notify = handle_tool_tip;
+
+ wl_signal_add(&seat->seat->events.request_set_cursor,
+ &seat->cursor->request_set_cursor);
+ seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
+
+ wl_signal_add(&seat->seat->events.pointer_grab_begin,
+ &seat->cursor->pointer_grab_begin);
+ seat->cursor->pointer_grab_begin.notify = handle_pointer_grab_begin;
+
+ wl_signal_add(&seat->seat->events.pointer_grab_end,
+ &seat->cursor->pointer_grab_end);
+ seat->cursor->pointer_grab_end.notify = handle_pointer_grab_end;
+}
+
+struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
+ struct roots_seat *seat = calloc(1, sizeof(struct roots_seat));
+ if (!seat) {
+ return NULL;
+ }
+
+ wl_list_init(&seat->keyboards);
+ wl_list_init(&seat->pointers);
+ wl_list_init(&seat->touch);
+ wl_list_init(&seat->tablet_tools);
+ wl_list_init(&seat->drag_icons);
+
+ seat->input = input;
+
+ seat->seat = wlr_seat_create(input->server->wl_display, name);
+ if (!seat->seat) {
+ free(seat);
+ return NULL;
+ }
+
+ roots_seat_init_cursor(seat);
+ if (!seat->cursor) {
+ wlr_seat_destroy(seat->seat);
+ free(seat);
+ return NULL;
+ }
+
+ wlr_seat_set_capabilities(seat->seat,
+ WL_SEAT_CAPABILITY_KEYBOARD |
+ WL_SEAT_CAPABILITY_POINTER |
+ WL_SEAT_CAPABILITY_TOUCH);
+
+ wl_list_insert(&input->seats, &seat->link);
+
+ return seat;
+}
+
+void roots_seat_destroy(struct roots_seat *seat) {
+ // TODO
+}
+
+static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) {
+ assert(device->type == WLR_INPUT_DEVICE_KEYBOARD);
+ struct roots_keyboard *keyboard = roots_keyboard_create(device, seat->input);
+ if (keyboard == NULL) {
+ wlr_log(L_ERROR, "could not allocate keyboard for seat");
+ return;
+ }
+
+ keyboard->seat = seat;
+
+ wl_list_insert(&seat->keyboards, &keyboard->link);
+
+ keyboard->keyboard_key.notify = handle_keyboard_key;
+ wl_signal_add(&keyboard->device->keyboard->events.key,
+ &keyboard->keyboard_key);
+
+ keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
+ wl_signal_add(&keyboard->device->keyboard->events.modifiers,
+ &keyboard->keyboard_modifiers);
+
+ wlr_seat_set_keyboard(seat->seat, device);
+}
+
+static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1);
+ if (!pointer) {
+ wlr_log(L_ERROR, "could not allocate pointer for seat");
+ return;
+ }
+
+ device->data = pointer;
+ pointer->device = device;
+ pointer->seat = seat;
+ wl_list_insert(&seat->pointers, &pointer->link);
+ wlr_cursor_attach_input_device(seat->cursor->cursor, device);
+ roots_seat_configure_cursor(seat);
+}
+
+static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1);
+ if (!touch) {
+ wlr_log(L_ERROR, "could not allocate touch for seat");
+ return;
+ }
+
+ device->data = touch;
+ touch->device = device;
+ touch->seat = seat;
+ wl_list_insert(&seat->touch, &touch->link);
+ wlr_cursor_attach_input_device(seat->cursor->cursor, device);
+ roots_seat_configure_cursor(seat);
+}
+
+static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) {
+ // TODO
+}
+
+static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_tablet_tool *tablet_tool = calloc(sizeof(struct roots_tablet_tool), 1);
+ if (!tablet_tool) {
+ wlr_log(L_ERROR, "could not allocate tablet_tool for seat");
+ return;
+ }
+
+ device->data = tablet_tool;
+ tablet_tool->device = device;
+ tablet_tool->seat = seat;
+ wl_list_insert(&seat->tablet_tools, &tablet_tool->link);
+ wlr_cursor_attach_input_device(seat->cursor->cursor, device);
+ roots_seat_configure_cursor(seat);
+}
+
+void roots_seat_add_device(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ switch (device->type) {
+ case WLR_INPUT_DEVICE_KEYBOARD:
+ seat_add_keyboard(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_POINTER:
+ seat_add_pointer(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TOUCH:
+ seat_add_touch(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_PAD:
+ seat_add_tablet_pad(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_TOOL:
+ seat_add_tablet_tool(seat, device);
+ break;
+ }
+}
+
+static void seat_remove_keyboard(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ struct roots_keyboard *keyboard;
+ wl_list_for_each(keyboard, &seat->keyboards, link) {
+ if (keyboard->device == device) {
+ roots_keyboard_destroy(keyboard);
+ return;
+ }
+ }
+}
+
+static void seat_remove_pointer(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ struct roots_pointer *pointer;
+ wl_list_for_each(pointer, &seat->pointers, link) {
+ if (pointer->device == device) {
+ wl_list_remove(&pointer->link);
+ wlr_cursor_detach_input_device(seat->cursor->cursor, device);
+ free(pointer);
+ return;
+ }
+ }
+}
+
+static void seat_remove_touch(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ struct roots_touch *touch;
+ wl_list_for_each(touch, &seat->touch, link) {
+ if (touch->device == device) {
+ wl_list_remove(&touch->link);
+ wlr_cursor_detach_input_device(seat->cursor->cursor, device);
+ free(touch);
+ return;
+ }
+ }
+}
+
+static void seat_remove_tablet_pad(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ // TODO
+}
+
+static void seat_remove_tablet_tool(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ struct roots_tablet_tool *tablet_tool;
+ wl_list_for_each(tablet_tool, &seat->tablet_tools, link) {
+ if (tablet_tool->device == device) {
+ wl_list_remove(&tablet_tool->link);
+ wlr_cursor_detach_input_device(seat->cursor->cursor, device);
+ free(tablet_tool);
+ return;
+ }
+ }
+}
+
+void roots_seat_remove_device(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ switch (device->type) {
+ case WLR_INPUT_DEVICE_KEYBOARD:
+ seat_remove_keyboard(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_POINTER:
+ seat_remove_pointer(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TOUCH:
+ seat_remove_touch(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_PAD:
+ seat_remove_tablet_pad(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_TOOL:
+ seat_remove_tablet_tool(seat, device);
+ break;
+ }
+}
+
+void roots_seat_configure_xcursor(struct roots_seat *seat) {
+ struct roots_output *output;
+ wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
+ if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
+ output->wlr_output->scale)) {
+ wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' "
+ "with scale %d", output->wlr_output->name,
+ output->wlr_output->scale);
+ }
+ }
+
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ ROOTS_XCURSOR_DEFAULT, seat->cursor->cursor);
+ wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,
+ seat->cursor->cursor->y);
+}
+
+bool roots_seat_has_meta_pressed(struct roots_seat *seat) {
+ struct roots_keyboard *keyboard;
+ wl_list_for_each(keyboard, &seat->keyboards, link) {
+ if (!keyboard->config->meta_key) {
+ continue;
+ }
+
+ uint32_t modifiers =
+ wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+ if ((modifiers ^ keyboard->config->meta_key) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
+ struct roots_desktop *desktop = seat->input->server->desktop;
+ if (seat->focus == view) {
+ return;
+ }
+
+ if (view && view->type == ROOTS_XWAYLAND_VIEW &&
+ view->xwayland_surface->override_redirect) {
+ return;
+ }
+
+ struct roots_view *prev_focus = seat->focus;
+ seat->focus = view;
+
+ // unfocus the old view if it is not focused by some other seat
+ if (prev_focus && !input_view_has_focus(seat->input, prev_focus)) {
+ view_activate(prev_focus, false);
+ }
+
+ if (!seat->focus) {
+ seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
+ return;
+ }
+
+ size_t index = 0;
+ for (size_t i = 0; i < desktop->views->length; ++i) {
+ struct roots_view *_view = desktop->views->items[i];
+ if (_view == view) {
+ index = i;
+ break;
+ }
+ }
+
+ view_activate(view, true);
+ // TODO: list_swap
+ wlr_list_del(desktop->views, index);
+ wlr_list_add(desktop->views, view);
+ wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface);
+}
+
+void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
+ struct roots_cursor *cursor = seat->cursor;
+ cursor->mode = ROOTS_CURSOR_MOVE;
+ cursor->offs_x = cursor->cursor->x;
+ cursor->offs_y = cursor->cursor->y;
+ if (view->maximized) {
+ cursor->view_x = view->saved.x;
+ cursor->view_y = view->saved.y;
+ } else {
+ cursor->view_x = view->x;
+ cursor->view_y = view->y;
+ }
+ view_maximize(view, false);
+ wlr_seat_pointer_clear_focus(seat->seat);
+
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ ROOTS_XCURSOR_MOVE, seat->cursor->cursor);
+}
+
+void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
+ uint32_t edges) {
+ struct roots_cursor *cursor = seat->cursor;
+ cursor->mode = ROOTS_CURSOR_RESIZE;
+ cursor->offs_x = cursor->cursor->x;
+ cursor->offs_y = cursor->cursor->y;
+ if (view->maximized) {
+ cursor->view_x = view->saved.x;
+ cursor->view_y = view->saved.y;
+ cursor->view_width = view->saved.width;
+ cursor->view_height = view->saved.height;
+ } else {
+ cursor->view_x = view->x;
+ cursor->view_y = view->y;
+ struct wlr_box box;
+ view_get_box(view, &box);
+ cursor->view_width = box.width;
+ cursor->view_height = box.height;
+ }
+ cursor->resize_edges = edges;
+ view_maximize(view, false);
+ wlr_seat_pointer_clear_focus(seat->seat);
+
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ roots_xcursor_get_resize_name(edges), seat->cursor->cursor);
+}
+
+void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {
+ struct roots_cursor *cursor = seat->cursor;
+ cursor->mode = ROOTS_CURSOR_ROTATE;
+ cursor->offs_x = cursor->cursor->x;
+ cursor->offs_y = cursor->cursor->y;
+ cursor->view_rotation = view->rotation;
+ view_maximize(view, false);
+ wlr_seat_pointer_clear_focus(seat->seat);
+
+ wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
+ ROOTS_XCURSOR_ROTATE, seat->cursor->cursor);
+}
diff --git a/rootston/tablet_tool.c b/rootston/tablet_tool.c
deleted file mode 100644
index a612e683..00000000
--- a/rootston/tablet_tool.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdlib.h>
-#include <wayland-server.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/types/wlr_pointer.h>
-#include <wlr/util/log.h>
-#include "rootston/input.h"
-
-void tablet_tool_add(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_tablet_tool *tool = calloc(sizeof(struct roots_tablet_tool), 1);
- device->data = tool;
- tool->device = device;
- tool->input = input;
- wl_list_insert(&input->tablet_tools, &tool->link);
- wlr_cursor_attach_input_device(input->cursor, device);
- cursor_load_config(input->server->config, input->cursor,
- input, input->server->desktop);
-}
-
-void tablet_tool_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_tablet_tool *tablet_tool = device->data;
- wlr_cursor_detach_input_device(input->cursor, device);
- wl_list_remove(&tablet_tool->link);
- free(tablet_tool);
-}
diff --git a/rootston/touch.c b/rootston/touch.c
deleted file mode 100644
index f6d9b11a..00000000
--- a/rootston/touch.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <stdlib.h>
-#include <wayland-server.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/types/wlr_pointer.h>
-#include "rootston/input.h"
-
-// TODO: we'll likely want touch events to both control the cursor *and* be
-// submitted directly to the seat.
-
-void touch_add(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1);
- device->data = touch;
- touch->device = device;
- touch->input = input;
- wl_list_insert(&input->touch, &touch->link);
- wlr_cursor_attach_input_device(input->cursor, device);
- cursor_load_config(input->server->config, input->cursor,
- input, input->server->desktop);
-}
-
-void touch_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_touch *touch = device->data;
- wlr_cursor_detach_input_device(input->cursor, device);
- wl_list_remove(&touch->link);
- free(touch);
-}
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index e38eb697..96f461fe 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -29,11 +29,11 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_wl_shell_surface_move_event *e = data;
- const struct roots_input_event *event = get_input_event(input, e->serial);
- if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
+ if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- view_begin_move(input, event->cursor, view);
+ roots_seat_begin_move(seat, view);
}
static void handle_request_resize(struct wl_listener *listener, void *data) {
@@ -42,11 +42,32 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_wl_shell_surface_resize_event *e = data;
- const struct roots_input_event *event = get_input_event(input, e->serial);
- if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
+ // TODO verify input event
+ if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- view_begin_resize(input, event->cursor, view, e->edges);
+ roots_seat_begin_resize(seat, view, e->edges);
+}
+
+static void handle_request_set_maximized(struct wl_listener *listener,
+ void *data) {
+ struct roots_wl_shell_surface *roots_surface =
+ wl_container_of(listener, roots_surface, request_set_maximized);
+ struct roots_view *view = roots_surface->view;
+ //struct wlr_wl_shell_surface_set_maximized_event *e = data;
+ view_maximize(view, true);
+}
+
+static void handle_set_state(struct wl_listener *listener, void *data) {
+ struct roots_wl_shell_surface *roots_surface =
+ wl_container_of(listener, roots_surface, set_state);
+ struct roots_view *view = roots_surface->view;
+ struct wlr_wl_shell_surface *surface = view->wl_shell_surface;
+ if (view->maximized &&
+ surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) {
+ view_maximize(view, false);
+ }
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
@@ -60,6 +81,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link);
+ wl_list_remove(&roots_surface->request_set_maximized.link);
+ wl_list_remove(&roots_surface->set_state.link);
+ wl_list_remove(&roots_surface->surface_commit.link);
view_destroy(roots_surface->view);
free(roots_surface);
}
@@ -93,6 +117,11 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
+ roots_surface->request_set_maximized.notify = handle_request_set_maximized;
+ wl_signal_add(&surface->events.request_set_maximized,
+ &roots_surface->request_set_maximized);
+ roots_surface->set_state.notify = handle_set_state;
+ wl_signal_add(&surface->events.set_state, &roots_surface->set_state);
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
diff --git a/rootston/xcursor.c b/rootston/xcursor.c
index 43cbfc51..74e732c9 100644
--- a/rootston/xcursor.c
+++ b/rootston/xcursor.c
@@ -1,15 +1,10 @@
-#include <wlr/types/wlr_cursor.h>
+#define _POSIX_C_SOURCE 200809L
+#include <stdlib.h>
+#include <string.h>
+#include "rootston/xcursor.h"
#include "rootston/input.h"
-struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme) {
- return wlr_xcursor_theme_get_cursor(theme, "left_ptr");
-}
-
-struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme) {
- return wlr_xcursor_theme_get_cursor(theme, "grabbing");
-}
-
-static const char *get_resize_xcursor_name(uint32_t edges) {
+const char *roots_xcursor_get_resize_name(uint32_t edges) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
return "ne-resize";
@@ -31,12 +26,3 @@ static const char *get_resize_xcursor_name(uint32_t edges) {
}
return "se-resize"; // fallback
}
-
-struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme,
- uint32_t edges) {
- return wlr_xcursor_theme_get_cursor(theme, get_resize_xcursor_name(edges));
-}
-
-struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme) {
- return wlr_xcursor_theme_get_cursor(theme, "grabbing");
-}
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index 38341922..f9c905dd 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -10,11 +10,17 @@
#include "rootston/server.h"
#include "rootston/input.h"
-static void get_size(struct roots_view *view, struct wlr_box *box) {
+static void get_size(const struct roots_view *view, struct wlr_box *box) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
- // TODO: surface->geometry can be NULL
- memcpy(box, surface->geometry, sizeof(struct wlr_box));
+
+ if (surface->geometry->width > 0 && surface->geometry->height > 0) {
+ box->width = surface->geometry->width;
+ box->height = surface->geometry->height;
+ } else {
+ box->width = view->wlr_surface->current->width;
+ box->height = view->wlr_surface->current->height;
+ }
}
static void activate(struct roots_view *view, bool active) {
@@ -87,6 +93,16 @@ static void move_resize(struct roots_view *view, double x, double y,
constrained_height);
}
+static void maximize(struct roots_view *view, bool maximized) {
+ assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
+ struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
+ if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
+ return;
+ }
+
+ wlr_xdg_toplevel_v6_set_maximized(surface, maximized);
+}
+
static void close(struct roots_view *view) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
@@ -101,11 +117,12 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_xdg_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_xdg_toplevel_v6_move_event *e = data;
- const struct roots_input_event *event = get_input_event(input, e->serial);
- if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
+ // TODO verify event serial
+ if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- view_begin_move(input, event->cursor, view);
+ roots_seat_begin_move(seat, view);
}
static void handle_request_resize(struct wl_listener *listener, void *data) {
@@ -114,11 +131,26 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_xdg_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_xdg_toplevel_v6_resize_event *e = data;
- const struct roots_input_event *event = get_input_event(input, e->serial);
- if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ // TODO verify event serial
+ struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
+ assert(seat);
+ if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- view_begin_resize(input, event->cursor, view, e->edges);
+ roots_seat_begin_resize(seat, view, e->edges);
+}
+
+static void handle_request_maximize(struct wl_listener *listener, void *data) {
+ struct roots_xdg_surface_v6 *roots_xdg_surface =
+ wl_container_of(listener, roots_xdg_surface, request_maximize);
+ struct roots_view *view = roots_xdg_surface->view;
+ struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
+
+ if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
+ return;
+ }
+
+ view_maximize(view, surface->toplevel_state->next.maximized);
}
static void handle_commit(struct wl_listener *listener, void *data) {
@@ -178,6 +210,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
+ roots_surface->request_maximize.notify = handle_request_maximize;
+ wl_signal_add(&surface->events.request_maximize,
+ &roots_surface->request_maximize);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) {
@@ -192,6 +227,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->activate = activate;
view->resize = resize;
view->move_resize = move_resize;
+ view->maximize = maximize;
view->close = close;
view->desktop = desktop;
roots_surface->view = view;
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index 76cdf05a..f1093552 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -85,11 +85,22 @@ static void close(struct roots_view *view) {
wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface);
}
+static void maximize(struct roots_view *view, bool maximized) {
+ assert(view->type == ROOTS_XWAYLAND_VIEW);
+
+ wlr_xwayland_surface_set_maximized(view->desktop->xwayland,
+ view->xwayland_surface, maximized);
+}
+
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);
+ wl_list_remove(&roots_surface->request_configure.link);
+ wl_list_remove(&roots_surface->request_move.link);
+ wl_list_remove(&roots_surface->request_resize.link);
+ wl_list_remove(&roots_surface->request_maximize.link);
wl_list_remove(&roots_surface->map_notify.link);
wl_list_remove(&roots_surface->unmap_notify.link);
view_destroy(roots_surface->view);
@@ -110,26 +121,16 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
xwayland_surface, event->x, event->y, event->width, event->height);
}
-// XXX Needs deep refactoring to get this better. We need to select the correct
-// seat based on seat pointer focus, but interactive moving and resizing is not
-// yet seat aware. Even then, we can only guess because X11 events don't give us
-// enough wayland info to know for sure.
-static struct wlr_cursor *guess_cursor_for_view(struct roots_view *view) {
+static struct roots_seat *guess_seat_for_view(struct roots_view *view) {
+ // the best we can do is to pick the first seat that has the surface focused
+ // for the pointer
struct roots_input *input = view->desktop->server->input;
- size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
- for (size_t i = 0; i < len; i++) {
- struct wlr_cursor *cursor = input->input_events[i].cursor;
- if (cursor) {
- int width = view->xwayland_surface->surface->current->width;
- int height = view->xwayland_surface->surface->current->height;
- if (cursor->x > view->x && cursor->y > view->y &&
- cursor->x < view->x + width &&
- cursor->y < view->y + height) {
- return cursor;
- }
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (seat->seat->pointer_state.focused_surface == view->wlr_surface) {
+ return seat;
}
}
-
return NULL;
}
@@ -137,28 +138,37 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, request_move);
struct roots_view *view = roots_surface->view;
- struct roots_input *input = view->desktop->server->input;
- struct wlr_cursor *cursor = guess_cursor_for_view(view);
+ struct roots_seat *seat = guess_seat_for_view(view);
- if (!cursor || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- view_begin_move(input, cursor, view);
+ roots_seat_begin_move(seat, view);
}
static void handle_request_resize(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, request_resize);
struct roots_view *view = roots_surface->view;
- struct roots_input *input = view->desktop->server->input;
- struct wlr_cursor *cursor = guess_cursor_for_view(view);
+ struct roots_seat *seat = guess_seat_for_view(view);
struct wlr_xwayland_resize_event *e = data;
- if (!cursor || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
+ if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- view_begin_resize(input, cursor, view, e->edges);
+ roots_seat_begin_resize(seat, view, e->edges);
+}
+
+static void handle_request_maximize(struct wl_listener *listener, void *data) {
+ struct roots_xwayland_surface *roots_surface =
+ wl_container_of(listener, roots_surface, request_maximize);
+ struct roots_view *view = roots_surface->view;
+ struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
+
+ bool maximized = xwayland_surface->maximized_vert &&
+ xwayland_surface->maximized_horz;
+ view_maximize(view, maximized);
}
static void handle_map_notify(struct wl_listener *listener, void *data) {
@@ -202,24 +212,24 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
if (roots_surface == NULL) {
return;
}
+
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
-
roots_surface->request_configure.notify = handle_request_configure;
wl_signal_add(&surface->events.request_configure,
&roots_surface->request_configure);
-
roots_surface->map_notify.notify = handle_map_notify;
wl_signal_add(&surface->events.map_notify, &roots_surface->map_notify);
-
roots_surface->unmap_notify.notify = handle_unmap_notify;
wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify);
-
roots_surface->request_move.notify = handle_request_move;
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
-
roots_surface->request_resize.notify = handle_request_resize;
- wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize);
+ wl_signal_add(&surface->events.request_resize,
+ &roots_surface->request_resize);
+ roots_surface->request_maximize.notify = handle_request_maximize;
+ wl_signal_add(&surface->events.request_maximize,
+ &roots_surface->request_maximize);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (view == NULL) {
@@ -237,6 +247,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->resize = resize;
view->move = move;
view->move_resize = move_resize;
+ view->maximize = maximize;
view->close = close;
roots_surface->view = view;
wlr_list_add(desktop->views, view);