mirror of
https://github.com/davatorium/rofi.git
synced 2024-12-23 14:25:48 -05:00
More commenting.
Code Comment Comment % Blank Total File ------ --------- --------- --------- --------- ----------------- 36 69 65.7% 2 107 config.c 66 31 32.0% 14 111 dmenu-dialog.c 185 52 21.9% 19 256 helper.c 179 66 26.9% 27 272 history.c 1896 325 14.6% 345 2566 rofi.c 197 45 18.6% 42 284 run-dialog.c 144 31 17.7% 24 199 script-dialog.c 171 42 19.7% 31 244 ssh-dialog.c 350 69 16.5% 84 503 textbox.c 151 37 19.7% 27 215 xrmoptions.c 26 0 0.0% 5 31 helper-test.c 65 6 8.5% 35 106 history-test.c 109 5 4.4% 22 136 textbox-test.c 34 33 49.3% 24 91 config.h 5 10 66.7% 4 19 dmenu-dialog.h 11 70 86.4% 10 91 helper.h 9 46 83.6% 8 63 history.h 83 128 60.7% 17 228 rofi.h 4 8 66.7% 2 14 run-dialog.h 11 26 70.3% 5 42 script-dialog.h 4 8 66.7% 2 14 ssh-dialog.h 64 142 68.9% 31 237 textbox.h 6 13 68.4% 4 23 xrmoptions.h
This commit is contained in:
parent
471c0c5df7
commit
2c9f33a1bd
4 changed files with 65 additions and 31 deletions
|
@ -66,12 +66,12 @@ Settings config = {
|
|||
/** Command executed when running application in terminal */
|
||||
.run_shell_command = "{terminal} -e {cmd}",
|
||||
/** Key binding */
|
||||
.window_key = "F12",
|
||||
.window_key = "F12",
|
||||
/** Key to open run dialog */
|
||||
.run_key = "mod1+F2",
|
||||
.run_key = "mod1+F2",
|
||||
/** Key to open ssh dialog */
|
||||
.ssh_key = "mod1+F3",
|
||||
/**
|
||||
.ssh_key = "mod1+F3",
|
||||
/**
|
||||
* Location of the window.
|
||||
* Enumeration indicating location or gravity of window.
|
||||
*
|
||||
|
@ -86,22 +86,22 @@ Settings config = {
|
|||
/** Mode of window, list (Vertical) or dmenu like (Horizontal) */
|
||||
.hmode = FALSE,
|
||||
/** Padding between elements */
|
||||
.padding = 5,
|
||||
.padding = 5,
|
||||
/** Y offset */
|
||||
.y_offset = 0,
|
||||
.y_offset = 0,
|
||||
/** X offset */
|
||||
.x_offset = 0,
|
||||
.x_offset = 0,
|
||||
/** Always should config.menu_lines lines, even if less lines are available */
|
||||
.fixed_num_lines = FALSE,
|
||||
.fixed_num_lines = FALSE,
|
||||
/** Do not use history */
|
||||
.disable_history = FALSE,
|
||||
.disable_history = FALSE,
|
||||
/** Use levenshtein sorting when matching */
|
||||
.levenshtein_sort = FALSE,
|
||||
.levenshtein_sort = FALSE,
|
||||
/** Separator to use for dmenu mode */
|
||||
.separator = '\n',
|
||||
.separator = '\n',
|
||||
/** Height of an element in #chars */
|
||||
.element_height = 1,
|
||||
.element_height = 1,
|
||||
/** Sidebar mode, show the switchers */
|
||||
.sidebar_mode = FALSE
|
||||
.sidebar_mode = FALSE
|
||||
};
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ typedef enum
|
|||
|
||||
/**
|
||||
* @param tokens List of (input) tokens to match.
|
||||
* @param input The entry to match against.
|
||||
* @param input The entry to match against.
|
||||
* @param index The current selected index.
|
||||
* @param data User data.
|
||||
*
|
||||
|
@ -204,9 +204,9 @@ typedef struct _Settings
|
|||
extern Settings config;
|
||||
|
||||
/**
|
||||
* @params tokens
|
||||
* @params tokens
|
||||
* @param tokens List of (input) tokens to match.
|
||||
* @param input The entry to match against.
|
||||
* @param input The entry to match against.
|
||||
* @param index The current selected index.
|
||||
* @param data User data.
|
||||
*
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
#include <helper.h>
|
||||
#include <config.h>
|
||||
|
||||
|
||||
/**
|
||||
* `fgets` implementation with custom separator.
|
||||
*/
|
||||
char* fgets_s ( char* s, int n, FILE *iop, char sep )
|
||||
{
|
||||
// Map these to registers.
|
||||
register int c;
|
||||
register char* cs;
|
||||
cs = s;
|
||||
|
||||
// read until EOF or buffer is full.
|
||||
while ( --n > 0 && ( c = getc ( iop ) ) != EOF ) {
|
||||
// put the input char into the current pointer position, then increment it
|
||||
// if a newline entered, break
|
||||
|
@ -22,28 +25,40 @@ char* fgets_s ( char* s, int n, FILE *iop, char sep )
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Always, 0 terminate the buffer.
|
||||
*cs = '\0';
|
||||
// if last read was end of file and current index is start, we are done:
|
||||
// Return NULL.
|
||||
return ( c == EOF && cs == s ) ? NULL : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the entries
|
||||
* @param info The Match informati on.
|
||||
* @param res The string being generated.
|
||||
* @param data User data
|
||||
*
|
||||
* Replace the entries. This function gets called by g_regex_replace_eval.
|
||||
*
|
||||
* @returns TRUE to stop replacement, FALSE to continue
|
||||
*/
|
||||
static gboolean helper_eval_cb ( const GMatchInfo *info,
|
||||
GString *res,
|
||||
gpointer data )
|
||||
{
|
||||
gchar *match;
|
||||
gchar *r;
|
||||
|
||||
gchar *match, *r;
|
||||
// Get the match
|
||||
match = g_match_info_fetch ( info, 0 );
|
||||
r = g_hash_table_lookup ( (GHashTable *) data, match );
|
||||
if ( r != NULL ) {
|
||||
g_string_append ( res, r );
|
||||
if ( match != NULL ) {
|
||||
// Lookup the match, so we can replace it.
|
||||
r = g_hash_table_lookup ( (GHashTable *) data, match );
|
||||
if ( r != NULL ) {
|
||||
// Append the replacement to the string.
|
||||
g_string_append ( res, r );
|
||||
}
|
||||
// Free match.
|
||||
g_free ( match );
|
||||
}
|
||||
|
||||
// Continue replacement.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -52,9 +67,10 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... )
|
|||
GError *error = NULL;
|
||||
GHashTable *h;
|
||||
h = g_hash_table_new ( g_str_hash, g_str_equal );
|
||||
// By default, we insert terminal and ssh-client
|
||||
g_hash_table_insert ( h, "{terminal}", config.terminal_emulator );
|
||||
g_hash_table_insert ( h, "{ssh-client}", config.ssh_client );
|
||||
// Add list.
|
||||
// Add list from variable arguments.
|
||||
va_list ap;
|
||||
va_start ( ap, length );
|
||||
while ( 1 ) {
|
||||
|
@ -76,13 +92,17 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... )
|
|||
string, -1,
|
||||
0, 0, helper_eval_cb, h,
|
||||
NULL );
|
||||
// Free regex.
|
||||
g_regex_unref ( reg );
|
||||
// Destroy key-value storage.
|
||||
g_hash_table_destroy ( h );
|
||||
// Parse the string into shell arguments.
|
||||
if ( g_shell_parse_argv ( res, length, output, &error ) ) {
|
||||
g_free ( res );
|
||||
return TRUE;
|
||||
}
|
||||
g_free ( res );
|
||||
// Throw error if shell parsing fails.
|
||||
if ( error ) {
|
||||
char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string,
|
||||
error->message );
|
||||
|
@ -181,34 +201,45 @@ int find_arg_char ( const int argc, char * const argv[], const char * const key,
|
|||
|
||||
if ( val != NULL && i > 0 && i < ( argc - 1 ) ) {
|
||||
int len = strlen ( argv[i + 1] );
|
||||
// If the length is 1, it is not escaped.
|
||||
if ( len == 1 ) {
|
||||
*val = argv[i + 1][0];
|
||||
}
|
||||
// If the length is 2 and the first character is '\', we unescape it.
|
||||
else if ( len == 2 && argv[i + 1][0] == '\\' ) {
|
||||
// New line
|
||||
if ( argv[i + 1][1] == 'n' ) {
|
||||
*val = '\n';
|
||||
}
|
||||
// Bell
|
||||
else if ( argv[i + 1][1] == 'a' ) {
|
||||
*val = '\a';
|
||||
}
|
||||
// Backspace
|
||||
else if ( argv[i + 1][1] == 'b' ) {
|
||||
*val = '\b';
|
||||
}
|
||||
// Tab
|
||||
else if ( argv[i + 1][1] == 't' ) {
|
||||
*val = '\t';
|
||||
}
|
||||
// Vertical tab
|
||||
else if ( argv[i + 1][1] == 'v' ) {
|
||||
*val = '\v';
|
||||
}
|
||||
// Form feed
|
||||
else if ( argv[i + 1][1] == 'f' ) {
|
||||
*val = '\f';
|
||||
}
|
||||
// Carriage return
|
||||
else if ( argv[i + 1][1] == 'r' ) {
|
||||
*val = '\r';
|
||||
}
|
||||
// Forward slash
|
||||
else if ( argv[i + 1][1] == '\\' ) {
|
||||
*val = '\\';
|
||||
}
|
||||
// Otherwise it is not valid and throw error
|
||||
else {
|
||||
fprintf ( stderr, "Failed to parse command-line argument." );
|
||||
exit ( 1 );
|
||||
|
|
|
@ -2539,7 +2539,9 @@ int main ( int argc, char *argv[] )
|
|||
sigaction ( SIGHUP, &hup_action, NULL );
|
||||
|
||||
|
||||
// Main loop
|
||||
// Application Main loop.
|
||||
// This listens in the background for any events on the Xserver
|
||||
// catching global key presses.
|
||||
for (;; ) {
|
||||
XEvent ev;
|
||||
// caches only live for a single event
|
||||
|
@ -2548,11 +2550,12 @@ int main ( int argc, char *argv[] )
|
|||
|
||||
// block and wait for something
|
||||
XNextEvent ( display, &ev );
|
||||
|
||||
// If we get an event that does not belong to a window:
|
||||
// Ignore it.
|
||||
if ( ev.xany.window == None ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If keypress, handle it.
|
||||
if ( ev.type == KeyPress ) {
|
||||
handle_keypress ( &ev );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue