mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Sort the executable list.
* Add option to check timing.
This commit is contained in:
parent
b1d5e6a686
commit
8d0bf427e0
2 changed files with 36 additions and 6 deletions
8
Makefile
8
Makefile
|
@ -1,16 +1,20 @@
|
|||
CFLAGS?=-Wall -Wextra -Os -g3
|
||||
CFLAGS?=-Wall -Wextra -Os
|
||||
PREFIX?=$(DESTDIR)/usr
|
||||
BINDIR?=$(PREFIX)/bin
|
||||
MANDIR?=$(PREFIX)/share/man/man1
|
||||
|
||||
# Check deps.
|
||||
ifeq (${DEBUG},1)
|
||||
CFLAGS+=-DTIMING=1
|
||||
LDADD+=-lrt
|
||||
endif
|
||||
|
||||
PKG_CONFIG?=$(shell which pkg-config)
|
||||
ifeq (${PKG_CONFIG},${EMPTY})
|
||||
$(error Failed to find pkg-config. Please install pkg-config)
|
||||
endif
|
||||
|
||||
LDADD?=$(shell ${PKG_CONFIG} --cflags --libs x11 xinerama xft)
|
||||
LDADD+=$(shell ${PKG_CONFIG} --cflags --libs x11 xinerama xft)
|
||||
|
||||
ifeq (${LDADD},${EMPTY})
|
||||
$(error Failed to find the required dependencies: x11, xinerama, xft)
|
||||
|
|
|
@ -71,6 +71,10 @@
|
|||
#define OPACITY "_NET_WM_WINDOW_OPACITY"
|
||||
#define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH"
|
||||
|
||||
#ifdef TIMING
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
static void* allocate( unsigned long bytes )
|
||||
{
|
||||
void *ptr = malloc( bytes );
|
||||
|
@ -994,14 +998,23 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time )
|
|||
|
||||
#define FORK 1
|
||||
#define NOFORK 2
|
||||
|
||||
int sort_func ( const void *a, const void *b )
|
||||
{
|
||||
const char *astr = *( const char * const * )a;
|
||||
const char *bstr = *( const char * const * )b;
|
||||
return strcasecmp( astr,bstr );
|
||||
}
|
||||
static char ** get_apps ( )
|
||||
{
|
||||
#ifdef TIMING
|
||||
struct timespec start, stop;
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif
|
||||
if ( getenv( "PATH" ) == NULL ) return NULL;
|
||||
|
||||
char *path = strdup( getenv( "PATH" ) );
|
||||
char **retv = NULL;
|
||||
int index = 0;
|
||||
unsigned int index = 0;
|
||||
|
||||
for ( const char *dirname = strtok( path, ":" ); dirname != NULL; dirname = strtok( NULL, ":" ) ) {
|
||||
DIR *dir = opendir( dirname );
|
||||
|
@ -1010,7 +1023,11 @@ static char ** get_apps ( )
|
|||
struct dirent *dent;
|
||||
|
||||
while ( ( dent=readdir( dir ) )!=NULL ) {
|
||||
if ( dent->d_name[0] == '.' ) continue;
|
||||
if ( dent->d_type != DT_REG &&
|
||||
dent->d_type != DT_LNK &&
|
||||
dent->d_type != DT_UNKNOWN ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
retv = realloc( retv, ( index+2 )*sizeof( char* ) );
|
||||
retv[index] = strdup( dent->d_name );
|
||||
|
@ -1021,8 +1038,17 @@ static char ** get_apps ( )
|
|||
closedir( dir );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check this is still fast enough. (takes 1ms on laptop.)
|
||||
qsort( retv,index, sizeof( char* ), sort_func );
|
||||
free( path );
|
||||
#ifdef TIMING
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
if(stop.tv_sec != start.tv_sec) {
|
||||
stop.tv_nsec += (stop.tv_sec-start.tv_sec)*1e9;
|
||||
}
|
||||
long diff = stop.tv_nsec-start.tv_nsec;
|
||||
printf("Time elapsed: %ld us\n", diff/1000);
|
||||
#endif
|
||||
return retv;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue