mirror of
https://github.com/davatorium/rofi.git
synced 2025-03-03 16:05:20 -05:00
More cleanups to make more extendable
This commit is contained in:
parent
5e72018497
commit
3a44951e9f
3 changed files with 58 additions and 58 deletions
|
@ -15,15 +15,10 @@ typedef enum {
|
|||
} SwitcherMode;
|
||||
|
||||
|
||||
// window lists
|
||||
typedef struct {
|
||||
Window *array;
|
||||
void **data;
|
||||
int len;
|
||||
} winlist;
|
||||
|
||||
typedef int (*menu_match_cb)(char **tokens, const char *input, int index, void *data);
|
||||
int menu( char **lines, char **input, char *prompt,
|
||||
int selected, Time *time, int *shift, winlist *ids );
|
||||
int selected, Time *time, int *shift, menu_match_cb mmc, void *mmc_data);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,15 +26,9 @@
|
|||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xmd.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
@ -45,6 +39,9 @@
|
|||
|
||||
#include "simpleswitcher.h"
|
||||
#include "run-dialog.h"
|
||||
#ifdef TIMING
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
extern char *config_terminal_emulator;
|
||||
|
||||
|
@ -228,6 +225,17 @@ static char ** get_apps ( )
|
|||
return retv;
|
||||
}
|
||||
|
||||
int token_match ( char **tokens, const char *input,
|
||||
__attribute__( ( unused ) )int index,
|
||||
__attribute__( ( unused ) )void *data)
|
||||
{
|
||||
int match = 1;
|
||||
// Do a tokenized match.
|
||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
||||
match = ( strcasestr( input, tokens[j] ) != NULL );
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
SwitcherMode run_switcher_dialog ( char **input )
|
||||
{
|
||||
|
@ -242,7 +250,7 @@ SwitcherMode run_switcher_dialog ( char **input )
|
|||
}
|
||||
|
||||
int shift=0;
|
||||
int n = menu( cmd_list, input, "$ ", 0, NULL, &shift,NULL );
|
||||
int n = menu( cmd_list, input, "$ ", 0, NULL, &shift,token_match, NULL);
|
||||
|
||||
if ( n == -2 ) {
|
||||
retv = WINDOW_SWITCHER;
|
||||
|
|
|
@ -72,9 +72,6 @@
|
|||
#define TERMINAL_DEFAULT "x-terminal-emulator"
|
||||
char *config_terminal_emulator;
|
||||
|
||||
#ifdef TIMING
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -311,6 +308,13 @@ typedef struct {
|
|||
} workarea;
|
||||
|
||||
|
||||
// window lists
|
||||
typedef struct {
|
||||
Window *array;
|
||||
void **data;
|
||||
int len;
|
||||
} winlist;
|
||||
|
||||
winlist *cache_client;
|
||||
winlist *cache_xattr;
|
||||
|
||||
|
@ -773,8 +777,35 @@ static int calculate_common_prefix( char **filtered, int max_lines )
|
|||
return length_prefix;
|
||||
}
|
||||
|
||||
int menu( char **lines, char **input, char *prompt, int selected, Time *time, int *shift, winlist
|
||||
*ids )
|
||||
|
||||
int window_match ( char **tokens, const char *input, int index, void *data)
|
||||
{
|
||||
int match =1;
|
||||
winlist *ids = (winlist *)data;
|
||||
client *c = window_client(ids->array[index]);
|
||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
||||
int test = 0;
|
||||
|
||||
if ( !test && c->title[0] != '\0' )
|
||||
test = ( strcasestr( c->title, tokens[j] ) != NULL );
|
||||
|
||||
if ( !test && c->class[0] != '\0' )
|
||||
test = ( strcasestr( c->class, tokens[j] ) != NULL );
|
||||
|
||||
if ( !test && c->role[0] != '\0' )
|
||||
test = ( strcasestr( c->role, tokens[j] ) != NULL );
|
||||
|
||||
if ( !test && c->name[0] != '\0' )
|
||||
test = ( strcasestr( c->name, tokens[j] ) != NULL );
|
||||
|
||||
if ( test == 0 ) match = 0;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
int menu( char **lines, char **input, char *prompt, int selected, Time *time, int *shift,
|
||||
menu_match_cb mmc, void *mmc_data)
|
||||
{
|
||||
int line = -1, i, j, chosen = 0;
|
||||
workarea mon;
|
||||
|
@ -851,12 +882,7 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time, in
|
|||
|
||||
// input changed
|
||||
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
||||
int match = 1;
|
||||
|
||||
// Do a tokenized match.
|
||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
||||
match = ( strcasestr( lines[i], tokens[j] ) != NULL );
|
||||
}
|
||||
int match = mmc(tokens,lines[i], i, mmc_data);
|
||||
|
||||
// If each token was matched, add it to list.
|
||||
if ( match ) {
|
||||
|
@ -920,36 +946,7 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time, in
|
|||
|
||||
// input changed
|
||||
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
||||
int match = 1;
|
||||
|
||||
// If ids provided match on that.
|
||||
if ( ids != NULL ) {
|
||||
client *c = window_client( ids->array[i] );
|
||||
|
||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
||||
int test = 0;
|
||||
|
||||
if ( !test && c->title[0] != '\0' )
|
||||
test = ( strcasestr( c->title, tokens[j] ) != NULL );
|
||||
|
||||
if ( !test && c->class[0] != '\0' )
|
||||
test = ( strcasestr( c->class, tokens[j] ) != NULL );
|
||||
|
||||
if ( !test && c->role[0] != '\0' )
|
||||
test = ( strcasestr( c->role, tokens[j] ) != NULL );
|
||||
|
||||
if ( !test && c->name[0] != '\0' )
|
||||
test = ( strcasestr( c->name, tokens[j] ) != NULL );
|
||||
|
||||
if ( test == 0 ) match = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Do a tokenized match.
|
||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
||||
match = ( strcasestr( lines[i], tokens[j] ) != NULL );
|
||||
}
|
||||
}
|
||||
int match = mmc(tokens,lines[i], i, mmc_data);
|
||||
|
||||
// If each token was matched, add it to list.
|
||||
if ( match ) {
|
||||
|
@ -1112,7 +1109,7 @@ SwitcherMode run_switcher_window ( char **input )
|
|||
}
|
||||
}
|
||||
Time time;
|
||||
int n = menu( list, input, "> ", 0, &time, NULL,ids );
|
||||
int n = menu( list, input, "> ", 0, &time, NULL,window_match, ids );
|
||||
|
||||
if ( n == -2 ) {
|
||||
retv = RUN_DIALOG;
|
||||
|
|
Loading…
Add table
Reference in a new issue