aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/cursor.c2
-rw-r--r--rootston/desktop.c84
-rw-r--r--rootston/main.c2
-rw-r--r--rootston/output.c49
-rw-r--r--rootston/seat.c9
-rw-r--r--rootston/wl_shell.c32
-rw-r--r--rootston/xdg_shell.c88
-rw-r--r--rootston/xdg_shell_v6.c88
-rw-r--r--rootston/xwayland.c55
9 files changed, 254 insertions, 155 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index aa94daeb..52439dff 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -200,7 +200,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
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);
+ float angle = atan2(ux*vy - uy*vx, vx*ux + vy*uy);
int steps = 12;
angle = round(angle/M_PI*steps) / (steps/M_PI);
view_rotate(view, cursor->view_rotation + angle);
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 3628b051..65d9a280 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -9,6 +9,7 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_idle.h>
+#include <wlr/types/wlr_linux_dmabuf.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_primary_selection.h>
@@ -23,13 +24,16 @@
#include "rootston/view.h"
#include "rootston/xcursor.h"
-
-struct roots_view *view_create() {
+struct roots_view *view_create(struct roots_desktop *desktop) {
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) {
return NULL;
}
+ view->desktop = desktop;
view->alpha = 1.0f;
+ wl_signal_init(&view->events.unmap);
+ wl_signal_init(&view->events.destroy);
+ wl_list_init(&view->children);
return view;
}
@@ -52,7 +56,8 @@ void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) {
box->height += (view->border_width * 2 + view->titlebar_height);
}
-enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy) {
+enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx,
+ double sy) {
if (!view->decorated) {
return ROOTS_DECO_PART_NONE;
}
@@ -92,9 +97,15 @@ enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, doub
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;
+
+ if (view->wlr_surface == NULL) {
+ return;
+ }
+
struct wlr_box box;
view_get_box(view, &box);
+
+ struct roots_output *output;
wl_list_for_each(output, &desktop->outputs, link) {
bool intersected = before != NULL && wlr_output_layout_intersects(
desktop->layout, output->wlr_output, before);
@@ -402,20 +413,22 @@ struct roots_subsurface *subsurface_create(struct roots_view *view,
return subsurface;
}
-void view_finish(struct roots_view *view) {
- view_damage_whole(view);
- wl_signal_emit(&view->events.destroy, view);
+void view_destroy(struct roots_view *view) {
+ if (view == NULL) {
+ return;
+ }
- wl_list_remove(&view->new_subsurface.link);
+ wl_signal_emit(&view->events.destroy, view);
- struct roots_view_child *child, *tmp;
- wl_list_for_each_safe(child, tmp, &view->children, link) {
- child->destroy(child);
+ if (view->wlr_surface != NULL) {
+ view_unmap(view);
}
- if (view->fullscreen_output) {
- view->fullscreen_output->fullscreen_view = NULL;
+ if (view->destroy) {
+ view->destroy(view);
}
+
+ free(view);
}
static void view_handle_new_subsurface(struct wl_listener *listener,
@@ -425,12 +438,10 @@ static void view_handle_new_subsurface(struct wl_listener *listener,
subsurface_create(view, wlr_subsurface);
}
-void view_init(struct roots_view *view, struct roots_desktop *desktop) {
- assert(view->wlr_surface);
+void view_map(struct roots_view *view, struct wlr_surface *surface) {
+ assert(view->wlr_surface == NULL);
- view->desktop = desktop;
- wl_signal_init(&view->events.destroy);
- wl_list_init(&view->children);
+ view->wlr_surface = surface;
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list,
@@ -442,9 +453,35 @@ void view_init(struct roots_view *view, struct roots_desktop *desktop) {
wl_signal_add(&view->wlr_surface->events.new_subsurface,
&view->new_subsurface);
+ wl_list_insert(&view->desktop->views, &view->link);
view_damage_whole(view);
}
+void view_unmap(struct roots_view *view) {
+ assert(view->wlr_surface != NULL);
+
+ wl_signal_emit(&view->events.unmap, view);
+
+ view_damage_whole(view);
+ wl_list_remove(&view->link);
+
+ wl_list_remove(&view->new_subsurface.link);
+
+ struct roots_view_child *child, *tmp;
+ wl_list_for_each_safe(child, tmp, &view->children, link) {
+ child->destroy(child);
+ }
+
+ if (view->fullscreen_output != NULL) {
+ output_damage_whole(view->fullscreen_output);
+ view->fullscreen_output->fullscreen_view = NULL;
+ view->fullscreen_output = NULL;
+ }
+
+ view->wlr_surface = NULL;
+ view->width = view->height = 0;
+}
+
void view_initial_focus(struct roots_view *view) {
struct roots_input *input = view->desktop->server->input;
// TODO what seat gets focus? the one with the last input event?
@@ -457,7 +494,10 @@ void view_initial_focus(struct roots_view *view) {
void view_setup(struct roots_view *view) {
view_initial_focus(view);
- view_center(view);
+ if (view->fullscreen_output == NULL && !view->maximized) {
+ view_center(view);
+ }
+
view_update_output(view, NULL);
}
@@ -517,8 +557,8 @@ static bool view_at(struct roots_view *view, double lx, double ly,
double ox = view_sx - (double)box.width/2,
oy = view_sy - (double)box.height/2;
// Rotated coordinates
- double rx = cos(view->rotation)*ox - sin(view->rotation)*oy,
- ry = cos(view->rotation)*oy + sin(view->rotation)*ox;
+ double rx = cos(view->rotation)*ox + sin(view->rotation)*oy,
+ ry = cos(view->rotation)*oy - sin(view->rotation)*ox;
view_sx = rx + (double)box.width/2;
view_sy = ry + (double)box.height/2;
}
@@ -729,6 +769,8 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->idle = wlr_idle_create(server->wl_display);
desktop->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display);
+ struct wlr_egl *egl = wlr_backend_get_egl(server->backend);
+ desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display, egl);
return desktop;
}
diff --git a/rootston/main.c b/rootston/main.c
index 5450ade2..d85701ca 100644
--- a/rootston/main.c
+++ b/rootston/main.c
@@ -7,7 +7,7 @@
#include <wlr/backend/headless.h>
#include <wlr/backend/multi.h>
#include <wlr/config.h>
-#include <wlr/render.h>
+#include <wlr/render/wlr_renderer.h>
#include <wlr/util/log.h>
#include "rootston/config.h"
#include "rootston/server.h"
diff --git a/rootston/output.c b/rootston/output.c
index 4d0a9c05..1284c928 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -3,7 +3,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
-#include <wlr/render/matrix.h>
+#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_wl_shell.h>
@@ -29,8 +29,8 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
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;
+ 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;
}
@@ -227,7 +227,7 @@ static bool surface_intersect_output(struct wlr_surface *surface,
.x = lx, .y = ly,
.width = surface->current->width, .height = surface->current->height,
};
- wlr_box_rotated_bounds(&layout_box, -rotation, &layout_box);
+ wlr_box_rotated_bounds(&layout_box, rotation, &layout_box);
return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box);
}
@@ -275,7 +275,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
}
struct wlr_box rotated;
- wlr_box_rotated_bounds(&box, -rotation, &rotated);
+ wlr_box_rotated_bounds(&box, rotation, &rotated);
pixman_region32_t damage;
pixman_region32_init(&damage);
@@ -287,17 +287,17 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
goto damage_finish;
}
- float matrix[16];
+ float matrix[9];
enum wl_output_transform transform =
wlr_output_transform_invert(surface->current->transform);
- wlr_matrix_project_box(&matrix, &box, transform, rotation,
- &output->wlr_output->transform_matrix);
+ wlr_matrix_project_box(matrix, &box, transform, rotation,
+ output->wlr_output->transform_matrix);
int nrects;
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
- wlr_render_with_matrix(renderer, surface->texture, &matrix, data->alpha);
+ wlr_render_texture_with_matrix(renderer, surface->texture, matrix, data->alpha);
}
damage_finish:
@@ -341,7 +341,7 @@ static void render_decorations(struct roots_view *view,
get_decoration_box(view, output, &box);
struct wlr_box rotated;
- wlr_box_rotated_bounds(&box, -view->rotation, &rotated);
+ wlr_box_rotated_bounds(&box, view->rotation, &rotated);
pixman_region32_t damage;
pixman_region32_init(&damage);
@@ -353,9 +353,9 @@ static void render_decorations(struct roots_view *view,
goto damage_finish;
}
- float matrix[16];
- wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
- view->rotation, &output->wlr_output->transform_matrix);
+ float matrix[9];
+ wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
+ view->rotation, output->wlr_output->transform_matrix);
float color[] = { 0.2, 0.2, 0.2, view->alpha };
int nrects;
@@ -363,7 +363,7 @@ static void render_decorations(struct roots_view *view,
pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
- wlr_render_colored_quad(renderer, &color, &matrix);
+ wlr_render_colored_quad(renderer, color, matrix);
}
damage_finish:
@@ -433,7 +433,8 @@ static void render_output(struct roots_output *output) {
float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};
// Check if we can delegate the fullscreen surface to the output
- if (output->fullscreen_view != NULL) {
+ if (output->fullscreen_view != NULL &&
+ output->fullscreen_view->wlr_surface != NULL) {
struct roots_view *view = output->fullscreen_view;
// Make sure the view is centered on screen
@@ -478,7 +479,7 @@ static void render_output(struct roots_output *output) {
goto damage_finish;
}
- wlr_renderer_begin(renderer, wlr_output);
+ wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
if (!pixman_region32_not_empty(&damage)) {
// Output isn't damaged but needs buffer swap
@@ -489,7 +490,7 @@ static void render_output(struct roots_output *output) {
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
- wlr_renderer_clear(renderer, &clear_color);
+ wlr_renderer_clear(renderer, clear_color);
}
// If a view is fullscreen on this output, render it
@@ -501,7 +502,9 @@ static void render_output(struct roots_output *output) {
goto renderer_end;
}
- view_for_each_surface(view, render_surface, &data);
+ if (view->wlr_surface != NULL) {
+ view_for_each_surface(view, render_surface, &data);
+ }
// During normal rendering the xwayland window tree isn't traversed
// because all windows are rendered. Here we only want to render
@@ -570,6 +573,9 @@ void output_damage_whole(struct roots_output *output) {
static bool view_accept_damage(struct roots_output *output,
struct roots_view *view) {
+ if (view->wlr_surface == NULL) {
+ return false;
+ }
if (output->fullscreen_view == NULL) {
return true;
}
@@ -610,7 +616,7 @@ static void damage_whole_surface(struct wlr_surface *surface,
return;
}
- wlr_box_rotated_bounds(&box, -rotation, &box);
+ wlr_box_rotated_bounds(&box, rotation, &box);
wlr_output_damage_add_box(output->damage, &box);
}
@@ -624,7 +630,7 @@ static void damage_whole_decoration(struct roots_view *view,
struct wlr_box box;
get_decoration_box(view, output, &box);
- wlr_box_rotated_bounds(&box, -view->rotation, &box);
+ wlr_box_rotated_bounds(&box, view->rotation, &box);
wlr_output_damage_add_box(output->damage, &box);
}
@@ -674,6 +680,7 @@ static void damage_from_surface(struct wlr_surface *surface,
}
pixman_region32_translate(&damage, box.x, box.y);
wlr_output_damage_add(output->damage, &damage);
+ pixman_region32_fini(&damage);
} else {
pixman_box32_t *extents =
pixman_region32_extents(&surface->current->surface_damage);
@@ -683,7 +690,7 @@ static void damage_from_surface(struct wlr_surface *surface,
.width = (extents->x2 - extents->x1) * wlr_output->scale,
.height = (extents->y2 - extents->y1) * wlr_output->scale,
};
- wlr_box_rotated_bounds(&damage_box, -rotation, &damage_box);
+ wlr_box_rotated_bounds(&damage_box, rotation, &damage_box);
wlr_output_damage_add_box(output->damage, &damage_box);
}
}
diff --git a/rootston/seat.c b/rootston/seat.c
index 8ac41f6c..d2d211ba 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -645,6 +645,7 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) {
seat->cursor->pointer_view = NULL;
}
+ wl_list_remove(&seat_view->view_unmap.link);
wl_list_remove(&seat_view->view_destroy.link);
wl_list_remove(&seat_view->link);
free(seat_view);
@@ -657,6 +658,12 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) {
}
}
+static void seat_view_handle_unmap(struct wl_listener *listener, void *data) {
+ struct roots_seat_view *seat_view =
+ wl_container_of(listener, seat_view, view_unmap);
+ seat_view_destroy(seat_view);
+}
+
static void seat_view_handle_destroy(struct wl_listener *listener, void *data) {
struct roots_seat_view *seat_view =
wl_container_of(listener, seat_view, view_destroy);
@@ -675,6 +682,8 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
wl_list_insert(seat->views.prev, &seat_view->link);
+ seat_view->view_unmap.notify = seat_view_handle_unmap;
+ wl_signal_add(&view->events.unmap, &seat_view->view_unmap);
seat_view->view_destroy.notify = seat_view_handle_destroy;
wl_signal_add(&view->events.destroy, &seat_view->view_destroy);
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 899df1c6..d58f030a 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -78,6 +78,19 @@ static void close(struct roots_view *view) {
wl_client_destroy(surf->client);
}
+static void destroy(struct roots_view *view) {
+ assert(view->type == ROOTS_WL_SHELL_VIEW);
+ struct roots_wl_shell_surface *roots_surface = view->roots_wl_shell_surface;
+ 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_maximize.link);
+ wl_list_remove(&roots_surface->request_fullscreen.link);
+ wl_list_remove(&roots_surface->set_state.link);
+ wl_list_remove(&roots_surface->surface_commit.link);
+ free(roots_surface);
+}
+
static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, request_move);
@@ -174,17 +187,7 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
- 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_maximize.link);
- wl_list_remove(&roots_surface->request_fullscreen.link);
- wl_list_remove(&roots_surface->set_state.link);
- wl_list_remove(&roots_surface->surface_commit.link);
- wl_list_remove(&roots_surface->view->link);
- view_finish(roots_surface->view);
- free(roots_surface->view);
- free(roots_surface);
+ view_destroy(roots_surface->view);
}
void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
@@ -227,7 +230,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit);
- struct roots_view *view = view_create();
+ struct roots_view *view = view_create(desktop);
if (!view) {
free(roots_surface);
return;
@@ -238,13 +241,12 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->wl_shell_surface = surface;
view->roots_wl_shell_surface = roots_surface;
- view->wlr_surface = surface->surface;
view->resize = resize;
view->close = close;
+ view->destroy = destroy;
roots_surface->view = view;
- view_init(view, desktop);
- wl_list_insert(&desktop->views, &view->link);
+ view_map(view, surface->surface);
view_setup(view);
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c
index 9368ce0b..851c0045 100644
--- a/rootston/xdg_shell.c
+++ b/rootston/xdg_shell.c
@@ -60,12 +60,14 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
assert(view->type == ROOTS_XDG_SHELL_VIEW);
struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->geometry->width > 0 && surface->geometry->height > 0) {
- box->width = surface->geometry->width;
- box->height = surface->geometry->height;
- } else {
+ if (surface->geometry.width > 0 && surface->geometry.height > 0) {
+ box->width = surface->geometry.width;
+ box->height = surface->geometry.height;
+ } else if (view->wlr_surface != NULL) {
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
+ } else {
+ box->width = box->height = 0;
}
}
@@ -83,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface *surface,
*dest_width = width;
*dest_height = height;
- struct wlr_xdg_toplevel_state *state = &surface->toplevel_state->current;
+ struct wlr_xdg_toplevel_state *state = &surface->toplevel->current;
if (width < state->min_width) {
*dest_width = state->min_width;
} else if (state->max_width > 0 &&
@@ -180,6 +182,21 @@ static void close(struct roots_view *view) {
}
}
+static void destroy(struct roots_view *view) {
+ assert(view->type == ROOTS_XDG_SHELL_VIEW);
+ struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface;
+ wl_list_remove(&roots_xdg_surface->surface_commit.link);
+ wl_list_remove(&roots_xdg_surface->destroy.link);
+ wl_list_remove(&roots_xdg_surface->new_popup.link);
+ wl_list_remove(&roots_xdg_surface->map.link);
+ wl_list_remove(&roots_xdg_surface->unmap.link);
+ wl_list_remove(&roots_xdg_surface->request_move.link);
+ wl_list_remove(&roots_xdg_surface->request_resize.link);
+ wl_list_remove(&roots_xdg_surface->request_maximize.link);
+ wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
+ free(roots_xdg_surface);
+}
+
static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_move);
@@ -219,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) {
return;
}
- view_maximize(view, surface->toplevel_state->next.maximized);
+ view_maximize(view, surface->toplevel->next.maximized);
}
static void handle_request_fullscreen(struct wl_listener *listener,
@@ -243,6 +260,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view;
struct wlr_xdg_surface *surface = view->xdg_surface;
+ if (!surface->mapped) {
+ return;
+ }
+
view_apply_damage(view);
struct wlr_box size;
@@ -277,20 +298,30 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
popup_create(roots_xdg_surface->view, wlr_popup);
}
+static void handle_map(struct wl_listener *listener, void *data) {
+ struct roots_xdg_surface *roots_xdg_surface =
+ wl_container_of(listener, roots_xdg_surface, map);
+ struct roots_view *view = roots_xdg_surface->view;
+
+ struct wlr_box box;
+ get_size(view, &box);
+ view->width = box.width;
+ view->height = box.height;
+
+ view_map(view, view->xdg_surface->surface);
+ view_setup(view);
+}
+
+static void handle_unmap(struct wl_listener *listener, void *data) {
+ struct roots_xdg_surface *roots_xdg_surface =
+ wl_container_of(listener, roots_xdg_surface, unmap);
+ view_unmap(roots_xdg_surface->view);
+}
+
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, destroy);
- wl_list_remove(&roots_xdg_surface->surface_commit.link);
- wl_list_remove(&roots_xdg_surface->destroy.link);
- wl_list_remove(&roots_xdg_surface->new_popup.link);
- wl_list_remove(&roots_xdg_surface->request_move.link);
- wl_list_remove(&roots_xdg_surface->request_resize.link);
- wl_list_remove(&roots_xdg_surface->request_maximize.link);
- wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
- wl_list_remove(&roots_xdg_surface->view->link);
- view_finish(roots_xdg_surface->view);
- free(roots_xdg_surface->view);
- free(roots_xdg_surface);
+ view_destroy(roots_xdg_surface->view);
}
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
@@ -319,6 +350,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
&roots_surface->surface_commit);
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
+ roots_surface->map.notify = handle_map;
+ wl_signal_add(&surface->events.map, &roots_surface->map);
+ roots_surface->unmap.notify = handle_unmap;
+ wl_signal_add(&surface->events.unmap, &roots_surface->unmap);
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;
@@ -333,7 +368,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
- struct roots_view *view = view_create();
+ struct roots_view *view = view_create(desktop);
if (!view) {
free(roots_surface);
return;
@@ -342,22 +377,19 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
view->xdg_surface = surface;
view->roots_xdg_surface = roots_surface;
- view->wlr_surface = surface->surface;
view->activate = activate;
view->resize = resize;
view->move_resize = move_resize;
view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close;
+ view->destroy = destroy;
roots_surface->view = view;
- struct wlr_box box;
- get_size(view, &box);
- view->width = box.width;
- view->height = box.height;
-
- view_init(view, desktop);
- wl_list_insert(&desktop->views, &view->link);
-
- view_setup(view);
+ if (surface->toplevel->next.maximized) {
+ view_maximize(view, true);
+ }
+ if (surface->toplevel->next.fullscreen) {
+ view_set_fullscreen(view, true, NULL);
+ }
}
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index eda349cb..13d25331 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -60,12 +60,14 @@ 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;
- if (surface->geometry->width > 0 && surface->geometry->height > 0) {
- box->width = surface->geometry->width;
- box->height = surface->geometry->height;
- } else {
+ if (surface->geometry.width > 0 && surface->geometry.height > 0) {
+ box->width = surface->geometry.width;
+ box->height = surface->geometry.height;
+ } else if (view->wlr_surface != NULL) {
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
+ } else {
+ box->width = box->height = 0;
}
}
@@ -83,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface,
*dest_width = width;
*dest_height = height;
- struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current;
+ struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel->current;
if (width < state->min_width) {
*dest_width = state->min_width;
} else if (state->max_width > 0 &&
@@ -180,6 +182,21 @@ static void close(struct roots_view *view) {
}
}
+static void destroy(struct roots_view *view) {
+ assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
+ struct roots_xdg_surface_v6 *roots_xdg_surface = view->roots_xdg_surface_v6;
+ wl_list_remove(&roots_xdg_surface->surface_commit.link);
+ wl_list_remove(&roots_xdg_surface->destroy.link);
+ wl_list_remove(&roots_xdg_surface->new_popup.link);
+ wl_list_remove(&roots_xdg_surface->map.link);
+ wl_list_remove(&roots_xdg_surface->unmap.link);
+ wl_list_remove(&roots_xdg_surface->request_move.link);
+ wl_list_remove(&roots_xdg_surface->request_resize.link);
+ wl_list_remove(&roots_xdg_surface->request_maximize.link);
+ wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
+ free(roots_xdg_surface);
+}
+
static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_move);
@@ -219,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) {
return;
}
- view_maximize(view, surface->toplevel_state->next.maximized);
+ view_maximize(view, surface->toplevel->next.maximized);
}
static void handle_request_fullscreen(struct wl_listener *listener,
@@ -243,6 +260,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view;
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
+ if (!surface->mapped) {
+ return;
+ }
+
view_apply_damage(view);
struct wlr_box size;
@@ -277,20 +298,30 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
popup_create(roots_xdg_surface->view, wlr_popup);
}
+static void handle_map(struct wl_listener *listener, void *data) {
+ struct roots_xdg_surface_v6 *roots_xdg_surface =
+ wl_container_of(listener, roots_xdg_surface, map);
+ struct roots_view *view = roots_xdg_surface->view;
+
+ struct wlr_box box;
+ get_size(view, &box);
+ view->width = box.width;
+ view->height = box.height;
+
+ view_map(view, view->xdg_surface_v6->surface);
+ view_setup(view);
+}
+
+static void handle_unmap(struct wl_listener *listener, void *data) {
+ struct roots_xdg_surface_v6 *roots_xdg_surface =
+ wl_container_of(listener, roots_xdg_surface, unmap);
+ view_unmap(roots_xdg_surface->view);
+}
+
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, destroy);
- wl_list_remove(&roots_xdg_surface->surface_commit.link);
- wl_list_remove(&roots_xdg_surface->destroy.link);
- wl_list_remove(&roots_xdg_surface->new_popup.link);
- wl_list_remove(&roots_xdg_surface->request_move.link);
- wl_list_remove(&roots_xdg_surface->request_resize.link);
- wl_list_remove(&roots_xdg_surface->request_maximize.link);
- wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
- wl_list_remove(&roots_xdg_surface->view->link);
- view_finish(roots_xdg_surface->view);
- free(roots_xdg_surface->view);
- free(roots_xdg_surface);
+ view_destroy(roots_xdg_surface->view);
}
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
@@ -319,6 +350,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
&roots_surface->surface_commit);
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
+ roots_surface->map.notify = handle_map;
+ wl_signal_add(&surface->events.map, &roots_surface->map);
+ roots_surface->unmap.notify = handle_unmap;
+ wl_signal_add(&surface->events.unmap, &roots_surface->unmap);
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;
@@ -333,7 +368,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
- struct roots_view *view = view_create();
+ struct roots_view *view = view_create(desktop);
if (!view) {
free(roots_surface);
return;
@@ -342,22 +377,19 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->xdg_surface_v6 = surface;
view->roots_xdg_surface_v6 = roots_surface;
- view->wlr_surface = surface->surface;
view->activate = activate;
view->resize = resize;
view->move_resize = move_resize;
view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close;
+ view->destroy = destroy;
roots_surface->view = view;
- struct wlr_box box;
- get_size(view, &box);
- view->width = box.width;
- view->height = box.height;
-
- view_init(view, desktop);
- wl_list_insert(&desktop->views, &view->link);
-
- view_setup(view);
+ if (surface->toplevel->next.maximized) {
+ view_maximize(view, true);
+ }
+ if (surface->toplevel->next.fullscreen) {
+ view_set_fullscreen(view, true, NULL);
+ }
}
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index 56f068ea..53331b1f 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -106,11 +106,9 @@ static void set_fullscreen(struct roots_view *view, bool fullscreen) {
wlr_xwayland_surface_set_fullscreen(view->xwayland_surface, fullscreen);
}
-static void handle_destroy(struct wl_listener *listener, void *data) {
- struct roots_xwayland_surface *roots_surface =
- wl_container_of(listener, roots_surface, destroy);
- struct wlr_xwayland_surface *xwayland_surface =
- roots_surface->view->xwayland_surface;
+static void destroy(struct roots_view *view) {
+ assert(view->type == ROOTS_XWAYLAND_VIEW);
+ struct roots_xwayland_surface *roots_surface = view->roots_xwayland_surface;
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_configure.link);
wl_list_remove(&roots_surface->request_move.link);
@@ -118,14 +116,15 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->request_maximize.link);
wl_list_remove(&roots_surface->map_notify.link);
wl_list_remove(&roots_surface->unmap_notify.link);
- if (xwayland_surface->mapped) {
- wl_list_remove(&roots_surface->view->link);
- }
- view_finish(roots_surface->view);
- free(roots_surface->view);
free(roots_surface);
}
+static void handle_destroy(struct wl_listener *listener, void *data) {
+ struct roots_xwayland_surface *roots_surface =
+ wl_container_of(listener, roots_surface, destroy);
+ view_destroy(roots_surface->view);
+}
+
static void handle_request_configure(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, request_configure);
@@ -231,22 +230,13 @@ static void handle_map_notify(struct wl_listener *listener, void *data) {
wl_container_of(listener, roots_surface, map_notify);
struct wlr_xwayland_surface *xsurface = data;
struct roots_view *view = roots_surface->view;
- struct roots_desktop *desktop = view->desktop;
- view->wlr_surface = xsurface->surface;
view->x = xsurface->x;
view->y = xsurface->y;
view->width = xsurface->surface->current->width;
view->height = xsurface->surface->current->height;
- wl_list_insert(&desktop->views, &view->link);
- struct wlr_subsurface *subsurface;
- wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list,
- parent_link) {
- subsurface_create(view, subsurface);
- }
-
- view_damage_whole(view);
+ view_map(view, xsurface->surface);
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&xsurface->surface->events.commit,
@@ -260,22 +250,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->surface_commit.link);
- view_damage_whole(view);
-
- struct roots_view_child *child, *tmp;
- wl_list_for_each_safe(child, tmp, &view->children, link) {
- child->destroy(child);
- }
-
- if (view->fullscreen_output != NULL) {
- output_damage_whole(view->fullscreen_output);
- view->fullscreen_output->fullscreen_view = NULL;
- view->fullscreen_output = NULL;
- }
-
- view->wlr_surface = NULL;
- view->width = view->height = 0;
- wl_list_remove(&view->link);
+ view_unmap(view);
}
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
@@ -317,7 +292,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
- struct roots_view *view = view_create();
+ struct roots_view *view = view_create(desktop);
if (view == NULL) {
free(roots_surface);
return;
@@ -330,7 +305,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->xwayland_surface = surface;
view->roots_xwayland_surface = roots_surface;
- view->wlr_surface = surface->surface;
view->activate = activate;
view->resize = resize;
view->move = move;
@@ -338,9 +312,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->maximize = maximize;
view->set_fullscreen = set_fullscreen;
view->close = close;
+ view->destroy = destroy;
roots_surface->view = view;
- view_init(view, desktop);
- wl_list_insert(&desktop->views, &view->link);
+
+ view_map(view, surface->surface);
if (!surface->override_redirect) {
if (surface->decorations == WLR_XWAYLAND_SURFACE_DECORATIONS_ALL) {