From: Rodolfo García Peñas (kix) Date: Sat, 3 Nov 2012 18:54:01 +0000 (+0100) Subject: get_pixmap_icon_from_icon_win rewritten X-Git-Tag: wmaker-0.95.4~64 X-Git-Url: https://repo.or.cz/w/wmaker-crm.git/commitdiff_plain/314f1dc9070433a18f914ab3bbc04599c9eabdca get_pixmap_icon_from_icon_win rewritten The function get_pixmap_icon_from_icon_win() is now rewritten. This function now creates the icon using the function get_window_image_from_x11(), using itself as Window and updates 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), checks if the icon has title and then reparents the dockapp to put it inside the icon. This patch includes a lot of comments to better understand the code. --- diff --git a/src/icon.c b/src/icon.c index b02fce05..6aca13b4 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; + drawIconTitle(scr, icon->pixmap, theight); } else { - pixmap = None; - theight = 0; - XSetWindowBackgroundPixmap(dpy, icon->core->window, scr->icon_tile_pixmap); - } + XSetWindowBackgroundPixmap(dpy, icon->core->window, scr->icon_tile_pixmap); + } + /* 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 */