aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--include/config.h5
-rw-r--r--include/container.h6
-rw-r--r--sway-xorg.desktop5
-rw-r--r--sway/commands.c28
-rw-r--r--sway/config.c152
-rw-r--r--sway/container.c9
7 files changed, 156 insertions, 54 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 576b875d..2a9ffde9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,8 +71,3 @@ install(
DESTINATION share/wayland-sessions
COMPONENT data
)
-install(
- FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway-xorg.desktop
- DESTINATION share/xsessions
- COMPONENT data
-)
diff --git a/include/config.h b/include/config.h
index 32562908..e6fc9f28 100644
--- a/include/config.h
+++ b/include/config.h
@@ -92,6 +92,7 @@ struct bar_config {
enum desktop_shell_panel_position position;
list_t *bindings;
char *status_command;
+ char *swaybar_command;
char *font;
int height; // -1 not defined
int tray_padding;
@@ -184,6 +185,10 @@ int sway_mouse_binding_cmp(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);
+void load_swaybars(swayc_t *output, int output_idx);
+void terminate_swaybars(list_t *pids);
+void terminate_swaybg(pid_t pid);
+
/**
* Allocate and initialize default bar configuration.
*/
diff --git a/include/container.h b/include/container.h
index 9a67a689..d76160de 100644
--- a/include/container.h
+++ b/include/container.h
@@ -1,5 +1,6 @@
#ifndef _SWAY_CONTAINER_H
#define _SWAY_CONTAINER_H
+#include <sys/types.h>
#include <wlc/wlc.h>
typedef struct sway_container swayc_t;
@@ -81,6 +82,11 @@ struct sway_container {
char *class;
char *app_id;
+ // Used by output containers to keep track of swaybar/swaybg child
+ // processes.
+ list_t *bar_pids;
+ pid_t bg_pid;
+
int gaps;
list_t *children;
diff --git a/sway-xorg.desktop b/sway-xorg.desktop
deleted file mode 100644
index e93a4284..00000000
--- a/sway-xorg.desktop
+++ /dev/null
@@ -1,5 +0,0 @@
-[Desktop Entry]
-Name=Sway (Xorg)
-Comment=SirCmpwn's Wayland window manager
-Exec=sway
-Type=Application
diff --git a/sway/commands.c b/sway/commands.c
index 24d56052..4af9186a 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -79,6 +79,7 @@ static sway_cmd bar_cmd_position;
static sway_cmd bar_cmd_separator_symbol;
static sway_cmd bar_cmd_status_command;
static sway_cmd bar_cmd_strip_workspace_numbers;
+static sway_cmd bar_cmd_swaybar_command;
static sway_cmd bar_cmd_tray_output;
static sway_cmd bar_cmd_tray_padding;
static sway_cmd bar_cmd_workspace_buttons;
@@ -1094,6 +1095,15 @@ static struct cmd_results *cmd_reload(int argc, char **argv) {
}
if (!load_config(NULL)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config.");
+ int i;
+ swayc_t *cont = NULL;
+ for (i = 0; i < root_container.children->length; ++i) {
+ cont = root_container.children->items[i];
+ if (cont->type == C_OUTPUT) {
+ load_swaybars(cont, i);
+ }
+ }
+
arrange_windows(&root_container, -1, -1);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
@@ -1909,6 +1919,23 @@ static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+static 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);
+ sway_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command);
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
static struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
sway_log(L_ERROR, "warning: tray_output is not supported on wayland");
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
@@ -1977,6 +2004,7 @@ static struct cmd_handler bar_handlers[] = {
{ "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 },
diff --git a/sway/config.c b/sway/config.c
index 970225f4..b0871366 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -3,6 +3,9 @@
#include <stdlib.h>
#include <unistd.h>
#include <wordexp.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
#include "wayland-desktop-shell-server-protocol.h"
#include "readline.h"
#include "stringop.h"
@@ -360,6 +363,101 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
}
}
+static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i) {
+ sway_log(L_DEBUG, "Invoking swaybar for output %s[%d] and bar %s", output->name, output_i, bar->id);
+
+ size_t bufsize = 4;
+ char output_id[bufsize];
+ snprintf(output_id, bufsize, "%d", output_i);
+ output_id[bufsize-1] = 0;
+
+ char *const cmd[] = {
+ "swaybar",
+ "-b",
+ bar->id,
+ output_id,
+ NULL,
+ };
+
+ pid_t *pid = malloc(sizeof(pid_t));
+ *pid = fork();
+ if (*pid == 0) {
+ execvp(cmd[0], cmd);
+ }
+
+ // add swaybar pid to output
+ list_add(output->bar_pids, pid);
+}
+
+void terminate_swaybars(list_t *pids) {
+ int i, ret;
+ pid_t *pid;
+ for (i = 0; i < pids->length; ++i) {
+ pid = pids->items[i];
+ ret = kill(*pid, SIGTERM);
+ if (ret != 0) {
+ sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", *pid);
+ } else {
+ int status;
+ waitpid(*pid, &status, 0);
+ }
+ }
+
+ // empty pids list
+ for (i = 0; i < pids->length; ++i) {
+ pid = pids->items[i];
+ list_del(pids, i);
+ free(pid);
+ }
+}
+
+void terminate_swaybg(pid_t pid) {
+ int ret = kill(pid, SIGTERM);
+ if (ret != 0) {
+ sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid);
+ } else {
+ int status;
+ waitpid(pid, &status, 0);
+ }
+}
+
+void load_swaybars(swayc_t *output, int output_idx) {
+ // Check for bars
+ list_t *bars = create_list();
+ struct bar_config *bar = NULL;
+ int i;
+ for (i = 0; i < config->bars->length; ++i) {
+ bar = config->bars->items[i];
+ bool apply = false;
+ if (bar->outputs) {
+ int j;
+ for (j = 0; j < bar->outputs->length; ++j) {
+ char *o = bar->outputs->items[j];
+ if (strcmp(o, "*") || strcasecmp(o, output->name)) {
+ apply = true;
+ break;
+ }
+ }
+ } else {
+ apply = true;
+ }
+ if (apply) {
+ list_add(bars, bar);
+ }
+ }
+
+ // terminate swaybar processes previously spawned for this
+ // output.
+ terminate_swaybars(output->bar_pids);
+
+ for (i = 0; i < bars->length; ++i) {
+ bar = bars->items[i];
+ invoke_swaybar(output, bar, output_idx);
+ }
+
+ list_free(bars);
+}
+
void apply_output_config(struct output_config *oc, swayc_t *output) {
if (oc && oc->width > 0 && oc->height > 0) {
output->width = oc->width;
@@ -407,6 +505,10 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
if (oc && oc->background) {
+ if (output->bg_pid != 0) {
+ terminate_swaybg(output->bg_pid);
+ }
+
sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
size_t bufsize = 4;
@@ -421,54 +523,15 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
oc->background_option,
NULL,
};
- if (fork() == 0) {
- execvp(cmd[0], cmd);
- }
- }
- // Check for a bar
- struct bar_config *bar = NULL;
- int i;
- for (i = 0; i < config->bars->length; ++i) {
- bar = config->bars->items[i];
- bool apply = false;
- if (bar->outputs) {
- int j;
- for (j = 0; j < bar->outputs->length; ++j) {
- char *o = bar->outputs->items[j];
- if (strcmp(o, "*") || strcasecmp(o, output->name)) {
- apply = true;
- break;
- }
- }
- } else {
- apply = true;
- }
- if (apply) {
- break;
- } else {
- bar = NULL;
- }
- }
- if (bar) {
- sway_log(L_DEBUG, "Invoking swaybar for output %s[%d] and bar %s", output->name, i, bar->id);
-
- size_t bufsize = 4;
- char output_id[bufsize];
- snprintf(output_id, bufsize, "%d", output_i);
- output_id[bufsize-1] = 0;
-
- char *const cmd[] = {
- "swaybar",
- "-b",
- bar->id,
- output_id,
- NULL,
- };
- if (fork() == 0) {
+ output->bg_pid = fork();
+ if (output->bg_pid == 0) {
execvp(cmd[0], cmd);
}
}
+
+ // load swaybars for output
+ load_swaybars(output, output_i);
}
char *do_var_replacement(char *str) {
@@ -610,6 +673,7 @@ struct bar_config *default_bar_config(void) {
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
bar->bindings = create_list();
bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done");
+ bar->swaybar_command = NULL;
bar->font = strdup("monospace 10");
bar->height = -1;
bar->workspace_buttons = true;
diff --git a/sway/container.c b/sway/container.c
index 36056ff7..b85d2114 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -60,6 +60,13 @@ static void free_swayc(swayc_t *cont) {
if (cont->app_id) {
free(cont->app_id);
}
+ if (cont->bar_pids) {
+ terminate_swaybars(cont->bar_pids);
+ free_flat_list(cont->bar_pids);
+ }
+ if (cont->bg_pid != 0) {
+ terminate_swaybg(cont->bg_pid);
+ }
free(cont);
}
@@ -109,6 +116,8 @@ swayc_t *new_output(wlc_handle handle) {
output->width = size->w;
output->height = size->h;
output->unmanaged = create_list();
+ output->bar_pids = create_list();
+ output->bg_pid = 0;
apply_output_config(oc, output);
add_child(&root_container, output);