1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-02-10 15:44:41 -05:00

act as launcher if no window chosen

This commit is contained in:
seanpringle 2012-08-24 11:35:33 +10:00
parent 3c3d6305fc
commit e2ce7b0f5a

View file

@ -87,6 +87,26 @@ void catch_exit(int sig)
while (0 < waitpid(-1, NULL, WNOHANG)); while (0 < waitpid(-1, NULL, WNOHANG));
} }
int execsh(char *cmd)
{
// use sh for args parsing
return execlp("/bin/sh", "sh", "-c", cmd, NULL);
}
// execute sub-process
pid_t exec_cmd(char *cmd)
{
if (!cmd || !cmd[0]) return -1;
signal(SIGCHLD, catch_exit);
pid_t pid = fork();
if (!pid)
{
setsid();
execsh(cmd);
exit(EXIT_FAILURE);
}
return pid;
}
// cli arg handling // cli arg handling
int find_arg(int argc, char *argv[], char *key) int find_arg(int argc, char *argv[], char *key)
{ {
@ -728,7 +748,8 @@ void run_switcher(int mode, int fmode)
// strangeness... // strangeness...
display = XOpenDisplay(0); display = XOpenDisplay(0);
XSync(display, True); XSync(display, True);
int n = menu(list, NULL, "> ", 1); char *input = NULL;
int n = menu(list, &input, "> ", 1);
if (n >= 0 && list[n]) if (n >= 0 && list[n])
{ {
if (mode == ALLWINDOWS) if (mode == ALLWINDOWS)
@ -741,6 +762,12 @@ void run_switcher(int mode, int fmode)
window_send_message(root, ids->array[n], netatoms[_NET_ACTIVE_WINDOW], 2, // 2 = pager window_send_message(root, ids->array[n], netatoms[_NET_ACTIVE_WINDOW], 2, // 2 = pager
SubstructureNotifyMask | SubstructureRedirectMask); SubstructureNotifyMask | SubstructureRedirectMask);
} }
else
// act as a launcher
if (input)
{
exec_cmd(input);
}
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
for (i = 0; i < lines; i++) free(list[i]); for (i = 0; i < lines; i++) free(list[i]);