From 781ca03f02b7f0002ea7fba43c2de2f43bf644cc Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 2 Dec 2014 09:09:20 +0100 Subject: [PATCH] Small moving to helper. --- include/helper.h | 15 ++++++++++++++ include/rofi.h | 15 -------------- source/helper.c | 22 ++++++++++++++++++++ source/rofi.c | 54 ++++++++++++------------------------------------ 4 files changed, 50 insertions(+), 56 deletions(-) diff --git a/include/helper.h b/include/helper.h index cc996e64..5e615f32 100644 --- a/include/helper.h +++ b/include/helper.h @@ -88,4 +88,19 @@ int find_arg_str ( const int argc, char * const argv[], const char * const key, */ int find_arg ( const int argc, char * const argv[], const char * const key ); +/** + * @params tokens + * @param tokens List of (input) tokens to match. + * @param input The entry to match against. + * @param index The current selected index. + * @param data User data. + * + * Tokenized match, match tokens to line input. + * + * @returns 1 when matches, 0 otherwise + */ +int token_match ( char **tokens, const char *input, + __attribute__( ( unused ) ) int index, + __attribute__( ( unused ) ) void *data ); + #endif // __HELPER_H__ diff --git a/include/rofi.h b/include/rofi.h index 57f4899e..0ffe53f6 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -203,21 +203,6 @@ typedef struct _Settings /** Global Settings structure. */ extern Settings config; -/** - * @params tokens - * @param tokens List of (input) tokens to match. - * @param input The entry to match against. - * @param index The current selected index. - * @param data User data. - * - * Tokenized match, match tokens to line input. - * - * @returns 1 when matches, 0 otherwise - */ -int token_match ( char **tokens, const char *input, - __attribute__( ( unused ) ) int index, - __attribute__( ( unused ) ) void *data ); - /** * @param msg The error message to show. * diff --git a/source/helper.c b/source/helper.c index 9702ea4b..0c23fcdd 100644 --- a/source/helper.c +++ b/source/helper.c @@ -254,3 +254,25 @@ int find_arg_char ( const int argc, char * const argv[], const char * const key, return FALSE; } +/** + * Shared 'token_match' function. + * Matches tokenized. + */ +int token_match ( char **tokens, const char *input, + __attribute__( ( unused ) ) int index, + __attribute__( ( unused ) ) void *data ) +{ + int match = 1; + + char *lowerc = g_utf8_casefold ( input, -1 ); + char *compk = g_utf8_collate_key ( lowerc, -1 ); + // Do a tokenized match. + if ( tokens ) { + for ( int j = 0; match && tokens[j]; j++ ) { + match = ( strstr ( compk, tokens[j] ) != NULL ); + } + } + g_free ( lowerc ); + g_free ( compk ); + return match; +} diff --git a/source/rofi.c b/source/rofi.c index 86034bde..48de84c8 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -115,30 +115,6 @@ static int switcher_get ( const char *name ) return -1; } -/** - * Shared 'token_match' function. - * Matches tokenized. - */ -int token_match ( char **tokens, const char *input, - __attribute__( ( unused ) ) int index, - __attribute__( ( unused ) ) void *data ) -{ - int match = 1; - - char *lowerc = g_utf8_casefold ( input, -1 ); - char *compk = g_utf8_collate_key ( lowerc, -1 ); - // Do a tokenized match. - if ( tokens ) { - for ( int j = 0; match && tokens[j]; j++ ) { - match = ( strstr ( compk, tokens[j] ) != NULL ); - } - } - g_free ( lowerc ); - g_free ( compk ); - return match; -} - - #ifdef HAVE_I3_IPC_H // Focus window on HAVE_I3_IPC_H window manager. @@ -355,8 +331,15 @@ static unsigned int color_get ( Display *display, const char *const name ) return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None; } -// find mouse pointer location -int pointer_get ( Window root, int *x, int *y ) +/** + * @param x The x position of the mouse [out] + * @param y The y position of the mouse [out] + * + * find mouse pointer location + * + * @returns 1 when found + */ +static int pointer_get ( Display *display, Window root, int *x, int *y ) { *x = 0; *y = 0; @@ -388,13 +371,13 @@ static int take_keyboard ( Window w ) return 0; } -void release_keyboard () +static void release_keyboard () { XUngrabKeyboard ( display, CurrentTime ); } // XGetWindowAttributes with caching -XWindowAttributes* window_get_attributes ( Window w ) +static XWindowAttributes* window_get_attributes ( Window w ) { int idx = winlist_find ( cache_xattr, w ); @@ -414,19 +397,8 @@ XWindowAttributes* window_get_attributes ( Window w ) } // retrieve a property of any type from a window -int window_get_prop ( Window w, Atom prop, Atom *type, int *items, void *buffer, unsigned int bytes ) +static int window_get_prop ( Window w, Atom prop, Atom *type, int *items, void *buffer, unsigned int bytes ) { - Atom _type; - - if ( !type ) { - type = &_type; - } - - int _items; - - if ( !items ) { - items = &_items; - } int format; unsigned long nitems, nbytes; @@ -576,7 +548,7 @@ void monitor_active ( workarea *mon ) } } } - if ( pointer_get ( root, &x, &y ) ) { + if ( pointer_get ( display, root, &x, &y ) ) { monitor_dimensions ( screen, x, y, mon ); return; }