@@ -38,14 +38,17 @@ static Atom netatom[NetLast];
38
38
static struct DC dc ;
39
39
static struct Fonts titlefnt , bodyfnt ;
40
40
41
+ /* flags */
42
+ static int oflag = 0 ; /* whether only one notification must exist at a time */
43
+
41
44
/* include configuration structure */
42
45
#include "config.h"
43
46
44
47
/* show usage */
45
48
void
46
49
usage (void )
47
50
{
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" );
49
52
exit (1 );
50
53
}
51
54
@@ -108,7 +111,7 @@ getoptions(int argc, char *argv[])
108
111
unsigned long n ;
109
112
int ch ;
110
113
111
- while ((ch = getopt (argc , argv , "G:g:m:s :" )) != -1 ) {
114
+ while ((ch = getopt (argc , argv , "G:g:m:os :" )) != -1 ) {
112
115
switch (ch ) {
113
116
case 'G' :
114
117
config .gravityspec = optarg ;
@@ -119,6 +122,9 @@ getoptions(int argc, char *argv[])
119
122
case 'm' :
120
123
mon .num = atoi (optarg );
121
124
break ;
125
+ case 'o' :
126
+ oflag = 1 ;
127
+ break ;
122
128
case 's' :
123
129
if ((n = strtoul (optarg , NULL , 10 )) < INT_MAX )
124
130
config .sec = n ;
@@ -794,7 +800,6 @@ delitem(struct Queue *queue, struct Item *item)
794
800
free (item -> body );
795
801
XFreePixmap (dpy , item -> pixmap );
796
802
XDestroyWindow (dpy , item -> win );
797
-
798
803
if (item -> prev )
799
804
item -> prev -> next = item -> next ;
800
805
else
@@ -803,7 +808,7 @@ delitem(struct Queue *queue, struct Item *item)
803
808
item -> next -> prev = item -> prev ;
804
809
else
805
810
queue -> tail = item -> prev ;
806
-
811
+ free ( item );
807
812
queue -> change = 1 ;
808
813
}
809
814
@@ -822,6 +827,21 @@ optiontype(const char *s)
822
827
return UNKNOWN ;
823
828
}
824
829
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
+
825
845
/* read stdin */
826
846
static void
827
847
parseinput (struct Queue * queue , char * s )
@@ -856,7 +876,6 @@ parseinput(struct Queue *queue, char *s)
856
876
default :
857
877
break ;
858
878
}
859
-
860
879
}
861
880
862
881
/* get the body */
@@ -868,6 +887,9 @@ parseinput(struct Queue *queue, char *s)
868
887
if (!title )
869
888
return ;
870
889
890
+ if (oflag )
891
+ cleanitems (queue );
892
+
871
893
additem (queue , title , body , file , bg , fg , brd );
872
894
}
873
895
@@ -976,21 +998,6 @@ moveitems(struct Queue *queue)
976
998
queue -> change = 0 ;
977
999
}
978
1000
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
-
994
1001
/* clean up dc elements */
995
1002
static void
996
1003
cleandc (void )
0 commit comments