diff options
author | emersion <contact@emersion.fr> | 2018-05-18 21:57:58 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-05-18 21:57:58 +0100 |
commit | b7ab7c0e66433aacaaccce08d6e40304e6f6593c (patch) | |
tree | cf888c149521a7c2f5f705a361adaed98710a5b7 /swaylock/main.c | |
parent | e4dbafe4d84c8666a2f658fd195a47d13ae42378 (diff) |
Fix output hotplugging
Diffstat (limited to 'swaylock/main.c')
-rw-r--r-- | swaylock/main.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 08a8691e..9da99f97 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -75,6 +75,33 @@ static void destroy_surface(struct swaylock_surface *surface) { free(surface); } +static const struct zwlr_layer_surface_v1_listener layer_surface_listener; + +static void create_layer_surface(struct swaylock_surface *surface) { + struct swaylock_state *state = surface->state; + + surface->surface = wl_compositor_create_surface(state->compositor); + assert(surface->surface); + + surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( + state->layer_shell, surface->surface, surface->output, + ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "lockscreen"); + assert(surface->layer_surface); + + zwlr_layer_surface_v1_set_size(surface->layer_surface, 0, 0); + zwlr_layer_surface_v1_set_anchor(surface->layer_surface, + ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); + zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, -1); + zwlr_layer_surface_v1_set_keyboard_interactivity( + surface->layer_surface, true); + zwlr_layer_surface_v1_add_listener(surface->layer_surface, + &layer_surface_listener, surface); + wl_surface_commit(surface->surface); +} + static void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *layer_surface, uint32_t serial, uint32_t width, uint32_t height) { @@ -152,8 +179,14 @@ static void handle_global(void *data, struct wl_registry *registry, surface->output = wl_registry_bind(registry, name, &wl_output_interface, 3); surface->output_global_name = name; + surface->image = state->background_image; wl_output_add_listener(surface->output, &output_listener, surface); wl_list_insert(&state->surfaces, &surface->link); + + if (state->run_display) { + create_layer_surface(surface); + wl_display_roundtrip(state->display); + } } } @@ -190,7 +223,7 @@ int main(int argc, char **argv) { {0, 0, 0, 0} }; - const char *usage = + const char usage[] = "Usage: swaylock [options...]\n" "\n" " -h, --help Show help message and quit.\n" @@ -203,13 +236,12 @@ int main(int argc, char **argv) { " -f, --daemonize Detach from the controlling terminal.\n" " --socket <socket> Use the specified socket.\n"; - struct swaylock_args args = { + state.args = (struct swaylock_args){ .mode = BACKGROUND_MODE_SOLID_COLOR, .color = 0xFFFFFFFF, .show_indicator = true, }; - cairo_surface_t *background_image = NULL; - state.args = args; + wlr_log_init(L_DEBUG, NULL); int c; @@ -227,8 +259,8 @@ int main(int argc, char **argv) { } case 'i': // TODO: Multiple background images (bleh) - background_image = load_background_image(optarg); - if (!background_image) { + state.background_image = load_background_image(optarg); + if (!state.background_image) { return 1; } state.args.mode = BACKGROUND_MODE_FILL; @@ -288,34 +320,13 @@ int main(int argc, char **argv) { return 0; } + zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager); + struct swaylock_surface *surface; wl_list_for_each(surface, &state.surfaces, link) { - surface->image = background_image; - - surface->surface = wl_compositor_create_surface(state.compositor); - assert(surface->surface); - - surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( - state.layer_shell, surface->surface, surface->output, - ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "lockscreen"); - assert(surface->layer_surface); - - zwlr_layer_surface_v1_set_size(surface->layer_surface, 0, 0); - zwlr_layer_surface_v1_set_anchor(surface->layer_surface, - ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | - ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | - ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | - ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); - zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, -1); - zwlr_layer_surface_v1_set_keyboard_interactivity( - surface->layer_surface, true); - zwlr_layer_surface_v1_add_listener(surface->layer_surface, - &layer_surface_listener, surface); - wl_surface_commit(surface->surface); - wl_display_roundtrip(state.display); + create_layer_surface(surface); } - - zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager); + wl_display_roundtrip(state.display); state.run_display = true; while (wl_display_dispatch(state.display) != -1 && state.run_display) { |