Skip to content

Commit 99187d5

Browse files
committed
add -o and free(item) on delitem
1 parent cc431a2 commit 99187d5

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

xnotify.1

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xnotify \- popup a notification on the screen
44
.SH SYNOPSIS
55
.B xnotify
6+
.RB [ \-o ]
67
.RB [ \-G
78
.IR gravity ]
89
.RB [ \-g
@@ -65,6 +66,11 @@ Monitor numbers start from 0.
6566
Without this option,
6667
xnotify is displayed on the first monitor (that is, the monitor 0).
6768
.TP
69+
.B \-o
70+
With this option,
71+
only one notification should exist at a time.
72+
So, when a new notification appears, the other ones are removed.
73+
.TP
6874
.BI "\-s " seconds
6975
Specify the time, in seconds,
7076
for a notification to be displayed before it is removed from screen.

xnotify.c

+27-20
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ static Atom netatom[NetLast];
3838
static struct DC dc;
3939
static struct Fonts titlefnt, bodyfnt;
4040

41+
/* flags */
42+
static int oflag = 0; /* whether only one notification must exist at a time */
43+
4144
/* include configuration structure */
4245
#include "config.h"
4346

4447
/* show usage */
4548
void
4649
usage(void)
4750
{
48-
(void)fprintf(stderr, "usage: xnotify [-G gravity] [-g geometry] [-m monitor] [-s seconds]\n");
51+
(void)fprintf(stderr, "usage: xnotify [-o] [-G gravity] [-g geometry] [-m monitor] [-s seconds]\n");
4952
exit(1);
5053
}
5154

@@ -108,7 +111,7 @@ getoptions(int argc, char *argv[])
108111
unsigned long n;
109112
int ch;
110113

111-
while ((ch = getopt(argc, argv, "G:g:m:s:")) != -1) {
114+
while ((ch = getopt(argc, argv, "G:g:m:os:")) != -1) {
112115
switch (ch) {
113116
case 'G':
114117
config.gravityspec = optarg;
@@ -119,6 +122,9 @@ getoptions(int argc, char *argv[])
119122
case 'm':
120123
mon.num = atoi(optarg);
121124
break;
125+
case 'o':
126+
oflag = 1;
127+
break;
122128
case 's':
123129
if ((n = strtoul(optarg, NULL, 10)) < INT_MAX)
124130
config.sec = n;
@@ -794,7 +800,6 @@ delitem(struct Queue *queue, struct Item *item)
794800
free(item->body);
795801
XFreePixmap(dpy, item->pixmap);
796802
XDestroyWindow(dpy, item->win);
797-
798803
if (item->prev)
799804
item->prev->next = item->next;
800805
else
@@ -803,7 +808,7 @@ delitem(struct Queue *queue, struct Item *item)
803808
item->next->prev = item->prev;
804809
else
805810
queue->tail = item->prev;
806-
811+
free(item);
807812
queue->change = 1;
808813
}
809814

@@ -822,6 +827,21 @@ optiontype(const char *s)
822827
return UNKNOWN;
823828
}
824829

830+
/* destroy all notification items */
831+
static void
832+
cleanitems(struct Queue *queue)
833+
{
834+
struct Item *item;
835+
struct Item *tmp;
836+
837+
item = queue->head;
838+
while (item) {
839+
tmp = item;
840+
item = item->next;
841+
delitem(queue, tmp);
842+
}
843+
}
844+
825845
/* read stdin */
826846
static void
827847
parseinput(struct Queue *queue, char *s)
@@ -856,7 +876,6 @@ parseinput(struct Queue *queue, char *s)
856876
default:
857877
break;
858878
}
859-
860879
}
861880

862881
/* get the body */
@@ -868,6 +887,9 @@ parseinput(struct Queue *queue, char *s)
868887
if (!title)
869888
return;
870889

890+
if (oflag)
891+
cleanitems(queue);
892+
871893
additem(queue, title, body, file, bg, fg, brd);
872894
}
873895

@@ -976,21 +998,6 @@ moveitems(struct Queue *queue)
976998
queue->change = 0;
977999
}
9781000

979-
/* destroy all notification items */
980-
static void
981-
cleanitems(struct Queue *queue)
982-
{
983-
struct Item *item;
984-
struct Item *tmp;
985-
986-
item = queue->head;
987-
while (item) {
988-
tmp = item;
989-
item = item->next;
990-
delitem(queue, tmp);
991-
}
992-
}
993-
9941001
/* clean up dc elements */
9951002
static void
9961003
cleandc(void)

0 commit comments

Comments
 (0)