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"
54 extern Cursor wCursor
[WCUR_LAST
];
56 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
57 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
58 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
60 static WIcon
*wIconCreateCore(WScreen
*scr
, int coord_x
, int coord_y
);
62 void get_pixmap_icon_from_icon_win(WIcon
*icon
);
63 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
);
64 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
);
65 /****** Notification Observers ******/
67 static void appearanceObserver(void *self
, WMNotification
* notif
)
69 WIcon
*icon
= (WIcon
*) self
;
70 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
72 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
73 icon
->force_paint
= 1;
77 /* so that the appicon expose handlers will paint the appicon specific
79 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
82 static void tileObserver(void *self
, WMNotification
* notif
)
84 WIcon
*icon
= (WIcon
*) self
;
86 icon
->force_paint
= 1;
89 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
92 /************************************/
94 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
100 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
103 WIcon
*wIconCreate(WWindow
* wwin
)
105 WScreen
*scr
= wwin
->screen_ptr
;
109 icon
= wIconCreateCore(scr
, wwin
->icon_x
, wwin
->icon_y
);
112 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
113 if (wwin
->client_win
== wwin
->main_window
) {
115 /* do not let miniwindow steal app-icon's icon window */
116 wapp
= wApplicationOf(wwin
->client_win
);
117 if (!wapp
|| wapp
->app_icon
== NULL
)
118 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
120 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
123 #ifdef NO_MINIWINDOW_TITLES
124 icon
->show_title
= 0;
126 icon
->show_title
= 1;
128 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
130 file
= wDefaultGetIconFile(wwin
->wm_instance
, wwin
->wm_class
, False
);
132 icon
->file
= wstrdup(file
);
134 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
136 wwin
->flags
.net_has_icon_title
= 1;
138 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
140 icon
->tile_type
= TILE_NORMAL
;
146 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
147 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
151 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
155 icon
= wIconCreateCore(scr
, 0, 0);
158 icon
->file_image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
159 if (!icon
->file_image
)
160 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
162 icon
->file_image
= wIconValidateIconSize(scr
, icon
->file_image
, wPreferences
.icon_size
);
164 icon
->file
= wstrdup(iconfile
);
167 icon
->tile_type
= tile
;
171 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
172 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
177 static WIcon
*wIconCreateCore(WScreen
*scr
, int coord_x
, int coord_y
)
180 unsigned long vmask
= 0;
181 XSetWindowAttributes attribs
;
183 icon
= wmalloc(sizeof(WIcon
));
184 icon
->core
= wCoreCreateTopLevel(scr
,
187 wPreferences
.icon_size
,
188 wPreferences
.icon_size
,
191 if (wPreferences
.use_saveunders
) {
193 attribs
.save_under
= True
;
196 /* a white border for selecting it */
197 vmask
|= CWBorderPixel
;
198 attribs
.border_pixel
= scr
->white_pixel
;
200 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
202 /* will be overriden if this is a application icon */
203 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
204 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
205 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
206 icon
->core
->descriptor
.parent
= icon
;
208 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
209 icon
->core
->stacking
->above
= NULL
;
210 icon
->core
->stacking
->under
= NULL
;
211 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
212 icon
->core
->stacking
->child_of
= NULL
;
217 void wIconDestroy(WIcon
* icon
)
219 WCoreWindow
*core
= icon
->core
;
220 WScreen
*scr
= core
->screen_ptr
;
222 WMRemoveNotificationObserver(icon
);
225 WMDeleteTimerHandler(icon
->handlerID
);
227 if (icon
->icon_win
) {
231 x
= icon
->owner
->icon_x
;
232 y
= icon
->owner
->icon_y
;
234 XUnmapWindow(dpy
, icon
->icon_win
);
235 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
238 XFree(icon
->icon_name
);
241 XFreePixmap(dpy
, icon
->pixmap
);
246 if (icon
->file_image
!= NULL
)
247 RReleaseImage(icon
->file_image
);
249 wCoreDestroy(icon
->core
);
253 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
255 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
256 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
257 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
258 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
259 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
262 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
270 if (tileType
== TILE_NORMAL
) {
271 tile
= RCloneImage(scr
->icon_tile
);
273 assert(scr
->clip_tile
);
274 tile
= RCloneImage(scr
->clip_tile
);
278 w
= (icon
->width
> wPreferences
.icon_size
)
279 ? wPreferences
.icon_size
: icon
->width
;
280 x
= (wPreferences
.icon_size
- w
) / 2;
281 sx
= (icon
->width
- w
) / 2;
284 theight
= WMFontHeight(scr
->icon_title_font
);
286 h
= (icon
->height
+ theight
> wPreferences
.icon_size
287 ? wPreferences
.icon_size
- theight
: icon
->height
);
288 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
289 sy
= (icon
->height
- h
) / 2;
291 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
297 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
298 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
299 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
300 color
.alpha
= 150; /* about 60% */
301 RClearImage(tile
, &color
);
307 color
.red
= color
.green
= color
.blue
= 0;
309 RLightImage(tile
, &color
);
312 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
313 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
318 drawIconTitle(scr
, pixmap
, theight
);
323 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
327 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
328 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
330 if (icon
->icon_name
!= NULL
)
331 XFree(icon
->icon_name
);
333 icon
->icon_name
= new_title
;
336 icon
->force_paint
= 1;
340 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
, int max_size
)
347 #ifndef DONT_SCALE_ICONS
348 if (max_size
!= 64) {
349 w
= max_size
* icon
->width
/ 64;
350 h
= max_size
* icon
->height
/ 64;
352 tmp
= RScaleImage(icon
, w
, h
);
361 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
363 WScreen
*scr
= icon
->core
->screen_ptr
;
368 if (icon
->file_image
)
369 RReleaseImage(icon
->file_image
);
372 icon
->file_image
= NULL
;
377 path
= FindImage(wPreferences
.icon_path
, file
);
379 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
380 icon
->file_image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
, wPreferences
.icon_size
);
392 static char *get_name_for_wwin(WWindow
*wwin
)
394 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
397 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
402 if (wm_class
&& wm_instance
) {
403 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
404 suffix
= wmalloc(len
);
405 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
406 } else if (wm_class
) {
407 len
= strlen(wm_class
) + 1;
408 suffix
= wmalloc(len
);
409 snprintf(suffix
, len
, "%s", wm_class
);
410 } else if (wm_instance
) {
411 len
= strlen(wm_instance
) + 1;
412 suffix
= wmalloc(len
);
413 snprintf(suffix
, len
, "%s", wm_instance
);
421 static char *get_icon_cache_path(void)
426 prefix
= wusergnusteppath();
427 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
429 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
431 /* If the folder exists, exit */
432 if (access(path
, F_OK
) == 0)
435 /* Create the folder */
436 ret
= wmkdirhier((const char *) path
);
438 /* Exit 1 on success, 0 on failure */
447 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
449 RImage
*image
= NULL
;
450 XWMHints
*hints
= wwin
->wm_hints
;
452 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
453 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
455 (hints
->flags
& IconMaskHint
)
456 ? hints
->icon_mask
: None
);
463 * Stores the client supplied icon at CACHE_ICON_PATH
464 * and returns the path for that icon. Returns NULL if there is no
465 * client supplied icon or on failure.
468 * New directories might be created.
470 char *wIconStore(WIcon
* icon
)
472 char *path
, *dir_path
, *file
;
474 RImage
*image
= NULL
;
475 WWindow
*wwin
= icon
->owner
;
480 dir_path
= get_icon_cache_path();
484 file
= get_name_for_wwin(wwin
);
490 len
= strlen(dir_path
) + strlen(file
) + 5;
492 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
496 /* If icon exists, exit */
497 if (access(path
, F_OK
) == 0)
500 if (wwin
->net_icon_image
)
501 image
= RRetainImage(wwin
->net_icon_image
);
503 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
510 if (!RSaveImage(image
, path
, "XPM")) {
515 RReleaseImage(image
);
520 static void cycleColor(void *data
)
522 WIcon
*icon
= (WIcon
*) data
;
523 WScreen
*scr
= icon
->core
->screen_ptr
;
527 gcv
.dash_offset
= icon
->step
;
528 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
530 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
531 icon
->core
->width
- 1, icon
->core
->height
- 1);
532 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
536 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
538 if (icon
->highlighted
== flag
)
541 icon
->highlighted
= flag
;
542 icon
->force_paint
= True
;
547 void wIconSelect(WIcon
* icon
)
549 WScreen
*scr
= icon
->core
->screen_ptr
;
550 icon
->selected
= !icon
->selected
;
552 if (icon
->selected
) {
554 if (!wPreferences
.dont_blink
)
555 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
557 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
558 icon
->core
->width
- 1, icon
->core
->height
- 1);
560 if (icon
->handlerID
) {
561 WMDeleteTimerHandler(icon
->handlerID
);
562 icon
->handlerID
= NULL
;
564 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
568 void wIconUpdate(WIcon
* icon
)
570 WScreen
*scr
= icon
->core
->screen_ptr
;
571 WWindow
*wwin
= icon
->owner
;
573 assert(scr
->icon_tile
!= NULL
);
575 if (icon
->pixmap
!= None
)
576 XFreePixmap(dpy
, icon
->pixmap
);
580 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
581 /* Forced use user_icon */
582 get_pixmap_icon_from_user_icon(scr
, icon
);
583 } else if (icon
->icon_win
!= None
) {
584 /* Get the Pixmap from the WIcon */
585 get_pixmap_icon_from_icon_win(icon
);
586 } else if (wwin
&& wwin
->net_icon_image
) {
587 /* Use _NET_WM_ICON icon */
588 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
589 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
590 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
591 /* Get the Pixmap from the wm_hints, else, from the user */
592 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
593 get_pixmap_icon_from_user_icon(scr
, icon
);
595 /* Get the Pixmap from the user */
596 get_pixmap_icon_from_user_icon(scr
, icon
);
599 /* No pixmap, set default background */
600 if (icon
->pixmap
!= None
)
601 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
604 XClearWindow(dpy
, icon
->core
->window
);
608 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
)
610 RImage
*image
= NULL
;
614 if (icon
->file_image
) {
615 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
616 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
618 /* make default icons */
619 if (!scr
->def_icon_pixmap
) {
620 file
= wDefaultGetIconFile(NULL
, NULL
, False
);
622 path
= FindImage(wPreferences
.icon_path
, file
);
624 image
= RLoadImage(scr
->rcontext
, path
, 0);
626 wwarning(_("could not load default icon \"%s\":%s"),
627 file
, RMessageForError(RErrorCode
));
630 wwarning(_("could not find default icon \"%s\""), file
);
634 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
635 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
636 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
638 RReleaseImage(image
);
641 if (icon
->show_title
)
642 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
644 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
650 /* Get the Pixmap from the WIcon of the WWindow */
651 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
653 XWindowAttributes attr
;
654 WScreen
*scr
= icon
->core
->screen_ptr
;
655 int title_height
= WMFontHeight(scr
->icon_title_font
);
656 unsigned int width
, height
, depth
;
661 getSize(icon
->icon_win
, &width
, &height
, &depth
);
663 if (width
> wPreferences
.icon_size
) {
665 width
= wPreferences
.icon_size
;
668 if (height
> wPreferences
.icon_size
) {
670 height
= wPreferences
.icon_size
;
673 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
674 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
675 wPreferences
.icon_size
, scr
->w_depth
);
676 XSetClipMask(dpy
, scr
->copy_gc
, None
);
677 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
678 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
679 drawIconTitle(scr
, pixmap
, title_height
);
680 theight
= title_height
;
684 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
687 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
688 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
689 (wPreferences
.icon_size
- width
) / 2,
690 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
692 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
694 XMapWindow(dpy
, icon
->icon_win
);
695 XAddToSaveSet(dpy
, icon
->icon_win
);
698 icon
->pixmap
= pixmap
;
700 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
701 (attr
.all_event_masks
& ButtonPressMask
))
702 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
703 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
704 None
, wCursor
[WCUR_ARROW
]);
707 /* Get the Pixmap from the XWindow wm_hints */
708 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
712 unsigned int w
, h
, ju
, d
;
714 int title_height
= WMFontHeight(scr
->icon_title_font
);
716 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
717 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
721 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
722 wPreferences
.icon_size
, scr
->w_depth
);
723 XSetClipMask(dpy
, scr
->copy_gc
, None
);
724 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
725 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
727 if (w
> wPreferences
.icon_size
)
728 w
= wPreferences
.icon_size
;
729 x
= (wPreferences
.icon_size
- w
) / 2;
731 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
732 drawIconTitle(scr
, pixmap
, title_height
);
734 if (h
> wPreferences
.icon_size
- title_height
- 2) {
735 h
= wPreferences
.icon_size
- title_height
- 2;
736 y
= title_height
+ 1;
738 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
741 if (w
> wPreferences
.icon_size
)
742 w
= wPreferences
.icon_size
;
743 y
= (wPreferences
.icon_size
- h
) / 2;
746 if (wwin
->wm_hints
->flags
& IconMaskHint
)
747 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
749 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
751 if (d
!= scr
->w_depth
) {
752 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
753 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
754 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
756 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
759 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
761 icon
->pixmap
= pixmap
;
765 void wIconPaint(WIcon
* icon
)
767 WScreen
*scr
= icon
->core
->screen_ptr
;
771 if (icon
->force_paint
) {
772 icon
->force_paint
= 0;
777 XClearWindow(dpy
, icon
->core
->window
);
779 /* draw the icon title */
780 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
784 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
785 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
787 if (w
> icon
->core
->width
- 4)
788 x
= (icon
->core
->width
- 4) - w
;
790 x
= (icon
->core
->width
- w
) / 2;
792 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
793 scr
->icon_title_font
, x
, 1, tmp
, l
);
798 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
799 icon
->core
->width
- 1, icon
->core
->height
- 1);
802 /******************************************************************/
804 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
806 wIconPaint(desc
->parent
);
809 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
811 WIcon
*icon
= desc
->parent
;
813 assert(icon
->owner
!= NULL
);
815 wDeiconifyWindow(icon
->owner
);
818 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
820 WIcon
*icon
= desc
->parent
;
821 WWindow
*wwin
= icon
->owner
;
823 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
824 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
826 int clickButton
= event
->xbutton
.button
;
827 Bool hasMoved
= False
;
829 if (WCHECK_STATE(WSTATE_MODAL
))
832 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
833 miniwindowDblClick(desc
, event
);
837 if (event
->xbutton
.button
== Button1
) {
838 if (event
->xbutton
.state
& MOD_MASK
)
839 wLowerFrame(icon
->core
);
841 wRaiseFrame(icon
->core
);
842 if (event
->xbutton
.state
& ShiftMask
) {
844 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
846 } else if (event
->xbutton
.button
== Button3
) {
847 WObjDescriptor
*desc
;
849 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
851 /* allow drag select of menu */
852 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
853 event
->xbutton
.send_event
= True
;
854 (*desc
->handle_mousedown
) (desc
, event
);
859 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
860 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
861 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
864 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
865 | ButtonMotionMask
| ExposureMask
, &ev
);
874 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
875 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
876 XChangeActivePointerGrab(dpy
, ButtonMotionMask
877 | ButtonReleaseMask
| ButtonPressMask
,
878 wCursor
[WCUR_MOVE
], CurrentTime
);
884 x
= ev
.xmotion
.x_root
- dx
;
885 y
= ev
.xmotion
.y_root
- dy
;
886 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
893 if (ev
.xbutton
.button
!= clickButton
)
896 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
897 wwin
->flags
.icon_moved
= 1;
899 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
903 XUngrabPointer(dpy
, CurrentTime
);
905 if (wPreferences
.auto_arrange_icons
)
906 wArrangeIcons(wwin
->screen_ptr
, True
);
907 if (wPreferences
.single_click
&& !hasMoved
)
908 miniwindowDblClick(desc
, event
);