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

[Theme] First attempt at more cleanups and nested media support.

First throw at nested media support.

Issue: #1189
This commit is contained in:
Dave Davenport 2020-09-13 15:11:12 +02:00
parent 1d2453a948
commit 3499e1dad0
4 changed files with 47 additions and 71 deletions

View file

@ -1410,11 +1410,11 @@ Parts of the theme can be conditionally loaded, like the CSS \fB\fC@media\fR opt
.PP
It supports the following keys as constraint:
.IP \(bu 2
\fB\fCmin\-width\fR: load when width is bigger then value.
\fB\fCmin\-width\fR: load when width is bigger or equal then value.
.IP \(bu 2
\fB\fCmax\-width\fR: load when width is smaller then value.
.IP \(bu 2
\fB\fCmin\-height\fR: load when height is bigger then value.
\fB\fCmin\-height\fR: load when height is bigger or equal then value.
.IP \(bu 2
\fB\fCmax\-height\fR: load when height is smaller then value.
.IP \(bu 2

View file

@ -992,9 +992,9 @@ Parts of the theme can be conditionally loaded, like the CSS `@media` option.
It supports the following keys as constraint:
* `min-width`: load when width is bigger then value.
* `min-width`: load when width is bigger or equal then value.
* `max-width`: load when width is smaller then value.
* `min-height`: load when height is bigger then value.
* `min-height`: load when height is bigger or equal then value.
* `max-height`: load when height is smaller then value.
* `min-aspect-ratio` load when aspect ratio is over value.
* `max-aspect-ratio`: load when aspect ratio is under value.

View file

@ -244,7 +244,6 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token T_MEDIA_SEP "-"
%type <theme> t_entry_list
%type <theme> t_media_entry_list
%type <list> t_entry_name_path
%type <list> t_entry_name_path_selectors
%type <property> t_property
@ -302,56 +301,6 @@ t_configuration_list:
| t_configuration_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE {};
t_media_entry_list:
t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optional T_BCLOSE {
ThemeWidget *widget = $$ = g_slice_new0 ( ThemeWidget );
for ( GList *liter = g_list_first ( $2); liter; liter = g_list_next ( liter ) ) {
for ( GList *iter = g_list_first ( (GList*)liter->data ); widget && iter ; iter = g_list_next ( iter ) ) {
widget = rofi_theme_find_or_create_name ( widget, iter->data );
}
g_list_free_full ( (GList*)liter->data, g_free );
widget->set = TRUE;
rofi_theme_widget_add_properties ( widget, $4);
}
if ( $4 ) {
g_hash_table_destroy ( $4 );
}
g_list_free ( $2 );
}
| T_PDEFAULTS T_BOPEN t_property_list_optional T_BCLOSE {
ThemeWidget *widget = $$ = g_slice_new0( ThemeWidget ) ;
widget = rofi_theme_find_or_create_name ( widget, "*" );
widget->set = TRUE;
rofi_theme_widget_add_properties ( widget, $3);
if ( $3 ) {
g_hash_table_destroy ( $3 );
}
}
| t_media_entry_list T_PDEFAULTS T_BOPEN t_property_list_optional T_BCLOSE {
ThemeWidget *widget = $$ = $1 ;
widget = rofi_theme_find_or_create_name ( widget, "*" );
widget->set = TRUE;
rofi_theme_widget_add_properties ( widget, $4);
if ( $4 ) {
g_hash_table_destroy ( $4 );
}
}
| t_media_entry_list t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optional T_BCLOSE {
ThemeWidget *widget = $$ = $1 ;
for ( GList *liter = g_list_first ( $3); liter; liter = g_list_next ( liter ) ) {
for ( GList *iter = g_list_first ( (GList*)liter->data ); widget && iter ; iter = g_list_next ( iter ) ) {
widget = rofi_theme_find_or_create_name ( widget, iter->data );
}
g_list_free_full ( (GList*)liter->data, g_free );
widget->set = TRUE;
rofi_theme_widget_add_properties ( widget, $5);
}
if ( $5 ) {
g_hash_table_destroy ( $5 );
}
g_list_free ( $3 );
};
/**
* Small dummy object to make the prefix optional.
*/
@ -386,7 +335,7 @@ t_entry_list:
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_media_entry_list T_BCLOSE {
| t_entry_list T_MEDIA T_PARENT_LEFT T_STRING 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;
@ -399,7 +348,7 @@ t_entry_list:
}
g_free ( name );
}
| t_entry_list T_MEDIA T_PARENT_LEFT T_STRING T_PSEP T_DOUBLE T_PARENT_RIGHT T_BOPEN t_media_entry_list T_BCLOSE {
| t_entry_list T_MEDIA T_PARENT_LEFT T_STRING 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;
@ -412,7 +361,7 @@ t_entry_list:
}
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_media_entry_list T_BCLOSE {
| 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 {
gchar *name = g_strdup_printf("@media ( %s: %d px )",$4, $6);
ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name );
widget->set = TRUE;

View file

@ -1199,6 +1199,23 @@ char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file
return filename;
}
static void rofi_theme_parse_merge_widgets_no_media ( ThemeWidget *parent, ThemeWidget *child )
{
g_assert ( parent != NULL );
g_assert ( child != NULL );
if ( parent == rofi_theme && g_strcmp0 ( child->name, "*" ) == 0 ) {
rofi_theme_widget_add_properties ( parent, child->properties );
return;
}
ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name );
rofi_theme_widget_add_properties ( w, child->properties );
for ( unsigned int i = 0; i < child->num_widgets; i++ ) {
rofi_theme_parse_merge_widgets_no_media ( w, child->widgets[i] );
}
}
void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child )
{
g_assert ( parent != NULL );
@ -1209,22 +1226,26 @@ void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child )
return;
}
ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name );
if ( child->media ) {
w->media = g_slice_new0(ThemeMedia);
*(w->media) = *(child->media);
}
rofi_theme_widget_add_properties ( w, child->properties );
for ( unsigned int i = 0; i < child->num_widgets; i++ ) {
rofi_theme_parse_merge_widgets ( w, child->widgets[i] );
}
}
void rofi_theme_parse_process_conditionals ( void )
static void rofi_theme_parse_process_conditionals_int ( workarea mon, ThemeWidget *rwidget )
{
workarea mon;
monitor_active ( &mon );
if ( rofi_theme == NULL ) {
if ( rwidget == NULL ) {
return;
}
for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) {
ThemeWidget *widget = rofi_theme->widgets[i];
for ( unsigned int i = 0; i < rwidget->num_widgets; i++ ) {
ThemeWidget *widget = rwidget->widgets[i];
rofi_theme_parse_process_conditionals_int ( mon, widget );
if ( widget->media != NULL ) {
switch ( widget->media->type )
{
@ -1233,7 +1254,7 @@ void rofi_theme_parse_process_conditionals ( void )
int w = widget->media->value;
if ( mon.w >= w ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1243,7 +1264,7 @@ void rofi_theme_parse_process_conditionals ( void )
int w = widget->media->value;
if ( mon.w < w ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1253,7 +1274,7 @@ void rofi_theme_parse_process_conditionals ( void )
int h = widget->media->value;
if ( mon.h >= h ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1263,7 +1284,7 @@ void rofi_theme_parse_process_conditionals ( void )
int h = widget->media->value;
if ( mon.h < h ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1272,7 +1293,7 @@ void rofi_theme_parse_process_conditionals ( void )
{
if ( mon.monitor_id == widget->media->value ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1282,7 +1303,7 @@ void rofi_theme_parse_process_conditionals ( void )
double r = widget->media->value;
if ( ( mon.w / (double) mon.h ) >= r ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1292,7 +1313,7 @@ void rofi_theme_parse_process_conditionals ( void )
double r = widget->media->value;
if ( ( mon.w / (double) mon.h ) < r ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
rofi_theme_parse_merge_widgets_no_media ( rofi_theme, widget->widgets[x] );
}
}
break;
@ -1305,6 +1326,12 @@ void rofi_theme_parse_process_conditionals ( void )
}
}
}
void rofi_theme_parse_process_conditionals ( void )
{
workarea mon;
monitor_active ( &mon );
rofi_theme_parse_process_conditionals_int ( mon, rofi_theme );
}
ThemeMediaType rofi_theme_parse_media_type ( const char *type )
{