Launcher: Added launcher completion.
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
*/
|
||||
|
||||
#include "wmfs.h"
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
|
||||
void
|
||||
launcher_execute(Launcher launcher)
|
||||
@@ -39,7 +41,18 @@ launcher_execute(Launcher launcher)
|
||||
KeySym ks;
|
||||
char tmp[32] = { 0 };
|
||||
char buf[512] = { 0 };
|
||||
char tabbuf[512] = { 0 };
|
||||
int pos = 0;
|
||||
DIR *dir;
|
||||
struct dirent *dirent;
|
||||
char *searchpath;
|
||||
char *start, *end;
|
||||
Bool stop, found;
|
||||
char currentpath[PATH_MAX];
|
||||
Bool lastwastab = False;
|
||||
int tabhits = 0;
|
||||
int searchhits = 0;
|
||||
|
||||
BarWindow *bw;
|
||||
Bool my_guitar_gently_wheeps = True;
|
||||
|
||||
@@ -84,11 +97,85 @@ launcher_execute(Launcher launcher)
|
||||
case XK_Escape:
|
||||
my_guitar_gently_wheeps = 0;
|
||||
break;
|
||||
case XK_Tab:
|
||||
stop = False;
|
||||
found = False;
|
||||
|
||||
searchpath = getenv("PATH");
|
||||
start = searchpath;
|
||||
|
||||
if (lastwastab)
|
||||
{
|
||||
strcpy(buf, tabbuf);
|
||||
tabhits++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tabhits = 1;
|
||||
}
|
||||
searchhits = 0;
|
||||
|
||||
do
|
||||
{
|
||||
end = strchr(start, ':');
|
||||
if (end == NULL)
|
||||
{
|
||||
stop = True;
|
||||
strncpy(currentpath, start, PATH_MAX);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(currentpath, start, end - start);
|
||||
currentpath[end - start] = '\0';
|
||||
}
|
||||
if (!stop)
|
||||
{
|
||||
start = end + 1;
|
||||
}
|
||||
|
||||
|
||||
dir = opendir(currentpath);
|
||||
if (dir)
|
||||
{
|
||||
while ((dirent = readdir(dir)) != NULL)
|
||||
{
|
||||
if (!strncmp(dirent->d_name, buf, strlen(buf)))
|
||||
{
|
||||
searchhits++;
|
||||
if (searchhits == tabhits)
|
||||
{
|
||||
strcpy(tabbuf, buf);
|
||||
strcpy(buf, dirent->d_name);
|
||||
pos = strlen(dirent->d_name);
|
||||
buf[pos] = '\0';
|
||||
found = True;
|
||||
stop = True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
while (!stop);
|
||||
|
||||
lastwastab = True;
|
||||
|
||||
if (!found)
|
||||
{
|
||||
tabhits = 0; /* start a new round of tabbing */
|
||||
}
|
||||
pos = strlen(buf);
|
||||
|
||||
break;
|
||||
|
||||
case XK_BackSpace:
|
||||
lastwastab = False;
|
||||
if(pos)
|
||||
buf[--pos] = 0;
|
||||
break;
|
||||
default:
|
||||
lastwastab = False;
|
||||
strncat(buf, tmp, sizeof(buf));
|
||||
++pos;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user