mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
[RUN] UTF-8/locale conversion and sardem exec test.
This commit is contained in:
parent
e39f2dd53c
commit
98fdf04285
2 changed files with 64 additions and 16 deletions
|
@ -40,15 +40,15 @@ typedef struct
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TB_AUTOHEIGHT = 1 << 0,
|
TB_AUTOHEIGHT = 1 << 0,
|
||||||
TB_AUTOWIDTH = 1 << 1,
|
TB_AUTOWIDTH = 1 << 1,
|
||||||
TB_LEFT = 1 << 16,
|
TB_LEFT = 1 << 16,
|
||||||
TB_RIGHT = 1 << 17,
|
TB_RIGHT = 1 << 17,
|
||||||
TB_CENTER = 1 << 18,
|
TB_CENTER = 1 << 18,
|
||||||
TB_EDITABLE = 1 << 19,
|
TB_EDITABLE = 1 << 19,
|
||||||
TB_MARKUP = 1 << 20,
|
TB_MARKUP = 1 << 20,
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
TB_PASSWORD = 1 << 22,
|
TB_PASSWORD = 1 << 22,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
/**
|
/**
|
||||||
* Name of the history file where previously choosen commands are stored.
|
* Name of the history file where previously choosen commands are stored.
|
||||||
*/
|
*/
|
||||||
#define RUN_CACHE_FILE "rofi-2.runcache"
|
#define RUN_CACHE_FILE "rofi-3.runcache"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal data structure holding the private data of the Run Mode.
|
* The internal data structure holding the private data of the Run Mode.
|
||||||
|
@ -109,11 +109,19 @@ static inline int execsh ( const char *cmd, int run_in_term )
|
||||||
*/
|
*/
|
||||||
static void exec_cmd ( const char *cmd, int run_in_term )
|
static void exec_cmd ( const char *cmd, int run_in_term )
|
||||||
{
|
{
|
||||||
|
GError *error = NULL;
|
||||||
if ( !cmd || !cmd[0] ) {
|
if ( !cmd || !cmd[0] ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
gsize lf_cmd_size = 0;
|
||||||
|
gchar *lf_cmd = g_locale_from_utf8 ( cmd, -1, NULL, &lf_cmd_size, &error );
|
||||||
|
if ( error != NULL ) {
|
||||||
|
fprintf ( stderr, "Failed to convert command to locale encoding: %s\n", error->message );
|
||||||
|
g_error_free ( error );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( execsh ( cmd, run_in_term ) ) {
|
if ( execsh ( lf_cmd, run_in_term ) ) {
|
||||||
/**
|
/**
|
||||||
* This happens in non-critical time (After launching app)
|
* This happens in non-critical time (After launching app)
|
||||||
* It is allowed to be a bit slower.
|
* It is allowed to be a bit slower.
|
||||||
|
@ -124,6 +132,7 @@ static void exec_cmd ( const char *cmd, int run_in_term )
|
||||||
|
|
||||||
g_free ( path );
|
g_free ( path );
|
||||||
}
|
}
|
||||||
|
g_free ( lf_cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,6 +224,7 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
|
||||||
*/
|
*/
|
||||||
static char ** get_apps ( unsigned int *length )
|
static char ** get_apps ( unsigned int *length )
|
||||||
{
|
{
|
||||||
|
GError *error = NULL;
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
unsigned int num_favorites = 0;
|
unsigned int num_favorites = 0;
|
||||||
char *path;
|
char *path;
|
||||||
|
@ -222,7 +232,7 @@ static char ** get_apps ( unsigned int *length )
|
||||||
if ( g_getenv ( "PATH" ) == NULL ) {
|
if ( g_getenv ( "PATH" ) == NULL ) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
TICK_N ( "start" );
|
||||||
path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
|
path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
|
||||||
retv = history_get_list ( path, length );
|
retv = history_get_list ( path, length );
|
||||||
g_free ( path );
|
g_free ( path );
|
||||||
|
@ -231,11 +241,31 @@ static char ** get_apps ( unsigned int *length )
|
||||||
|
|
||||||
path = g_strdup ( getenv ( "PATH" ) );
|
path = g_strdup ( getenv ( "PATH" ) );
|
||||||
|
|
||||||
|
gsize l = 0;
|
||||||
|
gchar *homedir = g_locale_to_utf8 ( g_get_home_dir (), -1, NULL, &l, &error );
|
||||||
|
if ( error != NULL ) {
|
||||||
|
fprintf ( stderr, "Failed to convert homedir to UTF-8: %s\n", error->message );
|
||||||
|
g_error_free ( error );
|
||||||
|
error = NULL;
|
||||||
|
g_free ( homedir );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for ( const char *dirname = strtok ( path, ":" ); dirname != NULL; dirname = strtok ( NULL, ":" ) ) {
|
for ( const char *dirname = strtok ( path, ":" ); dirname != NULL; dirname = strtok ( NULL, ":" ) ) {
|
||||||
DIR *dir = opendir ( dirname );
|
DIR *dir = opendir ( dirname );
|
||||||
|
|
||||||
if ( dir != NULL ) {
|
if ( dir != NULL ) {
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
|
gsize dirn_len = 0;
|
||||||
|
gchar *dirn = g_filename_to_utf8 ( dirname, -1, NULL, &dirn_len, &error );
|
||||||
|
if ( error != NULL ) {
|
||||||
|
fprintf ( stderr, "Failed to convert directory name to UTF-8: %s\n", error->message );
|
||||||
|
g_error_free ( error );
|
||||||
|
error = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int is_homedir = g_str_has_prefix ( dirn, homedir );
|
||||||
|
g_free ( dirn );
|
||||||
|
|
||||||
while ( ( dent = readdir ( dir ) ) != NULL ) {
|
while ( ( dent = readdir ( dir ) ) != NULL ) {
|
||||||
if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
|
if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
|
||||||
|
@ -245,13 +275,29 @@ static char ** get_apps ( unsigned int *length )
|
||||||
if ( dent->d_name[0] == '.' ) {
|
if ( dent->d_name[0] == '.' ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ( is_homedir ) {
|
||||||
|
gchar *fpath = g_build_filename ( dirname, dent->d_name, NULL );
|
||||||
|
gboolean b = g_file_test ( fpath, G_FILE_TEST_IS_EXECUTABLE );
|
||||||
|
g_free ( fpath );
|
||||||
|
if ( !b ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int found = 0;
|
gsize name_len;
|
||||||
|
gchar *name = g_filename_to_utf8 ( dent->d_name, -1, NULL, &name_len, &error );
|
||||||
|
if ( error != NULL ) {
|
||||||
|
fprintf ( stderr, "Failed to convert filename to UTF-8: %s\n", error->message );
|
||||||
|
g_error_free ( error );
|
||||||
|
error = NULL;
|
||||||
|
g_free ( name );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// This is a nice little penalty, but doable? time will tell.
|
// This is a nice little penalty, but doable? time will tell.
|
||||||
// given num_favorites is max 25.
|
// given num_favorites is max 25.
|
||||||
|
int found = 0;
|
||||||
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
|
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
|
||||||
if ( strcasecmp ( dent->d_name, retv[j] ) == 0 ) {
|
if ( g_strcmp0 ( name, retv[j] ) == 0 ) {
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +307,7 @@ static char ** get_apps ( unsigned int *length )
|
||||||
}
|
}
|
||||||
|
|
||||||
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
|
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
|
||||||
retv[( *length )] = g_strdup ( dent->d_name );
|
retv[( *length )] = name;
|
||||||
retv[( *length ) + 1] = NULL;
|
retv[( *length ) + 1] = NULL;
|
||||||
( *length )++;
|
( *length )++;
|
||||||
}
|
}
|
||||||
|
@ -269,6 +315,7 @@ static char ** get_apps ( unsigned int *length )
|
||||||
closedir ( dir );
|
closedir ( dir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
g_free ( homedir );
|
||||||
|
|
||||||
// Get external apps.
|
// Get external apps.
|
||||||
if ( config.run_list_command != NULL && config.run_list_command[0] != '\0' ) {
|
if ( config.run_list_command != NULL && config.run_list_command[0] != '\0' ) {
|
||||||
|
@ -301,6 +348,7 @@ static char ** get_apps ( unsigned int *length )
|
||||||
// Reduce array length;
|
// Reduce array length;
|
||||||
( *length ) -= removed;
|
( *length ) -= removed;
|
||||||
|
|
||||||
|
TICK_N ( "stop" );
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue