8 Commits

Author SHA1 Message Date
70639c7462 Port WMPixmap to Rust. 2026-04-18 20:54:24 -04:00
784e896fad Generate a distinct FFI module for constants in WINGs C headers. 2026-04-18 20:39:11 -04:00
abd24dd745 Use a sed script instead of a shell script to fix up autogenerated WINGs FFI bindings. 2026-04-18 20:14:52 -04:00
6097395d45 Create integration tests for WINGs WMPixmap API. 2026-04-17 22:42:31 -04:00
c527a9f007 Spotfix for import path error. 2026-04-14 15:00:49 -04:00
b4a91efedc Port WMColor to Rust. 2026-04-14 13:35:09 -04:00
49e2a9071d Mirror WMRange into Rust.
This is a simple value type with only a constructor method. We keep duplicate type definitions in C and Rust for now, with the intention of doing something smarter later on.
2026-04-14 13:16:26 -04:00
e71673e46b Get rid of the W_PIXEL macro. 2026-04-14 12:55:51 -04:00
77 changed files with 2101 additions and 660 deletions

2
.gitignore vendored
View File

@@ -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

View File

@@ -32,7 +32,6 @@ libWINGs_la_SOURCES = \
wbox.c \
wbrowser.c \
wbutton.c \
wcolor.c \
wcolorpanel.c \
wcolorwell.c \
wconfig.h \
@@ -46,7 +45,6 @@ libWINGs_la_SOURCES = \
wmenuitem.c \
wmisc.c \
wpanel.c \
wpixmap.c \
wpopupbutton.c \
wprogressindicator.c \
wruler.c \

View File

@@ -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,26 +832,34 @@ 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/wcolor.c ]-------------------------------------------------- */
/* ---[ WINGs/wings-rs/src/color.rs ]------------------------------------- */
WMColor* WMDarkGrayColor(WMScreen *scr);

View File

@@ -67,9 +67,11 @@ typedef struct W_DraggingInfo {
/* ---[ Structures from WINGs.h ]----------------------------------------- */
/* Pre-definition of internal structs */
/* Opaque primitive types defined in Rust. */
typedef struct W_Color W_Color;
typedef struct W_Pixmap W_Pixmap;
/* Pre-definition of internal structs */
typedef struct W_Pixmap WMPixmap;
typedef struct W_View W_View;
typedef struct W_FocusInfo {
@@ -104,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 */
@@ -130,10 +132,10 @@ typedef struct W_Screen {
W_DraggingInfo dragInfo;
/* colors */
W_Color *white;
W_Color *black;
W_Color *gray;
W_Color *darkGray;
WMColor *white;
WMColor *black;
WMColor *gray;
WMColor *darkGray;
GC stippleGC;
@@ -163,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;
@@ -270,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;
@@ -413,23 +415,6 @@ void W_BalloonHandleEnterView(WMView *view);
void W_BalloonHandleLeaveView(WMView *view);
/* ---[ wcolor.c ]-------------------------------------------------------- */
struct W_Color {
struct W_Screen *screen;
XColor color;
unsigned short alpha;
short refCount;
GC gc;
struct {
unsigned int exact:1;
} flags;
};
#define W_PIXEL(c) (c)->color.pixel
/* ---[ wevent.c ]-------------------------------------------------------- */
typedef struct W_EventHandler {
@@ -491,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,
@@ -501,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 {

View File

@@ -281,7 +281,7 @@ char* wtrimspace(const char *s);
*/
char *wshellquote(const char *s);
/* ---[ WINGs/misc.c ]--------------------------------------------------- */
/* ---[ wutil-rs/src/range.rs ]------------------------------------------ */
WMRange wmkrange(int start, int count);

View File

@@ -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

View File

@@ -24,16 +24,6 @@
#include "error.h"
WMRange wmkrange(int start, int count)
{
WMRange range;
range.position = start;
range.count = count;
return range;
}
/*
* wutil_shutdown - cleanup in WUtil when user program wants to exit
*/

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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"));
@@ -1292,7 +1292,7 @@ void WMSetColorPanelPickerMode(WMColorPanel * panel, WMColorPanelMode mode)
panel->mode = mode;
}
WMColor *WMGetColorPanelColor(WMColorPanel * panel)
WMColor* WMGetColorPanelColor(WMColorPanel * panel)
{
return WMGetColorWellColor(panel->colorWell);
}
@@ -1301,9 +1301,9 @@ void WMSetColorPanelColor(WMColorPanel * panel, WMColor * color)
{
WMSetColorWellColor(panel->colorWell, color);
panel->color.rgb.red = color->color.red >> 8;
panel->color.rgb.green = color->color.green >> 8;
panel->color.rgb.blue = color->color.blue >> 8;
panel->color.rgb.red = (WMRedComponentOfColor(color) >> 8);
panel->color.rgb.green = (WMGreenComponentOfColor(color) >> 8);
panel->color.rgb.blue = (WMBlueComponentOfColor(color) >> 8);
panel->color.set = cpRGB;
if (panel->mode == panel->lastChanged)
@@ -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

View File

@@ -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);

View File

@@ -725,14 +725,14 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
gcv.graphics_exposures = False;
gcv.function = GXxor;
gcv.foreground = W_PIXEL(scrPtr->white);
gcv.foreground = WMColorPixel(scrPtr->white);
if (gcv.foreground == 0)
gcv.foreground = 1;
scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
| GCGraphicsExposures | GCForeground, &gcv);
gcv.function = GXxor;
gcv.foreground = W_PIXEL(scrPtr->gray);
gcv.foreground = WMColorPixel(scrPtr->gray);
gcv.subwindow_mode = IncludeInferiors;
scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
| GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
@@ -743,8 +743,8 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
gcv.foreground = W_PIXEL(scrPtr->darkGray);
gcv.background = W_PIXEL(scrPtr->gray);
gcv.foreground = WMColorPixel(scrPtr->darkGray);
gcv.background = WMColorPixel(scrPtr->gray);
gcv.fill_style = FillStippled;
gcv.stipple = stipple;
scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
@@ -1000,7 +1000,7 @@ void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
WMRedisplayWidget(w);
}
WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
WMColor * WMGetWidgetBackgroundColor(WMWidget * w)
{
return W_VIEW(w)->backColor;
}

View File

@@ -10,6 +10,7 @@ insta-image = { version = "1.0", features = ["png"] }
png = "0.18"
tempdir = "0.3.7"
wings-rs = { path = "../wings-rs" }
wrlib-rs = { path = "../../wrlib-rs" }
wutil-rs = { path = "../../wutil-rs" }
x11 = "2.21.0"

View File

@@ -40,4 +40,4 @@ all: rustlib
# process, and WINGs currently assumes that it is running in a single-threaded
# environment.
test: rustlib
LD_LIBRARY_PATH=../.libs $(CARGO) nextest run
LD_LIBRARY_PATH=../.libs:../../wrlib/.libs $(CARGO) nextest run

View File

@@ -1,19 +1,13 @@
fn main() {
println!("cargo::rustc-link-search=../.libs");
println!("cargo::rustc-link-search=../../wrlib/.libs");
println!("cargo::rustc-link-arg=-lX11");
println!("cargo::rustc-link-arg-tests=-lWUtil");
println!("cargo::rustc-link-arg-tests=-lWINGs");
println!("cargo::rustc-link-arg-tests=-lXft");
println!("cargo::rustc-link-arg-tests=-lpango-1.0");
println!("cargo::rustc-link-arg-tests=-lpangoxft-1.0");
println!("cargo::rustc-link-arg-tests=-lpangoft2-1.0");
println!("cargo::rustc-link-arg-examples=-lWUtil");
println!("cargo::rustc-link-arg-examples=-lWINGs");
println!("cargo::rustc-link-arg-examples=-lX11");
println!("cargo::rustc-link-arg-examples=-lXft");
println!("cargo::rustc-link-arg-examples=-lpango-1.0");
println!("cargo::rustc-link-arg-examples=-lpangoxft-1.0");
println!("cargo::rustc-link-arg-examples=-lpangoft2-1.0");
println!("cargo::rustc-link-arg=-lWUtil");
println!("cargo::rustc-link-arg=-lWINGs");
println!("cargo::rustc-link-arg=-lwraster");
println!("cargo::rustc-link-arg=-lX11");
println!("cargo::rustc-link-arg=-lXft");
println!("cargo::rustc-link-arg=-lpango-1.0");
println!("cargo::rustc-link-arg=-lpangoxft-1.0");
println!("cargo::rustc-link-arg=-lpangoft2-1.0");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 56
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 41
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 142
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 160
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 162
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 58
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 204
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 222
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 268
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 286
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 304
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 220
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 130
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -0,0 +1,7 @@
---
source: tests/wmpixmap_tests.rs
assertion_line: 229
expression: app.xvfb.png_screenshot()
extension: png
snapshot_kind: binary
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View File

@@ -0,0 +1,419 @@
use insta_image::assert_png_snapshot;
use std::{
ptr::{self, NonNull},
time::Instant,
};
use wings_rs::pixmap::ffi::*;
use wings_rs_tests::HeadlessApplication;
use wrlib_rs::ffi::{RLoadImage, RReleaseImage};
#[test]
fn draw_blank_pixmap() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmap(app.screen.as_ptr(), 128, 196, 24, 1)).unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
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());
x11::xlib::XSetForeground(display, gc, 0);
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());
x11::xlib::XFreeGC(display, gc);
WMReleasePixmap(pixmap.as_ptr());
}
}
// WMCreatePixmapFromXPixmaps is not tested because it simply fills in struct
// fields. Coverage from other tests in this file should be adequate.
#[test]
fn draw_pixmap_from_file() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_128x120.png".as_ptr(),
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!("from_file_pixmap", app.xvfb.png_screenshot());
WMReleasePixmap(pixmap.as_ptr());
}
}
#[test]
fn draw_pixmap_from_r_image_no_mask() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120.png".as_ptr(),
0,
);
let pixmap =
NonNull::new(WMCreatePixmapFromRImage(app.screen.as_ptr(), rimage, 255)).unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 70, 74);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!("from_r_image_no_mask", app.xvfb.png_screenshot());
WMReleasePixmap(pixmap.as_ptr());
}
}
#[test]
fn draw_pixmap_from_r_image_with_mask() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XBlackPixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = NonNull::new(RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120_varying_alpha.png".as_ptr(),
255,
))
.unwrap();
// The threshold given to WMCreatePixmapFromRImage is compared against
// the image's alpha channel. Pixels whose transparency are below the
// threshold are masked out. This should draw a quartet of images with
// varying masks.
// Totally masked.
let pixmap_255 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
255,
))
.unwrap();
WMDrawPixmap(pixmap_255.as_ptr(), win, 70, 74);
// Three bubbles masked.
let pixmap_200 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
200,
))
.unwrap();
WMDrawPixmap(pixmap_200.as_ptr(), win, 200, 74);
// Two bubbles masked.
let pixmap_128 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
128,
))
.unwrap();
WMDrawPixmap(pixmap_128.as_ptr(), win, 70, 200);
// Nothing masked.
let pixmap_0 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
0,
))
.unwrap();
WMDrawPixmap(pixmap_0.as_ptr(), win, 200, 200);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!("from_r_image_with_mask", app.xvfb.png_screenshot());
WMReleasePixmap(pixmap_255.as_ptr());
WMReleasePixmap(pixmap_200.as_ptr());
WMReleasePixmap(pixmap_128.as_ptr());
WMReleasePixmap(pixmap_0.as_ptr());
RReleaseImage(rimage.as_ptr());
}
}
#[test]
fn draw_blended_pixmap_from_r_image() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120.png".as_ptr(),
0,
);
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()) {}
assert_png_snapshot!("from_r_image_no_mask", app.xvfb.png_screenshot());
WMReleasePixmap(pixmap.as_ptr());
}
}
#[test]
fn draw_blended_pixmap_from_file() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!("from_file_blended_base_pixmap", app.xvfb.png_screenshot());
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_blended_cleared_window",
app.xvfb.png_screenshot()
);
let pixmap = NonNull::new(WMCreateGreyedPixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!("from_file_blended_with_grey", app.xvfb.png_screenshot());
WMReleasePixmap(pixmap.as_ptr());
}
}
#[test]
fn draw_scaled_blended_pixmap_from_file() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_scaled_blended_base_pixmap",
app.xvfb.png_screenshot()
);
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_scaled_blended_cleared_window",
app.xvfb.png_screenshot()
);
let pixmap = NonNull::new(WMCreateScaledGreyedPixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
60,
64,
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_scaled_blended_with_grey",
app.xvfb.png_screenshot()
);
WMReleasePixmap(pixmap.as_ptr());
}
}
#[test]
fn draw_scaled_blended_pixmap_from_file_non_integral_scaling() {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_128x120.png".as_ptr(),
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_scaled_blended_non_integral_base_pixmap",
app.xvfb.png_screenshot()
);
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_scaled_blended_non_integral_cleared_window",
app.xvfb.png_screenshot()
);
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(),
// Shrink by only a little bit, such that simple integer division
// might be thrown off. This test ensures that rescaling will
// actually happen.
110,
114,
))
.unwrap();
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
assert_png_snapshot!(
"from_file_scaled_blended_non_integral_scaled",
app.xvfb.png_screenshot()
);
WMReleasePixmap(pixmap.as_ptr());
}
}

View File

@@ -1,14 +1,18 @@
AUTOMAKE_OPTIONS =
RUST_SOURCES = \
src/WINGsP.rs \
RUST_SRC = \
src/WINGsP/constants.rs \
src/WINGsP/mod.rs \
src/button.rs \
src/color.rs \
src/configuration.rs \
src/ffi.rs \
src/font.rs \
src/font_panel.rs \
src/lib.rs \
src/list.rs \
src/pango_extras.rs \
src/pixmap.rs \
src/screen.rs \
src/widget.rs
@@ -16,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|Color|Pixmap|FilePanel)|R(Context|ContextAttributes|Image|RenderingMode|ScalingFilter|StdColormapMode|ImageFormat|Color)|_WINGsConfiguration" \
--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" \
@@ -46,21 +53,26 @@ src/WINGsP.rs: ../WINGs/WINGsP.h ../../wrlib/wraster.h ../WINGs/WINGs.h ../WINGs
--allowlist-function "^WM(CreateLabel|SetLabelText|SetLabelFont|SetLabelTextColor|SetLabelRelief|SetLabelTextAlignment)" \
--allowlist-type "^WM(Button|ButtonBehaviorMask)" \
--allowlist-function "^WM(CreateCustomButton|SetButtonText|SetButtonAction|SetButtonText)" \
--allowlist-function "wmkrange" \
--allowlist-type "^WM(View|Array|DragOperationType|Point|Data|OpenPanel|SavePanel|HashTable|DraggingInfo|SelectionProcs|Rect|EventProc|Widget|Size|Color|Pixmap|FilePanel|Screen|Range|List|ListItem)" \
--allowlist-type "^R(Context|ContextAttributes|Image|RenderingMode|ScalingFilter|StdColormapMode|ImageFormat|Color)" \
--allowlist-type "_WINGsConfiguration" \
--allowlist-item "^WMAlignment" \
--allowlist-item "^WMReliefType" \
-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
target/debug/libwings_rs.so: $(RUST_SOURCES) $(RUST_EXTRA)
target/debug/libwings_rs.so: $(RUST_SRC) $(RUST_EXTRA)
$(CARGO) build
check-local:
@@ -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

View File

@@ -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

View File

@@ -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) <file to patch>"
exit 1
fi
FILE="$1"
exec sed -i -r \
-e "1s/^/use x11::xlib::*;\nuse crate::font::ffi::WMFont;\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"

566
WINGs/wings-rs/src/color.rs Normal file
View File

@@ -0,0 +1,566 @@
use crate::WINGsP::WMScreen;
use std::cell::RefCell;
use std::ffi::c_ulong;
use std::ptr::{self, NonNull};
use wrlib_rs::ffi::{RColor, RGetClosestXColor};
pub struct Color {
screen: NonNull<WMScreen>,
color: x11::xlib::XColor,
alpha: RefCell<u16>,
gc: RefCell<x11::xlib::GC>,
}
#[derive(Clone, Copy, Debug)]
pub struct Rgb {
pub r: u16,
pub g: u16,
pub b: u16,
}
impl Rgb {
pub fn with_alpha(self, alpha: u16) -> Rgba {
Rgba {
r: self.r,
g: self.g,
b: self.b,
a: alpha,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ColorMatch {
Approximate,
Exact,
}
#[derive(Clone, Copy, Debug)]
pub struct Rgba {
pub r: u16,
pub g: u16,
pub b: u16,
pub a: u16,
}
impl Color {
const LIGHT_STIPPLE_WIDTH: u32 = 4;
const LIGHT_STIPPLE_HEIGHT: u32 = 4;
const LIGHT_STIPPLE_BITS: [u8; 4] = [0x05, 0x0a, 0x05, 0x0a];
const DARK_STIPPLE_WIDTH: u32 = 4;
const DARK_STIPPLE_HEIGHT: u32 = 4;
const DARK_STIPPLE_BITS: [u8; 4] = [0x0a, 0x04, 0x0a, 0x01];
pub fn new_rgb(screen: NonNull<WMScreen>, rgb: Rgb, mtch: ColorMatch) -> Option<Self> {
Self::new_rgba(screen, rgb.with_alpha(0xffff), mtch)
}
pub fn new_rgba(screen: NonNull<WMScreen>, rgba: Rgba, mtch: ColorMatch) -> Option<Self> {
match mtch {
ColorMatch::Approximate => find_close_rgba(screen, rgba),
ColorMatch::Exact => create_rgba(screen, rgba),
}
}
pub fn red(&self) -> u16 {
self.color.red
}
pub fn green(&self) -> u16 {
self.color.green
}
pub fn blue(&self) -> u16 {
self.color.blue
}
pub fn alpha(&self) -> u16 {
*self.alpha.borrow()
}
pub fn pixel(&self) -> c_ulong {
self.color.pixel
}
pub fn to_xft_color(&self) -> x11::xft::XftColor {
x11::xft::XftColor {
color: x11::xrender::XRenderColor {
red: self.red(),
green: self.green(),
blue: self.blue(),
alpha: self.alpha(),
},
pixel: self.pixel(),
}
}
pub fn to_rcolor(&self) -> RColor {
RColor {
red: (self.red() >> 8) as u8,
green: (self.green() >> 8) as u8,
blue: (self.blue() >> 8) as u8,
alpha: (self.alpha() >> 8) as u8,
}
}
pub fn gc(&self) -> x11::xlib::GC {
let mut gc = self.gc.borrow_mut();
if gc.is_null() {
let mut gcv =
unsafe { std::mem::MaybeUninit::<x11::xlib::XGCValues>::zeroed().assume_init() };
gcv.foreground = self.pixel();
gcv.graphics_exposures = 0;
*gc = unsafe {
let screen = &mut *self.screen.as_ptr();
x11::xlib::XCreateGC(
screen.display,
(*screen.rcontext).drawable,
(x11::xlib::GCForeground | x11::xlib::GCGraphicsExposures) as u64,
&mut gcv,
)
};
}
*gc
}
pub fn hex_triplet(&self) -> String {
format!(
"#{:02x}{:02x}{:02x}",
self.red() >> 8,
self.green() >> 8,
self.blue() >> 8
)
}
}
/*
* TODO: make the color creation code return the same WMColor for the
* same colors.
* make findCloseColor() find the closest color in the RContext pallette
* or in the other colors allocated by WINGs.
*/
fn find_close_rgba(screen: NonNull<WMScreen>, rgba: Rgba) -> Option<Color> {
let rcontext = unsafe { (*screen.as_ptr()).rcontext };
let display = unsafe { (*screen.as_ptr()).display };
let colormap = unsafe { (*screen.as_ptr()).colormap };
let mut xcolor = x11::xlib::XColor {
pixel: 0,
red: 0,
green: 0,
blue: 0,
flags: 0,
pad: 0,
};
let mut rcolor = RColor {
red: (rgba.r >> 8) as u8,
green: (rgba.g >> 8) as u8,
blue: (rgba.b >> 8) as u8,
alpha: (rgba.a >> 8) as u8,
};
if unsafe { RGetClosestXColor(rcontext, &mut rcolor, &mut xcolor) } == 0 {
return None;
}
if unsafe { x11::xlib::XAllocColor(display, colormap, &mut xcolor) } == 0 {
return None;
}
Some(Color {
screen: screen,
color: xcolor,
alpha: RefCell::new(rgba.a),
gc: RefCell::new(ptr::null_mut()),
})
}
fn create_rgba(screen: NonNull<WMScreen>, rgba: Rgba) -> Option<Color> {
let display = unsafe { (*screen.as_ptr()).display };
let colormap = unsafe { (*screen.as_ptr()).colormap };
let mut xcolor = x11::xlib::XColor {
red: rgba.r,
green: rgba.g,
blue: rgba.b,
flags: x11::xlib::DoRed | x11::xlib::DoGreen | x11::xlib::DoBlue,
pad: 0,
pixel: 0,
};
if unsafe { x11::xlib::XAllocColor(display, colormap, &mut xcolor) } == 0 {
return None;
}
Some(Color {
screen: screen,
color: xcolor,
alpha: RefCell::new(rgba.a),
gc: RefCell::new(ptr::null_mut()),
})
}
impl Drop for Color {
fn drop(&mut self) {
unsafe {
let display = (*self.screen.as_ptr()).display;
let colormap = (*self.screen.as_ptr()).colormap;
x11::xlib::XFreeColors(display, colormap, &mut self.color.pixel, 1, 0);
let gc = self.gc.borrow();
if !gc.is_null() {
x11::xlib::XFreeGC(display, *gc);
}
}
}
}
pub mod ffi {
use super::*;
use std::ffi::{c_char, c_int, c_uint, c_ulong, c_ushort, CString};
use std::ptr::NonNull;
use std::rc::Rc;
use wrlib_rs::ffi::RColor;
pub type WMColor = Rc<Color>;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMCreateRGBColor(
screen: NonNull<WMScreen>,
red: c_ushort,
green: c_ushort,
blue: c_ushort,
exact: c_int,
) -> *mut WMColor {
Color::new_rgb(
screen,
Rgb {
r: red,
g: green,
b: blue,
},
if exact == 0 {
ColorMatch::Approximate
} else {
ColorMatch::Exact
},
)
.map(|c| Box::leak(Box::new(Rc::new(c))) as *mut _)
.unwrap_or(unsafe { (*screen.as_ptr()).black })
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMGetRColorFroMColor(color: NonNull<WMColor>) -> RColor {
unsafe { (*color.as_ptr()).to_rcolor() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn pixel(c: &WMColor) -> c_ulong {
c.color.pixel
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMCreateRGBAColor(
screen: NonNull<WMScreen>,
red: c_ushort,
green: c_ushort,
blue: c_ushort,
alpha: c_ushort,
exact: c_int,
) -> *mut WMColor {
Color::new_rgba(
screen,
Rgba {
r: red,
g: green,
b: blue,
a: alpha,
},
if exact == 0 {
ColorMatch::Approximate
} else {
ColorMatch::Exact
},
)
.map(|c| Box::leak(Box::new(Rc::new(c))) as *mut _)
.unwrap_or(unsafe { (*screen.as_ptr()).black })
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMCreateNamedColor(
screen: NonNull<WMScreen>,
name: *const c_char,
exact: c_int,
) -> *mut WMColor {
let display = unsafe { (*screen.as_ptr()).display };
let colormap = unsafe { (*screen.as_ptr()).colormap };
let mut xcolor = x11::xlib::XColor {
red: 0,
green: 0,
blue: 0,
flags: 0,
pad: 0,
pixel: 0,
};
if unsafe { x11::xlib::XParseColor(display, colormap, name, &mut xcolor) } == 0 {
return ptr::null_mut();
}
let visual_class = unsafe { (*(*screen.as_ptr()).visual).class };
let exact = visual_class == x11::xlib::TrueColor || exact != 0;
if exact {
if let Some(c) = Color::new_rgb(
screen,
Rgb {
r: xcolor.red,
g: xcolor.green,
b: xcolor.blue,
},
ColorMatch::Exact,
) {
return Box::leak(Box::new(Rc::new(c))) as *mut _;
}
}
match Color::new_rgb(
screen,
Rgb {
r: xcolor.red,
g: xcolor.green,
b: xcolor.blue,
},
ColorMatch::Approximate,
) {
Some(c) => Box::leak(Box::new(Rc::new(c))) as *mut _,
None => ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMRetainColor(color: NonNull<WMColor>) -> *mut WMColor {
Box::leak(Box::new(unsafe { (*color.as_ptr()).clone() })) as *mut _
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMReleaseColor(color: NonNull<WMColor>) {
unsafe {
let _ = Box::from_raw(color.as_ptr());
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMSetColorAlpha(color: NonNull<WMColor>, alpha: c_ushort) {
unsafe {
(&mut *color.as_ptr()).alpha.replace(alpha);
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMPaintColorSwatch(
color: NonNull<WMColor>,
d: x11::xlib::Drawable,
x: c_int,
y: c_int,
width: c_uint,
height: c_uint,
) {
unsafe {
let color = &mut *color.as_ptr();
let display = (*color.screen.as_ptr()).display;
x11::xlib::XFillRectangle(display, d, color.gc(), x, y, width, height);
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMColorPixel(color: NonNull<WMColor>) -> c_ulong {
unsafe { (*color.as_ptr()).pixel() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMColorGC(color: NonNull<WMColor>) -> x11::xlib::GC {
unsafe { (&mut *color.as_ptr()).gc() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMSetColorInGC(color: NonNull<WMColor>, gc: x11::xlib::GC) {
unsafe {
let color = &mut *color.as_ptr();
let display = (*color.screen.as_ptr()).display;
x11::xlib::XSetForeground(display, gc, color.pixel());
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMWhiteColor(screen: NonNull<WMScreen>) -> *mut WMColor {
unsafe {
let scr = &mut *screen.as_ptr();
if scr.white.is_null() {
// TODO: warn if we couldn't allocate.
scr.white = WMCreateRGBColor(screen, 0xffff, 0xffff, 0xffff, 1);
}
NonNull::new(scr.white)
.map(|c| WMRetainColor(c))
.unwrap_or(ptr::null_mut())
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMBlackColor(screen: NonNull<WMScreen>) -> *mut WMColor {
unsafe {
let scr = &mut *screen.as_ptr();
if scr.black.is_null() {
// TODO: warn or bail out if we couldn't allocate.
scr.black = WMCreateRGBColor(screen, 0, 0, 0, 1);
}
NonNull::new(scr.black)
.map(|c| WMRetainColor(c))
.unwrap_or(ptr::null_mut())
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMGrayColor(screen: NonNull<WMScreen>) -> *mut WMColor {
unsafe {
let scr = &mut *screen.as_ptr();
if scr.gray.is_null() {
if scr.depth == 1 {
let white = WMWhiteColor(screen);
let black = WMBlackColor(screen);
let stipple = x11::xlib::XCreateBitmapFromData(
scr.display,
(*scr.rcontext).drawable,
Color::LIGHT_STIPPLE_BITS.as_ptr(),
Color::LIGHT_STIPPLE_WIDTH,
Color::LIGHT_STIPPLE_HEIGHT,
);
let color = create_rgba(
screen,
Rgba {
r: 0,
g: 0,
b: 0,
a: 0xffff,
},
)
.expect("cannot create stipple color");
let mut gcv =
std::mem::MaybeUninit::<x11::xlib::XGCValues>::zeroed().assume_init();
gcv.foreground = (&mut *white).color.pixel;
gcv.background = (&mut *black).color.pixel;
gcv.fill_style = x11::xlib::FillStippled;
gcv.stipple = stipple;
*color.gc.borrow_mut() = x11::xlib::XCreateGC(
scr.display,
(*scr.rcontext).drawable,
(x11::xlib::GCForeground
| x11::xlib::GCBackground
| x11::xlib::GCStipple
| x11::xlib::GCFillStyle
| x11::xlib::GCGraphicsExposures) as u64,
&mut gcv,
);
x11::xlib::XFreePixmap(scr.display, stipple);
if let Some(white) = NonNull::new(white) {
WMReleaseColor(white);
}
if let Some(black) = NonNull::new(black) {
WMReleaseColor(black);
}
} else {
scr.gray = WMCreateRGBColor(screen, 0xaeba, 0xaaaa, 0xaeba, 1);
// TODO: warn or bail if we couldn't allocate.
}
}
NonNull::new(scr.gray)
.map(|c| WMRetainColor(c))
.unwrap_or(ptr::null_mut())
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMDarkGrayColor(screen: NonNull<WMScreen>) -> *mut WMColor {
unsafe {
let scr = &mut *screen.as_ptr();
if scr.darkGray.is_null() {
if scr.depth == 1 {
let white = WMWhiteColor(screen);
let black = WMBlackColor(screen);
let stipple = x11::xlib::XCreateBitmapFromData(
scr.display,
(*scr.rcontext).drawable,
Color::DARK_STIPPLE_BITS.as_ptr(),
Color::DARK_STIPPLE_WIDTH,
Color::DARK_STIPPLE_HEIGHT,
);
let color = create_rgba(
screen,
Rgba {
r: 0,
g: 0,
b: 0,
a: 0xffff,
},
)
.expect("cannot create dark stipple color");
let mut gcv =
std::mem::MaybeUninit::<x11::xlib::XGCValues>::zeroed().assume_init();
gcv.foreground = (&mut *white).color.pixel;
gcv.background = (&mut *black).color.pixel;
gcv.fill_style = x11::xlib::FillStippled;
gcv.stipple = stipple;
*color.gc.borrow_mut() = x11::xlib::XCreateGC(
scr.display,
(*scr.rcontext).drawable,
(x11::xlib::GCForeground
| x11::xlib::GCBackground
| x11::xlib::GCStipple
| x11::xlib::GCFillStyle
| x11::xlib::GCGraphicsExposures) as u64,
&mut gcv,
);
x11::xlib::XFreePixmap(scr.display, stipple);
if let Some(white) = NonNull::new(white) {
WMReleaseColor(white);
}
if let Some(black) = NonNull::new(black) {
WMReleaseColor(black);
}
} else {
scr.darkGray = WMCreateRGBColor(screen, 0x5144, 0x5555, 0x5144, 1);
// TODO: warn or bail if we couldn't allocate.
}
}
NonNull::new(scr.darkGray)
.map(|c| WMRetainColor(c))
.unwrap_or(ptr::null_mut())
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMRedComponentOfColor(color: NonNull<WMColor>) -> c_ushort {
unsafe { (*color.as_ptr()).red() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMGreenComponentOfColor(color: NonNull<WMColor>) -> c_ushort {
unsafe { (*color.as_ptr()).green() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMBlueComponentOfColor(color: NonNull<WMColor>) -> c_ushort {
unsafe { (*color.as_ptr()).blue() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMGetColorAlpha(color: NonNull<WMColor>) -> c_ushort {
unsafe { (*color.as_ptr()).alpha() }
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn WMGetColorRGBDescription(color: NonNull<WMColor>) -> *const c_char {
unsafe {
wutil_rs::string::wstrdup(
CString::new((*color.as_ptr()).hex_triplet())
.unwrap()
.as_ptr(),
)
}
}
}

View File

@@ -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,
};

View File

@@ -0,0 +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::*;

View File

@@ -210,7 +210,12 @@ pub mod ffi {
use std::ffi::CStr;
use crate::{WINGsP, configuration::Configuration, pango_extras};
use crate::{
WINGsP,
configuration::Configuration,
color::ffi::WMColor,
pango_extras,
};
use std::{
ffi::{c_char, c_int, c_uint},
@@ -452,7 +457,7 @@ pub mod ffi {
pub unsafe extern "C" fn WMDrawString(
screen: *mut WINGsP::W_Screen,
d: x11::xlib::Drawable,
color: *mut WINGsP::W_Color,
color: *mut WMColor,
font: *mut WMFont,
x: c_int,
y: c_int,
@@ -466,15 +471,7 @@ pub mod ffi {
let screen = unsafe { &*screen };
let color = unsafe { &*color };
let layout = unsafe { &mut *(**font).layout.as_ptr() };
let mut xftcolor = x11::xft::XftColor {
color: x11::xrender::XRenderColor {
red: color.color.red,
green: color.color.green,
blue: color.color.blue,
alpha: color.alpha,
},
pixel: color.color.pixel,
};
let mut xftcolor = color.to_xft_color();
let previous_text = unsafe { pango_sys::pango_layout_get_text(layout) };
if previous_text.is_null() {
@@ -507,8 +504,8 @@ pub mod ffi {
pub unsafe extern "C" fn WMDrawImageString(
screen: *mut WINGsP::W_Screen,
d: x11::xlib::Drawable,
color: *mut WINGsP::W_Color,
background: *mut WINGsP::W_Color,
color: *mut WMColor,
background: *mut WMColor,
font: *mut WMFont,
x: c_int,
y: c_int,
@@ -523,24 +520,8 @@ pub mod ffi {
let color = unsafe { &*color };
let background = unsafe { &*background };
let layout = unsafe { &mut *(**font).layout.as_ptr() };
let mut text_color = x11::xft::XftColor {
color: x11::xrender::XRenderColor {
red: color.color.red,
green: color.color.green,
blue: color.color.blue,
alpha: color.alpha,
},
pixel: color.color.pixel,
};
let background = x11::xft::XftColor {
color: x11::xrender::XRenderColor {
red: background.color.red,
green: background.color.green,
blue: background.color.blue,
alpha: background.alpha,
},
pixel: color.color.pixel,
};
let mut text_color = color.to_xft_color();
let background = background.to_xft_color();
unsafe {
let Ok(width) = u32::try_from(WMWidthOfString(font, text, length)) else {

View File

@@ -741,10 +741,10 @@ impl FontPanel {
return;
}
WMSetTextFieldText(self.size_text.as_ptr(), (*item).text);
let Ok(len) = CStr::from_ptr((*item).text).count_bytes().try_into() else {
let Ok(len) = TryInto::<c_int>::try_into(CStr::from_ptr((*item).text).count_bytes()) else {
return;
};
WMSelectTextFieldRange(self.size_text.as_ptr(), wmkrange(0, len));
WMSelectTextFieldRange(self.size_text.as_ptr(), wutil_rs::range::Range::from(0..len));
}
}

View File

@@ -4,10 +4,13 @@
#[allow(non_upper_case_globals)]
pub mod WINGsP;
pub mod button;
pub mod color;
pub mod configuration;
pub mod ffi;
pub mod font;
pub mod font_panel;
pub mod list;
pub(crate) mod pango_extras;
pub mod pixmap;
pub mod screen;
pub mod widget;

View File

@@ -0,0 +1,602 @@
use crate::WINGsP;
use std::{
cell::RefCell,
ffi::CStr,
ptr::NonNull,
};
pub struct Pixmap {
display: NonNull<x11::xlib::Display>,
clip_gc: x11::xlib::GC,
pixmap: RefCell<x11::xlib::Pixmap>,
mask: RefCell<x11::xlib::Pixmap>,
width: u16,
height: u16,
depth: u16,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Masked {
Yes,
No,
}
impl Pixmap {
pub fn new(screen: NonNull<WINGsP::WMScreen>, 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<WINGsP::WMScreen>,
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<WINGsP::WMScreen>,
file_name: &CStr,
) -> Option<Self> {
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<WINGsP::WMScreen>,
image: NonNull<wrlib_rs::ffi::RImage>,
threshold: u16,
) -> Option<Self> {
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<R>(
rcontext: NonNull<wrlib_rs::ffi::RContext>,
file_name: &CStr,
f: impl FnOnce(Option<NonNull<wrlib_rs::ffi::RImage>>) -> 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<R>(
mut image: NonNull<wrlib_rs::ffi::RImage>,
transforms: &[Transform],
f: impl FnOnce(NonNull<wrlib_rs::ffi::RImage>) -> 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<wrlib_rs::ffi::RImage>,
) -> NonNull<wrlib_rs::ffi::RImage> {
match self {
Transform::Downscale { width, height } => {
let Ok(current_width): Result<u32, _> = (unsafe { (*image.as_ptr()).width.try_into() }) else {
return image;
};
let Ok(current_height): Result<u32, _> = (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<Pixmap>;
#[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,
);
}
}
}

View File

@@ -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;

View File

@@ -165,7 +165,7 @@ int W_GetTextHeight(WMFont * font, const char *text, int width, int wrap)
void
W_PaintText(W_View * view, Drawable d, WMFont * font, int x, int y,
int width, WMAlignment alignment, WMColor * color, int wrap,
int width, WMAlignment alignment, WMColor *color, int wrap,
const char *text, int length)
{
const char *ptr = text;
@@ -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 */

View File

@@ -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;

View File

@@ -1,260 +0,0 @@
#include "WINGsP.h"
#include <wraster.h>
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);
}

View File

@@ -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++;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
@@ -2989,8 +2990,8 @@ WMText *WMCreateTextForDocumentType(WMWidget * parent, WMAction * parser, WMActi
W_SetViewBackgroundColor(tPtr->view, tPtr->bgColor);
gcv.graphics_exposures = False;
gcv.foreground = W_PIXEL(scr->gray);
gcv.background = W_PIXEL(scr->darkGray);
gcv.foreground = WMColorPixel(scr->gray);
gcv.background = WMColorPixel(scr->darkGray);
gcv.fill_style = FillStippled;
/* why not use scr->stipple here? */
gcv.stipple = XCreateBitmapFromData(dpy, W_DRAWABLE(scr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);

View File

@@ -102,8 +102,8 @@ static W_View *createView(W_Screen * screen, W_View * parent)
view->attribFlags |= CWBackPixel | CWColormap | CWBorderPixel | CWBackPixmap;
view->attribs.background_pixmap = None;
view->attribs.background_pixel = W_PIXEL(screen->gray);
view->attribs.border_pixel = W_PIXEL(screen->black);
view->attribs.background_pixel = WMColorPixel(screen->gray);
view->attribs.border_pixel = WMColorPixel(screen->black);
view->attribs.colormap = screen->colormap;
view->backColor = WMRetainColor(screen->gray);
@@ -483,7 +483,7 @@ void W_RedisplayView(W_View * view)
WMHandleEvent(&ev);
}
void W_SetViewBackgroundColor(W_View * view, WMColor * color)
void W_SetViewBackgroundColor(W_View * view, WMColor *color)
{
if (view->backColor)
WMReleaseColor(view->backColor);
@@ -491,9 +491,9 @@ void W_SetViewBackgroundColor(W_View * view, WMColor * color)
view->attribFlags |= CWBackPixel;
view->attribFlags &= ~CWBackPixmap;
view->attribs.background_pixel = W_PIXEL(color);
view->attribs.background_pixel = WMColorPixel(color);
if (view->flags.realized) {
XSetWindowBackground(view->screen->display, view->window, W_PIXEL(color));
XSetWindowBackground(view->screen->display, view->window, WMColorPixel(color));
XClearWindow(view->screen->display, view->window);
}
}
@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -109,6 +109,7 @@ wmsetbg_LDADD = \
$(top_builddir)/wrlib/libwraster.la \
-lwings_rs \
-lwutil_rs \
$(top_builddir)/WINGs/libWINGs.la \
@XLFLAGS@ @LIBXINERAMA@ @XLIBS@ @INTLIBS@ @FCLIBS@ @PANGO_LIBS@
wmgenmenu_LDFLAGS = \

View File

@@ -12,6 +12,8 @@ src/ffi.rs: ../wrlib/wraster.h patch_ffi.sed Makefile
--allowlist-type "Bool" \
--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 \

View File

@@ -13,6 +13,7 @@ RUST_SOURCES = \
src/memory.rs \
src/notification.rs \
src/prop_list.rs \
src/range.rs \
src/sendable.rs \
src/string.rs \
src/tree.rs

View File

@@ -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 {

View File

@@ -8,6 +8,7 @@ pub mod hash_table;
pub mod memory;
pub mod notification;
pub mod prop_list;
pub mod range;
pub mod sendable;
pub mod string;
pub mod tree;

58
wutil-rs/src/range.rs Normal file
View File

@@ -0,0 +1,58 @@
use std::ffi::c_int;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[repr(C)]
pub struct Range {
pub start: c_int,
pub count: c_int,
}
impl Into<std::ops::Range<c_int>> for Range {
fn into(self) -> std::ops::Range<c_int> {
self.start..(self.start + self.count)
}
}
impl From<std::ops::Range<c_int>> for Range {
fn from(other: std::ops::Range<c_int>) -> Range {
Range {
start: other.start,
count: other.end - other.start
}
}
}
#[cfg(test)]
mod test {
use std::ffi::c_int;
use super::Range;
#[test]
fn from_std_range() {
assert_eq!(Range { start: 0, count: 10 }, Range::from(0..10));
assert_eq!(Range { start: 1, count: 9 }, Range::from(1..10));
}
#[test]
fn into_std_range() {
assert_eq!(0..10, Into::<std::ops::Range<c_int>>::into(Range {
start: 0,
count: 10
}));
assert_eq!(1..10, Into::<std::ops::Range<c_int>>::into(Range {
start: 1,
count: 9
}));
}
}
pub mod ffi {
use std::ffi::c_int;
pub type WMRange = super::Range;
#[unsafe(no_mangle)]
pub extern "C" fn wmkrange(start: c_int, count: c_int) -> WMRange {
WMRange { start, count }
}
}