changeset 3120:73e63dc190a6

Updated #266: Added subTrayClose()
author unexist
date Fri, 11 Nov 2011 15:21:33 +0100
parents 8b0f10882519
children 42ae3bebb840
files src/subtle/tray.c
diffstat 1 files changed, 69 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/subtle/tray.c	Fri Nov 11 15:21:03 2011 +0100
+++ b/src/subtle/tray.c	Fri Nov 11 15:21:33 2011 +0100
@@ -22,6 +22,8 @@
 subTrayNew(Window win)
 {
   SubTray *t = NULL;
+  int i, n = 0;
+  Atom *protos = NULL;
 
   assert(win);
 
@@ -39,6 +41,21 @@
   XAddToSaveSet(subtle->dpy, t->win);
   XSaveContext(subtle->dpy, t->win, TRAYID, (void *)t);
 
+  /* Window manager protocols */
+  if(XGetWMProtocols(subtle->dpy, t->win, &protos, &n))
+    {
+      for(i = 0; i < n; i++)
+        {
+          switch(subEwmhFind(protos[i]))
+            {
+              case SUB_EWMH_WM_DELETE_WINDOW: t->flags |= SUB_TRAY_CLOSE; break;
+              default: break;
+            }
+         }
+
+      XFree(protos);
+    }
+
   /* Start embedding life cycle */
   subEwmhMessage(t->win, SUB_EWMH_XEMBED, 0xFFFFFF, CurrentTime,
     XEMBED_EMBEDDED_NOTIFY, 0, subtle->windows.tray, 0);
@@ -198,27 +215,42 @@
     }
 } /* }}} */
 
- /** subTrayPublish {{{
-  * @brief Publish trays
+ /** subTrayClose {{{
+  * @brief Send tray delete message or just kill it
+  * @param[in]  t  A #SubTray
   **/
 
 void
-subTrayPublish(void)
+subTrayClose(SubTray *t)
 {
-  int i;
-  Window *wins = (Window *)subSharedMemoryAlloc(subtle->trays->ndata, sizeof(Window));
+  assert(t);
 
-  for(i = 0; i < subtle->trays->ndata; i++)
-    wins[i] = TRAY(subtle->trays->data[i])->win;
+  /* Honor window preferences (see ICCCM 4.1.2.7, 4.2.8.1) */
+  if(t->flags & SUB_TRAY_CLOSE)
+    {
+      subEwmhMessage(t->win, SUB_EWMH_WM_PROTOCOLS, NoEventMask,
+        subEwmhGet(SUB_EWMH_WM_DELETE_WINDOW), CurrentTime, 0, 0, 0);
+    }
+  else
+    {
+      int focus = (subtle->windows.focus[0] == t->win); ///< Save
 
-  /* EWMH: Client list and client list stacking */
-  subEwmhSetWindows(ROOT, SUB_EWMH_SUBTLE_TRAY_LIST, wins, subtle->trays->ndata);
+      /* Kill it manually */
+      XKillClient(subtle->dpy, t->win);
+
+      subArrayRemove(subtle->trays, (void *)t);
+      subTrayKill(t);
+      subTrayPublish();
+      subTrayUpdate();
 
-  XSync(subtle->dpy, False); ///< Sync all changes
+      subScreenUpdate();
+      subScreenRender();
 
-  free(wins);
+      /* Update focus if necessary */
+      if(focus) subSubtleFocus(True);
+    }
 
-  subSubtleLogDebugSubtle("Publish: trays=%d\n", subtle->trays->ndata);
+  subSubtleLogDebugSubtle("Close\n");
 } /* }}} */
 
  /** subTrayKill {{{
@@ -246,4 +278,29 @@
   subSubtleLogDebugSubtle("Kill\n");
 } /* }}} */
 
+/* All */
+
+ /** subTrayPublish {{{
+  * @brief Publish trays
+  **/
+
+void
+subTrayPublish(void)
+{
+  int i;
+  Window *wins = (Window *)subSharedMemoryAlloc(subtle->trays->ndata, sizeof(Window));
+
+  for(i = 0; i < subtle->trays->ndata; i++)
+    wins[i] = TRAY(subtle->trays->data[i])->win;
+
+  /* EWMH: Client list and client list stacking */
+  subEwmhSetWindows(ROOT, SUB_EWMH_SUBTLE_TRAY_LIST, wins, subtle->trays->ndata);
+
+  XSync(subtle->dpy, False); ///< Sync all changes
+
+  free(wins);
+
+  subSubtleLogDebugSubtle("Publish: trays=%d\n", subtle->trays->ndata);
+} /* }}} */
+
 // vim:ts=2:bs=2:sw=2:et:fdm=marker