summaryrefslogtreecommitdiffstats
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(
71 DESTINATION share/wayland-sessions 71 DESTINATION share/wayland-sessions
72 COMPONENT data 72 COMPONENT data
73) 73)
74install(
75 FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway-xorg.desktop
76 DESTINATION share/xsessions
77 COMPONENT data
78)
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 {
92 enum desktop_shell_panel_position position; 92 enum desktop_shell_panel_position position;
93 list_t *bindings; 93 list_t *bindings;
94 char *status_command; 94 char *status_command;
95 char *swaybar_command;
95 char *font; 96 char *font;
96 int height; // -1 not defined 97 int height; // -1 not defined
97 int tray_padding; 98 int tray_padding;
@@ -184,6 +185,10 @@ int sway_mouse_binding_cmp(const void *a, const void *b);
184int sway_mouse_binding_cmp_buttons(const void *a, const void *b); 185int sway_mouse_binding_cmp_buttons(const void *a, const void *b);
185void free_sway_mouse_binding(struct sway_mouse_binding *smb); 186void free_sway_mouse_binding(struct sway_mouse_binding *smb);
186 187
188void load_swaybars(swayc_t *output, int output_idx);
189void terminate_swaybars(list_t *pids);
190void terminate_swaybg(pid_t pid);
191
187/** 192/**
188 * Allocate and initialize default bar configuration. 193 * Allocate and initialize default bar configuration.
189 */ 194 */
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 @@
1#ifndef _SWAY_CONTAINER_H 1#ifndef _SWAY_CONTAINER_H
2#define _SWAY_CONTAINER_H 2#define _SWAY_CONTAINER_H
3#include <sys/types.h>
3#include <wlc/wlc.h> 4#include <wlc/wlc.h>
4typedef struct sway_container swayc_t; 5typedef struct sway_container swayc_t;
5 6
@@ -81,6 +82,11 @@ struct sway_container {
81 char *class; 82 char *class;
82 char *app_id; 83 char *app_id;
83 84
85 // Used by output containers to keep track of swaybar/swaybg child
86 // processes.
87 list_t *bar_pids;
88 pid_t bg_pid;
89
84 int gaps; 90 int gaps;
85 91
86 list_t *children; 92 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 @@
1[Desktop Entry]
2Name=Sway (Xorg)
3Comment=SirCmpwn's Wayland window manager
4Exec=sway
5Type=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;
79static sway_cmd bar_cmd_separator_symbol; 79static sway_cmd bar_cmd_separator_symbol;
80static sway_cmd bar_cmd_status_command; 80static sway_cmd bar_cmd_status_command;
81static sway_cmd bar_cmd_strip_workspace_numbers; 81static sway_cmd bar_cmd_strip_workspace_numbers;
82static sway_cmd bar_cmd_swaybar_command;
82static sway_cmd bar_cmd_tray_output; 83static sway_cmd bar_cmd_tray_output;
83static sway_cmd bar_cmd_tray_padding; 84static sway_cmd bar_cmd_tray_padding;
84static sway_cmd bar_cmd_workspace_buttons; 85static sway_cmd bar_cmd_workspace_buttons;
@@ -1094,6 +1095,15 @@ static struct cmd_results *cmd_reload(int argc, char **argv) {
1094 } 1095 }
1095 if (!load_config(NULL)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); 1096 if (!load_config(NULL)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config.");
1096 1097
1098 int i;
1099 swayc_t *cont = NULL;
1100 for (i = 0; i < root_container.children->length; ++i) {
1101 cont = root_container.children->items[i];
1102 if (cont->type == C_OUTPUT) {
1103 load_swaybars(cont, i);
1104 }
1105 }
1106
1097 arrange_windows(&root_container, -1, -1); 1107 arrange_windows(&root_container, -1, -1);
1098 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1108 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1099} 1109}
@@ -1909,6 +1919,23 @@ static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv
1909 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1919 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1910} 1920}
1911 1921
1922static struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) {
1923 struct cmd_results *error = NULL;
1924 if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) {
1925 return error;
1926 }
1927
1928 if (!config->current_bar) {
1929 return cmd_results_new(CMD_FAILURE, "swaybar_command", "No bar defined.");
1930 }
1931
1932 free(config->current_bar->swaybar_command);
1933 config->current_bar->swaybar_command = join_args(argv, argc);
1934 sway_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command);
1935
1936 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1937}
1938
1912static struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { 1939static struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
1913 sway_log(L_ERROR, "warning: tray_output is not supported on wayland"); 1940 sway_log(L_ERROR, "warning: tray_output is not supported on wayland");
1914 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1941 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
@@ -1977,6 +2004,7 @@ static struct cmd_handler bar_handlers[] = {
1977 { "separator_symbol", bar_cmd_separator_symbol }, 2004 { "separator_symbol", bar_cmd_separator_symbol },
1978 { "status_command", bar_cmd_status_command }, 2005 { "status_command", bar_cmd_status_command },
1979 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, 2006 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
2007 { "swaybar_command", bar_cmd_swaybar_command },
1980 { "tray_output", bar_cmd_tray_output }, 2008 { "tray_output", bar_cmd_tray_output },
1981 { "tray_padding", bar_cmd_tray_padding }, 2009 { "tray_padding", bar_cmd_tray_padding },
1982 { "workspace_buttons", bar_cmd_workspace_buttons }, 2010 { "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 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <wordexp.h> 5#include <wordexp.h>
6#include <sys/types.h>
7#include <sys/wait.h>
8#include <signal.h>
6#include "wayland-desktop-shell-server-protocol.h" 9#include "wayland-desktop-shell-server-protocol.h"
7#include "readline.h" 10#include "readline.h"
8#include "stringop.h" 11#include "stringop.h"
@@ -360,6 +363,101 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
360 } 363 }
361} 364}
362 365
366static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i) {
367 sway_log(L_DEBUG, "Invoking swaybar for output %s[%d] and bar %s", output->name, output_i, bar->id);
368
369 size_t bufsize = 4;
370 char output_id[bufsize];
371 snprintf(output_id, bufsize, "%d", output_i);
372 output_id[bufsize-1] = 0;
373
374 char *const cmd[] = {
375 "swaybar",
376 "-b",
377 bar->id,
378 output_id,
379 NULL,
380 };
381
382 pid_t *pid = malloc(sizeof(pid_t));
383 *pid = fork();
384 if (*pid == 0) {
385 execvp(cmd[0], cmd);
386 }
387
388 // add swaybar pid to output
389 list_add(output->bar_pids, pid);
390}
391
392void terminate_swaybars(list_t *pids) {
393 int i, ret;
394 pid_t *pid;
395 for (i = 0; i < pids->length; ++i) {
396 pid = pids->items[i];
397 ret = kill(*pid, SIGTERM);
398 if (ret != 0) {
399 sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", *pid);
400 } else {
401 int status;
402 waitpid(*pid, &status, 0);
403 }
404 }
405
406 // empty pids list
407 for (i = 0; i < pids->length; ++i) {
408 pid = pids->items[i];
409 list_del(pids, i);
410 free(pid);
411 }
412}
413
414void terminate_swaybg(pid_t pid) {
415 int ret = kill(pid, SIGTERM);
416 if (ret != 0) {
417 sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid);
418 } else {
419 int status;
420 waitpid(pid, &status, 0);
421 }
422}
423
424void load_swaybars(swayc_t *output, int output_idx) {
425 // Check for bars
426 list_t *bars = create_list();
427 struct bar_config *bar = NULL;
428 int i;
429 for (i = 0; i < config->bars->length; ++i) {
430 bar = config->bars->items[i];
431 bool apply = false;
432 if (bar->outputs) {
433 int j;
434 for (j = 0; j < bar->outputs->length; ++j) {
435 char *o = bar->outputs->items[j];
436 if (strcmp(o, "*") || strcasecmp(o, output->name)) {
437 apply = true;
438 break;
439 }
440 }
441 } else {
442 apply = true;
443 }
444 if (apply) {
445 list_add(bars, bar);
446 }
447 }
448
449 // terminate swaybar processes previously spawned for this
450 // output.
451 terminate_swaybars(output->bar_pids);
452
453 for (i = 0; i < bars->length; ++i) {
454 bar = bars->items[i];
455 invoke_swaybar(output, bar, output_idx);
456 }
457
458 list_free(bars);
459}
460
363void apply_output_config(struct output_config *oc, swayc_t *output) { 461void apply_output_config(struct output_config *oc, swayc_t *output) {
364 if (oc && oc->width > 0 && oc->height > 0) { 462 if (oc && oc->width > 0 && oc->height > 0) {
365 output->width = oc->width; 463 output->width = oc->width;
@@ -407,6 +505,10 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
407 505
408 if (oc && oc->background) { 506 if (oc && oc->background) {
409 507
508 if (output->bg_pid != 0) {
509 terminate_swaybg(output->bg_pid);
510 }
511
410 sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background); 512 sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
411 513
412 size_t bufsize = 4; 514 size_t bufsize = 4;
@@ -421,54 +523,15 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
421 oc->background_option, 523 oc->background_option,
422 NULL, 524 NULL,
423 }; 525 };
424 if (fork() == 0) {
425 execvp(cmd[0], cmd);
426 }
427 }
428 526
429 // Check for a bar 527 output->bg_pid = fork();
430 struct bar_config *bar = NULL; 528 if (output->bg_pid == 0) {
431 int i;
432 for (i = 0; i < config->bars->length; ++i) {
433 bar = config->bars->items[i];
434 bool apply = false;
435 if (bar->outputs) {
436 int j;
437 for (j = 0; j < bar->outputs->length; ++j) {
438 char *o = bar->outputs->items[j];
439 if (strcmp(o, "*") || strcasecmp(o, output->name)) {
440 apply = true;
441 break;
442 }
443 }
444 } else {
445 apply = true;
446 }
447 if (apply) {
448 break;
449 } else {
450 bar = NULL;
451 }
452 }
453 if (bar) {
454 sway_log(L_DEBUG, "Invoking swaybar for output %s[%d] and bar %s", output->name, i, bar->id);
455
456 size_t bufsize = 4;
457 char output_id[bufsize];
458 snprintf(output_id, bufsize, "%d", output_i);
459 output_id[bufsize-1] = 0;
460
461 char *const cmd[] = {
462 "swaybar",
463 "-b",
464 bar->id,
465 output_id,
466 NULL,
467 };
468 if (fork() == 0) {
469 execvp(cmd[0], cmd); 529 execvp(cmd[0], cmd);
470 } 530 }
471 } 531 }
532
533 // load swaybars for output
534 load_swaybars(output, output_i);
472} 535}
473 536
474char *do_var_replacement(char *str) { 537char *do_var_replacement(char *str) {
@@ -610,6 +673,7 @@ struct bar_config *default_bar_config(void) {
610 bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; 673 bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
611 bar->bindings = create_list(); 674 bar->bindings = create_list();
612 bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); 675 bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done");
676 bar->swaybar_command = NULL;
613 bar->font = strdup("monospace 10"); 677 bar->font = strdup("monospace 10");
614 bar->height = -1; 678 bar->height = -1;
615 bar->workspace_buttons = true; 679 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) {
60 if (cont->app_id) { 60 if (cont->app_id) {
61 free(cont->app_id); 61 free(cont->app_id);
62 } 62 }
63 if (cont->bar_pids) {
64 terminate_swaybars(cont->bar_pids);
65 free_flat_list(cont->bar_pids);
66 }
67 if (cont->bg_pid != 0) {
68 terminate_swaybg(cont->bg_pid);
69 }
63 free(cont); 70 free(cont);
64} 71}
65 72
@@ -109,6 +116,8 @@ swayc_t *new_output(wlc_handle handle) {
109 output->width = size->w; 116 output->width = size->w;
110 output->height = size->h; 117 output->height = size->h;
111 output->unmanaged = create_list(); 118 output->unmanaged = create_list();
119 output->bar_pids = create_list();
120 output->bg_pid = 0;
112 121
113 apply_output_config(oc, output); 122 apply_output_config(oc, output);
114 add_child(&root_container, output); 123 add_child(&root_container, output);