mirror of
https://github.com/swaywm/sway.git
synced 2025-11-26 06:59:59 -05:00
Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although with a sway_* prefix. (This is very similar to PR #2009.) However, the logging function no longer needs to be replaceable, so sway_log_init's second argument is used to set the exit callback for sway_abort. wlr_log_init is still invoked in sway/main.c This commit makes it easier to remove the wlroots dependency for the helper programs swaymsg, swaybg, swaybar, and swaynag.
This commit is contained in:
parent
5c834d36e1
commit
1211a81aad
108 changed files with 613 additions and 504 deletions
|
|
@ -19,10 +19,10 @@
|
|||
#include "util.h"
|
||||
|
||||
static void terminate_swaybar(pid_t pid) {
|
||||
wlr_log(WLR_DEBUG, "Terminating swaybar %d", pid);
|
||||
sway_log(SWAY_DEBUG, "Terminating swaybar %d", pid);
|
||||
int ret = kill(-pid, SIGTERM);
|
||||
if (ret != 0) {
|
||||
wlr_log_errno(WLR_ERROR, "Unable to terminate swaybar %d", pid);
|
||||
sway_log_errno(SWAY_ERROR, "Unable to terminate swaybar %d", pid);
|
||||
} else {
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
|
|
@ -194,7 +194,7 @@ static void invoke_swaybar(struct bar_config *bar) {
|
|||
// Pipe to communicate errors
|
||||
int filedes[2];
|
||||
if (pipe(filedes) == -1) {
|
||||
wlr_log(WLR_ERROR, "Pipe setup failed! Cannot fork into bar");
|
||||
sway_log(SWAY_ERROR, "Pipe setup failed! Cannot fork into bar");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -227,17 +227,17 @@ static void invoke_swaybar(struct bar_config *bar) {
|
|||
execvp(cmd[0], cmd);
|
||||
exit(1);
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "Spawned swaybar %d", bar->pid);
|
||||
sway_log(SWAY_DEBUG, "Spawned swaybar %d", bar->pid);
|
||||
close(filedes[0]);
|
||||
size_t len;
|
||||
if (read(filedes[1], &len, sizeof(size_t)) == sizeof(size_t)) {
|
||||
char *buf = malloc(len);
|
||||
if(!buf) {
|
||||
wlr_log(WLR_ERROR, "Cannot allocate error string");
|
||||
sway_log(SWAY_ERROR, "Cannot allocate error string");
|
||||
return;
|
||||
}
|
||||
if (read(filedes[1], buf, len)) {
|
||||
wlr_log(WLR_ERROR, "%s", buf);
|
||||
sway_log(SWAY_ERROR, "%s", buf);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ void load_swaybar(struct bar_config *bar) {
|
|||
if (bar->pid != 0) {
|
||||
terminate_swaybar(bar->pid);
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
|
||||
sway_log(SWAY_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
|
||||
invoke_swaybar(bar);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(WLR_DEBUG, "Unable to allocate input config");
|
||||
sway_log(SWAY_DEBUG, "Unable to allocate input config");
|
||||
return NULL;
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "new_input_config(%s)", identifier);
|
||||
sway_log(SWAY_DEBUG, "new_input_config(%s)", identifier);
|
||||
if (!(input->identifier = strdup(identifier))) {
|
||||
free(input);
|
||||
wlr_log(WLR_DEBUG, "Unable to allocate input config");
|
||||
sway_log(SWAY_DEBUG, "Unable to allocate input config");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ static void merge_wildcard_on_all(struct input_config *wildcard) {
|
|||
for (int i = 0; i < config->input_configs->length; i++) {
|
||||
struct input_config *ic = config->input_configs->items[i];
|
||||
if (strcmp(wildcard->identifier, ic->identifier) != 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging input * config on %s", ic->identifier);
|
||||
sway_log(SWAY_DEBUG, "Merging input * config on %s", ic->identifier);
|
||||
merge_input_config(ic, wildcard);
|
||||
}
|
||||
}
|
||||
|
|
@ -151,16 +151,16 @@ struct input_config *store_input_config(struct input_config *ic) {
|
|||
int i = list_seq_find(config->input_configs, input_identifier_cmp,
|
||||
ic->identifier);
|
||||
if (i >= 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging on top of existing input config");
|
||||
sway_log(SWAY_DEBUG, "Merging on top of existing input config");
|
||||
struct input_config *current = config->input_configs->items[i];
|
||||
merge_input_config(current, ic);
|
||||
free_input_config(ic);
|
||||
ic = current;
|
||||
} else if (!wildcard) {
|
||||
wlr_log(WLR_DEBUG, "Adding non-wildcard input config");
|
||||
sway_log(SWAY_DEBUG, "Adding non-wildcard input config");
|
||||
i = list_seq_find(config->input_configs, input_identifier_cmp, "*");
|
||||
if (i >= 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging on top of input * config");
|
||||
sway_log(SWAY_DEBUG, "Merging on top of input * config");
|
||||
struct input_config *current = new_input_config(ic->identifier);
|
||||
merge_input_config(current, config->input_configs->items[i]);
|
||||
merge_input_config(current, ic);
|
||||
|
|
@ -170,11 +170,11 @@ struct input_config *store_input_config(struct input_config *ic) {
|
|||
list_add(config->input_configs, ic);
|
||||
} else {
|
||||
// New wildcard config. Just add it
|
||||
wlr_log(WLR_DEBUG, "Adding input * config");
|
||||
sway_log(SWAY_DEBUG, "Adding input * config");
|
||||
list_add(config->input_configs, ic);
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Config stored for input %s", ic->identifier);
|
||||
sway_log(SWAY_DEBUG, "Config stored for input %s", ic->identifier);
|
||||
|
||||
return ic;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static void merge_wildcard_on_all(struct output_config *wildcard) {
|
|||
for (int i = 0; i < config->output_configs->length; i++) {
|
||||
struct output_config *oc = config->output_configs->items[i];
|
||||
if (strcmp(wildcard->name, oc->name) != 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging output * config on %s", oc->name);
|
||||
sway_log(SWAY_DEBUG, "Merging output * config on %s", oc->name);
|
||||
merge_output_config(oc, wildcard);
|
||||
}
|
||||
}
|
||||
|
|
@ -105,16 +105,16 @@ struct output_config *store_output_config(struct output_config *oc) {
|
|||
|
||||
int i = list_seq_find(config->output_configs, output_name_cmp, oc->name);
|
||||
if (i >= 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging on top of existing output config");
|
||||
sway_log(SWAY_DEBUG, "Merging on top of existing output config");
|
||||
struct output_config *current = config->output_configs->items[i];
|
||||
merge_output_config(current, oc);
|
||||
free_output_config(oc);
|
||||
oc = current;
|
||||
} else if (!wildcard) {
|
||||
wlr_log(WLR_DEBUG, "Adding non-wildcard output config");
|
||||
sway_log(SWAY_DEBUG, "Adding non-wildcard output config");
|
||||
i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
||||
if (i >= 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging on top of output * config");
|
||||
sway_log(SWAY_DEBUG, "Merging on top of output * config");
|
||||
struct output_config *current = new_output_config(oc->name);
|
||||
merge_output_config(current, config->output_configs->items[i]);
|
||||
merge_output_config(current, oc);
|
||||
|
|
@ -124,11 +124,11 @@ struct output_config *store_output_config(struct output_config *oc) {
|
|||
list_add(config->output_configs, oc);
|
||||
} else {
|
||||
// New wildcard config. Just add it
|
||||
wlr_log(WLR_DEBUG, "Adding output * config");
|
||||
sway_log(SWAY_DEBUG, "Adding output * config");
|
||||
list_add(config->output_configs, oc);
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
||||
sway_log(SWAY_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
||||
"position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
|
||||
oc->name, oc->enabled, oc->width, oc->height, oc->refresh_rate,
|
||||
oc->x, oc->y, oc->scale, oc->transform, oc->background,
|
||||
|
|
@ -141,7 +141,7 @@ static bool 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(WLR_DEBUG, "Assigning custom mode to %s", output->name);
|
||||
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
|
||||
return wlr_output_set_custom_mode(output, width, height, mhz);
|
||||
}
|
||||
|
||||
|
|
@ -156,11 +156,11 @@ static bool set_mode(struct wlr_output *output, int width, int height,
|
|||
}
|
||||
}
|
||||
if (!best) {
|
||||
wlr_log(WLR_ERROR, "Configured mode for %s not available", output->name);
|
||||
wlr_log(WLR_INFO, "Picking default mode instead");
|
||||
sway_log(SWAY_ERROR, "Configured mode for %s not available", output->name);
|
||||
sway_log(SWAY_INFO, "Picking default mode instead");
|
||||
best = wl_container_of(output->modes.prev, mode, link);
|
||||
} else {
|
||||
wlr_log(WLR_DEBUG, "Assigning configured mode to %s", output->name);
|
||||
sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
|
||||
}
|
||||
return wlr_output_set_mode(output, best);
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ static bool 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(WLR_ERROR, "Unable to terminate swaybg [pid: %d]", pid);
|
||||
sway_log(SWAY_ERROR, "Unable to terminate swaybg [pid: %d]", pid);
|
||||
} else {
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
|
|
@ -197,7 +197,7 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
|||
|
||||
bool modeset_success;
|
||||
if (oc && oc->width > 0 && oc->height > 0) {
|
||||
wlr_log(WLR_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
|
||||
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
|
||||
oc->height, oc->refresh_rate);
|
||||
modeset_success =
|
||||
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
|
||||
|
|
@ -213,22 +213,22 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
|||
// Failed to modeset, maybe the output is missing a CRTC. Leave the
|
||||
// output disabled for now and try again when the output gets the mode
|
||||
// we asked for.
|
||||
wlr_log(WLR_ERROR, "Failed to modeset output %s", wlr_output->name);
|
||||
sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (oc && oc->scale > 0) {
|
||||
wlr_log(WLR_DEBUG, "Set %s scale to %f", oc->name, oc->scale);
|
||||
sway_log(SWAY_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(WLR_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
|
||||
sway_log(SWAY_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(WLR_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
||||
sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
||||
wlr_output_layout_add(root->output_layout, wlr_output, oc->x, oc->y);
|
||||
} else {
|
||||
wlr_output_layout_add_auto(root->output_layout, wlr_output);
|
||||
|
|
@ -238,7 +238,7 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
|||
terminate_swaybg(output->bg_pid);
|
||||
}
|
||||
if (oc && oc->background && config->swaybg_command) {
|
||||
wlr_log(WLR_DEBUG, "Setting background for output %s to %s",
|
||||
sway_log(SWAY_DEBUG, "Setting background for output %s to %s",
|
||||
wlr_output->name, oc->background);
|
||||
|
||||
char *const cmd[] = {
|
||||
|
|
@ -252,21 +252,21 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
|||
|
||||
output->bg_pid = fork();
|
||||
if (output->bg_pid < 0) {
|
||||
wlr_log_errno(WLR_ERROR, "fork failed");
|
||||
sway_log_errno(SWAY_ERROR, "fork failed");
|
||||
} else if (output->bg_pid == 0) {
|
||||
execvp(cmd[0], cmd);
|
||||
wlr_log_errno(WLR_ERROR, "Failed to execute swaybg");
|
||||
sway_log_errno(SWAY_ERROR, "Failed to execute swaybg");
|
||||
}
|
||||
}
|
||||
|
||||
if (oc) {
|
||||
switch (oc->dpms_state) {
|
||||
case DPMS_ON:
|
||||
wlr_log(WLR_DEBUG, "Turning on screen");
|
||||
sway_log(SWAY_DEBUG, "Turning on screen");
|
||||
wlr_output_enable(wlr_output, true);
|
||||
break;
|
||||
case DPMS_OFF:
|
||||
wlr_log(WLR_DEBUG, "Turning off screen");
|
||||
sway_log(SWAY_DEBUG, "Turning off screen");
|
||||
wlr_output_enable(wlr_output, false);
|
||||
break;
|
||||
case DPMS_IGNORE:
|
||||
|
|
@ -325,7 +325,7 @@ static struct output_config *get_output_config(char *identifier,
|
|||
merge_output_config(result, oc_name);
|
||||
merge_output_config(result, oc_id);
|
||||
|
||||
wlr_log(WLR_DEBUG, "Generated output config \"%s\" (enabled: %d)"
|
||||
sway_log(SWAY_DEBUG, "Generated output config \"%s\" (enabled: %d)"
|
||||
" (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)"
|
||||
" (dpms %d)", result->name, result->enabled, result->width,
|
||||
result->height, result->refresh_rate, result->x, result->y,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
struct seat_config *new_seat_config(const char* name) {
|
||||
struct seat_config *seat = calloc(1, sizeof(struct seat_config));
|
||||
if (!seat) {
|
||||
wlr_log(WLR_DEBUG, "Unable to allocate seat config");
|
||||
sway_log(SWAY_DEBUG, "Unable to allocate seat config");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ static void merge_wildcard_on_all(struct seat_config *wildcard) {
|
|||
for (int i = 0; i < config->seat_configs->length; i++) {
|
||||
struct seat_config *sc = config->seat_configs->items[i];
|
||||
if (strcmp(wildcard->name, sc->name) != 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging seat * config on %s", sc->name);
|
||||
sway_log(SWAY_DEBUG, "Merging seat * config on %s", sc->name);
|
||||
merge_seat_config(sc, wildcard);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,16 +48,16 @@ struct seat_config *store_seat_config(struct seat_config *sc) {
|
|||
|
||||
int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name);
|
||||
if (i >= 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging on top of existing seat config");
|
||||
sway_log(SWAY_DEBUG, "Merging on top of existing seat config");
|
||||
struct seat_config *current = config->seat_configs->items[i];
|
||||
merge_seat_config(current, sc);
|
||||
free_seat_config(sc);
|
||||
sc = current;
|
||||
} else if (!wildcard) {
|
||||
wlr_log(WLR_DEBUG, "Adding non-wildcard seat config");
|
||||
sway_log(SWAY_DEBUG, "Adding non-wildcard seat config");
|
||||
i = list_seq_find(config->seat_configs, seat_name_cmp, "*");
|
||||
if (i >= 0) {
|
||||
wlr_log(WLR_DEBUG, "Merging on top of seat * config");
|
||||
sway_log(SWAY_DEBUG, "Merging on top of seat * config");
|
||||
struct seat_config *current = new_seat_config(sc->name);
|
||||
merge_seat_config(current, config->seat_configs->items[i]);
|
||||
merge_seat_config(current, sc);
|
||||
|
|
@ -67,11 +67,11 @@ struct seat_config *store_seat_config(struct seat_config *sc) {
|
|||
list_add(config->seat_configs, sc);
|
||||
} else {
|
||||
// New wildcard config. Just add it
|
||||
wlr_log(WLR_DEBUG, "Adding seat * config");
|
||||
sway_log(SWAY_DEBUG, "Adding seat * config");
|
||||
list_add(config->seat_configs, sc);
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Config stored for seat %s", sc->name);
|
||||
sway_log(SWAY_DEBUG, "Config stored for seat %s", sc->name);
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ struct seat_attachment_config *seat_attachment_config_new(void) {
|
|||
struct seat_attachment_config *attachment =
|
||||
calloc(1, sizeof(struct seat_attachment_config));
|
||||
if (!attachment) {
|
||||
wlr_log(WLR_DEBUG, "cannot allocate attachment config");
|
||||
sway_log(SWAY_DEBUG, "cannot allocate attachment config");
|
||||
return NULL;
|
||||
}
|
||||
return attachment;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue