The new function wIconCreateCore do the common work to create a WIcon.

This code was before in wIconCreateWithIconFile() and wIconCreateWithIconFile().
---
 src/icon.c |   85 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 38 insertions(+), 47 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index d7fd3cd..e8382bb 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -56,6 +56,8 @@ static void miniwindowExpose(WObjDescriptor * desc, XEvent * 
event);
 static void miniwindowMouseDown(WObjDescriptor * desc, XEvent * event);
 static void miniwindowDblClick(WObjDescriptor * desc, XEvent * event);
 
+static WIcon *wIconCreateCore(WScreen *scr, int coord_x, int coord_y);
+
 void get_pixmap_icon_from_icon_win(WIcon *icon);
 int get_pixmap_icon_from_wm_hints(WScreen *scr, WWindow *wwin, WIcon *icon);
 void get_pixmap_icon_from_user_icon(WScreen *scr, WIcon * icon);
@@ -110,35 +112,8 @@ WIcon *wIconCreate(WWindow * wwin)
        WScreen *scr = wwin->screen_ptr;
        WIcon *icon;
        char *file;
-       unsigned long vmask = 0;
-       XSetWindowAttributes attribs;
-
-       icon = wmalloc(sizeof(WIcon));
-       memset(icon, 0, sizeof(WIcon));
-       icon->core = wCoreCreateTopLevel(scr, wwin->icon_x, wwin->icon_y,
-                                        wPreferences.icon_size, 
wPreferences.icon_size, 0);
-
-       if (wPreferences.use_saveunders) {
-               vmask |= CWSaveUnder;
-               attribs.save_under = True;
-       }
-       /* a white border for selecting it */
-       vmask |= CWBorderPixel;
-       attribs.border_pixel = scr->white_pixel;
 
-       XChangeWindowAttributes(dpy, icon->core->window, vmask, &attribs);
-
-       /* will be overriden if this is an application icon */
-       icon->core->descriptor.handle_mousedown = miniwindowMouseDown;
-       icon->core->descriptor.handle_expose = miniwindowExpose;
-       icon->core->descriptor.parent_type = WCLASS_MINIWINDOW;
-       icon->core->descriptor.parent = icon;
-
-       icon->core->stacking = wmalloc(sizeof(WStacking));
-       icon->core->stacking->above = NULL;
-       icon->core->stacking->under = NULL;
-       icon->core->stacking->window_level = NORMAL_ICON_LEVEL;
-       icon->core->stacking->child_of = NULL;
+       icon = wIconCreateCore(scr, wwin->icon_x, wwin->icon_y);
 
        icon->owner = wwin;
        if (wwin->wm_hints && (wwin->wm_hints->flags & IconWindowHint)) {
@@ -183,16 +158,50 @@ WIcon *wIconCreate(WWindow * wwin)
 WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
 {
        WIcon *icon;
+
+       icon = wIconCreateCore(scr, 0, 0);
+
+       if (iconfile) {
+               icon->file_image = RLoadImage(scr->rcontext, iconfile, 0);
+               if (!icon->file_image) {
+                       wwarning(_("error loading image file \"%s\": %s"), 
iconfile, RMessageForError(RErrorCode));
+               }
+
+               icon->file_image = wIconValidateIconSize(scr, icon->file_image, 
wPreferences.icon_size);
+
+               icon->file = wstrdup(iconfile);
+       }
+
+       icon->tile_type = tile;
+
+       wIconUpdate(icon);
+
+       WMAddNotificationObserver(appearanceObserver, icon, 
WNIconAppearanceSettingsChanged, icon);
+       WMAddNotificationObserver(tileObserver, icon, 
WNIconTileSettingsChanged, icon);
+
+       return icon;
+}
+
+static WIcon *wIconCreateCore(WScreen *scr, int coord_x, int coord_y)
+{
+       WIcon *icon;
        unsigned long vmask = 0;
        XSetWindowAttributes attribs;
 
        icon = wmalloc(sizeof(WIcon));
        memset(icon, 0, sizeof(WIcon));
-       icon->core = wCoreCreateTopLevel(scr, 0, 0, wPreferences.icon_size, 
wPreferences.icon_size, 0);
+       icon->core = wCoreCreateTopLevel(scr,
+                                        coord_x,
+                                        coord_y,
+                                        wPreferences.icon_size,
+                                        wPreferences.icon_size,
+                                        0);
+
        if (wPreferences.use_saveunders) {
                vmask = CWSaveUnder;
                attribs.save_under = True;
        }
+
        /* a white border for selecting it */
        vmask |= CWBorderPixel;
        attribs.border_pixel = scr->white_pixel;
@@ -211,24 +220,6 @@ WIcon *wIconCreateWithIconFile(WScreen * scr, char 
*iconfile, int tile)
        icon->core->stacking->window_level = NORMAL_ICON_LEVEL;
        icon->core->stacking->child_of = NULL;
 
-       if (iconfile) {
-               icon->file_image = RLoadImage(scr->rcontext, iconfile, 0);
-               if (!icon->file_image) {
-                       wwarning(_("error loading image file \"%s\": %s"), 
iconfile, RMessageForError(RErrorCode));
-               }
-
-               icon->file_image = wIconValidateIconSize(scr, icon->file_image, 
wPreferences.icon_size);
-
-               icon->file = wstrdup(iconfile);
-       }
-
-       icon->tile_type = tile;
-
-       wIconUpdate(icon);
-
-       WMAddNotificationObserver(appearanceObserver, icon, 
WNIconAppearanceSettingsChanged, icon);
-       WMAddNotificationObserver(tileObserver, icon, 
WNIconTileSettingsChanged, icon);
-
        return icon;
 }
 
-- 
1.7.9.1

>From 8c2f3289833e52118a4a9f4bccf3bf58849e55e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sat, 14 Apr 2012 13:31:09 +0200
Subject: [PATCH 14/16] WindowMaker: New function wIconCreateCore()

The new function wIconCreateCore do the common work to create a WIcon.

This code was before in wIconCreateWithIconFile() and wIconCreateWithIconFile().
---
 src/icon.c |   85 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 38 insertions(+), 47 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index d7fd3cd..e8382bb 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -56,6 +56,8 @@ static void miniwindowExpose(WObjDescriptor * desc, XEvent * event);
 static void miniwindowMouseDown(WObjDescriptor * desc, XEvent * event);
 static void miniwindowDblClick(WObjDescriptor * desc, XEvent * event);
 
+static WIcon *wIconCreateCore(WScreen *scr, int coord_x, int coord_y);
+
 void get_pixmap_icon_from_icon_win(WIcon *icon);
 int get_pixmap_icon_from_wm_hints(WScreen *scr, WWindow *wwin, WIcon *icon);
 void get_pixmap_icon_from_user_icon(WScreen *scr, WIcon * icon);
@@ -110,35 +112,8 @@ WIcon *wIconCreate(WWindow * wwin)
 	WScreen *scr = wwin->screen_ptr;
 	WIcon *icon;
 	char *file;
-	unsigned long vmask = 0;
-	XSetWindowAttributes attribs;
-
-	icon = wmalloc(sizeof(WIcon));
-	memset(icon, 0, sizeof(WIcon));
-	icon->core = wCoreCreateTopLevel(scr, wwin->icon_x, wwin->icon_y,
-					 wPreferences.icon_size, wPreferences.icon_size, 0);
-
-	if (wPreferences.use_saveunders) {
-		vmask |= CWSaveUnder;
-		attribs.save_under = True;
-	}
-	/* a white border for selecting it */
-	vmask |= CWBorderPixel;
-	attribs.border_pixel = scr->white_pixel;
 
-	XChangeWindowAttributes(dpy, icon->core->window, vmask, &attribs);
-
-	/* will be overriden if this is an application icon */
-	icon->core->descriptor.handle_mousedown = miniwindowMouseDown;
-	icon->core->descriptor.handle_expose = miniwindowExpose;
-	icon->core->descriptor.parent_type = WCLASS_MINIWINDOW;
-	icon->core->descriptor.parent = icon;
-
-	icon->core->stacking = wmalloc(sizeof(WStacking));
-	icon->core->stacking->above = NULL;
-	icon->core->stacking->under = NULL;
-	icon->core->stacking->window_level = NORMAL_ICON_LEVEL;
-	icon->core->stacking->child_of = NULL;
+	icon = wIconCreateCore(scr, wwin->icon_x, wwin->icon_y);
 
 	icon->owner = wwin;
 	if (wwin->wm_hints && (wwin->wm_hints->flags & IconWindowHint)) {
@@ -183,16 +158,50 @@ WIcon *wIconCreate(WWindow * wwin)
 WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
 {
 	WIcon *icon;
+
+	icon = wIconCreateCore(scr, 0, 0);
+
+	if (iconfile) {
+		icon->file_image = RLoadImage(scr->rcontext, iconfile, 0);
+		if (!icon->file_image) {
+			wwarning(_("error loading image file \"%s\": %s"), iconfile, RMessageForError(RErrorCode));
+		}
+
+		icon->file_image = wIconValidateIconSize(scr, icon->file_image, wPreferences.icon_size);
+
+		icon->file = wstrdup(iconfile);
+	}
+
+	icon->tile_type = tile;
+
+	wIconUpdate(icon);
+
+	WMAddNotificationObserver(appearanceObserver, icon, WNIconAppearanceSettingsChanged, icon);
+	WMAddNotificationObserver(tileObserver, icon, WNIconTileSettingsChanged, icon);
+
+	return icon;
+}
+
+static WIcon *wIconCreateCore(WScreen *scr, int coord_x, int coord_y)
+{
+	WIcon *icon;
 	unsigned long vmask = 0;
 	XSetWindowAttributes attribs;
 
 	icon = wmalloc(sizeof(WIcon));
 	memset(icon, 0, sizeof(WIcon));
-	icon->core = wCoreCreateTopLevel(scr, 0, 0, wPreferences.icon_size, wPreferences.icon_size, 0);
+	icon->core = wCoreCreateTopLevel(scr,
+					 coord_x,
+					 coord_y,
+					 wPreferences.icon_size,
+					 wPreferences.icon_size,
+					 0);
+
 	if (wPreferences.use_saveunders) {
 		vmask = CWSaveUnder;
 		attribs.save_under = True;
 	}
+
 	/* a white border for selecting it */
 	vmask |= CWBorderPixel;
 	attribs.border_pixel = scr->white_pixel;
@@ -211,24 +220,6 @@ WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
 	icon->core->stacking->window_level = NORMAL_ICON_LEVEL;
 	icon->core->stacking->child_of = NULL;
 
-	if (iconfile) {
-		icon->file_image = RLoadImage(scr->rcontext, iconfile, 0);
-		if (!icon->file_image) {
-			wwarning(_("error loading image file \"%s\": %s"), iconfile, RMessageForError(RErrorCode));
-		}
-
-		icon->file_image = wIconValidateIconSize(scr, icon->file_image, wPreferences.icon_size);
-
-		icon->file = wstrdup(iconfile);
-	}
-
-	icon->tile_type = tile;
-
-	wIconUpdate(icon);
-
-	WMAddNotificationObserver(appearanceObserver, icon, WNIconAppearanceSettingsChanged, icon);
-	WMAddNotificationObserver(tileObserver, icon, WNIconTileSettingsChanged, icon);
-
 	return icon;
 }
 
-- 
1.7.9.1

Reply via email to