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 static void set_dockapp_in_icon(WIcon
*icon
);
64 static void get_rimage_icon_from_icon_win(WIcon
*icon
);
65 static void get_rimage_icon_from_user_icon(WIcon
*icon
);
66 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
67 static void get_rimage_icon_from_x11(WIcon
*icon
);
69 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
70 static void unset_icon_image(WIcon
*icon
);
72 /****** Notification Observers ******/
74 static void appearanceObserver(void *self
, WMNotification
*notif
)
76 WIcon
*icon
= (WIcon
*) self
;
77 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
79 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
)) {
80 /* If the rimage exists, update the icon, else create it */
82 update_icon_pixmap(icon
);
87 /* so that the appicon expose handlers will paint the appicon specific
89 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
92 static void tileObserver(void *self
, WMNotification
*notif
)
94 WIcon
*icon
= (WIcon
*) self
;
96 wIconUpdate(icon
, NULL
);
98 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
101 /************************************/
103 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
109 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
112 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
114 WScreen
*scr
= wwin
->screen_ptr
;
118 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
121 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
122 if (wwin
->client_win
== wwin
->main_window
) {
124 /* do not let miniwindow steal app-icon's icon window */
125 wapp
= wApplicationOf(wwin
->client_win
);
126 if (!wapp
|| wapp
->app_icon
== NULL
)
127 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
129 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
132 #ifdef NO_MINIWINDOW_TITLES
133 icon
->show_title
= 0;
135 icon
->show_title
= 1;
138 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
140 wwin
->flags
.net_has_icon_title
= 1;
142 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
144 /* Get the application icon, default included */
145 file
= get_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
147 icon
->file
= wstrdup(file
);
148 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
152 icon
->tile_type
= TILE_NORMAL
;
154 wIconUpdate(icon
, NULL
);
156 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
157 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
162 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
167 icon
= icon_create_core(scr
, 0, 0);
169 /* Search the icon using instance and class, without default icon */
170 file
= get_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
172 icon
->file
= wstrdup(file
);
173 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
177 icon
->tile_type
= tile
;
179 wIconUpdate(icon
, NULL
);
181 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
182 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
187 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
190 unsigned long vmask
= 0;
191 XSetWindowAttributes attribs
;
193 icon
= wmalloc(sizeof(WIcon
));
194 icon
->core
= wCoreCreateTopLevel(scr
,
197 wPreferences
.icon_size
,
198 wPreferences
.icon_size
,
199 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
201 if (wPreferences
.use_saveunders
) {
203 attribs
.save_under
= True
;
206 /* a white border for selecting it */
207 vmask
|= CWBorderPixel
;
208 attribs
.border_pixel
= scr
->white_pixel
;
210 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
212 /* will be overriden if this is a application icon */
213 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
214 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
215 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
216 icon
->core
->descriptor
.parent
= icon
;
218 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
219 icon
->core
->stacking
->above
= NULL
;
220 icon
->core
->stacking
->under
= NULL
;
221 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
222 icon
->core
->stacking
->child_of
= NULL
;
226 icon
->file_image
= NULL
;
231 void wIconDestroy(WIcon
* icon
)
233 WCoreWindow
*core
= icon
->core
;
234 WScreen
*scr
= core
->screen_ptr
;
236 WMRemoveNotificationObserver(icon
);
239 WMDeleteTimerHandler(icon
->handlerID
);
241 if (icon
->icon_win
) {
245 x
= icon
->owner
->icon_x
;
246 y
= icon
->owner
->icon_y
;
248 XUnmapWindow(dpy
, icon
->icon_win
);
249 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
252 XFree(icon
->icon_name
);
255 XFreePixmap(dpy
, icon
->pixmap
);
257 unset_icon_image(icon
);
259 wCoreDestroy(icon
->core
);
263 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
265 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
266 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
267 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
268 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
269 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
272 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
279 WScreen
*scr
= icon
->core
->screen_ptr
;
280 int titled
= icon
->show_title
;
282 if (icon
->tile_type
== TILE_NORMAL
) {
283 tile
= RCloneImage(scr
->icon_tile
);
285 assert(scr
->clip_tile
);
286 tile
= RCloneImage(scr
->clip_tile
);
290 w
= (image
->width
> wPreferences
.icon_size
)
291 ? wPreferences
.icon_size
: image
->width
;
292 x
= (wPreferences
.icon_size
- w
) / 2;
293 sx
= (image
->width
- w
) / 2;
296 theight
= WMFontHeight(scr
->icon_title_font
);
298 h
= (image
->height
+ theight
> wPreferences
.icon_size
299 ? wPreferences
.icon_size
- theight
: image
->height
);
300 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
301 sy
= (image
->height
- h
) / 2;
303 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
306 if (icon
->shadowed
) {
309 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
310 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
311 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
312 color
.alpha
= 150; /* about 60% */
313 RClearImage(tile
, &color
);
316 if (icon
->highlighted
) {
319 color
.red
= color
.green
= color
.blue
= 0;
321 RLightImage(tile
, &color
);
324 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
325 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
330 drawIconTitle(scr
, pixmap
, theight
);
332 icon
->pixmap
= pixmap
;
335 void wIconChangeTitle(WIcon
*icon
, char *new_title
)
339 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
) ||
340 (new_title
!= NULL
&& icon
->icon_name
== NULL
);
342 if (icon
->icon_name
!= NULL
)
343 XFree(icon
->icon_name
);
345 icon
->icon_name
= new_title
;
348 wIconUpdate(icon
, NULL
);
353 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
360 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
361 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
362 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
363 if (icon
->width
> icon
->height
)
364 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
365 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
367 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
368 max_size
- ICON_BORDER
);
376 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
378 WScreen
*scr
= icon
->core
->screen_ptr
;
380 RImage
*image
= NULL
;
383 /* If no new image, don't do nothing */
387 /* Find the new image */
388 path
= FindImage(wPreferences
.icon_path
, file
);
390 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
395 if (!error
&& image
) {
396 /* Remove the old one */
397 unset_icon_image(icon
);
399 /* Set the new image */
400 icon
->file
= wstrdup(path
);
401 wIconUpdate(icon
, image
);
412 static char *get_name_for_wwin(WWindow
*wwin
)
414 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
417 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
422 if (wm_class
&& wm_instance
) {
423 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
424 suffix
= wmalloc(len
);
425 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
426 } else if (wm_class
) {
427 len
= strlen(wm_class
) + 1;
428 suffix
= wmalloc(len
);
429 snprintf(suffix
, len
, "%s", wm_class
);
430 } else if (wm_instance
) {
431 len
= strlen(wm_instance
) + 1;
432 suffix
= wmalloc(len
);
433 snprintf(suffix
, len
, "%s", wm_instance
);
441 static char *get_icon_cache_path(void)
446 prefix
= wusergnusteppath();
447 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
449 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
451 /* If the folder exists, exit */
452 if (access(path
, F_OK
) == 0)
455 /* Create the folder */
456 ret
= wmkdirhier((const char *) path
);
458 /* Exit 1 on success, 0 on failure */
467 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
469 RImage
*image
= NULL
;
470 XWMHints
*hints
= wwin
->wm_hints
;
472 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
473 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
475 (hints
->flags
& IconMaskHint
)
476 ? hints
->icon_mask
: None
);
483 * Stores the client supplied icon at CACHE_ICON_PATH
484 * and returns the path for that icon. Returns NULL if there is no
485 * client supplied icon or on failure.
488 * New directories might be created.
490 char *wIconStore(WIcon
* icon
)
492 char *path
, *dir_path
, *file
;
494 RImage
*image
= NULL
;
495 WWindow
*wwin
= icon
->owner
;
500 dir_path
= get_icon_cache_path();
504 file
= get_name_for_wwin(wwin
);
510 len
= strlen(dir_path
) + strlen(file
) + 5;
512 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
516 /* If icon exists, exit */
517 if (access(path
, F_OK
) == 0)
520 if (wwin
->net_icon_image
)
521 image
= RRetainImage(wwin
->net_icon_image
);
523 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
530 if (!RSaveImage(image
, path
, "XPM")) {
535 RReleaseImage(image
);
540 static void cycleColor(void *data
)
542 WIcon
*icon
= (WIcon
*) data
;
543 WScreen
*scr
= icon
->core
->screen_ptr
;
547 gcv
.dash_offset
= icon
->step
;
548 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
550 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
551 icon
->core
->width
- 1, icon
->core
->height
- 1);
552 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
555 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
557 if (icon
->highlighted
== flag
)
560 icon
->highlighted
= flag
;
561 update_icon_pixmap(icon
);
564 void wIconSelect(WIcon
* icon
)
566 WScreen
*scr
= icon
->core
->screen_ptr
;
567 icon
->selected
= !icon
->selected
;
569 if (icon
->selected
) {
571 if (!wPreferences
.dont_blink
)
572 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
574 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
575 icon
->core
->width
- 1, icon
->core
->height
- 1);
577 if (icon
->handlerID
) {
578 WMDeleteTimerHandler(icon
->handlerID
);
579 icon
->handlerID
= NULL
;
581 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
585 static void unset_icon_image(WIcon
*icon
)
592 if (icon
->file_image
) {
593 RReleaseImage(icon
->file_image
);
594 icon
->file_image
= NULL
;
598 void wIconUpdate(WIcon
*icon
, RImage
*image
)
600 WWindow
*wwin
= NULL
;
603 icon
->file_image
= image
;
605 if (icon
&& icon
->owner
)
608 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
609 /* Forced use user_icon */
610 get_rimage_icon_from_user_icon(icon
);
611 } else if (icon
->icon_win
!= None
) {
612 /* Get the Pixmap from the WIcon */
613 get_rimage_icon_from_icon_win(icon
);
614 } else if (wwin
&& wwin
->net_icon_image
) {
615 /* Use _NET_WM_ICON icon */
616 get_rimage_icon_from_x11(icon
);
617 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
618 /* Get the Pixmap from the wm_hints, else, from the user */
619 unset_icon_image(icon
);
620 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
621 if (!icon
->file_image
)
622 get_rimage_icon_from_user_icon(icon
);
624 /* Get the Pixmap from the user */
625 get_rimage_icon_from_user_icon(icon
);
629 update_icon_pixmap(icon
);
632 void update_icon_pixmap(WIcon
*icon
)
634 if (icon
->pixmap
!= None
)
635 XFreePixmap(dpy
, icon
->pixmap
);
639 /* Create the pixmap */
640 if (icon
->file_image
)
641 icon_update_pixmap(icon
, icon
->file_image
);
643 /* If dockapp, put inside the icon */
644 if (icon
->icon_win
!= None
) {
645 /* file_image is NULL, because is docked app */
646 icon_update_pixmap(icon
, NULL
);
647 set_dockapp_in_icon(icon
);
650 /* No pixmap, set default background */
651 if (icon
->pixmap
!= None
)
652 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
655 XClearWindow(dpy
, icon
->core
->window
);
659 static void get_rimage_icon_from_x11(WIcon
*icon
)
661 /* Remove the icon image */
662 unset_icon_image(icon
);
664 /* Set the new icon image */
665 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
668 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
670 if (icon
->file_image
)
673 get_rimage_icon_from_default_icon(icon
);
676 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
678 WScreen
*scr
= icon
->core
->screen_ptr
;
680 /* If the icon don't have image, we should use the default image. */
681 if (!scr
->def_icon_rimage
)
682 scr
->def_icon_rimage
= get_default_image(scr
);
684 /* Remove the icon image */
685 unset_icon_image(icon
);
687 /* Set the new icon image */
688 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
691 /* Get the RImage from the WIcon of the WWindow */
692 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
696 /* Create the new RImage */
697 image
= get_window_image_from_x11(icon
->icon_win
);
699 /* Free the icon info */
700 unset_icon_image(icon
);
702 /* Set the new info */
703 icon
->file_image
= image
;
706 /* Set the dockapp in the WIcon */
707 static void set_dockapp_in_icon(WIcon
*icon
)
709 XWindowAttributes attr
;
710 WScreen
*scr
= icon
->core
->screen_ptr
;
711 int title_height
= WMFontHeight(scr
->icon_title_font
);
712 unsigned int w
, h
, d
;
715 /* Reparent the dock application to the icon */
717 /* We need the application size to center it
718 * and show in the correct position */
719 getSize(icon
->icon_win
, &w
, &h
, &d
);
721 /* Set extra space for title */
722 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
723 theight
= title_height
;
724 drawIconTitle(scr
, icon
->pixmap
, theight
);
726 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
729 /* Set the icon border */
730 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
732 /* Put the dock application in the icon */
733 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
734 (wPreferences
.icon_size
- w
) / 2,
735 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
737 /* Show it and save */
738 XMapWindow(dpy
, icon
->icon_win
);
739 XAddToSaveSet(dpy
, icon
->icon_win
);
741 /* Needed to move the icon clicking on the application part */
742 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
743 (attr
.all_event_masks
& ButtonPressMask
))
744 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
745 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
746 None
, wCursor
[WCUR_ARROW
]);
749 /* Get the RImage from the XWindow wm_hints */
750 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
752 RImage
*image
= NULL
;
753 unsigned int w
, h
, d
;
754 WWindow
*wwin
= icon
->owner
;
756 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
757 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
761 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
765 /* Resize the icon to the wPreferences.icon_size size */
766 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
771 void wIconPaint(WIcon
*icon
)
773 WScreen
*scr
= icon
->core
->screen_ptr
;
777 XClearWindow(dpy
, icon
->core
->window
);
779 /* draw the icon title */
780 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
781 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
782 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
784 if (w
> icon
->core
->width
- 4)
785 x
= (icon
->core
->width
- 4) - w
;
787 x
= (icon
->core
->width
- w
) / 2;
789 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
790 scr
->icon_title_font
, x
, 1, tmp
, l
);
795 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
796 icon
->core
->width
- 1, icon
->core
->height
- 1);
799 /******************************************************************/
801 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
803 wIconPaint(desc
->parent
);
806 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
808 WIcon
*icon
= desc
->parent
;
810 assert(icon
->owner
!= NULL
);
812 wDeiconifyWindow(icon
->owner
);
815 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
817 WIcon
*icon
= desc
->parent
;
818 WWindow
*wwin
= icon
->owner
;
820 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
821 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
823 int clickButton
= event
->xbutton
.button
;
824 Bool hasMoved
= False
;
826 if (WCHECK_STATE(WSTATE_MODAL
))
829 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
830 miniwindowDblClick(desc
, event
);
834 if (event
->xbutton
.button
== Button1
) {
835 if (event
->xbutton
.state
& MOD_MASK
)
836 wLowerFrame(icon
->core
);
838 wRaiseFrame(icon
->core
);
839 if (event
->xbutton
.state
& ShiftMask
) {
841 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
843 } else if (event
->xbutton
.button
== Button3
) {
844 WObjDescriptor
*desc
;
846 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
848 /* allow drag select of menu */
849 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
850 event
->xbutton
.send_event
= True
;
851 (*desc
->handle_mousedown
) (desc
, event
);
856 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
857 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
858 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
861 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
862 | ButtonMotionMask
| ExposureMask
, &ev
);
871 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
872 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
873 XChangeActivePointerGrab(dpy
, ButtonMotionMask
874 | ButtonReleaseMask
| ButtonPressMask
,
875 wCursor
[WCUR_MOVE
], CurrentTime
);
881 x
= ev
.xmotion
.x_root
- dx
;
882 y
= ev
.xmotion
.y_root
- dy
;
883 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
890 if (ev
.xbutton
.button
!= clickButton
)
893 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
894 wwin
->flags
.icon_moved
= 1;
896 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
900 XUngrabPointer(dpy
, CurrentTime
);
902 if (wPreferences
.auto_arrange_icons
)
903 wArrangeIcons(wwin
->screen_ptr
, True
);
904 if (wPreferences
.single_click
&& !hasMoved
)
905 miniwindowDblClick(desc
, event
);