if isatty() first read from stdin and then grab the keyboard, otherwise first grab the keyboard and then read from stdin
This commit is contained in:
parent
6c0e05eb0d
commit
8a066fabd9
25
main.c
25
main.c
|
@ -108,6 +108,13 @@ drawmenu(void) {
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
grabkeyboard(void) {
|
||||||
|
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
||||||
|
GrabModeAsync, CurrentTime) != GrabSuccess)
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned long
|
static unsigned long
|
||||||
initcolor(const char *colstr) {
|
initcolor(const char *colstr) {
|
||||||
Colormap cmap = DefaultColormap(dpy, screen);
|
Colormap cmap = DefaultColormap(dpy, screen);
|
||||||
|
@ -418,12 +425,6 @@ main(int argc, char *argv[]) {
|
||||||
XModifierKeymap *modmap;
|
XModifierKeymap *modmap;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
|
|
||||||
if(argc == 2 && !strncmp("-v", argv[1], 3))
|
|
||||||
eprint("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n");
|
|
||||||
else if(isatty(STDIN_FILENO)) {
|
|
||||||
fputs("error: dmenu can't run in an interactive shell\n", stdout);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
/* command line args */
|
/* command line args */
|
||||||
for(i = 1; i < argc; i++)
|
for(i = 1; i < argc; i++)
|
||||||
if(!strncmp(argv[i], "-b", 3)) {
|
if(!strncmp(argv[i], "-b", 3)) {
|
||||||
|
@ -447,6 +448,8 @@ main(int argc, char *argv[]) {
|
||||||
else if(!strncmp(argv[i], "-sf", 4)) {
|
else if(!strncmp(argv[i], "-sf", 4)) {
|
||||||
if(++i < argc) selfg = argv[i];
|
if(++i < argc) selfg = argv[i];
|
||||||
}
|
}
|
||||||
|
else if(!strncmp(argv[i], "-v", 3))
|
||||||
|
eprint("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n");
|
||||||
else
|
else
|
||||||
usage();
|
usage();
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
|
@ -455,10 +458,14 @@ main(int argc, char *argv[]) {
|
||||||
eprint("dmenu: cannot open display\n");
|
eprint("dmenu: cannot open display\n");
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
root = RootWindow(dpy, screen);
|
root = RootWindow(dpy, screen);
|
||||||
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
if(isatty(STDIN_FILENO)) {
|
||||||
GrabModeAsync, CurrentTime) != GrabSuccess)
|
|
||||||
usleep(1000);
|
|
||||||
maxname = readstdin();
|
maxname = readstdin();
|
||||||
|
grabkeyboard();
|
||||||
|
}
|
||||||
|
else { /* prevent keypress loss */
|
||||||
|
grabkeyboard();
|
||||||
|
maxname = readstdin();
|
||||||
|
}
|
||||||
/* init modifier map */
|
/* init modifier map */
|
||||||
modmap = XGetModifierMapping(dpy);
|
modmap = XGetModifierMapping(dpy);
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
|
|
Loading…
Reference in New Issue