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:
committed by
Carlos R. Mafra
parent
118a93808a
commit
c7868fa405
@@ -39,6 +39,11 @@ static void synchronizeUserDefaults(void *foo);
|
||||
extern char *WMGetApplicationName();
|
||||
|
||||
#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()
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
database->dontSync = !enable;
|
||||
@@ -309,6 +327,9 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
|
||||
defaults->next = sharedUserDefaults;
|
||||
sharedUserDefaults = defaults;
|
||||
|
||||
#ifndef HAVE_INOTIFY
|
||||
addSynchronizeTimerHandler();
|
||||
#endif
|
||||
registerSaveOnExit();
|
||||
|
||||
return defaults;
|
||||
@@ -382,6 +403,9 @@ WMUserDefaults *WMGetDefaultsFromPath(char *path)
|
||||
defaults->next = sharedUserDefaults;
|
||||
sharedUserDefaults = defaults;
|
||||
|
||||
#ifndef HAVE_INOTIFY
|
||||
addSynchronizeTimerHandler();
|
||||
#endif
|
||||
registerSaveOnExit();
|
||||
|
||||
return defaults;
|
||||
|
||||
@@ -128,7 +128,9 @@ if test "x$HAVEDL" = xyes; then
|
||||
AC_CHECK_HEADERS(dlfcn.h)
|
||||
fi
|
||||
|
||||
|
||||
dnl Check for inotify
|
||||
dnl =================
|
||||
AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify))
|
||||
|
||||
dnl Check CPP
|
||||
dnl =========
|
||||
|
||||
@@ -425,6 +425,9 @@ typedef struct WPreferences {
|
||||
unsigned int noautolaunch:1; /* don't autolaunch apps */
|
||||
unsigned int norestore:1; /* don't restore session */
|
||||
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;
|
||||
} flags; /* internal flags */
|
||||
} WPreferences;
|
||||
|
||||
@@ -897,7 +897,7 @@ void wReadStaticDefaults(WMPropList * dict)
|
||||
}
|
||||
}
|
||||
|
||||
void wDefaultsCheckDomains(void)
|
||||
void wDefaultsCheckDomains(void* arg)
|
||||
{
|
||||
WScreen *scr;
|
||||
struct stat stbuf;
|
||||
@@ -1016,6 +1016,10 @@ void wDefaultsCheckDomains(void)
|
||||
}
|
||||
WDRootMenu->timestamp = stbuf.st_mtime;
|
||||
}
|
||||
#ifndef HAVE_INOTIFY
|
||||
if (!arg)
|
||||
WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wReadDefaults(WScreen * scr, WMPropList * new_dict)
|
||||
|
||||
@@ -46,7 +46,7 @@ void wDefaultUpdateIcons(WScreen *scr);
|
||||
|
||||
void wReadStaticDefaults(WMPropList *dict);
|
||||
|
||||
void wDefaultsCheckDomains(void);
|
||||
void wDefaultsCheckDomains(void *arg);
|
||||
|
||||
void wSaveDefaults(WScreen *scr);
|
||||
|
||||
|
||||
20
src/event.c
20
src/event.c
@@ -20,9 +20,12 @@
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#include <sys/inotify.h>
|
||||
#include "wconfig.h"
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
#include <sys/inotify.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -198,7 +201,7 @@ void DispatchEvent(XEvent * event)
|
||||
Restart(NULL, True);
|
||||
} else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
|
||||
WCHANGE_STATE(WSTATE_NORMAL);
|
||||
wDefaultsCheckDomains();
|
||||
wDefaultsCheckDomains(NULL);
|
||||
}
|
||||
|
||||
/* for the case that all that is wanted to be dispatched is
|
||||
@@ -282,6 +285,7 @@ void DispatchEvent(XEvent * event)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* inotifyHandleEvents-
|
||||
@@ -299,7 +303,7 @@ void DispatchEvent(XEvent * event)
|
||||
#define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
|
||||
void inotifyHandleEvents(int fd, int wd)
|
||||
{
|
||||
extern void wDefaultsCheckDomains(void);
|
||||
extern void wDefaultsCheckDomains(void *);
|
||||
ssize_t eventQLength, i = 0;
|
||||
char buff[BUFF_SIZE] = { 0 };
|
||||
/* 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) {
|
||||
fprintf(stdout, "wmaker: reading config files in defaults database.\n");
|
||||
wDefaultsCheckDomains();
|
||||
wDefaultsCheckDomains(NULL);
|
||||
}
|
||||
|
||||
/* move to next event in the buffer */
|
||||
i += sizeof(struct inotify_event) + pevent->len;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_INOTIFY */
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
@@ -359,6 +364,7 @@ void inotifyHandleEvents(int fd, int wd)
|
||||
void EventLoop(void)
|
||||
{
|
||||
XEvent event;
|
||||
#ifdef HAVE_INOTIFY
|
||||
extern int inotifyFD;
|
||||
extern int inotifyWD;
|
||||
struct timeval time;
|
||||
@@ -367,12 +373,13 @@ void EventLoop(void)
|
||||
|
||||
if (inotifyFD < 0 || inotifyWD < 0)
|
||||
retVal = -1;
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
|
||||
WMNextEvent(dpy, &event); /* Blocks here */
|
||||
WMHandleEvent(&event);
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
if (retVal != -1) {
|
||||
time.tv_sec = 0;
|
||||
time.tv_usec = 0;
|
||||
@@ -392,6 +399,7 @@ void EventLoop(void)
|
||||
if (FD_ISSET(inotifyFD, &rfds))
|
||||
inotifyHandleEvents(inotifyFD, inotifyWD);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,7 +926,7 @@ static void handleClientMessage(XEvent * event)
|
||||
}
|
||||
} else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
|
||||
|
||||
wDefaultsCheckDomains();
|
||||
wDefaultsCheckDomains(NULL);
|
||||
|
||||
} else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
|
||||
WApplication *wapp;
|
||||
|
||||
21
src/main.c
21
src/main.c
@@ -19,10 +19,12 @@
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#include <sys/inotify.h>
|
||||
|
||||
#include "wconfig.h"
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
#include <sys/inotify.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -67,8 +69,10 @@ char *ProgName;
|
||||
|
||||
unsigned int ValidModMask = 0xff;
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
int inotifyFD;
|
||||
int inotifyWD;
|
||||
#endif
|
||||
/* locale to use. NULL==POSIX or C */
|
||||
char *Locale = NULL;
|
||||
|
||||
@@ -436,6 +440,9 @@ void print_help()
|
||||
puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
|
||||
puts(_(" --visual-id visualid visual id of visual to use"));
|
||||
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(_(" --help show this message"));
|
||||
}
|
||||
@@ -460,6 +467,7 @@ void check_defaults()
|
||||
wfree(path);
|
||||
}
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
/*
|
||||
* Add watch here, used to notify if configuration
|
||||
* files have changed, using linux kernel inotify mechanism
|
||||
@@ -490,6 +498,7 @@ static void inotifyWatchConfig()
|
||||
}
|
||||
wfree(watchPath);
|
||||
}
|
||||
#endif /* HAVE_INOTIFY */
|
||||
|
||||
static void execInitScript()
|
||||
{
|
||||
@@ -661,7 +670,11 @@ static int real_main(int argc, char **argv)
|
||||
wwarning(_("bad value for visualid: \"%s\""), argv[i]);
|
||||
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;
|
||||
} else if (strcmp(argv[i], "--help") == 0) {
|
||||
print_help();
|
||||
@@ -762,7 +775,9 @@ static int real_main(int argc, char **argv)
|
||||
multiHead = False;
|
||||
|
||||
execInitScript();
|
||||
#ifdef HAVE_INOTIFY
|
||||
inotifyWatchConfig();
|
||||
#endif
|
||||
EventLoop();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ static void wipeDesktop(WScreen * scr);
|
||||
void Shutdown(WShutdownMode mode)
|
||||
{
|
||||
int i;
|
||||
#ifdef HAVE_INOTIFY
|
||||
extern int inotifyFD;
|
||||
#endif
|
||||
|
||||
switch (mode) {
|
||||
case WSLogoutMode:
|
||||
@@ -64,7 +66,9 @@ void Shutdown(WShutdownMode mode)
|
||||
case WSExitMode:
|
||||
/* if there is no session manager, send SAVE_YOURSELF to
|
||||
* the clients */
|
||||
#ifdef HAVE_INOTIFY
|
||||
close(inotifyFD);
|
||||
#endif
|
||||
for (i = 0; i < wScreenCount; i++) {
|
||||
WScreen *scr;
|
||||
|
||||
@@ -92,7 +96,9 @@ void Shutdown(WShutdownMode mode)
|
||||
for (i = 0; i < wScreenCount; i++) {
|
||||
WScreen *scr;
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
close(inotifyFD);
|
||||
#endif
|
||||
scr = wScreenWithNumber(i);
|
||||
if (scr) {
|
||||
if (scr->helper_pid)
|
||||
|
||||
@@ -134,6 +134,11 @@ extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
|
||||
/* cursors */
|
||||
extern Cursor wCursor[WCUR_LAST];
|
||||
|
||||
#ifndef HAVE_INOTIFY
|
||||
/* special flags */
|
||||
extern char WDelayedActionSet;
|
||||
#endif
|
||||
|
||||
/***** Local *****/
|
||||
|
||||
static WScreen **wScreen = NULL;
|
||||
@@ -187,6 +192,28 @@ static int handleXIO(Display * xio_dpy)
|
||||
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--
|
||||
@@ -574,6 +601,11 @@ void StartUp(Bool defaultScreenOnly)
|
||||
XFreePixmap(dpy, cur);
|
||||
}
|
||||
|
||||
#ifndef HAVE_INOTIFY
|
||||
/* signal handler stuff that gets called when a signal is caught */
|
||||
WMAddPersistentTimerHandler(500, delayedAction, NULL);
|
||||
#endif
|
||||
|
||||
/* emergency exit... */
|
||||
sig_action.sa_handler = handleSig;
|
||||
sigemptyset(&sig_action.sa_mask);
|
||||
@@ -757,6 +789,13 @@ void StartUp(Bool defaultScreenOnly)
|
||||
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)
|
||||
|
||||
@@ -347,6 +347,11 @@
|
||||
/* max width of window title in window list */
|
||||
#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
|
||||
|
||||
/* if your keyboard don't have arrow keys */
|
||||
|
||||
Reference in New Issue
Block a user