detect active monitor using input focus f1848a3e
Connor Lane Smith · 2011-09-19 18:15 1 file(s) · +12 −7
dmenu.c +12 −7
473 473
setup(void) {
474 474
	int x, y, screen = DefaultScreen(dc->dpy);
475 475
	Window root = RootWindow(dc->dpy, screen);
476 -
	XSetWindowAttributes wa;
476 +
	XSetWindowAttributes swa;
477 477
#ifdef XINERAMA
478 478
	int n;
479 479
	XineramaScreenInfo *info;
494 494
	if((info = XineramaQueryScreens(dc->dpy, &n))) {
495 495
		int i, di;
496 496
		unsigned int du;
497 -
		Window dw;
497 +
		Window w, dw;
498 +
		XWindowAttributes wa;
498 499
499 -
		XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du);
500 +
		XGetInputFocus(dc->dpy, &w, &di);
501 +
		if(w != root && XGetWindowAttributes(dc->dpy, w, &wa))
502 +
			XTranslateCoordinates(dc->dpy, root, root, wa.x, wa.y, &x, &y, &dw);
503 +
		else
504 +
			XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du);
500 505
		for(i = 0; i < n-1; i++)
501 506
			if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
502 507
				break;
517 522
	match(False);
518 523
519 524
	/* menu window */
520 -
	wa.override_redirect = True;
521 -
	wa.background_pixmap = ParentRelative;
522 -
	wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
525 +
	swa.override_redirect = True;
526 +
	swa.background_pixmap = ParentRelative;
527 +
	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
523 528
	win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
524 529
	                    DefaultDepth(dc->dpy, screen), CopyFromParent,
525 530
	                    DefaultVisual(dc->dpy, screen),
526 -
	                    CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
531 +
	                    CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa);
527 532
528 533
	XMapRaised(dc->dpy, win);
529 534
	resizedc(dc, mw, mh);