From ab5d2cb726cb7f677648c61862e37761e27c6b1a Mon Sep 17 00:00:00 2001 From: Leon Henrik Plickat Date: Fri, 17 Nov 2023 15:27:56 +0100 Subject: [PATCH] add --survive-close feature --- wayneko.1 | 10 ++++++++++ wayneko.c | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/wayneko.1 b/wayneko.1 index 48740a2..7b37b3f 100644 --- a/wayneko.1 +++ b/wayneko.1 @@ -17,6 +17,7 @@ wayneko \- Neko on Wayland .OP \-\-outline\-colour 0xRRGGBB[AA] .OP \-\-type neko|inu|random .OP \-\-follow\-pointer true|false +.OP \-\-survive\-close .YS . . @@ -63,6 +64,15 @@ This option lets you choose between neko and her friend inu. Set whether neko follows the pointer when it approaches the bottom of the output .RE . +.P +\fB\-\-survive\-close\fR +.RS +If this flag is used, wayneko will recreate the surface after it has been closed. +This allows neko to migrate outputs should the one she is currently on be +disconnected, but may cause some undesired behaviour should the server try to +close the surface for a different reason. +.RE +. . .SH AUTHOR .P diff --git a/wayneko.c b/wayneko.c index 082b04b..13138c2 100644 --- a/wayneko.c +++ b/wayneko.c @@ -31,6 +31,7 @@ const char usage[] = " --background-colour 0xRRGGBB[AA]\n" " --outline-colour 0xRRGGBB[AA]\n" " --type neko|inu|random\n" + " --survive-close\n" "\n"; pixman_color_t bg_colour; @@ -71,6 +72,7 @@ size_t animation_ticks_until_next_frame = 10; enum Neko current_neko = NEKO_STARE; enum Type type = NEKO; bool follow_pointer = true; +bool recreate_surface_on_close = false; struct Seat { @@ -1040,6 +1042,7 @@ static void surface_destroy (void) wl_surface_destroy(surface.wl_surface ); surface.wl_surface = NULL; } + surface.configured = false; } static void layer_surface_handle_configure (void *data, struct zwlr_layer_surface_v1 *layer_surface, @@ -1064,12 +1067,20 @@ static void layer_surface_handle_configure (void *data, struct zwlr_layer_surfac surface_next_frame(); } +static const struct wl_callback_listener sync_callback_listener; static void layer_surface_handle_closed (void *data, struct zwlr_layer_surface_v1 *layer_surface) { (void)data; (void)layer_surface; surface_destroy(); - loop = false; + + if (recreate_surface_on_close) + { + sync_callback = wl_display_sync(wl_display); + wl_callback_add_listener(sync_callback, &sync_callback_listener, NULL); + } + else + loop = false; } const struct zwlr_layer_surface_v1_listener layer_surface_listener = { @@ -1253,6 +1264,8 @@ int main (int argc, char *argv[]) fputs(usage, stderr); return EXIT_SUCCESS; } + else if ( strcmp(argv[i], "--survive-close") == 0 ) + recreate_surface_on_close = true; else if ( strcmp(argv[i], "--background-colour") == 0 ) { if (!colour_from_flag(&bg_colour, argc, argv, &i))