1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-07-31 21:59:25 -04:00

Indent all the code.

This commit is contained in:
Dave Davenport 2020-02-02 13:56:37 +01:00
parent 83c2e467d5
commit b169289996
25 changed files with 840 additions and 832 deletions

View file

@ -36,39 +36,39 @@ Settings config = {
/** List of enabled modi. */ /** List of enabled modi. */
/** -modi */ /** -modi */
#ifdef WINDOW_MODE #ifdef WINDOW_MODE
.modi = "window,run,ssh", .modi = "window,run,ssh",
#else #else
.modi = "run,ssh", .modi = "run,ssh",
#endif #endif
/** Border width around the window. */ /** Border width around the window. */
.menu_bw = 1, .menu_bw = 1,
/** The width of the switcher. (0100 in % > 100 in pixels) */ /** The width of the switcher. (0100 in % > 100 in pixels) */
.menu_width = 50, .menu_width = 50,
/** Maximum number of options to show. */ /** Maximum number of options to show. */
.menu_lines = 15, .menu_lines = 15,
/** Number of columns */ /** Number of columns */
.menu_columns = 1, .menu_columns = 1,
/** Font */ /** Font */
.menu_font = "mono 12", .menu_font = "mono 12",
/** Whether to load and show icons */ /** Whether to load and show icons */
.show_icons = FALSE, .show_icons = FALSE,
/** Terminal to use. (for ssh and open in terminal) */ /** Terminal to use. (for ssh and open in terminal) */
.terminal_emulator = "rofi-sensible-terminal", .terminal_emulator = "rofi-sensible-terminal",
.ssh_client = "ssh", .ssh_client = "ssh",
/** Command when executing ssh. */ /** Command when executing ssh. */
.ssh_command = "{terminal} -e {ssh-client} {host} [-p {port}]", .ssh_command = "{terminal} -e {ssh-client} {host} [-p {port}]",
/** Command when running */ /** Command when running */
.run_command = "{cmd}", .run_command = "{cmd}",
/** Command used to list executable commands. empty -> internal */ /** Command used to list executable commands. empty -> internal */
.run_list_command = "", .run_list_command = "",
/** Command executed when running application in terminal */ /** Command executed when running application in terminal */
.run_shell_command = "{terminal} -e {cmd}", .run_shell_command = "{terminal} -e {cmd}",
/** Command executed on accep-entry-custom for window modus */ /** Command executed on accep-entry-custom for window modus */
.window_command = "wmctrl -i -R {window}", .window_command = "wmctrl -i -R {window}",
/** No default icon theme, we search Adwaita and gnome as fallback */ /** No default icon theme, we search Adwaita and gnome as fallback */
.icon_theme = NULL, .icon_theme = NULL,
/** /**
* Location of the window. * Location of the window.
* Enumeration indicating location or gravity of window. * Enumeration indicating location or gravity of window.
@ -80,61 +80,61 @@ Settings config = {
* WL_SOUTH_WEST WL_SOUTH WL_SOUTH_EAST * WL_SOUTH_WEST WL_SOUTH WL_SOUTH_EAST
* *
*/ */
.location = WL_CENTER, .location = WL_CENTER,
/** Padding between elements */ /** Padding between elements */
.padding = 5, .padding = 5,
/** Y offset */ /** Y offset */
.y_offset = 0, .y_offset = 0,
/** X offset */ /** X offset */
.x_offset = 0, .x_offset = 0,
/** Always show config.menu_lines lines, even if less lines are available */ /** Always show config.menu_lines lines, even if less lines are available */
.fixed_num_lines = TRUE, .fixed_num_lines = TRUE,
/** Do not use history */ /** Do not use history */
.disable_history = FALSE, .disable_history = FALSE,
/** Programs ignored for history */ /** Programs ignored for history */
.ignored_prefixes = "", .ignored_prefixes = "",
/** Sort the displayed list */ /** Sort the displayed list */
.sort = FALSE, .sort = FALSE,
/** Use levenshtein sorting when matching */ /** Use levenshtein sorting when matching */
.sorting_method = SORT_NORMAL, .sorting_method = SORT_NORMAL,
/** Case sensitivity of the search */ /** Case sensitivity of the search */
.case_sensitive = FALSE, .case_sensitive = FALSE,
/** Cycle through in the element list */ /** Cycle through in the element list */
.cycle = TRUE, .cycle = TRUE,
/** Height of an element in #chars */ /** Height of an element in #chars */
.element_height = 1, .element_height = 1,
/** Sidebar mode, show the modi */ /** Sidebar mode, show the modi */
.sidebar_mode = FALSE, .sidebar_mode = FALSE,
/** auto select */ /** auto select */
.auto_select = FALSE, .auto_select = FALSE,
/** Parse /etc/hosts file in ssh view. */ /** Parse /etc/hosts file in ssh view. */
.parse_hosts = FALSE, .parse_hosts = FALSE,
/** Parse ~/.ssh/known_hosts file in ssh view. */ /** Parse ~/.ssh/known_hosts file in ssh view. */
.parse_known_hosts = TRUE, .parse_known_hosts = TRUE,
/** Modi to combine into one view. */ /** Modi to combine into one view. */
.combi_modi = "window,run", .combi_modi = "window,run",
.tokenize = TRUE, .tokenize = TRUE,
.matching = "normal", .matching = "normal",
.matching_method = MM_NORMAL, .matching_method = MM_NORMAL,
/** Desktop entry fields to match*/ /** Desktop entry fields to match*/
.drun_match_fields = "name,generic,exec,categories,keywords", .drun_match_fields = "name,generic,exec,categories,keywords",
.drun_categories = NULL, .drun_categories = NULL,
/** Desktop format display */ /** Desktop format display */
.drun_display_format = "{name} [<span weight='light' size='small'><i>({generic})</i></span>]", .drun_display_format = "{name} [<span weight='light' size='small'><i>({generic})</i></span>]",
/** Desktop entry show actions */ /** Desktop entry show actions */
.drun_show_actions = FALSE, .drun_show_actions = FALSE,
/** Desktop entry show actions */ /** Desktop entry show actions */
/** Window fields to match in window mode*/ /** Window fields to match in window mode*/
.window_match_fields = "all", .window_match_fields = "all",
/** Monitor */ /** Monitor */
.monitor = "-5", .monitor = "-5",
/** set line margin */ /** set line margin */
.line_margin = 2, .line_margin = 2,
.line_padding = 1, .line_padding = 1,
/** Set filter */ /** Set filter */
.filter = NULL, .filter = NULL,
/** Separator style: dash/solid */ /** Separator style: dash/solid */
.separator_style = "dash", .separator_style = "dash",
/** Hide scrollbar */ /** Hide scrollbar */
.hide_scrollbar = FALSE, .hide_scrollbar = FALSE,
.fullscreen = FALSE, .fullscreen = FALSE,
@ -156,10 +156,10 @@ Settings config = {
.max_history_size = 25, .max_history_size = 25,
.combi_hide_mode_prefix = FALSE, .combi_hide_mode_prefix = FALSE,
.matching_negate_char = '-', .matching_negate_char = '-',
.cache_dir = NULL, .cache_dir = NULL,
.window_thumbnail = FALSE, .window_thumbnail = FALSE,
.drun_use_desktop_cache = FALSE, .drun_use_desktop_cache = FALSE,
.drun_reload_desktop_cache = FALSE .drun_reload_desktop_cache = FALSE
}; };

View file

@ -1,7 +1,8 @@
#ifndef ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H #ifndef ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H
#define ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H #define ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H
typedef struct { typedef struct
{
/** Entry content. (visible part) */ /** Entry content. (visible part) */
char *entry; char *entry;
/** Icon name to display. */ /** Icon name to display. */

View file

@ -337,7 +337,6 @@ void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length );
*/ */
void rofi_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter ); void rofi_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter );
/** /**
* @param string The string with elements to be replaced * @param string The string with elements to be replaced
* @param ... Set of {key}, value that will be replaced, terminated by a NULL * @param ... Set of {key}, value that will be replaced, terminated by a NULL

View file

@ -35,7 +35,8 @@
/** /**
* Describe the media constraint type. * Describe the media constraint type.
*/ */
typedef enum { typedef enum
{
/** Minimum width constraint. */ /** Minimum width constraint. */
THEME_MEDIA_TYPE_MIN_WIDTH, THEME_MEDIA_TYPE_MIN_WIDTH,
/** Maximum width constraint. */ /** Maximum width constraint. */
@ -57,9 +58,10 @@ typedef enum {
/** /**
* Theme Media description. * Theme Media description.
*/ */
typedef struct ThemeMedia { typedef struct ThemeMedia
{
ThemeMediaType type; ThemeMediaType type;
double value; double value;
} ThemeMedia; } ThemeMedia;
/** /**

View file

@ -103,9 +103,9 @@ struct RofiViewState
textbox **modi; textbox **modi;
/** Total rows. */ /** Total rows. */
textbox *tb_total_rows; textbox *tb_total_rows;
/** filtered rows */ /** filtered rows */
textbox *tb_filtered_rows; textbox *tb_filtered_rows;
/** Settings of the menu */ /** Settings of the menu */
MenuFlags menu_flags; MenuFlags menu_flags;

View file

@ -61,7 +61,7 @@ typedef enum
* *
* Update callback, this is called to set the value of each (visible) element. * Update callback, this is called to set the value of each (visible) element.
*/ */
typedef void ( *listview_update_callback )( textbox *tb,icon *ico, unsigned int entry, void *udata, TextBoxFontType *type, gboolean full ); typedef void ( *listview_update_callback )( textbox *tb, icon *ico, unsigned int entry, void *udata, TextBoxFontType *type, gboolean full );
/** /**
* Callback when a element is activated. * Callback when a element is activated.

View file

@ -49,27 +49,27 @@
*/ */
typedef struct typedef struct
{ {
widget widget; widget widget;
unsigned long flags; unsigned long flags;
short cursor; short cursor;
char *text; char *text;
const char *placeholder; const char *placeholder;
int show_placeholder; int show_placeholder;
PangoLayout *layout; PangoLayout *layout;
int tbft; int tbft;
int markup; int markup;
int changed; int changed;
int blink; int blink;
guint blink_timeout; guint blink_timeout;
double yalign; double yalign;
double xalign; double xalign;
PangoFontMetrics *metrics; PangoFontMetrics *metrics;
PangoEllipsizeMode emode; PangoEllipsizeMode emode;
// //
const char *theme_name; const char *theme_name;
} textbox; } textbox;
/** /**

View file

@ -142,7 +142,6 @@ void widget_move ( widget *widget, short x, short y );
*/ */
WidgetType widget_type ( widget *widget ); WidgetType widget_type ( widget *widget );
/** /**
* @param widget Handle to widget * @param widget Handle to widget
* @param type The widget type. * @param type The widget type.

View file

@ -53,7 +53,6 @@
#include "dialogs/dmenuscriptshared.h" #include "dialogs/dmenuscriptshared.h"
static int dmenu_mode_init ( Mode *sw ); static int dmenu_mode_init ( Mode *sw );
static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ); static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index );
static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_line, int height ); static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_line, int height );
@ -90,7 +89,7 @@ typedef struct
unsigned int num_selected_list; unsigned int num_selected_list;
unsigned int do_markup; unsigned int do_markup;
// List with entries. // List with entries.
DmenuScriptEntry *cmd_list; DmenuScriptEntry *cmd_list;
unsigned int cmd_list_real_length; unsigned int cmd_list_real_length;
unsigned int cmd_list_length; unsigned int cmd_list_length;
unsigned int only_selected; unsigned int only_selected;
@ -123,14 +122,14 @@ static void read_add ( DmenuModePrivateData * pd, char *data, gsize len )
pd->cmd_list[pd->cmd_list_length].icon_fetch_uid = 0; pd->cmd_list[pd->cmd_list_length].icon_fetch_uid = 0;
pd->cmd_list[pd->cmd_list_length].icon_name = NULL; pd->cmd_list[pd->cmd_list_length].icon_name = NULL;
pd->cmd_list[pd->cmd_list_length].meta = NULL; pd->cmd_list[pd->cmd_list_length].meta = NULL;
char *end = strchr(data, '\0'); char *end = strchr ( data, '\0' );
if ( end != NULL ) { if ( end != NULL ) {
data_len = end-data; data_len = end - data;
dmenuscript_parse_entry_extras ( NULL, &(pd->cmd_list[pd->cmd_list_length]), end+1, len-data_len); dmenuscript_parse_entry_extras ( NULL, &( pd->cmd_list[pd->cmd_list_length] ), end + 1, len - data_len );
} }
char *utfstr = rofi_force_utf8 ( data, data_len ); char *utfstr = rofi_force_utf8 ( data, data_len );
pd->cmd_list[pd->cmd_list_length].entry = utfstr; pd->cmd_list[pd->cmd_list_length].entry = utfstr;
pd->cmd_list[pd->cmd_list_length + 1].entry = NULL; pd->cmd_list[pd->cmd_list_length + 1].entry = NULL;
pd->cmd_list_length++; pd->cmd_list_length++;
} }
@ -250,17 +249,21 @@ static gchar * dmenu_format_output_string ( const DmenuModePrivateData *pd, cons
static inline unsigned int get_index ( unsigned int length, int index ) static inline unsigned int get_index ( unsigned int length, int index )
{ {
if ( index >= 0 ) return index; if ( index >= 0 ) {
if ( ((unsigned int)-index) <= length ) return (length+index); return index;
}
if ( ( (unsigned int) -index ) <= length ) {
return length + index;
}
// Out of range. // Out of range.
return UINT_MAX; return UINT_MAX;
} }
static char *get_display_data ( const Mode *data, unsigned int index, int *state, G_GNUC_UNUSED GList **list, int get_entry ) static char *get_display_data ( const Mode *data, unsigned int index, int *state, G_GNUC_UNUSED GList **list, int get_entry )
{ {
Mode *sw = (Mode *) data; Mode *sw = (Mode *) data;
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw ); DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
DmenuScriptEntry *retv = (DmenuScriptEntry *) pd->cmd_list; DmenuScriptEntry *retv = (DmenuScriptEntry *) pd->cmd_list;
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) { for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
unsigned int start = get_index ( pd->cmd_list_length, pd->active_list[i].start ); unsigned int start = get_index ( pd->cmd_list_length, pd->active_list[i].start );
unsigned int stop = get_index ( pd->cmd_list_length, pd->active_list[i].stop ); unsigned int stop = get_index ( pd->cmd_list_length, pd->active_list[i].stop );
@ -433,18 +436,18 @@ static int dmenu_mode_init ( Mode *sw )
static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ) static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{ {
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw ); DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw );
if ( rmpd->do_markup) { if ( rmpd->do_markup ) {
/** Strip out the markup when matching. */ /** Strip out the markup when matching. */
char *esc = NULL; char *esc = NULL;
pango_parse_markup(rmpd->cmd_list[index].entry, -1, 0, NULL, &esc, NULL, NULL); pango_parse_markup ( rmpd->cmd_list[index].entry, -1, 0, NULL, &esc, NULL, NULL );
if ( esc ) { if ( esc ) {
int retv = helper_token_match ( tokens, esc); int retv = helper_token_match ( tokens, esc );
g_free (esc); g_free ( esc );
return retv; return retv;
} }
return FALSE; return FALSE;
}
} else { else {
return helper_token_match ( tokens, rmpd->cmd_list[index].entry ); return helper_token_match ( tokens, rmpd->cmd_list[index].entry );
} }
} }
@ -460,7 +463,7 @@ static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_l
{ {
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw ); DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] );
if ( dr->icon_name == NULL ) { if ( dr->icon_name == NULL ) {
return NULL; return NULL;
} }
@ -471,7 +474,6 @@ static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_l
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
} }
static void dmenu_finish ( RofiViewState *state, int retv ) static void dmenu_finish ( RofiViewState *state, int retv )
{ {
if ( retv == FALSE ) { if ( retv == FALSE ) {
@ -491,19 +493,19 @@ static void dmenu_finish ( RofiViewState *state, int retv )
static void dmenu_print_results ( DmenuModePrivateData *pd, const char *input ) static void dmenu_print_results ( DmenuModePrivateData *pd, const char *input )
{ {
DmenuScriptEntry *cmd_list = pd->cmd_list; DmenuScriptEntry *cmd_list = pd->cmd_list;
int seen = FALSE; int seen = FALSE;
if ( pd->selected_list != NULL ) { if ( pd->selected_list != NULL ) {
for ( unsigned int st = 0; st < pd->cmd_list_length; st++ ) { for ( unsigned int st = 0; st < pd->cmd_list_length; st++ ) {
if ( bitget ( pd->selected_list, st ) ) { if ( bitget ( pd->selected_list, st ) ) {
seen = TRUE; seen = TRUE;
rofi_output_formatted_line ( pd->format, cmd_list[st].entry , st, input ); rofi_output_formatted_line ( pd->format, cmd_list[st].entry, st, input );
} }
} }
} }
if ( !seen ) { if ( !seen ) {
const char *cmd = input; const char *cmd = input;
if ( pd->selected_line != UINT32_MAX ) { if ( pd->selected_line != UINT32_MAX ) {
cmd = cmd_list[pd->selected_line].entry ; cmd = cmd_list[pd->selected_line].entry;
} }
rofi_output_formatted_line ( pd->format, cmd, pd->selected_line, input ); rofi_output_formatted_line ( pd->format, cmd, pd->selected_line, input );
} }
@ -514,7 +516,7 @@ static void dmenu_finalize ( RofiViewState *state )
int retv = FALSE; int retv = FALSE;
DmenuModePrivateData *pd = (DmenuModePrivateData *) rofi_view_get_mode ( state )->private_data; DmenuModePrivateData *pd = (DmenuModePrivateData *) rofi_view_get_mode ( state )->private_data;
unsigned int cmd_list_length = pd->cmd_list_length; unsigned int cmd_list_length = pd->cmd_list_length;
DmenuScriptEntry *cmd_list = pd->cmd_list; DmenuScriptEntry *cmd_list = pd->cmd_list;
char *input = g_strdup ( rofi_view_get_user_input ( state ) ); char *input = g_strdup ( rofi_view_get_user_input ( state ) );
pd->selected_line = rofi_view_get_selected_line ( state );; pd->selected_line = rofi_view_get_selected_line ( state );;
@ -647,9 +649,9 @@ int dmenu_switcher_dialog ( void )
get_dmenu_sync ( pd ); get_dmenu_sync ( pd );
} }
} }
char *input = NULL; char *input = NULL;
unsigned int cmd_list_length = pd->cmd_list_length; unsigned int cmd_list_length = pd->cmd_list_length;
DmenuScriptEntry *cmd_list = pd->cmd_list; DmenuScriptEntry *cmd_list = pd->cmd_list;
pd->only_selected = FALSE; pd->only_selected = FALSE;
pd->multi_select = FALSE; pd->multi_select = FALSE;
@ -667,7 +669,7 @@ int dmenu_switcher_dialog ( void )
} }
} }
if ( config.auto_select && cmd_list_length == 1 ) { if ( config.auto_select && cmd_list_length == 1 ) {
rofi_output_formatted_line ( pd->format, cmd_list[0].entry , 0, config.filter ); rofi_output_formatted_line ( pd->format, cmd_list[0].entry, 0, config.filter );
return TRUE; return TRUE;
} }
if ( find_arg ( "-password" ) >= 0 ) { if ( find_arg ( "-password" ) >= 0 ) {
@ -694,7 +696,7 @@ int dmenu_switcher_dialog ( void )
unsigned int i = 0; unsigned int i = 0;
for ( i = 0; i < cmd_list_length; i++ ) { for ( i = 0; i < cmd_list_length; i++ ) {
if ( tokens == NULL || helper_token_match ( tokens, cmd_list[i].entry ) ) { if ( tokens == NULL || helper_token_match ( tokens, cmd_list[i].entry ) ) {
rofi_output_formatted_line ( pd->format, cmd_list[i].entry , i, config.filter ); rofi_output_formatted_line ( pd->format, cmd_list[i].entry, i, config.filter );
} }
} }
helper_tokenize_free ( tokens ); helper_tokenize_free ( tokens );

View file

@ -55,7 +55,7 @@
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
#define DRUN_CACHE_FILE "rofi3.druncache" #define DRUN_CACHE_FILE "rofi3.druncache"
#define DRUN_DESKTOP_CACHE_FILE "rofi-drun-desktop.cache" #define DRUN_DESKTOP_CACHE_FILE "rofi-drun-desktop.cache"
char *DRUN_GROUP_NAME = "Desktop Entry"; char *DRUN_GROUP_NAME = "Desktop Entry";
@ -142,8 +142,7 @@ struct _DRunModePrivateData
unsigned int disabled_entries_length; unsigned int disabled_entries_length;
unsigned int expected_line_height; unsigned int expected_line_height;
char **show_categories;
char **show_categories;
// Theme // Theme
const gchar *icon_theme; const gchar *icon_theme;
@ -234,11 +233,10 @@ static void exec_cmd_entry ( DRunModeEntry *e )
} }
if ( e->key_file == NULL ) { if ( e->key_file == NULL ) {
GKeyFile *kf = g_key_file_new (); GKeyFile *kf = g_key_file_new ();
GError *error = NULL; GError *error = NULL;
gboolean res = g_key_file_load_from_file ( kf, e->path, 0, &error ); gboolean res = g_key_file_load_from_file ( kf, e->path, 0, &error );
if ( res ) if ( res ) {
{
e->key_file = kf; e->key_file = kf;
} }
else { else {
@ -282,11 +280,10 @@ static void exec_cmd_entry ( DRunModeEntry *e )
g_free ( str ); g_free ( str );
} }
static gboolean rofi_strv_contains ( const char * const *categories, const char *const *field ) static gboolean rofi_strv_contains ( const char * const *categories, const char *const *field )
{ {
for ( int i = 0; categories && categories[i] ; i++ ){ for ( int i = 0; categories && categories[i]; i++ ) {
for ( int j = 0; field[j] ; j++ ){ for ( int j = 0; field[j]; j++ ) {
if ( g_str_equal ( categories[i], field[j] ) ) { if ( g_str_equal ( categories[i], field[j] ) ) {
return TRUE; return TRUE;
} }
@ -314,7 +311,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
// Check if item is on disabled list. // Check if item is on disabled list.
if ( g_hash_table_contains ( pd->disabled_entries, id ) && !parse_action ) { if ( g_hash_table_contains ( pd->disabled_entries, id ) && !parse_action ) {
g_debug ( "[%s] [%s] Skipping, was previously seen.", id, path ); g_debug ( "[%s] [%s] Skipping, was previously seen.", id, path );
return ; return;
} }
GKeyFile *kf = g_key_file_new (); GKeyFile *kf = g_key_file_new ();
GError *error = NULL; GError *error = NULL;
@ -324,14 +321,14 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
g_debug ( "[%s] [%s] Failed to parse desktop file because: %s.", id, path, error->message ); g_debug ( "[%s] [%s] Failed to parse desktop file because: %s.", id, path, error->message );
g_error_free ( error ); g_error_free ( error );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
if ( g_key_file_has_group ( kf, action ) == FALSE ) { if ( g_key_file_has_group ( kf, action ) == FALSE ) {
// No type? ignore. // No type? ignore.
g_debug ( "[%s] [%s] Invalid desktop file: No %s group", id, path, action ); g_debug ( "[%s] [%s] Invalid desktop file: No %s group", id, path, action );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
// Skip non Application entries. // Skip non Application entries.
gchar *key = g_key_file_get_string ( kf, DRUN_GROUP_NAME, "Type", NULL ); gchar *key = g_key_file_get_string ( kf, DRUN_GROUP_NAME, "Type", NULL );
@ -339,13 +336,13 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
// No type? ignore. // No type? ignore.
g_debug ( "[%s] [%s] Invalid desktop file: No type indicated", id, path ); g_debug ( "[%s] [%s] Invalid desktop file: No type indicated", id, path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
if ( g_strcmp0 ( key, "Application" ) ) { if ( g_strcmp0 ( key, "Application" ) ) {
g_debug ( "[%s] [%s] Skipping desktop file: Not of type application (%s)", id, path, key ); g_debug ( "[%s] [%s] Skipping desktop file: Not of type application (%s)", id, path, key );
g_free ( key ); g_free ( key );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
g_free ( key ); g_free ( key );
@ -353,7 +350,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
if ( !g_key_file_has_key ( kf, DRUN_GROUP_NAME, "Name", NULL ) ) { if ( !g_key_file_has_key ( kf, DRUN_GROUP_NAME, "Name", NULL ) ) {
g_debug ( "[%s] [%s] Invalid desktop file: no 'Name' key present.", id, path ); g_debug ( "[%s] [%s] Invalid desktop file: no 'Name' key present.", id, path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
// Skip hidden entries. // Skip hidden entries.
@ -361,7 +358,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'Hidden' key is true", id, path ); g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'Hidden' key is true", id, path );
g_key_file_free ( kf ); g_key_file_free ( kf );
g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
return ; return;
} }
if ( pd->current_desktop_list ) { if ( pd->current_desktop_list ) {
gboolean show = TRUE; gboolean show = TRUE;
@ -396,7 +393,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'OnlyShowIn'/'NotShowIn' keys don't match current desktop", id, path ); g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'OnlyShowIn'/'NotShowIn' keys don't match current desktop", id, path );
g_key_file_free ( kf ); g_key_file_free ( kf );
g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
return ; return;
} }
} }
// Skip entries that have NoDisplay set. // Skip entries that have NoDisplay set.
@ -404,13 +401,13 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'NoDisplay' key is true", id, path ); g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'NoDisplay' key is true", id, path );
g_key_file_free ( kf ); g_key_file_free ( kf );
g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
return ; return;
} }
// We need Exec, don't support DBusActivatable // We need Exec, don't support DBusActivatable
if ( !g_key_file_has_key ( kf, DRUN_GROUP_NAME, "Exec", NULL ) ) { if ( !g_key_file_has_key ( kf, DRUN_GROUP_NAME, "Exec", NULL ) ) {
g_debug ( "[%s] [%s] Unsupported desktop file: no 'Exec' key present.", id, path ); g_debug ( "[%s] [%s] Unsupported desktop file: no 'Exec' key present.", id, path );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
if ( g_key_file_has_key ( kf, DRUN_GROUP_NAME, "TryExec", NULL ) ) { if ( g_key_file_has_key ( kf, DRUN_GROUP_NAME, "TryExec", NULL ) ) {
@ -420,7 +417,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
if ( fp == NULL ) { if ( fp == NULL ) {
g_free ( te ); g_free ( te );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
g_free ( fp ); g_free ( fp );
} }
@ -428,7 +425,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
if ( g_file_test ( te, G_FILE_TEST_IS_EXECUTABLE ) == FALSE ) { if ( g_file_test ( te, G_FILE_TEST_IS_EXECUTABLE ) == FALSE ) {
g_free ( te ); g_free ( te );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
} }
g_free ( te ); g_free ( te );
@ -437,10 +434,10 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
char **categories = NULL; char **categories = NULL;
if ( pd->show_categories ) { if ( pd->show_categories ) {
categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL ); categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL );
if ( !rofi_strv_contains( (const char * const *)categories, (const char *const *)pd->show_categories ) ){ if ( !rofi_strv_contains ( (const char * const *) categories, (const char *const *) pd->show_categories ) ) {
g_strfreev(categories); g_strfreev ( categories );
g_key_file_free ( kf ); g_key_file_free ( kf );
return ; return;
} }
} }
@ -478,23 +475,25 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
pd->entry_list[pd->cmd_list_length].generic_name = gn; pd->entry_list[pd->cmd_list_length].generic_name = gn;
if ( matching_entry_fields[DRUN_MATCH_FIELD_KEYWORDS].enabled ) { if ( matching_entry_fields[DRUN_MATCH_FIELD_KEYWORDS].enabled ) {
pd->entry_list[pd->cmd_list_length].keywords = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Keywords", NULL, NULL, NULL ); pd->entry_list[pd->cmd_list_length].keywords = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Keywords", NULL, NULL, NULL );
} else { }
else {
pd->entry_list[pd->cmd_list_length].keywords = NULL; pd->entry_list[pd->cmd_list_length].keywords = NULL;
} }
if ( matching_entry_fields[DRUN_MATCH_FIELD_CATEGORIES].enabled ) { if ( matching_entry_fields[DRUN_MATCH_FIELD_CATEGORIES].enabled ) {
if ( categories ) { if ( categories ) {
pd->entry_list[pd->cmd_list_length].categories = categories; pd->entry_list[pd->cmd_list_length].categories = categories;
categories = NULL; categories = NULL;
} else { }
else {
pd->entry_list[pd->cmd_list_length].categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL ); pd->entry_list[pd->cmd_list_length].categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL );
} }
} }
else { else {
pd->entry_list[pd->cmd_list_length].categories = NULL; pd->entry_list[pd->cmd_list_length].categories = NULL;
} }
g_strfreev(categories); g_strfreev ( categories );
pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, action, "Exec", NULL ); pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, action, "Exec", NULL );
@ -530,7 +529,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
} }
g_strfreev ( actions ); g_strfreev ( actions );
} }
return ; return;
} }
/** /**
@ -641,86 +640,88 @@ static gint drun_int_sort_list ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED
if ( da->sort_index < 0 && db->sort_index < 0 ) { if ( da->sort_index < 0 && db->sort_index < 0 ) {
return g_utf8_collate ( da->name, db->name ); return g_utf8_collate ( da->name, db->name );
} else { }
else {
return db->sort_index - da->sort_index; return db->sort_index - da->sort_index;
} }
} }
/******************************************* /*******************************************
* Cache voodoo * * Cache voodoo *
*******************************************/ *******************************************/
#define CACHE_VERSION 1 #define CACHE_VERSION 1
static void drun_write_str ( FILE *fd, const char *str ) static void drun_write_str ( FILE *fd, const char *str )
{ {
size_t l = (str == NULL? 0 : strlen(str)); size_t l = ( str == NULL ? 0 : strlen ( str ) );
fwrite ( &l, sizeof(l),1, fd ); fwrite ( &l, sizeof ( l ), 1, fd );
// Only write string if it is not NULL or empty. // Only write string if it is not NULL or empty.
if ( l > 0 ) { if ( l > 0 ) {
// Also writeout terminating '\0' // Also writeout terminating '\0'
fwrite ( str, 1, l+1, fd ); fwrite ( str, 1, l + 1, fd );
} }
} }
static void drun_read_string ( FILE *fd, char **str ) static void drun_read_string ( FILE *fd, char **str )
{ {
size_t l = 0; size_t l = 0;
if ( fread ( &l, sizeof(l), 1, fd ) != 1 ){ if ( fread ( &l, sizeof ( l ), 1, fd ) != 1 ) {
g_warning( "Failed to read entry, cache corrupt?" ); g_warning ( "Failed to read entry, cache corrupt?" );
return; return;
} }
(*str) = NULL; ( *str ) = NULL;
if ( l > 0 ) { if ( l > 0 ) {
// Include \0 // Include \0
l++; l++;
(*str) = g_malloc(l); ( *str ) = g_malloc ( l );
if ( fread ( (*str), 1, l, fd ) != l ){ if ( fread ( ( *str ), 1, l, fd ) != l ) {
g_warning( "Failed to read entry, cache corrupt?" ); g_warning ( "Failed to read entry, cache corrupt?" );
} }
} }
} }
static void drun_write_strv ( FILE *fd, char **str ) static void drun_write_strv ( FILE *fd, char **str )
{ {
guint vl = (str == NULL? 0 : g_strv_length ( str )); guint vl = ( str == NULL ? 0 : g_strv_length ( str ) );
fwrite ( &vl, sizeof(vl),1, fd ); fwrite ( &vl, sizeof ( vl ), 1, fd );
for ( guint index = 0; index < vl ; index++ ) { for ( guint index = 0; index < vl; index++ ) {
drun_write_str ( fd, str[index] ); drun_write_str ( fd, str[index] );
} }
} }
static void drun_read_stringv ( FILE *fd, char ***str ) static void drun_read_stringv ( FILE *fd, char ***str )
{ {
guint vl = 0; guint vl = 0;
(*str) = NULL; ( *str ) = NULL;
if ( fread ( &vl, sizeof(vl), 1, fd ) != 1 ){ if ( fread ( &vl, sizeof ( vl ), 1, fd ) != 1 ) {
g_warning( "Failed to read entry, cache corrupt?" ); g_warning ( "Failed to read entry, cache corrupt?" );
return; return;
} }
if ( vl > 0 ){ if ( vl > 0 ) {
// Include terminating NULL entry. // Include terminating NULL entry.
(*str) = g_malloc0((vl+1)*sizeof(**str)); ( *str ) = g_malloc0 ( ( vl + 1 ) * sizeof ( **str ) );
for ( guint index = 0; index < vl; index++ ) { for ( guint index = 0; index < vl; index++ ) {
drun_read_string ( fd, &((*str)[index])); drun_read_string ( fd, &( ( *str )[index] ) );
} }
} }
} }
static void write_cache ( DRunModePrivateData *pd, const char *cache_file ) static void write_cache ( DRunModePrivateData *pd, const char *cache_file )
{ {
if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) return; if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) {
return;
}
TICK_N ( "DRUN Write CACHE: start" ); TICK_N ( "DRUN Write CACHE: start" );
FILE *fd = fopen ( cache_file, "w" ); FILE *fd = fopen ( cache_file, "w" );
if ( fd == NULL ){ if ( fd == NULL ) {
g_warning ( "Failed to write to cache file" ); g_warning ( "Failed to write to cache file" );
return; return;
} }
uint8_t version = CACHE_VERSION; uint8_t version = CACHE_VERSION;
fwrite ( &version, sizeof(version),1, fd ); fwrite ( &version, sizeof ( version ), 1, fd );
fwrite ( &(pd->cmd_list_length), sizeof(pd->cmd_list_length),1,fd ); fwrite ( &( pd->cmd_list_length ), sizeof ( pd->cmd_list_length ), 1, fd );
for ( unsigned int index = 0; index < pd->cmd_list_length; index ++ ) for ( unsigned int index = 0; index < pd->cmd_list_length; index++ ) {
{ DRunModeEntry *entry = &( pd->entry_list[index] );
DRunModeEntry *entry = & ( pd->entry_list[index] );
drun_write_str ( fd, entry->action ); drun_write_str ( fd, entry->action );
drun_write_str ( fd, entry->root ); drun_write_str ( fd, entry->root );
@ -736,20 +737,20 @@ static void write_cache ( DRunModePrivateData *pd, const char *cache_file )
drun_write_strv ( fd, entry->keywords ); drun_write_strv ( fd, entry->keywords );
drun_write_str ( fd, entry->comment ); drun_write_str ( fd, entry->comment );
} }
fclose ( fd) ; fclose ( fd );
TICK_N ( "DRUN Write CACHE: end" ); TICK_N ( "DRUN Write CACHE: end" );
} }
/** /**
* Read cache file. returns FALSE when success. * Read cache file. returns FALSE when success.
*/ */
static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_file ) static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_file )
{ {
if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) return TRUE; if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) {
return TRUE;
}
if ( config.drun_reload_desktop_cache ) { if ( config.drun_reload_desktop_cache ) {
return TRUE; return TRUE;
@ -764,8 +765,7 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil
// Read version. // Read version.
uint8_t version = 0; uint8_t version = 0;
if ( fread ( &version, sizeof(version),1, fd ) != 1 ) if ( fread ( &version, sizeof ( version ), 1, fd ) != 1 ) {
{
fclose ( fd ); fclose ( fd );
g_warning ( "Cache corrupt, ignoring." ); g_warning ( "Cache corrupt, ignoring." );
TICK_N ( "DRUN Read CACHE: stop" ); TICK_N ( "DRUN Read CACHE: stop" );
@ -779,7 +779,7 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil
return FALSE; return FALSE;
} }
if ( fread ( &(pd->cmd_list_length), sizeof(pd->cmd_list_length),1,fd ) != 1 ){ if ( fread ( &( pd->cmd_list_length ), sizeof ( pd->cmd_list_length ), 1, fd ) != 1 ) {
fclose ( fd ); fclose ( fd );
g_warning ( "Cache corrupt, ignoring." ); g_warning ( "Cache corrupt, ignoring." );
TICK_N ( "DRUN Read CACHE: stop" ); TICK_N ( "DRUN Read CACHE: stop" );
@ -788,29 +788,27 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil
// set actual length to length; // set actual length to length;
pd->cmd_list_length_actual = pd->cmd_list_length; pd->cmd_list_length_actual = pd->cmd_list_length;
pd->entry_list = g_malloc0 ( pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) )); pd->entry_list = g_malloc0 ( pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) ) );
for ( unsigned int index = 0; index < pd->cmd_list_length; index++ ) for ( unsigned int index = 0; index < pd->cmd_list_length; index++ ) {
{ DRunModeEntry *entry = &( pd->entry_list[index] );
DRunModeEntry *entry = & ( pd->entry_list[index] );
drun_read_string ( fd, &(entry->action) ); drun_read_string ( fd, &( entry->action ) );
drun_read_string ( fd, &(entry->root) ); drun_read_string ( fd, &( entry->root ) );
drun_read_string ( fd, &(entry->path) ); drun_read_string ( fd, &( entry->path ) );
drun_read_string ( fd, &(entry->app_id) ); drun_read_string ( fd, &( entry->app_id ) );
drun_read_string ( fd, &(entry->desktop_id) ); drun_read_string ( fd, &( entry->desktop_id ) );
drun_read_string ( fd, &(entry->icon_name) ); drun_read_string ( fd, &( entry->icon_name ) );
drun_read_string ( fd, &(entry->exec) ); drun_read_string ( fd, &( entry->exec ) );
drun_read_string ( fd, &(entry->name) ); drun_read_string ( fd, &( entry->name ) );
drun_read_string ( fd, &(entry->generic_name) ); drun_read_string ( fd, &( entry->generic_name ) );
drun_read_stringv ( fd, &(entry->categories) ); drun_read_stringv ( fd, &( entry->categories ) );
drun_read_stringv ( fd, &(entry->keywords) ); drun_read_stringv ( fd, &( entry->keywords ) );
drun_read_string ( fd, &(entry->comment) ); drun_read_string ( fd, &( entry->comment ) );
} }
fclose ( fd ); fclose ( fd );
TICK_N ( "DRUN Read CACHE: stop" ); TICK_N ( "DRUN Read CACHE: stop" );
return FALSE; return FALSE;
@ -820,9 +818,7 @@ static void get_apps ( DRunModePrivateData *pd )
{ {
char *cache_file = g_build_filename ( cache_dir, DRUN_DESKTOP_CACHE_FILE, NULL ); char *cache_file = g_build_filename ( cache_dir, DRUN_DESKTOP_CACHE_FILE, NULL );
TICK_N ( "Get Desktop apps (start)" ); TICK_N ( "Get Desktop apps (start)" );
if ( drun_read_cache ( pd, cache_file ) ) if ( drun_read_cache ( pd, cache_file ) ) {
{
gchar *dir; gchar *dir;
// First read the user directory. // First read the user directory.
dir = g_build_filename ( g_get_user_data_dir (), "applications", NULL ); dir = g_build_filename ( g_get_user_data_dir (), "applications", NULL );
@ -906,8 +902,8 @@ static int drun_mode_init ( Mode *sw )
const char *current_desktop = g_getenv ( "XDG_CURRENT_DESKTOP" ); const char *current_desktop = g_getenv ( "XDG_CURRENT_DESKTOP" );
pd->current_desktop_list = current_desktop ? g_strsplit ( current_desktop, ":", 0 ) : NULL; pd->current_desktop_list = current_desktop ? g_strsplit ( current_desktop, ":", 0 ) : NULL;
if ( config.drun_categories && *(config.drun_categories) ){ if ( config.drun_categories && *( config.drun_categories ) ) {
pd->show_categories = g_strsplit(config.drun_categories, ",",0); pd->show_categories = g_strsplit ( config.drun_categories, ",", 0 );
} }
drun_mode_parse_entry_fields (); drun_mode_parse_entry_fields ();
@ -1000,27 +996,27 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
return g_strdup ( "Failed" ); return g_strdup ( "Failed" );
} }
/* Free temp storage. */ /* Free temp storage. */
DRunModeEntry *dr = &( pd->entry_list[selected_line] ); DRunModeEntry *dr = &( pd->entry_list[selected_line] );
gchar *cats = NULL; gchar *cats = NULL;
if ( dr->categories ){ if ( dr->categories ) {
char *tcats = g_strjoinv(",", dr->categories); char *tcats = g_strjoinv ( ",", dr->categories );
if ( tcats ) { if ( tcats ) {
cats = g_markup_escape_text ( tcats, -1 ); cats = g_markup_escape_text ( tcats, -1 );
g_free (tcats); g_free ( tcats );
} }
} }
gchar *keywords= NULL; gchar *keywords = NULL;
if ( dr->keywords ){ if ( dr->keywords ) {
char *tkeyw= g_strjoinv(",", dr->keywords); char *tkeyw = g_strjoinv ( ",", dr->keywords );
if ( tkeyw ) { if ( tkeyw ) {
keywords = g_markup_escape_text ( tkeyw, -1 ); keywords = g_markup_escape_text ( tkeyw, -1 );
g_free (tkeyw); g_free ( tkeyw );
} }
} }
// Needed for display. // Needed for display.
char *egn = NULL; char *egn = NULL;
char *en = NULL; char *en = NULL;
char *ec = NULL; char *ec = NULL;
if ( dr->generic_name ) { if ( dr->generic_name ) {
egn = g_markup_escape_text ( dr->generic_name, -1 ); egn = g_markup_escape_text ( dr->generic_name, -1 );
} }
@ -1028,22 +1024,21 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
en = g_markup_escape_text ( dr->name, -1 ); en = g_markup_escape_text ( dr->name, -1 );
} }
if ( dr->comment ) { if ( dr->comment ) {
ec = g_markup_escape_text ( dr->comment , -1 ); ec = g_markup_escape_text ( dr->comment, -1 );
} }
char *retv = helper_string_replace_if_exists ( config.drun_display_format, char *retv = helper_string_replace_if_exists ( config.drun_display_format,
"{generic}", egn, "{generic}", egn,
"{name}", en, "{name}", en,
"{comment}", ec, "{comment}", ec,
"{exec}", dr->exec, "{exec}", dr->exec,
"{categories}", cats, "{categories}", cats,
"{keywords}", keywords, "{keywords}", keywords,
NULL); NULL );
g_free ( egn ); g_free ( egn );
g_free ( en ); g_free ( en );
g_free ( ec ); g_free ( ec );
g_free(cats); g_free ( cats );
return retv; return retv;
} }

View file

@ -45,18 +45,16 @@
#include "mode-private.h" #include "mode-private.h"
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
#include "dialogs/dmenuscriptshared.h" #include "dialogs/dmenuscriptshared.h"
typedef struct typedef struct
{ {
/** ID of the current script. */ /** ID of the current script. */
unsigned int id; unsigned int id;
/** List of visible items. */ /** List of visible items. */
DmenuScriptEntry *cmd_list; DmenuScriptEntry *cmd_list;
/** length list of visible items. */ /** length list of visible items. */
unsigned int cmd_list_length; unsigned int cmd_list_length;
@ -77,18 +75,18 @@ typedef struct
*/ */
void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, size_t length ) void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, size_t length )
{ {
size_t length_key = 0;//strlen ( line ); size_t length_key = 0; //strlen ( line );
while ( length_key <= length && buffer[length_key] != '\x1f' ) { while ( length_key <= length && buffer[length_key] != '\x1f' ) {
length_key++; length_key++;
} }
if ( length_key < length ) { if ( length_key < length ) {
buffer[length_key] = '\0'; buffer[length_key] = '\0';
char *value = buffer + length_key + 1; char *value = buffer + length_key + 1;
if ( strcasecmp(buffer, "icon" ) == 0 ) { if ( strcasecmp ( buffer, "icon" ) == 0 ) {
entry->icon_name = g_strdup(value); entry->icon_name = g_strdup ( value );
} }
if ( strcasecmp(buffer, "meta" ) == 0 ) { if ( strcasecmp ( buffer, "meta" ) == 0 ) {
entry->meta = g_strdup(value); entry->meta = g_strdup ( value );
} }
} }
} }
@ -131,11 +129,11 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length )
static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, unsigned int *length ) static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, unsigned int *length )
{ {
int fd = -1; int fd = -1;
GError *error = NULL; GError *error = NULL;
DmenuScriptEntry *retv = NULL; DmenuScriptEntry *retv = NULL;
char **argv = NULL; char **argv = NULL;
int argc = 0; int argc = 0;
*length = 0; *length = 0;
if ( g_shell_parse_argv ( command, &argc, &argv, &error ) ) { if ( g_shell_parse_argv ( command, &argc, &argv, &error ) ) {
argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) );
@ -171,13 +169,13 @@ static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg,
actual_size += 256; actual_size += 256;
retv = g_realloc ( retv, ( actual_size ) * sizeof ( DmenuScriptEntry ) ); retv = g_realloc ( retv, ( actual_size ) * sizeof ( DmenuScriptEntry ) );
} }
size_t buf_length = strlen(buffer)+1; size_t buf_length = strlen ( buffer ) + 1;
retv[( *length )].entry = g_memdup ( buffer, buf_length); retv[( *length )].entry = g_memdup ( buffer, buf_length );
retv[( *length )].icon_name = NULL; retv[( *length )].icon_name = NULL;
retv[( *length )].meta = NULL; retv[( *length )].meta = NULL;
retv[(*length)].icon_fetch_uid = 0; retv[( *length )].icon_fetch_uid = 0;
if ( buf_length > 0 && (read_length > (ssize_t)buf_length) ) { if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) {
dmenuscript_parse_entry_extras ( sw, &(retv[(*length)]), buffer+buf_length, read_length-buf_length); dmenuscript_parse_entry_extras ( sw, &( retv[( *length )] ), buffer + buf_length, read_length - buf_length );
} }
retv[( *length ) + 1].entry = NULL; retv[( *length ) + 1].entry = NULL;
( *length )++; ( *length )++;
@ -242,7 +240,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
{ {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
ModeMode retv = MODE_EXIT; ModeMode retv = MODE_EXIT;
DmenuScriptEntry *new_list = NULL; DmenuScriptEntry *new_list = NULL;
unsigned int new_length = 0; unsigned int new_length = 0;
if ( ( mretv & MENU_NEXT ) ) { if ( ( mretv & MENU_NEXT ) ) {
@ -265,7 +263,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
// If a new list was generated, use that an loop around. // If a new list was generated, use that an loop around.
if ( new_list != NULL ) { if ( new_list != NULL ) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){ for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
g_free ( rmpd->cmd_list[i].entry ); g_free ( rmpd->cmd_list[i].entry );
g_free ( rmpd->cmd_list[i].icon_name ); g_free ( rmpd->cmd_list[i].icon_name );
g_free ( rmpd->cmd_list[i].meta ); g_free ( rmpd->cmd_list[i].meta );
@ -283,7 +281,7 @@ static void script_mode_destroy ( Mode *sw )
{ {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
if ( rmpd != NULL ) { if ( rmpd != NULL ) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){ for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
g_free ( rmpd->cmd_list[i].entry ); g_free ( rmpd->cmd_list[i].entry );
g_free ( rmpd->cmd_list[i].icon_name ); g_free ( rmpd->cmd_list[i].icon_name );
g_free ( rmpd->cmd_list[i].meta ); g_free ( rmpd->cmd_list[i].meta );
@ -299,8 +297,12 @@ static void script_mode_destroy ( Mode *sw )
} }
static inline unsigned int get_index ( unsigned int length, int index ) static inline unsigned int get_index ( unsigned int length, int index )
{ {
if ( index >= 0 ) return index; if ( index >= 0 ) {
if ( ((unsigned int)-index) <= length ) return (length+index); return index;
}
if ( ( (unsigned int) -index ) <= length ) {
return length + index;
}
// Out of range. // Out of range.
return UINT_MAX; return UINT_MAX;
} }
@ -330,20 +332,20 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ) static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{ {
ScriptModePrivateData *rmpd = sw->private_data; ScriptModePrivateData *rmpd = sw->private_data;
int match = 1; int match = 1;
if ( tokens ) { if ( tokens ) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
rofi_int_matcher *ftokens[2] = { tokens[j], NULL }; rofi_int_matcher *ftokens[2] = { tokens[j], NULL };
int test = 0; int test = 0;
test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry ); test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry );
if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) { if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) {
test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta); test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta );
} }
if ( test == 0 ) { if ( test == 0 ) {
match = 0; match = 0;
} }
} }
} }
return match; return match;
} }
@ -356,7 +358,7 @@ static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_
{ {
ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw ); ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] );
if ( dr->icon_name == NULL ) { if ( dr->icon_name == NULL ) {
return NULL; return NULL;
} }

View file

@ -59,7 +59,8 @@
/** /**
* Holding an ssh entry. * Holding an ssh entry.
*/ */
typedef struct _SshEntry { typedef struct _SshEntry
{
/** SSH hostname */ /** SSH hostname */
char *hostname; char *hostname;
/** SSH port number */ /** SSH port number */
@ -70,9 +71,9 @@ typedef struct _SshEntry {
*/ */
typedef struct typedef struct
{ {
GList *user_known_hosts; GList *user_known_hosts;
/** List if available ssh hosts.*/ /** List if available ssh hosts.*/
SshEntry *hosts_list; SshEntry *hosts_list;
/** Length of the #hosts_list.*/ /** Length of the #hosts_list.*/
unsigned int hosts_list_length; unsigned int hosts_list_length;
} SSHModePrivateData; } SSHModePrivateData;
@ -88,7 +89,6 @@ typedef struct
*/ */
#define SSH_TOKEN_DELIM "= \t\r\n" #define SSH_TOKEN_DELIM "= \t\r\n"
/** /**
* @param entry The host to connect too * @param entry The host to connect too
* *
@ -96,18 +96,18 @@ typedef struct
* *
* @returns FALSE On failure, TRUE on success * @returns FALSE On failure, TRUE on success
*/ */
static int execshssh ( const SshEntry *entry) static int execshssh ( const SshEntry *entry )
{ {
char **args = NULL; char **args = NULL;
int argsv = 0; int argsv = 0;
gchar *portstr = NULL; gchar *portstr = NULL;
if ( entry->port > 0 ) { if ( entry->port > 0 ) {
portstr = g_strdup_printf("%d", entry->port); portstr = g_strdup_printf ( "%d", entry->port );
} }
helper_parse_setup ( config.ssh_command, &args, &argsv, helper_parse_setup ( config.ssh_command, &args, &argsv,
"{host}", entry->hostname, "{host}", entry->hostname,
"{port}", portstr, "{port}", portstr,
(char *) 0 ); (char *) 0 );
g_free ( portstr ); g_free ( portstr );
gsize l = strlen ( "Connecting to '' via rofi" ) + strlen ( entry->hostname ) + 1; gsize l = strlen ( "Connecting to '' via rofi" ) + strlen ( entry->hostname ) + 1;
@ -130,7 +130,7 @@ static int execshssh ( const SshEntry *entry)
*/ */
static void exec_ssh ( const SshEntry *entry ) static void exec_ssh ( const SshEntry *entry )
{ {
if ( !(entry->hostname )|| !(entry->hostname[0]) ) { if ( !( entry->hostname ) || !( entry->hostname[0] ) ) {
return; return;
} }
@ -143,10 +143,11 @@ static void exec_ssh ( const SshEntry *entry )
char *path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL ); char *path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
// TODO update. // TODO update.
if ( entry->port > 0 ) { if ( entry->port > 0 ) {
char *store = g_strdup_printf("%s\x1F%d", entry->hostname, entry->port ); char *store = g_strdup_printf ( "%s\x1F%d", entry->hostname, entry->port );
history_set ( path, store ); history_set ( path, store );
g_free ( store ); g_free ( store );
} else { }
else {
history_set ( path, entry->hostname ); history_set ( path, entry->hostname );
} }
g_free ( path ); g_free ( path );
@ -178,16 +179,16 @@ static void delete_ssh ( const char *host )
*/ */
static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsigned int *length ) static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsigned int *length )
{ {
FILE *fd = fopen ( path, "r" ); FILE *fd = fopen ( path, "r" );
if ( fd != NULL ) { if ( fd != NULL ) {
char *buffer = NULL; char *buffer = NULL;
size_t buffer_length = 0; size_t buffer_length = 0;
// Reading one line per time. // Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Strip whitespace. // Strip whitespace.
char *start = g_strstrip(&(buffer[0])); char *start = g_strstrip ( &( buffer[0] ) );
// Find start. // Find start.
if ( *start == '#' || *start == '@' ){ if ( *start == '#' || *start == '@' ) {
// skip comments or cert-authority or revoked items. // skip comments or cert-authority or revoked items.
continue; continue;
} }
@ -196,32 +197,34 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi
continue; continue;
} }
// Find end of hostname set. // Find end of hostname set.
char *end = strstr ( start, " " ); char *end = strstr ( start, " " );
if ( end == NULL ) { if ( end == NULL ) {
// Something is wrong. // Something is wrong.
continue; continue;
} }
*end = '\0'; *end = '\0';
char *sep = start; char *sep = start;
start = strsep(&sep,", " ); start = strsep ( &sep, ", " );
while ( start ) while ( start ) {
{
int port = 0; int port = 0;
if ( start[0] == '[' ) { if ( start[0] == '[' ) {
start++; start++;
char *end = strchr ( start, ']'); char *end = strchr ( start, ']' );
if ( end[1] == ':' ){ if ( end[1] == ':' ) {
*end = '\0'; *end = '\0';
errno = 0; errno = 0;
gchar *endptr = NULL; gchar *endptr = NULL;
gint64 number = g_ascii_strtoll ( &(end[2]), &endptr, 10); gint64 number = g_ascii_strtoll ( &( end[2] ), &endptr, 10 );
if ( errno != 0 ) { if ( errno != 0 ) {
g_warning ( "Failed to parse port number: %s.", &(end[2]) ); g_warning ( "Failed to parse port number: %s.", &( end[2] ) );
} else if ( endptr == &(end[2])) { }
g_warning ( "Failed to parse port number: %s, invalid number.", &(end[2]) ); else if ( endptr == &( end[2] ) ) {
} else if ( number < 0 || number > 65535 ) { g_warning ( "Failed to parse port number: %s, invalid number.", &( end[2] ) );
g_warning ( "Failed to parse port number: %s, out of range.", &(end[2]) ); }
} else { else if ( number < 0 || number > 65535 ) {
g_warning ( "Failed to parse port number: %s, out of range.", &( end[2] ) );
}
else {
port = number; port = number;
} }
} }
@ -245,7 +248,7 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi
retv[( *length ) + 1].port = 0; retv[( *length ) + 1].port = 0;
( *length )++; ( *length )++;
} }
start = strsep(&sep,", " ); start = strsep ( &sep, ", " );
} }
} }
if ( buffer != NULL ) { if ( buffer != NULL ) {
@ -254,7 +257,8 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi
if ( fclose ( fd ) != 0 ) { if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) ); g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) );
} }
} else { }
else {
g_debug ( "Failed to open KnownHostFile: '%s'", path ); g_debug ( "Failed to open KnownHostFile: '%s'", path );
} }
@ -338,12 +342,13 @@ static SshEntry *read_hosts_file ( SshEntry * retv, unsigned int *length )
static void add_known_hosts_file ( SSHModePrivateData *pd, const char *token ) static void add_known_hosts_file ( SSHModePrivateData *pd, const char *token )
{ {
GList *item = g_list_find_custom ( pd->user_known_hosts, token, (GCompareFunc)g_strcmp0 ); GList *item = g_list_find_custom ( pd->user_known_hosts, token, (GCompareFunc) g_strcmp0 );
if ( item == NULL ) { if ( item == NULL ) {
g_debug("Add '%s' to UserKnownHost list", token); g_debug ( "Add '%s' to UserKnownHost list", token );
pd->user_known_hosts = g_list_append ( pd->user_known_hosts, g_strdup ( token ) ); pd->user_known_hosts = g_list_append ( pd->user_known_hosts, g_strdup ( token ) );
} else { }
g_debug("File '%s' already in UserKnownHostsFile list", token); else {
g_debug ( "File '%s' already in UserKnownHostsFile list", token );
} }
} }
@ -368,7 +373,7 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename
if ( !token || *token == '#' ) { if ( !token || *token == '#' ) {
continue; continue;
} }
char *low_token = g_ascii_strdown(token, -1); char *low_token = g_ascii_strdown ( token, -1 );
if ( g_strcmp0 ( low_token, "include" ) == 0 ) { if ( g_strcmp0 ( low_token, "include" ) == 0 ) {
token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ); token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer );
g_debug ( "Found Include: %s", token ); g_debug ( "Found Include: %s", token );
@ -396,7 +401,7 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename
} }
else if ( g_strcmp0 ( low_token, "userknownhostsfile" ) == 0 ) { else if ( g_strcmp0 ( low_token, "userknownhostsfile" ) == 0 ) {
while ( ( token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ) ) ) { while ( ( token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ) ) ) {
g_debug("Found extra UserKnownHostsFile: %s", token); g_debug ( "Found extra UserKnownHostsFile: %s", token );
add_known_hosts_file ( pd, token ); add_known_hosts_file ( pd, token );
} }
} }
@ -463,7 +468,7 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename
*/ */
static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length ) static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
{ {
SshEntry *retv = NULL; SshEntry *retv = NULL;
unsigned int num_favorites = 0; unsigned int num_favorites = 0;
char *path; char *path;
@ -474,29 +479,32 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL ); path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
char **h = history_get_list ( path, length ); char **h = history_get_list ( path, length );
retv = malloc ( (*length)*sizeof(SshEntry)); retv = malloc ( ( *length ) * sizeof ( SshEntry ) );
for ( unsigned int i = 0; i < (*length); i++ ){ for ( unsigned int i = 0; i < ( *length ); i++ ) {
int port = 0; int port = 0;
char *portstr = strchr ( h[i], '\x1F' ); char *portstr = strchr ( h[i], '\x1F' );
if ( portstr != NULL ) { if ( portstr != NULL ) {
*portstr = '\0'; *portstr = '\0';
errno = 0; errno = 0;
gchar *endptr= NULL; gchar *endptr = NULL;
gint64 number = g_ascii_strtoll ( &(portstr[1]), &endptr, 10); gint64 number = g_ascii_strtoll ( &( portstr[1] ), &endptr, 10 );
if ( errno != 0 ) { if ( errno != 0 ) {
g_warning ( "Failed to parse port number: %s.", &(portstr[1]) ); g_warning ( "Failed to parse port number: %s.", &( portstr[1] ) );
} else if ( endptr == &(portstr[1])) { }
g_warning ( "Failed to parse port number: %s, invalid number.", &(portstr[1]) ); else if ( endptr == &( portstr[1] ) ) {
} else if ( number < 0 || number > 65535 ) { g_warning ( "Failed to parse port number: %s, invalid number.", &( portstr[1] ) );
g_warning ( "Failed to parse port number: %s, out of range.", &(portstr[1]) ); }
} else { else if ( number < 0 || number > 65535 ) {
g_warning ( "Failed to parse port number: %s, out of range.", &( portstr[1] ) );
}
else {
port = number; port = number;
} }
} }
retv[i].hostname = h[i]; retv[i].hostname = h[i];
retv[i].port = port; retv[i].port = port;
} }
g_free (h); g_free ( h );
g_free ( path ); g_free ( path );
num_favorites = ( *length ); num_favorites = ( *length );
@ -509,23 +517,21 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
char *path = g_build_filename ( g_get_home_dir (), ".ssh", "known_hosts", NULL ); char *path = g_build_filename ( g_get_home_dir (), ".ssh", "known_hosts", NULL );
retv = read_known_hosts_file ( path, retv, length ); retv = read_known_hosts_file ( path, retv, length );
g_free ( path ); g_free ( path );
for ( GList *iter = g_list_first ( pd->user_known_hosts); iter; iter = g_list_next ( iter ) ) { for ( GList *iter = g_list_first ( pd->user_known_hosts ); iter; iter = g_list_next ( iter ) ) {
char *path = rofi_expand_path ( (const char *)iter->data); char *path = rofi_expand_path ( (const char *) iter->data );
retv = read_known_hosts_file ( (const char*)path, retv, length ); retv = read_known_hosts_file ( (const char*) path, retv, length );
g_free (path); g_free ( path );
} }
} }
if ( config.parse_hosts == TRUE ) { if ( config.parse_hosts == TRUE ) {
retv = read_hosts_file ( retv, length ); retv = read_hosts_file ( retv, length );
} }
g_free ( path ); g_free ( path );
return retv; return retv;
} }
/** /**
* @param sw Object handle to the SSH Mode object * @param sw Object handle to the SSH Mode object
* *
@ -563,8 +569,8 @@ static void ssh_mode_destroy ( Mode *sw )
{ {
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw ); SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) { if ( rmpd != NULL ) {
for ( unsigned int i = 0; i < rmpd->hosts_list_length; i++ ){ for ( unsigned int i = 0; i < rmpd->hosts_list_length; i++ ) {
g_free( rmpd->hosts_list[i].hostname ); g_free ( rmpd->hosts_list[i].hostname );
} }
g_list_free_full ( rmpd->user_known_hosts, g_free ); g_list_free_full ( rmpd->user_known_hosts, g_free );
g_free ( rmpd->hosts_list ); g_free ( rmpd->hosts_list );
@ -597,7 +603,7 @@ static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned in
retv = ( mretv & MENU_LOWER_MASK ); retv = ( mretv & MENU_LOWER_MASK );
} }
else if ( ( mretv & MENU_OK ) && rmpd->hosts_list[selected_line].hostname != NULL ) { else if ( ( mretv & MENU_OK ) && rmpd->hosts_list[selected_line].hostname != NULL ) {
exec_ssh ( &(rmpd->hosts_list[selected_line]) ); exec_ssh ( &( rmpd->hosts_list[selected_line] ) );
} }
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
SshEntry entry = { .hostname = *input, .port = 0 }; SshEntry entry = { .hostname = *input, .port = 0 };

View file

@ -470,7 +470,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
ModeModePrivateData *pd = (ModeModePrivateData *) mode_get_private_data ( sw ); ModeModePrivateData *pd = (ModeModePrivateData *) mode_get_private_data ( sw );
// find window list // find window list
xcb_window_t curr_win_id; xcb_window_t curr_win_id;
int found = 0; int found = 0;
// Create cache // Create cache
@ -488,7 +488,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
} }
c = xcb_ewmh_get_client_list_stacking ( &xcb->ewmh, 0 ); c = xcb_ewmh_get_client_list_stacking ( &xcb->ewmh, 0 );
xcb_ewmh_get_windows_reply_t clients = {0,}; xcb_ewmh_get_windows_reply_t clients = { 0, };
if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb->ewmh, c, &clients, NULL ) ) { if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb->ewmh, c, &clients, NULL ) ) {
found = 1; found = 1;
} }
@ -498,7 +498,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
found = 1; found = 1;
} }
} }
if ( ! found ) { if ( !found ) {
return; return;
} }

View file

@ -79,7 +79,6 @@ void cmd_set_arguments ( int argc, char **argv )
stored_argv = argv; stored_argv = argv;
} }
int helper_parse_setup ( char * string, char ***output, int *length, ... ) int helper_parse_setup ( char * string, char ***output, int *length, ... )
{ {
GError *error = NULL; GError *error = NULL;
@ -433,8 +432,8 @@ PangoAttrList *helper_token_match_get_pango_attr ( RofiHighlightColorStyle th, r
pa->end_index = end; pa->end_index = end;
pango_attr_list_insert ( retv, pa ); pango_attr_list_insert ( retv, pa );
if ( th.color.alpha < 1.0 ){ if ( th.color.alpha < 1.0 ) {
pa = pango_attr_foreground_alpha_new(th.color.alpha*65535); pa = pango_attr_foreground_alpha_new ( th.color.alpha * 65535 );
pa->start_index = start; pa->start_index = start;
pa->end_index = end; pa->end_index = end;
pango_attr_list_insert ( retv, pa ); pango_attr_list_insert ( retv, pa );
@ -1135,12 +1134,13 @@ cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int he
static void parse_pair ( char *input, rofi_range_pair *item ) static void parse_pair ( char *input, rofi_range_pair *item )
{ {
// Skip leading blanks. // Skip leading blanks.
while ( input != NULL && isblank(*input) ) while ( input != NULL && isblank ( *input ) ) {
++input; ++input;
}
const char *sep[] = { "-", ":" }; const char *sep[] = { "-", ":" };
int pythonic = ( strchr(input, ':') || input[0] == '-' ) ? 1 : 0; int pythonic = ( strchr ( input, ':' ) || input[0] == '-' ) ? 1 : 0;
int index = 0; int index = 0;
for ( char *token = strsep ( &input, sep[pythonic] ); token != NULL; token = strsep ( &input, sep[pythonic] ) ) { for ( char *token = strsep ( &input, sep[pythonic] ); token != NULL; token = strsep ( &input, sep[pythonic] ) ) {
if ( index == 0 ) { if ( index == 0 ) {
@ -1208,12 +1208,13 @@ void rofi_output_formatted_line ( const char *format, const char *string, int se
} }
else if ( format[i] == 'p' ) { else if ( format[i] == 'p' ) {
char *esc = NULL; char *esc = NULL;
pango_parse_markup(string, -1, 0, NULL, &esc, NULL, NULL); pango_parse_markup ( string, -1, 0, NULL, &esc, NULL, NULL );
if ( esc ){ if ( esc ) {
fputs ( esc, stdout ); fputs ( esc, stdout );
g_free ( esc ); g_free ( esc );
} else { }
fputs ( "invalid string" , stdout ); else {
fputs ( "invalid string", stdout );
} }
} }
else if ( format[i] == 'q' ) { else if ( format[i] == 'q' ) {
@ -1241,15 +1242,14 @@ void rofi_output_formatted_line ( const char *format, const char *string, int se
fflush ( stdout ); fflush ( stdout );
} }
static gboolean helper_eval_cb2 ( const GMatchInfo *info, GString *res, gpointer data ) static gboolean helper_eval_cb2 ( const GMatchInfo *info, GString *res, gpointer data )
{ {
gchar *match; gchar *match;
// Get the match // Get the match
int num_match = g_match_info_get_match_count(info); int num_match = g_match_info_get_match_count ( info );
// Just {text} This is inside () 5. // Just {text} This is inside () 5.
if ( num_match == 5 ) { if ( num_match == 5 ) {
match = g_match_info_fetch ( info, 4); match = g_match_info_fetch ( info, 4 );
if ( match != NULL ) { if ( match != NULL ) {
// Lookup the match, so we can replace it. // Lookup the match, so we can replace it.
gchar *r = g_hash_table_lookup ( (GHashTable *) data, match ); gchar *r = g_hash_table_lookup ( (GHashTable *) data, match );
@ -1263,21 +1263,21 @@ static gboolean helper_eval_cb2 ( const GMatchInfo *info, GString *res, gpointer
} }
// {} with [] guard around it. // {} with [] guard around it.
else if ( num_match == 4 ) { else if ( num_match == 4 ) {
match = g_match_info_fetch ( info, 2); match = g_match_info_fetch ( info, 2 );
if ( match != NULL ) { if ( match != NULL ) {
// Lookup the match, so we can replace it. // Lookup the match, so we can replace it.
gchar *r = g_hash_table_lookup ( (GHashTable *) data, match ); gchar *r = g_hash_table_lookup ( (GHashTable *) data, match );
if ( r != NULL ) { if ( r != NULL ) {
// Add (optional) prefix // Add (optional) prefix
gchar *prefix = g_match_info_fetch (info, 1); gchar *prefix = g_match_info_fetch ( info, 1 );
g_string_append ( res, prefix ); g_string_append ( res, prefix );
g_free (prefix ); g_free ( prefix );
// Append the replacement to the string. // Append the replacement to the string.
g_string_append ( res, r ); g_string_append ( res, r );
// Add (optional) postfix // Add (optional) postfix
gchar *post = g_match_info_fetch (info, 3); gchar *post = g_match_info_fetch ( info, 3 );
g_string_append ( res, post ); g_string_append ( res, post );
g_free (post ); g_free ( post );
} }
// Free match. // Free match.
g_free ( match ); g_free ( match );
@ -1292,7 +1292,7 @@ char *helper_string_replace_if_exists ( char * string, ... )
{ {
GHashTable *h; GHashTable *h;
h = g_hash_table_new ( g_str_hash, g_str_equal ); h = g_hash_table_new ( g_str_hash, g_str_equal );
va_list ap; va_list ap;
va_start ( ap, string ); va_start ( ap, string );
// Add list from variable arguments. // Add list from variable arguments.
while ( 1 ) { while ( 1 ) {
@ -1324,12 +1324,12 @@ char *helper_string_replace_if_exists ( char * string, ... )
*/ */
char *helper_string_replace_if_exists_v ( char * string, GHashTable *h ) char *helper_string_replace_if_exists_v ( char * string, GHashTable *h )
{ {
GError *error = NULL; GError *error = NULL;
char *res = NULL; char *res = NULL;
// Replace hits within {-\w+}. // Replace hits within {-\w+}.
GRegex *reg = g_regex_new ( "\\[(.*)({[-\\w]+})(.*)\\]|({[\\w-]+})", 0, 0, &error ); GRegex *reg = g_regex_new ( "\\[(.*)({[-\\w]+})(.*)\\]|({[\\w-]+})", 0, 0, &error );
if ( error == NULL ){ if ( error == NULL ) {
res = g_regex_replace_eval ( reg, string, -1, 0, 0, helper_eval_cb2, h, &error ); res = g_regex_replace_eval ( reg, string, -1, 0, 0, helper_eval_cb2, h, &error );
} }
// Free regex. // Free regex.

View file

@ -77,7 +77,7 @@ ActionBindingEntry rofi_bindings[] =
{ .id = ROW_LAST, .name = "kb-row-last", .binding = "End,KP_End", .comment = "Go to the last entry" }, { .id = ROW_LAST, .name = "kb-row-last", .binding = "End,KP_End", .comment = "Go to the last entry" },
{ .id = ROW_SELECT, .name = "kb-row-select", .binding = "Control+space", .comment = "Set selected item as input text" }, { .id = ROW_SELECT, .name = "kb-row-select", .binding = "Control+space", .comment = "Set selected item as input text" },
{ .id = SCREENSHOT, .name = "kb-screenshot", .binding = "Alt+S", .comment = "Take a screenshot of the rofi window" }, { .id = SCREENSHOT, .name = "kb-screenshot", .binding = "Alt+S", .comment = "Take a screenshot of the rofi window" },
{ .id = CHANGE_ELLIPSIZE, .name = "kb-ellipsize", .binding = "Alt+period", .comment = "Toggle between ellipsize modes for displayed data" }, { .id = CHANGE_ELLIPSIZE, .name = "kb-ellipsize", .binding = "Alt+period", .comment = "Toggle between ellipsize modes for displayed data" },
{ .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .binding = "grave,dead_grave", .comment = "Toggle case sensitivity" }, { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .binding = "grave,dead_grave", .comment = "Toggle case sensitivity" },
{ .id = TOGGLE_SORT, .name = "kb-toggle-sort", .binding = "Alt+grave", .comment = "Toggle sort" }, { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .binding = "Alt+grave", .comment = "Toggle sort" },
{ .id = CANCEL, .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" }, { .id = CANCEL, .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" },

View file

@ -115,11 +115,11 @@ NkBindings *bindings = NULL;
GMainLoop *main_loop = NULL; GMainLoop *main_loop = NULL;
/** Flag indicating we are in dmenu mode. */ /** Flag indicating we are in dmenu mode. */
static int dmenu_mode = FALSE; static int dmenu_mode = FALSE;
/** Rofi's return code */ /** Rofi's return code */
int return_code = EXIT_SUCCESS; int return_code = EXIT_SUCCESS;
static gboolean old_config_format = FALSE; static gboolean old_config_format = FALSE;
void process_result ( RofiViewState *state ); void process_result ( RofiViewState *state );
@ -364,8 +364,8 @@ static void help_print_disabled_mode ( const char *mode )
} }
static void help_print_mode_not_found ( const char *mode ) static void help_print_mode_not_found ( const char *mode )
{ {
GString *str = g_string_new (""); GString *str = g_string_new ( "" );
g_string_printf(str, "Mode %s is not found.\nThe following modi are known:\n", mode ); g_string_printf ( str, "Mode %s is not found.\nThe following modi are known:\n", mode );
for ( unsigned int i = 0; i < num_available_modi; i++ ) { for ( unsigned int i = 0; i < num_available_modi; i++ ) {
gboolean active = FALSE; gboolean active = FALSE;
for ( unsigned int j = 0; j < num_modi; j++ ) { for ( unsigned int j = 0; j < num_modi; j++ ) {
@ -374,10 +374,10 @@ static void help_print_mode_not_found ( const char *mode )
break; break;
} }
} }
g_string_append_printf (str, " * %s%s\n", g_string_append_printf ( str, " * %s%s\n",
active ? "+" : "", active ? "+" : "",
available_modi[i]->name available_modi[i]->name
); );
} }
rofi_add_error_message ( str ); rofi_add_error_message ( str );
} }
@ -663,7 +663,6 @@ static void show_error_dialog ()
rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP ); rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP );
g_string_free ( emesg, TRUE ); g_string_free ( emesg, TRUE );
rofi_set_return_code ( EX_DATAERR ); rofi_set_return_code ( EX_DATAERR );
} }
static gboolean startup ( G_GNUC_UNUSED gpointer data ) static gboolean startup ( G_GNUC_UNUSED gpointer data )
@ -852,11 +851,12 @@ int main ( int argc, char *argv[] )
if ( find_arg ( "-no-config" ) < 0 ) { if ( find_arg ( "-no-config" ) < 0 ) {
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL ); gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL );
g_debug ( "Testing: %s", etc); g_debug ( "Testing: %s", etc );
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
g_debug ( "Parsing: %s", etc); g_debug ( "Parsing: %s", etc );
rofi_theme_parse_file ( etc ); rofi_theme_parse_file ( etc );
} else { }
else {
// Load distro default settings // Load distro default settings
gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL );
if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) { if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) {
@ -896,7 +896,7 @@ int main ( int argc, char *argv[] )
TICK_N ( "Load cmd config " ); TICK_N ( "Load cmd config " );
if ( old_config_format ) { if ( old_config_format ) {
g_warning ( "The old Xresources based configuration format is deprecated."); g_warning ( "The old Xresources based configuration format is deprecated." );
g_warning ( "Please upgrade: rofi -upgrade-config." ); g_warning ( "Please upgrade: rofi -upgrade-config." );
} }
parse_keys_abe ( bindings ); parse_keys_abe ( bindings );
@ -975,9 +975,8 @@ int main ( int argc, char *argv[] )
cleanup (); cleanup ();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if ( find_arg ( "-upgrade-config") >= 0 ) { if ( find_arg ( "-upgrade-config" ) >= 0 ) {
setup_modi ();
setup_modi();
for ( unsigned int i = 0; i < num_modi; i++ ) { for ( unsigned int i = 0; i < num_modi; i++ ) {
mode_init ( modi[i] ); mode_init ( modi[i] );
@ -986,7 +985,7 @@ int main ( int argc, char *argv[] )
const char *cpath = g_get_user_config_dir (); const char *cpath = g_get_user_config_dir ();
if ( cpath ) { if ( cpath ) {
char *fcpath = g_build_filename ( cpath, "rofi", NULL ); char *fcpath = g_build_filename ( cpath, "rofi", NULL );
if ( !g_file_test ( fcpath, G_FILE_TEST_IS_DIR ) && g_mkdir_with_parents ( fcpath, 0700) < 0 ) { if ( !g_file_test ( fcpath, G_FILE_TEST_IS_DIR ) && g_mkdir_with_parents ( fcpath, 0700 ) < 0 ) {
g_warning ( "Failed to create rofi configuration directory: %s", fcpath ); g_warning ( "Failed to create rofi configuration directory: %s", fcpath );
cleanup (); cleanup ();
g_free ( fcpath ); g_free ( fcpath );
@ -1000,20 +999,21 @@ int main ( int argc, char *argv[] )
g_free ( fcpath ); g_free ( fcpath );
return EXIT_FAILURE; return EXIT_FAILURE;
} }
FILE *fd = fopen(fcpath, "w" ); FILE *fd = fopen ( fcpath, "w" );
if ( fd == NULL ) { if ( fd == NULL ) {
g_warning ( "Failed to open new rofi configuration file: %s: %s", fcpath , strerror(errno)); g_warning ( "Failed to open new rofi configuration file: %s: %s", fcpath, strerror ( errno ) );
cleanup (); cleanup ();
g_free ( fcpath ); g_free ( fcpath );
return EXIT_FAILURE; return EXIT_FAILURE;
} }
config_parse_dump_config_rasi_format ( fd, TRUE ); config_parse_dump_config_rasi_format ( fd, TRUE );
fprintf(stdout, "\n***** Generated configuration file in: %s *****\n", fcpath ); fprintf ( stdout, "\n***** Generated configuration file in: %s *****\n", fcpath );
fflush ( fd ); fflush ( fd );
fclose ( fd ); fclose ( fd );
g_free( fcpath ); g_free ( fcpath );
} else { }
else {
g_warning ( "Failed to get user configuration directory." ); g_warning ( "Failed to get user configuration directory." );
cleanup (); cleanup ();
return EXIT_FAILURE; return EXIT_FAILURE;

View file

@ -96,8 +96,8 @@ Property* rofi_theme_property_copy ( Property *p )
case P_LINK: case P_LINK:
retv->value.link.name = g_strdup ( p->value.link.name ); retv->value.link.name = g_strdup ( p->value.link.name );
retv->value.link.ref = NULL; retv->value.link.ref = NULL;
if ( p->value.link.def_value ){ if ( p->value.link.def_value ) {
retv->value.link.def_value = rofi_theme_property_copy(p->value.link.def_value); retv->value.link.def_value = rofi_theme_property_copy ( p->value.link.def_value );
} }
break; break;
default: default:
@ -129,49 +129,44 @@ void rofi_theme_property_free ( Property *p )
*/ */
static void rofi_theme_insert_listview_backwards_fix ( void ) static void rofi_theme_insert_listview_backwards_fix ( void )
{ {
GHashTable *table= g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); GHashTable *table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free );
ThemeWidget *t = rofi_theme_find_or_create_name ( rofi_theme, "element" ); ThemeWidget *t = rofi_theme_find_or_create_name ( rofi_theme, "element" );
ThemeWidget *tt = rofi_theme_find_or_create_name ( rofi_theme, "element-text" ); ThemeWidget *tt = rofi_theme_find_or_create_name ( rofi_theme, "element-text" );
ThemeWidget *ti = rofi_theme_find_or_create_name ( rofi_theme, "element-icon" ); ThemeWidget *ti = rofi_theme_find_or_create_name ( rofi_theme, "element-icon" );
// Inherit text color // Inherit text color
Property *ptc = rofi_theme_property_create ( P_INHERIT ); Property *ptc = rofi_theme_property_create ( P_INHERIT );
ptc->name = g_strdup("text-color"); ptc->name = g_strdup ( "text-color" );
g_hash_table_replace ( table, ptc->name, ptc ); g_hash_table_replace ( table, ptc->name, ptc );
// Transparent background // Transparent background
Property *ptb = rofi_theme_property_create ( P_COLOR ); Property *ptb = rofi_theme_property_create ( P_COLOR );
ptb->name = g_strdup("background-color"); ptb->name = g_strdup ( "background-color" );
ptb->value.color.red = 0.0; ptb->value.color.red = 0.0;
ptb->value.color.green = 0.0; ptb->value.color.green = 0.0;
ptb->value.color.blue = 0.0; ptb->value.color.blue = 0.0;
ptb->value.color.alpha = 0.0; ptb->value.color.alpha = 0.0;
g_hash_table_replace ( table, ptb->name, ptb ); g_hash_table_replace ( table, ptb->name, ptb );
rofi_theme_widget_add_properties ( tt, table );
rofi_theme_widget_add_properties ( tt, table); RofiDistance dsize = (RofiDistance){ 1.2, ROFI_PU_CH, ROFI_HL_SOLID };
Property *pts = rofi_theme_property_create ( P_PADDING );
RofiDistance dsize = (RofiDistance){1.2, ROFI_PU_CH, ROFI_HL_SOLID };
Property *pts = rofi_theme_property_create ( P_PADDING );
pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize; pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize;
pts->name = g_strdup ( "size" ); pts->name = g_strdup ( "size" );
g_hash_table_replace ( table, pts->name, pts ); g_hash_table_replace ( table, pts->name, pts );
rofi_theme_widget_add_properties ( ti, table );
rofi_theme_widget_add_properties ( ti, table);
/** Add spacing between icon and text. */ /** Add spacing between icon and text. */
g_hash_table_destroy ( table ); g_hash_table_destroy ( table );
table= g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free );
Property *psp = rofi_theme_property_create ( P_PADDING ); Property *psp = rofi_theme_property_create ( P_PADDING );
psp->name = g_strdup( "spacing" ); psp->name = g_strdup ( "spacing" );
RofiDistance d = (RofiDistance){5, ROFI_PU_PX, ROFI_HL_SOLID }; RofiDistance d = (RofiDistance){ 5, ROFI_PU_PX, ROFI_HL_SOLID };
psp->value.padding = (RofiPadding){d,d,d,d}; psp->value.padding = (RofiPadding){ d, d, d, d };
g_hash_table_replace ( table, psp->name, psp ); g_hash_table_replace ( table, psp->name, psp );
rofi_theme_widget_add_properties ( t, table); rofi_theme_widget_add_properties ( t, table );
g_hash_table_destroy ( table ); g_hash_table_destroy ( table );
} }
void rofi_theme_reset ( void ) void rofi_theme_reset ( void )
@ -247,102 +242,102 @@ static void int_rofi_theme_print_property ( Property *p )
{ {
switch ( p->type ) switch ( p->type )
{ {
case P_LIST: case P_LIST:
printf ( "[ " ); printf ( "[ " );
for ( GList *iter = p->value.list; iter != NULL; iter = g_list_next ( iter ) ) { for ( GList *iter = p->value.list; iter != NULL; iter = g_list_next ( iter ) ) {
printf ( "%s", (char *) ( iter->data ) ); printf ( "%s", (char *) ( iter->data ) );
if ( iter->next != NULL ) { if ( iter->next != NULL ) {
printf ( "," ); printf ( "," );
}
} }
printf ( " ]" ); }
break; printf ( " ]" );
case P_ORIENTATION: break;
printf ( "%s", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" ); case P_ORIENTATION:
break; printf ( "%s", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" );
case P_HIGHLIGHT: break;
if ( p->value.highlight.style & ROFI_HL_BOLD ) { case P_HIGHLIGHT:
printf ( "bold " ); if ( p->value.highlight.style & ROFI_HL_BOLD ) {
} printf ( "bold " );
if ( p->value.highlight.style & ROFI_HL_UNDERLINE ) { }
printf ( "underline " ); if ( p->value.highlight.style & ROFI_HL_UNDERLINE ) {
} printf ( "underline " );
if ( p->value.highlight.style & ROFI_HL_STRIKETHROUGH ) { }
printf ( "strikethrough " ); if ( p->value.highlight.style & ROFI_HL_STRIKETHROUGH ) {
} printf ( "strikethrough " );
if ( p->value.highlight.style & ROFI_HL_ITALIC ) { }
printf ( "italic " ); if ( p->value.highlight.style & ROFI_HL_ITALIC ) {
} printf ( "italic " );
if ( p->value.highlight.style & ROFI_HL_COLOR ) { }
printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", if ( p->value.highlight.style & ROFI_HL_COLOR ) {
( p->value.highlight.color.red * 255.0 ),
( p->value.highlight.color.green * 255.0 ),
( p->value.highlight.color.blue * 255.0 ),
( p->value.highlight.color.alpha * 100.0 ) );
}
break;
case P_POSITION:
printf ( "%s", WindowLocationStr[p->value.i] );
break;
case P_STRING:
printf ( "\"%s\"", p->value.s );
break;
case P_INTEGER:
printf ( "%d", p->value.i );
break;
case P_DOUBLE:
printf ( "%.2f", p->value.f );
break;
case P_BOOLEAN:
printf ( "%s", p->value.b ? "true" : "false" );
break;
case P_COLOR:
printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )",
( p->value.color.red * 255.0 ), ( p->value.highlight.color.red * 255.0 ),
( p->value.color.green * 255.0 ), ( p->value.highlight.color.green * 255.0 ),
( p->value.color.blue * 255.0 ), ( p->value.highlight.color.blue * 255.0 ),
( p->value.color.alpha * 100.0 ) ); ( p->value.highlight.color.alpha * 100.0 ) );
break; }
case P_PADDING: break;
if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && case P_POSITION:
distance_compare ( p->value.padding.left, p->value.padding.right ) && printf ( "%s", WindowLocationStr[p->value.i] );
distance_compare ( p->value.padding.left, p->value.padding.top ) ) { break;
rofi_theme_print_distance ( p->value.padding.left ); case P_STRING:
} printf ( "\"%s\"", p->value.s );
else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && break;
distance_compare ( p->value.padding.left, p->value.padding.right ) ) { case P_INTEGER:
rofi_theme_print_distance ( p->value.padding.top ); printf ( "%d", p->value.i );
rofi_theme_print_distance ( p->value.padding.left ); break;
} case P_DOUBLE:
else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) && printf ( "%.2f", p->value.f );
distance_compare ( p->value.padding.left, p->value.padding.right ) ) { break;
rofi_theme_print_distance ( p->value.padding.top ); case P_BOOLEAN:
rofi_theme_print_distance ( p->value.padding.left ); printf ( "%s", p->value.b ? "true" : "false" );
rofi_theme_print_distance ( p->value.padding.bottom ); break;
} case P_COLOR:
else { printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )",
rofi_theme_print_distance ( p->value.padding.top ); ( p->value.color.red * 255.0 ),
rofi_theme_print_distance ( p->value.padding.right ); ( p->value.color.green * 255.0 ),
rofi_theme_print_distance ( p->value.padding.bottom ); ( p->value.color.blue * 255.0 ),
rofi_theme_print_distance ( p->value.padding.left ); ( p->value.color.alpha * 100.0 ) );
} break;
break; case P_PADDING:
case P_LINK: if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) &&
if ( p->value.link.def_value) { distance_compare ( p->value.padding.left, p->value.padding.right ) &&
printf( "var( %s, ", p->value.link.name ); distance_compare ( p->value.padding.left, p->value.padding.top ) ) {
int_rofi_theme_print_property ( p->value.link.def_value ); rofi_theme_print_distance ( p->value.padding.left );
printf (")"); }
}else { else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) &&
printf ( "var(%s)", p->value.link.name ); distance_compare ( p->value.padding.left, p->value.padding.right ) ) {
} rofi_theme_print_distance ( p->value.padding.top );
break; rofi_theme_print_distance ( p->value.padding.left );
case P_INHERIT: }
printf ( "inherit" ); else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) &&
break; distance_compare ( p->value.padding.left, p->value.padding.right ) ) {
default: rofi_theme_print_distance ( p->value.padding.top );
break; rofi_theme_print_distance ( p->value.padding.left );
rofi_theme_print_distance ( p->value.padding.bottom );
}
else {
rofi_theme_print_distance ( p->value.padding.top );
rofi_theme_print_distance ( p->value.padding.right );
rofi_theme_print_distance ( p->value.padding.bottom );
rofi_theme_print_distance ( p->value.padding.left );
}
break;
case P_LINK:
if ( p->value.link.def_value ) {
printf ( "var( %s, ", p->value.link.name );
int_rofi_theme_print_property ( p->value.link.def_value );
printf ( ")" );
}
else {
printf ( "var(%s)", p->value.link.name );
}
break;
case P_INHERIT:
printf ( "inherit" );
break;
default:
break;
} }
} }
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 )
@ -518,7 +513,7 @@ 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;// + (*(p->value.link.name)== '@'?1:0; const char *name = p->value.link.name;// + (*(p->value.link.name)== '@'?1:0;
g_info ( "Resolving link to %s", p->value.link.name); g_info ( "Resolving link to %s", p->value.link.name );
if ( depth > 20 ) { if ( depth > 20 ) {
g_warning ( "Found more then 20 redirects for property. Stopping." ); g_warning ( "Found more then 20 redirects for property. Stopping." );
p->value.link.ref = p; p->value.link.ref = p;
@ -527,7 +522,7 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth )
if ( rofi_theme->properties && g_hash_table_contains ( rofi_theme->properties, name ) ) { if ( rofi_theme->properties && 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 );
g_info ("Resolving link %s found: %s", p->value.link.name, pr->name); g_info ( "Resolving link %s found: %s", p->value.link.name, pr->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 );
@ -543,7 +538,7 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth )
} }
} }
// No found and we have default value. // No found and we have default value.
if ( p->value.link.def_value ){ if ( p->value.link.def_value ) {
p->value.link.ref = p->value.link.def_value; p->value.link.ref = p->value.link.def_value;
return; return;
} }
@ -1022,21 +1017,20 @@ char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file
return filename; return filename;
} }
void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child ) void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child )
{ {
g_assert ( parent != NULL ); g_assert ( parent != NULL );
g_assert ( child != NULL ); g_assert ( child != NULL );
if ( parent == rofi_theme && g_strcmp0(child->name, "*") == 0 ){ if ( parent == rofi_theme && g_strcmp0 ( child->name, "*" ) == 0 ) {
rofi_theme_widget_add_properties ( parent, child->properties); rofi_theme_widget_add_properties ( parent, child->properties );
return; return;
} }
ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name); ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name );
rofi_theme_widget_add_properties ( w, child->properties); rofi_theme_widget_add_properties ( w, child->properties );
for ( unsigned int i =0; i < child->num_widgets; i++) { for ( unsigned int i = 0; i < child->num_widgets; i++ ) {
rofi_theme_parse_merge_widgets ( w, child->widgets[i]); rofi_theme_parse_merge_widgets ( w, child->widgets[i] );
} }
} }
@ -1044,108 +1038,114 @@ void rofi_theme_parse_process_conditionals ( void )
{ {
workarea mon; workarea mon;
monitor_active ( &mon ); monitor_active ( &mon );
if ( rofi_theme == NULL ) return; if ( rofi_theme == NULL ) {
return;
}
for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) { for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) {
ThemeWidget *widget = rofi_theme->widgets[i]; ThemeWidget *widget = rofi_theme->widgets[i];
if ( widget->media != NULL ) { if ( widget->media != NULL ) {
switch ( widget->media->type ) switch ( widget->media->type )
{ {
case THEME_MEDIA_TYPE_MIN_WIDTH: case THEME_MEDIA_TYPE_MIN_WIDTH:
{ {
int w = widget->media->value; int w = widget->media->value;
if ( mon.w >= w ){ if ( mon.w >= w ) {
for ( unsigned int x =0; x < widget->num_widgets; x++) { for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
} }
}
break;
}
case THEME_MEDIA_TYPE_MAX_WIDTH:
{
int w = widget->media->value;
if ( mon.w < w ){
for ( unsigned int x =0; x < widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MIN_HEIGHT:
{
int h = widget->media->value;
if ( mon.h >= h ){
for ( unsigned int x =0; x < widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MAX_HEIGHT:
{
int h = widget->media->value;
if ( mon.h < h ){
for ( unsigned int x =0; x < widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MON_ID:
{
if ( mon.monitor_id == widget->media->value ){
for ( unsigned int x =0; x < widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MIN_ASPECT_RATIO:
{
double r = widget->media->value;
if ( (mon.w/(double)mon.h) >= r ){
for ( unsigned int x =0; x < widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MAX_ASPECT_RATIO:
{
double r = widget->media->value;
if ( (mon.w/(double)mon.h) < r ){
for ( unsigned int x =0; x < widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
default:
{
break;
}
} }
break;
} }
case THEME_MEDIA_TYPE_MAX_WIDTH:
{
int w = widget->media->value;
if ( mon.w < w ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MIN_HEIGHT:
{
int h = widget->media->value;
if ( mon.h >= h ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MAX_HEIGHT:
{
int h = widget->media->value;
if ( mon.h < h ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MON_ID:
{
if ( mon.monitor_id == widget->media->value ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MIN_ASPECT_RATIO:
{
double r = widget->media->value;
if ( ( mon.w / (double) mon.h ) >= r ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
case THEME_MEDIA_TYPE_MAX_ASPECT_RATIO:
{
double r = widget->media->value;
if ( ( mon.w / (double) mon.h ) < r ) {
for ( unsigned int x = 0; x < widget->num_widgets; x++ ) {
rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] );
}
}
break;
}
default:
{
break;
}
}
}
} }
} }
ThemeMediaType rofi_theme_parse_media_type ( const char *type ) ThemeMediaType rofi_theme_parse_media_type ( const char *type )
{ {
if ( g_strcmp0( type, "monitor-id" ) == 0 ) { if ( g_strcmp0 ( type, "monitor-id" ) == 0 ) {
return THEME_MEDIA_TYPE_MON_ID; return THEME_MEDIA_TYPE_MON_ID;
} else if ( g_strcmp0 ( type, "min-width") == 0 ) { }
else if ( g_strcmp0 ( type, "min-width" ) == 0 ) {
return THEME_MEDIA_TYPE_MIN_WIDTH; return THEME_MEDIA_TYPE_MIN_WIDTH;
} else if ( g_strcmp0 ( type, "min-height") == 0 ) { }
else if ( g_strcmp0 ( type, "min-height" ) == 0 ) {
return THEME_MEDIA_TYPE_MIN_HEIGHT; return THEME_MEDIA_TYPE_MIN_HEIGHT;
} else if ( g_strcmp0 ( type, "max-width") == 0 ) { }
else if ( g_strcmp0 ( type, "max-width" ) == 0 ) {
return THEME_MEDIA_TYPE_MAX_WIDTH; return THEME_MEDIA_TYPE_MAX_WIDTH;
} else if ( g_strcmp0 ( type, "max-height") == 0 ) { }
else if ( g_strcmp0 ( type, "max-height" ) == 0 ) {
return THEME_MEDIA_TYPE_MAX_HEIGHT; return THEME_MEDIA_TYPE_MAX_HEIGHT;
} else if ( g_strcmp0 ( type, "min-aspect-ratio") == 0 ) { }
else if ( g_strcmp0 ( type, "min-aspect-ratio" ) == 0 ) {
return THEME_MEDIA_TYPE_MIN_ASPECT_RATIO; return THEME_MEDIA_TYPE_MIN_ASPECT_RATIO;
} else if ( g_strcmp0 ( type, "max-aspect-ratio") == 0 ) { }
else if ( g_strcmp0 ( type, "max-aspect-ratio" ) == 0 ) {
return THEME_MEDIA_TYPE_MAX_ASPECT_RATIO; return THEME_MEDIA_TYPE_MAX_ASPECT_RATIO;
} }
return THEME_MEDIA_TYPE_INVALID; return THEME_MEDIA_TYPE_INVALID;
} }

View file

@ -35,7 +35,7 @@
/** /**
* Timer used to calculate time stamps. * Timer used to calculate time stamps.
*/ */
GTimer *global_timer = NULL; GTimer *global_timer = NULL;
/** /**
* Last timestamp made. * Last timestamp made.
*/ */
@ -58,8 +58,7 @@ void rofi_timings_tick ( const char *file, char const *str, int line, char const
void rofi_timings_quit ( void ) void rofi_timings_quit ( void )
{ {
double now = g_timer_elapsed ( global_timer, NULL ); double now = g_timer_elapsed ( global_timer, NULL );
g_debug ( "%4.6f (%2.6f): Stopped", now, 0.0 ); g_debug ( "%4.6f (%2.6f): Stopped", now, 0.0 );
g_timer_destroy ( global_timer ); g_timer_destroy ( global_timer );
} }

View file

@ -926,14 +926,14 @@ inline static void rofi_view_nav_last ( RofiViewState * state )
listview_set_selected ( state->list_view, -1 ); listview_set_selected ( state->list_view, -1 );
} }
static void update_callback ( textbox *t,icon *ico, unsigned int index, void *udata, TextBoxFontType *type, gboolean full ) static void update_callback ( textbox *t, icon *ico, unsigned int index, void *udata, TextBoxFontType *type, gboolean full )
{ {
RofiViewState *state = (RofiViewState *) udata; RofiViewState *state = (RofiViewState *) udata;
if ( full ) { if ( full ) {
GList *add_list = NULL; GList *add_list = NULL;
int fstate = 0; int fstate = 0;
char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE ); char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE );
(*type) |= fstate; ( *type ) |= fstate;
// TODO needed for markup. // TODO needed for markup.
textbox_font ( t, *type ); textbox_font ( t, *type );
// Move into list view. // Move into list view.
@ -945,9 +945,9 @@ static void update_callback ( textbox *t,icon *ico, unsigned int index, void *ud
else{ else{
list = pango_attr_list_new (); list = pango_attr_list_new ();
} }
if( ico ) { if ( ico ) {
int icon_height = widget_get_desired_height( WIDGET(ico) ); int icon_height = widget_get_desired_height ( WIDGET ( ico ) );
cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height ); cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height );
icon_set_surface ( ico, icon ); icon_set_surface ( ico, icon );
} }
@ -967,7 +967,7 @@ static void update_callback ( textbox *t,icon *ico, unsigned int index, void *ud
else { else {
int fstate = 0; int fstate = 0;
mode_get_display_value ( state->sw, state->line_map[index], &fstate, NULL, FALSE ); mode_get_display_value ( state->sw, state->line_map[index], &fstate, NULL, FALSE );
(*type) |= fstate; ( *type ) |= fstate;
// TODO needed for markup. // TODO needed for markup.
textbox_font ( t, *type ); textbox_font ( t, *type );
} }
@ -1030,12 +1030,12 @@ static void rofi_view_refilter ( RofiViewState *state )
_rofi_view_reload_row ( state ); _rofi_view_reload_row ( state );
state->reload = FALSE; state->reload = FALSE;
} }
TICK_N ("Filter reload rows"); TICK_N ( "Filter reload rows" );
if ( state->tokens ) { if ( state->tokens ) {
helper_tokenize_free ( state->tokens ); helper_tokenize_free ( state->tokens );
state->tokens = NULL; state->tokens = NULL;
} }
TICK_N ("Filter tokenize"); TICK_N ( "Filter tokenize" );
if ( state->text && strlen ( state->text->text ) > 0 ) { if ( state->text && strlen ( state->text->text ) > 0 ) {
unsigned int j = 0; unsigned int j = 0;
gchar *pattern = mode_preprocess_input ( state->sw, state->text->text ); gchar *pattern = mode_preprocess_input ( state->sw, state->text->text );
@ -1102,22 +1102,20 @@ static void rofi_view_refilter ( RofiViewState *state )
} }
state->filtered_lines = state->num_lines; state->filtered_lines = state->num_lines;
} }
TICK_N ("Filter matching done"); TICK_N ( "Filter matching done" );
listview_set_num_elements ( state->list_view, state->filtered_lines ); listview_set_num_elements ( state->list_view, state->filtered_lines );
if ( state->tb_filtered_rows ) { if ( state->tb_filtered_rows ) {
char *r = g_strdup_printf("%u", state->filtered_lines); char *r = g_strdup_printf ( "%u", state->filtered_lines );
textbox_text( state->tb_filtered_rows, r ); textbox_text ( state->tb_filtered_rows, r );
g_free(r); g_free ( r );
} }
if ( state->tb_total_rows ) { if ( state->tb_total_rows ) {
char *r = g_strdup_printf("%u", state->num_lines); char *r = g_strdup_printf ( "%u", state->num_lines );
textbox_text( state->tb_total_rows, r ); textbox_text ( state->tb_total_rows, r );
g_free(r); g_free ( r );
} }
TICK_N ("Update filter lines"); TICK_N ( "Update filter lines" );
if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) { if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) {
( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
@ -1133,7 +1131,7 @@ static void rofi_view_refilter ( RofiViewState *state )
rofi_view_window_update_size ( state ); rofi_view_window_update_size ( state );
g_debug ( "Resize based on re-filter" ); g_debug ( "Resize based on re-filter" );
} }
TICK_N ("Filter resize window based on window "); TICK_N ( "Filter resize window based on window " );
state->refilter = FALSE; state->refilter = FALSE;
TICK_N ( "Filter done" ); TICK_N ( "Filter done" );
} }
@ -1528,25 +1526,29 @@ static WidgetTriggerActionResult textbox_button_trigger_action ( widget *wid, Mo
switch ( action ) switch ( action )
{ {
case MOUSE_CLICK_DOWN: case MOUSE_CLICK_DOWN:
{ {
const char * type = rofi_theme_get_string ( wid, "action", "ok" ); const char * type = rofi_theme_get_string ( wid, "action", "ok" );
( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
if ( strcmp(type, "ok") == 0 ) { if ( strcmp ( type, "ok" ) == 0 ) {
state->retv = MENU_OK; state->retv = MENU_OK;
} else if ( strcmp ( type, "ok|alternate" ) == 0 ) {
state->retv = MENU_CUSTOM_ACTION|MENU_OK;
} else if ( strcmp ( type, "custom") ) {
state->retv = MENU_CUSTOM_INPUT;
} else if ( strcmp ( type, "custom|alternate" ) == 0 ) {
state->retv = MENU_CUSTOM_ACTION|MENU_CUSTOM_INPUT;
} else {
g_warning("Invalid action specified.");
return WIDGET_TRIGGER_ACTION_RESULT_IGNORED;
}
state->quit = TRUE;
state->skip_absorb = TRUE;
return WIDGET_TRIGGER_ACTION_RESULT_HANDLED;
} }
else if ( strcmp ( type, "ok|alternate" ) == 0 ) {
state->retv = MENU_CUSTOM_ACTION | MENU_OK;
}
else if ( strcmp ( type, "custom" ) ) {
state->retv = MENU_CUSTOM_INPUT;
}
else if ( strcmp ( type, "custom|alternate" ) == 0 ) {
state->retv = MENU_CUSTOM_ACTION | MENU_CUSTOM_INPUT;
}
else {
g_warning ( "Invalid action specified." );
return WIDGET_TRIGGER_ACTION_RESULT_IGNORED;
}
state->quit = TRUE;
state->skip_absorb = TRUE;
return WIDGET_TRIGGER_ACTION_RESULT_HANDLED;
}
case MOUSE_CLICK_UP: case MOUSE_CLICK_UP:
case MOUSE_DCLICK_DOWN: case MOUSE_DCLICK_DOWN:
case MOUSE_DCLICK_UP: case MOUSE_DCLICK_UP:
@ -1609,7 +1611,8 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE ); box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE );
if ( config.sidebar_mode ) { if ( config.sidebar_mode ) {
defaults = "inputbar,message,listview,mode-switcher"; defaults = "inputbar,message,listview,mode-switcher";
} else { }
else {
defaults = "inputbar,message,listview"; defaults = "inputbar,message,listview";
} }
} }
@ -1635,14 +1638,14 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE ); box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE );
defaults = NULL; defaults = NULL;
} }
else if ( strcmp ( name, "num-rows" ) == 0 ){ else if ( strcmp ( name, "num-rows" ) == 0 ) {
state->tb_total_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); state->tb_total_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
box_add ( (box *) parent_widget, WIDGET ( state->tb_total_rows ), FALSE ); box_add ( (box *) parent_widget, WIDGET ( state->tb_total_rows ), FALSE );
defaults = NULL; defaults = NULL;
} }
else if ( strcmp ( name, "num-filtered-rows" ) == 0 ){ else if ( strcmp ( name, "num-filtered-rows" ) == 0 ) {
state->tb_filtered_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); state->tb_filtered_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
box_add ( (box *) parent_widget, WIDGET ( state->tb_filtered_rows), FALSE ); box_add ( (box *) parent_widget, WIDGET ( state->tb_filtered_rows ), FALSE );
defaults = NULL; defaults = NULL;
} }
/** /**
@ -1720,14 +1723,14 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
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 ( WIDGET ( state->sidebar_bar ), WIDGET_TYPE_MODE_SWITCHER, "button", TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL, state->modi[j] = textbox_create ( WIDGET ( state->sidebar_bar ), WIDGET_TYPE_MODE_SWITCHER, "button", TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
mode_get_display_name ( mode ), 0.5, 0.5 ); mode_get_display_name ( mode ), 0.5, 0.5 );
box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE ); box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE );
widget_set_trigger_action_handler ( WIDGET ( state->modi[j] ), textbox_sidebar_modi_trigger_action, state ); widget_set_trigger_action_handler ( WIDGET ( state->modi[j] ), textbox_sidebar_modi_trigger_action, state );
} }
} }
else if ( g_ascii_strcasecmp ( name, "overlay" ) == 0 ) { else if ( g_ascii_strcasecmp ( name, "overlay" ) == 0 ) {
state->overlay = textbox_create ( WIDGET ( parent_widget ), WIDGET_TYPE_TEXTBOX_TEXT, "overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat", 0.5, 0 ); state->overlay = textbox_create ( WIDGET ( parent_widget ), WIDGET_TYPE_TEXTBOX_TEXT, "overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat", 0.5, 0 );
box_add ( (box *) parent_widget, WIDGET ( state->overlay), FALSE ); box_add ( (box *) parent_widget, WIDGET ( state->overlay ), FALSE );
widget_disable ( WIDGET ( state->overlay ) ); widget_disable ( WIDGET ( state->overlay ) );
} }
else if ( g_ascii_strncasecmp ( name, "textbox", 7 ) == 0 ) { else if ( g_ascii_strncasecmp ( name, "textbox", 7 ) == 0 ) {
@ -1780,10 +1783,11 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->num_lines = mode_get_num_entries ( sw ); state->num_lines = mode_get_num_entries ( sw );
if ( state->sw ) { if ( state->sw ) {
char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name (state->sw ) ); char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name ( state->sw ) );
rofi_view_set_window_title ( title ); rofi_view_set_window_title ( title );
g_free ( title ); g_free ( title );
} else { }
else {
rofi_view_set_window_title ( "rofi" ); rofi_view_set_window_title ( "rofi" );
} }
TICK_N ( "Startup notification" ); TICK_N ( "Startup notification" );
@ -1804,7 +1808,6 @@ RofiViewState *rofi_view_create ( Mode *sw,
textbox_cursor_end ( state->text ); textbox_cursor_end ( state->text );
} }
// 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 ) );
state->distance = (int *) g_malloc0_n ( state->num_lines, sizeof ( int ) ); state->distance = (int *) g_malloc0_n ( state->num_lines, sizeof ( int ) );
@ -1993,10 +1996,11 @@ void rofi_view_switch_mode ( RofiViewState *state, Mode *mode )
rofi_view_update_prompt ( state ); rofi_view_update_prompt ( state );
} }
if ( state->sw ) { if ( state->sw ) {
char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name (state->sw ) ); char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name ( state->sw ) );
rofi_view_set_window_title ( title ); rofi_view_set_window_title ( title );
g_free ( title ); g_free ( title );
} else { }
else {
rofi_view_set_window_title ( "rofi" ); rofi_view_set_window_title ( "rofi" );
} }
if ( state->sidebar_bar ) { if ( state->sidebar_bar ) {
@ -2019,7 +2023,7 @@ xcb_window_t rofi_view_get_window ( void )
void rofi_view_set_window_title ( const char * title ) void rofi_view_set_window_title ( const char * title )
{ {
ssize_t len = strlen(title); ssize_t len = strlen ( title );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, len, title ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, len, title );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, len, title ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, len, title );
} }

View file

@ -46,7 +46,7 @@ struct _icon
uint32_t icon_fetch_id; uint32_t icon_fetch_id;
double yalign,xalign; double yalign, xalign;
// Source surface. // Source surface.
cairo_surface_t *icon; cairo_surface_t *icon;
@ -85,16 +85,16 @@ static void icon_draw ( widget *wid, cairo_t *draw )
int icons = MAX ( iconh, iconw ); int icons = MAX ( iconh, iconw );
double scale = (double) b->size / icons; double scale = (double) b->size / icons;
int lpad = widget_padding_get_left ( WIDGET ( b ) ) ; int lpad = widget_padding_get_left ( WIDGET ( b ) );
int rpad = widget_padding_get_right ( WIDGET ( b ) ) ; int rpad = widget_padding_get_right ( WIDGET ( b ) );
int tpad = widget_padding_get_top ( WIDGET ( b ) ) ; int tpad = widget_padding_get_top ( WIDGET ( b ) );
int bpad = widget_padding_get_bottom ( WIDGET ( b ) ) ; int bpad = widget_padding_get_bottom ( WIDGET ( b ) );
cairo_save ( draw ); cairo_save ( draw );
cairo_translate ( draw, cairo_translate ( draw,
lpad + ( b->widget.w - iconw * scale - lpad -rpad )*b->xalign, lpad + ( b->widget.w - iconw * scale - lpad - rpad ) * b->xalign,
tpad + ( b->widget.h- iconh * scale -tpad - bpad )*b->yalign ); tpad + ( b->widget.h - iconh * scale - tpad - bpad ) * b->yalign );
cairo_scale ( draw, scale, scale ); cairo_scale ( draw, scale, scale );
cairo_set_source_surface ( draw, b->icon, 0, 0 ); cairo_set_source_surface ( draw, b->icon, 0, 0 );
cairo_paint ( draw ); cairo_paint ( draw );
@ -149,7 +149,7 @@ icon * icon_create ( widget *parent, const char *name )
b->widget.get_desired_height = icon_get_desired_height; b->widget.get_desired_height = icon_get_desired_height;
b->widget.get_desired_width = icon_get_desired_width; b->widget.get_desired_width = icon_get_desired_width;
RofiDistance d = rofi_theme_get_distance ( WIDGET (b), "size" , b->size ); RofiDistance d = rofi_theme_get_distance ( WIDGET ( b ), "size", b->size );
b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL ); b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL );
const char * filename = rofi_theme_get_string ( WIDGET ( b ), "filename", NULL ); const char * filename = rofi_theme_get_string ( WIDGET ( b ), "filename", NULL );

View file

@ -62,11 +62,12 @@ typedef enum
RIGHT_TO_LEFT = 1 RIGHT_TO_LEFT = 1
} MoveDirection; } MoveDirection;
typedef struct { typedef struct
box *box; {
textbox *textbox; box *box;
textbox *index; textbox *textbox;
icon *icon; textbox *index;
icon *icon;
} _listview_row; } _listview_row;
struct _listview struct _listview
@ -121,7 +122,6 @@ struct _listview
char *listview_name; char *listview_name;
PangoEllipsizeMode emode; PangoEllipsizeMode emode;
/** Barview */ /** Barview */
struct struct
@ -170,45 +170,46 @@ static void listview_set_style ( widget *w, TextBoxFontType tbft )
static void listview_create_row ( listview *lv, _listview_row *row ) static void listview_create_row ( listview *lv, _listview_row *row )
{ {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0; TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
row->box = box_create ( WIDGET ( lv ), "element",ROFI_ORIENTATION_HORIZONTAL ); row->box = box_create ( WIDGET ( lv ), "element", ROFI_ORIENTATION_HORIZONTAL );
widget_set_type ( WIDGET(row->box), WIDGET_TYPE_LISTVIEW_ELEMENT); widget_set_type ( WIDGET ( row->box ), WIDGET_TYPE_LISTVIEW_ELEMENT );
GList *list = rofi_theme_get_list ( WIDGET(row->box), "children", "element-icon,element-text"); GList *list = rofi_theme_get_list ( WIDGET ( row->box ), "children", "element-icon,element-text" );
row->textbox = NULL; row->textbox = NULL;
row->icon = NULL; row->icon = NULL;
row->index = NULL; row->index = NULL;
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 ) ) {
if ( strcasecmp((char *)iter->data, "element-icon") == 0 ) { if ( strcasecmp ( (char *) iter->data, "element-icon" ) == 0 ) {
if ( config.show_icons ) { if ( config.show_icons ) {
row->icon = icon_create ( WIDGET ( row->box ), "element-icon" ); row->icon = icon_create ( WIDGET ( row->box ), "element-icon" );
box_add ( row->box, WIDGET ( row->icon ), FALSE); box_add ( row->box, WIDGET ( row->icon ), FALSE );
} }
} else if ( strcasecmp ((char *)iter->data, "element-text") == 0 ){ }
row->textbox= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT|flags, NORMAL, "DDD", 0, 0 ); else if ( strcasecmp ( (char *) iter->data, "element-text" ) == 0 ) {
box_add ( row->box, WIDGET ( row->textbox ), TRUE); row->textbox = textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT | flags, NORMAL, "DDD", 0, 0 );
} else if ( strcasecmp ( (char*)iter->data, "element-index" ) == 0 ){ box_add ( row->box, WIDGET ( row->textbox ), TRUE );
row->index= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT, NORMAL, " ", 0, 0 ); }
box_add ( row->box, WIDGET ( row->index ), FALSE); else if ( strcasecmp ( (char*) iter->data, "element-index" ) == 0 ) {
row->index = textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT, NORMAL, " ", 0, 0 );
box_add ( row->box, WIDGET ( row->index ), FALSE );
} }
} }
g_list_free_full ( list, g_free ); g_list_free_full ( list, g_free );
} }
static void listview_set_state ( _listview_row r, TextBoxFontType type ) static void listview_set_state ( _listview_row r, TextBoxFontType type )
{ {
listview_set_style ( WIDGET(r.box), type); listview_set_style ( WIDGET ( r.box ), type );
if ( r.textbox ) { if ( r.textbox ) {
listview_set_style ( WIDGET(r.textbox), type); listview_set_style ( WIDGET ( r.textbox ), type );
} }
if ( r.index ) { if ( r.index ) {
listview_set_style ( WIDGET(r.index), type); listview_set_style ( WIDGET ( r.index ), type );
} }
if ( r.icon ) { if ( r.icon ) {
listview_set_style ( WIDGET(r.icon), type); listview_set_style ( WIDGET ( r.icon ), type );
} }
widget_queue_redraw ( WIDGET( r.box ) ); widget_queue_redraw ( WIDGET ( r.box ) );
} }
static int listview_get_desired_height ( widget *wid ); static int listview_get_desired_height ( widget *wid );
@ -292,18 +293,19 @@ static void update_element ( listview *lv, unsigned int tb, unsigned int index,
if ( lv->boxes[tb].index ) { if ( lv->boxes[tb].index ) {
if ( index < 10 ) { if ( index < 10 ) {
char str[2] = { char str[2] = {
((index+1)%10)+'0', ( ( index + 1 ) % 10 ) + '0',
'\0' '\0'
}; };
textbox_text( lv->boxes[tb].index, str ); textbox_text ( lv->boxes[tb].index, str );
} else { }
textbox_text( lv->boxes[tb].index, " " ); else {
textbox_text ( lv->boxes[tb].index, " " );
} }
} }
if ( lv->callback ) { if ( lv->callback ) {
lv->callback ( lv->boxes[tb].textbox, lv->boxes[tb].icon, index, lv->udata, &type, full ); lv->callback ( lv->boxes[tb].textbox, lv->boxes[tb].icon, index, lv->udata, &type, full );
listview_set_state ( lv->boxes[tb], type); listview_set_state ( lv->boxes[tb], type );
} }
} }
@ -336,8 +338,8 @@ static void barview_draw ( widget *wid, cairo_t *draw )
} }
twidth = width; twidth = width;
} }
widget_move ( WIDGET(lv->boxes[i].box), left_offset, top_offset); widget_move ( WIDGET ( lv->boxes[i].box ), left_offset, top_offset );
widget_resize ( WIDGET (lv->boxes[i].box), twidth, lv->element_height); widget_resize ( WIDGET ( lv->boxes[i].box ), twidth, lv->element_height );
widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw );
width -= twidth + spacing_hori; width -= twidth + spacing_hori;
@ -357,8 +359,8 @@ static void barview_draw ( widget *wid, cairo_t *draw )
twidth = width; twidth = width;
} }
right_offset -= twidth; right_offset -= twidth;
widget_move ( WIDGET(lv->boxes[i].box), right_offset, top_offset); widget_move ( WIDGET ( lv->boxes[i].box ), right_offset, top_offset );
widget_resize ( WIDGET (lv->boxes[i].box), twidth, lv->element_height); widget_resize ( WIDGET ( lv->boxes[i].box ), twidth, lv->element_height );
widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw );
width -= twidth + spacing_hori; width -= twidth + spacing_hori;
@ -369,8 +371,8 @@ static void barview_draw ( widget *wid, cairo_t *draw )
offset -= lv->barview.cur_visible - 1; offset -= lv->barview.cur_visible - 1;
lv->last_offset = offset; lv->last_offset = offset;
for ( unsigned int i = 0; i < ( lv->barview.cur_visible / 2 ); i++ ) { for ( unsigned int i = 0; i < ( lv->barview.cur_visible / 2 ); i++ ) {
_listview_row temp = lv->boxes[i]; _listview_row temp = lv->boxes[i];
int sw = lv->barview.cur_visible - i - 1; int sw = lv->barview.cur_visible - i - 1;
lv->boxes[i] = lv->boxes[sw]; lv->boxes[i] = lv->boxes[sw];
lv->boxes[sw] = temp; lv->boxes[sw] = temp;
} }
@ -379,7 +381,7 @@ static void barview_draw ( widget *wid, cairo_t *draw )
} }
else { else {
for ( unsigned int i = 0; i < lv->barview.cur_visible; i++ ) { for ( unsigned int i = 0; i < lv->barview.cur_visible; i++ ) {
update_element ( lv, i, i + offset, TRUE); update_element ( lv, i, i + offset, TRUE );
widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw );
} }
} }
@ -426,39 +428,37 @@ static void listview_draw ( widget *wid, cairo_t *draw )
width -= spacing_hori; width -= spacing_hori;
width -= widget_get_width ( WIDGET ( lv->scrollbar ) ); width -= widget_get_width ( WIDGET ( lv->scrollbar ) );
} }
unsigned int element_width = ( width - spacing_hori * ( lv->cur_columns - 1 )) / lv->cur_columns; unsigned int element_width = ( width - spacing_hori * ( lv->cur_columns - 1 ) ) / lv->cur_columns;
int d = width - (element_width+spacing_hori)*(lv->cur_columns-1)-element_width; int d = width - ( element_width + spacing_hori ) * ( lv->cur_columns - 1 ) - element_width;
if ( lv->cur_columns > 1) if ( lv->cur_columns > 1 ) {
{ int diff = d / ( lv->cur_columns - 1 );
int diff = d/(lv->cur_columns-1); if ( diff >= 1 ) {
if ( diff >= 1 ){ spacing_hori += 1;
spacing_hori+=1; d -= lv->cur_columns - 1;
d -= lv->cur_columns-1;
} }
} }
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 ( (i)/lv->max_rows == (lv->cur_columns-1) ) { if ( ( i ) / lv->max_rows == ( lv->cur_columns - 1 ) ) {
ex+=d; ex += d;
} }
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;
widget_move ( WIDGET(lv->boxes[i].box), ex, ey); widget_move ( WIDGET ( lv->boxes[i].box ), ex, ey );
widget_resize ( WIDGET (lv->boxes[i].box), element_width, lv->element_height); widget_resize ( WIDGET ( lv->boxes[i].box ), 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 );
widget_move ( WIDGET(lv->boxes[i].box), ex, ey); widget_move ( WIDGET ( lv->boxes[i].box ), ex, ey );
widget_resize ( WIDGET (lv->boxes[i].box), element_width, lv->element_height); widget_resize ( WIDGET ( lv->boxes[i].box ), element_width, lv->element_height );
} }
update_element ( lv, i, i + offset, TRUE ); update_element ( lv, i, i + offset, TRUE );
widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw );
} }
lv->rchanged = FALSE; lv->rchanged = FALSE;
} }
else { else {
for ( unsigned int i = 0; i < max; i++ ) { for ( unsigned int i = 0; i < max; i++ ) {
@ -490,12 +490,12 @@ static void listview_recompute_elements ( listview *lv )
if ( lv->max_rows == 0 ) { if ( lv->max_rows == 0 ) {
return; return;
} }
if ( !(lv->fixed_columns) && lv->req_elements < lv->max_elements ) { if ( !( lv->fixed_columns ) && lv->req_elements < lv->max_elements ) {
newne = lv->req_elements; newne = lv->req_elements;
lv->cur_columns = ( lv->req_elements + ( lv->max_rows - 1 ) ) / lv->max_rows; lv->cur_columns = ( lv->req_elements + ( lv->max_rows - 1 ) ) / lv->max_rows;
} }
else { else {
newne = MIN( lv->req_elements, lv->max_elements); newne = MIN ( lv->req_elements, lv->max_elements );
lv->cur_columns = lv->menu_columns; lv->cur_columns = lv->menu_columns;
} }
for ( unsigned int i = newne; i < lv->cur_elements; i++ ) { for ( unsigned int i = newne; i < lv->cur_elements; i++ ) {
@ -504,9 +504,9 @@ static void listview_recompute_elements ( listview *lv )
lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( _listview_row ) ); lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( _listview_row ) );
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++ ) {
listview_create_row ( lv, &(lv->boxes[i]) ); listview_create_row ( lv, &( lv->boxes[i] ) );
widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i].box ), listview_element_trigger_action, lv ); widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i].box ), listview_element_trigger_action, lv );
listview_set_state ( lv->boxes[i], NORMAL); listview_set_state ( lv->boxes[i], NORMAL );
} }
} }
lv->rchanged = TRUE; lv->rchanged = TRUE;
@ -518,14 +518,14 @@ void listview_set_num_elements ( listview *lv, unsigned int rows )
if ( lv == NULL ) { if ( lv == NULL ) {
return; return;
} }
TICK_N(__FUNCTION__); TICK_N ( __FUNCTION__ );
lv->req_elements = rows; lv->req_elements = rows;
listview_set_selected ( lv, lv->selected ); listview_set_selected ( lv, lv->selected );
TICK_N("Set selected"); TICK_N ( "Set selected" );
listview_recompute_elements ( lv ); listview_recompute_elements ( lv );
TICK_N("recompute elements"); TICK_N ( "recompute elements" );
widget_queue_redraw ( WIDGET ( lv ) ); widget_queue_redraw ( WIDGET ( lv ) );
TICK_N("queue redraw"); TICK_N ( "queue redraw" );
} }
unsigned int listview_get_selected ( listview *lv ) unsigned int listview_get_selected ( listview *lv )
@ -626,7 +626,7 @@ static WidgetTriggerActionResult listview_element_trigger_action ( widget *wid,
listview *lv = (listview *) user_data; listview *lv = (listview *) user_data;
unsigned int max = MIN ( lv->cur_elements, lv->req_elements - lv->last_offset ); unsigned int max = MIN ( lv->cur_elements, lv->req_elements - lv->last_offset );
unsigned int i; unsigned int i;
for ( i = 0; i < max && WIDGET ( lv->boxes[i].box) != wid; i++ ) { for ( i = 0; i < max && WIDGET ( lv->boxes[i].box ) != wid; i++ ) {
} }
if ( i == max ) { if ( i == max ) {
return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; return WIDGET_TRIGGER_ACTION_RESULT_IGNORED;
@ -667,8 +667,8 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca
// Calculate height of an element. // Calculate height of an element.
// //
_listview_row row; _listview_row row;
listview_create_row ( lv, &row); listview_create_row ( lv, &row );
lv->element_height = widget_get_desired_height ( WIDGET(row.box) ); lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) );
widget_free ( WIDGET ( row.box ) ); widget_free ( WIDGET ( row.box ) );
lv->callback = cb; lv->callback = cb;
@ -967,12 +967,14 @@ void listview_set_fixed_num_lines ( listview *lv )
void listview_toggle_ellipsizing ( listview *lv ) void listview_toggle_ellipsizing ( listview *lv )
{ {
if ( lv ) { if ( lv ) {
PangoEllipsizeMode mode = lv->emode; PangoEllipsizeMode mode = lv->emode;
if ( mode == PANGO_ELLIPSIZE_START ) { if ( mode == PANGO_ELLIPSIZE_START ) {
mode = PANGO_ELLIPSIZE_MIDDLE; mode = PANGO_ELLIPSIZE_MIDDLE;
} else if ( mode == PANGO_ELLIPSIZE_MIDDLE ) { }
else if ( mode == PANGO_ELLIPSIZE_MIDDLE ) {
mode = PANGO_ELLIPSIZE_END; mode = PANGO_ELLIPSIZE_END;
} else if ( mode == PANGO_ELLIPSIZE_END ) { }
else if ( mode == PANGO_ELLIPSIZE_END ) {
mode = PANGO_ELLIPSIZE_START; mode = PANGO_ELLIPSIZE_START;
} }
lv->emode = mode; lv->emode = mode;

View file

@ -156,7 +156,7 @@ static void textbox_initialize_font ( textbox *tb )
if ( tbfc ) { if ( tbfc ) {
// Update for used font. // Update for used font.
pango_layout_set_font_description ( tb->layout, tbfc->pfd ); pango_layout_set_font_description ( tb->layout, tbfc->pfd );
tb->metrics = tbfc->metrics; tb->metrics = tbfc->metrics;
} }
} }
} }
@ -189,11 +189,11 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex
} }
const char *txt = rofi_theme_get_string ( WIDGET ( tb ), "str", text ); const char *txt = rofi_theme_get_string ( WIDGET ( tb ), "str", text );
if ( txt == NULL || (*txt) == '\0' ){ if ( txt == NULL || ( *txt ) == '\0' ) {
txt = rofi_theme_get_string ( WIDGET ( tb ), "content", text ); txt = rofi_theme_get_string ( WIDGET ( tb ), "content", text );
} }
const char *placeholder = rofi_theme_get_string ( WIDGET(tb), "placeholder", NULL); const char *placeholder = rofi_theme_get_string ( WIDGET ( tb ), "placeholder", NULL );
if ( placeholder){ if ( placeholder ) {
tb->placeholder = placeholder; tb->placeholder = placeholder;
} }
textbox_text ( tb, txt ? txt : "" ); textbox_text ( tb, txt ? txt : "" );
@ -205,8 +205,8 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex
tb->blink_timeout = 0; tb->blink_timeout = 0;
tb->blink = 1; tb->blink = 1;
if ( ( flags & TB_EDITABLE ) == TB_EDITABLE ) { if ( ( flags & TB_EDITABLE ) == TB_EDITABLE ) {
if ( rofi_theme_get_boolean ( WIDGET(tb), "blink", TRUE) ) { if ( rofi_theme_get_boolean ( WIDGET ( tb ), "blink", TRUE ) ) {
tb->blink_timeout = g_timeout_add ( 1200, textbox_blink, tb ); tb->blink_timeout = g_timeout_add ( 1200, textbox_blink, tb );
} }
tb->widget.trigger_action = textbox_editable_trigger_action; tb->widget.trigger_action = textbox_editable_trigger_action;
} }
@ -268,8 +268,7 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
static void __textbox_update_pango_text ( textbox *tb ) static void __textbox_update_pango_text ( textbox *tb )
{ {
pango_layout_set_attributes ( tb->layout, NULL ); pango_layout_set_attributes ( tb->layout, NULL );
if ( tb->placeholder && (tb->text == NULL || tb->text[0] == 0) ) if ( tb->placeholder && ( tb->text == NULL || tb->text[0] == 0 ) ) {
{
tb->show_placeholder = TRUE; tb->show_placeholder = TRUE;
pango_layout_set_text ( tb->layout, tb->placeholder, -1 ); pango_layout_set_text ( tb->layout, tb->placeholder, -1 );
return; return;
@ -344,7 +343,6 @@ void textbox_text ( textbox *tb, const char *text )
widget_queue_redraw ( WIDGET ( tb ) ); widget_queue_redraw ( WIDGET ( tb ) );
} }
// within the parent handled auto width/height modes // within the parent handled auto width/height modes
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
{ {
@ -360,7 +358,8 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
} }
else if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { else if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) {
pango_layout_set_ellipsize ( tb->layout, tb->emode ); pango_layout_set_ellipsize ( tb->layout, tb->emode );
} else { }
else {
pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_NONE ); pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_NONE );
} }
} }
@ -450,7 +449,6 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
cairo_move_to ( draw, x, top ); cairo_move_to ( draw, x, top );
pango_cairo_show_layout ( draw, tb->layout ); pango_cairo_show_layout ( draw, tb->layout );
// draw the cursor // draw the cursor
rofi_theme_get_color ( WIDGET ( tb ), "text-color", draw ); rofi_theme_get_color ( WIDGET ( tb ), "text-color", draw );
if ( tb->flags & TB_EDITABLE && tb->blink ) { if ( tb->flags & TB_EDITABLE && tb->blink ) {
@ -470,7 +468,6 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
cairo_fill ( draw ); cairo_fill ( draw );
} }
if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) { if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) {
cairo_arc ( draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI ); cairo_arc ( draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI );
cairo_fill ( draw ); cairo_fill ( draw );
@ -941,11 +938,9 @@ int textbox_get_desired_width ( widget *wid )
return width + padding + offset; return width + padding + offset;
} }
void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode ) void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode )
{ {
if ( tb ) if ( tb ) {
{
tb->emode = mode; tb->emode = mode;
if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) {
// Store the mode. // Store the mode.

View file

@ -107,7 +107,7 @@ void widget_move ( widget *widget, short x, short y )
void widget_set_type ( widget *widget, WidgetType type ) void widget_set_type ( widget *widget, WidgetType type )
{ {
if ( widget == NULL ) { if ( widget == NULL ) {
return ; return;
} }
widget->type = type; widget->type = type;
} }

View file

@ -99,72 +99,74 @@ static xcb_visualtype_t *root_visual = NULL;
xcb_atom_t netatoms[NUM_NETATOMS]; xcb_atom_t netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) }; const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
static xcb_visualtype_t * lookup_visual (xcb_screen_t *s, xcb_visualid_t visual) static xcb_visualtype_t * lookup_visual ( xcb_screen_t *s, xcb_visualid_t visual )
{ {
xcb_depth_iterator_t d; xcb_depth_iterator_t d;
d = xcb_screen_allowed_depths_iterator (s); d = xcb_screen_allowed_depths_iterator ( s );
for (; d.rem; xcb_depth_next (&d)) { for (; d.rem; xcb_depth_next ( &d ) ) {
xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator (d.data); xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator ( d.data );
for (; v.rem; xcb_visualtype_next (&v)) { for (; v.rem; xcb_visualtype_next ( &v ) ) {
if (v.data->visual_id == visual) if ( v.data->visual_id == visual ) {
return v.data; return v.data;
}
} }
} }
return 0; return 0;
} }
cairo_surface_t *x11_helper_get_screenshot_surface_window ( xcb_window_t window, int size ) cairo_surface_t *x11_helper_get_screenshot_surface_window ( xcb_window_t window, int size )
{ {
xcb_get_geometry_cookie_t cookie; xcb_get_geometry_cookie_t cookie;
xcb_get_geometry_reply_t *reply; xcb_get_geometry_reply_t *reply;
cookie = xcb_get_geometry(xcb->connection, window); cookie = xcb_get_geometry ( xcb->connection, window );
reply = xcb_get_geometry_reply(xcb->connection, cookie, NULL); reply = xcb_get_geometry_reply ( xcb->connection, cookie, NULL );
if ( reply == NULL ) { if ( reply == NULL ) {
return NULL; return NULL;
} }
xcb_get_window_attributes_cookie_t attributesCookie = xcb_get_window_attributes (xcb->connection, window); xcb_get_window_attributes_cookie_t attributesCookie = xcb_get_window_attributes ( xcb->connection, window );
xcb_get_window_attributes_reply_t *attributes = xcb_get_window_attributes_reply (xcb->connection, xcb_get_window_attributes_reply_t *attributes = xcb_get_window_attributes_reply ( xcb->connection,
attributesCookie, attributesCookie,
NULL ); NULL );
if ( attributes == NULL || ( attributes->map_state != XCB_MAP_STATE_VIEWABLE ) ) { if ( attributes == NULL || ( attributes->map_state != XCB_MAP_STATE_VIEWABLE ) ) {
free(reply); free ( reply );
if ( attributes ) free(attributes); if ( attributes ) {
free ( attributes );
}
return NULL; return NULL;
} }
// Create a cairo surface for the window. // Create a cairo surface for the window.
xcb_visualtype_t * vt = lookup_visual(xcb->screen, attributes->visual); xcb_visualtype_t * vt = lookup_visual ( xcb->screen, attributes->visual );
free ( attributes ); free ( attributes );
cairo_surface_t *t = cairo_xcb_surface_create ( xcb->connection, window, vt , reply->width, reply->height ); cairo_surface_t *t = cairo_xcb_surface_create ( xcb->connection, window, vt, reply->width, reply->height );
if ( cairo_surface_status ( t ) != CAIRO_STATUS_SUCCESS ) { if ( cairo_surface_status ( t ) != CAIRO_STATUS_SUCCESS ) {
cairo_surface_destroy(t); cairo_surface_destroy ( t );
free(reply); free ( reply );
return NULL; return NULL;
} }
// Scale the image, as we don't want to keep large one around. // Scale the image, as we don't want to keep large one around.
int max = MAX(reply->width, reply->height); int max = MAX ( reply->width, reply->height );
double scale = (double)size/ max; double scale = (double) size / max;
cairo_surface_t *s2 = cairo_surface_create_similar_image ( t, CAIRO_FORMAT_ARGB32, reply->width*scale,reply->height*scale ); cairo_surface_t *s2 = cairo_surface_create_similar_image ( t, CAIRO_FORMAT_ARGB32, reply->width * scale, reply->height * scale );
free ( reply ); free ( reply );
if ( cairo_surface_status ( s2 ) != CAIRO_STATUS_SUCCESS ) { if ( cairo_surface_status ( s2 ) != CAIRO_STATUS_SUCCESS ) {
cairo_surface_destroy ( t ) ; cairo_surface_destroy ( t );
return NULL; return NULL;
} }
// Paint it in. // Paint it in.
cairo_t *d = cairo_create (s2); cairo_t *d = cairo_create ( s2 );
cairo_scale ( d, scale, scale ); cairo_scale ( d, scale, scale );
cairo_set_source_surface ( d, t, 0, 0 ); cairo_set_source_surface ( d, t, 0, 0 );
cairo_paint ( d); cairo_paint ( d );
cairo_destroy(d); cairo_destroy ( d );
cairo_surface_destroy(t); cairo_surface_destroy ( t );
return s2; return s2;
} }
/** /**
@ -1056,8 +1058,8 @@ static int take_pointer ( xcb_window_t w, int iters )
break; break;
} }
struct timespec del = { struct timespec del = {
.tv_sec = 0, .tv_sec = 0,
.tv_nsec = 1000000 .tv_nsec = 1000000
}; };
nanosleep ( &del, NULL ); nanosleep ( &del, NULL );
} }
@ -1087,8 +1089,8 @@ static int take_keyboard ( xcb_window_t w, int iters )
break; break;
} }
struct timespec del = { struct timespec del = {
.tv_sec = 0, .tv_sec = 0,
.tv_nsec = 1000000 .tv_nsec = 1000000
}; };
nanosleep ( &del, NULL ); nanosleep ( &del, NULL );
} }

View file

@ -81,153 +81,153 @@ 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_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_Boolean, "show-icons", { .snum = &config.show_icons }, NULL, { xrm_Boolean, "show-icons", { .snum = &config.show_icons }, NULL,
"Whether to load and show icons", CONFIG_DEFAULT }, "Whether to load and show icons", 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_String, "window-match-fields", { .str = &config.window_match_fields }, NULL, { xrm_String, "window-match-fields", { .str = &config.window_match_fields }, NULL,
"Window fields to match in window mode", CONFIG_DEFAULT }, "Window fields to match in window mode", CONFIG_DEFAULT },
{ xrm_String, "icon-theme", { .str = &config.icon_theme }, NULL, { xrm_String, "icon-theme", { .str = &config.icon_theme }, NULL,
"Theme to use to look for icons", CONFIG_DEFAULT }, "Theme to use to look for icons", CONFIG_DEFAULT },
{ xrm_String, "drun-match-fields", { .str = &config.drun_match_fields }, NULL, { xrm_String, "drun-match-fields", { .str = &config.drun_match_fields }, NULL,
"Desktop entry fields to match in drun", CONFIG_DEFAULT }, "Desktop entry fields to match in drun", CONFIG_DEFAULT },
{ xrm_String, "drun-categories", { .str = &config.drun_categories }, NULL, { xrm_String, "drun-categories", { .str = &config.drun_categories }, NULL,
"Only show Desktop entry from these categories", CONFIG_DEFAULT }, "Only show Desktop entry from these categories", CONFIG_DEFAULT },
{ xrm_Boolean, "drun-show-actions", { .num = &config.drun_show_actions }, NULL, { xrm_Boolean, "drun-show-actions", { .num = &config.drun_show_actions }, NULL,
"Desktop entry show actions.", CONFIG_DEFAULT }, "Desktop entry show actions.", CONFIG_DEFAULT },
{ xrm_String, "drun-display-format", { .str = &config.drun_display_format }, NULL, { xrm_String, "drun-display-format", { .str = &config.drun_display_format }, NULL,
"DRUN format string. (Supports: generic,name,comment,exec,categories)", CONFIG_DEFAULT }, "DRUN format string. (Supports: generic,name,comment,exec,categories)", 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_String, "ignored-prefixes", { .str = &config.ignored_prefixes }, NULL, { xrm_String, "ignored-prefixes", { .str = &config.ignored_prefixes }, NULL,
"Programs ignored for history", CONFIG_DEFAULT }, "Programs ignored for history", CONFIG_DEFAULT },
{ xrm_Boolean, "sort", { .num = &config.sort }, NULL, { xrm_Boolean, "sort", { .num = &config.sort }, NULL,
"Use sorting", CONFIG_DEFAULT }, "Use sorting", CONFIG_DEFAULT },
{ xrm_String, "sorting-method", { .str = &config.sorting_method }, NULL, { xrm_String, "sorting-method", { .str = &config.sorting_method }, NULL,
"Choose the strategy used for sorting: normal (levenshtein) or fzf.", CONFIG_DEFAULT }, "Choose the strategy used for sorting: normal (levenshtein) or fzf.", 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 *DEPRECATED*", CONFIG_DEFAULT }, "Margin between rows *DEPRECATED*", CONFIG_DEFAULT },
{ xrm_Number, "line-padding", { .num = &config.line_padding }, NULL, { xrm_Number, "line-padding", { .num = &config.line_padding }, NULL,
"Padding within rows *DEPRECATED*", CONFIG_DEFAULT }, "Padding within rows *DEPRECATED*", 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) *DEPRECATED*", CONFIG_DEFAULT }, "Separator style (none, dash, solid) *DEPRECATED*", CONFIG_DEFAULT },
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL,
"Hide scroll-bar *DEPRECATED*", CONFIG_DEFAULT }, "Hide scroll-bar *DEPRECATED*", 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 *DEPRECATED*", CONFIG_DEFAULT }, "Fake transparency *DEPRECATED*", 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 *DEPRECATED*", CONFIG_DEFAULT }, "Scrollbar width *DEPRECATED*", 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) *DEPRECATED*", CONFIG_DEFAULT }, "Background to use for fake transparency. (background or screenshot) *DEPRECATED*", 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 },
{ 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, "max-history-size", { .num = &config.max_history_size }, NULL, { xrm_Number, "max-history-size", { .num = &config.max_history_size }, NULL,
"Max history size (WARNING: can cause slowdowns when set to high).", CONFIG_DEFAULT }, "Max history size (WARNING: can cause slowdowns when set to high).", CONFIG_DEFAULT },
{ xrm_Boolean, "combi-hide-mode-prefix", { .snum = &config.combi_hide_mode_prefix }, NULL, { xrm_Boolean, "combi-hide-mode-prefix", { .snum = &config.combi_hide_mode_prefix }, NULL,
"Hide the prefix mode prefix on the combi view.", CONFIG_DEFAULT }, "Hide the prefix mode prefix on the combi view.", CONFIG_DEFAULT },
{ xrm_Char, "matching-negate-char", { .charc= &config.matching_negate_char }, NULL, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL,
"Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT },
{ xrm_String, "cache-dir", { .str = &config.cache_dir }, NULL, { xrm_String, "cache-dir", { .str = &config.cache_dir }, NULL,
"Directory where history and temporary files are stored.", CONFIG_DEFAULT }, "Directory where history and temporary files are stored.", CONFIG_DEFAULT },
{ xrm_Boolean, "window-thumbnail", { .snum = &config.window_thumbnail }, NULL, { xrm_Boolean, "window-thumbnail", { .snum = &config.window_thumbnail }, NULL,
"Show window thumbnail in window switcher if availalbe.", CONFIG_DEFAULT }, "Show window thumbnail in window switcher if availalbe.", CONFIG_DEFAULT },
{ xrm_Boolean, "drun-use-desktop-cache", { .snum = &config.drun_use_desktop_cache }, NULL, { xrm_Boolean, "drun-use-desktop-cache", { .snum = &config.drun_use_desktop_cache }, NULL,
"DRUN: build and use a cache with desktop file content.", CONFIG_DEFAULT }, "DRUN: build and use a cache with desktop file content.", CONFIG_DEFAULT },
{ xrm_Boolean, "drun-reload-desktop-cache", { .snum = &config.drun_reload_desktop_cache}, NULL, { xrm_Boolean, "drun-reload-desktop-cache", { .snum = &config.drun_reload_desktop_cache }, NULL,
"DRUN: If enabled, reload the cache with desktop file content.", CONFIG_DEFAULT }, "DRUN: If enabled, reload the cache with desktop file content.", CONFIG_DEFAULT },
}; };
@ -582,45 +582,45 @@ void config_parse_xresource_dump ( void )
static void config_parse_dump_config_option ( FILE *out, XrmOption *option ) static void config_parse_dump_config_option ( FILE *out, XrmOption *option )
{ {
if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) { if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) {
fprintf ( out, "/*" ); fprintf ( out, "/*" );
} }
fprintf ( out, "\t%s: ", option->name ); fprintf ( out, "\t%s: ", option->name );
switch ( option->type ) switch ( option->type )
{ {
case xrm_Number: case xrm_Number:
fprintf ( out, "%u", *( option->value.num ) ); fprintf ( out, "%u", *( option->value.num ) );
break; break;
case xrm_SNumber: case xrm_SNumber:
fprintf ( out, "%i", *( option->value.snum ) ); fprintf ( out, "%i", *( option->value.snum ) );
break; break;
case xrm_String: case xrm_String:
if ( ( *( option->value.str ) ) != NULL ) { if ( ( *( option->value.str ) ) != NULL ) {
// TODO should this be escaped? // TODO should this be escaped?
fprintf ( out, "\"%s\"", *( option->value.str ) ); fprintf ( out, "\"%s\"", *( option->value.str ) );
} }
break; break;
case xrm_Boolean: case xrm_Boolean:
fprintf ( out, "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" ); fprintf ( out, "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" );
break; break;
case xrm_Char: case xrm_Char:
// TODO // TODO
if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) { if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) {
fprintf ( out, "'%c'", *( option->value.charc ) ); fprintf ( out, "'%c'", *( option->value.charc ) );
} }
else { else {
fprintf ( out, "'\\x%02X'", *( option->value.charc ) ); fprintf ( out, "'\\x%02X'", *( option->value.charc ) );
} }
fprintf ( out, " /* unsupported */" ); fprintf ( out, " /* unsupported */" );
break; break;
default: default:
break; break;
} }
fprintf ( out, ";" ); fprintf ( out, ";" );
if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) { if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) {
fprintf ( out, "*/" ); fprintf ( out, "*/" );
} }
fprintf ( out, "\n" ); fprintf ( out, "\n" );
} }
void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes ) void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes )