From 5f4a3f6777f90e170482bddaab61235bb0446840 Mon Sep 17 00:00:00 2001 From: kojima Date: Thu, 14 Oct 2004 19:12:26 +0000 Subject: [PATCH] enhanced icon highlighting in window switcher --- WindowMaker/Pixmaps/Makefile.am | 3 +- WindowMaker/Pixmaps/swtile.png | Bin 0 -> 607 bytes src/monitor.c | 1 + src/switchpanel.c | 236 +++++++++++++++++++++++++++++++--------- 4 files changed, 187 insertions(+), 53 deletions(-) create mode 100644 WindowMaker/Pixmaps/swtile.png diff --git a/WindowMaker/Pixmaps/Makefile.am b/WindowMaker/Pixmaps/Makefile.am index e768c2ff..3d2ac702 100644 --- a/WindowMaker/Pixmaps/Makefile.am +++ b/WindowMaker/Pixmaps/Makefile.am @@ -2,6 +2,7 @@ defsdatadir = $(pkgdatadir)/Pixmaps defsdata_DATA = tile.tiff \ - tile.xpm + tile.xpm \ + swtile.png EXTRA_DIST = $(defsdata_DATA) diff --git a/WindowMaker/Pixmaps/swtile.png b/WindowMaker/Pixmaps/swtile.png new file mode 100644 index 0000000000000000000000000000000000000000..d8abc64c9a685b1fe9ca4112cda87516ad71a5d7 GIT binary patch literal 607 zcwXxa@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPW7oV^Yvq0x^Z=jHDiEBiObAE1aYF-J0b5UwyNotBh zd1gt5LP$ocg1e`0!21-{JO&2F!=5gVAr-gY&R*}QoG5a%zWl?AP*iU_0w{e z+Ao&6(cdwO zc2{mkuH)g~9?5T9ThweHlq-E^h)t;8#w0hHkzs}Mqx4X&wjSzpL`*m%vFxvXZfFPZtiZH+icons, index); + RImage *image= WMGetFromArray(panel->images, index); + WMScreen *wscr = WMWidgetScreen(label); + + if (image) { + RColor bgColor; + RImage *back; + + if (selected) { + back= RCloneImage(panel->tile); + RCombineArea(back, image, 0, 0, image->width, image->height, + (back->width - image->width)/2, (back->height - image->height)/2); + + pixmap= WMCreatePixmapFromRImage(wscr, back, -1); + RReleaseImage(back); + } else { + bgColor.alpha= 100; + bgColor.red = WMRedComponentOfColor(WMGrayColor(wscr))>>8; + bgColor.green = WMGreenComponentOfColor(WMGrayColor(wscr))>>8; + bgColor.blue = WMBlueComponentOfColor(WMGrayColor(wscr))>>8; + + image= RCloneImage(image); + RCombineImageWithColor(image, &bgColor); + + pixmap= WMCreatePixmapFromRImage(wscr, image, -1); + RReleaseImage(image); + } + } + + if (pixmap) { + WMSetLabelImage(label, pixmap); + WMSetLabelImagePosition(label, WIPImageOnly); + WMReleasePixmap(pixmap); + } +} + static void addIconForWindow(WSwitchPanel *panel, WWindow *wwin, int iconWidth) { WMLabel *label= WMCreateLabel(panel->hbox); WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(label), False, True, iconWidth + ICON_EXTRASPACE, 0, 0); RImage *image = NULL; - WMPixmap *pixmap; - WMScreen *wscr = WMWidgetScreen(label); - + if (!WFLAGP(wwin, always_user_icon) && wwin->net_icon_image) image = RRetainImage(wwin->net_icon_image); if (!image) - image = wDefaultGetImage(panel->scr, wwin->wm_instance, wwin->wm_class); + image = wDefaultGetImage(panel->scr, wwin->wm_instance, wwin->wm_class); + + if (!image && !panel->defIcon) + { + char *file = wDefaultGetIconFile(panel->scr, NULL, NULL, False); + if (file) { + char *path = FindImage(wPreferences.icon_path, file); + if (path) { + image = RLoadImage(panel->scr->rcontext, path, 0); + wfree(path); + } + } + } + if (!image && panel->defIcon) + image= RRetainImage(panel->defIcon); if (image && (abs(image->width - iconWidth) > 2 || abs(image->height - iconWidth) > 2)) { RImage *nimage; @@ -72,38 +202,8 @@ static void addIconForWindow(WSwitchPanel *panel, WWindow *wwin, int iconWidth) RReleaseImage(image); image= nimage; } - - if (image) { - pixmap= WMCreatePixmapFromRImage(wscr, image, 100); - RReleaseImage(image); - } else { - if (!panel->defIcon) - { - char *file = wDefaultGetIconFile(panel->scr, NULL, NULL, False); - if (file) { - char *path = FindImage(wPreferences.icon_path, file); - if (path) { - image = RLoadImage(panel->scr->rcontext, path, 0); - wfree(path); - - panel->defIcon= WMCreatePixmapFromRImage(wscr, image, 100); - RReleaseImage(image); - } - } - } - - if (panel->defIcon) - pixmap= WMRetainPixmap(panel->defIcon); - else - pixmap= NULL; - } - - if (pixmap) { - WMSetLabelImage(label, pixmap); - WMSetLabelImagePosition(label, WIPImageOnly); - WMReleasePixmap(pixmap); - } + WMAddToArray(panel->images, image); WMAddToArray(panel->icons, label); } @@ -153,6 +253,7 @@ WSwitchPanel *wInitSwitchPanel(WScreen *scr, int workspace) height= iconWidth + 20 + 10 + ICON_EXTRASPACE; panel->icons= WMCreateArray(WMGetArrayItemCount(panel->windows)); + panel->images= WMCreateArray(WMGetArrayItemCount(panel->windows)); panel->win = WMCreateWindow(scr->wmscreen, ""); WMResizeWidget(panel->win, width + 10, height); @@ -189,37 +290,73 @@ WSwitchPanel *wInitSwitchPanel(WScreen *scr, int workspace) WMReleaseFont(boldFont); } + { + RImage *tmp= NULL; + RColor bgColor; + char *path = FindImage(wPreferences.pixmap_path, "swtile.png"); + if (path) { + tmp = RLoadImage(panel->scr->rcontext, path, 0); + wfree(path); + } + + if (!tmp) + tmp= RGetImageFromXPMData(scr->rcontext, tile_xpm); + + panel->tile = RScaleImage(tmp, iconWidth+ICON_EXTRASPACE, iconWidth+ICON_EXTRASPACE); + + bgColor.alpha = 255; + bgColor.red = WMRedComponentOfColor(WMGrayColor(scr->wmscreen))>>8; + bgColor.green = WMGreenComponentOfColor(WMGrayColor(scr->wmscreen))>>8; + bgColor.blue = WMBlueComponentOfColor(WMGrayColor(scr->wmscreen))>>8; + + RCombineImageWithColor(panel->tile, &bgColor); + + RReleaseImage(tmp); + } + panel->hbox = WMCreateBox(vbox); WMSetBoxHorizontal(panel->hbox, True); WMAddBoxSubviewAtEnd(vbox, WMWidgetView(panel->hbox), True, True, 20, 0, 2); WM_ITERATE_ARRAY(panel->windows, wwin, i) { addIconForWindow(panel, wwin, iconWidth); + changeImage(panel, i, 0); } WMMapSubwidgets(panel->win); WMRealizeWidget(panel->win); WMMapWidget(panel->win); - WMMoveWidget(panel->win, - (WMScreenWidth(scr->wmscreen) - (width+10))/2, - (WMScreenHeight(scr->wmscreen) - height)/2); + { + WMPoint center; - WMSetWidgetBackgroundColor(WMGetFromArray(panel->icons, 0), - panel->selectColor); + center= wGetPointToCenterRectInHead(scr, wGetHeadForPointerLocation(scr), + width+10, height); + WMMoveWidget(panel->win, center.x, center.y); + } + changeImage(panel, 0, 1); + return panel; } void wSwitchPanelDestroy(WSwitchPanel *panel) { + int i; + RImage *image; + WM_ITERATE_ARRAY(panel->images, image, i) { + if (image) + RReleaseImage(image); + } WMDestroyWidget(panel->win); WMFreeArray(panel->icons); WMFreeArray(panel->windows); + WMFreeArray(panel->images); WMReleaseColor(panel->selectColor); WMReleaseColor(panel->normalColor); if (panel->defIcon) - WMReleasePixmap(panel->defIcon); + RReleaseImage(panel->defIcon); + RReleaseImage(panel->tile); wfree(panel); } @@ -228,12 +365,9 @@ WWindow *wSwitchPanelSelectNext(WSwitchPanel *panel, int back) { WWindow *wwin; int count = WMGetArrayItemCount(panel->windows); - WMLabel *label; - - label= WMGetFromArray(panel->icons, panel->current); - WMSetWidgetBackgroundColor(label, panel->normalColor); - WMSetLabelRelief(label, WRFlat); + changeImage(panel, panel->current, 0); + if (!back) panel->current = (count + panel->current - 1) % count; else @@ -243,9 +377,7 @@ WWindow *wSwitchPanelSelectNext(WSwitchPanel *panel, int back) WMSetLabelText(panel->label, wwin->frame->title); - label= WMGetFromArray(panel->icons, panel->current); - WMSetWidgetBackgroundColor(label, panel->selectColor); - WMSetLabelRelief(label, WRSimple); + changeImage(panel, panel->current, 1); return wwin; } -- 2.11.4.GIT