Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onetime functionality #2

Merged
merged 6 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions xnotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ static struct Item *head;
static struct Item *tail;
static int remap = 0; /* whether we should remap item windows */

/* flags */
static int oflag = 0;

/* include configuration structure */
#include "config.h"

Expand Down Expand Up @@ -87,8 +90,11 @@ getoptions(int argc, char *argv[])
unsigned long n;
int ch;

while ((ch = getopt(argc, argv, "G:g:m:s:")) != -1) {
while ((ch = getopt(argc, argv, "G:g:m:s:o")) != -1) {
switch (ch) {
case 'o':
oflag = 1;
break;
case 'G':
config.gravityspec = optarg;
break;
Expand Down Expand Up @@ -732,19 +738,24 @@ parseinput(char *s)
}

/* check whether items have passed the time */
static void
static int
timeitems(void)
{
struct Item *item;
struct Item *tmp;
int nitem=0; /* number of items deleted */

item = head;
while (item) {
tmp = item;
item = item->next;
if (time(NULL) - tmp->time > config.sec)
if (time(NULL) - tmp->time > config.sec) {
delitem(tmp);
nitem++;
}
}

return nitem;
}

static void
Expand Down Expand Up @@ -801,6 +812,7 @@ main(int argc, char *argv[])
struct pollfd pfd[2]; /* [2] for stdin and xfd, see poll(2) */
int timeout = -1; /* maximum interval for poll(2) to complete */
int flags; /* status flags for stdin */
int done = 0; /* increments when a notifications time is up */

/* open connection to server and set X variables */
if ((dpy = XOpenDisplay(NULL)) == NULL)
Expand Down Expand Up @@ -857,11 +869,14 @@ main(int argc, char *argv[])
readevent();
}
}
timeitems();
done += timeitems();
if (remap)
mapitems();
timeout = (head) ? 1000 : -1;
XFlush(dpy);

if (oflag && done)
break;
}

/* clean up stuff */
Expand Down
62 changes: 0 additions & 62 deletions xnotify.h

This file was deleted.

Binary file added xnotify.o
Binary file not shown.