mirror of
https://github.com/lbonn/rofi
synced 2024-11-23 12:23:02 +00:00
First start at adding 4 sided padding
This commit is contained in:
parent
c5439118a7
commit
1c611b0eec
11 changed files with 178 additions and 78 deletions
|
@ -136,7 +136,12 @@ The following properties are currently supports:
|
||||||
* background: color
|
* background: color
|
||||||
* foreground: color
|
* foreground: color
|
||||||
* border-width: integer
|
* border-width: integer
|
||||||
|
* spacing: integer
|
||||||
* padding: integer
|
* padding: integer
|
||||||
|
* padding-left: integer
|
||||||
|
* padding-right: integer
|
||||||
|
* padding-top: integer
|
||||||
|
* padding-bottom: integer
|
||||||
* transparency: string
|
* transparency: string
|
||||||
- real
|
- real
|
||||||
- background
|
- background
|
||||||
|
@ -151,14 +156,19 @@ The following properties are currently supports:
|
||||||
* foreground: color
|
* foreground: color
|
||||||
|
|
||||||
* box
|
* box
|
||||||
|
* spacing: integer
|
||||||
* padding: integer
|
* padding: integer
|
||||||
|
* padding-left: integer
|
||||||
|
* padding-right: integer
|
||||||
|
* padding-top: integer
|
||||||
|
* padding-bottom: integer
|
||||||
|
|
||||||
* textbox:
|
* textbox:
|
||||||
* background: color
|
* background: color
|
||||||
* foreground: color
|
* foreground: color
|
||||||
|
|
||||||
* listview:
|
* listview:
|
||||||
* padding: integer
|
* spacing: integer
|
||||||
* lines: integer
|
* lines: integer
|
||||||
* columns: integer
|
* columns: integer
|
||||||
* fixed-height: boolean
|
* fixed-height: boolean
|
||||||
|
|
|
@ -22,6 +22,15 @@ typedef struct
|
||||||
double alpha;
|
double alpha;
|
||||||
} ThemeColor;
|
} ThemeColor;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int left;
|
||||||
|
int right;
|
||||||
|
int top;
|
||||||
|
int bottom;
|
||||||
|
gboolean percentual;
|
||||||
|
} Padding;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
PropertyType type;
|
PropertyType type;
|
||||||
|
@ -69,4 +78,5 @@ int rofi_theme_get_boolean ( const char *wclass, const char *name, const char
|
||||||
char *rofi_theme_get_string ( const char *wclass, const char *name, const char *state, const char *property, char *def );
|
char *rofi_theme_get_string ( const char *wclass, const char *name, const char *state, const char *property, char *def );
|
||||||
double rofi_theme_get_double ( const char *wclass, const char *name, const char *state, const char *property, double def );
|
double rofi_theme_get_double ( const char *wclass, const char *name, const char *state, const char *property, double def );
|
||||||
void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d);
|
void rofi_theme_get_color ( const char *wclass, const char *name, const char *state, const char *property, cairo_t *d);
|
||||||
|
Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "widgets/box.h"
|
#include "widgets/box.h"
|
||||||
#include "keyb.h"
|
#include "keyb.h"
|
||||||
#include "x11-helper.h"
|
#include "x11-helper.h"
|
||||||
|
#include "theme.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup ViewHandle
|
* @ingroup ViewHandle
|
||||||
|
@ -65,6 +66,7 @@ struct RofiViewState
|
||||||
MenuReturn retv;
|
MenuReturn retv;
|
||||||
/** Calculated border width */
|
/** Calculated border width */
|
||||||
unsigned int border;
|
unsigned int border;
|
||||||
|
Padding pad;
|
||||||
/** Monitor #workarea the view is displayed on */
|
/** Monitor #workarea the view is displayed on */
|
||||||
workarea mon;
|
workarea mon;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ void box_add ( box *box, widget *child, gboolean expand, gboolean end );
|
||||||
* @param box Handle to the box widget.
|
* @param box Handle to the box widget.
|
||||||
*
|
*
|
||||||
* Obtains the minimal size required to display all widgets. (expanding widgets are not counted, except for their
|
* Obtains the minimal size required to display all widgets. (expanding widgets are not counted, except for their
|
||||||
* padding)
|
* spacing)
|
||||||
*
|
*
|
||||||
* @returns the minimum size in pixels.
|
* @returns the minimum size in pixels.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef WIDGET_INTERNAL_H
|
#ifndef WIDGET_INTERNAL_H
|
||||||
#define WIDGET_INTERNAL_H
|
#define WIDGET_INTERNAL_H
|
||||||
|
|
||||||
|
#include "theme.h"
|
||||||
/**
|
/**
|
||||||
* Data structure holding the internal state of the Widget
|
* Data structure holding the internal state of the Widget
|
||||||
*/
|
*/
|
||||||
|
@ -14,6 +15,8 @@ struct _widget
|
||||||
short w;
|
short w;
|
||||||
/** Height of the widget */
|
/** Height of the widget */
|
||||||
short h;
|
short h;
|
||||||
|
/** Padding */
|
||||||
|
Padding pad;
|
||||||
/** enabled or not */
|
/** enabled or not */
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
/** Expand the widget when packed */
|
/** Expand the widget when packed */
|
||||||
|
@ -48,5 +51,8 @@ struct _widget
|
||||||
|
|
||||||
/** Name of widget (used for theming) */
|
/** Name of widget (used for theming) */
|
||||||
char *name;
|
char *name;
|
||||||
|
char *class_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void widget_init ( widget *widget , const char *name, const char *class_name );
|
||||||
#endif // WIDGET_INTERNAL_H
|
#endif // WIDGET_INTERNAL_H
|
||||||
|
|
|
@ -278,3 +278,38 @@ 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 )
|
||||||
|
{
|
||||||
|
Widget *widget = rofi_theme_find_widget ( wclass, name, state );
|
||||||
|
Property *p = rofi_theme_find_property ( widget, P_INTEGER, property );
|
||||||
|
if ( p ){
|
||||||
|
pad.left = pad.top = pad.bottom = pad.right = p->value.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *s = g_strdup_printf("%s-top", property);
|
||||||
|
p = rofi_theme_find_property ( widget, P_INTEGER, s );
|
||||||
|
if ( p ){
|
||||||
|
pad.top = p->value.i;
|
||||||
|
}
|
||||||
|
g_free(s);
|
||||||
|
s = g_strdup_printf("%s-left", property);
|
||||||
|
p = rofi_theme_find_property ( widget, P_INTEGER, s );
|
||||||
|
if ( p ){
|
||||||
|
pad.left = p->value.i;
|
||||||
|
}
|
||||||
|
g_free(s);
|
||||||
|
s = g_strdup_printf("%s-bottom", property);
|
||||||
|
p = rofi_theme_find_property ( widget, P_INTEGER, s );
|
||||||
|
if ( p ){
|
||||||
|
pad.bottom = p->value.i;
|
||||||
|
}
|
||||||
|
g_free(s);
|
||||||
|
s = g_strdup_printf("%s-right", property);
|
||||||
|
p = rofi_theme_find_property ( widget, P_INTEGER, s );
|
||||||
|
if ( p ){
|
||||||
|
pad.right = p->value.i;
|
||||||
|
}
|
||||||
|
g_free(s);
|
||||||
|
|
||||||
|
return pad;
|
||||||
|
}
|
||||||
|
|
|
@ -296,7 +296,11 @@ static void rofi_view_window_update_size ( RofiViewState * state )
|
||||||
|
|
||||||
CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
|
CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
|
||||||
CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
|
CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
|
||||||
widget_resize ( WIDGET ( state->main_box ), state->width - 2 * state->border, state->height - 2 * state->border );
|
|
||||||
|
// Should wrap main window in a widget.
|
||||||
|
int width = state->width - 2*state->border - state->pad.left - state->pad.right;
|
||||||
|
int height = state->height - 2*state->border - state->pad.top- state->pad.bottom;
|
||||||
|
widget_resize ( WIDGET ( state->main_box ), width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data )
|
static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data )
|
||||||
|
@ -1274,7 +1278,9 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *ev, xkb_st
|
||||||
|
|
||||||
CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
|
CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
|
||||||
CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
|
CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
|
||||||
widget_resize ( WIDGET ( state->main_box ), state->width - 2 * state->border, state->height - 2 * state->border );
|
int width = state->width - 2*state->border - state->pad.left - state->pad.right;
|
||||||
|
int height = state->height - 2*state->border - state->pad.top- state->pad.bottom;
|
||||||
|
widget_resize ( WIDGET ( state->main_box ), width, height );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1377,7 +1383,7 @@ static int rofi_view_calculate_height ( RofiViewState *state )
|
||||||
}
|
}
|
||||||
height = listview_get_desired_height ( state->list_view );
|
height = listview_get_desired_height ( state->list_view );
|
||||||
height += box_get_fixed_pixels ( state->main_box );
|
height += box_get_fixed_pixels ( state->main_box );
|
||||||
height += 2 * state->border;
|
height += 2 * state->border +state->pad.top+state->pad.bottom;
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1430,7 +1436,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
||||||
state->finalize = finalize;
|
state->finalize = finalize;
|
||||||
state->mouse_seen = FALSE;
|
state->mouse_seen = FALSE;
|
||||||
|
|
||||||
state->border = rofi_theme_get_integer ("@window", "window", NULL, "padding" , config.padding );
|
state->pad = (Padding){config.padding,config.padding, config.padding, config.padding, FALSE};
|
||||||
|
state->pad = rofi_theme_get_padding ( "@window", "window", NULL, "padding", state->pad);
|
||||||
|
//state->border = rofi_theme_get_integer ("@window", "window", NULL, "padding" , config.padding );
|
||||||
state->border += rofi_theme_get_integer ("@window", "window", NULL, "border-width" , config.menu_bw);
|
state->border += rofi_theme_get_integer ("@window", "window", NULL, "border-width" , config.menu_bw);
|
||||||
|
|
||||||
// Request the lines to show.
|
// Request the lines to show.
|
||||||
|
@ -1441,20 +1449,22 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
||||||
// Get active monitor size.
|
// Get active monitor size.
|
||||||
TICK_N ( "Get active monitor" );
|
TICK_N ( "Get active monitor" );
|
||||||
|
|
||||||
|
int total_width = state->width - 2*state->border - state->pad.left - state->pad.right;
|
||||||
|
int total_height = state->height - 2*state->border - state->pad.top- state->pad.bottom;
|
||||||
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
|
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
|
||||||
state->border, state->border,
|
state->border+state->pad.left, state->border+state->pad.top,
|
||||||
state->width - 2 * state->border, state->height - 2 * state->border );
|
total_width, total_height);
|
||||||
|
|
||||||
// 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 ( "inputbar.box", BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height );
|
state->input_bar = box_create ( "inputbar.box", BOX_HORIZONTAL, 0, 0, total_width, line_height );
|
||||||
state->input_bar_separator = separator_create ( "inputbar.separator", S_HORIZONTAL, 2 );
|
state->input_bar_separator = separator_create ( "inputbar.separator", S_HORIZONTAL, 2 );
|
||||||
|
|
||||||
// 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 ( "sidebar.box", BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height );
|
state->sidebar_bar = box_create ( "sidebar.box", BOX_HORIZONTAL, 0, 0, total_width, line_height );
|
||||||
separator *sep = separator_create ( "sidebar.separator", S_HORIZONTAL, 2 );
|
separator *sep = separator_create ( "sidebar.separator", S_HORIZONTAL, 2 );
|
||||||
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 );
|
||||||
|
@ -1491,7 +1501,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
||||||
textbox_text ( state->case_indicator, get_matching_state () );
|
textbox_text ( state->case_indicator, get_matching_state () );
|
||||||
if ( message ) {
|
if ( message ) {
|
||||||
textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
|
textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
|
||||||
state->width - ( 2 * ( state->border ) ), -1, NORMAL, message );
|
total_width, -1, NORMAL, message );
|
||||||
separator *sep = separator_create ( "message.separator", S_HORIZONTAL, 2 );
|
separator *sep = separator_create ( "message.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);
|
||||||
|
@ -1550,21 +1560,26 @@ int rofi_view_error_dialog ( const char *msg, int markup )
|
||||||
state->retv = MENU_CANCEL;
|
state->retv = MENU_CANCEL;
|
||||||
state->menu_flags = MENU_ERROR_DIALOG;
|
state->menu_flags = MENU_ERROR_DIALOG;
|
||||||
state->finalize = process_result;
|
state->finalize = process_result;
|
||||||
state->border = rofi_theme_get_integer ( "@window", "window", NULL, "padding" , config.padding );
|
state->pad = (Padding){config.padding,config.padding, config.padding, config.padding, FALSE};
|
||||||
|
state->pad = rofi_theme_get_padding ( "@window", "window", NULL, "padding", state->pad);
|
||||||
|
// state->border = rofi_theme_get_integer ( "@window", "window", NULL, "padding" , config.padding );
|
||||||
state->border += rofi_theme_get_integer ( "@window", "window", NULL, "border-width" , config.menu_bw);
|
state->border += rofi_theme_get_integer ( "@window", "window", NULL, "border-width" , config.menu_bw);
|
||||||
|
|
||||||
|
int total_width = state->width - 2*state->border - state->pad.left - state->pad.right;
|
||||||
|
int total_height = state->height - 2*state->border - state->pad.top- state->pad.bottom;
|
||||||
|
|
||||||
rofi_view_calculate_window_and_element_width ( state );
|
rofi_view_calculate_window_and_element_width ( state );
|
||||||
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
|
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL,
|
||||||
state->border, state->border,
|
state->border, state->border,
|
||||||
state->width - 2 * state->border, state->height - 2 * state->border );
|
total_width, total_height );
|
||||||
state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||||
( state->border ), ( state->border ),
|
( state->border+state->pad.left ), ( state->border+state->pad.top ),
|
||||||
( state->width - ( 2 * ( state->border ) ) ), 1, NORMAL, ( msg != NULL ) ? msg : "" );
|
total_width, 1, NORMAL, ( msg != NULL ) ? msg : "" );
|
||||||
box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE );
|
box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE );
|
||||||
unsigned int line_height = textbox_get_height ( state->text );
|
unsigned int line_height = textbox_get_height ( state->text );
|
||||||
|
|
||||||
// resize window vertically to suit
|
// resize window vertically to suit
|
||||||
state->height = line_height + ( state->border ) * 2;
|
state->height = line_height + ( state->border ) * 2+state->pad.top+state->pad.bottom;
|
||||||
|
|
||||||
// Calculte window position.
|
// Calculte window position.
|
||||||
rofi_view_calculate_window_position ( state );
|
rofi_view_calculate_window_position ( state );
|
||||||
|
|
|
@ -33,14 +33,15 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#define LOG_DOMAIN "Widgets.Box"
|
#define LOG_DOMAIN "Widgets.Box"
|
||||||
|
const char *BOX_CLASS_NAME = "@box";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param box Handle to the box widget.
|
* @param box Handle to the box widget.
|
||||||
* @param padding The padding to apply.
|
* @param spacing The spacing to apply.
|
||||||
*
|
*
|
||||||
* Set the padding to apply between the children in pixels.
|
* Set the spacing to apply between the children in pixels.
|
||||||
*/
|
*/
|
||||||
void box_set_padding ( box * box, unsigned int padding );
|
void box_set_spacing ( box * box, unsigned int spacing );
|
||||||
|
|
||||||
struct _box
|
struct _box
|
||||||
{
|
{
|
||||||
|
@ -48,7 +49,7 @@ struct _box
|
||||||
boxType type;
|
boxType type;
|
||||||
int max_size;
|
int max_size;
|
||||||
// Padding between elements
|
// Padding between elements
|
||||||
int padding;
|
int spacing;
|
||||||
|
|
||||||
GList *children;
|
GList *children;
|
||||||
};
|
};
|
||||||
|
@ -72,15 +73,17 @@ static void vert_calculate_size ( box *b )
|
||||||
}
|
}
|
||||||
b->max_size += child->h;
|
b->max_size += child->h;
|
||||||
}
|
}
|
||||||
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->padding ) );
|
int rem_width = b->widget.w - b->widget.pad.left-b->widget.pad.right;
|
||||||
if ( b->max_size > b->widget.h ) {
|
int rem_height = b->widget.h - b->widget.pad.top-b->widget.pad.bottom;
|
||||||
|
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
|
||||||
|
if ( b->max_size > rem_height ) {
|
||||||
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h );
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if ( active_widgets > 0 ) {
|
||||||
int bottom = b->widget.h;
|
int bottom = b->widget.h - b->widget.pad.bottom;
|
||||||
int top = 0;
|
int top = b->widget.pad.top;
|
||||||
double rem = b->widget.h - b->max_size;
|
double rem = rem_height - b->max_size;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
widget * child = (widget *) iter->data;
|
widget * child = (widget *) iter->data;
|
||||||
|
@ -92,30 +95,30 @@ static void vert_calculate_size ( box *b )
|
||||||
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
|
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
|
||||||
if ( child->end ) {
|
if ( child->end ) {
|
||||||
bottom -= expanding_widgets_size;
|
bottom -= expanding_widgets_size;
|
||||||
widget_move ( child, child->x, bottom );
|
widget_move ( child, b->widget.pad.left, bottom );
|
||||||
widget_resize ( child, b->widget.w, expanding_widgets_size );
|
widget_resize ( child, rem_width, expanding_widgets_size );
|
||||||
bottom -= b->padding;
|
bottom -= b->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widget_move ( child, child->x, top );
|
widget_move ( child, b->widget.pad.left, top );
|
||||||
top += expanding_widgets_size;
|
top += expanding_widgets_size;
|
||||||
widget_resize ( child, b->widget.w, expanding_widgets_size );
|
widget_resize ( child, rem_width, expanding_widgets_size );
|
||||||
top += b->padding;
|
top += b->spacing;
|
||||||
}
|
}
|
||||||
rem -= expanding_widgets_size;
|
rem -= expanding_widgets_size;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
else if ( child->end ) {
|
else if ( child->end ) {
|
||||||
bottom -= widget_get_height ( child );
|
bottom -= widget_get_height ( child );
|
||||||
widget_move ( child, child->x, bottom );
|
widget_move ( child, b->widget.pad.left, bottom );
|
||||||
widget_resize ( child, b->widget.w, child->h );
|
widget_resize ( child, rem_width, child->h );
|
||||||
bottom -= b->padding;
|
bottom -= b->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widget_move ( child, child->x, top );
|
widget_move ( child, b->widget.pad.left, top );
|
||||||
top += widget_get_height ( child );
|
top += widget_get_height ( child );
|
||||||
widget_resize ( child, b->widget.w, child->h );
|
widget_resize ( child, rem_width, child->h );
|
||||||
top += b->padding;
|
top += b->spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,15 +141,17 @@ static void hori_calculate_size ( box *b )
|
||||||
// Size used by fixed width widgets.
|
// Size used by fixed width widgets.
|
||||||
b->max_size += child->w;
|
b->max_size += child->w;
|
||||||
}
|
}
|
||||||
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->padding ) );
|
int rem_height = b->widget.h - b->widget.pad.top-b->widget.pad.bottom;
|
||||||
if ( b->max_size > b->widget.w ) {
|
int rem_width = b->widget.w - b->widget.pad.left-b->widget.pad.right;
|
||||||
|
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
|
||||||
|
if ( b->max_size > (rem_width)) {
|
||||||
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w );
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if ( active_widgets > 0 ) {
|
||||||
int right = b->widget.w;
|
int right = b->widget.w-b->widget.pad.right;
|
||||||
int left = 0;
|
int left = b->widget.pad.left;
|
||||||
double rem = b->widget.w - b->max_size;
|
double rem = rem_width - b->max_size;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
widget * child = (widget *) iter->data;
|
widget * child = (widget *) iter->data;
|
||||||
|
@ -158,30 +163,30 @@ static void hori_calculate_size ( box *b )
|
||||||
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
|
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
|
||||||
if ( child->end ) {
|
if ( child->end ) {
|
||||||
right -= expanding_widgets_size;
|
right -= expanding_widgets_size;
|
||||||
widget_move ( child, right, child->y );
|
widget_move ( child, right, b->widget.pad.top);
|
||||||
widget_resize ( child, expanding_widgets_size, b->widget.h );
|
widget_resize ( child, expanding_widgets_size, rem_height );
|
||||||
right -= b->padding;
|
right -= b->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widget_move ( child, left, child->y );
|
widget_move ( child, left, b->widget.pad.top );
|
||||||
left += expanding_widgets_size;
|
left += expanding_widgets_size;
|
||||||
widget_resize ( child, expanding_widgets_size, b->widget.h );
|
widget_resize ( child, expanding_widgets_size, rem_height );
|
||||||
left += b->padding;
|
left += b->spacing;
|
||||||
}
|
}
|
||||||
rem -= expanding_widgets_size;
|
rem -= expanding_widgets_size;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
else if ( child->end ) {
|
else if ( child->end ) {
|
||||||
right -= widget_get_width ( child );
|
right -= widget_get_width ( child );
|
||||||
widget_move ( child, right, child->y );
|
widget_move ( child, right, b->widget.pad.top );
|
||||||
widget_resize ( child, child->w, b->widget.h );
|
widget_resize ( child, child->w, rem_height );
|
||||||
right -= b->padding;
|
right -= b->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widget_move ( child, left, child->y );
|
widget_move ( child, left, b->widget.pad.top );
|
||||||
left += widget_get_width ( child );
|
left += widget_get_width ( child );
|
||||||
widget_resize ( child, child->w, b->widget.h );
|
widget_resize ( child, child->w, rem_height );
|
||||||
left += b->padding;
|
left += b->spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,12 +281,11 @@ static gboolean box_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme
|
||||||
box * box_create ( const char *name, 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 ) );
|
||||||
|
// Initialize widget.
|
||||||
|
widget_init ( WIDGET(b), name, BOX_CLASS_NAME);
|
||||||
b->type = type;
|
b->type = type;
|
||||||
b->widget.name = g_strdup (name);
|
|
||||||
b->widget.x = x;
|
|
||||||
b->widget.y = y;
|
b->widget.y = y;
|
||||||
b->widget.w = w;
|
b->widget.w = w;
|
||||||
b->widget.h = h;
|
|
||||||
b->widget.draw = box_draw;
|
b->widget.draw = box_draw;
|
||||||
b->widget.free = box_free;
|
b->widget.free = box_free;
|
||||||
b->widget.resize = box_resize;
|
b->widget.resize = box_resize;
|
||||||
|
@ -290,7 +294,10 @@ box * box_create ( const char *name, boxType type, short x, short y, short w, sh
|
||||||
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 ( "@box", b->widget.name, NULL, "padding",config.line_margin ));
|
box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin ));
|
||||||
|
// Do this dynamically
|
||||||
|
b->widget.h = h+b->widget.pad.top+b->widget.pad.bottom;
|
||||||
|
b->widget.x = x+b->widget.pad.left+b->widget.pad.right;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,10 +322,10 @@ int box_get_fixed_pixels ( box *box )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void box_set_padding ( box * box, unsigned int padding )
|
void box_set_spacing ( box * box, unsigned int spacing )
|
||||||
{
|
{
|
||||||
if ( box != NULL ) {
|
if ( box != NULL ) {
|
||||||
box->padding = padding;
|
box->spacing = spacing;
|
||||||
widget_queue_redraw ( WIDGET ( box ) );
|
widget_queue_redraw ( WIDGET ( box ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ struct _listview
|
||||||
unsigned int req_elements;
|
unsigned int req_elements;
|
||||||
unsigned int cur_elements;
|
unsigned int cur_elements;
|
||||||
|
|
||||||
unsigned int padding;
|
unsigned int spacing;
|
||||||
unsigned int menu_lines;
|
unsigned int menu_lines;
|
||||||
unsigned int menu_columns;
|
unsigned int menu_columns;
|
||||||
unsigned int fixed_num_lines;
|
unsigned int fixed_num_lines;
|
||||||
|
@ -163,15 +163,15 @@ static void listview_draw ( widget *wid, cairo_t *draw )
|
||||||
cairo_translate ( draw, wid->x, wid->y );
|
cairo_translate ( draw, wid->x, wid->y );
|
||||||
unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset );
|
unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset );
|
||||||
if ( lv->rchanged ) {
|
if ( lv->rchanged ) {
|
||||||
unsigned int width = lv->widget.w - lv->padding * ( lv->cur_columns - 1 );
|
unsigned int width = lv->widget.w - lv->spacing * ( lv->cur_columns - 1 );
|
||||||
if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) ) {
|
if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) ) {
|
||||||
width -= lv->padding;
|
width -= lv->spacing;
|
||||||
width -= widget_get_width ( WIDGET ( lv->scrollbar ) );
|
width -= widget_get_width ( WIDGET ( lv->scrollbar ) );
|
||||||
}
|
}
|
||||||
unsigned int element_width = ( width ) / lv->cur_columns;
|
unsigned int element_width = ( width ) / lv->cur_columns;
|
||||||
for ( unsigned int i = 0; i < max; i++ ) {
|
for ( unsigned int i = 0; i < max; i++ ) {
|
||||||
unsigned int ex = ( ( i ) / lv->max_rows ) * ( element_width + lv->padding );
|
unsigned int ex = ( ( i ) / lv->max_rows ) * ( element_width + lv->spacing );
|
||||||
unsigned int ey = ( ( i ) % lv->max_rows ) * ( lv->element_height + lv->padding );
|
unsigned int ey = ( ( i ) % lv->max_rows ) * ( lv->element_height + lv->spacing );
|
||||||
textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
|
textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
|
||||||
|
|
||||||
update_element ( lv, i, i + offset, TRUE );
|
update_element ( lv, i, i + offset, TRUE );
|
||||||
|
@ -249,7 +249,7 @@ static void listview_resize ( widget *wid, short w, short h )
|
||||||
listview *lv = (listview *) wid;
|
listview *lv = (listview *) wid;
|
||||||
lv->widget.w = MAX ( 0, w );
|
lv->widget.w = MAX ( 0, w );
|
||||||
lv->widget.h = MAX ( 0, h );
|
lv->widget.h = MAX ( 0, h );
|
||||||
lv->max_rows = ( lv->padding + lv->widget.h ) / ( lv->element_height + lv->padding );
|
lv->max_rows = ( lv->spacing + lv->widget.h ) / ( lv->element_height + lv->spacing );
|
||||||
lv->max_elements = lv->max_rows * lv->menu_columns;
|
lv->max_elements = lv->max_rows * lv->menu_columns;
|
||||||
|
|
||||||
widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET ( lv->scrollbar ) ), 0 );
|
widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET ( lv->scrollbar ) ), 0 );
|
||||||
|
@ -338,7 +338,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
|
||||||
lv->udata = udata;
|
lv->udata = udata;
|
||||||
|
|
||||||
// Some settings.
|
// Some settings.
|
||||||
lv->padding = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "padding", config.line_margin );
|
lv->spacing = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "spacing", config.line_margin );
|
||||||
lv->menu_lines = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "lines", config.menu_lines );
|
lv->menu_lines = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "lines", config.menu_lines );
|
||||||
lv->menu_columns = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "columns", config.menu_columns);
|
lv->menu_columns = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "columns", config.menu_columns);
|
||||||
lv->fixed_num_lines = rofi_theme_get_boolean ("@listview", lv->widget.name, NULL, "fixed-height", config.fixed_num_lines );
|
lv->fixed_num_lines = rofi_theme_get_boolean ("@listview", lv->widget.name, NULL, "fixed-height", config.fixed_num_lines );
|
||||||
|
@ -455,7 +455,7 @@ unsigned int listview_get_desired_height ( listview *lv )
|
||||||
if ( h == 0 ) {
|
if ( h == 0 ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return h * lv->element_height + ( h - 1 ) * lv->padding;
|
return h * lv->element_height + ( h - 1 ) * lv->spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void listview_set_show_scrollbar ( listview *lv, gboolean enabled )
|
void listview_set_show_scrollbar ( listview *lv, gboolean enabled )
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
|
const char *SEPARATOR_CLASS_NAME = "@separator";
|
||||||
/**
|
/**
|
||||||
* @param sp The separator widget handle.
|
* @param sp The separator widget handle.
|
||||||
* @param style_str String representation of the style.
|
* @param style_str String representation of the style.
|
||||||
|
@ -69,17 +70,17 @@ static void separator_free ( widget * );
|
||||||
separator *separator_create ( const char *name, 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 ) );
|
||||||
|
widget_init ( WIDGET (sb), name, SEPARATOR_CLASS_NAME );
|
||||||
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 ) {
|
||||||
sb->widget.w = 1;
|
sb->widget.w = 1;
|
||||||
sb->widget.h = MAX ( 1, sw );
|
sb->widget.h = MAX ( 1, sw )+sb->widget.pad.top+sb->widget.pad.bottom;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb->widget.h = 1;
|
sb->widget.h = 1;
|
||||||
sb->widget.w = MAX ( 1, sw );
|
sb->widget.w = MAX ( 1, sw )+sb->widget.pad.left+sb->widget.pad.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb->widget.draw = separator_draw;
|
sb->widget.draw = separator_draw;
|
||||||
|
@ -88,7 +89,7 @@ separator *separator_create ( const char *name, 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 ( "@separator", sb->widget.name, NULL, "line-style", "solid");
|
const char *line_style = rofi_theme_get_string ( sb->widget.class_name, sb->widget.name, NULL, "line-style", "solid");
|
||||||
separator_set_line_style_from_string ( sb, line_style );
|
separator_set_line_style_from_string ( sb, line_style );
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
@ -129,22 +130,23 @@ static void separator_draw ( widget *wid, cairo_t *draw )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
color_separator ( draw );
|
color_separator ( draw );
|
||||||
rofi_theme_get_color ( "@separator", wid->name, NULL, "foreground", draw );
|
rofi_theme_get_color ( wid->class_name, wid->name, NULL, "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 );
|
||||||
}
|
}
|
||||||
if ( sep->type == S_HORIZONTAL ) {
|
if ( sep->type == S_HORIZONTAL ) {
|
||||||
cairo_set_line_width ( draw, wid->h );
|
cairo_set_line_width ( draw, wid->h );
|
||||||
double half = wid->h / 2.0;
|
int height= wid->h-wid->pad.top-wid->pad.bottom;
|
||||||
cairo_move_to ( draw, wid->x, wid->y + half );
|
double half = height / 2.0;
|
||||||
cairo_line_to ( draw, wid->x + wid->w, wid->y + half );
|
cairo_move_to ( draw, wid->x+wid->pad.left, wid->y + wid->pad.top +half );
|
||||||
|
cairo_line_to ( draw, wid->x+wid->w-wid->pad.right, wid->y +wid->pad.top + half );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cairo_set_line_width ( draw, wid->w );
|
cairo_set_line_width ( draw, wid->w );
|
||||||
double half = wid->w / 2.0;
|
double half = wid->w / 2.0;
|
||||||
cairo_move_to ( draw, wid->x + half, wid->y );
|
cairo_move_to ( draw, wid->x + wid->pad.left + half, wid->y +wid->pad.top);
|
||||||
cairo_line_to ( draw, wid->x + half, wid->y + wid->h );
|
cairo_line_to ( draw, wid->x + wid->pad.left + half, wid->y + wid->h-wid->pad.bottom );
|
||||||
}
|
}
|
||||||
cairo_stroke ( draw );
|
cairo_stroke ( draw );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "widgets/widget.h"
|
#include "widgets/widget.h"
|
||||||
#include "widgets/widget-internal.h"
|
#include "widgets/widget-internal.h"
|
||||||
|
#include "theme.h"
|
||||||
|
|
||||||
|
|
||||||
|
void widget_init ( widget *widget , const char *name, const char *class_name )
|
||||||
|
{
|
||||||
|
widget->name = g_strdup(name);
|
||||||
|
widget->class_name = g_strdup(class_name);
|
||||||
|
widget->pad = rofi_theme_get_padding (widget->class_name, widget->name, NULL, "padding", (Padding){0,0,0,0,FALSE});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int widget_intersect ( const widget *widget, int x, int y )
|
int widget_intersect ( const widget *widget, int x, int y )
|
||||||
{
|
{
|
||||||
|
@ -72,6 +82,9 @@ void widget_free ( widget *wid )
|
||||||
if ( wid->name ) {
|
if ( wid->name ) {
|
||||||
g_free ( wid->name );
|
g_free ( wid->name );
|
||||||
}
|
}
|
||||||
|
if ( wid->class_name ) {
|
||||||
|
g_free( wid->class_name );
|
||||||
|
}
|
||||||
if ( wid->free ) {
|
if ( wid->free ) {
|
||||||
wid->free ( wid );
|
wid->free ( wid );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue