From a54ab707cf77ad9ba37e13ba76c1192e58ff2917 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Mon, 27 Jul 2020 18:36:08 +0200 Subject: [PATCH] Pass a *run level* argument to `bspwmrc` Fixes #1158. --- doc/bspwm.1 | 11 ++++++++--- doc/bspwm.1.asciidoc | 7 +++++++ src/bspwm.c | 5 ++++- src/settings.c | 8 ++++---- src/settings.h | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/doc/bspwm.1 b/doc/bspwm.1 index 65ed6f0..9c3e99f 100644 --- a/doc/bspwm.1 +++ b/doc/bspwm.1 @@ -2,12 +2,12 @@ .\" Title: bspwm .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets vsnapshot -.\" Date: 07/26/2020 +.\" Date: 07/27/2020 .\" Manual: Bspwm Manual -.\" Source: Bspwm 0.9.9-16-g1506582 +.\" Source: Bspwm 0.9.9-25-g8f41d79 .\" Language: English .\" -.TH "BSPWM" "1" "07/26/2020" "Bspwm 0\&.9\&.9\-16\-g1506582" "Bspwm Manual" +.TH "BSPWM" "1" "07/27/2020" "Bspwm 0\&.9\&.9\-25\-g8f41d79" "Bspwm Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -1601,6 +1601,11 @@ State of the focused node of a focused desktop\&. .RS 4 Active flags of the focused node of a focused desktop\&. .RE +.SH "CONFIGURATION FILE" +.sp +Its default path is \fI$XDG_CONFIG_HOME/bspwm/bspwmrc\fR\&. +.sp +An argument is passed to this script: the run level, a number which indicates whether it was launched after a restart (cf\&. \fIwm \-r\fR) or not\&. .SH "ENVIRONMENT VARIABLES" .PP \fIBSPWM_SOCKET\fR diff --git a/doc/bspwm.1.asciidoc b/doc/bspwm.1.asciidoc index a120d27..0923f94 100644 --- a/doc/bspwm.1.asciidoc +++ b/doc/bspwm.1.asciidoc @@ -944,6 +944,13 @@ Each item has the form '' where '' is the first character of 'G(S?P?L?M?)':: Active flags of the focused node of a focused desktop. +Configuration file +------------------ + +Its default path is '$XDG_CONFIG_HOME/bspwm/bspwmrc'. + +An argument is passed to this script: the run level, a number which indicates whether it was launched after a restart (cf. 'wm -r') or not. + Environment Variables --------------------- diff --git a/src/bspwm.c b/src/bspwm.c index d70a35a..dca03fd 100644 --- a/src/bspwm.c +++ b/src/bspwm.c @@ -94,6 +94,7 @@ int main(int argc, char *argv[]) fd_set descriptors; char socket_path[MAXLEN]; char state_path[MAXLEN] = {0}; + int run_level = 0; config_path[0] = '\0'; int sock_fd = -1, cli_fd, dpy_fd, max_fd, n; struct sockaddr_un sock_address; @@ -116,9 +117,11 @@ int main(int argc, char *argv[]) snprintf(config_path, sizeof(config_path), "%s", optarg); break; case 's': + run_level |= 1; snprintf(state_path, sizeof(state_path), "%s", optarg); break; case 'o': + run_level |= 2; sock_fd = strtol(optarg, &end, 0); if (*end != '\0') { sock_fd = -1; @@ -192,7 +195,7 @@ int main(int argc, char *argv[]) signal(SIGTERM, sig_handler); signal(SIGCHLD, sig_handler); signal(SIGPIPE, SIG_IGN); - run_config(); + run_config(run_level); running = true; while (running) { diff --git a/src/settings.c b/src/settings.c index df2dbe2..15f652b 100644 --- a/src/settings.c +++ b/src/settings.c @@ -28,8 +28,6 @@ #include "bspwm.h" #include "settings.h" -extern char **environ; - char external_rules_command[MAXLEN]; char status_prefix[MAXLEN]; @@ -74,14 +72,16 @@ bool remove_disabled_monitors; bool remove_unplugged_monitors; bool merge_overlapping_monitors; -void run_config(void) +void run_config(int run_level) { if (fork() == 0) { if (dpy != NULL) { close(xcb_get_file_descriptor(dpy)); } setsid(); - execle(config_path, config_path, (char *) NULL, environ); + char arg1[2]; + snprintf(arg1, 2, "%i", run_level); + execl(config_path, config_path, arg1, (char *) NULL); err("Couldn't execute the configuration file.\n"); } } diff --git a/src/settings.h b/src/settings.h index 021bf6d..f1cb85e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -111,7 +111,7 @@ extern bool remove_disabled_monitors; extern bool remove_unplugged_monitors; extern bool merge_overlapping_monitors; -void run_config(void); +void run_config(int run_level); void load_settings(void); #endif -- 2.44.0