AppIcon helper functions.
authorIain Patterson <wm@iain.cx>
Mon, 29 Oct 2012 22:35:56 +0000 (29 15:35 -0700)
committerCarlos R. Mafra <crmafra@gmail.com>
Tue, 30 Oct 2012 15:26:52 +0000 (30 15:26 +0000)
Create wAppIconFor() and wAppIconTouchesHead() to match wWindowFor()
and wWindowTouchesHead().  These functions will allow us to locate the
window and head associated with a particular app icon or dock icon.

src/appicon.c
src/appicon.h
src/xinerama.c
src/xinerama.h

index 9bac0ef..6be3057 100644 (file)
@@ -60,6 +60,7 @@
 extern Cursor wCursor[WCUR_LAST];
 extern WPreferences wPreferences;
 extern WDDomain *WDWindowAttributes;
+extern XContext wWinContext;
 
 #define MOD_MASK       wPreferences.modifier_mask
 
@@ -1016,3 +1017,19 @@ static void remove_from_appicon_list(WScreen *scr, WAppIcon *appicon)
        appicon->prev = NULL;
        appicon->next = NULL;
 }
+
+WAppIcon *wAppIconFor(Window window)
+{
+       WObjDescriptor *desc;
+
+       if (window == None)
+               return NULL;
+
+       if (XFindContext(dpy, window, wWinContext, (XPointer *) & desc) == XCNOENT)
+               return NULL;
+
+       if (desc->parent_type == WCLASS_APPICON || desc->parent_type == WCLASS_DOCK_ICON)
+               return desc->parent;
+
+       return NULL;
+}
index a6c6a6a..6f72c8e 100644 (file)
@@ -83,4 +83,5 @@ void paint_app_icon(WApplication *wapp);
 void unpaint_app_icon(WApplication *wapp);
 void wApplicationExtractDirPackIcon(WScreen * scr, char *path, char *wm_instance,
                                    char *wm_class);
+WAppIcon *wAppIconFor(Window window);
 #endif
index 823df99..4bd9ca4 100644 (file)
@@ -201,6 +201,25 @@ Bool wWindowTouchesHead(WWindow * wwin, int head)
        return (a != 0);
 }
 
+Bool wAppIconTouchesHead(WAppIcon * aicon, int head)
+{
+       WScreen *scr;
+       WMRect rect;
+       int a;
+
+       if (!aicon || !aicon->icon)
+               return False;
+
+       scr = aicon->icon->core->screen_ptr;
+       rect = wGetRectForHead(scr, head);
+       a = calcIntersectionArea(aicon->x_pos, aicon->y_pos,
+                                aicon->icon->core->width,
+                                aicon->icon->core->height,
+                                rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
+
+       return (a != 0);
+}
+
 int wGetHeadForWindow(WWindow * wwin)
 {
        WMRect rect;
index 0699726..fd1d469 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef _WMXINERAMA_H_
 #define _WMXINERAMA_H_
 
+#include "appicon.h"
 #include "screen.h"
 #include "window.h"
 #include <WINGs/WINGs.h>
@@ -51,6 +52,7 @@ WArea wGetUsableAreaForHead(WScreen *scr, int head, WArea *totalAreaPtr, Bool no
 WMPoint wGetPointToCenterRectInHead(WScreen *scr, int head, int width, int height);
 
 Bool wWindowTouchesHead(WWindow *wwin, int head);
+Bool wAppIconTouchesHead(WAppIcon *aicon, int head);
 
 #endif