@@ -83,8 +83,6 @@ static struct {
8383 int monitor_width ;
8484 int monitor_height ;
8585
86- gboolean capture_click_outside ;
87-
8886 int surface_width ;
8987 int surface_height ;
9088
@@ -102,6 +100,15 @@ static struct {
102100 .fullscreen = FALSE,
103101 .monitor_width = 0 ,
104102 .monitor_height = 0 ,
103+
104+ .surface_width = 0 ,
105+ .surface_height = 0 ,
106+
107+ .menu_width = 0 ,
108+ .menu_height = 0 ,
109+
110+ .menu_x = 0 ,
111+ .menu_y = 0 ,
105112};
106113
107114static void wayland_rofi_view_get_current_monitor (int * width , int * height ) {
@@ -152,52 +159,38 @@ static int rofi_get_offset_px(RofiViewState *state, RofiOrientation ori) {
152159 return distance_get_pixel (offset , ori );
153160}
154161
155- static void wayland_rofi_view_window_update_size (RofiViewState * state ) {
156- if (state == NULL ) {
157- return ;
158- }
159-
160- int offset_x = rofi_get_offset_px (state , ROFI_ORIENTATION_HORIZONTAL );
161- int offset_y = rofi_get_offset_px (state , ROFI_ORIENTATION_VERTICAL );
162-
163- /* The widget itself should always keep the visible menu size. */
164- widget_resize (WIDGET (state -> main_window ), state -> width , state -> height );
165-
166- /* Store visible menu size. */
167- WlState .menu_width = state -> width ;
168- WlState .menu_height = state -> height ;
169-
170- if (!WlState .capture_click_outside ) {
171- WlState .surface_width = state -> width ;
172- WlState .surface_height = state -> height ;
173- WlState .menu_x = 0 ;
174- WlState .menu_y = 0 ;
175-
176- g_debug ("normal mode: surface=%dx%d menu=%dx%d" , WlState .surface_width ,
177- WlState .surface_height , WlState .menu_width , WlState .menu_height );
162+ static void window_update_size_normal (RofiViewState * state , int offset_x ,
163+ int offset_y ) {
164+ WlState .surface_width = state -> width ;
165+ WlState .surface_height = state -> height ;
166+ WlState .menu_x = 0 ;
167+ WlState .menu_y = 0 ;
178168
179- display_set_surface_dimensions (state -> width , state -> height , offset_x ,
180- offset_y , rofi_get_location (state ));
181- rofi_view_pool_refresh ();
182- return ;
183- }
169+ /* Click-capture is limited to the current output. If the menu is larger than
170+ * the output and visually overflows onto another output, the overflowed area
171+ * will not be part of the capture surface and clicks there will not trigger
172+ * click-to-exit.
173+ */
174+ display_set_surface_dimensions (state -> width , state -> height , offset_x ,
175+ offset_y , rofi_get_location (state ));
176+ }
184177
185- /* Capture mode: surface becomes fullscreen, menu stays normal size. */
178+ static void window_update_size_with_outside_click (RofiViewState * state ,
179+ int offset_x , int offset_y ) {
186180 int screen_width = 0 ;
187181 int screen_height = 0 ;
182+ int loc = rofi_get_location (state );
183+
188184 wayland_rofi_view_get_current_monitor (& screen_width , & screen_height );
189185
190186 if (screen_width <= 0 || screen_height <= 0 ) {
191- /* Fallback so we do not create a broken surface. */
192187 screen_width = state -> width ;
193188 screen_height = state -> height ;
194189 }
195190
196191 WlState .surface_width = screen_width ;
197192 WlState .surface_height = screen_height ;
198193
199- int loc = rofi_get_location (state );
200-
201194 switch (loc ) {
202195 case WL_NORTH_WEST :
203196 WlState .menu_x = offset_x ;
@@ -244,26 +237,29 @@ static void wayland_rofi_view_window_update_size(RofiViewState *state) {
244237 break ;
245238 }
246239
247- /* Keep the actual layer surface fullscreen for outside-click capture. */
248240 display_set_surface_dimensions (WlState .surface_width , WlState .surface_height ,
249241 0 , 0 , WL_NORTH_WEST );
250-
251- g_debug ("capture mode: surface=%dx%d menu=%dx%d pos=(%d,%d) loc=%d "
252- "offsets=(%d,%d)" ,
253- WlState .surface_width , WlState .surface_height , WlState .menu_width ,
254- WlState .menu_height , WlState .menu_x , WlState .menu_y , loc , offset_x ,
255- offset_y );
256-
257- rofi_view_pool_refresh ();
258242}
259243
260- void wayland_rofi_view_cancel (RofiViewState * state ) {
244+ static void wayland_rofi_view_window_update_size (RofiViewState * state ) {
261245 if (state == NULL ) {
262246 return ;
263247 }
264248
265- state -> retv = MENU_CANCEL ;
266- state -> quit = TRUE;
249+ int offset_x = rofi_get_offset_px (state , ROFI_ORIENTATION_HORIZONTAL );
250+ int offset_y = rofi_get_offset_px (state , ROFI_ORIENTATION_VERTICAL );
251+
252+ widget_resize (WIDGET (state -> main_window ), state -> width , state -> height );
253+
254+ WlState .menu_width = state -> width ;
255+ WlState .menu_height = state -> height ;
256+
257+ if (config .click_to_exit ) {
258+ window_update_size_with_outside_click (state , offset_x , offset_y );
259+ } else {
260+ window_update_size_normal (state , offset_x , offset_y );
261+ }
262+ rofi_view_pool_refresh ();
267263}
268264
269265static void wayland_rofi_view_set_size (RofiViewState * state , gint width ,
@@ -335,15 +331,6 @@ static void wayland___create_window(MenuFlags menu_flags) {
335331
336332 WlState .flags = menu_flags ;
337333
338- /* Reset Wayland-local click-capture state for this view instance. */
339- WlState .capture_click_outside = config .click_to_exit ? TRUE : FALSE;
340- WlState .surface_width = 0 ;
341- WlState .surface_height = 0 ;
342- WlState .menu_width = 0 ;
343- WlState .menu_height = 0 ;
344- WlState .menu_x = 0 ;
345- WlState .menu_y = 0 ;
346-
347334 // Setup dpi
348335 PangoFontMap * font_map = pango_cairo_font_map_get_default ();
349336 if (config .dpi > 1 ) {
@@ -433,7 +420,7 @@ static void wayland_rofi_view_update(RofiViewState *state, gboolean qr) {
433420 int buffer_width = state -> width ;
434421 int buffer_height = state -> height ;
435422
436- if (WlState . capture_click_outside ) {
423+ if (config . click_to_exit ) {
437424 buffer_width = WlState .surface_width ;
438425 buffer_height = WlState .surface_height ;
439426 }
@@ -461,7 +448,7 @@ static void wayland_rofi_view_update(RofiViewState *state, gboolean qr) {
461448 // Always paint as overlay over the background.
462449 cairo_set_operator (d , CAIRO_OPERATOR_OVER );
463450
464- if (WlState . capture_click_outside ) {
451+ if (config . click_to_exit ) {
465452 g_debug ("draw capture mode: surface=%dx%d menu=%dx%d pos=(%d,%d)" ,
466453 WlState .surface_width , WlState .surface_height , WlState .menu_width ,
467454 WlState .menu_height , WlState .menu_x , WlState .menu_y );
@@ -481,12 +468,6 @@ static void wayland_rofi_view_update(RofiViewState *state, gboolean qr) {
481468 }
482469}
483470
484- /**
485- * @param state The Menu Handle
486- *
487- * Check if a finalize function is set, and if sets executes it.
488- */
489-
490471static void wayland_rofi_view_frame_callback (void ) {
491472 if (WlState .repaint_source == 0 ) {
492473 WlState .repaint_source = g_idle_add_full (
@@ -539,14 +520,6 @@ static void wayland_rofi_view_cleanup(void) {
539520 WlState .repaint_source = 0 ;
540521 }
541522
542- WlState .capture_click_outside = FALSE;
543- WlState .surface_width = 0 ;
544- WlState .surface_height = 0 ;
545- WlState .menu_width = 0 ;
546- WlState .menu_height = 0 ;
547- WlState .menu_x = 0 ;
548- WlState .menu_y = 0 ;
549-
550523 input_history_save ();
551524}
552525
@@ -564,7 +537,7 @@ static void wayland_rofi_view_pool_refresh(void) {
564537}
565538
566539gboolean wayland_rofi_view_capture_click_outside_enabled (void ) {
567- return WlState . capture_click_outside ;
540+ return config . click_to_exit ;
568541}
569542
570543void wayland_rofi_view_get_menu_rect (int * x , int * y , int * w , int * h ) {
0 commit comments