mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Add some properties to themes
This commit is contained in:
parent
aa8c90cd7e
commit
2d01d1566a
7 changed files with 140 additions and 43 deletions
|
@ -3,7 +3,7 @@
|
|||
#include <glib.h>
|
||||
typedef enum {
|
||||
P_INTEGER,
|
||||
P_FLOAT,
|
||||
P_DOUBLE,
|
||||
P_STRING,
|
||||
P_BOOLEAN,
|
||||
P_COLOR
|
||||
|
@ -43,4 +43,13 @@ Property *rofi_theme_property_create ( PropertyType type );
|
|||
void rofi_theme_property_free ( Property *p );
|
||||
void rofi_theme_free ( Widget * );
|
||||
void rofi_theme_parse_file ( const char *file );
|
||||
|
||||
/**
|
||||
* Public API
|
||||
*/
|
||||
|
||||
int rofi_theme_get_integer ( const char *name, const char *property, int def );
|
||||
int rofi_theme_get_boolean ( const char *name, const char *property, int def );
|
||||
char *rofi_theme_get_string ( const char *name, const char *property, char *def );
|
||||
double rofi_theme_get_double ( const char *name, const char *property, double def );
|
||||
#endif
|
||||
|
|
|
@ -168,7 +168,7 @@ void listview_set_fixed_num_lines ( listview *lv, gboolean enabled );
|
|||
*
|
||||
* Hide the scrollbar.
|
||||
*/
|
||||
void listview_set_hide_scrollbar ( listview *lv, gboolean enabled );
|
||||
void listview_set_show_scrollbar ( listview *lv, gboolean enabled );
|
||||
/**
|
||||
* @param lv Handler to the listview object
|
||||
* @param width Width in pixels
|
||||
|
|
|
@ -19,11 +19,11 @@ int yylex(void);
|
|||
";" { return PCLOSE;}
|
||||
"." { return NSEP; }
|
||||
[ \t] ; // ignore all whitespace
|
||||
[0-9]+\.[0-9]+ { yylval.fval = g_ascii_strtod(yytext, NULL); return T_FLOAT;}
|
||||
[0-9]+\.[0-9]+ { yylval.fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;}
|
||||
[0-9]+ { yylval.ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;}
|
||||
(true|false) { yylval.bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
|
||||
[a-zA-Z0-9]+ { yylval.sval = g_strdup(yytext); return N_STRING;}
|
||||
\"[a-zA-Z0-9]+\" { yylval.sval = g_strdup(yytext); return T_STRING;}
|
||||
[_\-a-zA-Z0-9]+ { yylval.sval = g_strdup(yytext); return N_STRING;}
|
||||
\"[_\-a-zA-Z0-9 \t]+\" { yytext[yyleng-1] = '\0'; yylval.sval = g_strdup(&yytext[1]); return T_STRING;}
|
||||
#[0-9A-Fa-f]+ { yylval.colorval = (unsigned int)strtoull ( &yytext[1], NULL, 16); return T_COLOR;}
|
||||
[\r\n]+ ;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ Widget *rofi_theme = NULL;
|
|||
}
|
||||
|
||||
%token <ival> T_INT
|
||||
%token <fval> T_FLOAT
|
||||
%token <fval> T_DOUBLE
|
||||
%token <sval> T_STRING
|
||||
%token <sval> N_STRING
|
||||
%token <bval> T_BOOLEAN
|
||||
|
@ -123,8 +123,8 @@ property
|
|||
$$->name = $1;
|
||||
$$->value.i = $3;
|
||||
}
|
||||
| pvalue PSEP T_FLOAT PCLOSE {
|
||||
$$ = rofi_theme_property_create ( P_FLOAT );
|
||||
| pvalue PSEP T_DOUBLE PCLOSE {
|
||||
$$ = rofi_theme_property_create ( P_DOUBLE );
|
||||
$$->name = $1;
|
||||
$$->value.f = $3;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in a new issue