From 1185a8cc1f5bbad33d8c26a8c030b1456a99ee78 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 24 May 2018 21:43:56 +0200 Subject: [PATCH 1/6] introduce sway_log functions Introduce the sway_log functions as equivalents of the wlr_log functions. This is a first step to free clients from the wlroots dependency and allows to use the sway source path for file path stripping which should get nicer __FILE__ cleans. --- common/log.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/log.h | 29 +++++++++++++++-- meson.build | 1 + 3 files changed, 113 insertions(+), 5 deletions(-) diff --git a/common/log.c b/common/log.c index 2cc7289c5..bf1246bba 100644 --- a/common/log.c +++ b/common/log.c @@ -1,14 +1,20 @@ +#define _POSIX_C_SOURCE 199506L #include #include +#include #include +#include +#include #include "log.h" void sway_terminate(int code); + + void _sway_abort(const char *format, ...) { va_list args; va_start(args, format); - _wlr_vlog(L_ERROR, format, args); + _sway_vlog(L_ERROR, format, args); va_end(args); sway_terminate(EXIT_FAILURE); } @@ -20,7 +26,7 @@ bool _sway_assert(bool condition, const char *format, ...) { va_list args; va_start(args, format); - _wlr_vlog(L_ERROR, format, args); + _sway_vlog(L_ERROR, format, args); va_end(args); #ifndef NDEBUG @@ -29,3 +35,81 @@ bool _sway_assert(bool condition, const char *format, ...) { return false; } + +static bool colored = true; +static log_importance_t log_importance = L_ERROR; + +static const char *verbosity_colors[] = { + [L_SILENT] = "", + [L_ERROR ] = "\x1B[1;31m", + [L_INFO ] = "\x1B[1;34m", + [L_DEBUG ] = "\x1B[1;30m", +}; + +static void log_stderr(log_importance_t verbosity, const char *fmt, + va_list args) { + if (verbosity > log_importance) { + return; + } + // prefix the time to the log message + struct tm result; + time_t t = time(NULL); + struct tm *tm_info = localtime_r(&t, &result); + char buffer[26]; + + // generate time prefix + strftime(buffer, sizeof(buffer), "%F %T - ", tm_info); + fprintf(stderr, "%s", buffer); + + unsigned c = (verbosity < L_LAST) ? verbosity : L_LAST - 1; + + if (colored && isatty(STDERR_FILENO)) { + fprintf(stderr, "%s", verbosity_colors[c]); + } + + vfprintf(stderr, fmt, args); + + if (colored && isatty(STDERR_FILENO)) { + fprintf(stderr, "\x1B[0m"); + } + fprintf(stderr, "\n"); +} + +static log_callback_t log_callback = log_stderr; + +void sway_log_init(log_importance_t verbosity, log_callback_t callback) { + if (verbosity < L_LAST) { + log_importance = verbosity; + } + if (callback) { + log_callback = callback; + } +} + +void _sway_vlog(log_importance_t verbosity, const char *fmt, va_list args) { + log_callback(verbosity, fmt, args); +} + +void _sway_log(log_importance_t verbosity, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + log_callback(verbosity, fmt, args); + va_end(args); +} + +// strips the path prefix from filepath +// will try to strip SWAY_SRC_DIR as well as a relative src dir +// e.g. '/src/build/sway/util/log.c' and +// '../util/log.c' will both be stripped to +// 'util/log.c' +const char *sway_strip_path(const char *filepath) { + static int srclen = sizeof(SWAY_SRC_DIR); + if (strstr(filepath, SWAY_SRC_DIR) == filepath) { + filepath += srclen; + } else if (*filepath == '.') { + while (*filepath == '.' || *filepath == '/') { + ++filepath; + } + } + return filepath; +} diff --git a/include/log.h b/include/log.h index a97481274..2599c9aa2 100644 --- a/include/log.h +++ b/include/log.h @@ -1,16 +1,39 @@ #ifndef _SWAY_LOG_H #define _SWAY_LOG_H -#include + #include +#include +#include +#include +#include void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); #define sway_abort(FMT, ...) \ - _sway_abort("[%s:%d] " FMT, wlr_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) + _sway_abort("[%s:%d] " FMT, sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3); #define sway_assert(COND, FMT, ...) \ - _sway_assert(COND, "[%s:%d] %s:" FMT, wlr_strip_path(__FILE__), __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__) + _sway_assert(COND, "[%s:%d] %s:" FMT, sway_strip_path(__FILE__), __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__) void error_handler(int sig); +typedef void (*log_callback_t)(log_importance_t importance, const char *fmt, va_list args); + +// Will log all messages less than or equal to `verbosity` +// If `callback` is NULL, sway will use its default logger. +void sway_log_init(log_importance_t verbosity, log_callback_t callback); + +void _sway_log(log_importance_t verbosity, const char *format, ...) ATTRIB_PRINTF(2, 3); +void _sway_vlog(log_importance_t verbosity, const char *format, va_list args) ATTRIB_PRINTF(2, 0); +const char *sway_strip_path(const char *filepath); + +#define sway_log(verb, fmt, ...) \ + _sway_log(verb, "[%s:%d] " fmt, sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) + +#define sway_vlog(verb, fmt, args) \ + _sway_vlog(verb, "[%s:%d] " fmt, sway_strip_path(__FILE__), __LINE__, args) + +#define sway_log_errno(verb, fmt, ...) \ + sway_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno)) + #endif diff --git a/meson.build b/meson.build index d4ee1a118..890c1787f 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ project( add_project_arguments('-Wno-unused-parameter', language: 'c') add_project_arguments('-Wno-unused-function', language: 'c') add_project_arguments('-Wno-unused-result', language: 'c') +add_project_arguments('-DSWAY_SRC_DIR="@0@"'.format(meson.source_root()), language: 'c') cc = meson.get_compiler('c') From c7c1cf31f7ce5893f7b4640413491d54e188e4e2 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 24 May 2018 21:45:22 +0200 Subject: [PATCH 2/6] Use sway_log functions instead of wlr_log --- common/background-image.c | 10 +-- common/ipc-client.c | 2 +- common/pango.c | 2 +- common/readline.c | 4 +- common/util.c | 2 +- sway/commands.c | 12 ++-- sway/commands/assign.c | 2 +- sway/commands/bar.c | 4 +- sway/commands/bar/binding_mode_indicator.c | 4 +- sway/commands/bar/font.c | 2 +- sway/commands/bar/height.c | 2 +- sway/commands/bar/hidden_state.c | 2 +- sway/commands/bar/id.c | 2 +- sway/commands/bar/mode.c | 2 +- sway/commands/bar/modifier.c | 2 +- sway/commands/bar/output.c | 2 +- sway/commands/bar/pango_markup.c | 4 +- sway/commands/bar/position.c | 2 +- sway/commands/bar/separator_symbol.c | 2 +- sway/commands/bar/status_command.c | 2 +- sway/commands/bar/strip_workspace_numbers.c | 4 +- sway/commands/bar/swaybar_command.c | 2 +- sway/commands/bar/workspace_buttons.c | 4 +- sway/commands/bar/wrap_scroll.c | 4 +- sway/commands/bind.c | 8 +-- sway/commands/exec.c | 2 +- sway/commands/exec_always.c | 8 +-- sway/commands/for_window.c | 2 +- sway/commands/input.c | 2 +- sway/commands/input/events.c | 2 +- sway/commands/input/tap.c | 2 +- sway/commands/input/xkb_layout.c | 2 +- sway/commands/input/xkb_model.c | 2 +- sway/commands/input/xkb_options.c | 2 +- sway/commands/input/xkb_rules.c | 2 +- sway/commands/input/xkb_variant.c | 2 +- sway/commands/mode.c | 2 +- sway/commands/output.c | 8 +-- sway/commands/rename.c | 2 +- sway/commands/resize.c | 2 +- sway/commands/seat.c | 2 +- sway/commands/set.c | 2 +- sway/commands/swaybg_command.c | 2 +- sway/commands/workspace.c | 2 +- sway/config.c | 66 +++++++++--------- sway/config/bar.c | 14 ++-- sway/config/input.c | 8 +-- sway/config/output.c | 26 ++++---- sway/config/seat.c | 6 +- sway/criteria.c | 2 +- sway/desktop/layer_shell.c | 6 +- sway/desktop/output.c | 2 +- sway/desktop/xdg_shell.c | 4 +- sway/desktop/xdg_shell_v6.c | 4 +- sway/desktop/xwayland.c | 6 +- sway/input/cursor.c | 2 +- sway/input/input-manager.c | 38 +++++------ sway/input/keyboard.c | 6 +- sway/input/seat.c | 20 +++--- sway/ipc-server.c | 64 +++++++++--------- sway/main.c | 52 +++++++-------- sway/server.c | 12 ++-- sway/tree/arrange.c | 18 ++--- sway/tree/container.c | 18 ++--- sway/tree/layout.c | 48 ++++++------- sway/tree/output.c | 6 +- sway/tree/view.c | 12 ++-- sway/tree/workspace.c | 16 ++--- swaybar/bar.c | 2 +- swaybar/i3bar.c | 6 +- swaybar/ipc.c | 6 +- swaybar/main.c | 10 +-- swaybar/status_line.c | 8 +-- swaybg/main.c | 13 ++-- swayidle/main.c | 74 ++++++++++----------- swaylock/main.c | 20 +++--- swaylock/password.c | 8 +-- swaylock/seat.c | 6 +- swaymsg/main.c | 2 +- 79 files changed, 377 insertions(+), 372 deletions(-) diff --git a/common/background-image.c b/common/background-image.c index e5fb4433e..4173749d4 100644 --- a/common/background-image.c +++ b/common/background-image.c @@ -1,6 +1,6 @@ #include #include -#include +#include "log.h" #include "background-image.h" #include "cairo.h" @@ -18,7 +18,7 @@ enum background_mode parse_background_mode(const char *mode) { } else if (strcmp(mode, "solid_color") == 0) { return BACKGROUND_MODE_SOLID_COLOR; } - wlr_log(L_ERROR, "Unsupported background mode: %s", mode); + sway_log(L_ERROR, "Unsupported background mode: %s", mode); return BACKGROUND_MODE_INVALID; } @@ -28,7 +28,7 @@ cairo_surface_t *load_background_image(const char *path) { GError *err = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err); if (!pixbuf) { - wlr_log(L_ERROR, "Failed to load background image (%s).", + sway_log(L_ERROR, "Failed to load background image (%s).", err->message); return false; } @@ -38,11 +38,11 @@ cairo_surface_t *load_background_image(const char *path) { image = cairo_image_surface_create_from_png(path); #endif //HAVE_GDK_PIXBUF if (!image) { - wlr_log(L_ERROR, "Failed to read background image."); + sway_log(L_ERROR, "Failed to read background image."); return NULL; } if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) { - wlr_log(L_ERROR, "Failed to read background image: %s." + sway_log(L_ERROR, "Failed to read background image: %s." #ifndef HAVE_GDK_PIXBUF "\nSway was compiled without gdk_pixbuf support, so only" "\nPNG images can be loaded. This is the likely cause." diff --git a/common/ipc-client.c b/common/ipc-client.c index a88df0800..f0ba1c783 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c @@ -97,7 +97,7 @@ struct ipc_response *ipc_recv_response(int socketfd) { error_2: free(response); error_1: - wlr_log(L_ERROR, "Unable to allocate memory for IPC response"); + sway_log(L_ERROR, "Unable to allocate memory for IPC response"); return NULL; } diff --git a/common/pango.c b/common/pango.c index c88e50ce1..a882c3a11 100644 --- a/common/pango.c +++ b/common/pango.c @@ -81,7 +81,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, pango_layout_set_markup(layout, buf, -1); free(buf); } else { - wlr_log(L_ERROR, "pango_parse_markup '%s' -> error %s", text, + sway_log(L_ERROR, "pango_parse_markup '%s' -> error %s", text, error->message); g_error_free(error); markup = false; // fallback to plain text diff --git a/common/readline.c b/common/readline.c index ed5801de4..cc40a2cc1 100644 --- a/common/readline.c +++ b/common/readline.c @@ -8,7 +8,7 @@ char *read_line(FILE *file) { char *string = malloc(size); char lastChar = '\0'; if (!string) { - wlr_log(L_ERROR, "Unable to allocate memory for read_line"); + sway_log(L_ERROR, "Unable to allocate memory for read_line"); return NULL; } while (1) { @@ -29,7 +29,7 @@ char *read_line(FILE *file) { char *new_string = realloc(string, size *= 2); if (!new_string) { free(string); - wlr_log(L_ERROR, "Unable to allocate memory for read_line"); + sway_log(L_ERROR, "Unable to allocate memory for read_line"); return NULL; } string = new_string; diff --git a/common/util.c b/common/util.c index fb7f94541..839811608 100644 --- a/common/util.c +++ b/common/util.c @@ -113,7 +113,7 @@ uint32_t parse_color(const char *color) { int len = strlen(color); if (len != 6 && len != 8) { - wlr_log(L_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color); + sway_log(L_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color); return 0xFFFFFFFF; } uint32_t res = (uint32_t)strtoul(color, NULL, 16); diff --git a/sway/commands.c b/sway/commands.c index 6cba0a1c5..f0b2396c8 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -230,7 +230,7 @@ static struct cmd_handler seat_handlers[] = { static struct cmd_handler *find_handler(char *line, enum cmd_status block) { struct cmd_handler d = { .command=line }; struct cmd_handler *res = NULL; - wlr_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT); + sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT); bool config_loading = config->reading || !config->active; @@ -328,10 +328,10 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { cmd = argsep(&cmdlist, ","); cmd += strspn(cmd, whitespace); if (strcmp(cmd, "") == 0) { - wlr_log(L_INFO, "Ignoring empty command."); + sway_log(L_INFO, "Ignoring empty command."); continue; } - wlr_log(L_INFO, "Handling command '%s'", cmd); + sway_log(L_INFO, "Handling command '%s'", cmd); //TODO better handling of argv int argc; char **argv = split_args(cmd, &argc); @@ -416,7 +416,7 @@ struct cmd_results *config_command(char *exec, enum cmd_status block) { goto cleanup; } - wlr_log(L_INFO, "handling config command '%s'", exec); + sway_log(L_INFO, "handling config command '%s'", exec); // Endblock if (**argv == '}') { results = cmd_results_new(CMD_BLOCK_END, NULL, NULL); @@ -520,7 +520,7 @@ struct cmd_results *config_commands_command(char *exec) { } policy->context = context; - wlr_log(L_INFO, "Set command policy for %s to %d", + sway_log(L_INFO, "Set command policy for %s to %d", policy->command, policy->context); results = cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -534,7 +534,7 @@ struct cmd_results *cmd_results_new(enum cmd_status status, const char *input, const char *format, ...) { struct cmd_results *results = malloc(sizeof(struct cmd_results)); if (!results) { - wlr_log(L_ERROR, "Unable to allocate command results"); + sway_log(L_ERROR, "Unable to allocate command results"); return NULL; } results->status = status; diff --git a/sway/commands/assign.c b/sway/commands/assign.c index 9d15e166e..1c57a8b8f 100644 --- a/sway/commands/assign.c +++ b/sway/commands/assign.c @@ -44,7 +44,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) { criteria->target = join_args(argv, target_len); list_add(config->criteria, criteria); - wlr_log(L_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, + sway_log(L_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, criteria->target); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/bar.c b/sway/commands/bar.c index ff111163e..40533cb74 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c @@ -1,6 +1,6 @@ #include #include -#include +#include "log.h" #include "sway/commands.h" #include "sway/config.h" #include "util.h" @@ -52,6 +52,6 @@ struct cmd_results *cmd_bar(int argc, char **argv) { // Set current bar config->current_bar = bar; - wlr_log(L_DEBUG, "Configuring bar %s", bar->id); + sway_log(L_DEBUG, "Configuring bar %s", bar->id); return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); } diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c index 3ba5f33f8..97246d60b 100644 --- a/sway/commands/bar/binding_mode_indicator.c +++ b/sway/commands/bar/binding_mode_indicator.c @@ -15,11 +15,11 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { } if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->binding_mode_indicator = true; - wlr_log(L_DEBUG, "Enabling binding mode indicator on bar: %s", + sway_log(L_DEBUG, "Enabling binding mode indicator on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->binding_mode_indicator = false; - wlr_log(L_DEBUG, "Disabling binding mode indicator on bar: %s", + sway_log(L_DEBUG, "Disabling binding mode indicator on bar: %s", config->current_bar->id); } return cmd_results_new(CMD_INVALID, "binding_mode_indicator", diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c index 80b7a5931..d10e7d69c 100644 --- a/sway/commands/bar/font.c +++ b/sway/commands/bar/font.c @@ -15,7 +15,7 @@ struct cmd_results *bar_cmd_font(int argc, char **argv) { char *font = join_args(argv, argc); free(config->current_bar->font); config->current_bar->font = strdup(font); - wlr_log(L_DEBUG, "Settings font '%s' for bar: %s", + sway_log(L_DEBUG, "Settings font '%s' for bar: %s", config->current_bar->font, config->current_bar->id); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/height.c b/sway/commands/bar/height.c index 3160caed8..3a3c8810e 100644 --- a/sway/commands/bar/height.c +++ b/sway/commands/bar/height.c @@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_height(int argc, char **argv) { "Invalid height value: %s", argv[0]); } config->current_bar->height = height; - wlr_log(L_DEBUG, "Setting bar height to %d on bar: %s", + sway_log(L_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c index 6641f1848..c918d19b3 100644 --- a/sway/commands/bar/hidden_state.c +++ b/sway/commands/bar/hidden_state.c @@ -27,7 +27,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, if (!config->reading) { ipc_event_barconfig_update(bar); } - wlr_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", + sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id); } // free old mode diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c index c1e56f039..d744cd0cb 100644 --- a/sway/commands/bar/id.c +++ b/sway/commands/bar/id.c @@ -21,7 +21,7 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) { } } - wlr_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); + sway_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); // free old bar id free(config->current_bar->id); diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c index 34bb0a4ff..5af4cbc2d 100644 --- a/sway/commands/bar/mode.c +++ b/sway/commands/bar/mode.c @@ -28,7 +28,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode if (!config->reading) { ipc_event_barconfig_update(bar); } - wlr_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); + sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); } // free old mode diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c index 7ba4b125d..43907007a 100644 --- a/sway/commands/bar/modifier.c +++ b/sway/commands/bar/modifier.c @@ -29,7 +29,7 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) { } free_flat_list(split); config->current_bar->modifier = mod; - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c index f7ca0aa41..d21a1f545 100644 --- a/sway/commands/bar/output.c +++ b/sway/commands/bar/output.c @@ -42,7 +42,7 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) { if (add_output) { list_add(outputs, strdup(output)); - wlr_log(L_DEBUG, "Adding bar: '%s' to output '%s'", + sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/bar/pango_markup.c b/sway/commands/bar/pango_markup.c index 480af724b..a53b7efad 100644 --- a/sway/commands/bar/pango_markup.c +++ b/sway/commands/bar/pango_markup.c @@ -13,11 +13,11 @@ struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { } if (strcasecmp("enabled", argv[0]) == 0) { config->current_bar->pango_markup = true; - wlr_log(L_DEBUG, "Enabling pango markup for bar: %s", + sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); } else if (strcasecmp("disabled", argv[0]) == 0) { config->current_bar->pango_markup = false; - wlr_log(L_DEBUG, "Disabling pango markup for bar: %s", + sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); } else { error = cmd_results_new(CMD_INVALID, "pango_markup", diff --git a/sway/commands/bar/position.c b/sway/commands/bar/position.c index 9c5804839..59cd251b2 100644 --- a/sway/commands/bar/position.c +++ b/sway/commands/bar/position.c @@ -15,7 +15,7 @@ struct cmd_results *bar_cmd_position(int argc, char **argv) { char *valid[] = { "top", "bottom", "left", "right" }; for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) { if (strcasecmp(valid[i], argv[0]) == 0) { - wlr_log(L_DEBUG, "Setting bar position '%s' for bar: %s", + sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id); config->current_bar->position = strdup(argv[0]); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/bar/separator_symbol.c b/sway/commands/bar/separator_symbol.c index 1e08df6d2..38ce43f41 100644 --- a/sway/commands/bar/separator_symbol.c +++ b/sway/commands/bar/separator_symbol.c @@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) { } free(config->current_bar->separator_symbol); config->current_bar->separator_symbol = strdup(argv[0]); - wlr_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s", + sway_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s", config->current_bar->separator_symbol, config->current_bar->id); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c index 5e199cde6..4cfbf5d41 100644 --- a/sway/commands/bar/status_command.c +++ b/sway/commands/bar/status_command.c @@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_status_command(int argc, char **argv) { } free(config->current_bar->status_command); config->current_bar->status_command = join_args(argv, argc); - wlr_log(L_DEBUG, "Feeding bar with status command: %s", + sway_log(L_DEBUG, "Feeding bar with status command: %s", config->current_bar->status_command); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/strip_workspace_numbers.c b/sway/commands/bar/strip_workspace_numbers.c index 4f24a3563..35a7231f3 100644 --- a/sway/commands/bar/strip_workspace_numbers.c +++ b/sway/commands/bar/strip_workspace_numbers.c @@ -15,11 +15,11 @@ struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { } if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->strip_workspace_numbers = true; - wlr_log(L_DEBUG, "Stripping workspace numbers on bar: %s", + sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->strip_workspace_numbers = false; - wlr_log(L_DEBUG, "Enabling workspace numbers on bar: %s", + sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id); } else { return cmd_results_new(CMD_INVALID, diff --git a/sway/commands/bar/swaybar_command.c b/sway/commands/bar/swaybar_command.c index 520cdd118..4f9cefcdc 100644 --- a/sway/commands/bar/swaybar_command.c +++ b/sway/commands/bar/swaybar_command.c @@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) { } free(config->current_bar->swaybar_command); config->current_bar->swaybar_command = join_args(argv, argc); - wlr_log(L_DEBUG, "Using custom swaybar command: %s", + sway_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/workspace_buttons.c b/sway/commands/bar/workspace_buttons.c index 6edc3a0de..83fb8d8e4 100644 --- a/sway/commands/bar/workspace_buttons.c +++ b/sway/commands/bar/workspace_buttons.c @@ -14,11 +14,11 @@ struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { } if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->workspace_buttons = true; - wlr_log(L_DEBUG, "Enabling workspace buttons on bar: %s", + sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->workspace_buttons = false; - wlr_log(L_DEBUG, "Disabling workspace buttons on bar: %s", + sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id); } else { return cmd_results_new(CMD_INVALID, "workspace_buttons", diff --git a/sway/commands/bar/wrap_scroll.c b/sway/commands/bar/wrap_scroll.c index 7386f82ce..84979960f 100644 --- a/sway/commands/bar/wrap_scroll.c +++ b/sway/commands/bar/wrap_scroll.c @@ -13,11 +13,11 @@ struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { } if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->wrap_scroll = true; - wlr_log(L_DEBUG, "Enabling wrap scroll on bar: %s", + sway_log(L_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->wrap_scroll = false; - wlr_log(L_DEBUG, "Disabling wrap scroll on bar: %s", + sway_log(L_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id); } else { return cmd_results_new(CMD_INVALID, diff --git a/sway/commands/bind.c b/sway/commands/bind.c index cbabb07bf..791214041 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -145,7 +145,7 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) { for (int i = 0; i < mode_bindings->length; ++i) { struct sway_binding *config_binding = mode_bindings->items[i]; if (binding_key_compare(binding, config_binding)) { - wlr_log(L_DEBUG, "overwriting old binding with command '%s'", + sway_log(L_DEBUG, "overwriting old binding with command '%s'", config_binding->command); free_sway_binding(config_binding); mode_bindings->items[i] = binding; @@ -157,7 +157,7 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) { list_add(mode_bindings, binding); } - wlr_log(L_DEBUG, "bindsym - Bound %s to command %s", + sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -227,7 +227,7 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { for (int i = 0; i < mode_bindings->length; ++i) { struct sway_binding *config_binding = mode_bindings->items[i]; if (binding_key_compare(binding, config_binding)) { - wlr_log(L_DEBUG, "overwriting old binding with command '%s'", + sway_log(L_DEBUG, "overwriting old binding with command '%s'", config_binding->command); free_sway_binding(config_binding); mode_bindings->items[i] = binding; @@ -239,7 +239,7 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { list_add(mode_bindings, binding); } - wlr_log(L_DEBUG, "bindcode - Bound %s to command %s", + sway_log(L_DEBUG, "bindcode - Bound %s to command %s", argv[0], binding->command); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/exec.c b/sway/commands/exec.c index 363d5bef4..fbbc49410 100644 --- a/sway/commands/exec.c +++ b/sway/commands/exec.c @@ -8,7 +8,7 @@ struct cmd_results *cmd_exec(int argc, char **argv) { if (!config->active) return cmd_results_new(CMD_DEFER, "exec", NULL); if (config->reloading) { char *args = join_args(argv, argc); - wlr_log(L_DEBUG, "Ignoring 'exec %s' due to reload", args); + sway_log(L_DEBUG, "Ignoring 'exec %s' due to reload", args); free(args); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index af4e4965a..a2a58c07c 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -20,7 +20,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { char *tmp = NULL; if (strcmp((char*)*argv, "--no-startup-id") == 0) { - wlr_log(L_INFO, "exec switch '--no-startup-id' not supported, ignored."); + sway_log(L_INFO, "exec switch '--no-startup-id' not supported, ignored."); if ((error = checkarg(argc - 1, "exec_always", EXPECTED_MORE_THAN, 0))) { return error; } @@ -35,11 +35,11 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { strncpy(cmd, tmp, sizeof(cmd) - 1); cmd[sizeof(cmd) - 1] = 0; free(tmp); - wlr_log(L_DEBUG, "Executing %s", cmd); + sway_log(L_DEBUG, "Executing %s", cmd); int fd[2]; if (pipe(fd) != 0) { - wlr_log(L_ERROR, "Unable to create pipe for fork"); + sway_log(L_ERROR, "Unable to create pipe for fork"); } pid_t pid; @@ -75,7 +75,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { // cleanup child process wait(0); if (*child > 0) { - wlr_log(L_DEBUG, "Child process created with pid %d", *child); + sway_log(L_DEBUG, "Child process created with pid %d", *child); // TODO: add PID to active workspace } else { free(child); diff --git a/sway/commands/for_window.c b/sway/commands/for_window.c index 8c425a1dd..428275e71 100644 --- a/sway/commands/for_window.c +++ b/sway/commands/for_window.c @@ -24,7 +24,7 @@ struct cmd_results *cmd_for_window(int argc, char **argv) { criteria->cmdlist = join_args(argv + 1, argc - 1); list_add(config->criteria, criteria); - wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist); + sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/input.c b/sway/commands/input.c index eeb4ee75c..6d97c6587 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -16,7 +16,7 @@ struct cmd_results *cmd_input(int argc, char **argv) { if (!config->handler_context.input_config) { return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); } - wlr_log(L_DEBUG, "entering input block: %s", argv[0]); + sway_log(L_DEBUG, "entering input block: %s", argv[0]); return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); } diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index 2217f5cec..727630d26 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -16,7 +16,7 @@ struct cmd_results *input_cmd_events(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); } - wlr_log(L_DEBUG, "events for device: %s", + sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); struct input_config *new_config = new_input_config(current_input_config->identifier); diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c index e7f030581..94a7434e3 100644 --- a/sway/commands/input/tap.c +++ b/sway/commands/input/tap.c @@ -27,7 +27,7 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) { "Expected 'tap '"); } - wlr_log(L_DEBUG, "apply-tap for device: %s", + sway_log(L_DEBUG, "apply-tap for device: %s", current_input_config->identifier); apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/input/xkb_layout.c b/sway/commands/input/xkb_layout.c index 867e65d3a..384b0d861 100644 --- a/sway/commands/input/xkb_layout.c +++ b/sway/commands/input/xkb_layout.c @@ -19,7 +19,7 @@ struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) { new_config->xkb_layout = strdup(argv[0]); - wlr_log(L_DEBUG, "apply-xkb_layout for device: %s layout: %s", + sway_log(L_DEBUG, "apply-xkb_layout for device: %s layout: %s", current_input_config->identifier, new_config->xkb_layout); apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/input/xkb_model.c b/sway/commands/input/xkb_model.c index e8c8e04eb..1740a6af7 100644 --- a/sway/commands/input/xkb_model.c +++ b/sway/commands/input/xkb_model.c @@ -19,7 +19,7 @@ struct cmd_results *input_cmd_xkb_model(int argc, char **argv) { new_config->xkb_model = strdup(argv[0]); - wlr_log(L_DEBUG, "apply-xkb_model for device: %s model: %s", + sway_log(L_DEBUG, "apply-xkb_model for device: %s model: %s", current_input_config->identifier, new_config->xkb_model); apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/input/xkb_options.c b/sway/commands/input/xkb_options.c index e9ddd6e31..e1d734884 100644 --- a/sway/commands/input/xkb_options.c +++ b/sway/commands/input/xkb_options.c @@ -19,7 +19,7 @@ struct cmd_results *input_cmd_xkb_options(int argc, char **argv) { new_config->xkb_options = strdup(argv[0]); - wlr_log(L_DEBUG, "apply-xkb_options for device: %s options: %s", + sway_log(L_DEBUG, "apply-xkb_options for device: %s options: %s", current_input_config->identifier, new_config->xkb_options); apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/input/xkb_rules.c b/sway/commands/input/xkb_rules.c index 926d0ac15..8fc9139d0 100644 --- a/sway/commands/input/xkb_rules.c +++ b/sway/commands/input/xkb_rules.c @@ -19,7 +19,7 @@ struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) { new_config->xkb_rules = strdup(argv[0]); - wlr_log(L_DEBUG, "apply-xkb_rules for device: %s rules: %s", + sway_log(L_DEBUG, "apply-xkb_rules for device: %s rules: %s", current_input_config->identifier, new_config->xkb_rules); apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/input/xkb_variant.c b/sway/commands/input/xkb_variant.c index 0e3ffd41e..22a0d54c5 100644 --- a/sway/commands/input/xkb_variant.c +++ b/sway/commands/input/xkb_variant.c @@ -19,7 +19,7 @@ struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) { new_config->xkb_variant = strdup(argv[0]); - wlr_log(L_DEBUG, "apply-xkb_variant for device: %s variant: %s", + sway_log(L_DEBUG, "apply-xkb_variant for device: %s variant: %s", current_input_config->identifier, new_config->xkb_variant); apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/mode.c b/sway/commands/mode.c index c30a8bac2..f883606cd 100644 --- a/sway/commands/mode.c +++ b/sway/commands/mode.c @@ -47,7 +47,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) { return error; } if ((config->reading && new_mode) || (!config->reading && !new_mode)) { - wlr_log(L_DEBUG, "Switching to mode `%s'",mode->name); + sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); } // Set current mode config->current_mode = mode; diff --git a/sway/commands/output.c b/sway/commands/output.c index e8881f776..ebc529399 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -222,12 +222,12 @@ static struct cmd_results *cmd_output_background(struct output_config *output, if (src) { sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); } else { - wlr_log(L_ERROR, + sway_log(L_ERROR, "Unable to allocate background source"); } free(conf); } else { - wlr_log(L_ERROR, "Unable to allocate background source"); + sway_log(L_ERROR, "Unable to allocate background source"); } } if (!src || access(src, F_OK) == -1) { @@ -257,7 +257,7 @@ struct cmd_results *cmd_output(int argc, char **argv) { struct output_config *output = new_output_config(argv[0]); if (!output) { - wlr_log(L_ERROR, "Failed to allocate output config"); + sway_log(L_ERROR, "Failed to allocate output config"); return NULL; } @@ -305,7 +305,7 @@ struct cmd_results *cmd_output(int argc, char **argv) { list_add(config->output_configs, output); } - wlr_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz " + sway_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz " "position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)", output->name, output->enabled, output->width, output->height, output->refresh_rate, output->x, output->y, output->scale, diff --git a/sway/commands/rename.c b/sway/commands/rename.c index 104a33925..6cdba14b2 100644 --- a/sway/commands/rename.c +++ b/sway/commands/rename.c @@ -68,7 +68,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) { "Workspace already exists"); } - wlr_log(L_DEBUG, "renaming workspace '%s' to '%s'", workspace->name, new_name); + sway_log(L_DEBUG, "renaming workspace '%s' to '%s'", workspace->name, new_name); free(workspace->name); workspace->name = new_name; diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 296379531..f8e0b2f2f 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -95,7 +95,7 @@ static void resize_tiled(int amount, enum resize_axis axis) { return; } - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, minor_weight, major_weight); diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 5916015fa..b337083f8 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -17,7 +17,7 @@ struct cmd_results *cmd_seat(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); } - wlr_log(L_DEBUG, "entering seat block: %s", argv[0]); + sway_log(L_DEBUG, "entering seat block: %s", argv[0]); return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); } diff --git a/sway/commands/set.c b/sway/commands/set.c index 84e9b792c..cbdb2f95f 100644 --- a/sway/commands/set.c +++ b/sway/commands/set.c @@ -32,7 +32,7 @@ struct cmd_results *cmd_set(int argc, char **argv) { } if (argv[0][0] != '$') { - wlr_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); + sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); size_t size = snprintf(NULL, 0, "$%s", argv[0]); tmp = malloc(size + 1); diff --git a/sway/commands/swaybg_command.c b/sway/commands/swaybg_command.c index 770d48214..de104b20f 100644 --- a/sway/commands/swaybg_command.c +++ b/sway/commands/swaybg_command.c @@ -13,7 +13,7 @@ struct cmd_results *cmd_swaybg_command(int argc, char **argv) { free(config->swaybg_command); } config->swaybg_command = join_args(argv, argc); - wlr_log(L_DEBUG, "Using custom swaybg command: %s", + sway_log(L_DEBUG, "Using custom swaybg command: %s", config->swaybg_command); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 958b32227..fc4b228f6 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -51,7 +51,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { free(old); // workspaces can only be assigned to a single output list_del(config->workspace_outputs, i); } - wlr_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); + sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); list_add(config->workspace_outputs, wso); } else { if (config->reading || !config->active) { diff --git a/sway/config.c b/sway/config.c index 34c8a2802..9b88ed3ab 100644 --- a/sway/config.c +++ b/sway/config.c @@ -270,12 +270,12 @@ static char *get_config_path(void) { char *home = getenv("HOME"); char *config_home = malloc(strlen(home) + strlen("/.config") + 1); if (!config_home) { - wlr_log(L_ERROR, "Unable to allocate $HOME/.config"); + sway_log(L_ERROR, "Unable to allocate $HOME/.config"); } else { strcpy(config_home, home); strcat(config_home, "/.config"); setenv("XDG_CONFIG_HOME", config_home, 1); - wlr_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home); + sway_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home); free(config_home); } } @@ -301,7 +301,7 @@ static char *get_config_path(void) { const char *current_config_path; static bool load_config(const char *path, struct sway_config *config) { - wlr_log(L_INFO, "Loading config from %s", path); + sway_log(L_INFO, "Loading config from %s", path); current_config_path = path; struct stat sb; @@ -310,13 +310,13 @@ static bool load_config(const char *path, struct sway_config *config) { } if (path == NULL) { - wlr_log(L_ERROR, "Unable to find a config file!"); + sway_log(L_ERROR, "Unable to find a config file!"); return false; } FILE *f = fopen(path, "r"); if (!f) { - wlr_log(L_ERROR, "Unable to open %s for reading", path); + sway_log(L_ERROR, "Unable to open %s for reading", path); return false; } @@ -324,7 +324,7 @@ static bool load_config(const char *path, struct sway_config *config) { fclose(f); if (!config_load_success) { - wlr_log(L_ERROR, "Error(s) loading config!"); + sway_log(L_ERROR, "Error(s) loading config!"); } current_config_path = NULL; @@ -347,7 +347,7 @@ bool load_main_config(const char *file, bool is_active) { config_defaults(config); if (is_active) { - wlr_log(L_DEBUG, "Performing configuration file reload"); + sway_log(L_DEBUG, "Performing configuration file reload"); config->reloading = true; config->active = true; } @@ -363,7 +363,7 @@ bool load_main_config(const char *file, bool is_active) { /* DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); if (!dir) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "%s does not exist, sway will have no security configuration" " and will probably be broken", SYSCONFDIR "/sway/security.d"); } else { @@ -392,7 +392,7 @@ bool load_main_config(const char *file, bool is_active) { if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "Refusing to load %s - it must be owned by root " "and mode 644 or 444", _path); success = false; @@ -430,7 +430,7 @@ static bool load_include_config(const char *path, const char *parent_dir, len = len + strlen(parent_dir) + 2; full_path = malloc(len * sizeof(char)); if (!full_path) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "Unable to allocate full path to included config"); return false; } @@ -441,7 +441,7 @@ static bool load_include_config(const char *path, const char *parent_dir, free(full_path); if (real_path == NULL) { - wlr_log(L_DEBUG, "%s not found.", path); + sway_log(L_DEBUG, "%s not found.", path); return false; } @@ -450,7 +450,7 @@ static bool load_include_config(const char *path, const char *parent_dir, for (j = 0; j < config->config_chain->length; ++j) { char *old_path = config->config_chain->items[j]; if (strcmp(real_path, old_path) == 0) { - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path); free(real_path); @@ -504,7 +504,7 @@ bool load_include_configs(const char *path, struct sway_config *config) { // restore wd if (chdir(wd) < 0) { free(wd); - wlr_log(L_ERROR, "failed to restore working directory"); + sway_log(L_ERROR, "failed to restore working directory"); return false; } @@ -546,13 +546,13 @@ bool read_config(FILE *file, struct sway_config *config) { switch(res->status) { case CMD_FAILURE: case CMD_INVALID: - wlr_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, + sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, line, res->error, config->current_config); success = false; break; case CMD_DEFER: - wlr_log(L_DEBUG, "Deferring command `%s'", line); + sway_log(L_DEBUG, "Deferring command `%s'", line); list_add(config->cmd_queue, strdup(line)); break; @@ -560,7 +560,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_END) { block = CMD_BLOCK_MODE; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -568,7 +568,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_END) { block = CMD_BLOCK_INPUT; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -576,7 +576,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_END) { block = CMD_BLOCK_SEAT; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -584,7 +584,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_END) { block = CMD_BLOCK_BAR; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -592,7 +592,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_BAR) { block = CMD_BLOCK_BAR_COLORS; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -600,7 +600,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_END) { block = CMD_BLOCK_COMMANDS; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -608,7 +608,7 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_END) { block = CMD_BLOCK_IPC; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; @@ -616,56 +616,56 @@ bool read_config(FILE *file, struct sway_config *config) { if (block == CMD_BLOCK_IPC) { block = CMD_BLOCK_IPC_EVENTS; } else { - wlr_log(L_ERROR, "Invalid block '%s'", line); + sway_log(L_ERROR, "Invalid block '%s'", line); } break; case CMD_BLOCK_END: switch(block) { case CMD_BLOCK_MODE: - wlr_log(L_DEBUG, "End of mode block"); + sway_log(L_DEBUG, "End of mode block"); config->current_mode = config->modes->items[0]; block = CMD_BLOCK_END; break; case CMD_BLOCK_INPUT: - wlr_log(L_DEBUG, "End of input block"); + sway_log(L_DEBUG, "End of input block"); block = CMD_BLOCK_END; break; case CMD_BLOCK_SEAT: - wlr_log(L_DEBUG, "End of seat block"); + sway_log(L_DEBUG, "End of seat block"); block = CMD_BLOCK_END; break; case CMD_BLOCK_BAR: - wlr_log(L_DEBUG, "End of bar block"); + sway_log(L_DEBUG, "End of bar block"); config->current_bar = NULL; block = CMD_BLOCK_END; break; case CMD_BLOCK_BAR_COLORS: - wlr_log(L_DEBUG, "End of bar colors block"); + sway_log(L_DEBUG, "End of bar colors block"); block = CMD_BLOCK_BAR; break; case CMD_BLOCK_COMMANDS: - wlr_log(L_DEBUG, "End of commands block"); + sway_log(L_DEBUG, "End of commands block"); block = CMD_BLOCK_END; break; case CMD_BLOCK_IPC: - wlr_log(L_DEBUG, "End of IPC block"); + sway_log(L_DEBUG, "End of IPC block"); block = CMD_BLOCK_END; break; case CMD_BLOCK_IPC_EVENTS: - wlr_log(L_DEBUG, "End of IPC events block"); + sway_log(L_DEBUG, "End of IPC events block"); block = CMD_BLOCK_IPC; break; case CMD_BLOCK_END: - wlr_log(L_ERROR, "Unmatched }"); + sway_log(L_ERROR, "Unmatched }"); break; default:; @@ -699,7 +699,7 @@ char *do_var_replacement(char *str) { int vvlen = strlen(var->value); char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); if (!newstr) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "Unable to allocate replacement " "during variable expansion"); break; diff --git a/sway/config/bar.c b/sway/config/bar.c index 5a97c3cc5..86157449c 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c @@ -16,10 +16,10 @@ #include "log.h" static void terminate_swaybar(pid_t pid) { - wlr_log(L_DEBUG, "Terminating swaybar %d", pid); + sway_log(L_DEBUG, "Terminating swaybar %d", pid); int ret = kill(-pid, SIGTERM); if (ret != 0) { - wlr_log_errno(L_ERROR, "Unable to terminate swaybar %d", pid); + sway_log_errno(L_ERROR, "Unable to terminate swaybar %d", pid); } else { int status; waitpid(pid, &status, 0); @@ -157,7 +157,7 @@ void invoke_swaybar(struct bar_config *bar) { // Pipe to communicate errors int filedes[2]; if (pipe(filedes) == -1) { - wlr_log(L_ERROR, "Pipe setup failed! Cannot fork into bar"); + sway_log(L_ERROR, "Pipe setup failed! Cannot fork into bar"); return; } @@ -187,17 +187,17 @@ void invoke_swaybar(struct bar_config *bar) { execvp(cmd[0], cmd); exit(1); } - wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid); + sway_log(L_DEBUG, "Spawned swaybar %d", bar->pid); close(filedes[0]); ssize_t len; if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) { char *buf = malloc(len); if(!buf) { - wlr_log(L_ERROR, "Cannot allocate error string"); + sway_log(L_ERROR, "Cannot allocate error string"); return; } if (read(filedes[1], buf, len)) { - wlr_log(L_ERROR, "%s", buf); + sway_log(L_ERROR, "%s", buf); } free(buf); } @@ -234,7 +234,7 @@ void load_swaybars() { if (bar->pid != 0) { terminate_swaybar(bar->pid); } - wlr_log(L_DEBUG, "Invoking swaybar for bar id '%s'", bar->id); + sway_log(L_DEBUG, "Invoking swaybar for bar id '%s'", bar->id); invoke_swaybar(bar); } } diff --git a/sway/config/input.c b/sway/config/input.c index 17303ccc9..360ef61af 100644 --- a/sway/config/input.c +++ b/sway/config/input.c @@ -8,13 +8,13 @@ struct input_config *new_input_config(const char* identifier) { struct input_config *input = calloc(1, sizeof(struct input_config)); if (!input) { - wlr_log(L_DEBUG, "Unable to allocate input config"); + sway_log(L_DEBUG, "Unable to allocate input config"); return NULL; } - wlr_log(L_DEBUG, "new_input_config(%s)", identifier); + sway_log(L_DEBUG, "new_input_config(%s)", identifier); if (!(input->identifier = strdup(identifier))) { free(input); - wlr_log(L_DEBUG, "Unable to allocate input config"); + sway_log(L_DEBUG, "Unable to allocate input config"); return NULL; } @@ -112,7 +112,7 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { struct input_config *copy_input_config(struct input_config *ic) { struct input_config *copy = calloc(1, sizeof(struct input_config)); if (copy == NULL) { - wlr_log(L_ERROR, "could not allocate input config"); + sway_log(L_ERROR, "could not allocate input config"); return NULL; } merge_input_config(copy, ic); diff --git a/sway/config/output.c b/sway/config/output.c index ee2440eab..c175e2b43 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -90,7 +90,7 @@ static void set_mode(struct wlr_output *output, int width, int height, float refresh_rate) { int mhz = (int)(refresh_rate * 1000); if (wl_list_empty(&output->modes)) { - wlr_log(L_DEBUG, "Assigning custom mode to %s", output->name); + sway_log(L_DEBUG, "Assigning custom mode to %s", output->name); wlr_output_set_custom_mode(output, width, height, mhz); return; } @@ -106,9 +106,9 @@ static void set_mode(struct wlr_output *output, int width, int height, } } if (!best) { - wlr_log(L_ERROR, "Configured mode for %s not available", output->name); + sway_log(L_ERROR, "Configured mode for %s not available", output->name); } else { - wlr_log(L_DEBUG, "Assigning configured mode to %s", output->name); + sway_log(L_DEBUG, "Assigning configured mode to %s", output->name); wlr_output_set_mode(output, best); } } @@ -116,7 +116,7 @@ static void set_mode(struct wlr_output *output, int width, int height, void terminate_swaybg(pid_t pid) { int ret = kill(pid, SIGTERM); if (ret != 0) { - wlr_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid); + sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid); } else { int status; waitpid(pid, &status, 0); @@ -142,22 +142,22 @@ void apply_output_config(struct output_config *oc, struct sway_container *output } if (oc && oc->width > 0 && oc->height > 0) { - wlr_log(L_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width, + sway_log(L_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width, oc->height, oc->refresh_rate); set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); } if (oc && oc->scale > 0) { - wlr_log(L_DEBUG, "Set %s scale to %f", oc->name, oc->scale); + sway_log(L_DEBUG, "Set %s scale to %f", oc->name, oc->scale); wlr_output_set_scale(wlr_output, oc->scale); } if (oc && oc->transform >= 0) { - wlr_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); + sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); wlr_output_set_transform(wlr_output, oc->transform); } // Find position for it if (oc && (oc->x != -1 || oc->y != -1)) { - wlr_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); + sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); wlr_output_layout_add(output_layout, wlr_output, oc->x, oc->y); } else { wlr_output_layout_add_auto(output_layout, wlr_output); @@ -185,7 +185,7 @@ void apply_output_config(struct output_config *oc, struct sway_container *output terminate_swaybg(output->sway_output->bg_pid); } - wlr_log(L_DEBUG, "Setting background for output %d to %s", + sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background); size_t len = snprintf(NULL, 0, "%s %d %s %s", @@ -193,13 +193,13 @@ void apply_output_config(struct output_config *oc, struct sway_container *output output_i, oc->background, oc->background_option); char *command = malloc(len + 1); if (!command) { - wlr_log(L_DEBUG, "Unable to allocate swaybg command"); + sway_log(L_DEBUG, "Unable to allocate swaybg command"); return; } snprintf(command, len + 1, "%s %d %s %s", config->swaybg_command ? config->swaybg_command : "swaybg", output_i, oc->background, oc->background_option); - wlr_log(L_DEBUG, "-> %s", command); + sway_log(L_DEBUG, "-> %s", command); char *const cmd[] = { "sh", "-c", command, NULL }; output->sway_output->bg_pid = fork(); @@ -210,11 +210,11 @@ void apply_output_config(struct output_config *oc, struct sway_container *output if (oc && oc->dpms_state != DPMS_IGNORE) { switch (oc->dpms_state) { case DPMS_ON: - wlr_log(L_DEBUG, "Turning on screen"); + sway_log(L_DEBUG, "Turning on screen"); wlr_output_enable(wlr_output, true); break; case DPMS_OFF: - wlr_log(L_DEBUG, "Turning off screen"); + sway_log(L_DEBUG, "Turning off screen"); wlr_output_enable(wlr_output, false); break; case DPMS_IGNORE: diff --git a/sway/config/seat.c b/sway/config/seat.c index bd8b45c87..3cc4405ea 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c @@ -7,11 +7,11 @@ struct seat_config *new_seat_config(const char* name) { struct seat_config *seat = calloc(1, sizeof(struct seat_config)); if (!seat) { - wlr_log(L_DEBUG, "Unable to allocate seat config"); + sway_log(L_DEBUG, "Unable to allocate seat config"); return NULL; } - wlr_log(L_DEBUG, "new_seat_config(%s)", name); + sway_log(L_DEBUG, "new_seat_config(%s)", name); seat->name = strdup(name); if (!sway_assert(seat->name, "could not allocate name for seat")) { free(seat); @@ -34,7 +34,7 @@ struct seat_attachment_config *seat_attachment_config_new() { struct seat_attachment_config *attachment = calloc(1, sizeof(struct seat_attachment_config)); if (!attachment) { - wlr_log(L_DEBUG, "cannot allocate attachment config"); + sway_log(L_DEBUG, "cannot allocate attachment config"); return NULL; } return attachment; diff --git a/sway/criteria.c b/sway/criteria.c index 4295cacc0..d300009b1 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -484,7 +484,7 @@ struct criteria *criteria_parse(char *raw, char **error_arg) { } unescape(value); } - wlr_log(L_DEBUG, "Found pair: %s=%s", name, value); + sway_log(L_DEBUG, "Found pair: %s=%s", name, value); if (!parse_token(criteria, name, value)) { *error_arg = error; goto cleanup; diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index b60aa4873..c093888e3 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -174,7 +174,7 @@ void arrange_layers(struct sway_output *output) { if (memcmp(&usable_area, &output->usable_area, sizeof(struct wlr_box)) != 0) { - wlr_log(L_DEBUG, "Usable area changed, rearranging output"); + sway_log(L_DEBUG, "Usable area changed, rearranging output"); memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); arrange_output(output->swayc); } @@ -262,7 +262,7 @@ static void unmap(struct sway_layer_surface *sway_layer) { static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_layer_surface *sway_layer = wl_container_of(listener, sway_layer, destroy); - wlr_log(L_DEBUG, "Layer surface destroyed (%s)", + sway_log(L_DEBUG, "Layer surface destroyed (%s)", sway_layer->layer_surface->namespace); if (sway_layer->layer_surface->mapped) { unmap(sway_layer); @@ -304,7 +304,7 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { struct wlr_layer_surface *layer_surface = data; struct sway_server *server = wl_container_of(listener, server, layer_shell_surface); - wlr_log(L_DEBUG, "new layer surface: namespace %s layer %d anchor %d " + sway_log(L_DEBUG, "new layer surface: namespace %s layer %d anchor %d " "size %dx%d margin %d,%d,%d,%d", layer_surface->namespace, layer_surface->layer, layer_surface->layer, layer_surface->client_pending.desired_width, diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 765647fd3..ecafe27b7 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1106,7 +1106,7 @@ static void handle_scale(struct wl_listener *listener, void *data) { void handle_new_output(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, new_output); struct wlr_output *wlr_output = data; - wlr_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); + sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); struct sway_output *output = calloc(1, sizeof(struct sway_output)); if (!output) { diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 9a0d282b2..5fa14c7b1 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -241,11 +241,11 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { struct wlr_xdg_surface *xdg_surface = data; if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - wlr_log(L_DEBUG, "New xdg_shell popup"); + sway_log(L_DEBUG, "New xdg_shell popup"); return; } - wlr_log(L_DEBUG, "New xdg_shell toplevel title='%s' app_id='%s'", + sway_log(L_DEBUG, "New xdg_shell toplevel title='%s' app_id='%s'", xdg_surface->toplevel->title, xdg_surface->toplevel->app_id); wlr_xdg_surface_ping(xdg_surface); wlr_xdg_toplevel_set_maximized(xdg_surface, true); diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index d098c7975..07c0b5aa3 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -241,11 +241,11 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { struct wlr_xdg_surface_v6 *xdg_surface = data; if (xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { - wlr_log(L_DEBUG, "New xdg_shell_v6 popup"); + sway_log(L_DEBUG, "New xdg_shell_v6 popup"); return; } - wlr_log(L_DEBUG, "New xdg_shell_v6 toplevel title='%s' app_id='%s'", + sway_log(L_DEBUG, "New xdg_shell_v6 toplevel title='%s' app_id='%s'", xdg_surface->toplevel->title, xdg_surface->toplevel->app_id); wlr_xdg_surface_v6_ping(xdg_surface); wlr_xdg_toplevel_v6_set_maximized(xdg_surface, true); diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 6a99a66aa..4caf35ab0 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -93,7 +93,7 @@ static struct sway_xwayland_unmanaged *create_unmanaged( struct sway_xwayland_unmanaged *surface = calloc(1, sizeof(struct sway_xwayland_unmanaged)); if (surface == NULL) { - wlr_log(L_ERROR, "Allocation failed"); + sway_log(L_ERROR, "Allocation failed"); return NULL; } @@ -341,12 +341,12 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { if (wlr_xwayland_surface_is_unmanaged(xsurface) || xsurface->override_redirect) { - wlr_log(L_DEBUG, "New xwayland unmanaged surface"); + sway_log(L_DEBUG, "New xwayland unmanaged surface"); create_unmanaged(xsurface); return; } - wlr_log(L_DEBUG, "New xwayland surface title='%s' class='%s'", + sway_log(L_DEBUG, "New xwayland surface title='%s' class='%s'", xsurface->title, xsurface->class); struct sway_xwayland_view *xwayland_view = diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 9a0b4f01b..feb722a97 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -426,7 +426,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, // TODO: check cursor mode if (focused_client == NULL || event->seat_client->client != focused_client) { - wlr_log(L_DEBUG, "denying request to set cursor from unfocused client"); + sway_log(L_DEBUG, "denying request to set cursor from unfocused client"); return; } diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 29b47a7ba..0e68a6b53 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -61,7 +61,7 @@ static char *get_device_identifier(struct wlr_input_device *device) { int len = snprintf(NULL, 0, fmt, vendor, product, name) + 1; char *identifier = malloc(len); if (!identifier) { - wlr_log(L_ERROR, "Unable to allocate unique input device name"); + sway_log(L_ERROR, "Unable to allocate unique input device name"); return NULL; } @@ -104,74 +104,74 @@ static void input_manager_libinput_config_pointer( } libinput_device = wlr_libinput_get_device_handle(wlr_device); - wlr_log(L_DEBUG, "input_manager_libinput_config_pointer(%s)", + sway_log(L_DEBUG, "input_manager_libinput_config_pointer(%s)", ic->identifier); if (ic->accel_profile != INT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_profile(%d)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_profile(%d)", ic->identifier, ic->accel_profile); libinput_device_config_accel_set_profile(libinput_device, ic->accel_profile); } if (ic->click_method != INT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) click_set_method(%d)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) click_set_method(%d)", ic->identifier, ic->click_method); libinput_device_config_click_set_method(libinput_device, ic->click_method); } if (ic->drag_lock != INT_MIN) { - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)", ic->identifier, ic->click_method); libinput_device_config_tap_set_drag_lock_enabled(libinput_device, ic->drag_lock); } if (ic->dwt != INT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) dwt_set_enabled(%d)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) dwt_set_enabled(%d)", ic->identifier, ic->dwt); libinput_device_config_dwt_set_enabled(libinput_device, ic->dwt); } if (ic->left_handed != INT_MIN) { - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "libinput_config_pointer(%s) left_handed_set_enabled(%d)", ic->identifier, ic->left_handed); libinput_device_config_left_handed_set(libinput_device, ic->left_handed); } if (ic->middle_emulation != INT_MIN) { - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "libinput_config_pointer(%s) middle_emulation_set_enabled(%d)", ic->identifier, ic->middle_emulation); libinput_device_config_middle_emulation_set_enabled(libinput_device, ic->middle_emulation); } if (ic->natural_scroll != INT_MIN) { - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "libinput_config_pointer(%s) natural_scroll_set_enabled(%d)", ic->identifier, ic->natural_scroll); libinput_device_config_scroll_set_natural_scroll_enabled( libinput_device, ic->natural_scroll); } if (ic->pointer_accel != FLT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_speed(%f)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) accel_set_speed(%f)", ic->identifier, ic->pointer_accel); libinput_device_config_accel_set_speed(libinput_device, ic->pointer_accel); } if (ic->scroll_method != INT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) scroll_set_method(%d)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) scroll_set_method(%d)", ic->identifier, ic->scroll_method); libinput_device_config_scroll_set_method(libinput_device, ic->scroll_method); } if (ic->send_events != INT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) send_events_set_mode(%d)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) send_events_set_mode(%d)", ic->identifier, ic->send_events); libinput_device_config_send_events_set_mode(libinput_device, ic->send_events); } if (ic->tap != INT_MIN) { - wlr_log(L_DEBUG, "libinput_config_pointer(%s) tap_set_enabled(%d)", + sway_log(L_DEBUG, "libinput_config_pointer(%s) tap_set_enabled(%d)", ic->identifier, ic->tap); libinput_device_config_tap_set_enabled(libinput_device, ic->tap); } @@ -187,7 +187,7 @@ static void handle_device_destroy(struct wl_listener *listener, void *data) { return; } - wlr_log(L_DEBUG, "removing device: '%s'", + sway_log(L_DEBUG, "removing device: '%s'", input_device->identifier); struct sway_seat *seat = NULL; @@ -217,7 +217,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) { input_device->identifier = get_device_identifier(device); wl_list_insert(&input->devices, &input_device->link); - wlr_log(L_DEBUG, "adding device: '%s'", + sway_log(L_DEBUG, "adding device: '%s'", input_device->identifier); if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { @@ -226,7 +226,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) { struct sway_seat *seat = NULL; if (!input_has_seat_configuration(input)) { - wlr_log(L_DEBUG, "no seat configuration, using default seat"); + sway_log(L_DEBUG, "no seat configuration, using default seat"); seat = input_manager_get_seat(input, default_seat); seat_add_device(seat, input_device); return; @@ -256,7 +256,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) { } if (!added) { - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "device '%s' is not configured on any seats", input_device->identifier); } @@ -282,7 +282,7 @@ static void handle_inhibit_deactivate(struct wl_listener *listener, void *data) seat_set_exclusive_client(seat, NULL); struct sway_container *previous = seat_get_focus(seat); if (previous) { - wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, + sway_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, container_type_to_str(previous->type), previous->name); // Hack to get seat to re-focus the return value of get_focus seat_set_focus(seat, previous->parent); @@ -359,7 +359,7 @@ void input_manager_apply_input_config(struct sway_input_manager *input, void input_manager_apply_seat_config(struct sway_input_manager *input, struct seat_config *seat_config) { - wlr_log(L_DEBUG, "applying new seat config for seat %s", + sway_log(L_DEBUG, "applying new seat config for seat %s", seat_config->name); struct sway_seat *seat = input_manager_get_seat(input, seat_config->name); if (!seat) { diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index c07557db8..8bf5abff6 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -93,13 +93,13 @@ static bool binding_matches_key_state(struct sway_binding *binding, static void keyboard_execute_command(struct sway_keyboard *keyboard, struct sway_binding *binding) { - wlr_log(L_DEBUG, "running command for binding: %s", + sway_log(L_DEBUG, "running command for binding: %s", binding->command); config_clear_handler_context(config); config->handler_context.seat = keyboard->seat_device->sway_seat; struct cmd_results *results = execute_command(binding->command, NULL); if (results->status != CMD_SUCCESS) { - wlr_log(L_DEBUG, "could not run command for binding: %s (%s)", + sway_log(L_DEBUG, "could not run command for binding: %s (%s)", binding->command, results->error); } free_cmd_results(results); @@ -473,7 +473,7 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) { xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); if (!keymap) { - wlr_log(L_DEBUG, "cannot configure keyboard: keymap does not exist"); + sway_log(L_DEBUG, "cannot configure keyboard: keymap does not exist"); xkb_context_unref(context); return; } diff --git a/sway/input/seat.c b/sway/input/seat.c index 7a3e928a3..d6e185054 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -72,7 +72,7 @@ static void seat_send_activate(struct sway_container *con, struct sway_seat *seat) { if (con->type == C_VIEW) { if (!seat_is_input_allowed(seat, con->sway_view->surface)) { - wlr_log(L_DEBUG, "Refusing to set focus, input is inhibited"); + sway_log(L_DEBUG, "Refusing to set focus, input is inhibited"); return; } view_set_activated(con->sway_view, true); @@ -205,7 +205,7 @@ static struct sway_seat_container *seat_container_from_container( seat_con = calloc(1, sizeof(struct sway_seat_container)); if (seat_con == NULL) { - wlr_log(L_ERROR, "could not allocate seat container"); + sway_log(L_ERROR, "could not allocate seat container"); return NULL; } @@ -290,7 +290,7 @@ static void seat_apply_input_config(struct sway_seat *seat, struct input_config *ic = input_device_get_config( sway_device->input_device); if (ic != NULL) { - wlr_log(L_DEBUG, "Applying input config to %s", + sway_log(L_DEBUG, "Applying input config to %s", sway_device->input_device->identifier); mapped_to_output = ic->mapped_to_output; @@ -300,7 +300,7 @@ static void seat_apply_input_config(struct sway_seat *seat, mapped_to_output = sway_device->input_device->wlr_device->output_name; } if (mapped_to_output != NULL) { - wlr_log(L_DEBUG, "Mapping input device %s to output %s", + sway_log(L_DEBUG, "Mapping input device %s to output %s", sway_device->input_device->identifier, mapped_to_output); struct sway_container *output = NULL; for (int i = 0; i < root_container.children->length; ++i) { @@ -314,7 +314,7 @@ static void seat_apply_input_config(struct sway_seat *seat, wlr_cursor_map_input_to_output(seat->cursor->cursor, sway_device->input_device->wlr_device, output->sway_output->wlr_output); - wlr_log(L_DEBUG, "Mapped to output %s", output->name); + sway_log(L_DEBUG, "Mapped to output %s", output->name); } } } @@ -394,7 +394,7 @@ void seat_configure_device(struct sway_seat *seat, seat_configure_tablet_tool(seat, seat_device); break; case WLR_INPUT_DEVICE_TABLET_PAD: - wlr_log(L_DEBUG, "TODO: configure tablet pad"); + sway_log(L_DEBUG, "TODO: configure tablet pad"); break; } } @@ -409,11 +409,11 @@ void seat_add_device(struct sway_seat *seat, struct sway_seat_device *seat_device = calloc(1, sizeof(struct sway_seat_device)); if (!seat_device) { - wlr_log(L_DEBUG, "could not allocate seat device"); + sway_log(L_DEBUG, "could not allocate seat device"); return; } - wlr_log(L_DEBUG, "adding device %s to seat %s", + sway_log(L_DEBUG, "adding device %s to seat %s", input_device->identifier, seat->wlr_seat->name); seat_device->sway_seat = seat; @@ -432,7 +432,7 @@ void seat_remove_device(struct sway_seat *seat, return; } - wlr_log(L_DEBUG, "removing device %s from seat %s", + sway_log(L_DEBUG, "removing device %s from seat %s", input_device->identifier, seat->wlr_seat->name); seat_device_destroy(seat_device); @@ -652,7 +652,7 @@ void seat_set_focus_layer(struct sway_seat *seat, seat->focused_layer = NULL; struct sway_container *previous = seat_get_focus(seat); if (previous) { - wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, + sway_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, container_type_to_str(previous->type), previous->name); // Hack to get seat to re-focus the return value of get_focus seat_set_focus(seat, previous->parent); diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 15ed6f800..6fc633822 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -127,32 +127,32 @@ struct sockaddr_un *ipc_user_sockaddr(void) { int ipc_handle_connection(int fd, uint32_t mask, void *data) { (void) fd; struct sway_server *server = data; - wlr_log(L_DEBUG, "Event on IPC listening socket"); + sway_log(L_DEBUG, "Event on IPC listening socket"); assert(mask == WL_EVENT_READABLE); int client_fd = accept(ipc_socket, NULL, NULL); if (client_fd == -1) { - wlr_log_errno(L_ERROR, "Unable to accept IPC client connection"); + sway_log_errno(L_ERROR, "Unable to accept IPC client connection"); return 0; } int flags; if ((flags = fcntl(client_fd, F_GETFD)) == -1 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { - wlr_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket"); + sway_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket"); close(client_fd); return 0; } if ((flags = fcntl(client_fd, F_GETFL)) == -1 || fcntl(client_fd, F_SETFL, flags|O_NONBLOCK) == -1) { - wlr_log_errno(L_ERROR, "Unable to set NONBLOCK on IPC client socket"); + sway_log_errno(L_ERROR, "Unable to set NONBLOCK on IPC client socket"); close(client_fd); return 0; } struct ipc_client *client = malloc(sizeof(struct ipc_client)); if (!client) { - wlr_log(L_ERROR, "Unable to allocate ipc client"); + sway_log(L_ERROR, "Unable to allocate ipc client"); close(client_fd); return 0; } @@ -168,12 +168,12 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) { client->write_buffer_len = 0; client->write_buffer = malloc(client->write_buffer_size); if (!client->write_buffer) { - wlr_log(L_ERROR, "Unable to allocate ipc client write buffer"); + sway_log(L_ERROR, "Unable to allocate ipc client write buffer"); close(client_fd); return 0; } - wlr_log(L_DEBUG, "New client: fd %d", client_fd); + sway_log(L_DEBUG, "New client: fd %d", client_fd); list_add(ipc_client_list, client); return 0; } @@ -184,22 +184,22 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { struct ipc_client *client = data; if (mask & WL_EVENT_ERROR) { - wlr_log(L_ERROR, "IPC Client socket error, removing client"); + sway_log(L_ERROR, "IPC Client socket error, removing client"); ipc_client_disconnect(client); return 0; } if (mask & WL_EVENT_HANGUP) { - wlr_log(L_DEBUG, "Client %d hung up", client->fd); + sway_log(L_DEBUG, "Client %d hung up", client->fd); ipc_client_disconnect(client); return 0; } - wlr_log(L_DEBUG, "Client %d readable", client->fd); + sway_log(L_DEBUG, "Client %d readable", client->fd); int read_available; if (ioctl(client_fd, FIONREAD, &read_available) == -1) { - wlr_log_errno(L_INFO, "Unable to read IPC socket buffer size"); + sway_log_errno(L_INFO, "Unable to read IPC socket buffer size"); ipc_client_disconnect(client); return 0; } @@ -221,13 +221,13 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { // Should be fully available, because read_available >= ipc_header_size ssize_t received = recv(client_fd, buf, ipc_header_size, 0); if (received == -1) { - wlr_log_errno(L_INFO, "Unable to receive header from IPC client"); + sway_log_errno(L_INFO, "Unable to receive header from IPC client"); ipc_client_disconnect(client); return 0; } if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) { - wlr_log(L_DEBUG, "IPC header check failed"); + sway_log(L_DEBUG, "IPC header check failed"); ipc_client_disconnect(client); return 0; } @@ -261,7 +261,7 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event) } client->current_command = event; if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) { - wlr_log_errno(L_INFO, "Unable to send reply to IPC client"); + sway_log_errno(L_INFO, "Unable to send reply to IPC client"); ipc_client_disconnect(client); } } @@ -272,7 +272,7 @@ void ipc_event_workspace(struct sway_container *old, if (!ipc_has_event_listeners(IPC_EVENT_WORKSPACE)) { return; } - wlr_log(L_DEBUG, "Sending workspace::%s event", change); + sway_log(L_DEBUG, "Sending workspace::%s event", change); json_object *obj = json_object_new_object(); json_object_object_add(obj, "change", json_object_new_string(change)); if (strcmp("focus", change) == 0) { @@ -300,7 +300,7 @@ void ipc_event_window(struct sway_container *window, const char *change) { if (!ipc_has_event_listeners(IPC_EVENT_WINDOW)) { return; } - wlr_log(L_DEBUG, "Sending window::%s event", change); + sway_log(L_DEBUG, "Sending window::%s event", change); json_object *obj = json_object_new_object(); json_object_object_add(obj, "change", json_object_new_string(change)); json_object_object_add(obj, "container", ipc_json_describe_container_recursive(window)); @@ -314,7 +314,7 @@ void ipc_event_barconfig_update(struct bar_config *bar) { if (!ipc_has_event_listeners(IPC_EVENT_BARCONFIG_UPDATE)) { return; } - wlr_log(L_DEBUG, "Sending barconfig_update event"); + sway_log(L_DEBUG, "Sending barconfig_update event"); json_object *json = ipc_json_describe_bar_config(bar); const char *json_string = json_object_to_json_string(json); @@ -326,7 +326,7 @@ void ipc_event_mode(const char *mode) { if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { return; } - wlr_log(L_DEBUG, "Sending mode::%s event", mode); + sway_log(L_DEBUG, "Sending mode::%s event", mode); json_object *obj = json_object_new_object(); json_object_object_add(obj, "change", json_object_new_string(mode)); @@ -339,13 +339,13 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { struct ipc_client *client = data; if (mask & WL_EVENT_ERROR) { - wlr_log(L_ERROR, "IPC Client socket error, removing client"); + sway_log(L_ERROR, "IPC Client socket error, removing client"); ipc_client_disconnect(client); return 0; } if (mask & WL_EVENT_HANGUP) { - wlr_log(L_DEBUG, "Client %d hung up", client->fd); + sway_log(L_DEBUG, "Client %d hung up", client->fd); ipc_client_disconnect(client); return 0; } @@ -354,14 +354,14 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { return 0; } - wlr_log(L_DEBUG, "Client %d writable", client->fd); + sway_log(L_DEBUG, "Client %d writable", client->fd); ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); if (written == -1 && errno == EAGAIN) { return 0; } else if (written == -1) { - wlr_log_errno(L_INFO, "Unable to send data from queue to IPC client"); + sway_log_errno(L_INFO, "Unable to send data from queue to IPC client"); ipc_client_disconnect(client); return 0; } @@ -386,7 +386,7 @@ void ipc_client_disconnect(struct ipc_client *client) { shutdown(client->fd, SHUT_RDWR); } - wlr_log(L_INFO, "IPC Client %d disconnected", client->fd); + sway_log(L_INFO, "IPC Client %d disconnected", client->fd); wl_event_source_remove(client->event_source); if (client->writable_event_source) { wl_event_source_remove(client->writable_event_source); @@ -447,7 +447,7 @@ void ipc_client_handle_command(struct ipc_client *client) { char *buf = malloc(client->payload_length + 1); if (!buf) { - wlr_log_errno(L_INFO, "Unable to allocate IPC payload"); + sway_log_errno(L_INFO, "Unable to allocate IPC payload"); ipc_client_disconnect(client); return; } @@ -456,7 +456,7 @@ void ipc_client_handle_command(struct ipc_client *client) { ssize_t received = recv(client->fd, buf, client->payload_length, 0); if (received == -1) { - wlr_log_errno(L_INFO, "Unable to receive payload from IPC client"); + sway_log_errno(L_INFO, "Unable to receive payload from IPC client"); ipc_client_disconnect(client); free(buf); return; @@ -512,7 +512,7 @@ void ipc_client_handle_command(struct ipc_client *client) { struct json_object *request = json_tokener_parse(buf); if (request == NULL) { ipc_send_reply(client, "{\"success\": false}", 18); - wlr_log_errno(L_INFO, "Failed to read request"); + sway_log_errno(L_INFO, "Failed to read request"); goto exit_cleanup; } @@ -534,7 +534,7 @@ void ipc_client_handle_command(struct ipc_client *client) { } else { ipc_send_reply(client, "{\"success\": false}", 18); json_object_put(request); - wlr_log_errno(L_INFO, "Failed to parse request"); + sway_log_errno(L_INFO, "Failed to parse request"); goto exit_cleanup; } } @@ -636,12 +636,12 @@ void ipc_client_handle_command(struct ipc_client *client) { } default: - wlr_log(L_INFO, "Unknown IPC command type %i", client->current_command); + sway_log(L_INFO, "Unknown IPC command type %i", client->current_command); goto exit_cleanup; } ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied)); - wlr_log(L_DEBUG, "Denied IPC client access to %i", client->current_command); + sway_log(L_DEBUG, "Denied IPC client access to %i", client->current_command); exit_cleanup: client->payload_length = 0; @@ -665,14 +665,14 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay } if (client->write_buffer_size > 4e6) { // 4 MB - wlr_log(L_ERROR, "Client write buffer too big, disconnecting client"); + sway_log(L_ERROR, "Client write buffer too big, disconnecting client"); ipc_client_disconnect(client); return false; } char *new_buffer = realloc(client->write_buffer, client->write_buffer_size); if (!new_buffer) { - wlr_log(L_ERROR, "Unable to reallocate ipc client write buffer"); + sway_log(L_ERROR, "Unable to reallocate ipc client write buffer"); ipc_client_disconnect(client); return false; } @@ -689,6 +689,6 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay ipc_client_handle_writable, client); } - wlr_log(L_DEBUG, "Added IPC reply to client %d queue: %s", client->fd, payload); + sway_log(L_DEBUG, "Added IPC reply to client %d queue: %s", client->fd, payload); return true; } diff --git a/sway/main.c b/sway/main.c index e03b8e3af..8abb083a7 100644 --- a/sway/main.c +++ b/sway/main.c @@ -15,7 +15,7 @@ #include #include #endif -#include +#include "log.h" #include "sway/commands.h" #include "sway/config.h" #include "sway/debug.h" @@ -128,7 +128,7 @@ static void log_env() { "SWAYSOCK" }; for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) { - wlr_log(L_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); + sway_log(L_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); } } @@ -143,14 +143,14 @@ static void log_distro() { for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) { FILE *f = fopen(paths[i], "r"); if (f) { - wlr_log(L_INFO, "Contents of %s:", paths[i]); + sway_log(L_INFO, "Contents of %s:", paths[i]); while (!feof(f)) { char *line; if (!(line = read_line(f))) { break; } if (*line) { - wlr_log(L_INFO, "%s", line); + sway_log(L_INFO, "%s", line); } free(line); } @@ -163,7 +163,7 @@ static void log_kernel() { return; FILE *f = popen("uname -a", "r"); if (!f) { - wlr_log(L_INFO, "Unable to determine kernel version"); + sway_log(L_INFO, "Unable to determine kernel version"); return; } while (!feof(f)) { @@ -172,7 +172,7 @@ static void log_kernel() { break; } if (*line) { - wlr_log(L_INFO, "%s", line); + sway_log(L_INFO, "%s", line); } free(line); } @@ -183,14 +183,14 @@ static void security_sanity_check() { // TODO: Notify users visually if this has issues struct stat s; if (stat("/proc", &s)) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "!! DANGER !! /proc is not available - sway CANNOT enforce security rules!"); } #ifdef __linux__ cap_flag_value_t v; cap_t cap = cap_get_proc(); if (!cap || cap_get_flag(cap, CAP_SYS_PTRACE, CAP_PERMITTED, &v) != 0 || v != CAP_SET) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "!! DANGER !! Sway does not have CAP_SYS_PTRACE and cannot enforce security rules for processes running as other users."); } if (cap) { @@ -206,13 +206,13 @@ static void executable_sanity_check() { stat(exe, &sb); // We assume that cap_get_file returning NULL implies ENODATA if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) { - wlr_log(L_ERROR, + sway_log(L_ERROR, "sway executable has both the s(g)uid bit AND file caps set."); - wlr_log(L_ERROR, + sway_log(L_ERROR, "This is strongly discouraged (and completely broken)."); - wlr_log(L_ERROR, + sway_log(L_ERROR, "Please clear one of them (either the suid bit, or the file caps)."); - wlr_log(L_ERROR, + sway_log(L_ERROR, "If unsure, strip the file caps."); exit(EXIT_FAILURE); } @@ -223,16 +223,16 @@ static void executable_sanity_check() { static void drop_permissions(bool keep_caps) { if (getuid() != geteuid() || getgid() != getegid()) { if (setgid(getgid()) != 0) { - wlr_log(L_ERROR, "Unable to drop root"); + sway_log(L_ERROR, "Unable to drop root"); exit(EXIT_FAILURE); } if (setuid(getuid()) != 0) { - wlr_log(L_ERROR, "Unable to drop root"); + sway_log(L_ERROR, "Unable to drop root"); exit(EXIT_FAILURE); } } if (setuid(0) != -1) { - wlr_log(L_ERROR, "Root privileges can be restored."); + sway_log(L_ERROR, "Root privileges can be restored."); exit(EXIT_FAILURE); } #ifdef __linux__ @@ -240,11 +240,11 @@ static void drop_permissions(bool keep_caps) { // Drop every cap except CAP_SYS_PTRACE cap_t caps = cap_init(); cap_value_t keep = CAP_SYS_PTRACE; - wlr_log(L_INFO, "Dropping extra capabilities"); + sway_log(L_INFO, "Dropping extra capabilities"); if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) || cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) || cap_set_proc(caps)) { - wlr_log(L_ERROR, "Failed to drop extra capabilities"); + sway_log(L_ERROR, "Failed to drop extra capabilities"); exit(EXIT_FAILURE); } } @@ -335,22 +335,22 @@ int main(int argc, char **argv) { // TODO: switch logging over to wlroots? if (debug) { - wlr_log_init(L_DEBUG, NULL); + sway_log_init(L_DEBUG, NULL); } else if (verbose || validate) { - wlr_log_init(L_INFO, NULL); + sway_log_init(L_INFO, NULL); } else { - wlr_log_init(L_ERROR, NULL); + sway_log_init(L_ERROR, NULL); } if (optind < argc) { // Behave as IPC client if(optind != 1) { - wlr_log(L_ERROR, "Don't use options with the IPC client"); + sway_log(L_ERROR, "Don't use options with the IPC client"); exit(EXIT_FAILURE); } drop_permissions(false); char *socket_path = getenv("SWAYSOCK"); if (!socket_path) { - wlr_log(L_ERROR, "Unable to retrieve socket path"); + sway_log(L_ERROR, "Unable to retrieve socket path"); exit(EXIT_FAILURE); } char *command = join_args(argv + optind, argc - optind); @@ -364,7 +364,7 @@ int main(int argc, char **argv) { if (getuid() != geteuid() || getgid() != getegid()) { // Retain capabilities after setuid() if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { - wlr_log(L_ERROR, "Cannot keep caps after setuid()"); + sway_log(L_ERROR, "Cannot keep caps after setuid()"); exit(EXIT_FAILURE); } suid = true; @@ -385,7 +385,7 @@ int main(int argc, char **argv) { // prevent ipc from crashing sway signal(SIGPIPE, SIG_IGN); - wlr_log(L_INFO, "Starting sway version " SWAY_VERSION); + sway_log(L_INFO, "Starting sway version " SWAY_VERSION); layout_init(); @@ -417,7 +417,7 @@ int main(int argc, char **argv) { char *line = config->cmd_queue->items[0]; struct cmd_results *res = execute_command(line, NULL); if (res->status != CMD_SUCCESS) { - wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error); + sway_log(L_ERROR, "Error on line '%s': %s", line, res->error); } free_cmd_results(res); free(line); @@ -428,7 +428,7 @@ int main(int argc, char **argv) { server_run(&server); } - wlr_log(L_INFO, "Shutting down sway"); + sway_log(L_INFO, "Shutting down sway"); server_fini(&server); diff --git a/sway/server.c b/sway/server.c index e47cc5b67..1de748b34 100644 --- a/sway/server.c +++ b/sway/server.c @@ -16,9 +16,9 @@ #include #include #include -#include // TODO WLR: make Xwayland optional #include +#include "log.h" #include "sway/config.h" #include "sway/input/input-manager.h" #include "sway/server.h" @@ -26,14 +26,14 @@ bool server_init(struct sway_server *server) { - wlr_log(L_DEBUG, "Initializing Wayland server"); + sway_log(L_DEBUG, "Initializing Wayland server"); server->wl_display = wl_display_create(); server->wl_event_loop = wl_display_get_event_loop(server->wl_display); server->backend = wlr_backend_autocreate(server->wl_display); if (!server->backend) { - wlr_log(L_ERROR, "Unable to create backend"); + sway_log(L_ERROR, "Unable to create backend"); return false; } struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); @@ -100,7 +100,7 @@ bool server_init(struct sway_server *server) { server->socket = wl_display_add_socket_auto(server->wl_display); if (!server->socket) { - wlr_log(L_ERROR, "Unable to open wayland socket"); + sway_log(L_ERROR, "Unable to open wayland socket"); wlr_backend_destroy(server->backend); return false; } @@ -115,11 +115,11 @@ void server_fini(struct sway_server *server) { } void server_run(struct sway_server *server) { - wlr_log(L_INFO, "Running compositor on wayland display '%s'", + sway_log(L_INFO, "Running compositor on wayland display '%s'", server->socket); setenv("WAYLAND_DISPLAY", server->socket, true); if (!wlr_backend_start(server->backend)) { - wlr_log(L_ERROR, "Failed to start backend"); + sway_log(L_ERROR, "Failed to start backend"); wlr_backend_destroy(server->backend); return; } diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index bdef56eaa..796f2852b 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -50,7 +50,7 @@ void arrange_output(struct sway_container *output) { output->y = output_box->y; output->width = output_box->width; output->height = output_box->height; - wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", + sway_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y); for (int i = 0; i < output->children->length; ++i) { struct sway_container *workspace = output->children->items[i]; @@ -69,13 +69,13 @@ void arrange_workspace(struct sway_container *workspace) { } struct sway_container *output = workspace->parent; struct wlr_box *area = &output->sway_output->usable_area; - wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", + sway_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", area->width, area->height, area->x, area->y); workspace->width = area->width; workspace->height = area->height; workspace->x = area->x; workspace->y = area->y; - wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", + sway_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, workspace->x, workspace->y); arrange_children_of(workspace); container_damage_whole(workspace); @@ -111,12 +111,12 @@ static void apply_horiz_layout(struct sway_container *parent) { double scale = parent->width / total_width; // Resize windows - wlr_log(L_DEBUG, "Arranging %p horizontally", parent); + sway_log(L_DEBUG, "Arranging %p horizontally", parent); double child_x = parent->x; struct sway_container *child; for (size_t i = 0; i < num_children; ++i) { child = parent->children->items[i]; - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, child->width, scale); child->x = child_x; @@ -159,12 +159,12 @@ static void apply_vert_layout(struct sway_container *parent) { double scale = parent_height / total_height; // Resize - wlr_log(L_DEBUG, "Arranging %p vertically", parent); + sway_log(L_DEBUG, "Arranging %p vertically", parent); double child_y = parent->y + parent_offset; struct sway_container *child; for (size_t i = 0; i < num_children; ++i) { child = parent->children->items[i]; - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, child->height, scale); child->x = parent->x; @@ -217,7 +217,7 @@ void arrange_children_of(struct sway_container *parent) { return; } - wlr_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent, + sway_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent, parent->name, parent->width, parent->height, parent->x, parent->y); // Calculate x, y, width and height of children @@ -233,7 +233,7 @@ void arrange_children_of(struct sway_container *parent) { apply_tabbed_or_stacked_layout(parent); break; default: - wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); + sway_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); apply_horiz_layout(parent); break; } diff --git a/sway/tree/container.c b/sway/tree/container.c index 9cf18f616..3da255a3e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -28,7 +28,7 @@ static list_t *get_bfs_queue() { if (!bfs_queue) { bfs_queue = create_list(); if (!bfs_queue) { - wlr_log(L_ERROR, "could not allocate list for bfs queue"); + sway_log(L_ERROR, "could not allocate list for bfs queue"); return NULL; } } @@ -209,7 +209,7 @@ static struct sway_container *container_output_destroy( // clear the wlr_output reference to this container output->sway_output->wlr_output->data = NULL; - wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); + sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); _container_destroy(output); return &root_container; } @@ -229,7 +229,7 @@ static struct sway_container *container_workspace_destroy( struct sway_container *parent = workspace->parent; if (workspace->children->length == 0) { // destroy the WS if there are no children (TODO check for floating) - wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); + sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name); ipc_event_workspace(workspace, NULL, "empty"); } else { // Move children to a different workspace on this output @@ -242,7 +242,7 @@ static struct sway_container *container_workspace_destroy( } } - wlr_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'", + sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'", workspace->name, new_workspace->name); for (int i = 0; i < workspace->children->length; i++) { container_move_to(workspace->children->items[i], new_workspace); @@ -258,7 +258,7 @@ static struct sway_container *container_workspace_destroy( } static void container_root_finish(struct sway_container *con) { - wlr_log(L_ERROR, "TODO: destroy the root container"); + sway_log(L_ERROR, "TODO: destroy the root container"); } bool container_reap_empty(struct sway_container *con) { @@ -269,7 +269,7 @@ bool container_reap_empty(struct sway_container *con) { break; case C_WORKSPACE: if (!workspace_is_visible(con) && con->children->length == 0) { - wlr_log(L_DEBUG, "Destroying workspace via reaper"); + sway_log(L_DEBUG, "Destroying workspace via reaper"); container_workspace_destroy(con); return true; } @@ -346,7 +346,7 @@ struct sway_container *container_destroy(struct sway_container *con) { _container_destroy(con); break; case C_TYPES: - wlr_log(L_ERROR, "container_destroy called on an invalid " + sway_log(L_ERROR, "container_destroy called on an invalid " "container"); break; } @@ -385,7 +385,7 @@ struct sway_container *container_view_create(struct sway_container *sibling, } const char *title = view_get_title(sway_view); struct sway_container *swayc = container_create(C_VIEW); - wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", + sway_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); // Setup values swayc->sway_view = sway_view; @@ -627,7 +627,7 @@ void container_for_each_descendant_bfs(struct sway_container *con, } if (queue == NULL) { - wlr_log(L_ERROR, "could not allocate list"); + sway_log(L_ERROR, "could not allocate list"); return; } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 91759f7bc..3ca008e8e 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -100,7 +100,7 @@ void container_insert_child(struct sway_container *parent, if (old_parent) { container_remove_child(child); } - wlr_log(L_DEBUG, "Inserting id:%zd at index %d", child->id, i); + sway_log(L_DEBUG, "Inserting id:%zd at index %d", child->id, i); list_insert(parent->children, i, child); child->parent = parent; container_handle_fullscreen_reparent(child, old_parent); @@ -126,7 +126,7 @@ struct sway_container *container_add_sibling(struct sway_container *fixed, void container_add_child(struct sway_container *parent, struct sway_container *child) { - wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", + sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, parent, parent->type, parent->width, parent->height); struct sway_container *old_parent = child->parent; @@ -340,7 +340,7 @@ void container_move(struct sway_container *container, } parent = current->parent; - wlr_log(L_DEBUG, "Visiting %p %s '%s'", current, + sway_log(L_DEBUG, "Visiting %p %s '%s'", current, container_type_to_str(current->type), current->name); int index = index_child(current); @@ -358,12 +358,12 @@ void container_move(struct sway_container *container, root_container.sway_root->output_layout, wlr_dir, current->sway_output->wlr_output, ref_lx, ref_ly); if (!next) { - wlr_log(L_DEBUG, "Hit edge of output, nowhere else to go"); + sway_log(L_DEBUG, "Hit edge of output, nowhere else to go"); return; } struct sway_output *next_output = next->data; current = next_output->swayc; - wlr_log(L_DEBUG, "Selected next output (%s)", current->name); + sway_log(L_DEBUG, "Selected next output (%s)", current->name); // Select workspace and get outta here current = seat_get_focus_inactive( config->handler_context.seat, current); @@ -376,11 +376,11 @@ void container_move(struct sway_container *container, case C_WORKSPACE: if (!is_parallel(current->layout, move_dir)) { if (current->children->length > 2) { - wlr_log(L_DEBUG, "Rejiggering the workspace (%d kiddos)", + sway_log(L_DEBUG, "Rejiggering the workspace (%d kiddos)", current->children->length); workspace_rejigger(current, container, move_dir); } else if (current->children->length == 2) { - wlr_log(L_DEBUG, "Changing workspace layout"); + sway_log(L_DEBUG, "Changing workspace layout"); current->layout = move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; @@ -389,7 +389,7 @@ void container_move(struct sway_container *container, } return; } else { - wlr_log(L_DEBUG, "Selecting output"); + sway_log(L_DEBUG, "Selecting output"); current = current->parent; } break; @@ -399,10 +399,10 @@ void container_move(struct sway_container *container, if ((index == parent->children->length - 1 && offs > 0) || (index == 0 && offs < 0)) { if (current->parent == container->parent) { - wlr_log(L_DEBUG, "Hit limit, selecting parent"); + sway_log(L_DEBUG, "Hit limit, selecting parent"); current = current->parent; } else { - wlr_log(L_DEBUG, "Hit limit, " + sway_log(L_DEBUG, "Hit limit, " "promoting descendant to sibling"); // Special case struct sway_container *old_parent = container->parent; @@ -415,10 +415,10 @@ void container_move(struct sway_container *container, } } else { sibling = parent->children->items[index + offs]; - wlr_log(L_DEBUG, "Selecting sibling id:%zd", sibling->id); + sway_log(L_DEBUG, "Selecting sibling id:%zd", sibling->id); } } else { - wlr_log(L_DEBUG, "Moving up to find a parallel container"); + sway_log(L_DEBUG, "Moving up to find a parallel container"); current = current->parent; } break; @@ -437,12 +437,12 @@ void container_move(struct sway_container *container, switch (sibling->type) { case C_VIEW: if (sibling->parent == container->parent) { - wlr_log(L_DEBUG, "Swapping siblings"); + sway_log(L_DEBUG, "Swapping siblings"); sibling->parent->children->items[index + offs] = container; sibling->parent->children->items[index] = sibling; arrange_children_of(sibling->parent); } else { - wlr_log(L_DEBUG, "Promoting to sibling of cousin"); + sway_log(L_DEBUG, "Promoting to sibling of cousin"); container_insert_child(sibling->parent, container, index_child(sibling) + (offs > 0 ? 0 : 1)); container->width = container->height = 0; @@ -455,8 +455,8 @@ void container_move(struct sway_container *container, case C_CONTAINER: if (is_parallel(sibling->layout, move_dir)) { int limit = container_limit(sibling, invert_movement(move_dir)); - wlr_log(L_DEBUG, "limit: %d", limit); - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "limit: %d", limit); + sway_log(L_DEBUG, "Reparenting container (parallel) to index %d " "(move dir: %d)", limit, move_dir); container_insert_child(sibling, container, limit); @@ -465,7 +465,7 @@ void container_move(struct sway_container *container, arrange_children_of(old_parent); sibling = NULL; } else { - wlr_log(L_DEBUG, "Reparenting container (perpendicular)"); + sway_log(L_DEBUG, "Reparenting container (perpendicular)"); container_remove_child(container); struct sway_container *focus_inactive = seat_get_focus_inactive( config->handler_context.seat, sibling); @@ -473,15 +473,15 @@ void container_move(struct sway_container *container, while (focus_inactive->parent != sibling) { focus_inactive = focus_inactive->parent; } - wlr_log(L_DEBUG, "Focus inactive: id:%zd", + sway_log(L_DEBUG, "Focus inactive: id:%zd", focus_inactive->id); sibling = focus_inactive; continue; } else if (sibling->children->length) { - wlr_log(L_DEBUG, "No focus-inactive, adding arbitrarily"); + sway_log(L_DEBUG, "No focus-inactive, adding arbitrarily"); container_add_sibling(sibling->children->items[0], container); } else { - wlr_log(L_DEBUG, "No kiddos, adding container alone"); + sway_log(L_DEBUG, "No kiddos, adding container alone"); container_add_child(sibling, container); } container->width = container->height = 0; @@ -579,7 +579,7 @@ static struct sway_container *get_swayc_in_output_direction( } if (ws == NULL) { - wlr_log(L_ERROR, "got an output without a workspace"); + sway_log(L_ERROR, "got an output without a workspace"); return NULL; } @@ -750,7 +750,7 @@ struct sway_container *container_get_in_direction( } } else { struct sway_container *desired_con = parent->children->items[desired]; - wlr_log(L_DEBUG, + sway_log(L_DEBUG, "cont %d-%p dir %i sibling %d: %p", idx, container, dir, desired, desired_con); struct sway_container *next = seat_get_focus_inactive_view(seat, desired_con); @@ -814,7 +814,7 @@ struct sway_container *container_split(struct sway_container *child, struct sway_container *cont = container_create(C_CONTAINER); - wlr_log(L_DEBUG, "creating container %p around %p", cont, child); + sway_log(L_DEBUG, "creating container %p around %p", cont, child); cont->prev_layout = L_NONE; cont->width = child->width; @@ -855,7 +855,7 @@ struct sway_container *container_split(struct sway_container *child, void container_recursive_resize(struct sway_container *container, double amount, enum resize_edge edge) { bool layout_match = true; - wlr_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); + sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); if (edge == RESIZE_EDGE_LEFT || edge == RESIZE_EDGE_RIGHT) { container->width += amount; layout_match = container->layout == L_HORIZ; diff --git a/sway/tree/output.c b/sway/tree/output.c index 6c7044a2c..968a79fc6 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -22,11 +22,11 @@ struct sway_container *output_create( if (strcasecmp(name, cur->name) == 0 || strcasecmp(identifier, cur->name) == 0) { - wlr_log(L_DEBUG, "Matched output config for %s", name); + sway_log(L_DEBUG, "Matched output config for %s", name); oc = cur; } if (strcasecmp("*", cur->name) == 0) { - wlr_log(L_DEBUG, "Matched wildcard output config for %s", name); + sway_log(L_DEBUG, "Matched wildcard output config for %s", name); all = cur; } @@ -56,7 +56,7 @@ struct sway_container *output_create( // Create workspace char *ws_name = workspace_next_name(output->name); - wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); + sway_log(L_DEBUG, "Creating default workspace %s", ws_name); struct sway_container *ws = workspace_create(output, ws_name); // Set each seat's focus if not already set struct sway_seat *seat = NULL; diff --git a/sway/tree/view.c b/sway/tree/view.c index 071578188..5d7bde5df 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -404,17 +404,17 @@ void view_execute_criteria(struct sway_view *view) { list_t *criterias = criteria_for_view(view, CT_COMMAND); for (int i = 0; i < criterias->length; i++) { struct criteria *criteria = criterias->items[i]; - wlr_log(L_DEBUG, "Checking criteria %s", criteria->raw); + sway_log(L_DEBUG, "Checking criteria %s", criteria->raw); if (view_has_executed_criteria(view, criteria)) { - wlr_log(L_DEBUG, "Criteria already executed"); + sway_log(L_DEBUG, "Criteria already executed"); continue; } - wlr_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'", + sway_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'", criteria->raw, view, criteria->cmdlist); list_add(view->executed_criteria, criteria); struct cmd_results *res = execute_command(criteria->cmdlist, NULL); if (res->status != CMD_SUCCESS) { - wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); + sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); } free_cmd_results(res); // view must be focused for commands to affect it, @@ -541,7 +541,7 @@ static void view_subsurface_create(struct sway_view *view, struct wlr_subsurface *subsurface) { struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); if (child == NULL) { - wlr_log(L_ERROR, "Allocation failed"); + sway_log(L_ERROR, "Allocation failed"); return; } view_child_init(child, NULL, view, subsurface->surface); @@ -714,7 +714,7 @@ static char *escape_title(char *buffer) { char *escaped_title = calloc(length + 1, sizeof(char)); int result = escape_markup_text(buffer, escaped_title, length); if (result != length) { - wlr_log(L_ERROR, "Could not escape title: %s", buffer); + sway_log(L_ERROR, "Could not escape title: %s", buffer); free(escaped_title); return buffer; } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index f34baa9ee..f2b340834 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -48,7 +48,7 @@ struct sway_container *workspace_create(struct sway_container *output, output = get_workspace_initial_output(name); } - wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); + sway_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); struct sway_container *workspace = container_create(C_WORKSPACE); workspace->x = output->x; @@ -101,7 +101,7 @@ static bool workspace_valid_on_output(const char *output_name, } char *workspace_next_name(const char *output_name) { - wlr_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", + sway_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", output_name); int l = 1; // Scan all workspace bindings to find the next available workspace name, @@ -124,7 +124,7 @@ char *workspace_next_name(const char *output_name) { } if (strcmp("workspace", cmd) == 0 && name) { - wlr_log(L_DEBUG, "Got valid workspace command for target: '%s'", name); + sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name); char *_target = strdup(name); strip_quotes(_target); while (isspace(*_target)) { @@ -154,7 +154,7 @@ char *workspace_next_name(const char *output_name) { temp[length - 1] = '\0'; free(_target); _target = temp; - wlr_log(L_DEBUG, "Isolated name from workspace number: '%s'", _target); + sway_log(L_DEBUG, "Isolated name from workspace number: '%s'", _target); // Make sure the workspace number doesn't already exist if (workspace_by_number(_target)) { @@ -183,7 +183,7 @@ char *workspace_next_name(const char *output_name) { order = binding->order; free(target); target = _target; - wlr_log(L_DEBUG, "Workspace: Found free name %s", _target); + sway_log(L_DEBUG, "Workspace: Found free name %s", _target); } } free(dup); @@ -201,7 +201,7 @@ char *workspace_next_name(const char *output_name) { } char *name = malloc(l + 1); if (!name) { - wlr_log(L_ERROR, "Could not allocate workspace name"); + sway_log(L_ERROR, "Could not allocate workspace name"); return NULL; } sprintf(name, "%d", ws_num++); @@ -377,7 +377,7 @@ bool workspace_switch(struct sway_container *workspace) { free(prev_workspace_name); prev_workspace_name = malloc(strlen(active_ws->name) + 1); if (!prev_workspace_name) { - wlr_log(L_ERROR, "Unable to allocate previous workspace name"); + sway_log(L_ERROR, "Unable to allocate previous workspace name"); return false; } strcpy(prev_workspace_name, active_ws->name); @@ -385,7 +385,7 @@ bool workspace_switch(struct sway_container *workspace) { // TODO: Deal with sticky containers - wlr_log(L_DEBUG, "Switching to workspace %p:%s", + sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); struct sway_container *next = seat_get_focus_inactive(seat, workspace); if (next == NULL) { diff --git a/swaybar/bar.c b/swaybar/bar.c index 5b8028e5a..f53b6315a 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -46,7 +46,7 @@ static void swaybar_output_free(struct swaybar_output *output) { if (!output) { return; } - wlr_log(L_DEBUG, "Removing output %s", output->name); + sway_log(L_DEBUG, "Removing output %s", output->name); zwlr_layer_surface_v1_destroy(output->layer_surface); wl_surface_destroy(output->surface); wl_output_destroy(output->output); diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 141612a67..11f254de5 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "log.h" #include "swaybar/config.h" #include "swaybar/status_line.h" @@ -31,7 +31,7 @@ static bool i3bar_parse_json(struct status_line *status, const char *text) { status_error(status, "[failed to parse i3bar json]"); return false; } - wlr_log(L_DEBUG, "Got i3bar json: '%s'", text); + sway_log(L_DEBUG, "Got i3bar json: '%s'", text); for (size_t i = 0; i < json_object_array_length(results); ++i) { json_object *full_text, *short_text, *color, *min_width, *align, *urgent; json_object *name, *instance, *separator, *separator_block_width; @@ -193,7 +193,7 @@ bool i3bar_handle_readable(struct status_line *status) { void i3bar_block_send_click(struct status_line *status, struct i3bar_block *block, int x, int y, uint32_t button) { - wlr_log(L_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); + sway_log(L_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); if (!block->name || !status->i3bar_state.click_events) { return; } diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 959fa0953..eeb559b8b 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "log.h" #include "swaybar/config.h" #include "swaybar/ipc.h" #include "ipc-client.h" @@ -327,7 +327,7 @@ bool handle_ipc_readable(struct swaybar *bar) { json_object *result = json_tokener_parse(resp->payload); if (!result) { free_ipc_response(resp); - wlr_log(L_ERROR, "failed to parse payload as json"); + sway_log(L_ERROR, "failed to parse payload as json"); return false; } json_object *json_change, *json_pango_markup; @@ -340,7 +340,7 @@ bool handle_ipc_readable(struct swaybar *bar) { bar->config->mode = strdup(change); } } else { - wlr_log(L_ERROR, "failed to parse response"); + sway_log(L_ERROR, "failed to parse response"); json_object_put(result); free_ipc_response(resp); return false; diff --git a/swaybar/main.c b/swaybar/main.c index c897e1c92..099f8085d 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include "log.h" #include "swaybar/bar.h" #include "ipc-client.h" @@ -75,13 +75,13 @@ int main(int argc, char **argv) { } if (debug) { - wlr_log_init(L_DEBUG, NULL); + sway_log_init(L_DEBUG, NULL); } else { - wlr_log_init(L_ERROR, NULL); + sway_log_init(L_ERROR, NULL); } if (!bar_id) { - wlr_log(L_ERROR, "No bar_id passed. " + sway_log(L_ERROR, "No bar_id passed. " "Provide --bar_id or let sway start swaybar"); return 1; } @@ -89,7 +89,7 @@ int main(int argc, char **argv) { if (!socket_path) { socket_path = get_socketpath(); if (!socket_path) { - wlr_log(L_ERROR, "Unable to retrieve socket path"); + sway_log(L_ERROR, "Unable to retrieve socket path"); return 1; } } diff --git a/swaybar/status_line.c b/swaybar/status_line.c index e0e7414ab..19745cb46 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "log.h" #include "swaybar/config.h" #include "swaybar/status_line.h" #include "readline.h" @@ -49,14 +49,14 @@ bool status_handle_readable(struct status_line *status) { json_object *version; if (json_object_object_get_ex(proto, "version", &version) && json_object_get_int(version) == 1) { - wlr_log(L_DEBUG, "Switched to i3bar protocol."); + sway_log(L_DEBUG, "Switched to i3bar protocol."); status->protocol = PROTOCOL_I3BAR; } json_object *click_events; if (json_object_object_get_ex( proto, "click_events", &click_events) && json_object_get_boolean(click_events)) { - wlr_log(L_DEBUG, "Enabled click events."); + sway_log(L_DEBUG, "Enabled click events."); status->i3bar_state.click_events = true; const char *events_array = "[\n"; ssize_t len = strlen(events_array); @@ -91,7 +91,7 @@ struct status_line *status_line_init(char *cmd) { int pipe_read_fd[2]; int pipe_write_fd[2]; if (pipe(pipe_read_fd) != 0 || pipe(pipe_write_fd) != 0) { - wlr_log(L_ERROR, "Unable to create pipes for status_command fork"); + sway_log(L_ERROR, "Unable to create pipes for status_command fork"); exit(1); } diff --git a/swaybg/main.c b/swaybg/main.c index 5b6c378c3..493339a22 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include "log.h" #include "background-image.h" #include "pool-buffer.h" #include "cairo.h" @@ -48,7 +48,7 @@ struct swaybg_state { bool is_valid_color(const char *color) { int len = strlen(color); if (len != 7 || color[0] != '#') { - wlr_log(L_ERROR, "%s is not a valid color for swaybg. " + sway_log(L_ERROR, "%s is not a valid color for swaybg. " "Color should be specified as #rrggbb (no alpha).", color); return false; } @@ -185,10 +185,10 @@ int main(int argc, const char **argv) { struct swaybg_args args = {0}; struct swaybg_state state = {0}; state.args = &args; - wlr_log_init(L_DEBUG, NULL); + sway_log_init(L_DEBUG, NULL); if (argc != 4) { - wlr_log(L_ERROR, "Do not run this program manually. " + sway_log(L_ERROR, "Do not run this program manually. " "See man 5 sway and look for output options."); return 1; } @@ -244,3 +244,8 @@ int main(int argc, const char **argv) { } return 0; } + +/* Required by common code */ +void sway_terminate(int code) { + exit(code); +} diff --git a/swayidle/main.c b/swayidle/main.c index ad9c84c96..4311e90cc 100644 --- a/swayidle/main.c +++ b/swayidle/main.c @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#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 "); 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 "); 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); diff --git a/swaylock/main.c b/swaylock/main.c index f89f28495..e2579e7d4 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -34,7 +34,7 @@ void sway_terminate(int exit_code) { static void daemonize() { int fds[2]; if (pipe(fds) != 0) { - wlr_log(L_ERROR, "Failed to pipe"); + sway_log(L_ERROR, "Failed to pipe"); exit(1); } if (fork() == 0) { @@ -56,7 +56,7 @@ static void daemonize() { close(fds[1]); uint8_t success; if (read(fds[0], &success, 1) != 1 || !success) { - wlr_log(L_ERROR, "Failed to daemonize"); + sway_log(L_ERROR, "Failed to daemonize"); exit(1); } close(fds[0]); @@ -174,7 +174,7 @@ static void handle_xdg_output_logical_position(void *data, static void handle_xdg_output_name(void *data, struct zxdg_output_v1 *output, const char *name) { - wlr_log(L_DEBUG, "output name is %s", name); + sway_log(L_DEBUG, "output name is %s", name); struct swaylock_surface *surface = data; surface->xdg_output = output; surface->output_name = strdup(name); @@ -290,10 +290,10 @@ static void load_image(char *arg, struct swaylock_state *state) { } if (exists) { if (image->output_name) { - wlr_log(L_ERROR, "Multiple images defined for output %s", + sway_log(L_ERROR, "Multiple images defined for output %s", image->output_name); } else { - wlr_log(L_ERROR, "Multiple default images defined"); + sway_log(L_ERROR, "Multiple default images defined"); } } @@ -313,7 +313,7 @@ static void load_image(char *arg, struct swaylock_state *state) { } wl_list_insert(&state->images, &image->link); state->args.mode = BACKGROUND_MODE_FILL; - wlr_log(L_DEBUG, "Loaded image %s for output %s", + sway_log(L_DEBUG, "Loaded image %s for output %s", image->path, image->output_name ? image->output_name : "*"); } @@ -352,7 +352,7 @@ int main(int argc, char **argv) { }; wl_list_init(&state.images); - wlr_log_init(L_DEBUG, NULL); + sway_log_init(L_DEBUG, NULL); int c; while (1) { @@ -416,13 +416,13 @@ int main(int argc, char **argv) { wl_display_roundtrip(state.display); assert(state.compositor && state.layer_shell && state.shm); if (!state.input_inhibit_manager) { - wlr_log(L_ERROR, "Compositor does not support the input inhibitor " + sway_log(L_ERROR, "Compositor does not support the input inhibitor " "protocol, refusing to run insecurely"); return 1; } if (wl_list_empty(&state.surfaces)) { - wlr_log(L_DEBUG, "Exiting - no outputs to show on."); + sway_log(L_DEBUG, "Exiting - no outputs to show on."); return 0; } @@ -438,7 +438,7 @@ int main(int argc, char **argv) { } wl_display_roundtrip(state.display); } else { - wlr_log(L_INFO, "Compositor does not support zxdg output manager, " + sway_log(L_INFO, "Compositor does not support zxdg output manager, " "images assigned to named outputs will not work"); } diff --git a/swaylock/password.c b/swaylock/password.c index 1ad5cd817..00c96eba6 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include "log.h" #include #include "swaylock/swaylock.h" #include "swaylock/seat.h" @@ -53,15 +53,15 @@ static bool attempt_password(struct swaylock_password *pw) { // TODO: only call pam_start once. keep the same handle the whole time if ((pam_err = pam_start("swaylock", username, &local_conversation, &local_auth_handle)) != PAM_SUCCESS) { - wlr_log(L_ERROR, "PAM returned error %d", pam_err); + sway_log(L_ERROR, "PAM returned error %d", pam_err); } if ((pam_err = pam_authenticate(local_auth_handle, 0)) != PAM_SUCCESS) { - wlr_log(L_ERROR, "pam_authenticate failed"); + sway_log(L_ERROR, "pam_authenticate failed"); goto fail; } // TODO: only call pam_end once we succeed at authing. refresh tokens beforehand if ((pam_err = pam_end(local_auth_handle, pam_err)) != PAM_SUCCESS) { - wlr_log(L_ERROR, "pam_end failed"); + sway_log(L_ERROR, "pam_end failed"); goto fail; } clear_password_buffer(pw); diff --git a/swaylock/seat.c b/swaylock/seat.c index a81899a61..d9c573cbf 100644 --- a/swaylock/seat.c +++ b/swaylock/seat.c @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include "log.h" #include "swaylock/swaylock.h" #include "swaylock/seat.h" @@ -34,13 +34,13 @@ static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, struct swaylock_state *state = data; if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { close(fd); - wlr_log(L_ERROR, "Unknown keymap format %d, aborting", format); + sway_log(L_ERROR, "Unknown keymap format %d, aborting", format); exit(1); } char *map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (map_shm == MAP_FAILED) { close(fd); - wlr_log(L_ERROR, "Unable to initialize keymap shm, aborting"); + sway_log(L_ERROR, "Unable to initialize keymap shm, aborting"); exit(1); } struct xkb_keymap *keymap = xkb_keymap_new_from_string( diff --git a/swaymsg/main.c b/swaymsg/main.c index 89af73454..1cd60a3ae 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -287,7 +287,7 @@ int main(int argc, char **argv) { char *socket_path = NULL; char *cmdtype = NULL; - wlr_log_init(L_INFO, NULL); + sway_log_init(L_INFO, NULL); static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, From acae6ad40f173bec372a3ad65c89a290635f4348 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 24 May 2018 21:52:35 +0200 Subject: [PATCH 3/6] move wlr dependent input handler to sway Moves input handling code that uses headers from wlroots from the common code to sway proper, to allow for removing the wlroots dependency from clients --- common/util.c | 53 ----------------------------------- include/sway/input/keyboard.h | 22 +++++++++++++++ include/util.h | 21 -------------- sway/commands/bar/modifier.c | 2 +- sway/commands/bind.c | 2 +- sway/input/keyboard.c | 53 +++++++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 76 deletions(-) diff --git a/common/util.c b/common/util.c index 839811608..b52e7448d 100644 --- a/common/util.c +++ b/common/util.c @@ -9,7 +9,6 @@ #include #include #include -#include #include "log.h" #include "readline.h" #include "util.h" @@ -25,58 +24,6 @@ int numlen(int n) { return log10(n) + 1; } -static struct modifier_key { - char *name; - uint32_t mod; -} modifiers[] = { - { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, - { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, - { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, - { "Ctrl", WLR_MODIFIER_CTRL }, - { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, - { "Alt", WLR_MODIFIER_ALT }, - { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, - { "Mod3", WLR_MODIFIER_MOD3 }, - { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, - { "Mod5", WLR_MODIFIER_MOD5 }, -}; - -uint32_t get_modifier_mask_by_name(const char *name) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (strcasecmp(modifiers[i].name, name) == 0) { - return modifiers[i].mod; - } - } - - return 0; -} - -const char *get_modifier_name_by_mask(uint32_t modifier) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (modifiers[i].mod == modifier) { - return modifiers[i].name; - } - } - - return NULL; -} - -int get_modifier_names(const char **names, uint32_t modifier_masks) { - int length = 0; - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if ((modifier_masks & modifiers[i].mod) != 0) { - names[length] = modifiers[i].name; - ++length; - modifier_masks ^= modifiers[i].mod; - } - } - - return length; -} - pid_t get_parent_pid(pid_t child) { pid_t parent = -1; char file_name[100]; diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h index 8ec3eb356..6f9ace863 100644 --- a/include/sway/input/keyboard.h +++ b/include/sway/input/keyboard.h @@ -5,6 +5,28 @@ #define SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP 32 +/** + * Get modifier mask from modifier name. + * + * Returns the modifer mask or 0 if the name isn't found. + */ +uint32_t get_modifier_mask_by_name(const char *name); + +/** + * Get modifier name from modifier mask. + * + * Returns the modifier name or NULL if it isn't found. + */ +const char *get_modifier_name_by_mask(uint32_t modifier); + +/** + * Get an array of modifier names from modifier_masks + * + * Populates the names array and return the number of names added. + */ +int get_modifier_names(const char **names, uint32_t modifier_masks); + + struct sway_keyboard { struct sway_seat_device *seat_device; diff --git a/include/util.h b/include/util.h index f68deae84..02519c93a 100644 --- a/include/util.h +++ b/include/util.h @@ -16,27 +16,6 @@ int wrap(int i, int max); */ int numlen(int n); -/** - * Get modifier mask from modifier name. - * - * Returns the modifer mask or 0 if the name isn't found. - */ -uint32_t get_modifier_mask_by_name(const char *name); - -/** - * Get modifier name from modifier mask. - * - * Returns the modifier name or NULL if it isn't found. - */ -const char *get_modifier_name_by_mask(uint32_t modifier); - -/** - * Get an array of modifier names from modifier_masks - * - * Populates the names array and return the number of names added. - */ -int get_modifier_names(const char **names, uint32_t modifier_masks); - /** * Get the pid of a parent process given the pid of a child process. * diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c index 43907007a..5e2316df5 100644 --- a/sway/commands/bar/modifier.c +++ b/sway/commands/bar/modifier.c @@ -2,7 +2,7 @@ #include "sway/commands.h" #include "log.h" #include "stringop.h" -#include "util.h" +#include "sway/input/keyboard.h" struct cmd_results *bar_cmd_modifier(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 791214041..d3ce731cf 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -11,7 +11,7 @@ #include "list.h" #include "log.h" #include "stringop.h" -#include "util.h" +#include "sway/input/keyboard.h" int binding_order = 0; diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 8bf5abff6..e1a516dc0 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -9,6 +10,58 @@ #include "sway/commands.h" #include "log.h" +static struct modifier_key { + char *name; + uint32_t mod; +} modifiers[] = { + { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, + { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, + { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, + { "Ctrl", WLR_MODIFIER_CTRL }, + { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, + { "Alt", WLR_MODIFIER_ALT }, + { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, + { "Mod3", WLR_MODIFIER_MOD3 }, + { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, + { "Mod5", WLR_MODIFIER_MOD5 }, +}; + +uint32_t get_modifier_mask_by_name(const char *name) { + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if (strcasecmp(modifiers[i].name, name) == 0) { + return modifiers[i].mod; + } + } + + return 0; +} + +const char *get_modifier_name_by_mask(uint32_t modifier) { + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if (modifiers[i].mod == modifier) { + return modifiers[i].name; + } + } + + return NULL; +} + +int get_modifier_names(const char **names, uint32_t modifier_masks) { + int length = 0; + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if ((modifier_masks & modifiers[i].mod) != 0) { + names[length] = modifiers[i].name; + ++length; + modifier_masks ^= modifiers[i].mod; + } + } + + return length; +} + static bool keysym_is_modifier(xkb_keysym_t keysym) { switch (keysym) { case XKB_KEY_Shift_L: case XKB_KEY_Shift_R: From 3fb60b6aedef6012ef97d3b668978b247ffdb664 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 24 May 2018 21:55:52 +0200 Subject: [PATCH 4/6] remove wlroots dependency from common code Removes the wlroots dependency from the common code. To remove the dependency on the header, the defines and log-level enum are copied over. This causes a redefine error if both the wlr and the sway log.h are included. --- common/meson.build | 1 - include/log.h | 15 ++++++++++++++- sway/commands/focus.c | 1 - sway/commands/kill.c | 1 - sway/commands/resize.c | 1 - sway/desktop/layer_shell.c | 1 - swaybar/bar.c | 1 - swaylock/main.c | 1 - 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/common/meson.build b/common/meson.build index 44a295084..06311f555 100644 --- a/common/meson.build +++ b/common/meson.build @@ -17,7 +17,6 @@ lib_sway_common = static_library( gdk_pixbuf, pango, pangocairo, - wlroots ], include_directories: sway_inc ) diff --git a/include/log.h b/include/log.h index 2599c9aa2..3773dca2f 100644 --- a/include/log.h +++ b/include/log.h @@ -1,12 +1,25 @@ #ifndef _SWAY_LOG_H #define _SWAY_LOG_H -#include #include #include #include #include +typedef enum { + L_SILENT = 0, + L_ERROR = 1, + L_INFO = 2, + L_DEBUG = 3, + L_LAST, +} log_importance_t; + +#ifdef __GNUC__ +#define ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) +#else +#define ATTRIB_PRINTF(start, end) +#endif + void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); #define sway_abort(FMT, ...) \ _sway_abort("[%s:%d] " FMT, sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 74d9d5359..e6a9d76cc 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -1,5 +1,4 @@ #include -#include #include "log.h" #include "sway/input/input-manager.h" #include "sway/input/seat.h" diff --git a/sway/commands/kill.c b/sway/commands/kill.c index f3fa52f14..6fc5f7836 100644 --- a/sway/commands/kill.c +++ b/sway/commands/kill.c @@ -1,4 +1,3 @@ -#include #include "log.h" #include "sway/input/input-manager.h" #include "sway/input/seat.h" diff --git a/sway/commands/resize.c b/sway/commands/resize.c index f8e0b2f2f..1b39ac8e0 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -4,7 +4,6 @@ #include #include #include -#include #include "sway/commands.h" #include "sway/tree/arrange.h" #include "log.h" diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index c093888e3..873e288de 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -6,7 +6,6 @@ #include #include #include -#include #include "sway/input/input-manager.h" #include "sway/input/seat.h" #include "sway/layers.h" diff --git a/swaybar/bar.c b/swaybar/bar.c index f53b6315a..946651ec4 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -10,7 +10,6 @@ #include #include #include -#include #ifdef __FreeBSD__ #include #else diff --git a/swaylock/main.c b/swaylock/main.c index e2579e7d4..8efb38b88 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "swaylock/seat.h" #include "swaylock/swaylock.h" #include "background-image.h" From 4a967f2d9d1b31016cf4a2a752d88346914c967f Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 24 May 2018 21:59:55 +0200 Subject: [PATCH 5/6] move sway specific ipc code out of common Moves the ipc-client code out of common into a dedicated ipc library to allow moving swaybg/swaylock into a separate project more easily --- common/meson.build | 1 - {common => ipc}/ipc-client.c | 0 ipc/meson.build | 8 ++++++++ meson.build | 1 + sway/meson.build | 2 +- swaybar/meson.build | 2 +- swaymsg/meson.build | 2 +- 7 files changed, 12 insertions(+), 4 deletions(-) rename {common => ipc}/ipc-client.c (100%) create mode 100644 ipc/meson.build diff --git a/common/meson.build b/common/meson.build index 06311f555..242ec84f1 100644 --- a/common/meson.build +++ b/common/meson.build @@ -3,7 +3,6 @@ lib_sway_common = static_library( files( 'background-image.c', 'cairo.c', - 'ipc-client.c', 'log.c', 'list.c', 'pango.c', diff --git a/common/ipc-client.c b/ipc/ipc-client.c similarity index 100% rename from common/ipc-client.c rename to ipc/ipc-client.c diff --git a/ipc/meson.build b/ipc/meson.build new file mode 100644 index 000000000..9df9cb64f --- /dev/null +++ b/ipc/meson.build @@ -0,0 +1,8 @@ +lib_sway_ipc = static_library( + 'sway-ipc', + files( + 'ipc-client.c', + ), + dependencies: [ ], + include_directories: sway_inc +) diff --git a/meson.build b/meson.build index 890c1787f..7d107c67f 100644 --- a/meson.build +++ b/meson.build @@ -115,6 +115,7 @@ sway_inc = include_directories('include') subdir('include') subdir('protocols') subdir('common') +subdir('ipc') subdir('sway') subdir('swaymsg') diff --git a/sway/meson.build b/sway/meson.build index 72347d51c..fcb15ae9c 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -143,6 +143,6 @@ executable( sway_sources, include_directories: [sway_inc], dependencies: sway_deps, - link_with: [lib_sway_common], + link_with: [lib_sway_common, lib_sway_ipc], install: true ) diff --git a/swaybar/meson.build b/swaybar/meson.build index d65edb11e..fcc68df76 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build @@ -23,6 +23,6 @@ executable( wayland_cursor, wlroots, ], - link_with: [lib_sway_common, lib_sway_client], + link_with: [lib_sway_common, lib_sway_client, lib_sway_ipc], install: true ) diff --git a/swaymsg/meson.build b/swaymsg/meson.build index 8638b838d..6d4282103 100644 --- a/swaymsg/meson.build +++ b/swaymsg/meson.build @@ -3,6 +3,6 @@ executable( 'main.c', include_directories: [sway_inc], dependencies: [jsonc, wlroots], - link_with: [lib_sway_common], + link_with: [lib_sway_common, lib_sway_ipc], install: true ) From 7faee6637fc73ab92e3abed2efdfc821ad633c6f Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 24 May 2018 22:06:24 +0200 Subject: [PATCH 6/6] also init wlr log functions to log level --- sway/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sway/main.c b/sway/main.c index 8abb083a7..45a2b6b2f 100644 --- a/sway/main.c +++ b/sway/main.c @@ -251,6 +251,7 @@ static void drop_permissions(bool keep_caps) { #endif } +void wlr_log_init(log_importance_t verbosity, log_callback_t callback); int main(int argc, char **argv) { static int verbose = 0, debug = 0, validate = 0; @@ -333,12 +334,14 @@ int main(int argc, char **argv) { } } - // TODO: switch logging over to wlroots? if (debug) { + wlr_log_init(L_DEBUG, NULL); sway_log_init(L_DEBUG, NULL); } else if (verbose || validate) { + wlr_log_init(L_INFO, NULL); sway_log_init(L_INFO, NULL); } else { + wlr_log_init(L_ERROR, NULL); sway_log_init(L_ERROR, NULL); }