aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dinput.c28
-rw-r--r--dmenu.c30
2 files changed, 20 insertions, 38 deletions
diff --git a/dinput.c b/dinput.c
index 64ce036..b789bd7 100644
--- a/dinput.c
+++ b/dinput.c
@@ -1,7 +1,6 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include <ctype.h> 2#include <ctype.h>
3#include <locale.h> 3#include <locale.h>
4#include <stdarg.h>
5#include <stdio.h> 4#include <stdio.h>
6#include <stdlib.h> 5#include <stdlib.h>
7#include <string.h> 6#include <string.h>
@@ -15,7 +14,6 @@
15#include <draw.h> 14#include <draw.h>
16 15
17/* macros */ 16/* macros */
18#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
19#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) 17#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
20#define MIN(a, b) ((a) < (b) ? (a) : (b)) 18#define MIN(a, b) ((a) < (b) ? (a) : (b))
21#define MAX(a, b) ((a) > (b) ? (a) : (b)) 19#define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -46,7 +44,7 @@ static unsigned long selcol[ColLast];
46static Bool running = True; 44static Bool running = True;
47static DC dc; 45static DC dc;
48static Display *dpy; 46static Display *dpy;
49static Window win, parent; 47static Window win, root;
50 48
51void 49void
52cleanup(void) { 50cleanup(void) {
@@ -91,7 +89,7 @@ grabkeyboard(void) {
91 unsigned int len; 89 unsigned int len;
92 90
93 for(len = 1000; len; len--) { 91 for(len = 1000; len; len--) {
94 if(XGrabKeyboard(dpy, parent, True, GrabModeAsync, GrabModeAsync, CurrentTime) 92 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
95 == GrabSuccess) 93 == GrabSuccess)
96 break; 94 break;
97 usleep(1000); 95 usleep(1000);
@@ -257,7 +255,6 @@ setup(Bool topbar) {
257#endif 255#endif
258 XModifierKeymap *modmap; 256 XModifierKeymap *modmap;
259 XSetWindowAttributes wa; 257 XSetWindowAttributes wa;
260 XWindowAttributes pwa;
261 258
262 /* init modifier map */ 259 /* init modifier map */
263 modmap = XGetModifierMapping(dpy); 260 modmap = XGetModifierMapping(dpy);
@@ -284,13 +281,13 @@ setup(Bool topbar) {
284 /* input window geometry */ 281 /* input window geometry */
285 mh = dc.font.height + 2; 282 mh = dc.font.height + 2;
286#if XINERAMA 283#if XINERAMA
287 if(parent == RootWindow(dpy, screen) && XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { 284 if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
288 i = 0; 285 i = 0;
289 if(n > 1) { 286 if(n > 1) {
290 int di; 287 int di;
291 unsigned int dui; 288 unsigned int dui;
292 Window dummy; 289 Window dummy;
293 if(XQueryPointer(dpy, parent, &dummy, &dummy, &x, &y, &di, &di, &dui)) 290 if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui))
294 for(i = 0; i < n; i++) 291 for(i = 0; i < n; i++)
295 if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) 292 if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
296 break; 293 break;
@@ -303,13 +300,12 @@ setup(Bool topbar) {
303 else 300 else
304#endif 301#endif
305 { 302 {
306 XGetWindowAttributes(dpy, parent, &pwa);
307 x = 0; 303 x = 0;
308 y = topbar ? 0 : pwa.height - mh; 304 y = topbar ? 0 : DisplayHeight(dpy, screen) - mh;
309 mw = pwa.width; 305 mw = DisplayWidth(dpy, screen);
310 } 306 }
311 307
312 win = XCreateWindow(dpy, parent, x, y, mw, mh, 0, 308 win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
313 DefaultDepth(dpy, screen), CopyFromParent, 309 DefaultDepth(dpy, screen), CopyFromParent,
314 DefaultVisual(dpy, screen), 310 DefaultVisual(dpy, screen),
315 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 311 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
@@ -327,15 +323,12 @@ main(int argc, char *argv[]) {
327 Bool topbar = True; 323 Bool topbar = True;
328 324
329 /* command line args */ 325 /* command line args */
330 progname = argv[0]; 326 progname = "dinput";
331 for(i = 1; i < argc; i++) 327 for(i = 1; i < argc; i++)
332 if(!strcmp(argv[i], "-i")) 328 if(!strcmp(argv[i], "-i"))
333 ; /* ignore flag */ 329 ; /* ignore flag */
334 else if(!strcmp(argv[i], "-b")) 330 else if(!strcmp(argv[i], "-b"))
335 topbar = False; 331 topbar = False;
336 else if(!strcmp(argv[i], "-e")) {
337 if(++i < argc) parent = atoi(argv[i]);
338 }
339 else if(!strcmp(argv[i], "-l")) 332 else if(!strcmp(argv[i], "-l"))
340 i++; /* ignore flag */ 333 i++; /* ignore flag */
341 else if(!strcmp(argv[i], "-fn")) { 334 else if(!strcmp(argv[i], "-fn")) {
@@ -363,7 +356,7 @@ main(int argc, char *argv[]) {
363 else if(!*text) 356 else if(!*text)
364 strncpy(text, argv[i], sizeof text); 357 strncpy(text, argv[i], sizeof text);
365 else { 358 else {
366 fputs("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n" 359 fputs("usage: dinput [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n"
367 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n", stderr); 360 " [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n", stderr);
368 exit(EXIT_FAILURE); 361 exit(EXIT_FAILURE);
369 } 362 }
@@ -372,8 +365,7 @@ main(int argc, char *argv[]) {
372 if(!(dpy = XOpenDisplay(NULL))) 365 if(!(dpy = XOpenDisplay(NULL)))
373 eprint("cannot open display\n"); 366 eprint("cannot open display\n");
374 screen = DefaultScreen(dpy); 367 screen = DefaultScreen(dpy);
375 if(!parent) 368 root = RootWindow(dpy, screen);
376 parent = RootWindow(dpy, screen);
377 369
378 running = grabkeyboard(); 370 running = grabkeyboard();
379 setup(topbar); 371 setup(topbar);
diff --git a/dmenu.c b/dmenu.c
index 9315181..680b4e7 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -1,11 +1,9 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include <ctype.h> 2#include <ctype.h>
3#include <locale.h> 3#include <locale.h>
4#include <stdarg.h>
5#include <stdio.h> 4#include <stdio.h>
6#include <stdlib.h> 5#include <stdlib.h>
7#include <string.h> 6#include <string.h>
8#include <strings.h>
9#include <unistd.h> 7#include <unistd.h>
10#include <X11/keysym.h> 8#include <X11/keysym.h>
11#include <X11/Xlib.h> 9#include <X11/Xlib.h>
@@ -16,7 +14,6 @@
16#include <draw.h> 14#include <draw.h>
17 15
18/* macros */ 16/* macros */
19#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
20#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) 17#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
21#define MIN(a, b) ((a) < (b) ? (a) : (b)) 18#define MIN(a, b) ((a) < (b) ? (a) : (b))
22#define MAX(a, b) ((a) > (b) ? (a) : (b)) 19#define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -72,7 +69,7 @@ static Item *sel = NULL;
72static Item *next = NULL; 69static Item *next = NULL;
73static Item *prev = NULL; 70static Item *prev = NULL;
74static Item *curr = NULL; 71static Item *curr = NULL;
75static Window win, parent; 72static Window win, root;
76static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; 73static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
77static char *(*fstrstr)(const char *, const char *) = strstr; 74static char *(*fstrstr)(const char *, const char *) = strstr;
78static void (*calcoffsets)(void) = calcoffsetsh; 75static void (*calcoffsets)(void) = calcoffsetsh;
@@ -227,7 +224,7 @@ grabkeyboard(void) {
227 unsigned int len; 224 unsigned int len;
228 225
229 for(len = 1000; len; len--) { 226 for(len = 1000; len; len--) {
230 if(XGrabKeyboard(dpy, parent, True, GrabModeAsync, GrabModeAsync, CurrentTime) 227 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
231 == GrabSuccess) 228 == GrabSuccess)
232 break; 229 break;
233 usleep(1000); 230 usleep(1000);
@@ -482,7 +479,6 @@ setup(void) {
482#endif 479#endif
483 XModifierKeymap *modmap; 480 XModifierKeymap *modmap;
484 XSetWindowAttributes wa; 481 XSetWindowAttributes wa;
485 XWindowAttributes pwa;
486 482
487 /* init modifier map */ 483 /* init modifier map */
488 modmap = XGetModifierMapping(dpy); 484 modmap = XGetModifierMapping(dpy);
@@ -509,13 +505,13 @@ setup(void) {
509 /* menu window geometry */ 505 /* menu window geometry */
510 mh = (dc.font.height + 2) * (lines + 1); 506 mh = (dc.font.height + 2) * (lines + 1);
511#if XINERAMA 507#if XINERAMA
512 if(parent == RootWindow(dpy, screen) && XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { 508 if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
513 i = 0; 509 i = 0;
514 if(n > 1) { 510 if(n > 1) {
515 int di; 511 int di;
516 unsigned int dui; 512 unsigned int dui;
517 Window dummy; 513 Window dummy;
518 if(XQueryPointer(dpy, parent, &dummy, &dummy, &x, &y, &di, &di, &dui)) 514 if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui))
519 for(i = 0; i < n; i++) 515 for(i = 0; i < n; i++)
520 if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) 516 if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
521 break; 517 break;
@@ -528,14 +524,12 @@ setup(void) {
528 else 524 else
529#endif 525#endif
530 { 526 {
531 if(!XGetWindowAttributes(dpy, parent, &pwa))
532 eprint("cannot get window attributes");
533 x = 0; 527 x = 0;
534 y = topbar ? 0 : pwa.height - mh; 528 y = topbar ? 0 : mh - DisplayHeight(dpy, screen);
535 mw = pwa.width; 529 mw = DisplayWidth(dpy, screen);
536 } 530 }
537 531
538 win = XCreateWindow(dpy, parent, x, y, mw, mh, 0, 532 win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
539 DefaultDepth(dpy, screen), CopyFromParent, 533 DefaultDepth(dpy, screen), CopyFromParent,
540 DefaultVisual(dpy, screen), 534 DefaultVisual(dpy, screen),
541 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 535 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
@@ -555,7 +549,7 @@ main(int argc, char *argv[]) {
555 unsigned int i; 549 unsigned int i;
556 550
557 /* command line args */ 551 /* command line args */
558 progname = argv[0]; 552 progname = "dmenu";
559 for(i = 1; i < argc; i++) 553 for(i = 1; i < argc; i++)
560 if(!strcmp(argv[i], "-i")) { 554 if(!strcmp(argv[i], "-i")) {
561 fstrncmp = strncasecmp; 555 fstrncmp = strncasecmp;
@@ -563,9 +557,6 @@ main(int argc, char *argv[]) {
563 } 557 }
564 else if(!strcmp(argv[i], "-b")) 558 else if(!strcmp(argv[i], "-b"))
565 topbar = False; 559 topbar = False;
566 else if(!strcmp(argv[i], "-e")) {
567 if(++i < argc) parent = atoi(argv[i]);
568 }
569 else if(!strcmp(argv[i], "-l")) { 560 else if(!strcmp(argv[i], "-l")) {
570 if(++i < argc) lines = atoi(argv[i]); 561 if(++i < argc) lines = atoi(argv[i]);
571 if(lines > 0) 562 if(lines > 0)
@@ -594,7 +585,7 @@ main(int argc, char *argv[]) {
594 exit(EXIT_SUCCESS); 585 exit(EXIT_SUCCESS);
595 } 586 }
596 else { 587 else {
597 fputs("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n" 588 fputs("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>]\n"
598 " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr); 589 " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr);
599 exit(EXIT_FAILURE); 590 exit(EXIT_FAILURE);
600 } 591 }
@@ -603,8 +594,7 @@ main(int argc, char *argv[]) {
603 if(!(dpy = XOpenDisplay(NULL))) 594 if(!(dpy = XOpenDisplay(NULL)))
604 eprint("cannot open display\n"); 595 eprint("cannot open display\n");
605 screen = DefaultScreen(dpy); 596 screen = DefaultScreen(dpy);
606 if(!parent) 597 root = RootWindow(dpy, screen);
607 parent = RootWindow(dpy, screen);
608 if(!(argp = malloc(sizeof *argp * (argc+2)))) 598 if(!(argp = malloc(sizeof *argp * (argc+2))))
609 eprint("cannot malloc %u bytes\n", sizeof *argp * (argc+2)); 599 eprint("cannot malloc %u bytes\n", sizeof *argp * (argc+2));
610 memcpy(argp + 2, argv + 1, sizeof *argp * argc); 600 memcpy(argp + 2, argv + 1, sizeof *argp * argc);