neuswc

patched neuswc library (tracked)
git clone https://git.daat.foo/neuswc.git
Log | Files | Refs | README | LICENSE

keys.patch (3764B)


      1 diff --git a/libswc/layer_shell.c b/libswc/layer_shell.c
      2 index f167c8f..ffbed24 100644
      3 --- a/libswc/layer_shell.c
      4 +++ b/libswc/layer_shell.c
      5 @@ -387,6 +387,73 @@ static const struct zwlr_layer_surface_v1_interface layer_surface_impl = {
      6      .set_exclusive_edge = set_exclusive_edge,
      7  };
      8  
      9 +/* an exclusive surface has every key while it is mapped; the view a
     10 + * window asked for meanwhile gets them when it goes */
     11 +static struct {
     12 +	struct layer_surface *holder;
     13 +	struct compositor_view *wanted;
     14 +	struct wl_listener wanted_destroy;
     15 +} keys;
     16 +
     17 +static void
     18 +handle_wanted_destroy(struct wl_listener *listener, void *data)
     19 +{
     20 +	(void)data;
     21 +	wl_list_remove(&listener->link);
     22 +	keys.wanted = NULL;
     23 +}
     24 +
     25 +static void
     26 +want_keys(struct compositor_view *view)
     27 +{
     28 +	if (keys.wanted) {
     29 +		wl_list_remove(&keys.wanted_destroy.link);
     30 +	}
     31 +	keys.wanted = view;
     32 +	if (view) {
     33 +		keys.wanted_destroy.notify = handle_wanted_destroy;
     34 +		wl_signal_add(&view->destroy_signal, &keys.wanted_destroy);
     35 +	}
     36 +}
     37 +
     38 +static void
     39 +hold_keys(struct layer_surface *surface)
     40 +{
     41 +	struct compositor_view *focus = swc.seat->keyboard->focus.view;
     42 +
     43 +	/* a second exclusive surface over the first gives back what the first held */
     44 +	if (!keys.holder) {
     45 +		want_keys(focus);
     46 +	}
     47 +	keys.holder = surface;
     48 +	keyboard_set_focus(swc.seat->keyboard, surface->view);
     49 +}
     50 +
     51 +static void
     52 +release_keys(struct layer_surface *surface)
     53 +{
     54 +	struct compositor_view *view = keys.wanted;
     55 +
     56 +	if (keys.holder != surface) {
     57 +		return;
     58 +	}
     59 +	keys.holder = NULL;
     60 +	want_keys(NULL);
     61 +	if (swc.seat->keyboard->focus.view == surface->view) {
     62 +		keyboard_set_focus(swc.seat->keyboard, view);
     63 +	}
     64 +}
     65 +
     66 +bool
     67 +layer_shell_hold_keys(struct compositor_view *view)
     68 +{
     69 +	if (!keys.holder) {
     70 +		return false;
     71 +	}
     72 +	want_keys(view);
     73 +	return true;
     74 +}
     75 +
     76  static void
     77  handle_attach(struct view_handler *handler)
     78  {
     79 @@ -402,10 +469,11 @@ handle_attach(struct view_handler *handler)
     80  			/* on demand waits for a press, see layer_shell_pressed */
     81  			if (surface->current.keyboard_interactivity ==
     82  			    ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) {
     83 -				keyboard_set_focus(swc.seat->keyboard, surface->view);
     84 +				hold_keys(surface);
     85  			}
     86  		}
     87  	} else if (surface->mapped) {
     88 +		release_keys(surface);
     89  		compositor_view_hide(surface->view);
     90  	}
     91  
     92 @@ -535,6 +603,7 @@ destroy_layer_surface(struct wl_resource *resource)
     93  	wl_list_remove(&surface->surface_destroy_listener.link);
     94  	wl_list_remove(&surface->surface_commit_listener.link);
     95  	wl_list_remove(&surface->modifier.link);
     96 +	release_keys(surface);
     97  	compositor_view_destroy(surface->view);
     98  	if (had_screen) {
     99  		screen_update_usable_geometry(surface->screen);
    100 diff --git a/libswc/layer_shell.h b/libswc/layer_shell.h
    101 index 138db1a..5f3f53d 100644
    102 --- a/libswc/layer_shell.h
    103 +++ b/libswc/layer_shell.h
    104 @@ -1,6 +1,8 @@
    105  #ifndef SWC_LAYER_SHELL_H
    106  #define SWC_LAYER_SHELL_H
    107  
    108 +#include <stdbool.h>
    109 +
    110  struct wl_display;
    111  struct wl_global;
    112  
    113 @@ -18,4 +20,8 @@ struct compositor_view;
    114  void
    115  layer_shell_pressed(struct compositor_view *view);
    116  
    117 +/* true while an exclusive surface has the keys: view gets them after it */
    118 +bool
    119 +layer_shell_hold_keys(struct compositor_view *view);
    120 +
    121  #endif
    122 diff --git a/libswc/window.c b/libswc/window.c
    123 index 0efd250..2e1cfa8 100644
    124 --- a/libswc/window.c
    125 +++ b/libswc/window.c
    126 @@ -26,6 +26,7 @@
    127  #include "event.h"
    128  #include "internal.h"
    129  #include "keyboard.h"
    130 +#include "layer_shell.h"
    131  #include "seat.h"
    132  #include "surface.h"
    133  #include "swc.h"
    134 @@ -242,7 +243,7 @@ swc_window_focus(struct swc_window *base)
    135  	struct compositor_view *new = window ? window->view : NULL,
    136  	                       *old = swc.seat->keyboard->focus.view;
    137  
    138 -	if (new == old) {
    139 +	if (new == old || layer_shell_hold_keys(new)) {
    140  		return;
    141  	}
    142