aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/config.h26
-rw-r--r--sway/config.c127
-rw-r--r--sway/config/bar.c143
-rw-r--r--sway/config/output.c2
-rw-r--r--sway/meson.build1
5 files changed, 151 insertions, 148 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index f9ab6778..dbcfc91e 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -12,6 +12,8 @@
#include "container.h"
#include "wlr-layer-shell-unstable-v1-protocol.h"
+// TODO: Refactor this shit
+
/**
* Describes a variable created via the `set` command.
*/
@@ -407,11 +409,6 @@ void merge_output_config(struct output_config *dst, struct output_config *src);
void apply_output_config(struct output_config *oc, swayc_t *output);
void free_output_config(struct output_config *oc);
-/**
- * Updates the list of active bar modifiers
- */
-void update_active_bar_modifiers(void);
-
int workspace_output_cmp_workspace(const void *a, const void *b);
int sway_binding_cmp(const void *a, const void *b);
@@ -420,27 +417,16 @@ int sway_binding_cmp_keys(const void *a, const void *b);
void free_sway_binding(struct sway_binding *sb);
struct sway_binding *sway_binding_dup(struct sway_binding *sb);
-int sway_mouse_binding_cmp(const void *a, const void *b);
-int sway_mouse_binding_cmp_qsort(const void *a, const void *b);
-int sway_mouse_binding_cmp_buttons(const void *a, const void *b);
-void free_sway_mouse_binding(struct sway_mouse_binding *smb);
-
+/* Bar stuff */
void load_swaybars();
void terminate_swaybg(pid_t pid);
-
-/**
- * Allocate and initialize default bar configuration.
- */
struct bar_config *default_bar_config(void);
+void free_bar_config(struct bar_config *bar);
-/**
- * Global config singleton.
- */
+/* Global config singleton. */
extern struct sway_config *config;
-/**
- * Config file currently being read.
- */
+/* Config file currently being read */
extern const char *current_config_path;
#endif
diff --git a/sway/config.c b/sway/config.c
index a0e408de..0422fdd9 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -110,48 +110,6 @@ 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;
@@ -281,91 +239,6 @@ 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;
}
diff --git a/sway/config/bar.c b/sway/config/bar.c
new file mode 100644
index 00000000..ecc357d0
--- /dev/null
+++ b/sway/config/bar.c
@@ -0,0 +1,143 @@
+#define _POSIX_C_SOURCE 200809L
+#define _XOPEN_SOURCE 700
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <wordexp.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <strings.h>
+#include "sway/config.h"
+#include "stringop.h"
+#include "list.h"
+#include "log.h"
+
+void free_bar_config(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);
+}
+
+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_config(bar);
+ return NULL;
+}
diff --git a/sway/config/output.c b/sway/config/output.c
index 9e211861..24b4a18e 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -186,7 +186,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
output_id[bufsize-1] = 0;
char *const cmd[] = {
- "./swaybg/swaybg",
+ "swaybg",
output_id,
oc->background,
oc->background_option,
diff --git a/sway/meson.build b/sway/meson.build
index 8fcb0dbf..ac65d05e 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -64,6 +64,7 @@ sway_sources = files(
'commands/reload.c',
'commands/workspace.c',
'config.c',
+ 'config/bar.c',
'config/output.c',
'config/seat.c',
'config/input.c',