diff options
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) { | |||
75 | free(surface); | 75 | free(surface); |
76 | } | 76 | } |
77 | 77 | ||
78 | static const struct zwlr_layer_surface_v1_listener layer_surface_listener; | ||
79 | |||
80 | static void create_layer_surface(struct swaylock_surface *surface) { | ||
81 | struct swaylock_state *state = surface->state; | ||
82 | |||
83 | surface->surface = wl_compositor_create_surface(state->compositor); | ||
84 | assert(surface->surface); | ||
85 | |||
86 | surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | ||
87 | state->layer_shell, surface->surface, surface->output, | ||
88 | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "lockscreen"); | ||
89 | assert(surface->layer_surface); | ||
90 | |||
91 | zwlr_layer_surface_v1_set_size(surface->layer_surface, 0, 0); | ||
92 | zwlr_layer_surface_v1_set_anchor(surface->layer_surface, | ||
93 | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | | ||
94 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | | ||
95 | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | | ||
96 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); | ||
97 | zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, -1); | ||
98 | zwlr_layer_surface_v1_set_keyboard_interactivity( | ||
99 | surface->layer_surface, true); | ||
100 | zwlr_layer_surface_v1_add_listener(surface->layer_surface, | ||
101 | &layer_surface_listener, surface); | ||
102 | wl_surface_commit(surface->surface); | ||
103 | } | ||
104 | |||
78 | static void layer_surface_configure(void *data, | 105 | static void layer_surface_configure(void *data, |
79 | struct zwlr_layer_surface_v1 *layer_surface, | 106 | struct zwlr_layer_surface_v1 *layer_surface, |
80 | uint32_t serial, uint32_t width, uint32_t height) { | 107 | uint32_t serial, uint32_t width, uint32_t height) { |
@@ -152,8 +179,14 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
152 | surface->output = wl_registry_bind(registry, name, | 179 | surface->output = wl_registry_bind(registry, name, |
153 | &wl_output_interface, 3); | 180 | &wl_output_interface, 3); |
154 | surface->output_global_name = name; | 181 | surface->output_global_name = name; |
182 | surface->image = state->background_image; | ||
155 | wl_output_add_listener(surface->output, &output_listener, surface); | 183 | wl_output_add_listener(surface->output, &output_listener, surface); |
156 | wl_list_insert(&state->surfaces, &surface->link); | 184 | wl_list_insert(&state->surfaces, &surface->link); |
185 | |||
186 | if (state->run_display) { | ||
187 | create_layer_surface(surface); | ||
188 | wl_display_roundtrip(state->display); | ||
189 | } | ||
157 | } | 190 | } |
158 | } | 191 | } |
159 | 192 | ||
@@ -190,7 +223,7 @@ int main(int argc, char **argv) { | |||
190 | {0, 0, 0, 0} | 223 | {0, 0, 0, 0} |
191 | }; | 224 | }; |
192 | 225 | ||
193 | const char *usage = | 226 | const char usage[] = |
194 | "Usage: swaylock [options...]\n" | 227 | "Usage: swaylock [options...]\n" |
195 | "\n" | 228 | "\n" |
196 | " -h, --help Show help message and quit.\n" | 229 | " -h, --help Show help message and quit.\n" |
@@ -203,13 +236,12 @@ int main(int argc, char **argv) { | |||
203 | " -f, --daemonize Detach from the controlling terminal.\n" | 236 | " -f, --daemonize Detach from the controlling terminal.\n" |
204 | " --socket <socket> Use the specified socket.\n"; | 237 | " --socket <socket> Use the specified socket.\n"; |
205 | 238 | ||
206 | struct swaylock_args args = { | 239 | state.args = (struct swaylock_args){ |
207 | .mode = BACKGROUND_MODE_SOLID_COLOR, | 240 | .mode = BACKGROUND_MODE_SOLID_COLOR, |
208 | .color = 0xFFFFFFFF, | 241 | .color = 0xFFFFFFFF, |
209 | .show_indicator = true, | 242 | .show_indicator = true, |
210 | }; | 243 | }; |
211 | cairo_surface_t *background_image = NULL; | 244 | |
212 | state.args = args; | ||
213 | wlr_log_init(L_DEBUG, NULL); | 245 | wlr_log_init(L_DEBUG, NULL); |
214 | 246 | ||
215 | int c; | 247 | int c; |
@@ -227,8 +259,8 @@ int main(int argc, char **argv) { | |||
227 | } | 259 | } |
228 | case 'i': | 260 | case 'i': |
229 | // TODO: Multiple background images (bleh) | 261 | // TODO: Multiple background images (bleh) |
230 | background_image = load_background_image(optarg); | 262 | state.background_image = load_background_image(optarg); |
231 | if (!background_image) { | 263 | if (!state.background_image) { |
232 | return 1; | 264 | return 1; |
233 | } | 265 | } |
234 | state.args.mode = BACKGROUND_MODE_FILL; | 266 | state.args.mode = BACKGROUND_MODE_FILL; |
@@ -288,34 +320,13 @@ int main(int argc, char **argv) { | |||
288 | return 0; | 320 | return 0; |
289 | } | 321 | } |
290 | 322 | ||
323 | zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager); | ||
324 | |||
291 | struct swaylock_surface *surface; | 325 | struct swaylock_surface *surface; |
292 | wl_list_for_each(surface, &state.surfaces, link) { | 326 | wl_list_for_each(surface, &state.surfaces, link) { |
293 | surface->image = background_image; | 327 | create_layer_surface(surface); |
294 | |||
295 | surface->surface = wl_compositor_create_surface(state.compositor); | ||
296 | assert(surface->surface); | ||
297 | |||
298 | surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | ||
299 | state.layer_shell, surface->surface, surface->output, | ||
300 | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "lockscreen"); | ||
301 | assert(surface->layer_surface); | ||
302 | |||
303 | zwlr_layer_surface_v1_set_size(surface->layer_surface, 0, 0); | ||
304 | zwlr_layer_surface_v1_set_anchor(surface->layer_surface, | ||
305 | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | | ||
306 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | | ||
307 | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | | ||
308 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); | ||
309 | zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, -1); | ||
310 | zwlr_layer_surface_v1_set_keyboard_interactivity( | ||
311 | surface->layer_surface, true); | ||
312 | zwlr_layer_surface_v1_add_listener(surface->layer_surface, | ||
313 | &layer_surface_listener, surface); | ||
314 | wl_surface_commit(surface->surface); | ||
315 | wl_display_roundtrip(state.display); | ||
316 | } | 328 | } |
317 | 329 | wl_display_roundtrip(state.display); | |
318 | zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager); | ||
319 | 330 | ||
320 | state.run_display = true; | 331 | state.run_display = true; |
321 | while (wl_display_dispatch(state.display) != -1 && state.run_display) { | 332 | while (wl_display_dispatch(state.display) != -1 && state.run_display) { |