mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
Merge pull request #3415 from RedSoxFan/swaybar-output-improved
swaybar: allow identifiers for output and tray
This commit is contained in:
commit
9b5ac08682
|
@ -61,6 +61,7 @@ struct swaybar_output {
|
||||||
struct wl_list hotspots; // swaybar_hotspot::link
|
struct wl_list hotspots; // swaybar_hotspot::link
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
char *identifier;
|
||||||
bool focused;
|
bool focused;
|
||||||
|
|
||||||
uint32_t width, height;
|
uint32_t width, height;
|
||||||
|
|
|
@ -59,6 +59,7 @@ static void swaybar_output_free(struct swaybar_output *output) {
|
||||||
free_workspaces(&output->workspaces);
|
free_workspaces(&output->workspaces);
|
||||||
wl_list_remove(&output->link);
|
wl_list_remove(&output->link);
|
||||||
free(output->name);
|
free(output->name);
|
||||||
|
free(output->identifier);
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,13 +167,15 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool bar_uses_output(struct swaybar *bar, const char *name) {
|
static bool bar_uses_output(struct swaybar_output *output) {
|
||||||
if (bar->config->all_outputs) {
|
if (output->bar->config->all_outputs) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
char *identifier = output->identifier;
|
||||||
struct config_output *coutput;
|
struct config_output *coutput;
|
||||||
wl_list_for_each(coutput, &bar->config->outputs, link) {
|
wl_list_for_each(coutput, &output->bar->config->outputs, link) {
|
||||||
if (strcmp(coutput->name, name) == 0) {
|
if (strcmp(coutput->name, output->name) == 0 ||
|
||||||
|
(identifier && strcmp(coutput->name, identifier) == 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,7 +236,7 @@ static void xdg_output_handle_done(void *data,
|
||||||
struct swaybar *bar = output->bar;
|
struct swaybar *bar = output->bar;
|
||||||
|
|
||||||
assert(output->name != NULL);
|
assert(output->name != NULL);
|
||||||
if (!bar_uses_output(bar, output->name)) {
|
if (!bar_uses_output(output)) {
|
||||||
swaybar_output_free(output);
|
swaybar_output_free(output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -258,7 +261,22 @@ static void xdg_output_handle_name(void *data,
|
||||||
|
|
||||||
static void xdg_output_handle_description(void *data,
|
static void xdg_output_handle_description(void *data,
|
||||||
struct zxdg_output_v1 *xdg_output, const char *description) {
|
struct zxdg_output_v1 *xdg_output, const char *description) {
|
||||||
// Who cares
|
// wlroots currently sets the description to `make model serial (name)`
|
||||||
|
// If this changes in the future, this will need to be modified.
|
||||||
|
struct swaybar_output *output = data;
|
||||||
|
free(output->identifier);
|
||||||
|
output->identifier = NULL;
|
||||||
|
char *paren = strrchr(description, '(');
|
||||||
|
if (paren) {
|
||||||
|
size_t length = paren - description;
|
||||||
|
output->identifier = malloc(length);
|
||||||
|
if (!output->identifier) {
|
||||||
|
wlr_log(WLR_ERROR, "Failed to allocate output identifier");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strncpy(output->identifier, description, length);
|
||||||
|
output->identifier[length - 1] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct zxdg_output_v1_listener xdg_output_listener = {
|
struct zxdg_output_v1_listener xdg_output_listener = {
|
||||||
|
|
|
@ -101,13 +101,17 @@ void tray_in(int fd, short mask, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmp_output(const void *item, const void *cmp_to) {
|
static int cmp_output(const void *item, const void *cmp_to) {
|
||||||
return strcmp(item, cmp_to);
|
const struct swaybar_output *output = cmp_to;
|
||||||
|
if (output->identifier && strcmp(item, output->identifier) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return strcmp(item, output->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
|
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
|
||||||
struct swaybar_config *config = output->bar->config;
|
struct swaybar_config *config = output->bar->config;
|
||||||
if (config->tray_outputs) {
|
if (config->tray_outputs) {
|
||||||
if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) {
|
if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // else display on all
|
} // else display on all
|
||||||
|
|
Loading…
Reference in a new issue