It is working fine but there are a couple of problems.

1. It looks like I should use addFileWatch rather than
directly accessing FAM, is this correct?  I notice dbus
uses addFileWatch rather than (*d->addFileWatch) is
this intentional, and does it get wrapped in the same
way?

Yep, you should use the file watch interface instead of FAM. You should
call addFileWatch to add a watch for a specific file or directory.
addFileWatch will then call display->fileWatchAdded which is a wrapped
function that plugins that provide file watch functionality like the
inotify function will hook into. If you have any problems with using the
file watch interface please let me know.


Hi,

I modified the inotify plugin to send an event structure instead of just
the file name in the callback. The event contains an event mask to allow to
switch between event types in the callback, and the file name.

Currently the name variable in the callback sends the event->name of the 
inotify struct,
but that's not very useful. eg. if you watch two files directly, there is no 
way to distinguish
between them in the callback, because event->name will be empty.

So the new CompNotifyEvent will send the watch path if a file is watched,
or the relative filename if a directory is watched.

I think this can be very useful for the ini plugin and for other plugins as 
well.

Any thoughts on that?

diff --git a/plugins/inotify.c b/plugins/inotify.c
index 9782c61..e3d7a8b 100644
--- a/plugins/inotify.c
+++ b/plugins/inotify.c
@@ -53,6 +53,20 @@ typedef struct _InotifyDisplay {
 #define INOTIFY_DISPLAY(d)		         \
     InotifyDisplay *id = GET_INOTIFY_DISPLAY (d)
 
+static int
+inotifyNotifyEventMask (int inotifyMask)
+{
+    int compMask = 0;
+
+    if (inotifyMask & IN_CREATE)
+	compMask = NOTIFY_CREATE_MASK;
+    else if (inotifyMask & IN_DELETE)
+	compMask = NOTIFY_DELETE_MASK;
+    else if (inotifyMask & IN_MOVE)
+	compMask = NOTIFY_MOVE_MASK;
+
+    return compMask;
+}
 
 static Bool
 inotifyProcessEvents (void *data)
@@ -90,7 +104,28 @@ inotifyProcessEvents (void *data)
 			break;
 
 		if (fw)
-		    (*fw->callBack) (event->name, fw->closure);
+                {
+                    CompNotifyEvent *nev;
+
+                    nev = malloc (sizeof (CompNotifyEvent));
+                    if (nev)
+                    {
+                        if (event->len == 0)
+                        {
+                            nev->name = fw->path;
+                        }
+                        else
+                        {
+                            nev->name = event->name;
+                        }
+
+                        nev->mask = inotifyNotifyEventMask (event->mask);
+
+                        (*fw->callBack) (nev, fw->closure);
+
+                        free (nev);
+                    }
+                }
 	    }
 
 	    i += sizeof (*event) + event->len;
diff --git a/include/compiz.h b/include/compiz.h
index 9107270..e67a1e3 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -621,8 +621,13 @@ typedef Bool (*ImageToFileProc) (CompDisplay *display,
 #define NOTIFY_DELETE_MASK (1 << 1)
 #define NOTIFY_MOVE_MASK   (1 << 2)
 
-typedef void (*FileWatchCallBackProc) (const char *name,
-				       void	  *closure);
+typedef struct _CompNotifyEvent {
+    const char *name;
+    int        mask;
+} CompNotifyEvent;
+
+typedef void (*FileWatchCallBackProc) (CompNotifyEvent *event,
+                                       void            *closure);
 
 typedef struct _CompFileWatch {
     struct _CompFileWatch *next;
diff --git a/plugins/dbus.c b/plugins/dbus.c
index 782ad24..00e7d9b 100644
--- a/plugins/dbus.c
+++ b/plugins/dbus.c
@@ -1518,8 +1518,8 @@ dbusSetScreenOptionForPlugin (CompScreen      *s,
 }
 
 static void
-dbusSendPluginsChangedSignal (const char *name,
-			      void	 *closure)
+dbusSendPluginsChangedSignal (CompNotifyEvent *event,
+                              void            *closure)
 {
     CompDisplay *d = (CompDisplay *) closure;
     DBusMessage *signal;
_______________________________________________
compiz mailing list
compiz@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/compiz

Reply via email to