mirror of
https://github.com/lbonn/rofi
synced 2024-11-26 22:00:20 +00:00
Update to new theme
This commit is contained in:
parent
5fd76b75b1
commit
1dfac3c4da
11 changed files with 103 additions and 47 deletions
|
@ -1,6 +1,7 @@
|
||||||
#ifndef THEME_H
|
#ifndef THEME_H
|
||||||
#define THEME_H
|
#define THEME_H
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <cairo.h>
|
||||||
typedef enum {
|
typedef enum {
|
||||||
P_INTEGER,
|
P_INTEGER,
|
||||||
P_DOUBLE,
|
P_DOUBLE,
|
||||||
|
@ -65,4 +66,5 @@ 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 );
|
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 );
|
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 );
|
double rofi_theme_get_double ( const char *name, const char *property, double def );
|
||||||
|
void rofi_theme_get_color ( const char *name, const char *property, cairo_t *d);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,6 +32,7 @@ typedef enum
|
||||||
} boxType;
|
} boxType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param name The name of the widget.
|
||||||
* @param type The packing direction of the newly created box.
|
* @param type The packing direction of the newly created box.
|
||||||
* @param x The x position of the box relative to its parent.
|
* @param x The x position of the box relative to its parent.
|
||||||
* @param y The y position of the box relative to its parent.
|
* @param y The y position of the box relative to its parent.
|
||||||
|
@ -40,7 +41,7 @@ typedef enum
|
||||||
*
|
*
|
||||||
* @returns a newly created box, free with #widget_free
|
* @returns a newly created box, free with #widget_free
|
||||||
*/
|
*/
|
||||||
box * box_create ( boxType type, short x, short y, short w, short h );
|
box * box_create ( const char *name, boxType type, short x, short y, short w, short h );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param box Handle to the box widget.
|
* @param box Handle to the box widget.
|
||||||
|
@ -61,13 +62,5 @@ void box_add ( box *box, widget *child, gboolean expand, gboolean end );
|
||||||
* @returns the minimum size in pixels.
|
* @returns the minimum size in pixels.
|
||||||
*/
|
*/
|
||||||
int box_get_fixed_pixels ( box *box );
|
int box_get_fixed_pixels ( box *box );
|
||||||
|
|
||||||
/**
|
|
||||||
* @param box Handle to the box widget.
|
|
||||||
* @param padding The padding to apply.
|
|
||||||
*
|
|
||||||
* Set the padding to apply between the children in pixels.
|
|
||||||
*/
|
|
||||||
void box_set_padding ( box * box, unsigned int padding );
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
#endif // ROFI_HBOX_H
|
#endif // ROFI_HBOX_H
|
||||||
|
|
|
@ -37,6 +37,7 @@ typedef enum
|
||||||
} separator_line_style;
|
} separator_line_style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param name The name of the widget.
|
||||||
* @param type The type of separator.
|
* @param type The type of separator.
|
||||||
* @param sw The thickness of the separator.
|
* @param sw The thickness of the separator.
|
||||||
*
|
*
|
||||||
|
@ -44,22 +45,7 @@ typedef enum
|
||||||
*
|
*
|
||||||
* @returns a new separator, free with ::widget_free
|
* @returns a new separator, free with ::widget_free
|
||||||
*/
|
*/
|
||||||
separator *separator_create ( separator_type type, short sw );
|
separator *separator_create ( const char *name, separator_type type, short sw );
|
||||||
|
|
||||||
/**
|
|
||||||
* @param sp The separator widget handle.
|
|
||||||
* @param style_str String representation of the style.
|
|
||||||
*
|
|
||||||
* Sets the line style based on the string style_str
|
|
||||||
*/
|
|
||||||
void separator_set_line_style_from_string ( separator *sp, const char *style_str );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param sp The separator widget handle.
|
|
||||||
* @param style The new style.
|
|
||||||
*
|
|
||||||
* Sets the line style.
|
|
||||||
*/
|
|
||||||
void separator_set_line_style ( separator *sp, separator_line_style style );
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
#endif // ROFI_SEPARATOR_H
|
#endif // ROFI_SEPARATOR_H
|
||||||
|
|
|
@ -45,5 +45,8 @@ struct _widget
|
||||||
|
|
||||||
/** Free widget callback */
|
/** Free widget callback */
|
||||||
void ( *free )( struct _widget *widget );
|
void ( *free )( struct _widget *widget );
|
||||||
|
|
||||||
|
/** Name of widget (used for theming) */
|
||||||
|
char *name;
|
||||||
};
|
};
|
||||||
#endif // WIDGET_INTERNAL_H
|
#endif // WIDGET_INTERNAL_H
|
||||||
|
|
|
@ -173,5 +173,8 @@ void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata
|
||||||
* returns TRUE when handled.
|
* returns TRUE when handled.
|
||||||
*/
|
*/
|
||||||
gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
|
gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
|
||||||
|
|
||||||
|
|
||||||
|
void widget_set_name ( widget *wid, const char *name );
|
||||||
/*@}*/
|
/*@}*/
|
||||||
#endif // ROFI_WIDGET_H
|
#endif // ROFI_WIDGET_H
|
||||||
|
|
|
@ -24,14 +24,23 @@ int yylex(void);
|
||||||
(true|false) { yylval.bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
|
(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 N_STRING;}
|
||||||
\"[_\-a-zA-Z0-9 \t]+\" { yytext[yyleng-1] = '\0'; yylval.sval = g_strdup(&yytext[1]); return T_STRING;}
|
\"[_\-a-zA-Z0-9 \t]+\" { yytext[yyleng-1] = '\0'; yylval.sval = g_strdup(&yytext[1]); return T_STRING;}
|
||||||
#[0-9A-Fa-f]+ {
|
#[0-9A-Fa-f]{8} {
|
||||||
union { unsigned int val; struct { unsigned char a,r,g,b;};} val;
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
||||||
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
|
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
|
||||||
yylval.colorval.alpha = val.a/255.0;
|
yylval.colorval.alpha = val.a/255.0;
|
||||||
yylval.colorval.red = val.r/255.0;
|
yylval.colorval.red = val.r/255.0;
|
||||||
yylval.colorval.green = val.g/255.0;
|
yylval.colorval.green = val.g/255.0;
|
||||||
yylval.colorval.blue = val.b/255.0;
|
yylval.colorval.blue = val.b/255.0;
|
||||||
return T_COLOR;
|
return T_COLOR;
|
||||||
|
}
|
||||||
|
#[0-9A-Fa-f]{6} {
|
||||||
|
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
|
||||||
|
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
|
||||||
|
yylval.colorval.alpha = 1.0;
|
||||||
|
yylval.colorval.red = val.r/255.0;
|
||||||
|
yylval.colorval.green = val.g/255.0;
|
||||||
|
yylval.colorval.blue = val.b/255.0;
|
||||||
|
return T_COLOR;
|
||||||
}
|
}
|
||||||
[\r\n]+ ;
|
[\r\n]+ ;
|
||||||
|
|
||||||
|
|
|
@ -217,3 +217,20 @@ double rofi_theme_get_double ( const char *name, const char *property, double d
|
||||||
}
|
}
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
void rofi_theme_get_color ( const char *name, const char *property, cairo_t *d)
|
||||||
|
{
|
||||||
|
if ( rofi_theme == NULL ) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
Widget *widget = rofi_theme_find ( name );
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -780,15 +780,18 @@ void rofi_view_update ( RofiViewState *state )
|
||||||
cairo_paint ( d );
|
cairo_paint ( d );
|
||||||
cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
|
cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
|
||||||
color_background ( d );
|
color_background ( d );
|
||||||
|
rofi_theme_get_color ( "window" , "background", d );
|
||||||
cairo_paint ( d );
|
cairo_paint ( d );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Paint the background.
|
// Paint the background.
|
||||||
color_background ( d );
|
color_background ( d );
|
||||||
|
rofi_theme_get_color ( "window" , "background", d );
|
||||||
cairo_paint ( d );
|
cairo_paint ( d );
|
||||||
}
|
}
|
||||||
TICK_N ( "Background" );
|
TICK_N ( "Background" );
|
||||||
color_border ( d );
|
color_border ( d );
|
||||||
|
rofi_theme_get_color ( "window" , "foreground", d );
|
||||||
|
|
||||||
if ( config.menu_bw > 0 ) {
|
if ( config.menu_bw > 0 ) {
|
||||||
cairo_save ( d );
|
cairo_save ( d );
|
||||||
|
@ -1428,26 +1431,21 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
||||||
// Get active monitor size.
|
// Get active monitor size.
|
||||||
TICK_N ( "Get active monitor" );
|
TICK_N ( "Get active monitor" );
|
||||||
|
|
||||||
state->main_box = box_create ( BOX_VERTICAL,
|
state->main_box = box_create ( "box.mainbox", BOX_VERTICAL,
|
||||||
state->border, state->border,
|
state->border, state->border,
|
||||||
state->width - 2 * state->border, state->height - 2 * state->border );
|
state->width - 2 * state->border, state->height - 2 * state->border );
|
||||||
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.
|
// we need this at this point so we can get height.
|
||||||
unsigned int line_height = textbox_get_estimated_char_height ();
|
unsigned int line_height = textbox_get_estimated_char_height ();
|
||||||
rofi_view_calculate_window_and_element_width ( state );
|
rofi_view_calculate_window_and_element_width ( state );
|
||||||
|
|
||||||
state->input_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height );
|
state->input_bar = box_create ( "box.inputbar", BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height );
|
||||||
state->input_bar_separator = separator_create ( S_HORIZONTAL, 2 );
|
state->input_bar_separator = separator_create ( "separator.inputbar", S_HORIZONTAL, 2 );
|
||||||
separator_set_line_style_from_string ( state->input_bar_separator, config.separator_style );
|
|
||||||
|
|
||||||
|
|
||||||
// Only enable widget when sidebar is enabled.
|
// Only enable widget when sidebar is enabled.
|
||||||
if ( config.sidebar_mode ) {
|
if ( config.sidebar_mode ) {
|
||||||
state->sidebar_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height );
|
state->sidebar_bar = box_create ( "box.sidebar", BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height );
|
||||||
box_set_padding ( state->sidebar_bar, rofi_theme_get_integer ( "box.sidebar", "padding",config.line_margin ) );
|
separator *sep = separator_create ( "separator.sidebar", S_HORIZONTAL, 2 );
|
||||||
separator *sep = separator_create ( S_HORIZONTAL, 2 );
|
|
||||||
separator_set_line_style_from_string ( sep, config.separator_style );
|
|
||||||
box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE );
|
box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE );
|
||||||
box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE );
|
box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE );
|
||||||
state->num_modi = rofi_get_num_enabled_modi ();
|
state->num_modi = rofi_get_num_enabled_modi ();
|
||||||
|
@ -1484,10 +1482,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
||||||
if ( message ) {
|
if ( message ) {
|
||||||
textbox *message_tb = textbox_create ( TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
|
textbox *message_tb = textbox_create ( TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
|
||||||
state->width - ( 2 * ( state->border ) ), -1, NORMAL, message );
|
state->width - ( 2 * ( state->border ) ), -1, NORMAL, message );
|
||||||
separator *sep = separator_create ( S_HORIZONTAL, 2 );
|
separator *sep = separator_create ( "separator", S_HORIZONTAL, 2 );
|
||||||
box_add ( state->main_box, WIDGET ( sep ), FALSE, end);
|
box_add ( state->main_box, WIDGET ( sep ), FALSE, end);
|
||||||
box_add ( state->main_box, WIDGET ( message_tb ), FALSE, end);
|
box_add ( state->main_box, WIDGET ( message_tb ), FALSE, end);
|
||||||
separator_set_line_style_from_string ( sep, config.separator_style );
|
|
||||||
}
|
}
|
||||||
box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, end );
|
box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, end );
|
||||||
|
|
||||||
|
@ -1553,7 +1550,7 @@ int rofi_view_error_dialog ( const char *msg, int markup )
|
||||||
state->finalize = process_result;
|
state->finalize = process_result;
|
||||||
|
|
||||||
rofi_view_calculate_window_and_element_width ( state );
|
rofi_view_calculate_window_and_element_width ( state );
|
||||||
state->main_box = box_create ( BOX_VERTICAL,
|
state->main_box = box_create ( "box.mainbox", BOX_VERTICAL,
|
||||||
state->border, state->border,
|
state->border, state->border,
|
||||||
state->width - 2 * state->border, state->height - 2 * state->border );
|
state->width - 2 * state->border, state->height - 2 * state->border );
|
||||||
state->text = textbox_create ( ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
state->text = textbox_create ( ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||||
|
|
|
@ -29,9 +29,19 @@
|
||||||
#include "widgets/widget.h"
|
#include "widgets/widget.h"
|
||||||
#include "widgets/widget-internal.h"
|
#include "widgets/widget-internal.h"
|
||||||
#include "widgets/box.h"
|
#include "widgets/box.h"
|
||||||
|
#include "theme.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
#define LOG_DOMAIN "Widgets.Box"
|
#define LOG_DOMAIN "Widgets.Box"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param box Handle to the box widget.
|
||||||
|
* @param padding The padding to apply.
|
||||||
|
*
|
||||||
|
* Set the padding to apply between the children in pixels.
|
||||||
|
*/
|
||||||
|
void box_set_padding ( box * box, unsigned int padding );
|
||||||
|
|
||||||
struct _box
|
struct _box
|
||||||
{
|
{
|
||||||
widget widget;
|
widget widget;
|
||||||
|
@ -263,10 +273,11 @@ static gboolean box_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
box * box_create ( boxType type, short x, short y, short w, short h )
|
box * box_create ( const char *name, boxType type, short x, short y, short w, short h )
|
||||||
{
|
{
|
||||||
box *b = g_malloc0 ( sizeof ( box ) );
|
box *b = g_malloc0 ( sizeof ( box ) );
|
||||||
b->type = type;
|
b->type = type;
|
||||||
|
b->widget.name = g_strdup (name);
|
||||||
b->widget.x = x;
|
b->widget.x = x;
|
||||||
b->widget.y = y;
|
b->widget.y = y;
|
||||||
b->widget.w = w;
|
b->widget.w = w;
|
||||||
|
@ -279,6 +290,7 @@ box * box_create ( boxType type, short x, short y, short w, short h )
|
||||||
b->widget.motion_notify = box_motion_notify;
|
b->widget.motion_notify = box_motion_notify;
|
||||||
b->widget.enabled = TRUE;
|
b->widget.enabled = TRUE;
|
||||||
|
|
||||||
|
box_set_padding ( b, rofi_theme_get_integer ( b->widget.name, "padding",config.line_margin ));
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,23 @@
|
||||||
#include "widgets/separator.h"
|
#include "widgets/separator.h"
|
||||||
#include "x11-helper.h"
|
#include "x11-helper.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "theme.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sp The separator widget handle.
|
||||||
|
* @param style_str String representation of the style.
|
||||||
|
*
|
||||||
|
* Sets the line style based on the string style_str
|
||||||
|
*/
|
||||||
|
void separator_set_line_style_from_string ( separator *sp, const char *style_str );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sp The separator widget handle.
|
||||||
|
* @param style The new style.
|
||||||
|
*
|
||||||
|
* Sets the line style.
|
||||||
|
*/
|
||||||
|
void separator_set_line_style ( separator *sp, separator_line_style style );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal structure for the separator.
|
* Internal structure for the separator.
|
||||||
|
@ -49,11 +66,11 @@ const char *const _separator_style_dash = "dash";
|
||||||
static void separator_draw ( widget *, cairo_t * );
|
static void separator_draw ( widget *, cairo_t * );
|
||||||
static void separator_free ( widget * );
|
static void separator_free ( widget * );
|
||||||
|
|
||||||
separator *separator_create ( separator_type type, short sw )
|
separator *separator_create ( const char *name, separator_type type, short sw )
|
||||||
{
|
{
|
||||||
separator *sb = g_malloc0 ( sizeof ( separator ) );
|
separator *sb = g_malloc0 ( sizeof ( separator ) );
|
||||||
sb->type = type;
|
sb->type = type;
|
||||||
|
sb->widget.name = g_strdup ( name );
|
||||||
sb->widget.x = 0;
|
sb->widget.x = 0;
|
||||||
sb->widget.y = 0;
|
sb->widget.y = 0;
|
||||||
if ( sb->type == S_HORIZONTAL ) {
|
if ( sb->type == S_HORIZONTAL ) {
|
||||||
|
@ -70,6 +87,9 @@ separator *separator_create ( separator_type type, short sw )
|
||||||
|
|
||||||
// Enabled by default
|
// Enabled by default
|
||||||
sb->widget.enabled = TRUE;
|
sb->widget.enabled = TRUE;
|
||||||
|
|
||||||
|
const char *line_style = rofi_theme_get_string ( sb->widget.name, "line-style", "solid");
|
||||||
|
separator_set_line_style_from_string ( sb, line_style );
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +129,7 @@ static void separator_draw ( widget *wid, cairo_t *draw )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
color_separator ( draw );
|
color_separator ( draw );
|
||||||
|
rofi_theme_get_color ( wid->name, "foreground", draw );
|
||||||
if ( sep->line_style == S_LINE_DASH ) {
|
if ( sep->line_style == S_LINE_DASH ) {
|
||||||
const double dashes[1] = { 4 };
|
const double dashes[1] = { 4 };
|
||||||
cairo_set_dash ( draw, dashes, 1, 0.0 );
|
cairo_set_dash ( draw, dashes, 1, 0.0 );
|
||||||
|
|
|
@ -68,9 +68,14 @@ void widget_draw ( widget *widget, cairo_t *d )
|
||||||
}
|
}
|
||||||
void widget_free ( widget *wid )
|
void widget_free ( widget *wid )
|
||||||
{
|
{
|
||||||
if ( wid && wid->free ) {
|
if ( wid ) {
|
||||||
|
if ( wid->name ) {
|
||||||
|
g_free ( wid->name );
|
||||||
|
}
|
||||||
|
if ( wid->free ) {
|
||||||
wid->free ( wid );
|
wid->free ( wid );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int widget_get_height ( widget *widget )
|
int widget_get_height ( widget *widget )
|
||||||
|
@ -163,3 +168,11 @@ gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void widget_set_name ( widget *wid, const char *name )
|
||||||
|
{
|
||||||
|
if ( wid->name ) {
|
||||||
|
g_free(wid);
|
||||||
|
}
|
||||||
|
wid->name = g_strdup ( name );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue