mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Update comments, replace printf/build_filename
This commit is contained in:
parent
70dd6e2cef
commit
c512f81c9c
3 changed files with 72 additions and 24 deletions
|
@ -1,5 +1,17 @@
|
||||||
#ifndef __RUN_DIALOG_H__
|
#ifndef ROFI_DIALOG_RUN_H
|
||||||
#define __RUN_DIALOG_H__
|
#define ROFI_DIALOG_RUN_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup RUNMode Run
|
||||||
|
*
|
||||||
|
* This mode uses the following options from the #config object:
|
||||||
|
* * #_Settings::run_command
|
||||||
|
* * #_Settings::run_shell_command
|
||||||
|
* * #_Settings::run_list_command
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
extern Mode run_mode;
|
extern Mode run_mode;
|
||||||
#endif
|
|
||||||
|
/*@}*/
|
||||||
|
#endif // DIALOG_RUN_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __SSH_DIALOG_H__
|
#ifndef ROFI_DIALOG_SSH_H
|
||||||
#define __SSH_DIALOG_H__
|
#define ROFI_DIALOG_SSH_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup SSHMode SSH
|
* @defgroup SSHMode SSH
|
||||||
|
@ -21,4 +21,4 @@
|
||||||
*/
|
*/
|
||||||
extern Mode ssh_mode;
|
extern Mode ssh_mode;
|
||||||
/*@}*/
|
/*@}*/
|
||||||
#endif
|
#endif // ROFI_DIALOG_SSH_H
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* rofi
|
* rofi
|
||||||
*
|
*
|
||||||
* MIT/X11 License
|
* MIT/X11 License
|
||||||
|
@ -24,6 +24,11 @@
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \ingroup RUNMode
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -43,8 +48,30 @@
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "dialogs/run.h"
|
#include "dialogs/run.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the history file where previously choosen commands are stored.
|
||||||
|
*/
|
||||||
#define RUN_CACHE_FILE "rofi-2.runcache"
|
#define RUN_CACHE_FILE "rofi-2.runcache"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The internal data structure holding the private data of the Run Mode.
|
||||||
|
*/
|
||||||
|
typedef struct _RunModePrivateData
|
||||||
|
{
|
||||||
|
/** list of available commands. */
|
||||||
|
char **cmd_list;
|
||||||
|
/** Length of the #cmd_list. */
|
||||||
|
unsigned int cmd_list_length;
|
||||||
|
} RunModePrivateData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The cmd to execute
|
||||||
|
* @param run_in_term Indicate if command should be run in a terminal
|
||||||
|
*
|
||||||
|
* Execute command.
|
||||||
|
*
|
||||||
|
* @returns FALSE On failure, TRUE on success
|
||||||
|
*/
|
||||||
static inline int execsh ( const char *cmd, int run_in_term )
|
static inline int execsh ( const char *cmd, int run_in_term )
|
||||||
{
|
{
|
||||||
int retv = TRUE;
|
int retv = TRUE;
|
||||||
|
@ -72,7 +99,12 @@ static inline int execsh ( const char *cmd, int run_in_term )
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute sub-process
|
/**
|
||||||
|
* @param cmd The cmd to execute
|
||||||
|
* @param run_in_term Indicate if command should be run in a terminal
|
||||||
|
*
|
||||||
|
* Execute command and add to history.
|
||||||
|
*/
|
||||||
static void exec_cmd ( const char *cmd, int run_in_term )
|
static void exec_cmd ( const char *cmd, int run_in_term )
|
||||||
{
|
{
|
||||||
if ( !cmd || !cmd[0] ) {
|
if ( !cmd || !cmd[0] ) {
|
||||||
|
@ -84,26 +116,36 @@ static void exec_cmd ( const char *cmd, int 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.
|
||||||
*/
|
*/
|
||||||
char *path = g_strdup_printf ( "%s/%s", cache_dir, RUN_CACHE_FILE );
|
char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
|
||||||
|
|
||||||
history_set ( path, cmd );
|
history_set ( path, cmd );
|
||||||
|
|
||||||
g_free ( path );
|
g_free ( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// execute sub-process
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command to remove from history
|
||||||
|
*
|
||||||
|
* Remove command from history.
|
||||||
|
*/
|
||||||
static void delete_entry ( const char *cmd )
|
static void delete_entry ( const char *cmd )
|
||||||
{
|
{
|
||||||
/**
|
char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
|
||||||
* This happens in non-critical time (After launching app)
|
|
||||||
* It is allowed to be a bit slower.
|
|
||||||
*/
|
|
||||||
char *path = g_strdup_printf ( "%s/%s", cache_dir, RUN_CACHE_FILE );
|
|
||||||
|
|
||||||
history_remove ( path, cmd );
|
history_remove ( path, cmd );
|
||||||
|
|
||||||
g_free ( path );
|
g_free ( path );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param a The First key to compare
|
||||||
|
* @param b The second key to compare
|
||||||
|
*
|
||||||
|
* Function used for sorting.
|
||||||
|
*
|
||||||
|
* @returns returns less then, equal to and greater than zero is a is less than, is a match or greater than b.
|
||||||
|
*/
|
||||||
static int sort_func ( const void *a, const void *b, void *data __attribute__( ( unused ) ) )
|
static int sort_func ( const void *a, const void *b, void *data __attribute__( ( unused ) ) )
|
||||||
{
|
{
|
||||||
const char *astr = *( const char * const * ) a;
|
const char *astr = *( const char * const * ) a;
|
||||||
|
@ -118,7 +160,7 @@ static int sort_func ( const void *a, const void *b, void *data __attribute__( (
|
||||||
else if ( bstr == NULL ) {
|
else if ( bstr == NULL ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return strcasecmp ( astr, bstr );
|
return g_ascii_strcasecmp ( astr, bstr );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,7 +221,7 @@ static char ** get_apps ( unsigned int *length )
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = g_strdup_printf ( "%s/%s", cache_dir, RUN_CACHE_FILE );
|
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 );
|
||||||
// Keep track of how many where loaded as favorite.
|
// Keep track of how many where loaded as favorite.
|
||||||
|
@ -260,13 +302,6 @@ static char ** get_apps ( unsigned int *length )
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _RunModePrivateData
|
|
||||||
{
|
|
||||||
unsigned int id;
|
|
||||||
char **cmd_list;
|
|
||||||
unsigned int cmd_list_length;
|
|
||||||
} RunModePrivateData;
|
|
||||||
|
|
||||||
static void run_mode_init ( Mode *sw )
|
static void run_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
|
@ -359,3 +394,4 @@ Mode run_mode =
|
||||||
.private_data = NULL,
|
.private_data = NULL,
|
||||||
.free = NULL
|
.free = NULL
|
||||||
};
|
};
|
||||||
|
/*@}*/
|
||||||
|
|
Loading…
Reference in a new issue