1 /* icon.c - window icon and dock and appicon parent
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <X11/Xutil.h>
35 #include "WindowMaker.h"
43 #include "application.h"
48 /**** Global varianebles ****/
49 extern WPreferences wPreferences
;
51 #define MOD_MASK wPreferences.modifier_mask
53 extern Cursor wCursor
[WCUR_LAST
];
55 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
56 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
57 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
59 /****** Notification Observers ******/
61 static void appearanceObserver(void *self
, WMNotification
* notif
)
63 WIcon
*icon
= (WIcon
*) self
;
64 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
66 if (flags
& WTextureSettings
) {
67 icon
->force_paint
= 1;
69 if (flags
& WFontSettings
) {
70 icon
->force_paint
= 1;
73 if (flags & WColorSettings) {
79 /* so that the appicon expose handlers will paint the appicon specific
81 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
84 static void tileObserver(void *self
, WMNotification
* notif
)
86 WIcon
*icon
= (WIcon
*) self
;
88 icon
->force_paint
= 1;
91 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
94 /************************************/
96 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
102 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
105 WIcon
*wIconCreate(WWindow
* wwin
)
107 WScreen
*scr
= wwin
->screen_ptr
;
110 unsigned long vmask
= 0;
111 XSetWindowAttributes attribs
;
113 icon
= wmalloc(sizeof(WIcon
));
114 memset(icon
, 0, sizeof(WIcon
));
115 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
116 wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
118 if (wPreferences
.use_saveunders
) {
119 vmask
|= CWSaveUnder
;
120 attribs
.save_under
= True
;
122 /* a white border for selecting it */
123 vmask
|= CWBorderPixel
;
124 attribs
.border_pixel
= scr
->white_pixel
;
126 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
128 /* will be overriden if this is an application icon */
129 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
130 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
131 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
132 icon
->core
->descriptor
.parent
= icon
;
134 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
135 icon
->core
->stacking
->above
= NULL
;
136 icon
->core
->stacking
->under
= NULL
;
137 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
138 icon
->core
->stacking
->child_of
= NULL
;
141 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
142 if (wwin
->client_win
== wwin
->main_window
) {
144 /* do not let miniwindow steal app-icon's icon window */
145 wapp
= wApplicationOf(wwin
->client_win
);
146 if (!wapp
|| wapp
->app_icon
== NULL
)
147 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
149 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
152 #ifdef NO_MINIWINDOW_TITLES
153 icon
->show_title
= 0;
155 icon
->show_title
= 1;
157 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
159 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
161 icon
->file
= wstrdup(file
);
164 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
166 wwin
->flags
.net_has_icon_title
= 1;
168 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
170 icon
->tile_type
= TILE_NORMAL
;
176 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
177 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
181 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
184 unsigned long vmask
= 0;
185 XSetWindowAttributes attribs
;
187 icon
= wmalloc(sizeof(WIcon
));
188 memset(icon
, 0, sizeof(WIcon
));
189 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
190 if (wPreferences
.use_saveunders
) {
192 attribs
.save_under
= True
;
194 /* a white border for selecting it */
195 vmask
|= CWBorderPixel
;
196 attribs
.border_pixel
= scr
->white_pixel
;
198 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
200 /* will be overriden if this is a application icon */
201 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
202 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
203 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
204 icon
->core
->descriptor
.parent
= icon
;
206 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
207 icon
->core
->stacking
->above
= NULL
;
208 icon
->core
->stacking
->under
= NULL
;
209 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
210 icon
->core
->stacking
->child_of
= NULL
;
213 icon
->file_image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
214 if (!icon
->file_image
) {
215 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
218 icon
->file_image
= wIconValidateIconSize(scr
, icon
->file_image
, wPreferences
.icon_size
);
220 icon
->file
= wstrdup(iconfile
);
223 icon
->tile_type
= tile
;
227 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
228 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
233 void wIconDestroy(WIcon
* icon
)
235 WCoreWindow
*core
= icon
->core
;
236 WScreen
*scr
= core
->screen_ptr
;
238 WMRemoveNotificationObserver(icon
);
241 WMDeleteTimerHandler(icon
->handlerID
);
243 if (icon
->icon_win
) {
247 x
= icon
->owner
->icon_x
;
248 y
= icon
->owner
->icon_y
;
250 XUnmapWindow(dpy
, icon
->icon_win
);
251 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
254 XFree(icon
->icon_name
);
257 XFreePixmap(dpy
, icon
->pixmap
);
262 if (icon
->file_image
!= NULL
)
263 RReleaseImage(icon
->file_image
);
265 wCoreDestroy(icon
->core
);
269 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
271 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
272 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
273 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
274 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
275 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
278 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
284 int theight
= WMFontHeight(scr
->icon_title_font
);
286 if (tileType
== TILE_NORMAL
)
287 tile
= RCloneImage(scr
->icon_tile
);
289 assert(scr
->clip_tile
);
290 tile
= RCloneImage(scr
->clip_tile
);
293 w
= (icon
->width
> wPreferences
.icon_size
)
294 ? wPreferences
.icon_size
: icon
->width
;
295 x
= (wPreferences
.icon_size
- w
) / 2;
296 sx
= (icon
->width
- w
) / 2;
299 h
= (icon
->height
> wPreferences
.icon_size
)
300 ? wPreferences
.icon_size
: icon
->height
;
301 y
= (wPreferences
.icon_size
- h
) / 2;
302 sy
= (icon
->height
- h
) / 2;
304 h
= (icon
->height
+ theight
> wPreferences
.icon_size
305 ? wPreferences
.icon_size
- theight
: icon
->height
);
306 y
= theight
+ ((int)wPreferences
.icon_size
- theight
- h
) / 2;
307 sy
= (icon
->height
- h
) / 2;
309 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
315 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
316 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
317 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
318 color
.alpha
= 150; /* about 60% */
319 RClearImage(tile
, &color
);
324 color
.red
= color
.green
= color
.blue
= 0;
326 RLightImage(tile
, &color
);
329 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
330 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
335 drawIconTitle(scr
, pixmap
, theight
);
340 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
344 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
345 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
347 if (icon
->icon_name
!= NULL
)
348 XFree(icon
->icon_name
);
350 icon
->icon_name
= new_title
;
353 icon
->force_paint
= 1;
357 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
, int max_size
)
364 #ifndef DONT_SCALE_ICONS
365 if (max_size
!= 64) {
366 w
= max_size
* icon
->width
/ 64;
367 h
= max_size
* icon
->height
/ 64;
369 tmp
= RScaleImage(icon
, w
, h
);
378 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
380 WScreen
*scr
= icon
->core
->screen_ptr
;
385 if (icon
->file_image
)
386 RReleaseImage(icon
->file_image
);
389 icon
->file_image
= NULL
;
394 path
= FindImage(wPreferences
.icon_path
, file
);
396 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
397 icon
->file_image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
, wPreferences
.icon_size
);
409 static char *getnameforicon(WWindow
* wwin
)
411 char *prefix
, *suffix
;
415 if (wwin
->wm_class
&& wwin
->wm_instance
) {
416 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
417 suffix
= wmalloc(len
);
418 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
419 } else if (wwin
->wm_class
) {
420 int len
= strlen(wwin
->wm_class
) + 1;
421 suffix
= wmalloc(len
);
422 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
423 } else if (wwin
->wm_instance
) {
424 int len
= strlen(wwin
->wm_instance
) + 1;
425 suffix
= wmalloc(len
);
426 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
431 prefix
= wusergnusteppath();
432 len
= strlen(prefix
) + 64 + strlen(suffix
);
433 path
= wmalloc(len
+ 1);
434 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
436 if (access(path
, F_OK
) != 0) {
437 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
438 werror(_("could not create directory %s"), path
);
444 strcat(path
, "/CachedPixmaps");
445 if (access(path
, F_OK
) != 0) {
446 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
447 werror(_("could not create directory %s"), path
);
455 strcat(path
, suffix
);
456 strcat(path
, ".xpm");
464 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
465 * and returns the path for that icon. Returns NULL if there is no
466 * client supplied icon or on failure.
469 * New directories might be created.
471 char *wIconStore(WIcon
* icon
)
474 RImage
*image
= NULL
;
475 WWindow
*wwin
= icon
->owner
;
477 if (!wwin
) return NULL
;
479 path
= getnameforicon(wwin
);
483 if (wwin
->net_icon_image
) {
484 image
= RRetainImage(wwin
->net_icon_image
);
485 } else if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)
486 && wwin
->wm_hints
->icon_pixmap
!= None
) {
487 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
488 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
489 ? wwin
->wm_hints
->icon_mask
: None
);
496 if (!RSaveImage(image
, path
, "XPM")) {
500 RReleaseImage(image
);
505 static void cycleColor(void *data
)
507 WIcon
*icon
= (WIcon
*) data
;
508 WScreen
*scr
= icon
->core
->screen_ptr
;
512 gcv
.dash_offset
= icon
->step
;
513 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
515 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
516 icon
->core
->width
- 1, icon
->core
->height
- 1);
517 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
521 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
523 if (icon
->highlighted
== flag
)
526 icon
->highlighted
= flag
;
527 icon
->force_paint
= True
;
532 void wIconSelect(WIcon
* icon
)
534 WScreen
*scr
= icon
->core
->screen_ptr
;
535 icon
->selected
= !icon
->selected
;
537 if (icon
->selected
) {
539 if (!wPreferences
.dont_blink
)
540 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
542 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
543 icon
->core
->width
- 1, icon
->core
->height
- 1);
545 if (icon
->handlerID
) {
546 WMDeleteTimerHandler(icon
->handlerID
);
547 icon
->handlerID
= NULL
;
549 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
553 void wIconUpdate(WIcon
* icon
)
555 WScreen
*scr
= icon
->core
->screen_ptr
;
556 int title_height
= WMFontHeight(scr
->icon_title_font
);
557 WWindow
*wwin
= icon
->owner
;
559 assert(scr
->icon_tile
!= NULL
);
561 if (icon
->pixmap
!= None
)
562 XFreePixmap(dpy
, icon
->pixmap
);
565 if (wwin
&& WFLAGP(wwin
, always_user_icon
))
568 if (icon
->icon_win
!= None
) {
569 /* use client specified icon window */
570 XWindowAttributes attr
;
572 unsigned int width
, height
, depth
;
576 getSize(icon
->icon_win
, &width
, &height
, &depth
);
578 if (width
> wPreferences
.icon_size
) {
580 width
= wPreferences
.icon_size
;
582 if (height
> wPreferences
.icon_size
) {
584 height
= wPreferences
.icon_size
;
586 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
587 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
588 wPreferences
.icon_size
, scr
->w_depth
);
589 XSetClipMask(dpy
, scr
->copy_gc
, None
);
590 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
591 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
592 drawIconTitle(scr
, pixmap
, title_height
);
593 theight
= title_height
;
597 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
600 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
601 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
602 (wPreferences
.icon_size
- width
) / 2,
603 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
605 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
607 XMapWindow(dpy
, icon
->icon_win
);
609 XAddToSaveSet(dpy
, icon
->icon_win
);
611 icon
->pixmap
= pixmap
;
613 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
614 if (attr
.all_event_masks
& ButtonPressMask
) {
615 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
616 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
617 None
, wCursor
[WCUR_ARROW
]);
620 } else if (wwin
&& wwin
->net_icon_image
) {
621 /* Use _NET_WM_ICON icon */
622 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
623 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
624 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
632 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
633 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
637 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
638 wPreferences
.icon_size
, scr
->w_depth
);
639 XSetClipMask(dpy
, scr
->copy_gc
, None
);
640 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
641 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
643 if (w
> wPreferences
.icon_size
)
644 w
= wPreferences
.icon_size
;
645 x
= (wPreferences
.icon_size
- w
) / 2;
647 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
648 drawIconTitle(scr
, pixmap
, title_height
);
650 if (h
> wPreferences
.icon_size
- title_height
- 2) {
651 h
= wPreferences
.icon_size
- title_height
- 2;
652 y
= title_height
+ 1;
654 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
657 if (w
> wPreferences
.icon_size
)
658 w
= wPreferences
.icon_size
;
659 y
= (wPreferences
.icon_size
- h
) / 2;
662 if (wwin
->wm_hints
->flags
& IconMaskHint
)
663 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
665 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
667 if (d
!= scr
->w_depth
) {
668 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
669 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
670 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
672 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
675 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
677 icon
->pixmap
= pixmap
;
681 if (icon
->file_image
) {
682 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
683 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
685 /* make default icons */
687 if (!scr
->def_icon_pixmap
) {
688 RImage
*image
= NULL
;
692 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
694 path
= FindImage(wPreferences
.icon_path
, file
);
696 wwarning(_("could not find default icon \"%s\""), file
);
700 image
= RLoadImage(scr
->rcontext
, path
, 0);
702 wwarning(_("could not load default icon \"%s\":%s"),
703 file
, RMessageForError(RErrorCode
));
709 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
710 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
711 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
713 RReleaseImage(image
);
716 if (icon
->show_title
) {
717 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
719 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
724 if (icon
->pixmap
!= None
) {
725 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
727 XClearWindow(dpy
, icon
->core
->window
);
732 void wIconPaint(WIcon
* icon
)
734 WScreen
*scr
= icon
->core
->screen_ptr
;
738 if (icon
->force_paint
) {
739 icon
->force_paint
= 0;
744 XClearWindow(dpy
, icon
->core
->window
);
746 /* draw the icon title */
747 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
751 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
752 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
754 if (w
> icon
->core
->width
- 4)
755 x
= (icon
->core
->width
- 4) - w
;
757 x
= (icon
->core
->width
- w
) / 2;
759 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
760 scr
->icon_title_font
, x
, 1, tmp
, l
);
765 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
766 icon
->core
->width
- 1, icon
->core
->height
- 1);
769 /******************************************************************/
771 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
773 wIconPaint(desc
->parent
);
776 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
778 WIcon
*icon
= desc
->parent
;
780 assert(icon
->owner
!= NULL
);
782 wDeiconifyWindow(icon
->owner
);
785 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
787 WIcon
*icon
= desc
->parent
;
788 WWindow
*wwin
= icon
->owner
;
790 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
791 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
793 int clickButton
= event
->xbutton
.button
;
794 Bool hasMoved
= False
;
796 if (WCHECK_STATE(WSTATE_MODAL
))
799 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
800 miniwindowDblClick(desc
, event
);
804 if (event
->xbutton
.button
== Button1
) {
805 if (event
->xbutton
.state
& MOD_MASK
)
806 wLowerFrame(icon
->core
);
808 wRaiseFrame(icon
->core
);
809 if (event
->xbutton
.state
& ShiftMask
) {
811 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
813 } else if (event
->xbutton
.button
== Button3
) {
814 WObjDescriptor
*desc
;
816 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
818 /* allow drag select of menu */
819 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
820 event
->xbutton
.send_event
= True
;
821 (*desc
->handle_mousedown
) (desc
, event
);
826 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
827 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
828 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
831 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
832 | ButtonMotionMask
| ExposureMask
, &ev
);
841 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
842 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
843 XChangeActivePointerGrab(dpy
, ButtonMotionMask
844 | ButtonReleaseMask
| ButtonPressMask
,
845 wCursor
[WCUR_MOVE
], CurrentTime
);
851 x
= ev
.xmotion
.x_root
- dx
;
852 y
= ev
.xmotion
.y_root
- dy
;
853 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
860 if (ev
.xbutton
.button
!= clickButton
)
863 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
864 wwin
->flags
.icon_moved
= 1;
866 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
870 XUngrabPointer(dpy
, CurrentTime
);
872 if (wPreferences
.auto_arrange_icons
)
873 wArrangeIcons(wwin
->screen_ptr
, True
);
874 if (wPreferences
.single_click
&& !hasMoved
)
875 miniwindowDblClick(desc
, event
);