2 * Window Maker window manager
4 * Copyright (c) 1998-2002 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"
50 extern WPreferences wPreferences
;
52 typedef struct _WBalloon
{
78 #define TLEFT (TOP|LEFT)
79 #define TRIGHT (TOP|RIGHT)
80 #define BLEFT (BOTTOM|LEFT)
81 #define BRIGHT (BOTTOM|RIGHT)
90 drawBalloon(WScreen
*scr
, Pixmap bitmap
, Pixmap pix
, int x
, int y
, int w
,
93 GC bgc
= scr
->balloon
->monoGC
;
100 XSetForeground(dpy
, bgc
, 1);
102 XFillArc(dpy
, bitmap
, bgc
, x
, y
, rad
, rad
, 90*64, 90*64);
103 XFillArc(dpy
, bitmap
, bgc
, x
, y
+h
-1-rad
, rad
, rad
, 180*64, 90*64);
105 XFillArc(dpy
, bitmap
, bgc
, x
+w
-1-rad
, y
, rad
, rad
, 0*64, 90*64);
106 XFillArc(dpy
, bitmap
, bgc
, x
+w
-1-rad
, y
+h
-1-rad
, rad
, rad
, 270*64, 90*64);
108 XFillRectangle(dpy
, bitmap
, bgc
, x
, y
+rad
/2, w
, h
-rad
);
109 XFillRectangle(dpy
, bitmap
, bgc
, x
+rad
/2, y
, w
-rad
, h
);
112 XSetForeground(dpy
, gc
, scr
->white_pixel
);
114 XFillArc(dpy
, pix
, gc
, x
+1, y
+1, rad
, rad
, 90*64, 90*64);
115 XFillArc(dpy
, pix
, gc
, x
+1, y
+h
-2-rad
, rad
, rad
, 180*64, 90*64);
117 XFillArc(dpy
, pix
, gc
, x
+w
-2-rad
, y
+1, rad
, rad
, 0*64, 90*64);
118 XFillArc(dpy
, pix
, gc
, x
+w
-2-rad
, y
+h
-2-rad
, rad
, rad
, 270*64, 90*64);
120 XFillRectangle(dpy
, pix
, gc
, x
+1, y
+1+rad
/2, w
-2, h
-2-rad
);
121 XFillRectangle(dpy
, pix
, gc
, x
+1+rad
/2, y
+1, w
-2-rad
, h
-2);
125 pt
[1].y
= y
+h
-1+SPACE
;
127 ipt
[0].y
= pt
[0].y
-1;
128 ipt
[1].y
= pt
[1].y
-1;
129 ipt
[2].y
= pt
[2].y
-1;
134 ipt
[0].y
= pt
[0].y
+1;
135 ipt
[1].y
= pt
[1].y
+1;
136 ipt
[2].y
= pt
[2].y
+1;
139 /*w1 = WMAX(h, 24);*/
143 pt
[0].x
= x
+w
-w1
+2*w1
/16;
144 pt
[1].x
= x
+w
-w1
+11*w1
/16;
145 pt
[2].x
= x
+w
-w1
+7*w1
/16;
146 ipt
[0].x
= x
+1+w
-w1
+2*(w1
-1)/16;
147 ipt
[1].x
= x
+1+w
-w1
+11*(w1
-1)/16;
148 ipt
[2].x
= x
+1+w
-w1
+7*(w1
-1)/16;
149 /*ipt[0].x = pt[0].x+1;
151 ipt[2].x = pt[2].x;*/
153 pt
[0].x
= x
+w1
-2*w1
/16;
154 pt
[1].x
= x
+w1
-11*w1
/16;
155 pt
[2].x
= x
+w1
-7*w1
/16;
156 ipt
[0].x
= x
-1+w1
-2*(w1
-1)/16;
157 ipt
[1].x
= x
-1+w1
-11*(w1
-1)/16;
158 ipt
[2].x
= x
-1+w1
-7*(w1
-1)/16;
159 /*ipt[0].x = pt[0].x-1;
161 ipt[2].x = pt[2].x;*/
164 XFillPolygon(dpy
, bitmap
, bgc
, pt
, 3, Convex
, CoordModeOrigin
);
165 XFillPolygon(dpy
, pix
, gc
, ipt
, 3, Convex
, CoordModeOrigin
);
168 XSetForeground(dpy
, gc
, scr
->black_pixel
);
170 XDrawLines(dpy
, pix
, gc
, pt
, 3, CoordModeOrigin
);
178 XDrawLines(dpy
, pix
, gc
, pt
, 3, CoordModeOrigin
);
183 makePixmap(WScreen
*scr
, int width
, int height
, int side
, Pixmap
*mask
)
185 WBalloon
*bal
= scr
->balloon
;
190 bitmap
= XCreatePixmap(dpy
, scr
->root_win
, width
+SPACE
, height
+SPACE
, 1);
193 bal
->monoGC
= XCreateGC(dpy
, bitmap
, 0, NULL
);
195 XSetForeground(dpy
, bal
->monoGC
, 0);
196 XFillRectangle(dpy
, bitmap
, bal
->monoGC
, 0, 0, width
+SPACE
, height
+SPACE
);
198 pixmap
= XCreatePixmap(dpy
, scr
->root_win
, width
+SPACE
, height
+SPACE
,
200 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
201 XFillRectangle(dpy
, pixmap
, scr
->draw_gc
, 0, 0, width
+SPACE
, height
+SPACE
);
210 drawBalloon(scr
, bitmap
, pixmap
, x
, y
, width
, height
, side
);
219 showText(WScreen
*scr
, int x
, int y
, int h
, int w
, char *text
)
225 WMFont
*font
= scr
->info_text_font
;
230 if (scr
->balloon
->contents
)
231 XFreePixmap(dpy
, scr
->balloon
->contents
);
233 width
= WMWidthOfString(font
, text
, strlen(text
))+16;
234 height
= WMFontHeight(font
) + 4;
242 if (x
+ width
> scr
->scr_width
) {
244 bx
= x
- width
+ w
/2;
251 if (bx
+ width
> scr
->scr_width
)
252 bx
= scr
->scr_width
- width
;
254 if (y
- (height
+ SPACE
) < 0) {
260 by
= y
- (height
+ SPACE
);
263 pixmap
= makePixmap(scr
, width
, height
, side
, &mask
);
265 WMDrawString(scr
->wmscreen
, pixmap
, scr
->black
, font
, 8,
266 ty
+ (height
- WMFontHeight(font
))/2,
269 XSetWindowBackgroundPixmap(dpy
, scr
->balloon
->window
, pixmap
);
270 scr
->balloon
->contents
= pixmap
;
272 XResizeWindow(dpy
, scr
->balloon
->window
, width
, height
+SPACE
);
273 XShapeCombineMask(dpy
, scr
->balloon
->window
, ShapeBounding
, 0, 0, mask
,
275 XFreePixmap(dpy
, mask
);
276 XMoveWindow(dpy
, scr
->balloon
->window
, bx
, by
);
277 XMapRaised(dpy
, scr
->balloon
->window
);
280 scr
->balloon
->mapped
= 1;
282 #else /* !SHAPED_BALLOON */
284 showText(WScreen
*scr
, int x
, int y
, int h
, int w
, char *text
)
289 WMFont
*font
= scr
->info_text_font
;
291 if (scr
->balloon
->contents
)
292 XFreePixmap(dpy
, scr
->balloon
->contents
);
294 width
= WMWidthOfString(font
, text
, strlen(text
))+8;
295 height
= WMFontHeight(font
) + 4;
299 else if (x
+ width
> scr
->scr_width
-1)
300 x
= scr
->scr_width
- width
;
302 if (y
- height
- 2 < 0) {
310 if (scr
->window_title_texture
[0])
311 XSetForeground(dpy
, scr
->draw_gc
,
312 scr
->window_title_texture
[0]->any
.color
.pixel
);
314 XSetForeground(dpy
, scr
->draw_gc
, scr
->light_pixel
);
316 pixmap
= XCreatePixmap(dpy
, scr
->root_win
, width
, height
, scr
->w_depth
);
317 XFillRectangle(dpy
, pixmap
, scr
->draw_gc
, 0, 0, width
, height
);
319 WMDrawString(scr
->wmscreen
, pixmap
, scr
->window_title_color
[0], font
, 4, 2,
322 XResizeWindow(dpy
, scr
->balloon
->window
, width
, height
);
323 XMoveWindow(dpy
, scr
->balloon
->window
, x
, y
);
325 XSetWindowBackgroundPixmap(dpy
, scr
->balloon
->window
, pixmap
);
326 XClearWindow(dpy
, scr
->balloon
->window
);
327 XMapRaised(dpy
, scr
->balloon
->window
);
329 scr
->balloon
->contents
= pixmap
;
331 scr
->balloon
->mapped
= 1;
333 #endif /* !SHAPED_BALLOON */
337 showBalloon(WScreen
*scr
)
344 scr
->balloon
->timer
= NULL
;
345 scr
->balloon
->ignoreTimer
= 1;
348 if (!XGetGeometry(dpy
, scr
->balloon
->objectWindow
, &foow
, &x
, &y
,
349 &w
, &foo
, &foo
, &foo
)) {
350 scr
->balloon
->prevType
= 0;
353 showText(scr
, x
, y
, scr
->balloon
->h
, w
, scr
->balloon
->text
);
359 frameBalloon(WObjDescriptor
*object
)
361 WFrameWindow
*fwin
= (WFrameWindow
*)object
->parent
;
362 WScreen
*scr
= fwin
->core
->screen_ptr
;
364 if (fwin
->titlebar
!= object
->self
365 || !fwin
->flags
.is_client_window_frame
) {
369 if (fwin
->title
&& fwin
->flags
.incomplete_title
) {
370 scr
->balloon
->h
= (fwin
->titlebar
? fwin
->titlebar
->height
: 0);
371 scr
->balloon
->text
= wstrdup(fwin
->title
);
372 scr
->balloon
->objectWindow
= fwin
->core
->window
;
373 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
,
374 (WMCallback
*)showBalloon
, scr
);
380 miniwindowBalloon(WObjDescriptor
*object
)
382 WIcon
*icon
= (WIcon
*)object
->parent
;
383 WScreen
*scr
= icon
->core
->screen_ptr
;
385 if (!icon
->icon_name
) {
389 scr
->balloon
->h
= icon
->core
->height
;
390 scr
->balloon
->text
= wstrdup(icon
->icon_name
);
391 scr
->balloon
->objectWindow
= icon
->core
->window
;
392 if ((scr
->balloon
->prevType
== object
->parent_type
393 || scr
->balloon
->prevType
== WCLASS_APPICON
)
394 && scr
->balloon
->ignoreTimer
) {
395 XUnmapWindow(dpy
, scr
->balloon
->window
);
398 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
,
399 (WMCallback
*)showBalloon
, scr
);
406 appiconBalloon(WObjDescriptor
*object
)
408 WAppIcon
*aicon
= (WAppIcon
*)object
->parent
;
409 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
412 if (aicon
->command
&& aicon
->wm_class
) {
413 int len
= strlen(aicon
->command
)+strlen(aicon
->wm_class
)+8;
415 snprintf(tmp
, len
, "%s (%s)", aicon
->wm_class
, aicon
->command
);
416 scr
->balloon
->text
= tmp
;
417 } else if (aicon
->command
) {
418 scr
->balloon
->text
= wstrdup(aicon
->command
);
419 } else if (aicon
->wm_class
) {
420 scr
->balloon
->text
= wstrdup(aicon
->wm_class
);
425 scr
->balloon
->h
= aicon
->icon
->core
->height
-2;
427 scr
->balloon
->objectWindow
= aicon
->icon
->core
->window
;
428 if ((scr
->balloon
->prevType
== object
->parent_type
429 || scr
->balloon
->prevType
== WCLASS_MINIWINDOW
)
430 && scr
->balloon
->ignoreTimer
) {
431 XUnmapWindow(dpy
, scr
->balloon
->window
);
434 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
,
435 (WMCallback
*)showBalloon
, scr
);
442 wBalloonInitialize(WScreen
*scr
)
445 XSetWindowAttributes attribs
;
448 bal
= wmalloc(sizeof(WBalloon
));
449 memset(bal
, 0, sizeof(WBalloon
));
453 vmask
= CWSaveUnder
|CWOverrideRedirect
|CWColormap
|CWBackPixel
455 attribs
.save_under
= True
;
456 attribs
.override_redirect
= True
;
457 attribs
.colormap
= scr
->w_colormap
;
458 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
459 attribs
.border_pixel
= 0; /* do not care */
461 bal
->window
= XCreateWindow(dpy
, scr
->root_win
, 1, 1, 10, 10, 1,
462 scr
->w_depth
, CopyFromParent
,
463 scr
->w_visual
, vmask
, &attribs
);
465 /* select EnterNotify to so that the balloon will be unmapped
466 * when the pointer is moved over it */
467 XSelectInput(dpy
, bal
->window
, EnterWindowMask
);
474 wBalloonEnteredObject(WScreen
*scr
, WObjDescriptor
*object
)
476 WBalloon
*balloon
= scr
->balloon
;
478 if (balloon
->timer
) {
479 WMDeleteTimerHandler(balloon
->timer
);
480 balloon
->timer
= NULL
;
481 balloon
->ignoreTimer
= 0;
484 if (scr
->balloon
->text
)
485 wfree(scr
->balloon
->text
);
486 scr
->balloon
->text
= NULL
;
490 balloon
->ignoreTimer
= 0;
493 switch (object
->parent_type
) {
495 if (wPreferences
.window_balloon
) {
496 frameBalloon(object
);
500 case WCLASS_DOCK_ICON
:
501 if (object
->parent
!= scr
->clip_icon
&& wPreferences
.appicon_balloon
)
502 appiconBalloon(object
);
507 case WCLASS_MINIWINDOW
:
508 if (wPreferences
.miniwin_balloon
) {
509 miniwindowBalloon(object
);
513 if (wPreferences
.appicon_balloon
)
514 appiconBalloon(object
);
520 scr
->balloon
->prevType
= object
->parent_type
;
526 wBalloonHide(WScreen
*scr
)
529 if (scr
->balloon
->mapped
) {
530 XUnmapWindow(dpy
, scr
->balloon
->window
);
531 scr
->balloon
->mapped
= 0;
532 } else if (scr
->balloon
->timer
) {
533 WMDeleteTimerHandler(scr
->balloon
->timer
);
534 scr
->balloon
->timer
= NULL
;
536 scr
->balloon
->prevType
= 0;