summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-12-09 22:16:31 +0100
committerDave Davenport <qball@gmpclient.org>2016-12-09 22:16:31 +0100
commit2d01d1566af91502dee35a132e6957a1f9e9c939 (patch)
tree6772d4baf02133d1bfc52ffcfaedbdba26d52f7f /source
parentaa8c90cd7e3a7d226f59a8119639d91be9a60dc1 (diff)
Add some properties to themes
Diffstat (limited to 'source')
-rw-r--r--source/theme.c95
-rw-r--r--source/view.c23
-rw-r--r--source/widgets/listview.c2
3 files changed, 104 insertions, 16 deletions
diff --git a/source/theme.c b/source/theme.c
index 7fb05816..16ec8dec 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -72,7 +72,7 @@ static void rofi_theme_print_property_index ( int depth, Property *p )
case P_INTEGER:
printf("%d", p->value.i);
break;
- case P_FLOAT:
+ case P_DOUBLE:
printf("%.2f", p->value.f);
break;
case P_BOOLEAN:
@@ -112,6 +112,14 @@ extern int yyparse();
extern FILE* yyin;
extern Widget *rofi_theme;
+void yyerror(const char* s) {
+ fprintf(stderr, "Parse error: %s\n", s);
+ exit(EXIT_FAILURE);
+}
+/**
+ * Public API
+ */
+
void rofi_theme_parse_file ( const char *file )
{
yyin = fopen ( file, "rb");
@@ -122,7 +130,86 @@ void rofi_theme_parse_file ( const char *file )
while ( yyparse() );
}
-void yyerror(const char* s) {
- fprintf(stderr, "Parse error: %s\n", s);
- exit(EXIT_FAILURE);
+static Widget *rofi_theme_find ( const char *name )
+{
+ Widget *widget = rofi_theme;
+ char **names = g_strsplit ( name, "." , 0 );
+ int found = TRUE;
+ for ( unsigned int i = 0; found && names && names[i]; i++ ){
+ found = FALSE;
+ for ( unsigned int j = 0; j < widget ->num_widgets;j++){
+ if ( g_strcmp0(widget->widgets[j]->name, names[i]) == 0 ){
+ widget = widget->widgets[j];
+ found = TRUE;
+ break;
+ }
+ }
+ }
+ g_strfreev(names);
+ return widget;
+}
+
+static Property *rofi_theme_find_property ( Widget *widget, PropertyType type, const char *property )
+{
+ while ( widget ) {
+ if ( widget->properties && g_hash_table_contains ( widget->properties, property) ) {
+ Property *p = g_hash_table_lookup ( widget->properties, property);
+ if ( p->type == type ){
+ return p;
+ }
+ }
+ widget = widget->parent;
+ }
+ return NULL;
+}
+
+int rofi_theme_get_integer ( const char *name, const char *property, int def )
+{
+ if ( rofi_theme == NULL ) {
+ return def;
+ }
+ Widget *widget = rofi_theme_find ( name );
+ Property *p = rofi_theme_find_property ( widget, P_INTEGER, property );
+ if ( p ){
+ return p->value.i;
+ }
+ return def;
+}
+
+int rofi_theme_get_boolean ( const char *name, const char *property, int def )
+{
+ if ( rofi_theme == NULL ) {
+ return def;
+ }
+ Widget *widget = rofi_theme_find ( name );
+ Property *p = rofi_theme_find_property ( widget, P_BOOLEAN, property );
+ if ( p ){
+ return p->value.b;
+ }
+ return def;
+}
+
+char *rofi_theme_get_string ( const char *name, const char *property, char *def )
+{
+ if ( rofi_theme == NULL ) {
+ return def;
+ }
+ Widget *widget = rofi_theme_find ( name );
+ Property *p = rofi_theme_find_property ( widget, P_STRING, property );
+ if ( p ){
+ return p->value.s;
+ }
+ return def;
+}
+double rofi_theme_get_double ( const char *name, const char *property, double def )
+{
+ if ( rofi_theme == NULL ) {
+ return def;
+ }
+ Widget *widget = rofi_theme_find ( name );
+ Property *p = rofi_theme_find_property ( widget, P_DOUBLE, property );
+ if ( p ){
+ return p->value.b;
+ }
+ return def;
}
diff --git a/source/view.c b/source/view.c
index ab88e13f..feec10da 100644
--- a/source/view.c
+++ b/source/view.c
@@ -58,6 +58,8 @@
#include "view.h"
#include "view-internal.h"
+#include "theme.h"
+
/** The Rofi View log domain */
#define LOG_DOMAIN "View"
@@ -1426,16 +1428,15 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->main_box = box_create ( BOX_VERTICAL,
state->border, state->border,
state->width - 2 * state->border, state->height - 2 * state->border );
- box_set_padding ( state->main_box, config.line_margin );
+ box_set_padding ( state->main_box, rofi_theme_get_integer ( "box.main_box", "padding",config.line_margin ));
// we need this at this point so we can get height.
unsigned int line_height = textbox_get_estimated_char_height ();
rofi_view_calculate_window_and_element_width ( state );
state->input_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height );
- //box_set_padding ( state->input_bar, config.line_margin );
state->input_bar_separator = separator_create ( S_HORIZONTAL, 2 );
- separator_set_line_style_from_string ( state->input_bar_separator, config.separator_style );
+ separator_set_line_style_from_string ( state->input_bar_separator, rofi_theme_get_string ( "separator.input_bar", "style", config.separator_style ));
int end = ( config.location == WL_EAST_SOUTH || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST );
box_add ( state->main_box, WIDGET ( state->input_bar ), FALSE, end );
@@ -1473,13 +1474,13 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->list_view = listview_create ( update_callback, state, config.element_height );
// Set configuration
listview_set_multi_select ( state->list_view, ( state->menu_flags & MENU_INDICATOR ) == MENU_INDICATOR );
- listview_set_padding ( state->list_view, config.line_margin );
- listview_set_max_lines ( state->list_view, config.menu_lines );
- listview_set_max_columns ( state->list_view, config.menu_columns );
- listview_set_fixed_num_lines ( state->list_view, config.fixed_num_lines );
- listview_set_hide_scrollbar ( state->list_view, !config.hide_scrollbar );
- listview_set_scrollbar_width ( state->list_view, config.scrollbar_width );
- listview_set_cycle ( state->list_view, config.cycle );
+ listview_set_padding ( state->list_view, rofi_theme_get_integer ( "listview", "padding", config.line_margin ));
+ listview_set_max_lines ( state->list_view, rofi_theme_get_integer ( "listview", "lines", config.menu_lines ));
+ listview_set_max_columns ( state->list_view, rofi_theme_get_integer ( "listview", "columns", config.menu_columns));
+ listview_set_fixed_num_lines ( state->list_view, rofi_theme_get_boolean ( "listview", "fixed-height", config.fixed_num_lines ));
+ listview_set_show_scrollbar ( state->list_view, rofi_theme_get_boolean ( "listview", "scrollbar", !config.hide_scrollbar ));
+ listview_set_scrollbar_width ( state->list_view, rofi_theme_get_integer ( "listview", "scrollbar-width", config.scrollbar_width ));
+ listview_set_cycle ( state->list_view, rofi_theme_get_boolean ( "listview" , "cycle", config.cycle ));
listview_set_scroll_type ( state->list_view, config.scroll_method );
listview_set_mouse_activated_cb ( state->list_view, rofi_view_listview_mouse_activated_cb, state );
@@ -1488,7 +1489,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
// Only enable widget when sidebar is enabled.
if ( config.sidebar_mode ) {
state->sidebar_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height );
- box_set_padding ( state->sidebar_bar, config.line_margin );
+ box_set_padding ( state->sidebar_bar, rofi_theme_get_integer ( "box.sidebar", "padding",config.line_margin ) );
separator *sep = separator_create ( S_HORIZONTAL, 2 );
box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE );
separator_set_line_style_from_string ( sep, config.separator_style );
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index d5f0efe0..47280d17 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -466,7 +466,7 @@ void listview_set_fixed_num_lines ( listview *lv, gboolean enabled )
lv->fixed_num_lines = enabled;
}
}
-void listview_set_hide_scrollbar ( listview *lv, gboolean enabled )
+void listview_set_show_scrollbar ( listview *lv, gboolean enabled )
{
if ( lv ) {
if ( enabled ) {