2 * Window Maker window manager
4 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
29 #include <X11/extensions/shape.h>
37 #include "WindowMaker.h"
45 #include "workspace.h"
48 extern WPreferences wPreferences
;
50 typedef struct _WBalloon
{
75 #define TLEFT (TOP|LEFT)
76 #define TRIGHT (TOP|RIGHT)
77 #define BLEFT (BOTTOM|LEFT)
78 #define BRIGHT (BOTTOM|RIGHT)
80 static int countLines(const char *text
)
86 if (*p
== '\n' && p
[1] != 0)
93 static int getMaxStringWidth(WMFont
* font
, char *text
)
102 wt
= WMWidthOfString(font
, pb
, pos
);
113 wt
= WMWidthOfString(font
, pb
, pos
);
121 drawMultiLineString(WMScreen
* scr
, Pixmap pixmap
, WMColor
* color
,
122 WMFont
* font
, int x
, int y
, char *text
, int len
)
127 int height
= WMFontHeight(font
);
129 while (*p
&& p
- text
< len
) {
131 WMDrawString(scr
, pixmap
, color
, font
, x
, y
+ l
* height
, pb
, pos
);
141 WMDrawString(scr
, pixmap
, color
, font
, x
, y
+ l
* height
, pb
, pos
);
145 #ifdef SHAPED_BALLOON
149 static void drawBalloon(WScreen
* scr
, Pixmap bitmap
, Pixmap pix
, int x
, int y
, int w
, int h
, int side
)
151 GC bgc
= scr
->balloon
->monoGC
;
152 GC gc
= scr
->draw_gc
;
153 int rad
= h
* 3 / 10;
154 XPoint pt
[3], ipt
[3];
158 XSetForeground(dpy
, bgc
, 1);
160 XFillArc(dpy
, bitmap
, bgc
, x
, y
, rad
, rad
, 90 * 64, 90 * 64);
161 XFillArc(dpy
, bitmap
, bgc
, x
, y
+ h
- 1 - rad
, rad
, rad
, 180 * 64, 90 * 64);
163 XFillArc(dpy
, bitmap
, bgc
, x
+ w
- 1 - rad
, y
, rad
, rad
, 0 * 64, 90 * 64);
164 XFillArc(dpy
, bitmap
, bgc
, x
+ w
- 1 - rad
, y
+ h
- 1 - rad
, rad
, rad
, 270 * 64, 90 * 64);
166 XFillRectangle(dpy
, bitmap
, bgc
, x
, y
+ rad
/ 2, w
, h
- rad
);
167 XFillRectangle(dpy
, bitmap
, bgc
, x
+ rad
/ 2, y
, w
- rad
, h
);
170 XSetForeground(dpy
, gc
, scr
->white_pixel
);
172 XFillArc(dpy
, pix
, gc
, x
+ 1, y
+ 1, rad
, rad
, 90 * 64, 90 * 64);
173 XFillArc(dpy
, pix
, gc
, x
+ 1, y
+ h
- 2 - rad
, rad
, rad
, 180 * 64, 90 * 64);
175 XFillArc(dpy
, pix
, gc
, x
+ w
- 2 - rad
, y
+ 1, rad
, rad
, 0 * 64, 90 * 64);
176 XFillArc(dpy
, pix
, gc
, x
+ w
- 2 - rad
, y
+ h
- 2 - rad
, rad
, rad
, 270 * 64, 90 * 64);
178 XFillRectangle(dpy
, pix
, gc
, x
+ 1, y
+ 1 + rad
/ 2, w
- 2, h
- 2 - rad
);
179 XFillRectangle(dpy
, pix
, gc
, x
+ 1 + rad
/ 2, y
+ 1, w
- 2 - rad
, h
- 2);
183 pt
[1].y
= y
+ h
- 1 + SPACE
;
185 ipt
[0].y
= pt
[0].y
- 1;
186 ipt
[1].y
= pt
[1].y
- 1;
187 ipt
[2].y
= pt
[2].y
- 1;
192 ipt
[0].y
= pt
[0].y
+ 1;
193 ipt
[1].y
= pt
[1].y
+ 1;
194 ipt
[2].y
= pt
[2].y
+ 1;
197 /*w1 = WMAX(h, 24); */
201 pt
[0].x
= x
+ w
- w1
+ 2 * w1
/ 16;
202 pt
[1].x
= x
+ w
- w1
+ 11 * w1
/ 16;
203 pt
[2].x
= x
+ w
- w1
+ 7 * w1
/ 16;
204 ipt
[0].x
= x
+ 1 + w
- w1
+ 2 * (w1
- 1) / 16;
205 ipt
[1].x
= x
+ 1 + w
- w1
+ 11 * (w1
- 1) / 16;
206 ipt
[2].x
= x
+ 1 + w
- w1
+ 7 * (w1
- 1) / 16;
207 /*ipt[0].x = pt[0].x+1;
209 ipt[2].x = pt[2].x; */
211 pt
[0].x
= x
+ w1
- 2 * w1
/ 16;
212 pt
[1].x
= x
+ w1
- 11 * w1
/ 16;
213 pt
[2].x
= x
+ w1
- 7 * w1
/ 16;
214 ipt
[0].x
= x
- 1 + w1
- 2 * (w1
- 1) / 16;
215 ipt
[1].x
= x
- 1 + w1
- 11 * (w1
- 1) / 16;
216 ipt
[2].x
= x
- 1 + w1
- 7 * (w1
- 1) / 16;
217 /*ipt[0].x = pt[0].x-1;
219 ipt[2].x = pt[2].x; */
222 XFillPolygon(dpy
, bitmap
, bgc
, pt
, 3, Convex
, CoordModeOrigin
);
223 XFillPolygon(dpy
, pix
, gc
, ipt
, 3, Convex
, CoordModeOrigin
);
226 XSetForeground(dpy
, gc
, scr
->black_pixel
);
228 XDrawLines(dpy
, pix
, gc
, pt
, 3, CoordModeOrigin
);
236 XDrawLines(dpy
, pix
, gc
, pt
, 3, CoordModeOrigin
);
239 static Pixmap
makePixmap(WScreen
* scr
, int width
, int height
, int side
, Pixmap
* mask
)
241 WBalloon
*bal
= scr
->balloon
;
246 bitmap
= XCreatePixmap(dpy
, scr
->root_win
, width
+ SPACE
, height
+ SPACE
, 1);
249 bal
->monoGC
= XCreateGC(dpy
, bitmap
, 0, NULL
);
251 XSetForeground(dpy
, bal
->monoGC
, 0);
252 XFillRectangle(dpy
, bitmap
, bal
->monoGC
, 0, 0, width
+ SPACE
, height
+ SPACE
);
254 pixmap
= XCreatePixmap(dpy
, scr
->root_win
, width
+ SPACE
, height
+ SPACE
, scr
->w_depth
);
255 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
256 XFillRectangle(dpy
, pixmap
, scr
->draw_gc
, 0, 0, width
+ SPACE
, height
+ SPACE
);
265 drawBalloon(scr
, bitmap
, pixmap
, x
, y
, width
, height
, side
);
272 static void showText(WScreen
* scr
, int x
, int y
, int h
, int w
, char *text
)
278 WMFont
*font
= scr
->info_text_font
;
283 if (scr
->balloon
->contents
)
284 XFreePixmap(dpy
, scr
->balloon
->contents
);
286 width
= getMaxStringWidth(font
, text
) + 16;
287 height
= countLines(text
) * WMFontHeight(font
) + 4;
294 if (x
+ width
> scr
->scr_width
) {
296 bx
= x
- width
+ w
/ 2;
303 if (bx
+ width
> scr
->scr_width
)
304 bx
= scr
->scr_width
- width
;
306 if (y
- (height
+ SPACE
) < 0) {
312 by
= y
- (height
+ SPACE
);
315 pixmap
= makePixmap(scr
, width
, height
, side
, &mask
);
317 drawMultiLineString(scr
->wmscreen
, pixmap
, scr
->black
, font
, 8, ty
+ 2, text
, strlen(text
));
319 XSetWindowBackgroundPixmap(dpy
, scr
->balloon
->window
, pixmap
);
320 scr
->balloon
->contents
= pixmap
;
322 XResizeWindow(dpy
, scr
->balloon
->window
, width
, height
+ SPACE
);
323 XShapeCombineMask(dpy
, scr
->balloon
->window
, ShapeBounding
, 0, 0, mask
, ShapeSet
);
324 XFreePixmap(dpy
, mask
);
325 XMoveWindow(dpy
, scr
->balloon
->window
, bx
, by
);
326 XMapRaised(dpy
, scr
->balloon
->window
);
328 scr
->balloon
->mapped
= 1;
330 #else /* !SHAPED_BALLOON */
332 static void showText(WScreen
* scr
, int x
, int y
, int h
, int w
, char *text
)
337 WMFont
*font
= scr
->info_text_font
;
339 if (scr
->balloon
->contents
)
340 XFreePixmap(dpy
, scr
->balloon
->contents
);
342 width
= getMaxStringWidth(font
, text
) + 8;
343 /*width = WMWidthOfString(font, text, strlen(text))+8; */
344 height
= countLines(text
) * WMFontHeight(font
) + 4;
348 else if (x
+ width
> scr
->scr_width
- 1)
349 x
= scr
->scr_width
- width
;
351 if (y
- height
- 2 < 0) {
359 if (scr
->window_title_texture
[0])
360 XSetForeground(dpy
, scr
->draw_gc
, scr
->window_title_texture
[0]->any
.color
.pixel
);
362 XSetForeground(dpy
, scr
->draw_gc
, scr
->light_pixel
);
364 pixmap
= XCreatePixmap(dpy
, scr
->root_win
, width
, height
, scr
->w_depth
);
365 XFillRectangle(dpy
, pixmap
, scr
->draw_gc
, 0, 0, width
, height
);
367 drawMultiLineString(scr
->wmscreen
, pixmap
, scr
->window_title_color
[0], font
, 4, 2, text
, strlen(text
));
369 XResizeWindow(dpy
, scr
->balloon
->window
, width
, height
);
370 XMoveWindow(dpy
, scr
->balloon
->window
, x
, y
);
372 XSetWindowBackgroundPixmap(dpy
, scr
->balloon
->window
, pixmap
);
373 XClearWindow(dpy
, scr
->balloon
->window
);
374 XMapRaised(dpy
, scr
->balloon
->window
);
376 scr
->balloon
->contents
= pixmap
;
378 scr
->balloon
->mapped
= 1;
380 #endif /* !SHAPED_BALLOON */
382 static void showBalloon(WScreen
* scr
)
389 scr
->balloon
->timer
= NULL
;
390 scr
->balloon
->ignoreTimer
= 1;
393 if (!XGetGeometry(dpy
, scr
->balloon
->objectWindow
, &foow
, &x
, &y
, &w
, &foo
, &foo
, &foo
)) {
394 scr
->balloon
->prevType
= 0;
397 showText(scr
, x
, y
, scr
->balloon
->h
, w
, scr
->balloon
->text
);
400 static void frameBalloon(WObjDescriptor
* object
)
402 WFrameWindow
*fwin
= (WFrameWindow
*) object
->parent
;
403 WScreen
*scr
= fwin
->core
->screen_ptr
;
405 if (fwin
->titlebar
!= object
->self
|| !fwin
->flags
.is_client_window_frame
) {
409 if (fwin
->title
&& fwin
->flags
.incomplete_title
) {
410 scr
->balloon
->h
= (fwin
->titlebar
? fwin
->titlebar
->height
: 0);
411 scr
->balloon
->text
= wstrdup(fwin
->title
);
412 scr
->balloon
->objectWindow
= fwin
->core
->window
;
413 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
, (WMCallback
*) showBalloon
, scr
);
417 static void miniwindowBalloon(WObjDescriptor
* object
)
419 WIcon
*icon
= (WIcon
*) object
->parent
;
420 WScreen
*scr
= icon
->core
->screen_ptr
;
422 if (!icon
->icon_name
) {
426 scr
->balloon
->h
= icon
->core
->height
;
427 scr
->balloon
->text
= wstrdup(icon
->icon_name
);
428 scr
->balloon
->objectWindow
= icon
->core
->window
;
429 if ((scr
->balloon
->prevType
== object
->parent_type
|| scr
->balloon
->prevType
== WCLASS_APPICON
)
430 && scr
->balloon
->ignoreTimer
) {
431 XUnmapWindow(dpy
, scr
->balloon
->window
);
434 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
, (WMCallback
*) showBalloon
, scr
);
438 static void appiconBalloon(WObjDescriptor
* object
)
440 WAppIcon
*aicon
= (WAppIcon
*) object
->parent
;
441 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
444 if (aicon
->command
&& aicon
->wm_class
) {
445 int len
= strlen(aicon
->command
) + strlen(aicon
->wm_class
) + 8;
447 snprintf(tmp
, len
, "%s\n(%s)", aicon
->wm_class
, aicon
->command
);
448 scr
->balloon
->text
= tmp
;
449 } else if (aicon
->command
) {
450 scr
->balloon
->text
= wstrdup(aicon
->command
);
451 } else if (aicon
->wm_class
) {
452 scr
->balloon
->text
= wstrdup(aicon
->wm_class
);
457 scr
->balloon
->h
= aicon
->icon
->core
->height
- 2;
459 scr
->balloon
->objectWindow
= aicon
->icon
->core
->window
;
460 if ((scr
->balloon
->prevType
== object
->parent_type
|| scr
->balloon
->prevType
== WCLASS_MINIWINDOW
)
461 && scr
->balloon
->ignoreTimer
) {
462 XUnmapWindow(dpy
, scr
->balloon
->window
);
465 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
, (WMCallback
*) showBalloon
, scr
);
469 void wBalloonInitialize(WScreen
* scr
)
472 XSetWindowAttributes attribs
;
475 bal
= wmalloc(sizeof(WBalloon
));
476 memset(bal
, 0, sizeof(WBalloon
));
480 vmask
= CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBackPixel
| CWBorderPixel
;
481 attribs
.save_under
= True
;
482 attribs
.override_redirect
= True
;
483 attribs
.colormap
= scr
->w_colormap
;
484 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
485 attribs
.border_pixel
= 0; /* do not care */
487 bal
->window
= XCreateWindow(dpy
, scr
->root_win
, 1, 1, 10, 10, 1,
488 scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
490 /* select EnterNotify to so that the balloon will be unmapped
491 * when the pointer is moved over it */
492 XSelectInput(dpy
, bal
->window
, EnterWindowMask
);
496 void wBalloonEnteredObject(WScreen
* scr
, WObjDescriptor
* object
)
498 WBalloon
*balloon
= scr
->balloon
;
500 if (balloon
->timer
) {
501 WMDeleteTimerHandler(balloon
->timer
);
502 balloon
->timer
= NULL
;
503 balloon
->ignoreTimer
= 0;
506 if (scr
->balloon
->text
)
507 wfree(scr
->balloon
->text
);
508 scr
->balloon
->text
= NULL
;
512 balloon
->ignoreTimer
= 0;
515 switch (object
->parent_type
) {
517 if (wPreferences
.window_balloon
) {
518 frameBalloon(object
);
522 case WCLASS_DOCK_ICON
:
523 if (object
->parent
!= scr
->clip_icon
&& wPreferences
.appicon_balloon
)
524 appiconBalloon(object
);
529 case WCLASS_MINIWINDOW
:
530 if (wPreferences
.miniwin_balloon
) {
531 miniwindowBalloon(object
);
535 if (wPreferences
.appicon_balloon
)
536 appiconBalloon(object
);
542 scr
->balloon
->prevType
= object
->parent_type
;
545 void wBalloonHide(WScreen
* scr
)
548 if (scr
->balloon
->mapped
) {
549 XUnmapWindow(dpy
, scr
->balloon
->window
);
550 scr
->balloon
->mapped
= 0;
551 } else if (scr
->balloon
->timer
) {
552 WMDeleteTimerHandler(scr
->balloon
->timer
);
553 scr
->balloon
->timer
= NULL
;
555 scr
->balloon
->prevType
= 0;