@@ -85,12 +85,34 @@ static struct zwlr_layer_surface_v1_listener layer_surface_listener = {
85
85
.closed = layer_surface_closed ,
86
86
};
87
87
88
+ static void surface_enter (void * data , struct wl_surface * surface ,
89
+ struct wl_output * output ) {
90
+ struct swaynag * swaynag = data ;
91
+ struct swaynag_output * swaynag_output ;
92
+ wl_list_for_each (swaynag_output , & swaynag -> outputs , link ) {
93
+ if (swaynag_output -> wl_output == output ) {
94
+ wlr_log (WLR_DEBUG , "Surface enter on output %s" ,
95
+ swaynag_output -> name );
96
+ swaynag -> output = swaynag_output ;
97
+ swaynag -> scale = swaynag -> output -> scale ;
98
+ render_frame (swaynag );
99
+ break ;
100
+ }
101
+ };
102
+ }
103
+
104
+ static struct wl_surface_listener surface_listener = {
105
+ .enter = surface_enter ,
106
+ .leave = nop ,
107
+ };
108
+
88
109
static void wl_pointer_enter (void * data , struct wl_pointer * wl_pointer ,
89
110
uint32_t serial , struct wl_surface * surface ,
90
111
wl_fixed_t surface_x , wl_fixed_t surface_y ) {
91
112
struct swaynag * swaynag = data ;
92
113
struct swaynag_pointer * pointer = & swaynag -> pointer ;
93
- wl_surface_set_buffer_scale (pointer -> cursor_surface , swaynag -> scale );
114
+ wl_surface_set_buffer_scale (pointer -> cursor_surface ,
115
+ swaynag -> scale );
94
116
wl_surface_attach (pointer -> cursor_surface ,
95
117
wl_cursor_image_get_buffer (pointer -> cursor_image ), 0 , 0 );
96
118
wl_pointer_set_cursor (wl_pointer , serial , pointer -> cursor_surface ,
@@ -141,7 +163,8 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
141
163
}
142
164
143
165
struct swaynag_button button_down = swaynag -> details .button_down ;
144
- int bot = swaynag -> details .total_lines - swaynag -> details .visible_lines ;
166
+ int bot = swaynag -> details .total_lines ;
167
+ bot -= swaynag -> details .visible_lines ;
145
168
if (x >= button_down .x
146
169
&& y >= button_down .y
147
170
&& x < button_down .x + button_down .width
@@ -206,9 +229,12 @@ const struct wl_seat_listener seat_listener = {
206
229
207
230
static void output_scale (void * data , struct wl_output * output ,
208
231
int32_t factor ) {
209
- struct swaynag * swaynag = data ;
210
- swaynag -> scale = factor ;
211
- render_frame (swaynag );
232
+ struct swaynag_output * swaynag_output = data ;
233
+ swaynag_output -> scale = factor ;
234
+ if (swaynag_output -> swaynag -> output == swaynag_output ) {
235
+ swaynag_output -> swaynag -> scale = swaynag_output -> scale ;
236
+ render_frame (swaynag_output -> swaynag );
237
+ }
212
238
}
213
239
214
240
static struct wl_output_listener output_listener = {
@@ -218,33 +244,19 @@ static struct wl_output_listener output_listener = {
218
244
.scale = output_scale ,
219
245
};
220
246
221
- struct output_state {
222
- struct wl_output * wl_output ;
223
- uint32_t wl_name ;
224
- struct zxdg_output_v1 * xdg_output ;
225
- struct swaynag * swaynag ;
226
- };
227
-
228
247
static void xdg_output_handle_name (void * data ,
229
248
struct zxdg_output_v1 * xdg_output , const char * name ) {
230
- struct output_state * state = data ;
231
- char * outname = state -> swaynag -> output . name ;
249
+ struct swaynag_output * swaynag_output = data ;
250
+ char * outname = swaynag_output -> swaynag -> type -> output ;
232
251
wlr_log (WLR_DEBUG , "Checking against output %s for %s" , name , outname );
233
- if (!state -> swaynag -> output . wl_output && outname && name
252
+ if (!swaynag_output -> swaynag -> output && outname && name
234
253
&& strcmp (outname , name ) == 0 ) {
235
254
wlr_log (WLR_DEBUG , "Using output %s" , name );
236
- state -> swaynag -> output .wl_output = state -> wl_output ;
237
- state -> swaynag -> output .wl_name = state -> wl_name ;
238
- wl_output_add_listener (state -> swaynag -> output .wl_output ,
239
- & output_listener , state -> swaynag );
240
- wl_display_roundtrip (state -> swaynag -> display );
241
- zxdg_output_v1_destroy (state -> xdg_output );
242
- } else {
243
- zxdg_output_v1_destroy (state -> xdg_output );
244
- wl_output_destroy (state -> wl_output );
255
+ swaynag_output -> swaynag -> output = swaynag_output ;
245
256
}
246
- state -> swaynag -> querying_outputs -- ;
247
- free (state );
257
+ swaynag_output -> name = strdup (name );
258
+ zxdg_output_v1_destroy (xdg_output );
259
+ swaynag_output -> swaynag -> querying_outputs -- ;
248
260
}
249
261
250
262
static struct zxdg_output_v1_listener xdg_output_listener = {
@@ -267,18 +279,24 @@ static void handle_global(void *data, struct wl_registry *registry,
267
279
} else if (strcmp (interface , wl_shm_interface .name ) == 0 ) {
268
280
swaynag -> shm = wl_registry_bind (registry , name , & wl_shm_interface , 1 );
269
281
} else if (strcmp (interface , wl_output_interface .name ) == 0 ) {
270
- if (!swaynag -> output . wl_output && swaynag -> xdg_output_manager ) {
282
+ if (!swaynag -> output && swaynag -> xdg_output_manager ) {
271
283
swaynag -> querying_outputs ++ ;
272
- struct output_state * state =
273
- calloc (1 , sizeof (struct output_state ));
274
- state -> swaynag = swaynag ;
275
- state -> wl_output = wl_registry_bind (registry , name ,
284
+ struct swaynag_output * output =
285
+ calloc (1 , sizeof (struct swaynag_output ));
286
+ output -> wl_output = wl_registry_bind (registry , name ,
276
287
& wl_output_interface , 3 );
277
- state -> wl_name = name ;
278
- state -> xdg_output = zxdg_output_manager_v1_get_xdg_output (
279
- swaynag -> xdg_output_manager , state -> wl_output );
280
- zxdg_output_v1_add_listener (state -> xdg_output ,
281
- & xdg_output_listener , state );
288
+ output -> wl_name = name ;
289
+ output -> scale = 1 ;
290
+ output -> swaynag = swaynag ;
291
+ wl_list_insert (& swaynag -> outputs , & output -> link );
292
+ wl_output_add_listener (output -> wl_output ,
293
+ & output_listener , output );
294
+
295
+ struct zxdg_output_v1 * xdg_output ;
296
+ xdg_output = zxdg_output_manager_v1_get_xdg_output (
297
+ swaynag -> xdg_output_manager , output -> wl_output );
298
+ zxdg_output_v1_add_listener (xdg_output ,
299
+ & xdg_output_listener , output );
282
300
}
283
301
} else if (strcmp (interface , zwlr_layer_shell_v1_interface .name ) == 0 ) {
284
302
swaynag -> layer_shell = wl_registry_bind (
@@ -294,7 +312,7 @@ static void handle_global(void *data, struct wl_registry *registry,
294
312
static void handle_global_remove (void * data , struct wl_registry * registry ,
295
313
uint32_t name ) {
296
314
struct swaynag * swaynag = data ;
297
- if (swaynag -> output . wl_name == name ) {
315
+ if (swaynag -> output -> wl_name == name ) {
298
316
swaynag -> run_display = false;
299
317
}
300
318
}
@@ -309,6 +327,7 @@ void swaynag_setup(struct swaynag *swaynag) {
309
327
assert (swaynag -> display );
310
328
311
329
swaynag -> scale = 1 ;
330
+ wl_list_init (& swaynag -> outputs );
312
331
313
332
struct wl_registry * registry = wl_display_get_registry (swaynag -> display );
314
333
wl_registry_add_listener (registry , & registry_listener , swaynag );
@@ -319,16 +338,16 @@ void swaynag_setup(struct swaynag *swaynag) {
319
338
wl_display_roundtrip (swaynag -> display );
320
339
}
321
340
322
- if (!swaynag -> output . wl_output && swaynag -> output . name ) {
323
- wlr_log (WLR_ERROR , "Output '%s' not found" , swaynag -> output . name );
341
+ if (!swaynag -> output && swaynag -> type -> output ) {
342
+ wlr_log (WLR_ERROR , "Output '%s' not found" , swaynag -> type -> output );
324
343
swaynag_destroy (swaynag );
325
344
exit (EXIT_FAILURE );
326
345
}
327
346
328
347
struct swaynag_pointer * pointer = & swaynag -> pointer ;
329
- int scale = swaynag -> scale < 1 ? 1 : swaynag -> scale ;
330
- pointer -> cursor_theme = wl_cursor_theme_load (
331
- NULL , 24 * scale , swaynag -> shm );
348
+ int scale = swaynag -> output ? swaynag -> scale : 1 ;
349
+ pointer -> cursor_theme = wl_cursor_theme_load (NULL , 24 * scale ,
350
+ swaynag -> shm );
332
351
assert (pointer -> cursor_theme );
333
352
struct wl_cursor * cursor =
334
353
wl_cursor_theme_get_cursor (pointer -> cursor_theme , "left_ptr" );
@@ -339,8 +358,11 @@ void swaynag_setup(struct swaynag *swaynag) {
339
358
340
359
swaynag -> surface = wl_compositor_create_surface (swaynag -> compositor );
341
360
assert (swaynag -> surface );
361
+ wl_surface_add_listener (swaynag -> surface , & surface_listener , swaynag );
362
+
342
363
swaynag -> layer_surface = zwlr_layer_shell_v1_get_layer_surface (
343
- swaynag -> layer_shell , swaynag -> surface , swaynag -> output .wl_output ,
364
+ swaynag -> layer_shell , swaynag -> surface ,
365
+ swaynag -> output ? swaynag -> output -> wl_output : NULL ,
344
366
ZWLR_LAYER_SHELL_V1_LAYER_TOP , "swaynag" );
345
367
assert (swaynag -> layer_surface );
346
368
zwlr_layer_surface_v1_add_listener (swaynag -> layer_surface ,
@@ -388,10 +410,6 @@ void swaynag_destroy(struct swaynag *swaynag) {
388
410
wl_surface_destroy (swaynag -> surface );
389
411
}
390
412
391
- if (swaynag -> output .wl_output ) {
392
- wl_output_destroy (swaynag -> output .wl_output );
393
- }
394
-
395
413
if (& swaynag -> buffers [0 ]) {
396
414
destroy_buffer (& swaynag -> buffers [0 ]);
397
415
}
@@ -400,6 +418,14 @@ void swaynag_destroy(struct swaynag *swaynag) {
400
418
destroy_buffer (& swaynag -> buffers [1 ]);
401
419
}
402
420
421
+ struct swaynag_output * output , * temp ;
422
+ wl_list_for_each_safe (output , temp , & swaynag -> outputs , link ) {
423
+ wl_output_destroy (output -> wl_output );
424
+ free (output -> name );
425
+ wl_list_remove (& output -> link );
426
+ free (output );
427
+ };
428
+
403
429
if (swaynag -> compositor ) {
404
430
wl_compositor_destroy (swaynag -> compositor );
405
431
}
0 commit comments