diff --git a/.gitignore b/.gitignore index 82592007..eb0d3d85 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,8 @@ WPrefs.app/WPrefs.desktop WINGs/wings-rs-tests/Cargo.lock WINGs/wings-rs/Cargo.lock WINGs/wings-rs/src/WINGsP.rs +WINGs/wings-rs/src/WINGsP/constants.rs +WINGs/wings-rs/src/WINGsP/mod.rs wmaker-rs/Cargo.lock wrlib-rs/src/ffi.rs wrlib-rs/Cargo.lock diff --git a/WINGs/Makefile.am b/WINGs/Makefile.am index 08dd0050..453e36c9 100644 --- a/WINGs/Makefile.am +++ b/WINGs/Makefile.am @@ -45,7 +45,6 @@ libWINGs_la_SOURCES = \ wmenuitem.c \ wmisc.c \ wpanel.c \ - wpixmap.c \ wpopupbutton.c \ wprogressindicator.c \ wruler.c \ diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index 49df41da..4a68fa8b 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -688,8 +688,7 @@ void WMSetApplicationIconPixmap(WMScreen *app, WMPixmap *icon); WMPixmap* WMGetApplicationIconPixmap(WMScreen *app); -/* If color==NULL it will use the default color for panels: ae/aa/ae */ -WMPixmap* WMCreateApplicationIconBlendedPixmap(WMScreen *scr, const RColor *color); +WMPixmap* WMCreateApplicationIconGreyedPixmap(WMScreen *scr); void WMSetApplicationIconWindow(WMScreen *scr, Window window); @@ -833,23 +832,31 @@ WMSize WMGetPixmapSize(WMPixmap *pixmap); WMPixmap* WMCreatePixmapFromFile(WMScreen *scrPtr, const char *fileName); -WMPixmap* WMCreateBlendedPixmapFromRImage(WMScreen *scrPtr, RImage *image, - const RColor *color); +WMPixmap* WMCreateGreyedPixmapFromRImage(WMScreen *scrPtr, RImage *image); -WMPixmap* WMCreateBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName, - const RColor *color); +WMPixmap* WMCreateGreyedPixmapFromFile(WMScreen *scrPtr, const char *fileName); -WMPixmap* WMCreateScaledBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName, - const RColor *color, - unsigned int width, - unsigned int height); +WMPixmap* WMCreateScaledPixmapFromFile(WMScreen *scrPtr, const char *fileName, + unsigned int width, + unsigned int height); + +WMPixmap* WMCreateScaledGreyedPixmapFromFile(WMScreen *scrPtr, const char *fileName, + unsigned int width, + unsigned int height); void WMDrawPixmap(WMPixmap *pixmap, Drawable d, int x, int y); Pixmap WMGetPixmapXID(WMPixmap *pixmap); +/* Note that this can be used to deliberately leak the current pixmap. */ +void WMSetPixmapXID(WMPixmap *pixmap, Pixmap value); + Pixmap WMGetPixmapMaskXID(WMPixmap *pixmap); +void WMSetPixmapMaskXID(WMPixmap *pixmap, Pixmap mask); + +int WMGetPixmapDepth(WMPixmap *pixmap); + WMPixmap* WMGetSystemPixmap(WMScreen *scr, int image); /* ---[ WINGs/wings-rs/src/color.rs ]------------------------------------- */ diff --git a/WINGs/WINGs/WINGsP.h.in b/WINGs/WINGs/WINGsP.h.in index a3d45dfa..000bcacf 100644 --- a/WINGs/WINGs/WINGsP.h.in +++ b/WINGs/WINGs/WINGsP.h.in @@ -71,7 +71,7 @@ typedef struct W_DraggingInfo { typedef struct W_Color W_Color; /* Pre-definition of internal structs */ -typedef struct W_Pixmap W_Pixmap; +typedef struct W_Pixmap WMPixmap; typedef struct W_View W_View; typedef struct W_FocusInfo { @@ -106,7 +106,7 @@ typedef struct W_Screen { W_FocusInfo *focusInfo; RImage *applicationIconImage; /* image (can have alpha channel) */ - W_Pixmap *applicationIconPixmap; /* pixmap - no alpha channel */ + WMPixmap *applicationIconPixmap; /* pixmap - no alpha channel */ Window applicationIconWindow; struct W_Window *windowList; /* list of windows in the app */ @@ -165,57 +165,57 @@ typedef struct W_Screen { struct W_Balloon *balloon; - W_Pixmap *checkButtonImageOn; - W_Pixmap *checkButtonImageOff; + WMPixmap *checkButtonImageOn; + WMPixmap *checkButtonImageOff; - W_Pixmap *radioButtonImageOn; - W_Pixmap *radioButtonImageOff; + WMPixmap *radioButtonImageOn; + WMPixmap *radioButtonImageOff; - W_Pixmap *buttonArrow; - W_Pixmap *pushedButtonArrow; + WMPixmap *buttonArrow; + WMPixmap *pushedButtonArrow; - W_Pixmap *scrollerDimple; + WMPixmap *scrollerDimple; - W_Pixmap *upArrow; - W_Pixmap *downArrow; - W_Pixmap *leftArrow; - W_Pixmap *rightArrow; + WMPixmap *upArrow; + WMPixmap *downArrow; + WMPixmap *leftArrow; + WMPixmap *rightArrow; - W_Pixmap *hiUpArrow; - W_Pixmap *hiDownArrow; - W_Pixmap *hiLeftArrow; - W_Pixmap *hiRightArrow; + WMPixmap *hiUpArrow; + WMPixmap *hiDownArrow; + WMPixmap *hiLeftArrow; + WMPixmap *hiRightArrow; - W_Pixmap *pullDownIndicator; - W_Pixmap *popUpIndicator; + WMPixmap *pullDownIndicator; + WMPixmap *popUpIndicator; - W_Pixmap *checkMark; + WMPixmap *checkMark; - W_Pixmap *homeIcon; - W_Pixmap *altHomeIcon; + WMPixmap *homeIcon; + WMPixmap *altHomeIcon; - W_Pixmap *trashcanIcon; - W_Pixmap *altTrashcanIcon; + WMPixmap *trashcanIcon; + WMPixmap *altTrashcanIcon; - W_Pixmap *createDirIcon; - W_Pixmap *altCreateDirIcon; + WMPixmap *createDirIcon; + WMPixmap *altCreateDirIcon; - W_Pixmap *disketteIcon; - W_Pixmap *altDisketteIcon; - W_Pixmap *unmountIcon; - W_Pixmap *altUnmountIcon; + WMPixmap *disketteIcon; + WMPixmap *altDisketteIcon; + WMPixmap *unmountIcon; + WMPixmap *altUnmountIcon; - W_Pixmap *magnifyIcon; - /*W_Pixmap *altMagnifyIcon;*/ - W_Pixmap *wheelIcon; - W_Pixmap *grayIcon; - W_Pixmap *rgbIcon; - W_Pixmap *cmykIcon; - W_Pixmap *hsbIcon; - W_Pixmap *customPaletteIcon; - W_Pixmap *colorListIcon; + WMPixmap *magnifyIcon; + /*WMPixmap *altMagnifyIcon;*/ + WMPixmap *wheelIcon; + WMPixmap *grayIcon; + WMPixmap *rgbIcon; + WMPixmap *cmykIcon; + WMPixmap *hsbIcon; + WMPixmap *customPaletteIcon; + WMPixmap *colorListIcon; - W_Pixmap *defaultObjectIcon; + WMPixmap *defaultObjectIcon; Cursor defaultCursor; @@ -272,9 +272,9 @@ typedef struct W_Screen { * Added at the end of the structure to avoid breaking binary compatibility * with previous versions of the toolkit */ - W_Pixmap *tristateButtonImageOn; - W_Pixmap *tristateButtonImageOff; - W_Pixmap *tristateButtonImageTri; + WMPixmap *tristateButtonImageOn; + WMPixmap *tristateButtonImageOff; + WMPixmap *tristateButtonImageTri; } W_Screen; @@ -476,7 +476,7 @@ void W_DrawReliefWithGC(W_Screen *scr, Drawable d, int x, int y, void W_PaintTextAndImage(W_View *view, int wrap, WMColor *textColor, WMFont *font, WMReliefType relief, const char *text, - WMAlignment alignment, W_Pixmap *image, + WMAlignment alignment, WMPixmap *image, WMImagePosition position, WMColor *backColor, int ofs); void W_PaintText(W_View *view, Drawable d, WMFont *font, int x, int y, @@ -486,19 +486,6 @@ void W_PaintText(W_View *view, Drawable d, WMFont *font, int x, int y, int W_GetTextHeight(WMFont *font, const char *text, int width, int wrap); -/* ---[ wpixmap.c ]------------------------------------------------------- */ - -struct W_Pixmap { - struct W_Screen *screen; - Pixmap pixmap; - Pixmap mask; - unsigned short width; - unsigned short height; - short depth; - short refCount; -}; - - /* ---[ wview.c ]--------------------------------------------------------- */ typedef struct W_ViewDelegate { diff --git a/WINGs/dragsource.c b/WINGs/dragsource.c index c6bb9466..a97136e3 100644 --- a/WINGs/dragsource.c +++ b/WINGs/dragsource.c @@ -195,7 +195,7 @@ static Window makeDragIcon(WMScreen * scr, WMPixmap * pixmap) flags = CWSaveUnder | CWBackPixmap | CWOverrideRedirect | CWColormap; attribs.save_under = True; - attribs.background_pixmap = pixmap->pixmap; + attribs.background_pixmap = WMGetPixmapXID(pixmap); attribs.override_redirect = True; attribs.colormap = scr->colormap; @@ -203,8 +203,8 @@ static Window makeDragIcon(WMScreen * scr, WMPixmap * pixmap) size.height, 0, scr->depth, InputOutput, scr->visual, flags, &attribs); #ifdef USE_XSHAPE - if (pixmap->mask) { - XShapeCombineMask(scr->display, window, ShapeBounding, 0, 0, pixmap->mask, ShapeSet); + if (WMGetPixmapMaskXID(pixmap)) { + XShapeCombineMask(scr->display, window, ShapeBounding, 0, 0, WMGetPixmapMaskXID(pixmap), ShapeSet); } #endif diff --git a/WINGs/wappresource.c b/WINGs/wappresource.c index 013049c0..c0f54b79 100644 --- a/WINGs/wappresource.c +++ b/WINGs/wappresource.c @@ -63,8 +63,8 @@ void WMSetApplicationIconPixmap(WMScreen * scr, WMPixmap * icon) hints = XGetWMHints(scr->display, scr->groupLeader); hints->flags |= IconPixmapHint | IconMaskHint; - hints->icon_pixmap = (icon != NULL ? icon->pixmap : None); - hints->icon_mask = (icon != NULL ? icon->mask : None); + hints->icon_pixmap = (icon != NULL ? WMGetPixmapXID(icon) : None); + hints->icon_mask = (icon != NULL ? WMGetPixmapMaskXID(icon) : None); XSetWMHints(scr->display, scr->groupLeader, hints); XFree(hints); @@ -76,22 +76,12 @@ WMPixmap *WMGetApplicationIconPixmap(WMScreen * scr) return scr->applicationIconPixmap; } -WMPixmap *WMCreateApplicationIconBlendedPixmap(WMScreen * scr, const RColor * color) +WMPixmap *WMCreateApplicationIconGreyedPixmap(WMScreen * scr) { WMPixmap *pix; if (scr->applicationIconImage) { - static const RColor gray = { - /* red */ 0xAE, - /* green */ 0xAA, - /* blue */ 0xAE, - /* alpha */ 0xFF - }; - - if (!color) - color = &gray; - - pix = WMCreateBlendedPixmapFromRImage(scr, scr->applicationIconImage, color); + pix = WMCreateGreyedPixmapFromRImage(scr, scr->applicationIconImage); } else { pix = NULL; } @@ -133,10 +123,10 @@ void W_InitApplication(WMScreen * scr) */ if (scr->applicationIconPixmap) { hints->flags |= IconPixmapHint; - hints->icon_pixmap = scr->applicationIconPixmap->pixmap; - if (scr->applicationIconPixmap->mask) { + hints->icon_pixmap = WMGetPixmapXID(scr->applicationIconPixmap); + if (WMGetPixmapMaskXID(scr->applicationIconPixmap)) { hints->flags |= IconMaskHint; - hints->icon_mask = scr->applicationIconPixmap->mask; + hints->icon_mask = WMGetPixmapMaskXID(scr->applicationIconPixmap); } } diff --git a/WINGs/wbutton.c b/WINGs/wbutton.c index f8c23cd3..7312f949 100644 --- a/WINGs/wbutton.c +++ b/WINGs/wbutton.c @@ -15,11 +15,11 @@ typedef struct W_Button { WMColor *altTextColor; WMColor *disTextColor; - W_Pixmap *image; - W_Pixmap *altImage; - W_Pixmap *tsImage; + WMPixmap *image; + WMPixmap *altImage; + WMPixmap *tsImage; - W_Pixmap *dimage; + WMPixmap *dimage; void *clientData; WMAction *action; @@ -232,32 +232,32 @@ static void updateDisabledMask(WMButton * bPtr) if (bPtr->image) { XGCValues gcv; - if (bPtr->dimage->mask) { - XFreePixmap(dpy, bPtr->dimage->mask); - bPtr->dimage->mask = None; + if (WMGetPixmapMaskXID(bPtr->dimage)) { + XFreePixmap(dpy, WMGetPixmapMaskXID(bPtr->dimage)); + WMSetPixmapMaskXID(bPtr->dimage, 0); } if (bPtr->flags.dimsWhenDisabled) { - bPtr->dimage->mask = XCreatePixmap(dpy, scr->stipple, - bPtr->dimage->width, bPtr->dimage->height, 1); + WMSize size = WMGetPixmapSize(bPtr->dimage); + WMSetPixmapMaskXID(bPtr->dimage, XCreatePixmap(dpy, scr->stipple, size.width, size.height, 1)); XSetForeground(dpy, scr->monoGC, 0); - XFillRectangle(dpy, bPtr->dimage->mask, scr->monoGC, 0, 0, - bPtr->dimage->width, bPtr->dimage->height); + XFillRectangle(dpy, WMGetPixmapMaskXID(bPtr->dimage), scr->monoGC, 0, 0, + size.width, size.height); gcv.foreground = 1; gcv.background = 0; gcv.stipple = scr->stipple; gcv.fill_style = FillStippled; - gcv.clip_mask = bPtr->image->mask; + gcv.clip_mask = WMGetPixmapMaskXID(bPtr->image); gcv.clip_x_origin = 0; gcv.clip_y_origin = 0; XChangeGC(dpy, scr->monoGC, GCForeground | GCBackground | GCStipple | GCFillStyle | GCClipMask | GCClipXOrigin | GCClipYOrigin, &gcv); - XFillRectangle(dpy, bPtr->dimage->mask, scr->monoGC, 0, 0, - bPtr->dimage->width, bPtr->dimage->height); + XFillRectangle(dpy, WMGetPixmapMaskXID(bPtr->dimage), scr->monoGC, 0, 0, + size.width, size.height); gcv.fill_style = FillSolid; gcv.clip_mask = None; @@ -279,15 +279,17 @@ void WMSetButtonImage(WMButton * bPtr, WMPixmap * image) bPtr->image = WMRetainPixmap(image); if (bPtr->dimage) { - bPtr->dimage->pixmap = None; + WMSetPixmapXID(bPtr->dimage, None); WMReleasePixmap(bPtr->dimage); bPtr->dimage = NULL; } if (image) { + WMSize size = WMGetPixmapSize(image); bPtr->dimage = WMCreatePixmapFromXPixmaps(WMWidgetScreen(bPtr), - image->pixmap, None, - image->width, image->height, image->depth); + WMGetPixmapXID(image), None, + size.width, size.height, + WMGetPixmapDepth(image)); updateDisabledMask(bPtr); } @@ -771,7 +773,7 @@ static void destroyButton(Button * bPtr) if (bPtr->dimage) { /* yuck.. kluge */ - bPtr->dimage->pixmap = None; + WMSetPixmapXID(bPtr->dimage, None); WMReleasePixmap(bPtr->dimage); } diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c index 5ae526f5..f58c6a75 100644 --- a/WINGs/wcolorpanel.c +++ b/WINGs/wcolorpanel.c @@ -560,7 +560,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->grayBrightnessS), pixmap->pixmap, + W_PaintText(W_VIEW(panel->grayBrightnessS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->white, False, _("Brightness"), strlen(_("Brightness"))); else @@ -581,7 +581,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) graybuttoncolor = WMCreateRGBColor(scrPtr, (255 / 6) * i << 8, (255 / 6) * i << 8, (255 / 6) * i << 8, True); - WMPaintColorSwatch(graybuttoncolor, pixmap->pixmap, 0, 0, 15, 15); + WMPaintColorSwatch(graybuttoncolor, WMGetPixmapXID(pixmap), 0, 0, 15, 15); WMReleaseColor(graybuttoncolor); panel->grayPresetBtn[i] = WMCreateCommandButton(panel->grayFrm); @@ -635,7 +635,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->rgbRedS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->rgbRedS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->white, False, _("Red"), strlen(_("Red"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -666,7 +666,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->rgbGreenS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->rgbGreenS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->white, False, _("Green"), strlen(_("Green"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -697,7 +697,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->rgbBlueS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->rgbBlueS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->white, False, _("Blue"), strlen(_("Blue"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -772,7 +772,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->cmykCyanS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->cmykCyanS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->black, False, _("Cyan"), strlen(_("Cyan"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -803,7 +803,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->cmykMagentaS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->cmykMagentaS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->black, False, _("Magenta"), strlen(_("Magenta"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -835,7 +835,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->cmykYellowS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->cmykYellowS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->black, False, _("Yellow"), strlen(_("Yellow"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -868,7 +868,7 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, const char *name) RReleaseImage(image); if (pixmap) - W_PaintText(W_VIEW(panel->cmykBlackS), pixmap->pixmap, panel->font12, + W_PaintText(W_VIEW(panel->cmykBlackS), WMGetPixmapXID(pixmap), panel->font12, 2, 0, 100, WALeft, scrPtr->black, False, _("Black"), strlen(_("Black"))); else wwarning(_("Color Panel: Could not allocate memory")); @@ -2711,7 +2711,7 @@ static void hsbUpdateBrightnessGradient(W_ColorPanel * panel) RReleaseImage(sliderImg); if (sliderPxmp) - W_PaintText(W_VIEW(panel->hsbBrightnessS), sliderPxmp->pixmap, + W_PaintText(W_VIEW(panel->hsbBrightnessS), WMGetPixmapXID(sliderPxmp), panel->font12, 2, 0, 100, WALeft, scr->white, False, _("Brightness"), strlen(_("Brightness"))); else @@ -2744,7 +2744,7 @@ static void hsbUpdateSaturationGradient(W_ColorPanel * panel) RReleaseImage(sliderImg); if (sliderPxmp) - W_PaintText(W_VIEW(panel->hsbSaturationS), sliderPxmp->pixmap, + W_PaintText(W_VIEW(panel->hsbSaturationS), WMGetPixmapXID(sliderPxmp), panel->font12, 2, 0, 100, WALeft, from.hsv.value < 128 ? scr->white : scr->black, False, _("Saturation"), strlen(_("Saturation"))); @@ -2779,7 +2779,7 @@ static void hsbUpdateHueGradient(W_ColorPanel * panel) RReleaseImage(sliderImg); if (sliderPxmp) - W_PaintText(W_VIEW(panel->hsbHueS), sliderPxmp->pixmap, + W_PaintText(W_VIEW(panel->hsbHueS), WMGetPixmapXID(sliderPxmp), panel->font12, 2, 0, 100, WALeft, hsvcolor.value < 128 ? scr->white : scr->black, False, _("Hue"), strlen(_("Hue"))); else diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index cb01ca1a..d620fa63 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -180,7 +180,7 @@ static WMFilePanel *makeFilePanel(WMScreen * scrPtr, const char *name, const cha WMResizeWidget(fPtr->iconLabel, 64, 64); WMMoveWidget(fPtr->iconLabel, 0, 0); WMSetLabelImagePosition(fPtr->iconLabel, WIPImageOnly); - icon = WMCreateApplicationIconBlendedPixmap(scrPtr, (RColor *) NULL); + icon = WMCreateApplicationIconGreyedPixmap(scrPtr); if (icon) { WMSetLabelImage(fPtr->iconLabel, icon); WMReleasePixmap(icon); diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap index 13c6fb0e..61d1314b 100644 --- a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap @@ -1,6 +1,6 @@ --- source: tests/wmpixmap_tests.rs -assertion_line: 63 +assertion_line: 56 expression: app.xvfb.png_screenshot() extension: png snapshot_kind: binary diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_grey.snap similarity index 85% rename from WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap rename to WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_grey.snap index b1482c84..fab3a044 100644 --- a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_grey.snap @@ -1,6 +1,6 @@ --- source: tests/wmpixmap_tests.rs -assertion_line: 175 +assertion_line: 162 expression: app.xvfb.png_screenshot() extension: png snapshot_kind: binary diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_grey.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_grey.snap.png new file mode 100644 index 00000000..10189505 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_grey.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap.png deleted file mode 100644 index c2917169..00000000 Binary files a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap.png and /dev/null differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_grey.snap similarity index 85% rename from WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap rename to WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_grey.snap index b4eb991a..1b86eafd 100644 --- a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_grey.snap @@ -1,6 +1,6 @@ --- source: tests/wmpixmap_tests.rs -assertion_line: 239 +assertion_line: 220 expression: app.xvfb.png_screenshot() extension: png snapshot_kind: binary diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_grey.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_grey.snap.png new file mode 100644 index 00000000..d4b2ffe9 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_grey.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap.png deleted file mode 100644 index 4b1d8ca9..00000000 Binary files a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap.png and /dev/null differ diff --git a/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs b/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs index 85d8fb65..753e4791 100644 --- a/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs +++ b/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs @@ -3,13 +3,9 @@ use std::{ ptr::{self, NonNull}, time::Instant, }; -use wings_rs::WINGsP::{ - WMCreateBlendedPixmapFromFile, WMCreateBlendedPixmapFromRImage, WMCreatePixmap, - WMCreatePixmapFromFile, WMCreatePixmapFromRImage, WMCreateScaledBlendedPixmapFromFile, - WMDrawPixmap, WMReleasePixmap, -}; +use wings_rs::pixmap::ffi::*; use wings_rs_tests::HeadlessApplication; -use wrlib_rs::ffi::{RColor, RLoadImage, RReleaseImage}; +use wrlib_rs::ffi::{RLoadImage, RReleaseImage}; #[test] fn draw_blank_pixmap() { @@ -34,9 +30,9 @@ fn draw_blank_pixmap() { while app.pump_event_queue(Instant::now()) {} assert_png_snapshot!("empty_window", app.xvfb.png_screenshot()); - let gc = x11::xlib::XCreateGC(display, (*pixmap.as_ptr()).pixmap, 0, ptr::null_mut()); + let gc = x11::xlib::XCreateGC(display, (*pixmap.as_ptr()).pixmap(), 0, ptr::null_mut()); x11::xlib::XSetForeground(display, gc, 0); - x11::xlib::XFillRectangle(display, (*pixmap.as_ptr()).pixmap, gc, 0, 0, 128, 196); + x11::xlib::XFillRectangle(display, (*pixmap.as_ptr()).pixmap(), gc, 0, 0, 128, 196); WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); while app.pump_event_queue(Instant::now()) {} assert_png_snapshot!("empty_pixmap_on_window", app.xvfb.png_screenshot()); @@ -209,17 +205,8 @@ fn draw_blended_pixmap_from_r_image() { c"tests/image_128x120.png".as_ptr(), 0, ); - let pixmap = NonNull::new(WMCreateBlendedPixmapFromRImage( - app.screen.as_ptr(), - rimage, - &RColor { - red: 255, - green: 0, - blue: 0, - alpha: 255, - } as *const _, - )) - .unwrap(); + let pixmap = + NonNull::new(WMCreateGreyedPixmapFromRImage(app.screen.as_ptr(), rimage)).unwrap(); WMDrawPixmap(pixmap.as_ptr(), win, 70, 74); while app.pump_event_queue(Instant::now()) {} @@ -276,21 +263,15 @@ fn draw_blended_pixmap_from_file() { app.xvfb.png_screenshot() ); - let pixmap = NonNull::new(WMCreateBlendedPixmapFromFile( + let pixmap = NonNull::new(WMCreateGreyedPixmapFromFile( app.screen.as_ptr(), c"tests/image_with_transparent_dot_128x120.png".as_ptr(), - &RColor { - red: 255, - green: 0, - blue: 0, - alpha: 255, - } as *const _, )) .unwrap(); WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); while app.pump_event_queue(Instant::now()) {} - assert_png_snapshot!("from_file_blended_with_red", app.xvfb.png_screenshot()); + assert_png_snapshot!("from_file_blended_with_grey", app.xvfb.png_screenshot()); WMReleasePixmap(pixmap.as_ptr()); } } @@ -346,15 +327,9 @@ fn draw_scaled_blended_pixmap_from_file() { app.xvfb.png_screenshot() ); - let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile( + let pixmap = NonNull::new(WMCreateScaledGreyedPixmapFromFile( app.screen.as_ptr(), c"tests/image_with_transparent_dot_128x120.png".as_ptr(), - &RColor { - red: 255, - green: 0, - blue: 0, - alpha: 255, - } as *const _, 60, 64, )) @@ -363,7 +338,7 @@ fn draw_scaled_blended_pixmap_from_file() { while app.pump_event_queue(Instant::now()) {} assert_png_snapshot!( - "from_file_scaled_blended_with_red", + "from_file_scaled_blended_with_grey", app.xvfb.png_screenshot() ); WMReleasePixmap(pixmap.as_ptr()); @@ -421,16 +396,10 @@ fn draw_scaled_blended_pixmap_from_file_non_integral_scaling() { app.xvfb.png_screenshot() ); - let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile( + let pixmap = NonNull::new(WMCreateScaledGreyedPixmapFromFile( app.screen.as_ptr(), // No alpha channel on this image, so no color blending happens. c"tests/image_128x120.png".as_ptr(), - &RColor { - red: 255, - green: 0, - blue: 0, - alpha: 255, - } as *const _, // Shrink by only a little bit, such that simple integer division // might be thrown off. This test ensures that rescaling will // actually happen. diff --git a/WINGs/wings-rs/Makefile.am b/WINGs/wings-rs/Makefile.am index 14eda0fe..26d4f663 100644 --- a/WINGs/wings-rs/Makefile.am +++ b/WINGs/wings-rs/Makefile.am @@ -1,7 +1,8 @@ AUTOMAKE_OPTIONS = RUST_SRC = \ - src/WINGsP.rs \ + src/WINGsP/constants.rs \ + src/WINGsP/mod.rs \ src/button.rs \ src/color.rs \ src/configuration.rs \ @@ -11,6 +12,7 @@ RUST_SRC = \ src/lib.rs \ src/list.rs \ src/pango_extras.rs \ + src/pixmap.rs \ src/screen.rs \ src/widget.rs @@ -18,11 +20,14 @@ RUST_EXTRA = \ Cargo.lock \ Cargo.toml -src/WINGsP.rs: ../WINGs/WINGsP.h ../../wrlib/wraster.h ../WINGs/WINGs.h ../WINGs/WUtil.h Makefile patch_WINGsP.sh - $(BINDGEN) ../WINGs/WINGsP.h \ + src/WINGsP/mod.rs: ../WINGs/WINGsP.h ../../wrlib/wraster.h ../WINGs/WINGs.h ../WINGs/WUtil.h Makefile patch_WINGsP.sed + mkdir -p src/WINGsP \ + && $(BINDGEN) ../WINGs/WINGsP.h \ --no-recursive-allowlist \ - --allowlist-type "^W_.+|^WM(View|Array|DragOperationType|Point|Data|OpenPanel|SavePanel|HashTable|DraggingInfo|SelectionProcs|Rect|EventProc|Widget|Size|Pixmap|FilePanel|List|ListItem)" \ + --allowlist-type "^W_.+|^WM(View|DragOperationType|Point|Data|OpenPanel|SavePanel|HashTable|DraggingInfo|SelectionProcs|Rect|EventProc|Widget|Size|FilePanel|List|ListItem)" \ --allowlist-type "^WM(FontPanel|Screen|Button)" \ + --allowlist-type "^W_(Screen|View|DragSourceProcs|ViewDelegate|DragDestinationProcs|Data|HashTable|Button|FilePanel|DraggingInfo|IMContext|Window|FocusInfo|SelectionHandlers|FontPanel|DragSourceInfo|DragDestinationInfo|ColorPanel|Balloon|DndState)" \ + --allowlist-type "^WM(View|DragOperationType|Point|Data|OpenPanel|SavePanel|HashTable|DraggingInfo|SelectionProcs|Rect|EventProc|Widget|Size|FilePanel|FontPanel|Screen|Button)|_WINGsConfiguration" \ --allowlist-function "^WMCreateScreen|^WM(Get|Show)FontPanel|^WMCreateCommandButton|^WM(Initialize|Release)Application|^WMScreenMainLoop|^WMHandleEvent" \ --allowlist-function "^WMWidgetScreen|^WM(Initialize|Release)Application|^WM(ScreenMainLoop|HandleEvent)|^WM(((Get|Set)TextFieldFont)|GetTextFieldText|SetTextFieldText|SelectTextFieldRange)" \ --allowlist-type "WMList" \ @@ -51,11 +56,18 @@ src/WINGsP.rs: ../WINGs/WINGsP.h ../../wrlib/wraster.h ../WINGs/WINGs.h ../WINGs --allowlist-type "_WINGsConfiguration" \ --allowlist-item "^WMAlignment" \ --allowlist-item "^WMReliefType" \ - --allowlist-function "^WM(Create|Release|Draw)Pixmap|^WMCreate(|Blended|ScaledBlended)PixmapFromFile|^WMCreate(|Blended)PixmapFromRImage" \ - -o src/WINGsP.rs -- \ + -o src/WINGsP/mod.rs -- \ @PANGO_CFLAGS@ \ -I../../wrlib \ - -I.. && ./patch_WINGsP.sh src/WINGsP.rs + -I.. \ + && sed -i -r -f patch_WINGsP.sed src/WINGsP/mod.rs + +src/WINGsP/constants.rs: src/WINGsP src/defines.h ../WINGs/WINGs.h Makefile + $(BINDGEN) src/defines.h \ + --allowlist-type WSystemIcon \ + -o src/WINGsP/constants.rs -- \ + -I../../wrlib \ + -I.. Cargo.lock: $(CARGO) build @@ -69,5 +81,7 @@ check-local: clean-local: $(CARGO) clean rm -f src/WINGsP.rs + rm -f src/WINGsP/constants.rs + rm -f src/WINGsP/mod.rs all: target/debug/libwings_rs.so diff --git a/WINGs/wings-rs/patch_WINGsP.sed b/WINGs/wings-rs/patch_WINGsP.sed new file mode 100644 index 00000000..21f58ca1 --- /dev/null +++ b/WINGs/wings-rs/patch_WINGsP.sed @@ -0,0 +1,10 @@ +# This file provides ad-hoc fixups to the WINGsP provided by bindgen: +# - Import Xlib symbols so that everything compiles. +# - Import FFI symbols from Rust bindings and rewrites. +# - The opaque type names _XftDraw and _XftFont are replaced with void*. +# - Pango bindings aren't yet pulled into our Rust code, so PangoLayout is also demoted to void*. + +1s/^/use wrlib_rs::ffi::*;\nuse wutil_rs::array::ffi::*;\nuse wutil_rs::range::ffi::*;\nuse x11::xlib::*;\nuse crate::ffi::*;\n\npub mod constants;\n\n/ +s/_XftDraw/::std::ffi::c_void/g +s/_XftFont/::std::ffi::c_void/g +s/PangoLayout/::std::ffi::c_void/g diff --git a/WINGs/wings-rs/patch_WINGsP.sh b/WINGs/wings-rs/patch_WINGsP.sh deleted file mode 100755 index 966ed1ea..00000000 --- a/WINGs/wings-rs/patch_WINGsP.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -# This file provides ad-hoc fixups to the WINGsP provided by bindgen: -# - Import Xlib symbols so that everything compiles. -# - The opaque type names _XftDraw and _XftFont are replaced with void*. -# - Pango bindings aren't yet pulled into our Rust code, so PangoLayout is also demoted to void*. - -set -e - -if [ "x$1" = "x" ]; then - echo "Usage: $(basename $0) " - exit 1 -fi - -FILE="$1" - -exec sed -i -r \ - -e "1s/^/use wrlib_rs::ffi::*;\nuse wutil_rs::range::ffi::*;\nuse x11::xlib::*;\nuse crate::ffi::*;\n\n/" \ - -e "s/_XftDraw/::std::ffi::c_void/g" \ - -e "s/_XftFont/::std::ffi::c_void/g" \ - -e "s/PangoLayout/::std::ffi::c_void/g" \ - "$1" diff --git a/WINGs/wings-rs/src/defines.h b/WINGs/wings-rs/src/defines.h new file mode 100644 index 00000000..dad7bdce --- /dev/null +++ b/WINGs/wings-rs/src/defines.h @@ -0,0 +1,18 @@ +// Exposes preprocessor symbol constants as an enum so that bindgen can see them. + +#include "../../WINGs/WINGs.h" + +enum WSystemIcon { + ReturnArrow = WSIReturnArrow, + HighlightedReturnArrow = WSIHighlightedReturnArrow, + ScrollerDimple = WSIScrollerDimple, + ArrowLeft = WSIArrowLeft, + HighlightedArrowLeft = WSIHighlightedArrowLeft, + ArrowRight = WSIArrowRight, + HighlightedArrowRight = WSIHighlightedArrowRight, + ArrowUp = WSIArrowUp, + HighlightedArrowUp = WSIHighlightedArrowUp, + ArrowDown = WSIArrowDown, + HighlightedArrowDown = WSIHighlightedArrowDown, + CheckMark = WSICheckMark, +}; diff --git a/WINGs/wings-rs/src/ffi.rs b/WINGs/wings-rs/src/ffi.rs index 3ef6248c..b0727f16 100644 --- a/WINGs/wings-rs/src/ffi.rs +++ b/WINGs/wings-rs/src/ffi.rs @@ -1,2 +1,5 @@ +//! Provides reexports of all public FFI symbols, for convenience. + pub use crate::color::ffi::*; pub use crate::font::ffi::*; +pub use crate::pixmap::ffi::*; diff --git a/WINGs/wings-rs/src/lib.rs b/WINGs/wings-rs/src/lib.rs index 4364ee1b..6afff5f5 100644 --- a/WINGs/wings-rs/src/lib.rs +++ b/WINGs/wings-rs/src/lib.rs @@ -11,5 +11,6 @@ pub mod font; pub mod font_panel; pub mod list; pub(crate) mod pango_extras; +pub mod pixmap; pub mod screen; pub mod widget; diff --git a/WINGs/wings-rs/src/pixmap.rs b/WINGs/wings-rs/src/pixmap.rs new file mode 100644 index 00000000..c10a4aae --- /dev/null +++ b/WINGs/wings-rs/src/pixmap.rs @@ -0,0 +1,602 @@ +use crate::WINGsP; +use std::{ + cell::RefCell, + ffi::CStr, + ptr::NonNull, +}; + +pub struct Pixmap { + display: NonNull, + clip_gc: x11::xlib::GC, + pixmap: RefCell, + mask: RefCell, + width: u16, + height: u16, + depth: u16, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum Masked { + Yes, + No, +} + +impl Pixmap { + pub fn new(screen: NonNull, width: u16, height: u16, depth: u16, masked: Masked) -> Self { + let display = NonNull::new(unsafe { (*screen.as_ptr()).display }).unwrap(); + let drawable = unsafe { (*(*screen.as_ptr()).rcontext).drawable }; + let clip_gc = unsafe { (*screen.as_ptr()).clipGC }; + let pixmap = unsafe { x11::xlib::XCreatePixmap(display.as_ptr(), drawable, width.into(), height.into(), depth.into()) }; + let mask = match masked { + Masked::Yes => RefCell::new(unsafe { x11::xlib::XCreatePixmap(display.as_ptr(), drawable, width.into(), height.into(), 1) }), + Masked::No => RefCell::new(0), + }; + Pixmap { + display, + clip_gc, + pixmap: RefCell::new(pixmap), + mask, + width, + height, + depth, + } + } + + pub fn new_from_x_pixmaps( + screen: NonNull, + pixmap: x11::xlib::Pixmap, + mask: x11::xlib::Pixmap, + width: u16, + height: u16, + depth: u16, + ) -> Self { + let display = NonNull::new(unsafe { (*screen.as_ptr()).display }).unwrap(); + let clip_gc = unsafe { (*screen.as_ptr()).clipGC }; + Pixmap { + display, + clip_gc, + pixmap: RefCell::new(pixmap), + mask: RefCell::new(mask), + width, + height, + depth, + } + } + + pub fn new_from_file( + screen: NonNull, + file_name: &CStr, + ) -> Option { + let rcontext = NonNull::new(unsafe { (*screen.as_ptr()).rcontext }).unwrap(); + let Some(image) = NonNull::new(unsafe { wrlib_rs::ffi::RLoadImage(rcontext.as_ptr(), file_name.as_ptr(), 0) }) else { + return None; + }; + let result = Self::new_from_r_image(screen, image, 127); + unsafe { wrlib_rs::ffi::RReleaseImage(image.as_ptr()) }; + result + } + + pub fn new_from_r_image( + screen: NonNull, + image: NonNull, + threshold: u16, + ) -> Option { + let display = NonNull::new(unsafe { (*screen.as_ptr()).display }).unwrap(); + let clip_gc = unsafe { (*screen.as_ptr()).clipGC }; + let depth: u16 = unsafe { (*screen.as_ptr()).depth.try_into().expect("invalid depth") }; + let rcontext = NonNull::new(unsafe { (*screen.as_ptr()).rcontext }).unwrap(); + let mut pixmap: x11::xlib::Pixmap = 0; + let mut mask: x11::xlib::Pixmap = 0; + if unsafe { wrlib_rs::ffi::RConvertImageMask(rcontext.as_ptr(), image.as_ptr(), &mut pixmap, &mut mask, threshold.into()) } == 0 { + return None; + } + + let (width, height) = unsafe { + ((*image.as_ptr()).width.try_into().expect("invalid width"), + (*image.as_ptr()).height.try_into().expect("invalid height")) + }; + Some(Pixmap { + display, + clip_gc, + pixmap: RefCell::new(pixmap), + mask: RefCell::new(mask), + width, + height, + depth, + }) + } + + pub fn draw(&self, drawable: x11::xlib::Drawable, x: i32, y: i32) { + unsafe { + x11::xlib::XSetClipMask(self.display.as_ptr(), self.clip_gc, *self.mask.borrow()); + x11::xlib::XSetClipOrigin(self.display.as_ptr(), self.clip_gc, x, y); + x11::xlib::XCopyArea( + self.display.as_ptr(), + *self.pixmap.borrow(), + drawable, + self.clip_gc, + 0, + 0, + self.width.into(), + self.height.into(), + x, + y, + ); + } + } + + pub fn pixmap(&self) -> x11::xlib::Pixmap { + *self.pixmap.borrow() + } + + pub fn mask(&self) -> x11::xlib::Pixmap { + *self.mask.borrow() + } +} + +/// Attempts to load an `RImage` from `file_name` and returns the value of invoking `f` on it. +/// +/// If image loading fails, `f` is invoked on a `None` value. +/// +/// For example: +/// +/// ```ignore +/// # use std::ffi::CString; +/// # use wings_rs::pixmap::with_r_image_from_file; +/// # fn main() { +/// # let rcontext = unsafe { wrlib_rs::RCreateContext(display, 0, ptr::null_mut()) }; +/// let (width, height) = with_r_image_from_file( +/// rcontext, +/// &CString::new("test_image_32x48.png").unwrap(), +/// |image| { +/// let image = image.expect("image loading failed"); +/// ((*image.as_ptr()).width, (*image.as_ptr()).height) +/// } +/// ); +/// assert_eq!(width, 32); +/// assert_eq!(height, 48); +/// # unsafe { wrlib_rs::RDestroyContext(rcontext); } +/// # } +/// ``` +pub fn with_r_image_from_file( + rcontext: NonNull, + file_name: &CStr, + f: impl FnOnce(Option>) -> R, +) -> R { + let image = NonNull::new(unsafe { + wrlib_rs::ffi::RLoadImage(rcontext.as_ptr(), file_name.as_ptr(), 0) + }); + let result = f(image); + if let Some(image) = image { + unsafe { wrlib_rs::ffi::RReleaseImage(image.as_ptr()); } + } + result +} + +#[derive(Clone, Copy, Eq, PartialEq, Debug)] +pub enum Transform { + Downscale { width: u32, height: u32 }, + Greymask, +} + +impl Transform { + pub fn with_transformed( + mut image: NonNull, + transforms: &[Transform], + f: impl FnOnce(NonNull) -> R, + ) -> R { + let mut transforms_i = transforms.iter(); + if let Some(t) = transforms_i.next() { + image = t.apply(image); + } + for t in transforms_i { + let next_image = t.apply(image); + unsafe { wrlib_rs::ffi::RReleaseImage(image.as_ptr()); } + image = next_image; + } + let result = f(image); + if !transforms.is_empty() { + unsafe { wrlib_rs::ffi::RReleaseImage(image.as_ptr()); } + } + result + } + + fn apply( + &self, + image: NonNull, + ) -> NonNull { + match self { + Transform::Downscale { width, height } => { + let Ok(current_width): Result = (unsafe { (*image.as_ptr()).width.try_into() }) else { + return image; + }; + let Ok(current_height): Result = (unsafe { (*image.as_ptr()).height.try_into() }) else { + return image; + }; + if current_width <= *width && current_height <= *height { + return image; + } + + let mut new_width = current_width; + let mut new_height = current_height; + if new_width > *width { + new_width = *width; + new_height = *width * current_height / current_width; + } + if new_height > *height { + new_width = *height * current_width / current_height; + new_height = *height; + } + let image = unsafe { wrlib_rs::ffi::RScaleImage(image.as_ptr(), new_width, new_height) }; + NonNull::new(image).expect("RScaleImage failed") + } + Transform::Greymask => { + const GREY: wrlib_rs::ffi::RColor = wrlib_rs::ffi::RColor { + red: 0xAE, + green: 0xAA, + blue: 0xAE, + alpha: 0xFF, + }; + unsafe { + let result = NonNull::new(wrlib_rs::ffi::RCloneImage(image.as_ptr())) + .expect("RCloneImage failed"); + wrlib_rs::ffi::RCombineImageWithColor(result.as_ptr(), &GREY as *const _); + result + } + } + } + } +} + +impl Drop for Pixmap { + fn drop(&mut self) { + unsafe { + if *self.pixmap.borrow() != 0 { + x11::xlib::XFreePixmap(self.display.as_ptr(), *self.pixmap.borrow()); + } + if *self.mask.borrow() != 0 { + x11::xlib::XFreePixmap(self.display.as_ptr(), *self.mask.borrow()); + } + } + } +} + +pub mod ffi { + use super::*; + use std::{ + ffi::{c_char, c_int, c_uint, c_ushort}, + ptr, + rc::Rc, + }; + + pub type WMPixmap = Rc; + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMRetainPixmap(pixmap: *mut WMPixmap) -> *mut WMPixmap { + if pixmap.is_null() { + return ptr::null_mut(); + } + Box::leak(Box::new(unsafe { (*pixmap).clone() })) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMReleasePixmap(pixmap: *mut WMPixmap) { + let _ = unsafe { Box::from_raw(pixmap) }; + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreatePixmap( + screen: *mut WINGsP::WMScreen, + width: c_ushort, + height: c_ushort, + depth: c_ushort, + masked: c_int, + ) -> *mut WMPixmap { + let pixmap = Pixmap::new( + NonNull::new(screen).expect("pixmap screen cannot be null"), + width, + height, + depth, + if masked == 0 { + Masked::No + } else { + Masked::Yes + }, + ); + Box::leak(Box::new(Rc::new(pixmap))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreatePixmapFromXPixmaps( + screen: *mut WINGsP::WMScreen, + pixmap: x11::xlib::Pixmap, + mask: x11::xlib::Pixmap, + width: c_ushort, + height: c_ushort, + depth: c_ushort, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + let pixmap = Pixmap::new_from_x_pixmaps( + screen, + pixmap, + mask, + width, + height, + depth, + ); + Box::leak(Box::new(Rc::new(pixmap))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreatePixmapFromFile( + screen: *mut WINGsP::WMScreen, + file_name: *const c_char, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + if file_name.is_null() { + return ptr::null_mut(); + } + let file_name = unsafe { CStr::from_ptr(file_name) }; + let Some(pixmap) = Pixmap::new_from_file(screen, file_name) else { + return ptr::null_mut(); + }; + Box::leak(Box::new(Rc::new(pixmap))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreatePixmapFromRImage( + screen: *mut WINGsP::WMScreen, + image: *mut wrlib_rs::ffi::RImage, + threshold: c_ushort, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + let Some(image) = NonNull::new(image) else { + return ptr::null_mut(); + }; + let Some(pixmap) = Pixmap::new_from_r_image( + screen, + image, + threshold, + ) else { + return ptr::null_mut(); + }; + Box::leak(Box::new(Rc::new(pixmap))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreateGreyedPixmapFromRImage( + screen: *mut WINGsP::WMScreen, + image: *mut wrlib_rs::ffi::RImage, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + let image = NonNull::new(image).expect("image cannot be null"); + let Some(result) = Transform::with_transformed( + image, + &[Transform::Greymask], + |image| Pixmap::new_from_r_image(screen, image, 0)) else { + return ptr::null_mut(); + }; + Box::leak(Box::new(Rc::new(result))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreateScaledPixmapFromFile( + screen: *mut WINGsP::WMScreen, + file_name: *const c_char, + width: c_uint, + height: c_uint, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + if file_name.is_null() { + return ptr::null_mut(); + } + let file_name = unsafe { CStr::from_ptr(file_name) }; + let Some(rcontext) = NonNull::new(unsafe { (*screen.as_ptr()).rcontext }) else { + return ptr::null_mut(); + }; + let Some(result) = + with_r_image_from_file( + rcontext, + file_name, + |image| { + let Some(image) = image else { + return None; + }; + Transform::with_transformed( + image, + &[Transform::Downscale { width, height }], + |image| Pixmap::new_from_r_image(screen, image, 0), + ) + } + ) else { + return ptr::null_mut(); + }; + Box::leak(Box::new(Rc::new(result))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreateGreyedPixmapFromFile( + screen: *mut WINGsP::WMScreen, + file_name: *const c_char, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + if file_name.is_null() { + return ptr::null_mut(); + } + let file_name = unsafe { CStr::from_ptr(file_name) }; + let Some(rcontext) = NonNull::new(unsafe { (*screen.as_ptr()).rcontext }) else { + return ptr::null_mut(); + }; + let Some(result) = + with_r_image_from_file( + rcontext, + file_name, + |image| { + let Some(image) = image else { + return None; + }; + Transform::with_transformed( + image, + &[Transform::Greymask], + |image| Pixmap::new_from_r_image(screen, image, 0), + ) + } + ) else { + return ptr::null_mut(); + }; + Box::leak(Box::new(Rc::new(result))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreateScaledGreyedPixmapFromFile( + screen: *mut WINGsP::WMScreen, + file_name: *const c_char, + width: c_uint, + height: c_uint, + ) -> *mut WMPixmap { + let Some(screen) = NonNull::new(screen) else { + return ptr::null_mut(); + }; + if file_name.is_null() { + return ptr::null_mut(); + } + let file_name = unsafe { CStr::from_ptr(file_name) }; + let Some(rcontext) = NonNull::new(unsafe { (*screen.as_ptr()).rcontext }) else { + return ptr::null_mut(); + }; + let Some(result) = with_r_image_from_file( + rcontext, + file_name, + |image| { + let Some(image) = image else { + return None; + }; + Transform::with_transformed( + image, + &[Transform::Downscale { width, height }, + Transform::Greymask], + |image| Pixmap::new_from_r_image(screen, image, 0), + ) + }, + ) else { + return ptr::null_mut(); + }; + Box::leak(Box::new(Rc::new(result))) as *mut _ + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMCreatePixmapFromXPMData( + screen: *mut WINGsP::WMScreen, + data: *mut *mut c_char, + ) -> *mut WMPixmap { + todo!() + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMGetPixmapXID(pixmap: *mut WMPixmap) -> x11::xlib::Pixmap { + let pixmap = NonNull::new(pixmap).expect("pixmap cannot be null"); + + unsafe { *(&(*pixmap.as_ptr())).pixmap.borrow() } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMSetPixmapXID(pixmap: *mut WMPixmap, value: x11::xlib::Pixmap) { + let pixmap = NonNull::new(pixmap).expect("pixmap cannot be null"); + + unsafe { *(&mut (*pixmap.as_ptr())).pixmap.borrow_mut() = value; } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMGetPixmapMaskXID(pixmap: *mut WMPixmap) -> x11::xlib::Pixmap { + let pixmap = NonNull::new(pixmap).expect("pixmap cannot be null"); + + unsafe { *(&(*pixmap.as_ptr())).mask.borrow() } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMSetPixmapMaskXID(pixmap: *mut WMPixmap, mask: x11::xlib::Pixmap) { + let pixmap = NonNull::new(pixmap).expect("pixmap cannot be null"); + + unsafe { *(&mut (*pixmap.as_ptr())).mask.borrow_mut() = mask; } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMGetPixmapSize(pixmap: *mut WMPixmap) -> WINGsP::WMSize { + let pixmap = NonNull::new(pixmap).expect("pixmap cannot be null"); + + let (width, height) = unsafe { + ((&(*pixmap.as_ptr())).width, (&(*pixmap.as_ptr())).height) + }; + WINGsP::WMSize { + width: width.into(), + height: height.into(), + } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMGetPixmapDepth(pixmap: *mut WMPixmap) -> c_int { + let pixmap = NonNull::new(pixmap).expect("pixmap cannot be null"); + + unsafe { (&(*pixmap.as_ptr())).depth.into() } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMGetSystemPixmap(screen: *mut WINGsP::WMScreen, image: c_uint) -> *mut WMPixmap { + unsafe { + let screen = &*screen; + match image { + WINGsP::constants::WSystemIcon_ReturnArrow => WMRetainPixmap(screen.buttonArrow), + WINGsP::constants::WSystemIcon_HighlightedReturnArrow => WMRetainPixmap(screen.pushedButtonArrow), + WINGsP::constants::WSystemIcon_ScrollerDimple => WMRetainPixmap(screen.scrollerDimple), + WINGsP::constants::WSystemIcon_ArrowLeft => WMRetainPixmap(screen.leftArrow), + WINGsP::constants::WSystemIcon_HighlightedArrowLeft => WMRetainPixmap(screen.hiLeftArrow), + WINGsP::constants::WSystemIcon_ArrowRight => WMRetainPixmap(screen.rightArrow), + WINGsP::constants::WSystemIcon_HighlightedArrowRight => WMRetainPixmap(screen.hiRightArrow), + WINGsP::constants::WSystemIcon_ArrowUp => WMRetainPixmap(screen.upArrow), + WINGsP::constants::WSystemIcon_HighlightedArrowUp => WMRetainPixmap(screen.hiUpArrow), + WINGsP::constants::WSystemIcon_ArrowDown => WMRetainPixmap(screen.downArrow), + WINGsP::constants::WSystemIcon_HighlightedArrowDown => WMRetainPixmap(screen.hiDownArrow), + WINGsP::constants::WSystemIcon_CheckMark => WMRetainPixmap(screen.checkMark), + _ => ptr::null_mut(), + } + } + } + + #[unsafe(no_mangle)] + pub unsafe extern "C" fn WMDrawPixmap( + pixmap: *mut WMPixmap, + drawable: x11::xlib::Drawable, + x: c_int, + y: c_int, + ) { + unsafe { + let pixmap = &*pixmap; + x11::xlib::XSetClipMask(pixmap.display.as_ptr(), pixmap.clip_gc, *pixmap.mask.borrow()); + x11::xlib::XSetClipOrigin(pixmap.display.as_ptr(), pixmap.clip_gc, x, y); + x11::xlib::XCopyArea( + pixmap.display.as_ptr(), + *pixmap.pixmap.borrow(), + drawable, + pixmap.clip_gc, + 0, + 0, + pixmap.width.into(), + pixmap.height.into(), + x, + y, + ); + } + } +} diff --git a/WINGs/wlabel.c b/WINGs/wlabel.c index 9726cb15..9445a4ee 100644 --- a/WINGs/wlabel.c +++ b/WINGs/wlabel.c @@ -10,7 +10,7 @@ typedef struct W_Label { WMColor *textColor; WMFont *font; /* if NULL, use default */ - W_Pixmap *image; + WMPixmap *image; struct { WMReliefType relief:3; diff --git a/WINGs/wmisc.c b/WINGs/wmisc.c index 68b98e2b..4623e4ba 100644 --- a/WINGs/wmisc.c +++ b/WINGs/wmisc.c @@ -203,7 +203,7 @@ W_PaintText(W_View * view, Drawable d, WMFont * font, int x, int y, void W_PaintTextAndImage(W_View * view, int wrap, WMColor * textColor, WMFont * font, WMReliefType relief, const char *text, - WMAlignment alignment, W_Pixmap * image, + WMAlignment alignment, WMPixmap * image, WMImagePosition position, WMColor * backColor, int ofs) { W_Screen *screen = view->screen; @@ -250,11 +250,12 @@ W_PaintTextAndImage(W_View * view, int wrap, WMColor * textColor, WMFont * font, /* calc. image alignment */ if (position != WIPNoImage && image != NULL) { + WMSize size = WMGetPixmapSize(image); switch (position) { case WIPOverlaps: case WIPImageOnly: - ix = (view->size.width - image->width) / 2; - iy = (view->size.height - image->height) / 2; + ix = (view->size.width - size.width) / 2; + iy = (view->size.height - size.height) / 2; /* x = 2; y = 0; @@ -263,31 +264,31 @@ W_PaintTextAndImage(W_View * view, int wrap, WMColor * textColor, WMFont * font, case WIPLeft: ix = x; - iy = y + (h - image->height) / 2; - x = x + image->width + 5; + iy = y + (h - size.height) / 2; + x = x + size.width + 5; y = 0; - w -= image->width + 5; + w -= size.width + 5; break; case WIPRight: - ix = view->size.width - image->width - x; - iy = y + (h - image->height) / 2; - w -= image->width + 5; + ix = view->size.width - size.width - x; + iy = y + (h - size.height) / 2; + w -= size.width + 5; break; case WIPBelow: - ix = (view->size.width - image->width) / 2; - iy = h - image->height; + ix = (view->size.width - size.width) / 2; + iy = h - size.height; y = 0; - h -= image->height; + h -= size.height; break; default: case WIPAbove: - ix = (view->size.width - image->width) / 2; + ix = (view->size.width - size.width) / 2; iy = y; - y = image->height; - h -= image->height; + y = size.height; + h -= size.height; break; } @@ -295,14 +296,14 @@ W_PaintTextAndImage(W_View * view, int wrap, WMColor * textColor, WMFont * font, iy += ofs; XSetClipOrigin(screen->display, screen->clipGC, ix, iy); - XSetClipMask(screen->display, screen->clipGC, image->mask); + XSetClipMask(screen->display, screen->clipGC, WMGetPixmapMaskXID(image)); - if (image->depth == 1) - XCopyPlane(screen->display, image->pixmap, d, screen->clipGC, - 0, 0, image->width, image->height, ix, iy, 1); + if (WMGetPixmapDepth(image) == 1) + XCopyPlane(screen->display, WMGetPixmapXID(image), d, screen->clipGC, + 0, 0, size.width, size.height, ix, iy, 1); else - XCopyArea(screen->display, image->pixmap, d, screen->clipGC, - 0, 0, image->width, image->height, ix, iy); + XCopyArea(screen->display, WMGetPixmapXID(image), d, screen->clipGC, + 0, 0, size.width, size.height, ix, iy); } /* draw text */ diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c index a0220487..3d8be03a 100644 --- a/WINGs/wpanel.c +++ b/WINGs/wpanel.c @@ -124,7 +124,7 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner, WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); WMMapWidget(panel->iLbl); WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 10); - icon = WMCreateApplicationIconBlendedPixmap(scrPtr, (RColor *) NULL); + icon = WMCreateApplicationIconGreyedPixmap(scrPtr); if (icon) { WMSetLabelImage(panel->iLbl, icon); WMReleasePixmap(icon); @@ -181,7 +181,7 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner, if (defaultButton) dw = WMWidthOfString(defaultFont, defaultButton, strlen(defaultButton)); - dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + dw = dw + (scrPtr->buttonArrow ? WMGetPixmapSize(scrPtr->buttonArrow).width : 0); aw += 30; ow += 30; @@ -291,7 +291,7 @@ WMAlertPanel *WMCreateScaledAlertPanel(WMScreen * scrPtr, WMWindow * owner, WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); WMMapWidget(panel->iLbl); WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 10); - icon = WMCreateApplicationIconBlendedPixmap(scrPtr, (RColor *) NULL); + icon = WMCreateApplicationIconGreyedPixmap(scrPtr); if (icon) { WMSetLabelImage(panel->iLbl, icon); WMReleasePixmap(icon); @@ -347,7 +347,7 @@ WMAlertPanel *WMCreateScaledAlertPanel(WMScreen * scrPtr, WMWindow * owner, if (defaultButton) dw = WMWidthOfString(scrPtr->normalFont, defaultButton, strlen(defaultButton)); - dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + dw = dw + (scrPtr->buttonArrow ? WMGetPixmapSize(scrPtr->buttonArrow).width : 0); aw += WMScaleX(30); ow += WMScaleX(30); @@ -563,7 +563,7 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr, WMWindow * owner, const char if (okButton) dw = WMWidthOfString(defaultFont, okButton, strlen(okButton)); - w = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + w = dw + (scrPtr->buttonArrow ? WMGetPixmapSize(scrPtr->buttonArrow).width : 0); if (aw > w) w = aw; @@ -662,7 +662,7 @@ WMInputPanel *WMCreateScaledInputPanel(WMScreen * scrPtr, WMWindow * owner, cons if (okButton) dw = WMWidthOfString(scrPtr->normalFont, okButton, strlen(okButton)); - w = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + w = dw + (scrPtr->buttonArrow ? WMGetPixmapSize(scrPtr->buttonArrow).width : 0); if (aw > w) w = aw; @@ -767,7 +767,7 @@ WMGenericPanel *WMCreateGenericPanel(WMScreen * scrPtr, WMWindow * owner, WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); WMMapWidget(panel->iLbl); WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 10); - icon = WMCreateApplicationIconBlendedPixmap(scrPtr, (RColor *) NULL); + icon = WMCreateApplicationIconGreyedPixmap(scrPtr); if (icon) { WMSetLabelImage(panel->iLbl, icon); WMReleasePixmap(icon); @@ -815,7 +815,7 @@ WMGenericPanel *WMCreateGenericPanel(WMScreen * scrPtr, WMWindow * owner, if (alternateButton) aw = WMWidthOfString(defaultFont, alternateButton, strlen(alternateButton)); - dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + dw = dw + (scrPtr->buttonArrow ? WMGetPixmapSize(scrPtr->buttonArrow).width : 0); aw += 30; dw += 30; diff --git a/WINGs/wpixmap.c b/WINGs/wpixmap.c deleted file mode 100644 index 5ad311cb..00000000 --- a/WINGs/wpixmap.c +++ /dev/null @@ -1,260 +0,0 @@ - -#include "WINGsP.h" - -#include - -WMPixmap *WMRetainPixmap(WMPixmap * pixmap) -{ - if (pixmap) - pixmap->refCount++; - - return pixmap; -} - -void WMReleasePixmap(WMPixmap * pixmap) -{ - wassertr(pixmap != NULL); - - pixmap->refCount--; - - if (pixmap->refCount < 1) { - if (pixmap->pixmap) - XFreePixmap(pixmap->screen->display, pixmap->pixmap); - if (pixmap->mask) - XFreePixmap(pixmap->screen->display, pixmap->mask); - wfree(pixmap); - } -} - -WMPixmap *WMCreatePixmap(WMScreen * scrPtr, int width, int height, int depth, Bool masked) -{ - WMPixmap *pixPtr; - - pixPtr = wmalloc(sizeof(WMPixmap)); - pixPtr->screen = scrPtr; - pixPtr->width = width; - pixPtr->height = height; - pixPtr->depth = depth; - pixPtr->refCount = 1; - - pixPtr->pixmap = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr), width, height, depth); - if (masked) { - pixPtr->mask = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr), width, height, 1); - } else { - pixPtr->mask = None; - } - - return pixPtr; -} - -WMPixmap *WMCreatePixmapFromXPixmaps(WMScreen * scrPtr, Pixmap pixmap, Pixmap mask, - int width, int height, int depth) -{ - WMPixmap *pixPtr; - - pixPtr = wmalloc(sizeof(WMPixmap)); - pixPtr->screen = scrPtr; - pixPtr->pixmap = pixmap; - pixPtr->mask = mask; - pixPtr->width = width; - pixPtr->height = height; - pixPtr->depth = depth; - pixPtr->refCount = 1; - - return pixPtr; -} - -WMPixmap *WMCreatePixmapFromFile(WMScreen * scrPtr, const char *fileName) -{ - WMPixmap *pixPtr; - RImage *image; - - image = RLoadImage(scrPtr->rcontext, fileName, 0); - if (!image) - return NULL; - - pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127); - - RReleaseImage(image); - - return pixPtr; -} - -WMPixmap *WMCreatePixmapFromRImage(WMScreen * scrPtr, RImage * image, int threshold) -{ - WMPixmap *pixPtr; - Pixmap pixmap, mask; - - if (image == NULL) - return NULL; - - if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask, threshold)) { - return NULL; - } - - pixPtr = wmalloc(sizeof(WMPixmap)); - pixPtr->screen = scrPtr; - pixPtr->pixmap = pixmap; - pixPtr->mask = mask; - pixPtr->width = image->width; - pixPtr->height = image->height; - pixPtr->depth = scrPtr->depth; - pixPtr->refCount = 1; - - return pixPtr; -} - -WMPixmap *WMCreateBlendedPixmapFromRImage(WMScreen * scrPtr, RImage * image, const RColor * color) -{ - WMPixmap *pixPtr; - RImage *copy; - - copy = RCloneImage(image); - if (!copy) - return NULL; - - RCombineImageWithColor(copy, color); - pixPtr = WMCreatePixmapFromRImage(scrPtr, copy, 0); - RReleaseImage(copy); - - return pixPtr; -} - -WMPixmap *WMCreateBlendedPixmapFromFile(WMScreen * scrPtr, const char *fileName, const RColor * color) -{ - return WMCreateScaledBlendedPixmapFromFile(scrPtr, fileName, color, 0, 0); -} - -WMPixmap *WMCreateScaledBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName, const RColor *color, - unsigned int width, unsigned int height) -{ - WMPixmap *pixPtr; - RImage *image; - - image = RLoadImage(scrPtr->rcontext, fileName, 0); - if (!image) - return NULL; - - /* scale it if needed to fit in the specified box */ - if ((width > 0) && (height > 0) && ((image->width > width) || (image->height > height))) { - int new_width, new_height; - RImage *new_image; - - new_width = image->width; - new_height = image->height; - if (new_width > width) { - new_width = width; - new_height = width * image->height / image->width; - } - if (new_height > height) { - new_width = height * image->width / image->height; - new_height = height; - } - - new_image = RScaleImage(image, new_width, new_height); - RReleaseImage(image); - image = new_image; - } - - RCombineImageWithColor(image, color); - pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0); - RReleaseImage(image); - - return pixPtr; -} - -WMPixmap *WMCreatePixmapFromXPMData(WMScreen * scrPtr, char **data) -{ - WMPixmap *pixPtr; - RImage *image; - - image = RGetImageFromXPMData(scrPtr->rcontext, data); - if (!image) - return NULL; - - pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127); - - RReleaseImage(image); - - return pixPtr; -} - -Pixmap WMGetPixmapXID(WMPixmap * pixmap) -{ - wassertrv(pixmap != NULL, None); - - return pixmap->pixmap; -} - -Pixmap WMGetPixmapMaskXID(WMPixmap * pixmap) -{ - wassertrv(pixmap != NULL, None); - - return pixmap->mask; -} - -WMSize WMGetPixmapSize(WMPixmap * pixmap) -{ - WMSize size = { 0, 0 }; - - wassertrv(pixmap != NULL, size); - - size.width = pixmap->width; - size.height = pixmap->height; - - return size; -} - -WMPixmap *WMGetSystemPixmap(WMScreen * scr, int image) -{ - switch (image) { - case WSIReturnArrow: - return WMRetainPixmap(scr->buttonArrow); - - case WSIHighlightedReturnArrow: - return WMRetainPixmap(scr->pushedButtonArrow); - - case WSIScrollerDimple: - return WMRetainPixmap(scr->scrollerDimple); - - case WSIArrowLeft: - return WMRetainPixmap(scr->leftArrow); - - case WSIHighlightedArrowLeft: - return WMRetainPixmap(scr->hiLeftArrow); - - case WSIArrowRight: - return WMRetainPixmap(scr->rightArrow); - - case WSIHighlightedArrowRight: - return WMRetainPixmap(scr->hiRightArrow); - - case WSIArrowUp: - return WMRetainPixmap(scr->upArrow); - - case WSIHighlightedArrowUp: - return WMRetainPixmap(scr->hiUpArrow); - - case WSIArrowDown: - return WMRetainPixmap(scr->downArrow); - - case WSIHighlightedArrowDown: - return WMRetainPixmap(scr->hiDownArrow); - - case WSICheckMark: - return WMRetainPixmap(scr->checkMark); - - default: - return NULL; - } -} - -void WMDrawPixmap(WMPixmap * pixmap, Drawable d, int x, int y) -{ - WMScreen *scr = pixmap->screen; - - XSetClipMask(scr->display, scr->clipGC, pixmap->mask); - XSetClipOrigin(scr->display, scr->clipGC, x, y); - - XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0, pixmap->width, pixmap->height, x, y); -} diff --git a/WINGs/wpopupbutton.c b/WINGs/wpopupbutton.c index 1a8156b4..256d534f 100644 --- a/WINGs/wpopupbutton.c +++ b/WINGs/wpopupbutton.c @@ -284,21 +284,23 @@ static void paintPopUpButton(PopUpButton * bPtr) } if (bPtr->flags.pullsDown) { - XCopyArea(scr->display, scr->pullDownIndicator->pixmap, - pixmap, scr->copyGC, 0, 0, scr->pullDownIndicator->width, - scr->pullDownIndicator->height, - bPtr->view->size.width - scr->pullDownIndicator->width - 4, - (bPtr->view->size.height - scr->pullDownIndicator->height) / 2); + WMSize size = WMGetPixmapSize(scr->pullDownIndicator); + XCopyArea(scr->display, WMGetPixmapXID(scr->pullDownIndicator), + pixmap, scr->copyGC, 0, 0, size.width, + size.height, + bPtr->view->size.width - size.width - 4, + (bPtr->view->size.height - size.height) / 2); } else { int x, y; + WMSize size = WMGetPixmapSize(scr->popUpIndicator); - x = bPtr->view->size.width - scr->popUpIndicator->width - 4; - y = (bPtr->view->size.height - scr->popUpIndicator->height) / 2; + x = bPtr->view->size.width - size.width - 4; + y = (bPtr->view->size.height - size.height) / 2; XSetClipOrigin(scr->display, scr->clipGC, x, y); - XSetClipMask(scr->display, scr->clipGC, scr->popUpIndicator->mask); - XCopyArea(scr->display, scr->popUpIndicator->pixmap, pixmap, - scr->clipGC, 0, 0, scr->popUpIndicator->width, scr->popUpIndicator->height, x, y); + XSetClipMask(scr->display, scr->clipGC, WMGetPixmapMaskXID(scr->popUpIndicator)); + XCopyArea(scr->display, WMGetPixmapXID(scr->popUpIndicator), pixmap, + scr->clipGC, 0, 0, size.width, size.height, x, y); } XCopyArea(scr->display, pixmap, bPtr->view->window, scr->copyGC, 0, 0, @@ -357,11 +359,12 @@ static void paintMenuEntry(PopUpButton * bPtr, int index, int highlight) index * itemHeight + yo, width, WALeft, scr->black, False, title, strlen(title)); if (!bPtr->flags.pullsDown && index == bPtr->selectedItemIndex) { - XCopyArea(scr->display, scr->popUpIndicator->pixmap, + WMSize size = WMGetPixmapSize(scr->popUpIndicator); + XCopyArea(scr->display, WMGetPixmapXID(scr->popUpIndicator), bPtr->menuView->window, scr->copyGC, 0, 0, - scr->popUpIndicator->width, scr->popUpIndicator->height, - width - scr->popUpIndicator->width - 4, - index * itemHeight + (itemHeight - scr->popUpIndicator->height) / 2); + size.width, size.height, + width - size.width - 4, + index * itemHeight + (itemHeight - size.height) / 2); } } @@ -401,11 +404,12 @@ static Pixmap makeMenuPixmap(PopUpButton * bPtr) i * itemHeight + yo, width, WALeft, color, False, text, strlen(text)); if (!bPtr->flags.pullsDown && i == bPtr->selectedItemIndex) { - XCopyArea(scr->display, scr->popUpIndicator->pixmap, pixmap, - scr->copyGC, 0, 0, scr->popUpIndicator->width, - scr->popUpIndicator->height, - width - scr->popUpIndicator->width - 4, - i * itemHeight + (itemHeight - scr->popUpIndicator->height) / 2); + WMSize size = WMGetPixmapSize(scr->popUpIndicator); + XCopyArea(scr->display, WMGetPixmapXID(scr->popUpIndicator), pixmap, + scr->copyGC, 0, 0, size.width, + size.height, + width - size.width - 4, + i * itemHeight + (itemHeight - size.height) / 2); } i++; diff --git a/WINGs/wscroller.c b/WINGs/wscroller.c index 1533da93..5dbc4024 100644 --- a/WINGs/wscroller.c +++ b/WINGs/wscroller.c @@ -225,7 +225,7 @@ static void paintArrow(WMScroller * sPtr, Drawable d, int part) WMView *view = sPtr->view; WMScreen *scr = view->screen; int ofs; - W_Pixmap *arrow; + WMPixmap *arrow; #ifndef DOUBLE_BUFFER GC gc = scr->lightGC; @@ -290,6 +290,7 @@ static void paintArrow(WMScroller * sPtr, Drawable d, int part) if (sPtr->flags.horizontal) { /* paint button */ + WMSize size = WMGetPixmapSize(arrow); #ifndef DOUBLE_BUFFER XFillRectangle(scr->display, d, gc, ofs + 1, 2 + 1, BUTTON_SIZE + 1 - 3, BUTTON_SIZE - 3); #else @@ -300,16 +301,16 @@ static void paintArrow(WMScroller * sPtr, Drawable d, int part) W_DrawRelief(scr, d, ofs, 2, BUTTON_SIZE, BUTTON_SIZE, WRRaised); /* paint arrow */ - XSetClipMask(scr->display, scr->clipGC, arrow->mask); + XSetClipMask(scr->display, scr->clipGC, WMGetPixmapMaskXID(arrow)); XSetClipOrigin(scr->display, scr->clipGC, - ofs + (BUTTON_SIZE - arrow->width) / 2, 2 + (BUTTON_SIZE - arrow->height) / 2); + ofs + (BUTTON_SIZE - size.width) / 2, 2 + (BUTTON_SIZE - size.height) / 2); - XCopyArea(scr->display, arrow->pixmap, d, scr->clipGC, - 0, 0, arrow->width, arrow->height, - ofs + (BUTTON_SIZE - arrow->width) / 2, 2 + (BUTTON_SIZE - arrow->height) / 2); + XCopyArea(scr->display, WMGetPixmapXID(arrow), d, scr->clipGC, + 0, 0, size.width, size.height, + ofs + (BUTTON_SIZE - size.width) / 2, 2 + (BUTTON_SIZE - size.height) / 2); } else { /* vertical */ - + WMSize size = WMGetPixmapSize(arrow); /* paint button */ #ifndef DOUBLE_BUFFER XFillRectangle(scr->display, d, gc, 2 + 1, ofs + 1, BUTTON_SIZE - 3, BUTTON_SIZE + 1 - 3); @@ -322,12 +323,12 @@ static void paintArrow(WMScroller * sPtr, Drawable d, int part) /* paint arrow */ - XSetClipMask(scr->display, scr->clipGC, arrow->mask); + XSetClipMask(scr->display, scr->clipGC, WMGetPixmapMaskXID(arrow)); XSetClipOrigin(scr->display, scr->clipGC, - 2 + (BUTTON_SIZE - arrow->width) / 2, ofs + (BUTTON_SIZE - arrow->height) / 2); - XCopyArea(scr->display, arrow->pixmap, d, scr->clipGC, - 0, 0, arrow->width, arrow->height, - 2 + (BUTTON_SIZE - arrow->width) / 2, ofs + (BUTTON_SIZE - arrow->height) / 2); + 2 + (BUTTON_SIZE - size.width) / 2, ofs + (BUTTON_SIZE - size.height) / 2); + XCopyArea(scr->display, WMGetPixmapXID(arrow), d, scr->clipGC, + 0, 0, size.width, size.height, + 2 + (BUTTON_SIZE - size.width) / 2, ofs + (BUTTON_SIZE - size.height) / 2); } } @@ -395,6 +396,7 @@ static void paintScroller(Scroller * sPtr) knobP = sPtr->floatValue * ((float)length - knobL); if (sPtr->flags.horizontal) { + WMSize size = WMGetPixmapSize(scr->scrollerDimple); /* before */ XFillRectangle(scr->display, d, scr->stippleGC, ofs, 2, (int)knobP, view->size.height - 4); @@ -405,11 +407,11 @@ static void paintScroller(Scroller * sPtr) #endif W_DrawRelief(scr, d, ofs + (int)knobP, 2, (int)knobL, view->size.height - 4, WRRaised); - XCopyArea(scr->display, scr->scrollerDimple->pixmap, d, + XCopyArea(scr->display, WMGetPixmapXID(scr->scrollerDimple), d, scr->copyGC, 0, 0, - scr->scrollerDimple->width, scr->scrollerDimple->height, - ofs + (int)knobP + ((int)knobL - scr->scrollerDimple->width - 1) / 2, - (view->size.height - scr->scrollerDimple->height - 1) / 2); + size.width, size.height, + ofs + (int)knobP + ((int)knobL - size.width - 1) / 2, + (view->size.height - size.height - 1) / 2); /* after */ if ((int)(knobP + knobL) < length) @@ -418,6 +420,7 @@ static void paintScroller(Scroller * sPtr) length - (int)(knobP + knobL), view->size.height - 4); } else { /* before */ + WMSize size = WMGetPixmapSize(scr->scrollerDimple); if (knobP > 0.0F) XFillRectangle(scr->display, d, scr->stippleGC, 2, ofs, view->size.width - 4, (int)knobP); @@ -427,11 +430,11 @@ static void paintScroller(Scroller * sPtr) XFillRectangle(scr->display, d, scr->lightGC, 2 + 2, ofs + (int)knobP + 2, view->size.width - 4 - 4, (int)knobL - 4); #endif - XCopyArea(scr->display, scr->scrollerDimple->pixmap, d, + XCopyArea(scr->display, WMGetPixmapXID(scr->scrollerDimple), d, scr->copyGC, 0, 0, - scr->scrollerDimple->width, scr->scrollerDimple->height, - (view->size.width - scr->scrollerDimple->width - 1) / 2, - ofs + (int)knobP + ((int)knobL - scr->scrollerDimple->height - 1) / 2); + size.width, size.height, + (view->size.width - size.width - 1) / 2, + ofs + (int)knobP + ((int)knobL - size.height - 1) / 2); W_DrawRelief(scr, d, 2, ofs + (int)knobP, view->size.width - 4, (int)knobL, WRRaised); diff --git a/WINGs/wsplitview.c b/WINGs/wsplitview.c index 3d8072db..55bab0e5 100644 --- a/WINGs/wsplitview.c +++ b/WINGs/wsplitview.c @@ -400,16 +400,18 @@ static void paintSplitView(WMSplitView * sPtr) sPtr->flags.adjustOnPaint = 0; } - XSetClipMask(scr->display, scr->clipGC, dimple->mask); + XSetClipMask(scr->display, scr->clipGC, WMGetPixmapMaskXID(dimple)); + WMSize size = WMGetPixmapSize(dimple); if (sPtr->flags.vertical) { - x = ((DIVIDER_THICKNESS - dimple->width) / 2); - y = (sPtr->view->size.height - dimple->height) / 2; + x = ((DIVIDER_THICKNESS - size.width) / 2); + y = (sPtr->view->size.height - size.height) / 2; } else { - x = (sPtr->view->size.width - dimple->width) / 2; - y = ((DIVIDER_THICKNESS - dimple->height) / 2); + x = (sPtr->view->size.width - size.width) / 2; + y = ((DIVIDER_THICKNESS - size.height) / 2); } + WMSize dimpleSize = WMGetPixmapSize(dimple); for (i = 0; i < count - 1; i++) { p = _GetPSubviewStructAt(i); @@ -419,8 +421,8 @@ static void paintSplitView(WMSplitView * sPtr) y += p->size; XSetClipOrigin(scr->display, scr->clipGC, x, y); - XCopyArea(scr->display, dimple->pixmap, sPtr->view->window, - scr->clipGC, 0, 0, dimple->width, dimple->height, x, y); + XCopyArea(scr->display, WMGetPixmapXID(dimple), sPtr->view->window, + scr->clipGC, 0, 0, dimpleSize.width, dimpleSize.height, x, y); if (sPtr->flags.vertical) x += DIVIDER_THICKNESS; diff --git a/WINGs/wtext.c b/WINGs/wtext.c index 2a9c3660..dc175bcf 100644 --- a/WINGs/wtext.c +++ b/WINGs/wtext.c @@ -627,9 +627,10 @@ static void paintText(Text * tPtr) XFillRectangle(dpy, tPtr->db, WMColorGC(tPtr->bgColor), 0, 0, tPtr->visible.w, tPtr->visible.h); if (tPtr->bgPixmap) { + WMSize bgSize = WMGetPixmapSize(tPtr->bgPixmap); WMDrawPixmap(tPtr->bgPixmap, tPtr->db, - (tPtr->visible.w - tPtr->visible.x - tPtr->bgPixmap->width) / 2, - (tPtr->visible.h - tPtr->visible.y - tPtr->bgPixmap->height) / 2); + (tPtr->visible.w - tPtr->visible.x - bgSize.width) / 2, + (tPtr->visible.h - tPtr->visible.y - bgSize.height) / 2); } if (!(tb = tPtr->currentTextBlock)) { @@ -766,7 +767,7 @@ static void paintText(Text * tPtr) WMDrawPixmap(tb->d.pixmap, tPtr->db, tb->sections[0].x - tPtr->hpos, tb->sections[0].y - tPtr->vpos); - h = tb->d.pixmap->height + 1; + h = WMGetPixmapSize(tb->d.pixmap).height + 1; } @@ -848,7 +849,7 @@ static void mouseOverObject(Text * tPtr, int x, int y) if (tb->sections[0].x <= x && tb->sections[0].y <= y && tb->sections[0].x + tb->sections[0].w >= x - && tb->sections[0].y + tb->d.pixmap->height >= y) { + && tb->sections[0].y + WMGetPixmapSize(tb->d.pixmap).height >= y) { tPtr->flags.isOverGraphic = 3; result = True; break; @@ -1059,7 +1060,7 @@ static void cursorToTextPosition(Text * tPtr, int x, int y) if (tb->object) _w = WMWidgetWidth(tb->d.widget) - 5; else - _w = tb->d.pixmap->width - 5; + _w = WMGetPixmapSize(tb->d.pixmap).width - 5; if (tb->sections[0].x + _w >= x) break; @@ -1096,7 +1097,7 @@ static void cursorToTextPosition(Text * tPtr, int x, int y) if (tb->object) tPtr->cursor.x += WMWidgetWidth(tb->d.widget); else - tPtr->cursor.x += tb->d.pixmap->width; + tPtr->cursor.x += WMGetPixmapSize(tb->d.pixmap).width; } else if (pos > tb->sections[s].begin) { tPtr->cursor.x += WMWidthOfString(tb->d.font, @@ -1121,7 +1122,7 @@ static void cursorToTextPosition(Text * tPtr, int x, int y) /* we have said TextBlock, now where within it? */ if (tb) { if (tb->graphic) { - int gw = (tb->object ? WMWidgetWidth(tb->d.widget) : tb->d.pixmap->width); + int gw = (tb->object ? WMWidgetWidth(tb->d.widget) : WMGetPixmapSize(tb->d.pixmap).width); tPtr->cursor.x = tb->sections[0].x; @@ -1370,9 +1371,9 @@ static int layOutLine(Text * tPtr, myLineItems * items, int nitems, int x, int y if (tPtr->flags.alignment != WALeft) lw += WMWidgetWidth(wdt); } else { - line_height = WMAX(line_height, tb->d.pixmap->height + max_d); + line_height = WMAX(line_height, WMGetPixmapSize(tb->d.pixmap).height + max_d); if (tPtr->flags.alignment != WALeft) - lw += tb->d.pixmap->width; + lw += WMGetPixmapSize(tb->d.pixmap).width; } } @@ -1420,8 +1421,8 @@ static int layOutLine(Text * tPtr, myLineItems * items, int nitems, int x, int y tb->sections[n].y = max_d + y + line_height - WMWidgetHeight(wdt); tb->sections[n].w = WMWidgetWidth(wdt); } else { - tb->sections[n].y = y + line_height + max_d - tb->d.pixmap->height; - tb->sections[n].w = tb->d.pixmap->width; + tb->sections[n].y = y + line_height + max_d - WMGetPixmapSize(tb->d.pixmap).height; + tb->sections[n].w = WMGetPixmapSize(tb->d.pixmap).width; } x += tb->sections[n].w; } @@ -1530,7 +1531,7 @@ static void layOutDocument(Text * tPtr) if (tb->object) width = WMWidgetWidth(tb->d.widget); else - width = tb->d.pixmap->width; + width = WMGetPixmapSize(tb->d.pixmap).width; if (width > tPtr->docWidth) tPtr->docWidth = width; diff --git a/WINGs/wview.c b/WINGs/wview.c index 9a927fae..0701f442 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -506,9 +506,9 @@ void W_SetViewBackgroundPixmap(W_View *view, WMPixmap *pix) view->attribFlags |= CWBackPixmap; view->attribFlags &= ~CWBackPixel; - view->attribs.background_pixmap = pix->pixmap; + view->attribs.background_pixmap = WMGetPixmapXID(pix); if (view->flags.realized) { - XSetWindowBackgroundPixmap(view->screen->display, view->window, pix->pixmap); + XSetWindowBackgroundPixmap(view->screen->display, view->window, WMGetPixmapXID(pix)); XClearWindow(view->screen->display, view->window); } } diff --git a/WPrefs.app/HotCornerShortcuts.c b/WPrefs.app/HotCornerShortcuts.c index 73595cdc..8d6f33ee 100644 --- a/WPrefs.app/HotCornerShortcuts.c +++ b/WPrefs.app/HotCornerShortcuts.c @@ -350,12 +350,13 @@ static void createPanel(Panel * p) CreateImages(scr, rc, xis, ICON_FILE, &panel->icon, NULL); if (panel->icon) { + WMSize size = WMGetPixmapSize(panel->icon); WMPixmap *nicon; - panel->quarter[0] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); - XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[0], gc, 0, 0, panel->icon->width/2, panel->icon->height/2, 0, 0); + panel->quarter[0] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), size.width/2, size.height/2, WMScreenDepth(scr)); + XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[0], gc, 0, 0, size.width/2, size.height/2, 0, 0); nicon = WMCreatePixmapFromXPixmaps(scr, panel->quarter[0], WMGetPixmapMaskXID(panel->icon), - panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); + size.width/2, size.height/2, WMScreenDepth(scr)); WMSetLabelImage(panel->icornerL, nicon); WMReleasePixmap(nicon); } @@ -370,12 +371,13 @@ static void createPanel(Panel * p) WMSetLabelImagePosition(panel->icornerL, WIPImageOnly); if (panel->icon) { + WMSize size = WMGetPixmapSize(panel->icon); WMPixmap *nicon; - panel->quarter[1] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); - XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[1], gc, panel->icon->width/2, 0, panel->icon->width/2, panel->icon->height/2, 0, 0); + panel->quarter[1] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), size.width/2, size.height/2, WMScreenDepth(scr)); + XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[1], gc, size.width/2, 0, size.width/2, size.height/2, 0, 0); nicon = WMCreatePixmapFromXPixmaps(scr, panel->quarter[1], WMGetPixmapMaskXID(panel->icon), - panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); + size.width/2, size.height/2, WMScreenDepth(scr)); WMSetLabelImage(panel->icornerL, nicon); WMReleasePixmap(nicon); } @@ -390,12 +392,13 @@ static void createPanel(Panel * p) WMSetLabelImagePosition(panel->icornerL, WIPImageOnly); if (panel->icon) { + WMSize size = WMGetPixmapSize(panel->icon); WMPixmap *nicon; - panel->quarter[2] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); - XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[2], gc, 0, panel->icon->height/2, panel->icon->width/2, panel->icon->height/2, 0, 0); + panel->quarter[2] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), size.width/2, size.height/2, WMScreenDepth(scr)); + XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[2], gc, 0, size.height/2, size.width/2, size.height/2, 0, 0); nicon = WMCreatePixmapFromXPixmaps(scr, panel->quarter[2], WMGetPixmapMaskXID(panel->icon), - panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); + size.width/2, size.height/2, WMScreenDepth(scr)); WMSetLabelImage(panel->icornerL, nicon); WMReleasePixmap(nicon); } @@ -409,12 +412,13 @@ static void createPanel(Panel * p) WMSetLabelImagePosition(panel->icornerL, WIPImageOnly); if (panel->icon) { + WMSize size = WMGetPixmapSize(panel->icon); WMPixmap *nicon; - panel->quarter[3] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); - XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[3], gc, panel->icon->width/2, panel->icon->height/2, panel->icon->width/2, panel->icon->height/2, 0, 0); + panel->quarter[3] = XCreatePixmap(scr->display, WMWidgetXID(panel->parent), size.width/2, size.height/2, WMScreenDepth(scr)); + XCopyArea(scr->display, WMGetPixmapXID(panel->icon), panel->quarter[3], gc, size.width/2, size.height/2, size.width/2, size.height/2, 0, 0); nicon = WMCreatePixmapFromXPixmaps(scr, panel->quarter[3], WMGetPixmapMaskXID(panel->icon), - panel->icon->width/2, panel->icon->height/2, WMScreenDepth(scr)); + size.width/2, size.height/2, WMScreenDepth(scr)); WMSetLabelImage(panel->icornerL, nicon); WMReleasePixmap(nicon); } diff --git a/WPrefs.app/MouseSettings.c b/WPrefs.app/MouseSettings.c index d15d7a45..7d3236c9 100644 --- a/WPrefs.app/MouseSettings.c +++ b/WPrefs.app/MouseSettings.c @@ -438,13 +438,8 @@ static void createPanel(Panel * p) WMPixmap *icon; char *buf1, *buf2; int i; - RColor color; char *path; - color.red = 0xae; - color.green = 0xaa; - color.blue = 0xae; - panel->box = WMCreateBox(panel->parent); WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2); @@ -460,7 +455,7 @@ static void createPanel(Panel * p) WMSetLabelImagePosition(panel->speedL, WIPImageOnly); path = LocateImage(SPEED_ICON_FILE); if (path) { - icon = WMCreateBlendedPixmapFromFile(scr, path, &color); + icon = WMCreateGreyedPixmapFromFile(scr, path); if (icon) { WMSetLabelImage(panel->speedL, icon); WMReleasePixmap(icon); diff --git a/WPrefs.app/WPrefs.c b/WPrefs.app/WPrefs.c index c95f8a17..4de0efde 100644 --- a/WPrefs.app/WPrefs.c +++ b/WPrefs.app/WPrefs.c @@ -444,17 +444,12 @@ void CreateImages(WMScreen *scr, RContext *rc, RImage *xis, const char *file, void SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, const char *file) { WMPixmap *icon; - RColor color; char *iconPath; iconPath = LocateImage(file); - color.red = 0xae; - color.green = 0xaa; - color.blue = 0xae; - color.alpha = 0; if (iconPath) { - icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color); + icon = WMCreateGreyedPixmapFromFile(scr, iconPath); if (!icon) wwarning(_("could not load icon file %s"), iconPath); } else { @@ -463,12 +458,12 @@ void SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, const char *file) WMSetButtonImage(bPtr, icon); - color.red = 0xff; - color.green = 0xff; - color.blue = 0xff; - color.alpha = 0; + /* color.red = 0xff; */ + /* color.green = 0xff; */ + /* color.blue = 0xff; */ + /* color.alpha = 0; */ if (iconPath) { - icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color); + icon = WMCreateGreyedPixmapFromFile(scr, iconPath); if (!icon) wwarning(_("could not load icon file %s"), iconPath); } else { diff --git a/src/dialog.c b/src/dialog.c index 7b0298f5..787fd6e0 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -631,16 +631,11 @@ static void listPixmaps(WScreen *scr, WMList *lPtr, const char *path) static void setViewedImage(IconPanel *panel, const char *file) { WMPixmap *pixmap; - RColor color; int iwidth, iheight; - color.red = 0xae; - color.green = 0xaa; - color.blue = 0xae; - color.alpha = 0; iwidth = WMWidgetWidth(panel->iconView); iheight = WMWidgetHeight(panel->iconView); - pixmap = WMCreateScaledBlendedPixmapFromFile(WMWidgetScreen(panel->win), file, &color, iwidth, iheight); + pixmap = WMCreateScaledGreyedPixmapFromFile(WMWidgetScreen(panel->win), file, iwidth, iheight); if (!pixmap) { WMSetButtonEnabled(panel->okButton, False); @@ -737,7 +732,6 @@ static void drawIconProc(WMList * lPtr, int index, Drawable d, char *text, int s WMColor *back; WMSize size; WMScreen *wmscr = WMWidgetScreen(panel->win); - RColor color; int x, y, width, height, len; /* Parameter not used, but tell the compiler that it is ok */ @@ -759,12 +753,11 @@ static void drawIconProc(WMList * lPtr, int index, Drawable d, char *text, int s snprintf(file, len, "%s/%s", dirfile, text); wfree(dirfile); - color.red = WMRedComponentOfColor(back) >> 8; - color.green = WMGreenComponentOfColor(back) >> 8; - color.blue = WMBlueComponentOfColor(back) >> 8; - color.alpha = WMGetColorAlpha(back) >> 8; - - pixmap = WMCreateScaledBlendedPixmapFromFile(wmscr, file, &color, width - 2, height - 2); + if (state & WLDSSelected) { + pixmap = WMCreateScaledPixmapFromFile(wmscr, file, width - 2, height - 2); + } else { + pixmap = WMCreateScaledGreyedPixmapFromFile(wmscr, file, width - 2, height - 2); + } wfree(file); if (!pixmap) { @@ -1279,7 +1272,7 @@ void wShowInfoPanel(WScreen *scr) pheight = WMScaleY(270); WMResizeWidget(panel->win, pwidth, pheight); - logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor *) NULL); + logo = WMCreateApplicationIconGreyedPixmap(scr->wmscreen); if (!logo) { logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen)); } @@ -1652,14 +1645,7 @@ static WMPixmap *getWindowMakerIconImage(WMScreen *scr) path = get_icon_filename("Logo", "WMPanel", NULL, False); if (path) { - RColor gray; - - gray.red = 0xae; - gray.green = 0xaa; - gray.blue = 0xae; - gray.alpha = 0; - - pix = WMCreateBlendedPixmapFromFile(scr, path, &gray); + pix = WMCreateGreyedPixmapFromFile(scr, path); wfree(path); } diff --git a/src/dockedapp.c b/src/dockedapp.c index 26f0a610..157bfb4e 100644 --- a/src/dockedapp.c +++ b/src/dockedapp.c @@ -68,14 +68,9 @@ static void updateSettingsPanelIcon(AppSettingsPanel * panel) return; } else { WMPixmap *pixmap; - RColor color; - color.red = 0xae; - color.green = 0xaa; - color.blue = 0xae; - color.alpha = 0; size = wPreferences.icon_size; - pixmap = WMCreateScaledBlendedPixmapFromFile(WMWidgetScreen(panel->win), path, &color, size, size); + pixmap = WMCreateScaledGreyedPixmapFromFile(WMWidgetScreen(panel->win), path, size, size); if (!pixmap) { WMSetLabelImage(panel->iconLabel, NULL); } else { diff --git a/wrlib-rs/Makefile.am b/wrlib-rs/Makefile.am index 228aaa4f..8d86dfb6 100644 --- a/wrlib-rs/Makefile.am +++ b/wrlib-rs/Makefile.am @@ -13,6 +13,7 @@ src/ffi.rs: ../wrlib/wraster.h patch_ffi.sed Makefile --allowlist-type "R(Context|ContextAttributes|Image|RenderingMode|ScalingFilter|StdColormapMode|ImageFormat|Color)" \ --allowlist-function "RGetClosestXColor" \ --allowlist-function "RLoadImage|RReleaseImage" \ + --allowlist-function "R(Load|Release|Clone|Scale)Image|RConvertImageMask|RCombineImageWithColor" \ -o src/ffi.rs \ -- \ -I../../wrlib \ diff --git a/wutil-rs/src/array.rs b/wutil-rs/src/array.rs index a0d94684..d12f2160 100644 --- a/wutil-rs/src/array.rs +++ b/wutil-rs/src/array.rs @@ -15,6 +15,8 @@ pub mod ffi { pub const NOT_FOUND: c_int = -1; + pub type WMArray = Array; + #[unsafe(no_mangle)] pub unsafe extern "C" fn WMCreateArray(initial_size: c_int) -> *mut Array { let cap = if initial_size < 0 {