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
52 #define CACHE_ICON_PATH "/Library/WindowMaker/CachedPixmaps"
55 extern Cursor wCursor
[WCUR_LAST
];
57 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
58 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
59 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
61 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
);
63 void get_pixmap_icon_from_icon_win(WIcon
*icon
);
64 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
);
65 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
);
66 /****** Notification Observers ******/
68 static void appearanceObserver(void *self
, WMNotification
* notif
)
70 WIcon
*icon
= (WIcon
*) self
;
71 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
73 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
74 icon
->force_paint
= 1;
78 /* so that the appicon expose handlers will paint the appicon specific
80 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
83 static void tileObserver(void *self
, WMNotification
* notif
)
85 WIcon
*icon
= (WIcon
*) self
;
87 icon
->force_paint
= 1;
90 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
93 /************************************/
95 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
101 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
104 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
106 WScreen
*scr
= wwin
->screen_ptr
;
110 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
113 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
114 if (wwin
->client_win
== wwin
->main_window
) {
116 /* do not let miniwindow steal app-icon's icon window */
117 wapp
= wApplicationOf(wwin
->client_win
);
118 if (!wapp
|| wapp
->app_icon
== NULL
)
119 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
121 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
124 #ifdef NO_MINIWINDOW_TITLES
125 icon
->show_title
= 0;
127 icon
->show_title
= 1;
130 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
132 wwin
->flags
.net_has_icon_title
= 1;
134 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
136 /* Get the application icon, default included */
137 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
139 icon
->file
= wstrdup(file
);
140 icon
->file_image
= get_default_icon_rimage(scr
, icon
->file
, wPreferences
.icon_size
);
144 icon
->tile_type
= TILE_NORMAL
;
148 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
149 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
154 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
159 icon
= icon_create_core(scr
, 0, 0);
161 /* Search the icon using instance and class, without default icon */
162 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
164 icon
->file
= wstrdup(file
);
165 icon
->file_image
= get_default_icon_rimage(scr
, icon
->file
, wPreferences
.icon_size
);
169 icon
->tile_type
= tile
;
173 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
174 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
179 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
182 unsigned long vmask
= 0;
183 XSetWindowAttributes attribs
;
185 icon
= wmalloc(sizeof(WIcon
));
186 icon
->core
= wCoreCreateTopLevel(scr
,
189 wPreferences
.icon_size
,
190 wPreferences
.icon_size
,
191 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
193 if (wPreferences
.use_saveunders
) {
195 attribs
.save_under
= True
;
198 /* a white border for selecting it */
199 vmask
|= CWBorderPixel
;
200 attribs
.border_pixel
= scr
->white_pixel
;
202 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
204 /* will be overriden if this is a application icon */
205 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
206 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
207 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
208 icon
->core
->descriptor
.parent
= icon
;
210 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
211 icon
->core
->stacking
->above
= NULL
;
212 icon
->core
->stacking
->under
= NULL
;
213 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
214 icon
->core
->stacking
->child_of
= NULL
;
218 icon
->file_image
= NULL
;
223 void wIconDestroy(WIcon
* icon
)
225 WCoreWindow
*core
= icon
->core
;
226 WScreen
*scr
= core
->screen_ptr
;
228 WMRemoveNotificationObserver(icon
);
231 WMDeleteTimerHandler(icon
->handlerID
);
233 if (icon
->icon_win
) {
237 x
= icon
->owner
->icon_x
;
238 y
= icon
->owner
->icon_y
;
240 XUnmapWindow(dpy
, icon
->icon_win
);
241 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
244 XFree(icon
->icon_name
);
247 XFreePixmap(dpy
, icon
->pixmap
);
252 if (icon
->file_image
!= NULL
)
253 RReleaseImage(icon
->file_image
);
255 wCoreDestroy(icon
->core
);
259 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
261 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
262 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
263 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
264 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
265 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
268 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
276 if (tileType
== TILE_NORMAL
) {
277 tile
= RCloneImage(scr
->icon_tile
);
279 assert(scr
->clip_tile
);
280 tile
= RCloneImage(scr
->clip_tile
);
284 w
= (icon
->width
> wPreferences
.icon_size
)
285 ? wPreferences
.icon_size
: icon
->width
;
286 x
= (wPreferences
.icon_size
- w
) / 2;
287 sx
= (icon
->width
- w
) / 2;
290 theight
= WMFontHeight(scr
->icon_title_font
);
292 h
= (icon
->height
+ theight
> wPreferences
.icon_size
293 ? wPreferences
.icon_size
- theight
: icon
->height
);
294 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
295 sy
= (icon
->height
- h
) / 2;
297 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
303 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
304 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
305 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
306 color
.alpha
= 150; /* about 60% */
307 RClearImage(tile
, &color
);
313 color
.red
= color
.green
= color
.blue
= 0;
315 RLightImage(tile
, &color
);
318 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
319 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
324 drawIconTitle(scr
, pixmap
, theight
);
329 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
333 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
334 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
336 if (icon
->icon_name
!= NULL
)
337 XFree(icon
->icon_name
);
339 icon
->icon_name
= new_title
;
342 icon
->force_paint
= 1;
346 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
353 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
354 if ((icon
->width
- max_size
) > -ICON_BORDER
||
355 (icon
->height
- max_size
) > -ICON_BORDER
) {
356 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
357 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
365 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
367 WScreen
*scr
= icon
->core
->screen_ptr
;
372 if (icon
->file_image
)
373 RReleaseImage(icon
->file_image
);
376 icon
->file_image
= NULL
;
381 path
= FindImage(wPreferences
.icon_path
, file
);
383 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
384 icon
->file_image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
396 static char *get_name_for_wwin(WWindow
*wwin
)
398 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
401 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
406 if (wm_class
&& wm_instance
) {
407 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
408 suffix
= wmalloc(len
);
409 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
410 } else if (wm_class
) {
411 len
= strlen(wm_class
) + 1;
412 suffix
= wmalloc(len
);
413 snprintf(suffix
, len
, "%s", wm_class
);
414 } else if (wm_instance
) {
415 len
= strlen(wm_instance
) + 1;
416 suffix
= wmalloc(len
);
417 snprintf(suffix
, len
, "%s", wm_instance
);
425 static char *get_icon_cache_path(void)
430 prefix
= wusergnusteppath();
431 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
433 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
435 /* If the folder exists, exit */
436 if (access(path
, F_OK
) == 0)
439 /* Create the folder */
440 ret
= wmkdirhier((const char *) path
);
442 /* Exit 1 on success, 0 on failure */
451 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
453 RImage
*image
= NULL
;
454 XWMHints
*hints
= wwin
->wm_hints
;
456 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
457 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
459 (hints
->flags
& IconMaskHint
)
460 ? hints
->icon_mask
: None
);
467 * Stores the client supplied icon at CACHE_ICON_PATH
468 * and returns the path for that icon. Returns NULL if there is no
469 * client supplied icon or on failure.
472 * New directories might be created.
474 char *wIconStore(WIcon
* icon
)
476 char *path
, *dir_path
, *file
;
478 RImage
*image
= NULL
;
479 WWindow
*wwin
= icon
->owner
;
484 dir_path
= get_icon_cache_path();
488 file
= get_name_for_wwin(wwin
);
494 len
= strlen(dir_path
) + strlen(file
) + 5;
496 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
500 /* If icon exists, exit */
501 if (access(path
, F_OK
) == 0)
504 if (wwin
->net_icon_image
)
505 image
= RRetainImage(wwin
->net_icon_image
);
507 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
514 if (!RSaveImage(image
, path
, "XPM")) {
519 RReleaseImage(image
);
524 static void cycleColor(void *data
)
526 WIcon
*icon
= (WIcon
*) data
;
527 WScreen
*scr
= icon
->core
->screen_ptr
;
531 gcv
.dash_offset
= icon
->step
;
532 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
534 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
535 icon
->core
->width
- 1, icon
->core
->height
- 1);
536 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
540 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
542 if (icon
->highlighted
== flag
)
545 icon
->highlighted
= flag
;
546 icon
->force_paint
= True
;
551 void wIconSelect(WIcon
* icon
)
553 WScreen
*scr
= icon
->core
->screen_ptr
;
554 icon
->selected
= !icon
->selected
;
556 if (icon
->selected
) {
558 if (!wPreferences
.dont_blink
)
559 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
561 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
562 icon
->core
->width
- 1, icon
->core
->height
- 1);
564 if (icon
->handlerID
) {
565 WMDeleteTimerHandler(icon
->handlerID
);
566 icon
->handlerID
= NULL
;
568 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
572 void wIconUpdate(WIcon
* icon
)
574 WScreen
*scr
= icon
->core
->screen_ptr
;
575 WWindow
*wwin
= icon
->owner
;
577 assert(scr
->icon_tile
!= NULL
);
579 if (icon
->pixmap
!= None
)
580 XFreePixmap(dpy
, icon
->pixmap
);
584 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
585 /* Forced use user_icon */
586 get_pixmap_icon_from_user_icon(scr
, icon
);
587 } else if (icon
->icon_win
!= None
) {
588 /* Get the Pixmap from the WIcon */
589 get_pixmap_icon_from_icon_win(icon
);
590 } else if (wwin
&& wwin
->net_icon_image
) {
591 /* Use _NET_WM_ICON icon */
592 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
593 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
594 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
595 /* Get the Pixmap from the wm_hints, else, from the user */
596 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
597 get_pixmap_icon_from_user_icon(scr
, icon
);
599 /* Get the Pixmap from the user */
600 get_pixmap_icon_from_user_icon(scr
, icon
);
603 /* No pixmap, set default background */
604 if (icon
->pixmap
!= None
)
605 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
608 XClearWindow(dpy
, icon
->core
->window
);
612 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
)
614 RImage
*image
= NULL
;
618 if (icon
->file_image
) {
619 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
620 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
622 /* make default icons */
623 if (!scr
->def_icon_pixmap
) {
624 /* Get the default icon */
625 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
627 path
= FindImage(wPreferences
.icon_path
, file
);
629 image
= RLoadImage(scr
->rcontext
, path
, 0);
631 wwarning(_("could not load default icon \"%s\":%s"),
632 file
, RMessageForError(RErrorCode
));
635 wwarning(_("could not find default icon \"%s\""), file
);
639 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
640 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
641 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
643 RReleaseImage(image
);
646 if (icon
->show_title
)
647 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
649 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
655 /* Get the Pixmap from the WIcon of the WWindow */
656 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
658 XWindowAttributes attr
;
659 WScreen
*scr
= icon
->core
->screen_ptr
;
660 int title_height
= WMFontHeight(scr
->icon_title_font
);
661 unsigned int width
, height
, depth
;
666 getSize(icon
->icon_win
, &width
, &height
, &depth
);
668 if (width
> wPreferences
.icon_size
) {
670 width
= wPreferences
.icon_size
;
673 if (height
> wPreferences
.icon_size
) {
675 height
= wPreferences
.icon_size
;
678 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
679 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
680 wPreferences
.icon_size
, scr
->w_depth
);
681 XSetClipMask(dpy
, scr
->copy_gc
, None
);
682 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
683 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
684 drawIconTitle(scr
, pixmap
, title_height
);
685 theight
= title_height
;
689 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
692 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
693 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
694 (wPreferences
.icon_size
- width
) / 2,
695 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
697 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
699 XMapWindow(dpy
, icon
->icon_win
);
700 XAddToSaveSet(dpy
, icon
->icon_win
);
703 icon
->pixmap
= pixmap
;
705 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
706 (attr
.all_event_masks
& ButtonPressMask
))
707 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
708 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
709 None
, wCursor
[WCUR_ARROW
]);
712 /* Get the Pixmap from the XWindow wm_hints */
713 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
717 unsigned int w
, h
, ju
, d
;
719 int title_height
= WMFontHeight(scr
->icon_title_font
);
721 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
722 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
726 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
727 wPreferences
.icon_size
, scr
->w_depth
);
728 XSetClipMask(dpy
, scr
->copy_gc
, None
);
729 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
730 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
732 if (w
> wPreferences
.icon_size
)
733 w
= wPreferences
.icon_size
;
734 x
= (wPreferences
.icon_size
- w
) / 2;
736 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
737 drawIconTitle(scr
, pixmap
, title_height
);
739 if (h
> wPreferences
.icon_size
- title_height
- 2) {
740 h
= wPreferences
.icon_size
- title_height
- 2;
741 y
= title_height
+ 1;
743 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
746 if (w
> wPreferences
.icon_size
)
747 w
= wPreferences
.icon_size
;
748 y
= (wPreferences
.icon_size
- h
) / 2;
751 if (wwin
->wm_hints
->flags
& IconMaskHint
)
752 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
754 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
756 if (d
!= scr
->w_depth
) {
757 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
758 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
759 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
761 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
764 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
766 icon
->pixmap
= pixmap
;
770 void wIconPaint(WIcon
* icon
)
772 WScreen
*scr
= icon
->core
->screen_ptr
;
776 if (icon
->force_paint
) {
777 icon
->force_paint
= 0;
782 XClearWindow(dpy
, icon
->core
->window
);
784 /* draw the icon title */
785 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
789 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
790 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
792 if (w
> icon
->core
->width
- 4)
793 x
= (icon
->core
->width
- 4) - w
;
795 x
= (icon
->core
->width
- w
) / 2;
797 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
798 scr
->icon_title_font
, x
, 1, tmp
, l
);
803 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
804 icon
->core
->width
- 1, icon
->core
->height
- 1);
807 /******************************************************************/
809 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
811 wIconPaint(desc
->parent
);
814 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
816 WIcon
*icon
= desc
->parent
;
818 assert(icon
->owner
!= NULL
);
820 wDeiconifyWindow(icon
->owner
);
823 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
825 WIcon
*icon
= desc
->parent
;
826 WWindow
*wwin
= icon
->owner
;
828 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
829 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
831 int clickButton
= event
->xbutton
.button
;
832 Bool hasMoved
= False
;
834 if (WCHECK_STATE(WSTATE_MODAL
))
837 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
838 miniwindowDblClick(desc
, event
);
842 if (event
->xbutton
.button
== Button1
) {
843 if (event
->xbutton
.state
& MOD_MASK
)
844 wLowerFrame(icon
->core
);
846 wRaiseFrame(icon
->core
);
847 if (event
->xbutton
.state
& ShiftMask
) {
849 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
851 } else if (event
->xbutton
.button
== Button3
) {
852 WObjDescriptor
*desc
;
854 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
856 /* allow drag select of menu */
857 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
858 event
->xbutton
.send_event
= True
;
859 (*desc
->handle_mousedown
) (desc
, event
);
864 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
865 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
866 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
869 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
870 | ButtonMotionMask
| ExposureMask
, &ev
);
879 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
880 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
881 XChangeActivePointerGrab(dpy
, ButtonMotionMask
882 | ButtonReleaseMask
| ButtonPressMask
,
883 wCursor
[WCUR_MOVE
], CurrentTime
);
889 x
= ev
.xmotion
.x_root
- dx
;
890 y
= ev
.xmotion
.y_root
- dy
;
891 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
898 if (ev
.xbutton
.button
!= clickButton
)
901 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
902 wwin
->flags
.icon_moved
= 1;
904 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
908 XUngrabPointer(dpy
, CurrentTime
);
910 if (wPreferences
.auto_arrange_icons
)
911 wArrangeIcons(wwin
->screen_ptr
, True
);
912 if (wPreferences
.single_click
&& !hasMoved
)
913 miniwindowDblClick(desc
, event
);