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;
|
} 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 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
|
#define _GNU_SOURCE
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <X11/X.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 <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -45,6 +39,9 @@
|
||||||
|
|
||||||
#include "simpleswitcher.h"
|
#include "simpleswitcher.h"
|
||||||
#include "run-dialog.h"
|
#include "run-dialog.h"
|
||||||
|
#ifdef TIMING
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
extern char *config_terminal_emulator;
|
extern char *config_terminal_emulator;
|
||||||
|
|
||||||
|
@ -228,6 +225,17 @@ static char ** get_apps ( )
|
||||||
return retv;
|
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 )
|
SwitcherMode run_switcher_dialog ( char **input )
|
||||||
{
|
{
|
||||||
|
@ -242,7 +250,7 @@ SwitcherMode run_switcher_dialog ( char **input )
|
||||||
}
|
}
|
||||||
|
|
||||||
int shift=0;
|
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 ) {
|
if ( n == -2 ) {
|
||||||
retv = WINDOW_SWITCHER;
|
retv = WINDOW_SWITCHER;
|
||||||
|
|
|
@ -72,9 +72,6 @@
|
||||||
#define TERMINAL_DEFAULT "x-terminal-emulator"
|
#define TERMINAL_DEFAULT "x-terminal-emulator"
|
||||||
char *config_terminal_emulator;
|
char *config_terminal_emulator;
|
||||||
|
|
||||||
#ifdef TIMING
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -311,6 +308,13 @@ typedef struct {
|
||||||
} workarea;
|
} workarea;
|
||||||
|
|
||||||
|
|
||||||
|
// window lists
|
||||||
|
typedef struct {
|
||||||
|
Window *array;
|
||||||
|
void **data;
|
||||||
|
int len;
|
||||||
|
} winlist;
|
||||||
|
|
||||||
winlist *cache_client;
|
winlist *cache_client;
|
||||||
winlist *cache_xattr;
|
winlist *cache_xattr;
|
||||||
|
|
||||||
|
@ -773,8 +777,35 @@ static int calculate_common_prefix( char **filtered, int max_lines )
|
||||||
return length_prefix;
|
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;
|
int line = -1, i, j, chosen = 0;
|
||||||
workarea mon;
|
workarea mon;
|
||||||
|
@ -851,12 +882,7 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time, in
|
||||||
|
|
||||||
// input changed
|
// input changed
|
||||||
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
||||||
int match = 1;
|
int match = mmc(tokens,lines[i], i, mmc_data);
|
||||||
|
|
||||||
// Do a tokenized match.
|
|
||||||
if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
|
|
||||||
match = ( strcasestr( lines[i], tokens[j] ) != NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
// If each token was matched, add it to list.
|
// If each token was matched, add it to list.
|
||||||
if ( match ) {
|
if ( match ) {
|
||||||
|
@ -920,36 +946,7 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time, in
|
||||||
|
|
||||||
// input changed
|
// input changed
|
||||||
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
for ( i = 0, j = 0; i < num_lines && j < max_lines; i++ ) {
|
||||||
int match = 1;
|
int match = mmc(tokens,lines[i], i, mmc_data);
|
||||||
|
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If each token was matched, add it to list.
|
// If each token was matched, add it to list.
|
||||||
if ( match ) {
|
if ( match ) {
|
||||||
|
@ -1112,7 +1109,7 @@ SwitcherMode run_switcher_window ( char **input )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Time time;
|
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 ) {
|
if ( n == -2 ) {
|
||||||
retv = RUN_DIALOG;
|
retv = RUN_DIALOG;
|
||||||
|
|
Loading…
Add table
Reference in a new issue