mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 00:16:22 +01:00
swayidle: fix dbus_event not to block
This commit is contained in:
parent
41ffb5b4d5
commit
9b88ee0143
1 changed files with 31 additions and 11 deletions
|
@ -43,6 +43,12 @@ struct swayidle_timeout_cmd {
|
||||||
char *resume_cmd;
|
char *resume_cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void sway_terminate(int exit_code) {
|
||||||
|
wl_display_disconnect(state.display);
|
||||||
|
wl_event_loop_destroy(state.event_loop);
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
static void cmd_exec(char *param) {
|
static void cmd_exec(char *param) {
|
||||||
wlr_log(WLR_DEBUG, "Cmd exec %s", param);
|
wlr_log(WLR_DEBUG, "Cmd exec %s", param);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
@ -138,10 +144,28 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
|
||||||
|
|
||||||
static int dbus_event(int fd, uint32_t mask, void *data) {
|
static int dbus_event(int fd, uint32_t mask, void *data) {
|
||||||
sd_bus *bus = data;
|
sd_bus *bus = data;
|
||||||
while (sd_bus_process(bus, NULL) > 0) {
|
|
||||||
// Do nothing.
|
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
|
||||||
|
sway_terminate(0);
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
|
int count = 0;
|
||||||
|
if (mask & WL_EVENT_READABLE) {
|
||||||
|
count = sd_bus_process(bus, NULL);
|
||||||
|
}
|
||||||
|
if (mask & WL_EVENT_WRITABLE) {
|
||||||
|
sd_bus_flush(bus);
|
||||||
|
}
|
||||||
|
if (mask == 0) {
|
||||||
|
sd_bus_flush(bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count < 0) {
|
||||||
|
wlr_log_errno(WLR_ERROR, "sd_bus_process failed, exiting");
|
||||||
|
sway_terminate(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_sleep_listener(void) {
|
static void setup_sleep_listener(void) {
|
||||||
|
@ -167,8 +191,10 @@ static void setup_sleep_listener(void) {
|
||||||
}
|
}
|
||||||
acquire_sleep_lock();
|
acquire_sleep_lock();
|
||||||
|
|
||||||
wl_event_loop_add_fd(state.event_loop, sd_bus_get_fd(bus),
|
struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop,
|
||||||
WL_EVENT_READABLE, dbus_event, bus);
|
sd_bus_get_fd(bus), WL_EVENT_READABLE | WL_EVENT_WRITABLE,
|
||||||
|
dbus_event, bus);
|
||||||
|
wl_event_source_check(source);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -340,12 +366,6 @@ static int parse_args(int argc, char *argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sway_terminate(int exit_code) {
|
|
||||||
wl_display_disconnect(state.display);
|
|
||||||
wl_event_loop_destroy(state.event_loop);
|
|
||||||
exit(exit_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register_zero_idle_timeout(void *item) {
|
static void register_zero_idle_timeout(void *item) {
|
||||||
struct swayidle_timeout_cmd *cmd = item;
|
struct swayidle_timeout_cmd *cmd = item;
|
||||||
register_timeout(cmd, 0);
|
register_timeout(cmd, 0);
|
||||||
|
|
Loading…
Reference in a new issue