diff -r c2e77ee26371 dmenu.1 --- a/dmenu.1 Fri Jan 07 18:55:00 2011 +0000 +++ b/dmenu.1 Fri Mar 11 20:10:39 2011 +0100 @@ -54,7 +54,9 @@ dmenu lists items vertically, with the given number of lines. .TP .BI \-m " monitor" -dmenu appears on the given Xinerama screen. +dmenu appears on the given Xinerama screen. Alternatively you can give "mouse" to +get the screen by the current mouse-position, or "focus" to get it by the currently +focused window. .TP .BI \-p " prompt" defines the prompt to be displayed to the left of the input field. diff -r c2e77ee26371 dmenu.c --- a/dmenu.c Fri Jan 07 18:55:00 2011 +0000 +++ b/dmenu.c Fri Mar 11 20:10:39 2011 +0100 @@ -43,6 +43,10 @@ static int inputw = 0; static int lines = 0; static int monitor = -1; +#define POSITION_BY_NUMBER 1 +#define POSITION_BY_MOUSE 2 +#define POSITION_BY_FOCUS 3 +static int position_by = POSITION_BY_FOCUS; static int promptw; static size_t cursor = 0; static const char *font = NULL; @@ -84,7 +88,14 @@ else if(!strcmp(argv[i], "-l")) lines = atoi(argv[++i]); else if(!strcmp(argv[i], "-m")) - monitor = atoi(argv[++i]); + if(!strcmp(argv[++i], "focus")) + position_by = POSITION_BY_FOCUS; + else if(!strcmp(argv[i], "mouse")) + position_by = POSITION_BY_MOUSE; + else { + position_by = POSITION_BY_NUMBER; + monitor = atoi(argv[i]); + } else if(!strcmp(argv[i], "-p")) prompt = argv[++i]; else if(!strcmp(argv[i], "-fn")) @@ -496,10 +507,27 @@ #ifdef XINERAMA if((info = XineramaQueryScreens(dc->dpy, &n))) { int i, di; - unsigned int du; + unsigned int du; Window dw; + XWindowAttributes fwa; + Window chi; + int revert; - XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); + switch (position_by) { + case POSITION_BY_NUMBER: + break; + case POSITION_BY_MOUSE: + XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); + break; + case POSITION_BY_FOCUS: + XGetInputFocus(dc->dpy, &dw, &revert); + XGetWindowAttributes(dc->dpy, dw, &fwa); + XTranslateCoordinates(dc->dpy, dw, fwa.root, fwa.x, fwa.y, &x, &y, &chi); + x = x + fwa.width / 2; + y = y + fwa.height / 2; + break; + } + for(i = 0; i < n; i++) if((monitor == info[i].screen_number) || (monitor < 0 && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)))