Listen to server-decoration mode changes

This commit is contained in:
emersion 2018-07-13 21:53:56 +01:00
parent 0cd418ba42
commit 700941dde8
5 changed files with 72 additions and 6 deletions

13
include/sway/decoration.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef _SWAY_DECORATION_H
#define _SWAY_DECORATION_H
#include <wlr/types/wlr_server_decoration.h>
struct sway_server_decoration {
struct wlr_server_decoration *wlr_server_decoration;
struct wl_listener destroy;
struct wl_listener mode;
};
#endif

View file

@ -4,12 +4,13 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_layer_shell.h> #include <wlr/types/wlr_layer_shell.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/render/wlr_renderer.h>
// TODO WLR: make Xwayland optional // TODO WLR: make Xwayland optional
#include "list.h" #include "list.h"
#include "config.h" #include "config.h"
@ -42,11 +43,16 @@ struct sway_server {
struct wlr_xdg_shell *xdg_shell; struct wlr_xdg_shell *xdg_shell;
struct wl_listener xdg_shell_surface; struct wl_listener xdg_shell_surface;
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
struct sway_xwayland xwayland; struct sway_xwayland xwayland;
struct wl_listener xwayland_surface; struct wl_listener xwayland_surface;
struct wl_listener xwayland_ready; struct wl_listener xwayland_ready;
#endif #endif
struct wlr_server_decoration_manager *server_decoration_manager;
struct wl_listener server_decoration;
bool debug_txn_timings; bool debug_txn_timings;
list_t *transactions; list_t *transactions;
@ -71,4 +77,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
void handle_xwayland_surface(struct wl_listener *listener, void *data); void handle_xwayland_surface(struct wl_listener *listener, void *data);
#endif #endif
void handle_server_decoration(struct wl_listener *listener, void *data);
#endif #endif

41
sway/decoration.c Normal file
View file

@ -0,0 +1,41 @@
#include <stdlib.h>
#include "sway/decoration.h"
#include "sway/server.h"
#include "sway/tree/view.h"
#include "log.h"
static void server_decoration_handle_destroy(struct wl_listener *listener,
void *data) {
struct sway_server_decoration *deco =
wl_container_of(listener, deco, destroy);
wl_list_remove(&deco->destroy.link);
free(deco);
}
static void server_decoration_handle_mode(struct wl_listener *listener,
void *data) {
struct sway_server_decoration *deco =
wl_container_of(listener, deco, mode);
struct sway_view *view =
view_from_wlr_surface(deco->wlr_server_decoration->surface);
// TODO
wlr_log(WLR_ERROR, "%p %d", view, deco->wlr_server_decoration->mode);
}
void handle_server_decoration(struct wl_listener *listener, void *data) {
struct wlr_server_decoration *wlr_deco = data;
struct sway_server_decoration *deco = calloc(1, sizeof(*deco));
if (deco == NULL) {
return;
}
deco->wlr_server_decoration = wlr_deco;
wl_signal_add(&wlr_deco->events.destroy, &deco->destroy);
deco->destroy.notify = server_decoration_handle_destroy;
wl_signal_add(&wlr_deco->events.mode, &deco->mode);
deco->mode.notify = server_decoration_handle_mode;
}

View file

@ -1,13 +1,14 @@
sway_sources = files( sway_sources = files(
'main.c',
'server.c',
'commands.c', 'commands.c',
'config.c', 'config.c',
'criteria.c', 'criteria.c',
'debug-tree.c', 'debug-tree.c',
'decoration.c',
'ipc-json.c', 'ipc-json.c',
'ipc-server.c', 'ipc-server.c',
'main.c',
'security.c', 'security.c',
'server.c',
'swaynag.c', 'swaynag.c',
'desktop/desktop.c', 'desktop/desktop.c',

View file

@ -109,11 +109,14 @@ bool server_init(struct sway_server *server) {
} }
#endif #endif
// TODO: Integration with sway borders server->server_decoration_manager =
struct wlr_server_decoration_manager *deco_manager =
wlr_server_decoration_manager_create(server->wl_display); wlr_server_decoration_manager_create(server->wl_display);
wlr_server_decoration_manager_set_default_mode( wlr_server_decoration_manager_set_default_mode(
deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); server->server_decoration_manager,
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
wl_signal_add(&server->server_decoration_manager->events.new_decoration,
&server->server_decoration);
server->server_decoration.notify = handle_server_decoration;
wlr_linux_dmabuf_v1_create(server->wl_display, renderer); wlr_linux_dmabuf_v1_create(server->wl_display, renderer);
wlr_export_dmabuf_manager_v1_create(server->wl_display); wlr_export_dmabuf_manager_v1_create(server->wl_display);