mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Support converting old theme internally, add first option to dump theme
This commit is contained in:
parent
05871703d5
commit
d35e70d817
4 changed files with 210 additions and 23 deletions
|
@ -95,4 +95,5 @@ void rofi_theme_get_color ( const char *wclass, const char *name, const char *s
|
|||
Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad );
|
||||
|
||||
int distance_get_pixel ( Distance d );
|
||||
void rofi_theme_convert_old_theme ( void );
|
||||
#endif
|
||||
|
|
|
@ -80,7 +80,7 @@ entries:
|
|||
%empty {
|
||||
// There is always a base widget.
|
||||
$$ = rofi_theme = (Widget*)g_malloc0 (sizeof(Widget));
|
||||
rofi_theme->name = g_strdup ( "Window" );
|
||||
rofi_theme->name = g_strdup ( "Root" );
|
||||
}
|
||||
| entries
|
||||
optional_properties
|
||||
|
|
|
@ -905,8 +905,14 @@ int main ( int argc, char *argv[] )
|
|||
TICK_N ( "Parse theme" );
|
||||
rofi_theme_parse_file ( config.theme );
|
||||
TICK_N ( "Parsed theme" );
|
||||
} else {
|
||||
rofi_theme_convert_old_theme ( );
|
||||
}
|
||||
|
||||
if ( find_arg ( "-dump-theme" ) >= 0 ){
|
||||
rofi_theme_print ( rofi_theme );
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
// Dump.
|
||||
// catch help request
|
||||
if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) {
|
||||
|
|
224
source/theme.c
224
source/theme.c
|
@ -5,6 +5,7 @@
|
|||
#include "theme.h"
|
||||
#include "lexer/theme-parser.h"
|
||||
#include "helper.h"
|
||||
#include "settings.h"
|
||||
#include "widgets/textbox.h"
|
||||
|
||||
void yyerror ( YYLTYPE *ylloc, const char *);
|
||||
|
@ -67,64 +68,105 @@ void rofi_theme_free ( Widget *widget )
|
|||
*/
|
||||
static void rofi_theme_print_property_index ( int depth, Property *p )
|
||||
{
|
||||
printf("%*s %s: ", depth, "", p->name );
|
||||
printf("%*s%s: ", depth, "", p->name );
|
||||
switch ( p->type )
|
||||
{
|
||||
case P_STRING:
|
||||
printf("\"%s\"", p->value.s);
|
||||
printf("\"%s\";", p->value.s);
|
||||
break;
|
||||
case P_INTEGER:
|
||||
printf("%d", p->value.i);
|
||||
printf("%d;", p->value.i);
|
||||
break;
|
||||
case P_DOUBLE:
|
||||
printf("%.2f", p->value.f);
|
||||
printf("%.2f;", p->value.f);
|
||||
break;
|
||||
case P_BOOLEAN:
|
||||
printf("%s", p->value.b?"true":"false");
|
||||
printf("%s;", p->value.b?"true":"false");
|
||||
break;
|
||||
case P_COLOR:
|
||||
printf("#%02X%02X%02X%02X",
|
||||
printf("#%02X%02X%02X%02X;",
|
||||
(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));
|
||||
break;
|
||||
case P_PADDING:
|
||||
printf("%f%s %f%s %f%s %f%s",
|
||||
p->value.padding.left.distance,
|
||||
p->value.padding.left.type == PW_PX? "px":"em",
|
||||
p->value.padding.right.distance,
|
||||
p->value.padding.right.type == PW_PX? "px":"em",
|
||||
p->value.padding.top.distance,
|
||||
p->value.padding.top.type == PW_PX? "px":"em",
|
||||
p->value.padding.bottom.distance,
|
||||
p->value.padding.bottom.type == PW_PX? "px":"em"
|
||||
);
|
||||
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");
|
||||
}
|
||||
putchar ( '\n' );
|
||||
}
|
||||
|
||||
static void rofi_theme_print_index ( int depth, Widget *widget )
|
||||
static void rofi_theme_print_index ( Widget *widget )
|
||||
{
|
||||
printf ( "%*sName: %s \n", depth, "", widget->name );
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
if ( widget->properties ){
|
||||
int index = 0;
|
||||
GList *list = NULL;
|
||||
Widget *w = widget;
|
||||
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");
|
||||
}
|
||||
g_hash_table_iter_init (&iter, widget->properties);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
Property *p = (Property*)value;
|
||||
rofi_theme_print_property_index ( depth, p );
|
||||
rofi_theme_print_property_index ( index, p );
|
||||
}
|
||||
if ( g_list_length ( list ) > 0 ) {
|
||||
printf("}\n");
|
||||
}
|
||||
g_list_free ( list );
|
||||
}
|
||||
for ( unsigned int i = 0; i < widget->num_widgets;i++){
|
||||
rofi_theme_print_index ( depth+2, widget->widgets[i] );
|
||||
rofi_theme_print_index ( widget->widgets[i] );
|
||||
}
|
||||
}
|
||||
void rofi_theme_print ( Widget *widget )
|
||||
{
|
||||
rofi_theme_print_index ( 0, widget);
|
||||
rofi_theme_print_index ( widget );
|
||||
}
|
||||
|
||||
int yyparse();
|
||||
|
@ -332,3 +374,141 @@ int distance_get_pixel ( Distance d )
|
|||
}
|
||||
return d.distance;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
rofi_theme = (Widget*)g_malloc0 ( sizeof ( Widget ) );
|
||||
rofi_theme->name = g_strdup ( "Root" );
|
||||
rofi_theme->properties = rofi_theme_convert_create_property_ht ( );
|
||||
{
|
||||
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 );
|
||||
p = rofi_theme_property_create ( P_INTEGER );
|
||||
p->name = g_strdup("padding");
|
||||
p->value.i = config.padding;
|
||||
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 ) {
|
||||
Widget *widget = rofi_theme_find_or_create_class ( rofi_theme , "@separator" );
|
||||
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;
|
||||
Widget *widget = rofi_theme_find_or_create_class ( rofi_theme , "@textbox" );
|
||||
|
||||
Widget *wnormal = rofi_theme_find_or_create_class ( widget, "normal" );
|
||||
Widget *wselected = rofi_theme_find_or_create_class ( widget, "selected" );
|
||||
Widget *walternate = rofi_theme_find_or_create_class ( widget, "alternate" );
|
||||
|
||||
|
||||
gchar **vals = g_strsplit ( config.color_normal, ",", 5 );
|
||||
if ( g_strv_length (vals) == 5 ) {
|
||||
Widget *wnn = rofi_theme_find_or_create_class ( wnormal, "normal" );
|
||||
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 );
|
||||
|
||||
Widget *wsl = rofi_theme_find_or_create_class ( wselected, "normal" );
|
||||
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 );
|
||||
|
||||
Widget *wal = rofi_theme_find_or_create_class ( walternate, "normal" );
|
||||
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 ) {
|
||||
Widget *wnn = rofi_theme_find_or_create_class ( wnormal, "urgent" );
|
||||
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 );
|
||||
|
||||
Widget *wsl = rofi_theme_find_or_create_class ( wselected, "urgent" );
|
||||
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 );
|
||||
|
||||
Widget *wal = rofi_theme_find_or_create_class ( walternate, "urgent" );
|
||||
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 ) {
|
||||
Widget *wnn = rofi_theme_find_or_create_class ( wnormal, "active" );
|
||||
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 );
|
||||
|
||||
Widget *wsl = rofi_theme_find_or_create_class ( wselected, "active" );
|
||||
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 );
|
||||
|
||||
Widget *wal = rofi_theme_find_or_create_class ( walternate, "active" );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue