1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

Make inotify optional

This time keeping the ability to fall back to the old polling method.
This commit is contained in:
Tamas TEVESZ
2010-03-18 19:18:18 +01:00
committed by Carlos R. Mafra
parent 118a93808a
commit c7868fa405
10 changed files with 118 additions and 12 deletions

View File

@@ -39,6 +39,11 @@ static void synchronizeUserDefaults(void *foo);
extern char *WMGetApplicationName(); extern char *WMGetApplicationName();
#define DEFAULTS_DIR "/Defaults" #define DEFAULTS_DIR "/Defaults"
#ifndef HAVE_INOTIFY
/* Check defaults database for changes every this many milliseconds */
/* XXX: this is shared with src/ stuff, put it in some common header */
#define UD_SYNC_INTERVAL 2000
#endif
char *wusergnusteppath() char *wusergnusteppath()
{ {
@@ -133,6 +138,19 @@ static void synchronizeUserDefaults(void *foo)
} }
} }
#ifndef HAVE_INOTIFY
static void addSynchronizeTimerHandler(void)
{
static Bool initialized = False;
if (!initialized) {
WMAddPersistentTimerHandler(UD_SYNC_INTERVAL,
synchronizeUserDefaults, NULL);
initialized = True;
}
}
#endif
void WMEnableUDPeriodicSynchronization(WMUserDefaults * database, Bool enable) void WMEnableUDPeriodicSynchronization(WMUserDefaults * database, Bool enable)
{ {
database->dontSync = !enable; database->dontSync = !enable;
@@ -309,6 +327,9 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
defaults->next = sharedUserDefaults; defaults->next = sharedUserDefaults;
sharedUserDefaults = defaults; sharedUserDefaults = defaults;
#ifndef HAVE_INOTIFY
addSynchronizeTimerHandler();
#endif
registerSaveOnExit(); registerSaveOnExit();
return defaults; return defaults;
@@ -382,6 +403,9 @@ WMUserDefaults *WMGetDefaultsFromPath(char *path)
defaults->next = sharedUserDefaults; defaults->next = sharedUserDefaults;
sharedUserDefaults = defaults; sharedUserDefaults = defaults;
#ifndef HAVE_INOTIFY
addSynchronizeTimerHandler();
#endif
registerSaveOnExit(); registerSaveOnExit();
return defaults; return defaults;

View File

@@ -128,7 +128,9 @@ if test "x$HAVEDL" = xyes; then
AC_CHECK_HEADERS(dlfcn.h) AC_CHECK_HEADERS(dlfcn.h)
fi fi
dnl Check for inotify
dnl =================
AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify))
dnl Check CPP dnl Check CPP
dnl ========= dnl =========

View File

@@ -425,6 +425,9 @@ typedef struct WPreferences {
unsigned int noautolaunch:1; /* don't autolaunch apps */ unsigned int noautolaunch:1; /* don't autolaunch apps */
unsigned int norestore:1; /* don't restore session */ unsigned int norestore:1; /* don't restore session */
unsigned int create_stdcmap:1; /* create std colormap */ unsigned int create_stdcmap:1; /* create std colormap */
#ifndef HAVE_INOTIFY
unsigned int nopolling:1; /* don't poll the defaults database for changes */
#endif
unsigned int restarting:2; unsigned int restarting:2;
} flags; /* internal flags */ } flags; /* internal flags */
} WPreferences; } WPreferences;

View File

@@ -897,7 +897,7 @@ void wReadStaticDefaults(WMPropList * dict)
} }
} }
void wDefaultsCheckDomains(void) void wDefaultsCheckDomains(void* arg)
{ {
WScreen *scr; WScreen *scr;
struct stat stbuf; struct stat stbuf;
@@ -1016,6 +1016,10 @@ void wDefaultsCheckDomains(void)
} }
WDRootMenu->timestamp = stbuf.st_mtime; WDRootMenu->timestamp = stbuf.st_mtime;
} }
#ifndef HAVE_INOTIFY
if (!arg)
WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
#endif
} }
void wReadDefaults(WScreen * scr, WMPropList * new_dict) void wReadDefaults(WScreen * scr, WMPropList * new_dict)

View File

@@ -46,7 +46,7 @@ void wDefaultUpdateIcons(WScreen *scr);
void wReadStaticDefaults(WMPropList *dict); void wReadStaticDefaults(WMPropList *dict);
void wDefaultsCheckDomains(void); void wDefaultsCheckDomains(void *arg);
void wSaveDefaults(WScreen *scr); void wSaveDefaults(WScreen *scr);

View File

@@ -20,9 +20,12 @@
* USA. * USA.
*/ */
#include <sys/inotify.h>
#include "wconfig.h" #include "wconfig.h"
#ifdef HAVE_INOTIFY
#include <sys/inotify.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -198,7 +201,7 @@ void DispatchEvent(XEvent * event)
Restart(NULL, True); Restart(NULL, True);
} else if (WCHECK_STATE(WSTATE_NEED_REREAD)) { } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
WCHANGE_STATE(WSTATE_NORMAL); WCHANGE_STATE(WSTATE_NORMAL);
wDefaultsCheckDomains(); wDefaultsCheckDomains(NULL);
} }
/* for the case that all that is wanted to be dispatched is /* for the case that all that is wanted to be dispatched is
@@ -282,6 +285,7 @@ void DispatchEvent(XEvent * event)
} }
} }
#ifdef HAVE_INOTIFY
/* /*
*---------------------------------------------------------------------- *----------------------------------------------------------------------
* inotifyHandleEvents- * inotifyHandleEvents-
@@ -299,7 +303,7 @@ void DispatchEvent(XEvent * event)
#define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5) #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
void inotifyHandleEvents(int fd, int wd) void inotifyHandleEvents(int fd, int wd)
{ {
extern void wDefaultsCheckDomains(void); extern void wDefaultsCheckDomains(void *);
ssize_t eventQLength, i = 0; ssize_t eventQLength, i = 0;
char buff[BUFF_SIZE] = { 0 }; char buff[BUFF_SIZE] = { 0 };
/* Check config only once per read of the event queue */ /* Check config only once per read of the event queue */
@@ -335,13 +339,14 @@ void inotifyHandleEvents(int fd, int wd)
} }
if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) { if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
fprintf(stdout, "wmaker: reading config files in defaults database.\n"); fprintf(stdout, "wmaker: reading config files in defaults database.\n");
wDefaultsCheckDomains(); wDefaultsCheckDomains(NULL);
} }
/* move to next event in the buffer */ /* move to next event in the buffer */
i += sizeof(struct inotify_event) + pevent->len; i += sizeof(struct inotify_event) + pevent->len;
} }
} }
#endif /* HAVE_INOTIFY */
/* /*
*---------------------------------------------------------------------- *----------------------------------------------------------------------
@@ -359,6 +364,7 @@ void inotifyHandleEvents(int fd, int wd)
void EventLoop(void) void EventLoop(void)
{ {
XEvent event; XEvent event;
#ifdef HAVE_INOTIFY
extern int inotifyFD; extern int inotifyFD;
extern int inotifyWD; extern int inotifyWD;
struct timeval time; struct timeval time;
@@ -367,12 +373,13 @@ void EventLoop(void)
if (inotifyFD < 0 || inotifyWD < 0) if (inotifyFD < 0 || inotifyWD < 0)
retVal = -1; retVal = -1;
#endif
for (;;) { for (;;) {
WMNextEvent(dpy, &event); /* Blocks here */ WMNextEvent(dpy, &event); /* Blocks here */
WMHandleEvent(&event); WMHandleEvent(&event);
#ifdef HAVE_INOTIFY
if (retVal != -1) { if (retVal != -1) {
time.tv_sec = 0; time.tv_sec = 0;
time.tv_usec = 0; time.tv_usec = 0;
@@ -392,6 +399,7 @@ void EventLoop(void)
if (FD_ISSET(inotifyFD, &rfds)) if (FD_ISSET(inotifyFD, &rfds))
inotifyHandleEvents(inotifyFD, inotifyWD); inotifyHandleEvents(inotifyFD, inotifyWD);
} }
#endif
} }
} }
@@ -918,7 +926,7 @@ static void handleClientMessage(XEvent * event)
} }
} else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) { } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
wDefaultsCheckDomains(); wDefaultsCheckDomains(NULL);
} else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) { } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
WApplication *wapp; WApplication *wapp;

View File

@@ -19,10 +19,12 @@
* USA. * USA.
*/ */
#include <sys/inotify.h>
#include "wconfig.h" #include "wconfig.h"
#ifdef HAVE_INOTIFY
#include <sys/inotify.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -67,8 +69,10 @@ char *ProgName;
unsigned int ValidModMask = 0xff; unsigned int ValidModMask = 0xff;
#ifdef HAVE_INOTIFY
int inotifyFD; int inotifyFD;
int inotifyWD; int inotifyWD;
#endif
/* locale to use. NULL==POSIX or C */ /* locale to use. NULL==POSIX or C */
char *Locale = NULL; char *Locale = NULL;
@@ -436,6 +440,9 @@ void print_help()
puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals")); puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
puts(_(" --visual-id visualid visual id of visual to use")); puts(_(" --visual-id visualid visual id of visual to use"));
puts(_(" --static do not update or save configurations")); puts(_(" --static do not update or save configurations"));
#ifndef HAVE_INOTIFY
puts(_(" --no-polling do not periodically check for configuration updates"));
#endif
puts(_(" --version print version and exit")); puts(_(" --version print version and exit"));
puts(_(" --help show this message")); puts(_(" --help show this message"));
} }
@@ -460,6 +467,7 @@ void check_defaults()
wfree(path); wfree(path);
} }
#ifdef HAVE_INOTIFY
/* /*
* Add watch here, used to notify if configuration * Add watch here, used to notify if configuration
* files have changed, using linux kernel inotify mechanism * files have changed, using linux kernel inotify mechanism
@@ -490,6 +498,7 @@ static void inotifyWatchConfig()
} }
wfree(watchPath); wfree(watchPath);
} }
#endif /* HAVE_INOTIFY */
static void execInitScript() static void execInitScript()
{ {
@@ -661,7 +670,11 @@ static int real_main(int argc, char **argv)
wwarning(_("bad value for visualid: \"%s\""), argv[i]); wwarning(_("bad value for visualid: \"%s\""), argv[i]);
exit(0); exit(0);
} }
} else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0) { } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
#ifndef HAVE_INOTIFY
|| strcmp(argv[i], "--no-polling") == 0
#endif
) {
wPreferences.flags.noupdates = 1; wPreferences.flags.noupdates = 1;
} else if (strcmp(argv[i], "--help") == 0) { } else if (strcmp(argv[i], "--help") == 0) {
print_help(); print_help();
@@ -762,7 +775,9 @@ static int real_main(int argc, char **argv)
multiHead = False; multiHead = False;
execInitScript(); execInitScript();
#ifdef HAVE_INOTIFY
inotifyWatchConfig(); inotifyWatchConfig();
#endif
EventLoop(); EventLoop();
return -1; return -1;
} }

View File

@@ -56,7 +56,9 @@ static void wipeDesktop(WScreen * scr);
void Shutdown(WShutdownMode mode) void Shutdown(WShutdownMode mode)
{ {
int i; int i;
#ifdef HAVE_INOTIFY
extern int inotifyFD; extern int inotifyFD;
#endif
switch (mode) { switch (mode) {
case WSLogoutMode: case WSLogoutMode:
@@ -64,7 +66,9 @@ void Shutdown(WShutdownMode mode)
case WSExitMode: case WSExitMode:
/* if there is no session manager, send SAVE_YOURSELF to /* if there is no session manager, send SAVE_YOURSELF to
* the clients */ * the clients */
#ifdef HAVE_INOTIFY
close(inotifyFD); close(inotifyFD);
#endif
for (i = 0; i < wScreenCount; i++) { for (i = 0; i < wScreenCount; i++) {
WScreen *scr; WScreen *scr;
@@ -92,7 +96,9 @@ void Shutdown(WShutdownMode mode)
for (i = 0; i < wScreenCount; i++) { for (i = 0; i < wScreenCount; i++) {
WScreen *scr; WScreen *scr;
#ifdef HAVE_INOTIFY
close(inotifyFD); close(inotifyFD);
#endif
scr = wScreenWithNumber(i); scr = wScreenWithNumber(i);
if (scr) { if (scr) {
if (scr->helper_pid) if (scr->helper_pid)

View File

@@ -134,6 +134,11 @@ extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
/* cursors */ /* cursors */
extern Cursor wCursor[WCUR_LAST]; extern Cursor wCursor[WCUR_LAST];
#ifndef HAVE_INOTIFY
/* special flags */
extern char WDelayedActionSet;
#endif
/***** Local *****/ /***** Local *****/
static WScreen **wScreen = NULL; static WScreen **wScreen = NULL;
@@ -187,6 +192,28 @@ static int handleXIO(Display * xio_dpy)
return 0; return 0;
} }
#ifndef HAVE_INOTIFY
/*
*----------------------------------------------------------------------
* delayedAction-
* Action to be executed after the signal() handler is exited.
*----------------------------------------------------------------------
*/
static void delayedAction(void *cdata)
{
if (WDelayedActionSet == 0)
return;
WDelayedActionSet--;
/*
* Make the event dispatcher do whatever it needs to do,
* including handling zombie processes, restart and exit
* signals.
*/
DispatchEvent(NULL);
}
#endif
/* /*
*---------------------------------------------------------------------- *----------------------------------------------------------------------
* handleExitSig-- * handleExitSig--
@@ -574,6 +601,11 @@ void StartUp(Bool defaultScreenOnly)
XFreePixmap(dpy, cur); XFreePixmap(dpy, cur);
} }
#ifndef HAVE_INOTIFY
/* signal handler stuff that gets called when a signal is caught */
WMAddPersistentTimerHandler(500, delayedAction, NULL);
#endif
/* emergency exit... */ /* emergency exit... */
sig_action.sa_handler = handleSig; sig_action.sa_handler = handleSig;
sigemptyset(&sig_action.sa_mask); sigemptyset(&sig_action.sa_mask);
@@ -757,6 +789,13 @@ void StartUp(Bool defaultScreenOnly)
Exit(1); Exit(1);
} }
#ifndef HAVE_INOTIFY
if (!wPreferences.flags.nopolling && !wPreferences.flags.noupdates) {
/* setup defaults file polling */
WMAddTimerHandler(3000, wDefaultsCheckDomains, NULL);
}
#endif
} }
static Bool windowInList(Window window, Window * list, int count) static Bool windowInList(Window window, Window * list, int count)

View File

@@ -347,6 +347,11 @@
/* max width of window title in window list */ /* max width of window title in window list */
#define MAX_WINDOWLIST_WIDTH 160 #define MAX_WINDOWLIST_WIDTH 160
#ifndef HAVE_INOTIFY
/* Check defaults database for changes every this many milliseconds */
#define DEFAULTS_CHECK_INTERVAL 2000
#endif
#define KEY_CONTROL_WINDOW_WEIGHT 1 #define KEY_CONTROL_WINDOW_WEIGHT 1
/* if your keyboard don't have arrow keys */ /* if your keyboard don't have arrow keys */