From: "Rodolfo García Peñas (kix)" <[email protected]>

The function get_pixmap_icon_from_icon_win() is now rewrited.

This function now creates the icon using the function 
get_window_image_from_x11(),
using itself as Window and update the icon using icon_update_pixmap().

At this point the Pixmap is only the icon background. Now we must put inside the
dockapp, in the correct position. Then the funcion get the dock application 
size,
(the max size is wPreferences.icon_size, because get_window_image_from_x11() 
checks
the valid size), check if the icon has title and then reparent the dockapp to 
put
it inside the icon.

This patch includes a lot of comments to better code understanding.
---
 src/icon.c |   70 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index 14c287f..46b9a79 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -715,60 +715,60 @@ static RImage *get_default_image(WScreen *scr)
 }
 
 /* Get the Pixmap from the WIcon of the WWindow */
-static void get_pixmap_icon_from_icon_win(WIcon * icon)
+static void get_pixmap_icon_from_icon_win(WIcon *icon)
 {
        XWindowAttributes attr;
+       RImage *image;
        WScreen *scr = icon->core->screen_ptr;
        int title_height = WMFontHeight(scr->icon_title_font);
-       unsigned int width, height, depth;
-       int theight;
-       int resize = 0;
-       Pixmap pixmap;
+       unsigned int w, h, d;
+       int theight = 0;
 
-       getSize(icon->icon_win, &width, &height, &depth);
+       /* Create the new RImage */
+       image = get_window_image_from_x11(icon->icon_win);
 
-       if (width > wPreferences.icon_size) {
-               resize = 1;
-               width = wPreferences.icon_size;
-       }
+       /* Free the icon info */
+       unset_icon_image(icon);
 
-       if (height > wPreferences.icon_size) {
-               resize = 1;
-               height = wPreferences.icon_size;
-       }
+       /* Set the new info */
+       icon->file = NULL;
+       icon->file_image = image;
 
-       if (icon->show_title && (height + title_height < 
wPreferences.icon_size)) {
-               pixmap = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
-                                      wPreferences.icon_size, scr->w_depth);
-               XSetClipMask(dpy, scr->copy_gc, None);
-               XCopyArea(dpy, scr->icon_tile_pixmap, pixmap, scr->copy_gc, 0, 
0,
-                         wPreferences.icon_size, wPreferences.icon_size, 0, 0);
-               drawIconTitle(scr, pixmap, title_height);
+       /* Paint the image at the icon */
+       icon_update_pixmap(icon, image);
+
+       /* Reparent the dock application to the icon */
+
+       /* We need the application size to center it
+        * and show in the correct position */
+       getSize(icon->icon_win, &w, &h, &d);
+
+       /* Set extra space for title */
+       if (icon->show_title && (h + title_height < wPreferences.icon_size)) {
                theight = title_height;
-       } else {
-               pixmap = None;
-               theight = 0;
-               XSetWindowBackgroundPixmap(dpy, icon->core->window, 
scr->icon_tile_pixmap);
+               drawIconTitle(scr, icon->pixmap, theight);
        }
 
+       /* Now is time to do the work */
+
+       /* Set the icon border */
        XSetWindowBorderWidth(dpy, icon->icon_win, 0);
+
+       /* Put the dock application in the icon */
        XReparentWindow(dpy, icon->icon_win, icon->core->window,
-                       (wPreferences.icon_size - width) / 2,
-                       theight + (wPreferences.icon_size - height - theight) / 
2);
-       if (resize)
-               XResizeWindow(dpy, icon->icon_win, width, height);
+                       (wPreferences.icon_size - w) / 2,
+                       theight + (wPreferences.icon_size - h - theight) / 2);
 
+       /* Show it and save */
        XMapWindow(dpy, icon->icon_win);
        XAddToSaveSet(dpy, icon->icon_win);
 
-       /* Save it */
-       icon->pixmap = pixmap;
-
+       /* Needed to move the icon clicking on the application part */
        if ((XGetWindowAttributes(dpy, icon->icon_win, &attr)) &&
            (attr.all_event_masks & ButtonPressMask))
-                       wHackedGrabButton(Button1, MOD_MASK, 
icon->core->window, True,
-                                         ButtonPressMask, GrabModeSync, 
GrabModeAsync,
-                                         None, wCursor[WCUR_ARROW]);
+               wHackedGrabButton(Button1, MOD_MASK, icon->core->window, True,
+                                 ButtonPressMask, GrabModeSync, GrabModeAsync,
+                                 None, wCursor[WCUR_ARROW]);
 }
 
 /* Get the RImage from the XWindow wm_hints */
-- 
1.7.10.4


-- 
To unsubscribe, send mail to [email protected].

Reply via email to