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 <WINGs/WINGsP.h>
39 #include "WindowMaker.h"
47 #include "workspace.h"
52 extern WPreferences wPreferences
;
54 typedef struct _WBalloon
{
80 #define TLEFT (TOP|LEFT)
81 #define TRIGHT (TOP|RIGHT)
82 #define BLEFT (BOTTOM|LEFT)
83 #define BRIGHT (BOTTOM|RIGHT)
92 drawBalloon(Pixmap pix
, GC gc
, int x
, int y
, int w
, int h
, int side
)
97 XFillArc(dpy
, pix
, gc
, x
, y
, rad
, rad
, 90*64, 90*64);
98 XFillArc(dpy
, pix
, gc
, x
, y
+h
-1-rad
, rad
, rad
, 180*64, 90*64);
100 XFillArc(dpy
, pix
, gc
, x
+w
-1-rad
, y
, rad
, rad
, 0*64, 90*64);
101 XFillArc(dpy
, pix
, gc
, x
+w
-1-rad
, y
+h
-1-rad
, rad
, rad
, 270*64, 90*64);
103 XFillRectangle(dpy
, pix
, gc
, x
, y
+rad
/2, w
, h
-rad
);
104 XFillRectangle(dpy
, pix
, gc
, x
+rad
/2, y
, w
-rad
, h
);
108 pt
[1].y
= y
+h
-1+SPACE
;
116 pt
[0].x
= x
+w
-h
+2*h
/16;
117 pt
[1].x
= x
+w
-h
+11*h
/16;
118 pt
[2].x
= x
+w
-h
+7*h
/16;
120 pt
[0].x
= x
+h
-2*h
/16;
121 pt
[1].x
= x
+h
-11*h
/16;
122 pt
[2].x
= x
+h
-7*h
/16;
124 XFillPolygon(dpy
, pix
, gc
, pt
, 3, Convex
, CoordModeOrigin
);
129 makePixmap(WScreen
*scr
, int width
, int height
, int side
, Pixmap
*mask
)
131 WBalloon
*bal
= scr
->balloon
;
136 bitmap
= XCreatePixmap(dpy
, scr
->root_win
, width
+SPACE
, height
+SPACE
, 1);
139 bal
->monoGC
= XCreateGC(dpy
, bitmap
, 0, NULL
);
141 XSetForeground(dpy
, bal
->monoGC
, 0);
142 XFillRectangle(dpy
, bitmap
, bal
->monoGC
, 0, 0, width
+SPACE
, height
+SPACE
);
144 pixmap
= XCreatePixmap(dpy
, scr
->root_win
, width
+SPACE
, height
+SPACE
,
146 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
147 XFillRectangle(dpy
, pixmap
, scr
->draw_gc
, 0, 0, width
+SPACE
, height
+SPACE
);
156 XSetForeground(dpy
, bal
->monoGC
, 1);
157 drawBalloon(bitmap
, bal
->monoGC
, x
, y
, width
, height
, side
);
158 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
159 drawBalloon(pixmap
, scr
->draw_gc
, x
+1, y
+1, width
-2, height
-2, side
);
168 showText(WScreen
*scr
, int x
, int y
, int h
, int w
, char *text
)
174 WMFont
*font
= scr
->info_text_font
;
179 if (scr
->balloon
->contents
)
180 XFreePixmap(dpy
, scr
->balloon
->contents
);
182 width
= WMWidthOfString(font
, text
, strlen(text
))+16;
183 height
= WMFontHeight(font
) + 4;
191 if (x
+ width
> scr
->scr_width
) {
193 bx
= x
- width
+ w
/2;
200 if (bx
+ width
> scr
->scr_width
)
201 bx
= scr
->scr_width
- width
;
203 if (y
- (height
+ SPACE
) < 0) {
209 by
= y
- (height
+ SPACE
);
212 pixmap
= makePixmap(scr
, width
, height
, side
, &mask
);
214 WMDrawString(scr
->wmscreen
, pixmap
, scr
->black
, font
, 8,
215 ty
+ (height
- WMFontHeight(font
))/2,
218 XSetWindowBackgroundPixmap(dpy
, scr
->balloon
->window
, pixmap
);
219 scr
->balloon
->contents
= pixmap
;
221 XResizeWindow(dpy
, scr
->balloon
->window
, width
, height
+SPACE
);
222 XShapeCombineMask(dpy
, scr
->balloon
->window
, ShapeBounding
, 0, 0, mask
,
224 XFreePixmap(dpy
, mask
);
225 XMoveWindow(dpy
, scr
->balloon
->window
, bx
, by
);
226 XMapRaised(dpy
, scr
->balloon
->window
);
229 scr
->balloon
->mapped
= 1;
231 #else /* !SHAPED_BALLOON */
233 showText(WScreen
*scr
, int x
, int y
, int h
, int w
, char *text
)
238 WMFont
*font
= scr
->info_text_font
;
240 if (scr
->balloon
->contents
)
241 XFreePixmap(dpy
, scr
->balloon
->contents
);
243 width
= WMWidthOfString(font
, text
, strlen(text
))+8;
244 height
= WMFontHeight(font
) + 4;
248 else if (x
+ width
> scr
->scr_width
-1)
249 x
= scr
->scr_width
- width
;
251 if (y
- height
- 2 < 0) {
259 if (scr
->window_title_texture
[0])
260 XSetForeground(dpy
, scr
->draw_gc
,
261 scr
->window_title_texture
[0]->any
.color
.pixel
);
263 XSetForeground(dpy
, scr
->draw_gc
, scr
->light_pixel
);
265 pixmap
= XCreatePixmap(dpy
, scr
->root_win
, width
, height
, scr
->w_depth
);
266 XFillRectangle(dpy
, pixmap
, scr
->draw_gc
, 0, 0, width
, height
);
268 WMDrawString(scr
->wmscreen
, pixmap
, scr
->window_title_color
[0], font
, 4, 2,
271 XResizeWindow(dpy
, scr
->balloon
->window
, width
, height
);
272 XMoveWindow(dpy
, scr
->balloon
->window
, x
, y
);
274 XSetWindowBackgroundPixmap(dpy
, scr
->balloon
->window
, pixmap
);
275 XClearWindow(dpy
, scr
->balloon
->window
);
276 XMapRaised(dpy
, scr
->balloon
->window
);
278 scr
->balloon
->contents
= pixmap
;
280 scr
->balloon
->mapped
= 1;
282 #endif /* !SHAPED_BALLOON */
286 showBalloon(WScreen
*scr
)
293 scr
->balloon
->timer
= NULL
;
294 scr
->balloon
->ignoreTimer
= 1;
297 if (!XGetGeometry(dpy
, scr
->balloon
->objectWindow
, &foow
, &x
, &y
,
298 &w
, &foo
, &foo
, &foo
)) {
299 scr
->balloon
->prevType
= 0;
302 showText(scr
, x
, y
, scr
->balloon
->h
, w
, scr
->balloon
->text
);
308 frameBalloon(WObjDescriptor
*object
)
310 WFrameWindow
*fwin
= (WFrameWindow
*)object
->parent
;
311 WScreen
*scr
= fwin
->core
->screen_ptr
;
313 if (fwin
->titlebar
!= object
->self
314 || !fwin
->flags
.is_client_window_frame
) {
318 if (fwin
->title
&& fwin
->flags
.incomplete_title
) {
319 scr
->balloon
->h
= (fwin
->titlebar
? fwin
->titlebar
->height
: 0);
320 scr
->balloon
->text
= wstrdup(fwin
->title
);
321 scr
->balloon
->objectWindow
= fwin
->core
->window
;
322 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
,
323 (WMCallback
*)showBalloon
, scr
);
329 miniwindowBalloon(WObjDescriptor
*object
)
331 WIcon
*icon
= (WIcon
*)object
->parent
;
332 WScreen
*scr
= icon
->core
->screen_ptr
;
334 if (!icon
->icon_name
) {
338 scr
->balloon
->h
= icon
->core
->height
;
339 scr
->balloon
->text
= wstrdup(icon
->icon_name
);
340 scr
->balloon
->objectWindow
= icon
->core
->window
;
341 if ((scr
->balloon
->prevType
== object
->parent_type
342 || scr
->balloon
->prevType
== WCLASS_APPICON
)
343 && scr
->balloon
->ignoreTimer
) {
344 XUnmapWindow(dpy
, scr
->balloon
->window
);
347 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
,
348 (WMCallback
*)showBalloon
, scr
);
355 appiconBalloon(WObjDescriptor
*object
)
357 WAppIcon
*aicon
= (WAppIcon
*)object
->parent
;
358 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
361 if (aicon
->command
&& aicon
->wm_class
) {
362 int len
= strlen(aicon
->command
)+strlen(aicon
->wm_class
)+8;
364 snprintf(tmp
, len
, "%s (%s)", aicon
->wm_class
, aicon
->command
);
365 scr
->balloon
->text
= tmp
;
366 } else if (aicon
->command
) {
367 scr
->balloon
->text
= wstrdup(aicon
->command
);
368 } else if (aicon
->wm_class
) {
369 scr
->balloon
->text
= wstrdup(aicon
->wm_class
);
374 scr
->balloon
->h
= aicon
->icon
->core
->height
-2;
376 scr
->balloon
->objectWindow
= aicon
->icon
->core
->window
;
377 if ((scr
->balloon
->prevType
== object
->parent_type
378 || scr
->balloon
->prevType
== WCLASS_MINIWINDOW
)
379 && scr
->balloon
->ignoreTimer
) {
380 XUnmapWindow(dpy
, scr
->balloon
->window
);
383 scr
->balloon
->timer
= WMAddTimerHandler(BALLOON_DELAY
,
384 (WMCallback
*)showBalloon
, scr
);
391 wBalloonInitialize(WScreen
*scr
)
394 XSetWindowAttributes attribs
;
397 bal
= wmalloc(sizeof(WBalloon
));
398 memset(bal
, 0, sizeof(WBalloon
));
402 vmask
= CWSaveUnder
|CWOverrideRedirect
|CWColormap
|CWBackPixel
404 attribs
.save_under
= True
;
405 attribs
.override_redirect
= True
;
406 attribs
.colormap
= scr
->w_colormap
;
407 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
408 attribs
.border_pixel
= 0; /* do not care */
410 bal
->window
= XCreateWindow(dpy
, scr
->root_win
, 1, 1, 10, 10, 1,
411 scr
->w_depth
, CopyFromParent
,
412 scr
->w_visual
, vmask
, &attribs
);
414 /* select EnterNotify to so that the balloon will be unmapped
415 * when the pointer is moved over it */
416 XSelectInput(dpy
, bal
->window
, EnterWindowMask
);
423 wBalloonEnteredObject(WScreen
*scr
, WObjDescriptor
*object
)
425 WBalloon
*balloon
= scr
->balloon
;
427 if (balloon
->timer
) {
428 WMDeleteTimerHandler(balloon
->timer
);
429 balloon
->timer
= NULL
;
430 balloon
->ignoreTimer
= 0;
433 if (scr
->balloon
->text
)
434 wfree(scr
->balloon
->text
);
435 scr
->balloon
->text
= NULL
;
439 balloon
->ignoreTimer
= 0;
442 switch (object
->parent_type
) {
444 if (wPreferences
.window_balloon
) {
445 frameBalloon(object
);
449 case WCLASS_DOCK_ICON
:
450 if (object
->parent
!= scr
->clip_icon
&& wPreferences
.appicon_balloon
)
451 appiconBalloon(object
);
456 case WCLASS_MINIWINDOW
:
457 if (wPreferences
.miniwin_balloon
) {
458 miniwindowBalloon(object
);
462 if (wPreferences
.appicon_balloon
)
463 appiconBalloon(object
);
469 scr
->balloon
->prevType
= object
->parent_type
;
475 wBalloonHide(WScreen
*scr
)
478 if (scr
->balloon
->mapped
) {
479 XUnmapWindow(dpy
, scr
->balloon
->window
);
480 scr
->balloon
->mapped
= 0;
481 } else if (scr
->balloon
->timer
) {
482 WMDeleteTimerHandler(scr
->balloon
->timer
);
483 scr
->balloon
->timer
= NULL
;
485 scr
->balloon
->prevType
= 0;