Implement empty workspaces in swaybar

This commit is contained in:
Marko 2023-06-09 20:16:39 +02:00
parent d3ac856688
commit 173c918e43
10 changed files with 44 additions and 0 deletions

View file

@ -244,6 +244,7 @@ sway_cmd bar_colors_cmd_focused_separator;
sway_cmd bar_colors_cmd_statusline; sway_cmd bar_colors_cmd_statusline;
sway_cmd bar_colors_cmd_focused_statusline; sway_cmd bar_colors_cmd_focused_statusline;
sway_cmd bar_colors_cmd_urgent_workspace; sway_cmd bar_colors_cmd_urgent_workspace;
sway_cmd bar_colors_cmd_empty_workspace;
sway_cmd input_cmd_seat; sway_cmd input_cmd_seat;
sway_cmd input_cmd_accel_profile; sway_cmd input_cmd_accel_profile;

View file

@ -387,6 +387,9 @@ struct bar_config {
char *urgent_workspace_border; char *urgent_workspace_border;
char *urgent_workspace_bg; char *urgent_workspace_bg;
char *urgent_workspace_text; char *urgent_workspace_text;
char *empty_workspace_border;
char *empty_workspace_bg;
char *empty_workspace_text;
char *binding_mode_border; char *binding_mode_border;
char *binding_mode_bg; char *binding_mode_bg;
char *binding_mode_text; char *binding_mode_text;

View file

@ -86,6 +86,7 @@ struct swaybar_workspace {
bool focused; bool focused;
bool visible; bool visible;
bool urgent; bool urgent;
bool empty;
}; };
bool bar_setup(struct swaybar *bar, const char *socket_path); bool bar_setup(struct swaybar *bar, const char *socket_path);

View file

@ -65,6 +65,7 @@ struct swaybar_config {
struct box_colors active_workspace; struct box_colors active_workspace;
struct box_colors inactive_workspace; struct box_colors inactive_workspace;
struct box_colors urgent_workspace; struct box_colors urgent_workspace;
struct box_colors empty_workspace;
struct box_colors binding_mode; struct box_colors binding_mode;
} colors; } colors;

View file

@ -8,6 +8,7 @@ static const struct cmd_handler bar_colors_handlers[] = {
{ "active_workspace", bar_colors_cmd_active_workspace }, { "active_workspace", bar_colors_cmd_active_workspace },
{ "background", bar_colors_cmd_background }, { "background", bar_colors_cmd_background },
{ "binding_mode", bar_colors_cmd_binding_mode }, { "binding_mode", bar_colors_cmd_binding_mode },
{ "empty_workspace", bar_colors_cmd_empty_workspace },
{ "focused_background", bar_colors_cmd_focused_background }, { "focused_background", bar_colors_cmd_focused_background },
{ "focused_separator", bar_colors_cmd_focused_separator }, { "focused_separator", bar_colors_cmd_focused_separator },
{ "focused_statusline", bar_colors_cmd_focused_statusline }, { "focused_statusline", bar_colors_cmd_focused_statusline },
@ -150,3 +151,12 @@ struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
}; };
return parse_three_colors(colors, "urgent_workspace", argc, argv); return parse_three_colors(colors, "urgent_workspace", argc, argv);
} }
struct cmd_results *bar_colors_cmd_empty_workspace(int argc, char **argv) {
char **colors[3] = {
&(config->current_bar->colors.empty_workspace_border),
&(config->current_bar->colors.empty_workspace_bg),
&(config->current_bar->colors.empty_workspace_text)
};
return parse_three_colors(colors, "empty_workspace", argc, argv);
}

View file

@ -67,6 +67,9 @@ void free_bar_config(struct bar_config *bar) {
free(bar->colors.urgent_workspace_border); free(bar->colors.urgent_workspace_border);
free(bar->colors.urgent_workspace_bg); free(bar->colors.urgent_workspace_bg);
free(bar->colors.urgent_workspace_text); free(bar->colors.urgent_workspace_text);
free(bar->colors.empty_workspace_border);
free(bar->colors.empty_workspace_bg);
free(bar->colors.empty_workspace_text);
free(bar->colors.binding_mode_border); free(bar->colors.binding_mode_border);
free(bar->colors.binding_mode_bg); free(bar->colors.binding_mode_bg);
free(bar->colors.binding_mode_text); free(bar->colors.binding_mode_text);
@ -161,6 +164,15 @@ struct bar_config *default_bar_config(void) {
if (!(bar->colors.urgent_workspace_text = strndup("#ffffffff", 9))) { if (!(bar->colors.urgent_workspace_text = strndup("#ffffffff", 9))) {
goto cleanup; goto cleanup;
} }
if (!(bar->colors.empty_workspace_border = strndup("#000000ff", 9))) {
goto cleanup;
}
if (!(bar->colors.empty_workspace_bg = strndup("#000000ff", 9))) {
goto cleanup;
}
if (!(bar->colors.empty_workspace_text = strndup("#666666FF", 9))) {
goto cleanup;
}
// if the following colors stay undefined, they fall back to background, // if the following colors stay undefined, they fall back to background,
// statusline, separator and urgent_workspace_*. // statusline, separator and urgent_workspace_*.
bar->colors.focused_background = NULL; bar->colors.focused_background = NULL;

View file

@ -1307,6 +1307,13 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_object_add(colors, "urgent_workspace_text", json_object_object_add(colors, "urgent_workspace_text",
json_object_new_string(bar->colors.urgent_workspace_text)); json_object_new_string(bar->colors.urgent_workspace_text));
json_object_object_add(colors, "empty_workspace_border",
json_object_new_string(bar->colors.empty_workspace_border));
json_object_object_add(colors, "empty_workspace_bg",
json_object_new_string(bar->colors.empty_workspace_bg));
json_object_object_add(colors, "empty_workspace_text",
json_object_new_string(bar->colors.empty_workspace_text));
if (bar->colors.binding_mode_border) { if (bar->colors.binding_mode_border) {
json_object_object_add(colors, "binding_mode_border", json_object_object_add(colors, "binding_mode_border",
json_object_new_string(bar->colors.binding_mode_border)); json_object_new_string(bar->colors.binding_mode_border));

View file

@ -73,6 +73,10 @@ struct swaybar_config *init_config(void) {
config->colors.urgent_workspace.background = 0x900000FF; config->colors.urgent_workspace.background = 0x900000FF;
config->colors.urgent_workspace.text = 0xFFFFFFFF; config->colors.urgent_workspace.text = 0xFFFFFFFF;
config->colors.empty_workspace.border = 0x000000FF;
config->colors.empty_workspace.background = 0x000000FF;
config->colors.empty_workspace.text = 0x666666FF;
config->colors.binding_mode.border = 0x2F343AFF; config->colors.binding_mode.border = 0x2F343AFF;
config->colors.binding_mode.background = 0x900000FF; config->colors.binding_mode.background = 0x900000FF;
config->colors.binding_mode.text = 0xFFFFFFFF; config->colors.binding_mode.text = 0xFFFFFFFF;

View file

@ -77,6 +77,9 @@ static void ipc_parse_colors(
{ "urgent_workspace_border", &config->colors.urgent_workspace.border }, { "urgent_workspace_border", &config->colors.urgent_workspace.border },
{ "urgent_workspace_bg", &config->colors.urgent_workspace.background }, { "urgent_workspace_bg", &config->colors.urgent_workspace.background },
{ "urgent_workspace_text", &config->colors.urgent_workspace.text }, { "urgent_workspace_text", &config->colors.urgent_workspace.text },
{ "empty_workspace_border", &config->colors.empty_workspace.border },
{ "empty_workspace_bg", &config->colors.empty_workspace.background },
{ "empty_workspace_text", &config->colors.empty_workspace.text },
{ "binding_mode_border", &config->colors.binding_mode.border }, { "binding_mode_border", &config->colors.binding_mode.border },
{ "binding_mode_bg", &config->colors.binding_mode.background }, { "binding_mode_bg", &config->colors.binding_mode.background },
{ "binding_mode_text", &config->colors.binding_mode.text }, { "binding_mode_text", &config->colors.binding_mode.text },

View file

@ -623,6 +623,8 @@ static uint32_t render_workspace_button(struct render_context *ctx,
box_colors = config->colors.focused_workspace; box_colors = config->colors.focused_workspace;
} else if (ws->visible) { } else if (ws->visible) {
box_colors = config->colors.active_workspace; box_colors = config->colors.active_workspace;
} else if (ws->empty) {
box_colors = config->colors.empty_workspace;
} else { } else {
box_colors = config->colors.inactive_workspace; box_colors = config->colors.inactive_workspace;
} }