#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "theme.h"
#include "lexer/theme-parser.h"
#include "helper.h"
#include "settings.h"
#include "widgets/textbox.h"
#include "view.h"
#include "rofi.h"
/** Logging domain for theme */
#define LOG_DOMAIN "Theme"
void yyerror ( YYLTYPE *ylloc, const char *, const char * );
static gboolean distance_compare ( Distance d, Distance e )
{
return d.type == e.type && d.distance == e.distance && d.style == e.style;
}
ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *name )
{
for ( unsigned int i = 0; i < base->num_widgets; i++ ) {
if ( g_strcmp0 ( base->widgets[i]->name, name ) == 0 ) {
return base->widgets[i];
}
}
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];
retv->parent = base;
retv->name = g_strdup ( name );
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 );
}
else if ( p->type == P_LINK ) {
g_free ( p->value.link.name );
}
g_free ( p );
}
void rofi_theme_free ( ThemeWidget *widget )
{
if ( widget == NULL ) {
return;
}
if ( widget->properties ) {
g_hash_table_destroy ( widget->properties );
}
for ( unsigned int i = 0; i < widget->num_widgets; i++ ) {
rofi_theme_free ( widget->widgets[i] );
}
g_free ( widget->widgets );
g_free ( widget->name );
g_free ( widget );
}
/**
* print
*/
static void rofi_theme_print_distance ( Distance d )
{
if ( d.type == PW_PX ) {
printf ( "%upx ", (unsigned int) d.distance );
}
else if ( d.type == PW_PERCENT ) {
printf ( "%f%% ", d.distance );
}
else {
printf ( "%fem ", d.distance );
}
if ( d.style == DASH ) {
printf ( "dash " );
}
}
/** Textual representation of Window Location */
const char const * WindowLocationStr[9] = {
"center",
"northwest",
"north",
"northeast",
"east",
"southeast",
"south",
"southwest",
"west"
};
static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p )
{
int pl = strlen ( p->name );
printf ( "%*s%s:%*s ", depth, "", p->name, (int) pnl - pl, "" );
switch ( p->type )
{
case P_HIGHLIGHT:
if ( p->value