summaryrefslogtreecommitdiffstats
path: root/sway/extensions.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/extensions.c')
-rw-r--r--sway/extensions.c87
1 files changed, 81 insertions, 6 deletions
diff --git a/sway/extensions.c b/sway/extensions.c
index 96957dbf..91746561 100644
--- a/sway/extensions.c
+++ b/sway/extensions.c
@@ -5,6 +5,7 @@
5#include "wayland-desktop-shell-server-protocol.h" 5#include "wayland-desktop-shell-server-protocol.h"
6#include "wayland-swaylock-server-protocol.h" 6#include "wayland-swaylock-server-protocol.h"
7#include "wayland-gamma-control-server-protocol.h" 7#include "wayland-gamma-control-server-protocol.h"
8#include "wayland-server-decoration-server-protocol.h"
8#include "sway/layout.h" 9#include "sway/layout.h"
9#include "sway/input_state.h" 10#include "sway/input_state.h"
10#include "sway/extensions.h" 11#include "sway/extensions.h"
@@ -13,6 +14,7 @@
13#include "log.h" 14#include "log.h"
14 15
15struct desktop_shell_state desktop_shell; 16struct desktop_shell_state desktop_shell;
17struct decoration_state decoration_state;
16 18
17static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { 19static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
18 for (int i = 0; i < desktop_shell.panels->length; i++) { 20 for (int i = 0; i < desktop_shell.panels->length; i++) {
@@ -173,7 +175,7 @@ static struct desktop_shell_interface desktop_shell_implementation = {
173}; 175};
174 176
175static void desktop_shell_bind(struct wl_client *client, void *data, 177static void desktop_shell_bind(struct wl_client *client, void *data,
176 unsigned int version, unsigned int id) { 178 uint32_t version, uint32_t id) {
177 if (version > 3) { 179 if (version > 3) {
178 // Unsupported version 180 // Unsupported version
179 return; 181 return;
@@ -232,7 +234,7 @@ static struct lock_interface swaylock_implementation = {
232}; 234};
233 235
234static void swaylock_bind(struct wl_client *client, void *data, 236static void swaylock_bind(struct wl_client *client, void *data,
235 unsigned int version, unsigned int id) { 237 uint32_t version, uint32_t id) {
236 if (version > 1) { 238 if (version > 1) {
237 // Unsupported version 239 // Unsupported version
238 return; 240 return;
@@ -305,28 +307,101 @@ static struct gamma_control_manager_interface gamma_manager_implementation = {
305}; 307};
306 308
307static void gamma_control_manager_bind(struct wl_client *client, void *data, 309static void gamma_control_manager_bind(struct wl_client *client, void *data,
308 unsigned int version, unsigned int fd) { 310 uint32_t version, uint32_t id) {
309 if (version > 1) { 311 if (version > 1) {
310 // Unsupported version 312 // Unsupported version
311 return; 313 return;
312 } 314 }
313
314 struct wl_resource *resource = wl_resource_create(client, 315 struct wl_resource *resource = wl_resource_create(client,
315 &gamma_control_manager_interface, version, fd); 316 &gamma_control_manager_interface, version, id);
316 if (!resource) { 317 if (!resource) {
317 wl_client_post_no_memory(client); 318 wl_client_post_no_memory(client);
318 } 319 }
319
320 wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL); 320 wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL);
321} 321}
322 322
323static void server_decoration_release(struct wl_client *client,
324 struct wl_resource *resource) {
325 wl_resource_destroy(resource);
326}
327
328void server_decoration_enable_csd(wlc_handle handle) {
329 swayc_t *view = swayc_by_handle(handle);
330 if (!view) {
331 sway_log(L_DEBUG, "view invalid");
332 return;
333 }
334 sway_log(L_DEBUG, "%s requested client side decorations", view->name);
335 view->border_type = B_NONE;
336 update_geometry(view);
337}
338
339static void server_decoration_request_mode(struct wl_client *client,
340 struct wl_resource *resource, uint32_t mode) {
341 sway_log(L_DEBUG, "Client requested server decoration mode %d", mode);
342 if (mode == ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER) {
343 return;
344 }
345 struct wl_resource *surface = wl_resource_get_user_data(resource);
346 if (!surface) {
347 sway_log(L_DEBUG, "surface invalid");
348 return;
349 }
350 wlc_handle handle = wlc_handle_from_wl_surface_resource(surface);
351 if (!handle) {
352 list_add(decoration_state.csd_resources, surface);
353 return;
354 }
355 server_decoration_enable_csd(handle);
356}
357
358static struct org_kde_kwin_server_decoration_interface server_decoration_implementation = {
359 .release = server_decoration_release,
360 .request_mode = server_decoration_request_mode,
361};
362
363static void server_decoration_manager_create(struct wl_client *client,
364 struct wl_resource *resource, uint32_t id, struct wl_resource *surface) {
365 sway_log(L_DEBUG, "Client requested server decoration manager");
366 struct wl_resource *manager = wl_resource_create(client,
367 &org_kde_kwin_server_decoration_interface, 1, id);
368 if (!manager) {
369 wl_client_post_no_memory(client);
370 }
371 wl_resource_set_implementation(manager, &server_decoration_implementation, surface, NULL);
372}
373
374// Jesus christ KDE, these names are whack as hell
375static struct org_kde_kwin_server_decoration_manager_interface server_decoration_manager_implementation = {
376 .create = server_decoration_manager_create,
377};
378
379static void server_decoration_manager_bind(struct wl_client *client, void *data,
380 uint32_t version, uint32_t id) {
381 if (version > 1) {
382 // Unsupported version
383 return;
384 }
385 struct wl_resource *resource = wl_resource_create(client,
386 &org_kde_kwin_server_decoration_manager_interface, version, id);
387 if (!resource) {
388 wl_client_post_no_memory(client);
389 }
390 wl_resource_set_implementation(resource, &server_decoration_manager_implementation, NULL, NULL);
391 org_kde_kwin_server_decoration_manager_send_default_mode(resource,
392 ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER);
393}
394
323void register_extensions(void) { 395void register_extensions(void) {
324 wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); 396 wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
325 desktop_shell.backgrounds = create_list(); 397 desktop_shell.backgrounds = create_list();
326 desktop_shell.panels = create_list(); 398 desktop_shell.panels = create_list();
327 desktop_shell.lock_surfaces = create_list(); 399 desktop_shell.lock_surfaces = create_list();
328 desktop_shell.is_locked = false; 400 desktop_shell.is_locked = false;
401 decoration_state.csd_resources = create_list();
329 wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); 402 wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind);
330 wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1, 403 wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1,
331 NULL, gamma_control_manager_bind); 404 NULL, gamma_control_manager_bind);
405 wl_global_create(wlc_get_wl_display(), &org_kde_kwin_server_decoration_manager_interface ,
406 1, NULL, server_decoration_manager_bind);
332} 407}