diff options
-rw-r--r-- | sway/commands/resize.c | 28 | ||||
-rw-r--r-- | swayidle/main.c | 78 |
2 files changed, 73 insertions, 33 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index a90d578e..cf5dea02 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -512,34 +512,42 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, | |||
512 | calculate_constraints(&min_width, &max_width, &min_height, &max_height); | 512 | calculate_constraints(&min_width, &max_width, &min_height, &max_height); |
513 | 513 | ||
514 | if (width->amount) { | 514 | if (width->amount) { |
515 | if (width->unit == RESIZE_UNIT_PPT || | 515 | switch (width->unit) { |
516 | width->unit == RESIZE_UNIT_DEFAULT) { | 516 | case RESIZE_UNIT_PPT: |
517 | // Convert to px | 517 | // Convert to px |
518 | width->amount = con->workspace->width * width->amount / 100; | 518 | width->amount = con->workspace->width * width->amount / 100; |
519 | width->unit = RESIZE_UNIT_PX; | 519 | width->unit = RESIZE_UNIT_PX; |
520 | } | 520 | // Falls through |
521 | if (width->unit == RESIZE_UNIT_PX) { | 521 | case RESIZE_UNIT_PX: |
522 | case RESIZE_UNIT_DEFAULT: | ||
522 | width->amount = fmax(min_width, fmin(width->amount, max_width)); | 523 | width->amount = fmax(min_width, fmin(width->amount, max_width)); |
523 | grow_width = width->amount - con->width; | 524 | grow_width = width->amount - con->width; |
524 | |||
525 | con->x -= grow_width / 2; | 525 | con->x -= grow_width / 2; |
526 | con->width = width->amount; | 526 | con->width = width->amount; |
527 | break; | ||
528 | case RESIZE_UNIT_INVALID: | ||
529 | sway_assert(false, "invalid width unit"); | ||
530 | break; | ||
527 | } | 531 | } |
528 | } | 532 | } |
529 | 533 | ||
530 | if (height->amount) { | 534 | if (height->amount) { |
531 | if (height->unit == RESIZE_UNIT_PPT || | 535 | switch (height->unit) { |
532 | height->unit == RESIZE_UNIT_DEFAULT) { | 536 | case RESIZE_UNIT_PPT: |
533 | // Convert to px | 537 | // Convert to px |
534 | height->amount = con->workspace->height * height->amount / 100; | 538 | height->amount = con->workspace->height * height->amount / 100; |
535 | height->unit = RESIZE_UNIT_PX; | 539 | height->unit = RESIZE_UNIT_PX; |
536 | } | 540 | // Falls through |
537 | if (height->unit == RESIZE_UNIT_PX) { | 541 | case RESIZE_UNIT_PX: |
542 | case RESIZE_UNIT_DEFAULT: | ||
538 | height->amount = fmax(min_height, fmin(height->amount, max_height)); | 543 | height->amount = fmax(min_height, fmin(height->amount, max_height)); |
539 | grow_height = height->amount - con->height; | 544 | grow_height = height->amount - con->height; |
540 | |||
541 | con->y -= grow_height / 2; | 545 | con->y -= grow_height / 2; |
542 | con->height = height->amount; | 546 | con->height = height->amount; |
547 | break; | ||
548 | case RESIZE_UNIT_INVALID: | ||
549 | sway_assert(false, "invalid height unit"); | ||
550 | break; | ||
543 | } | 551 | } |
544 | } | 552 | } |
545 | 553 | ||
diff --git a/swayidle/main.c b/swayidle/main.c index 2b185949..89ccf671 100644 --- a/swayidle/main.c +++ b/swayidle/main.c | |||
@@ -43,6 +43,12 @@ struct swayidle_timeout_cmd { | |||
43 | char *resume_cmd; | 43 | char *resume_cmd; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | void sway_terminate(int exit_code) { | ||
47 | wl_display_disconnect(state.display); | ||
48 | wl_event_loop_destroy(state.event_loop); | ||
49 | exit(exit_code); | ||
50 | } | ||
51 | |||
46 | static void cmd_exec(char *param) { | 52 | static void cmd_exec(char *param) { |
47 | wlr_log(WLR_DEBUG, "Cmd exec %s", param); | 53 | wlr_log(WLR_DEBUG, "Cmd exec %s", param); |
48 | pid_t pid = fork(); | 54 | pid_t pid = fork(); |
@@ -81,16 +87,16 @@ static int release_lock(void *data) { | |||
81 | } | 87 | } |
82 | 88 | ||
83 | static void acquire_sleep_lock(void) { | 89 | static void acquire_sleep_lock(void) { |
84 | sd_bus_message *msg; | 90 | sd_bus_message *msg = NULL; |
85 | sd_bus_error error; | 91 | sd_bus_error error = SD_BUS_ERROR_NULL; |
86 | int ret = sd_bus_call_method(bus, "org.freedesktop.login1", | 92 | int ret = sd_bus_call_method(bus, "org.freedesktop.login1", |
87 | "/org/freedesktop/login1", | 93 | "/org/freedesktop/login1", |
88 | "org.freedesktop.login1.Manager", "Inhibit", | 94 | "org.freedesktop.login1.Manager", "Inhibit", |
89 | &error, &msg, "ssss", "sleep", "swayidle", | 95 | &error, &msg, "ssss", "sleep", "swayidle", |
90 | "Setup Up Lock Screen", "delay"); | 96 | "Setup Up Lock Screen", "delay"); |
91 | if (ret < 0) { | 97 | if (ret < 0) { |
92 | wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s", | 98 | wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s", error.message); |
93 | strerror(-ret)); | 99 | sd_bus_error_free(&error); |
94 | return; | 100 | return; |
95 | } | 101 | } |
96 | 102 | ||
@@ -98,10 +104,11 @@ static void acquire_sleep_lock(void) { | |||
98 | if (ret < 0) { | 104 | if (ret < 0) { |
99 | wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", | 105 | wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", |
100 | strerror(-ret)); | 106 | strerror(-ret)); |
101 | return; | 107 | } else { |
108 | wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd); | ||
102 | } | 109 | } |
103 | 110 | sd_bus_error_free(&error); | |
104 | wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd); | 111 | sd_bus_message_unref(msg); |
105 | } | 112 | } |
106 | 113 | ||
107 | static int prepare_for_sleep(sd_bus_message *msg, void *userdata, | 114 | static int prepare_for_sleep(sd_bus_message *msg, void *userdata, |
@@ -137,10 +144,28 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata, | |||
137 | 144 | ||
138 | static int dbus_event(int fd, uint32_t mask, void *data) { | 145 | static int dbus_event(int fd, uint32_t mask, void *data) { |
139 | sd_bus *bus = data; | 146 | sd_bus *bus = data; |
140 | while (sd_bus_process(bus, NULL) > 0) { | 147 | |
141 | // Do nothing. | 148 | if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { |
149 | sway_terminate(0); | ||
150 | } | ||
151 | |||
152 | int count = 0; | ||
153 | if (mask & WL_EVENT_READABLE) { | ||
154 | count = sd_bus_process(bus, NULL); | ||
155 | } | ||
156 | if (mask & WL_EVENT_WRITABLE) { | ||
157 | sd_bus_flush(bus); | ||
142 | } | 158 | } |
143 | return 1; | 159 | if (mask == 0) { |
160 | sd_bus_flush(bus); | ||
161 | } | ||
162 | |||
163 | if (count < 0) { | ||
164 | wlr_log_errno(WLR_ERROR, "sd_bus_process failed, exiting"); | ||
165 | sway_terminate(0); | ||
166 | } | ||
167 | |||
168 | return count; | ||
144 | } | 169 | } |
145 | 170 | ||
146 | static void setup_sleep_listener(void) { | 171 | static void setup_sleep_listener(void) { |
@@ -166,8 +191,10 @@ static void setup_sleep_listener(void) { | |||
166 | } | 191 | } |
167 | acquire_sleep_lock(); | 192 | acquire_sleep_lock(); |
168 | 193 | ||
169 | wl_event_loop_add_fd(state.event_loop, sd_bus_get_fd(bus), | 194 | struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, |
170 | WL_EVENT_READABLE, dbus_event, bus); | 195 | sd_bus_get_fd(bus), WL_EVENT_READABLE | WL_EVENT_WRITABLE, |
196 | dbus_event, bus); | ||
197 | wl_event_source_check(source); | ||
171 | } | 198 | } |
172 | #endif | 199 | #endif |
173 | 200 | ||
@@ -339,12 +366,6 @@ static int parse_args(int argc, char *argv[]) { | |||
339 | return 0; | 366 | return 0; |
340 | } | 367 | } |
341 | 368 | ||
342 | void sway_terminate(int exit_code) { | ||
343 | wl_display_disconnect(state.display); | ||
344 | wl_event_loop_destroy(state.event_loop); | ||
345 | exit(exit_code); | ||
346 | } | ||
347 | |||
348 | static void register_zero_idle_timeout(void *item) { | 369 | static void register_zero_idle_timeout(void *item) { |
349 | struct swayidle_timeout_cmd *cmd = item; | 370 | struct swayidle_timeout_cmd *cmd = item; |
350 | register_timeout(cmd, 0); | 371 | register_timeout(cmd, 0); |
@@ -365,15 +386,26 @@ static int handle_signal(int sig, void *data) { | |||
365 | } | 386 | } |
366 | 387 | ||
367 | static int display_event(int fd, uint32_t mask, void *data) { | 388 | static int display_event(int fd, uint32_t mask, void *data) { |
368 | if (mask & WL_EVENT_HANGUP) { | 389 | if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { |
369 | sway_terminate(0); | 390 | sway_terminate(0); |
370 | } | 391 | } |
371 | if (wl_display_dispatch(state.display) < 0) { | 392 | |
393 | int count = 0; | ||
394 | if (mask & WL_EVENT_READABLE) { | ||
395 | count = wl_display_dispatch(state.display); | ||
396 | } | ||
397 | if (mask & WL_EVENT_WRITABLE) { | ||
398 | wl_display_flush(state.display); | ||
399 | } | ||
400 | if (mask == 0) { | ||
401 | count = wl_display_dispatch_pending(state.display); | ||
402 | wl_display_flush(state.display); | ||
403 | } | ||
404 | if (count < 0) { | ||
372 | wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting"); | 405 | wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting"); |
373 | sway_terminate(0); | 406 | sway_terminate(0); |
374 | } | 407 | } |
375 | wl_display_flush(state.display); | 408 | return count; |
376 | return 0; | ||
377 | } | 409 | } |
378 | 410 | ||
379 | static void register_idle_timeout(void *item) { | 411 | static void register_idle_timeout(void *item) { |
@@ -430,7 +462,7 @@ int main(int argc, char *argv[]) { | |||
430 | wl_display_roundtrip(state.display); | 462 | wl_display_roundtrip(state.display); |
431 | 463 | ||
432 | struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, | 464 | struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, |
433 | wl_display_get_fd(state.display), WL_EVENT_READABLE, | 465 | wl_display_get_fd(state.display), WL_EVENT_READABLE | WL_EVENT_WRITABLE, |
434 | display_event, NULL); | 466 | display_event, NULL); |
435 | wl_event_source_check(source); | 467 | wl_event_source_check(source); |
436 | 468 | ||