aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2018-03-17 10:00:54 -0400
committerGitHub <noreply@github.com>2018-03-17 10:00:54 -0400
commit09413aa7f1eab176c12675217a17ebe367fa7d8f (patch)
treed97059ac24cefd144db7c7789461106a1f70b9c5
parent9cc875429b40e2567b219f8e9ffd23316d136204 (diff)
parent303883ce49b81438c8653991f40e72b0481e27cf (diff)
Merge pull request #711 from emersion/map-unmap
Add map/unmap to xdg-shell
-rw-r--r--include/rootston/desktop.h6
-rw-r--r--include/rootston/seat.h1
-rw-r--r--include/rootston/view.h7
-rw-r--r--include/wlr/types/wlr_xdg_shell.h33
-rw-r--r--include/wlr/types/wlr_xdg_shell_v6.h33
-rw-r--r--rootston/desktop.c77
-rw-r--r--rootston/output.c10
-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
-rw-r--r--types/wlr_xdg_shell.c518
-rw-r--r--types/wlr_xdg_shell_v6.c521
14 files changed, 855 insertions, 623 deletions
diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h
index db8a088e..5986c96f 100644
--- a/include/rootston/desktop.h
+++ b/include/rootston/desktop.h
@@ -73,14 +73,16 @@ struct roots_output *desktop_output_from_wlr_output(
struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
double ly, struct wlr_surface **surface, double *sx, double *sy);
-void view_init(struct roots_view *view, struct roots_desktop *desktop);
-void view_finish(struct roots_view *view);
+struct roots_view *view_create(struct roots_desktop *desktop);
+void view_destroy(struct roots_view *view);
void view_activate(struct roots_view *view, bool activate);
void view_apply_damage(struct roots_view *view);
void view_damage_whole(struct roots_view *view);
void view_update_position(struct roots_view *view, double x, double y);
void view_update_size(struct roots_view *view, uint32_t width, uint32_t height);
void view_initial_focus(struct roots_view *view);
+void view_map(struct roots_view *view, struct wlr_surface *surface);
+void view_unmap(struct roots_view *view);
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
diff --git a/include/rootston/seat.h b/include/rootston/seat.h
index cc0293b5..0b1dbe2d 100644
--- a/include/rootston/seat.h
+++ b/include/rootston/seat.h
@@ -39,6 +39,7 @@ struct roots_seat_view {
struct wl_list link; // roots_seat::views
+ struct wl_listener view_unmap;
struct wl_listener view_destroy;
};
diff --git a/include/rootston/view.h b/include/rootston/view.h
index ff5ef44a..775f3d11 100644
--- a/include/rootston/view.h
+++ b/include/rootston/view.h
@@ -27,6 +27,8 @@ struct roots_xdg_surface_v6 {
struct wl_listener destroy;
struct wl_listener new_popup;
+ struct wl_listener map;
+ struct wl_listener unmap;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
@@ -42,6 +44,8 @@ struct roots_xdg_surface {
struct wl_listener destroy;
struct wl_listener new_popup;
+ struct wl_listener map;
+ struct wl_listener unmap;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
@@ -128,6 +132,7 @@ struct roots_view {
struct wl_listener new_subsurface;
struct {
+ struct wl_signal unmap;
struct wl_signal destroy;
} events;
@@ -140,6 +145,7 @@ struct roots_view {
void (*maximize)(struct roots_view *view, bool maximized);
void (*set_fullscreen)(struct roots_view *view, bool fullscreen);
void (*close)(struct roots_view *view);
+ void (*destroy)(struct roots_view *view);
};
struct roots_view_child {
@@ -181,7 +187,6 @@ struct roots_xdg_popup {
struct wl_listener new_popup;
};
-struct roots_view *view_create();
void view_get_box(const struct roots_view *view, struct wlr_box *box);
void view_activate(struct roots_view *view, bool active);
void view_move(struct roots_view *view, double x, double y);
diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h
index 8422863c..ad0a626f 100644
--- a/include/wlr/types/wlr_xdg_shell.h
+++ b/include/wlr/types/wlr_xdg_shell.h
@@ -62,19 +62,10 @@ enum wlr_xdg_surface_role {
};
struct wlr_xdg_toplevel_state {
- bool maximized;
- bool fullscreen;
- bool resizing;
- bool activated;
-
- uint32_t width;
- uint32_t height;
-
- uint32_t max_width;
- uint32_t max_height;
-
- uint32_t min_width;
- uint32_t min_height;
+ bool maximized, fullscreen, resizing, activated;
+ uint32_t width, height;
+ uint32_t max_width, max_height;
+ uint32_t min_width, min_height;
};
struct wlr_xdg_toplevel {
@@ -90,7 +81,8 @@ struct wlr_xdg_toplevel {
struct wlr_xdg_surface_configure {
struct wl_list link; // wlr_xdg_surface::configure_list
uint32_t serial;
- struct wlr_xdg_toplevel_state state;
+
+ struct wlr_xdg_toplevel_state *toplevel_state;
};
struct wlr_xdg_surface {
@@ -101,14 +93,13 @@ struct wlr_xdg_surface {
enum wlr_xdg_surface_role role;
union {
- struct wlr_xdg_toplevel *toplevel_state;
- struct wlr_xdg_popup *popup_state;
+ struct wlr_xdg_toplevel *toplevel;
+ struct wlr_xdg_popup *popup;
};
struct wl_list popups; // wlr_xdg_popup::link
- bool configured;
- bool added;
+ bool added, configured, mapped;
uint32_t configure_serial;
struct wl_event_source *configure_idle;
uint32_t configure_next_serial;
@@ -118,8 +109,8 @@ struct wlr_xdg_surface {
char *app_id;
bool has_next_geometry;
- struct wlr_box *next_geometry;
- struct wlr_box *geometry;
+ struct wlr_box next_geometry;
+ struct wlr_box geometry;
struct wl_listener surface_destroy_listener;
@@ -127,6 +118,8 @@ struct wlr_xdg_surface {
struct wl_signal destroy;
struct wl_signal ping_timeout;
struct wl_signal new_popup;
+ struct wl_signal map;
+ struct wl_signal unmap;
struct wl_signal request_maximize;
struct wl_signal request_fullscreen;
diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h
index 7dc746ce..d8503d28 100644
--- a/include/wlr/types/wlr_xdg_shell_v6.h
+++ b/include/wlr/types/wlr_xdg_shell_v6.h
@@ -62,19 +62,10 @@ enum wlr_xdg_surface_v6_role {
};
struct wlr_xdg_toplevel_v6_state {
- bool maximized;
- bool fullscreen;
- bool resizing;
- bool activated;
-
- uint32_t width;
- uint32_t height;
-
- uint32_t max_width;
- uint32_t max_height;
-
- uint32_t min_width;
- uint32_t min_height;
+ bool maximized, fullscreen, resizing, activated;
+ uint32_t width, height;
+ uint32_t max_width, max_height;
+ uint32_t min_width, min_height;
};
struct wlr_xdg_toplevel_v6 {
@@ -90,7 +81,8 @@ struct wlr_xdg_toplevel_v6 {
struct wlr_xdg_surface_v6_configure {
struct wl_list link; // wlr_xdg_surface_v6::configure_list
uint32_t serial;
- struct wlr_xdg_toplevel_v6_state state;
+
+ struct wlr_xdg_toplevel_v6_state *toplevel_state;
};
struct wlr_xdg_surface_v6 {
@@ -101,14 +93,13 @@ struct wlr_xdg_surface_v6 {
enum wlr_xdg_surface_v6_role role;
union {
- struct wlr_xdg_toplevel_v6 *toplevel_state;
- struct wlr_xdg_popup_v6 *popup_state;
+ struct wlr_xdg_toplevel_v6 *toplevel;
+ struct wlr_xdg_popup_v6 *popup;
};
struct wl_list popups; // wlr_xdg_popup_v6::link
- bool configured;
- bool added;
+ bool added, configured, mapped;
uint32_t configure_serial;
struct wl_event_source *configure_idle;
uint32_t configure_next_serial;
@@ -118,8 +109,8 @@ struct wlr_xdg_surface_v6 {
char *app_id;
bool has_next_geometry;
- struct wlr_box *next_geometry;
- struct wlr_box *geometry;
+ struct wlr_box next_geometry;
+ struct wlr_box geometry;
struct wl_listener surface_destroy_listener;
@@ -127,6 +118,8 @@ struct wlr_xdg_surface_v6 {
struct wl_signal destroy;
struct wl_signal ping_timeout;
struct wl_signal new_popup;
+ struct wl_signal map;
+ struct wl_signal unmap;
struct wl_signal request_maximize;
struct wl_signal request_fullscreen;
diff --git a/rootston/desktop.c b/rootston/desktop.c
index a130fe38..9730ca57 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -24,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;
}
@@ -53,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;
}
@@ -93,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);
@@ -403,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,
@@ -426,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,
@@ -443,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?
@@ -458,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);
}
diff --git a/rootston/output.c b/rootston/output.c
index 4d0a9c05..f772ea24 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -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
@@ -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;
}
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) {
diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c
index 990926cf..5b02088d 100644
--- a/types/wlr_xdg_shell.c
+++ b/types/wlr_xdg_shell.c
@@ -34,7 +34,7 @@ struct wlr_xdg_positioner {
};
-static void resource_destroy(struct wl_client *client,
+static void resource_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
@@ -159,43 +159,37 @@ static struct wlr_xdg_popup_grab *xdg_shell_popup_grab_from_seat(
}
-static void xdg_surface_destroy(struct wlr_xdg_surface *surface) {
- // TODO: probably need to ungrab before this event
- wlr_signal_emit_safe(&surface->events.destroy, surface);
-
- if (surface->configure_idle) {
- wl_event_source_remove(surface->configure_idle);
+static void xdg_surface_configure_destroy(
+ struct wlr_xdg_surface_configure *configure) {
+ if (configure == NULL) {
+ return;
}
+ wl_list_remove(&configure->link);
+ free(configure->toplevel_state);
+ free(configure);
+}
- struct wlr_xdg_surface_configure *configure, *tmp;
- wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
- free(configure);
- }
+static void xdg_surface_unmap(struct wlr_xdg_surface *surface) {
+ assert(surface->role != WLR_XDG_SURFACE_ROLE_NONE);
+
+ // TODO: probably need to ungrab before this event
+ wlr_signal_emit_safe(&surface->events.unmap, surface);
if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
- wl_resource_set_user_data(surface->toplevel_state->resource, NULL);
- free(surface->toplevel_state);
+ wl_resource_set_user_data(surface->toplevel->resource, NULL);
+ free(surface->toplevel);
+ surface->toplevel = NULL;
}
if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
- wl_resource_set_user_data(surface->popup_state->resource, NULL);
+ wl_resource_set_user_data(surface->popup->resource, NULL);
- if (surface->popup_state->seat) {
+ if (surface->popup->seat) {
struct wlr_xdg_popup_grab *grab =
xdg_shell_popup_grab_from_seat(surface->client->shell,
- surface->popup_state->seat);
+ surface->popup->seat);
- struct wlr_xdg_surface *topmost =
- xdg_popup_grab_get_topmost(grab);
-
- if (topmost != surface) {
- wl_resource_post_error(surface->client->resource,
- XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP,
- "xdg_popup was destroyed while it was not the topmost "
- "popup.");
- }
-
- wl_list_remove(&surface->popup_state->grab_link);
+ wl_list_remove(&surface->popup->grab_link);
if (wl_list_empty(&grab->popups)) {
if (grab->seat->pointer_state.grab == &grab->pointer_grab) {
@@ -207,18 +201,46 @@ static void xdg_surface_destroy(struct wlr_xdg_surface *surface) {
}
}
- wl_list_remove(&surface->popup_state->link);
- free(surface->popup_state);
+ wl_list_remove(&surface->popup->link);
+ free(surface->popup);
+ surface->popup = NULL;
}
+ struct wlr_xdg_surface_configure *configure, *tmp;
+ wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
+ xdg_surface_configure_destroy(configure);
+ }
+
+ surface->role = WLR_XDG_SURFACE_ROLE_NONE;
+ free(surface->title);
+ surface->title = NULL;
+ free(surface->app_id);
+ surface->app_id = NULL;
+
+ surface->added = surface->configured = surface->mapped = false;
+ surface->configure_serial = 0;
+ if (surface->configure_idle) {
+ wl_event_source_remove(surface->configure_idle);
+ surface->configure_idle = NULL;
+ }
+ surface->configure_next_serial = 0;
+
+ surface->has_next_geometry = false;
+ memset(&surface->geometry, 0, sizeof(struct wlr_box));
+ memset(&surface->next_geometry, 0, sizeof(struct wlr_box));
+}
+
+static void xdg_surface_destroy(struct wlr_xdg_surface *surface) {
+ if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) {
+ xdg_surface_unmap(surface);
+ }
+
+ wlr_signal_emit_safe(&surface->events.destroy, surface);
+
wl_resource_set_user_data(surface->resource, NULL);
wl_list_remove(&surface->link);
wl_list_remove(&surface->surface_destroy_listener.link);
wlr_surface_set_role_committed(surface->surface, NULL, NULL);
- free(surface->geometry);
- free(surface->next_geometry);
- free(surface->title);
- free(surface->app_id);
free(surface);
}
@@ -238,7 +260,7 @@ static void xdg_positioner_destroy(struct wl_resource *resource) {
free(positioner);
}
-static void xdg_positioner_protocol_set_size(struct wl_client *client,
+static void xdg_positioner_handle_set_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_positioner *positioner =
xdg_positioner_from_resource(resource);
@@ -254,7 +276,7 @@ static void xdg_positioner_protocol_set_size(struct wl_client *client,
positioner->size.height = height;
}
-static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client,
+static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
int32_t height) {
struct wlr_xdg_positioner *positioner =
@@ -273,7 +295,7 @@ static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client,
positioner->anchor_rect.height = height;
}
-static void xdg_positioner_protocol_set_anchor(struct wl_client *client,
+static void xdg_positioner_handle_set_anchor(struct wl_client *client,
struct wl_resource *resource, uint32_t anchor) {
struct wlr_xdg_positioner *positioner =
xdg_positioner_from_resource(resource);
@@ -288,7 +310,7 @@ static void xdg_positioner_protocol_set_anchor(struct wl_client *client,
positioner->anchor = anchor;
}
-static void xdg_positioner_protocol_set_gravity(struct wl_client *client,
+static void xdg_positioner_handle_set_gravity(struct wl_client *client,
struct wl_resource *resource, uint32_t gravity) {
struct wlr_xdg_positioner *positioner =
xdg_positioner_from_resource(resource);
@@ -303,7 +325,7 @@ static void xdg_positioner_protocol_set_gravity(struct wl_client *client,
positioner->gravity = gravity;
}
-static void xdg_positioner_protocol_set_constraint_adjustment(
+static void xdg_positioner_handle_set_constraint_adjustment(
struct wl_client *client, struct wl_resource *resource,
uint32_t constraint_adjustment) {
struct wlr_xdg_positioner *positioner =
@@ -312,7 +334,7 @@ static void xdg_positioner_protocol_set_constraint_adjustment(
positioner->constraint_adjustment = constraint_adjustment;
}
-static void xdg_positioner_protocol_set_offset(struct wl_client *client,
+static void xdg_positioner_handle_set_offset(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y) {
struct wlr_xdg_positioner *positioner =
xdg_positioner_from_resource(resource);
@@ -323,17 +345,17 @@ static void xdg_positioner_protocol_set_offset(struct wl_client *client,
static const struct xdg_positioner_interface
xdg_positioner_implementation = {
- .destroy = resource_destroy,
- .set_size = xdg_positioner_protocol_set_size,
- .set_anchor_rect = xdg_positioner_protocol_set_anchor_rect,
- .set_anchor = xdg_positioner_protocol_set_anchor,
- .set_gravity = xdg_positioner_protocol_set_gravity,
+ .destroy = resource_handle_destroy,
+ .set_size = xdg_positioner_handle_set_size,
+ .set_anchor_rect = xdg_positioner_handle_set_anchor_rect,
+ .set_anchor = xdg_positioner_handle_set_anchor,
+ .set_gravity = xdg_positioner_handle_set_gravity,
.set_constraint_adjustment =
- xdg_positioner_protocol_set_constraint_adjustment,
- .set_offset = xdg_positioner_protocol_set_offset,
+ xdg_positioner_handle_set_constraint_adjustment,
+ .set_offset = xdg_positioner_handle_set_offset,
};
-static void xdg_shell_create_positioner(struct wl_client *wl_client,
+static void xdg_shell_handle_create_positioner(struct wl_client *wl_client,
struct wl_resource *resource, uint32_t id) {
struct wlr_xdg_positioner *positioner =
calloc(1, sizeof(struct wlr_xdg_positioner));
@@ -458,7 +480,7 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_popup_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_popup_protocol_grab(struct wl_client *client,
+static void xdg_popup_handle_grab(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
struct wlr_xdg_surface *surface =
@@ -466,8 +488,8 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
struct wlr_seat_client *seat_client =
wlr_seat_client_from_resource(seat_resource);
- if (surface->popup_state->committed) {
- wl_resource_post_error(surface->popup_state->resource,
+ if (surface->popup->committed) {
+ wl_resource_post_error(surface->popup->resource,
XDG_POPUP_ERROR_INVALID_GRAB,
"xdg_popup is already mapped");
return;
@@ -479,10 +501,10 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
struct wlr_xdg_surface *topmost = xdg_popup_grab_get_topmost(popup_grab);
bool parent_is_toplevel =
- surface->popup_state->parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL;
+ surface->popup->parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL;
if ((topmost == NULL && !parent_is_toplevel) ||
- (topmost != NULL && topmost != surface->popup_state->parent)) {
+ (topmost != NULL && topmost != surface->popup->parent)) {
wl_resource_post_error(surface->client->resource,
XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP,
"xdg_popup was not created on the topmost popup");
@@ -490,9 +512,9 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
}
popup_grab->client = surface->client->client;
- surface->popup_state->seat = seat_client->seat;
+ surface->popup->seat = seat_client->seat;
- wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link);
+ wl_list_insert(&popup_grab->popups, &surface->popup->grab_link);
wlr_seat_pointer_start_grab(seat_client->seat,
&popup_grab->pointer_grab);
@@ -500,16 +522,36 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
&popup_grab->keyboard_grab);
}
+static void xdg_popup_handle_destroy(struct wl_client *client,
+ struct wl_resource *resource) {
+ struct wlr_xdg_surface *surface =
+ xdg_surface_from_xdg_popup_resource(resource);
+ struct wlr_xdg_popup_grab *grab =
+ xdg_shell_popup_grab_from_seat(surface->client->shell,
+ surface->popup->seat);
+ struct wlr_xdg_surface *topmost =
+ xdg_popup_grab_get_topmost(grab);
+
+ if (topmost != surface) {
+ wl_resource_post_error(surface->client->resource,
+ XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP,
+ "xdg_popup was destroyed while it was not the topmost popup");
+ return;
+ }
+
+ wl_resource_destroy(resource);
+}
+
static const struct xdg_popup_interface xdg_popup_implementation = {
- .destroy = resource_destroy,
- .grab = xdg_popup_protocol_grab,
+ .destroy = xdg_popup_handle_destroy,
+ .grab = xdg_popup_handle_grab,
};
static void xdg_popup_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_popup_resource(resource);
if (surface != NULL) {
- xdg_surface_destroy(surface);
+ xdg_surface_unmap(surface);
}
}
@@ -522,7 +564,7 @@ static struct wlr_xdg_surface *xdg_surface_from_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_surface_get_popup(struct wl_client *client,
+static void xdg_surface_handle_get_popup(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
struct wl_resource *parent_resource,
struct wl_resource *positioner_resource) {
@@ -545,33 +587,33 @@ static void xdg_surface_get_popup(struct wl_client *client,
return;
}
- surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup));
- if (!surface->popup_state) {
+ surface->popup = calloc(1, sizeof(struct wlr_xdg_popup));
+ if (!surface->popup) {
wl_resource_post_no_memory(resource);
return;
}
- surface->popup_state->resource =
+ surface->popup->resource =
wl_resource_create(client, &xdg_popup_interface,
wl_resource_get_version(resource), id);
- if (surface->popup_state->resource == NULL) {
- free(surface->popup_state);
+ if (surface->popup->resource == NULL) {
+ free(surface->popup);
wl_resource_post_no_memory(resource);
return;
}
surface->role = WLR_XDG_SURFACE_ROLE_POPUP;
- surface->popup_state->base = surface;
- surface->popup_state->parent = parent;
- surface->popup_state->geometry =
+ surface->popup->base = surface;
+ surface->popup->parent = parent;
+ surface->popup->geometry =
xdg_positioner_get_geometry(positioner, surface, parent);
- wl_list_insert(&parent->popups, &surface->popup_state->link);
+ wl_list_insert(&parent->popups, &surface->popup->link);
- wl_resource_set_implementation(surface->popup_state->resource,
+ wl_resource_set_implementation(surface->popup->resource,
&xdg_popup_implementation, surface,
xdg_popup_resource_destroy);
- wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state);
+ wlr_signal_emit_safe(&parent->events.new_popup, surface->popup);
}
@@ -584,7 +626,7 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_toplevel_protocol_set_parent(struct wl_client *client,
+static void xdg_toplevel_handle_set_parent(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *parent_resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -594,10 +636,10 @@ static void xdg_toplevel_protocol_set_parent(struct wl_client *client,
parent = xdg_surface_from_xdg_toplevel_resource(parent_resource);
}
- surface->toplevel_state->parent = parent;
+ surface->toplevel->parent = parent;
}
-static void xdg_toplevel_protocol_set_title(struct wl_client *client,
+static void xdg_toplevel_handle_set_title(struct wl_client *client,
struct wl_resource *resource, const char *title) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -612,7 +654,7 @@ static void xdg_toplevel_protocol_set_title(struct wl_client *client,
surface->title = tmp;
}
-static void xdg_toplevel_protocol_set_app_id(struct wl_client *client,
+static void xdg_toplevel_handle_set_app_id(struct wl_client *client,
struct wl_resource *resource, const char *app_id) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -627,7 +669,7 @@ static void xdg_toplevel_protocol_set_app_id(struct wl_client *client,
surface->app_id = tmp;
}
-static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
+static void xdg_toplevel_handle_show_window_menu(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, int32_t x, int32_t y) {
struct wlr_xdg_surface *surface =
@@ -636,7 +678,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
wlr_seat_client_from_resource(seat_resource);
if (!surface->configured) {
- wl_resource_post_error(surface->toplevel_state->resource,
+ wl_resource_post_error(surface->toplevel->resource,
XDG_SURFACE_ERROR_NOT_CONSTRUCTED,
"surface has not been configured yet");
return;
@@ -658,7 +700,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event);
}
-static void xdg_toplevel_protocol_move(struct wl_client *client,
+static void xdg_toplevel_handle_move(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
struct wlr_xdg_surface *surface =
@@ -667,7 +709,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client,
wlr_seat_client_from_resource(seat_resource);
if (!surface->configured) {
- wl_resource_post_error(surface->toplevel_state->resource,
+ wl_resource_post_error(surface->toplevel->resource,
XDG_SURFACE_ERROR_NOT_CONSTRUCTED,
"surface has not been configured yet");
return;
@@ -687,7 +729,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_move, &event);
}
-static void xdg_toplevel_protocol_resize(struct wl_client *client,
+static void xdg_toplevel_handle_resize(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, uint32_t edges) {
struct wlr_xdg_surface *surface =
@@ -696,7 +738,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client,
wlr_seat_client_from_resource(seat_resource);
if (!surface->configured) {
- wl_resource_post_error(surface->toplevel_state->resource,
+ wl_resource_post_error(surface->toplevel->resource,
XDG_SURFACE_ERROR_NOT_CONSTRUCTED,
"surface has not been configured yet");
return;
@@ -717,39 +759,39 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_resize, &event);
}
-static void xdg_toplevel_protocol_set_max_size(struct wl_client *client,
+static void xdg_toplevel_handle_set_max_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.max_width = width;
- surface->toplevel_state->next.max_height = height;
+ surface->toplevel->next.max_width = width;
+ surface->toplevel->next.max_height = height;
}
-static void xdg_toplevel_protocol_set_min_size(struct wl_client *client,
+static void xdg_toplevel_handle_set_min_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.min_width = width;
- surface->toplevel_state->next.min_height = height;
+ surface->toplevel->next.min_width = width;
+ surface->toplevel->next.min_height = height;
}
-static void xdg_toplevel_protocol_set_maximized(struct wl_client *client,
+static void xdg_toplevel_handle_set_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.maximized = true;
+ surface->toplevel->next.maximized = true;
wlr_signal_emit_safe(&surface->events.request_maximize, surface);
}
-static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client,
+static void xdg_toplevel_handle_unset_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.maximized = false;
+ surface->toplevel->next.maximized = false;
wlr_signal_emit_safe(&surface->events.request_maximize, surface);
}
-static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
+static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -759,7 +801,7 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
output = wlr_output_from_resource(output_resource);
}
- surface->toplevel_state->next.fullscreen = true;
+ surface->toplevel->next.fullscreen = true;
struct wlr_xdg_toplevel_set_fullscreen_event event = {
.surface = surface,
@@ -770,12 +812,12 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_fullscreen, &event);
}
-static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
+static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.fullscreen = false;
+ surface->toplevel->next.fullscreen = false;
struct wlr_xdg_toplevel_set_fullscreen_event event = {
.surface = surface,
@@ -786,7 +828,7 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_fullscreen, &event);
}
-static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,
+static void xdg_toplevel_handle_set_minimized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -794,20 +836,20 @@ static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,
}
static const struct xdg_toplevel_interface xdg_toplevel_implementation = {
- .destroy = resource_destroy,
- .set_parent = xdg_toplevel_protocol_set_parent,
- .set_title = xdg_toplevel_protocol_set_title,
- .set_app_id = xdg_toplevel_protocol_set_app_id,
- .show_window_menu = xdg_toplevel_protocol_show_window_menu,
- .move = xdg_toplevel_protocol_move,
- .resize = xdg_toplevel_protocol_resize,
- .set_max_size = xdg_toplevel_protocol_set_max_size,
- .set_min_size = xdg_toplevel_protocol_set_min_size,
- .set_maximized = xdg_toplevel_protocol_set_maximized,
- .unset_maximized = xdg_toplevel_protocol_unset_maximized,
- .set_fullscreen = xdg_toplevel_protocol_set_fullscreen,
- .unset_fullscreen = xdg_toplevel_protocol_unset_fullscreen,
- .set_minimized = xdg_toplevel_protocol_set_minimized
+ .destroy = resource_handle_destroy,
+ .set_parent = xdg_toplevel_handle_set_parent,
+ .set_title = xdg_toplevel_handle_set_title,
+ .set_app_id = xdg_toplevel_handle_set_app_id,
+ .show_window_menu = xdg_toplevel_handle_show_window_menu,
+ .move = xdg_toplevel_handle_move,
+ .resize = xdg_toplevel_handle_resize,
+ .set_max_size = xdg_toplevel_handle_set_max_size,
+ .set_min_size = xdg_toplevel_handle_set_min_size,
+ .set_maximized = xdg_toplevel_handle_set_maximized,
+ .unset_maximized = xdg_toplevel_handle_unset_maximized,
+ .set_fullscreen = xdg_toplevel_handle_set_fullscreen,
+ .unset_fullscreen = xdg_toplevel_handle_unset_fullscreen,
+ .set_minimized = xdg_toplevel_handle_set_minimized,
};
static void xdg_surface_resource_destroy(struct wl_resource *resource) {
@@ -822,11 +864,11 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
if (surface != NULL) {
- xdg_surface_destroy(surface);
+ xdg_surface_unmap(surface);
}
}
-static void xdg_surface_get_toplevel(struct wl_client *client,
+static void xdg_surface_handle_get_toplevel(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource);
@@ -835,24 +877,24 @@ static void xdg_surface_get_toplevel(struct wl_client *client,
return;
}
- surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel));
- if (surface->toplevel_state == NULL) {
+ surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel));
+ if (surface->toplevel == NULL) {
wl_resource_post_no_memory(resource);
return;
}
surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL;
- surface->toplevel_state->base = surface;
+ surface->toplevel->base = surface;
struct wl_resource *toplevel_resource = wl_resource_create(client,
&xdg_toplevel_interface, wl_resource_get_version(resource), id);
if (toplevel_resource == NULL) {
- free(surface->toplevel_state);
+ free(surface->toplevel);
wl_resource_post_no_memory(resource);
return;
}
- surface->toplevel_state->resource = toplevel_resource;
+ surface->toplevel->resource = toplevel_resource;
wl_resource_set_implementation(toplevel_resource,
&xdg_toplevel_implementation, surface,
@@ -863,12 +905,19 @@ static void wlr_xdg_toplevel_ack_configure(
struct wlr_xdg_surface *surface,
struct wlr_xdg_surface_configure *configure) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- surface->toplevel_state->next = configure->state;
- surface->toplevel_state->pending.width = 0;
- surface->toplevel_state->pending.height = 0;
+ assert(configure->toplevel_state != NULL);
+
+ surface->toplevel->current.maximized =
+ configure->toplevel_state->maximized;
+ surface->toplevel->current.fullscreen =
+ configure->toplevel_state->fullscreen;
+ surface->toplevel->current.resizing =
+ configure->toplevel_state->resizing;
+ surface->toplevel->current.activated =
+ configure->toplevel_state->activated;
}
-static void xdg_surface_ack_configure(struct wl_client *client,
+static void xdg_surface_handle_ack_configure(struct wl_client *client,
struct wl_resource *resource, uint32_t serial) {
struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource);
@@ -883,10 +932,8 @@ static void xdg_surface_ack_configure(struct wl_client *client,
struct wlr_xdg_surface_configure *configure, *tmp;
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
if (configure->serial < serial) {
- wl_list_remove(&configure->link);
- free(configure);
+ xdg_surface_configure_destroy(configure);
} else if (configure->serial == serial) {
- wl_list_remove(&configure->link);
found = true;
break;
} else {
@@ -914,10 +961,10 @@ static void xdg_surface_ack_configure(struct wl_client *client,
surface->configured = true;
surface->configure_serial = serial;
- free(configure);
+ xdg_surface_configure_destroy(configure);
}
-static void xdg_surface_set_window_geometry(struct wl_client *client,
+static void xdg_surface_handle_set_window_geometry(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
int32_t height) {
struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource);
@@ -930,19 +977,31 @@ static void xdg_surface_set_window_geometry(struct wl_client *client,
}
surface->has_next_geometry = true;
- surface->next_geometry->height = height;
- surface->next_geometry->width = width;
- surface->next_geometry->x = x;
- surface->next_geometry->y = y;
+ surface->next_geometry.height = height;
+ surface->next_geometry.width = width;
+ surface->next_geometry.x = x;
+ surface->next_geometry.y = y;
+}
+
+static void xdg_surface_handle_destroy(struct wl_client *client,
+ struct wl_resource *resource) {
+ struct wlr_xdg_surface *surface = xdg_surface_from_resource(resource);
+ if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) {
+ wlr_log(L_ERROR, "Tried to destroy an xdg_surface before its role "
+ "object");
+ return;
+ }
+
+ wl_resource_destroy(resource);
}
static const struct xdg_surface_interface xdg_surface_implementation = {
- .destroy = resource_destroy,
- .get_toplevel = xdg_surface_get_toplevel,
- .get_popup = xdg_surface_get_popup,
- .ack_configure = xdg_surface_ack_configure,
- .set_window_geometry = xdg_surface_set_window_geometry,
+ .destroy = xdg_surface_handle_destroy,
+ .get_toplevel = xdg_surface_handle_get_toplevel,
+ .get_popup = xdg_surface_handle_get_popup,
+ .ack_configure = xdg_surface_handle_ack_configure,
+ .set_window_geometry = xdg_surface_handle_set_window_geometry,
};
static bool wlr_xdg_surface_toplevel_state_compare(
@@ -965,9 +1024,9 @@ static bool wlr_xdg_surface_toplevel_state_compare(
} else {
struct wlr_xdg_surface_configure *configure =
wl_container_of(state->base->configure_list.prev, configure, link);
- configured.state = configure->state;
- configured.width = configure->state.width;
- configured.height = configure->state.height;
+ configured.state = *configure->toplevel_state;
+ configured.width = configure->toplevel_state->width;
+ configured.height = configure->toplevel_state->height;
}
if (state->pending.activated != configured.state.activated) {
@@ -999,13 +1058,19 @@ static void wlr_xdg_toplevel_send_configure(
struct wlr_xdg_surface *surface,
struct wlr_xdg_surface_configure *configure) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- uint32_t *s;
- struct wl_array states;
- configure->state = surface->toplevel_state->pending;
+ configure->toplevel_state = malloc(sizeof(*configure->toplevel_state));
+ if (configure->toplevel_state == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ wl_resource_post_no_memory(surface->toplevel->resource);
+ return;
+ }
+ *configure->toplevel_state = surface->toplevel->pending;
+ uint32_t *s;
+ struct wl_array states;
wl_array_init(&states);
- if (surface->toplevel_state->pending.maximized) {
+ if (surface->toplevel->pending.maximized) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel");
@@ -1013,7 +1078,7 @@ static void wlr_xdg_toplevel_send_configure(
}
*s = XDG_TOPLEVEL_STATE_MAXIMIZED;
}
- if (surface->toplevel_state->pending.fullscreen) {
+ if (surface->toplevel->pending.fullscreen) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel");
@@ -1021,7 +1086,7 @@ static void wlr_xdg_toplevel_send_configure(
}
*s = XDG_TOPLEVEL_STATE_FULLSCREEN;
}
- if (surface->toplevel_state->pending.resizing) {
+ if (surface->toplevel->pending.resizing) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel");
@@ -1029,7 +1094,7 @@ static void wlr_xdg_toplevel_send_configure(
}
*s = XDG_TOPLEVEL_STATE_RESIZING;
}
- if (surface->toplevel_state->pending.activated) {
+ if (surface->toplevel->pending.activated) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel");
@@ -1038,23 +1103,17 @@ static void wlr_xdg_toplevel_send_configure(
*s = XDG_TOPLEVEL_STATE_ACTIVATED;
}
- uint32_t width = surface->toplevel_state->pending.width;
- uint32_t height = surface->toplevel_state->pending.height;
-
- if (width == 0 || height == 0) {
- width = surface->geometry->width;
- height = surface->geometry->height;
- }
-
- xdg_toplevel_send_configure(surface->toplevel_state->resource, width,
- height, &states);
+ uint32_t width = surface->toplevel->pending.width;
+ uint32_t height = surface->toplevel->pending.height;
+ xdg_toplevel_send_configure(surface->toplevel->resource, width, height,
+ &states);
wl_array_release(&states);
return;
error_out:
wl_array_release(&states);
- wl_resource_post_no_memory(surface->toplevel_state->resource);
+ wl_resource_post_no_memory(surface->toplevel->resource);
}
static void wlr_xdg_surface_send_configure(void *user_data) {
@@ -1080,11 +1139,11 @@ static void wlr_xdg_surface_send_configure(void *user_data) {
wlr_xdg_toplevel_send_configure(surface, configure);
break;
case WLR_XDG_SURFACE_ROLE_POPUP:
- xdg_popup_send_configure(surface->popup_state->resource,
- surface->popup_state->geometry.x,
- surface->popup_state->geometry.y,
- surface->popup_state->geometry.width,
- surface->popup_state->geometry.height);
+ xdg_popup_send_configure(surface->popup->resource,
+ surface->popup->geometry.x,
+ surface->popup->geometry.y,
+ surface->popup->geometry.width,
+ surface->popup->geometry.height);
break;
}
@@ -1103,7 +1162,7 @@ static uint32_t wlr_xdg_surface_schedule_configure(
break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
pending_same =
- wlr_xdg_surface_toplevel_state_compare(surface->toplevel_state);
+ wlr_xdg_surface_toplevel_state_compare(surface->toplevel);
break;
case WLR_XDG_SURFACE_ROLE_POPUP:
break;
@@ -1143,29 +1202,32 @@ static void wlr_xdg_surface_toplevel_committed(
struct wlr_xdg_surface *surface) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- if (!wlr_surface_has_buffer(surface->surface)
- && !surface->toplevel_state->added) {
+ if (!surface->toplevel->added) {
// on the first commit, send a configure request to tell the client it
// is added
wlr_xdg_surface_schedule_configure(surface);
- surface->toplevel_state->added = true;
- return;
- }
-
- if (!wlr_surface_has_buffer(surface->surface)) {
+ surface->toplevel->added = true;
return;
}
- surface->toplevel_state->current = surface->toplevel_state->next;
+ // update state that doesn't need compositor approval
+ surface->toplevel->current.max_width =
+ surface->toplevel->next.max_width;
+ surface->toplevel->current.min_width =
+ surface->toplevel->next.min_width;
+ surface->toplevel->current.max_height =
+ surface->toplevel->next.max_height;
+ surface->toplevel->current.min_height =
+ surface->toplevel->next.min_height;
}
static void wlr_xdg_surface_popup_committed(
struct wlr_xdg_surface *surface) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP);
- if (!surface->popup_state->committed) {
+ if (!surface->popup->committed) {
wlr_xdg_surface_schedule_configure(surface);
- surface->popup_state->committed = true;
+ surface->popup->committed = true;
}
}
@@ -1182,10 +1244,10 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
if (surface->has_next_geometry) {
surface->has_next_geometry = false;
- surface->geometry->x = surface->next_geometry->x;
- surface->geometry->y = surface->next_geometry->y;
- surface->geometry->width = surface->next_geometry->width;
- surface->geometry->height = surface->next_geometry->height;
+ surface->geometry.x = surface->next_geometry.x;
+ surface->geometry.y = surface->next_geometry.y;
+ surface->geometry.width = surface->next_geometry.width;
+ surface->geometry.height = surface->next_geometry.height;
}
switch (surface->role) {
@@ -1202,9 +1264,19 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
break;
}
- if (surface->configured && !surface->added) {
+ if (!surface->added) {
surface->added = true;
- wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface);
+ wlr_signal_emit_safe(&surface->client->shell->events.new_surface,
+ surface);
+ }
+ if (surface->configured && wlr_surface_has_buffer(surface->surface) &&
+ !surface->mapped) {
+ surface->mapped = true;
+ wlr_signal_emit_safe(&surface->events.map, surface);
+ }
+ if (surface->configured && !wlr_surface_has_buffer(surface->surface) &&
+ surface->mapped) {
+ xdg_surface_unmap(surface);
}
}
@@ -1217,27 +1289,15 @@ static struct wlr_xdg_client *xdg_client_from_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
+static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client,
struct wl_resource *client_resource, uint32_t id,
struct wl_resource *surface_resource) {
struct wlr_xdg_client *client =
xdg_client_from_resource(client_resource);
- struct wlr_xdg_surface *surface;
- if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface)))) {
- wl_client_post_no_memory(wl_client);
- return;
- }
-
- if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) {
- free(surface);
- wl_client_post_no_memory(wl_client);
- return;
- }
-
- if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) {
- free(surface->geometry);
- free(surface);
+ struct wlr_xdg_surface *surface =
+ calloc(1, sizeof(struct wlr_xdg_surface));
+ if (surface == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
@@ -1249,8 +1309,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
&xdg_surface_interface, wl_resource_get_version(client_resource),
id);
if (surface->resource == NULL) {
- free(surface->next_geometry);
- free(surface->geometry);
free(surface);
wl_client_post_no_memory(wl_client);
return;
@@ -1258,8 +1316,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
if (wlr_surface_has_buffer(surface->surface)) {
wl_resource_destroy(surface->resource);
- free(surface->next_geometry);
- free(surface->geometry);
free(surface);
wl_resource_post_error(surface_resource,
XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER,
@@ -1279,6 +1335,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.ping_timeout);
wl_signal_init(&surface->events.new_popup);
+ wl_signal_init(&surface->events.map);
+ wl_signal_init(&surface->events.unmap);
wl_signal_add(&surface->surface->events.destroy,
&surface->surface_destroy_listener);
@@ -1293,7 +1351,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_list_insert(&client->surfaces, &surface->link);
}
-static void xdg_shell_pong(struct wl_client *wl_client,
+static void xdg_shell_handle_pong(struct wl_client *wl_client,
struct wl_resource *resource, uint32_t serial) {
struct wlr_xdg_client *client = xdg_client_from_resource(resource);
@@ -1305,11 +1363,25 @@ static void xdg_shell_pong(struct wl_client *wl_client,
client->ping_serial = 0;
}
+static void xdg_shell_handle_destroy(struct wl_client *wl_client,
+ struct wl_resource *resource) {
+ struct wlr_xdg_client *client = xdg_client_from_resource(resource);
+
+ if (!wl_list_empty(&client->surfaces)) {
+ wl_resource_post_error(client->resource,
+ XDG_WM_BASE_ERROR_DEFUNCT_SURFACES,
+ "xdg_wm_base was destroyed before children");
+ return;
+ }
+
+ wl_resource_destroy(resource);
+}
+
static const struct xdg_wm_base_interface xdg_shell_impl = {
- .destroy = resource_destroy,
- .create_positioner = xdg_shell_create_positioner,
- .get_xdg_surface = xdg_shell_get_xdg_surface,
- .pong = xdg_shell_pong,
+ .destroy = xdg_shell_handle_destroy,
+ .create_positioner = xdg_shell_handle_create_positioner,
+ .get_xdg_surface = xdg_shell_handle_get_xdg_surface,
+ .pong = xdg_shell_handle_pong,
};
static void wlr_xdg_client_destroy(struct wl_resource *resource) {
@@ -1437,8 +1509,8 @@ void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface) {
uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface,
uint32_t width, uint32_t height) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.width = width;
- surface->toplevel_state->pending.height = height;
+ surface->toplevel->pending.width = width;
+ surface->toplevel->pending.height = height;
return wlr_xdg_surface_schedule_configure(surface);
}
@@ -1446,7 +1518,7 @@ uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface,
uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface,
bool activated) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.activated = activated;
+ surface->toplevel->pending.activated = activated;
return wlr_xdg_surface_schedule_configure(surface);
}
@@ -1454,7 +1526,7 @@ uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface,
uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface,
bool maximized) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.maximized = maximized;
+ surface->toplevel->pending.maximized = maximized;
return wlr_xdg_surface_schedule_configure(surface);
}
@@ -1462,7 +1534,7 @@ uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface,
uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface,
bool fullscreen) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.fullscreen = fullscreen;
+ surface->toplevel->pending.fullscreen = fullscreen;
return wlr_xdg_surface_schedule_configure(surface);
}
@@ -1470,24 +1542,24 @@ uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface,
uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface,
bool resizing) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.resizing = resizing;
+ surface->toplevel->pending.resizing = resizing;
return wlr_xdg_surface_schedule_configure(surface);
}
void wlr_xdg_toplevel_send_close(struct wlr_xdg_surface *surface) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
- xdg_toplevel_send_close(surface->toplevel_state->resource);
+ xdg_toplevel_send_close(surface->toplevel->resource);
}
void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
double *popup_sx, double *popup_sy) {
assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP);
- struct wlr_xdg_surface *parent = surface->popup_state->parent;
- *popup_sx = parent->geometry->x + surface->popup_state->geometry.x -
- surface->geometry->x;
- *popup_sy = parent->geometry->y + surface->popup_state->geometry.y -
- surface->geometry->y;
+ struct wlr_xdg_surface *parent = surface->popup->parent;
+ *popup_sx = parent->geometry.x + surface->popup->geometry.x -
+ surface->geometry.x;
+ *popup_sy = parent->geometry.y + surface->popup->geometry.y -
+ surface->geometry.y;
}
struct wlr_xdg_surface *wlr_xdg_surface_popup_at(
@@ -1501,30 +1573,30 @@ struct wlr_xdg_surface *wlr_xdg_surface_popup_at(
struct wlr_xdg_surface *popup = popup_state->base;
double _popup_sx =
- surface->geometry->x + popup_state->geometry.x;
+ surface->geometry.x + popup_state->geometry.x;
double _popup_sy =
- surface->geometry->y + popup_state->geometry.y;
+ surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
struct wlr_xdg_surface *_popup =
wlr_xdg_surface_popup_at(popup,
- sx - _popup_sx + popup->geometry->x,
- sy - _popup_sy + popup->geometry->y,
+ sx - _popup_sx + popup->geometry.x,
+ sy - _popup_sy + popup->geometry.y,
popup_sx, popup_sy);
if (_popup) {
- *popup_sx = *popup_sx + _popup_sx - popup->geometry->x;
- *popup_sy = *popup_sy + _popup_sy - popup->geometry->y;
+ *popup_sx = *popup_sx + _popup_sx - popup->geometry.x;
+ *popup_sy = *popup_sy + _popup_sy - popup->geometry.y;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
if (pixman_region32_contains_point(&popup->surface->current->input,
- sx - _popup_sx + popup->geometry->x,
- sy - _popup_sy + popup->geometry->y, NULL)) {
- *popup_sx = _popup_sx - popup->geometry->x;
- *popup_sy = _popup_sy - popup->geometry->y;
+ sx - _popup_sx + popup->geometry.x,
+ sy - _popup_sy + popup->geometry.y, NULL)) {
+ *popup_sx = _popup_sx - popup->geometry.x;
+ *popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
}
diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c
index 48dfa3ac..a0c74e6f 100644
--- a/types/wlr_xdg_shell_v6.c
+++ b/types/wlr_xdg_shell_v6.c
@@ -34,7 +34,7 @@ struct wlr_xdg_positioner_v6 {
};
-static void resource_destroy(struct wl_client *client,
+static void resource_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
@@ -159,43 +159,37 @@ static struct wlr_xdg_popup_grab_v6 *xdg_shell_popup_grab_from_seat(
}
-static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) {
- // TODO: probably need to ungrab before this event
- wlr_signal_emit_safe(&surface->events.destroy, surface);
-
- if (surface->configure_idle) {
- wl_event_source_remove(surface->configure_idle);
+static void xdg_surface_configure_destroy(
+ struct wlr_xdg_surface_v6_configure *configure) {
+ if (configure == NULL) {
+ return;
}
+ wl_list_remove(&configure->link);
+ free(configure->toplevel_state);
+ free(configure);
+}
- struct wlr_xdg_surface_v6_configure *configure, *tmp;
- wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
- free(configure);
- }
+static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) {
+ assert(surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE);
+
+ // TODO: probably need to ungrab before this event
+ wlr_signal_emit_safe(&surface->events.unmap, surface);
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
- wl_resource_set_user_data(surface->toplevel_state->resource, NULL);
- free(surface->toplevel_state);
+ wl_resource_set_user_data(surface->toplevel->resource, NULL);
+ free(surface->toplevel);
+ surface->toplevel = NULL;
}
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) {
- wl_resource_set_user_data(surface->popup_state->resource, NULL);
+ wl_resource_set_user_data(surface->popup->resource, NULL);
- if (surface->popup_state->seat) {
+ if (surface->popup->seat) {
struct wlr_xdg_popup_grab_v6 *grab =
xdg_shell_popup_grab_from_seat(surface->client->shell,
- surface->popup_state->seat);
+ surface->popup->seat);
- struct wlr_xdg_surface_v6 *topmost =
- xdg_popup_grab_get_topmost(grab);
-
- if (topmost != surface) {
- wl_resource_post_error(surface->client->resource,
- ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
- "xdg_popup was destroyed while it was not the topmost "
- "popup.");
- }
-
- wl_list_remove(&surface->popup_state->grab_link);
+ wl_list_remove(&surface->popup->grab_link);
if (wl_list_empty(&grab->popups)) {
if (grab->seat->pointer_state.grab == &grab->pointer_grab) {
@@ -207,18 +201,46 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) {
}
}
- wl_list_remove(&surface->popup_state->link);
- free(surface->popup_state);
+ wl_list_remove(&surface->popup->link);
+ free(surface->popup);
+ surface->popup = NULL;
}
+ struct wlr_xdg_surface_v6_configure *configure, *tmp;
+ wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
+ xdg_surface_configure_destroy(configure);
+ }
+
+ surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE;
+ free(surface->title);
+ surface->title = NULL;
+ free(surface->app_id);
+ surface->app_id = NULL;
+
+ surface->added = surface->configured = surface->mapped = false;
+ surface->configure_serial = 0;
+ if (surface->configure_idle) {
+ wl_event_source_remove(surface->configure_idle);
+ surface->configure_idle = NULL;
+ }
+ surface->configure_next_serial = 0;
+
+ surface->has_next_geometry = false;
+ memset(&surface->geometry, 0, sizeof(struct wlr_box));
+ memset(&surface->next_geometry, 0, sizeof(struct wlr_box));
+}
+
+static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) {
+ if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) {
+ xdg_surface_unmap(surface);
+ }
+
+ wlr_signal_emit_safe(&surface->events.destroy, surface);
+
wl_resource_set_user_data(surface->resource, NULL);
wl_list_remove(&surface->link);
wl_list_remove(&surface->surface_destroy_listener.link);
wlr_surface_set_role_committed(surface->surface, NULL, NULL);
- free(surface->geometry);
- free(surface->next_geometry);
- free(surface->title);
- free(surface->app_id);
free(surface);
}
@@ -237,10 +259,9 @@ static void xdg_positioner_destroy(struct wl_resource *resource) {
struct wlr_xdg_positioner_v6 *positioner =
xdg_positioner_from_resource(resource);
free(positioner);
-
}
-static void xdg_positioner_protocol_set_size(struct wl_client *client,
+static void xdg_positioner_handle_set_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_positioner_v6 *positioner =
xdg_positioner_from_resource(resource);
@@ -256,7 +277,7 @@ static void xdg_positioner_protocol_set_size(struct wl_client *client,
positioner->size.height = height;
}
-static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client,
+static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
int32_t height) {
struct wlr_xdg_positioner_v6 *positioner =
@@ -275,7 +296,7 @@ static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client,
positioner->anchor_rect.height = height;
}
-static void xdg_positioner_protocol_set_anchor(struct wl_client *client,
+static void xdg_positioner_handle_set_anchor(struct wl_client *client,
struct wl_resource *resource, uint32_t anchor) {
struct wlr_xdg_positioner_v6 *positioner =
xdg_positioner_from_resource(resource);
@@ -293,7 +314,7 @@ static void xdg_positioner_protocol_set_anchor(struct wl_client *client,
positioner->anchor = anchor;
}
-static void xdg_positioner_protocol_set_gravity(struct wl_client *client,
+static void xdg_positioner_handle_set_gravity(struct wl_client *client,
struct wl_resource *resource, uint32_t gravity) {
struct wlr_xdg_positioner_v6 *positioner =
xdg_positioner_from_resource(resource);
@@ -311,7 +332,7 @@ static void xdg_positioner_protocol_set_gravity(struct wl_client *client,
positioner->gravity = gravity;
}
-static void xdg_positioner_protocol_set_constraint_adjustment(
+static void xdg_positioner_handle_set_constraint_adjustment(
struct wl_client *client, struct wl_resource *resource,
uint32_t constraint_adjustment) {
struct wlr_xdg_positioner_v6 *positioner =
@@ -320,7 +341,7 @@ static void xdg_positioner_protocol_set_constraint_adjustment(
positioner->constraint_adjustment = constraint_adjustment;
}
-static void xdg_positioner_protocol_set_offset(struct wl_client *client,
+static void xdg_positioner_handle_set_offset(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y) {
struct wlr_xdg_positioner_v6 *positioner =
xdg_positioner_from_resource(resource);
@@ -331,17 +352,17 @@ static void xdg_positioner_protocol_set_offset(struct wl_client *client,
static const struct zxdg_positioner_v6_interface
zxdg_positioner_v6_implementation = {
- .destroy = resource_destroy,
- .set_size = xdg_positioner_protocol_set_size,
- .set_anchor_rect = xdg_positioner_protocol_set_anchor_rect,
- .set_anchor = xdg_positioner_protocol_set_anchor,
- .set_gravity = xdg_positioner_protocol_set_gravity,
+ .destroy = resource_handle_destroy,
+ .set_size = xdg_positioner_handle_set_size,
+ .set_anchor_rect = xdg_positioner_handle_set_anchor_rect,
+ .set_anchor = xdg_positioner_handle_set_anchor,
+ .set_gravity = xdg_positioner_handle_set_gravity,
.set_constraint_adjustment =
- xdg_positioner_protocol_set_constraint_adjustment,
- .set_offset = xdg_positioner_protocol_set_offset,
+ xdg_positioner_handle_set_constraint_adjustment,
+ .set_offset = xdg_positioner_handle_set_offset,
};
-static void xdg_shell_create_positioner(struct wl_client *wl_client,
+static void xdg_shell_handle_create_positioner(struct wl_client *wl_client,
struct wl_resource *resource, uint32_t id) {
struct wlr_xdg_positioner_v6 *positioner =
calloc(1, sizeof(struct wlr_xdg_positioner_v6));
@@ -430,7 +451,7 @@ static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_popup_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_popup_protocol_grab(struct wl_client *client,
+static void xdg_popup_handle_grab(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
struct wlr_xdg_surface_v6 *surface =
@@ -438,8 +459,8 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
struct wlr_seat_client *seat_client =
wlr_seat_client_from_resource(seat_resource);
- if (surface->popup_state->committed) {
- wl_resource_post_error(surface->popup_state->resource,
+ if (surface->popup->committed) {
+ wl_resource_post_error(surface->popup->resource,
ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
"xdg_popup is already mapped");
return;
@@ -451,10 +472,10 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(popup_grab);
bool parent_is_toplevel =
- surface->popup_state->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
+ surface->popup->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
if ((topmost == NULL && !parent_is_toplevel) ||
- (topmost != NULL && topmost != surface->popup_state->parent)) {
+ (topmost != NULL && topmost != surface->popup->parent)) {
wl_resource_post_error(surface->client->resource,
ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
"xdg_popup was not created on the topmost popup");
@@ -462,9 +483,9 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
}
popup_grab->client = surface->client->client;
- surface->popup_state->seat = seat_client->seat;
+ surface->popup->seat = seat_client->seat;
- wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link);
+ wl_list_insert(&popup_grab->popups, &surface->popup->grab_link);
wlr_seat_pointer_start_grab(seat_client->seat,
&popup_grab->pointer_grab);
@@ -472,16 +493,36 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
&popup_grab->keyboard_grab);
}
+static void xdg_popup_handle_destroy(struct wl_client *client,
+ struct wl_resource *resource) {
+ struct wlr_xdg_surface_v6 *surface =
+ xdg_surface_from_xdg_popup_resource(resource);
+ struct wlr_xdg_popup_grab_v6 *grab =
+ xdg_shell_popup_grab_from_seat(surface->client->shell,
+ surface->popup->seat);
+ struct wlr_xdg_surface_v6 *topmost =
+ xdg_popup_grab_get_topmost(grab);
+
+ if (topmost != surface) {
+ wl_resource_post_error(surface->client->resource,
+ ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
+ "xdg_popup was destroyed while it was not the topmost popup");
+ return;
+ }
+
+ wl_resource_destroy(resource);
+}
+
static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = {
- .destroy = resource_destroy,
- .grab = xdg_popup_protocol_grab,
+ .destroy = xdg_popup_handle_destroy,
+ .grab = xdg_popup_handle_grab,
};
static void xdg_popup_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_popup_resource(resource);
if (surface != NULL) {
- xdg_surface_destroy(surface);
+ xdg_surface_unmap(surface);
}
}
@@ -494,7 +535,7 @@ static struct wlr_xdg_surface_v6 *xdg_surface_from_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_surface_get_popup(struct wl_client *client,
+static void xdg_surface_handle_get_popup(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
struct wl_resource *parent_resource,
struct wl_resource *positioner_resource) {
@@ -517,33 +558,33 @@ static void xdg_surface_get_popup(struct wl_client *client,
return;
}
- surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6));
- if (!surface->popup_state) {
+ surface->popup = calloc(1, sizeof(struct wlr_xdg_popup_v6));
+ if (!surface->popup) {
wl_resource_post_no_memory(resource);
return;
}
- surface->popup_state->resource =
+ surface->popup->resource =
wl_resource_create(client, &zxdg_popup_v6_interface,
wl_resource_get_version(resource), id);
- if (surface->popup_state->resource == NULL) {
- free(surface->popup_state);
+ if (surface->popup->resource == NULL) {
+ free(surface->popup);
wl_resource_post_no_memory(resource);
return;
}
surface->role = WLR_XDG_SURFACE_V6_ROLE_POPUP;
- surface->popup_state->base = surface;
- surface->popup_state->parent = parent;
- surface->popup_state->geometry =
+ surface->popup->base = surface;
+ surface->popup->parent = parent;
+ surface->popup->geometry =
xdg_positioner_get_geometry(positioner, surface, parent);
- wl_list_insert(&parent->popups, &surface->popup_state->link);
+ wl_list_insert(&parent->popups, &surface->popup->link);
- wl_resource_set_implementation(surface->popup_state->resource,
+ wl_resource_set_implementation(surface->popup->resource,
&zxdg_popup_v6_implementation, surface,
xdg_popup_resource_destroy);
- wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state);
+ wlr_signal_emit_safe(&parent->events.new_popup, surface->popup);
}
@@ -556,7 +597,7 @@ static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_toplevel_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_toplevel_protocol_set_parent(struct wl_client *client,
+static void xdg_toplevel_handle_set_parent(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *parent_resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -566,10 +607,10 @@ static void xdg_toplevel_protocol_set_parent(struct wl_client *client,
parent = xdg_surface_from_xdg_toplevel_resource(parent_resource);
}
- surface->toplevel_state->parent = parent;
+ surface->toplevel->parent = parent;
}
-static void xdg_toplevel_protocol_set_title(struct wl_client *client,
+static void xdg_toplevel_handle_set_title(struct wl_client *client,
struct wl_resource *resource, const char *title) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -583,7 +624,7 @@ static void xdg_toplevel_protocol_set_title(struct wl_client *client,
surface->title = tmp;
}
-static void xdg_toplevel_protocol_set_app_id(struct wl_client *client,
+static void xdg_toplevel_handle_set_app_id(struct wl_client *client,
struct wl_resource *resource, const char *app_id) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -597,7 +638,7 @@ static void xdg_toplevel_protocol_set_app_id(struct wl_client *client,
surface->app_id = tmp;
}
-static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
+static void xdg_toplevel_handle_show_window_menu(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, int32_t x, int32_t y) {
struct wlr_xdg_surface_v6 *surface =
@@ -606,7 +647,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
wlr_seat_client_from_resource(seat_resource);
if (!surface->configured) {
- wl_resource_post_error(surface->toplevel_state->resource,
+ wl_resource_post_error(surface->toplevel->resource,
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
"surface has not been configured yet");
return;
@@ -628,7 +669,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event);
}
-static void xdg_toplevel_protocol_move(struct wl_client *client,
+static void xdg_toplevel_handle_move(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
struct wlr_xdg_surface_v6 *surface =
@@ -637,7 +678,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client,
wlr_seat_client_from_resource(seat_resource);
if (!surface->configured) {
- wl_resource_post_error(surface->toplevel_state->resource,
+ wl_resource_post_error(surface->toplevel->resource,
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
"surface has not been configured yet");
return;
@@ -657,7 +698,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_move, &event);
}
-static void xdg_toplevel_protocol_resize(struct wl_client *client,
+static void xdg_toplevel_handle_resize(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, uint32_t edges) {
struct wlr_xdg_surface_v6 *surface =
@@ -666,7 +707,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client,
wlr_seat_client_from_resource(seat_resource);
if (!surface->configured) {
- wl_resource_post_error(surface->toplevel_state->resource,
+ wl_resource_post_error(surface->toplevel->resource,
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
"surface has not been configured yet");
return;
@@ -687,39 +728,39 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_resize, &event);
}
-static void xdg_toplevel_protocol_set_max_size(struct wl_client *client,
+static void xdg_toplevel_handle_set_max_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.max_width = width;
- surface->toplevel_state->next.max_height = height;
+ surface->toplevel->next.max_width = width;
+ surface->toplevel->next.max_height = height;
}
-static void xdg_toplevel_protocol_set_min_size(struct wl_client *client,
+static void xdg_toplevel_handle_set_min_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.min_width = width;
- surface->toplevel_state->next.min_height = height;
+ surface->toplevel->next.min_width = width;
+ surface->toplevel->next.min_height = height;
}
-static void xdg_toplevel_protocol_set_maximized(struct wl_client *client,
+static void xdg_toplevel_handle_set_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.maximized = true;
+ surface->toplevel->next.maximized = true;
wlr_signal_emit_safe(&surface->events.request_maximize, surface);
}
-static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client,
+static void xdg_toplevel_handle_unset_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.maximized = false;
+ surface->toplevel->next.maximized = false;
wlr_signal_emit_safe(&surface->events.request_maximize, surface);
}
-static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
+static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
@@ -729,7 +770,7 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
output = wlr_output_from_resource(output_resource);
}
- surface->toplevel_state->next.fullscreen = true;
+ surface->toplevel->next.fullscreen = true;
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
.surface = surface,
@@ -740,12 +781,12 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_fullscreen, &event);
}
-static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
+static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
- surface->toplevel_state->next.fullscreen = false;
+ surface->toplevel->next.fullscreen = false;
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
.surface = surface,
@@ -756,29 +797,29 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.request_fullscreen, &event);
}
-static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,
+static void xdg_toplevel_handle_set_minimized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_signal_emit_safe(&surface->events.request_minimize, surface);
}
-static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation =
-{
- .destroy = resource_destroy,
- .set_parent = xdg_toplevel_protocol_set_parent,
- .set_title = xdg_toplevel_protocol_set_title,
- .set_app_id = xdg_toplevel_protocol_set_app_id,
- .show_window_menu = xdg_toplevel_protocol_show_window_menu,
- .move = xdg_toplevel_protocol_move,
- .resize = xdg_toplevel_protocol_resize,
- .set_max_size = xdg_toplevel_protocol_set_max_size,
- .set_min_size = xdg_toplevel_protocol_set_min_size,
- .set_maximized = xdg_toplevel_protocol_set_maximized,
- .unset_maximized = xdg_toplevel_protocol_unset_maximized,
- .set_fullscreen = xdg_toplevel_protocol_set_fullscreen,
- .unset_fullscreen = xdg_toplevel_protocol_unset_fullscreen,
- .set_minimized = xdg_toplevel_protocol_set_minimized
+static const struct zxdg_toplevel_v6_interface
+ zxdg_toplevel_v6_implementation = {
+ .destroy = resource_handle_destroy,
+ .set_parent = xdg_toplevel_handle_set_parent,
+ .set_title = xdg_toplevel_handle_set_title,
+ .set_app_id = xdg_toplevel_handle_set_app_id,
+ .show_window_menu = xdg_toplevel_handle_show_window_menu,
+ .move = xdg_toplevel_handle_move,
+ .resize = xdg_toplevel_handle_resize,
+ .set_max_size = xdg_toplevel_handle_set_max_size,
+ .set_min_size = xdg_toplevel_handle_set_min_size,
+ .set_maximized = xdg_toplevel_handle_set_maximized,
+ .unset_maximized = xdg_toplevel_handle_unset_maximized,
+ .set_fullscreen = xdg_toplevel_handle_set_fullscreen,
+ .unset_fullscreen = xdg_toplevel_handle_unset_fullscreen,
+ .set_minimized = xdg_toplevel_handle_set_minimized,
};
static void xdg_surface_resource_destroy(struct wl_resource *resource) {
@@ -792,11 +833,11 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
if (surface != NULL) {
- xdg_surface_destroy(surface);
+ xdg_surface_unmap(surface);
}
}
-static void xdg_surface_get_toplevel(struct wl_client *client,
+static void xdg_surface_handle_get_toplevel(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
@@ -805,24 +846,24 @@ static void xdg_surface_get_toplevel(struct wl_client *client,
return;
}
- surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6));
- if (surface->toplevel_state == NULL) {
+ surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel_v6));
+ if (surface->toplevel == NULL) {
wl_resource_post_no_memory(resource);
return;
}
surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
- surface->toplevel_state->base = surface;
+ surface->toplevel->base = surface;
struct wl_resource *toplevel_resource = wl_resource_create(client,
&zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id);
if (toplevel_resource == NULL) {
- free(surface->toplevel_state);
+ free(surface->toplevel);
wl_resource_post_no_memory(resource);
return;
}
- surface->toplevel_state->resource = toplevel_resource;
+ surface->toplevel->resource = toplevel_resource;
wl_resource_set_implementation(toplevel_resource,
&zxdg_toplevel_v6_implementation, surface,
@@ -833,12 +874,19 @@ static void wlr_xdg_toplevel_v6_ack_configure(
struct wlr_xdg_surface_v6 *surface,
struct wlr_xdg_surface_v6_configure *configure) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- surface->toplevel_state->next = configure->state;
- surface->toplevel_state->pending.width = 0;
- surface->toplevel_state->pending.height = 0;
+ assert(configure->toplevel_state != NULL);
+
+ surface->toplevel->current.maximized =
+ configure->toplevel_state->maximized;
+ surface->toplevel->current.fullscreen =
+ configure->toplevel_state->fullscreen;
+ surface->toplevel->current.resizing =
+ configure->toplevel_state->resizing;
+ surface->toplevel->current.activated =
+ configure->toplevel_state->activated;
}
-static void xdg_surface_ack_configure(struct wl_client *client,
+static void xdg_surface_handle_ack_configure(struct wl_client *client,
struct wl_resource *resource, uint32_t serial) {
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
@@ -853,10 +901,8 @@ static void xdg_surface_ack_configure(struct wl_client *client,
struct wlr_xdg_surface_v6_configure *configure, *tmp;
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
if (configure->serial < serial) {
- wl_list_remove(&configure->link);
- free(configure);
+ xdg_surface_configure_destroy(configure);
} else if (configure->serial == serial) {
- wl_list_remove(&configure->link);
found = true;
break;
} else {
@@ -884,10 +930,10 @@ static void xdg_surface_ack_configure(struct wl_client *client,
surface->configured = true;
surface->configure_serial = serial;
- free(configure);
+ xdg_surface_configure_destroy(configure);
}
-static void xdg_surface_set_window_geometry(struct wl_client *client,
+static void xdg_surface_handle_set_window_geometry(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
int32_t height) {
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
@@ -900,19 +946,31 @@ static void xdg_surface_set_window_geometry(struct wl_client *client,
}
surface->has_next_geometry = true;
- surface->next_geometry->height = height;
- surface->next_geometry->width = width;
- surface->next_geometry->x = x;
- surface->next_geometry->y = y;
+ surface->next_geometry.height = height;
+ surface->next_geometry.width = width;
+ surface->next_geometry.x = x;
+ surface->next_geometry.y = y;
+}
+
+static void xdg_surface_handle_destroy(struct wl_client *client,
+ struct wl_resource *resource) {
+ struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
+
+ if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) {
+ wlr_log(L_ERROR, "Tried to destroy an xdg_surface before its role "
+ "object");
+ return;
+ }
+ wl_resource_destroy(resource);
}
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = {
- .destroy = resource_destroy,
- .get_toplevel = xdg_surface_get_toplevel,
- .get_popup = xdg_surface_get_popup,
- .ack_configure = xdg_surface_ack_configure,
- .set_window_geometry = xdg_surface_set_window_geometry,
+ .destroy = xdg_surface_handle_destroy,
+ .get_toplevel = xdg_surface_handle_get_toplevel,
+ .get_popup = xdg_surface_handle_get_popup,
+ .ack_configure = xdg_surface_handle_ack_configure,
+ .set_window_geometry = xdg_surface_handle_set_window_geometry,
};
static bool wlr_xdg_surface_v6_toplevel_state_compare(
@@ -935,9 +993,9 @@ static bool wlr_xdg_surface_v6_toplevel_state_compare(
} else {
struct wlr_xdg_surface_v6_configure *configure =
wl_container_of(state->base->configure_list.prev, configure, link);
- configured.state = configure->state;
- configured.width = configure->state.width;
- configured.height = configure->state.height;
+ configured.state = *configure->toplevel_state;
+ configured.width = configure->toplevel_state->width;
+ configured.height = configure->toplevel_state->height;
}
if (state->pending.activated != configured.state.activated) {
@@ -969,13 +1027,19 @@ static void wlr_xdg_toplevel_v6_send_configure(
struct wlr_xdg_surface_v6 *surface,
struct wlr_xdg_surface_v6_configure *configure) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- uint32_t *s;
- struct wl_array states;
- configure->state = surface->toplevel_state->pending;
+ configure->toplevel_state = malloc(sizeof(*configure->toplevel_state));
+ if (configure->toplevel_state == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ wl_resource_post_no_memory(surface->toplevel->resource);
+ return;
+ }
+ *configure->toplevel_state = surface->toplevel->pending;
+ uint32_t *s;
+ struct wl_array states;
wl_array_init(&states);
- if (surface->toplevel_state->pending.maximized) {
+ if (surface->toplevel->pending.maximized) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel");
@@ -983,7 +1047,7 @@ static void wlr_xdg_toplevel_v6_send_configure(
}
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
}
- if (surface->toplevel_state->pending.fullscreen) {
+ if (surface->toplevel->pending.fullscreen) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel");
@@ -991,7 +1055,7 @@ static void wlr_xdg_toplevel_v6_send_configure(
}
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
}
- if (surface->toplevel_state->pending.resizing) {
+ if (surface->toplevel->pending.resizing) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel");
@@ -999,7 +1063,7 @@ static void wlr_xdg_toplevel_v6_send_configure(
}
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
}
- if (surface->toplevel_state->pending.activated) {
+ if (surface->toplevel->pending.activated) {
s = wl_array_add(&states, sizeof(uint32_t));
if (!s) {
wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel");
@@ -1008,15 +1072,9 @@ static void wlr_xdg_toplevel_v6_send_configure(
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
}
- uint32_t width = surface->toplevel_state->pending.width;
- uint32_t height = surface->toplevel_state->pending.height;
-
- if (width == 0 || height == 0) {
- width = surface->geometry->width;
- height = surface->geometry->height;
- }
-
- zxdg_toplevel_v6_send_configure(surface->toplevel_state->resource, width,
+ uint32_t width = surface->toplevel->pending.width;
+ uint32_t height = surface->toplevel->pending.height;
+ zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width,
height, &states);
wl_array_release(&states);
@@ -1024,7 +1082,7 @@ static void wlr_xdg_toplevel_v6_send_configure(
error_out:
wl_array_release(&states);
- wl_resource_post_no_memory(surface->toplevel_state->resource);
+ wl_resource_post_no_memory(surface->toplevel->resource);
}
static void wlr_xdg_surface_send_configure(void *user_data) {
@@ -1050,11 +1108,11 @@ static void wlr_xdg_surface_send_configure(void *user_data) {
wlr_xdg_toplevel_v6_send_configure(surface, configure);
break;
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
- zxdg_popup_v6_send_configure(surface->popup_state->resource,
- surface->popup_state->geometry.x,
- surface->popup_state->geometry.y,
- surface->popup_state->geometry.width,
- surface->popup_state->geometry.height);
+ zxdg_popup_v6_send_configure(surface->popup->resource,
+ surface->popup->geometry.x,
+ surface->popup->geometry.y,
+ surface->popup->geometry.width,
+ surface->popup->geometry.height);
break;
}
@@ -1073,7 +1131,7 @@ static uint32_t wlr_xdg_surface_v6_schedule_configure(
break;
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
pending_same =
- wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel_state);
+ wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel);
break;
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
break;
@@ -1113,29 +1171,32 @@ static void wlr_xdg_surface_v6_toplevel_committed(
struct wlr_xdg_surface_v6 *surface) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- if (!wlr_surface_has_buffer(surface->surface)
- && !surface->toplevel_state->added) {
+ if (!surface->toplevel->added) {
// on the first commit, send a configure request to tell the client it
// is added
wlr_xdg_surface_v6_schedule_configure(surface);
- surface->toplevel_state->added = true;
+ surface->toplevel->added = true;
return;
}
- if (!wlr_surface_has_buffer(surface->surface)) {
- return;
- }
-
- surface->toplevel_state->current = surface->toplevel_state->next;
+ // update state that doesn't need compositor approval
+ surface->toplevel->current.max_width =
+ surface->toplevel->next.max_width;
+ surface->toplevel->current.min_width =
+ surface->toplevel->next.min_width;
+ surface->toplevel->current.max_height =
+ surface->toplevel->next.max_height;
+ surface->toplevel->current.min_height =
+ surface->toplevel->next.min_height;
}
static void wlr_xdg_surface_v6_popup_committed(
struct wlr_xdg_surface_v6 *surface) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP);
- if (!surface->popup_state->committed) {
+ if (!surface->popup->committed) {
wlr_xdg_surface_v6_schedule_configure(surface);
- surface->popup_state->committed = true;
+ surface->popup->committed = true;
}
}
@@ -1152,10 +1213,10 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
if (surface->has_next_geometry) {
surface->has_next_geometry = false;
- surface->geometry->x = surface->next_geometry->x;
- surface->geometry->y = surface->next_geometry->y;
- surface->geometry->width = surface->next_geometry->width;
- surface->geometry->height = surface->next_geometry->height;
+ surface->geometry.x = surface->next_geometry.x;
+ surface->geometry.y = surface->next_geometry.y;
+ surface->geometry.width = surface->next_geometry.width;
+ surface->geometry.height = surface->next_geometry.height;
}
switch (surface->role) {
@@ -1172,9 +1233,19 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
break;
}
- if (surface->configured && !surface->added) {
+ if (!surface->added) {
surface->added = true;
- wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface);
+ wlr_signal_emit_safe(&surface->client->shell->events.new_surface,
+ surface);
+ }
+ if (surface->configured && wlr_surface_has_buffer(surface->surface) &&
+ !surface->mapped) {
+ surface->mapped = true;
+ wlr_signal_emit_safe(&surface->events.map, surface);
+ }
+ if (surface->configured && !wlr_surface_has_buffer(surface->surface) &&
+ surface->mapped) {
+ xdg_surface_unmap(surface);
}
}
@@ -1187,27 +1258,15 @@ static struct wlr_xdg_client_v6 *xdg_client_from_resource(
return wl_resource_get_user_data(resource);
}
-static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
+static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client,
struct wl_resource *client_resource, uint32_t id,
struct wl_resource *surface_resource) {
struct wlr_xdg_client_v6 *client =
xdg_client_from_resource(client_resource);
- struct wlr_xdg_surface_v6 *surface;
- if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface_v6)))) {
- wl_client_post_no_memory(wl_client);
- return;
- }
-
- if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) {
- free(surface);
- wl_client_post_no_memory(wl_client);
- return;
- }
-
- if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) {
- free(surface->geometry);
- free(surface);
+ struct wlr_xdg_surface_v6 *surface =
+ calloc(1, sizeof(struct wlr_xdg_surface_v6));
+ if (surface == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
@@ -1219,8 +1278,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
&zxdg_surface_v6_interface, wl_resource_get_version(client_resource),
id);
if (surface->resource == NULL) {
- free(surface->next_geometry);
- free(surface->geometry);
free(surface);
wl_client_post_no_memory(wl_client);
return;
@@ -1228,8 +1285,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
if (wlr_surface_has_buffer(surface->surface)) {
wl_resource_destroy(surface->resource);
- free(surface->next_geometry);
- free(surface->geometry);
free(surface);
wl_resource_post_error(surface_resource,
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
@@ -1249,6 +1304,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.ping_timeout);
wl_signal_init(&surface->events.new_popup);
+ wl_signal_init(&surface->events.map);
+ wl_signal_init(&surface->events.unmap);
wl_signal_add(&surface->surface->events.destroy,
&surface->surface_destroy_listener);
@@ -1263,7 +1320,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_list_insert(&client->surfaces, &surface->link);
}
-static void xdg_shell_pong(struct wl_client *wl_client,
+static void xdg_shell_handle_pong(struct wl_client *wl_client,
struct wl_resource *resource, uint32_t serial) {
struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
@@ -1275,11 +1332,25 @@ static void xdg_shell_pong(struct wl_client *wl_client,
client->ping_serial = 0;
}
+static void xdg_shell_handle_destroy(struct wl_client *wl_client,
+ struct wl_resource *resource) {
+ struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
+
+ if (!wl_list_empty(&client->surfaces)) {
+ wl_resource_post_error(client->resource,
+ ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES,
+ "xdg_wm_base was destroyed before children");
+ return;
+ }
+
+ wl_resource_destroy(resource);
+}
+
static const struct zxdg_shell_v6_interface xdg_shell_impl = {
- .destroy = resource_destroy,
- .create_positioner = xdg_shell_create_positioner,
- .get_xdg_surface = xdg_shell_get_xdg_surface,
- .pong = xdg_shell_pong,
+ .destroy = xdg_shell_handle_destroy,
+ .create_positioner = xdg_shell_handle_create_positioner,
+ .get_xdg_surface = xdg_shell_handle_get_xdg_surface,
+ .pong = xdg_shell_handle_pong,
};
static void wlr_xdg_client_v6_destroy(struct wl_resource *resource) {
@@ -1407,8 +1478,8 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) {
uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface,
uint32_t width, uint32_t height) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.width = width;
- surface->toplevel_state->pending.height = height;
+ surface->toplevel->pending.width = width;
+ surface->toplevel->pending.height = height;
return wlr_xdg_surface_v6_schedule_configure(surface);
}
@@ -1416,7 +1487,7 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface,
uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface,
bool activated) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.activated = activated;
+ surface->toplevel->pending.activated = activated;
return wlr_xdg_surface_v6_schedule_configure(surface);
}
@@ -1424,7 +1495,7 @@ uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface,
uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface,
bool maximized) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.maximized = maximized;
+ surface->toplevel->pending.maximized = maximized;
return wlr_xdg_surface_v6_schedule_configure(surface);
}
@@ -1432,7 +1503,7 @@ uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface,
uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
bool fullscreen) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.fullscreen = fullscreen;
+ surface->toplevel->pending.fullscreen = fullscreen;
return wlr_xdg_surface_v6_schedule_configure(surface);
}
@@ -1440,24 +1511,24 @@ uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
bool resizing) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- surface->toplevel_state->pending.resizing = resizing;
+ surface->toplevel->pending.resizing = resizing;
return wlr_xdg_surface_v6_schedule_configure(surface);
}
void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
- zxdg_toplevel_v6_send_close(surface->toplevel_state->resource);
+ zxdg_toplevel_v6_send_close(surface->toplevel->resource);
}
void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface,
double *popup_sx, double *popup_sy) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP);
- struct wlr_xdg_surface_v6 *parent = surface->popup_state->parent;
- *popup_sx = parent->geometry->x + surface->popup_state->geometry.x -
- surface->geometry->x;
- *popup_sy = parent->geometry->y + surface->popup_state->geometry.y -
- surface->geometry->y;
+ struct wlr_xdg_surface_v6 *parent = surface->popup->parent;
+ *popup_sx = parent->geometry.x + surface->popup->geometry.x -
+ surface->geometry.x;
+ *popup_sy = parent->geometry.y + surface->popup->geometry.y -
+ surface->geometry.y;
}
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
@@ -1471,30 +1542,30 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
struct wlr_xdg_surface_v6 *popup = popup_state->base;
double _popup_sx =
- surface->geometry->x + popup_state->geometry.x;
+ surface->geometry.x + popup_state->geometry.x;
double _popup_sy =
- surface->geometry->y + popup_state->geometry.y;
+ surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
struct wlr_xdg_surface_v6 *_popup =
wlr_xdg_surface_v6_popup_at(popup,
- sx - _popup_sx + popup->geometry->x,
- sy - _popup_sy + popup->geometry->y,
+ sx - _popup_sx + popup->geometry.x,
+ sy - _popup_sy + popup->geometry.y,
popup_sx, popup_sy);
if (_popup) {
- *popup_sx = *popup_sx + _popup_sx - popup->geometry->x;
- *popup_sy = *popup_sy + _popup_sy - popup->geometry->y;
+ *popup_sx = *popup_sx + _popup_sx - popup->geometry.x;
+ *popup_sy = *popup_sy + _popup_sy - popup->geometry.y;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
if (pixman_region32_contains_point(&popup->surface->current->input,
- sx - _popup_sx + popup->geometry->x,
- sy - _popup_sy + popup->geometry->y, NULL)) {
- *popup_sx = _popup_sx - popup->geometry->x;
- *popup_sy = _popup_sy - popup->geometry->y;
+ sx - _popup_sx + popup->geometry.x,
+ sy - _popup_sy + popup->geometry.y, NULL)) {
+ *popup_sx = _popup_sx - popup->geometry.x;
+ *popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
}