[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
parent 828aaa231a
commit 0f21541327
7 changed files with 51 additions and 2 deletions

View File

@ -87,6 +87,14 @@ typedef struct ThemeWidget
*/ */
extern ThemeWidget *rofi_theme; 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 base Handle to the current level in the theme.
* @param name Name of the new element. * @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. * @returns the ThemeWidget if found, otherwise NULL.
*/ */
ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state, gboolean exact ); 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. * @param widget The widget to find the property on.

View File

@ -474,6 +474,14 @@ if ( queue == NULL ){
return T_LINK; 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>{EM} { return T_UNIT_EM; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CH} { return T_UNIT_CH; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CH} { return T_UNIT_CH; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PX} { return T_UNIT_PX; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PX} { return T_UNIT_PX; }

View File

@ -318,7 +318,12 @@ t_main
; ;
t_configuration_list: 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 {}; | 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. // We don't keep any reference to this after this point, so the property can be free'ed.
rofi_theme_property_free ( $1 ); 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 * properties

View File

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

View File

@ -472,6 +472,11 @@ static void cleanup ()
TIMINGS_STOP (); TIMINGS_STOP ();
rofi_collect_modi_destroy ( ); rofi_collect_modi_destroy ( );
rofi_icon_fetcher_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; 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 ) ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state, gboolean exact )
{ {
// First find exact match based on name. // First find exact match based on name.

View File

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