diff options
author | 2018-07-10 20:41:02 +1000 | |
---|---|---|
committer | 2018-07-10 20:41:02 +1000 | |
commit | 56ad148403d77a6defcbd6cd383dd5cde1a44954 (patch) | |
tree | 9dc36287be4bed02c4e98e600f26f48ceff5d8d6 /swayidle | |
parent | Fix titlebar rendering for nested stacked containers (diff) | |
parent | Merge pull request #2228 from emersion/focus-mode-toggle (diff) | |
download | sway-56ad148403d77a6defcbd6cd383dd5cde1a44954.tar.gz sway-56ad148403d77a6defcbd6cd383dd5cde1a44954.tar.zst sway-56ad148403d77a6defcbd6cd383dd5cde1a44954.zip |
Merge branch 'master' into fix-stacked-layout
Diffstat (limited to 'swayidle')
-rw-r--r-- | swayidle/main.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/swayidle/main.c b/swayidle/main.c index 7666578f..64e45036 100644 --- a/swayidle/main.c +++ b/swayidle/main.c | |||
@@ -59,24 +59,24 @@ static void cmd_exec(void *data) { | |||
59 | return; | 59 | return; |
60 | } | 60 | } |
61 | char *param = (char *)data; | 61 | char *param = (char *)data; |
62 | wlr_log(L_DEBUG, "Cmd exec %s", param); | 62 | wlr_log(WLR_DEBUG, "Cmd exec %s", param); |
63 | pid_t pid = fork(); | 63 | pid_t pid = fork(); |
64 | if (pid == 0) { | 64 | if (pid == 0) { |
65 | pid = fork(); | 65 | pid = fork(); |
66 | if (pid == 0) { | 66 | if (pid == 0) { |
67 | char *const cmd[] = { "sh", "-c", param, NULL, }; | 67 | char *const cmd[] = { "sh", "-c", param, NULL, }; |
68 | execvp(cmd[0], cmd); | 68 | execvp(cmd[0], cmd); |
69 | wlr_log_errno(L_ERROR, "execve failed!"); | 69 | wlr_log_errno(WLR_ERROR, "execve failed!"); |
70 | exit(1); | 70 | exit(1); |
71 | } else if (pid < 0) { | 71 | } else if (pid < 0) { |
72 | wlr_log_errno(L_ERROR, "fork failed"); | 72 | wlr_log_errno(WLR_ERROR, "fork failed"); |
73 | exit(1); | 73 | exit(1); |
74 | } | 74 | } |
75 | exit(0); | 75 | exit(0); |
76 | } else if (pid < 0) { | 76 | } else if (pid < 0) { |
77 | wlr_log_errno(L_ERROR, "fork failed"); | 77 | wlr_log_errno(WLR_ERROR, "fork failed"); |
78 | } else { | 78 | } else { |
79 | wlr_log(L_DEBUG, "Spawned process %s", param); | 79 | wlr_log(WLR_DEBUG, "Spawned process %s", param); |
80 | waitpid(pid, NULL, 0); | 80 | waitpid(pid, NULL, 0); |
81 | } | 81 | } |
82 | } | 82 | } |
@@ -86,7 +86,7 @@ static int lock_fd = -1; | |||
86 | static int ongoing_fd = -1; | 86 | static int ongoing_fd = -1; |
87 | 87 | ||
88 | static int release_lock(void *data) { | 88 | static int release_lock(void *data) { |
89 | wlr_log(L_INFO, "Releasing sleep lock %d", ongoing_fd); | 89 | wlr_log(WLR_INFO, "Releasing sleep lock %d", ongoing_fd); |
90 | if (ongoing_fd >= 0) { | 90 | if (ongoing_fd >= 0) { |
91 | close(ongoing_fd); | 91 | close(ongoing_fd); |
92 | } | 92 | } |
@@ -101,7 +101,7 @@ void acquire_sleep_lock() { | |||
101 | int ret = sd_bus_default_system(&bus); | 101 | int ret = sd_bus_default_system(&bus); |
102 | 102 | ||
103 | if (ret < 0) { | 103 | if (ret < 0) { |
104 | wlr_log(L_ERROR, "Failed to open D-Bus connection: %s", | 104 | wlr_log(WLR_ERROR, "Failed to open D-Bus connection: %s", |
105 | strerror(-ret)); | 105 | strerror(-ret)); |
106 | return; | 106 | return; |
107 | } | 107 | } |
@@ -112,17 +112,17 @@ void acquire_sleep_lock() { | |||
112 | &error, &msg, "ssss", "sleep", "swayidle", | 112 | &error, &msg, "ssss", "sleep", "swayidle", |
113 | "Setup Up Lock Screen", "delay"); | 113 | "Setup Up Lock Screen", "delay"); |
114 | if (ret < 0) { | 114 | if (ret < 0) { |
115 | wlr_log(L_ERROR, "Failed to send Inhibit signal: %s", | 115 | wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s", |
116 | strerror(-ret)); | 116 | strerror(-ret)); |
117 | } else { | 117 | } else { |
118 | ret = sd_bus_message_read(msg, "h", &lock_fd); | 118 | ret = sd_bus_message_read(msg, "h", &lock_fd); |
119 | if (ret < 0) { | 119 | if (ret < 0) { |
120 | wlr_log(L_ERROR, | 120 | wlr_log(WLR_ERROR, |
121 | "Failed to parse D-Bus response for Inhibit: %s", | 121 | "Failed to parse D-Bus response for Inhibit: %s", |
122 | strerror(-ret)); | 122 | strerror(-ret)); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | wlr_log(L_INFO, "Got sleep lock: %d", lock_fd); | 125 | wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd); |
126 | } | 126 | } |
127 | 127 | ||
128 | static int prepare_for_sleep(sd_bus_message *msg, void *userdata, | 128 | static int prepare_for_sleep(sd_bus_message *msg, void *userdata, |
@@ -131,10 +131,10 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata, | |||
131 | int going_down = 1; | 131 | int going_down = 1; |
132 | int ret = sd_bus_message_read(msg, "b", &going_down); | 132 | int ret = sd_bus_message_read(msg, "b", &going_down); |
133 | if (ret < 0) { | 133 | if (ret < 0) { |
134 | wlr_log(L_ERROR, "Failed to parse D-Bus response for Inhibit: %s", | 134 | wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", |
135 | strerror(-ret)); | 135 | strerror(-ret)); |
136 | } | 136 | } |
137 | wlr_log(L_DEBUG, "PrepareForSleep signal received %d", going_down); | 137 | wlr_log(WLR_DEBUG, "PrepareForSleep signal received %d", going_down); |
138 | if (!going_down) { | 138 | if (!going_down) { |
139 | acquire_sleep_lock(); | 139 | acquire_sleep_lock(); |
140 | return 0; | 140 | return 0; |
@@ -151,7 +151,7 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata, | |||
151 | wl_event_loop_add_timer(state.event_loop, release_lock, NULL); | 151 | wl_event_loop_add_timer(state.event_loop, release_lock, NULL); |
152 | wl_event_source_timer_update(source, 1000); | 152 | wl_event_source_timer_update(source, 1000); |
153 | } | 153 | } |
154 | wlr_log(L_DEBUG, "Prepare for sleep done"); | 154 | wlr_log(WLR_DEBUG, "Prepare for sleep done"); |
155 | return 0; | 155 | return 0; |
156 | } | 156 | } |
157 | 157 | ||
@@ -168,7 +168,7 @@ void setup_sleep_listener() { | |||
168 | 168 | ||
169 | int ret = sd_bus_default_system(&bus); | 169 | int ret = sd_bus_default_system(&bus); |
170 | if (ret < 0) { | 170 | if (ret < 0) { |
171 | wlr_log(L_ERROR, "Failed to open D-Bus connection: %s", | 171 | wlr_log(WLR_ERROR, "Failed to open D-Bus connection: %s", |
172 | strerror(-ret)); | 172 | strerror(-ret)); |
173 | return; | 173 | return; |
174 | } | 174 | } |
@@ -183,7 +183,7 @@ void setup_sleep_listener() { | |||
183 | "/org/freedesktop/login1"); | 183 | "/org/freedesktop/login1"); |
184 | ret = sd_bus_add_match(bus, NULL, str, prepare_for_sleep, NULL); | 184 | ret = sd_bus_add_match(bus, NULL, str, prepare_for_sleep, NULL); |
185 | if (ret < 0) { | 185 | if (ret < 0) { |
186 | wlr_log(L_ERROR, "Failed to add D-Bus match: %s", strerror(-ret)); | 186 | wlr_log(WLR_ERROR, "Failed to add D-Bus match: %s", strerror(-ret)); |
187 | return; | 187 | return; |
188 | } | 188 | } |
189 | acquire_sleep_lock(); | 189 | acquire_sleep_lock(); |
@@ -214,7 +214,7 @@ static const struct wl_registry_listener registry_listener = { | |||
214 | 214 | ||
215 | static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) { | 215 | static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) { |
216 | struct swayidle_timeout_cmd *cmd = data; | 216 | struct swayidle_timeout_cmd *cmd = data; |
217 | wlr_log(L_DEBUG, "idle state"); | 217 | wlr_log(WLR_DEBUG, "idle state"); |
218 | if (cmd && cmd->idle_cmd && cmd->idle_cmd->callback) { | 218 | if (cmd && cmd->idle_cmd && cmd->idle_cmd->callback) { |
219 | cmd->idle_cmd->callback(cmd->idle_cmd->param); | 219 | cmd->idle_cmd->callback(cmd->idle_cmd->param); |
220 | } | 220 | } |
@@ -222,7 +222,7 @@ static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) { | |||
222 | 222 | ||
223 | static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) { | 223 | static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) { |
224 | struct swayidle_timeout_cmd *cmd = data; | 224 | struct swayidle_timeout_cmd *cmd = data; |
225 | wlr_log(L_DEBUG, "active state"); | 225 | wlr_log(WLR_DEBUG, "active state"); |
226 | if (cmd && cmd->resume_cmd && cmd->resume_cmd->callback) { | 226 | if (cmd && cmd->resume_cmd && cmd->resume_cmd->callback) { |
227 | cmd->resume_cmd->callback(cmd->resume_cmd->param); | 227 | cmd->resume_cmd->callback(cmd->resume_cmd->param); |
228 | } | 228 | } |
@@ -235,12 +235,12 @@ static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = { | |||
235 | 235 | ||
236 | struct swayidle_cmd *parse_command(int argc, char **argv) { | 236 | struct swayidle_cmd *parse_command(int argc, char **argv) { |
237 | if (argc < 1) { | 237 | if (argc < 1) { |
238 | wlr_log(L_ERROR, "Too few parameters for command in parse_command"); | 238 | wlr_log(WLR_ERROR, "Too few parameters for command in parse_command"); |
239 | return NULL; | 239 | return NULL; |
240 | } | 240 | } |
241 | 241 | ||
242 | struct swayidle_cmd *cmd = calloc(1, sizeof(struct swayidle_cmd)); | 242 | struct swayidle_cmd *cmd = calloc(1, sizeof(struct swayidle_cmd)); |
243 | wlr_log(L_DEBUG, "Command: %s", argv[0]); | 243 | wlr_log(WLR_DEBUG, "Command: %s", argv[0]); |
244 | cmd->callback = cmd_exec; | 244 | cmd->callback = cmd_exec; |
245 | cmd->param = argv[0]; | 245 | cmd->param = argv[0]; |
246 | return cmd; | 246 | return cmd; |
@@ -248,7 +248,7 @@ struct swayidle_cmd *parse_command(int argc, char **argv) { | |||
248 | 248 | ||
249 | int parse_timeout(int argc, char **argv) { | 249 | int parse_timeout(int argc, char **argv) { |
250 | if (argc < 3) { | 250 | if (argc < 3) { |
251 | wlr_log(L_ERROR, "Too few parameters to timeout command. " | 251 | wlr_log(WLR_ERROR, "Too few parameters to timeout command. " |
252 | "Usage: timeout <seconds> <command>"); | 252 | "Usage: timeout <seconds> <command>"); |
253 | exit(-1); | 253 | exit(-1); |
254 | } | 254 | } |
@@ -256,7 +256,7 @@ int parse_timeout(int argc, char **argv) { | |||
256 | char *endptr; | 256 | char *endptr; |
257 | int seconds = strtoul(argv[1], &endptr, 10); | 257 | int seconds = strtoul(argv[1], &endptr, 10); |
258 | if (errno != 0 || *endptr != '\0') { | 258 | if (errno != 0 || *endptr != '\0') { |
259 | wlr_log(L_ERROR, "Invalid timeout parameter '%s', it should be a " | 259 | wlr_log(WLR_ERROR, "Invalid timeout parameter '%s', it should be a " |
260 | "numeric value representing seconds", optarg); | 260 | "numeric value representing seconds", optarg); |
261 | exit(-1); | 261 | exit(-1); |
262 | } | 262 | } |
@@ -264,13 +264,13 @@ int parse_timeout(int argc, char **argv) { | |||
264 | calloc(1, sizeof(struct swayidle_timeout_cmd)); | 264 | calloc(1, sizeof(struct swayidle_timeout_cmd)); |
265 | cmd->timeout = seconds * 1000; | 265 | cmd->timeout = seconds * 1000; |
266 | 266 | ||
267 | wlr_log(L_DEBUG, "Register idle timeout at %d ms", cmd->timeout); | 267 | wlr_log(WLR_DEBUG, "Register idle timeout at %d ms", cmd->timeout); |
268 | wlr_log(L_DEBUG, "Setup idle"); | 268 | wlr_log(WLR_DEBUG, "Setup idle"); |
269 | cmd->idle_cmd = parse_command(argc - 2, &argv[2]); | 269 | cmd->idle_cmd = parse_command(argc - 2, &argv[2]); |
270 | 270 | ||
271 | int result = 3; | 271 | int result = 3; |
272 | if (argc >= 5 && !strcmp("resume", argv[3])) { | 272 | if (argc >= 5 && !strcmp("resume", argv[3])) { |
273 | wlr_log(L_DEBUG, "Setup resume"); | 273 | wlr_log(WLR_DEBUG, "Setup resume"); |
274 | cmd->resume_cmd = parse_command(argc - 4, &argv[4]); | 274 | cmd->resume_cmd = parse_command(argc - 4, &argv[4]); |
275 | result = 5; | 275 | result = 5; |
276 | } | 276 | } |
@@ -280,14 +280,14 @@ int parse_timeout(int argc, char **argv) { | |||
280 | 280 | ||
281 | int parse_sleep(int argc, char **argv) { | 281 | int parse_sleep(int argc, char **argv) { |
282 | if (argc < 2) { | 282 | if (argc < 2) { |
283 | wlr_log(L_ERROR, "Too few parameters to before-sleep command. " | 283 | wlr_log(WLR_ERROR, "Too few parameters to before-sleep command. " |
284 | "Usage: before-sleep <command>"); | 284 | "Usage: before-sleep <command>"); |
285 | exit(-1); | 285 | exit(-1); |
286 | } | 286 | } |
287 | 287 | ||
288 | lock_cmd = parse_command(argc - 1, &argv[1]); | 288 | lock_cmd = parse_command(argc - 1, &argv[1]); |
289 | if (lock_cmd) { | 289 | if (lock_cmd) { |
290 | wlr_log(L_DEBUG, "Setup sleep lock: %s", lock_cmd->param); | 290 | wlr_log(WLR_DEBUG, "Setup sleep lock: %s", lock_cmd->param); |
291 | } | 291 | } |
292 | 292 | ||
293 | return 2; | 293 | return 2; |
@@ -314,10 +314,10 @@ int parse_args(int argc, char *argv[]) { | |||
314 | } | 314 | } |
315 | 315 | ||
316 | if (debug) { | 316 | if (debug) { |
317 | wlr_log_init(L_DEBUG, NULL); | 317 | wlr_log_init(WLR_DEBUG, NULL); |
318 | wlr_log(L_DEBUG, "Loglevel debug"); | 318 | wlr_log(WLR_DEBUG, "Loglevel debug"); |
319 | } else { | 319 | } else { |
320 | wlr_log_init(L_INFO, NULL); | 320 | wlr_log_init(WLR_INFO, NULL); |
321 | } | 321 | } |
322 | 322 | ||
323 | 323 | ||
@@ -326,13 +326,13 @@ int parse_args(int argc, char *argv[]) { | |||
326 | int i = optind; | 326 | int i = optind; |
327 | while (i < argc) { | 327 | while (i < argc) { |
328 | if (!strcmp("timeout", argv[i])) { | 328 | if (!strcmp("timeout", argv[i])) { |
329 | wlr_log(L_DEBUG, "Got timeout"); | 329 | wlr_log(WLR_DEBUG, "Got timeout"); |
330 | i += parse_timeout(argc - i, &argv[i]); | 330 | i += parse_timeout(argc - i, &argv[i]); |
331 | } else if (!strcmp("before-sleep", argv[i])) { | 331 | } else if (!strcmp("before-sleep", argv[i])) { |
332 | wlr_log(L_DEBUG, "Got before-sleep"); | 332 | wlr_log(WLR_DEBUG, "Got before-sleep"); |
333 | i += parse_sleep(argc - i, &argv[i]); | 333 | i += parse_sleep(argc - i, &argv[i]); |
334 | } else { | 334 | } else { |
335 | wlr_log(L_ERROR, "Unsupported command '%s'", argv[i]); | 335 | wlr_log(WLR_ERROR, "Unsupported command '%s'", argv[i]); |
336 | exit(-1); | 336 | exit(-1); |
337 | } | 337 | } |
338 | } | 338 | } |
@@ -358,7 +358,7 @@ static int display_event(int fd, uint32_t mask, void *data) { | |||
358 | sway_terminate(0); | 358 | sway_terminate(0); |
359 | } | 359 | } |
360 | if (wl_display_dispatch(state.display) < 0) { | 360 | if (wl_display_dispatch(state.display) < 0) { |
361 | wlr_log_errno(L_ERROR, "wl_display_dispatch failed, exiting"); | 361 | wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting"); |
362 | sway_terminate(0); | 362 | sway_terminate(0); |
363 | }; | 363 | }; |
364 | return 0; | 364 | return 0; |
@@ -367,7 +367,7 @@ static int display_event(int fd, uint32_t mask, void *data) { | |||
367 | void register_idle_timeout(void *item) { | 367 | void register_idle_timeout(void *item) { |
368 | struct swayidle_timeout_cmd *cmd = item; | 368 | struct swayidle_timeout_cmd *cmd = item; |
369 | if (cmd == NULL || !cmd->timeout) { | 369 | if (cmd == NULL || !cmd->timeout) { |
370 | wlr_log(L_ERROR, "Invalid idle cmd, will not register"); | 370 | wlr_log(WLR_ERROR, "Invalid idle cmd, will not register"); |
371 | return; | 371 | return; |
372 | } | 372 | } |
373 | state.idle_timer = | 373 | state.idle_timer = |
@@ -376,7 +376,7 @@ void register_idle_timeout(void *item) { | |||
376 | org_kde_kwin_idle_timeout_add_listener(state.idle_timer, | 376 | org_kde_kwin_idle_timeout_add_listener(state.idle_timer, |
377 | &idle_timer_listener, cmd); | 377 | &idle_timer_listener, cmd); |
378 | } else { | 378 | } else { |
379 | wlr_log(L_ERROR, "Could not create idle timer"); | 379 | wlr_log(WLR_ERROR, "Could not create idle timer"); |
380 | } | 380 | } |
381 | } | 381 | } |
382 | 382 | ||
@@ -390,7 +390,7 @@ int main(int argc, char *argv[]) { | |||
390 | 390 | ||
391 | state.display = wl_display_connect(NULL); | 391 | state.display = wl_display_connect(NULL); |
392 | if (state.display == NULL) { | 392 | if (state.display == NULL) { |
393 | wlr_log(L_ERROR, "Failed to create display"); | 393 | wlr_log(WLR_ERROR, "Failed to create display"); |
394 | return -3; | 394 | return -3; |
395 | } | 395 | } |
396 | 396 | ||
@@ -401,11 +401,11 @@ int main(int argc, char *argv[]) { | |||
401 | state.event_loop = wl_event_loop_create(); | 401 | state.event_loop = wl_event_loop_create(); |
402 | 402 | ||
403 | if (idle_manager == NULL) { | 403 | if (idle_manager == NULL) { |
404 | wlr_log(L_ERROR, "Display doesn't support idle protocol"); | 404 | wlr_log(WLR_ERROR, "Display doesn't support idle protocol"); |
405 | return -4; | 405 | return -4; |
406 | } | 406 | } |
407 | if (seat == NULL) { | 407 | if (seat == NULL) { |
408 | wlr_log(L_ERROR, "Seat error"); | 408 | wlr_log(WLR_ERROR, "Seat error"); |
409 | return -5; | 409 | return -5; |
410 | } | 410 | } |
411 | 411 | ||
@@ -417,7 +417,7 @@ int main(int argc, char *argv[]) { | |||
417 | } | 417 | } |
418 | #endif | 418 | #endif |
419 | if (!should_run) { | 419 | if (!should_run) { |
420 | wlr_log(L_INFO, "No command specified! Nothing to do, will exit"); | 420 | wlr_log(WLR_INFO, "No command specified! Nothing to do, will exit"); |
421 | sway_terminate(0); | 421 | sway_terminate(0); |
422 | } | 422 | } |
423 | list_foreach(state.timeout_cmds, register_idle_timeout); | 423 | list_foreach(state.timeout_cmds, register_idle_timeout); |