home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gatling.ikk.sztaki.hu
/
gatling.ikk.sztaki.hu.zip
/
gatling.ikk.sztaki.hu
/
pub
/
xbusy.diff
< prev
next >
Wrap
Text File
|
2003-02-06
|
24KB
|
887 lines
diff -urw --new-file /tmp/xidle/Makefile ./Makefile
--- /tmp/xidle/Makefile Fri Aug 8 23:18:12 1997
+++ ./Makefile Tue Feb 4 15:26:24 2003
@@ -4,15 +4,15 @@
#-DDEBUG=1
CFLAGS=-g -I/usr/X11R6/include -I/usr/X11R6/include/X11
-xidle: xidle.o
- $(CC) $(LDFLAGS) -o xidle xidle.o -L/usr/X11R6/lib $(LIBES)
+xbusy: xbusy.o
+ $(CC) $(LDFLAGS) -o xbusy xbusy.o -L/usr/X11R6/lib $(LIBES)
-install: xidle xidle.1
- rm -f $(BINDIR)/xidle
- mv xidle $(BINDIR)/xidle
- rm -f $(MANDIR)/man1/xidle.1
- cp xidle.1 $(MANDIR)/man1/xidle.1
+#install: xidle xidle.1
+# rm -f $(BINDIR)/xidle
+# mv xidle $(BINDIR)/xidle
+# rm -f $(MANDIR)/man1/xidle.1
+# cp xidle.1 $(MANDIR)/man1/xidle.1
clean:
- -rm -f xidle
+ -rm -f xbusy
-rm -f *.o
diff -urw --new-file /tmp/xidle/xbusy.c ./xbusy.c
--- /tmp/xidle/xbusy.c Thu Jan 1 01:00:00 1970
+++ ./xbusy.c Wed Feb 5 14:58:27 2003
@@ -0,0 +1,460 @@
+/*
+ * This program is a hacked version of Bennet Yee's xidle.
+ * Modified by Gabor Kiss, 2003.
+ *
+ * Original copyright message follows:
+ */
+/*
+ * Copyright (C) 1990, Bennet Yee. You may freely distribute this code as long
+ * as this notice is intact. If you make any modifications in your
+ * distribution, you must clearly document them. If you distribute this code
+ * or any derivative thereof, it must be given at no charge to all parties
+ * on terms identical to those prescribed herein. All distributions must
+ * contain source code.
+ *
+ * This software is provided with absolutely no warranty.
+ *
+ * If you have questions, you can contact me at bsy@cs.cmu.edu
+ */
+#ifndef lint
+ static char copyright[] = "\n\
+Copyright (C) 1990, Bennet Yee. You may freely distribute this code as long\n\
+as this notice is intact. If you make any modifications in your\n\
+distribution, you must clearly document them. If you distribute this code\n\
+or any derivative thereof, it must be provided at no charge to all parties\n\
+on terms identical to those prescribed herein. All distributions must\n\
+contain source code.\n\
+\n\
+This software is provided with absolutely no warranty.\n\
+";
+#endif /* lint */
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
+#include <X11/cursorfont.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <signal.h>
+#include <errno.h>
+#include <syslog.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/time.h>
+
+extern int errno;
+
+#ifdef DEBUG
+#define D(x) fprintf x
+#define D2(x) fprintf x
+#define D3(x) fprintf x
+#else
+#define D(x)
+#define D2(x)
+#define D3(x)
+#endif
+
+#define MAXDISPLAY 1024
+#define MAXNAME 1024
+#define MAXRESOURCE 1024
+
+#define HIDE_POLL 50 /* < one minute */
+#define POLL 60
+#define MAX_ELAPSED_MSEC (5*1000)
+#define UPDATE_CLOCK_IVL (5*60*1000)
+#define UPDATE_WIN_IVL (60*1000)
+
+long poll = POLL;
+Time max_elapsed_msec = MAX_ELAPSED_MSEC,
+ update_clock_ivl = UPDATE_CLOCK_IVL,
+ update_win_ivl = UPDATE_WIN_IVL;
+time_t kezdes; // kissg
+int kemeny_munka = 1; // kissg
+
+XrmOptionDescRec tbl[] = {
+{"-display",".display",XrmoptionSepArg, (caddr_t) ""},
+{"-name",".name",XrmoptionSepArg, (caddr_t) "xbusy"},
+// kissg {"-console",".console",XrmoptionSepArg, (caddr_t) "/dev/console"},
+{"-poll",".poll",XrmoptionSepArg, (caddr_t) NULL},
+{"-error",".error",XrmoptionSepArg, (caddr_t) NULL},
+{"-sync",".sync",XrmoptionSepArg, (caddr_t) NULL},
+{"-wcheck",".win",XrmoptionSepArg, (caddr_t) NULL},
+{"-xrm",NULL,XrmoptionResArg, (caddr_t) NULL},
+{"-nomouse",".nomouse",XrmoptionNoArg, (caddr_t) "on"},
+{"-nodaemon",".nodaemon",XrmoptionNoArg, (caddr_t) "on"}
+};
+
+// kissg char console[MAXPATHLEN] = "/dev/console";
+
+usage()
+{
+ fprintf(stderr,"Usage: xbusy [-display dpy] [-name n] [-xrm rm] [-poll N] [-error N] [-sync N] [-wcheck N]\n");
+ exit(1);
+}
+
+#define STATE_NORM 0
+#define STATE_HIDE 1
+#define STATE_BUSY 2
+
+int state = STATE_NORM;
+
+void hide(int signum){ state = STATE_HIDE;}
+void cont(int signum){ state = STATE_NORM;}
+void fake(int signum){ state = STATE_BUSY;}
+void kampec(int signum) // kissg
+{
+ if (kemeny_munka) {
+ time_t munkaido = time(NULL) - kezdes;
+ syslog(LOG_INFO, "%d seconds of hard work confirmed", munkaido);
+ }
+ syslog(LOG_INFO, "exiting");
+ exit(0);
+}
+
+main(ac,av)
+int ac;
+char **av;
+{
+ Display *dpy;
+ XEvent ev;
+ XKeyPressedEvent *kev = (XKeyPressedEvent *) &ev;
+ XrmDatabase db, rmdb;
+ char *type, display[MAXDISPLAY], name[MAXNAME];
+ XrmValue val;
+ char *tmp_string(), *Tmp_string();
+ Atom typeA;
+ int format;
+ unsigned long nitems, bytes;
+ char *prop;
+ fd_set in_fds, in_fd_init;
+ int Xfd;
+ struct timeval time_out, time_of_server_base, keytime;
+ int get_time, time_of_server_base_valid,
+ orig_timeout;
+ Time current_time, key, server_base, elapsed,
+ elapsed_mseconds, update_clock_mseconds,
+ update_win_mseconds;
+ int ignore();
+ int nomouse = 0;
+ int nodaemon = 0;
+// (*signal())();
+
+ openlog("xbusy",LOG_PID,LOG_DAEMON);
+D3((stderr,"initializing RM\n"));
+ XrmInitialize();
+ db = (XrmDatabase) 0;
+D3((stderr,"parsing cmds\n"));
+ XrmParseCommand(&db,tbl,sizeof tbl/sizeof tbl[0],"xbusy",&ac,av);
+D3((stderr,"db points to %X\n",db));
+ if (ac != 1) {
+ fprintf(stderr,"Option not understood: %s\n",av[1]);
+ usage();
+ exit(1);
+ }
+ strcpy(name,"xbusy");
+
+#define RSRC(x,X) (XrmGetResource(db, \
+ tmp_string(name,x), \
+ Tmp_string(name,X), \
+ &type, \
+ &val))
+#define RSRCSTR(x,X) (RSRC(x,X) && !strcmp(type,"String"))
+
+ if (RSRCSTR(".name",".Name")) {
+ strcpy(name,(char *)val.addr);
+ }
+ locase(name);
+ strcpy(display,"");
+ if (RSRCSTR(".display",".Display")) {
+ strcpy(display,(char *)val.addr);
+ }
+ dpy = XOpenDisplay(display);
+ if (!dpy) {
+ fprintf(stderr,"No display\n");
+ exit(1);
+ }
+
+ /*
+ * now that the display is open, we can merge in the
+ * XA_RESOURCE_MANAGER rdb entry
+ */
+ if (XGetWindowProperty(dpy,
+ RootWindow(dpy,DefaultScreen(dpy)),
+ XA_RESOURCE_MANAGER,
+ 0,
+ (int)(((unsigned)~0)>>1),
+ 0,
+ XA_STRING,
+ &typeA,
+ &format,
+ &nitems,
+ &bytes,
+ (unsigned char**)&prop) == Success && typeA != None) {
+ if (format != 8) {
+ fprintf(stderr,"xbusy: warning: your RESOURCE MANAGER property is not an 8-bit string!\n");
+ goto cont_xdefault;
+ }
+ rmdb = XrmGetStringDatabase(prop);
+ XrmMergeDatabases(db,&rmdb);
+ XFree(prop);
+ db = rmdb;
+ }
+cont_xdefault:
+ {
+ char *getenv();
+ char *home = getenv("HOME");
+ char buf[MAXPATHLEN];
+ XrmDatabase xdefaults;
+ if (home) {
+ strcpy(buf,home);
+ strcat(buf,"/.Xdefaults");
+ xdefaults = XrmGetFileDatabase(buf);
+ if (xdefaults) {
+ XrmMergeDatabases(db,&xdefaults);
+ db = xdefaults;
+ }
+ }
+ }
+// if (RSRCSTR(".console",".Console")) {
+// strcpy(console,(char *)val.addr);
+// }
+ if (RSRCSTR(".poll",".Poll")) {
+ poll = atoi((char *)val.addr);
+ }
+ if (RSRCSTR(".error",".Error")) {
+ max_elapsed_msec = 1000 * atoi((char *)val.addr);
+ }
+ if (RSRCSTR(".sync",".Sync")) {
+ update_clock_ivl = 1000 * atoi((char *)val.addr);
+ }
+ if (RSRCSTR(".wcheck",".Wcheck")) {
+ update_win_ivl = 1000 * atoi((char *)val.addr);
+ }
+ if (RSRC(".nomouse",".NoMouse")) {
+ nomouse = 1;
+D((stderr,"nomouse\n"));
+ }
+ if (RSRC(".nodaemon",".NoDaemon")) {
+ nodaemon = 1;
+D((stderr,"nodaemon\n"));
+ }
+
+ if (!nodaemon) {
+ if (-1 == daemon(0, 0)) {
+ fprintf(stderr, "xbusy: cannot go background\n");
+ exit(1);
+ }
+ }
+ syslog(LOG_INFO, "starting");
+
+ XSetErrorHandler(ignore);
+
+ FD_ZERO(&in_fd_init);
+ Xfd = ConnectionNumber(dpy);
+ FD_SET(Xfd,&in_fd_init);
+ recurse_win(dpy,RootWindow(dpy,DefaultScreen(dpy)),nomouse);
+D((stderr,"looping\n"));
+ elapsed_mseconds = 0;
+ update_clock_mseconds = 0;
+ update_win_mseconds = 0;
+ get_time = 1;
+ time_of_server_base_valid = 0;
+ kezdes = time(NULL);
+ (void) signal(SIGTSTP,hide);
+ (void) signal(SIGCONT,cont);
+ (void) signal(SIGUSR1,fake);
+ (void) signal(SIGHUP,kampec);
+ (void) signal(SIGINT,kampec);
+ (void) signal(SIGTERM,kampec);
+ for (;;) {
+ in_fds = in_fd_init;
+ if (state != STATE_HIDE) time_out.tv_sec = poll;
+ else time_out.tv_sec = HIDE_POLL;
+ time_out.tv_usec = 0;
+ orig_timeout = time_out.tv_sec;
+ errno = 0;
+ if (select(Xfd+1,&in_fds,(fd_set *) 0, (fd_set *) 0,&time_out) == -1 && errno != EINTR) {
+ perror("xbusy");
+ fprintf(stderr,"xbusy: select failed\n");
+ exit(1);
+ }
+ if (errno == EINTR) {
+ get_time = 1;
+ /*
+ * Kernel may or may not modify the time_out value,
+ * so we could lose time here. This only happens
+ * when we get a signal, however, so is not a big deal.
+ */
+ elapsed = 1000 * (orig_timeout - time_out.tv_sec);
+ current_time += elapsed;
+ } else if (FD_ISSET(Xfd,&in_fds)) {
+D((stderr,"normal ev proc\n"));
+ XNextEvent(dpy,&ev);
+ /* check for more */
+ while (XPending(dpy)) {
+ XNextEvent(dpy,&ev);
+ }
+ key = kev->time;
+ if (get_time) {
+ get_time = 0;
+ (void) gettimeofday(&time_of_server_base,(struct timezone *) 0);
+ elapsed_mseconds = max_elapsed_msec + 1;
+ /* force an update */
+ current_time = key;
+ server_base = current_time;
+ time_of_server_base_valid = 1;
+ }
+ elapsed = key - current_time;
+ current_time = key;
+ if (!kemeny_munka) {
+ kemeny_munka = 1;
+ kezdes = time(NULL);
+ }
+ } else {
+ elapsed = 1000 * orig_timeout;
+ current_time += elapsed;
+ if (kemeny_munka) {
+ time_t munkaido = time(NULL) - kezdes - orig_timeout;
+ syslog(LOG_INFO,
+ "%d seconds of hard work confirmed",
+ munkaido);
+ kemeny_munka = 0;
+ }
+ }
+ /*
+ * current_time == key iff got an keypress (poll>0)
+ * otherwise, current_time > key
+ */
+
+ /* update timers */
+ elapsed_mseconds += elapsed;
+ update_clock_mseconds += elapsed;
+ update_win_mseconds += elapsed;
+
+ /* check expiration */
+ if (update_win_mseconds > update_win_ivl) {
+ update_win_mseconds = 0;
+ recurse_win(dpy,RootWindow(dpy,DefaultScreen(dpy)),nomouse);
+ }
+ if (update_clock_mseconds > update_clock_ivl) {
+ update_clock_mseconds = 0;
+ get_time = 1;
+ }
+D((stderr,"elapsed_mseconds=%d,max_elapsed_msec=%d\n", elapsed_mseconds, max_elapsed_msec));
+ if (elapsed_mseconds > max_elapsed_msec && time_of_server_base_valid) {
+ elapsed_mseconds = 0;
+ switch (state) {
+ case STATE_NORM:
+D((stderr,"current_time=%d,key=%d\n", current_time, key));
+ if (current_time == key) {
+ keytime.tv_sec = (key - server_base)/1000 + time_of_server_base.tv_sec;
+D((stderr,"keytime=%d\n", keytime.tv_sec));
+ keytime.tv_usec = 0; /* ignore it */
+// kissg update(console,&keytime);
+ }
+ break;
+ case STATE_BUSY:
+ /*
+ * Presumably, we will not get any events
+ * from the server, so we can not periodically
+ * resynchronize our timers. They still run
+ * and give us relative time, ....
+ */
+ (void) gettimeofday(&keytime,(struct timezone *) 0);
+ keytime.tv_usec = 0; /* ignore it */
+// kissg update(console,&keytime);
+ break;
+ case STATE_HIDE:
+ break;
+ }
+ }
+ }
+}
+
+/* since utimes has to go to the fs, we want to avoid it if poss. */
+
+#if 0 //kissg
+update(file,now)
+char *file;
+struct timeval *now;
+{
+ struct timeval t[2];
+ t[1] = t[0] = *now;
+ if (utimes(file,t) < 0) {
+ perror(file);
+ }
+}
+#endif
+
+recurse_win(dpy,w,nomouse)
+Display *dpy;
+Window w;
+int nomouse;
+{
+ Window *child_list, root, parent;
+ int nchild;
+ XWindowAttributes attr;
+ int mask;
+
+ mask = KeyPressMask;
+ if (!nomouse) {
+ mask |= PointerMotionMask;
+ }
+ /*
+ * if nobody else is interested in keypresses,
+ * this may be a subwindow the keypresses of which should
+ * propagate to a parent window where it is handled.
+ */
+ if (XGetWindowAttributes(dpy,w,&attr)) {
+ if (attr.all_event_masks & mask) {
+ XSelectInput(dpy,w,mask);
+ } else D((stderr,"nobody interested in %d %X\n",w,w));
+ if (XQueryTree(dpy,w,&root,&parent,&child_list,&nchild)) {
+ while (--nchild >= 0) {
+ recurse_win(dpy,child_list[nchild]);
+ }
+ XFree((char *) child_list);
+ } else D((stderr,"can not query %d %X\n",w,w));
+ }
+ else D((stderr,"No attr for window %d %X\n",w,w));
+}
+
+ignore(dpy,err_ev)
+Display *dpy;
+XErrorEvent *err_ev;
+{
+ ;
+}
+
+locase(str)
+char *str;
+{
+ char ch;
+ while (ch = *str) {
+ if (isupper(ch)) *str = ch + ('a'-(int)'A');
+ ++str;
+ }
+}
+
+char *tmp_string(name,prop)
+char *name,*prop;
+{
+ static char buf[MAXRESOURCE];
+
+ strcpy(buf,name);
+ strcat(buf,prop);
+ return buf;
+}
+
+char *Tmp_string(name,prop)
+char *name,*prop;
+{
+ static char buf[MAXRESOURCE];
+
+ strcpy(buf,name);
+ strcat(buf,prop);
+ buf[0] += 'A' - (int) 'a';
+ return buf;
+}
diff -urw --new-file /tmp/xidle/xidle.c ./xidle.c
--- /tmp/xidle/xidle.c Fri Aug 8 23:07:53 1997
+++ ./xidle.c Thu Jan 1 01:00:00 1970
@@ -1,391 +0,0 @@
-/*
- * Copyright (C) 1990, Bennet Yee. You may freely distribute this code as long
- * as this notice is intact. If you make any modifications in your
- * distribution, you must clearly document them. If you distribute this code
- * or any derivative thereof, it must be given at no charge to all parties
- * on terms identical to those prescribed herein. All distributions must
- * contain source code.
- *
- * This software is provided with absolutely no warranty.
- *
- * If you have questions, you can contact me at bsy@cs.cmu.edu
- */
-#ifndef lint
- static char copyright[] = "\n\
-Copyright (C) 1990, Bennet Yee. You may freely distribute this code as long\n\
-as this notice is intact. If you make any modifications in your\n\
-distribution, you must clearly document them. If you distribute this code\n\
-or any derivative thereof, it must be provided at no charge to all parties\n\
-on terms identical to those prescribed herein. All distributions must\n\
-contain source code.\n\
-\n\
-This software is provided with absolutely no warranty.\n\
-";
-#endif /* lint */
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/Xresource.h>
-#include <X11/Xutil.h>
-#include <X11/cursorfont.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/time.h>
-
-extern int errno;
-
-#ifdef DEBUG
-#define D(x) fprintf x
-#define D2(x) fprintf x
-#define D3(x) fprintf x
-#else
-#define D(x)
-#define D2(x)
-#define D3(x)
-#endif
-
-#define MAXDISPLAY 1024
-#define MAXNAME 1024
-#define MAXRESOURCE 1024
-
-#define HIDE_POLL 50 /* < one minute */
-#define POLL 60
-#define MAX_ELAPSED_MSEC (5*1000)
-#define UPDATE_CLOCK_IVL (5*60*1000)
-#define UPDATE_WIN_IVL (60*1000)
-
-long poll = POLL;
-Time max_elapsed_msec = MAX_ELAPSED_MSEC,
- update_clock_ivl = UPDATE_CLOCK_IVL,
- update_win_ivl = UPDATE_WIN_IVL;
-
-XrmOptionDescRec tbl[] = {
-{"-display",".display",XrmoptionSepArg, (caddr_t) ""},
-{"-name",".name",XrmoptionSepArg, (caddr_t) "xidle"},
-{"-console",".console",XrmoptionSepArg, (caddr_t) "/dev/console"},
-{"-poll",".poll",XrmoptionSepArg, (caddr_t) NULL},
-{"-error",".error",XrmoptionSepArg, (caddr_t) NULL},
-{"-sync",".sync",XrmoptionSepArg, (caddr_t) NULL},
-{"-wcheck",".win",XrmoptionSepArg, (caddr_t) NULL},
-{"-xrm",NULL,XrmoptionResArg, (caddr_t) NULL},
-{"-nomouse",".nomouse",XrmoptionNoArg, (caddr_t) "on"}
-};
-
-char console[MAXPATHLEN] = "/dev/console";
-
-usage()
-{
- fprintf(stderr,"Usage: xidle [-display dpy] [-name n] [-xrm rm] [-poll N] [-error N] [-sync N] [-wcheck N]\n");
-}
-
-#define STATE_NORM 0
-#define STATE_HIDE 1
-#define STATE_BUSY 2
-
-int state = STATE_NORM;
-
-hide(){ state = STATE_HIDE;}
-cont(){ state = STATE_NORM;}
-fake(){ state = STATE_BUSY;}
-
-main(ac,av)
-int ac;
-char **av;
-{
- Display *dpy;
- XEvent ev;
- XKeyPressedEvent *kev = (XKeyPressedEvent *) &ev;
- XrmDatabase db, rmdb;
- char *type, display[MAXDISPLAY], name[MAXNAME];
- XrmValue val;
- char *tmp_string(), *Tmp_string();
- Atom typeA;
- int format;
- unsigned long nitems, bytes;
- char *prop;
- fd_set in_fds, in_fd_init;
- int Xfd;
- struct timeval time_out, time_of_server_base, keytime;
- int get_time, time_of_server_base_valid,
- orig_timeout;
- Time current_time, key, server_base, elapsed,
- elapsed_mseconds, update_clock_mseconds,
- update_win_mseconds;
- int ignore();
- int nomouse;
-// (*signal())();
-
-D3((stderr,"initializing RM\n"));
- XrmInitialize();
- db = (XrmDatabase) 0;
-D3((stderr,"parsing cmds\n"));
- XrmParseCommand(&db,tbl,sizeof tbl/sizeof tbl[0],"xidle",&ac,av);
-D3((stderr,"db points to %X\n",db));
- if (ac != 1) {
- fprintf(stderr,"Option not understood: %s\n",av[1]);
- usage();
- exit(1);
- }
- strcpy(name,"xidle");
- if (XrmGetResource(db,tmp_string(name,".name"),Tmp_string(name,".Name"),&type,&val) && !strcmp(type,"String")) {
- strcpy(name,(char *)val.addr);
- }
- locase(name);
- strcpy(display,"");
- if (XrmGetResource(db,tmp_string(name,".display"),Tmp_string(name,".Display"),&type,&val) && !strcmp(type,"String")) {
- strcpy(display,(char *)val.addr);
- }
- dpy = XOpenDisplay(display);
- if (!dpy) {
- fprintf(stderr,"No display\n");
- exit(1);
- }
-
- /*
- * now that the display is open, we can merge in the
- * XA_RESOURCE_MANAGER rdb entry
- */
- if (XGetWindowProperty(dpy,RootWindow(dpy,DefaultScreen(dpy)),XA_RESOURCE_MANAGER,0,(int)(((unsigned)~0)>>1),0,XA_STRING,&typeA,&format,&nitems,&bytes,&prop) == Success && typeA != None) {
- if (format != 8) {
- fprintf(stderr,"xidle: warning: your RESOURCE MANAGER property is not an 8-bit string!\n");
- goto cont_xdefault;
- }
- rmdb = XrmGetStringDatabase(prop);
- XrmMergeDatabases(db,&rmdb);
- XFree(prop);
- db = rmdb;
- }
-cont_xdefault:
- {
- char *getenv();
- char *home = getenv("HOME");
- char buf[MAXPATHLEN];
- XrmDatabase xdefaults;
- if (home) {
- strcpy(buf,home);
- strcat(buf,"/.Xdefaults");
- xdefaults = XrmGetFileDatabase(buf);
- if (xdefaults) {
- XrmMergeDatabases(db,&xdefaults);
- db = xdefaults;
- }
- }
- }
- if (XrmGetResource(db,tmp_string(name,".console"),Tmp_string(name,".Console"),&type,&val) && !strcmp(type,"String")) {
- strcpy(console,(char *)val.addr);
- }
- if (XrmGetResource(db,tmp_string(name,".poll"),Tmp_string(name,".Poll"),&type,&val) && !strcmp(type,"String")) {
- poll = atoi((char *)val.addr);
- }
- if (XrmGetResource(db,tmp_string(name,".error"),Tmp_string(name,".Error"),&type,&val) && !strcmp(type,"String")) {
- max_elapsed_msec = 1000 * atoi((char *)val.addr);
- }
- if (XrmGetResource(db,tmp_string(name,".sync"),Tmp_string(name,".Sync"),&type,&val) && !strcmp(type,"String")) {
- update_clock_ivl = 1000 * atoi((char *)val.addr);
- }
- if (XrmGetResource(db,tmp_string(name,".wcheck"),Tmp_string(name,".Wcheck"),&type,&val) && !strcmp(type,"String")) {
- update_win_ivl = 1000 * atoi((char *)val.addr);
- }
- nomouse = 0;
- if (XrmGetResource(db,tmp_string(name,".nomouse"),Tmp_string(name,".NoMouse"),&type,&val)) {
- nomouse = 1;
-D((stderr,"nomouse\n"));
- }
-
- XSetErrorHandler(ignore);
-
- FD_ZERO(&in_fd_init);
- Xfd = ConnectionNumber(dpy);
- FD_SET(Xfd,&in_fd_init);
- recurse_win(dpy,RootWindow(dpy,DefaultScreen(dpy)),nomouse);
-D((stderr,"looping\n"));
- elapsed_mseconds = 0;
- update_clock_mseconds = 0;
- update_win_mseconds = 0;
- get_time = 1;
- time_of_server_base_valid = 0;
- (void) signal(SIGTSTP,hide);
- (void) signal(SIGCONT,cont);
- (void) signal(SIGUSR1,fake);
- for (;;) {
- in_fds = in_fd_init;
- if (state != STATE_HIDE) time_out.tv_sec = poll;
- else time_out.tv_sec = HIDE_POLL;
- time_out.tv_usec = 0;
- orig_timeout = time_out.tv_sec;
- errno = 0;
- if (select(Xfd+1,&in_fds,(fd_set *) 0, (fd_set *) 0,&time_out) == -1 && errno != EINTR) {
- perror("xidle");
- fprintf(stderr,"xidle: select failed\n");
- exit(1);
- }
- if (errno == EINTR) {
- get_time = 1;
- /*
- * Kernel may or may not modify the time_out value,
- * so we could lose time here. This only happens
- * when we get a signal, however, so is not a big deal.
- */
- elapsed = 1000 * (orig_timeout - time_out.tv_sec);
- current_time += elapsed;
- } else if (FD_ISSET(Xfd,&in_fds)) {
-D((stderr,"normal ev proc\n"));
- XNextEvent(dpy,&ev);
- /* check for more */
- while (XPending(dpy)) {
- XNextEvent(dpy,&ev);
- }
- key = kev->time;
- if (get_time) {
- get_time = 0;
- (void) gettimeofday(&time_of_server_base,(struct timezone *) 0);
- elapsed_mseconds = max_elapsed_msec + 1;
- /* force an update */
- current_time = key;
- server_base = current_time;
- time_of_server_base_valid = 1;
- }
- elapsed = key - current_time;
- current_time = key;
- } else {
- elapsed = 1000 * orig_timeout;
- current_time += elapsed;
- }
- /*
- * current_time == key iff got an keypress (poll>0)
- * otherwise, current_time > key
- */
-
- /* update timers */
- elapsed_mseconds += elapsed;
- update_clock_mseconds += elapsed;
- update_win_mseconds += elapsed;
-
- /* check expiration */
- if (update_win_mseconds > update_win_ivl) {
- update_win_mseconds = 0;
- recurse_win(dpy,RootWindow(dpy,DefaultScreen(dpy)),nomouse);
- }
- if (update_clock_mseconds > update_clock_ivl) {
- update_clock_mseconds = 0;
- get_time = 1;
- }
-D((stderr,"elapsed_mseconds=%d,max_elapsed_msec=%d\n", elapsed_mseconds, max_elapsed_msec));
- if (elapsed_mseconds > max_elapsed_msec && time_of_server_base_valid) {
- elapsed_mseconds = 0;
- switch (state) {
- case STATE_NORM:
-D((stderr,"current_time=%d,key=%d\n", current_time, key));
- if (current_time == key) {
- keytime.tv_sec = (key - server_base)/1000 + time_of_server_base.tv_sec;
-D((stderr,"keytime=%d\n", keytime.tv_sec));
- keytime.tv_usec = 0; /* ignore it */
- update(console,&keytime);
- }
- break;
- case STATE_BUSY:
- /*
- * Presumably, we will not get any events
- * from the server, so we can not periodically
- * resynchronize our timers. They still run
- * and give us relative time, ....
- */
- (void) gettimeofday(&keytime.tv_sec,(struct timezone *) 0);
- keytime.tv_usec = 0; /* ignore it */
- update(console,&keytime);
- break;
- case STATE_HIDE:
- break;
- }
- }
- }
-}
-
-/* since utimes has to go to the fs, we want to avoid it if poss. */
-
-update(file,now)
-char *file;
-struct timeval *now;
-{
- struct timeval t[2];
- t[1] = t[0] = *now;
- if (utimes(file,t) < 0) {
- perror(file);
- }
-}
-
-recurse_win(dpy,w,nomouse)
-Display *dpy;
-Window w;
-int nomouse;
-{
- Window *child_list, root, parent;
- int nchild;
- XWindowAttributes attr;
- int mask;
-
- mask = KeyPressMask;
- if (!nomouse) {
- mask |= PointerMotionMask;
- }
- /*
- * if nobody else is interested in keypresses,
- * this may be a subwindow the keypresses of which should
- * propagate to a parent window where it is handled.
- */
- if (XGetWindowAttributes(dpy,w,&attr)) {
- if (attr.all_event_masks & mask) {
- XSelectInput(dpy,w,mask);
- } else D((stderr,"nobody interested in %d %X\n",w,w));
- if (XQueryTree(dpy,w,&root,&parent,&child_list,&nchild)) {
- while (--nchild >= 0) {
- recurse_win(dpy,child_list[nchild]);
- }
- XFree((char *) child_list);
- } else D((stderr,"can not query %d %X\n",w,w));
- }
- else D((stderr,"No attr for window %d %X\n",w,w));
-}
-
-ignore(dpy,err_ev)
-Display *dpy;
-XErrorEvent *err_ev;
-{
- ;
-}
-
-locase(str)
-char *str;
-{
- char ch;
- while (ch = *str) {
- if (isupper(ch)) *str = ch + ('a'-(int)'A');
- ++str;
- }
-}
-
-char *tmp_string(name,prop)
-char *name,*prop;
-{
- static char buf[MAXRESOURCE];
-
- strcpy(buf,name);
- strcat(buf,prop);
- return buf;
-}
-
-char *Tmp_string(name,prop)
-char *name,*prop;
-{
- static char buf[MAXRESOURCE];
-
- strcpy(buf,name);
- strcat(buf,prop);
- buf[0] += 'A' - (int) 'a';
- return buf;
-}