From c78179dcc8fe7d19ae713d4fa009bec76fd691f8 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 3 Oct 2023 21:06:53 +0200 Subject: [PATCH] [lexer] Add dmenu as enabled option for media type. fixes: #1903 --- doc/rofi-theme.5 | 16 ++++++++++++++-- doc/rofi-theme.5.markdown | 11 +++++++++-- lexer/theme-lexer.l | 4 ++++ source/rofi.c | 10 +++++----- test/box-test.c | 1 + test/scrollbar-test.c | 1 + test/textbox-test.c | 1 + test/theme-parser-test.c | 2 ++ test/widget-test.c | 1 + 9 files changed, 38 insertions(+), 9 deletions(-) diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index eb4c3fa0..7a4708fa 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -2206,7 +2206,8 @@ It supports the following keys as constraint: .IP \(bu 2 \fB\fCmonitor-id\fR: The monitor id, see rofi -help for id's. .IP \(bu 2 -\fB\fCenabled\fR: Boolean option to enable. Supports environment variable. +\fB\fCenabled\fR: Boolean option to enable. Supports environment variable +or DMENU to detect if in dmenu mode. .RE @@ -2229,7 +2230,18 @@ added. .RS .nf -@media ( enabled: env(DO_LIGHT, false ) { +@media ( enabled: env(DO_LIGHT, false )) { + +} + +.fi +.RE + +.PP +.RS + +.nf +@media ( enabled: DMENU) { } diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index ea60a4c5..f1778e65 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -1497,7 +1497,8 @@ It supports the following keys as constraint: - `min-aspect-ratio` load when aspect ratio is over value. - `max-aspect-ratio`: load when aspect ratio is under value. - `monitor-id`: The monitor id, see rofi -help for id's. -- `enabled`: Boolean option to enable. Supports environment variable. +- `enabled`: Boolean option to enable. Supports environment variable + or DMENU to detect if in dmenu mode. @media takes an integer number or a fraction, for integer number `px` can be added. @@ -1509,7 +1510,13 @@ added. ``` ```css -@media ( enabled: env(DO_LIGHT, false ) { +@media ( enabled: env(DO_LIGHT, false )) { + +} +``` + +```css +@media ( enabled: DMENU) { } ``` diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 8edd776e..0a844158 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -49,6 +49,7 @@ #define LOG_DOMAIN "Parser" int last_state = 0; +extern int rofi_is_in_dmenu_mode; const char *rasi_theme_file_extensions[] = {".rasi", ".rasinc", NULL}; /** @@ -298,6 +299,8 @@ CONFIGURATION (?i:configuration) MEDIA_TYPES (monitor-id|(min|max)-(width|height|aspect-ratio)|enabled) +DMENU (?i:dmenu) + %x INCLUDE %x PROPERTIES %x PROPERTIES_ENV @@ -513,6 +516,7 @@ if ( queue == NULL ) {
":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return T_PSEP; } ";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return T_PCLOSE;} (true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} +{DMENU} { yylval->bval = rofi_is_in_dmenu_mode; return T_BOOLEAN;} {NUMBER}\.{NUMBER} { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} {NUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} {UNARYMIN} { return T_MIN; } diff --git a/source/rofi.c b/source/rofi.c index 0b98c461..3d6917f8 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -139,7 +139,7 @@ NkBindings *bindings = NULL; GMainLoop *main_loop = NULL; /** Flag indicating we are in dmenu mode. */ -static int dmenu_mode = FALSE; +int rofi_is_in_dmenu_mode = FALSE; /** Rofi's return code */ int return_code = EXIT_SUCCESS; @@ -789,7 +789,7 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) { } } // Dmenu mode. - if (dmenu_mode == TRUE) { + if (rofi_is_in_dmenu_mode == TRUE) { // force off sidebar mode: config.sidebar_mode = FALSE; int retv = dmenu_mode_dialog(); @@ -936,14 +936,14 @@ int main(int argc, char *argv[]) { // This has two possible causes. // 1 the user specifies it on the command-line. if (find_arg("-dmenu") >= 0) { - dmenu_mode = TRUE; + rofi_is_in_dmenu_mode = TRUE; } // 2 the binary that executed is called dmenu (e.g. symlink to rofi) else { // Get the base name of the executable called. char *base_name = g_path_get_basename(argv[0]); const char *const dmenu_str = "dmenu"; - dmenu_mode = (strcmp(base_name, dmenu_str) == 0); + rofi_is_in_dmenu_mode = (strcmp(base_name, dmenu_str) == 0); // Free the basename for dmenu detection. g_free(base_name); } @@ -1103,7 +1103,7 @@ int main(int argc, char *argv[]) { /** dirty hack for dmenu compatibility */ char *windowid = NULL; - if (!dmenu_mode) { + if (!rofi_is_in_dmenu_mode) { // setup_modes if (setup_modes()) { cleanup(); diff --git a/test/box-test.c b/test/box-test.c index 7faa654b..54afcbca 100644 --- a/test/box-test.c +++ b/test/box-test.c @@ -41,6 +41,7 @@ #include #include unsigned int test = 0; +int rofi_is_in_dmenu_mode = 0; #define TASSERT(a) \ { \ assert(a); \ diff --git a/test/scrollbar-test.c b/test/scrollbar-test.c index fa4d0df3..57da2ef9 100644 --- a/test/scrollbar-test.c +++ b/test/scrollbar-test.c @@ -59,6 +59,7 @@ unsigned int test = 0; } \ } +int rofi_is_in_dmenu_mode = 0; ThemeWidget *rofi_configuration = NULL; uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, diff --git a/test/textbox-test.c b/test/textbox-test.c index 0ddfc50f..3c7d6798 100644 --- a/test/textbox-test.c +++ b/test/textbox-test.c @@ -46,6 +46,7 @@ #include "rofi-icon-fetcher.h" static int test = 0; unsigned int normal_window_mode = 0; +int rofi_is_in_dmenu_mode = 0; #define TASSERT(a) \ { \ diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 7eeb4508..81ae0230 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -47,6 +47,8 @@ #define REAL_COMPARE_DELTA 0.001 +int rofi_is_in_dmenu_mode = 0; + uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, G_GNUC_UNUSED const int size) { return 0; diff --git a/test/widget-test.c b/test/widget-test.c index 69f32132..29783d67 100644 --- a/test/widget-test.c +++ b/test/widget-test.c @@ -40,6 +40,7 @@ #include #include unsigned int test = 0; +int rofi_is_in_dmenu_mode = 0; #define TASSERT(a) \ { \ assert(a); \