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
);
374 icon
->file_image
= NULL
;
382 path
= FindImage(wPreferences
.icon_path
, file
);
384 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
385 icon
->file_image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
397 static char *get_name_for_wwin(WWindow
*wwin
)
399 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
402 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
407 if (wm_class
&& wm_instance
) {
408 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
409 suffix
= wmalloc(len
);
410 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
411 } else if (wm_class
) {
412 len
= strlen(wm_class
) + 1;
413 suffix
= wmalloc(len
);
414 snprintf(suffix
, len
, "%s", wm_class
);
415 } else if (wm_instance
) {
416 len
= strlen(wm_instance
) + 1;
417 suffix
= wmalloc(len
);
418 snprintf(suffix
, len
, "%s", wm_instance
);
426 static char *get_icon_cache_path(void)
431 prefix
= wusergnusteppath();
432 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
434 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
436 /* If the folder exists, exit */
437 if (access(path
, F_OK
) == 0)
440 /* Create the folder */
441 ret
= wmkdirhier((const char *) path
);
443 /* Exit 1 on success, 0 on failure */
452 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
454 RImage
*image
= NULL
;
455 XWMHints
*hints
= wwin
->wm_hints
;
457 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
458 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
460 (hints
->flags
& IconMaskHint
)
461 ? hints
->icon_mask
: None
);
468 * Stores the client supplied icon at CACHE_ICON_PATH
469 * and returns the path for that icon. Returns NULL if there is no
470 * client supplied icon or on failure.
473 * New directories might be created.
475 char *wIconStore(WIcon
* icon
)
477 char *path
, *dir_path
, *file
;
479 RImage
*image
= NULL
;
480 WWindow
*wwin
= icon
->owner
;
485 dir_path
= get_icon_cache_path();
489 file
= get_name_for_wwin(wwin
);
495 len
= strlen(dir_path
) + strlen(file
) + 5;
497 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
501 /* If icon exists, exit */
502 if (access(path
, F_OK
) == 0)
505 if (wwin
->net_icon_image
)
506 image
= RRetainImage(wwin
->net_icon_image
);
508 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
515 if (!RSaveImage(image
, path
, "XPM")) {
520 RReleaseImage(image
);
525 static void cycleColor(void *data
)
527 WIcon
*icon
= (WIcon
*) data
;
528 WScreen
*scr
= icon
->core
->screen_ptr
;
532 gcv
.dash_offset
= icon
->step
;
533 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
535 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
536 icon
->core
->width
- 1, icon
->core
->height
- 1);
537 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
541 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
543 if (icon
->highlighted
== flag
)
546 icon
->highlighted
= flag
;
547 icon
->force_paint
= True
;
552 void wIconSelect(WIcon
* icon
)
554 WScreen
*scr
= icon
->core
->screen_ptr
;
555 icon
->selected
= !icon
->selected
;
557 if (icon
->selected
) {
559 if (!wPreferences
.dont_blink
)
560 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
562 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
563 icon
->core
->width
- 1, icon
->core
->height
- 1);
565 if (icon
->handlerID
) {
566 WMDeleteTimerHandler(icon
->handlerID
);
567 icon
->handlerID
= NULL
;
569 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
573 void wIconUpdate(WIcon
* icon
)
575 WScreen
*scr
= icon
->core
->screen_ptr
;
576 WWindow
*wwin
= icon
->owner
;
578 assert(scr
->icon_tile
!= NULL
);
580 if (icon
->pixmap
!= None
)
581 XFreePixmap(dpy
, icon
->pixmap
);
585 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
586 /* Forced use user_icon */
587 get_pixmap_icon_from_user_icon(scr
, icon
);
588 } else if (icon
->icon_win
!= None
) {
589 /* Get the Pixmap from the WIcon */
590 get_pixmap_icon_from_icon_win(icon
);
591 } else if (wwin
&& wwin
->net_icon_image
) {
592 /* Use _NET_WM_ICON icon */
593 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
594 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
595 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
596 /* Get the Pixmap from the wm_hints, else, from the user */
597 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
598 get_pixmap_icon_from_user_icon(scr
, icon
);
600 /* Get the Pixmap from the user */
601 get_pixmap_icon_from_user_icon(scr
, icon
);
604 /* No pixmap, set default background */
605 if (icon
->pixmap
!= None
)
606 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
609 XClearWindow(dpy
, icon
->core
->window
);
613 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
)
615 RImage
*image
= NULL
;
619 if (icon
->file_image
) {
620 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
621 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
623 /* make default icons */
624 if (!scr
->def_icon_pixmap
) {
625 /* Get the default icon */
626 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
628 path
= FindImage(wPreferences
.icon_path
, file
);
630 image
= RLoadImage(scr
->rcontext
, path
, 0);
632 wwarning(_("could not load default icon \"%s\":%s"),
633 file
, RMessageForError(RErrorCode
));
636 wwarning(_("could not find default icon \"%s\""), file
);
640 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
641 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
642 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
644 RReleaseImage(image
);
647 if (icon
->show_title
)
648 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
650 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
656 /* Get the Pixmap from the WIcon of the WWindow */
657 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
659 XWindowAttributes attr
;
660 WScreen
*scr
= icon
->core
->screen_ptr
;
661 int title_height
= WMFontHeight(scr
->icon_title_font
);
662 unsigned int width
, height
, depth
;
667 getSize(icon
->icon_win
, &width
, &height
, &depth
);
669 if (width
> wPreferences
.icon_size
) {
671 width
= wPreferences
.icon_size
;
674 if (height
> wPreferences
.icon_size
) {
676 height
= wPreferences
.icon_size
;
679 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
680 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
681 wPreferences
.icon_size
, scr
->w_depth
);
682 XSetClipMask(dpy
, scr
->copy_gc
, None
);
683 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
684 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
685 drawIconTitle(scr
, pixmap
, title_height
);
686 theight
= title_height
;
690 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
693 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
694 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
695 (wPreferences
.icon_size
- width
) / 2,
696 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
698 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
700 XMapWindow(dpy
, icon
->icon_win
);
701 XAddToSaveSet(dpy
, icon
->icon_win
);
704 icon
->pixmap
= pixmap
;
706 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
707 (attr
.all_event_masks
& ButtonPressMask
))
708 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
709 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
710 None
, wCursor
[WCUR_ARROW
]);
713 /* Get the Pixmap from the XWindow wm_hints */
714 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
718 unsigned int w
, h
, ju
, d
;
720 int title_height
= WMFontHeight(scr
->icon_title_font
);
722 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
723 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
727 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
728 wPreferences
.icon_size
, scr
->w_depth
);
729 XSetClipMask(dpy
, scr
->copy_gc
, None
);
730 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
731 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
733 if (w
> wPreferences
.icon_size
)
734 w
= wPreferences
.icon_size
;
735 x
= (wPreferences
.icon_size
- w
) / 2;
737 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
738 drawIconTitle(scr
, pixmap
, title_height
);
740 if (h
> wPreferences
.icon_size
- title_height
- 2) {
741 h
= wPreferences
.icon_size
- title_height
- 2;
742 y
= title_height
+ 1;
744 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
747 if (w
> wPreferences
.icon_size
)
748 w
= wPreferences
.icon_size
;
749 y
= (wPreferences
.icon_size
- h
) / 2;
752 if (wwin
->wm_hints
->flags
& IconMaskHint
)
753 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
755 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
757 if (d
!= scr
->w_depth
) {
758 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
759 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
760 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
762 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
765 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
767 icon
->pixmap
= pixmap
;
771 void wIconPaint(WIcon
* icon
)
773 WScreen
*scr
= icon
->core
->screen_ptr
;
777 if (icon
->force_paint
) {
778 icon
->force_paint
= 0;
783 XClearWindow(dpy
, icon
->core
->window
);
785 /* draw the icon title */
786 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
790 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
791 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
793 if (w
> icon
->core
->width
- 4)
794 x
= (icon
->core
->width
- 4) - w
;
796 x
= (icon
->core
->width
- w
) / 2;
798 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
799 scr
->icon_title_font
, x
, 1, tmp
, l
);
804 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
805 icon
->core
->width
- 1, icon
->core
->height
- 1);
808 /******************************************************************/
810 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
812 wIconPaint(desc
->parent
);
815 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
817 WIcon
*icon
= desc
->parent
;
819 assert(icon
->owner
!= NULL
);
821 wDeiconifyWindow(icon
->owner
);
824 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
826 WIcon
*icon
= desc
->parent
;
827 WWindow
*wwin
= icon
->owner
;
829 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
830 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
832 int clickButton
= event
->xbutton
.button
;
833 Bool hasMoved
= False
;
835 if (WCHECK_STATE(WSTATE_MODAL
))
838 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
839 miniwindowDblClick(desc
, event
);
843 if (event
->xbutton
.button
== Button1
) {
844 if (event
->xbutton
.state
& MOD_MASK
)
845 wLowerFrame(icon
->core
);
847 wRaiseFrame(icon
->core
);
848 if (event
->xbutton
.state
& ShiftMask
) {
850 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
852 } else if (event
->xbutton
.button
== Button3
) {
853 WObjDescriptor
*desc
;
855 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
857 /* allow drag select of menu */
858 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
859 event
->xbutton
.send_event
= True
;
860 (*desc
->handle_mousedown
) (desc
, event
);
865 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
866 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
867 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
870 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
871 | ButtonMotionMask
| ExposureMask
, &ev
);
880 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
881 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
882 XChangeActivePointerGrab(dpy
, ButtonMotionMask
883 | ButtonReleaseMask
| ButtonPressMask
,
884 wCursor
[WCUR_MOVE
], CurrentTime
);
890 x
= ev
.xmotion
.x_root
- dx
;
891 y
= ev
.xmotion
.y_root
- dy
;
892 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
899 if (ev
.xbutton
.button
!= clickButton
)
902 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
903 wwin
->flags
.icon_moved
= 1;
905 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
909 XUngrabPointer(dpy
, CurrentTime
);
911 if (wPreferences
.auto_arrange_icons
)
912 wArrangeIcons(wwin
->screen_ptr
, True
);
913 if (wPreferences
.single_click
&& !hasMoved
)
914 miniwindowDblClick(desc
, event
);