mirror of
https://github.com/gryf/wmaker.git
synced 2026-03-08 02:25:50 +01:00
- Support for multiline balloons (Vitaly Ovtchinnikov <ov@rbcmail.ru>)
This commit is contained in:
@@ -80,6 +80,7 @@ Changes since version 0.80.2:
|
|||||||
- Fixed e memory leak in the code that reads a localized root menu
|
- Fixed e memory leak in the code that reads a localized root menu
|
||||||
- Added support for generating pkgconfig files for WINGS, wmlib and wrlib.
|
- Added support for generating pkgconfig files for WINGS, wmlib and wrlib.
|
||||||
("Marcelo E. Magallon" <mmagallo@debian.org>)
|
("Marcelo E. Magallon" <mmagallo@debian.org>)
|
||||||
|
- Support for multiline balloons (Vitaly Ovtchinnikov <ov@rbcmail.ru>)
|
||||||
|
|
||||||
|
|
||||||
Changes since version 0.80.1:
|
Changes since version 0.80.1:
|
||||||
|
|||||||
150
src/balloon.c
150
src/balloon.c
@@ -81,6 +81,79 @@ typedef struct _WBalloon {
|
|||||||
#define BRIGHT (BOTTOM|RIGHT)
|
#define BRIGHT (BOTTOM|RIGHT)
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
countLines(const char *text)
|
||||||
|
{
|
||||||
|
const char *p = text;
|
||||||
|
int h = 1;
|
||||||
|
|
||||||
|
while (*p) {
|
||||||
|
if (*p == '\n' && p[1] != 0)
|
||||||
|
h++;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
getMaxStringWidth(WMFont *font, char *text)
|
||||||
|
{
|
||||||
|
char *p = text;
|
||||||
|
char *pb = p;
|
||||||
|
int pos = 0;
|
||||||
|
int w = 0, wt;
|
||||||
|
|
||||||
|
while (*p) {
|
||||||
|
if (*p == '\n') {
|
||||||
|
wt = WMWidthOfString(font, pb, pos);
|
||||||
|
if (wt > w)
|
||||||
|
w = wt;
|
||||||
|
pos = 0;
|
||||||
|
pb = p + 1;
|
||||||
|
} else {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
if (pos > 0) {
|
||||||
|
wt = WMWidthOfString(font, pb, pos);
|
||||||
|
if (wt > w)
|
||||||
|
w = wt;
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawMultiLineString(WMScreen *scr, Pixmap pixmap, WMColor *color,
|
||||||
|
WMFont *font, int x, int y, char *text, int len)
|
||||||
|
{
|
||||||
|
char *p = text;
|
||||||
|
char *pb = p;
|
||||||
|
int l = 0, pos = 0;
|
||||||
|
int height = WMFontHeight(font);
|
||||||
|
|
||||||
|
while (*p && p - text < len) {
|
||||||
|
if (*p == '\n') {
|
||||||
|
WMDrawString(scr, pixmap, color, font, x, y + l * height, pb,
|
||||||
|
pos);
|
||||||
|
l++;
|
||||||
|
pos = 0;
|
||||||
|
pb = p + 1;
|
||||||
|
} else {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
if (pos > 0) {
|
||||||
|
WMDrawString(scr, pixmap, color, font, x, y + l * height, pb, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SHAPED_BALLOON
|
#ifdef SHAPED_BALLOON
|
||||||
|
|
||||||
#define SPACE 12
|
#define SPACE 12
|
||||||
@@ -100,10 +173,13 @@ drawBalloon(WScreen *scr, Pixmap bitmap, Pixmap pix, int x, int y, int w,
|
|||||||
XSetForeground(dpy, bgc, 1);
|
XSetForeground(dpy, bgc, 1);
|
||||||
|
|
||||||
XFillArc(dpy, bitmap, bgc, x, y, rad, rad, 90 * 64, 90 * 64);
|
XFillArc(dpy, bitmap, bgc, x, y, rad, rad, 90 * 64, 90 * 64);
|
||||||
XFillArc(dpy, bitmap, bgc, x, y+h-1-rad, rad, rad, 180*64, 90*64);
|
XFillArc(dpy, bitmap, bgc, x, y + h - 1 - rad, rad, rad, 180 * 64,
|
||||||
|
90 * 64);
|
||||||
|
|
||||||
XFillArc(dpy, bitmap, bgc, x+w-1-rad, y, rad, rad, 0*64, 90*64);
|
XFillArc(dpy, bitmap, bgc, x + w - 1 - rad, y, rad, rad, 0 * 64,
|
||||||
XFillArc(dpy, bitmap, bgc, x+w-1-rad, y+h-1-rad, rad, rad, 270*64, 90*64);
|
90 * 64);
|
||||||
|
XFillArc(dpy, bitmap, bgc, x + w - 1 - rad, y + h - 1 - rad, rad, rad,
|
||||||
|
270 * 64, 90 * 64);
|
||||||
|
|
||||||
XFillRectangle(dpy, bitmap, bgc, x, y + rad / 2, w, h - rad);
|
XFillRectangle(dpy, bitmap, bgc, x, y + rad / 2, w, h - rad);
|
||||||
XFillRectangle(dpy, bitmap, bgc, x + rad / 2, y, w - rad, h);
|
XFillRectangle(dpy, bitmap, bgc, x + rad / 2, y, w - rad, h);
|
||||||
@@ -112,13 +188,18 @@ drawBalloon(WScreen *scr, Pixmap bitmap, Pixmap pix, int x, int y, int w,
|
|||||||
XSetForeground(dpy, gc, scr->white_pixel);
|
XSetForeground(dpy, gc, scr->white_pixel);
|
||||||
|
|
||||||
XFillArc(dpy, pix, gc, x + 1, y + 1, rad, rad, 90 * 64, 90 * 64);
|
XFillArc(dpy, pix, gc, x + 1, y + 1, rad, rad, 90 * 64, 90 * 64);
|
||||||
XFillArc(dpy, pix, gc, x+1, y+h-2-rad, rad, rad, 180*64, 90*64);
|
XFillArc(dpy, pix, gc, x + 1, y + h - 2 - rad, rad, rad, 180 * 64,
|
||||||
|
90 * 64);
|
||||||
|
|
||||||
XFillArc(dpy, pix, gc, x+w-2-rad, y+1, rad, rad, 0*64, 90*64);
|
XFillArc(dpy, pix, gc, x + w - 2 - rad, y + 1, rad, rad, 0 * 64,
|
||||||
XFillArc(dpy, pix, gc, x+w-2-rad, y+h-2-rad, rad, rad, 270*64, 90*64);
|
90 * 64);
|
||||||
|
XFillArc(dpy, pix, gc, x + w - 2 - rad, y + h - 2 - rad, rad, rad,
|
||||||
|
270 * 64, 90 * 64);
|
||||||
|
|
||||||
XFillRectangle(dpy, pix, gc, x+1, y+1+rad/2, w-2, h-2-rad);
|
XFillRectangle(dpy, pix, gc, x + 1, y + 1 + rad / 2, w - 2,
|
||||||
XFillRectangle(dpy, pix, gc, x+1+rad/2, y+1, w-2-rad, h-2);
|
h - 2 - rad);
|
||||||
|
XFillRectangle(dpy, pix, gc, x + 1 + rad / 2, y + 1, w - 2 - rad,
|
||||||
|
h - 2);
|
||||||
|
|
||||||
if (side & BOTTOM) {
|
if (side & BOTTOM) {
|
||||||
pt[0].y = y + h - 1;
|
pt[0].y = y + h - 1;
|
||||||
@@ -187,18 +268,23 @@ makePixmap(WScreen *scr, int width, int height, int side, Pixmap *mask)
|
|||||||
Pixmap pixmap;
|
Pixmap pixmap;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
bitmap = XCreatePixmap(dpy, scr->root_win, width+SPACE, height+SPACE, 1);
|
bitmap =
|
||||||
|
XCreatePixmap(dpy, scr->root_win, width + SPACE, height + SPACE,
|
||||||
|
1);
|
||||||
|
|
||||||
if (!bal->monoGC) {
|
if (!bal->monoGC) {
|
||||||
bal->monoGC = XCreateGC(dpy, bitmap, 0, NULL);
|
bal->monoGC = XCreateGC(dpy, bitmap, 0, NULL);
|
||||||
}
|
}
|
||||||
XSetForeground(dpy, bal->monoGC, 0);
|
XSetForeground(dpy, bal->monoGC, 0);
|
||||||
XFillRectangle(dpy, bitmap, bal->monoGC, 0, 0, width+SPACE, height+SPACE);
|
XFillRectangle(dpy, bitmap, bal->monoGC, 0, 0, width + SPACE,
|
||||||
|
height + SPACE);
|
||||||
|
|
||||||
pixmap = XCreatePixmap(dpy, scr->root_win, width+SPACE, height+SPACE,
|
pixmap =
|
||||||
|
XCreatePixmap(dpy, scr->root_win, width + SPACE, height + SPACE,
|
||||||
scr->w_depth);
|
scr->w_depth);
|
||||||
XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
|
XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
|
||||||
XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width+SPACE, height+SPACE);
|
XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width + SPACE,
|
||||||
|
height + SPACE);
|
||||||
|
|
||||||
if (side & BOTTOM) {
|
if (side & BOTTOM) {
|
||||||
y = 0;
|
y = 0;
|
||||||
@@ -230,8 +316,8 @@ showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
|||||||
if (scr->balloon->contents)
|
if (scr->balloon->contents)
|
||||||
XFreePixmap(dpy, scr->balloon->contents);
|
XFreePixmap(dpy, scr->balloon->contents);
|
||||||
|
|
||||||
width = WMWidthOfString(font, text, strlen(text))+16;
|
width = getMaxStringWidth(font, text) + 16;
|
||||||
height = WMFontHeight(font) + 4;
|
height = countLines(text) * WMFontHeight(font) + 4;
|
||||||
|
|
||||||
if (height < 16)
|
if (height < 16)
|
||||||
height = 16;
|
height = 16;
|
||||||
@@ -262,8 +348,7 @@ showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
|||||||
}
|
}
|
||||||
pixmap = makePixmap(scr, width, height, side, &mask);
|
pixmap = makePixmap(scr, width, height, side, &mask);
|
||||||
|
|
||||||
WMDrawString(scr->wmscreen, pixmap, scr->black, font, 8,
|
drawMultiLineString(scr->wmscreen, pixmap, scr->black, font, 8, ty + 2,
|
||||||
ty + (height - WMFontHeight(font))/2,
|
|
||||||
text, strlen(text));
|
text, strlen(text));
|
||||||
|
|
||||||
XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap);
|
XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap);
|
||||||
@@ -280,6 +365,8 @@ showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
|||||||
scr->balloon->mapped = 1;
|
scr->balloon->mapped = 1;
|
||||||
}
|
}
|
||||||
#else /* !SHAPED_BALLOON */
|
#else /* !SHAPED_BALLOON */
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
||||||
{
|
{
|
||||||
@@ -291,8 +378,9 @@ showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
|||||||
if (scr->balloon->contents)
|
if (scr->balloon->contents)
|
||||||
XFreePixmap(dpy, scr->balloon->contents);
|
XFreePixmap(dpy, scr->balloon->contents);
|
||||||
|
|
||||||
width = WMWidthOfString(font, text, strlen(text))+8;
|
width = getMaxStringWidth(font, text) + 8;
|
||||||
height = WMFontHeight(font) + 4;
|
/*width = WMWidthOfString(font, text, strlen(text))+8;*/
|
||||||
|
height = countLines(text) * WMFontHeight(font) + 4;
|
||||||
|
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
x = 0;
|
x = 0;
|
||||||
@@ -313,11 +401,12 @@ showText(WScreen *scr, int x, int y, int h, int w, char *text)
|
|||||||
else
|
else
|
||||||
XSetForeground(dpy, scr->draw_gc, scr->light_pixel);
|
XSetForeground(dpy, scr->draw_gc, scr->light_pixel);
|
||||||
|
|
||||||
pixmap = XCreatePixmap(dpy, scr->root_win, width, height, scr->w_depth);
|
pixmap =
|
||||||
|
XCreatePixmap(dpy, scr->root_win, width, height, scr->w_depth);
|
||||||
XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width, height);
|
XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width, height);
|
||||||
|
|
||||||
WMDrawString(scr->wmscreen, pixmap, scr->window_title_color[0], font, 4, 2,
|
drawMultiLineString(scr->wmscreen, pixmap, scr->window_title_color[0],
|
||||||
text, strlen(text));
|
font, 4, 2, text, strlen(text));
|
||||||
|
|
||||||
XResizeWindow(dpy, scr->balloon->window, width, height);
|
XResizeWindow(dpy, scr->balloon->window, width, height);
|
||||||
XMoveWindow(dpy, scr->balloon->window, x, y);
|
XMoveWindow(dpy, scr->balloon->window, x, y);
|
||||||
@@ -354,7 +443,6 @@ showBalloon(WScreen *scr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
frameBalloon(WObjDescriptor *object)
|
frameBalloon(WObjDescriptor *object)
|
||||||
{
|
{
|
||||||
@@ -371,7 +459,8 @@ frameBalloon(WObjDescriptor *object)
|
|||||||
scr->balloon->text = wstrdup(fwin->title);
|
scr->balloon->text = wstrdup(fwin->title);
|
||||||
scr->balloon->objectWindow = fwin->core->window;
|
scr->balloon->objectWindow = fwin->core->window;
|
||||||
scr->balloon->timer = WMAddTimerHandler(BALLOON_DELAY,
|
scr->balloon->timer = WMAddTimerHandler(BALLOON_DELAY,
|
||||||
(WMCallback*)showBalloon, scr);
|
(WMCallback *) showBalloon,
|
||||||
|
scr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,12 +485,12 @@ miniwindowBalloon(WObjDescriptor *object)
|
|||||||
showBalloon(scr);
|
showBalloon(scr);
|
||||||
} else {
|
} else {
|
||||||
scr->balloon->timer = WMAddTimerHandler(BALLOON_DELAY,
|
scr->balloon->timer = WMAddTimerHandler(BALLOON_DELAY,
|
||||||
(WMCallback*)showBalloon, scr);
|
(WMCallback *) showBalloon,
|
||||||
|
scr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
appiconBalloon(WObjDescriptor *object)
|
appiconBalloon(WObjDescriptor *object)
|
||||||
{
|
{
|
||||||
@@ -412,7 +501,7 @@ appiconBalloon(WObjDescriptor *object)
|
|||||||
if (aicon->command && aicon->wm_class) {
|
if (aicon->command && aicon->wm_class) {
|
||||||
int len = strlen(aicon->command) + strlen(aicon->wm_class) + 8;
|
int len = strlen(aicon->command) + strlen(aicon->wm_class) + 8;
|
||||||
tmp = wmalloc(len);
|
tmp = wmalloc(len);
|
||||||
snprintf(tmp, len, "%s (%s)", aicon->wm_class, aicon->command);
|
snprintf(tmp, len, "%s\n(%s)", aicon->wm_class, aicon->command);
|
||||||
scr->balloon->text = tmp;
|
scr->balloon->text = tmp;
|
||||||
} else if (aicon->command) {
|
} else if (aicon->command) {
|
||||||
scr->balloon->text = wstrdup(aicon->command);
|
scr->balloon->text = wstrdup(aicon->command);
|
||||||
@@ -432,7 +521,8 @@ appiconBalloon(WObjDescriptor *object)
|
|||||||
showBalloon(scr);
|
showBalloon(scr);
|
||||||
} else {
|
} else {
|
||||||
scr->balloon->timer = WMAddTimerHandler(BALLOON_DELAY,
|
scr->balloon->timer = WMAddTimerHandler(BALLOON_DELAY,
|
||||||
(WMCallback*)showBalloon, scr);
|
(WMCallback *) showBalloon,
|
||||||
|
scr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +559,6 @@ wBalloonInitialize(WScreen *scr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wBalloonEnteredObject(WScreen *scr, WObjDescriptor *object)
|
wBalloonEnteredObject(WScreen *scr, WObjDescriptor *object)
|
||||||
{
|
{
|
||||||
@@ -498,7 +587,8 @@ wBalloonEnteredObject(WScreen *scr, WObjDescriptor *object)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WCLASS_DOCK_ICON:
|
case WCLASS_DOCK_ICON:
|
||||||
if (object->parent != scr->clip_icon && wPreferences.appicon_balloon)
|
if (object->parent != scr->clip_icon
|
||||||
|
&& wPreferences.appicon_balloon)
|
||||||
appiconBalloon(object);
|
appiconBalloon(object);
|
||||||
else
|
else
|
||||||
wBalloonHide(scr);
|
wBalloonHide(scr);
|
||||||
@@ -536,4 +626,6 @@ wBalloonHide(WScreen *scr)
|
|||||||
scr->balloon->prevType = 0;
|
scr->balloon->prevType = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user