Use sway_log functions instead of wlr_log

This commit is contained in:
Markus Ongyerth 2018-05-24 21:45:22 +02:00
parent 1185a8cc1f
commit c7c1cf31f7
79 changed files with 377 additions and 372 deletions

View file

@ -11,9 +11,9 @@
#include <wayland-client.h>
#include <wayland-util.h>
#include <wlr/config.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include "log.h"
#include "idle-client-protocol.h"
#include "config.h"
#include "list.h"
@ -58,14 +58,14 @@ static void cmd_exec(void *data) {
return;
}
char *param = (char *)data;
wlr_log(L_DEBUG, "Cmd exec %s", param);
sway_log(L_DEBUG, "Cmd exec %s", param);
int pid = fork();
if (pid == 0) {
char *const cmd[] = { "sh", "-c", param, NULL, };
execvp(cmd[0], cmd);
exit(1);
}
wlr_log(L_DEBUG, "Spawned process %d", pid);
sway_log(L_DEBUG, "Spawned process %d", pid);
}
#if defined(SWAY_IDLE_HAS_SYSTEMD) || defined(SWAY_IDLE_HAS_ELOGIND)
@ -73,7 +73,7 @@ static int lock_fd = -1;
static int ongoing_fd = -1;
static int release_lock(void *data) {
wlr_log(L_INFO, "Releasing sleep lock %d", ongoing_fd);
sway_log(L_INFO, "Releasing sleep lock %d", ongoing_fd);
if (ongoing_fd >= 0) {
close(ongoing_fd);
}
@ -88,7 +88,7 @@ void acquire_sleep_lock() {
int ret = sd_bus_default_system(&bus);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to open D-Bus connection: %s",
sway_log(L_ERROR, "Failed to open D-Bus connection: %s",
strerror(-ret));
return;
}
@ -99,17 +99,17 @@ void acquire_sleep_lock() {
&error, &msg, "ssss", "sleep", "swayidle",
"Setup Up Lock Screen", "delay");
if (ret < 0) {
wlr_log(L_ERROR, "Failed to send Inhibit signal: %s",
sway_log(L_ERROR, "Failed to send Inhibit signal: %s",
strerror(-ret));
} else {
ret = sd_bus_message_read(msg, "h", &lock_fd);
if (ret < 0) {
wlr_log(L_ERROR,
sway_log(L_ERROR,
"Failed to parse D-Bus response for Inhibit: %s",
strerror(-ret));
}
}
wlr_log(L_INFO, "Got sleep lock: %d", lock_fd);
sway_log(L_INFO, "Got sleep lock: %d", lock_fd);
}
static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
@ -117,10 +117,10 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
bool going_down = true;
int ret = sd_bus_message_read(msg, "b", &going_down);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
sway_log(L_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
strerror(-ret));
}
wlr_log(L_DEBUG, "PrepareForSleep signal received %d", going_down);
sway_log(L_DEBUG, "PrepareForSleep signal received %d", going_down);
if (!going_down) {
acquire_sleep_lock();
return 0;
@ -137,7 +137,7 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
wl_event_loop_add_timer(state.event_loop, release_lock, NULL);
wl_event_source_timer_update(source, 1000);
}
wlr_log(L_DEBUG, "Prepare for sleep done");
sway_log(L_DEBUG, "Prepare for sleep done");
return 0;
}
@ -154,7 +154,7 @@ void setup_sleep_listener() {
int ret = sd_bus_default_system(&bus);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to open D-Bus connection: %s",
sway_log(L_ERROR, "Failed to open D-Bus connection: %s",
strerror(-ret));
return;
}
@ -169,7 +169,7 @@ void setup_sleep_listener() {
"/org/freedesktop/login1");
ret = sd_bus_add_match(bus, NULL, str, prepare_for_sleep, NULL);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to add D-Bus match: %s", strerror(-ret));
sway_log(L_ERROR, "Failed to add D-Bus match: %s", strerror(-ret));
return;
}
acquire_sleep_lock();
@ -200,7 +200,7 @@ static const struct wl_registry_listener registry_listener = {
static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
struct swayidle_timeout_cmd *cmd = data;
wlr_log(L_DEBUG, "idle state");
sway_log(L_DEBUG, "idle state");
if (cmd && cmd->idle_cmd && cmd->idle_cmd->callback) {
cmd->idle_cmd->callback(cmd->idle_cmd->param);
}
@ -208,7 +208,7 @@ static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
struct swayidle_timeout_cmd *cmd = data;
wlr_log(L_DEBUG, "active state");
sway_log(L_DEBUG, "active state");
if (cmd && cmd->resume_cmd && cmd->resume_cmd->callback) {
cmd->resume_cmd->callback(cmd->resume_cmd->param);
}
@ -221,12 +221,12 @@ static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
struct swayidle_cmd *parse_command(int argc, char **argv) {
if (argc < 1) {
wlr_log(L_ERROR, "Too few parameters for command in parse_command");
sway_log(L_ERROR, "Too few parameters for command in parse_command");
return NULL;
}
struct swayidle_cmd *cmd = calloc(1, sizeof(struct swayidle_cmd));
wlr_log(L_DEBUG, "Command: %s", argv[0]);
sway_log(L_DEBUG, "Command: %s", argv[0]);
cmd->callback = cmd_exec;
cmd->param = argv[0];
return cmd;
@ -234,7 +234,7 @@ struct swayidle_cmd *parse_command(int argc, char **argv) {
int parse_timeout(int argc, char **argv) {
if (argc < 3) {
wlr_log(L_ERROR, "Too few parameters to timeout command. "
sway_log(L_ERROR, "Too few parameters to timeout command. "
"Usage: timeout <seconds> <command>");
exit(-1);
}
@ -242,7 +242,7 @@ int parse_timeout(int argc, char **argv) {
char *endptr;
int seconds = strtoul(argv[1], &endptr, 10);
if (errno != 0 || *endptr != '\0') {
wlr_log(L_ERROR, "Invalid timeout parameter '%s', it should be a "
sway_log(L_ERROR, "Invalid timeout parameter '%s', it should be a "
"numeric value representing seconds", optarg);
exit(-1);
}
@ -250,13 +250,13 @@ int parse_timeout(int argc, char **argv) {
calloc(1, sizeof(struct swayidle_timeout_cmd));
cmd->timeout = seconds * 1000;
wlr_log(L_DEBUG, "Register idle timeout at %d ms", cmd->timeout);
wlr_log(L_DEBUG, "Setup idle");
sway_log(L_DEBUG, "Register idle timeout at %d ms", cmd->timeout);
sway_log(L_DEBUG, "Setup idle");
cmd->idle_cmd = parse_command(argc - 2, &argv[2]);
int result = 3;
if (argc >= 5 && !strcmp("resume", argv[3])) {
wlr_log(L_DEBUG, "Setup resume");
sway_log(L_DEBUG, "Setup resume");
cmd->resume_cmd = parse_command(argc - 4, &argv[4]);
result = 5;
}
@ -266,14 +266,14 @@ int parse_timeout(int argc, char **argv) {
int parse_sleep(int argc, char **argv) {
if (argc < 2) {
wlr_log(L_ERROR, "Too few parameters to before-sleep command. "
sway_log(L_ERROR, "Too few parameters to before-sleep command. "
"Usage: before-sleep <command>");
exit(-1);
}
lock_cmd = parse_command(argc - 1, &argv[1]);
if (lock_cmd) {
wlr_log(L_DEBUG, "Setup sleep lock: %s", lock_cmd->param);
sway_log(L_DEBUG, "Setup sleep lock: %s", lock_cmd->param);
}
return 2;
@ -300,10 +300,10 @@ int parse_args(int argc, char *argv[]) {
}
if (debug) {
wlr_log_init(L_DEBUG, NULL);
wlr_log(L_DEBUG, "Loglevel debug");
sway_log_init(L_DEBUG, NULL);
sway_log(L_DEBUG, "Loglevel debug");
} else {
wlr_log_init(L_INFO, NULL);
sway_log_init(L_INFO, NULL);
}
@ -312,13 +312,13 @@ int parse_args(int argc, char *argv[]) {
int i = optind;
while (i < argc) {
if (!strcmp("timeout", argv[i])) {
wlr_log(L_DEBUG, "Got timeout");
sway_log(L_DEBUG, "Got timeout");
i += parse_timeout(argc - i, &argv[i]);
} else if (!strcmp("before-sleep", argv[i])) {
wlr_log(L_DEBUG, "Got before-sleep");
sway_log(L_DEBUG, "Got before-sleep");
i += parse_sleep(argc - i, &argv[i]);
} else {
wlr_log(L_ERROR, "Unsupported command '%s'", argv[i]);
sway_log(L_ERROR, "Unsupported command '%s'", argv[i]);
exit(-1);
}
}
@ -344,7 +344,7 @@ static int display_event(int fd, uint32_t mask, void *data) {
sway_terminate(0);
}
if (wl_display_dispatch(state.display) < 0) {
wlr_log_errno(L_ERROR, "wl_display_dispatch failed, exiting");
sway_log_errno(L_ERROR, "wl_display_dispatch failed, exiting");
sway_terminate(0);
};
return 0;
@ -353,7 +353,7 @@ static int display_event(int fd, uint32_t mask, void *data) {
void register_idle_timeout(void *item) {
struct swayidle_timeout_cmd *cmd = item;
if (cmd == NULL || !cmd->timeout) {
wlr_log(L_ERROR, "Invalid idle cmd, will not register");
sway_log(L_ERROR, "Invalid idle cmd, will not register");
return;
}
state.idle_timer =
@ -362,7 +362,7 @@ void register_idle_timeout(void *item) {
org_kde_kwin_idle_timeout_add_listener(state.idle_timer,
&idle_timer_listener, cmd);
} else {
wlr_log(L_ERROR, "Could not create idle timer");
sway_log(L_ERROR, "Could not create idle timer");
}
}
@ -376,7 +376,7 @@ int main(int argc, char *argv[]) {
state.display = wl_display_connect(NULL);
if (state.display == NULL) {
wlr_log(L_ERROR, "Failed to create display");
sway_log(L_ERROR, "Failed to create display");
return -3;
}
@ -387,11 +387,11 @@ int main(int argc, char *argv[]) {
state.event_loop = wl_event_loop_create();
if (idle_manager == NULL) {
wlr_log(L_ERROR, "Display doesn't support idle protocol");
sway_log(L_ERROR, "Display doesn't support idle protocol");
return -4;
}
if (seat == NULL) {
wlr_log(L_ERROR, "Seat error");
sway_log(L_ERROR, "Seat error");
return -5;
}
@ -403,7 +403,7 @@ int main(int argc, char *argv[]) {
}
#endif
if (!should_run) {
wlr_log(L_INFO, "No command specified! Nothing to do, will exit");
sway_log(L_INFO, "No command specified! Nothing to do, will exit");
sway_terminate(0);
}
list_foreach(state.timeout_cmds, register_idle_timeout);