Skip to content

Commit

Permalink
wayland: use xdg-decoration if available
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion authored and jeeb committed Nov 18, 2018
1 parent ce2253b commit 6d2be82
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
56 changes: 43 additions & 13 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
// Generated from idle-inhibit-unstable-v1.xml
#include "video/out/wayland/idle-inhibit-v1.h"

// Generated from xdg-decoration-unstable-v1.xml
#include "video/out/wayland/xdg-decoration-v1.h"

// Generated from server-decoration.xml
#include "video/out/wayland/srv-decor.h"

Expand Down Expand Up @@ -827,6 +830,10 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id
wl->server_decoration_manager = wl_registry_bind(reg, id, &org_kde_kwin_server_decoration_manager_interface, 1);
}

if (!strcmp(interface, zxdg_decoration_manager_v1_interface.name) && found++) {
wl->xdg_decoration_manager = wl_registry_bind(reg, id, &zxdg_decoration_manager_v1_interface, 1);
}

if (!strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) && found++) {
wl->idle_inhibit_manager = wl_registry_bind(reg, id, &zwp_idle_inhibit_manager_v1_interface, 1);
}
Expand Down Expand Up @@ -970,18 +977,31 @@ static int create_xdg_surface(struct vo_wayland_state *wl)

static int set_border_decorations(struct vo_wayland_state *wl, int state)
{
if (!wl->server_decoration)
return VO_NOTIMPL;
enum org_kde_kwin_server_decoration_mode mode;
if (state) {
MP_VERBOSE(wl, "Enabling server decorations\n");
mode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER;
if (wl->xdg_toplevel_decoration) {
enum zxdg_toplevel_decoration_v1_mode mode;
if (state) {
MP_VERBOSE(wl, "Enabling server decorations\n");
mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
} else {
MP_VERBOSE(wl, "Disabling server decorations\n");
mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
}
zxdg_toplevel_decoration_v1_set_mode(wl->xdg_toplevel_decoration, mode);
return VO_TRUE;
} else if (wl->server_decoration) {
enum org_kde_kwin_server_decoration_mode mode;
if (state) {
MP_VERBOSE(wl, "Enabling server decorations\n");
mode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER;
} else {
MP_VERBOSE(wl, "Disabling server decorations\n");
mode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_NONE;
}
org_kde_kwin_server_decoration_request_mode(wl->server_decoration, mode);
return VO_TRUE;
} else {
MP_VERBOSE(wl, "Disabling server decorations\n");
mode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_NONE;
return VO_NOTIMPL;
}
org_kde_kwin_server_decoration_request_mode(wl->server_decoration, mode);
return VO_TRUE;
}

int vo_wayland_init(struct vo *vo)
Expand Down Expand Up @@ -1036,12 +1056,16 @@ int vo_wayland_init(struct vo *vo)
wl_data_device_manager_interface.name);
}

if (wl->server_decoration_manager) {
if (wl->xdg_decoration_manager) {
wl->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(wl->xdg_decoration_manager, wl->xdg_toplevel);
set_border_decorations(wl, vo->opts->border);
} else if (wl->server_decoration_manager) {
wl->server_decoration = org_kde_kwin_server_decoration_manager_create(wl->server_decoration_manager, wl->surface);
set_border_decorations(wl, vo->opts->border);
} else {
MP_VERBOSE(wl, "Compositor doesn't support the %s protocol!\n",
org_kde_kwin_server_decoration_manager_interface.name);
MP_VERBOSE(wl, "Compositor doesn't support the %s or %s protocols!\n",
org_kde_kwin_server_decoration_manager_interface.name,
zxdg_decoration_manager_v1_interface.name);
}

if (!wl->idle_inhibit_manager)
Expand Down Expand Up @@ -1092,6 +1116,12 @@ void vo_wayland_uninit(struct vo *vo)
if (wl->server_decoration_manager)
org_kde_kwin_server_decoration_manager_destroy(wl->server_decoration_manager);

if (wl->xdg_toplevel_decoration)
zxdg_toplevel_decoration_v1_destroy(wl->xdg_toplevel_decoration);

if (wl->xdg_decoration_manager)
zxdg_decoration_manager_v1_destroy(wl->xdg_decoration_manager);

if (wl->surface)
wl_surface_destroy(wl->surface);

Expand Down
2 changes: 2 additions & 0 deletions video/out/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ struct vo_wayland_state {
struct xdg_surface *xdg_surface;
struct org_kde_kwin_server_decoration_manager *server_decoration_manager;
struct org_kde_kwin_server_decoration *server_decoration;
struct zxdg_decoration_manager_v1 *xdg_decoration_manager;
struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration;
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager;
struct zwp_idle_inhibitor_v1 *idle_inhibitor;

Expand Down
2 changes: 1 addition & 1 deletion waftools/checks/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def check_lua(ctx, dependency_identifier):

def check_wl_protocols(ctx, dependency_identifier):
def fn(ctx, dependency_identifier):
ret = check_pkg_config_datadir("wayland-protocols", ">= 1.14")
ret = check_pkg_config_datadir("wayland-protocols", ">= 1.15")
ret = ret(ctx, dependency_identifier)
if ret != None:
ctx.env.WL_PROTO_DIR = ret.split()[0]
Expand Down
7 changes: 7 additions & 0 deletions wscript_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def build(ctx):
ctx.wayland_protocol_header(proto_dir = ctx.env.WL_PROTO_DIR,
protocol = "unstable/idle-inhibit/idle-inhibit-unstable-v1",
target = "video/out/wayland/idle-inhibit-v1.h")
ctx.wayland_protocol_code(proto_dir = ctx.env.WL_PROTO_DIR,
protocol = "unstable/xdg-decoration/xdg-decoration-unstable-v1",
target = "video/out/wayland/xdg-decoration-v1.c")
ctx.wayland_protocol_header(proto_dir = ctx.env.WL_PROTO_DIR,
protocol = "unstable/xdg-decoration/xdg-decoration-unstable-v1",
target = "video/out/wayland/xdg-decoration-v1.h")
ctx.wayland_protocol_code(proto_dir = "video/out/wayland",
protocol = "server-decoration",
vendored_protocol = True,
Expand Down Expand Up @@ -508,6 +514,7 @@ def swift(task):
( "video/out/w32_common.c", "win32-desktop" ),
( "video/out/wayland/idle-inhibit-v1.c", "wayland" ),
( "video/out/wayland/srv-decor.c", "wayland" ),
( "video/out/wayland/xdg-decoration-v1.c", "wayland" ),
( "video/out/wayland/xdg-shell.c", "wayland" ),
( "video/out/wayland_common.c", "wayland" ),
( "video/out/win32/displayconfig.c", "win32-desktop" ),
Expand Down

0 comments on commit 6d2be82

Please sign in to comment.