1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

[Configuration] Add start of more 'theme' based configuration.

Nested CSS blocks in configuration {} are parsed into
rofi_configuration.
This commit is contained in:
Dave Davenport 2021-06-14 19:29:05 +02:00 committed by Dave Davenport
parent 89ccfa7b3d
commit 74276e050d
7 changed files with 51 additions and 2 deletions

View file

@ -87,6 +87,14 @@ typedef struct ThemeWidget
*/
extern ThemeWidget *rofi_theme;
/**
* Used to store config options.
*/
extern ThemeWidget *rofi_theme;
extern ThemeWidget *rofi_configuration;
/**
* @param base Handle to the current level in the theme.
* @param name Name of the new element.
@ -333,6 +341,7 @@ void distance_get_linestyle ( RofiDistance d, cairo_t *draw );
* @returns the ThemeWidget if found, otherwise NULL.
*/
ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state, gboolean exact );
ThemeWidget *rofi_config_find_widget ( const char *name, const char *state, gboolean exact );
/**
* @param widget The widget to find the property on.

View file

@ -474,6 +474,14 @@ if ( queue == NULL ){
return T_LINK;
}
<SECTION>"\{" {
// Double to fit in scheme.
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
g_queue_push_head ( queue, GINT_TO_POINTER (SECTION) );
BEGIN(SECTION);
return T_BOPEN;
}
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{EM} { return T_UNIT_EM; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CH} { return T_UNIT_CH; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PX} { return T_UNIT_PX; }

View file

@ -318,7 +318,12 @@ t_main
;
t_configuration_list:
%empty {}
%empty {
if ( rofi_configuration == NULL ) {
rofi_configuration = g_slice_new0 ( ThemeWidget );
rofi_configuration->name = g_strdup ( "Configuration" );
}
}
| t_configuration_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {};
@ -429,6 +434,18 @@ t_config_property
// We don't keep any reference to this after this point, so the property can be free'ed.
rofi_theme_property_free ( $1 );
}
| t_property_name T_BOPEN t_property_list_optional T_BCLOSE
{
ThemeWidget *widget = rofi_configuration;
widget = rofi_theme_find_or_create_name ( widget, $1 );
widget->set = TRUE;
rofi_theme_widget_add_properties ( widget, $3);
if ( $3 ) {
g_hash_table_destroy ( $3 );
}
g_free ( $1 );
}
;
/**
* properties

View file

@ -223,7 +223,7 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat
}
if ( attr_list != NULL ) {
ThemeWidget *wid = rofi_theme_find_widget ( sw->name, NULL, TRUE );
ThemeWidget *wid = rofi_config_find_widget ( sw->name, NULL, TRUE );
Property *p = rofi_theme_find_property ( wid, P_COLOR, pd->switchers[i].mode->name, TRUE );
if ( p != NULL ) {
PangoAttribute *pa = pango_attr_foreground_new (

View file

@ -472,6 +472,11 @@ static void cleanup ()
TIMINGS_STOP ();
rofi_collect_modi_destroy ( );
rofi_icon_fetcher_destroy ( );
if ( rofi_configuration ) {
rofi_theme_free ( rofi_configuration );
rofi_configuration = NULL;
}
}
/**

View file

@ -798,6 +798,14 @@ Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, con
}
return NULL;
}
ThemeWidget *rofi_config_find_widget ( const char *name, const char *state, gboolean exact )
{
// First find exact match based on name.
ThemeWidget *widget = rofi_theme_find_single ( rofi_configuration, name );
widget = rofi_theme_find ( widget, state, exact );
return widget;
}
ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state, gboolean exact )
{
// First find exact match based on name.

View file

@ -44,6 +44,8 @@
#include "rofi-types.h"
ThemeWidget *rofi_configuration = NULL;
/** Different sources of configuration. */
const char * const ConfigSourceStr[] = {