mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Small hack to use it as a launcher (with tab complete)
This commit is contained in:
parent
67dea02a6a
commit
e134029af6
3 changed files with 141 additions and 66 deletions
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
CFLAGS?=-Wall -Wextra -Os
|
||||
CFLAGS?=-Wall -Wextra -Os -g3
|
||||
PREFIX?=$(DESTDIR)/usr
|
||||
BINDIR?=$(PREFIX)/bin
|
||||
MANDIR?=$(PREFIX)/share/man/man1
|
||||
|
|
|
@ -745,6 +745,7 @@ void menu_draw( textbox *text, textbox **boxes, int max_lines, int selected, cha
|
|||
i == selected ? config_menu_hlbg: config_menu_bg );
|
||||
textbox_text( boxes[i], filtered[i] );
|
||||
}
|
||||
|
||||
textbox_draw( boxes[i] );
|
||||
}
|
||||
}
|
||||
|
@ -989,6 +990,56 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time )
|
|||
#define FORK 1
|
||||
#define NOFORK 2
|
||||
|
||||
static char ** get_apps ( )
|
||||
{
|
||||
|
||||
int fd[2];
|
||||
pid_t childpid;
|
||||
|
||||
int retp = pipe( fd );
|
||||
|
||||
if ( retp != 0 ) {
|
||||
perror( "Pipe" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if ( ( childpid = fork() ) == -1 ) {
|
||||
perror( "fork" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if ( childpid == 0 ) {
|
||||
close( fd[0] );
|
||||
close( 1 );
|
||||
/* Child process closes up output side of pipe */
|
||||
dup2( fd[1],1 );
|
||||
char command[256];
|
||||
snprintf( command,256, "compgen -c" );
|
||||
int retv = execlp ( "bash", "bash", "-c" , command, NULL );
|
||||
close( fd[1] );
|
||||
exit( retv );
|
||||
} else {
|
||||
/* Parent process closes up input side of pipe */
|
||||
close( fd[1] );
|
||||
}
|
||||
|
||||
char **retv = NULL;
|
||||
int index = 0;
|
||||
char buffer[1024];
|
||||
FILE *file = fdopen( fd[0],"r" );
|
||||
|
||||
while ( fgets( buffer, 1024, file ) != NULL ) {
|
||||
retv = realloc( retv, ( index+2 )*sizeof( char* ) );
|
||||
retv[index] = strdup( buffer );
|
||||
retv[index][strlen( buffer )-1] = '\0';
|
||||
retv[index+1] = NULL;
|
||||
index++;
|
||||
}
|
||||
|
||||
close( fd[0] );
|
||||
return retv;
|
||||
}
|
||||
|
||||
void run_switcher( int fmode )
|
||||
{
|
||||
// TODO: this whole function is messy. build a nicer solution
|
||||
|
@ -1092,7 +1143,18 @@ void run_switcher( int fmode )
|
|||
|
||||
// act as a launcher
|
||||
if ( input ) {
|
||||
exec_cmd( input );
|
||||
char **cmd_list = get_apps( );
|
||||
int n = menu( cmd_list, &input, "$ ", 0, &time );
|
||||
|
||||
if ( n >=0 && cmd_list[n] != NULL ) {
|
||||
exec_cmd( cmd_list[n] );
|
||||
}
|
||||
|
||||
for ( i=0; cmd_list[i] != NULL; i++ ) {
|
||||
free( cmd_list[i] );
|
||||
}
|
||||
|
||||
free( cmd_list );
|
||||
}
|
||||
|
||||
for ( i = 0; i < lines; i++ )
|
||||
|
|
15
textbox.c
15
textbox.c
|
@ -90,7 +90,18 @@ textbox* textbox_create( Window parent, unsigned long flags, short x, short y, s
|
|||
// set an Xft font by name
|
||||
void textbox_font( textbox *tb, char *font, char *fg, char *bg )
|
||||
{
|
||||
if ( tb->font ) XftFontClose( display, tb->font );
|
||||
if ( tb->font ) {
|
||||
XftColorFree ( display,
|
||||
DefaultVisual( display, DefaultScreen( display ) ),
|
||||
DefaultColormap( display, DefaultScreen( display ) ),
|
||||
&tb->color_fg );
|
||||
XftColorFree ( display,
|
||||
DefaultVisual( display, DefaultScreen( display ) ),
|
||||
DefaultColormap( display, DefaultScreen( display ) ),
|
||||
&tb->color_bg );
|
||||
|
||||
XftFontClose( display, tb->font );
|
||||
}
|
||||
|
||||
tb->font = XftFontOpenName( display, DefaultScreen( display ), font );
|
||||
|
||||
|
@ -222,7 +233,9 @@ void textbox_draw( textbox *tb )
|
|||
while ( 1 ) {
|
||||
XftTextExtents8( display, tb->font, ( unsigned char* )line, length, &extents );
|
||||
line_width = extents.width;
|
||||
|
||||
if ( line_width < ( tb->w-2*SIDE_MARGIN ) ) break;
|
||||
|
||||
length--;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue