2018-05-13 17:38:56 +02:00
|
|
|
#define _POSIX_C_SOURCE 199309L
|
2018-07-21 04:13:00 +02:00
|
|
|
#include <float.h>
|
2018-05-13 17:38:56 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
2018-05-27 14:28:37 +02:00
|
|
|
#include <wlr/util/edges.h>
|
|
|
|
#include "log.h"
|
2018-07-29 19:31:10 +02:00
|
|
|
#include "sway/decoration.h"
|
2018-08-18 07:10:06 +02:00
|
|
|
#include "sway/desktop.h"
|
Prepare arrange code for type safe arguments
This commit changes the arrange code in a way that will support type
safe arguments.
The arrange_output et al functions are now public, however I opted not
to use them directly yet. I've kept the generic arrange_windows there
for convenience until type safety is fully implemented. This means this
patch has much less risk of breaking things as it would otherwise.
To be type safe, arrange_children_of cannot exist in its previous form
because the thing passed to it could be either a workspace or a
container. So it's now renamed to arrange_children and accepts a list_t,
as well as the parent layout and parent's box.
There was some code which checked the grandparent's layout to see if it
was tabbed or stacked and adjusted the Y offset of the grandchild
accordingly. Accessing the grandparent layout isn't easy when using type
safe arguments, and it seemed odd to even need to do this. I determined
that this was needed because a child of a tabbed container would have a
swayc Y matching the top of the tab bar. I've changed this so a child of
a tabbed container will have a swayc Y matching the bottom of the tab
bar, which means we don't need to access the grandparent layout. Some
tweaks to the rendering and autoconfigure code have been made to
implement this, and the container_at code appears to work without
needing any changes.
arrange_children_of (now arrange_children) would check if the parent had
gaps and would copy them to the child, effectively making the
workspace's gaps recurse into all children. We can't do this any more
without passing has_gaps, gaps_inner and gaps_outer as arguments to
arrange_children, so I've changed the add_gaps function to retrieve it
from the workspace directly.
apply_tabbed_or_stacked_layout has been split into two functions, as it
had different logic depending on the layout.
Lastly, arrange.h had an unnecessary include of transaction.h. I've
removed it, which means I've had to add it to several other files.
2018-08-26 02:16:49 +02:00
|
|
|
#include "sway/desktop/transaction.h"
|
2018-05-27 14:28:37 +02:00
|
|
|
#include "sway/input/input-manager.h"
|
|
|
|
#include "sway/input/seat.h"
|
|
|
|
#include "sway/server.h"
|
2018-06-06 14:57:34 +02:00
|
|
|
#include "sway/tree/arrange.h"
|
2018-05-13 17:38:56 +02:00
|
|
|
#include "sway/tree/container.h"
|
|
|
|
#include "sway/tree/view.h"
|
|
|
|
|
|
|
|
static const struct sway_view_child_impl popup_impl;
|
|
|
|
|
|
|
|
static void popup_destroy(struct sway_view_child *child) {
|
|
|
|
if (!sway_assert(child->impl == &popup_impl,
|
|
|
|
"Expected an xdg_shell popup")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child;
|
|
|
|
wl_list_remove(&popup->new_popup.link);
|
|
|
|
wl_list_remove(&popup->destroy.link);
|
|
|
|
free(popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sway_view_child_impl popup_impl = {
|
|
|
|
.destroy = popup_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sway_xdg_popup *popup_create(
|
|
|
|
struct wlr_xdg_popup *wlr_popup, struct sway_view *view);
|
|
|
|
|
|
|
|
static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_popup *popup =
|
|
|
|
wl_container_of(listener, popup, new_popup);
|
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
|
|
|
popup_create(wlr_popup, popup->child.view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_handle_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_popup *popup = wl_container_of(listener, popup, destroy);
|
|
|
|
view_child_destroy(&popup->child);
|
|
|
|
}
|
|
|
|
|
2018-07-12 21:30:10 +02:00
|
|
|
static void popup_unconstrain(struct sway_xdg_popup *popup) {
|
|
|
|
struct sway_view *view = popup->child.view;
|
|
|
|
struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_surface->popup;
|
|
|
|
|
2018-07-13 22:17:31 +02:00
|
|
|
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
|
2018-07-12 21:30:10 +02:00
|
|
|
|
|
|
|
// the output box expressed in the coordinate system of the toplevel parent
|
|
|
|
// of the popup
|
|
|
|
struct wlr_box output_toplevel_sx_box = {
|
2018-07-13 22:17:31 +02:00
|
|
|
.x = output->x - view->x,
|
|
|
|
.y = output->y - view->y,
|
|
|
|
.width = output->width,
|
|
|
|
.height = output->height,
|
2018-07-12 21:30:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
static struct sway_xdg_popup *popup_create(
|
|
|
|
struct wlr_xdg_popup *wlr_popup, struct sway_view *view) {
|
|
|
|
struct wlr_xdg_surface *xdg_surface = wlr_popup->base;
|
|
|
|
|
|
|
|
struct sway_xdg_popup *popup =
|
|
|
|
calloc(1, sizeof(struct sway_xdg_popup));
|
|
|
|
if (popup == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface);
|
2018-07-12 21:30:10 +02:00
|
|
|
popup->wlr_xdg_surface = xdg_surface;
|
2018-05-13 17:38:56 +02:00
|
|
|
|
|
|
|
wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup);
|
|
|
|
popup->new_popup.notify = popup_handle_new_popup;
|
|
|
|
wl_signal_add(&xdg_surface->events.destroy, &popup->destroy);
|
|
|
|
popup->destroy.notify = popup_handle_destroy;
|
|
|
|
|
2018-07-12 21:30:10 +02:00
|
|
|
popup_unconstrain(popup);
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct sway_xdg_shell_view *xdg_shell_view_from_view(
|
|
|
|
struct sway_view *view) {
|
|
|
|
if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL,
|
|
|
|
"Expected xdg_shell view")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (struct sway_xdg_shell_view *)view;
|
|
|
|
}
|
|
|
|
|
2018-07-21 04:13:00 +02:00
|
|
|
static void get_constraints(struct sway_view *view, double *min_width,
|
|
|
|
double *max_width, double *min_height, double *max_height) {
|
|
|
|
struct wlr_xdg_toplevel_state *state =
|
|
|
|
&view->wlr_xdg_surface->toplevel->current;
|
|
|
|
*min_width = state->min_width > 0 ? state->min_width : DBL_MIN;
|
|
|
|
*max_width = state->max_width > 0 ? state->max_width : DBL_MAX;
|
|
|
|
*min_height = state->min_height > 0 ? state->min_height : DBL_MIN;
|
|
|
|
*max_height = state->max_height > 0 ? state->max_height : DBL_MAX;
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:06:44 +02:00
|
|
|
static const char *get_string_prop(struct sway_view *view,
|
|
|
|
enum sway_view_prop prop) {
|
2018-05-13 17:38:56 +02:00
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
switch (prop) {
|
|
|
|
case VIEW_PROP_TITLE:
|
|
|
|
return view->wlr_xdg_surface->toplevel->title;
|
|
|
|
case VIEW_PROP_APP_ID:
|
|
|
|
return view->wlr_xdg_surface->toplevel->app_id;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 08:35:06 +02:00
|
|
|
static uint32_t configure(struct sway_view *view, double lx, double ly,
|
|
|
|
int width, int height) {
|
2018-05-13 17:38:56 +02:00
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
xdg_shell_view_from_view(view);
|
|
|
|
if (xdg_shell_view == NULL) {
|
2018-06-03 08:35:06 +02:00
|
|
|
return 0;
|
2018-05-13 17:38:56 +02:00
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
return wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
|
2018-05-13 17:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_activated(struct sway_view *view, bool activated) {
|
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
|
|
|
|
if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
|
|
|
wlr_xdg_toplevel_set_activated(surface, activated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 18:53:13 +02:00
|
|
|
static void set_tiled(struct sway_view *view, bool tiled) {
|
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
|
|
|
|
enum wlr_edges edges = WLR_EDGE_NONE;
|
|
|
|
if (tiled) {
|
|
|
|
edges = WLR_EDGE_LEFT | WLR_EDGE_RIGHT | WLR_EDGE_TOP |
|
|
|
|
WLR_EDGE_BOTTOM;
|
|
|
|
}
|
|
|
|
wlr_xdg_toplevel_set_tiled(surface, edges);
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
static void set_fullscreen(struct sway_view *view, bool fullscreen) {
|
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
|
|
|
|
wlr_xdg_toplevel_set_fullscreen(surface, fullscreen);
|
|
|
|
}
|
|
|
|
|
2018-05-24 14:30:44 +02:00
|
|
|
static bool wants_floating(struct sway_view *view) {
|
2018-06-26 04:59:06 +02:00
|
|
|
struct wlr_xdg_toplevel *toplevel = view->wlr_xdg_surface->toplevel;
|
|
|
|
struct wlr_xdg_toplevel_state *state = &toplevel->current;
|
|
|
|
return (state->min_width != 0 && state->min_height != 0
|
2018-05-31 13:58:28 +02:00
|
|
|
&& state->min_width == state->max_width
|
2018-06-26 04:59:06 +02:00
|
|
|
&& state->min_height == state->max_height)
|
|
|
|
|| toplevel->parent;
|
2018-05-24 14:30:44 +02:00
|
|
|
}
|
|
|
|
|
2018-07-29 19:31:10 +02:00
|
|
|
static bool has_client_side_decorations(struct sway_view *view) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
xdg_shell_view_from_view(view);
|
|
|
|
if (xdg_shell_view == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return xdg_shell_view->deco_mode != WLR_SERVER_DECORATION_MANAGER_MODE_SERVER;
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
static void for_each_surface(struct sway_view *view,
|
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data) {
|
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wlr_xdg_surface_for_each_surface(view->wlr_xdg_surface, iterator,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:30:26 +02:00
|
|
|
static void for_each_popup(struct sway_view *view,
|
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data) {
|
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wlr_xdg_surface_for_each_popup(view->wlr_xdg_surface, iterator, user_data);
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
static void _close(struct sway_view *view) {
|
|
|
|
if (xdg_shell_view_from_view(view) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
|
|
|
|
if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
|
|
|
wlr_xdg_surface_send_close(surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 11:58:34 +02:00
|
|
|
static void close_popups_iterator(struct wlr_surface *surface,
|
|
|
|
int sx, int sy, void *data) {
|
|
|
|
struct wlr_xdg_surface *xdg_surface =
|
|
|
|
wlr_xdg_surface_from_wlr_surface(surface);
|
|
|
|
wlr_xdg_surface_send_close(xdg_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void close_popups(struct sway_view *view) {
|
|
|
|
wlr_xdg_surface_for_each_popup(view->wlr_xdg_surface,
|
|
|
|
close_popups_iterator, NULL);
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:18:33 +02:00
|
|
|
static void destroy(struct sway_view *view) {
|
2018-05-13 17:38:56 +02:00
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
xdg_shell_view_from_view(view);
|
|
|
|
if (xdg_shell_view == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(xdg_shell_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sway_view_impl view_impl = {
|
2018-07-21 04:13:00 +02:00
|
|
|
.get_constraints = get_constraints,
|
2018-05-14 03:47:39 +02:00
|
|
|
.get_string_prop = get_string_prop,
|
2018-05-13 17:38:56 +02:00
|
|
|
.configure = configure,
|
|
|
|
.set_activated = set_activated,
|
2018-06-27 18:53:13 +02:00
|
|
|
.set_tiled = set_tiled,
|
2018-05-13 17:38:56 +02:00
|
|
|
.set_fullscreen = set_fullscreen,
|
2018-05-24 14:30:44 +02:00
|
|
|
.wants_floating = wants_floating,
|
2018-07-29 19:31:10 +02:00
|
|
|
.has_client_side_decorations = has_client_side_decorations,
|
2018-05-13 17:38:56 +02:00
|
|
|
.for_each_surface = for_each_surface,
|
2018-08-02 15:30:26 +02:00
|
|
|
.for_each_popup = for_each_popup,
|
2018-05-13 17:38:56 +02:00
|
|
|
.close = _close,
|
2018-07-31 11:58:34 +02:00
|
|
|
.close_popups = close_popups,
|
2018-06-26 05:18:33 +02:00
|
|
|
.destroy = destroy,
|
2018-05-13 17:38:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void handle_commit(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, commit);
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
2018-06-03 08:35:06 +02:00
|
|
|
struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
|
|
|
|
|
2018-06-23 08:24:11 +02:00
|
|
|
if (!view->swayc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-15 02:03:55 +02:00
|
|
|
if (view->swayc->instruction) {
|
2018-08-18 07:10:06 +02:00
|
|
|
wlr_xdg_surface_get_geometry(xdg_surface, &view->geometry);
|
2018-08-15 02:03:55 +02:00
|
|
|
transaction_notify_view_ready_by_serial(view,
|
|
|
|
xdg_surface->configure_serial);
|
2018-08-18 07:10:06 +02:00
|
|
|
} else {
|
|
|
|
struct wlr_box new_geo;
|
|
|
|
wlr_xdg_surface_get_geometry(xdg_surface, &new_geo);
|
|
|
|
|
|
|
|
if ((new_geo.width != view->width || new_geo.height != view->height) &&
|
|
|
|
container_is_floating(view->swayc)) {
|
|
|
|
// A floating view has unexpectedly sent a new size
|
|
|
|
desktop_damage_view(view);
|
|
|
|
view_update_size(view, new_geo.width, new_geo.height);
|
|
|
|
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
|
|
|
|
desktop_damage_view(view);
|
|
|
|
transaction_commit_dirty();
|
|
|
|
} else {
|
|
|
|
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
|
|
|
|
}
|
2018-05-24 14:30:44 +02:00
|
|
|
}
|
2018-06-03 08:35:06 +02:00
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
view_damage_from(view);
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:20:07 +02:00
|
|
|
static void handle_set_title(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, set_title);
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
|
|
|
view_update_title(view, false);
|
|
|
|
view_execute_criteria(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_app_id(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, set_app_id);
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
|
|
|
view_execute_criteria(view);
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
static void handle_new_popup(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, new_popup);
|
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
|
|
|
popup_create(wlr_popup, &xdg_shell_view->view);
|
|
|
|
}
|
|
|
|
|
2018-06-25 00:17:01 +02:00
|
|
|
static void handle_request_fullscreen(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, request_fullscreen);
|
|
|
|
struct wlr_xdg_toplevel_set_fullscreen_event *e = data;
|
|
|
|
struct wlr_xdg_surface *xdg_surface =
|
|
|
|
xdg_shell_view->view.wlr_xdg_surface;
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
|
|
|
|
|
|
|
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL,
|
|
|
|
"xdg_shell requested fullscreen of surface with role %i",
|
|
|
|
xdg_surface->role)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!xdg_surface->mapped) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-25 12:56:23 +02:00
|
|
|
container_set_fullscreen(view->swayc, e->fullscreen);
|
2018-06-25 00:17:01 +02:00
|
|
|
|
2018-07-02 13:58:21 +02:00
|
|
|
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
|
2018-07-14 15:14:55 +02:00
|
|
|
arrange_windows(output);
|
|
|
|
transaction_commit_dirty();
|
2018-06-25 00:17:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-20 01:28:22 +02:00
|
|
|
static void handle_request_move(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, request_move);
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
2018-07-22 13:45:01 +02:00
|
|
|
if (!container_is_floating(view->swayc)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
struct wlr_xdg_toplevel_move_event *e = data;
|
|
|
|
struct sway_seat *seat = e->seat->seat->data;
|
2018-07-21 03:23:48 +02:00
|
|
|
if (e->serial == seat->last_button_serial) {
|
|
|
|
seat_begin_move(seat, view->swayc, seat->last_button);
|
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, request_resize);
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
2018-07-22 13:45:01 +02:00
|
|
|
if (!container_is_floating(view->swayc)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-20 01:28:22 +02:00
|
|
|
struct wlr_xdg_toplevel_resize_event *e = data;
|
|
|
|
struct sway_seat *seat = e->seat->seat->data;
|
2018-07-21 03:23:48 +02:00
|
|
|
if (e->serial == seat->last_button_serial) {
|
2018-08-10 06:10:09 +02:00
|
|
|
seat_begin_resize_floating(seat, view->swayc,
|
|
|
|
seat->last_button, e->edges);
|
2018-07-21 03:23:48 +02:00
|
|
|
}
|
2018-06-25 00:17:01 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
static void handle_unmap(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, unmap);
|
2018-06-23 08:24:11 +02:00
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
|
|
|
|
|
|
|
if (!sway_assert(view->surface, "Cannot unmap unmapped view")) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-13 17:38:56 +02:00
|
|
|
|
2018-06-26 05:15:45 +02:00
|
|
|
view_unmap(view);
|
2018-05-13 17:38:56 +02:00
|
|
|
|
|
|
|
wl_list_remove(&xdg_shell_view->commit.link);
|
|
|
|
wl_list_remove(&xdg_shell_view->new_popup.link);
|
2018-06-25 00:17:01 +02:00
|
|
|
wl_list_remove(&xdg_shell_view->request_fullscreen.link);
|
2018-07-20 01:28:22 +02:00
|
|
|
wl_list_remove(&xdg_shell_view->request_move.link);
|
|
|
|
wl_list_remove(&xdg_shell_view->request_resize.link);
|
2018-07-22 23:20:07 +02:00
|
|
|
wl_list_remove(&xdg_shell_view->set_title.link);
|
|
|
|
wl_list_remove(&xdg_shell_view->set_app_id.link);
|
2018-05-13 17:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_map(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, map);
|
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
|
|
|
struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
|
|
|
|
|
2018-05-30 02:22:35 +02:00
|
|
|
view->natural_width = view->wlr_xdg_surface->geometry.width;
|
|
|
|
view->natural_height = view->wlr_xdg_surface->geometry.height;
|
|
|
|
if (!view->natural_width && !view->natural_height) {
|
2018-07-01 15:46:02 +02:00
|
|
|
view->natural_width = view->wlr_xdg_surface->surface->current.width;
|
|
|
|
view->natural_height = view->wlr_xdg_surface->surface->current.height;
|
2018-05-30 02:22:35 +02:00
|
|
|
}
|
2018-06-06 14:57:34 +02:00
|
|
|
|
2018-07-29 19:31:10 +02:00
|
|
|
struct sway_server_decoration *deco =
|
|
|
|
decoration_from_surface(xdg_surface->surface);
|
|
|
|
if (deco != NULL) {
|
|
|
|
xdg_shell_view->deco_mode = deco->wlr_server_decoration->mode;
|
|
|
|
} else {
|
|
|
|
xdg_shell_view->deco_mode = WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
view_map(view, view->wlr_xdg_surface->surface);
|
|
|
|
|
2018-06-06 14:57:34 +02:00
|
|
|
if (xdg_surface->toplevel->client_pending.fullscreen) {
|
2018-07-25 12:56:23 +02:00
|
|
|
container_set_fullscreen(view->swayc, true);
|
2018-06-26 06:24:15 +02:00
|
|
|
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
2018-07-14 15:14:55 +02:00
|
|
|
arrange_windows(ws);
|
2018-06-26 06:24:15 +02:00
|
|
|
} else {
|
2018-07-14 15:14:55 +02:00
|
|
|
arrange_windows(view->swayc->parent);
|
2018-06-06 14:57:34 +02:00
|
|
|
}
|
2018-07-14 15:14:55 +02:00
|
|
|
transaction_commit_dirty();
|
2018-06-06 14:57:34 +02:00
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
xdg_shell_view->commit.notify = handle_commit;
|
|
|
|
wl_signal_add(&xdg_surface->surface->events.commit,
|
|
|
|
&xdg_shell_view->commit);
|
|
|
|
|
|
|
|
xdg_shell_view->new_popup.notify = handle_new_popup;
|
|
|
|
wl_signal_add(&xdg_surface->events.new_popup,
|
|
|
|
&xdg_shell_view->new_popup);
|
2018-06-25 00:17:01 +02:00
|
|
|
|
|
|
|
xdg_shell_view->request_fullscreen.notify = handle_request_fullscreen;
|
|
|
|
wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen,
|
|
|
|
&xdg_shell_view->request_fullscreen);
|
2018-07-20 01:28:22 +02:00
|
|
|
|
|
|
|
xdg_shell_view->request_move.notify = handle_request_move;
|
|
|
|
wl_signal_add(&xdg_surface->toplevel->events.request_move,
|
|
|
|
&xdg_shell_view->request_move);
|
|
|
|
|
|
|
|
xdg_shell_view->request_resize.notify = handle_request_resize;
|
|
|
|
wl_signal_add(&xdg_surface->toplevel->events.request_resize,
|
|
|
|
&xdg_shell_view->request_resize);
|
2018-07-22 23:20:07 +02:00
|
|
|
|
|
|
|
xdg_shell_view->set_title.notify = handle_set_title;
|
|
|
|
wl_signal_add(&xdg_surface->toplevel->events.set_title,
|
|
|
|
&xdg_shell_view->set_title);
|
|
|
|
|
|
|
|
xdg_shell_view->set_app_id.notify = handle_set_app_id;
|
|
|
|
wl_signal_add(&xdg_surface->toplevel->events.set_app_id,
|
|
|
|
&xdg_shell_view->set_app_id);
|
2018-05-13 17:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
wl_container_of(listener, xdg_shell_view, destroy);
|
2018-06-23 08:24:11 +02:00
|
|
|
struct sway_view *view = &xdg_shell_view->view;
|
|
|
|
if (!sway_assert(view->swayc == NULL || view->swayc->destroying,
|
|
|
|
"Tried to destroy a mapped view")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_list_remove(&xdg_shell_view->destroy.link);
|
|
|
|
wl_list_remove(&xdg_shell_view->map.link);
|
|
|
|
wl_list_remove(&xdg_shell_view->unmap.link);
|
|
|
|
view->wlr_xdg_surface = NULL;
|
2018-08-20 07:54:30 +02:00
|
|
|
view_begin_destroy(view);
|
2018-05-13 17:38:56 +02:00
|
|
|
}
|
|
|
|
|
2018-06-30 07:00:24 +02:00
|
|
|
struct sway_view *view_from_wlr_xdg_surface(
|
|
|
|
struct wlr_xdg_surface *xdg_surface) {
|
|
|
|
return xdg_surface->data;
|
|
|
|
}
|
|
|
|
|
2018-05-13 17:38:56 +02:00
|
|
|
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_server *server = wl_container_of(listener, server,
|
|
|
|
xdg_shell_surface);
|
|
|
|
struct wlr_xdg_surface *xdg_surface = data;
|
|
|
|
|
|
|
|
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "New xdg_shell popup");
|
2018-05-13 17:38:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:54:30 +02:00
|
|
|
wlr_log(WLR_DEBUG, "New xdg_shell toplevel title='%s' app_id='%s'",
|
2018-05-13 17:38:56 +02:00
|
|
|
xdg_surface->toplevel->title, xdg_surface->toplevel->app_id);
|
|
|
|
wlr_xdg_surface_ping(xdg_surface);
|
|
|
|
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view =
|
|
|
|
calloc(1, sizeof(struct sway_xdg_shell_view));
|
|
|
|
if (!sway_assert(xdg_shell_view, "Failed to allocate view")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl);
|
|
|
|
xdg_shell_view->view.wlr_xdg_surface = xdg_surface;
|
|
|
|
|
|
|
|
xdg_shell_view->map.notify = handle_map;
|
|
|
|
wl_signal_add(&xdg_surface->events.map, &xdg_shell_view->map);
|
|
|
|
|
|
|
|
xdg_shell_view->unmap.notify = handle_unmap;
|
|
|
|
wl_signal_add(&xdg_surface->events.unmap, &xdg_shell_view->unmap);
|
|
|
|
|
|
|
|
xdg_shell_view->destroy.notify = handle_destroy;
|
|
|
|
wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy);
|
|
|
|
|
2018-06-30 07:00:24 +02:00
|
|
|
xdg_surface->data = xdg_shell_view;
|
2018-05-13 17:38:56 +02:00
|
|
|
}
|