Merge pull request #1199 from SirCmpwn/server-decoration

Implement KDE's server-side decoration protocol
This commit is contained in:
Drew DeVault 2017-06-14 19:02:15 -04:00 committed by GitHub
commit 4e663ab44f
5 changed files with 198 additions and 6 deletions

View file

@ -42,8 +42,15 @@ struct swaylock_state {
wlc_resource surface; wlc_resource surface;
}; };
struct decoration_state {
list_t *csd_resources;
};
extern struct desktop_shell_state desktop_shell; extern struct desktop_shell_state desktop_shell;
extern struct decoration_state decoration_state;
void register_extensions(void); void register_extensions(void);
void server_decoration_enable_csd(wlc_handle handle);
#endif #endif

View file

@ -27,6 +27,11 @@ WAYLAND_ADD_PROTOCOL_SERVER(proto-server-gamma-control
gamma-control gamma-control
) )
WAYLAND_ADD_PROTOCOL_SERVER(proto-server-server-decoration
server-decoration.xml
server-decoration
)
add_library(sway-protocols STATIC add_library(sway-protocols STATIC
${proto-client-xdg-shell} ${proto-client-xdg-shell}
${proto-client-desktop-shell} ${proto-client-desktop-shell}
@ -34,6 +39,7 @@ add_library(sway-protocols STATIC
${proto-client-swaylock} ${proto-client-swaylock}
${proto-server-swaylock} ${proto-server-swaylock}
${proto-server-gamma-control} ${proto-server-gamma-control}
${proto-server-server-decoration}
) )
set(PROTOCOLS_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/protocols PARENT_SCOPE) set(PROTOCOLS_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/protocols PARENT_SCOPE)

View file

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="server_decoration">
<copyright><![CDATA[
Copyright (C) 2015 Martin Gräßlin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]></copyright>
<interface name="org_kde_kwin_server_decoration_manager" version="1">
<description summary="Server side window decoration manager">
This interface allows to coordinate whether the server should create
a server-side window decoration around a wl_surface representing a
shell surface (wl_shell_surface or similar). By announcing support
for this interface the server indicates that it supports server
side decorations.
</description>
<request name="create">
<description summary="Create a server-side decoration object for a given surface">
When a client creates a server-side decoration object it indicates
that it supports the protocol. The client is supposed to tell the
server whether it wants server-side decorations or will provide
client-side decorations.
If the client does not create a server-side decoration object for
a surface the server interprets this as lack of support for this
protocol and considers it as client-side decorated. Nevertheless a
client-side decorated surface should use this protocol to indicate
to the server that it does not want a server-side deco.
</description>
<arg name="id" type="new_id" interface="org_kde_kwin_server_decoration"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
<enum name="mode">
<description summary="Possible values to use in request_mode and the event mode."/>
<entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
<entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
<entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
</enum>
<event name="default_mode">
<description summary="The default mode used on the server">
This event is emitted directly after binding the interface. It contains
the default mode for the decoration. When a new server decoration object
is created this new object will be in the default mode until the first
request_mode is requested.
The server may change the default mode at any time.
</description>
<arg name="mode" type="uint" summary="The default decoration mode applied to newly created server decorations."/>
</event>
</interface>
<interface name="org_kde_kwin_server_decoration" version="1">
<request name="release" type="destructor">
<description summary="release the server decoration object"/>
</request>
<enum name="mode">
<description summary="Possible values to use in request_mode and the event mode."/>
<entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
<entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
<entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
</enum>
<request name="request_mode">
<description summary="The decoration mode the surface wants to use."/>
<arg name="mode" type="uint" summary="The mode this surface wants to use."/>
</request>
<event name="mode">
<description summary="The new decoration mode applied by the server">
This event is emitted directly after the decoration is created and
represents the base decoration policy by the server. E.g. a server
which wants all surfaces to be client-side decorated will send Client,
a server which wants server-side decoration will send Server.
The client can request a different mode through the decoration request.
The server will acknowledge this by another event with the same mode. So
even if a server prefers server-side decoration it's possible to force a
client-side decoration.
The server may emit this event at any time. In this case the client can
again request a different mode. It's the responsibility of the server to
prevent a feedback loop.
</description>
<arg name="mode" type="uint" summary="The decoration mode applied to the surface by the server."/>
</event>
</interface>
</protocol>

View file

@ -5,6 +5,7 @@
#include "wayland-desktop-shell-server-protocol.h" #include "wayland-desktop-shell-server-protocol.h"
#include "wayland-swaylock-server-protocol.h" #include "wayland-swaylock-server-protocol.h"
#include "wayland-gamma-control-server-protocol.h" #include "wayland-gamma-control-server-protocol.h"
#include "wayland-server-decoration-server-protocol.h"
#include "sway/layout.h" #include "sway/layout.h"
#include "sway/input_state.h" #include "sway/input_state.h"
#include "sway/extensions.h" #include "sway/extensions.h"
@ -13,6 +14,7 @@
#include "log.h" #include "log.h"
struct desktop_shell_state desktop_shell; struct desktop_shell_state desktop_shell;
struct decoration_state decoration_state;
static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
for (int i = 0; i < desktop_shell.panels->length; i++) { for (int i = 0; i < desktop_shell.panels->length; i++) {
@ -173,7 +175,7 @@ static struct desktop_shell_interface desktop_shell_implementation = {
}; };
static void desktop_shell_bind(struct wl_client *client, void *data, static void desktop_shell_bind(struct wl_client *client, void *data,
unsigned int version, unsigned int id) { uint32_t version, uint32_t id) {
if (version > 3) { if (version > 3) {
// Unsupported version // Unsupported version
return; return;
@ -232,7 +234,7 @@ static struct lock_interface swaylock_implementation = {
}; };
static void swaylock_bind(struct wl_client *client, void *data, static void swaylock_bind(struct wl_client *client, void *data,
unsigned int version, unsigned int id) { uint32_t version, uint32_t id) {
if (version > 1) { if (version > 1) {
// Unsupported version // Unsupported version
return; return;
@ -305,28 +307,101 @@ static struct gamma_control_manager_interface gamma_manager_implementation = {
}; };
static void gamma_control_manager_bind(struct wl_client *client, void *data, static void gamma_control_manager_bind(struct wl_client *client, void *data,
unsigned int version, unsigned int fd) { uint32_t version, uint32_t id) {
if (version > 1) { if (version > 1) {
// Unsupported version // Unsupported version
return; return;
} }
struct wl_resource *resource = wl_resource_create(client, struct wl_resource *resource = wl_resource_create(client,
&gamma_control_manager_interface, version, fd); &gamma_control_manager_interface, version, id);
if (!resource) { if (!resource) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
} }
wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL); wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL);
} }
static void server_decoration_release(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
void server_decoration_enable_csd(wlc_handle handle) {
swayc_t *view = swayc_by_handle(handle);
if (!view) {
sway_log(L_DEBUG, "view invalid");
return;
}
sway_log(L_DEBUG, "%s requested client side decorations", view->name);
view->border_type = B_NONE;
update_geometry(view);
}
static void server_decoration_request_mode(struct wl_client *client,
struct wl_resource *resource, uint32_t mode) {
sway_log(L_DEBUG, "Client requested server decoration mode %d", mode);
if (mode == ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER) {
return;
}
struct wl_resource *surface = wl_resource_get_user_data(resource);
if (!surface) {
sway_log(L_DEBUG, "surface invalid");
return;
}
wlc_handle handle = wlc_handle_from_wl_surface_resource(surface);
if (!handle) {
list_add(decoration_state.csd_resources, surface);
return;
}
server_decoration_enable_csd(handle);
}
static struct org_kde_kwin_server_decoration_interface server_decoration_implementation = {
.release = server_decoration_release,
.request_mode = server_decoration_request_mode,
};
static void server_decoration_manager_create(struct wl_client *client,
struct wl_resource *resource, uint32_t id, struct wl_resource *surface) {
sway_log(L_DEBUG, "Client requested server decoration manager");
struct wl_resource *manager = wl_resource_create(client,
&org_kde_kwin_server_decoration_interface, 1, id);
if (!manager) {
wl_client_post_no_memory(client);
}
wl_resource_set_implementation(manager, &server_decoration_implementation, surface, NULL);
}
// Jesus christ KDE, these names are whack as hell
static struct org_kde_kwin_server_decoration_manager_interface server_decoration_manager_implementation = {
.create = server_decoration_manager_create,
};
static void server_decoration_manager_bind(struct wl_client *client, void *data,
uint32_t version, uint32_t id) {
if (version > 1) {
// Unsupported version
return;
}
struct wl_resource *resource = wl_resource_create(client,
&org_kde_kwin_server_decoration_manager_interface, version, id);
if (!resource) {
wl_client_post_no_memory(client);
}
wl_resource_set_implementation(resource, &server_decoration_manager_implementation, NULL, NULL);
org_kde_kwin_server_decoration_manager_send_default_mode(resource,
ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER);
}
void register_extensions(void) { void register_extensions(void) {
wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
desktop_shell.backgrounds = create_list(); desktop_shell.backgrounds = create_list();
desktop_shell.panels = create_list(); desktop_shell.panels = create_list();
desktop_shell.lock_surfaces = create_list(); desktop_shell.lock_surfaces = create_list();
desktop_shell.is_locked = false; desktop_shell.is_locked = false;
decoration_state.csd_resources = create_list();
wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind);
wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1, wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1,
NULL, gamma_control_manager_bind); NULL, gamma_control_manager_bind);
wl_global_create(wlc_get_wl_display(), &org_kde_kwin_server_decoration_manager_interface ,
1, NULL, server_decoration_manager_bind);
} }

View file

@ -345,6 +345,8 @@ static bool handle_view_created(wlc_handle handle) {
swayc_t *current_ws = swayc_active_workspace(); swayc_t *current_ws = swayc_active_workspace();
bool return_to_workspace = false; bool return_to_workspace = false;
struct wl_client *client = wlc_view_get_wl_client(handle); struct wl_client *client = wlc_view_get_wl_client(handle);
struct wl_resource *resource = wlc_surface_get_wl_resource(
wlc_view_get_surface(handle));
pid_t pid; pid_t pid;
struct panel_config *panel_config = NULL; struct panel_config *panel_config = NULL;
struct background_config *background_config = NULL; struct background_config *background_config = NULL;
@ -483,6 +485,14 @@ static bool handle_view_created(wlc_handle handle) {
if (workspace && workspace->fullscreen) { if (workspace && workspace->fullscreen) {
set_focused_container(workspace->fullscreen); set_focused_container(workspace->fullscreen);
} }
for (int i = 0; i < decoration_state.csd_resources->length; ++i) {
struct wl_resource *res = decoration_state.csd_resources->items[i];
if (res == resource) {
list_del(decoration_state.csd_resources, i);
server_decoration_enable_csd(handle);
break;
}
}
} else { } else {
swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
wlc_handle *h = malloc(sizeof(wlc_handle)); wlc_handle *h = malloc(sizeof(wlc_handle));