aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c4
-rw-r--r--rootston/cursor.c9
-rw-r--r--rootston/desktop.c66
-rw-r--r--rootston/keyboard.c91
-rw-r--r--rootston/output.c19
-rw-r--r--rootston/xdg_shell_v6.c2
6 files changed, 148 insertions, 43 deletions
diff --git a/rootston/config.c b/rootston/config.c
index dc7a4b1d..ff02ff1d 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -220,6 +220,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
oc = calloc(1, sizeof(struct 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 +228,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;
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 80836ccd..cbd03af1 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -402,11 +402,20 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
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;
+
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,
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
cursor_update_position(input, event->time_msec);
+ } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
+ wlr_cursor_warp_absolute(input->cursor, event->device,
+ event->x_mm / event->width_mm, -1);
+ cursor_update_position(input, event->time_msec);
+ } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
+ wlr_cursor_warp_absolute(input->cursor, event->device,
+ -1, event->y_mm / event->height_mm);
+ cursor_update_position(input, event->time_msec);
}
}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index f5d5925b..469a503b 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -35,36 +35,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_size(const struct roots_view *view, struct wlr_box *box) {
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;
+ box->x = view->x;
+ box->y = view->y;
}
-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_size(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_size(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_size(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,
@@ -129,8 +157,8 @@ 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_size(view, &box);
struct roots_desktop *desktop = view->desktop;
struct wlr_cursor *cursor = desktop->server->input->cursor;
@@ -153,19 +181,20 @@ 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;
+ view_center(view);
set_view_focus(input, view->desktop, view);
+ struct wlr_box before;
+ view_get_size(view, &before);
+ view_update_output(view, &before);
}
void view_teardown(struct roots_view *view) {
@@ -177,7 +206,6 @@ 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,
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index e174b731..bde912aa 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -60,7 +60,7 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
* should be propagated to clients.
*/
static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
- xkb_keysym_t keysym) {
+ xkb_keysym_t keysym, uint32_t modifiers) {
ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
if (i < 0) {
i = keyboard_pressed_keysym_index(keyboard, XKB_KEY_NoSymbol);
@@ -88,7 +88,6 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
wlr_seat_keyboard_end_grab(keyboard->input->wl_seat);
}
- uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
struct wl_list *bindings = &keyboard->input->server->config->bindings;
struct binding_config *bc;
wl_list_for_each(bc, bindings, link) {
@@ -122,25 +121,85 @@ static void keyboard_keysym_release(struct roots_keyboard *keyboard,
}
}
-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);
+/*
+ * Process keypresses from the keyboard as if modifiers didn't change keysyms.
+ *
+ * This avoids the xkb keysym translation based on modifiers considered pressed
+ * in the state and uses the list of modifiers saved on the rootston side.
+ *
+ * This will trigger the keybind: [Alt]+[Shift]+2
+ */
+static bool keyboard_keysyms_simple(struct roots_keyboard *keyboard,
+ uint32_t keycode, enum wlr_key_state state) {
+ uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+ const xkb_keysym_t *syms;
+ xkb_layout_index_t layout_index = xkb_state_key_get_layout(
+ keyboard->device->keyboard->xkb_state, keycode);
+ int syms_len = xkb_keymap_key_get_syms_by_level(
+ keyboard->device->keyboard->keymap, keycode, layout_index, 0, &syms);
- uint32_t keycode = event->keycode + 8;
+ bool handled = false;
+ for (int i = 0; i < syms_len; i++) {
+ if (state) {
+ bool keysym_handled = keyboard_keysym_press(keyboard,
+ syms[i], modifiers);
+ handled = handled || keysym_handled;
+ } else { // WLR_KEY_RELEASED
+ keyboard_keysym_release(keyboard, syms[i]);
+ }
+ }
+
+ return handled;
+}
+
+/*
+ * Process keypresses 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) this will trigger: [Alt]+[at]
+ */
+static bool keyboard_keysyms_xkb(struct roots_keyboard *keyboard,
+ uint32_t keycode, enum wlr_key_state state) {
+ uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
const xkb_keysym_t *syms;
int syms_len = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state,
keycode, &syms);
+ uint32_t consumed = xkb_state_key_get_consumed_mods2(
+ keyboard->device->keyboard->xkb_state, keycode, XKB_CONSUMED_MODE_XKB);
+
+ modifiers = modifiers & ~consumed;
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]);
+ if (state) {
+ bool keysym_handled = keyboard_keysym_press(keyboard,
+ syms[i], modifiers);
handled = handled || keysym_handled;
} else { // WLR_KEY_RELEASED
keyboard_keysym_release(keyboard, syms[i]);
}
}
+ return handled;
+}
+
+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);
+
+ uint32_t keycode = event->keycode + 8;
+
+ bool handled = keyboard_keysyms_xkb(keyboard, keycode, event->state);
+
+ if (!handled) {
+ bool key_handled = keyboard_keysyms_simple(keyboard, keycode,
+ event->state);
+ handled = handled || key_handled;
+ }
+
if (!handled) {
wlr_seat_set_keyboard(keyboard->input->wl_seat, keyboard->device);
wlr_seat_keyboard_notify_key(keyboard->input->wl_seat, event->time_msec,
@@ -149,17 +208,11 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
}
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;
- 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);
-
+ struct roots_keyboard *keyboard =
+ wl_container_of(listener, keyboard, modifiers);
+ struct wlr_seat *seat = keyboard->input->wl_seat;
+ wlr_seat_set_keyboard(seat, keyboard->device);
+ wlr_seat_keyboard_notify_modifiers(seat);
}
static void keyboard_config_merge(struct keyboard_config *config,
diff --git a/rootston/output.c b/rootston/output.c
index baa7b6cc..c21c6781 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -20,10 +20,13 @@ 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;
+ float scale_factor = (float)wlr_output->scale / surface->current->scale;
+ int width = surface->current->buffer_width * scale_factor;
+ int height = surface->current->buffer_height * scale_factor;
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)) {
@@ -32,15 +35,22 @@ static void render_surface(struct wlr_surface *surface,
float translate_origin[16];
wlr_matrix_translate(&translate_origin,
(int)ox + width / 2, (int)oy + 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);
+
+ float scale[16];
+ wlr_matrix_scale(&scale, width, 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_matrix_mul(&transform, &scale, &transform);
+ wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
+
wlr_render_with_matrix(desktop->server->renderer,
surface->texture, &matrix);
@@ -217,6 +227,7 @@ void output_add_notify(struct wl_listener *listener, void *data) {
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);
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index a86899be..2a0660a6 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -10,7 +10,7 @@
#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 *surf = view->xdg_surface_v6;
// TODO: surf->geometry can be NULL