mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
[Theme] Add enabled property with env support.
This commit is contained in:
parent
c000e1a9a2
commit
386877dd22
6 changed files with 136 additions and 22 deletions
|
@ -2041,6 +2041,8 @@ It supports the following keys as constraint:
|
|||
\fB\fCmax-aspect-ratio\fR: load when aspect ratio is under value.
|
||||
.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.
|
||||
|
||||
.RE
|
||||
|
||||
|
@ -2058,6 +2060,17 @@ It supports the following keys as constraint:
|
|||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
@media ( enabled: env(DO_LIGHT, false ) {
|
||||
|
||||
}
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH Font Parsing
|
||||
.PP
|
||||
Rofi uses pango
|
||||
|
|
|
@ -1308,6 +1308,7 @@ 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.
|
||||
|
||||
@media takes an integer number or a fraction, for integer number `px` can be added.
|
||||
|
||||
|
@ -1318,6 +1319,12 @@ It supports the following keys as constraint:
|
|||
}
|
||||
```
|
||||
|
||||
```
|
||||
@media ( enabled: env(DO_LIGHT, false ) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Font Parsing
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ typedef enum {
|
|||
THEME_MEDIA_TYPE_MIN_ASPECT_RATIO,
|
||||
/** Maximum aspect ratio constraint. */
|
||||
THEME_MEDIA_TYPE_MAX_ASPECT_RATIO,
|
||||
/** Boolean option for use with env. */
|
||||
THEME_MEDIA_TYPE_BOOLEAN,
|
||||
/** Invalid entry. */
|
||||
THEME_MEDIA_TYPE_INVALID,
|
||||
} ThemeMediaType;
|
||||
|
@ -60,6 +62,7 @@ typedef enum {
|
|||
typedef struct ThemeMedia {
|
||||
ThemeMediaType type;
|
||||
double value;
|
||||
gboolean boolv;
|
||||
} ThemeMedia;
|
||||
|
||||
/**
|
||||
|
|
|
@ -178,7 +178,6 @@ WSO [[:blank:]]*
|
|||
WORD [[:alnum:]-]+
|
||||
WORD_ELEMENT [[:alpha:]][[:alnum:]-]*
|
||||
WORD_ENV [[:alpha:]_][[:alnum:]_]*
|
||||
MEDIA_NAME [[:alpha:]-]+
|
||||
COLOR_NAME [[:alpha:]]+
|
||||
STRING \"{UANYN}*\"
|
||||
STRING_LIST \"{UANYNP}*\"
|
||||
|
@ -291,6 +290,8 @@ MEDIA "@media"
|
|||
|
||||
CONFIGURATION (?i:configuration)
|
||||
|
||||
MEDIA_TYPES (monitor-id|(min|max)-(width|height|aspect-ratio)|enabled)
|
||||
|
||||
%x INCLUDE
|
||||
%x PROPERTIES
|
||||
%x PROPERTIES_ENV
|
||||
|
@ -301,8 +302,12 @@ CONFIGURATION (?i:configuration)
|
|||
%x NAMESTR
|
||||
%x SECTION
|
||||
%x DEFAULTS
|
||||
/* Media section.*/
|
||||
%x MEDIA
|
||||
%x MEDIA_CONTENT
|
||||
%x MEDIA_ENV_VAR
|
||||
%x MEDIA_ENV_VAR_CONTENT
|
||||
%x MEDIA_ENV_VAR_DEFAULT
|
||||
%%
|
||||
|
||||
%{
|
||||
|
@ -497,11 +502,11 @@ if ( queue == NULL ) {
|
|||
|
||||
/* After Namestr/Classstr we want to go to state str, then to { */
|
||||
<INITIAL,SECTION>{WHITESPACE}+ ; // ignore all whitespace
|
||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,PROPERTIES_ARRAY,PROPERTIES_ENV_VAR,PROPERTIES_VAR,MEDIA_CONTENT>{WHITESPACE}+ ; // ignore all whitespace
|
||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,PROPERTIES_ARRAY,PROPERTIES_ENV_VAR,PROPERTIES_VAR>{WHITESPACE}+ ; // ignore all whitespace
|
||||
|
||||
<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>(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
|
||||
<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;}
|
||||
<PROPERTIES,PROPERTIES_ARRAY,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
|
||||
<PROPERTIES,PROPERTIES_ARRAY,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
|
||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{STRING} { yytext[yyleng-1] = '\0'; yylval->sval = g_strcompress(&yytext[1]); return T_STRING;}
|
||||
|
@ -579,6 +584,25 @@ if ( queue == NULL ) {
|
|||
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_ENV);
|
||||
}
|
||||
}
|
||||
<MEDIA_ENV_VAR>{WORD_ENV} {
|
||||
const char *val = g_getenv(yytext);
|
||||
if ( val ) {
|
||||
ParseObject *top = g_queue_peek_head ( file_queue );
|
||||
top->location = *yylloc;
|
||||
ParseObject *po = g_malloc0(sizeof(ParseObject));
|
||||
po->type = PT_ENV;
|
||||
po->input_str = val;
|
||||
po->str_len = strlen(val);
|
||||
current = po;
|
||||
g_queue_push_head ( file_queue, po );
|
||||
|
||||
yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE ));
|
||||
yylloc->first_line = yylloc->last_line = 1;
|
||||
yylloc->first_column = yylloc->last_column = 1;
|
||||
yylloc->filename = current->filename;
|
||||
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(MEDIA_ENV_VAR_CONTENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -641,7 +665,7 @@ if ( queue == NULL ) {
|
|||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{HWB} { return T_COL_HWB; }
|
||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CMYK} { return T_COL_CMYK; }
|
||||
|
||||
<PROPERTIES_ENV_VAR,PROPERTIES_VAR>{S_T_PARENT_LEFT} {
|
||||
<PROPERTIES_ENV_VAR,MEDIA_ENV_VAR,PROPERTIES_VAR>{S_T_PARENT_LEFT} {
|
||||
return T_PARENT_LEFT;
|
||||
}
|
||||
/* Fluff */
|
||||
|
@ -655,7 +679,12 @@ if ( queue == NULL ) {
|
|||
BEGIN(PROPERTIES_ENV_VAR);
|
||||
return T_ENV_START;
|
||||
}
|
||||
<PROPERTIES_VAR,PROPERTIES_ENV_VAR>{S_T_PARENT_RIGHT} {
|
||||
<MEDIA_CONTENT>{ENV_START} {
|
||||
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
||||
BEGIN(MEDIA_ENV_VAR);
|
||||
return T_ENV_START;
|
||||
}
|
||||
<PROPERTIES_VAR,MEDIA_ENV_VAR,PROPERTIES_ENV_VAR>{S_T_PARENT_RIGHT} {
|
||||
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
||||
return T_PARENT_RIGHT;
|
||||
}
|
||||
|
@ -664,7 +693,12 @@ if ( queue == NULL ) {
|
|||
BEGIN(PROPERTIES_VAR_DEFAULT);
|
||||
return T_COMMA;
|
||||
}
|
||||
<PROPERTIES_VAR_DEFAULT>{S_T_PARENT_RIGHT} {
|
||||
<MEDIA_ENV_VAR>{COMMA} {
|
||||
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
||||
BEGIN(MEDIA_ENV_VAR_DEFAULT);
|
||||
return T_COMMA;
|
||||
}
|
||||
<MEDIA_ENV_VAR_DEFAULT,PROPERTIES_VAR_DEFAULT>{S_T_PARENT_RIGHT} {
|
||||
// Pop 2.
|
||||
g_queue_pop_head ( queue );
|
||||
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
||||
|
@ -725,7 +759,7 @@ if ( queue == NULL ) {
|
|||
REJECT;
|
||||
}
|
||||
|
||||
<INITIAL,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT><<EOF>> {
|
||||
<INITIAL,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_ENV_VAR_CONTENT><<EOF>> {
|
||||
ParseObject *po = g_queue_pop_head ( file_queue );
|
||||
if ( po ) {
|
||||
if ( po->type == PT_FILE ) {
|
||||
|
@ -766,15 +800,20 @@ if ( queue == NULL ) {
|
|||
BEGIN(MEDIA);
|
||||
return T_MEDIA;
|
||||
}
|
||||
<INITIAL>"\}" {
|
||||
g_queue_pop_head ( queue );
|
||||
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
||||
return T_BCLOSE;
|
||||
}
|
||||
|
||||
<MEDIA>{S_T_PARENT_LEFT} {
|
||||
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
|
||||
BEGIN(MEDIA_CONTENT);
|
||||
return T_PARENT_LEFT;
|
||||
}
|
||||
<MEDIA_CONTENT>{MEDIA_NAME} {
|
||||
<MEDIA_CONTENT>{MEDIA_TYPES} {
|
||||
yylval->sval = g_strdup(yytext);
|
||||
return T_STRING;
|
||||
return T_MEDIA_TYPE;
|
||||
}
|
||||
<MEDIA_CONTENT>":" {
|
||||
return T_PSEP;
|
||||
|
@ -790,17 +829,14 @@ if ( queue == NULL ) {
|
|||
return T_BOPEN;
|
||||
}
|
||||
|
||||
<INITIAL>"\}" {
|
||||
g_queue_pop_head ( queue );
|
||||
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
|
||||
return T_BCLOSE;
|
||||
}
|
||||
<MEDIA>{WHITESPACE}+ ; // ignore all whitespace
|
||||
|
||||
/**
|
||||
* Media defaults.
|
||||
*/
|
||||
<MEDIA,MEDIA_CONTENT,MEDIA_ENV_VAR,MEDIA_ENV_VAR_DEFAULT,MEDIA_ENV_VAR_CONTENT>{WHITESPACE}+ ; // ignore all whitespace
|
||||
|
||||
<MEDIA,MEDIA_CONTENT>. {
|
||||
<MEDIA,MEDIA_CONTENT,MEDIA_ENV_VAR,MEDIA_ENV_VAR_DEFAULT,MEDIA_ENV_VAR_CONTENT>. {
|
||||
yytext[yyleng-1] = '\0';
|
||||
fprintf(stderr,"found: |%s|\n", yytext);
|
||||
return T_ERROR;
|
||||
}
|
||||
|
||||
|
@ -827,7 +863,7 @@ if ( queue == NULL ) {
|
|||
return T_ELEMENT;
|
||||
}
|
||||
|
||||
<PROPERTIES_ENV_VAR,PROPERTIES_VAR,PROPERTIES_ARRAY,PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>. {
|
||||
<MEDIA_ENV_VAR,PROPERTIES_ENV_VAR,PROPERTIES_VAR,PROPERTIES_ARRAY,PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>. {
|
||||
yytext[yyleng-1] = '\0';
|
||||
return T_ERROR_PROPERTY;
|
||||
}
|
||||
|
|
|
@ -162,7 +162,8 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b )
|
|||
%token <ival> T_ERROR_ARGB_SPEC 7 "invalid argb color. Requires 8 (not 7) elements: argb:AARRGGBB."
|
||||
%token <ival> T_INT "Integer number"
|
||||
%token <fval> T_DOUBLE "Floating-point number"
|
||||
%token <sval> T_STRING "UTF-8 encoded string"
|
||||
%token <sval> T_STRING "UTF-8 encode string"
|
||||
%token <sval> T_MEDIA_TYPE "Media type"
|
||||
%token <cval> T_CHAR "Character"
|
||||
%token <sval> T_PROP_NAME "property name"
|
||||
%token <colorval> T_COLOR_NAME "Color value by name"
|
||||
|
@ -387,7 +388,7 @@ t_entry_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {
|
|||
g_hash_table_destroy ( $4 );
|
||||
}
|
||||
}
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_STRING T_PSEP T_INT T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_INT T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
gchar *name = g_strdup_printf("@media ( %s: %d )",$4, $6);
|
||||
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
|
||||
widget->set = TRUE;
|
||||
|
@ -401,7 +402,7 @@ t_entry_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {
|
|||
g_free ( $4 );
|
||||
g_free ( name );
|
||||
}
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_STRING T_PSEP T_DOUBLE T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_DOUBLE T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
gchar *name = g_strdup_printf("@media ( %s: %f )",$4, $6);
|
||||
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
|
||||
widget->set = TRUE;
|
||||
|
@ -415,7 +416,7 @@ t_entry_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {
|
|||
g_free ( $4 );
|
||||
g_free ( name );
|
||||
}
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_STRING T_PSEP T_INT T_UNIT_PX T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_INT T_UNIT_PX T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
gchar *name = g_strdup_printf("@media ( %s: %d px )",$4, $6);
|
||||
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
|
||||
widget->set = TRUE;
|
||||
|
@ -429,6 +430,48 @@ t_entry_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {
|
|||
g_free ( $4 );
|
||||
g_free ( name );
|
||||
}
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_BOOLEAN T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
gchar *name = g_strdup_printf("@media ( %s: %s )",$4, $6?"true":"false");
|
||||
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
|
||||
widget->set = TRUE;
|
||||
widget->media = g_slice_new0(ThemeMedia);
|
||||
widget->media->type = rofi_theme_parse_media_type ( $4 );
|
||||
widget->media->boolv = $6;
|
||||
for ( unsigned int i = 0; i < $9->num_widgets; i++ ) {
|
||||
ThemeWidget *d = $9->widgets[i];
|
||||
rofi_theme_parse_merge_widgets(widget, d);
|
||||
}
|
||||
g_free ( $4 );
|
||||
g_free ( name );
|
||||
}
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_ENV_START T_PARENT_LEFT T_BOOLEAN T_COMMA T_BOOLEAN T_PARENT_RIGHT T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
gchar *name = g_strdup_printf("@media ( %s: %s )",$4, $8?"true":"false");
|
||||
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
|
||||
widget->set = TRUE;
|
||||
widget->media = g_slice_new0(ThemeMedia);
|
||||
widget->media->type = rofi_theme_parse_media_type ( $4 );
|
||||
widget->media->boolv = $8;
|
||||
for ( unsigned int i = 0; i < $14->num_widgets; i++ ) {
|
||||
ThemeWidget *d = $14->widgets[i];
|
||||
rofi_theme_parse_merge_widgets(widget, d);
|
||||
}
|
||||
g_free ( $4 );
|
||||
g_free ( name );
|
||||
}
|
||||
| t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_ENV_START T_PARENT_LEFT T_COMMA T_BOOLEAN T_PARENT_RIGHT T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE {
|
||||
gchar *name = g_strdup_printf("@media ( %s: %s )",$4, $9?"true":"false");
|
||||
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
|
||||
widget->set = TRUE;
|
||||
widget->media = g_slice_new0(ThemeMedia);
|
||||
widget->media->type = rofi_theme_parse_media_type ( $4 );
|
||||
widget->media->boolv = $9;
|
||||
for ( unsigned int i = 0; i < $13->num_widgets; i++ ) {
|
||||
ThemeWidget *d = $13->widgets[i];
|
||||
rofi_theme_parse_merge_widgets(widget, d);
|
||||
}
|
||||
g_free ( $4 );
|
||||
g_free ( name );
|
||||
}
|
||||
;
|
||||
|
||||
t_config_property_list_optional
|
||||
|
|
|
@ -1532,6 +1532,15 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon,
|
|||
}
|
||||
break;
|
||||
}
|
||||
case THEME_MEDIA_TYPE_BOOLEAN: {
|
||||
if (widget->media->boolv) {
|
||||
for (unsigned int x = 0; x < widget->num_widgets; x++) {
|
||||
rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
@ -1625,6 +1634,9 @@ ThemeMediaType rofi_theme_parse_media_type(const char *type) {
|
|||
if (g_strcmp0(type, "max-aspect-ratio") == 0) {
|
||||
return THEME_MEDIA_TYPE_MAX_ASPECT_RATIO;
|
||||
}
|
||||
if (g_strcmp0(type, "enabled") == 0) {
|
||||
return THEME_MEDIA_TYPE_BOOLEAN;
|
||||
}
|
||||
return THEME_MEDIA_TYPE_INVALID;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue