diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index 4f3b80fc..16b8caad 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -7,6 +7,7 @@ Changes since wmaker 0.80.1: - WMDrawString() and WMDrawImageString() now take WMColor instead of GC as arguments. WMDrawImageString() receives 2 colors (text & background). This is to allow easy extension for Xft/Xrender and hide X low level details + Read NEWS for details since this will break backward compatibility. - Added alpha channel to WMColor. 2 new functions also: WMCreateRGBAColor() and WMSetColorAlpha() - Miscelaneous code cleanups in wtext.c @@ -18,7 +19,11 @@ Changes since wmaker 0.80.1: - Fixed some improper calls to snprintf in wfont.c - Added double buffering when drawing a WMFrame title with an AA font to avoid flickering. -- Added double buffering when drawing WMList items to avoid flickering +- Added double buffering when drawing WMList items to avoid flickering. + Double buffering for list also works for user drawn lists. Read NEWS for + details and incompatibilities introduced by this change. +- Added new Bool WMIsAAFont(WMFont *font) to check if a font is AA or not. +- Added WMGetColorAlpha(WMColor *color) Changes since wmaker 0.80.0: diff --git a/WINGs/NEWS b/WINGs/NEWS index 45b263f9..6ac1290e 100644 --- a/WINGs/NEWS +++ b/WINGs/NEWS @@ -1,3 +1,124 @@ +*** Mon Oct 14 19:42:42 EEST 2002 - Dan + +Double buffering +---------------- + +To avoid flickering caused by redrawing the widgets on Expose events, a +double buffering tehnique was implemented for most of the widgets. +This flickering effect has gotten more vizible with the introduction +of antialiased text. If with normal text one can redraw the text over the +old one over and over again without any degradation of the text (new pixels +simply overwrite old pixels), with antialiased text the situation is +different. +The pixels that constitute the antialias around the text are partially +transparent pixels, which let part of the background be visible through them. +If antialiased text is drawn over and over again, whithout first erasing the +old one, the partially transparent pixels of the antialias will no longer +see the background through them, but some of them will see the old pixels of +the antialias around the old text that was there before. This for example +will make a black antialiased text over a white background get thicker as +the pixels of the antialias around it, combine with semitransparent black +pixels of the old antialias instead of combining with the white background. +The result is that the antialias will get darker (in this case) and the text +will be altered. + +Because of this the area where text is drawn needs to be cleared before +antialiased text can be drawn again. But between the moment whent he area is +cleared and the moment when the text is drawn again there is a small time +gap that results in flickering. This doesn't happen with normal text where +one doesn't need to clear the area before drawing the text, but instead can +simply draw over and over again. + +To avoid this situation, a double buffering tehnique was used. Instead of +drawing directly in the wisget's window (which is mapped and will flicker as +described above), we draw in a pixmap (unmapped) and after all is done we +XCopyArea() from that pixmap to the real window. +Since all this takes place off-screen, no flickering will be observed in +this case. + +This is a change that that will be automatically available for your +applications and will require no change from you. +However there is an exception from this in case of WMList if you delegate +the drawing of items to userspace (read below for the compelte details). + + +*** Mon Oct 14 22:07:42 EEST 2002 - Dan + +WMList change +------------- + +In case of WMList there is the posibility to delegate the drawing of the +list items to the application that is linked with WINGs, and this code will +not be inside the WINGs library, but in userland. Since we use the double +buffering tehnique in this case too (to allow all widgets based on WMList +and the ones that draw their list items by themselves to benefit from the +double buffering advantage automatically), we no longer pass the window to +the user code doing item drawing, but instead pass this pixmap in which we +draw before copying to the real window. + +Since one cannot use XClearWindow() or XClearArea() on pixmaps, but only on +windows, if your list item drawing code used to contain these to clear the +item area before drawing it needs to change, else the application will die +when it tires to XClearArea() on a pixmap. + +This means that in your application if you ever used WMSetListUserDrawProc() +so set a userspace routine which draws WMList items in a particular fashion, +you need to make sure your function will not call XClearArea() or +XClearWindow() on the drawable that was passed to draw in. + +Instead you should use XFillRectangle(). + +This change also means that you no longer need to do double buffering in +your code, if you ever used to do. It is not done by WINGs and you benefit +from it automatically. + + +*** Mon Oct 14 19:28:35 EEST 2002 - Dan + +API change +---------- + +WMDrawString() and WMDrawImageString() no longer take a GC as argument. +Instead WMDrawString() takes a WMColor* as the color for the string to be +drawn, while WMDrawImageString() takes 2 WMColor* arguments in place of the +old GC: first for text color and second for background color. + +This change is required to support extending WMFont to allow it to handle +antialiased fonts through the XFree86 Xft extension. + +This also has the advantage of hiding low level X11 details and use WINGs +internat objects instead. + +To fix your old code to work with the new WINGs API you need to replace the +GC passed to WMDraw***String() in your code with a WMColor*. +Most of the old code used to be like this: + +WMDrawString(screen, window, WMColorGC(color), font, x, y, txt, len); + +for the new API it should be replaced by: + +WMDrawString(screen, window, color, font, x, y, txt, len); + +However if you used a particular GC created by yourself to suit your special +needs, you need to pass a color which is the same as the foreground color of +that gc. + +For WMDrawImageString(), from: + +WMDrawImageString(screen, window, gc, font, x, y, txt, len); + +becomes + +WMDrawImageString(screen, window, textColor, backColor, font, x, y, txt, len); + +where textColor and backColor are declared like: + +WMColor *textColor, *backColor; + +and have the color of the foreground respective the background of the old gc. + + + *** Wed Oct 9 07:10:04 EEST 2002 - Dan Xft support in WINGs diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index 04390025..b0f4815b 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -240,7 +240,7 @@ testList(WMScreen *scr) list = WMCreateList(win); /*WMSetListAllowEmptySelection(list, True);*/ WMMoveWidget(list, 10, 40); - for (i=0; i<14050; i++) { + for (i=0; i<105; i++) { sprintf(text, "Item %i", i); WMAddListItem(list, text); } @@ -248,7 +248,7 @@ testList(WMScreen *scr) WMSetListAllowMultipleSelection(mlist, True); /*WMSetListAllowEmptySelection(mlist, True);*/ WMMoveWidget(mlist, 210, 40); - for (i=0; i<14135; i++) { + for (i=0; i<135; i++) { sprintf(text, "Item %i", i); WMAddListItem(mlist, text); } @@ -1264,7 +1264,7 @@ main(int argc, char **argv) * Do NOT use it unless when debugging. It will cause a major * slowdown in your application */ -#if 1 +#if 0 XSynchronize(dpy, True); #endif /* @@ -1292,8 +1292,10 @@ main(int argc, char **argv) testDragAndDrop(scr); testText(scr); + testFontPanel(scr); testList(scr); + #if 0 testColorPanel(scr); testScrollView(scr); diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index 3d1ee484..3a085283 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -709,6 +709,8 @@ void WMReleaseFont(WMFont *font); unsigned int WMFontHeight(WMFont *font); +Bool WMIsAAFont(WMFont *font); + /* WMFont* WMUserFontOfSize(WMScreen *scrPtr, int size); @@ -820,6 +822,8 @@ unsigned short WMGreenComponentOfColor(WMColor *color); unsigned short WMBlueComponentOfColor(WMColor *color); +unsigned short WMGetColorAlpha(WMColor *color); + char* WMGetColorRGBDescription(WMColor *color); /* ....................................................................... */ diff --git a/WINGs/wappresource.c b/WINGs/wappresource.c index 20f337e6..0f82675a 100644 --- a/WINGs/wappresource.c +++ b/WINGs/wappresource.c @@ -102,7 +102,7 @@ WMCreateApplicationIconBlendedPixmap(WMScreen *scr, RColor *color) gray.red = 0xae; gray.green = 0xaa; gray.blue = 0xae; - gray.alpha = 0; + gray.alpha = 0xff; if (!color) color = &gray; diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c index abba3eed..b0522899 100644 --- a/WINGs/wbrowser.c +++ b/WINGs/wbrowser.c @@ -540,15 +540,14 @@ willResizeBrowser(W_ViewDelegate *self, WMView *view, static void -paintItem(WMList *lPtr, int index, Drawable drawable, char *text, int state, - WMRect *rect) +paintItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMRect *rect) { WMView *view = W_VIEW(lPtr); W_Screen *scr = view->screen; Display *display = scr->display; WMFont *font = ((state & WLDSIsBranch) ? scr->boldFont : scr->normalFont); + WMColor *backColor = ((state & WLDSSelected) ? scr->white : view->backColor); int width, height, x, y, textLen; - Drawable d = drawable; width = rect->size.width; height = rect->size.height; @@ -556,20 +555,7 @@ paintItem(WMList *lPtr, int index, Drawable drawable, char *text, int state, y = rect->pos.y; textLen = strlen(text); -#ifdef DOUBLE_BUFFER_no - x = y = 0; - d = XCreatePixmap(display, drawable, width, height, scr->depth); - if (state & WLDSSelected) - XFillRectangle(display, d, WMColorGC(scr->white), 0, 0, width, height); - else - XFillRectangle(display, d, WMColorGC(view->backColor), 0, 0, width, height); -#else - if (state & WLDSSelected) - XFillRectangle(display, d, WMColorGC(scr->white), x, y, width, height); - else - //XFillRectangle(display, d, WMColorGC(view->backColor), x, y, width, height); - XClearArea(display, d, x, y, width, height, False); -#endif + XFillRectangle(display, d, WMColorGC(backColor), x, y, width, height); if (text) { /* Avoid overlaping... */ @@ -586,23 +572,15 @@ paintItem(WMList *lPtr, int index, Drawable drawable, char *text, int state, } if (state & WLDSIsBranch) { + WMColor *lineColor = ((state & WLDSSelected) ? scr->gray : scr->white); + XDrawLine(display, d, WMColorGC(scr->darkGray), x+width-11, y+3, x+width-6, y+height/2); - if (state & WLDSSelected) - XDrawLine(display, d,WMColorGC(scr->gray), x+width-11, y+height-5, - x+width-6, y+height/2); - else - XDrawLine(display, d,WMColorGC(scr->white), x+width-11, y+height-5, - x+width-6, y+height/2); + XDrawLine(display, d, WMColorGC(lineColor), x+width-11, y+height-5, + x+width-6, y+height/2); XDrawLine(display, d, WMColorGC(scr->black), x+width-12, y+3, x+width-12, y+height-5); } - -#ifdef DOUBLE_BUFFER_no - XCopyArea(display, d, drawable, scr->copyGC, 0, 0, width, height, - rect->pos.x, rect->pos.y); - XFreePixmap(display, d); -#endif } diff --git a/WINGs/wcolor.c b/WINGs/wcolor.c index 2140ca3c..5f6d9ea0 100644 --- a/WINGs/wcolor.c +++ b/WINGs/wcolor.c @@ -342,6 +342,13 @@ WMBlueComponentOfColor(WMColor *color) } +unsigned short +WMGetColorAlpha(WMColor *color) +{ + return color->alpha; +} + + char* WMGetColorRGBDescription(WMColor *color) { diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c index d5fa1009..97712dcc 100644 --- a/WINGs/wcolorpanel.c +++ b/WINGs/wcolorpanel.c @@ -3422,12 +3422,13 @@ static void colorListPaintItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMRect *rect) { - int width, height, x, y; - RColor color = *((RColor *)WMGetListItem(lPtr, index)->clientData); - WMScreen *scr = WMWidgetScreen(lPtr); - Display *dpy = WMScreenDisplay(scr); - W_ColorPanel *panel = WMGetHangedData(lPtr); - WMColor *fillColor; + WMScreen *scr = WMWidgetScreen(lPtr); + Display *dpy = WMScreenDisplay(scr); + WMView *view = W_VIEW(lPtr); + RColor color = *((RColor *)WMGetListItem(lPtr, index)->clientData); + W_ColorPanel *panel = WMGetHangedData(lPtr); + int width, height, x, y; + WMColor *fillColor; width = rect->size.width; height = rect->size.height; @@ -3435,15 +3436,14 @@ colorListPaintItem(WMList *lPtr, int index, Drawable d, char *text, y = rect->pos.y; if (state & WLDSSelected) - WMPaintColorSwatch(scr->white, d, x +15, y, width -15, height); + XFillRectangle(dpy, d, WMColorGC(scr->white), x, y, width, height); else - XClearArea(dpy, d, x +15, y, width -15, height, False); + XFillRectangle(dpy, d, WMColorGC(view->backColor), x, y, width, height); - fillColor = WMCreateRGBColor(scr, color.red*256, color.green*256, - color.blue*256, False); + fillColor = WMCreateRGBColor(scr, color.red<<8, color.green<<8, + color.blue<<8, True); - WMSetColorInGC(fillColor, WMColorGC(fillColor)); - WMPaintColorSwatch(fillColor, d, x, y, 15, 15); + XFillRectangle(dpy, d, WMColorGC(fillColor), x, y, 15, height); WMReleaseColor(fillColor); WMDrawString(scr, d, scr->black, panel->font12, x+18, y, text, strlen(text)); diff --git a/WINGs/wfont.c b/WINGs/wfont.c index a2dd6565..b729a2c1 100644 --- a/WINGs/wfont.c +++ b/WINGs/wfont.c @@ -343,6 +343,12 @@ WMReleaseFont(WMFont *font) } +Bool +WMIsAAFont(WMFont *font) +{ + return font->antialiased; +} + unsigned int WMFontHeight(WMFont *font) diff --git a/WINGs/wframe.c b/WINGs/wframe.c index e00fbb50..c095c50e 100644 --- a/WINGs/wframe.c +++ b/WINGs/wframe.c @@ -8,7 +8,6 @@ typedef struct W_Frame { char *caption; - struct { WMReliefType relief:4; WMTitlePosition titlePosition:4; @@ -43,9 +42,9 @@ void WMSetFrameRelief(WMFrame *fPtr, WMReliefType relief) { fPtr->flags.relief = relief; - - if (fPtr->view->flags.realized) { - repaintFrame(fPtr); + + if (fPtr->view->flags.realized) { + repaintFrame(fPtr); } } @@ -54,14 +53,15 @@ void WMSetFrameTitle(WMFrame *fPtr, char *title) { if (fPtr->caption) - wfree(fPtr->caption); - if (title) - fPtr->caption = wstrdup(title); - else - fPtr->caption = NULL; + wfree(fPtr->caption); - if (fPtr->view->flags.realized) { - repaintFrame(fPtr); + if (title) + fPtr->caption = wstrdup(title); + else + fPtr->caption = NULL; + + if (fPtr->view->flags.realized) { + repaintFrame(fPtr); } } @@ -197,8 +197,8 @@ paintFrame(Frame *fPtr) if (drawTitle) { /* can't draw AA text over and over again because it gets messed */ + // TODO create the dbl buffer pixmap when create/set frame title if (font->antialiased) { -#ifdef DOUBLE_BUFFER Drawable d; d = XCreatePixmap(display, view->window, tw, th, scrPtr->depth); @@ -207,11 +207,6 @@ paintFrame(Frame *fPtr) WMDrawString(scrPtr, d, scrPtr->black, font, 0, 0, fPtr->caption, tlen); XCopyArea(display, d, view->window, scrPtr->copyGC, 0, 0, tw, th, tx, ty); XFreePixmap(display, d); -#else - XClearArea(display, view->window, tx, ty, tw, th, False); - WMDrawString(scrPtr, view->window, scrPtr->black, font, tx, ty, - fPtr->caption, tlen); -#endif } else { WMDrawString(scrPtr, view->window, scrPtr->black, font, tx, ty, fPtr->caption, tlen); diff --git a/WINGs/wlist.c b/WINGs/wlist.c index 8b250ffb..d1ef779f 100644 --- a/WINGs/wlist.c +++ b/WINGs/wlist.c @@ -33,6 +33,8 @@ typedef struct W_List { WMScroller *vScroller; + Pixmap doubleBuffer; + struct { unsigned int allowMultipleSelection:1; unsigned int allowEmptySelection:1; @@ -83,6 +85,30 @@ W_ViewDelegate _ListViewDelegate = { }; +static void +updateDoubleBufferPixmap(WMList *lPtr) +{ + WMView *view = lPtr->view; + WMScreen *scr = view->screen; + + if (!view->flags.realized) + return; + + if (lPtr->doubleBuffer) + XFreePixmap(scr->display, lPtr->doubleBuffer); + lPtr->doubleBuffer = + XCreatePixmap(scr->display, view->window, view->size.width, + lPtr->itemHeight, scr->depth); +} + + +static void +realizeObserver(void *self, WMNotification *not) +{ + updateDoubleBufferPixmap(self); +} + + static void releaseItem(void *data) { @@ -138,6 +164,9 @@ WMCreateList(WMWidget *parent) W_ResizeView(lPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT); + WMAddNotificationObserver(realizeObserver, lPtr, + WMViewRealizedNotification, lPtr->view); + return lPtr; } @@ -274,11 +303,15 @@ WMSetListUserDrawProc(WMList *lPtr, WMListDrawProc *proc) void WMSetListUserDrawItemHeight(WMList *lPtr, unsigned short height) { + W_Screen *scr = lPtr->view->screen; + assert(height > 0); lPtr->flags.userItemHeight = 1; lPtr->itemHeight = height; + updateDoubleBufferPixmap(lPtr); + updateGeometry(lPtr); } @@ -494,6 +527,7 @@ paintItem(List *lPtr, int index) Display *display = scr->display; int width, height, x, y, tlen; WMListItem *itemPtr; + Drawable d = lPtr->doubleBuffer; itemPtr = WMGetFromArray(lPtr->items, index); @@ -505,14 +539,13 @@ paintItem(List *lPtr, int index) if (lPtr->flags.userDrawn) { WMRect rect; - Drawable d = view->window; int flags; rect.size.width = width; rect.size.height = height; - rect.pos.x = x; - rect.pos.y = y; + rect.pos.x = 0; + rect.pos.y = 0; flags = itemPtr->uflags; if (itemPtr->disabled) @@ -522,41 +555,18 @@ paintItem(List *lPtr, int index) if (itemPtr->isBranch) flags |= WLDSIsBranch; -#ifdef DOUBLE_BUFFER_no - d = XCreatePixmap(display, view->window, view->size.width, - view->size.height, scr->depth); -#endif - if (lPtr->draw) (*lPtr->draw)(lPtr, index, d, itemPtr->text, flags, &rect); -#ifdef DOUBLE_BUFFER_no - XCopyArea(display, d, view->window, scr->copyGC, x, y, width, height, x, y); - XFreePixmap(display, d); -#endif + XCopyArea(display, d, view->window, scr->copyGC, 0, 0, width, height, x, y); } else { -#ifdef DOUBLE_BUFFER WMColor *back = (itemPtr->selected ? scr->white : view->backColor); - Drawable d; - d = XCreatePixmap(display, view->window, width, height, scr->depth); XFillRectangle(display, d, WMColorGC(back), 0, 0, width, height); W_PaintText(view, d, scr->normalFont, 4, 0, width, WALeft, scr->black, False, itemPtr->text, tlen); XCopyArea(display, d, view->window, scr->copyGC, 0, 0, width, height, x, y); - XFreePixmap(display, d); -#else - if (itemPtr->selected) { - XFillRectangle(display, view->window, WMColorGC(scr->white), - x, y, width, height); - } else { - XClearArea(display, view->window, x, y, width, height, False); - } - - W_PaintText(view, view->window, scr->normalFont, x+4, y, width, - WALeft, scr->black, False, itemPtr->text, tlen); -#endif } if ((index-lPtr->topItem+lPtr->fullFitLines)*lPtr->itemHeight > @@ -1224,9 +1234,12 @@ static void didResizeList(W_ViewDelegate *self, WMView *view) { WMList *lPtr = (WMList*)view->self; + W_Screen *scr = view->screen; WMResizeWidget(lPtr->vScroller, 1, view->size.height-2); + updateDoubleBufferPixmap(lPtr); + updateGeometry(lPtr); } @@ -1248,6 +1261,9 @@ destroyList(List *lPtr) if (lPtr->items) WMFreeArray(lPtr->items); + if (lPtr->doubleBuffer) + XFreePixmap(lPtr->view->screen->display, lPtr->doubleBuffer); + wfree(lPtr); } diff --git a/WINGs/wprogressindicator.c b/WINGs/wprogressindicator.c index 54ce3f0d..36d5de5c 100644 --- a/WINGs/wprogressindicator.c +++ b/WINGs/wprogressindicator.c @@ -40,18 +40,10 @@ W_ViewDelegate _ProgressIndicatorDelegate = { static void destroyProgressIndicator(ProgressIndicator *pPtr); static void paintProgressIndicator(ProgressIndicator *pPtr); -static void realizeProgressIndicator(ProgressIndicator *pPtr); static void handleEvents(XEvent *event, void *data); -static void -realizeObserver(void *self, WMNotification *not) -{ - realizeProgressIndicator(self); -} - - WMProgressIndicator* WMCreateProgressIndicator(WMWidget *parent) { @@ -84,9 +76,6 @@ WMCreateProgressIndicator(WMWidget *parent) pPtr->minValue = 0; pPtr->maxValue = 100; - WMAddNotificationObserver(realizeObserver, pPtr, - WMViewRealizedNotification, pPtr->view); - return pPtr; } @@ -169,13 +158,6 @@ WMGetProgressIndicatorValue(WMProgressIndicator *progressindicator) } -static void -realizeProgressIndicator(ProgressIndicator *pPtr) -{ - W_RealizeView(pPtr->view); -} - - static void didResizeProgressIndicator(W_ViewDelegate *self, WMView *view) { diff --git a/WINGs/wruler.c b/WINGs/wruler.c index 4b3b935e..2bd633ad 100644 --- a/WINGs/wruler.c +++ b/WINGs/wruler.c @@ -95,7 +95,8 @@ drawLeftMarker(Ruler * rPtr) | */ -static void drawRightMarker(Ruler * rPtr) +static void +drawRightMarker(Ruler * rPtr) { XPoint points[4]; int xpos = (rPtr->flags.whichMarker==2 ? rPtr->motion : rPtr->margins.right); @@ -121,7 +122,8 @@ static void drawRightMarker(Ruler * rPtr) | */ -static void drawFirstMarker(Ruler * rPtr) +static void +drawFirstMarker(Ruler * rPtr) { int xpos = ((rPtr->flags.whichMarker == 3 || rPtr->flags.whichMarker == 6) ? rPtr->motion : rPtr->margins.first); @@ -137,7 +139,8 @@ static void drawFirstMarker(Ruler * rPtr) \ / \./ */ -static void drawBodyMarker(Ruler * rPtr) +static void +drawBodyMarker(Ruler * rPtr) { XPoint points[4]; int xpos = ((rPtr->flags.whichMarker == 4 || rPtr->flags.whichMarker == 6) ? @@ -154,13 +157,14 @@ static void drawBodyMarker(Ruler * rPtr) } -static void createDrawBuffer(Ruler * rPtr) +static void +createDrawBuffer(Ruler * rPtr) { if(!rPtr->view->flags.realized) return; if (rPtr->drawBuffer) - XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer); + XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer); rPtr->drawBuffer = XCreatePixmap(rPtr->view->screen->display, rPtr->view->window, rPtr->view->size.width, 40, @@ -170,7 +174,8 @@ static void createDrawBuffer(Ruler * rPtr) } -static void drawRulerOnPixmap(Ruler * rPtr) +static void +drawRulerOnPixmap(Ruler * rPtr) { int i, j, w, m; char c[3]; @@ -220,7 +225,8 @@ static void drawRulerOnPixmap(Ruler * rPtr) } -static void paintRuler(Ruler * rPtr) +static void +paintRuler(Ruler * rPtr) { if (!rPtr->drawBuffer || !rPtr->view->flags.realized) return; @@ -234,7 +240,7 @@ static void paintRuler(Ruler * rPtr) static Bool - verifyMarkerMove(Ruler * rPtr, int x) +verifyMarkerMove(Ruler * rPtr, int x) { if (rPtr->flags.whichMarker < 1 || rPtr->flags.whichMarker > 6) return False; @@ -279,7 +285,8 @@ static Bool } -static int whichMarker(Ruler * rPtr, int x, int y) +static int +whichMarker(Ruler * rPtr, int x, int y) { if (x < rPtr->offset || y > 22) return 0; @@ -320,7 +327,8 @@ static int whichMarker(Ruler * rPtr, int x, int y) return 0; } -static void rulerDidResize(W_ViewDelegate * self, WMView * view) +static void +rulerDidResize(W_ViewDelegate * self, WMView * view) { Ruler *rPtr = (Ruler *) view->self; @@ -331,7 +339,8 @@ static void rulerDidResize(W_ViewDelegate * self, WMView * view) } -static void handleEvents(XEvent * event, void *data) +static void +handleEvents(XEvent * event, void *data) { Ruler *rPtr = (Ruler *) data; @@ -470,7 +479,8 @@ WMCreateRuler(WMWidget * parent) } -void WMSetRulerMargins(WMRuler * rPtr, WMRulerMargins margins) +void +WMSetRulerMargins(WMRuler * rPtr, WMRulerMargins margins) { if (!rPtr) return; @@ -529,7 +539,8 @@ WMIsMarginEqualToMargin(WMRulerMargins *aMargin, WMRulerMargins *anotherMargin) -void WMSetRulerOffset(WMRuler * rPtr, int pixels) +void +WMSetRulerOffset(WMRuler * rPtr, int pixels) { if (!rPtr || pixels < 0 || pixels + MIN_DOC_WIDTH >= rPtr->view->size.width) return; @@ -538,7 +549,8 @@ void WMSetRulerOffset(WMRuler * rPtr, int pixels) } -int WMGetRulerOffset(WMRuler * rPtr) +int +WMGetRulerOffset(WMRuler * rPtr) { if (!rPtr) return 0; /* what value should return if no ruler? -1 or 0? */ @@ -546,7 +558,8 @@ int WMGetRulerOffset(WMRuler * rPtr) } -void WMSetRulerReleaseAction(WMRuler * rPtr, WMAction * action, void *clientData) +void +WMSetRulerReleaseAction(WMRuler * rPtr, WMAction * action, void *clientData) { if (!rPtr) return; @@ -556,7 +569,8 @@ void WMSetRulerReleaseAction(WMRuler * rPtr, WMAction * action, void *clientData } -void WMSetRulerMoveAction(WMRuler * rPtr, WMAction * action, void *clientData) +void +WMSetRulerMoveAction(WMRuler * rPtr, WMAction * action, void *clientData) { if (!rPtr) return; @@ -567,7 +581,8 @@ void WMSetRulerMoveAction(WMRuler * rPtr, WMAction * action, void *clientData) /* _which_ one was released */ -int WMGetReleasedRulerMargin(WMRuler * rPtr) +int +WMGetReleasedRulerMargin(WMRuler * rPtr) { if (!rPtr) return 0; @@ -576,7 +591,8 @@ int WMGetReleasedRulerMargin(WMRuler * rPtr) /* _which_ one is being grabbed */ -int WMGetGrabbedRulerMargin(WMRuler * rPtr) +int +WMGetGrabbedRulerMargin(WMRuler * rPtr) { if (!rPtr) return 0; diff --git a/WINGs/wslider.c b/WINGs/wslider.c index 65744521..aa978734 100644 --- a/WINGs/wslider.c +++ b/WINGs/wslider.c @@ -52,7 +52,6 @@ W_ViewDelegate _SliderViewDelegate = { static void destroySlider(Slider *sPtr); static void paintSlider(Slider *sPtr); -static void realizeSlider(Slider *sPtr); static void handleEvents(XEvent *event, void *data); static void handleActionEvents(XEvent *event, void *data); @@ -62,11 +61,11 @@ static void makeKnobPixmap(Slider *sPtr); static void realizeObserver(void *self, WMNotification *not) { - realizeSlider(self); + makeKnobPixmap(self); } - + WMSlider* WMCreateSlider(WMWidget *parent) { @@ -103,8 +102,8 @@ WMCreateSlider(WMWidget *parent) sPtr->knobThickness = 20; sPtr->flags.continuous = 1; - - WMAddNotificationObserver(realizeObserver, sPtr, + + WMAddNotificationObserver(realizeObserver, sPtr, WMViewRealizedNotification, sPtr->view); return sPtr; @@ -294,15 +293,6 @@ makeKnobPixmap(Slider *sPtr) } -static void -realizeSlider(Slider *sPtr) -{ - W_RealizeView(sPtr->view); - - makeKnobPixmap(sPtr); -} - - static void didResizeSlider(W_ViewDelegate *self, WMView *view) { diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index 85e756a9..e318bc68 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -835,7 +835,7 @@ paintTextField(TextField *tPtr) } totalWidth = tPtr->view->size.width - 2*bd; - + drawbuffer = XCreatePixmap(screen->display, view->window, view->size.width, view->size.height, screen->depth); XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white), @@ -849,7 +849,7 @@ paintTextField(TextField *tPtr) if (tPtr->textLen > 0) { tw = WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]), tPtr->textLen - tPtr->viewPosition); - + th = WMFontHeight(tPtr->font); ty = tPtr->offsetWidth; diff --git a/WINGs/wview.c b/WINGs/wview.c index 1d9fee3e..05ab0009 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -213,7 +213,7 @@ W_RealizeView(W_View *view) assert(view->size.width > 0); assert(view->size.height > 0); - + if (view->parent && !view->parent->flags.realized) { wwarning("trying to realize widget of unrealized parent"); return; @@ -226,7 +226,7 @@ W_RealizeView(W_View *view) view->screen->depth, InputOutput, view->screen->visual, view->attribFlags, &view->attribs); - + XSaveContext(dpy, view->window, ViewContext, (XPointer)view); view->flags.realized = 1; @@ -253,7 +253,7 @@ void W_ReparentView(W_View *view, W_View *newParent, int x, int y) { Display *dpy = view->screen->display; - + assert(!view->flags.topLevel); unparentView(view); @@ -481,7 +481,7 @@ void W_MoveView(W_View *view, int x, int y) { assert(view->flags.root==0); - + //TODO move this after the test pos==oldpos if (view->delegate && view->delegate->willMove) { (*view->delegate->willMove)(view->delegate, view, &x, &y); } @@ -503,9 +503,9 @@ W_MoveView(W_View *view, int x, int y) void W_ResizeView(W_View *view, unsigned int width, unsigned int height) -{ +{ int shrinked; - + // TODO move this after the test size==oldsize if (view->delegate && view->delegate->willResize) { (*view->delegate->willResize)(view->delegate, view, &width, &height); } @@ -520,7 +520,7 @@ W_ResizeView(W_View *view, unsigned int width, unsigned int height) if (view->flags.realized) { XResizeWindow(view->screen->display, view->window, width, height); - } + } view->size.width = width; view->size.height = height; diff --git a/WINGs/wwindow.c b/WINGs/wwindow.c index 333eeac4..fcfb56a9 100644 --- a/WINGs/wwindow.c +++ b/WINGs/wwindow.c @@ -445,7 +445,7 @@ realizeWindow(WMWindow *win) if (win->title || win->miniTitle) XmbSetWMProperties(scr->display, win->view->window, win->title, win->miniTitle, NULL, 0, NULL, NULL, NULL); - + setWindowMakerHints(win); setSizeHints(win); diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index 293df533..1db9b4fc 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -1296,7 +1296,7 @@ paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMScreen *scr = WMWidgetScreen(lPtr); int width, height, x, y; Display *dpy = WMScreenDisplay(scr); - WMColor *white = WMWhiteColor(scr); + WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr); WMListItem *item; WMColor *black = WMBlackColor(scr); TextureListItem *titem; @@ -1304,7 +1304,7 @@ paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state, item = WMGetListItem(lPtr, index); titem = (TextureListItem*)item->clientData; if (!titem) { - WMReleaseColor(white); + WMReleaseColor(back); WMReleaseColor(black); return; } @@ -1314,11 +1314,7 @@ paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state, x = rect->pos.x; y = rect->pos.y; - if (state & WLDSSelected) - XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height); - else - XClearArea(dpy, d, x, y, width, height, False); - + XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height); if (titem->preview) XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0, @@ -1338,7 +1334,7 @@ paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state, strlen(titem->texture)); - WMReleaseColor(white); + WMReleaseColor(back); WMReleaseColor(black); } diff --git a/WPrefs.app/KeyboardShortcuts.c b/WPrefs.app/KeyboardShortcuts.c index 9aa54edd..ed5c3904 100644 --- a/WPrefs.app/KeyboardShortcuts.c +++ b/WPrefs.app/KeyboardShortcuts.c @@ -53,6 +53,7 @@ typedef struct _Panel { WMColor *white; WMColor *black; + WMColor *gray; WMFont *font; /**/ @@ -433,17 +434,14 @@ paintItem(WMList *lPtr, int index, Drawable d, char *text, int state, _Panel *panel = (_Panel*)WMGetHangedData(lPtr); WMScreen *scr = WMWidgetScreen(lPtr); Display *dpy = WMScreenDisplay(scr); + WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray; width = rect->size.width; height = rect->size.height; x = rect->pos.x; y = rect->pos.y; - if (state & WLDSSelected) - XFillRectangle(dpy, d, WMColorGC(panel->white), x, y, width, height); - else - //XClearArea(dpy, d, x, y, width, height, False); - XFillRectangle(dpy, d, WMColorGC(WMGrayColor(scr)), x, y, width, height); + XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height); if (panel->shortcuts[index]) { WMPixmap *pix = WMGetSystemPixmap(scr, WSICheckMark); @@ -466,8 +464,11 @@ createPanel(Panel *p) WMFont *boldFont; panel->capturing = 0; - + panel->white = WMWhiteColor(scr); + panel->black = WMBlackColor(scr); + panel->gray = WMGrayColor(scr); + panel->font = WMSystemFontOfSize(scr, 12); panel->box = WMCreateBox(panel->parent); WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2); @@ -485,9 +486,7 @@ createPanel(Panel *p) color = WMDarkGrayColor(scr); WMSetWidgetBackgroundColor(panel->actL, color); WMReleaseColor(color); - color = WMWhiteColor(scr); - WMSetLabelTextColor(panel->actL, color); - WMReleaseColor(color); + WMSetLabelTextColor(panel->actL, panel->white); panel->actLs = WMCreateList(panel->box); WMResizeWidget(panel->actLs, 280, 190); @@ -632,18 +631,14 @@ InitKeyboardShortcuts(WMScreen *scr, WMWidget *parent) panel->sectionName = _("Keyboard Shortcut Preferences"); panel->description = _("Change the keyboard shortcuts for actions such\n" - "as changing workspaces and opening menus."); + "as changing workspaces and opening menus."); panel->parent = parent; - + panel->callbacks.createWidgets = createPanel; panel->callbacks.updateDomain = storeData; - panel->white = WMWhiteColor(scr); - panel->black = WMBlackColor(scr); - panel->font = WMSystemFontOfSize(scr, 12); - AddSection(panel, ICON_FILE); - + return panel; } diff --git a/WPrefs.app/Paths.c b/WPrefs.app/Paths.c index 68dd8fe8..9a57c10b 100644 --- a/WPrefs.app/Paths.c +++ b/WPrefs.app/Paths.c @@ -49,6 +49,7 @@ typedef struct _Panel { WMColor *red; WMColor *black; WMColor *white; + WMColor *gray; WMFont *font; } _Panel; @@ -180,24 +181,20 @@ browseForFile(WMWidget *w, void *data) static void -paintItem(WMList *lPtr, int index, Drawable d, char *text, int state, - WMRect *rect) +paintItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMRect *rect) { int width, height, x, y; _Panel *panel = (_Panel*)WMGetHangedData(lPtr); WMScreen *scr = WMWidgetScreen(lPtr); Display *dpy = WMScreenDisplay(scr); + WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray; width = rect->size.width; height = rect->size.height; x = rect->pos.x; y = rect->pos.y; - if (state & WLDSSelected) - XFillRectangle(dpy, d, WMColorGC(panel->white), x, y, width, - height); - else - XClearArea(dpy, d, x, y, width, height, False); + XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height); if (state & 1) { WMDrawString(scr, d, panel->red, panel->font, x+4, y, text, strlen(text)); @@ -244,6 +241,7 @@ createPanel(Panel *p) panel->white = WMWhiteColor(scr); panel->black = WMBlackColor(scr); + panel->gray = WMGrayColor(scr); panel->red = WMCreateRGBColor(scr, 0xffff, 0, 0, True); panel->font = WMSystemFontOfSize(scr, 12); diff --git a/WPrefs.app/TexturePanel.c b/WPrefs.app/TexturePanel.c index 0279e6ab..588d3535 100644 --- a/WPrefs.app/TexturePanel.c +++ b/WPrefs.app/TexturePanel.c @@ -465,11 +465,12 @@ paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state, { TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr); WMScreen *scr = WMWidgetScreen(lPtr); + WMColor *white = WMWhiteColor(scr); + WMColor *black = WMBlackColor(scr); + WMColor *gray = WMGrayColor(scr); + WMListItem *item; int width, height, x, y; Display *dpy; - WMColor *white = WMWhiteColor(scr); - WMListItem *item; - WMColor *black = WMBlackColor(scr); dpy = WMScreenDisplay(scr); @@ -481,7 +482,7 @@ paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state, if (state & WLDSSelected) XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height); else - XClearArea(dpy, d, x, y, width, height, False); + XFillRectangle(dpy, d, WMColorGC(gray), x, y, width, height); item = WMGetListItem(lPtr, index); @@ -494,6 +495,7 @@ paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMReleaseColor(white); WMReleaseColor(black); + WMReleaseColor(gray); } diff --git a/src/dialog.c b/src/dialog.c index eb0f3dce..ad4fc4ec 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -438,76 +438,67 @@ listIconPaths(WMList *lPtr) void -drawIconProc(WMList *lPtr, int index, Drawable d, char *text, - int state, WMRect *rect) +drawIconProc(WMList *lPtr, int index, Drawable d, char *text, int state, + WMRect *rect) { IconPanel *panel = WMGetHangedData(lPtr); GC gc = panel->scr->draw_gc; GC copygc = panel->scr->copy_gc; char *file, *dirfile; WMPixmap *pixmap; - WMColor *blackcolor; - WMColor *whitecolor; + WMColor *black, *white, *gray, *back; WMSize size; WMScreen *wmscr = WMWidgetScreen(panel->win); RColor color; - int width; + int x, y, width, height, len; if(!panel->preview) return; + x = rect->pos.x; + y = rect->pos.y; width = rect->size.width; + height = rect->size.height; - blackcolor = WMBlackColor(wmscr); - whitecolor = WMWhiteColor(wmscr); + black = WMBlackColor(wmscr); + white = WMWhiteColor(wmscr); + gray = WMGrayColor(wmscr); + back = (state & WLDSSelected) ? white : gray; dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text); - { - int len = strlen(dirfile)+strlen(text)+4; - file = wmalloc(len); - snprintf(file, len, "%s/%s", dirfile, text); - } + len = strlen(dirfile)+strlen(text)+4; + file = wmalloc(len); + snprintf(file, len, "%s/%s", dirfile, text); wfree(dirfile); - if ((state & WLDSSelected) != 0) { - color.red = color.green = color.blue = 0xff; - color.alpha = 0; - } else { - color.red = color.blue = 0xae; - color.green = 0xaa; color.alpha = 0; - } + color.red = WMRedComponentOfColor(back) >> 8; + color.green = WMGreenComponentOfColor(back) >> 8; + color.blue = WMBlueComponentOfColor(back) >> 8; + color.alpha = WMGetColorAlpha(back) >> 8; + pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color); wfree(file); if (!pixmap) { - WMRemoveListItem(lPtr, index); + /*WMRemoveListItem(lPtr, index);*/ + WMReleaseColor(black); + WMReleaseColor(white); + WMReleaseColor(gray); return; } - XClearArea(dpy, d, rect->pos.x, rect->pos.y, width, rect->size.height, - False); + XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height); + XSetClipMask(dpy, gc, None); - /* - XDrawRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5, - rect->pos.y +5, width - 10, 54); - */ - XDrawLine(dpy, d, WMColorGC(whitecolor), rect->pos.x, - rect->pos.y+rect->size.height-1, rect->pos.x+width, - rect->pos.y+rect->size.height-1); - - - if (state&WLDSSelected) { - XFillRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x, - rect->pos.y, width, rect->size.height); - } + /*XDrawRectangle(dpy, d, WMColorGC(white), x+5, y+5, width-10, 54);*/ + XDrawLine(dpy, d, WMColorGC(white), x, y+height-1, x+width, y+height-1); size = WMGetPixmapSize(pixmap); XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap)); - XSetClipOrigin(dpy, copygc, rect->pos.x + (width-size.width)/2, - rect->pos.y+2); + XSetClipOrigin(dpy, copygc, x + (width-size.width)/2, y+2); XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0, size.width>100?100:size.width, size.height>64?64:size.height, - rect->pos.x + (width-size.width)/2, rect->pos.y+2); + x + (width-size.width)/2, y+2); { int i,j; @@ -516,15 +507,15 @@ drawIconProc(WMList *lPtr, int index, Drawable d, char *text, int twidth = WMWidthOfString(panel->normalfont, text, tlen); int ofx, ofy; - ofx = rect->pos.x + (width - twidth)/2; - ofy = rect->pos.y + 64 - fheight; + ofx = x + (width - twidth)/2; + ofy = y + 64 - fheight; for(i=-1;i<2;i++) for(j=-1;j<2;j++) - WMDrawString(wmscr, d, whitecolor, panel->normalfont, + WMDrawString(wmscr, d, white, panel->normalfont, ofx+i, ofy+j, text, tlen); - WMDrawString(wmscr, d, blackcolor, panel->normalfont, ofx, ofy, + WMDrawString(wmscr, d, black, panel->normalfont, ofx, ofy, text, tlen); } @@ -532,8 +523,9 @@ drawIconProc(WMList *lPtr, int index, Drawable d, char *text, /* I hope it is better to do not use cache / on my box it is fast nuff */ XFlush(dpy); - WMReleaseColor(blackcolor); - WMReleaseColor(whitecolor); + WMReleaseColor(black); + WMReleaseColor(white); + WMReleaseColor(gray); } diff --git a/src/xinerama.c b/src/xinerama.c index d0858c1d..92d5330d 100644 --- a/src/xinerama.c +++ b/src/xinerama.c @@ -97,12 +97,12 @@ static int intersectArea(int x1, int y1, int w1, int h1, rect1.x1 = x1; rect1.y1 = y1; rect1.x2 = x1+w1; - rect1.x2 = y1+w1; + rect1.y2 = y1+h1; rect2.x1 = x2; rect2.y1 = y2; rect2.x2 = x2+w2; - rect2.x2 = y2+w2; + rect2.y2 = y2+h2; if (intersect_rectangles(&rect1, &rect2, &result)) return (result.x2-result.x1)*(result.y2-result.y1); @@ -195,7 +195,8 @@ int wGetHeadForPointerLocation(WScreen *scr) } /* get the dimensions of the head */ -WMRect wGetRectForHead(WScreen *scr, int head) +WMRect +wGetRectForHead(WScreen *scr, int head) { WMRect rect; @@ -204,38 +205,35 @@ WMRect wGetRectForHead(WScreen *scr, int head) rect.pos.y = scr->xine_screens[head].y_org; rect.size.width = scr->xine_screens[head].width; rect.size.height = scr->xine_screens[head].height; - - return rect; } else { - rect.pos.x = 0; rect.pos.y = 0; rect.size.width = scr->scr_width; rect.size.height = scr->scr_height; - - return rect; } + + return rect; } -WMRect wGetUsableRectForHead(WScreen *scr, int head) +WMRect +wGetUsableRectForHead(WScreen *scr, int head) { + WMRect rect; + if (head < scr->xine_count) { rect.pos.x = scr->xine_screens[head].x_org; rect.pos.y = scr->xine_screens[head].y_org; rect.size.width = scr->xine_screens[head].width; rect.size.height = scr->xine_screens[head].height; - - return rect; } else { - rect.pos.x = 0; rect.pos.y = 0; rect.size.width = scr->scr_width; rect.size.height = scr->scr_height; - - return rect; } + + return rect; } #endif