mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Make parser more flexible, allow global properties to be anywhere in file and allow multiple similar entries.
This commit is contained in:
parent
efd1e07755
commit
b8e58b0342
8 changed files with 61 additions and 30 deletions
|
@ -9,6 +9,8 @@
|
||||||
* autoconf
|
* autoconf
|
||||||
* automake (1.11.3 or up)
|
* automake (1.11.3 or up)
|
||||||
* pkg-config
|
* pkg-config
|
||||||
|
* flex
|
||||||
|
* bison
|
||||||
* Developer packages of the external libraries
|
* Developer packages of the external libraries
|
||||||
|
|
||||||
### External libraries
|
### External libraries
|
||||||
|
|
11
Makefile.am
11
Makefile.am
|
@ -273,6 +273,10 @@ box_test_CFLAGS=$(textbox_test_CFLAGS)
|
||||||
box_test_SOURCES=\
|
box_test_SOURCES=\
|
||||||
source/widgets/widget.c\
|
source/widgets/widget.c\
|
||||||
source/widgets/box.c\
|
source/widgets/box.c\
|
||||||
|
lexer/theme-parser.y\
|
||||||
|
lexer/theme-lexer.l\
|
||||||
|
source/theme.c\
|
||||||
|
inlucde/theme.h\
|
||||||
test/box-test.c
|
test/box-test.c
|
||||||
|
|
||||||
scrollbar_test_LDADD=$(textbox_test_LDADD)
|
scrollbar_test_LDADD=$(textbox_test_LDADD)
|
||||||
|
@ -280,11 +284,18 @@ scrollbar_test_CFLAGS=$(textbox_test_CFLAGS)
|
||||||
scrollbar_test_SOURCES=\
|
scrollbar_test_SOURCES=\
|
||||||
source/widgets/widget.c\
|
source/widgets/widget.c\
|
||||||
source/widgets/scrollbar.c\
|
source/widgets/scrollbar.c\
|
||||||
|
lexer/theme-parser.y\
|
||||||
|
lexer/theme-lexer.l\
|
||||||
|
source/theme.c\
|
||||||
|
inlucde/theme.h\
|
||||||
test/scrollbar-test.c
|
test/scrollbar-test.c
|
||||||
|
|
||||||
textbox_test_SOURCES=\
|
textbox_test_SOURCES=\
|
||||||
source/widgets/widget.c\
|
source/widgets/widget.c\
|
||||||
source/widgets/textbox.c\
|
source/widgets/textbox.c\
|
||||||
|
lexer/theme-parser.y\
|
||||||
|
lexer/theme-lexer.l\
|
||||||
|
source/theme.c\
|
||||||
config/config.c\
|
config/config.c\
|
||||||
include/keyb.h\
|
include/keyb.h\
|
||||||
include/rofi.h\
|
include/rofi.h\
|
||||||
|
|
|
@ -106,7 +106,7 @@ The file is structured as follows
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The global properties has to be at the top of the file, the rest can freeĺy be mixed.
|
The global properties an freeĺy be mixed between entries.
|
||||||
|
|
||||||
Each property is constructed like:
|
Each property is constructed like:
|
||||||
```
|
```
|
||||||
|
|
|
@ -58,6 +58,7 @@ Property *rofi_theme_property_create ( PropertyType type );
|
||||||
void rofi_theme_property_free ( Property *p );
|
void rofi_theme_property_free ( Property *p );
|
||||||
void rofi_theme_free ( Widget * );
|
void rofi_theme_free ( Widget * );
|
||||||
void rofi_theme_parse_file ( const char *file );
|
void rofi_theme_parse_file ( const char *file );
|
||||||
|
void rofi_theme_widget_add_properties ( Widget *widget, GHashTable *table );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public API
|
* Public API
|
||||||
|
|
|
@ -66,12 +66,11 @@ int yylex (YYSTYPE *, YYLTYPE *);
|
||||||
%%
|
%%
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
entries
|
||||||
optional_properties
|
optional_properties
|
||||||
entries {
|
{
|
||||||
$$ = $2;
|
$$ = $1;
|
||||||
if ( $1 != NULL ) {
|
rofi_theme_widget_add_properties ( $$, $2 );
|
||||||
$$->properties = $1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
entries:
|
entries:
|
||||||
|
@ -80,7 +79,12 @@ entries:
|
||||||
$$ = rofi_theme = (Widget*)g_malloc0 (sizeof(Widget));
|
$$ = rofi_theme = (Widget*)g_malloc0 (sizeof(Widget));
|
||||||
rofi_theme->name = g_strdup ( "Window" );
|
rofi_theme->name = g_strdup ( "Window" );
|
||||||
}
|
}
|
||||||
| entries entry { $$ = $1; }
|
| entries
|
||||||
|
optional_properties
|
||||||
|
entry {
|
||||||
|
$$ = $1;
|
||||||
|
rofi_theme_widget_add_properties ( $$, $2);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
entry:
|
entry:
|
||||||
|
@ -96,11 +100,7 @@ CLASS_PREFIX class_name state_path BOPEN optional_properties BCLOSE
|
||||||
g_list_foreach ( $3, (GFunc)g_free , NULL );
|
g_list_foreach ( $3, (GFunc)g_free , NULL );
|
||||||
g_list_free ( $3 );
|
g_list_free ( $3 );
|
||||||
widget->set = TRUE;
|
widget->set = TRUE;
|
||||||
if ( widget->properties != NULL ) {
|
rofi_theme_widget_add_properties ( widget, $5);
|
||||||
fprintf(stderr, "Properties already set on this widget.\n");
|
|
||||||
exit ( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
widget->properties = $5;
|
|
||||||
}
|
}
|
||||||
| NAME_PREFIX name_path state_path BOPEN optional_properties BCLOSE
|
| NAME_PREFIX name_path state_path BOPEN optional_properties BCLOSE
|
||||||
{
|
{
|
||||||
|
@ -117,11 +117,7 @@ CLASS_PREFIX class_name state_path BOPEN optional_properties BCLOSE
|
||||||
g_list_foreach ( $3, (GFunc)g_free , NULL );
|
g_list_foreach ( $3, (GFunc)g_free , NULL );
|
||||||
g_list_free ( $3 );
|
g_list_free ( $3 );
|
||||||
widget->set = TRUE;
|
widget->set = TRUE;
|
||||||
if ( widget->properties != NULL ) {
|
rofi_theme_widget_add_properties ( widget, $5);
|
||||||
fprintf(stderr, "Properties already set on this widget.\n");
|
|
||||||
exit ( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
widget->properties = $5;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -122,6 +122,27 @@ void yyerror(YYLTYPE *yylloc, const char* s) {
|
||||||
fprintf(stderr, "From line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column);
|
fprintf(stderr, "From line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean rofi_theme_steal_property_int ( gpointer key, gpointer value, gpointer user_data)
|
||||||
|
{
|
||||||
|
GHashTable *table = (GHashTable*)user_data;
|
||||||
|
g_hash_table_replace ( table, key, value);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
void rofi_theme_widget_add_properties ( Widget *widget, GHashTable *table )
|
||||||
|
{
|
||||||
|
if ( table == NULL ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( widget->properties == NULL ){
|
||||||
|
widget->properties = table;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_hash_table_foreach_steal ( table, rofi_theme_steal_property_int, widget->properties );
|
||||||
|
g_hash_table_destroy ( table );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public API
|
* Public API
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,8 +31,8 @@ static gboolean test_widget_clicked ( G_GNUC_UNUSED widget *wid, G_GNUC_UNUSED x
|
||||||
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
box *b = box_create ( BOX_HORIZONTAL, 0, 0, 100, 20 );
|
box *b = box_create ( "box", BOX_HORIZONTAL, 0, 0, 100, 20 );
|
||||||
box_set_padding ( b, 5 );
|
//box_set_padding ( b, 5 );
|
||||||
|
|
||||||
widget *wid1 = g_malloc0(sizeof(widget));
|
widget *wid1 = g_malloc0(sizeof(widget));
|
||||||
box_add ( b , WIDGET( wid1 ), TRUE, FALSE );
|
box_add ( b , WIDGET( wid1 ), TRUE, FALSE );
|
||||||
|
@ -92,8 +92,8 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
||||||
widget_free ( WIDGET ( b ) );
|
widget_free ( WIDGET ( b ) );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
box *b = box_create ( BOX_VERTICAL, 0, 0, 20, 100 );
|
box *b = box_create ( "box", BOX_VERTICAL, 0, 0, 20, 100 );
|
||||||
box_set_padding ( b, 5 );
|
//box_set_padding ( b, 5 );
|
||||||
|
|
||||||
widget *wid1 = g_malloc0(sizeof(widget));
|
widget *wid1 = g_malloc0(sizeof(widget));
|
||||||
box_add ( b , WIDGET( wid1 ), TRUE, FALSE );
|
box_add ( b , WIDGET( wid1 ), TRUE, FALSE );
|
||||||
|
@ -152,8 +152,8 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
||||||
widget_free ( WIDGET ( b ) );
|
widget_free ( WIDGET ( b ) );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
box *b = box_create ( BOX_VERTICAL, 0, 0, 20, 100 );
|
box *b = box_create ( "box", BOX_VERTICAL, 0, 0, 20, 100 );
|
||||||
box_set_padding ( b, 5 );
|
//box_set_padding ( b, 5 );
|
||||||
widget *wid1 = g_malloc0(sizeof(widget));
|
widget *wid1 = g_malloc0(sizeof(widget));
|
||||||
widget_enable(wid1);
|
widget_enable(wid1);
|
||||||
wid1->clicked = test_widget_clicked;
|
wid1->clicked = test_widget_clicked;
|
||||||
|
|
|
@ -53,7 +53,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
||||||
PangoContext *p = pango_cairo_create_context ( draw );
|
PangoContext *p = pango_cairo_create_context ( draw );
|
||||||
textbox_set_pango_context ( p );
|
textbox_set_pango_context ( p );
|
||||||
|
|
||||||
textbox *box = textbox_create ( TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
|
textbox *box = textbox_create ( "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
|
||||||
NORMAL, "test" );
|
NORMAL, "test" );
|
||||||
TASSERT ( box != NULL );
|
TASSERT ( box != NULL );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue