From e4148a49d539e6d702f5c6ef035987a67d88e9a0 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Sat, 10 Sep 2011 01:30:05 +0200 Subject: [PATCH] better multihead support --- README | 45 +++++++++++++++------------------- dunst.1 | 5 ++++ dunst.c | 76 ++++++++++++++++++++++++++++++--------------------------- 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/README b/README index 0abff12..e7cb5d3 100644 --- a/README +++ b/README @@ -2,15 +2,14 @@ NAME dunst - dmenu-ish universal notification system SYNOPSIS - dunst [-b] [-ne l/r] [-fn font] [-nb color] [-nf color] [-to secs] - [-key key] [-mod modifier] + dunst [-b] [-ne l/r] [-fn font] [-nb color] [-nf color] [-to secs] [-key key] [-mod modifier] + [-mon n] DESCRIPTION - dunst is a lightweight notification-daemon for the libnotify. It can - also be used as a standalone notification system. Dnotify displays mes‐ - sages received via dbus or as commandline argument in a fashion similar - to dmenu and additionally prints them to stdout. Notifications can be - closed via mouseclick. + dunst is a lightweight notification-daemon for the libnotify. It can also be used as a standalone + notification system. Dnotify displays messages received via dbus or as commandline argument in a + fashion similar to dmenu and additionally prints them to stdout. Notifications can be closed via + mouseclick. OPTIONS -h/--help @@ -19,48 +18,44 @@ OPTIONS -b dunst appears at the bottom of the screen. -ne l/r - Don't expand popup across the screen and put it in the [l]eft or - [r]ight edge + Don't expand popup across the screen and put it in the [l]eft or [r]ight edge -fn/ font defines the font or font set used. -nb/-bg color - defines the background color. #RGB, #RRGGBB and X color names - are supported. + defines the background color. #RGB, #RRGGBB and X color names are supported. -nf/-fg color defines the background color. -msg msg - display msg instead of listening to notifications. This option - can be used multiple times. + display msg instead of listening to notifications. This option can be used multiple times. -to secs display each message for secs seconds. -key key - close window by pressing key [a,b,space,Return etc.] (should be - used in combination with -mod). + close window by pressing key [a,b,space,Return etc.] (should be used in combination with + -mod). -mod modifier - defines the modifier for the key. Available modifiers are: - ctrl,shift,mod1 (usually the alt-key),mod2,mod3,mod4 (usually - windows key). This option can be used multiple times to combine - modifiers. + defines the modifier for the key. Available modifiers are: ctrl,shift,mod1 (usually the + alt-key),mod2,mod3,mod4 (usually windows key). This option can be used multiple times to + combine modifiers. + + -mon n show the notification on monitor n. AUTHOR written by Sascha Kruse COPYRIGHT - Parts of the code are taken from dmenu (especially draw.c and draw.h). - Read LICENCE.dmenu and look at http://tools.suckless.org/dmenu. + Parts of the code are taken from dmenu (especially draw.c and draw.h). Read LICENCE.dmenu and + look at http://tools.suckless.org/dmenu. - Some snippets in dunst_dbus.c are taken from twmn. See - http://github.com/sboli/twmn. + Some snippets in dunst_dbus.c are taken from twmn. See http://github.com/sboli/twmn. - If you feel that copyrights are violated, please send me an e-mail to - knopwob@googlemail.com. + If you feel that copyrights are violated, please send me an e-mail to knopwob@googlemail.com. SEE also dwm(1), dmenu(1), twmn(1), notify-send(1) diff --git a/dunst.1 b/dunst.1 index 210991b..ecbdb38 100644 --- a/dunst.1 +++ b/dunst.1 @@ -18,6 +18,8 @@ dunst \- dmenu\-ish universal notification system .IR key ] .RB [ \- mod .IR modifier ] +.RB [ \- mon +.IR n ] .P .SH DESCRIPTION .B dunst @@ -53,6 +55,9 @@ close window by pressing key [a,b,space,Return etc.] (should be used in combinat .TP .BI \-mod " modifier" defines the modifier for the key. Available modifiers are: ctrl,shift,mod1 (usually the alt-key),mod2,mod3,mod4 (usually windows key). This option can be used multiple times to combine modifiers. +.TP +.BI \-mon " n" +show the notification on monitor n. .SH AUTHOR written by Sascha Kruse .SH COPYRIGHT diff --git a/dunst.c b/dunst.c index 79ac7aa..c41b7e6 100644 --- a/dunst.c +++ b/dunst.c @@ -27,7 +27,6 @@ typedef struct _msg_queue_t { /* global variables */ -static int mw, mh; static int expand = True; static int right = False; static const char *font = NULL; @@ -45,6 +44,12 @@ static int listen_to_dbus = True; static int visible = False; static KeySym key = NoSymbol; static KeySym mask = 0; +static int screen = -1; +static int screen_x = 0; +static int screen_y = 0; +static int screen_h = 0; +static int screen_w = 0; +static int message_h = 0; /* list functions */ @@ -99,28 +104,27 @@ pop(msg_queue_t *queue) { void drawmsg(const char *msg) { int width, x, y; - int screen = DefaultScreen(dc->dpy); dc->x = 0; dc->y = 0; dc->h = 0; - y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; + y = topbar ? 0 : screen_h - message_h; if(expand) { - width = mw; + width = screen_w; } else { width = textw(dc, msg); } if(right) { - x = mw -width; + x = screen_x + (screen_w - width); } else { - x = 0; + x = screen_x; } - resizedc(dc, width, mh); - XResizeWindow(dc->dpy, win, width, mh); - drawrect(dc, 0, 0, width, mh, True, BG(dc, normcol)); + resizedc(dc, width, message_h); + XResizeWindow(dc->dpy, win, width, message_h); + drawrect(dc, 0, 0, width, message_h, True, BG(dc, normcol)); drawtext(dc, msg, normcol); XMoveWindow(dc->dpy, win, x, y); - mapdc(dc, win, width, mh); + mapdc(dc, win, width, message_h); } void @@ -131,7 +135,7 @@ handleXEvents(void) { switch(ev.type) { case Expose: if(ev.xexpose.count == 0) - mapdc(dc, win, mw, mh); + mapdc(dc, win, screen_w, message_h); break; case SelectionNotify: if(ev.xselection.property == utf8) @@ -195,14 +199,17 @@ run(void) { void setup(void) { - int x, y, screen = DefaultScreen(dc->dpy); - Window root = RootWindow(dc->dpy, screen); + Window root; XSetWindowAttributes wa; KeyCode code; #ifdef XINERAMA int n; XineramaScreenInfo *info; #endif + if(screen < 0) { + screen = DefaultScreen(dc->dpy); + } + root = RootWindow(dc->dpy, DefaultScreen(dc->dpy)); normcol[ColBG] = getcolor(dc, normbgcolor); normcol[ColFG] = getcolor(dc, normfgcolor); @@ -210,42 +217,36 @@ setup(void) { utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); /* menu geometry */ - mh = dc->font.height + 2; + message_h = dc->font.height + 2; #ifdef XINERAMA if((info = XineramaQueryScreens(dc->dpy, &n))) { - int i, di; - unsigned int du; - Window dw; - - XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); - for(i = 0; i < n-1; i++) - if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) - break; - x = info[i].x_org; - y = info[i].y_org + (topbar ? 0 : info[i].height - mh); - mw = info[i].width; + if(screen >= n) { + fprintf(stderr, "Monitor %d not found\n", n); + exit(EXIT_FAILURE); + } + screen_x = info[screen].x_org; + screen_y = info[screen].y_org; + screen_h = info[screen].height; + screen_w = info[screen].width; XFree(info); } else #endif { - x = 0; - y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; - mw = DisplayWidth(dc->dpy, screen); + screen_x = 0; + screen_y = 0; + screen_w = DisplayWidth(dc->dpy, screen); + screen_h = DisplayHeight(dc->dpy, screen); } - /* menu window */ wa.override_redirect = True; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask; - win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0, - DefaultDepth(dc->dpy, screen), CopyFromParent, - DefaultVisual(dc->dpy, screen), + win = XCreateWindow(dc->dpy, root, screen_x, screen_y, screen_w, message_h, 0, + DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)), CopyFromParent, + DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - XMapRaised(dc->dpy, win); - resizedc(dc, mw, mh); - /* grab keys */ code = XKeysymToKeycode(dc->dpy, key); XGrabKey(dc->dpy, code, mask, root, True, GrabModeAsync, GrabModeAsync); @@ -312,6 +313,9 @@ main(int argc, char *argv[]) { msgqueuehead = append(msgqueuehead, argv[++i]); listen_to_dbus = False; } + else if(!strcmp(argv[i], "-mon")) { + screen = atoi(argv[++i]); + } else if(!strcmp(argv[i], "-key")) { key = XStringToKeysym(argv[i+1]); if(key == NoSymbol) { @@ -363,6 +367,6 @@ main(int argc, char *argv[]) { void usage(int exit_status) { - fputs("usage: dunst [-h/--help] [-b] [-ne l/r] [-fn font]\n[-nb/-bg color] [-nf/-fg color] [-to secs] [-key key] [-mod modifier] [-msg msg]\n", stderr); + fputs("usage: dunst [-h/--help] [-b] [-ne l/r] [-fn font]\n[-nb/-bg color] [-nf/-fg color] [-to secs] [-key key] [-mod modifier] [-mon n] [-msg msg]\n", stderr); exit(exit_status); }