Indent round.

This commit is contained in:
Dave Davenport 2020-11-03 23:57:02 +01:00
parent d8eaeec66d
commit 7061eb21ae
17 changed files with 420 additions and 415 deletions

View File

@ -173,5 +173,5 @@ Settings config = {
.benchmark_ui = FALSE, .benchmark_ui = FALSE,
/** normalize match */ /** normalize match */
.normalize_match = FALSE .normalize_match = FALSE
}; };

View File

@ -38,7 +38,7 @@
/** #Mode object representing the run dialog. */ /** #Mode object representing the run dialog. */
extern Mode file_browser_mode; extern Mode file_browser_mode;
Mode *create_new_file_browser (void); Mode *create_new_file_browser ( void );
ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path ); ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path );
/**@}*/ /**@}*/
#endif // ROFI_DIALOG_FILE_BROWSER_H #endif // ROFI_DIALOG_FILE_BROWSER_H

View File

@ -45,8 +45,6 @@ uint32_t rofi_icon_fetcher_query ( const char *name, const int size );
*/ */
cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid ); cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid );
gboolean rofi_icon_fetcher_file_is_image ( const char * const path ); gboolean rofi_icon_fetcher_file_is_image ( const char * const path );
/** @} */ /** @} */
#endif // ROFI_ICON_FETCHER_H #endif // ROFI_ICON_FETCHER_H

View File

@ -181,7 +181,7 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
} }
} }
if ( ( mretv & MENU_CUSTOM_INPUT ) ) { if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
return mode_result ( pd->switchers[0].mode, mretv, input, selected_line ); return mode_result ( pd->switchers[0].mode, mretv, input, selected_line );
} }
return MODE_EXIT; return MODE_EXIT;
} }

View File

@ -736,11 +736,11 @@ static void drun_write_str ( FILE *fd, const char *str )
} }
static void drun_write_integer ( FILE *fd, int32_t val ) static void drun_write_integer ( FILE *fd, int32_t val )
{ {
fwrite ( &val,sizeof(val), 1, fd ); fwrite ( &val, sizeof ( val ), 1, fd );
} }
static void drun_read_integer ( FILE *fd, int32_t *type ) static void drun_read_integer ( FILE *fd, int32_t *type )
{ {
if ( fread ( type, sizeof ( int32_t), 1, fd ) != 1 ) { if ( fread ( type, sizeof ( int32_t ), 1, fd ) != 1 ) {
g_warning ( "Failed to read entry, cache corrupt?" ); g_warning ( "Failed to read entry, cache corrupt?" );
return; return;
} }
@ -821,7 +821,7 @@ 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 );
drun_write_integer ( fd, (int32_t)entry->type ); drun_write_integer ( fd, (int32_t) entry->type );
} }
fclose ( fd ); fclose ( fd );
@ -893,7 +893,7 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil
drun_read_string ( fd, &( entry->comment ) ); drun_read_string ( fd, &( entry->comment ) );
int32_t type = 0; int32_t type = 0;
drun_read_integer( fd, &( type ) ); drun_read_integer ( fd, &( type ) );
entry->type = type; entry->type = type;
} }
@ -1041,10 +1041,10 @@ static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned i
} }
} }
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
RofiHelperExecuteContext context = { .name = NULL }; RofiHelperExecuteContext context = { .name = NULL };
gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION ); gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION );
// FIXME: We assume startup notification in terminals, not in others // FIXME: We assume startup notification in terminals, not in others
if ( ! helper_execute_command ( NULL, *input, run_in_term, run_in_term ? &context : NULL ) ) { if ( !helper_execute_command ( NULL, *input, run_in_term, run_in_term ? &context : NULL ) ) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
} }

View File

@ -35,7 +35,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include "mode.h" #include "mode.h"
#include "helper.h" #include "helper.h"
#include "mode-private.h" #include "mode-private.h"
@ -47,13 +46,13 @@
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
/** /**
* The internal data structure holding the private data of the TEST Mode. * The internal data structure holding the private data of the TEST Mode.
*/ */
enum FBFileType { enum FBFileType
{
UP, UP,
DIRECTORY, DIRECTORY,
RFILE, RFILE,
@ -65,30 +64,31 @@ const char *icon_name[NUM_FILE_TYPES] =
"folder", "folder",
"gtk-file" "gtk-file"
}; };
typedef struct { typedef struct
char *name; {
char *path; char *name;
char *path;
enum FBFileType type; enum FBFileType type;
uint32_t icon_fetch_uid; uint32_t icon_fetch_uid;
gboolean link; gboolean link;
} FBFile; } FBFile;
typedef struct typedef struct
{ {
GFile *current_dir; GFile *current_dir;
FBFile *array; FBFile *array;
unsigned int array_length; unsigned int array_length;
} FileBrowserModePrivateData; } FileBrowserModePrivateData;
static void free_list ( FileBrowserModePrivateData *pd ) static void free_list ( FileBrowserModePrivateData *pd )
{ {
for ( unsigned int i = 0; i < pd->array_length; i++ ) { for ( unsigned int i = 0; i < pd->array_length; i++ ) {
FBFile *fb = & ( pd->array[i] ); FBFile *fb = &( pd->array[i] );
g_free ( fb->name ); g_free ( fb->name );
g_free ( fb->path ); g_free ( fb->path );
} }
g_free (pd->array); g_free ( pd->array );
pd->array = NULL; pd->array = NULL;
pd->array_length = 0; pd->array_length = 0;
} }
#include <sys/types.h> #include <sys/types.h>
@ -96,10 +96,10 @@ static void free_list ( FileBrowserModePrivateData *pd )
static gint compare ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data ) static gint compare ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data )
{ {
FBFile *fa = (FBFile*)a; FBFile *fa = (FBFile*) a;
FBFile *fb = (FBFile*)b; FBFile *fb = (FBFile*) b;
if ( fa->type != fb->type ){ if ( fa->type != fb->type ) {
return (fa->type - fb->type); return fa->type - fb->type;
} }
return g_strcmp0 ( fa->name, fb->name ); return g_strcmp0 ( fa->name, fb->name );
@ -113,85 +113,85 @@ static void get_file_browser ( Mode *sw )
* this gets called on plugin initialization. * this gets called on plugin initialization.
*/ */
char *cdir = g_file_get_path ( pd->current_dir ); char *cdir = g_file_get_path ( pd->current_dir );
DIR *dir = opendir ( cdir ); DIR *dir = opendir ( cdir );
if ( dir ) { if ( dir ) {
struct dirent *rd = NULL; struct dirent *rd = NULL;
while ((rd = readdir (dir)) != NULL ) while ( ( rd = readdir ( dir ) ) != NULL ) {
{ if ( g_strcmp0 ( rd->d_name, ".." ) == 0 ) {
if ( g_strcmp0 ( rd->d_name, ".." ) == 0 ){ pd->array = g_realloc ( pd->array, ( pd->array_length + 1 ) * sizeof ( FBFile ) );
pd->array = g_realloc ( pd->array, (pd->array_length+1)*sizeof(FBFile)); // Rofi expects utf-8, so lets convert the filename.
// Rofi expects utf-8, so lets convert the filename. pd->array[pd->array_length].name = g_strdup ( ".." );
pd->array[pd->array_length].name = g_strdup ( ".." ); pd->array[pd->array_length].path = NULL;
pd->array[pd->array_length].path = NULL; pd->array[pd->array_length].type = UP;
pd->array[pd->array_length].type = UP; pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].icon_fetch_uid = 0; pd->array[pd->array_length].link = FALSE;
pd->array[pd->array_length].link = FALSE; pd->array_length++;
pd->array_length++; continue;
continue; }
else if ( rd->d_name[0] == '.' ) {
} else if ( rd->d_name[0] == '.' ) {
continue; continue;
} }
switch ( rd->d_type ) switch ( rd->d_type )
{ {
case DT_BLK: case DT_BLK:
case DT_CHR: case DT_CHR:
case DT_FIFO: case DT_FIFO:
case DT_UNKNOWN: case DT_UNKNOWN:
case DT_SOCK: case DT_SOCK:
default: default:
break; break;
case DT_REG: case DT_REG:
case DT_DIR: case DT_DIR:
pd->array = g_realloc ( pd->array, (pd->array_length+1)*sizeof(FBFile)); pd->array = g_realloc ( pd->array, ( pd->array_length + 1 ) * sizeof ( FBFile ) );
// Rofi expects utf-8, so lets convert the filename. // Rofi expects utf-8, so lets convert the filename.
pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL); pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL );
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL ); pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
pd->array[pd->array_length].type = (rd->d_type == DT_DIR)? DIRECTORY: RFILE; pd->array[pd->array_length].type = ( rd->d_type == DT_DIR ) ? DIRECTORY : RFILE;
pd->array[pd->array_length].icon_fetch_uid = 0; pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].link = FALSE; pd->array[pd->array_length].link = FALSE;
pd->array_length++; pd->array_length++;
break; break;
case DT_LNK: case DT_LNK:
pd->array = g_realloc ( pd->array, (pd->array_length+1)*sizeof(FBFile)); pd->array = g_realloc ( pd->array, ( pd->array_length + 1 ) * sizeof ( FBFile ) );
// Rofi expects utf-8, so lets convert the filename. // Rofi expects utf-8, so lets convert the filename.
pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL); pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL );
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL ); pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
pd->array[pd->array_length].icon_fetch_uid = 0; pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].link = TRUE; pd->array[pd->array_length].link = TRUE;
// Default to file. // Default to file.
pd->array[pd->array_length].type = RFILE; pd->array[pd->array_length].type = RFILE;
{ {
// If we have link, use a stat to fine out what it is, if we fail, we mark it as file. // If we have link, use a stat to fine out what it is, if we fail, we mark it as file.
// TODO have a 'broken link' mode? // TODO have a 'broken link' mode?
// Convert full path to right encoding. // Convert full path to right encoding.
char *file = g_filename_from_utf8(pd->array[pd->array_length].path,-1, NULL, NULL, NULL ); char *file = g_filename_from_utf8 ( pd->array[pd->array_length].path, -1, NULL, NULL, NULL );
if ( file ) { if ( file ) {
struct stat statbuf; struct stat statbuf;
if ( stat(file, &statbuf ) == 0 ) { if ( stat ( file, &statbuf ) == 0 ) {
if ( S_ISDIR(statbuf.st_mode ) ) { if ( S_ISDIR ( statbuf.st_mode ) ) {
pd->array[pd->array_length].type = DIRECTORY; pd->array[pd->array_length].type = DIRECTORY;
} else if ( S_ISREG ( statbuf.st_mode ) ) { }
pd->array[pd->array_length].type = RFILE; else if ( S_ISREG ( statbuf.st_mode ) ) {
} pd->array[pd->array_length].type = RFILE;
} else {
g_warning("Failed to stat file: %s, %s" , file, strerror(errno));
} }
g_free ( file );
} }
else {
g_warning ( "Failed to stat file: %s, %s", file, strerror ( errno ) );
}
g_free ( file );
} }
pd->array_length++; }
break; pd->array_length++;
} break;
}
} }
closedir ( dir ); closedir ( dir );
} }
g_qsort_with_data ( pd->array, pd->array_length, sizeof (FBFile ), compare, NULL ); g_qsort_with_data ( pd->array, pd->array_length, sizeof ( FBFile ), compare, NULL );
} }
static int file_browser_mode_init ( Mode *sw ) static int file_browser_mode_init ( Mode *sw )
{ {
/** /**
@ -203,16 +203,16 @@ static int file_browser_mode_init ( Mode *sw )
{ {
char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL ); char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL );
char *file = NULL; char *file = NULL;
if ( g_file_get_contents (path, &file, NULL, NULL ) ) { if ( g_file_get_contents ( path, &file, NULL, NULL ) ) {
if ( g_file_test ( file, G_FILE_TEST_IS_DIR ) ){ if ( g_file_test ( file, G_FILE_TEST_IS_DIR ) ) {
pd->current_dir = g_file_new_for_path( file ); pd->current_dir = g_file_new_for_path ( file );
} }
g_free ( file ); g_free ( file );
} }
// Store it based on the unique identifiers (desktop_id). // Store it based on the unique identifiers (desktop_id).
g_free ( path ); g_free ( path );
if ( pd->current_dir == NULL ) { if ( pd->current_dir == NULL ) {
pd->current_dir = g_file_new_for_path(g_get_home_dir () ); pd->current_dir = g_file_new_for_path ( g_get_home_dir () );
} }
} }
// Load content. // Load content.
@ -228,73 +228,76 @@ static unsigned int file_browser_mode_get_num_entries ( const Mode *sw )
static ModeMode file_browser_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) static ModeMode file_browser_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{ {
ModeMode retv = MODE_EXIT; ModeMode retv = MODE_EXIT;
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( mretv & MENU_NEXT ) { if ( mretv & MENU_NEXT ) {
retv = NEXT_DIALOG; retv = NEXT_DIALOG;
} else if ( mretv & MENU_PREVIOUS ) { }
else if ( mretv & MENU_PREVIOUS ) {
retv = PREVIOUS_DIALOG; retv = PREVIOUS_DIALOG;
} else if ( mretv & MENU_QUICK_SWITCH ) { }
else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK ); retv = ( mretv & MENU_LOWER_MASK );
} else if ( ( mretv & MENU_OK ) ) { }
if ( selected_line < pd->array_length ) else if ( ( mretv & MENU_OK ) ) {
{ if ( selected_line < pd->array_length ) {
if ( pd->array[selected_line].type == UP ) { if ( pd->array[selected_line].type == UP ) {
GFile *new = g_file_get_parent ( pd->current_dir ); GFile *new = g_file_get_parent ( pd->current_dir );
if ( new ){ if ( new ) {
g_object_unref ( pd->current_dir ); g_object_unref ( pd->current_dir );
pd->current_dir = new; pd->current_dir = new;
free_list (pd); free_list ( pd );
get_file_browser ( sw ); get_file_browser ( sw );
return RESET_DIALOG; return RESET_DIALOG;
} }
} else if ( pd->array[selected_line].type == DIRECTORY ) { }
else if ( pd->array[selected_line].type == DIRECTORY ) {
char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL ); char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL );
g_file_set_contents (path, pd->array[selected_line].path, -1, NULL ); g_file_set_contents ( path, pd->array[selected_line].path, -1, NULL );
g_free(path); g_free ( path );
GFile *new = g_file_new_for_path ( pd->array[selected_line].path ); GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
g_object_unref ( pd->current_dir ); g_object_unref ( pd->current_dir );
pd->current_dir = new; pd->current_dir = new;
free_list (pd); free_list ( pd );
get_file_browser ( sw ); get_file_browser ( sw );
return RESET_DIALOG; return RESET_DIALOG;
} else if ( pd->array[selected_line].type == RFILE ) { }
char *d = g_filename_from_utf8 (pd->array[selected_line].path, -1, NULL, NULL, NULL); else if ( pd->array[selected_line].type == RFILE ) {
char *cmd = g_strdup_printf("xdg-open '%s'", d ); char *d = g_filename_from_utf8 ( pd->array[selected_line].path, -1, NULL, NULL, NULL );
g_free(d); char *cmd = g_strdup_printf ( "xdg-open '%s'", d );
g_free ( d );
char *cdir = g_file_get_path ( pd->current_dir ); char *cdir = g_file_get_path ( pd->current_dir );
helper_execute_command ( cdir,cmd, FALSE,NULL ); helper_execute_command ( cdir, cmd, FALSE, NULL );
g_free ( cdir ); g_free ( cdir );
g_free ( cmd ); g_free ( cmd );
return MODE_EXIT; return MODE_EXIT;
} }
} }
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} else if ( (mretv&MENU_CUSTOM_INPUT) && *input ) { }
char *p = rofi_expand_path ( *input ); else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input ) {
char *p = rofi_expand_path ( *input );
char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL ); char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
g_free (p); g_free ( p );
if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
{ if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ){
g_object_unref ( pd->current_dir ); g_object_unref ( pd->current_dir );
pd->current_dir = g_file_new_for_path ( dir ); pd->current_dir = g_file_new_for_path ( dir );
g_free ( dir ); g_free ( dir );
free_list (pd); free_list ( pd );
get_file_browser ( sw ); get_file_browser ( sw );
return RESET_DIALOG; return RESET_DIALOG;
} }
} }
g_free ( dir ); g_free ( dir );
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) { }
else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
return retv; return retv;
} }
static void file_browser_mode_destroy ( Mode *sw ) static void file_browser_mode_destroy ( Mode *sw )
{ {
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
@ -311,17 +314,21 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
// Only return the string if requested, otherwise only set state. // Only return the string if requested, otherwise only set state.
if ( !get_entry ) return NULL; if ( !get_entry ) {
if ( pd->array[selected_line].type == UP ){ return NULL;
return g_strdup( " .."); }
} else { if ( pd->array[selected_line].type == UP ) {
return g_strdup ( " .." );
}
else {
if ( pd->array[selected_line].link ) { if ( pd->array[selected_line].link ) {
return g_strconcat ( "@", pd->array[selected_line].name, NULL); return g_strconcat ( "@", pd->array[selected_line].name, NULL );
} else { }
return g_strdup ( pd->array[selected_line].name); else {
return g_strdup ( pd->array[selected_line].name );
} }
} }
return g_strdup("n/a"); return g_strdup ( "n/a" );
} }
/** /**
@ -338,21 +345,21 @@ static int file_browser_token_match ( const Mode *sw, rofi_int_matcher **tokens,
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
// Call default matching function. // Call default matching function.
return helper_token_match ( tokens, pd->array[index].name); return helper_token_match ( tokens, pd->array[index].name );
} }
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height ) static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{ {
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->array != NULL, NULL ); g_return_val_if_fail ( pd->array != NULL, NULL );
FBFile *dr = &( pd->array[selected_line] ); FBFile *dr = &( pd->array[selected_line] );
if ( dr->icon_fetch_uid > 0 ) { if ( dr->icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
} }
if ( rofi_icon_fetcher_file_is_image ( dr->path ) ){ if ( rofi_icon_fetcher_file_is_image ( dr->path ) ) {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->path, height ); dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->path, height );
} else { }
else {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( icon_name[dr->type], height ); dr->icon_fetch_uid = rofi_icon_fetcher_query ( icon_name[dr->type], height );
} }
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
@ -363,25 +370,24 @@ static char * _get_message ( const Mode *sw )
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( pd->current_dir ) { if ( pd->current_dir ) {
char *dirname = g_file_get_parse_name ( pd->current_dir ); char *dirname = g_file_get_parse_name ( pd->current_dir );
char *str = g_markup_printf_escaped("<b>Current directory:</b> %s", dirname); char *str = g_markup_printf_escaped ( "<b>Current directory:</b> %s", dirname );
g_free ( dirname ); g_free ( dirname );
return str; return str;
} }
return "n/a"; return "n/a";
} }
static char *_get_completion ( const Mode *sw, unsigned int index ) static char *_get_completion ( const Mode *sw, unsigned int index )
{ {
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
char *d = g_strescape ( pd->array[index].path,NULL ); char *d = g_strescape ( pd->array[index].path, NULL );
return d; return d;
} }
Mode *create_new_file_browser (void ) Mode *create_new_file_browser ( void )
{ {
Mode *sw = g_malloc0(sizeof(Mode)); Mode *sw = g_malloc0 ( sizeof ( Mode ) );
*sw = file_browser_mode; *sw = file_browser_mode;
@ -392,58 +398,62 @@ Mode *create_new_file_browser (void )
#if 0 #if 0
ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path ) ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path )
{ {
ModeMode retv = MODE_EXIT; ModeMode retv = MODE_EXIT;
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw ); FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( mretv & MENU_NEXT ) { if ( mretv & MENU_NEXT ) {
retv = NEXT_DIALOG; retv = NEXT_DIALOG;
} else if ( mretv & MENU_PREVIOUS ) { }
else if ( mretv & MENU_PREVIOUS ) {
retv = PREVIOUS_DIALOG; retv = PREVIOUS_DIALOG;
} else if ( mretv & MENU_QUICK_SWITCH ) { }
else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK ); retv = ( mretv & MENU_LOWER_MASK );
} else if ( ( mretv & MENU_OK ) ) { }
if ( selected_line < pd->array_length ) else if ( ( mretv & MENU_OK ) ) {
{ if ( selected_line < pd->array_length ) {
if ( pd->array[selected_line].type == UP ) { if ( pd->array[selected_line].type == UP ) {
GFile *new = g_file_get_parent ( pd->current_dir ); GFile *new = g_file_get_parent ( pd->current_dir );
if ( new ){ if ( new ) {
g_object_unref ( pd->current_dir ); g_object_unref ( pd->current_dir );
pd->current_dir = new; pd->current_dir = new;
free_list (pd); free_list ( pd );
get_file_browser ( sw ); get_file_browser ( sw );
return RESET_DIALOG; return RESET_DIALOG;
} }
} else if ( pd->array[selected_line].type == DIRECTORY ) { }
else if ( pd->array[selected_line].type == DIRECTORY ) {
GFile *new = g_file_new_for_path ( pd->array[selected_line].path ); GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
g_object_unref ( pd->current_dir ); g_object_unref ( pd->current_dir );
pd->current_dir = new; pd->current_dir = new;
free_list (pd); free_list ( pd );
get_file_browser ( sw ); get_file_browser ( sw );
return RESET_DIALOG; return RESET_DIALOG;
} else if ( pd->array[selected_line].type == RFILE ) { }
*path = g_strescape ( pd->array[selected_line].path,NULL ); else if ( pd->array[selected_line].type == RFILE ) {
*path = g_strescape ( pd->array[selected_line].path, NULL );
return MODE_EXIT; return MODE_EXIT;
} }
} }
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} else if ( (mretv&MENU_CUSTOM_INPUT) && *input ) { }
char *p = rofi_expand_path ( *input ); else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input ) {
char *p = rofi_expand_path ( *input );
char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL ); char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
g_free (p); g_free ( p );
if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
{ if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ){
g_object_unref ( pd->current_dir ); g_object_unref ( pd->current_dir );
pd->current_dir = g_file_new_for_path ( dir ); pd->current_dir = g_file_new_for_path ( dir );
g_free ( dir ); g_free ( dir );
free_list (pd); free_list ( pd );
get_file_browser ( sw ); get_file_browser ( sw );
return RESET_DIALOG; return RESET_DIALOG;
} }
} }
g_free ( dir ); g_free ( dir );
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) { }
else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
return retv; return retv;

View File

@ -376,12 +376,12 @@ static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned in
if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) {
if ( !exec_cmd ( rmpd->cmd_list[selected_line], run_in_term ) ) { if ( !exec_cmd ( rmpd->cmd_list[selected_line], run_in_term ) ) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
} }
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
if ( !exec_cmd ( *input, run_in_term ) ) { if ( !exec_cmd ( *input, run_in_term ) ) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
} }
else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) { else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) {

View File

@ -279,19 +279,19 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
unsigned int new_length = 0; unsigned int new_length = 0;
if ( ( mretv & MENU_CUSTOM_COMMAND ) ) { if ( ( mretv & MENU_CUSTOM_COMMAND ) ) {
//retv = 1+( mretv & MENU_LOWER_MASK ); //retv = 1+( mretv & MENU_LOWER_MASK );
script_mode_reset_highlight ( sw ); script_mode_reset_highlight ( sw );
if ( selected_line != UINT32_MAX ) { if ( selected_line != UINT32_MAX ) {
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), &( rmpd->cmd_list[selected_line] ) ); new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), &( rmpd->cmd_list[selected_line] ) );
}
else {
if ( rmpd->no_custom == FALSE ) {
new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), NULL );
} }
else { else {
return RELOAD_DIALOG; if ( rmpd->no_custom == FALSE ) {
new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), NULL );
}
else {
return RELOAD_DIALOG;
}
} }
}
} }
else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) { else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) {
if ( rmpd->cmd_list[selected_line].nonselectable ) { if ( rmpd->cmd_list[selected_line].nonselectable ) {

View File

@ -698,21 +698,21 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i
xcb_flush ( xcb->connection ); xcb_flush ( xcb->connection );
} }
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
GError *error = NULL; GError *error = NULL;
gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION ); gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION );
gsize lf_cmd_size = 0; gsize lf_cmd_size = 0;
gchar *lf_cmd = g_locale_from_utf8 ( *input, -1, NULL, &lf_cmd_size, &error ); gchar *lf_cmd = g_locale_from_utf8 ( *input, -1, NULL, &lf_cmd_size, &error );
if ( error != NULL ) { if ( error != NULL ) {
g_warning ( "Failed to convert command to locale encoding: %s", error->message ); g_warning ( "Failed to convert command to locale encoding: %s", error->message );
g_error_free ( error ); g_error_free ( error );
return RELOAD_DIALOG; return RELOAD_DIALOG;
} }
RofiHelperExecuteContext context = { .name = NULL }; RofiHelperExecuteContext context = { .name = NULL };
if ( ! helper_execute_command ( NULL, lf_cmd, run_in_term, run_in_term ? &context : NULL ) ) { if ( !helper_execute_command ( NULL, lf_cmd, run_in_term, run_in_term ? &context : NULL ) ) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
g_free ( lf_cmd ); g_free ( lf_cmd );
} }
return retv; return retv;
} }

View File

@ -179,43 +179,44 @@ static gchar *fuzzy_to_regex ( const char * input )
return retv; return retv;
} }
static char *utf8_helper_simplify_string ( const char *s) static char *utf8_helper_simplify_string ( const char *s )
{ {
gunichar buf2[G_UNICHAR_MAX_DECOMPOSITION_LENGTH] = {0,}; gunichar buf2[G_UNICHAR_MAX_DECOMPOSITION_LENGTH] = { 0, };
char buf[6] = {0,}; char buf[6] = { 0, };
// Compose the string in maximally composed form. // Compose the string in maximally composed form.
char * str = g_malloc0((g_utf8_strlen(s,0)*6+2)); char * str = g_malloc0 ( ( g_utf8_strlen ( s, 0 ) * 6 + 2 ) );
char *striter = str; char *striter = str;
for ( const char *iter = s; iter && *iter; iter = g_utf8_next_char ( iter )) { for ( const char *iter = s; iter && *iter; iter = g_utf8_next_char ( iter ) ) {
gunichar uc = g_utf8_get_char ( iter ); gunichar uc = g_utf8_get_char ( iter );
int l = 0; int l = 0;
gsize dl = g_unichar_fully_decompose ( uc, FALSE, buf2, G_UNICHAR_MAX_DECOMPOSITION_LENGTH) ; gsize dl = g_unichar_fully_decompose ( uc, FALSE, buf2, G_UNICHAR_MAX_DECOMPOSITION_LENGTH );
if ( dl ) { if ( dl ) {
l = g_unichar_to_utf8 ( buf2[0], buf); l = g_unichar_to_utf8 ( buf2[0], buf );
} else { }
l = g_unichar_to_utf8 ( uc, buf); else {
l = g_unichar_to_utf8 ( uc, buf );
}
memcpy ( striter, buf, l );
striter += l;
} }
memcpy(striter, buf, l);
striter+=l;
}
return str; return str;
} }
// Macro for quickly generating regex for matching. // Macro for quickly generating regex for matching.
static inline GRegex * R ( const char *s, int case_sensitive ) static inline GRegex * R ( const char *s, int case_sensitive )
{ {
if ( config.normalize_match ) { if ( config.normalize_match ) {
char *str = utf8_helper_simplify_string ( s ); char *str = utf8_helper_simplify_string ( s );
GRegex *r = g_regex_new ( str, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL ); GRegex *r = g_regex_new ( str, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL );
g_free ( str ); g_free ( str );
return r; return r;
} else { }
return g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL ); else {
return g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL );
} }
} }
static rofi_int_matcher * create_regex ( const char *input, int case_sensitive ) static rofi_int_matcher * create_regex ( const char *input, int case_sensitive )
@ -414,7 +415,7 @@ PangoAttrList *helper_token_match_get_pango_attr ( RofiHighlightColorStyle th, r
{ {
// Disable highlighting for normalize match, not supported atm. // Disable highlighting for normalize match, not supported atm.
if ( config.normalize_match ) { if ( config.normalize_match ) {
return retv; return retv;
} }
// Do a tokenized match. // Do a tokenized match.
if ( tokens ) { if ( tokens ) {
@ -489,19 +490,20 @@ int helper_token_match ( rofi_int_matcher* const *tokens, const char *input )
int match = TRUE; int match = TRUE;
// Do a tokenized match. // Do a tokenized match.
if ( tokens ) { if ( tokens ) {
if ( config.normalize_match ) { if ( config.normalize_match ) {
char *r = utf8_helper_simplify_string(input); char *r = utf8_helper_simplify_string ( input );
for ( int j = 0; match && tokens[j]; j++ ) { for ( int j = 0; match && tokens[j]; j++ ) {
match = g_regex_match ( tokens[j]->regex, r, 0, NULL ); match = g_regex_match ( tokens[j]->regex, r, 0, NULL );
match ^= tokens[j]->invert; match ^= tokens[j]->invert;
}
g_free ( r );
} }
g_free(r); else {
} else { for ( int j = 0; match && tokens[j]; j++ ) {
for ( int j = 0; match && tokens[j]; j++ ) { match = g_regex_match ( tokens[j]->regex, input, 0, NULL );
match = g_regex_match ( tokens[j]->regex, input, 0, NULL ); match ^= tokens[j]->invert;
match ^= tokens[j]->invert; }
} }
}
} }
return match; return match;
} }

View File

@ -103,7 +103,7 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel
return PREVIOUS_DIALOG; return PREVIOUS_DIALOG;
} }
else if ( menu_retv & MENU_QUICK_SWITCH ) { else if ( menu_retv & MENU_QUICK_SWITCH ) {
return ( menu_retv & MENU_LOWER_MASK ); return menu_retv & MENU_LOWER_MASK;
} }
g_assert ( mode != NULL ); g_assert ( mode != NULL );

View File

@ -58,7 +58,7 @@ typedef struct
GHashTable *icon_cache_uid; GHashTable *icon_cache_uid;
// list extensions // list extensions
GList *supported_extensions; GList *supported_extensions;
uint32_t last_uid; uint32_t last_uid;
} IconFetcher; } IconFetcher;
@ -88,7 +88,6 @@ typedef struct
*/ */
IconFetcher *rofi_icon_fetcher_data = NULL; IconFetcher *rofi_icon_fetcher_data = NULL;
static void rofi_icon_fetch_entry_free ( gpointer data ) static void rofi_icon_fetch_entry_free ( gpointer data )
{ {
IconFetcherNameEntry *entry = (IconFetcherNameEntry *) data; IconFetcherNameEntry *entry = (IconFetcherNameEntry *) data;
@ -126,23 +125,19 @@ void rofi_icon_fetcher_init ( void )
rofi_icon_fetcher_data->icon_cache_uid = g_hash_table_new ( g_direct_hash, g_direct_equal ); rofi_icon_fetcher_data->icon_cache_uid = g_hash_table_new ( g_direct_hash, g_direct_equal );
rofi_icon_fetcher_data->icon_cache = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, rofi_icon_fetch_entry_free ); rofi_icon_fetcher_data->icon_cache = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, rofi_icon_fetch_entry_free );
GSList *l = gdk_pixbuf_get_formats ();
for ( GSList *li = l; li != NULL; li = g_slist_next ( li ) ) {
gchar **exts = gdk_pixbuf_format_get_extensions ( (GdkPixbufFormat *) li->data );
GSList *l = gdk_pixbuf_get_formats(); for ( unsigned int i = 0; exts && exts[i]; i++ ) {
for ( GSList *li = l; li != NULL; li = g_slist_next(li)) rofi_icon_fetcher_data->supported_extensions = g_list_append ( rofi_icon_fetcher_data->supported_extensions, exts[i] );
{ g_info ( "Add image extension: %s", exts[i] );
gchar **exts = gdk_pixbuf_format_get_extensions ( (GdkPixbufFormat *)li->data ); exts[i] = NULL;
}
for ( unsigned int i = 0; exts && exts[i]; i ++ ) {
rofi_icon_fetcher_data->supported_extensions = g_list_append ( rofi_icon_fetcher_data->supported_extensions, exts[i]);
g_info ( "Add image extension: %s", exts[i]);
exts[i] = NULL;
}
g_free ( exts );
g_free ( exts );
} }
g_slist_free ( l ); g_slist_free ( l );
} }
void rofi_icon_fetcher_destroy ( void ) void rofi_icon_fetcher_destroy ( void )
@ -156,8 +151,7 @@ void rofi_icon_fetcher_destroy ( void )
g_hash_table_unref ( rofi_icon_fetcher_data->icon_cache_uid ); g_hash_table_unref ( rofi_icon_fetcher_data->icon_cache_uid );
g_hash_table_unref ( rofi_icon_fetcher_data->icon_cache ); g_hash_table_unref ( rofi_icon_fetcher_data->icon_cache );
g_list_foreach ( rofi_icon_fetcher_data->supported_extensions, (GFunc) g_free, NULL );
g_list_foreach ( rofi_icon_fetcher_data->supported_extensions, (GFunc)g_free, NULL );
g_list_free ( rofi_icon_fetcher_data->supported_extensions ); g_list_free ( rofi_icon_fetcher_data->supported_extensions );
g_free ( rofi_icon_fetcher_data ); g_free ( rofi_icon_fetcher_data );
} }
@ -169,18 +163,18 @@ void rofi_icon_fetcher_destroy ( void )
* Copyright (C) 2011-2018 Red Hat, Inc. * Copyright (C) 2011-2018 Red Hat, Inc.
*/ */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define RED_BYTE 2 #define RED_BYTE 2
#define GREEN_BYTE 1 #define GREEN_BYTE 1
#define BLUE_BYTE 0 #define BLUE_BYTE 0
#define ALPHA_BYTE 3 #define ALPHA_BYTE 3
#else #else
#define RED_BYTE 1 #define RED_BYTE 1
#define GREEN_BYTE 2 #define GREEN_BYTE 2
#define BLUE_BYTE 3 #define BLUE_BYTE 3
#define ALPHA_BYTE 0 #define ALPHA_BYTE 0
#endif #endif
static inline guchar alpha_mult(guchar c, guchar a) static inline guchar alpha_mult ( guchar c, guchar a )
{ {
guint16 t; guint16 t;
switch ( a ) switch ( a )
@ -191,70 +185,70 @@ static inline guchar alpha_mult(guchar c, guchar a)
return 0x00; return 0x00;
default: default:
t = c * a + 0x7f; t = c * a + 0x7f;
return ((t >> 8) + t) >> 8; return ( ( t >> 8 ) + t ) >> 8;
} }
} }
static cairo_surface_t * rofi_icon_fetcher_get_surface_from_pixbuf(GdkPixbuf static cairo_surface_t * rofi_icon_fetcher_get_surface_from_pixbuf ( GdkPixbuf
*pixbuf) *pixbuf )
{ {
gint width, height; gint width, height;
const guchar *pixels; const guchar *pixels;
gint stride; gint stride;
gboolean alpha; gboolean alpha;
if ( pixbuf == NULL ) if ( pixbuf == NULL ) {
return NULL; return NULL;
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
pixels = gdk_pixbuf_read_pixels(pixbuf);
stride = gdk_pixbuf_get_rowstride(pixbuf);
alpha = gdk_pixbuf_get_has_alpha(pixbuf);
cairo_surface_t *surface = NULL;
gint cstride;
guint lo, o;
guchar a = 0xff;
const guchar *pixels_end, *line, *line_end;
guchar *cpixels, *cline;
pixels_end = pixels + height * stride;
o = alpha ? 4 : 3;
lo = o * width;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cpixels = cairo_image_surface_get_data(surface);
cstride = cairo_image_surface_get_stride(surface);
cairo_surface_flush(surface);
while ( pixels < pixels_end )
{
line = pixels;
line_end = line + lo;
cline = cpixels;
while ( line < line_end )
{
if ( alpha )
a = line[3];
cline[RED_BYTE] = alpha_mult(line[0], a);
cline[GREEN_BYTE] = alpha_mult(line[1], a);
cline[BLUE_BYTE] = alpha_mult(line[2], a);
cline[ALPHA_BYTE] = a;
line += o;
cline += 4;
} }
pixels += stride; width = gdk_pixbuf_get_width ( pixbuf );
cpixels += cstride; height = gdk_pixbuf_get_height ( pixbuf );
} pixels = gdk_pixbuf_read_pixels ( pixbuf );
cairo_surface_mark_dirty(surface); stride = gdk_pixbuf_get_rowstride ( pixbuf );
cairo_surface_flush(surface); alpha = gdk_pixbuf_get_has_alpha ( pixbuf );
return surface; cairo_surface_t *surface = NULL;
gint cstride;
guint lo, o;
guchar a = 0xff;
const guchar *pixels_end, *line, *line_end;
guchar *cpixels, *cline;
pixels_end = pixels + height * stride;
o = alpha ? 4 : 3;
lo = o * width;
surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, width, height );
cpixels = cairo_image_surface_get_data ( surface );
cstride = cairo_image_surface_get_stride ( surface );
cairo_surface_flush ( surface );
while ( pixels < pixels_end ) {
line = pixels;
line_end = line + lo;
cline = cpixels;
while ( line < line_end ) {
if ( alpha ) {
a = line[3];
}
cline[RED_BYTE] = alpha_mult ( line[0], a );
cline[GREEN_BYTE] = alpha_mult ( line[1], a );
cline[BLUE_BYTE] = alpha_mult ( line[2], a );
cline[ALPHA_BYTE] = a;
line += o;
cline += 4;
}
pixels += stride;
cpixels += cstride;
}
cairo_surface_mark_dirty ( surface );
cairo_surface_flush ( surface );
return surface;
} }
gboolean rofi_icon_fetcher_file_is_image ( const char * const path ) gboolean rofi_icon_fetcher_file_is_image ( const char * const path )
@ -262,70 +256,71 @@ gboolean rofi_icon_fetcher_file_is_image ( const char * const path )
if ( path == NULL ) { if ( path == NULL ) {
return FALSE; return FALSE;
} }
const char *suf = strrchr(path, '.'); const char *suf = strrchr ( path, '.' );
if ( suf == NULL ) { if ( suf == NULL ) {
return FALSE; return FALSE;
} }
suf++; suf++;
for ( GList *iter = rofi_icon_fetcher_data->supported_extensions; iter != NULL ; iter = g_list_next ( iter ) ) { for ( GList *iter = rofi_icon_fetcher_data->supported_extensions; iter != NULL; iter = g_list_next ( iter ) ) {
if ( g_ascii_strcasecmp(iter->data, suf ) == 0 ) { if ( g_ascii_strcasecmp ( iter->data, suf ) == 0 ) {
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data ) static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data )
{ {
g_debug ( "starting up icon fetching thread." ); g_debug ( "starting up icon fetching thread." );
// as long as dr->icon is updated atomicly.. (is a pointer write atomic?) // as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
// this should be fine running in another thread. // this should be fine running in another thread.
IconFetcherEntry *sentry = (IconFetcherEntry *) sdata; IconFetcherEntry *sentry = (IconFetcherEntry *) sdata;
const gchar *themes[] = { const gchar *themes[] = {
config.icon_theme, config.icon_theme,
NULL NULL
}; };
const gchar *icon_path; const gchar *icon_path;
gchar *icon_path_ = NULL; gchar *icon_path_ = NULL;
if ( g_path_is_absolute ( sentry->entry->name ) ) { if ( g_path_is_absolute ( sentry->entry->name ) ) {
icon_path = sentry->entry->name; icon_path = sentry->entry->name;
}
else {
icon_path = icon_path_ = nk_xdg_theme_get_icon ( rofi_icon_fetcher_data->xdg_context, themes, NULL, sentry->entry->name, sentry->size, 1, TRUE );
if ( icon_path_ == NULL ) {
g_debug ( "failed to get icon %s(%d): n/a", sentry->entry->name, sentry->size );
return;
} }
else{ else {
g_debug ( "found icon %s(%d): %s", sentry->entry->name, sentry->size, icon_path ); icon_path = icon_path_ = nk_xdg_theme_get_icon ( rofi_icon_fetcher_data->xdg_context, themes, NULL, sentry->entry->name, sentry->size, 1, TRUE );
if ( icon_path_ == NULL ) {
g_debug ( "failed to get icon %s(%d): n/a", sentry->entry->name, sentry->size );
return;
}
else{
g_debug ( "found icon %s(%d): %s", sentry->entry->name, sentry->size, icon_path );
}
} }
} cairo_surface_t *icon_surf = NULL;
cairo_surface_t *icon_surf = NULL;
const char *suf = strrchr(icon_path, '.'); const char *suf = strrchr ( icon_path, '.' );
if ( suf == NULL ) { if ( suf == NULL ) {
return ; return;
}
GError *error = NULL;
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale ( icon_path, sentry->size, sentry->size, TRUE, &error );
if ( error != NULL ) {
g_warning ( "Failed to load image: %s", error->message);
g_error_free( error );
if ( pb ) {
g_object_unref ( pb );
} }
} else {
icon_surf = rofi_icon_fetcher_get_surface_from_pixbuf(pb );
g_object_unref ( pb );
}
sentry->surface = icon_surf; GError *error = NULL;
g_free ( icon_path_ ); GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale ( icon_path, sentry->size, sentry->size, TRUE, &error );
rofi_view_reload (); if ( error != NULL ) {
g_warning ( "Failed to load image: %s", error->message );
g_error_free ( error );
if ( pb ) {
g_object_unref ( pb );
}
}
else {
icon_surf = rofi_icon_fetcher_get_surface_from_pixbuf ( pb );
g_object_unref ( pb );
}
sentry->surface = icon_surf;
g_free ( icon_path_ );
rofi_view_reload ();
} }
uint32_t rofi_icon_fetcher_query ( const char *name, const int size ) uint32_t rofi_icon_fetcher_query ( const char *name, const int size )

View File

@ -208,7 +208,7 @@ static void run_switcher ( ModeMode mode )
void process_result ( RofiViewState *state ) void process_result ( RofiViewState *state )
{ {
Mode *sw = state->sw; Mode *sw = state->sw;
// rofi_view_set_active ( NULL ); // rofi_view_set_active ( NULL );
if ( sw != NULL ) { if ( sw != NULL ) {
unsigned int selected_line = rofi_view_get_selected_line ( state );; unsigned int selected_line = rofi_view_get_selected_line ( state );;
MenuReturn mretv = rofi_view_get_return_value ( state ); MenuReturn mretv = rofi_view_get_return_value ( state );
@ -248,15 +248,16 @@ void process_result ( RofiViewState *state )
rofi_view_switch_mode ( state, modi[mode] ); rofi_view_switch_mode ( state, modi[mode] );
curr_switcher = mode; curr_switcher = mode;
return; return;
} else { }
// On exit, free current view, and pop to one above. else {
rofi_view_remove_active ( state ); // On exit, free current view, and pop to one above.
rofi_view_free ( state ); rofi_view_remove_active ( state );
return; rofi_view_free ( state );
return;
} }
} }
// rofi_view_set_active ( NULL ); // rofi_view_set_active ( NULL );
rofi_view_remove_active ( state ); rofi_view_remove_active ( state );
rofi_view_free ( state ); rofi_view_free ( state );
} }

View File

@ -476,12 +476,13 @@ static void rofi_theme_print_index ( ThemeWidget *widget, int index )
gpointer key, value; gpointer key, value;
if ( widget->media ) { if ( widget->media ) {
printf("%s {\n", widget->name ); printf ( "%s {\n", widget->name );
for ( unsigned int i = 0; i < widget->num_widgets; i++ ) { for ( unsigned int i = 0; i < widget->num_widgets; i++ ) {
rofi_theme_print_index ( widget->widgets[i], index+4 ); rofi_theme_print_index ( widget->widgets[i], index + 4 );
} }
printf("}\n"); printf ( "}\n" );
} else { }
else {
if ( widget->properties ) { if ( widget->properties ) {
GList *list = NULL; GList *list = NULL;
ThemeWidget *w = widget; ThemeWidget *w = widget;
@ -496,7 +497,7 @@ static void rofi_theme_print_index ( ThemeWidget *widget, int index )
w = w->parent; w = w->parent;
} }
if ( g_list_length ( list ) > 0 ) { if ( g_list_length ( list ) > 0 ) {
printf("%*s", index, ""); printf ( "%*s", index, "" );
for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) { for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
char *name = (char *) iter->data; char *name = (char *) iter->data;
fputs ( name, stdout ); fputs ( name, stdout );
@ -521,7 +522,7 @@ static void rofi_theme_print_index ( ThemeWidget *widget, int index )
g_hash_table_iter_init ( &iter, widget->properties ); g_hash_table_iter_init ( &iter, widget->properties );
while ( g_hash_table_iter_next ( &iter, &key, &value ) ) { while ( g_hash_table_iter_next ( &iter, &key, &value ) ) {
Property *p = (Property *) value; Property *p = (Property *) value;
rofi_theme_print_property_index ( property_name_length, index+4, p ); rofi_theme_print_property_index ( property_name_length, index + 4, p );
} }
printf ( "%*s}\n", index, "" ); printf ( "%*s}\n", index, "" );
g_list_free ( list ); g_list_free ( list );
@ -1008,13 +1009,13 @@ static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori
{ {
int a = distance_unit_get_pixel ( unit->left, ori ); int a = distance_unit_get_pixel ( unit->left, ori );
int b = distance_unit_get_pixel ( unit->right, ori ); int b = distance_unit_get_pixel ( unit->right, ori );
return MIN(a,b); return MIN ( a, b );
} }
case ROFI_DISTANCE_MODIFIER_MAX: case ROFI_DISTANCE_MODIFIER_MAX:
{ {
int a = distance_unit_get_pixel ( unit->left, ori ); int a = distance_unit_get_pixel ( unit->left, ori );
int b = distance_unit_get_pixel ( unit->right, ori ); int b = distance_unit_get_pixel ( unit->right, ori );
return MAX(a,b); return MAX ( a, b );
} }
default: default:
break; break;
@ -1227,7 +1228,6 @@ static void rofi_theme_parse_merge_widgets_no_media ( ThemeWidget *parent, Theme
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++ ) {
@ -1244,11 +1244,10 @@ void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child )
return; return;
} }
ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name ); ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name );
if ( child->media ) { if ( child->media ) {
w->media = g_slice_new0(ThemeMedia); w->media = g_slice_new0 ( ThemeMedia );
*(w->media) = *(child->media); *( w->media ) = *( child->media );
} }
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++ ) {
@ -1346,9 +1345,9 @@ static void rofi_theme_parse_process_conditionals_int ( workarea mon, ThemeWidg
} }
void rofi_theme_parse_process_conditionals ( void ) void rofi_theme_parse_process_conditionals ( void )
{ {
workarea mon; workarea mon;
monitor_active ( &mon ); monitor_active ( &mon );
rofi_theme_parse_process_conditionals_int ( mon, rofi_theme ); rofi_theme_parse_process_conditionals_int ( mon, rofi_theme );
} }
ThemeMediaType rofi_theme_parse_media_type ( const char *type ) ThemeMediaType rofi_theme_parse_media_type ( const char *type )

View File

@ -416,7 +416,7 @@ static void rofi_view_calculate_window_position ( RofiViewState *state )
static void rofi_view_window_update_size ( RofiViewState * state ) static void rofi_view_window_update_size ( RofiViewState * state )
{ {
if ( state == NULL ) { if ( state == NULL ) {
return; return;
} }
uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
uint32_t vals[] = { state->x, state->y, state->width, state->height }; uint32_t vals[] = { state->x, state->y, state->width, state->height };
@ -495,12 +495,12 @@ RofiViewState * rofi_view_get_active ( void )
void rofi_view_remove_active ( RofiViewState *state ) void rofi_view_remove_active ( RofiViewState *state )
{ {
if ( state == current_active_menu ) { if ( state == current_active_menu ) {
rofi_view_set_active ( NULL ); rofi_view_set_active ( NULL );
} }
else if ( state ) { else if ( state ) {
g_queue_remove ( &(CacheState.views ), state); g_queue_remove ( &( CacheState.views ), state );
} }
} }
void rofi_view_set_active ( RofiViewState *state ) void rofi_view_set_active ( RofiViewState *state )
{ {

View File

@ -135,12 +135,12 @@ static void textbox_initialize_font ( textbox *tb )
if ( helper_validate_font ( tbfc->pfd, font ) ) { if ( helper_validate_font ( tbfc->pfd, font ) ) {
tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL ); tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL );
PangoLayout *layout = pango_layout_new(p_context ); PangoLayout *layout = pango_layout_new ( p_context );
pango_layout_set_text(layout,"aAjb", -1); pango_layout_set_text ( layout, "aAjb", -1 );
PangoRectangle rect; PangoRectangle rect;
pango_layout_get_pixel_extents(layout, NULL, &rect ); pango_layout_get_pixel_extents ( layout, NULL, &rect );
tbfc->height = rect.y + rect.height; tbfc->height = rect.y + rect.height;
g_object_unref ( layout); g_object_unref ( layout );
// Cast away consts. (*yuck*) because table_insert does not know it is const. // Cast away consts. (*yuck*) because table_insert does not know it is const.
g_hash_table_insert ( tbfc_cache, (char *) font, tbfc ); g_hash_table_insert ( tbfc_cache, (char *) font, tbfc );
@ -827,12 +827,12 @@ void textbox_set_pango_context ( const char *font, PangoContext *p )
TBFontConfig *tbfc = g_malloc0 ( sizeof ( TBFontConfig ) ); TBFontConfig *tbfc = g_malloc0 ( sizeof ( TBFontConfig ) );
tbfc->metrics = p_metrics; tbfc->metrics = p_metrics;
PangoLayout *layout = pango_layout_new( p_context ); PangoLayout *layout = pango_layout_new ( p_context );
pango_layout_set_text(layout,"aAjb", -1); pango_layout_set_text ( layout, "aAjb", -1 );
PangoRectangle rect; PangoRectangle rect;
pango_layout_get_pixel_extents(layout, NULL, &rect ); pango_layout_get_pixel_extents ( layout, NULL, &rect );
tbfc->height = rect.y + rect.height; tbfc->height = rect.y + rect.height;
g_object_unref ( layout); g_object_unref ( layout );
tbfc_default = tbfc; tbfc_default = tbfc;
g_hash_table_insert ( tbfc_cache, (gpointer *) ( font ? font : default_font_name ), tbfc ); g_hash_table_insert ( tbfc_cache, (gpointer *) ( font ? font : default_font_name ), tbfc );
@ -874,20 +874,20 @@ int textbox_get_font_height ( const textbox *tb )
{ {
PangoRectangle rect; PangoRectangle rect;
pango_layout_get_pixel_extents ( tb->layout, NULL, &rect ); pango_layout_get_pixel_extents ( tb->layout, NULL, &rect );
return rect.height+ rect.y; return rect.height + rect.y;
} }
int textbox_get_font_width ( const textbox *tb ) int textbox_get_font_width ( const textbox *tb )
{ {
PangoRectangle rect; PangoRectangle rect;
pango_layout_get_pixel_extents ( tb->layout, NULL, &rect); pango_layout_get_pixel_extents ( tb->layout, NULL, &rect );
return rect.width + rect.x; return rect.width + rect.x;
} }
/** Caching for the estimated character height. (em) */ /** Caching for the estimated character height. (em) */
double textbox_get_estimated_char_height ( void ) double textbox_get_estimated_char_height ( void )
{ {
return tbfc_default->height; return tbfc_default->height;
} }
/** Caching for the expected character width. */ /** Caching for the expected character width. */

View File

@ -231,8 +231,8 @@ static XrmOption xrmOptions[] = {
"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 },
{ xrm_Boolean, "normalize-match", { .snum = &config.normalize_match }, NULL, { xrm_Boolean, "normalize-match", { .snum = &config.normalize_match }, NULL,
"Normalize string when matching (implies -no-show-match).", CONFIG_DEFAULT }, "Normalize string when matching (implies -no-show-match).", CONFIG_DEFAULT },
}; };
/** Dynamic array of extra options */ /** Dynamic array of extra options */