From 38d160cb8cd30c3a5f16178f3675f365e33d6204 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 15 Nov 2014 19:40:40 +0100 Subject: [PATCH] =?utf8?q?wmaker:=20minor=20fixes=20for=20the=20size=20of?= =?utf8?q?=20an=20aper=C3=A7u?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There was a probable bug when reading settings, because the function used was 'getInt' which would try to store the result in a 'char'. As it would be probably easier for user to have the value directly in pixels, the storage is now done in an int so there won't be problem anymore. Changed the behaviour of the constant APERCU_BORDER, which would be assumed to be the size of the border in pixel, but in previous code it was actually the sum of the two border (1 on each side). All maths have been changed to have it as a single border width. Took opportunity to group variable assignation for titleHeight and shortenTitle in a single place, because it is not convenient to have them spread around (one value in the beginning and others later in the code) and using default values prevents some checks that modern compiler can do to help produce safer code. Signed-off-by: Christophe CURIS Signed-off-by: Carlos R. Mafra --- src/WindowMaker.h | 2 +- src/balloon.c | 29 +++++++++++++++++------------ src/defaults.c | 18 +++++++++++++++++- src/icon.c | 4 ++-- src/icon.h | 3 ++- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/WindowMaker.h b/src/WindowMaker.h index 17462f8f..0663b546 100644 --- a/src/WindowMaker.h +++ b/src/WindowMaker.h @@ -444,7 +444,7 @@ extern struct WPreferences { char cycle_ignore_minimized; /* Ignore minimized windows when cycling */ char strict_windoze_cycle; /* don't close switch panel when shift is released */ char panel_only_open; /* Only open the switch panel; don't switch */ - char apercu_size; /* Size of apercu preview as a multiple of icon size */ + int apercu_size; /* Size of apercu preview in pixels */ /* All delays here are in ms. 0 means instant auto-action. */ int clip_auto_raise_delay; /* Delay after which the clip will be raised when entered */ diff --git a/src/balloon.c b/src/balloon.c index de003aad..c989803e 100644 --- a/src/balloon.c +++ b/src/balloon.c @@ -376,26 +376,33 @@ static void showText(WScreen *scr, int x, int y, int h, int w, const char *text) } #endif /* !SHAPED_BALLOON */ -static void showApercu(WScreen *scr, int x, int y, int height, int width, char *title, Pixmap apercu) +static void showApercu(WScreen *scr, int x, int y, const char *title, Pixmap apercu) { Pixmap pixmap; WMFont *font = scr->info_text_font; - int titleHeight = 0; - char *shortenTitle = title; + int width, height; + int titleHeight; + char *shortenTitle; if (scr->balloon->contents) XFreePixmap(dpy, scr->balloon->contents); + width = wPreferences.apercu_size; + height = wPreferences.apercu_size; + if (wPreferences.miniwin_title_balloon) { - shortenTitle = ShrinkString(font, title, width - APERCU_BORDER); + shortenTitle = ShrinkString(font, title, width - APERCU_BORDER * 2); titleHeight = countLines(shortenTitle) * WMFontHeight(font) + 4; height += titleHeight; + } else { + shortenTitle = NULL; + titleHeight = 0; } if (x < 0) x = 0; else if (x + width > scr->scr_width - 1) - x = scr->scr_width - width - APERCU_BORDER; + x = scr->scr_width - width - 1; if (y - height - 2 < 0) { y += wPreferences.icon_size; @@ -413,16 +420,16 @@ static void showApercu(WScreen *scr, int x, int y, int height, int width, char * pixmap = XCreatePixmap(dpy, scr->root_win, width, height, scr->w_depth); XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width, height); - if (shortenTitle && wPreferences.miniwin_title_balloon) { + if (shortenTitle != NULL) { drawMultiLineString(scr->wmscreen, pixmap, scr->window_title_color[0], font, APERCU_BORDER, APERCU_BORDER, shortenTitle, strlen(shortenTitle)); wfree(shortenTitle); } XCopyArea(dpy, apercu, pixmap, scr->draw_gc, - 0, 0, (wPreferences.icon_size - 1 - APERCU_BORDER) * wPreferences.apercu_size, - (wPreferences.icon_size - 1 - APERCU_BORDER) * wPreferences.apercu_size, - APERCU_BORDER, APERCU_BORDER + titleHeight); + 0, 0, (wPreferences.apercu_size - 1 - APERCU_BORDER * 2), + (wPreferences.apercu_size - 1 - APERCU_BORDER * 2), + APERCU_BORDER, APERCU_BORDER + titleHeight); #ifdef SHAPED_BALLOON XShapeCombineMask(dpy, scr->balloon->window, ShapeBounding, 0, 0, None, ShapeSet); @@ -457,9 +464,7 @@ static void showBalloon(WScreen *scr) if (wPreferences.miniwin_apercu_balloon && scr->balloon->apercu != None) /* used to display either the apercu alone or the apercu and the title */ - showApercu(scr, x, y, (wPreferences.icon_size - 1) * wPreferences.apercu_size, - (wPreferences.icon_size - 1) * wPreferences.apercu_size, - scr->balloon->text, scr->balloon->apercu); + showApercu(scr, x, y, scr->balloon->text, scr->balloon->apercu); else showText(scr, x, y, scr->balloon->h, w, scr->balloon->text); } diff --git a/src/defaults.c b/src/defaults.c index cf344246..e1237d56 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -502,7 +502,7 @@ WDefaultEntry optionList[] = { &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL}, {"SwitchPanelOnlyOpen", "NO", NULL, &wPreferences.panel_only_open, getBool, NULL, NULL, NULL}, - {"ApercuSize", "2", NULL, + {"ApercuSize", "128", NULL, &wPreferences.apercu_size, getInt, NULL, NULL, NULL}, /* style options */ @@ -1181,6 +1181,22 @@ void wReadDefaults(WScreen * scr, WMPropList * new_dict) } } + /* + * Backward Compatibility: + * the option 'apercu_size' used to be coded as a multiple of the icon size in v0.95.6 + * it is now expressed directly in pixels, but to avoid breaking user's setting we check + * for old coding and convert it now. + * This code should probably stay for at least 2 years, you should not consider removing + * it before year 2017 + */ + if (wPreferences.apercu_size < 24) { + /* 24 is the minimum icon size proposed in WPref's settings */ + wPreferences.apercu_size *= wPreferences.icon_size; + if (wPreferences.miniwin_apercu_balloon) + wwarning(_("your ApercuSize setting is using old syntax, it is converted to %d pixels; consider running WPrefs.app to update your settings"), + wPreferences.apercu_size); + } + if (needs_refresh != 0 && !scr->flags.startup) { int foo; diff --git a/src/icon.c b/src/icon.c index d8265b52..75f5293e 100644 --- a/src/icon.c +++ b/src/icon.c @@ -593,8 +593,8 @@ void set_icon_apercu(WIcon *icon, RImage *image) RImage *scaled_apercu; WScreen *scr = icon->core->screen_ptr; - scaled_apercu = RSmoothScaleImage(image, (wPreferences.icon_size - 1 - APERCU_BORDER) * wPreferences.apercu_size, - (wPreferences.icon_size - 1 - APERCU_BORDER) * wPreferences.apercu_size); + scaled_apercu = RSmoothScaleImage(image, wPreferences.apercu_size - 2 * APERCU_BORDER, + wPreferences.apercu_size - 2 * APERCU_BORDER); if (RConvertImage(scr->rcontext, scaled_apercu, &tmp)) { if (icon->apercu != None) diff --git a/src/icon.h b/src/icon.h index af82f5c2..80e9acf9 100644 --- a/src/icon.h +++ b/src/icon.h @@ -29,7 +29,8 @@ #define TILE_CLIP 1 #define TILE_DRAWER 2 -#define APERCU_BORDER 2 +/* This is the border, in pixel, drawn around an Aperçu */ +#define APERCU_BORDER 1 typedef struct WIcon { WCoreWindow *core; -- 2.11.4.GIT