2018-09-24 20:54:57 +10:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "sway/desktop/transaction.h"
|
|
|
|
#include "sway/server.h"
|
|
|
|
#include "sway/tree/arrange.h"
|
|
|
|
#include "sway/tree/view.h"
|
|
|
|
#include "sway/xdg_decoration.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static void xdg_decoration_handle_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_xdg_decoration *deco =
|
|
|
|
wl_container_of(listener, deco, destroy);
|
2021-08-11 03:01:37 +10:00
|
|
|
if (deco->view) {
|
2019-02-23 18:28:49 +11:00
|
|
|
deco->view->xdg_decoration = NULL;
|
|
|
|
}
|
2018-09-24 20:54:57 +10:00
|
|
|
wl_list_remove(&deco->destroy.link);
|
2018-09-27 22:44:57 +10:00
|
|
|
wl_list_remove(&deco->request_mode.link);
|
2018-09-24 20:54:57 +10:00
|
|
|
wl_list_remove(&deco->link);
|
|
|
|
free(deco);
|
|
|
|
}
|
|
|
|
|
2018-09-27 22:44:57 +10:00
|
|
|
static void xdg_decoration_handle_request_mode(struct wl_listener *listener,
|
2018-09-24 20:54:57 +10:00
|
|
|
void *data) {
|
2018-09-27 22:44:57 +10:00
|
|
|
struct sway_xdg_decoration *deco =
|
|
|
|
wl_container_of(listener, deco, request_mode);
|
2021-08-11 03:01:37 +10:00
|
|
|
struct sway_view *view = deco->view;
|
|
|
|
enum wlr_xdg_toplevel_decoration_v1_mode mode =
|
|
|
|
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
|
|
|
|
enum wlr_xdg_toplevel_decoration_v1_mode client_mode =
|
2021-10-08 05:22:56 +11:00
|
|
|
deco->wlr_xdg_decoration->requested_mode;
|
2021-08-11 03:01:37 +10:00
|
|
|
|
|
|
|
bool floating;
|
|
|
|
if (view->container) {
|
|
|
|
floating = container_is_floating(view->container);
|
|
|
|
bool csd = false;
|
|
|
|
csd = client_mode ==
|
|
|
|
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
|
|
|
|
view_update_csd_from_client(view, csd);
|
|
|
|
arrange_container(view->container);
|
|
|
|
transaction_commit_dirty();
|
|
|
|
} else {
|
|
|
|
floating = view->impl->wants_floating &&
|
|
|
|
view->impl->wants_floating(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (floating && client_mode) {
|
|
|
|
mode = client_mode;
|
|
|
|
}
|
|
|
|
|
2018-09-27 22:44:57 +10:00
|
|
|
wlr_xdg_toplevel_decoration_v1_set_mode(deco->wlr_xdg_decoration,
|
2021-08-11 03:01:37 +10:00
|
|
|
mode);
|
2018-09-24 20:54:57 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_xdg_decoration(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xdg_toplevel_decoration_v1 *wlr_deco = data;
|
|
|
|
struct sway_xdg_shell_view *xdg_shell_view = wlr_deco->surface->data;
|
|
|
|
|
|
|
|
struct sway_xdg_decoration *deco = calloc(1, sizeof(*deco));
|
|
|
|
if (deco == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
deco->view = &xdg_shell_view->view;
|
|
|
|
deco->view->xdg_decoration = deco;
|
|
|
|
deco->wlr_xdg_decoration = wlr_deco;
|
|
|
|
|
|
|
|
wl_signal_add(&wlr_deco->events.destroy, &deco->destroy);
|
|
|
|
deco->destroy.notify = xdg_decoration_handle_destroy;
|
|
|
|
|
2018-09-27 22:44:57 +10:00
|
|
|
wl_signal_add(&wlr_deco->events.request_mode, &deco->request_mode);
|
|
|
|
deco->request_mode.notify = xdg_decoration_handle_request_mode;
|
2018-09-24 20:54:57 +10:00
|
|
|
|
|
|
|
wl_list_insert(&server.xdg_decorations, &deco->link);
|
2019-05-04 07:11:18 +10:00
|
|
|
|
|
|
|
xdg_decoration_handle_request_mode(&deco->request_mode, wlr_deco);
|
2018-09-24 20:54:57 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_xdg_decoration *xdg_decoration_from_surface(
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
struct sway_xdg_decoration *deco;
|
|
|
|
wl_list_for_each(deco, &server.xdg_decorations, link) {
|
|
|
|
if (deco->wlr_xdg_decoration->surface->surface == surface) {
|
|
|
|
return deco;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|