better multihead support

This commit is contained in:
Sascha Kruse 2011-09-10 01:30:05 +02:00
parent ef7cb76dc5
commit e4148a49d5
3 changed files with 65 additions and 61 deletions

45
README
View File

@ -2,15 +2,14 @@ NAME
dunst - dmenu-ish universal notification system dunst - dmenu-ish universal notification system
SYNOPSIS SYNOPSIS
dunst [-b] [-ne l/r] [-fn font] [-nb color] [-nf color] [-to secs] dunst [-b] [-ne l/r] [-fn font] [-nb color] [-nf color] [-to secs] [-key key] [-mod modifier]
[-key key] [-mod modifier] [-mon n]
DESCRIPTION DESCRIPTION
dunst is a lightweight notification-daemon for the libnotify. It can dunst is a lightweight notification-daemon for the libnotify. It can also be used as a standalone
also be used as a standalone notification system. Dnotify displays mes notification system. Dnotify displays messages received via dbus or as commandline argument in a
sages received via dbus or as commandline argument in a fashion similar fashion similar to dmenu and additionally prints them to stdout. Notifications can be closed via
to dmenu and additionally prints them to stdout. Notifications can be mouseclick.
closed via mouseclick.
OPTIONS OPTIONS
-h/--help -h/--help
@ -19,48 +18,44 @@ OPTIONS
-b dunst appears at the bottom of the screen. -b dunst appears at the bottom of the screen.
-ne l/r -ne l/r
Don't expand popup across the screen and put it in the [l]eft or Don't expand popup across the screen and put it in the [l]eft or [r]ight edge
[r]ight edge
-fn/ font -fn/ font
defines the font or font set used. defines the font or font set used.
-nb/-bg color -nb/-bg color
defines the background color. #RGB, #RRGGBB and X color names defines the background color. #RGB, #RRGGBB and X color names are supported.
are supported.
-nf/-fg color -nf/-fg color
defines the background color. defines the background color.
-msg msg -msg msg
display msg instead of listening to notifications. This option display msg instead of listening to notifications. This option can be used multiple times.
can be used multiple times.
-to secs -to secs
display each message for secs seconds. display each message for secs seconds.
-key key -key key
close window by pressing key [a,b,space,Return etc.] (should be close window by pressing key [a,b,space,Return etc.] (should be used in combination with
used in combination with -mod). -mod).
-mod modifier -mod modifier
defines the modifier for the key. Available modifiers are: defines the modifier for the key. Available modifiers are: ctrl,shift,mod1 (usually the
ctrl,shift,mod1 (usually the alt-key),mod2,mod3,mod4 (usually alt-key),mod2,mod3,mod4 (usually windows key). This option can be used multiple times to
windows key). This option can be used multiple times to combine combine modifiers.
modifiers.
-mon n show the notification on monitor n.
AUTHOR AUTHOR
written by Sascha Kruse <knopwob@googlemail.com> written by Sascha Kruse <knopwob@googlemail.com>
COPYRIGHT COPYRIGHT
Parts of the code are taken from dmenu (especially draw.c and draw.h). Parts of the code are taken from dmenu (especially draw.c and draw.h). Read LICENCE.dmenu and
Read LICENCE.dmenu and look at http://tools.suckless.org/dmenu. look at http://tools.suckless.org/dmenu.
Some snippets in dunst_dbus.c are taken from twmn. See Some snippets in dunst_dbus.c are taken from twmn. See http://github.com/sboli/twmn.
http://github.com/sboli/twmn.
If you feel that copyrights are violated, please send me an e-mail to If you feel that copyrights are violated, please send me an e-mail to knopwob@googlemail.com.
knopwob@googlemail.com.
SEE also SEE also
dwm(1), dmenu(1), twmn(1), notify-send(1) dwm(1), dmenu(1), twmn(1), notify-send(1)

View File

@ -18,6 +18,8 @@ dunst \- dmenu\-ish universal notification system
.IR key ] .IR key ]
.RB [ \- mod .RB [ \- mod
.IR modifier ] .IR modifier ]
.RB [ \- mon
.IR n ]
.P .P
.SH DESCRIPTION .SH DESCRIPTION
.B dunst .B dunst
@ -53,6 +55,9 @@ close window by pressing key [a,b,space,Return etc.] (should be used in combinat
.TP .TP
.BI \-mod " modifier" .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. 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 .SH AUTHOR
written by Sascha Kruse <knopwob@googlemail.com> written by Sascha Kruse <knopwob@googlemail.com>
.SH COPYRIGHT .SH COPYRIGHT

76
dunst.c
View File

@ -27,7 +27,6 @@ typedef struct _msg_queue_t {
/* global variables */ /* global variables */
static int mw, mh;
static int expand = True; static int expand = True;
static int right = False; static int right = False;
static const char *font = NULL; static const char *font = NULL;
@ -45,6 +44,12 @@ static int listen_to_dbus = True;
static int visible = False; static int visible = False;
static KeySym key = NoSymbol; static KeySym key = NoSymbol;
static KeySym mask = 0; 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 */ /* list functions */
@ -99,28 +104,27 @@ pop(msg_queue_t *queue) {
void void
drawmsg(const char *msg) { drawmsg(const char *msg) {
int width, x, y; int width, x, y;
int screen = DefaultScreen(dc->dpy);
dc->x = 0; dc->x = 0;
dc->y = 0; dc->y = 0;
dc->h = 0; dc->h = 0;
y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; y = topbar ? 0 : screen_h - message_h;
if(expand) { if(expand) {
width = mw; width = screen_w;
} else { } else {
width = textw(dc, msg); width = textw(dc, msg);
} }
if(right) { if(right) {
x = mw -width; x = screen_x + (screen_w - width);
} else { } else {
x = 0; x = screen_x;
} }
resizedc(dc, width, mh); resizedc(dc, width, message_h);
XResizeWindow(dc->dpy, win, width, mh); XResizeWindow(dc->dpy, win, width, message_h);
drawrect(dc, 0, 0, width, mh, True, BG(dc, normcol)); drawrect(dc, 0, 0, width, message_h, True, BG(dc, normcol));
drawtext(dc, msg, normcol); drawtext(dc, msg, normcol);
XMoveWindow(dc->dpy, win, x, y); XMoveWindow(dc->dpy, win, x, y);
mapdc(dc, win, width, mh); mapdc(dc, win, width, message_h);
} }
void void
@ -131,7 +135,7 @@ handleXEvents(void) {
switch(ev.type) { switch(ev.type) {
case Expose: case Expose:
if(ev.xexpose.count == 0) if(ev.xexpose.count == 0)
mapdc(dc, win, mw, mh); mapdc(dc, win, screen_w, message_h);
break; break;
case SelectionNotify: case SelectionNotify:
if(ev.xselection.property == utf8) if(ev.xselection.property == utf8)
@ -195,14 +199,17 @@ run(void) {
void void
setup(void) { setup(void) {
int x, y, screen = DefaultScreen(dc->dpy); Window root;
Window root = RootWindow(dc->dpy, screen);
XSetWindowAttributes wa; XSetWindowAttributes wa;
KeyCode code; KeyCode code;
#ifdef XINERAMA #ifdef XINERAMA
int n; int n;
XineramaScreenInfo *info; XineramaScreenInfo *info;
#endif #endif
if(screen < 0) {
screen = DefaultScreen(dc->dpy);
}
root = RootWindow(dc->dpy, DefaultScreen(dc->dpy));
normcol[ColBG] = getcolor(dc, normbgcolor); normcol[ColBG] = getcolor(dc, normbgcolor);
normcol[ColFG] = getcolor(dc, normfgcolor); normcol[ColFG] = getcolor(dc, normfgcolor);
@ -210,42 +217,36 @@ setup(void) {
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
/* menu geometry */ /* menu geometry */
mh = dc->font.height + 2; message_h = dc->font.height + 2;
#ifdef XINERAMA #ifdef XINERAMA
if((info = XineramaQueryScreens(dc->dpy, &n))) { if((info = XineramaQueryScreens(dc->dpy, &n))) {
int i, di; if(screen >= n) {
unsigned int du; fprintf(stderr, "Monitor %d not found\n", n);
Window dw; exit(EXIT_FAILURE);
}
XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); screen_x = info[screen].x_org;
for(i = 0; i < n-1; i++) screen_y = info[screen].y_org;
if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) screen_h = info[screen].height;
break; screen_w = info[screen].width;
x = info[i].x_org;
y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
mw = info[i].width;
XFree(info); XFree(info);
} }
else else
#endif #endif
{ {
x = 0; screen_x = 0;
y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; screen_y = 0;
mw = DisplayWidth(dc->dpy, screen); screen_w = DisplayWidth(dc->dpy, screen);
screen_h = DisplayHeight(dc->dpy, screen);
} }
/* menu window */ /* menu window */
wa.override_redirect = True; wa.override_redirect = True;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask; wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask;
win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0, win = XCreateWindow(dc->dpy, root, screen_x, screen_y, screen_w, message_h, 0,
DefaultDepth(dc->dpy, screen), CopyFromParent, DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)), CopyFromParent,
DefaultVisual(dc->dpy, screen), DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
XMapRaised(dc->dpy, win);
resizedc(dc, mw, mh);
/* grab keys */ /* grab keys */
code = XKeysymToKeycode(dc->dpy, key); code = XKeysymToKeycode(dc->dpy, key);
XGrabKey(dc->dpy, code, mask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dc->dpy, code, mask, root, True, GrabModeAsync, GrabModeAsync);
@ -312,6 +313,9 @@ main(int argc, char *argv[]) {
msgqueuehead = append(msgqueuehead, argv[++i]); msgqueuehead = append(msgqueuehead, argv[++i]);
listen_to_dbus = False; listen_to_dbus = False;
} }
else if(!strcmp(argv[i], "-mon")) {
screen = atoi(argv[++i]);
}
else if(!strcmp(argv[i], "-key")) { else if(!strcmp(argv[i], "-key")) {
key = XStringToKeysym(argv[i+1]); key = XStringToKeysym(argv[i+1]);
if(key == NoSymbol) { if(key == NoSymbol) {
@ -363,6 +367,6 @@ main(int argc, char *argv[]) {
void void
usage(int exit_status) { 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); exit(exit_status);
} }