Hi everyone!
After a lot of time I finally made it. It's still in a really hacky/durty
way (billiob, don't be scared. Maybe you could think that this patch causes
a kernel panic, but it doesn't... always... :p)
but I promisse that I'll keep trying to make it cleaner.

So, the patch basically makes the trayicon to detect when the tray manager
crashes or when it comes back to normallity, and according to this it
deletes the icon or creates it again.

-- 
Alexander Nest
--- amsn/utils/linux/traydock/libtray.c	2009-12-06 21:43:09.985847493 +0100
+++ libtray.c	2009-12-06 21:44:55.375370212 +0100
@@ -14,6 +14,9 @@
 #define SYSTEM_TRAY_BEGIN_MESSAGE   1
 #define SYSTEM_TRAY_CANCEL_MESSAGE  2
 
+#define SYSTEM_TRAY_ORIENTATION_HORZ 0
+#define SYSTEM_TRAY_ORIENTATION_VERT 1
+
 #define IL_LAST(il)				\
 {						\
 	if (il != NULL){			\
@@ -56,6 +59,17 @@
 	}					\
 }
 
+static int Tk_TrayIconNew (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);     
+static int Tk_RemoveIcon (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);                
+
+struct {
+    int managed; //1 is for managed, 0 is when no tray-manager
+    int destroyed; //1 is when tray is deleted because of tray crash, 0 is when tray is managed and visible.
+    ClientData clientData;
+    Tcl_Interp *interp;
+    int objc;
+    Tcl_Obj *objv;
+} trayinfo;
 
 typedef struct TrayIcon *TrayIcon_;
 typedef struct {
@@ -252,8 +266,24 @@
 static int
 MessageEvent (Tk_Window tkwin, XEvent *eventPtr)
 {
-//	printf("Message\n");
-	return 0;
+    if (eventPtr->type == 32) {
+        if (_GetSystemTray () == 0) {
+            if (trayinfo.managed == 1 && trayinfo.destroyed == 0){
+                trayinfo.managed = 0;
+                trayinfo.destroyed = 1;              
+                //printf("Tray manager is gone! Delete trayicon!\n");
+                Tk_RemoveIcon(trayinfo.clientData, trayinfo.interp, trayinfo.objc, trayinfo.objv);
+            }
+        } else {
+            if (trayinfo.managed == 0 && trayinfo.destroyed == 1){
+                trayinfo.managed = 1;
+                trayinfo.destroyed = 0;              
+                //printf("Tray manager is back! Recreate trayicon!\n");
+                Tk_TrayIconNew(trayinfo.clientData, trayinfo.interp, trayinfo.objc, trayinfo.objv);
+            }          
+        }
+    }
+    return 0;
 }
 
 
@@ -327,8 +357,20 @@
 	XSizeHints *hint;
 	char cmdBuffer[1024];
 
+        //set trayinfo
+        trayinfo.managed = 1;
+        trayinfo.destroyed = 0;
+        trayinfo.clientData = clientData;
+        trayinfo.interp = interp;
+        trayinfo.objc = objc;
+
+        trayinfo.objv = (Tcl_Obj *) calloc (objc, sizeof(Tcl_Obj));
+        memcpy(trayinfo.objv, objv, sizeof(Tcl_Obj)*objc);
+        
 	/* systemtray was not available in Init */
 	if (_GetSystemTray () == 0) {
+                trayinfo.managed = 0;
+                trayinfo.destroyed = 1;
 		Tcl_AppendResult (interp, "cannot create a tray icon without a system tray", (char *) NULL);
 		return TCL_ERROR;
 	}
@@ -415,9 +457,10 @@
 		icon->pixmap=Tk_GetImage(interp,icon->win,pixmap,ImageChangedProc, (ClientData)icon);
 		
 		/* Create callback function for event handling */
-		mask = StructureNotifyMask | ExposureMask | EnterWindowMask | LeaveWindowMask  | PropertyChangeMask;
+		mask = StructureNotifyMask | ExposureMask | EnterWindowMask | LeaveWindowMask  | PropertyChangeMask | DestroyNotify;
 		Tk_CreateEventHandler(icon->win, mask, IconEvent, (ClientData) icon);
 		Tk_CreateClientMessageHandler(MessageEvent);
+                Tk_CreateGenericHandler(MessageEvent, (ClientData)icon);
 		
 		/* Set default icon size hint */
 		hint = XAllocSizeHints();
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Amsn-devel mailing list
Amsn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amsn-devel

Reply via email to