aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c4
-rw-r--r--rootston/cursor.c8
-rw-r--r--rootston/desktop.c110
-rw-r--r--rootston/output.c19
-rw-r--r--rootston/seat.c31
-rw-r--r--rootston/wl_shell.c28
-rw-r--r--rootston/xdg_shell_v6.c45
-rw-r--r--rootston/xwayland.c35
8 files changed, 240 insertions, 40 deletions
diff --git a/rootston/config.c b/rootston/config.c
index 815040bf..54f10fcd 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -221,6 +221,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);
}
@@ -228,6 +229,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 c8abe098..cba9e782 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -273,6 +273,14 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
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);
+ } 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);
}
}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index c5242599..448171ec 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -39,36 +39,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,
@@ -82,6 +110,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);
@@ -89,8 +161,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_box(view, &box);
struct roots_desktop *desktop = view->desktop;
@@ -107,23 +179,25 @@ 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;
// 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) {
diff --git a/rootston/output.c b/rootston/output.c
index 329c29be..f192cb48 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);
@@ -220,6 +230,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/seat.c b/rootston/seat.c
index 3dcd7f2f..3530fb75 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -548,8 +548,14 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
cursor->mode = ROOTS_CURSOR_MOVE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
- cursor->view_x = view->x;
- cursor->view_y = view->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);
struct wlr_xcursor *xcursor = get_move_xcursor(seat->cursor->xcursor_theme);
@@ -565,13 +571,21 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
cursor->mode = ROOTS_CURSOR_RESIZE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
- cursor->view_x = view->x;
- cursor->view_y = view->y;
- struct wlr_box size;
- view_get_size(view, &size);
- cursor->view_width = size.width;
- cursor->view_height = size.height;
+ 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);
struct wlr_xcursor *xcursor = get_resize_xcursor(cursor->xcursor_theme, edges);
@@ -587,6 +601,7 @@ void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {
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);
struct wlr_xcursor *xcursor = get_rotate_xcursor(cursor->xcursor_theme);
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 81b9e640..96f461fe 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -50,6 +50,26 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
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) {
// TODO do we need to do anything here?
}
@@ -61,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);
}
@@ -94,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/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index ed952e18..6517c8b4 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 *surf = view->xdg_surface_v6;
- // TODO: surf->geometry can be NULL
- memcpy(box, surf->geometry, sizeof(struct wlr_box));
+
+ if (surf->geometry->width > 0 && surf->geometry->height > 0) {
+ box->width = surf->geometry->width;
+ box->height = surf->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) {
@@ -84,6 +90,16 @@ static void move_resize(struct roots_view *view, double x, double y,
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_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 *surf = view->xdg_surface_v6;
@@ -121,8 +137,25 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
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) {
- // TODO is there anything we need to do here?
+ //struct roots_xdg_surface_v6 *roots_xdg_surface =
+ // wl_container_of(listener, roots_xdg_surface, commit);
+ //struct roots_view *view = roots_xdg_surface->view;
+ //struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
+ // TODO
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -167,6 +200,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) {
@@ -181,6 +217,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 92ba5e60..f4e100dc 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);
@@ -149,6 +160,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
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) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, map_notify);
@@ -190,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) {
@@ -225,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);