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