wayland: ask KDE protocol extension to use server-side decorations if possible.

This commit is contained in:
Ryan C. Gordon
2018-10-29 10:14:59 -04:00
parent 8340b0f0e2
commit a5ebd4d775
5 changed files with 128 additions and 0 deletions

View File

@@ -47,6 +47,7 @@
#include "xdg-shell-client-protocol.h"
#include "xdg-shell-unstable-v6-client-protocol.h"
#include "org-kde-kwin-server-decoration-manager-client-protocol.h"
#define WAYLANDVID_DRIVER_NAME "wayland"
@@ -182,6 +183,7 @@ Wayland_CreateDevice(int devindex)
device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
device->MaximizeWindow = Wayland_MaximizeWindow;
device->RestoreWindow = Wayland_RestoreWindow;
device->SetWindowBordered = Wayland_SetWindowBordered;
device->SetWindowSize = Wayland_SetWindowSize;
device->SetWindowTitle = Wayland_SetWindowTitle;
device->DestroyWindow = Wayland_DestroyWindow;
@@ -345,6 +347,8 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
{
SDL_VideoData *d = data;
/*printf("WAYLAND INTERFACE: %s\n", interface);*/
if (strcmp(interface, "wl_compositor") == 0) {
d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
} else if (strcmp(interface, "wl_output") == 0) {
@@ -368,6 +372,8 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
Wayland_display_add_pointer_constraints(d, id);
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
} else if (strcmp(interface, "org_kde_kwin_server_decoration_manager") == 0) {
d->kwin_server_decoration_manager = wl_registry_bind(d->registry, id, &org_kde_kwin_server_decoration_manager_interface, 1);
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
} else if (strcmp(interface, "qt_touch_extension") == 0) {

View File

@@ -61,6 +61,7 @@ typedef struct {
struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
struct zwp_pointer_constraints_v1 *pointer_constraints;
struct wl_data_device_manager *data_device_manager;
struct org_kde_kwin_server_decoration_manager *kwin_server_decoration_manager;
EGLDisplay edpy;
EGLContext context;

View File

@@ -35,6 +35,7 @@
#include "xdg-shell-client-protocol.h"
#include "xdg-shell-unstable-v6-client-protocol.h"
#include "org-kde-kwin-server-decoration-manager-client-protocol.h"
/* On modern desktops, we probably will use the xdg-shell protocol instead
of wl_shell, but wl_shell might be useful on older Wayland installs that
@@ -459,6 +460,17 @@ Wayland_RestoreWindow(_THIS, SDL_Window * window)
WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
}
void
Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{
SDL_WindowData *wind = window->driverdata;
const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
if ((viddata->kwin_server_decoration_manager) && (wind->kwin_server_decoration)) {
const enum org_kde_kwin_server_decoration_mode mode = bordered ? ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER : ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
org_kde_kwin_server_decoration_request_mode(wind->kwin_server_decoration, mode);
}
}
void
Wayland_MaximizeWindow(_THIS, SDL_Window * window)
{
@@ -570,6 +582,15 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
if (c->kwin_server_decoration_manager) {
data->kwin_server_decoration = org_kde_kwin_server_decoration_manager_create(c->kwin_server_decoration_manager, data->surface);
if (data->kwin_server_decoration) {
const SDL_bool bordered = (window->flags & SDL_WINDOW_BORDERLESS) == 0;
const enum org_kde_kwin_server_decoration_mode mode = bordered ? ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER : ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
org_kde_kwin_server_decoration_request_mode(data->kwin_server_decoration, mode);
}
}
region = wl_compositor_create_region(c->compositor);
wl_region_add(region, 0, 0, window->w, window->h);
wl_surface_set_opaque_region(data->surface, region);
@@ -644,6 +665,10 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window)
SDL_EGL_DestroySurface(_this, wind->egl_surface);
WAYLAND_wl_egl_window_destroy(wind->egl_window);
if (wind->kwin_server_decoration) {
org_kde_kwin_server_decoration_release(wind->kwin_server_decoration);
}
if (data->shell.xdg) {
if (wind->shell_surface.xdg.roleobj.toplevel) {
xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel);

View File

@@ -62,6 +62,7 @@ typedef struct {
struct SDL_WaylandInput *keyboard_device;
EGLSurface egl_surface;
struct zwp_locked_pointer_v1 *locked_pointer;
struct org_kde_kwin_server_decoration *kwin_server_decoration;
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
struct qt_extended_surface *extended_surface;
@@ -74,6 +75,7 @@ extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
SDL_bool fullscreen);
extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window);
extern void Wayland_RestoreWindow(_THIS, SDL_Window * window);
extern void Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window);