add delay option to awesome-message

This commit is contained in:
Nathan LaFreniere 2008-02-08 11:51:12 +01:00 committed by Julien Danjou
parent 0bfa880b0f
commit bf2afc9489
1 changed files with 33 additions and 14 deletions

View File

@ -22,6 +22,7 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <getopt.h> #include <getopt.h>
#include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -36,6 +37,8 @@
#define PROGNAME "awesome-message" #define PROGNAME "awesome-message"
static Bool running = True;
/** Import awesome config file format */ /** Import awesome config file format */
extern cfg_opt_t awesome_opts[]; extern cfg_opt_t awesome_opts[];
@ -58,7 +61,7 @@ static void __attribute__ ((noreturn))
exit_help(int exit_code) exit_help(int exit_code)
{ {
FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr; FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr;
fprintf(outfile, "Usage: %s [-x xcoord] [-y ycoord] <message> <icon>\n", fprintf(outfile, "Usage: %s [-x xcoord] [-y ycoord] [-d delay] <message> <icon>\n",
PROGNAME); PROGNAME);
exit(exit_code); exit(exit_code);
} }
@ -113,6 +116,12 @@ config_parse(const char *confpatharg)
p_delete(&confpath); p_delete(&confpath);
} }
static void
exit_on_signal(int sig __attribute__ ((unused)))
{
running = False;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -120,10 +129,10 @@ main(int argc, char **argv)
SimpleWindow *sw; SimpleWindow *sw;
DrawCtx *ctx; DrawCtx *ctx;
XEvent ev; XEvent ev;
Bool running = True;
Area geometry = { 0, 0, 200, 50, NULL }, Area geometry = { 0, 0, 200, 50, NULL },
icon_geometry = { -1, -1, -1, -1, NULL }; icon_geometry = { -1, -1, -1, -1, NULL };
int opt; int opt;
int delay = 0;
char *configfile = NULL; char *configfile = NULL;
static struct option long_options[] = static struct option long_options[] =
{ {
@ -137,10 +146,13 @@ main(int argc, char **argv)
globalconf.display = disp; globalconf.display = disp;
while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:c:", while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:c:d:",
long_options, NULL)) != -1) long_options, NULL)) != -1)
switch(opt) switch(opt)
{ {
case 'd':
delay = atoi(optarg);
break;
case 'v': case 'v':
eprint_version(PROGNAME); eprint_version(PROGNAME);
break; break;
@ -200,7 +212,12 @@ main(int argc, char **argv)
XMapRaised(disp, sw->window); XMapRaised(disp, sw->window);
XSync(disp, False); XSync(disp, False);
signal(SIGALRM, &exit_on_signal);
alarm(delay);
while(running) while(running)
{
if(XPending(disp))
{ {
XNextEvent(disp, &ev); XNextEvent(disp, &ev);
switch(ev.type) switch(ev.type)
@ -215,6 +232,8 @@ main(int argc, char **argv)
break; break;
} }
} }
sleep(0.1);
}
simplewindow_delete(sw); simplewindow_delete(sw);
XCloseDisplay(disp); XCloseDisplay(disp);