Skip to content

Commit

Permalink
[lexer] Add dmenu as enabled option for media type.
Browse files Browse the repository at this point in the history
fixes: #1903
  • Loading branch information
DaveDavenport committed Oct 3, 2023
1 parent a6d2975 commit c78179d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 9 deletions.
16 changes: 14 additions & 2 deletions doc/rofi-theme.5
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {

}

Expand Down
11 changes: 9 additions & 2 deletions doc/rofi-theme.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1509,7 +1510,13 @@ added.
```

```css
@media ( enabled: env(DO_LIGHT, false ) {
@media ( enabled: env(DO_LIGHT, false )) {

}
```

```css
@media ( enabled: DMENU) {

}
```
Expand Down
4 changes: 4 additions & 0 deletions lexer/theme-lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -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};
/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -513,6 +516,7 @@ if ( queue == NULL ) {
<SECTION>":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return T_PSEP; }
<PROPERTIES>";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return T_PCLOSE;}
<PROPERTIES,PROPERTIES_ARRAY,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_ENV_VAR_CONTENT,MEDIA_ENV_VAR_DEFAULT>(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
<MEDIA_CONTENT>{DMENU} { yylval->bval = rofi_is_in_dmenu_mode; return T_BOOLEAN;}
<PROPERTIES,PROPERTIES_ARRAY,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{NUMBER}\.{NUMBER} { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
<PROPERTIES,PROPERTIES_ARRAY,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{NUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
<PROPERTIES,PROPERTIES_ARRAY,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{UNARYMIN} { return T_MIN; }
Expand Down
10 changes: 5 additions & 5 deletions source/rofi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/box-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <widgets/widget-internal.h>
#include <widgets/widget.h>
unsigned int test = 0;
int rofi_is_in_dmenu_mode = 0;
#define TASSERT(a) \
{ \
assert(a); \
Expand Down
1 change: 1 addition & 0 deletions test/scrollbar-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/textbox-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
{ \
Expand Down
2 changes: 2 additions & 0 deletions test/theme-parser-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/widget-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <widgets/widget-internal.h>
#include <widgets/widget.h>
unsigned int test = 0;
int rofi_is_in_dmenu_mode = 0;
#define TASSERT(a) \
{ \
assert(a); \
Expand Down

0 comments on commit c78179d

Please sign in to comment.