2016-12-09 18:49:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "theme.h"
|
2016-12-12 15:55:31 +00:00
|
|
|
#include "lexer/theme-parser.h"
|
2016-12-28 11:21:42 +00:00
|
|
|
#include "helper.h"
|
2017-01-01 00:06:38 +00:00
|
|
|
#include "settings.h"
|
2016-12-31 22:27:17 +00:00
|
|
|
#include "widgets/textbox.h"
|
|
|
|
|
2016-12-12 15:55:31 +00:00
|
|
|
void yyerror ( YYLTYPE *ylloc, const char *);
|
2016-12-09 18:49:49 +00:00
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *rofi_theme_find_or_create_class ( ThemeWidget *base, const char *class )
|
2016-12-09 18:49:49 +00:00
|
|
|
{
|
|
|
|
for ( unsigned int i = 0; i < base->num_widgets;i++){
|
|
|
|
if ( g_strcmp0(base->widgets[i]->name, class) == 0 ){
|
|
|
|
return base->widgets[i];
|
2016-12-12 15:55:31 +00:00
|
|
|
}
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
base->widgets = g_realloc ( base->widgets, sizeof(ThemeWidget*)*(base->num_widgets+1));
|
|
|
|
base->widgets[base->num_widgets] = g_malloc0(sizeof(ThemeWidget));
|
|
|
|
ThemeWidget *retv = base->widgets[base->num_widgets];
|
2016-12-09 18:49:49 +00:00
|
|
|
retv->parent = base;
|
|
|
|
retv->name = g_strdup(class);
|
|
|
|
base->num_widgets++;
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Properties
|
|
|
|
*/
|
|
|
|
Property *rofi_theme_property_create ( PropertyType type )
|
|
|
|
{
|
|
|
|
Property *retv = g_malloc0 ( sizeof(Property) );
|
|
|
|
retv->type = type;
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
void rofi_theme_property_free ( Property *p )
|
|
|
|
{
|
|
|
|
if ( p == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_free ( p->name );
|
|
|
|
if ( p->type == P_STRING ) {
|
|
|
|
g_free ( p->value.s );
|
|
|
|
}
|
|
|
|
g_free(p);
|
|
|
|
}
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
void rofi_theme_free ( ThemeWidget *widget )
|
2016-12-09 18:49:49 +00:00
|
|
|
{
|
|
|
|
if ( widget == NULL ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( widget->properties ) {
|
|
|
|
g_hash_table_destroy ( widget->properties );
|
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < widget->num_widgets; i++ ){
|
2016-12-16 08:28:13 +00:00
|
|
|
rofi_theme_free ( widget->widgets[i] );
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
|
|
|
g_free ( widget->widgets );
|
|
|
|
g_free ( widget->name );
|
|
|
|
g_free ( widget );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* print
|
|
|
|
*/
|
|
|
|
static void rofi_theme_print_property_index ( int depth, Property *p )
|
|
|
|
{
|
2017-01-01 00:06:38 +00:00
|
|
|
printf("%*s%s: ", depth, "", p->name );
|
2016-12-09 18:49:49 +00:00
|
|
|
switch ( p->type )
|
|
|
|
{
|
|
|
|
case P_STRING:
|
2017-01-01 00:06:38 +00:00
|
|
|
printf("\"%s\";", p->value.s);
|
2016-12-09 18:49:49 +00:00
|
|
|
break;
|
|
|
|
case P_INTEGER:
|
2017-01-01 00:06:38 +00:00
|
|
|
printf("%d;", p->value.i);
|
2016-12-09 18:49:49 +00:00
|
|
|
break;
|
2016-12-09 21:16:31 +00:00
|
|
|
case P_DOUBLE:
|
2017-01-01 00:06:38 +00:00
|
|
|
printf("%.2f;", p->value.f);
|
2016-12-09 18:49:49 +00:00
|
|
|
break;
|
|
|
|
case P_BOOLEAN:
|
2017-01-01 00:06:38 +00:00
|
|
|
printf("%s;", p->value.b?"true":"false");
|
2016-12-09 18:49:49 +00:00
|
|
|
break;
|
|
|
|
case P_COLOR:
|
2017-01-01 00:06:38 +00:00
|
|
|
printf("#%02X%02X%02X%02X;",
|
2016-12-10 18:48:44 +00:00
|
|
|
(unsigned char)(p->value.color.alpha*255.0),
|
|
|
|
(unsigned char)(p->value.color.red*255.0),
|
|
|
|
(unsigned char)(p->value.color.green*255.0),
|
|
|
|
(unsigned char)(p->value.color.blue*255.0));
|
2016-12-09 18:49:49 +00:00
|
|
|
break;
|
2016-12-31 21:47:22 +00:00
|
|
|
case P_PADDING:
|
2017-01-01 00:06:38 +00:00
|
|
|
if ( p->value.padding.left.type == PW_PX ) {
|
|
|
|
printf("%upx ", (int)p->value.padding.left.distance );
|
|
|
|
} else {
|
|
|
|
printf("%fem ", p->value.padding.left.distance );
|
|
|
|
}
|
|
|
|
if ( p->value.padding.right.type == PW_PX ) {
|
|
|
|
printf("%upx ", (int)p->value.padding.right.distance );
|
|
|
|
} else {
|
|
|
|
printf("%fem ", p->value.padding.right.distance );
|
|
|
|
}
|
|
|
|
if ( p->value.padding.top.type == PW_PX ) {
|
|
|
|
printf("%upx ", (int)p->value.padding.top.distance );
|
|
|
|
} else {
|
|
|
|
printf("%fem ", p->value.padding.top.distance );
|
|
|
|
}
|
|
|
|
if ( p->value.padding.bottom.type == PW_PX ) {
|
|
|
|
printf("%upx ", (int)p->value.padding.bottom.distance );
|
|
|
|
} else {
|
|
|
|
printf("%fem ", p->value.padding.bottom.distance );
|
|
|
|
}
|
|
|
|
printf(";\n");
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
|
|
|
putchar ( '\n' );
|
|
|
|
}
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
static void rofi_theme_print_index ( ThemeWidget *widget )
|
2016-12-09 18:49:49 +00:00
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
if ( widget->properties ){
|
2017-01-01 00:06:38 +00:00
|
|
|
int index = 0;
|
|
|
|
GList *list = NULL;
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *w = widget;
|
2017-01-01 00:06:38 +00:00
|
|
|
while ( w){
|
|
|
|
if ( g_strcmp0(w->name,"Root") == 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = g_list_prepend ( list, w->name );
|
|
|
|
w = w->parent;
|
|
|
|
}
|
|
|
|
if ( g_list_length ( list ) > 0 ) {
|
|
|
|
index = 4;
|
|
|
|
for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
|
|
|
|
char *name = (char *)iter->data;
|
|
|
|
if ( iter->prev == NULL && name[0] != '@' ){
|
|
|
|
putchar ( '#' );
|
|
|
|
}
|
|
|
|
fputs(name, stdout);
|
|
|
|
if ( name[0] == '@' ) {
|
|
|
|
putchar(' ');
|
|
|
|
} else {
|
|
|
|
if ( iter->next ) {
|
|
|
|
putchar('.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" {\n");
|
|
|
|
}
|
2016-12-09 18:49:49 +00:00
|
|
|
g_hash_table_iter_init (&iter, widget->properties);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
Property *p = (Property*)value;
|
2017-01-01 00:06:38 +00:00
|
|
|
rofi_theme_print_property_index ( index, p );
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
2017-01-01 00:06:38 +00:00
|
|
|
if ( g_list_length ( list ) > 0 ) {
|
|
|
|
printf("}\n");
|
|
|
|
}
|
|
|
|
g_list_free ( list );
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < widget->num_widgets;i++){
|
2017-01-01 00:06:38 +00:00
|
|
|
rofi_theme_print_index ( widget->widgets[i] );
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-01 17:08:49 +00:00
|
|
|
void rofi_theme_print ( ThemeWidget *widget )
|
2016-12-09 18:49:49 +00:00
|
|
|
{
|
2017-01-01 00:06:38 +00:00
|
|
|
rofi_theme_print_index ( widget );
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
/**
|
|
|
|
* Main lex parser.
|
|
|
|
*/
|
2016-12-19 14:50:35 +00:00
|
|
|
int yyparse();
|
2017-01-01 17:08:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the internal of lex parser.
|
|
|
|
*/
|
2016-12-19 14:50:35 +00:00
|
|
|
void yylex_destroy( void );
|
2017-01-01 17:08:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Global handle input file to flex parser.
|
|
|
|
*/
|
2016-12-09 18:49:49 +00:00
|
|
|
extern FILE* yyin;
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
/**
|
|
|
|
* @param yylloc The file location.
|
|
|
|
* @param s Error message string.
|
|
|
|
*
|
|
|
|
* Error handler for the lex parser.
|
|
|
|
*/
|
2016-12-12 15:55:31 +00:00
|
|
|
void yyerror(YYLTYPE *yylloc, const char* s) {
|
2016-12-09 21:16:31 +00:00
|
|
|
fprintf(stderr, "Parse error: %s\n", s);
|
2016-12-12 15:55:31 +00:00
|
|
|
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);
|
2016-12-09 21:16:31 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2016-12-16 08:28:13 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-01-01 17:08:49 +00:00
|
|
|
void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table )
|
2016-12-16 08:28:13 +00:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-09 21:16:31 +00:00
|
|
|
/**
|
|
|
|
* Public API
|
|
|
|
*/
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
static ThemeWidget *rofi_theme_find_single ( ThemeWidget *widget, const char *name)
|
2016-12-15 08:46:42 +00:00
|
|
|
{
|
|
|
|
for ( unsigned int j = 0; j < widget->num_widgets;j++){
|
|
|
|
if ( g_strcmp0(widget->widgets[j]->name, name ) == 0 ){
|
|
|
|
return widget->widgets[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
2016-12-09 18:49:49 +00:00
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
static ThemeWidget *rofi_theme_find ( ThemeWidget *widget , const char *name, const gboolean exact )
|
2016-12-09 21:16:31 +00:00
|
|
|
{
|
2016-12-20 08:17:19 +00:00
|
|
|
if ( widget == NULL || name == NULL ) {
|
2016-12-12 08:11:57 +00:00
|
|
|
return widget;
|
|
|
|
}
|
2016-12-09 21:16:31 +00:00
|
|
|
char **names = g_strsplit ( name, "." , 0 );
|
|
|
|
int found = TRUE;
|
|
|
|
for ( unsigned int i = 0; found && names && names[i]; i++ ){
|
|
|
|
found = FALSE;
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *f = rofi_theme_find_single ( widget, names[i]);
|
2016-12-15 08:46:42 +00:00
|
|
|
if ( f != widget ){
|
|
|
|
widget = f;
|
|
|
|
found = TRUE;
|
2016-12-09 21:16:31 +00:00
|
|
|
}
|
2016-12-16 08:28:13 +00:00
|
|
|
}
|
2016-12-09 21:16:31 +00:00
|
|
|
g_strfreev(names);
|
2016-12-20 08:17:19 +00:00
|
|
|
if ( !exact || found ){
|
|
|
|
return widget;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-12-09 21:16:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
static Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, const char *property )
|
2016-12-09 21:16:31 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2016-12-16 08:28:13 +00:00
|
|
|
}
|
2016-12-09 21:16:31 +00:00
|
|
|
widget = widget->parent;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-01-01 17:08:49 +00:00
|
|
|
static ThemeWidget *rofi_theme_find_widget ( const char *wclass, const char *name, const char *state )
|
2016-12-09 21:16:31 +00:00
|
|
|
{
|
2016-12-20 08:17:19 +00:00
|
|
|
// First find exact match based on name.
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find ( rofi_theme, name, TRUE );
|
2016-12-20 08:17:19 +00:00
|
|
|
widget = rofi_theme_find ( widget, state, TRUE );
|
|
|
|
|
|
|
|
if ( widget == NULL ){
|
2016-12-12 22:40:43 +00:00
|
|
|
// Fall back to class
|
2016-12-20 08:17:19 +00:00
|
|
|
widget = rofi_theme_find ( rofi_theme, wclass, TRUE);
|
|
|
|
widget = rofi_theme_find ( widget, state, TRUE );
|
2016-12-12 22:40:43 +00:00
|
|
|
}
|
2016-12-20 08:17:19 +00:00
|
|
|
if ( widget == NULL ){
|
|
|
|
// Fuzzy finder
|
2016-12-20 09:27:23 +00:00
|
|
|
widget = rofi_theme_find ( rofi_theme, name, FALSE );
|
2016-12-20 08:17:19 +00:00
|
|
|
if ( widget == rofi_theme ){
|
|
|
|
widget = rofi_theme_find ( widget, wclass, FALSE );
|
|
|
|
}
|
|
|
|
widget = rofi_theme_find ( widget, state, FALSE );
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rofi_theme_get_integer ( const char *wclass, const char *name, const char *state, const char *property, int def )
|
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-09 21:16:31 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_INTEGER, property );
|
|
|
|
if ( p ){
|
|
|
|
return p->value.i;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
2016-12-31 22:27:17 +00:00
|
|
|
Distance rofi_theme_get_distance ( const char *wclass, const char *name, const char *state, const char *property, int def )
|
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-31 22:27:17 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_PADDING, property );
|
|
|
|
if ( p ){
|
|
|
|
return p->value.padding.left;
|
|
|
|
}
|
2016-12-31 22:30:57 +00:00
|
|
|
// Fall back to px if no metric is given.
|
|
|
|
p = rofi_theme_find_property ( widget, P_INTEGER, property );
|
|
|
|
if ( p ){
|
|
|
|
return (Distance){(double)p->value.i, PW_PX};
|
|
|
|
}
|
2016-12-31 22:27:17 +00:00
|
|
|
return (Distance){def, PW_PX};
|
|
|
|
}
|
2016-12-09 21:16:31 +00:00
|
|
|
|
2016-12-12 22:40:43 +00:00
|
|
|
int rofi_theme_get_boolean ( const char *wclass, const char *name, const char *state, const char *property, int def )
|
2016-12-09 21:16:31 +00:00
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-09 21:16:31 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_BOOLEAN, property );
|
|
|
|
if ( p ){
|
|
|
|
return p->value.b;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2016-12-12 22:40:43 +00:00
|
|
|
char *rofi_theme_get_string ( const char *wclass, const char *name, const char *state, const char *property, char *def )
|
2016-12-09 21:16:31 +00:00
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-09 21:16:31 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_STRING, property );
|
|
|
|
if ( p ){
|
|
|
|
return p->value.s;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
2016-12-12 22:40:43 +00:00
|
|
|
double rofi_theme_get_double ( const char *wclass, const char *name, const char *state, const char *property, double def )
|
2016-12-09 21:16:31 +00:00
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-09 21:16:31 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_DOUBLE, property );
|
|
|
|
if ( p ){
|
|
|
|
return p->value.b;
|
|
|
|
}
|
|
|
|
return def;
|
2016-12-09 18:49:49 +00:00
|
|
|
}
|
2016-12-16 08:28:13 +00:00
|
|
|
void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d)
|
2016-12-11 11:19:46 +00:00
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-11 11:19:46 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_COLOR, property );
|
|
|
|
if ( p ){
|
|
|
|
cairo_set_source_rgba ( d,
|
|
|
|
p->value.color.red,
|
|
|
|
p->value.color.green,
|
|
|
|
p->value.color.blue,
|
|
|
|
p->value.color.alpha
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-12-27 21:19:15 +00:00
|
|
|
Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad )
|
|
|
|
{
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_widget ( wclass, name, state );
|
2016-12-31 20:37:19 +00:00
|
|
|
Property *p = rofi_theme_find_property ( widget, P_PADDING, property );
|
2016-12-27 21:19:15 +00:00
|
|
|
if ( p ){
|
2016-12-31 20:37:19 +00:00
|
|
|
pad = p->value.padding;
|
2016-12-31 22:34:48 +00:00
|
|
|
}else {
|
|
|
|
p = rofi_theme_find_property ( widget, P_INTEGER, property );
|
|
|
|
if ( p ){
|
|
|
|
Distance d = (Distance){p->value.i, PW_PX};
|
|
|
|
pad = (Padding){d,d,d,d};
|
|
|
|
}
|
2016-12-27 21:19:15 +00:00
|
|
|
}
|
|
|
|
return pad;
|
|
|
|
}
|
2016-12-31 22:27:17 +00:00
|
|
|
int distance_get_pixel ( Distance d )
|
|
|
|
{
|
|
|
|
if ( d.type == PW_EM ){
|
|
|
|
return d.distance*textbox_get_estimated_char_height();
|
|
|
|
}
|
|
|
|
return d.distance;
|
|
|
|
}
|
2017-01-01 00:06:38 +00:00
|
|
|
|
2017-01-01 15:32:01 +00:00
|
|
|
#ifdef THEME_CONVERTER
|
|
|
|
|
2017-01-01 00:06:38 +00:00
|
|
|
static Property* rofi_theme_convert_get_color ( const char *color, const char *name )
|
|
|
|
{
|
|
|
|
Color c = color_get ( color );
|
|
|
|
Property *p = rofi_theme_property_create ( P_COLOR );
|
|
|
|
p->name = g_strdup(name);
|
|
|
|
p->value.color.alpha = c.alpha;
|
|
|
|
p->value.color.red = c.red;
|
|
|
|
p->value.color.green = c.green;
|
|
|
|
p->value.color.blue = c.blue;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
static GHashTable * rofi_theme_convert_create_property_ht ( void )
|
|
|
|
{
|
|
|
|
return g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify)rofi_theme_property_free );
|
|
|
|
}
|
|
|
|
|
|
|
|
void rofi_theme_convert_old_theme ( void )
|
|
|
|
{
|
|
|
|
if ( rofi_theme != NULL ){
|
|
|
|
return;
|
|
|
|
}
|
2017-01-01 17:08:49 +00:00
|
|
|
rofi_theme = (ThemeWidget*)g_malloc0 ( sizeof ( ThemeWidget ) );
|
2017-01-01 00:06:38 +00:00
|
|
|
rofi_theme->name = g_strdup ( "Root" );
|
|
|
|
rofi_theme->properties = rofi_theme_convert_create_property_ht ( );
|
2017-01-01 14:39:02 +00:00
|
|
|
{
|
|
|
|
// Spacing
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *box_widget = rofi_theme_find_or_create_class ( rofi_theme , "@box" );
|
2017-01-01 14:39:02 +00:00
|
|
|
box_widget->properties = rofi_theme_convert_create_property_ht ( );
|
|
|
|
Property *p = rofi_theme_property_create ( P_INTEGER );
|
|
|
|
p->name = g_strdup("spacing");
|
|
|
|
p->value.i = config.padding;
|
|
|
|
g_hash_table_replace ( box_widget->properties, p->name, p );
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Spacing
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *listview_widget = rofi_theme_find_or_create_class ( rofi_theme , "@listview" );
|
2017-01-01 14:39:02 +00:00
|
|
|
listview_widget->properties = rofi_theme_convert_create_property_ht ( );
|
|
|
|
Property *p = rofi_theme_property_create ( P_INTEGER );
|
|
|
|
p->name = g_strdup("spacing");
|
|
|
|
p->value.i = config.padding;
|
|
|
|
g_hash_table_replace ( listview_widget->properties, p->name, p );
|
2017-01-03 13:25:24 +00:00
|
|
|
p = rofi_theme_property_create ( P_INTEGER );
|
|
|
|
p->name = g_strdup("columns");
|
|
|
|
p->value.i = config.padding;
|
|
|
|
g_hash_table_replace ( listview_widget->properties, p->name, p );
|
|
|
|
p = rofi_theme_property_create ( P_INTEGER );
|
|
|
|
p->name = g_strdup("fixed-height");
|
|
|
|
p->value.i = !(config.fixed_num_lines);
|
|
|
|
g_hash_table_replace ( listview_widget->properties, p->name, p );
|
2017-01-01 14:39:02 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// Border width.
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *window_widget = rofi_theme_find_or_create_class ( rofi_theme , "@window" );
|
2017-01-01 14:39:02 +00:00
|
|
|
window_widget->properties = rofi_theme_convert_create_property_ht ( );
|
|
|
|
Property *p = rofi_theme_property_create ( P_INTEGER );
|
|
|
|
p->name = g_strdup("border-width");
|
|
|
|
p->value.i = config.menu_bw;
|
|
|
|
g_hash_table_replace ( window_widget->properties, p->name, p );
|
|
|
|
// Padding
|
|
|
|
p = rofi_theme_property_create ( P_INTEGER );
|
|
|
|
p->name = g_strdup("padding");
|
|
|
|
p->value.i = config.padding;
|
|
|
|
g_hash_table_replace ( window_widget->properties, p->name, p );
|
|
|
|
}
|
2017-01-01 00:06:38 +00:00
|
|
|
{
|
|
|
|
gchar **vals = g_strsplit ( config.color_window, ",", 3 );
|
|
|
|
if ( vals != NULL ){
|
|
|
|
if ( vals[0] != NULL ) {
|
|
|
|
Property *p = rofi_theme_convert_get_color ( vals[0], "background" );
|
|
|
|
g_hash_table_replace ( rofi_theme->properties, p->name, p );
|
|
|
|
|
|
|
|
if ( vals[1] != NULL ) {
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( rofi_theme->properties, p->name, p );
|
|
|
|
|
|
|
|
if ( vals[2] != NULL ) {
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_or_create_class ( rofi_theme , "@separator" );
|
2017-01-01 00:06:38 +00:00
|
|
|
widget->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( widget->properties, p->name, p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_strfreev ( vals );
|
|
|
|
{
|
|
|
|
Property *p = NULL;
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *widget = rofi_theme_find_or_create_class ( rofi_theme , "@textbox" );
|
2017-01-01 00:06:38 +00:00
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wnormal = rofi_theme_find_or_create_class ( widget, "normal" );
|
|
|
|
ThemeWidget *wselected = rofi_theme_find_or_create_class ( widget, "selected" );
|
|
|
|
ThemeWidget *walternate = rofi_theme_find_or_create_class ( widget, "alternate" );
|
2017-01-01 00:06:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
gchar **vals = g_strsplit ( config.color_normal, ",", 5 );
|
|
|
|
if ( g_strv_length (vals) == 5 ) {
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wnn = rofi_theme_find_or_create_class ( wnormal, "normal" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wnn->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[0], "background" );
|
|
|
|
g_hash_table_replace ( wnn->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( wnn->properties, p->name, p );
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wsl = rofi_theme_find_or_create_class ( wselected, "normal" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wsl->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[3], "background" );
|
|
|
|
g_hash_table_replace ( wsl->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[4], "foreground" );
|
|
|
|
g_hash_table_replace ( wsl->properties, p->name, p );
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wal = rofi_theme_find_or_create_class ( walternate, "normal" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wal->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[2], "background" );
|
|
|
|
g_hash_table_replace ( wal->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( wal->properties, p->name, p );
|
|
|
|
}
|
|
|
|
g_strfreev ( vals );
|
|
|
|
|
|
|
|
vals = g_strsplit ( config.color_urgent, ",", 5 );
|
|
|
|
if ( g_strv_length (vals) == 5 ) {
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wnn = rofi_theme_find_or_create_class ( wnormal, "urgent" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wnn->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[0], "background" );
|
|
|
|
g_hash_table_replace ( wnn->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( wnn->properties, p->name, p );
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wsl = rofi_theme_find_or_create_class ( wselected, "urgent" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wsl->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[3], "background" );
|
|
|
|
g_hash_table_replace ( wsl->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[4], "foreground" );
|
|
|
|
g_hash_table_replace ( wsl->properties, p->name, p );
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wal = rofi_theme_find_or_create_class ( walternate, "urgent" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wal->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[2], "background" );
|
|
|
|
g_hash_table_replace ( wal->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( wal->properties, p->name, p );
|
|
|
|
}
|
|
|
|
g_strfreev ( vals );
|
|
|
|
|
|
|
|
vals = g_strsplit ( config.color_active, ",", 5 );
|
|
|
|
if ( g_strv_length (vals) == 5 ) {
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wnn = rofi_theme_find_or_create_class ( wnormal, "active" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wnn->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[0], "background" );
|
|
|
|
g_hash_table_replace ( wnn->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( wnn->properties, p->name, p );
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wsl = rofi_theme_find_or_create_class ( wselected, "active" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wsl->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[3], "background" );
|
|
|
|
g_hash_table_replace ( wsl->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[4], "foreground" );
|
|
|
|
g_hash_table_replace ( wsl->properties, p->name, p );
|
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
ThemeWidget *wal = rofi_theme_find_or_create_class ( walternate, "active" );
|
2017-01-01 00:06:38 +00:00
|
|
|
wal->properties = rofi_theme_convert_create_property_ht ();
|
|
|
|
p = rofi_theme_convert_get_color ( vals[2], "background" );
|
|
|
|
g_hash_table_replace ( wal->properties, p->name, p );
|
|
|
|
p = rofi_theme_convert_get_color ( vals[1], "foreground" );
|
|
|
|
g_hash_table_replace ( wal->properties, p->name, p );
|
|
|
|
}
|
|
|
|
g_strfreev ( vals );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-01 15:32:01 +00:00
|
|
|
void rofi_theme_parse_file ( const char *file )
|
|
|
|
{
|
|
|
|
char *filename = rofi_expand_path ( file );
|
|
|
|
yyin = fopen ( filename, "rb");
|
|
|
|
if ( yyin == NULL ){
|
|
|
|
fprintf(stderr, "Failed to open file: %s: '%s'\n", filename, strerror ( errno ) );
|
|
|
|
g_free(filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while ( yyparse() );
|
|
|
|
yylex_destroy();
|
|
|
|
g_free(filename);
|
|
|
|
}
|
|
|
|
#endif
|