1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 05:48:01 +01:00

wmaker: minor fixes for the size of an aperçu

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 <christophe.curis@free.fr>
Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
Christophe CURIS
2014-11-15 19:40:40 +01:00
committed by Carlos R. Mafra
parent 572af55c9f
commit 38d160cb8c
5 changed files with 39 additions and 17 deletions

View File

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

View File

@@ -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,15 +420,15 @@ 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,
0, 0, (wPreferences.apercu_size - 1 - APERCU_BORDER * 2),
(wPreferences.apercu_size - 1 - APERCU_BORDER * 2),
APERCU_BORDER, APERCU_BORDER + titleHeight);
#ifdef SHAPED_BALLOON
@@ -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);
}

View File

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

View File

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

View File

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