1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-02-10 15:44:41 -05:00

Indent magic, rework makefile so lexer and yacc file are not passed.

This commit is contained in:
Dave Davenport 2017-01-08 21:36:06 +01:00
parent 8c0c43952d
commit baab2047ad
25 changed files with 834 additions and 809 deletions

View file

@ -27,7 +27,7 @@ dist_bin_SCRIPTS=\
nodist_rofi_SOURCES=\ nodist_rofi_SOURCES=\
$(top_builddir)/gitconfig.h $(top_builddir)/gitconfig.h
rofi_SOURCES=\ SOURCES=\
source/rofi.c\ source/rofi.c\
source/view.c\ source/view.c\
source/mode.c\ source/mode.c\
@ -53,8 +53,6 @@ rofi_SOURCES=\
source/dialogs/window.c\ source/dialogs/window.c\
source/dialogs/script.c\ source/dialogs/script.c\
source/dialogs/help-keys.c\ source/dialogs/help-keys.c\
lexer/theme-parser.y\
lexer/theme-lexer.l\
include/xcb.h\ include/xcb.h\
include/xcb-internal.h\ include/xcb-internal.h\
include/rofi.h\ include/rofi.h\
@ -89,6 +87,11 @@ rofi_SOURCES=\
include/xkb.h\ include/xkb.h\
include/xkb-internal.h include/xkb-internal.h
rofi_SOURCES=\
lexer/theme-parser.y\
lexer/theme-lexer.l\
$(SOURCES)
rofi_CFLAGS=\ rofi_CFLAGS=\
$(AM_CFLAGS)\ $(AM_CFLAGS)\
$(glib_CFLAGS)\ $(glib_CFLAGS)\
@ -253,7 +256,7 @@ helper_pidfile_SOURCES=\
source/x11-helper.c\ source/x11-helper.c\
include/x11-helper.h\ include/x11-helper.h\
test/helper-pidfile.c test/helper-pidfile.c
helper_tokenize_CFLAGS=$(textbox_test_CFLAGS) helper_tokenize_CFLAGS=$(textbox_test_CFLAGS)
helper_tokenize_LDADD=$(textbox_test_LDADD) helper_tokenize_LDADD=$(textbox_test_LDADD)
helper_tokenize_SOURCES=\ helper_tokenize_SOURCES=\
@ -399,7 +402,7 @@ TESTS=\
scrollbar_test scrollbar_test
.PHONY: test-x .PHONY: test-x
test-x: $(bin_PROGRAMS) test-x: $(bin_PROGRAMS)
echo "Test 2" echo "Test 2"
$(top_srcdir)/test/run_test.sh 200 $(top_srcdir)/test/run_errormsg_test.sh $(top_builddir) $(top_srcdir)/test/run_test.sh 200 $(top_srcdir)/test/run_errormsg_test.sh $(top_builddir)
echo "Test 3" echo "Test 3"
@ -448,7 +451,7 @@ test-x1: $(bin_PROGRAMS)
.PHONY: indent .PHONY: indent
indent: $(rofi_SOURCES) $(helper_test_SOURCES) $(textbox_test_SOURCES) $(history_test_SOURCES) $(helper_expand_SOURCES) indent: $(SOURCES)
uncrustify -c $(top_srcdir)/data/uncrustify.cfg --replace $^ uncrustify -c $(top_srcdir)/data/uncrustify.cfg --replace $^
.PHONY: cppcheck .PHONY: cppcheck

View file

@ -6,7 +6,8 @@
#include <settings.h> #include <settings.h>
/** Style of line */ /** Style of line */
typedef enum { typedef enum
{
/** Solid line */ /** Solid line */
SOLID, SOLID,
/** Dashed line */ /** Dashed line */
@ -16,7 +17,8 @@ typedef enum {
/** /**
* Distance unit type. * Distance unit type.
*/ */
typedef enum { typedef enum
{
/** PixelWidth in pixels. */ /** PixelWidth in pixels. */
PW_PX, PW_PX,
/** PixelWidth in EM. */ /** PixelWidth in EM. */
@ -28,7 +30,8 @@ typedef enum {
/** /**
* Structure representing a distance. * Structure representing a distance.
*/ */
typedef struct { typedef struct
{
/** Distance */ /** Distance */
double distance; double distance;
/** Unit type of the distance */ /** Unit type of the distance */
@ -40,14 +43,16 @@ typedef struct {
/** /**
* Type of orientation. * Type of orientation.
*/ */
typedef enum { typedef enum
{
ORIENTATION_VERTICAL, ORIENTATION_VERTICAL,
ORIENTATION_HORIZONTAL ORIENTATION_HORIZONTAL
} Orientation; } Orientation;
/** /**
* Type of property * Type of property
*/ */
typedef enum { typedef enum
{
/** Integer */ /** Integer */
P_INTEGER, P_INTEGER,
/** Double */ /** Double */
@ -85,7 +90,7 @@ typedef struct
* Padding * Padding
*/ */
typedef struct typedef struct
{ {
Distance top; Distance top;
Distance right; Distance right;
Distance bottom; Distance bottom;
@ -95,29 +100,32 @@ typedef struct
/** /**
* Property structure. * Property structure.
*/ */
typedef struct Property { typedef struct Property
{
/** Name of property */ /** Name of property */
char *name; char *name;
/** Type of property. */ /** Type of property. */
PropertyType type; PropertyType type;
/** Value */ /** Value */
union { union
{
/** integer */ /** integer */
int i; int i;
/** Double */ /** Double */
double f; double f;
/** String */ /** String */
char *s; char *s;
/** boolean */ /** boolean */
gboolean b; gboolean b;
/** Color */ /** Color */
ThemeColor color; ThemeColor color;
/** Padding */ /** Padding */
Padding padding; Padding padding;
/** Reference */ /** Reference */
struct { struct
{
/** Name */ /** Name */
char *name; char *name;
/** Cached looked up ref */ /** Cached looked up ref */
struct Property *ref; struct Property *ref;
} link; } link;
@ -126,19 +134,19 @@ typedef struct Property {
/** /**
* ThemeWidget. * ThemeWidget.
*/ */
typedef struct ThemeWidget { typedef struct ThemeWidget
int set; {
char *name; int set;
char *name;
unsigned int num_widgets; unsigned int num_widgets;
struct ThemeWidget **widgets; struct ThemeWidget **widgets;
GHashTable *properties; GHashTable *properties;
struct ThemeWidget *parent; struct ThemeWidget *parent;
} ThemeWidget; } ThemeWidget;
/** /**
* Global pointer to the current active theme. * Global pointer to the current active theme.
*/ */
@ -234,7 +242,7 @@ Distance rofi_theme_get_distance ( const widget *widget, const char *property, i
* *
* @returns The integer value of this property for this widget. * @returns The integer value of this property for this widget.
*/ */
int rofi_theme_get_integer ( const widget *widget, const char *property, int def ); int rofi_theme_get_integer ( const widget *widget, const char *property, int def );
/** /**
* @param widget The widget to query * @param widget The widget to query
@ -267,7 +275,7 @@ int rofi_theme_get_integer_exact ( const widget *widget, const char *property, i
* *
* @returns The boolean value of this property for this widget. * @returns The boolean value of this property for this widget.
*/ */
int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ); int rofi_theme_get_boolean ( const widget *widget, const char *property, int def );
/** /**
* @param widget The widget to query * @param widget The widget to query
@ -278,7 +286,7 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int
* *
* @returns The string value of this property for this widget. * @returns The string value of this property for this widget.
*/ */
char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ); char *rofi_theme_get_string ( const widget *widget, const char *property, char *def );
/** /**
* @param widget The widget to query * @param widget The widget to query
@ -289,7 +297,7 @@ char *rofi_theme_get_string ( const widget *widget, const char *property, cha
* *
* @returns The double value of this property for this widget. * @returns The double value of this property for this widget.
*/ */
double rofi_theme_get_double ( const widget *widget, const char *property, double def ); double rofi_theme_get_double ( const widget *widget, const char *property, double def );
/** /**
* @param widget The widget to query * @param widget The widget to query
@ -299,7 +307,7 @@ double rofi_theme_get_double ( const widget *widget, const char *property, dou
* Obtain the color of the widget and applies this to the drawable d. * Obtain the color of the widget and applies this to the drawable d.
* *
*/ */
void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d); void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d );
/** /**
* @param widget The widget to query * @param widget The widget to query

View file

@ -24,7 +24,7 @@ struct RofiViewState
/** Flag indicating if view needs to be refiltered. */ /** Flag indicating if view needs to be refiltered. */
int refilter; int refilter;
/** Widget representing the main container. */ /** Widget representing the main container. */
container *main_window; container *main_window;
/** Main #box widget holding different elements. */ /** Main #box widget holding different elements. */
box *main_box; box *main_box;
/** #box widget packing the input bar widgets. */ /** #box widget packing the input bar widgets. */

View file

@ -111,7 +111,6 @@ unsigned int rofi_view_get_selected_line ( const RofiViewState *state );
*/ */
void rofi_view_restart ( RofiViewState *state ); void rofi_view_restart ( RofiViewState *state );
/** /**
* @param state The handle to the view * @param state The handle to the view
* @param action The keyboard action * @param action The keyboard action

View file

@ -40,7 +40,7 @@ typedef struct
int blink; int blink;
guint blink_timeout; guint blink_timeout;
// //
const char *theme_name ; const char *theme_name;
} textbox; } textbox;
/** /**
@ -48,16 +48,16 @@ typedef struct
*/ */
typedef enum typedef enum
{ {
TB_AUTOHEIGHT = 1 << 0, TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1, TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16, TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17, TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18, TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19, TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20, TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21, TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22, TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23, TB_INDICATOR = 1 << 23,
} TextboxFlags; } TextboxFlags;
/** /**
* Flags indicating current state of the textbox. * Flags indicating current state of the textbox.

View file

@ -57,8 +57,8 @@ struct _widget
void ( *free )( struct _widget *widget ); void ( *free )( struct _widget *widget );
/** Name of widget (used for theming) */ /** Name of widget (used for theming) */
char *name; char *name;
const char *state; const char *state;
}; };
/** /**
@ -68,7 +68,7 @@ struct _widget
* Initializes the widget structure. * Initializes the widget structure.
* *
*/ */
void widget_init ( widget *widget , const char *name ); void widget_init ( widget *widget, const char *name );
/** /**
* @param widget The widget handle. * @param widget The widget handle.
@ -117,17 +117,17 @@ int widget_padding_get_bottom ( const widget *wid );
/** /**
* @param wid The widget handle. * @param wid The widget handle.
* *
* Get width of the content of the widget * Get width of the content of the widget
* *
* @returns the widget width, excluding padding. * @returns the widget width, excluding padding.
*/ */
int widget_padding_get_remaining_width ( const widget *wid ); int widget_padding_get_remaining_width ( const widget *wid );
/** /**
* @param wid The widget handle. * @param wid The widget handle.
* *
* Get height of the content of the widget * Get height of the content of the widget
* *
* @returns the widget height, excluding padding. * @returns the widget height, excluding padding.
*/ */
int widget_padding_get_remaining_height ( const widget *wid ); int widget_padding_get_remaining_height ( const widget *wid );
/** /**

View file

@ -174,7 +174,6 @@ void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata
*/ */
gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ); gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
/** /**
* @param wid The widget handle * @param wid The widget handle
* @param name The name of the widget. * @param name The name of the widget.

View file

@ -137,21 +137,23 @@ static void async_read_callback ( GObject *source_object, GAsyncResult *res, gpo
g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel, g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel,
async_read_callback, pd ); async_read_callback, pd );
return; return;
} else { }
else {
GError *error = NULL; GError *error = NULL;
// Absorb separator, already in buffer so should not block. // Absorb separator, already in buffer so should not block.
// If error == NULL end of stream.. // If error == NULL end of stream..
g_data_input_stream_read_byte ( stream, NULL, &error); g_data_input_stream_read_byte ( stream, NULL, &error );
if ( error == NULL ) { if ( error == NULL ) {
// Add empty line. // Add empty line.
read_add ( pd, "", 0); read_add ( pd, "", 0 );
rofi_view_reload (); rofi_view_reload ();
g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel, g_data_input_stream_read_upto_async ( pd->data_input_stream, &( pd->separator ), 1, G_PRIORITY_LOW, pd->cancel,
async_read_callback, pd ); async_read_callback, pd );
return; return;
} else { }
g_error_free (error); else {
g_error_free ( error );
} }
} }
if ( !g_cancellable_is_cancelled ( pd->cancel ) ) { if ( !g_cancellable_is_cancelled ( pd->cancel ) ) {

View file

@ -192,7 +192,7 @@ static void exec_cmd_entry ( DRunModeEntry *e )
fprintf ( stderr, "Nothing to execute after processing: %s.\n", e->exec );; fprintf ( stderr, "Nothing to execute after processing: %s.\n", e->exec );;
return; return;
} }
gchar *fp = rofi_expand_path ( g_strstrip ( str ) ); gchar *fp = rofi_expand_path ( g_strstrip ( str ) );
gchar *exec_path = g_key_file_get_string ( e->key_file, "Desktop Entry", "Path", NULL ); gchar *exec_path = g_key_file_get_string ( e->key_file, "Desktop Entry", "Path", NULL );
if ( execsh ( exec_path, fp, e->terminal ) ) { if ( execsh ( exec_path, fp, e->terminal ) ) {
char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL ); char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL );
@ -539,12 +539,12 @@ static int drun_token_match ( const Mode *data, GRegex **tokens, unsigned int in
test = 1; test = 1;
} }
// Match against category. // Match against category.
if ( !test ){ if ( !test ) {
gchar **list = g_key_file_get_locale_string_list ( rmpd->entry_list[index].key_file, "Desktop Entry", "Categories" , NULL, NULL,NULL ); gchar **list = g_key_file_get_locale_string_list ( rmpd->entry_list[index].key_file, "Desktop Entry", "Categories", NULL, NULL, NULL );
for ( int iter = 0; !test && list && list[iter]; iter++){ for ( int iter = 0; !test && list && list[iter]; iter++ ) {
test = token_match ( ftokens, list[iter]); test = token_match ( ftokens, list[iter] );
} }
g_strfreev(list); g_strfreev ( list );
} }
if ( test == 0 ) { if ( test == 0 ) {
match = 0; match = 0;

View file

@ -146,7 +146,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
rmpd->cmd_list = new_list; rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length; rmpd->cmd_list_length = new_length;
retv = RESET_DIALOG; retv = RESET_DIALOG;
} }
return retv; return retv;
} }

View file

@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
// Reading one line per time. // Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Evaluate one line. // Evaluate one line.
unsigned int index = 0, ti = 0; unsigned int index = 0, ti = 0;
char *token = buffer; char *token = buffer;
// Tokenize it. // Tokenize it.

View file

@ -399,13 +399,12 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
// Check if we are in I3 mode. I3 has to be special and allow markup in it window name...... // Check if we are in I3 mode. I3 has to be special and allow markup in it window name......
char *i3_socket_path = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), netatoms[I3_SOCKET_PATH] ); char *i3_socket_path = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), netatoms[I3_SOCKET_PATH] );
if ( i3_socket_path != NULL ){ if ( i3_socket_path != NULL ) {
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Detected I3 Window manager running."); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Detected I3 Window manager running." );
pd->i3_mode = TRUE; pd->i3_mode = TRUE;
g_free ( i3_socket_path ); g_free ( i3_socket_path );
} }
// Create cache // Create cache
x11_cache_create (); x11_cache_create ();
@ -488,15 +487,15 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
if ( has_names ) { if ( has_names ) {
if ( pd->i3_mode ) { if ( pd->i3_mode ) {
char *output = NULL; char *output = NULL;
if (pango_parse_markup ( _window_name_list_entry ( names.strings, names.strings_len, if ( pango_parse_markup ( _window_name_list_entry ( names.strings, names.strings_len,
c->wmdesktop ),-1, 0, NULL, &output, NULL, NULL)){ c->wmdesktop ), -1, 0, NULL, &output, NULL, NULL ) ) {
c->wmdesktopstr = output; c->wmdesktopstr = output;
} }
else { else {
c->wmdesktopstr = g_strdup ( "Invalid name"); c->wmdesktopstr = g_strdup ( "Invalid name" );
} }
}
} else { else {
c->wmdesktopstr = g_strdup ( _window_name_list_entry ( names.strings, names.strings_len, c->wmdesktop ) ); c->wmdesktopstr = g_strdup ( _window_name_list_entry ( names.strings, names.strings_len, c->wmdesktop ) );
} }
} }
@ -634,7 +633,7 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i
} }
} }
else if ( ( mretv & ( MENU_ENTRY_DELETE ) ) == MENU_ENTRY_DELETE ) { else if ( ( mretv & ( MENU_ENTRY_DELETE ) ) == MENU_ENTRY_DELETE ) {
xcb_ewmh_request_close_window ( &(xcb->ewmh), xcb->screen_nbr, rmpd->ids->array[selected_line], XCB_CURRENT_TIME, XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER); xcb_ewmh_request_close_window ( &( xcb->ewmh ), xcb->screen_nbr, rmpd->ids->array[selected_line], XCB_CURRENT_TIME, XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER );
xcb_flush ( xcb->connection ); xcb_flush ( xcb->connection );
} }
return retv; return retv;

View file

@ -181,11 +181,13 @@ static gchar *fuzzy_to_regex ( const char * input )
else { else {
g_string_append ( str, ".*(" ); g_string_append ( str, ".*(" );
} }
if ( *iter == '\\' ){ if ( *iter == '\\' ) {
g_string_append_c ( str, '\\'); g_string_append_c ( str, '\\' );
iter = g_utf8_next_char ( iter ); iter = g_utf8_next_char ( iter );
// If EOL, break out of for loop. // If EOL, break out of for loop.
if ( (*iter) == '\0' ) break; if ( ( *iter ) == '\0' ) {
break;
}
} }
g_string_append_unichar ( str, g_utf8_get_char ( iter ) ); g_string_append_unichar ( str, g_utf8_get_char ( iter ) );
g_string_append ( str, ")" ); g_string_append ( str, ")" );
@ -246,7 +248,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
} }
char *saveptr = NULL, *token; char *saveptr = NULL, *token;
GRegex **retv = NULL; GRegex **retv = NULL;
if ( !config.tokenize ) { if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive ); retv[0] = (GRegex *) create_regex ( input, case_sensitive );
@ -297,19 +299,19 @@ int find_arg_str ( const char * const key, char** val )
const char ** find_arg_strv ( const char *const key ) const char ** find_arg_strv ( const char *const key )
{ {
const char **retv =NULL; const char **retv = NULL;
int length = 0; int length = 0;
for ( int i = 0; i < stored_argc; i++ ) { for ( int i = 0; i < stored_argc; i++ ) {
if ( strcasecmp ( stored_argv[i], key ) == 0 && i < (stored_argc -1 ) ){ if ( strcasecmp ( stored_argv[i], key ) == 0 && i < ( stored_argc - 1 ) ) {
length++; length++;
} }
} }
if ( length > 0 ) { if ( length > 0 ) {
retv = g_malloc0((length+1)*sizeof(char*)); retv = g_malloc0 ( ( length + 1 ) * sizeof ( char* ) );
int index = 0; int index = 0;
for ( int i = 0; i < stored_argc; i++ ) { for ( int i = 0; i < stored_argc; i++ ) {
if ( strcasecmp ( stored_argv[i], key ) == 0 && i < (stored_argc -1 ) ){ if ( strcasecmp ( stored_argv[i], key ) == 0 && i < ( stored_argc - 1 ) ) {
retv[index++] = stored_argv[i+1]; retv[index++] = stored_argv[i + 1];
} }
} }
} }

View file

@ -193,7 +193,7 @@ KeyBindingAction abe_find_action ( unsigned int mask, xkb_keysym_t key )
void abe_trigger_release ( void ) void abe_trigger_release ( void )
{ {
RofiViewState *state; RofiViewState *state;
state = rofi_view_get_active ( ); state = rofi_view_get_active ( );
if ( state ) { if ( state ) {

View file

@ -270,46 +270,47 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
printf ( "\n" ); printf ( "\n" );
x11_dump_monitor_layout (); x11_dump_monitor_layout ();
printf ( "\n" ); printf ( "\n" );
printf ( "Compile time options:\n"); printf ( "Compile time options:\n" );
#ifdef WINDOW_MODE #ifdef WINDOW_MODE
printf ( "\t* window %senabled%s\n", is_term?color_green:"", is_term?color_reset:""); printf ( "\t* window %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
#else #else
printf ( "\t* window %sdisabled%s\n", is_term?color_red:"", is_term?color_reset:""); printf ( "\t* window %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
#endif #endif
#ifdef ENABLE_DRUN #ifdef ENABLE_DRUN
printf ( "\t* drun %senabled%s\n", is_term?color_green:"", is_term?color_reset:""); printf ( "\t* drun %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
#else #else
printf ( "\t* drun %sdisabled%s\n", is_term?color_red:"", is_term?color_reset:""); printf ( "\t* drun %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
#endif #endif
#ifdef TIMINGS #ifdef TIMINGS
printf ( "\t* timings %senabled%s\n", is_term?color_green:"", is_term?color_reset:""); printf ( "\t* timings %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
#else #else
printf ( "\t* timings %sdisabled%s\n", is_term?color_red:"", is_term?color_reset:""); printf ( "\t* timings %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
#endif #endif
#ifdef ENABLE_GCOV #ifdef ENABLE_GCOV
printf ( "\t* gcov %senabled%s\n", is_term?color_green:"", is_term?color_reset:""); printf ( "\t* gcov %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
#else #else
printf ( "\t* gcov %sdisabled%s\n", is_term?color_red:"", is_term?color_reset:""); printf ( "\t* gcov %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
#endif #endif
#ifdef ENABLE_ASAN #ifdef ENABLE_ASAN
printf ( "\t* asan %senabled%s\n", is_term?color_green:"", is_term?color_reset:""); printf ( "\t* asan %senabled%s\n", is_term ? color_green : "", is_term ? color_reset : "" );
#else #else
printf ( "\t* asan %sdisabled%s\n", is_term?color_red:"", is_term?color_reset:""); printf ( "\t* asan %sdisabled%s\n", is_term ? color_red : "", is_term ? color_reset : "" );
#endif #endif
printf ( "\n" ); printf ( "\n" );
printf ( "For more information see: %sman rofi%s\n", is_term?color_bold:"",is_term?color_reset:"" ); printf ( "For more information see: %sman rofi%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
#ifdef GIT_VERSION #ifdef GIT_VERSION
printf ( " Version: %s"GIT_VERSION "%s\n", is_term?color_bold:"",is_term?color_reset:"" ); printf ( " Version: %s"GIT_VERSION "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
#else #else
printf ( " Version: %s"VERSION "%s\n", is_term?color_bold:"",is_term?color_reset:"" ); printf ( " Version: %s"VERSION "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
#endif #endif
printf ( " Bugreports: %s"PACKAGE_BUGREPORT "%s\n", is_term?color_bold:"",is_term?color_reset:"" ); printf ( " Bugreports: %s"PACKAGE_BUGREPORT "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
printf ( " Support: %s"PACKAGE_URL "%s\n", is_term?color_bold:"",is_term?color_reset:"" ); printf ( " Support: %s"PACKAGE_URL "%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
printf ( " %s#rofi @ freenode.net%s\n", is_term?color_bold:"",is_term?color_reset:"" ); printf ( " %s#rofi @ freenode.net%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
if ( find_arg ( "-no-config" ) < 0 ) { if ( find_arg ( "-no-config" ) < 0 ) {
printf ( " Configuration file: %s%s%s\n", is_term?color_bold:"", config_path, is_term?color_reset:"" ); printf ( " Configuration file: %s%s%s\n", is_term ? color_bold : "", config_path, is_term ? color_reset : "" );
} else { }
printf ( " Configuration file: %sDisabled%s\n", is_term?color_bold:"", is_term?color_reset:"" ); else {
printf ( " Configuration file: %sDisabled%s\n", is_term ? color_bold : "", is_term ? color_reset : "" );
} }
} }
@ -396,7 +397,7 @@ static int add_mode ( const char * token )
} }
else else
#endif // WINDOW_MODE #endif // WINDOW_MODE
// SSh dialog // SSh dialog
if ( strcasecmp ( token, "ssh" ) == 0 ) { if ( strcasecmp ( token, "ssh" ) == 0 ) {
modi[num_modi] = &ssh_mode; modi[num_modi] = &ssh_mode;
num_modi++; num_modi++;
@ -489,7 +490,8 @@ static inline void load_configuration_dynamic ( )
/** /**
* Process X11 events in the main-loop (gui-thread) of the application. * Process X11 events in the main-loop (gui-thread) of the application.
*/ */
static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev){ static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev )
{
RofiViewState *state = rofi_view_get_active (); RofiViewState *state = rofi_view_get_active ();
if ( state != NULL ) { if ( state != NULL ) {
rofi_view_itterrate ( state, ev, &xkb ); rofi_view_itterrate ( state, ev, &xkb );
@ -585,12 +587,12 @@ unsigned int lazy_grab_retry_count_pt = 0;
static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data ) static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data )
{ {
// After 5 sec. // After 5 sec.
if ( lazy_grab_retry_count_kb > (5*1000)) { if ( lazy_grab_retry_count_kb > ( 5 * 1000 ) ) {
fprintf(stderr, "Failed to grab keyboard after %u times. Giving up.\n", lazy_grab_retry_count_kb); fprintf ( stderr, "Failed to grab keyboard after %u times. Giving up.\n", lazy_grab_retry_count_kb );
g_main_loop_quit ( main_loop ); g_main_loop_quit ( main_loop );
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
if ( take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ){ if ( take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
lazy_grab_retry_count_kb++; lazy_grab_retry_count_kb++;
@ -599,11 +601,11 @@ static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data )
static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data ) static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
{ {
// After 5 sec. // After 5 sec.
if ( lazy_grab_retry_count_pt > (5*1000)) { if ( lazy_grab_retry_count_pt > ( 5 * 1000 ) ) {
fprintf(stderr, "Failed to grab pointer after %u times. Giving up.\n", lazy_grab_retry_count_pt); fprintf ( stderr, "Failed to grab pointer after %u times. Giving up.\n", lazy_grab_retry_count_pt );
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
if ( take_keyboard ( xcb_stuff_get_root_window ( xcb), 0 ) ){ if ( take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
lazy_grab_retry_count_pt++; lazy_grab_retry_count_pt++;
@ -629,23 +631,23 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
// We grab this using the rootwindow (as dmenu does it). // We grab this using the rootwindow (as dmenu does it).
// this seems to result in the smallest delay for most people. // this seems to result in the smallest delay for most people.
if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) { if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) {
if ( find_arg ( "-lazy-grab") >= 0 ){ if ( find_arg ( "-lazy-grab" ) >= 0 ) {
if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb), 0) ){ if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
g_timeout_add ( 1,lazy_grab_keyboard, NULL); g_timeout_add ( 1, lazy_grab_keyboard, NULL );
} }
if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 )) { if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
g_timeout_add ( 1,lazy_grab_pointer, NULL); g_timeout_add ( 1, lazy_grab_pointer, NULL );
} }
} else { }
if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb), 500) ){ else {
if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb ), 500 ) ) {
fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 ); fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
g_main_loop_quit ( main_loop ); g_main_loop_quit ( main_loop );
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
if ( ! take_pointer ( xcb_stuff_get_root_window ( xcb ), 100 ) ) { if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 100 ) ) {
fprintf ( stderr, "Failed to grab mouse pointer, even after %d uS.", 100*1000); fprintf ( stderr, "Failed to grab mouse pointer, even after %d uS.", 100 * 1000 );
} }
} }
} }
TICK_N ( "Grab keyboard" ); TICK_N ( "Grab keyboard" );
@ -949,26 +951,25 @@ int main ( int argc, char *argv[] )
TICK_N ( "Parse theme" ); TICK_N ( "Parse theme" );
rofi_theme_parse_file ( config.theme ); rofi_theme_parse_file ( config.theme );
TICK_N ( "Parsed theme" ); TICK_N ( "Parsed theme" );
} else { }
else {
rofi_theme_convert_old_theme ( ); rofi_theme_convert_old_theme ( );
} }
const char ** theme_str = find_arg_strv ( "-theme-str" ); const char ** theme_str = find_arg_strv ( "-theme-str" );
if ( theme_str ) { if ( theme_str ) {
for ( int index = 0; theme_str && theme_str[index]; index++ ){ for ( int index = 0; theme_str && theme_str[index]; index++ ) {
if ( ! rofi_theme_parse_string ( theme_str[index] ) ){ if ( !rofi_theme_parse_string ( theme_str[index] ) ) {
fprintf(stderr, "Failed to parse: %s\n", theme_str[index]); fprintf ( stderr, "Failed to parse: %s\n", theme_str[index] );
exit ( EXIT_FAILURE ); exit ( EXIT_FAILURE );
} }
} }
g_free ( theme_str ); g_free ( theme_str );
} }
if ( find_arg ( "-dump-theme" ) >= 0 ) {
if ( find_arg ( "-dump-theme" ) >= 0 ){
rofi_theme_print ( rofi_theme ); rofi_theme_print ( rofi_theme );
exit (EXIT_SUCCESS); exit ( EXIT_SUCCESS );
} }
// Dump. // Dump.
// catch help request // catch help request

View file

@ -10,27 +10,27 @@
#include "view.h" #include "view.h"
/** Logging domain for theme */ /** Logging domain for theme */
#define LOG_DOMAIN "Theme" #define LOG_DOMAIN "Theme"
void yyerror ( YYLTYPE *ylloc, const char *); void yyerror ( YYLTYPE *ylloc, const char * );
static gboolean distance_compare ( Distance d, Distance e ) static gboolean distance_compare ( Distance d, Distance e )
{ {
return ( d.type == e.type && d.distance == e.distance && d.style == e.style ); 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 ) ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *name )
{ {
for ( unsigned int i = 0; i < base->num_widgets;i++){ for ( unsigned int i = 0; i < base->num_widgets; i++ ) {
if ( g_strcmp0(base->widgets[i]->name, name) == 0 ){ if ( g_strcmp0 ( base->widgets[i]->name, name ) == 0 ) {
return base->widgets[i]; return base->widgets[i];
} }
} }
base->widgets = g_realloc ( base->widgets, sizeof(ThemeWidget*)*(base->num_widgets+1)); base->widgets = g_realloc ( base->widgets, sizeof ( ThemeWidget* ) * ( base->num_widgets + 1 ) );
base->widgets[base->num_widgets] = g_malloc0(sizeof(ThemeWidget)); base->widgets[base->num_widgets] = g_malloc0 ( sizeof ( ThemeWidget ) );
ThemeWidget *retv = base->widgets[base->num_widgets]; ThemeWidget *retv = base->widgets[base->num_widgets];
retv->parent = base; retv->parent = base;
retv->name = g_strdup(name); retv->name = g_strdup ( name );
base->num_widgets++; base->num_widgets++;
return retv; return retv;
} }
@ -39,7 +39,7 @@ ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *nam
*/ */
Property *rofi_theme_property_create ( PropertyType type ) Property *rofi_theme_property_create ( PropertyType type )
{ {
Property *retv = g_malloc0 ( sizeof(Property) ); Property *retv = g_malloc0 ( sizeof ( Property ) );
retv->type = type; retv->type = type;
return retv; return retv;
} }
@ -51,21 +51,22 @@ void rofi_theme_property_free ( Property *p )
g_free ( p->name ); g_free ( p->name );
if ( p->type == P_STRING ) { if ( p->type == P_STRING ) {
g_free ( p->value.s ); g_free ( p->value.s );
} else if ( p->type == P_LINK ) { }
else if ( p->type == P_LINK ) {
g_free ( p->value.link.name ); g_free ( p->value.link.name );
} }
g_free(p); g_free ( p );
} }
void rofi_theme_free ( ThemeWidget *widget ) void rofi_theme_free ( ThemeWidget *widget )
{ {
if ( widget == NULL ){ if ( widget == NULL ) {
return; return;
} }
if ( widget->properties ) { if ( widget->properties ) {
g_hash_table_destroy ( widget->properties ); g_hash_table_destroy ( widget->properties );
} }
for ( unsigned int i = 0; i < widget->num_widgets; i++ ){ for ( unsigned int i = 0; i < widget->num_widgets; i++ ) {
rofi_theme_free ( widget->widgets[i] ); rofi_theme_free ( widget->widgets[i] );
} }
g_free ( widget->widgets ); g_free ( widget->widgets );
@ -79,14 +80,16 @@ void rofi_theme_free ( ThemeWidget *widget )
static void rofi_theme_print_distance ( Distance d ) static void rofi_theme_print_distance ( Distance d )
{ {
if ( d.type == PW_PX ) { if ( d.type == PW_PX ) {
printf("%upx ", (int)d.distance ); printf ( "%upx ", (int) d.distance );
} else if ( d.type == PW_PERCENT ) { }
printf("%f%% ", d.distance ); else if ( d.type == PW_PERCENT ) {
} else { printf ( "%f%% ", d.distance );
printf("%fem ", d.distance ); }
else {
printf ( "%fem ", d.distance );
} }
if ( d.style == DASH ) { if ( d.style == DASH ) {
printf("dash "); printf ( "dash " );
} }
} }
/** Textual representation of Window Location */ /** Textual representation of Window Location */
@ -105,56 +108,59 @@ const char const * WindowLocationStr[9] = {
static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p ) static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p )
{ {
int pl = strlen ( p->name ); int pl = strlen ( p->name );
printf("%*s%s:%*s ", depth, "", p->name, (int)pnl-pl,"" ); printf ( "%*s%s:%*s ", depth, "", p->name, (int) pnl - pl, "" );
switch ( p->type ) switch ( p->type )
{ {
case P_POSITION: case P_POSITION:
printf("%s;", WindowLocationStr[p->value.i]); printf ( "%s;", WindowLocationStr[p->value.i] );
break; break;
case P_STRING: case P_STRING:
printf("\"%s\";", p->value.s); printf ( "\"%s\";", p->value.s );
break; break;
case P_INTEGER: case P_INTEGER:
printf("%d;", p->value.i); printf ( "%d;", p->value.i );
break; break;
case P_DOUBLE: case P_DOUBLE:
printf("%.2f;", p->value.f); printf ( "%.2f;", p->value.f );
break; break;
case P_BOOLEAN: case P_BOOLEAN:
printf("%s;", p->value.b?"true":"false"); printf ( "%s;", p->value.b ? "true" : "false" );
break; break;
case P_COLOR: 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.alpha * 255.0 ),
(unsigned char)(p->value.color.red*255.0), (unsigned char) ( p->value.color.red * 255.0 ),
(unsigned char)(p->value.color.green*255.0), (unsigned char) ( p->value.color.green * 255.0 ),
(unsigned char)(p->value.color.blue*255.0)); (unsigned char) ( p->value.color.blue * 255.0 ) );
break; break;
case P_PADDING: case P_PADDING:
if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) && if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) &&
distance_compare ( p->value.padding.left, p->value.padding.right) && distance_compare ( p->value.padding.left, p->value.padding.right ) &&
distance_compare ( p->value.padding.left, p->value.padding.top) ) { distance_compare ( p->value.padding.left, p->value.padding.top ) ) {
rofi_theme_print_distance ( p->value.padding.left ); rofi_theme_print_distance ( p->value.padding.left );
} else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) && }
distance_compare ( p->value.padding.left, p->value.padding.right)){ else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) &&
rofi_theme_print_distance ( p->value.padding.top ); distance_compare ( p->value.padding.left, p->value.padding.right ) ) {
rofi_theme_print_distance ( p->value.padding.left ); rofi_theme_print_distance ( p->value.padding.top );
} else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom) && rofi_theme_print_distance ( p->value.padding.left );
distance_compare ( p->value.padding.left, p->value.padding.right)){ }
rofi_theme_print_distance ( p->value.padding.top ); else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) &&
rofi_theme_print_distance ( p->value.padding.left ); distance_compare ( p->value.padding.left, p->value.padding.right ) ) {
rofi_theme_print_distance ( p->value.padding.bottom); rofi_theme_print_distance ( p->value.padding.top );
} else { rofi_theme_print_distance ( p->value.padding.left );
rofi_theme_print_distance ( p->value.padding.top ); rofi_theme_print_distance ( p->value.padding.bottom );
rofi_theme_print_distance ( p->value.padding.right ); }
rofi_theme_print_distance ( p->value.padding.bottom); else {
rofi_theme_print_distance ( p->value.padding.left ); rofi_theme_print_distance ( p->value.padding.top );
} rofi_theme_print_distance ( p->value.padding.right );
printf(";"); rofi_theme_print_distance ( p->value.padding.bottom );
break; rofi_theme_print_distance ( p->value.padding.left );
case P_LINK: }
printf("%s;", p->value.link.name); printf ( ";" );
break; break;
case P_LINK:
printf ( "%s;", p->value.link.name );
break;
} }
putchar ( '\n' ); putchar ( '\n' );
} }
@ -162,52 +168,51 @@ static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p
static void rofi_theme_print_index ( ThemeWidget *widget ) static void rofi_theme_print_index ( ThemeWidget *widget )
{ {
GHashTableIter iter; GHashTableIter iter;
gpointer key, value; gpointer key, value;
if ( widget->properties ){ if ( widget->properties ) {
int index = 0; int index = 0;
GList *list = NULL; GList *list = NULL;
ThemeWidget *w = widget; ThemeWidget *w = widget;
while ( w){ while ( w ) {
if ( g_strcmp0(w->name,"Root") == 0 ) { if ( g_strcmp0 ( w->name, "Root" ) == 0 ) {
break; break;
} }
list = g_list_prepend ( list, w->name ); list = g_list_prepend ( list, w->name );
w = w->parent; w = w->parent;
} }
if ( g_list_length ( list ) > 0 ) { if ( g_list_length ( list ) > 0 ) {
index = 4; index = 4;
for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) { for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
char *name = (char *)iter->data; char *name = (char *) iter->data;
if ( iter->prev == NULL ){ if ( iter->prev == NULL ) {
putchar ( '#' ); putchar ( '#' );
} }
fputs(name, stdout); fputs ( name, stdout );
if ( iter->next ) { if ( iter->next ) {
putchar('.'); putchar ( '.' );
} }
} }
printf(" {\n"); printf ( " {\n" );
} else { }
else {
index = 4; index = 4;
printf("* {\n"); printf ( "* {\n" );
} }
size_t property_name_length = 0; size_t property_name_length = 0;
g_hash_table_iter_init (&iter, widget->properties); g_hash_table_iter_init ( &iter, widget->properties );
while (g_hash_table_iter_next (&iter, &key, &value)) while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
{ Property *p = (Property *) value;
Property *p = (Property*)value; property_name_length = MAX ( strlen ( p->name ), property_name_length );
property_name_length = MAX ( strlen (p->name), property_name_length );
} }
g_hash_table_iter_init (&iter, widget->properties); g_hash_table_iter_init ( &iter, widget->properties );
while (g_hash_table_iter_next (&iter, &key, &value)) while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
{ Property *p = (Property *) value;
Property *p = (Property*)value;
rofi_theme_print_property_index ( property_name_length, index, p ); rofi_theme_print_property_index ( property_name_length, index, p );
} }
printf("}\n"); printf ( "}\n" );
g_list_free ( list ); g_list_free ( list );
} }
for ( unsigned int i = 0; i < widget->num_widgets;i++){ for ( unsigned int i = 0; i < widget->num_widgets; i++ ) {
rofi_theme_print_index ( widget->widgets[i] ); rofi_theme_print_index ( widget->widgets[i] );
} }
} }
@ -219,12 +224,12 @@ void rofi_theme_print ( ThemeWidget *widget )
/** /**
* Main lex parser. * Main lex parser.
*/ */
int yyparse(); int yyparse ();
/** /**
* Destroy the internal of lex parser. * Destroy the internal of lex parser.
*/ */
void yylex_destroy( void ); void yylex_destroy ( void );
/** /**
* Global handle input file to flex parser. * Global handle input file to flex parser.
@ -237,16 +242,17 @@ extern FILE* yyin;
* *
* Error handler for the lex parser. * Error handler for the lex parser.
*/ */
void yyerror(YYLTYPE *yylloc, const char* s) { void yyerror ( YYLTYPE *yylloc, const char* s )
fprintf(stderr, "Parse error: %s\n", s); {
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); fprintf ( stderr, "Parse error: %s\n", s );
exit(EXIT_FAILURE); 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 );
exit ( EXIT_FAILURE );
} }
static gboolean rofi_theme_steal_property_int ( gpointer key, gpointer value, gpointer user_data) static gboolean rofi_theme_steal_property_int ( gpointer key, gpointer value, gpointer user_data )
{ {
GHashTable *table = (GHashTable*)user_data; GHashTable *table = (GHashTable *) user_data;
g_hash_table_replace ( table, key, value); g_hash_table_replace ( table, key, value );
return TRUE; return TRUE;
} }
void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table ) void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table )
@ -254,7 +260,7 @@ void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table )
if ( table == NULL ) { if ( table == NULL ) {
return; return;
} }
if ( widget->properties == NULL ){ if ( widget->properties == NULL ) {
widget->properties = table; widget->properties = table;
return; return;
} }
@ -262,40 +268,40 @@ void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table )
g_hash_table_destroy ( table ); g_hash_table_destroy ( table );
} }
/** /**
* Public API * Public API
*/ */
static ThemeWidget *rofi_theme_find_single ( ThemeWidget *widget, const char *name) static ThemeWidget *rofi_theme_find_single ( ThemeWidget *widget, const char *name )
{ {
for ( unsigned int j = 0; j < widget->num_widgets;j++){ for ( unsigned int j = 0; j < widget->num_widgets; j++ ) {
if ( g_strcmp0(widget->widgets[j]->name, name ) == 0 ){ if ( g_strcmp0 ( widget->widgets[j]->name, name ) == 0 ) {
return widget->widgets[j]; return widget->widgets[j];
} }
} }
return widget; return widget;
} }
static ThemeWidget *rofi_theme_find ( ThemeWidget *widget , const char *name, const gboolean exact ) static ThemeWidget *rofi_theme_find ( ThemeWidget *widget, const char *name, const gboolean exact )
{ {
if ( widget == NULL || name == NULL ) { if ( widget == NULL || name == NULL ) {
return widget; return widget;
} }
char **names = g_strsplit ( name, "." , 0 ); char **names = g_strsplit ( name, ".", 0 );
int found = TRUE; int found = TRUE;
for ( unsigned int i = 0; found && names && names[i]; i++ ){ for ( unsigned int i = 0; found && names && names[i]; i++ ) {
found = FALSE; found = FALSE;
ThemeWidget *f = rofi_theme_find_single ( widget, names[i]); ThemeWidget *f = rofi_theme_find_single ( widget, names[i] );
if ( f != widget ){ if ( f != widget ) {
widget = f; widget = f;
found = TRUE; found = TRUE;
} }
} }
g_strfreev(names); g_strfreev ( names );
if ( !exact || found ){ if ( !exact || found ) {
return widget; return widget;
} else { }
else {
return NULL; return NULL;
} }
} }
@ -303,24 +309,25 @@ static ThemeWidget *rofi_theme_find ( ThemeWidget *widget , const char *name, co
static void rofi_theme_resolve_link_property ( Property *p, int depth ) static void rofi_theme_resolve_link_property ( Property *p, int depth )
{ {
// Set name, remove '@' prefix. // Set name, remove '@' prefix.
const char *name = p->value.link.name +1; const char *name = p->value.link.name + 1;
if ( depth > 20 ){ if ( depth > 20 ) {
g_log ( LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Found more then 20 redirects for property. Stopping."); g_log ( LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Found more then 20 redirects for property. Stopping." );
p->value.link.ref = p; p->value.link.ref = p;
return; return;
} }
if( g_hash_table_contains ( rofi_theme->properties, name ) ) { if ( g_hash_table_contains ( rofi_theme->properties, name ) ) {
Property *pr = g_hash_table_lookup ( rofi_theme->properties, name ); Property *pr = g_hash_table_lookup ( rofi_theme->properties, name );
if ( pr->type == P_LINK ) { if ( pr->type == P_LINK ) {
if ( pr->value.link.ref == NULL ) { if ( pr->value.link.ref == NULL ) {
rofi_theme_resolve_link_property ( pr, depth+1); rofi_theme_resolve_link_property ( pr, depth + 1 );
} }
if ( pr->value.link.ref != pr ){ if ( pr->value.link.ref != pr ) {
p->value.link.ref = pr->value.link.ref; p->value.link.ref = pr->value.link.ref;
return; return;
} }
} else { }
else {
p->value.link.ref = pr; p->value.link.ref = pr;
return; return;
} }
@ -333,22 +340,22 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth )
static Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, const char *property, gboolean exact ) static Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, const char *property, gboolean exact )
{ {
while ( widget ) { while ( widget ) {
if ( widget->properties && g_hash_table_contains ( widget->properties, property) ) { if ( widget->properties && g_hash_table_contains ( widget->properties, property ) ) {
Property *p = g_hash_table_lookup ( widget->properties, property); Property *p = g_hash_table_lookup ( widget->properties, property );
if ( p->type == P_LINK ) { if ( p->type == P_LINK ) {
if ( p->value.link.ref == NULL ) { if ( p->value.link.ref == NULL ) {
// Resolve link. // Resolve link.
rofi_theme_resolve_link_property ( p, 0 ); rofi_theme_resolve_link_property ( p, 0 );
} }
if ( p->value.link.ref->type == type ){ if ( p->value.link.ref->type == type ) {
return p->value.link.ref; return p->value.link.ref;
} }
} }
if ( p->type == type ){ if ( p->type == type ) {
return p; return p;
} }
// Padding and integer can be converted. // Padding and integer can be converted.
if ( p->type == P_INTEGER && type == P_PADDING ){ if ( p->type == P_INTEGER && type == P_PADDING ) {
return p; return p;
} }
} }
@ -371,125 +378,129 @@ static ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state
int rofi_theme_get_position ( const widget *widget, const char *property, int def ) int rofi_theme_get_position ( const widget *widget, const char *property, int def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_POSITION, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_POSITION, property, FALSE );
if ( p ){ if ( p ) {
return p->value.i; return p->value.i;
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def; return def;
} }
int rofi_theme_get_integer ( const widget *widget, const char *property, int def ) int rofi_theme_get_integer ( const widget *widget, const char *property, int def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_INTEGER, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_INTEGER, property, FALSE );
if ( p ){ if ( p ) {
return p->value.i; return p->value.i;
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def; return def;
} }
int rofi_theme_get_integer_exact ( const widget *widget, const char *property, int def ) int rofi_theme_get_integer_exact ( const widget *widget, const char *property, int def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, TRUE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, TRUE );
Property *p = rofi_theme_find_property ( wid, P_INTEGER, property, TRUE ); Property *p = rofi_theme_find_property ( wid, P_INTEGER, property, TRUE );
if ( p ){ if ( p ) {
return p->value.i; return p->value.i;
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def; return def;
} }
Distance rofi_theme_get_distance ( const widget *widget, const char *property, int def ) Distance rofi_theme_get_distance ( const widget *widget, const char *property, int def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_PADDING, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_PADDING, property, FALSE );
if ( p ){ if ( p ) {
if ( p->type == P_INTEGER ){ if ( p->type == P_INTEGER ) {
return (Distance){p->value.i,PW_PX, SOLID}; return (Distance){ p->value.i, PW_PX, SOLID };
} else { }
else {
return p->value.padding.left; return p->value.padding.left;
} }
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return (Distance){def, PW_PX, SOLID}; return (Distance){ def, PW_PX, SOLID };
} }
int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ) int rofi_theme_get_boolean ( const widget *widget, const char *property, int def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_BOOLEAN, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_BOOLEAN, property, FALSE );
if ( p ){ if ( p ) {
return p->value.b; return p->value.b;
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def; return def;
} }
char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ) char *rofi_theme_get_string ( const widget *widget, const char *property, char *def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_STRING, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_STRING, property, FALSE );
if ( p ){ if ( p ) {
return p->value.s; return p->value.s;
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def; return def;
} }
double rofi_theme_get_double ( const widget *widget, const char *property, double def ) double rofi_theme_get_double ( const widget *widget, const char *property, double def )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_DOUBLE, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_DOUBLE, property, FALSE );
if ( p ){ if ( p ) {
return p->value.b; return p->value.b;
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def; return def;
} }
void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d) void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_COLOR, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_COLOR, property, FALSE );
if ( p ){ if ( p ) {
cairo_set_source_rgba ( d, cairo_set_source_rgba ( d,
p->value.color.red, p->value.color.red,
p->value.color.green, p->value.color.green,
p->value.color.blue, p->value.color.blue,
p->value.color.alpha p->value.color.alpha
); );
} else { }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); else {
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
} }
} }
Padding rofi_theme_get_padding ( const widget *widget, const char *property, Padding pad ) Padding rofi_theme_get_padding ( const widget *widget, const char *property, Padding pad )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_PADDING, property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_PADDING, property, FALSE );
if ( p ){ if ( p ) {
if ( p->type == P_PADDING ){ if ( p->type == P_PADDING ) {
pad = p->value.padding; pad = p->value.padding;
} else { }
Distance d = (Distance){p->value.i, PW_PX, SOLID}; else {
return (Padding){d,d,d,d}; Distance d = (Distance){ p->value.i, PW_PX, SOLID };
return (Padding){ d, d, d, d };
} }
} }
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return pad; return pad;
} }
int distance_get_pixel ( Distance d, Orientation ori ) int distance_get_pixel ( Distance d, Orientation ori )
{ {
if ( d.type == PW_EM ){ if ( d.type == PW_EM ) {
return d.distance*textbox_get_estimated_char_height(); return d.distance * textbox_get_estimated_char_height ();
} else if ( d.type == PW_PERCENT ) { }
if ( ori == ORIENTATION_VERTICAL ){ else if ( d.type == PW_PERCENT ) {
if ( ori == ORIENTATION_VERTICAL ) {
int height = 0; int height = 0;
rofi_view_get_current_monitor ( NULL, &height ); rofi_view_get_current_monitor ( NULL, &height );
return (d.distance*height)/(100.0); return ( d.distance * height ) / ( 100.0 );
} else { }
else {
int width = 0; int width = 0;
rofi_view_get_current_monitor ( &width, NULL ); rofi_view_get_current_monitor ( &width, NULL );
return (d.distance*width)/(100.0); return ( d.distance * width ) / ( 100.0 );
} }
} }
return d.distance; return d.distance;
@ -497,11 +508,12 @@ int distance_get_pixel ( Distance d, Orientation ori )
void distance_get_linestyle ( Distance d, cairo_t *draw ) void distance_get_linestyle ( Distance d, cairo_t *draw )
{ {
if ( d.style == DASH ){ if ( d.style == 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 );
} else { }
cairo_set_dash ( draw, NULL, 0, 0.0); else {
cairo_set_dash ( draw, NULL, 0, 0.0 );
} }
} }
@ -509,9 +521,9 @@ void distance_get_linestyle ( Distance d, cairo_t *draw )
static Property* rofi_theme_convert_get_color ( const char *color, const char *name ) static Property* rofi_theme_convert_get_color ( const char *color, const char *name )
{ {
Color c = color_get ( color ); Color c = color_get ( color );
Property *p = rofi_theme_property_create ( P_COLOR ); Property *p = rofi_theme_property_create ( P_COLOR );
p->name = g_strdup(name); p->name = g_strdup ( name );
p->value.color.alpha = c.alpha; p->value.color.alpha = c.alpha;
p->value.color.red = c.red; p->value.color.red = c.red;
p->value.color.green = c.green; p->value.color.green = c.green;
@ -522,130 +534,131 @@ static Property* rofi_theme_convert_get_color ( const char *color, const char *n
static void rofi_theme_convert_create_property_ht ( ThemeWidget *widget ) static void rofi_theme_convert_create_property_ht ( ThemeWidget *widget )
{ {
if ( widget->properties == NULL ) { if ( widget->properties == NULL ) {
widget->properties = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify)rofi_theme_property_free ); widget->properties = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free );
} }
} }
void rofi_theme_convert_old_theme ( void ) void rofi_theme_convert_old_theme ( void )
{ {
if ( rofi_theme != NULL ){ if ( rofi_theme != NULL ) {
return; return;
} }
rofi_theme = (ThemeWidget*)g_malloc0 ( sizeof ( ThemeWidget ) ); rofi_theme = (ThemeWidget *) g_malloc0 ( sizeof ( ThemeWidget ) );
rofi_theme->name = g_strdup ( "Root" ); rofi_theme->name = g_strdup ( "Root" );
rofi_theme_convert_create_property_ht ( rofi_theme ); rofi_theme_convert_create_property_ht ( rofi_theme );
ThemeWidget *window_widget = rofi_theme_find_or_create_name ( rofi_theme , "window" ); ThemeWidget *window_widget = rofi_theme_find_or_create_name ( rofi_theme, "window" );
rofi_theme_convert_create_property_ht ( window_widget ); rofi_theme_convert_create_property_ht ( window_widget );
ThemeWidget *mainbox_widget = rofi_theme_find_or_create_name ( window_widget, "mainbox" ); ThemeWidget *mainbox_widget = rofi_theme_find_or_create_name ( window_widget, "mainbox" );
rofi_theme_convert_create_property_ht ( mainbox_widget ); rofi_theme_convert_create_property_ht ( mainbox_widget );
ThemeWidget *message = rofi_theme_find_or_create_name ( mainbox_widget, "message" ); ThemeWidget *message = rofi_theme_find_or_create_name ( mainbox_widget, "message" );
ThemeWidget *message_box = rofi_theme_find_or_create_name ( message, "box" ); ThemeWidget *message_box = rofi_theme_find_or_create_name ( message, "box" );
rofi_theme_convert_create_property_ht ( message_box ); rofi_theme_convert_create_property_ht ( message_box );
ThemeWidget *listview_widget = rofi_theme_find_or_create_name ( mainbox_widget, "listview" ); ThemeWidget *listview_widget = rofi_theme_find_or_create_name ( mainbox_widget, "listview" );
rofi_theme_convert_create_property_ht ( listview_widget ); rofi_theme_convert_create_property_ht ( listview_widget );
ThemeWidget *sidebar_widget = rofi_theme_find_or_create_name ( mainbox_widget, "sidebar" ); ThemeWidget *sidebar_widget = rofi_theme_find_or_create_name ( mainbox_widget, "sidebar" );
ThemeWidget *sidebarbox_widget = rofi_theme_find_or_create_name ( sidebar_widget, "box" ); ThemeWidget *sidebarbox_widget = rofi_theme_find_or_create_name ( sidebar_widget, "box" );
rofi_theme_convert_create_property_ht ( sidebarbox_widget ); rofi_theme_convert_create_property_ht ( sidebarbox_widget );
{ {
Property *p = rofi_theme_property_create ( P_INTEGER ); Property *p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup ("border"); p->name = g_strdup ( "border" );
p->value.i = 0; p->value.i = 0;
g_hash_table_replace ( mainbox_widget->properties, p->name, p); g_hash_table_replace ( mainbox_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup ("padding"); p->name = g_strdup ( "padding" );
p->value.i = config.padding; p->value.i = config.padding;
g_hash_table_replace ( window_widget->properties, p->name, p); g_hash_table_replace ( window_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup ("padding"); p->name = g_strdup ( "padding" );
p->value.i = 0; p->value.i = 0;
g_hash_table_replace ( mainbox_widget->properties, p->name, p); g_hash_table_replace ( mainbox_widget->properties, p->name, p );
// Spacing // Spacing
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup("spacing"); p->name = g_strdup ( "spacing" );
p->value.i = config.line_margin; p->value.i = config.line_margin;
g_hash_table_replace ( rofi_theme->properties, p->name, p ); g_hash_table_replace ( rofi_theme->properties, p->name, p );
} }
{ {
// Background // Background
Property *p = rofi_theme_property_create ( P_COLOR ); Property *p = rofi_theme_property_create ( P_COLOR );
p->name = g_strdup("background"); p->name = g_strdup ( "background" );
p->value.color.alpha = 0; p->value.color.alpha = 0;
p->value.color.red = 0; p->value.color.red = 0;
p->value.color.green= 0; p->value.color.green = 0;
p->value.color.blue= 0; p->value.color.blue = 0;
g_hash_table_replace ( rofi_theme->properties, p->name, p ); g_hash_table_replace ( rofi_theme->properties, p->name, p );
ThemeWidget *inputbar_widget = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" ); ThemeWidget *inputbar_widget = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" );
rofi_theme_convert_create_property_ht ( inputbar_widget ); rofi_theme_convert_create_property_ht ( inputbar_widget );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup("spacing"); p->name = g_strdup ( "spacing" );
p->value.i = 0; p->value.i = 0;
g_hash_table_replace ( inputbar_widget->properties, p->name, p ); g_hash_table_replace ( inputbar_widget->properties, p->name, p );
LineStyle style = ( g_strcmp0 ( config.separator_style, "dash" ) == 0 ) ? DASH : SOLID;
LineStyle style = (g_strcmp0(config.separator_style,"dash") == 0)?DASH:SOLID; int place_end = ( config.location == WL_SOUTH_EAST || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST );
int place_end = ( config.location == WL_SOUTH_EAST || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST ); p = rofi_theme_property_create ( P_PADDING );
p = rofi_theme_property_create ( P_PADDING ); p->name = g_strdup ( "border" );
p->name = g_strdup("border"); Distance d = (Distance){ config.menu_bw, PW_PX, style };
Distance d = (Distance){config.menu_bw, PW_PX, style}; if ( place_end ) {
if ( place_end ){ p->value.padding.bottom = d;
p->value.padding.bottom= d; }
} else { else {
p->value.padding.top= d; p->value.padding.top = d;
} }
g_hash_table_replace ( listview_widget->properties, p->name, p ); g_hash_table_replace ( listview_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_PADDING );
p = rofi_theme_property_create ( P_PADDING ); p->name = g_strdup ( "border" );
p->name = g_strdup("border"); d = (Distance){ config.menu_bw, PW_PX, style };
d = (Distance){config.menu_bw, PW_PX, style}; if ( place_end ) {
if ( place_end ){ p->value.padding.bottom = d;
p->value.padding.bottom= d; }
} else { else {
p->value.padding.top= d; p->value.padding.top = d;
} }
g_hash_table_replace ( message_box->properties, p->name, p ); g_hash_table_replace ( message_box->properties, p->name, p );
/** /**
* Sidebar top * Sidebar top
*/ */
p = rofi_theme_property_create ( P_PADDING ); p = rofi_theme_property_create ( P_PADDING );
p->name = g_strdup("border"); p->name = g_strdup ( "border" );
d = (Distance){config.menu_bw, PW_PX, style}; d = (Distance){ config.menu_bw, PW_PX, style };
p->value.padding.top= d; p->value.padding.top = d;
g_hash_table_replace ( sidebarbox_widget->properties, p->name, p ); g_hash_table_replace ( sidebarbox_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_PADDING ); p = rofi_theme_property_create ( P_PADDING );
p->name = g_strdup("padding"); p->name = g_strdup ( "padding" );
d = (Distance){config.line_margin, PW_PX, SOLID}; d = (Distance){ config.line_margin, PW_PX, SOLID };
if ( place_end ){ if ( place_end ) {
p->value.padding.bottom= d; p->value.padding.bottom = d;
} else { }
p->value.padding.top= d; else {
p->value.padding.top = d;
} }
g_hash_table_replace ( listview_widget->properties, p->name, p ); g_hash_table_replace ( listview_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_PADDING ); p = rofi_theme_property_create ( P_PADDING );
p->name = g_strdup("padding"); p->name = g_strdup ( "padding" );
d = (Distance){config.line_margin, PW_PX, SOLID}; d = (Distance){ config.line_margin, PW_PX, SOLID };
if ( place_end ){ if ( place_end ) {
p->value.padding.bottom= d; p->value.padding.bottom = d;
} else { }
p->value.padding.top= d; else {
p->value.padding.top = d;
} }
g_hash_table_replace ( message_box->properties, p->name, p ); g_hash_table_replace ( message_box->properties, p->name, p );
} }
{ {
Property *p = rofi_theme_property_create ( P_INTEGER ); Property *p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup("columns"); p->name = g_strdup ( "columns" );
p->value.i = config.menu_columns; p->value.i = config.menu_columns;
g_hash_table_replace ( listview_widget->properties, p->name, p ); g_hash_table_replace ( listview_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup("fixed-height"); p->name = g_strdup ( "fixed-height" );
p->value.i = !(config.fixed_num_lines); p->value.i = !( config.fixed_num_lines );
g_hash_table_replace ( listview_widget->properties, p->name, p ); g_hash_table_replace ( listview_widget->properties, p->name, p );
} }
{ {
@ -653,18 +666,18 @@ void rofi_theme_convert_old_theme ( void )
rofi_theme_convert_create_property_ht ( window_widget ); rofi_theme_convert_create_property_ht ( window_widget );
// Padding // Padding
Property *p = rofi_theme_property_create ( P_INTEGER ); Property *p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup("padding"); p->name = g_strdup ( "padding" );
p->value.i = config.padding; p->value.i = config.padding;
g_hash_table_replace ( window_widget->properties, p->name, p ); g_hash_table_replace ( window_widget->properties, p->name, p );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup("border"); p->name = g_strdup ( "border" );
p->value.i = config.menu_bw; p->value.i = config.menu_bw;
g_hash_table_replace ( window_widget->properties, p->name, p ); g_hash_table_replace ( window_widget->properties, p->name, p );
} }
{ {
gchar **vals = g_strsplit ( config.color_window, ",", 3 ); gchar **vals = g_strsplit ( config.color_window, ",", 3 );
if ( vals != NULL ){ if ( vals != NULL ) {
if ( vals[0] != NULL ) { if ( vals[0] != NULL ) {
Property *p = rofi_theme_convert_get_color ( vals[0], "background" ); Property *p = rofi_theme_convert_get_color ( vals[0], "background" );
g_hash_table_replace ( window_widget->properties, p->name, p ); g_hash_table_replace ( window_widget->properties, p->name, p );
@ -674,49 +687,47 @@ void rofi_theme_convert_old_theme ( void )
g_hash_table_replace ( window_widget->properties, p->name, p ); g_hash_table_replace ( window_widget->properties, p->name, p );
ThemeWidget *inputbar = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" ); ThemeWidget *inputbar = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" );
ThemeWidget *widget = rofi_theme_find_or_create_name ( inputbar, "box" ); ThemeWidget *widget = rofi_theme_find_or_create_name ( inputbar, "box" );
rofi_theme_convert_create_property_ht ( widget ); rofi_theme_convert_create_property_ht ( widget );
if ( vals[2] != NULL ) { if ( vals[2] != NULL ) {
p = rofi_theme_convert_get_color ( vals[2], "foreground" ); p = rofi_theme_convert_get_color ( vals[2], "foreground" );
g_hash_table_replace ( window_widget->properties, p->name, p ); g_hash_table_replace ( window_widget->properties, p->name, p );
} else { }
p = rofi_theme_convert_get_color ( vals[1], "foreground" ); else {
g_hash_table_replace ( window_widget->properties, p->name, p ); p = rofi_theme_convert_get_color ( vals[1], "foreground" );
} g_hash_table_replace ( window_widget->properties, p->name, p );
}
} }
} }
} }
g_strfreev ( vals ); g_strfreev ( vals );
{ {
Property *p = NULL; Property *p = NULL;
ThemeWidget *widget = rofi_theme_find_or_create_name ( listview_widget, "element" ); ThemeWidget *widget = rofi_theme_find_or_create_name ( listview_widget, "element" );
ThemeWidget *scrollbar = rofi_theme_find_or_create_name ( listview_widget, "scrollbar" ); ThemeWidget *scrollbar = rofi_theme_find_or_create_name ( listview_widget, "scrollbar" );
ThemeWidget *wnormal = rofi_theme_find_or_create_name ( widget, "normal" );
ThemeWidget *wnormal = rofi_theme_find_or_create_name ( widget, "normal" ); ThemeWidget *wselected = rofi_theme_find_or_create_name ( widget, "selected" );
ThemeWidget *wselected = rofi_theme_find_or_create_name ( widget, "selected" );
ThemeWidget *walternate = rofi_theme_find_or_create_name ( widget, "alternate" ); ThemeWidget *walternate = rofi_theme_find_or_create_name ( widget, "alternate" );
rofi_theme_convert_create_property_ht ( widget ); rofi_theme_convert_create_property_ht ( widget );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup ("border"); p->name = g_strdup ( "border" );
p->value.i = 0; p->value.i = 0;
g_hash_table_replace ( widget->properties, p->name, p); g_hash_table_replace ( widget->properties, p->name, p );
rofi_theme_convert_create_property_ht ( scrollbar ); rofi_theme_convert_create_property_ht ( scrollbar );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup ("border"); p->name = g_strdup ( "border" );
p->value.i = 0; p->value.i = 0;
g_hash_table_replace ( scrollbar->properties, p->name, p); g_hash_table_replace ( scrollbar->properties, p->name, p );
p = rofi_theme_property_create ( P_INTEGER ); p = rofi_theme_property_create ( P_INTEGER );
p->name = g_strdup ("padding"); p->name = g_strdup ( "padding" );
p->value.i = 0; p->value.i = 0;
g_hash_table_replace ( scrollbar->properties, p->name, p); g_hash_table_replace ( scrollbar->properties, p->name, p );
gchar **vals = g_strsplit ( config.color_normal, ",", 5 ); gchar **vals = g_strsplit ( config.color_normal, ",", 5 );
if ( g_strv_length (vals) == 5 ) { if ( g_strv_length ( vals ) == 5 ) {
ThemeWidget *wnn = rofi_theme_find_or_create_name ( wnormal, "normal" ); ThemeWidget *wnn = rofi_theme_find_or_create_name ( wnormal, "normal" );
rofi_theme_convert_create_property_ht ( wnn ); rofi_theme_convert_create_property_ht ( wnn );
p = rofi_theme_convert_get_color ( vals[0], "background" ); p = rofi_theme_convert_get_color ( vals[0], "background" );
@ -756,7 +767,7 @@ void rofi_theme_convert_old_theme ( void )
g_strfreev ( vals ); g_strfreev ( vals );
vals = g_strsplit ( config.color_urgent, ",", 5 ); vals = g_strsplit ( config.color_urgent, ",", 5 );
if ( g_strv_length (vals) == 5 ) { if ( g_strv_length ( vals ) == 5 ) {
ThemeWidget *wnn = rofi_theme_find_or_create_name ( wnormal, "urgent" ); ThemeWidget *wnn = rofi_theme_find_or_create_name ( wnormal, "urgent" );
rofi_theme_convert_create_property_ht ( wnn ); rofi_theme_convert_create_property_ht ( wnn );
p = rofi_theme_convert_get_color ( vals[0], "background" ); p = rofi_theme_convert_get_color ( vals[0], "background" );
@ -781,7 +792,7 @@ void rofi_theme_convert_old_theme ( void )
g_strfreev ( vals ); g_strfreev ( vals );
vals = g_strsplit ( config.color_active, ",", 5 ); vals = g_strsplit ( config.color_active, ",", 5 );
if ( g_strv_length (vals) == 5 ) { if ( g_strv_length ( vals ) == 5 ) {
ThemeWidget *wnn = rofi_theme_find_or_create_name ( wnormal, "active" ); ThemeWidget *wnn = rofi_theme_find_or_create_name ( wnormal, "active" );
rofi_theme_convert_create_property_ht ( wnn ); rofi_theme_convert_create_property_ht ( wnn );
p = rofi_theme_convert_get_color ( vals[0], "background" ); p = rofi_theme_convert_get_color ( vals[0], "background" );
@ -810,31 +821,35 @@ void rofi_theme_convert_old_theme ( void )
gboolean rofi_theme_parse_file ( const char *file ) gboolean rofi_theme_parse_file ( const char *file )
{ {
char *filename = rofi_expand_path ( file ); char *filename = rofi_expand_path ( file );
yyin = fopen ( filename, "rb"); yyin = fopen ( filename, "rb" );
if ( yyin == NULL ){ if ( yyin == NULL ) {
fprintf(stderr, "Failed to open file: %s: '%s'\n", filename, strerror ( errno ) ); fprintf ( stderr, "Failed to open file: %s: '%s'\n", filename, strerror ( errno ) );
g_free(filename); g_free ( filename );
return TRUE; return TRUE;
} }
extern int str_len; extern int str_len;
extern const char*input_str; extern const char*input_str;
str_len = 0; str_len = 0;
input_str = NULL; input_str = NULL;
while ( yyparse() ); while ( yyparse () ) {
yylex_destroy(); ;
g_free(filename); }
yylex_destroy ();
g_free ( filename );
yyin = NULL; yyin = NULL;
return FALSE; return FALSE;
} }
gboolean rofi_theme_parse_string ( const char *string ) gboolean rofi_theme_parse_string ( const char *string )
{ {
extern int str_len; extern int str_len;
extern const char*input_str; extern const char*input_str;
yyin = NULL; yyin = NULL;
input_str = string; input_str = string;
str_len = strlen ( string ); str_len = strlen ( string );
while ( yyparse () ); while ( yyparse () ) {
yylex_destroy(); ;
}
yylex_destroy ();
return TRUE; return TRUE;
} }
#endif #endif

View file

@ -86,33 +86,33 @@ RofiViewState *current_active_menu = NULL;
struct struct
{ {
/** main x11 windows */ /** main x11 windows */
xcb_window_t main_window; xcb_window_t main_window;
/** surface containing the fake background. */ /** surface containing the fake background. */
cairo_surface_t *fake_bg; cairo_surface_t *fake_bg;
/** Draw context for main window */ /** Draw context for main window */
xcb_gcontext_t gc; xcb_gcontext_t gc;
/** Main X11 side pixmap to draw on. */ /** Main X11 side pixmap to draw on. */
xcb_pixmap_t edit_pixmap; xcb_pixmap_t edit_pixmap;
/** Cairo Surface for edit_pixmap */ /** Cairo Surface for edit_pixmap */
cairo_surface_t *edit_surf; cairo_surface_t *edit_surf;
/** Drawable context for edit_surf */ /** Drawable context for edit_surf */
cairo_t *edit_draw; cairo_t *edit_draw;
/** Indicate that fake background should be drawn relative to the window */ /** Indicate that fake background should be drawn relative to the window */
int fake_bgrel; int fake_bgrel;
/** Main flags */ /** Main flags */
MenuFlags flags; MenuFlags flags;
/** List of stacked views */ /** List of stacked views */
GQueue views; GQueue views;
/** Current work area */ /** Current work area */
workarea mon; workarea mon;
/** timeout for reloading */ /** timeout for reloading */
guint idle_timeout; guint idle_timeout;
/** debug counter for redraws */ /** debug counter for redraws */
unsigned long long count; unsigned long long count;
/** redraw idle time. */ /** redraw idle time. */
guint repaint_source; guint repaint_source;
/** Window fullscreen */ /** Window fullscreen */
gboolean fullscreen; gboolean fullscreen;
} CacheState = { } CacheState = {
.main_window = XCB_WINDOW_NONE, .main_window = XCB_WINDOW_NONE,
.fake_bg = NULL, .fake_bg = NULL,
@ -124,15 +124,15 @@ struct
.idle_timeout = 0, .idle_timeout = 0,
.count = 0L, .count = 0L,
.repaint_source = 0, .repaint_source = 0,
.fullscreen = FALSE, .fullscreen = FALSE,
}; };
void rofi_view_get_current_monitor ( int *width, int *height) void rofi_view_get_current_monitor ( int *width, int *height )
{ {
if (width ){ if ( width ) {
*width = CacheState.mon.w; *width = CacheState.mon.w;
} }
if (height){ if ( height ) {
*height = CacheState.mon.h; *height = CacheState.mon.h;
} }
} }
@ -224,7 +224,7 @@ static gboolean rofi_view_repaint ( G_GNUC_UNUSED void * data )
// Repaint the view (if needed). // Repaint the view (if needed).
// After a resize the edit_pixmap surface might not contain anything anymore. // After a resize the edit_pixmap surface might not contain anything anymore.
// If we already re-painted, this does nothing. // If we already re-painted, this does nothing.
rofi_view_update (current_active_menu, FALSE); rofi_view_update ( current_active_menu, FALSE );
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "expose event" ); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "expose event" );
TICK_N ( "Expose" ); TICK_N ( "Expose" );
xcb_copy_area ( xcb->connection, CacheState.edit_pixmap, CacheState.main_window, CacheState.gc, xcb_copy_area ( xcb->connection, CacheState.edit_pixmap, CacheState.main_window, CacheState.gc,
@ -257,14 +257,16 @@ static void rofi_view_update_prompt ( RofiViewState *state )
static void rofi_view_calculate_window_position ( RofiViewState *state ) static void rofi_view_calculate_window_position ( RofiViewState *state )
{ {
int location = rofi_theme_get_position ( WIDGET ( state->main_window ), "location", config.location ); int location = rofi_theme_get_position ( WIDGET ( state->main_window ), "location", config.location );
int anchor = location; int anchor = location;
if ( !listview_get_fixed_num_lines ( state->list_view ) ) { if ( !listview_get_fixed_num_lines ( state->list_view ) ) {
anchor = location; anchor = location;
if ( location == WL_CENTER ) { if ( location == WL_CENTER ) {
anchor = WL_NORTH; anchor = WL_NORTH;
} else if ( location == WL_EAST ) { }
else if ( location == WL_EAST ) {
anchor = WL_NORTH_EAST; anchor = WL_NORTH_EAST;
} else if (location == WL_WEST ) { }
else if ( location == WL_WEST ) {
anchor = WL_NORTH_WEST; anchor = WL_NORTH_WEST;
} }
} }
@ -306,38 +308,38 @@ static void rofi_view_calculate_window_position ( RofiViewState *state )
} }
switch ( anchor ) switch ( anchor )
{ {
case WL_SOUTH_WEST: case WL_SOUTH_WEST:
state->y -= state->height; state->y -= state->height;
break; break;
case WL_SOUTH: case WL_SOUTH:
state->x -= state->width/2; state->x -= state->width / 2;
state->y -= state->height; state->y -= state->height;
break; break;
case WL_SOUTH_EAST: case WL_SOUTH_EAST:
state->x -= state->width; state->x -= state->width;
state->y -= state->height; state->y -= state->height;
break; break;
case WL_NORTH_EAST: case WL_NORTH_EAST:
state->x -= state->width; state->x -= state->width;
break; break;
case WL_NORTH_WEST: case WL_NORTH_WEST:
break; break;
case WL_NORTH: case WL_NORTH:
state->x -= state->width/2; state->x -= state->width / 2;
break; break;
case WL_EAST: case WL_EAST:
state->x -= state->width; state->x -= state->width;
state->y -= state->height/2; state->y -= state->height / 2;
break; break;
case WL_WEST: case WL_WEST:
state->y -= state->height/2; state->y -= state->height / 2;
break; break;
case WL_CENTER: case WL_CENTER:
state->y -= state->height/2; state->y -= state->height / 2;
state->x -= state->width/2; state->x -= state->width / 2;
break; break;
default: default:
break; break;
} }
// Apply offset. // Apply offset.
state->x += config.x_offset; state->x += config.x_offset;
@ -568,7 +570,7 @@ static void rofi_view_setup_fake_transparency ( const char const *fake_backgroun
* Current options: 'real', 'screenshot','background' * Current options: 'real', 'screenshot','background'
*/ */
TICK_N ( "Fake start" ); TICK_N ( "Fake start" );
if ( g_strcmp0 ( fake_background, "real" ) == 0 ){ if ( g_strcmp0 ( fake_background, "real" ) == 0 ) {
return; return;
} }
else if ( g_strcmp0 ( fake_background, "screenshot" ) == 0 ) { else if ( g_strcmp0 ( fake_background, "screenshot" ) == 0 ) {
@ -611,9 +613,9 @@ static void rofi_view_setup_fake_transparency ( const char const *fake_backgroun
} }
void __create_window ( MenuFlags menu_flags ) void __create_window ( MenuFlags menu_flags )
{ {
uint32_t selmask = XCB_CW_BACK_PIXMAP| XCB_CW_BORDER_PIXEL |XCB_CW_BIT_GRAVITY| XCB_CW_BACKING_STORE | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; uint32_t selmask = XCB_CW_BACK_PIXMAP | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY | XCB_CW_BACKING_STORE | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
uint32_t selval[] = { uint32_t selval[] = {
XCB_BACK_PIXMAP_NONE,0, XCB_BACK_PIXMAP_NONE, 0,
XCB_GRAVITY_STATIC, XCB_GRAVITY_STATIC,
XCB_BACKING_STORE_NOT_USEFUL, XCB_BACKING_STORE_NOT_USEFUL,
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
@ -622,14 +624,14 @@ void __create_window ( MenuFlags menu_flags )
map map
}; };
xcb_window_t box = xcb_generate_id ( xcb->connection ); xcb_window_t box = xcb_generate_id ( xcb->connection );
xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box, xcb_stuff_get_root_window ( xcb ), xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box, xcb_stuff_get_root_window ( xcb ),
0, 0, 200, 100, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, 0, 0, 200, 100, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
visual->visual_id, selmask, selval ); visual->visual_id, selmask, selval );
xcb_generic_error_t *error; xcb_generic_error_t *error;
error = xcb_request_check(xcb->connection, cc); error = xcb_request_check ( xcb->connection, cc );
if (error) { if ( error ) {
printf( "xcb_create_window() failed error=0x%x\n", error->error_code); printf ( "xcb_create_window() failed error=0x%x\n", error->error_code );
exit ( EXIT_FAILURE ); exit ( EXIT_FAILURE );
} }
CacheState.gc = xcb_generate_id ( xcb->connection ); CacheState.gc = xcb_generate_id ( xcb->connection );
@ -658,8 +660,8 @@ void __create_window ( MenuFlags menu_flags )
} }
// Setup font. // Setup font.
// Dummy widget. // Dummy widget.
container *win = container_create ( "window" ); container *win = container_create ( "window" );
char *font = rofi_theme_get_string ( WIDGET ( win ), "font" , config.menu_font ); char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
if ( font ) { if ( font ) {
PangoFontDescription *pfd = pango_font_description_from_string ( font ); PangoFontDescription *pfd = pango_font_description_from_string ( font );
pango_context_set_font_description ( p, pfd ); pango_context_set_font_description ( p, pfd );
@ -682,7 +684,7 @@ void __create_window ( MenuFlags menu_flags )
x11_disable_decoration ( box ); x11_disable_decoration ( box );
} }
CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET (win ), "fullscreen", config.fullscreen ); CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", config.fullscreen );
if ( CacheState.fullscreen ) { if ( CacheState.fullscreen ) {
xcb_atom_t atoms[] = { xcb_atom_t atoms[] = {
xcb->ewmh._NET_WM_STATE_FULLSCREEN, xcb->ewmh._NET_WM_STATE_FULLSCREEN,
@ -699,8 +701,8 @@ void __create_window ( MenuFlags menu_flags )
CacheState.flags = menu_flags; CacheState.flags = menu_flags;
monitor_active ( &( CacheState.mon ) ); monitor_active ( &( CacheState.mon ) );
char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL); char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL );
if ( transparency == NULL && config.fake_transparency ){ if ( transparency == NULL && config.fake_transparency ) {
transparency = config.fake_background; transparency = config.fake_background;
} }
if ( transparency ) { if ( transparency ) {
@ -869,7 +871,7 @@ void rofi_view_update ( RofiViewState *state, gboolean qr )
} }
else { else {
// Paint the background transparent. // Paint the background transparent.
cairo_set_source_rgba ( d, 0,0,0,0.0); cairo_set_source_rgba ( d, 0, 0, 0, 0.0 );
cairo_paint ( d ); cairo_paint ( d );
} }
TICK_N ( "Background" ); TICK_N ( "Background" );
@ -904,8 +906,8 @@ static void rofi_view_paste ( RofiViewState *state, xcb_selection_notify_event_t
if ( text != NULL && text[0] != '\0' ) { if ( text != NULL && text[0] != '\0' ) {
unsigned int dl = strlen ( text ); unsigned int dl = strlen ( text );
// Strip new line // Strip new line
for ( unsigned int i = 0; i < dl; i++){ for ( unsigned int i = 0; i < dl; i++ ) {
if ( text[i] == '\n' ){ if ( text[i] == '\n' ) {
dl = i; dl = i;
} }
} }
@ -1040,7 +1042,7 @@ static void rofi_view_refilter ( RofiViewState *state )
} }
// Make sure we enable fixed num lines when in normal window mode. // Make sure we enable fixed num lines when in normal window mode.
if ( (CacheState.flags&MENU_NORMAL_WINDOW) == 0 ){ if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
int height = rofi_view_calculate_height ( state ); int height = rofi_view_calculate_height ( state );
if ( height != state->height ) { if ( height != state->height ) {
state->height = height; state->height = height;
@ -1338,7 +1340,7 @@ 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 );
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Re-size window based external request: %d %d\n", state->width, state->height); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Re-size window based external request: %d %d\n", state->width, state->height );
widget_resize ( WIDGET ( state->main_window ), state->width, state->height ); widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
} }
} }
@ -1346,7 +1348,7 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *ev, xkb_st
} }
case XCB_FOCUS_IN: case XCB_FOCUS_IN:
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) { if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
take_keyboard ( CacheState.main_window, 1); take_keyboard ( CacheState.main_window, 1 );
} }
break; break;
case XCB_FOCUS_OUT: case XCB_FOCUS_OUT:
@ -1495,10 +1497,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
TICK_N ( "Get active monitor" ); TICK_N ( "Get active monitor" );
state->main_window = container_create ( "window" ); state->main_window = container_create ( "window" );
state->main_box = box_create ( "window.mainbox.box", BOX_VERTICAL ); state->main_box = box_create ( "window.mainbox.box", BOX_VERTICAL );
container_add ( state->main_window, WIDGET ( state->main_box ) ); container_add ( state->main_window, WIDGET ( state->main_box ) );
state->input_bar = box_create ( "window.mainbox.inputbar.box", BOX_HORIZONTAL ); state->input_bar = box_create ( "window.mainbox.inputbar.box", BOX_HORIZONTAL );
// Only enable widget when sidebar is enabled. // Only enable widget when sidebar is enabled.
@ -1509,7 +1510,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) ); state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
for ( unsigned int j = 0; j < state->num_modi; j++ ) { for ( unsigned int j = 0; j < state->num_modi; j++ ) {
const Mode * mode = rofi_get_mode ( j ); const Mode * mode = rofi_get_mode ( j );
state->modi[j] = textbox_create ( "window.mainbox.sidebar.button", TB_CENTER|TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL, state->modi[j] = textbox_create ( "window.mainbox.sidebar.button", TB_CENTER | TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
mode_get_display_name ( mode ) ); mode_get_display_name ( mode ) );
box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE, j ); box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE, j );
widget_set_clicked_handler ( WIDGET ( state->modi[j] ), rofi_view_modi_clicked_cb, state ); widget_set_clicked_handler ( WIDGET ( state->modi[j] ), rofi_view_modi_clicked_cb, state );
@ -1517,34 +1518,34 @@ RofiViewState *rofi_view_create ( Mode *sw,
} }
int location = rofi_theme_get_position ( WIDGET ( state->main_window ), "location", config.location ); int location = rofi_theme_get_position ( WIDGET ( state->main_window ), "location", config.location );
int end = ( location == WL_SOUTH_EAST || location == WL_SOUTH || location == WL_SOUTH_WEST ); int end = ( location == WL_SOUTH_EAST || location == WL_SOUTH || location == WL_SOUTH_WEST );
box_add ( state->main_box, WIDGET ( state->input_bar ), FALSE, end?9:0 ); box_add ( state->main_box, WIDGET ( state->input_bar ), FALSE, end ? 9 : 0 );
state->case_indicator = textbox_create ( "window.mainbox.inputbar.case-indicator", TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "*" ); state->case_indicator = textbox_create ( "window.mainbox.inputbar.case-indicator", TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*" );
// Add small separator between case indicator and text box. // Add small separator between case indicator and text box.
box_add ( state->input_bar, WIDGET ( state->case_indicator ), FALSE, 3 ); box_add ( state->input_bar, WIDGET ( state->case_indicator ), FALSE, 3 );
// Prompt box. // Prompt box.
state->prompt = textbox_create ( "window.mainbox.inputbar.prompt",TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "" ); state->prompt = textbox_create ( "window.mainbox.inputbar.prompt", TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "" );
rofi_view_update_prompt ( state ); rofi_view_update_prompt ( state );
box_add ( state->input_bar, WIDGET ( state->prompt ), FALSE, 1 ); box_add ( state->input_bar, WIDGET ( state->prompt ), FALSE, 1 );
// Entry box // Entry box
TextboxFlags tfl = TB_EDITABLE; TextboxFlags tfl = TB_EDITABLE;
tfl |= ( ( menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0; tfl |= ( ( menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0;
state->text = textbox_create ( "window.mainbox.inputbar.entry", tfl|TB_AUTOHEIGHT, NORMAL, input ); state->text = textbox_create ( "window.mainbox.inputbar.entry", tfl | TB_AUTOHEIGHT, NORMAL, input );
box_add ( state->input_bar, WIDGET ( state->text ), TRUE, 2 ); box_add ( state->input_bar, WIDGET ( state->text ), TRUE, 2 );
textbox_text ( state->case_indicator, get_matching_state () ); textbox_text ( state->case_indicator, get_matching_state () );
if ( message ) { if ( message ) {
container *box = container_create ( "window.mainbox.message.box" ); container *box = container_create ( "window.mainbox.message.box" );
textbox *message_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message ); textbox *message_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message );
container_add ( box, WIDGET (message_tb) ); container_add ( box, WIDGET ( message_tb ) );
box_add ( state->main_box, WIDGET ( box ), FALSE, end?8:2); box_add ( state->main_box, WIDGET ( box ), FALSE, end ? 8 : 2 );
} }
state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH|TB_AUTOHEIGHT, URGENT, "blaat" ); state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat" );
widget_disable ( WIDGET ( state->overlay ) ); widget_disable ( WIDGET ( state->overlay ) );
state->list_view = listview_create ( "window.mainbox.listview", update_callback, state, config.element_height, end ); state->list_view = listview_create ( "window.mainbox.listview", update_callback, state, config.element_height, end );
@ -1553,11 +1554,11 @@ RofiViewState *rofi_view_create ( Mode *sw,
listview_set_scroll_type ( state->list_view, config.scroll_method ); listview_set_scroll_type ( state->list_view, config.scroll_method );
listview_set_mouse_activated_cb ( state->list_view, rofi_view_listview_mouse_activated_cb, state ); listview_set_mouse_activated_cb ( state->list_view, rofi_view_listview_mouse_activated_cb, state );
int lines = rofi_theme_get_integer ( WIDGET (state->list_view ), "lines", config.menu_lines ); int lines = rofi_theme_get_integer ( WIDGET ( state->list_view ), "lines", config.menu_lines );
listview_set_num_lines ( state->list_view, lines ); listview_set_num_lines ( state->list_view, lines );
listview_set_max_lines ( state->list_view, state->num_lines ); listview_set_max_lines ( state->list_view, state->num_lines );
box_add ( state->main_box, WIDGET ( state->list_view ), TRUE, 3); box_add ( state->main_box, WIDGET ( state->list_view ), TRUE, 3 );
// filtered list // filtered list
state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) ); state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) );
@ -1565,9 +1566,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
rofi_view_calculate_window_width ( state ); rofi_view_calculate_window_width ( state );
// Need to resize otherwise calculated desired height is wrong. // Need to resize otherwise calculated desired height is wrong.
widget_resize ( WIDGET ( state->main_window ), state->width, 100); widget_resize ( WIDGET ( state->main_window ), state->width, 100 );
// Only needed when window is fixed size. // Only needed when window is fixed size.
if (( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) { if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {
listview_set_fixed_num_lines ( state->list_view ); listview_set_fixed_num_lines ( state->list_view );
rofi_view_window_update_size ( state ); rofi_view_window_update_size ( state );
} }
@ -1594,23 +1595,22 @@ int rofi_view_error_dialog ( const char *msg, int markup )
state->finalize = process_result; state->finalize = process_result;
state->main_window = container_create ( "window" ); state->main_window = container_create ( "window" );
state->main_box = box_create ( "window.mainbox.message.box", BOX_VERTICAL); state->main_box = box_create ( "window.mainbox.message.box", BOX_VERTICAL );
container_add ( state->main_window, WIDGET ( state->main_box ) ); container_add ( state->main_window, WIDGET ( state->main_box ) );
state->text = textbox_create ( "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), state->text = textbox_create ( "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
NORMAL, ( msg != NULL ) ? msg : "" ); NORMAL, ( msg != NULL ) ? msg : "" );
box_add ( state->main_box, WIDGET ( state->text ), TRUE, 1 ); box_add ( state->main_box, WIDGET ( state->text ), TRUE, 1 );
// Make sure we enable fixed num lines when in normal window mode. // Make sure we enable fixed num lines when in normal window mode.
if ( (CacheState.flags&MENU_NORMAL_WINDOW) == MENU_NORMAL_WINDOW){ if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {
listview_set_fixed_num_lines ( state->list_view ); listview_set_fixed_num_lines ( state->list_view );
} }
rofi_view_calculate_window_width ( state ); rofi_view_calculate_window_width ( state );
// Need to resize otherwise calculated desired height is wrong. // Need to resize otherwise calculated desired height is wrong.
widget_resize ( WIDGET ( state->main_window ), state->width, 100); widget_resize ( WIDGET ( state->main_window ), state->width, 100 );
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 + widget_padding_get_padding_height ( WIDGET(state->main_window) ); state->height = line_height + widget_padding_get_padding_height ( WIDGET ( state->main_window ) );
// Calculte window position. // Calculte window position.
rofi_view_calculate_window_position ( state ); rofi_view_calculate_window_position ( state );
@ -1727,16 +1727,16 @@ void rofi_view_set_overlay ( RofiViewState *state, const char *text )
} }
widget_enable ( WIDGET ( state->overlay ) ); widget_enable ( WIDGET ( state->overlay ) );
textbox_text ( state->overlay, text ); textbox_text ( state->overlay, text );
int x_offset = widget_get_width ( WIDGET(state->main_window) ); int x_offset = widget_get_width ( WIDGET ( state->main_window ) );
// Within padding of window. // Within padding of window.
x_offset -= widget_padding_get_right ( WIDGET (state->main_window) ); x_offset -= widget_padding_get_right ( WIDGET ( state->main_window ) );
// Within the border of widget. // Within the border of widget.
x_offset -= widget_padding_get_right ( WIDGET (state->main_box ) ); x_offset -= widget_padding_get_right ( WIDGET ( state->main_box ) );
x_offset -= widget_padding_get_right ( WIDGET (state->input_bar ) ); x_offset -= widget_padding_get_right ( WIDGET ( state->input_bar ) );
x_offset -= widget_get_width ( WIDGET ( state->case_indicator ) ); x_offset -= widget_get_width ( WIDGET ( state->case_indicator ) );
x_offset -= widget_get_width ( WIDGET ( state->overlay ) ); x_offset -= widget_get_width ( WIDGET ( state->overlay ) );
int top_offset = widget_padding_get_top ( WIDGET (state->main_window) ); int top_offset = widget_padding_get_top ( WIDGET ( state->main_window ) );
top_offset += widget_padding_get_top ( WIDGET (state->main_box ) ); top_offset += widget_padding_get_top ( WIDGET ( state->main_box ) );
widget_move ( WIDGET ( state->overlay ), x_offset, top_offset ); widget_move ( WIDGET ( state->overlay ), x_offset, top_offset );
// We want to queue a repaint. // We want to queue a repaint.
rofi_view_queue_redraw ( ); rofi_view_queue_redraw ( );
@ -1744,8 +1744,8 @@ void rofi_view_set_overlay ( RofiViewState *state, const char *text )
void rofi_view_clear_input ( RofiViewState *state ) void rofi_view_clear_input ( RofiViewState *state )
{ {
if ( state->text ){ if ( state->text ) {
textbox_text ( state->text, ""); textbox_text ( state->text, "" );
rofi_view_set_selected_line ( state, 0 ); rofi_view_set_selected_line ( state, 0 );
} }
} }

View file

@ -31,31 +31,31 @@
#include "widgets/box.h" #include "widgets/box.h"
#include "theme.h" #include "theme.h"
#define LOG_DOMAIN "Widgets.Box" #define LOG_DOMAIN "Widgets.Box"
/** Default spacing used in the box*/ /** Default spacing used in the box*/
#define DEFAULT_SPACING 2 #define DEFAULT_SPACING 2
struct _box struct _box
{ {
widget widget; widget widget;
boxType type; boxType type;
int max_size; int max_size;
// Padding between elements // Padding between elements
Distance spacing; Distance spacing;
GList *children; GList *children;
}; };
static void box_update ( widget *wid ); static void box_update ( widget *wid );
static int box_get_desired_height ( widget *wid ) static int box_get_desired_height ( widget *wid )
{ {
box *b = (box *)wid; box *b = (box *) wid;
int spacing = distance_get_pixel ( b->spacing, b->type == BOX_VERTICAL? ORIENTATION_VERTICAL:ORIENTATION_HORIZONTAL ); int spacing = distance_get_pixel ( b->spacing, b->type == BOX_VERTICAL ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL );
int active_widgets = 0; int active_widgets = 0;
int height = 0; int height = 0;
if ( b->type == BOX_VERTICAL ){ if ( b->type == BOX_VERTICAL ) {
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;
if ( !child->enabled ) { if ( !child->enabled ) {
@ -68,10 +68,11 @@ static int box_get_desired_height ( widget *wid )
} }
height += widget_get_desired_height ( child ); height += widget_get_desired_height ( child );
} }
if ( active_widgets > 0 ){ if ( active_widgets > 0 ) {
height += (active_widgets - 1)*spacing; height += ( active_widgets - 1 ) * spacing;
} }
} else { }
else {
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;
if ( !child->enabled ) { if ( !child->enabled ) {
@ -84,18 +85,17 @@ static int box_get_desired_height ( widget *wid )
return height; return height;
} }
static void vert_calculate_size ( box *b ) static void vert_calculate_size ( box *b )
{ {
int spacing = distance_get_pixel ( b->spacing, ORIENTATION_VERTICAL ); int spacing = distance_get_pixel ( b->spacing, ORIENTATION_VERTICAL );
int expanding_widgets = 0; int expanding_widgets = 0;
int active_widgets = 0; int active_widgets = 0;
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) ); int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) );
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) ); int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) );
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;
if ( child->enabled && child->expand == FALSE ){ if ( child->enabled && child->expand == FALSE ) {
widget_resize ( child, rem_width, widget_get_desired_height (child) ); widget_resize ( child, rem_width, widget_get_desired_height ( child ) );
} }
} }
b->max_size = 0; b->max_size = 0;
@ -109,11 +109,11 @@ static void vert_calculate_size ( box *b )
expanding_widgets++; expanding_widgets++;
continue; continue;
} }
if ( child->h > 0 ){ if ( child->h > 0 ) {
b->max_size += child->h; b->max_size += child->h;
} }
} }
if ( active_widgets > 0 ){ if ( active_widgets > 0 ) {
b->max_size += ( active_widgets - 1 ) * spacing; b->max_size += ( active_widgets - 1 ) * spacing;
} }
if ( b->max_size > rem_height ) { if ( b->max_size > rem_height ) {
@ -122,9 +122,9 @@ static void vert_calculate_size ( box *b )
return; return;
} }
if ( active_widgets > 0 ) { if ( active_widgets > 0 ) {
int top = widget_padding_get_top ( WIDGET ( b ) ); int top = widget_padding_get_top ( WIDGET ( b ) );
double rem = rem_height - 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;
if ( child->enabled == FALSE ) { if ( child->enabled == FALSE ) {
@ -147,18 +147,18 @@ static void vert_calculate_size ( box *b )
} }
} }
} }
b->max_size += widget_padding_get_padding_height ( WIDGET (b) ); b->max_size += widget_padding_get_padding_height ( WIDGET ( b ) );
} }
static void hori_calculate_size ( box *b ) static void hori_calculate_size ( box *b )
{ {
int spacing = distance_get_pixel ( b->spacing, ORIENTATION_HORIZONTAL ); int spacing = distance_get_pixel ( b->spacing, ORIENTATION_HORIZONTAL );
int expanding_widgets = 0; int expanding_widgets = 0;
int active_widgets = 0; int active_widgets = 0;
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) ); int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) );
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) ); int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) );
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;
if ( child->enabled && child->expand == FALSE ){ if ( child->enabled && child->expand == FALSE ) {
widget_resize ( child, child->w, rem_height ); widget_resize ( child, child->w, rem_height );
} }
} }
@ -174,18 +174,18 @@ static void hori_calculate_size ( box *b )
continue; continue;
} }
// Size used by fixed width widgets. // Size used by fixed width widgets.
if ( child->h > 0 ){ if ( child->h > 0 ) {
b->max_size += child->w; b->max_size += child->w;
} }
} }
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * spacing ) ); b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * spacing ) );
if ( b->max_size > (rem_width)) { if ( b->max_size > ( rem_width ) ) {
b->max_size = rem_width; 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 left = widget_padding_get_left ( WIDGET (b) ); int left = widget_padding_get_left ( WIDGET ( b ) );
double rem = rem_width - 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 ) ) {
@ -200,7 +200,7 @@ static void hori_calculate_size ( box *b )
left += expanding_widgets_size; left += expanding_widgets_size;
widget_resize ( child, expanding_widgets_size, rem_height ); widget_resize ( child, expanding_widgets_size, rem_height );
left += spacing; left += spacing;
rem -= expanding_widgets_size; rem -= expanding_widgets_size;
index++; index++;
} }
else { else {
@ -236,8 +236,8 @@ static void box_free ( widget *wid )
static int box_sort_children ( gconstpointer a, gconstpointer b ) static int box_sort_children ( gconstpointer a, gconstpointer b )
{ {
widget *child_a = (widget*)a; widget *child_a = (widget *) a;
widget *child_b = (widget*)b; widget *child_b = (widget *) b;
return child_a->index - child_b->index; return child_a->index - child_b->index;
} }
@ -248,17 +248,18 @@ void box_add ( box *box, widget *child, gboolean expand, int index )
return; return;
} }
// Make sure box is width/heigh enough. // Make sure box is width/heigh enough.
if ( box->type == BOX_VERTICAL){ if ( box->type == BOX_VERTICAL ) {
int width=box->widget.w; int width = box->widget.w;
width = MAX ( width, child->w+widget_padding_get_padding_width ( WIDGET ( box ) )); width = MAX ( width, child->w + widget_padding_get_padding_width ( WIDGET ( box ) ) );
box->widget.w = width; box->widget.w = width;
} else { }
else {
int height = box->widget.h; int height = box->widget.h;
height = MAX (height, child->h+widget_padding_get_padding_height ( WIDGET ( box ))); height = MAX ( height, child->h + widget_padding_get_padding_height ( WIDGET ( box ) ) );
box->widget.h = height; box->widget.h = height;
} }
child->expand = rofi_theme_get_boolean ( child, "expand", expand); child->expand = rofi_theme_get_boolean ( child, "expand", expand );
child->index = rofi_theme_get_integer_exact ( child, "index" , index ); child->index = rofi_theme_get_integer_exact ( child, "index", index );
child->parent = WIDGET ( box ); child->parent = WIDGET ( box );
box->children = g_list_append ( box->children, (void *) child ); box->children = g_list_append ( box->children, (void *) child );
box->children = g_list_sort ( box->children, box_sort_children ); box->children = g_list_sort ( box->children, box_sort_children );
@ -314,7 +315,7 @@ box * box_create ( const char *name, boxType type )
{ {
box *b = g_malloc0 ( sizeof ( box ) ); box *b = g_malloc0 ( sizeof ( box ) );
// Initialize widget. // Initialize widget.
widget_init ( WIDGET(b), name ); widget_init ( WIDGET ( b ), name );
b->type = type; b->type = type;
b->widget.draw = box_draw; b->widget.draw = box_draw;
b->widget.free = box_free; b->widget.free = box_free;
@ -323,9 +324,9 @@ box * box_create ( const char *name, boxType type )
b->widget.clicked = box_clicked; b->widget.clicked = box_clicked;
b->widget.motion_notify = box_motion_notify; b->widget.motion_notify = box_motion_notify;
b->widget.get_desired_height = box_get_desired_height; b->widget.get_desired_height = box_get_desired_height;
b->widget.enabled = TRUE; b->widget.enabled = TRUE;
b->spacing = rofi_theme_get_distance ( WIDGET(b), "spacing", DEFAULT_SPACING ); b->spacing = rofi_theme_get_distance ( WIDGET ( b ), "spacing", DEFAULT_SPACING );
return b; return b;
} }

View file

@ -31,24 +31,23 @@
#include "widgets/container.h" #include "widgets/container.h"
#include "theme.h" #include "theme.h"
#define LOG_DOMAIN "Widgets.Window" #define LOG_DOMAIN "Widgets.Window"
/** The default border width of the container */ /** The default border width of the container */
#define DEFAULT_BORDER_WIDTH 2 #define DEFAULT_BORDER_WIDTH 2
struct _window struct _window
{ {
widget widget; widget widget;
widget *child; widget *child;
}; };
static void container_update ( widget *wid ); static void container_update ( widget *wid );
static int container_get_desired_height ( widget *widget ) static int container_get_desired_height ( widget *widget )
{ {
container *b = (container *) widget; container *b = (container *) widget;
int height = 0; int height = 0;
if ( b->child ) { if ( b->child ) {
height += widget_get_desired_height ( b->child ); height += widget_get_desired_height ( b->child );
} }
@ -56,7 +55,6 @@ static int container_get_desired_height ( widget *widget )
return height; return height;
} }
static void container_draw ( widget *wid, cairo_t *draw ) static void container_draw ( widget *wid, cairo_t *draw )
{ {
container *b = (container *) wid; container *b = (container *) wid;
@ -78,7 +76,7 @@ void container_add ( container *container, widget *child )
return; return;
} }
container->child = child; container->child = child;
child->parent = WIDGET ( container ); child->parent = WIDGET ( container );
widget_update ( WIDGET ( container ) ); widget_update ( WIDGET ( container ) );
} }
@ -119,7 +117,7 @@ container * container_create ( const char *name )
{ {
container *b = g_malloc0 ( sizeof ( container ) ); container *b = g_malloc0 ( sizeof ( container ) );
// Initialize widget. // Initialize widget.
widget_init ( WIDGET(b), name ); widget_init ( WIDGET ( b ), name );
b->widget.draw = container_draw; b->widget.draw = container_draw;
b->widget.free = container_free; b->widget.free = container_free;
b->widget.resize = container_resize; b->widget.resize = container_resize;
@ -134,15 +132,14 @@ container * container_create ( const char *name )
static void container_update ( widget *wid ) static void container_update ( widget *wid )
{ {
container *b = (container *) wid; container *b = (container *) wid;
if ( b->child && b->child->enabled ){ if ( b->child && b->child->enabled ) {
widget_resize ( WIDGET ( b->child ), widget_resize ( WIDGET ( b->child ),
widget_padding_get_remaining_width (WIDGET(b)), widget_padding_get_remaining_width ( WIDGET ( b ) ),
widget_padding_get_remaining_height (WIDGET(b)) widget_padding_get_remaining_height ( WIDGET ( b ) )
); );
widget_move ( WIDGET ( b->child ), widget_move ( WIDGET ( b->child ),
widget_padding_get_left (WIDGET(b)), widget_padding_get_left ( WIDGET ( b ) ),
widget_padding_get_top (WIDGET(b)) widget_padding_get_top ( WIDGET ( b ) )
); );
} }
} }

View file

@ -32,7 +32,7 @@
#include "settings.h" #include "settings.h"
#include "theme.h" #include "theme.h"
#define DEFAULT_SPACING 2 #define DEFAULT_SPACING 2
struct _listview struct _listview
{ {
@ -81,8 +81,7 @@ struct _listview
listview_mouse_activated_cb mouse_activated; listview_mouse_activated_cb mouse_activated;
void *mouse_activated_data; void *mouse_activated_data;
char *listview_name;
char *listview_name;
}; };
static int listview_get_desired_height ( widget *wid ); static int listview_get_desired_height ( widget *wid );
@ -95,7 +94,7 @@ static void listview_free ( widget *wid )
} }
g_free ( lv->boxes ); g_free ( lv->boxes );
g_free( lv->listview_name ); g_free ( lv->listview_name );
widget_free ( WIDGET ( lv->scrollbar ) ); widget_free ( WIDGET ( lv->scrollbar ) );
g_free ( lv ); g_free ( lv );
} }
@ -168,8 +167,9 @@ static void listview_draw ( widget *wid, cairo_t *draw )
scrollbar_set_max_value ( lv->scrollbar, lv->req_elements ); scrollbar_set_max_value ( lv->scrollbar, lv->req_elements );
scrollbar_set_handle_length ( lv->scrollbar, lv->cur_columns * lv->max_rows ); scrollbar_set_handle_length ( lv->scrollbar, lv->cur_columns * lv->max_rows );
if ( lv->reverse ) { if ( lv->reverse ) {
scrollbar_set_handle ( lv->scrollbar, lv->req_elements - lv->selected -1 ); scrollbar_set_handle ( lv->scrollbar, lv->req_elements - lv->selected - 1 );
} else { }
else {
scrollbar_set_handle ( lv->scrollbar, lv->selected ); scrollbar_set_handle ( lv->scrollbar, lv->selected );
} }
lv->last_offset = offset; lv->last_offset = offset;
@ -195,9 +195,10 @@ static void listview_draw ( widget *wid, cairo_t *draw )
for ( unsigned int i = 0; i < max; i++ ) { for ( unsigned int i = 0; i < max; i++ ) {
unsigned int ex = left_offset + ( ( i ) / lv->max_rows ) * ( element_width + spacing_hori ); unsigned int ex = left_offset + ( ( i ) / lv->max_rows ) * ( element_width + spacing_hori );
if ( lv->reverse ) { if ( lv->reverse ) {
unsigned int ey = wid->h-(widget_padding_get_bottom ( wid ) + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert ))-lv->element_height; unsigned int ey = wid->h - ( widget_padding_get_bottom ( wid ) + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert ) ) - lv->element_height;
textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height ); textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
} else { }
else {
unsigned int ey = top_offset + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert ); unsigned int ey = top_offset + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert );
textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height ); textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
} }
@ -238,12 +239,12 @@ static void listview_recompute_elements ( listview *lv )
if ( newne > 0 ) { if ( newne > 0 ) {
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) { for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0; TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
char *name = g_strjoin (".", lv->listview_name,"element", NULL); char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" ); lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" );
g_free ( name ); g_free ( name );
} }
} }
lv->rchanged = TRUE; lv->rchanged = TRUE;
lv->cur_elements = newne; lv->cur_elements = newne;
} }
@ -274,21 +275,22 @@ void listview_set_selected ( listview *lv, unsigned int selected )
static void listview_resize ( widget *wid, short w, short h ) 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 );
int height = lv->widget.h - widget_padding_get_padding_height ( WIDGET (lv) ); int height = lv->widget.h - widget_padding_get_padding_height ( WIDGET ( lv ) );
int spacing_vert = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL ); int spacing_vert = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL );
lv->max_rows = ( spacing_vert + height ) / ( lv->element_height + spacing_vert ); lv->max_rows = ( spacing_vert + height ) / ( lv->element_height + spacing_vert );
lv->max_elements = lv->max_rows * lv->menu_columns; lv->max_elements = lv->max_rows * lv->menu_columns;
if ( lv->scrollbar->widget.index == 0 ){ if ( lv->scrollbar->widget.index == 0 ) {
widget_move ( WIDGET ( lv->scrollbar ), widget_move ( WIDGET ( lv->scrollbar ),
widget_padding_get_left ( WIDGET ( lv ) ), widget_padding_get_left ( WIDGET ( lv ) ),
widget_padding_get_top ( WIDGET ( lv ) ) ); widget_padding_get_top ( WIDGET ( lv ) ) );
} else { }
else {
widget_move ( WIDGET ( lv->scrollbar ), widget_move ( WIDGET ( lv->scrollbar ),
lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ),
widget_padding_get_top ( WIDGET (lv ) )); widget_padding_get_top ( WIDGET ( lv ) ) );
} }
widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height ); widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height );
@ -354,10 +356,10 @@ static gboolean listview_motion_notify ( widget *wid, xcb_motion_notify_event_t
} }
listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse ) listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse )
{ {
listview *lv = g_malloc0 ( sizeof ( listview ) ); listview *lv = g_malloc0 ( sizeof ( listview ) );
gchar *box = g_strjoin (".", name, "box", NULL ); gchar *box = g_strjoin ( ".", name, "box", NULL );
widget_init ( WIDGET ( lv ), box ); widget_init ( WIDGET ( lv ), box );
g_free(box); g_free ( box );
lv->listview_name = g_strdup ( name ); lv->listview_name = g_strdup ( name );
lv->widget.free = listview_free; lv->widget.free = listview_free;
lv->widget.resize = listview_resize; lv->widget.resize = listview_resize;
@ -366,21 +368,21 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->widget.motion_notify = listview_motion_notify; lv->widget.motion_notify = listview_motion_notify;
lv->widget.get_desired_height = listview_get_desired_height; lv->widget.get_desired_height = listview_get_desired_height;
lv->widget.enabled = TRUE; lv->widget.enabled = TRUE;
lv->eh = eh; lv->eh = eh;
char *n = g_strjoin(".", lv->listview_name,"scrollbar", NULL); char *n = g_strjoin ( ".", lv->listview_name, "scrollbar", NULL );
lv->scrollbar = scrollbar_create ( n ); lv->scrollbar = scrollbar_create ( n );
// Default position on right. // Default position on right.
lv->scrollbar->widget.index = rofi_theme_get_integer_exact ( WIDGET (lv->scrollbar), "index", 1); lv->scrollbar->widget.index = rofi_theme_get_integer_exact ( WIDGET ( lv->scrollbar ), "index", 1 );
g_free(n); g_free ( n );
widget_set_clicked_handler ( WIDGET ( lv->scrollbar ), listview_scrollbar_clicked, lv ); widget_set_clicked_handler ( WIDGET ( lv->scrollbar ), listview_scrollbar_clicked, lv );
lv->scrollbar->widget.parent = WIDGET ( lv ); lv->scrollbar->widget.parent = WIDGET ( lv );
// Calculate height of an element. // Calculate height of an element.
// //
char *tb_name = g_strjoin (".", lv->listview_name,"element", NULL); char *tb_name = g_strjoin ( ".", lv->listview_name, "element", NULL );
textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" ); textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" );
lv->element_height = textbox_get_estimated_height (tb, lv->eh); lv->element_height = textbox_get_estimated_height ( tb, lv->eh );
g_free(tb_name); g_free ( tb_name );
lv->callback = cb; lv->callback = cb;
lv->udata = udata; lv->udata = udata;
@ -389,12 +391,11 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->spacing = rofi_theme_get_distance ( WIDGET ( lv ), "spacing", DEFAULT_SPACING ); lv->spacing = rofi_theme_get_distance ( WIDGET ( lv ), "spacing", DEFAULT_SPACING );
lv->menu_columns = rofi_theme_get_integer ( WIDGET ( lv ), "columns", config.menu_columns ); lv->menu_columns = rofi_theme_get_integer ( WIDGET ( lv ), "columns", config.menu_columns );
lv->fixed_num_lines = rofi_theme_get_boolean ( WIDGET ( lv ), "fixed-height", config.fixed_num_lines ); lv->fixed_num_lines = rofi_theme_get_boolean ( WIDGET ( lv ), "fixed-height", config.fixed_num_lines );
lv->dynamic = rofi_theme_get_boolean ( WIDGET ( lv ), "dynamic", TRUE ); lv->dynamic = rofi_theme_get_boolean ( WIDGET ( lv ), "dynamic", TRUE );
lv->reverse = rofi_theme_get_boolean ( WIDGET ( lv ), "reverse", reverse ); lv->reverse = rofi_theme_get_boolean ( WIDGET ( lv ), "reverse", reverse );
listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( WIDGET ( lv ), "scrollbar", !config.hide_scrollbar )); listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( WIDGET ( lv ), "scrollbar", !config.hide_scrollbar ) );
lv->cycle = rofi_theme_get_boolean ( WIDGET ( lv ), "cycle", config.cycle ); lv->cycle = rofi_theme_get_boolean ( WIDGET ( lv ), "cycle", config.cycle );
return lv; return lv;
} }
@ -433,7 +434,8 @@ void listview_nav_up ( listview *lv )
{ {
if ( lv->reverse ) { if ( lv->reverse ) {
listview_nav_down_int ( lv ); listview_nav_down_int ( lv );
} else { }
else {
listview_nav_up_int ( lv ); listview_nav_up_int ( lv );
} }
} }
@ -441,7 +443,8 @@ void listview_nav_down ( listview *lv )
{ {
if ( lv->reverse ) { if ( lv->reverse ) {
listview_nav_up_int ( lv ); listview_nav_up_int ( lv );
} else { }
else {
listview_nav_down_int ( lv ); listview_nav_down_int ( lv );
} }
} }
@ -510,45 +513,48 @@ static void listview_nav_page_next_int ( listview *lv )
void listview_nav_page_prev ( listview *lv ) void listview_nav_page_prev ( listview *lv )
{ {
if ( lv->reverse ){ if ( lv->reverse ) {
listview_nav_page_next_int ( lv ); listview_nav_page_next_int ( lv );
} else { }
else {
listview_nav_page_prev_int ( lv ); listview_nav_page_prev_int ( lv );
} }
} }
void listview_nav_page_next ( listview *lv ) void listview_nav_page_next ( listview *lv )
{ {
if ( lv->reverse ){ if ( lv->reverse ) {
listview_nav_page_prev_int ( lv ); listview_nav_page_prev_int ( lv );
} else { }
else {
listview_nav_page_next_int ( lv ); listview_nav_page_next_int ( lv );
} }
} }
static int listview_get_desired_height ( widget *wid ) static int listview_get_desired_height ( widget *wid )
{ {
listview *lv = (listview *)wid; listview *lv = (listview *) wid;
int spacing = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL ); int spacing = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL );
if ( lv == NULL || lv->widget.enabled == FALSE ) { if ( lv == NULL || lv->widget.enabled == FALSE ) {
return 0; return 0;
} }
int h = lv->menu_lines; int h = lv->menu_lines;
if ( !( lv->fixed_num_lines ) ) { if ( !( lv->fixed_num_lines ) ) {
if ( lv->dynamic ) { if ( lv->dynamic ) {
h = MIN ( lv->menu_lines, lv->req_elements ); h = MIN ( lv->menu_lines, lv->req_elements );
} else { }
else {
h = MIN ( lv->menu_lines, lv->max_displayed_lines ); h = MIN ( lv->menu_lines, lv->max_displayed_lines );
} }
} }
if ( h == 0 ) { if ( h == 0 ) {
if ( lv->dynamic && !lv->fixed_num_lines ){ if ( lv->dynamic && !lv->fixed_num_lines ) {
// Hide widget fully. // Hide widget fully.
return 0; return 0;
} }
return widget_padding_get_padding_height ( WIDGET (lv) ); return widget_padding_get_padding_height ( WIDGET ( lv ) );
} }
int height = widget_padding_get_padding_height ( WIDGET (lv) ); int height = widget_padding_get_padding_height ( WIDGET ( lv ) );
height += h*(lv->element_height+spacing) - spacing; height += h * ( lv->element_height + spacing ) - spacing;
return height; return height;
} }

View file

@ -30,13 +30,12 @@
#include "theme.h" #include "theme.h"
#define DEFAULT_SCROLLBAR_WIDTH 8 #define DEFAULT_SCROLLBAR_WIDTH 8
static void scrollbar_draw ( widget *, cairo_t * ); static void scrollbar_draw ( widget *, cairo_t * );
static void scrollbar_free ( widget * ); static void scrollbar_free ( widget * );
static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ); static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
static int scrollbar_get_desired_height ( widget *wid ) static int scrollbar_get_desired_height ( widget *wid )
{ {
// Want height we are. // Want height we are.
@ -46,17 +45,17 @@ static int scrollbar_get_desired_height ( widget *wid )
scrollbar *scrollbar_create ( const char *name ) scrollbar *scrollbar_create ( const char *name )
{ {
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) ); scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
widget_init ( WIDGET (sb), name ); widget_init ( WIDGET ( sb ), name );
sb->widget.x = 0; sb->widget.x = 0;
sb->widget.y = 0; sb->widget.y = 0;
sb->width = rofi_theme_get_distance ( WIDGET (sb), "handle-width", DEFAULT_SCROLLBAR_WIDTH ); sb->width = rofi_theme_get_distance ( WIDGET ( sb ), "handle-width", DEFAULT_SCROLLBAR_WIDTH );
int width = distance_get_pixel (sb->width, ORIENTATION_HORIZONTAL); int width = distance_get_pixel ( sb->width, ORIENTATION_HORIZONTAL );
sb->widget.w = widget_padding_get_padding_width ( WIDGET (sb)) + width; sb->widget.w = widget_padding_get_padding_width ( WIDGET ( sb ) ) + width;
sb->widget.h = widget_padding_get_padding_height ( WIDGET ( sb ) ); sb->widget.h = widget_padding_get_padding_height ( WIDGET ( sb ) );
sb->widget.draw = scrollbar_draw; sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free; sb->widget.free = scrollbar_free;
sb->widget.motion_notify = scrollbar_motion_notify; sb->widget.motion_notify = scrollbar_motion_notify;
sb->widget.get_desired_height = scrollbar_get_desired_height; sb->widget.get_desired_height = scrollbar_get_desired_height;
sb->length = 10; sb->length = 10;
@ -110,7 +109,7 @@ void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
static void scrollbar_draw ( widget *wid, cairo_t *draw ) static void scrollbar_draw ( widget *wid, cairo_t *draw )
{ {
scrollbar *sb = (scrollbar *) wid; scrollbar *sb = (scrollbar *) wid;
unsigned int wh = widget_padding_get_remaining_height ( wid ); unsigned int wh = widget_padding_get_remaining_height ( wid );
// Calculate position and size. // Calculate position and size.
unsigned int r = ( sb->length * wh ) / ( (double) ( sb->length + sb->pos_length ) ); unsigned int r = ( sb->length * wh ) / ( (double) ( sb->length + sb->pos_length ) );
unsigned int handle = wid->h - r; unsigned int handle = wid->h - r;
@ -122,14 +121,14 @@ static void scrollbar_draw ( widget *wid, cairo_t *draw )
// Never go out of bar. // Never go out of bar.
height = MAX ( 2, height ); height = MAX ( 2, height );
// Cap length; // Cap length;
rofi_theme_get_color ( WIDGET (sb ), "foreground", draw ); rofi_theme_get_color ( WIDGET ( sb ), "foreground", draw );
rofi_theme_get_color ( WIDGET (sb ), "handle-color", draw ); rofi_theme_get_color ( WIDGET ( sb ), "handle-color", draw );
cairo_rectangle ( draw, cairo_rectangle ( draw,
widget_padding_get_left ( wid ), widget_padding_get_left ( wid ),
widget_padding_get_top ( wid ) + y, widget_padding_get_top ( wid ) + y,
widget_padding_get_remaining_width ( wid ), widget_padding_get_remaining_width ( wid ),
height ); height );
cairo_fill ( draw ); cairo_fill ( draw );
} }
static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ) static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
@ -146,10 +145,10 @@ unsigned int scrollbar_clicked ( const scrollbar *sb, int y )
{ {
if ( sb != NULL ) { if ( sb != NULL ) {
if ( y >= sb->widget.y && y <= ( sb->widget.y + sb->widget.h ) ) { if ( y >= sb->widget.y && y <= ( sb->widget.y + sb->widget.h ) ) {
short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) ); short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) );
short handle = sb->widget.h - r; short handle = sb->widget.h - r;
double sec = ( ( r ) / (double) ( sb->length - 1 ) ); double sec = ( ( r ) / (double) ( sb->length - 1 ) );
short half_handle = handle / 2; short half_handle = handle / 2;
y -= sb->widget.y + half_handle; y -= sb->widget.y + half_handle;
y = MIN ( MAX ( 0, y ), sb->widget.h - 2 * half_handle ); y = MIN ( MAX ( 0, y ), sb->widget.h - 2 * half_handle );
@ -159,4 +158,3 @@ unsigned int scrollbar_clicked ( const scrollbar *sb, int y )
} }
return 0; return 0;
} }

View file

@ -79,15 +79,14 @@ static void textbox_resize ( widget *wid, short w, short h )
} }
static int textbox_get_desired_height ( widget *wid ) static int textbox_get_desired_height ( widget *wid )
{ {
textbox *tb = (textbox *)wid; textbox *tb = (textbox *) wid;
if ( (tb->flags & TB_AUTOHEIGHT) == 0 ) if ( ( tb->flags & TB_AUTOHEIGHT ) == 0 ) {
{
return tb->widget.h; return tb->widget.h;
} }
if ( tb->changed ) { if ( tb->changed ) {
__textbox_update_pango_text ( tb ); __textbox_update_pango_text ( tb );
} }
int height = textbox_get_height (tb); int height = textbox_get_height ( tb );
return height; return height;
} }
@ -95,15 +94,15 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
{ {
textbox *tb = g_slice_new0 ( textbox ); textbox *tb = g_slice_new0 ( textbox );
widget_init ( WIDGET (tb), name ); widget_init ( WIDGET ( tb ), name );
tb->widget.draw = textbox_draw; tb->widget.draw = textbox_draw;
tb->widget.free = textbox_free; tb->widget.free = textbox_free;
tb->widget.resize = textbox_resize; tb->widget.resize = textbox_resize;
tb->widget.get_width = textbox_get_width; tb->widget.get_width = textbox_get_width;
tb->widget.get_height = _textbox_get_height; tb->widget.get_height = _textbox_get_height;
tb->widget.get_desired_height = textbox_get_desired_height; tb->widget.get_desired_height = textbox_get_desired_height;
tb->flags = flags; tb->flags = flags;
tb->changed = FALSE; tb->changed = FALSE;
@ -137,11 +136,11 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
*/ */
const char const *const theme_prop_names[][3] = { const char const *const theme_prop_names[][3] = {
/** Normal row */ /** Normal row */
{"normal.normal", "selected.normal", "alternate.normal"}, { "normal.normal", "selected.normal", "alternate.normal" },
/** Urgent row */ /** Urgent row */
{"normal.urgent", "selected.urgent", "alternate.urgent"}, { "normal.urgent", "selected.urgent", "alternate.urgent" },
/** Active row */ /** Active row */
{"normal.active", "selected.active", "alternate.active"}, { "normal.active", "selected.active", "alternate.active" },
}; };
void textbox_font ( textbox *tb, TextBoxFontType tbft ) void textbox_font ( textbox *tb, TextBoxFontType tbft )
@ -157,13 +156,13 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
switch ( ( tbft & FMOD_MASK ) ) switch ( ( tbft & FMOD_MASK ) )
{ {
case HIGHLIGHT: case HIGHLIGHT:
widget_set_state ( WIDGET (tb), theme_prop_names[t][1]); widget_set_state ( WIDGET ( tb ), theme_prop_names[t][1] );
break; break;
case ALT: case ALT:
widget_set_state ( WIDGET (tb), theme_prop_names[t][2]); widget_set_state ( WIDGET ( tb ), theme_prop_names[t][2] );
break; break;
default: default:
widget_set_state ( WIDGET (tb), theme_prop_names[t][0]); widget_set_state ( WIDGET ( tb ), theme_prop_names[t][0] );
break; break;
} }
if ( tb->tbft != tbft || tb->widget.state == NULL ) { if ( tb->tbft != tbft || tb->widget.state == NULL ) {
@ -232,7 +231,7 @@ void textbox_text ( textbox *tb, const char *text )
__textbox_update_pango_text ( tb ); __textbox_update_pango_text ( tb );
if ( tb->flags & TB_AUTOWIDTH ) { if ( tb->flags & TB_AUTOWIDTH ) {
textbox_moveresize ( tb, tb->widget.x, tb->widget.y, tb->widget.w, tb->widget.h ); textbox_moveresize ( tb, tb->widget.x, tb->widget.y, tb->widget.w, tb->widget.h );
if ( WIDGET(tb)->parent ){ if ( WIDGET ( tb )->parent ) {
widget_update ( WIDGET ( tb )->parent ); widget_update ( WIDGET ( tb )->parent );
} }
} }
@ -248,7 +247,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOWIDTH ) { if ( tb->flags & TB_AUTOWIDTH ) {
pango_layout_set_width ( tb->layout, -1 ); pango_layout_set_width ( tb->layout, -1 );
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
w = textbox_get_font_width ( tb ) + widget_padding_get_padding_width ( WIDGET (tb) ) + offset; w = textbox_get_font_width ( tb ) + widget_padding_get_padding_width ( WIDGET ( tb ) ) + offset;
} }
else { else {
// set ellipsize // set ellipsize
@ -263,9 +262,9 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOHEIGHT ) { if ( tb->flags & TB_AUTOHEIGHT ) {
// Width determines height! // Width determines height!
int tw = MAX ( 1, w ); int tw = MAX ( 1, w );
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - widget_padding_get_padding_width ( WIDGET (tb) ) - offset ) ); pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) );
int hd = textbox_get_height ( tb ); int hd = textbox_get_height ( tb );
h = MAX (hd, h); h = MAX ( hd, h );
} }
if ( x != tb->widget.x || y != tb->widget.y || w != tb->widget.w || h != tb->widget.h ) { if ( x != tb->widget.x || y != tb->widget.y || w != tb->widget.w || h != tb->widget.h ) {
@ -276,7 +275,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
} }
// We always want to update this // We always want to update this
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - widget_padding_get_padding_width ( WIDGET (tb) ) - offset ) ); pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) );
tb->update = TRUE; tb->update = TRUE;
widget_queue_redraw ( WIDGET ( tb ) ); widget_queue_redraw ( WIDGET ( tb ) );
} }
@ -323,9 +322,9 @@ static void texbox_update ( textbox *tb )
pango_cairo_update_layout ( tb->main_draw, tb->layout ); pango_cairo_update_layout ( tb->main_draw, tb->layout );
int font_height = textbox_get_font_height ( tb ); int font_height = textbox_get_font_height ( tb );
int cursor_x = 0; int cursor_x = 0;
int cursor_y = 0; int cursor_y = 0;
int cursor_width = 2;//MAX ( 2, font_height / 10 ); int cursor_width = 2;//MAX ( 2, font_height / 10 );
int cursor_height = font_height; int cursor_height = font_height;
if ( tb->changed ) { if ( tb->changed ) {
@ -341,33 +340,33 @@ static void texbox_update ( textbox *tb )
// convert to byte location. // convert to byte location.
char *offset = g_utf8_offset_to_pointer ( text, cursor_offset ); char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
pango_layout_get_cursor_pos ( tb->layout, offset - text, &pos, NULL ); pango_layout_get_cursor_pos ( tb->layout, offset - text, &pos, NULL );
cursor_x = pos.x / PANGO_SCALE; cursor_x = pos.x / PANGO_SCALE;
cursor_y = pos.y / PANGO_SCALE; cursor_y = pos.y / PANGO_SCALE;
cursor_height = pos.height/PANGO_SCALE; cursor_height = pos.height / PANGO_SCALE;
} }
// Skip the side MARGIN on the X axis. // Skip the side MARGIN on the X axis.
int x = widget_padding_get_left ( WIDGET (tb) ) + offset; int x = widget_padding_get_left ( WIDGET ( tb ) ) + offset;
int y = 0; int y = 0;
if ( tb->flags & TB_RIGHT ) { if ( tb->flags & TB_RIGHT ) {
int line_width = 0; int line_width = 0;
// Get actual width. // Get actual width.
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL ); pango_layout_get_pixel_size ( tb->layout, &line_width, NULL );
x = ( tb->widget.w - line_width - widget_padding_get_right ( WIDGET (tb) ) - offset ); x = ( tb->widget.w - line_width - widget_padding_get_right ( WIDGET ( tb ) ) - offset );
} }
else if ( tb->flags & TB_CENTER ) { else if ( tb->flags & TB_CENTER ) {
int tw = textbox_get_font_width ( tb ); int tw = textbox_get_font_width ( tb );
x = ( ( tb->widget.w - tw - widget_padding_get_padding_width( WIDGET (tb) ) - offset ) ) / 2; x = ( ( tb->widget.w - tw - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) ) / 2;
} }
y = widget_padding_get_top ( WIDGET (tb) ) + ( pango_font_metrics_get_ascent ( p_metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE; y = widget_padding_get_top ( WIDGET ( tb ) ) + ( pango_font_metrics_get_ascent ( p_metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
rofi_theme_get_color ( WIDGET ( tb ), "foreground", tb->main_draw); rofi_theme_get_color ( WIDGET ( tb ), "foreground", tb->main_draw );
// Text // Text
rofi_theme_get_color ( WIDGET ( tb ), "text", tb->main_draw); rofi_theme_get_color ( WIDGET ( tb ), "text", tb->main_draw );
// draw the cursor // draw the cursor
if ( tb->flags & TB_EDITABLE && tb->blink ) { if ( tb->flags & TB_EDITABLE && tb->blink ) {
cairo_rectangle ( tb->main_draw, x + cursor_x, y+cursor_y, cursor_width, cursor_height); cairo_rectangle ( tb->main_draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
cairo_fill ( tb->main_draw ); cairo_fill ( tb->main_draw );
} }
@ -378,7 +377,6 @@ static void texbox_update ( textbox *tb )
pango_cairo_show_layout ( tb->main_draw, tb->layout ); pango_cairo_show_layout ( tb->main_draw, tb->layout );
if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) { if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) {
cairo_arc ( tb->main_draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI ); cairo_arc ( tb->main_draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI );
cairo_fill ( tb->main_draw ); cairo_fill ( tb->main_draw );
} }
@ -392,8 +390,8 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
texbox_update ( tb ); texbox_update ( tb );
/* Write buffer */ /* Write buffer */
cairo_set_source_surface ( draw, tb->main_surface, 0,0 ); cairo_set_source_surface ( draw, tb->main_surface, 0, 0 );
cairo_rectangle ( draw, 0,0, tb->widget.w, tb->widget.h ); cairo_rectangle ( draw, 0, 0, tb->widget.w, tb->widget.h );
cairo_fill ( draw ); cairo_fill ( draw );
} }
@ -747,7 +745,7 @@ int _textbox_get_height ( widget *wid )
} }
int textbox_get_height ( const textbox *tb ) int textbox_get_height ( const textbox *tb )
{ {
return textbox_get_font_height ( tb ) + widget_padding_get_padding_height ( WIDGET (tb) ); return textbox_get_font_height ( tb ) + widget_padding_get_padding_height ( WIDGET ( tb ) );
} }
int textbox_get_font_height ( const textbox *tb ) int textbox_get_font_height ( const textbox *tb )
@ -768,7 +766,7 @@ int textbox_get_font_width ( const textbox *tb )
static double char_height = -1; static double char_height = -1;
double textbox_get_estimated_char_height ( void ) double textbox_get_estimated_char_height ( void )
{ {
if ( char_height < 0 ){ if ( char_height < 0 ) {
int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics ); int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
char_height = ( height ) / (double) PANGO_SCALE; char_height = ( height ) / (double) PANGO_SCALE;
} }
@ -779,7 +777,7 @@ double textbox_get_estimated_char_height ( void )
static double char_width = -1; static double char_width = -1;
double textbox_get_estimated_char_width ( void ) double textbox_get_estimated_char_width ( void )
{ {
if ( char_width < 0 ){ if ( char_width < 0 ) {
int width = pango_font_metrics_get_approximate_char_width ( p_metrics ); int width = pango_font_metrics_get_approximate_char_width ( p_metrics );
char_width = ( width ) / (double) PANGO_SCALE; char_width = ( width ) / (double) PANGO_SCALE;
} }
@ -789,5 +787,5 @@ double textbox_get_estimated_char_width ( void )
int textbox_get_estimated_height ( const textbox *tb, int eh ) int textbox_get_estimated_height ( const textbox *tb, int eh )
{ {
int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics ); int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
return ( eh*height ) / PANGO_SCALE + widget_padding_get_padding_height ( WIDGET ( tb ) ); return ( eh * height ) / PANGO_SCALE + widget_padding_get_padding_height ( WIDGET ( tb ) );
} }

View file

@ -3,25 +3,24 @@
#include "widgets/widget-internal.h" #include "widgets/widget-internal.h"
#include "theme.h" #include "theme.h"
void widget_init ( widget *widget, const char *name )
void widget_init ( widget *widget , const char *name )
{ {
widget->name = g_strdup(name); widget->name = g_strdup ( name );
widget->padding = (Padding){ {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}}; widget->padding = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };
widget->border = (Padding){ {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}}; widget->border = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };
widget->margin = (Padding){ {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}}; widget->margin = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };
widget->padding = rofi_theme_get_padding ( widget, "padding", widget->padding); widget->padding = rofi_theme_get_padding ( widget, "padding", widget->padding );
widget->border = rofi_theme_get_padding ( widget, "border", widget->border); widget->border = rofi_theme_get_padding ( widget, "border", widget->border );
widget->margin = rofi_theme_get_padding ( widget, "margin", widget->margin); widget->margin = rofi_theme_get_padding ( widget, "margin", widget->margin );
} }
void widget_set_state ( widget *widget, const char *state ) void widget_set_state ( widget *widget, const char *state )
{ {
if ( g_strcmp0(widget->state, state ) ){ if ( g_strcmp0 ( widget->state, state ) ) {
widget->state = state; widget->state = state;
// Update border. // Update border.
widget->border = rofi_theme_get_padding ( widget, "border", widget->border); widget->border = rofi_theme_get_padding ( widget, "border", widget->border );
widget_queue_redraw ( widget ); widget_queue_redraw ( widget );
} }
@ -94,67 +93,67 @@ void widget_draw ( widget *widget, cairo_t *d )
// Check if enabled and if draw is implemented. // Check if enabled and if draw is implemented.
if ( widget && widget->enabled && widget->draw ) { if ( widget && widget->enabled && widget->draw ) {
// Don't draw if there is no space. // Don't draw if there is no space.
if ( widget->h < 1 || widget->w < 1 ){ if ( widget->h < 1 || widget->w < 1 ) {
widget->need_redraw = FALSE; widget->need_redraw = FALSE;
return; return;
} }
// Store current state. // Store current state.
cairo_save ( d ); cairo_save ( d );
int margin_left = distance_get_pixel ( widget->margin.left, ORIENTATION_HORIZONTAL); int margin_left = distance_get_pixel ( widget->margin.left, ORIENTATION_HORIZONTAL );
int margin_top = distance_get_pixel ( widget->margin.top, ORIENTATION_VERTICAL); int margin_top = distance_get_pixel ( widget->margin.top, ORIENTATION_VERTICAL );
int margin_right = distance_get_pixel ( widget->margin.right, ORIENTATION_HORIZONTAL); int margin_right = distance_get_pixel ( widget->margin.right, ORIENTATION_HORIZONTAL );
int margin_bottom = distance_get_pixel ( widget->margin.bottom, ORIENTATION_VERTICAL); int margin_bottom = distance_get_pixel ( widget->margin.bottom, ORIENTATION_VERTICAL );
// Define a clipmask so we won't draw outside out widget. // Define a clipmask so we won't draw outside out widget.
cairo_rectangle ( d, cairo_rectangle ( d,
widget->x+margin_left, widget->x + margin_left,
widget->y+margin_top, widget->y + margin_top,
widget->w-margin_right-margin_left, widget->w - margin_right - margin_left,
widget->h-margin_top-margin_bottom widget->h - margin_top - margin_bottom
); );
cairo_clip ( d ); cairo_clip ( d );
rofi_theme_get_color ( widget, "background", d ); rofi_theme_get_color ( widget, "background", d );
cairo_paint( d ) ; cairo_paint ( d );
// Set new x/y possition. // Set new x/y possition.
cairo_translate ( d, widget->x, widget->y); cairo_translate ( d, widget->x, widget->y );
int left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL ); int left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL );
int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL); int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL );
int top = distance_get_pixel ( widget->border.top, ORIENTATION_VERTICAL); int top = distance_get_pixel ( widget->border.top, ORIENTATION_VERTICAL );
int bottom = distance_get_pixel ( widget->border.bottom, ORIENTATION_VERTICAL ); int bottom = distance_get_pixel ( widget->border.bottom, ORIENTATION_VERTICAL );
if ( left || top || right || bottom ) { if ( left || top || right || bottom ) {
cairo_save ( d ); cairo_save ( d );
rofi_theme_get_color ( widget, "foreground", d ); rofi_theme_get_color ( widget, "foreground", d );
if ( left > 0 ) { if ( left > 0 ) {
cairo_set_line_width ( d, left ); cairo_set_line_width ( d, left );
distance_get_linestyle ( widget->border.left, d); distance_get_linestyle ( widget->border.left, d );
cairo_move_to ( d, margin_left + left/2.0, margin_top ); cairo_move_to ( d, margin_left + left / 2.0, margin_top );
cairo_line_to ( d, margin_left + left/2.0, widget->h-margin_bottom); cairo_line_to ( d, margin_left + left / 2.0, widget->h - margin_bottom );
cairo_stroke ( d ); cairo_stroke ( d );
} }
if ( right > 0 ) { if ( right > 0 ) {
cairo_set_line_width ( d, right ); cairo_set_line_width ( d, right );
distance_get_linestyle ( widget->border.right, d); distance_get_linestyle ( widget->border.right, d );
cairo_move_to ( d, widget->w - margin_right - right/2.0, 0 ); cairo_move_to ( d, widget->w - margin_right - right / 2.0, 0 );
cairo_line_to ( d, widget->w - margin_right - right/2.0, widget->h-margin_bottom ); cairo_line_to ( d, widget->w - margin_right - right / 2.0, widget->h - margin_bottom );
cairo_stroke ( d ); cairo_stroke ( d );
} }
if ( top > 0 ) { if ( top > 0 ) {
cairo_set_line_width ( d, top ); cairo_set_line_width ( d, top );
distance_get_linestyle ( widget->border.top, d); distance_get_linestyle ( widget->border.top, d );
cairo_move_to ( d, margin_left,margin_top+ top/2.0 ); cairo_move_to ( d, margin_left, margin_top + top / 2.0 );
cairo_line_to ( d, widget->w-margin_right, margin_top+top/2.0 ); cairo_line_to ( d, widget->w - margin_right, margin_top + top / 2.0 );
cairo_stroke ( d ); cairo_stroke ( d );
} }
if ( bottom > 0 ) { if ( bottom > 0 ) {
cairo_set_line_width ( d, bottom ); cairo_set_line_width ( d, bottom );
distance_get_linestyle ( widget->border.bottom, d); distance_get_linestyle ( widget->border.bottom, d );
cairo_move_to ( d, margin_left, widget->h-bottom/2.0-margin_bottom); cairo_move_to ( d, margin_left, widget->h - bottom / 2.0 - margin_bottom );
cairo_line_to ( d, widget->w-margin_right, widget->h-bottom/2.0-margin_bottom); cairo_line_to ( d, widget->w - margin_right, widget->h - bottom / 2.0 - margin_bottom );
cairo_stroke ( d ); cairo_stroke ( d );
} }
cairo_restore (d); cairo_restore ( d );
} }
widget->draw ( widget, d ); widget->draw ( widget, d );
widget->need_redraw = FALSE; widget->need_redraw = FALSE;
@ -266,7 +265,7 @@ gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
void widget_set_name ( widget *wid, const char *name ) void widget_set_name ( widget *wid, const char *name )
{ {
if ( wid->name ) { if ( wid->name ) {
g_free(wid); g_free ( wid );
} }
wid->name = g_strdup ( name ); wid->name = g_strdup ( name );
} }
@ -329,11 +328,9 @@ int widget_padding_get_padding_width ( const widget *wid )
return width; return width;
} }
int widget_get_desired_height ( widget *wid ) int widget_get_desired_height ( widget *wid )
{ {
if ( wid && wid->get_desired_height ) if ( wid && wid->get_desired_height ) {
{
return wid->get_desired_height ( wid ); return wid->get_desired_height ( wid );
} }
return 0; return 0;

View file

@ -533,7 +533,7 @@ int take_pointer ( xcb_window_t w, int iters )
} }
free ( r ); free ( r );
} }
if ( (++i) > iters ){ if ( ( ++i ) > iters ) {
break; break;
} }
usleep ( 1000 ); usleep ( 1000 );
@ -559,7 +559,7 @@ int take_keyboard ( xcb_window_t w, int iters )
} }
free ( r ); free ( r );
} }
if ( (++i) > iters ){ if ( ( ++i ) > iters ) {
break; break;
} }
usleep ( 1000 ); usleep ( 1000 );
@ -646,14 +646,14 @@ gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key
char *mod_key = input_key; char *mod_key = input_key;
char *error_msg = NULL; char *error_msg = NULL;
unsigned int modmask = 0; unsigned int modmask = 0;
xkb_keysym_t sym = XKB_KEY_NoSymbol; xkb_keysym_t sym = XKB_KEY_NoSymbol;
// Test if this works on release. // Test if this works on release.
if ( g_str_has_prefix ( mod_key, "!" ) ) { if ( g_str_has_prefix ( mod_key, "!" ) ) {
++mod_key; ++mod_key;
*release = TRUE; *release = TRUE;
} }
char **entries = g_strsplit_set ( mod_key, "+-", -1); char **entries = g_strsplit_set ( mod_key, "+-", -1 );
for ( int i = 0; entries && entries[i]; i++ ) { for ( int i = 0; entries && entries[i]; i++ ) {
char *entry = entries[i]; char *entry = entries[i];
// Remove trailing and leading spaces. // Remove trailing and leading spaces.
@ -704,7 +704,7 @@ gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key
} }
g_free ( entry_lowered ); g_free ( entry_lowered );
} }
g_strfreev(entries); g_strfreev ( entries );
g_free ( input_key ); g_free ( input_key );

View file

@ -81,120 +81,120 @@ typedef struct
* Currently supports string, boolean and number (signed and unsigned). * Currently supports string, boolean and number (signed and unsigned).
*/ */
static XrmOption xrmOptions[] = { static XrmOption xrmOptions[] = {
{ xrm_String, "switchers", { .str = &config.modi }, NULL, { xrm_String, "switchers", { .str = &config.modi }, NULL,
"", CONFIG_DEFAULT }, "", CONFIG_DEFAULT },
{ xrm_String, "modi", { .str = &config.modi }, NULL, { xrm_String, "modi", { .str = &config.modi }, NULL,
"Enabled modi", CONFIG_DEFAULT }, "Enabled modi", CONFIG_DEFAULT },
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL, { xrm_SNumber, "width", { .snum = &config.menu_width }, NULL,
"Window width", CONFIG_DEFAULT }, "Window width", CONFIG_DEFAULT },
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL, { xrm_Number, "lines", { .num = &config.menu_lines }, NULL,
"Number of lines", CONFIG_DEFAULT }, "Number of lines", CONFIG_DEFAULT },
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL, { xrm_Number, "columns", { .num = &config.menu_columns }, NULL,
"Number of columns", CONFIG_DEFAULT }, "Number of columns", CONFIG_DEFAULT },
{ xrm_String, "font", { .str = &config.menu_font }, NULL, { xrm_String, "font", { .str = &config.menu_font }, NULL,
"Font to use", CONFIG_DEFAULT }, "Font to use", CONFIG_DEFAULT },
{ xrm_String, "color-normal", { .str = &config.color_normal }, NULL, { xrm_String, "color-normal", { .str = &config.color_normal }, NULL,
"Color scheme for normal row", CONFIG_DEFAULT }, "Color scheme for normal row", CONFIG_DEFAULT },
{ xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL, { xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL,
"Color scheme for urgent row", CONFIG_DEFAULT }, "Color scheme for urgent row", CONFIG_DEFAULT },
{ xrm_String, "color-active", { .str = &config.color_active }, NULL, { xrm_String, "color-active", { .str = &config.color_active }, NULL,
"Color scheme for active row", CONFIG_DEFAULT }, "Color scheme for active row", CONFIG_DEFAULT },
{ xrm_String, "color-window", { .str = &config.color_window }, NULL, { xrm_String, "color-window", { .str = &config.color_window }, NULL,
"Color scheme window", CONFIG_DEFAULT }, "Color scheme window", CONFIG_DEFAULT },
{ xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL, { xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL,
"", CONFIG_DEFAULT }, "", CONFIG_DEFAULT },
{ xrm_Number, "bw", { .num = &config.menu_bw }, NULL, { xrm_Number, "bw", { .num = &config.menu_bw }, NULL,
"Border width", CONFIG_DEFAULT }, "Border width", CONFIG_DEFAULT },
{ xrm_Number, "location", { .num = &config.location }, NULL, { xrm_Number, "location", { .num = &config.location }, NULL,
"Location on screen", CONFIG_DEFAULT }, "Location on screen", CONFIG_DEFAULT },
{ xrm_Number, "padding", { .num = &config.padding }, NULL, { xrm_Number, "padding", { .num = &config.padding }, NULL,
"Padding", CONFIG_DEFAULT }, "Padding", CONFIG_DEFAULT },
{ xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL, { xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL,
"Y-offset relative to location", CONFIG_DEFAULT }, "Y-offset relative to location", CONFIG_DEFAULT },
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL, { xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL,
"X-offset relative to location", CONFIG_DEFAULT }, "X-offset relative to location", CONFIG_DEFAULT },
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL, { xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL,
"Always show number of lines", CONFIG_DEFAULT }, "Always show number of lines", CONFIG_DEFAULT },
{ xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL, { xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL,
"Terminal to use", CONFIG_DEFAULT }, "Terminal to use", CONFIG_DEFAULT },
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL, { xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL,
"Ssh client to use", CONFIG_DEFAULT }, "Ssh client to use", CONFIG_DEFAULT },
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL, { xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL,
"Ssh command to execute", CONFIG_DEFAULT }, "Ssh command to execute", CONFIG_DEFAULT },
{ xrm_String, "run-command", { .str = &config.run_command }, NULL, { xrm_String, "run-command", { .str = &config.run_command }, NULL,
"Run command to execute", CONFIG_DEFAULT }, "Run command to execute", CONFIG_DEFAULT },
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL, { xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL,
"Command to get extra run targets", CONFIG_DEFAULT }, "Command to get extra run targets", CONFIG_DEFAULT },
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL, { xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
"Run command to execute that runs in shell", CONFIG_DEFAULT }, "Run command to execute that runs in shell", CONFIG_DEFAULT },
{ xrm_String, "window-command", { .str = &config.window_command }, NULL, { xrm_String, "window-command", { .str = &config.window_command }, NULL,
"Command executed on accep-entry-custom for window modus", CONFIG_DEFAULT }, "Command executed on accep-entry-custom for window modus", CONFIG_DEFAULT },
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL, { xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
"Disable history in run/ssh", CONFIG_DEFAULT }, "Disable history in run/ssh", CONFIG_DEFAULT },
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL, { xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL,
"Use levenshtein sorting", CONFIG_DEFAULT }, "Use levenshtein sorting", CONFIG_DEFAULT },
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL,
"Set case-sensitivity", CONFIG_DEFAULT }, "Set case-sensitivity", CONFIG_DEFAULT },
{ xrm_Boolean, "cycle", { .num = &config.cycle }, NULL, { xrm_Boolean, "cycle", { .num = &config.cycle }, NULL,
"Cycle through the results list", CONFIG_DEFAULT }, "Cycle through the results list", CONFIG_DEFAULT },
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL, { xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL,
"Enable sidebar-mode", CONFIG_DEFAULT }, "Enable sidebar-mode", CONFIG_DEFAULT },
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL, { xrm_SNumber, "eh", { .snum = &config.element_height }, NULL,
"Row height (in chars)", CONFIG_DEFAULT }, "Row height (in chars)", CONFIG_DEFAULT },
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL, { xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL,
"Enable auto select mode", CONFIG_DEFAULT }, "Enable auto select mode", CONFIG_DEFAULT },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL, { xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL,
"Parse hosts file for ssh mode", CONFIG_DEFAULT }, "Parse hosts file for ssh mode", CONFIG_DEFAULT },
{ xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL, { xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL,
"Parse known_hosts file for ssh mode", CONFIG_DEFAULT }, "Parse known_hosts file for ssh mode", CONFIG_DEFAULT },
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL, { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL,
"Set the modi to combine in combi mode", CONFIG_DEFAULT }, "Set the modi to combine in combi mode", CONFIG_DEFAULT },
{ xrm_String, "matching", { .str = &config.matching }, NULL, { xrm_String, "matching", { .str = &config.matching }, NULL,
"Set the matching algorithm. (normal, regex, glob, fuzzy)", CONFIG_DEFAULT }, "Set the matching algorithm. (normal, regex, glob, fuzzy)", CONFIG_DEFAULT },
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL, { xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL,
"Tokenize input string", CONFIG_DEFAULT }, "Tokenize input string", CONFIG_DEFAULT },
{ xrm_String, "monitor", { .str = &config.monitor }, NULL, { xrm_String, "monitor", { .str = &config.monitor }, NULL,
"", CONFIG_DEFAULT }, "", CONFIG_DEFAULT },
/* Alias for dmenu compatibility. */ /* Alias for dmenu compatibility. */
{ xrm_String, "m", { .str = &config.monitor }, NULL, { xrm_String, "m", { .str = &config.monitor }, NULL,
"Monitor id to show on", CONFIG_DEFAULT }, "Monitor id to show on", CONFIG_DEFAULT },
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL, { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
"Margin between rows", CONFIG_DEFAULT }, "Margin between rows", CONFIG_DEFAULT },
{ xrm_Number, "line-padding", { .num = &config.line_padding }, NULL, { xrm_Number, "line-padding", { .num = &config.line_padding }, NULL,
"Padding within rows", CONFIG_DEFAULT }, "Padding within rows", CONFIG_DEFAULT },
{ xrm_String, "filter", { .str = &config.filter }, NULL, { xrm_String, "filter", { .str = &config.filter }, NULL,
"Pre-set filter", CONFIG_DEFAULT }, "Pre-set filter", CONFIG_DEFAULT },
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL, { xrm_String, "separator-style", { .str = &config.separator_style }, NULL,
"Separator style (none, dash, solid)", CONFIG_DEFAULT }, "Separator style (none, dash, solid)", CONFIG_DEFAULT },
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL,
"Hide scroll-bar", CONFIG_DEFAULT }, "Hide scroll-bar", CONFIG_DEFAULT },
{ xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL,
"Fullscreen", CONFIG_DEFAULT }, "Fullscreen", CONFIG_DEFAULT },
{ xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, { xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL,
"Fake transparency", CONFIG_DEFAULT }, "Fake transparency", CONFIG_DEFAULT },
{ xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL, { xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL,
"DPI", CONFIG_DEFAULT }, "DPI", CONFIG_DEFAULT },
{ xrm_Number, "threads", { .num = &config.threads }, NULL, { xrm_Number, "threads", { .num = &config.threads }, NULL,
"Threads to use for string matching", CONFIG_DEFAULT }, "Threads to use for string matching", CONFIG_DEFAULT },
{ xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL,
"Scrollbar width", CONFIG_DEFAULT }, "Scrollbar width", CONFIG_DEFAULT },
{ xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL, { xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL,
"Scrolling method. (0: Page, 1: Centered)", CONFIG_DEFAULT }, "Scrolling method. (0: Page, 1: Centered)", CONFIG_DEFAULT },
{ xrm_String, "fake-background", { .str = &config.fake_background }, NULL, { xrm_String, "fake-background", { .str = &config.fake_background }, NULL,
"Background to use for fake transparency. (background or screenshot)", CONFIG_DEFAULT }, "Background to use for fake transparency. (background or screenshot)", CONFIG_DEFAULT },
{ xrm_String, "window-format", { .str = &config.window_format }, NULL, { xrm_String, "window-format", { .str = &config.window_format }, NULL,
"Window Format. w (desktop name), t (title), n (name), r (role), c (class)", CONFIG_DEFAULT }, "Window Format. w (desktop name), t (title), n (name), r (role), c (class)", CONFIG_DEFAULT },
{ xrm_Boolean, "click-to-exit", { .snum = &config.click_to_exit }, NULL, { xrm_Boolean, "click-to-exit", { .snum = &config.click_to_exit }, NULL,
"Click outside the window to exit", CONFIG_DEFAULT }, "Click outside the window to exit", CONFIG_DEFAULT },
{ xrm_Boolean, "show-match", { .snum = &config.show_match }, NULL, { xrm_Boolean, "show-match", { .snum = &config.show_match }, NULL,
"Indicate how it match by underlining it.", CONFIG_DEFAULT }, "Indicate how it match by underlining it.", CONFIG_DEFAULT },
{ xrm_String, "theme", { .str = &config.theme }, NULL, { xrm_String, "theme", { .str = &config.theme }, NULL,
"New style theme file", CONFIG_DEFAULT }, "New style theme file", CONFIG_DEFAULT },
}; };