From 4bb529bfaeb6899b4bfc8538162f884c99eca55f Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Thu, 8 Sep 2011 00:40:20 +0200 Subject: [PATCH] noexpand --- README | 11 ++++++++--- dunst.1 | 3 +++ dunst.c | 46 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/README b/README index 3c00de6..e26db07 100644 --- a/README +++ b/README @@ -5,8 +5,9 @@ SYNOPSIS dunst [-b] [-fn font] [-nb color] [-nf color] [-to secs] DESCRIPTION - 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. + dunst is a lightweight notification-daemon for the libnotify. It can also be used as a standalone notifica‐ + tion 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 @@ -14,6 +15,9 @@ 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 + -fn/ font defines the font or font set used. @@ -33,7 +37,8 @@ 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. diff --git a/dunst.1 b/dunst.1 index 4e56052..6c31c7b 100644 --- a/dunst.1 +++ b/dunst.1 @@ -24,6 +24,9 @@ display help message. .B \-b dunst appears at the bottom of the screen. .TP +.BI \-ne " l/r" +Don't expand popup across the screen and put it in the [l]eft or [r]ight edge +.TP .BI \-fn/ " font" defines the font or font set used. .TP diff --git a/dunst.c b/dunst.c index 16f14cb..c6266df 100644 --- a/dunst.c +++ b/dunst.c @@ -28,6 +28,8 @@ typedef struct _msg_queue_t { /* global variables */ static int bh, mw, mh; +static int expand = False; +static int right = False; static int lines = 0; static const char *font = NULL; static const char *normbgcolor = "#cccccc"; @@ -98,13 +100,29 @@ 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; - drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol)); + y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; + if(expand) { + width = mw; + } else { + width = textw(dc, msg); + } + if(right) { + x = mw -width; + } else { + x = 0; + } + resizedc(dc, width, mh); + XResizeWindow(dc->dpy, win, width, mh); + drawrect(dc, 0, 0, width, mh, True, BG(dc, normcol)); drawtext(dc, msg, normcol); + XMoveWindow(dc->dpy, win, x, y); - mapdc(dc, win, mw, mh); + mapdc(dc, win, width, mh); } void @@ -258,10 +276,27 @@ main(int argc, char *argv[]) { now = time(&now); for(i = 1; i < argc; i++) { + /* switches */ if(!strcmp(argv[i], "-b")) topbar = False; - else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) usage(EXIT_SUCCESS); + + /* options */ + else if(i == argc) { + printf("Option needs an argument\n"); + usage(1); + } + else if(!strcmp(argv[i], "-ne")) { + expand = False; + if(!strcmp(argv[i+1], "l")) { + right = False; + } else if (!strcmp(argv[i+1], "r")) { + right = True; + } else { + usage(EXIT_FAILURE); + } + i++; } else if(!strcmp(argv[i], "-fn")) font = argv[++i]; @@ -272,9 +307,6 @@ main(int argc, char *argv[]) { else if(!strcmp(argv[i], "-to")) global_timeout = atoi(argv[++i]); else if(!strcmp(argv[i], "-msg")) { - if(i+1 == argc) { - usage(EXIT_FAILURE); - } msgqueuehead = append(msgqueuehead, argv[++i]); loop = False; } @@ -297,6 +329,6 @@ main(int argc, char *argv[]) { void usage(int exit_status) { - fputs("usage: dunst [-h/--help] [-b] [-fn font]\n[-nb/-bg color] [-nf/-fg color] [-to secs] [-msg msg]\n", stderr); + fputs("usage: dunst [-h/--help] [-b] [-ne l/r] [-fn font]\n[-nb/-bg color] [-nf/-fg color] [-to secs] [-msg msg]\n", stderr); exit(exit_status); }