From cf9f0ec67ee3a3f5eb7303331ba76044fb2e065a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sun, 4 Mar 2012 14:54:45 +0100 Subject: [PATCH] WindowMaker: New function get_pixmap_icon_from_wm_hints The new function get_pixmap_icon_from_wm_hints() splits the function wIconUpdate(). --- src/icon.c | 112 ++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/src/icon.c b/src/icon.c index f5225475..8663e699 100644 --- a/src/icon.c +++ b/src/icon.c @@ -57,6 +57,7 @@ static void miniwindowMouseDown(WObjDescriptor * desc, XEvent * event); static void miniwindowDblClick(WObjDescriptor * desc, XEvent * event); void get_pixmap_icon_from_icon_win(WIcon *icon); +int get_pixmap_icon_from_wm_hints(WScreen *scr, WWindow *wwin, WIcon *icon); /****** Notification Observers ******/ static void appearanceObserver(void *self, WMNotification * notif) @@ -553,7 +554,6 @@ void wIconSelect(WIcon * icon) void wIconUpdate(WIcon * icon) { WScreen *scr = icon->core->screen_ptr; - int title_height = WMFontHeight(scr->icon_title_font); WWindow *wwin = icon->owner; assert(scr->icon_tile != NULL); @@ -573,59 +573,8 @@ void wIconUpdate(WIcon * icon) icon->pixmap = makeIcon(scr, wwin->net_icon_image, icon->show_title, icon->shadowed, icon->tile_type, icon->highlighted); } else if (wwin && wwin->wm_hints && (wwin->wm_hints->flags & IconPixmapHint)) { - int x, y; - unsigned int w, h; - Window jw; - int ji; - unsigned int ju, d; - Pixmap pixmap; - - if (!XGetGeometry(dpy, wwin->wm_hints->icon_pixmap, &jw, &ji, &ji, &w, &h, &ju, &d)) { - icon->owner->wm_hints->flags &= ~IconPixmapHint; + if (get_pixmap_icon_from_wm_hints(scr, wwin, icon)) goto user_icon; - } - - pixmap = XCreatePixmap(dpy, icon->core->window, 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); - - if (w > wPreferences.icon_size) - w = wPreferences.icon_size; - x = (wPreferences.icon_size - w) / 2; - - if (icon->show_title && (title_height < wPreferences.icon_size)) { - drawIconTitle(scr, pixmap, title_height); - - if (h > wPreferences.icon_size - title_height - 2) { - h = wPreferences.icon_size - title_height - 2; - y = title_height + 1; - } else { - y = (wPreferences.icon_size - h - title_height) / 2 + title_height + 1; - } - } else { - if (w > wPreferences.icon_size) - w = wPreferences.icon_size; - y = (wPreferences.icon_size - h) / 2; - } - - if (wwin->wm_hints->flags & IconMaskHint) - XSetClipMask(dpy, scr->copy_gc, wwin->wm_hints->icon_mask); - - XSetClipOrigin(dpy, scr->copy_gc, x, y); - - if (d != scr->w_depth) { - XSetForeground(dpy, scr->copy_gc, scr->black_pixel); - XSetBackground(dpy, scr->copy_gc, scr->white_pixel); - XCopyPlane(dpy, wwin->wm_hints->icon_pixmap, pixmap, scr->copy_gc, 0, 0, w, h, x, y, 1); - } else { - XCopyArea(dpy, wwin->wm_hints->icon_pixmap, pixmap, scr->copy_gc, 0, 0, w, h, x, y); - } - - XSetClipOrigin(dpy, scr->copy_gc, 0, 0); - - icon->pixmap = pixmap; } else { user_icon: if (icon->file_image) { @@ -733,6 +682,63 @@ void get_pixmap_icon_from_icon_win(WIcon * icon) None, wCursor[WCUR_ARROW]); } +/* Get the Pixmap from the XWindow wm_hints */ +int get_pixmap_icon_from_wm_hints(WScreen *scr, WWindow *wwin, WIcon *icon) +{ + Window jw; + Pixmap pixmap; + unsigned int w, h, ju, d; + int ji, x, y; + int title_height = WMFontHeight(scr->icon_title_font); + + if (!XGetGeometry(dpy, wwin->wm_hints->icon_pixmap, &jw, &ji, &ji, &w, &h, &ju, &d)) { + icon->owner->wm_hints->flags &= ~IconPixmapHint; + return(1); + } + + pixmap = XCreatePixmap(dpy, icon->core->window, 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); + + if (w > wPreferences.icon_size) + w = wPreferences.icon_size; + x = (wPreferences.icon_size - w) / 2; + + if (icon->show_title && (title_height < wPreferences.icon_size)) { + drawIconTitle(scr, pixmap, title_height); + + if (h > wPreferences.icon_size - title_height - 2) { + h = wPreferences.icon_size - title_height - 2; + y = title_height + 1; + } else { + y = (wPreferences.icon_size - h - title_height) / 2 + title_height + 1; + } + } else { + if (w > wPreferences.icon_size) + w = wPreferences.icon_size; + y = (wPreferences.icon_size - h) / 2; + } + + if (wwin->wm_hints->flags & IconMaskHint) + XSetClipMask(dpy, scr->copy_gc, wwin->wm_hints->icon_mask); + + XSetClipOrigin(dpy, scr->copy_gc, x, y); + + if (d != scr->w_depth) { + XSetForeground(dpy, scr->copy_gc, scr->black_pixel); + XSetBackground(dpy, scr->copy_gc, scr->white_pixel); + XCopyPlane(dpy, wwin->wm_hints->icon_pixmap, pixmap, scr->copy_gc, 0, 0, w, h, x, y, 1); + } else { + XCopyArea(dpy, wwin->wm_hints->icon_pixmap, pixmap, scr->copy_gc, 0, 0, w, h, x, y); + } + + XSetClipOrigin(dpy, scr->copy_gc, 0, 0); + + icon->pixmap = pixmap; + return (0); +} void wIconPaint(WIcon * icon) {