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

wmaker: Moved variables for Inotify into the global namespace

This commit is contained in:
Christophe CURIS
2013-10-10 20:38:26 +02:00
committed by Carlos R. Mafra
parent 6dcfdd072b
commit a79c0e76d0
4 changed files with 29 additions and 23 deletions

View File

@@ -522,6 +522,13 @@ extern struct wmaker_global_variables {
struct WMenu *drawer_menu; /* menu for the drawers */ struct WMenu *drawer_menu; /* menu for the drawers */
} dock; } dock;
#ifdef HAVE_INOTIFY
struct {
int fd_event_queue; /* Inotify's queue file descriptor */
int wd_defaults; /* Watch Descriptor for the 'Defaults' configuration file */
} inotify;
#endif
/* definition for X Atoms */ /* definition for X Atoms */
struct { struct {

View File

@@ -358,13 +358,11 @@ noreturn void EventLoop(void)
{ {
XEvent event; XEvent event;
#ifdef HAVE_INOTIFY #ifdef HAVE_INOTIFY
extern int inotifyFD;
extern int inotifyWD;
struct timeval time; struct timeval time;
fd_set rfds; fd_set rfds;
int retVal = 0; int retVal = 0;
if (inotifyFD < 0 || inotifyWD < 0) if (w_global.inotify.fd_event_queue < 0 || w_global.inotify.wd_defaults < 0)
retVal = -1; retVal = -1;
#endif #endif
@@ -377,20 +375,21 @@ noreturn void EventLoop(void)
time.tv_sec = 0; time.tv_sec = 0;
time.tv_usec = 0; time.tv_usec = 0;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(inotifyFD, &rfds); FD_SET(w_global.inotify.fd_event_queue, &rfds);
/* check for available read data from inotify - don't block! */ /* check for available read data from inotify - don't block! */
retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time); retVal = select(w_global.inotify.fd_event_queue + 1, &rfds, NULL, NULL, &time);
if (retVal < 0) { /* an error has occured */ if (retVal < 0) { /* an error has occured */
wwarning(_("select failed. The inotify instance will be closed." wwarning(_("select failed. The inotify instance will be closed."
" Changes to the defaults database will require" " Changes to the defaults database will require"
" a restart to take effect.")); " a restart to take effect."));
close(inotifyFD); close(w_global.inotify.fd_event_queue);
w_global.inotify.fd_event_queue = -1;
continue; continue;
} }
if (FD_ISSET(inotifyFD, &rfds)) if (FD_ISSET(w_global.inotify.fd_event_queue, &rfds))
handle_inotify_events(inotifyFD, inotifyWD); handle_inotify_events(w_global.inotify.fd_event_queue, w_global.inotify.wd_defaults);
} }
#endif #endif
} }

View File

@@ -74,11 +74,6 @@ char *ProgName;
unsigned int ValidModMask = 0xff; unsigned int ValidModMask = 0xff;
#ifdef HAVE_INOTIFY
int inotifyFD;
int inotifyWD;
#endif
struct WPreferences wPreferences; struct WPreferences wPreferences;
WShortKey wKeyBindings[WKBD_LAST]; WShortKey wKeyBindings[WKBD_LAST];
@@ -474,8 +469,9 @@ static void check_defaults(void)
static void inotifyWatchConfig(void) static void inotifyWatchConfig(void)
{ {
char *watchPath = NULL; char *watchPath = NULL;
inotifyFD = inotify_init(); /* Initialise an inotify instance */
if (inotifyFD < 0) { w_global.inotify.fd_event_queue = inotify_init(); /* Initialise an inotify instance */
if (w_global.inotify.fd_event_queue < 0) {
wwarning(_("could not initialise an inotify instance." wwarning(_("could not initialise an inotify instance."
" Changes to the defaults database will require" " Changes to the defaults database will require"
" a restart to take effect. Check your kernel!")); " a restart to take effect. Check your kernel!"));
@@ -485,12 +481,13 @@ static void inotifyWatchConfig(void)
* but we might want more in the future so check all events for now. * but we might want more in the future so check all events for now.
* The individual events are checked for in event.c. * The individual events are checked for in event.c.
*/ */
inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS); w_global.inotify.wd_defaults = inotify_add_watch(w_global.inotify.fd_event_queue, watchPath, IN_ALL_EVENTS);
if (inotifyWD < 0) { if (w_global.inotify.wd_defaults < 0) {
wwarning(_("could not add an inotify watch on path %s." wwarning(_("could not add an inotify watch on path %s."
"Changes to the defaults database will require" "Changes to the defaults database will require"
" a restart to take effect."), watchPath); " a restart to take effect."), watchPath);
close(inotifyFD); close(w_global.inotify.fd_event_queue);
w_global.inotify.fd_event_queue = -1;
} }
} }
wfree(watchPath); wfree(watchPath);

View File

@@ -54,9 +54,6 @@ static void wipeDesktop(WScreen * scr);
void Shutdown(WShutdownMode mode) void Shutdown(WShutdownMode mode)
{ {
int i; int i;
#ifdef HAVE_INOTIFY
extern int inotifyFD;
#endif
switch (mode) { switch (mode) {
case WSLogoutMode: case WSLogoutMode:
@@ -65,7 +62,10 @@ void Shutdown(WShutdownMode mode)
/* 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 #ifdef HAVE_INOTIFY
close(inotifyFD); if (w_global.inotify.fd_event_queue >= 0) {
close(w_global.inotify.fd_event_queue);
w_global.inotify.fd_event_queue = -1;
}
#endif #endif
for (i = 0; i < w_global.screen_count; i++) { for (i = 0; i < w_global.screen_count; i++) {
WScreen *scr; WScreen *scr;
@@ -92,7 +92,10 @@ void Shutdown(WShutdownMode mode)
WScreen *scr; WScreen *scr;
#ifdef HAVE_INOTIFY #ifdef HAVE_INOTIFY
close(inotifyFD); if (w_global.inotify.fd_event_queue >= 0) {
close(w_global.inotify.fd_event_queue);
w_global.inotify.fd_event_queue = -1;
}
#endif #endif
scr = wScreenWithNumber(i); scr = wScreenWithNumber(i);
if (scr) { if (scr) {