aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c4
-rw-r--r--rootston/cursor.c46
-rw-r--r--rootston/desktop.c109
-rw-r--r--rootston/output.c19
-rw-r--r--rootston/wl_shell.c28
-rw-r--r--rootston/xdg_shell_v6.c35
-rw-r--r--rootston/xwayland.c35
7 files changed, 237 insertions, 39 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 b153e8c8..cbd03af1 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -42,8 +42,15 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
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;
+ if (view->maximized) {
+ input->view_x = view->saved.x;
+ input->view_y = view->saved.y;
+ } else {
+ input->view_x = view->x;
+ input->view_y = view->y;
+ }
+
+ view_maximize(view, false);
wlr_seat_pointer_clear_focus(input->wl_seat);
struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme);
@@ -57,13 +64,22 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
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;
+ if (view->maximized) {
+ input->view_x = view->saved.x;
+ input->view_y = view->saved.y;
+ input->view_width = view->saved.width;
+ input->view_height = view->saved.height;
+ } else {
+ 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;
+
+ view_maximize(view, false);
wlr_seat_pointer_clear_focus(input->wl_seat);
struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges);
@@ -78,6 +94,8 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor,
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_rotation = view->rotation;
+
+ view_maximize(view, false);
wlr_seat_pointer_clear_focus(input->wl_seat);
struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme);
@@ -102,7 +120,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
set_compositor_cursor = view_client != input->cursor_client;
}
if (set_compositor_cursor) {
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
+ struct wlr_xcursor *xcursor =
+ get_default_xcursor(input->xcursor_theme);
cursor_set_xcursor_image(input, xcursor->images[0]);
input->cursor_client = NULL;
}
@@ -383,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 b36a6932..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,
@@ -78,6 +106,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_size(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,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;
@@ -109,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) {
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/wl_shell.c b/rootston/wl_shell.c
index e38eb697..3ac8fe61 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -49,6 +49,26 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
view_begin_resize(input, event->cursor, 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?
}
@@ -60,6 +80,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 +116,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 ca33c582..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
@@ -84,6 +84,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;
@@ -118,8 +128,25 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
view_begin_resize(input, event->cursor, 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) {
@@ -164,6 +191,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) {
@@ -178,6 +208,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 e3fc1c84..b608b143 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);
@@ -161,6 +172,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
view_begin_resize(input, cursor, 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);
@@ -202,24 +224,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 +259,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);