mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 18:01:29 +00:00
Add bar configuration commands
This commit is contained in:
parent
6836074fed
commit
bf7a4cd0eb
|
@ -74,6 +74,9 @@ void free_cmd_results(struct cmd_results *results);
|
|||
*/
|
||||
const char *cmd_results_to_json(struct cmd_results *results);
|
||||
|
||||
struct cmd_results *add_color(const char *name,
|
||||
char *buffer, const char *color);
|
||||
|
||||
typedef struct cmd_results *sway_cmd(int argc, char **argv);
|
||||
|
||||
sway_cmd cmd_assign;
|
||||
|
|
|
@ -12,5 +12,6 @@ struct sockaddr_un *ipc_user_sockaddr(void);
|
|||
|
||||
void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change);
|
||||
void ipc_event_window(swayc_t *window, const char *change);
|
||||
void ipc_event_barconfig_update(struct bar_config *bar);
|
||||
|
||||
#endif
|
||||
|
|
135
sway/commands.c
135
sway/commands.c
|
@ -91,45 +91,9 @@ void apply_seat_config(struct seat_config *seat) {
|
|||
sway_input_manager_apply_seat_config(input_manager, seat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and add color to buffer.
|
||||
*
|
||||
* return error object, or NULL if color is valid.
|
||||
*/
|
||||
struct cmd_results *add_color(const char *name, char *buffer, const char *color) {
|
||||
int len = strlen(color);
|
||||
if (len != 7 && len != 9) {
|
||||
return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
|
||||
}
|
||||
|
||||
if (color[0] != '#') {
|
||||
return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 1; i < len; ++i) {
|
||||
if (!isxdigit(color[i])) {
|
||||
return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
|
||||
}
|
||||
}
|
||||
|
||||
// copy color to buffer
|
||||
strncpy(buffer, color, len);
|
||||
// add default alpha channel if color was defined without it
|
||||
if (len == 7) {
|
||||
buffer[7] = 'f';
|
||||
buffer[8] = 'f';
|
||||
}
|
||||
buffer[9] = '\0';
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* handlers that can run in either config or command context
|
||||
* Keep alphabetized
|
||||
*/
|
||||
/* Keep alphabetized */
|
||||
static struct cmd_handler handlers[] = {
|
||||
{ "bar", cmd_bar },
|
||||
{ "bindcode", cmd_bindcode },
|
||||
{ "bindsym", cmd_bindsym },
|
||||
{ "exec", cmd_exec },
|
||||
|
@ -141,18 +105,53 @@ static struct cmd_handler handlers[] = {
|
|||
{ "workspace", cmd_workspace },
|
||||
};
|
||||
|
||||
/**
|
||||
* Commands that can *only* run in the config loading context
|
||||
* Keep alphabetized
|
||||
*/
|
||||
static struct cmd_handler bar_handlers[] = {
|
||||
{ "activate_button", bar_cmd_activate_button },
|
||||
{ "binding_mode_indicator", bar_cmd_binding_mode_indicator },
|
||||
{ "bindsym", bar_cmd_bindsym },
|
||||
{ "colors", bar_cmd_colors },
|
||||
{ "context_button", bar_cmd_context_button },
|
||||
{ "font", bar_cmd_font },
|
||||
{ "height", bar_cmd_height },
|
||||
{ "hidden_state", bar_cmd_hidden_state },
|
||||
{ "icon_theme", bar_cmd_icon_theme },
|
||||
{ "id", bar_cmd_id },
|
||||
{ "mode", bar_cmd_mode },
|
||||
{ "modifier", bar_cmd_modifier },
|
||||
{ "output", bar_cmd_output },
|
||||
{ "pango_markup", bar_cmd_pango_markup },
|
||||
{ "position", bar_cmd_position },
|
||||
{ "secondary_button", bar_cmd_secondary_button },
|
||||
{ "separator_symbol", bar_cmd_separator_symbol },
|
||||
{ "status_command", bar_cmd_status_command },
|
||||
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
|
||||
{ "swaybar_command", bar_cmd_swaybar_command },
|
||||
{ "tray_output", bar_cmd_tray_output },
|
||||
{ "tray_padding", bar_cmd_tray_padding },
|
||||
{ "workspace_buttons", bar_cmd_workspace_buttons },
|
||||
{ "wrap_scroll", bar_cmd_wrap_scroll },
|
||||
};
|
||||
|
||||
static struct cmd_handler bar_colors_handlers[] = {
|
||||
{ "active_workspace", bar_colors_cmd_active_workspace },
|
||||
{ "background", bar_colors_cmd_background },
|
||||
{ "binding_mode", bar_colors_cmd_binding_mode },
|
||||
{ "focused_background", bar_colors_cmd_focused_background },
|
||||
{ "focused_separator", bar_colors_cmd_focused_separator },
|
||||
{ "focused_statusline", bar_colors_cmd_focused_statusline },
|
||||
{ "focused_workspace", bar_colors_cmd_focused_workspace },
|
||||
{ "inactive_workspace", bar_colors_cmd_inactive_workspace },
|
||||
{ "separator", bar_colors_cmd_separator },
|
||||
{ "statusline", bar_colors_cmd_statusline },
|
||||
{ "urgent_workspace", bar_colors_cmd_urgent_workspace },
|
||||
};
|
||||
|
||||
/* Config-time only commands. Keep alphabetized */
|
||||
static struct cmd_handler config_handlers[] = {
|
||||
{ "set", cmd_set },
|
||||
};
|
||||
|
||||
/**
|
||||
* Commands that can *not* run in the config loading context
|
||||
* Keep alphabetized
|
||||
*/
|
||||
/* Runtime-only commands. Keep alphabetized */
|
||||
static struct cmd_handler command_handlers[] = {
|
||||
{ "exit", cmd_exit },
|
||||
{ "focus", cmd_focus },
|
||||
|
@ -200,13 +199,19 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
|
|||
|
||||
bool config_loading = config->reading || !config->active;
|
||||
|
||||
if (block == CMD_BLOCK_INPUT) {
|
||||
// input commands can run in either context
|
||||
if (block == CMD_BLOCK_BAR) {
|
||||
return bsearch(&d, bar_handlers,
|
||||
sizeof(bar_handlers) / sizeof(struct cmd_handler),
|
||||
sizeof(struct cmd_handler), handler_compare);
|
||||
} else if (block == CMD_BLOCK_BAR_COLORS) {
|
||||
return bsearch(&d, bar_colors_handlers,
|
||||
sizeof(bar_colors_handlers) / sizeof(struct cmd_handler),
|
||||
sizeof(struct cmd_handler), handler_compare);
|
||||
} else if (block == CMD_BLOCK_INPUT) {
|
||||
return bsearch(&d, input_handlers,
|
||||
sizeof(input_handlers) / sizeof(struct cmd_handler),
|
||||
sizeof(struct cmd_handler), handler_compare);
|
||||
} else if (block == CMD_BLOCK_SEAT) {
|
||||
// seat commands can run in either context
|
||||
return bsearch(&d, seat_handlers,
|
||||
sizeof(seat_handlers) / sizeof(struct cmd_handler),
|
||||
sizeof(struct cmd_handler), handler_compare);
|
||||
|
@ -558,3 +563,35 @@ const char *cmd_results_to_json(struct cmd_results *results) {
|
|||
free(root);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and add color to buffer.
|
||||
*
|
||||
* return error object, or NULL if color is valid.
|
||||
*/
|
||||
struct cmd_results *add_color(const char *name,
|
||||
char *buffer, const char *color) {
|
||||
int len = strlen(color);
|
||||
if (len != 7 && len != 9) {
|
||||
return cmd_results_new(CMD_INVALID, name,
|
||||
"Invalid color definition %s", color);
|
||||
}
|
||||
if (color[0] != '#') {
|
||||
return cmd_results_new(CMD_INVALID, name,
|
||||
"Invalid color definition %s", color);
|
||||
}
|
||||
for (int i = 1; i < len; ++i) {
|
||||
if (!isxdigit(color[i])) {
|
||||
return cmd_results_new(CMD_INVALID, name,
|
||||
"Invalid color definition %s", color);
|
||||
}
|
||||
}
|
||||
strncpy(buffer, color, len);
|
||||
// add default alpha channel if color was defined without it
|
||||
if (len == 7) {
|
||||
buffer[7] = 'f';
|
||||
buffer[8] = 'f';
|
||||
}
|
||||
buffer[9] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
|
|
57
sway/commands/bar.c
Normal file
57
sway/commands/bar.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "util.h"
|
||||
|
||||
struct cmd_results *cmd_bar(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (config->reading && strcmp("{", argv[0]) != 0) {
|
||||
return cmd_results_new(CMD_INVALID, "bar",
|
||||
"Expected '{' at start of bar config definition.");
|
||||
}
|
||||
|
||||
if (!config->reading) {
|
||||
if (argc > 1) {
|
||||
if (strcasecmp("mode", argv[0]) == 0) {
|
||||
return bar_cmd_mode(argc-1, argv + 1);
|
||||
}
|
||||
|
||||
if (strcasecmp("hidden_state", argv[0]) == 0) {
|
||||
return bar_cmd_hidden_state(argc-1, argv + 1);
|
||||
}
|
||||
}
|
||||
return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file.");
|
||||
}
|
||||
|
||||
// Create new bar with default values
|
||||
struct bar_config *bar = default_bar_config();
|
||||
if (!bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar state");
|
||||
}
|
||||
|
||||
// set bar id
|
||||
int i;
|
||||
for (i = 0; i < config->bars->length; ++i) {
|
||||
if (bar == config->bars->items[i]) {
|
||||
const int len = 5 + numlen(i); // "bar-" + i + \0
|
||||
bar->id = malloc(len * sizeof(char));
|
||||
if (bar->id) {
|
||||
snprintf(bar->id, len, "bar-%d", i);
|
||||
} else {
|
||||
return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set current bar
|
||||
config->current_bar = bar;
|
||||
wlr_log(L_DEBUG, "Configuring bar %s", bar->id);
|
||||
return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
|
||||
}
|
9
sway/commands/bar/activate_button.c
Normal file
9
sway/commands/bar/activate_button.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_activate_button(int argc, char **argv) {
|
||||
const char *cmd_name = "activate_button";
|
||||
// TODO TRAY
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY");
|
||||
}
|
27
sway/commands/bar/binding_mode_indicator.c
Normal file
27
sway/commands/bar/binding_mode_indicator.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "binding_mode_indicator", "No bar defined.");
|
||||
}
|
||||
|
||||
if (strcasecmp("yes", argv[0]) == 0) {
|
||||
config->current_bar->binding_mode_indicator = true;
|
||||
wlr_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", config->current_bar->id);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "binding_mode_indicator", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
11
sway/commands/bar/bindsym.c
Normal file
11
sway/commands/bar/bindsym.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
|
||||
struct cmd_results *bar_cmd_bindsym(int argc, char **argv) {
|
||||
return cmd_results_new(CMD_FAILURE, "bindsym", "TODO"); // TODO
|
||||
}
|
129
sway/commands/bar/colors.c
Normal file
129
sway/commands/bar/colors.c
Normal file
|
@ -0,0 +1,129 @@
|
|||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
|
||||
static struct cmd_results *parse_single_color(char **color, const char *cmd_name, int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!*color) {
|
||||
*color = malloc(10);
|
||||
if (!*color) {
|
||||
return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color");
|
||||
}
|
||||
}
|
||||
|
||||
error = add_color(cmd_name, *color, argv[0]);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_name, int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if (argc != 3) {
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly three color values");
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (!*colors[i]) {
|
||||
*(colors[i]) = malloc(10);
|
||||
if (!*(colors[i])) {
|
||||
return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color");
|
||||
}
|
||||
}
|
||||
error = add_color(cmd_name, *(colors[i]), argv[i]);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_cmd_colors(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (strcmp("{", argv[0]) != 0) {
|
||||
return cmd_results_new(CMD_INVALID, "colors",
|
||||
"Expected '{' at the start of colors config definition.");
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
|
||||
char **colors[3] = {
|
||||
&(config->current_bar->colors.active_workspace_border),
|
||||
&(config->current_bar->colors.active_workspace_bg),
|
||||
&(config->current_bar->colors.active_workspace_text)
|
||||
};
|
||||
return parse_three_colors(colors, "active_workspace", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
|
||||
return parse_single_color(&(config->current_bar->colors.background), "background", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) {
|
||||
return parse_single_color(&(config->current_bar->colors.focused_background), "focused_background", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
|
||||
char **colors[3] = {
|
||||
&(config->current_bar->colors.binding_mode_border),
|
||||
&(config->current_bar->colors.binding_mode_bg),
|
||||
&(config->current_bar->colors.binding_mode_text)
|
||||
};
|
||||
return parse_three_colors(colors, "binding_mode", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) {
|
||||
char **colors[3] = {
|
||||
&(config->current_bar->colors.focused_workspace_border),
|
||||
&(config->current_bar->colors.focused_workspace_bg),
|
||||
&(config->current_bar->colors.focused_workspace_text)
|
||||
};
|
||||
return parse_three_colors(colors, "focused_workspace", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) {
|
||||
char **colors[3] = {
|
||||
&(config->current_bar->colors.inactive_workspace_border),
|
||||
&(config->current_bar->colors.inactive_workspace_bg),
|
||||
&(config->current_bar->colors.inactive_workspace_text)
|
||||
};
|
||||
return parse_three_colors(colors, "inactive_workspace", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) {
|
||||
return parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) {
|
||||
return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) {
|
||||
return parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) {
|
||||
return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
|
||||
char **colors[3] = {
|
||||
&(config->current_bar->colors.urgent_workspace_border),
|
||||
&(config->current_bar->colors.urgent_workspace_bg),
|
||||
&(config->current_bar->colors.urgent_workspace_text)
|
||||
};
|
||||
return parse_three_colors(colors, "urgent_workspace", argc, argv);
|
||||
}
|
9
sway/commands/bar/context_button.c
Normal file
9
sway/commands/bar/context_button.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_context_button(int argc, char **argv) {
|
||||
const char *cmd_name = "context_button";
|
||||
// TODO TRAY
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY");
|
||||
}
|
26
sway/commands/bar/font.c
Normal file
26
sway/commands/bar/font.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
|
||||
struct cmd_results *bar_cmd_font(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "font", "No bar defined.");
|
||||
}
|
||||
|
||||
char *font = join_args(argv, argc);
|
||||
free(config->current_bar->font);
|
||||
if (strlen(font) > 6 && strncmp("pango:", font, 6) == 0) {
|
||||
config->current_bar->font = font;
|
||||
} else {
|
||||
config->current_bar->font = font;
|
||||
}
|
||||
|
||||
wlr_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);
|
||||
}
|
21
sway/commands/bar/height.c
Normal file
21
sway/commands/bar/height.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_height(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
int height = atoi(argv[0]);
|
||||
if (height < 0) {
|
||||
return cmd_results_new(CMD_INVALID, "height",
|
||||
"Invalid height value: %s", argv[0]);
|
||||
}
|
||||
|
||||
config->current_bar->height = height;
|
||||
wlr_log(L_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
78
sway/commands/bar/hidden_state.c
Normal file
78
sway/commands/bar/hidden_state.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/ipc-server.h"
|
||||
#include "log.h"
|
||||
|
||||
static struct cmd_results *bar_set_hidden_state(struct bar_config *bar,
|
||||
const char *hidden_state) {
|
||||
char *old_state = bar->hidden_state;
|
||||
if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) {
|
||||
if (strcasecmp("hide", bar->hidden_state) == 0) {
|
||||
bar->hidden_state = strdup("show");
|
||||
} else if (strcasecmp("show", bar->hidden_state) == 0) {
|
||||
bar->hidden_state = strdup("hide");
|
||||
}
|
||||
} else if (strcasecmp("hide", hidden_state) == 0) {
|
||||
bar->hidden_state = strdup("hide");
|
||||
} else if (strcasecmp("show", hidden_state) == 0) {
|
||||
bar->hidden_state = strdup("show");
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "hidden_state",
|
||||
"Invalid value %s", hidden_state);
|
||||
}
|
||||
|
||||
if (strcmp(old_state, bar->hidden_state) != 0) {
|
||||
if (!config->reading) {
|
||||
ipc_event_barconfig_update(bar);
|
||||
}
|
||||
wlr_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s",
|
||||
bar->hidden_state, bar->id);
|
||||
}
|
||||
|
||||
// free old mode
|
||||
free(old_state);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (config->reading && argc > 1) {
|
||||
return cmd_results_new(CMD_INVALID, "hidden_state",
|
||||
"Unexpected value %s in config mode", argv[1]);
|
||||
}
|
||||
|
||||
const char *state = argv[0];
|
||||
|
||||
if (config->reading) {
|
||||
return bar_set_hidden_state(config->current_bar, state);
|
||||
}
|
||||
|
||||
const char *id = NULL;
|
||||
if (argc == 2) {
|
||||
id = argv[1];
|
||||
}
|
||||
|
||||
struct bar_config *bar;
|
||||
for (int i = 0; i < config->bars->length; ++i) {
|
||||
bar = config->bars->items[i];
|
||||
if (id && strcmp(id, bar->id) == 0) {
|
||||
return bar_set_hidden_state(bar, state);
|
||||
}
|
||||
|
||||
error = bar_set_hidden_state(bar, state);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
9
sway/commands/bar/icon_theme.c
Normal file
9
sway/commands/bar/icon_theme.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
|
||||
struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) {
|
||||
const char *cmd_name = "tray_output";
|
||||
// TODO TRAY
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY");
|
||||
}
|
33
sway/commands/bar/id.c
Normal file
33
sway/commands/bar/id.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_id(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
const char *name = argv[0];
|
||||
const char *oldname = config->current_bar->id;
|
||||
|
||||
// check if id is used by a previously defined bar
|
||||
int i;
|
||||
for (i = 0; i < config->bars->length; ++i) {
|
||||
struct bar_config *find = config->bars->items[i];
|
||||
if (strcmp(name, find->id) == 0 && config->current_bar != find) {
|
||||
return cmd_results_new(CMD_FAILURE, "id",
|
||||
"Id '%s' already defined for another bar. Id unchanged (%s).",
|
||||
name, oldname);
|
||||
}
|
||||
}
|
||||
|
||||
wlr_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name);
|
||||
|
||||
// free old bar id
|
||||
free(config->current_bar->id);
|
||||
|
||||
config->current_bar->id = strdup(name);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
78
sway/commands/bar/mode.c
Normal file
78
sway/commands/bar/mode.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/ipc-server.h"
|
||||
#include "log.h"
|
||||
|
||||
static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) {
|
||||
char *old_mode = bar->mode;
|
||||
if (strcasecmp("toggle", mode) == 0 && !config->reading) {
|
||||
if (strcasecmp("dock", bar->mode) == 0) {
|
||||
bar->mode = strdup("hide");
|
||||
} else if (strcasecmp("hide", bar->mode) == 0) {
|
||||
bar->mode = strdup("dock");
|
||||
}
|
||||
} else if (strcasecmp("dock", mode) == 0) {
|
||||
bar->mode = strdup("dock");
|
||||
} else if (strcasecmp("hide", mode) == 0) {
|
||||
bar->mode = strdup("hide");
|
||||
} else if (strcasecmp("invisible", mode) == 0) {
|
||||
bar->mode = strdup("invisible");
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode);
|
||||
}
|
||||
|
||||
if (strcmp(old_mode, bar->mode) != 0) {
|
||||
if (!config->reading) {
|
||||
ipc_event_barconfig_update(bar);
|
||||
}
|
||||
wlr_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
|
||||
}
|
||||
|
||||
// free old mode
|
||||
free(old_mode);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
struct cmd_results *bar_cmd_mode(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (config->reading && argc > 1) {
|
||||
return cmd_results_new(CMD_INVALID, "mode", "Unexpected value %s in config mode", argv[1]);
|
||||
}
|
||||
|
||||
const char *mode = argv[0];
|
||||
|
||||
if (config->reading) {
|
||||
return bar_set_mode(config->current_bar, mode);
|
||||
}
|
||||
|
||||
const char *id = NULL;
|
||||
if (argc == 2) {
|
||||
id = argv[1];
|
||||
}
|
||||
|
||||
int i;
|
||||
struct bar_config *bar;
|
||||
for (i = 0; i < config->bars->length; ++i) {
|
||||
bar = config->bars->items[i];
|
||||
if (id && strcmp(id, bar->id) == 0) {
|
||||
return bar_set_mode(bar, mode);
|
||||
}
|
||||
|
||||
error = bar_set_mode(bar, mode);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
35
sway/commands/bar/modifier.c
Normal file
35
sway/commands/bar/modifier.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
#include "util.h"
|
||||
|
||||
struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined.");
|
||||
}
|
||||
|
||||
uint32_t mod = 0;
|
||||
|
||||
list_t *split = split_string(argv[0], "+");
|
||||
for (int i = 0; i < split->length; ++i) {
|
||||
uint32_t tmp_mod;
|
||||
if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
|
||||
mod |= tmp_mod;
|
||||
continue;
|
||||
} else {
|
||||
free_flat_list(split);
|
||||
return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]);
|
||||
}
|
||||
}
|
||||
free_flat_list(split);
|
||||
|
||||
config->current_bar->modifier = mod;
|
||||
wlr_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
50
sway/commands/bar/output.c
Normal file
50
sway/commands/bar/output.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_output(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "output", "No bar defined.");
|
||||
}
|
||||
|
||||
const char *output = argv[0];
|
||||
list_t *outputs = config->current_bar->outputs;
|
||||
if (!outputs) {
|
||||
outputs = create_list();
|
||||
config->current_bar->outputs = outputs;
|
||||
}
|
||||
|
||||
int i;
|
||||
int add_output = 1;
|
||||
if (strcmp("*", output) == 0) {
|
||||
// remove all previous defined outputs and replace with '*'
|
||||
for (i = 0; i < outputs->length; ++i) {
|
||||
free(outputs->items[i]);
|
||||
list_del(outputs, i);
|
||||
}
|
||||
} else {
|
||||
// only add output if not already defined with either the same
|
||||
// name or as '*'
|
||||
for (i = 0; i < outputs->length; ++i) {
|
||||
const char *find = outputs->items[i];
|
||||
if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
|
||||
add_output = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (add_output) {
|
||||
list_add(outputs, strdup(output));
|
||||
wlr_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
27
sway/commands/bar/pango_markup.c
Normal file
27
sway/commands/bar/pango_markup.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined.");
|
||||
}
|
||||
|
||||
if (strcasecmp("enabled", argv[0]) == 0) {
|
||||
config->current_bar->pango_markup = true;
|
||||
wlr_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", config->current_bar->id);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "pango_markup", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
29
sway/commands/bar/position.c
Normal file
29
sway/commands/bar/position.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "position", "No bar defined.");
|
||||
}
|
||||
|
||||
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",
|
||||
argv[0], config->current_bar->id);
|
||||
config->current_bar->position = strdup(argv[0]);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
error = cmd_results_new(CMD_INVALID, "position", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
9
sway/commands/bar/secondary_button.c
Normal file
9
sway/commands/bar/secondary_button.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_secondary_button(int argc, char **argv) {
|
||||
const char *cmd_name = "secondary_button";
|
||||
// TODO TRAY
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY");
|
||||
}
|
21
sway/commands/bar/separator_symbol.c
Normal file
21
sway/commands/bar/separator_symbol.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "separator_symbol", "No bar defined.");
|
||||
}
|
||||
|
||||
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", config->current_bar->separator_symbol, config->current_bar->id);
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
21
sway/commands/bar/status_command.c
Normal file
21
sway/commands/bar/status_command.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
|
||||
struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "status_command", "No bar defined.");
|
||||
}
|
||||
|
||||
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", config->current_bar->status_command);
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
27
sway/commands/bar/strip_workspace_numbers.c
Normal file
27
sway/commands/bar/strip_workspace_numbers.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "strip_workspace_numbers", "No bar defined.");
|
||||
}
|
||||
|
||||
if (strcasecmp("yes", argv[0]) == 0) {
|
||||
config->current_bar->strip_workspace_numbers = true;
|
||||
wlr_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", config->current_bar->id);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
21
sway/commands/bar/swaybar_command.c
Normal file
21
sway/commands/bar/swaybar_command.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
|
||||
struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "swaybar_command", "No bar defined.");
|
||||
}
|
||||
|
||||
free(config->current_bar->swaybar_command);
|
||||
config->current_bar->swaybar_command = join_args(argv, argc);
|
||||
wlr_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command);
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
9
sway/commands/bar/tray_output.c
Normal file
9
sway/commands/bar/tray_output.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include "sway/commands.h"
|
||||
|
||||
struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
|
||||
const char *cmd_name = "tray_output";
|
||||
// TODO TRAY
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY");
|
||||
}
|
10
sway/commands/bar/tray_padding.c
Normal file
10
sway/commands/bar/tray_padding.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
|
||||
const char *cmd_name = "tray_padding";
|
||||
// TODO TRAY
|
||||
return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY");
|
||||
}
|
27
sway/commands/bar/workspace_buttons.c
Normal file
27
sway/commands/bar/workspace_buttons.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "workspace_buttons", "No bar defined.");
|
||||
}
|
||||
|
||||
if (strcasecmp("yes", argv[0]) == 0) {
|
||||
config->current_bar->workspace_buttons = true;
|
||||
wlr_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", config->current_bar->id);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
27
sway/commands/bar/wrap_scroll.c
Normal file
27
sway/commands/bar/wrap_scroll.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "log.h"
|
||||
|
||||
struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined.");
|
||||
}
|
||||
|
||||
if (strcasecmp("yes", argv[0]) == 0) {
|
||||
config->current_bar->wrap_scroll = true;
|
||||
wlr_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", config->current_bar->id);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "wrap_scroll", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
127
sway/config.c
127
sway/config.c
|
@ -110,6 +110,48 @@ void free_config(struct sway_config *config) {
|
|||
free(config);
|
||||
}
|
||||
|
||||
static void free_bar(struct bar_config *bar) {
|
||||
if (!bar) {
|
||||
return;
|
||||
}
|
||||
free(bar->mode);
|
||||
free(bar->position);
|
||||
free(bar->hidden_state);
|
||||
free(bar->status_command);
|
||||
free(bar->font);
|
||||
free(bar->separator_symbol);
|
||||
// TODO: Free mouse bindings
|
||||
list_free(bar->bindings);
|
||||
if (bar->outputs) {
|
||||
free_flat_list(bar->outputs);
|
||||
}
|
||||
if (bar->pid != 0) {
|
||||
// TODO terminate_swaybar(bar->pid);
|
||||
}
|
||||
free(bar->colors.background);
|
||||
free(bar->colors.statusline);
|
||||
free(bar->colors.separator);
|
||||
free(bar->colors.focused_background);
|
||||
free(bar->colors.focused_statusline);
|
||||
free(bar->colors.focused_separator);
|
||||
free(bar->colors.focused_workspace_border);
|
||||
free(bar->colors.focused_workspace_bg);
|
||||
free(bar->colors.focused_workspace_text);
|
||||
free(bar->colors.active_workspace_border);
|
||||
free(bar->colors.active_workspace_bg);
|
||||
free(bar->colors.active_workspace_text);
|
||||
free(bar->colors.inactive_workspace_border);
|
||||
free(bar->colors.inactive_workspace_bg);
|
||||
free(bar->colors.inactive_workspace_text);
|
||||
free(bar->colors.urgent_workspace_border);
|
||||
free(bar->colors.urgent_workspace_bg);
|
||||
free(bar->colors.urgent_workspace_text);
|
||||
free(bar->colors.binding_mode_border);
|
||||
free(bar->colors.binding_mode_bg);
|
||||
free(bar->colors.binding_mode_text);
|
||||
free(bar);
|
||||
}
|
||||
|
||||
static void destroy_removed_seats(struct sway_config *old_config,
|
||||
struct sway_config *new_config) {
|
||||
struct seat_config *seat_config;
|
||||
|
@ -239,6 +281,91 @@ cleanup:
|
|||
sway_abort("Unable to allocate config structures");
|
||||
}
|
||||
|
||||
struct bar_config *default_bar_config(void) {
|
||||
struct bar_config *bar = NULL;
|
||||
bar = malloc(sizeof(struct bar_config));
|
||||
if (!bar) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(bar->mode = strdup("dock"))) goto cleanup;
|
||||
if (!(bar->hidden_state = strdup("hide"))) goto cleanup;
|
||||
bar->outputs = NULL;
|
||||
bar->position = strdup("bottom");
|
||||
if (!(bar->bindings = create_list())) goto cleanup;
|
||||
if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
|
||||
bar->pango_markup = false;
|
||||
bar->swaybar_command = NULL;
|
||||
bar->font = NULL;
|
||||
bar->height = -1;
|
||||
bar->workspace_buttons = true;
|
||||
bar->wrap_scroll = false;
|
||||
bar->separator_symbol = NULL;
|
||||
bar->strip_workspace_numbers = false;
|
||||
bar->binding_mode_indicator = true;
|
||||
bar->verbose = false;
|
||||
bar->pid = 0;
|
||||
// set default colors
|
||||
if (!(bar->colors.background = strndup("#000000ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.statusline = strndup("#ffffffff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.separator = strndup("#666666ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.focused_workspace_border = strndup("#4c7899ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.focused_workspace_bg = strndup("#285577ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.focused_workspace_text = strndup("#ffffffff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.active_workspace_border = strndup("#333333ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.active_workspace_bg = strndup("#5f676aff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.active_workspace_text = strndup("#ffffffff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.inactive_workspace_border = strndup("#333333ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.inactive_workspace_bg = strndup("#222222ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.inactive_workspace_text = strndup("#888888ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.urgent_workspace_border = strndup("#2f343aff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.urgent_workspace_bg = strndup("#900000ff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(bar->colors.urgent_workspace_text = strndup("#ffffffff", 9))) {
|
||||
goto cleanup;
|
||||
}
|
||||
// if the following colors stay undefined, they fall back to background,
|
||||
// statusline, separator and urgent_workspace_*.
|
||||
bar->colors.focused_background = NULL;
|
||||
bar->colors.focused_statusline = NULL;
|
||||
bar->colors.focused_separator = NULL;
|
||||
bar->colors.binding_mode_border = NULL;
|
||||
bar->colors.binding_mode_bg = NULL;
|
||||
bar->colors.binding_mode_text = NULL;
|
||||
|
||||
list_add(config->bars, bar);
|
||||
return bar;
|
||||
cleanup:
|
||||
free_bar(bar);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool file_exists(const char *path) {
|
||||
return path && access(path, R_OK) != -1;
|
||||
}
|
||||
|
|
|
@ -313,10 +313,18 @@ void ipc_event_window(swayc_t *window, const char *change) {
|
|||
|
||||
const char *json_string = json_object_to_json_string(obj);
|
||||
ipc_send_event(json_string, IPC_EVENT_WINDOW);
|
||||
|
||||
json_object_put(obj); // free
|
||||
}
|
||||
|
||||
void ipc_event_barconfig_update(struct bar_config *bar) {
|
||||
wlr_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);
|
||||
ipc_send_event(json_string, IPC_EVENT_BARCONFIG_UPDATE);
|
||||
json_object_put(json); // free
|
||||
}
|
||||
|
||||
int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
|
||||
struct ipc_client *client = data;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ sway_sources = files(
|
|||
'input/seat.c',
|
||||
'input/cursor.c',
|
||||
'input/keyboard.c',
|
||||
'commands/bar.c',
|
||||
'commands/bind.c',
|
||||
'commands/exit.c',
|
||||
'commands/exec.c',
|
||||
|
@ -19,6 +20,30 @@ sway_sources = files(
|
|||
'commands/seat/attach.c',
|
||||
'commands/seat/fallback.c',
|
||||
'commands/set.c',
|
||||
'commands/bar/activate_button.c',
|
||||
'commands/bar/binding_mode_indicator.c',
|
||||
'commands/bar/bindsym.c',
|
||||
'commands/bar/colors.c',
|
||||
'commands/bar/context_button.c',
|
||||
'commands/bar/font.c',
|
||||
'commands/bar/height.c',
|
||||
'commands/bar/hidden_state.c',
|
||||
'commands/bar/icon_theme.c',
|
||||
'commands/bar/id.c',
|
||||
'commands/bar/mode.c',
|
||||
'commands/bar/modifier.c',
|
||||
'commands/bar/output.c',
|
||||
'commands/bar/pango_markup.c',
|
||||
'commands/bar/position.c',
|
||||
'commands/bar/secondary_button.c',
|
||||
'commands/bar/separator_symbol.c',
|
||||
'commands/bar/status_command.c',
|
||||
'commands/bar/strip_workspace_numbers.c',
|
||||
'commands/bar/swaybar_command.c',
|
||||
'commands/bar/tray_output.c',
|
||||
'commands/bar/tray_padding.c',
|
||||
'commands/bar/workspace_buttons.c',
|
||||
'commands/bar/wrap_scroll.c',
|
||||
'commands/input/accel_profile.c',
|
||||
'commands/input/click_method.c',
|
||||
'commands/input/drag_lock.c',
|
||||
|
|
Loading…
Reference in a new issue