diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-06-14 19:02:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 19:02:15 -0400 |
commit | 4e663ab44f5320f20ec2376f24ea1eb3b458f2c2 (patch) | |
tree | dcb3b74f1dde93bce8657b7509662ffd7db667d0 /sway | |
parent | Merge pull request #1234 from 4e554c4c/tray (diff) | |
parent | Merge branch 'master' into server-decoration (diff) | |
download | sway-74e1c0e674bc5ecbf67c6d4106991877afcacb96.tar.gz sway-74e1c0e674bc5ecbf67c6d4106991877afcacb96.tar.zst sway-74e1c0e674bc5ecbf67c6d4106991877afcacb96.zip |
Implement KDE's server-side decoration protocol
Diffstat (limited to 'sway')
-rw-r--r-- | sway/extensions.c | 87 | ||||
-rw-r--r-- | sway/handlers.c | 10 |
2 files changed, 91 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 | ||
15 | struct desktop_shell_state desktop_shell; | 16 | struct desktop_shell_state desktop_shell; |
17 | struct decoration_state decoration_state; | ||
16 | 18 | ||
17 | static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { | 19 | static 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 | ||
175 | static void desktop_shell_bind(struct wl_client *client, void *data, | 177 | static 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 | ||
234 | static void swaylock_bind(struct wl_client *client, void *data, | 236 | static 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 | ||
307 | static void gamma_control_manager_bind(struct wl_client *client, void *data, | 309 | static 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 | ||
323 | static void server_decoration_release(struct wl_client *client, | ||
324 | struct wl_resource *resource) { | ||
325 | wl_resource_destroy(resource); | ||
326 | } | ||
327 | |||
328 | void 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 | |||
339 | static 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 | |||
358 | static struct org_kde_kwin_server_decoration_interface server_decoration_implementation = { | ||
359 | .release = server_decoration_release, | ||
360 | .request_mode = server_decoration_request_mode, | ||
361 | }; | ||
362 | |||
363 | static 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 | ||
375 | static struct org_kde_kwin_server_decoration_manager_interface server_decoration_manager_implementation = { | ||
376 | .create = server_decoration_manager_create, | ||
377 | }; | ||
378 | |||
379 | static 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 | |||
323 | void register_extensions(void) { | 395 | void 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 | } |
diff --git a/sway/handlers.c b/sway/handlers.c index a912b991..39261e3d 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -345,6 +345,8 @@ static bool handle_view_created(wlc_handle handle) { | |||
345 | swayc_t *current_ws = swayc_active_workspace(); | 345 | swayc_t *current_ws = swayc_active_workspace(); |
346 | bool return_to_workspace = false; | 346 | bool return_to_workspace = false; |
347 | struct wl_client *client = wlc_view_get_wl_client(handle); | 347 | struct wl_client *client = wlc_view_get_wl_client(handle); |
348 | struct wl_resource *resource = wlc_surface_get_wl_resource( | ||
349 | wlc_view_get_surface(handle)); | ||
348 | pid_t pid; | 350 | pid_t pid; |
349 | struct panel_config *panel_config = NULL; | 351 | struct panel_config *panel_config = NULL; |
350 | struct background_config *background_config = NULL; | 352 | struct background_config *background_config = NULL; |
@@ -483,6 +485,14 @@ static bool handle_view_created(wlc_handle handle) { | |||
483 | if (workspace && workspace->fullscreen) { | 485 | if (workspace && workspace->fullscreen) { |
484 | set_focused_container(workspace->fullscreen); | 486 | set_focused_container(workspace->fullscreen); |
485 | } | 487 | } |
488 | for (int i = 0; i < decoration_state.csd_resources->length; ++i) { | ||
489 | struct wl_resource *res = decoration_state.csd_resources->items[i]; | ||
490 | if (res == resource) { | ||
491 | list_del(decoration_state.csd_resources, i); | ||
492 | server_decoration_enable_csd(handle); | ||
493 | break; | ||
494 | } | ||
495 | } | ||
486 | } else { | 496 | } else { |
487 | swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); | 497 | swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); |
488 | wlc_handle *h = malloc(sizeof(wlc_handle)); | 498 | wlc_handle *h = malloc(sizeof(wlc_handle)); |