mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 00:16:22 +01:00
Merge pull request #337 from fluxchief/swaybar-check-command-args
Make swaybar check command arguments
This commit is contained in:
commit
9c0be49024
1 changed files with 49 additions and 22 deletions
|
@ -189,7 +189,9 @@ void bar_ipc_init(int outputi, const char *bar_id) {
|
||||||
|
|
||||||
// TODO: More of these options
|
// TODO: More of these options
|
||||||
// TODO: Refactor swaybar into several files, create a bar config struct (shared with compositor?)
|
// TODO: Refactor swaybar into several files, create a bar config struct (shared with compositor?)
|
||||||
if (_status_command) status_command = strdup(json_object_get_string(_status_command));
|
if (_status_command) {
|
||||||
|
status_command = strdup(json_object_get_string(_status_command));
|
||||||
|
}
|
||||||
|
|
||||||
if (_colors) {
|
if (_colors) {
|
||||||
json_object *background, *statusline, *separator;
|
json_object *background, *statusline, *separator;
|
||||||
|
@ -219,30 +221,42 @@ void bar_ipc_init(int outputi, const char *bar_id) {
|
||||||
if (background) colors.background = parse_color(json_object_get_string(background));
|
if (background) colors.background = parse_color(json_object_get_string(background));
|
||||||
if (statusline) colors.statusline = parse_color(json_object_get_string(statusline));
|
if (statusline) colors.statusline = parse_color(json_object_get_string(statusline));
|
||||||
if (separator) colors.seperator = parse_color(json_object_get_string(separator));
|
if (separator) colors.seperator = parse_color(json_object_get_string(separator));
|
||||||
if (focused_workspace_border)
|
if (focused_workspace_border) {
|
||||||
colors.focused_workspace.border = parse_color(json_object_get_string(focused_workspace_border));
|
colors.focused_workspace.border = parse_color(json_object_get_string(focused_workspace_border));
|
||||||
if (focused_workspace_bg)
|
}
|
||||||
|
if (focused_workspace_bg) {
|
||||||
colors.focused_workspace.background = parse_color(json_object_get_string(focused_workspace_bg));
|
colors.focused_workspace.background = parse_color(json_object_get_string(focused_workspace_bg));
|
||||||
if (focused_workspace_text)
|
}
|
||||||
|
if (focused_workspace_text) {
|
||||||
colors.focused_workspace.text = parse_color(json_object_get_string(focused_workspace_text));
|
colors.focused_workspace.text = parse_color(json_object_get_string(focused_workspace_text));
|
||||||
if (active_workspace_border)
|
}
|
||||||
|
if (active_workspace_border) {
|
||||||
colors.active_workspace.border = parse_color(json_object_get_string(active_workspace_border));
|
colors.active_workspace.border = parse_color(json_object_get_string(active_workspace_border));
|
||||||
if (active_workspace_bg)
|
}
|
||||||
|
if (active_workspace_bg) {
|
||||||
colors.active_workspace.background = parse_color(json_object_get_string(active_workspace_bg));
|
colors.active_workspace.background = parse_color(json_object_get_string(active_workspace_bg));
|
||||||
if (active_workspace_text)
|
}
|
||||||
|
if (active_workspace_text) {
|
||||||
colors.active_workspace.text = parse_color(json_object_get_string(active_workspace_text));
|
colors.active_workspace.text = parse_color(json_object_get_string(active_workspace_text));
|
||||||
if (inactive_workspace_border)
|
}
|
||||||
|
if (inactive_workspace_border) {
|
||||||
colors.inactive_workspace.border = parse_color(json_object_get_string(inactive_workspace_border));
|
colors.inactive_workspace.border = parse_color(json_object_get_string(inactive_workspace_border));
|
||||||
if (inactive_workspace_bg)
|
}
|
||||||
|
if (inactive_workspace_bg) {
|
||||||
colors.inactive_workspace.background = parse_color(json_object_get_string(inactive_workspace_bg));
|
colors.inactive_workspace.background = parse_color(json_object_get_string(inactive_workspace_bg));
|
||||||
if (inactive_workspace_text)
|
}
|
||||||
|
if (inactive_workspace_text) {
|
||||||
colors.inactive_workspace.text = parse_color(json_object_get_string(inactive_workspace_text));
|
colors.inactive_workspace.text = parse_color(json_object_get_string(inactive_workspace_text));
|
||||||
if (binding_mode_border)
|
}
|
||||||
|
if (binding_mode_border) {
|
||||||
colors.binding_mode.border = parse_color(json_object_get_string(binding_mode_border));
|
colors.binding_mode.border = parse_color(json_object_get_string(binding_mode_border));
|
||||||
if (binding_mode_bg)
|
}
|
||||||
|
if (binding_mode_bg) {
|
||||||
colors.binding_mode.background = parse_color(json_object_get_string(binding_mode_bg));
|
colors.binding_mode.background = parse_color(json_object_get_string(binding_mode_bg));
|
||||||
if (binding_mode_text)
|
}
|
||||||
|
if (binding_mode_text) {
|
||||||
colors.binding_mode.text = parse_color(json_object_get_string(binding_mode_text));
|
colors.binding_mode.text = parse_color(json_object_get_string(binding_mode_text));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object_put(bar_config);
|
json_object_put(bar_config);
|
||||||
|
@ -258,12 +272,15 @@ void bar_ipc_init(int outputi, const char *bar_id) {
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
int pending;
|
int pending;
|
||||||
if (ioctl(fileno(command), FIONREAD, &pending) != -1 && pending > 0) {
|
// If no command is set, we don't have to update anything
|
||||||
free(line);
|
if (status_command) {
|
||||||
line = read_line(command);
|
if (ioctl(fileno(command), FIONREAD, &pending) != -1 && pending > 0) {
|
||||||
int l = strlen(line) - 1;
|
free(line);
|
||||||
if (line[l] == '\n') {
|
line = read_line(command);
|
||||||
line[l] = '\0';
|
int l = strlen(line) - 1;
|
||||||
|
if (line[l] == '\n') {
|
||||||
|
line[l] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ioctl(socketfd, FIONREAD, &pending) != -1 && pending > 0) {
|
if (ioctl(socketfd, FIONREAD, &pending) != -1 && pending > 0) {
|
||||||
|
@ -368,6 +385,10 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bar_id) {
|
||||||
|
sway_abort("No bar_id passed. Provide --bar_id or let sway start swaybar");
|
||||||
|
}
|
||||||
|
|
||||||
registry = registry_poll();
|
registry = registry_poll();
|
||||||
|
|
||||||
if (!registry->desktop_shell) {
|
if (!registry->desktop_shell) {
|
||||||
|
@ -382,15 +403,21 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
socketfd = ipc_open_socket(socket_path);
|
socketfd = ipc_open_socket(socket_path);
|
||||||
|
|
||||||
|
if (argc == optind) {
|
||||||
|
sway_abort("No output index provided");
|
||||||
|
}
|
||||||
|
|
||||||
int desired_output = atoi(argv[optind]);
|
int desired_output = atoi(argv[optind]);
|
||||||
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
|
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
|
||||||
struct output_state *output = registry->outputs->items[desired_output];
|
struct output_state *output = registry->outputs->items[desired_output];
|
||||||
|
|
||||||
bar_ipc_init(desired_output, bar_id);
|
bar_ipc_init(desired_output, bar_id);
|
||||||
|
|
||||||
command = popen(status_command, "r");
|
if (status_command) {
|
||||||
line = malloc(1024);
|
command = popen(status_command, "r");
|
||||||
line[0] = '\0';
|
line = malloc(1024);
|
||||||
|
line[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
window = window_setup(registry, output->width, 30, false);
|
window = window_setup(registry, output->width, 30, false);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
|
|
Loading…
Reference in a new issue