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 int get_rimage_icon_from_wm_hints(WIcon
*icon
);
66 static void get_rimage_icon_from_user_icon(WIcon
*icon
);
67 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
68 static void get_rimage_icon_from_x11(WIcon
*icon
);
70 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
71 static void unset_icon_image(WIcon
*icon
);
73 /****** Notification Observers ******/
75 static void appearanceObserver(void *self
, WMNotification
* notif
)
77 WIcon
*icon
= (WIcon
*) self
;
78 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
80 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
81 icon
->force_paint
= 1;
85 /* so that the appicon expose handlers will paint the appicon specific
87 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
90 static void tileObserver(void *self
, WMNotification
* notif
)
92 WIcon
*icon
= (WIcon
*) self
;
94 icon
->force_paint
= 1;
97 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
100 /************************************/
102 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
108 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
111 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
113 WScreen
*scr
= wwin
->screen_ptr
;
117 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
120 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
121 if (wwin
->client_win
== wwin
->main_window
) {
123 /* do not let miniwindow steal app-icon's icon window */
124 wapp
= wApplicationOf(wwin
->client_win
);
125 if (!wapp
|| wapp
->app_icon
== NULL
)
126 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
128 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
131 #ifdef NO_MINIWINDOW_TITLES
132 icon
->show_title
= 0;
134 icon
->show_title
= 1;
137 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
139 wwin
->flags
.net_has_icon_title
= 1;
141 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
143 /* Get the application icon, default included */
144 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
146 icon
->file
= wstrdup(file
);
147 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
151 icon
->tile_type
= TILE_NORMAL
;
155 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
156 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
161 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
166 icon
= icon_create_core(scr
, 0, 0);
168 /* Search the icon using instance and class, without default icon */
169 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
171 icon
->file
= wstrdup(file
);
172 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
176 icon
->tile_type
= tile
;
180 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
181 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
186 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
189 unsigned long vmask
= 0;
190 XSetWindowAttributes attribs
;
192 icon
= wmalloc(sizeof(WIcon
));
193 icon
->core
= wCoreCreateTopLevel(scr
,
196 wPreferences
.icon_size
,
197 wPreferences
.icon_size
,
198 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
200 if (wPreferences
.use_saveunders
) {
202 attribs
.save_under
= True
;
205 /* a white border for selecting it */
206 vmask
|= CWBorderPixel
;
207 attribs
.border_pixel
= scr
->white_pixel
;
209 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
211 /* will be overriden if this is a application icon */
212 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
213 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
214 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
215 icon
->core
->descriptor
.parent
= icon
;
217 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
218 icon
->core
->stacking
->above
= NULL
;
219 icon
->core
->stacking
->under
= NULL
;
220 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
221 icon
->core
->stacking
->child_of
= NULL
;
225 icon
->file_image
= NULL
;
230 void wIconDestroy(WIcon
* icon
)
232 WCoreWindow
*core
= icon
->core
;
233 WScreen
*scr
= core
->screen_ptr
;
235 WMRemoveNotificationObserver(icon
);
238 WMDeleteTimerHandler(icon
->handlerID
);
240 if (icon
->icon_win
) {
244 x
= icon
->owner
->icon_x
;
245 y
= icon
->owner
->icon_y
;
247 XUnmapWindow(dpy
, icon
->icon_win
);
248 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
251 XFree(icon
->icon_name
);
254 XFreePixmap(dpy
, icon
->pixmap
);
256 unset_icon_image(icon
);
258 wCoreDestroy(icon
->core
);
262 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
264 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
265 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
266 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
267 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
268 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
271 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
278 WScreen
*scr
= icon
->core
->screen_ptr
;
279 int titled
= icon
->show_title
;
281 if (icon
->tile_type
== TILE_NORMAL
) {
282 tile
= RCloneImage(scr
->icon_tile
);
284 assert(scr
->clip_tile
);
285 tile
= RCloneImage(scr
->clip_tile
);
289 w
= (image
->width
> wPreferences
.icon_size
)
290 ? wPreferences
.icon_size
: image
->width
;
291 x
= (wPreferences
.icon_size
- w
) / 2;
292 sx
= (image
->width
- w
) / 2;
295 theight
= WMFontHeight(scr
->icon_title_font
);
297 h
= (image
->height
+ theight
> wPreferences
.icon_size
298 ? wPreferences
.icon_size
- theight
: image
->height
);
299 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
300 sy
= (image
->height
- h
) / 2;
302 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
305 if (icon
->shadowed
) {
308 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
309 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
310 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
311 color
.alpha
= 150; /* about 60% */
312 RClearImage(tile
, &color
);
315 if (icon
->highlighted
) {
318 color
.red
= color
.green
= color
.blue
= 0;
320 RLightImage(tile
, &color
);
323 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
324 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
329 drawIconTitle(scr
, pixmap
, theight
);
331 icon
->pixmap
= pixmap
;
334 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
338 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
339 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
341 if (icon
->icon_name
!= NULL
)
342 XFree(icon
->icon_name
);
344 icon
->icon_name
= new_title
;
347 icon
->force_paint
= 1;
351 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
358 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
359 if ((icon
->width
- max_size
) > -ICON_BORDER
||
360 (icon
->height
- max_size
) > -ICON_BORDER
) {
361 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
362 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
370 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
372 WScreen
*scr
= icon
->core
->screen_ptr
;
374 RImage
*image
= NULL
;
377 /* If no new image, don't do nothing */
381 /* Find the new image */
382 path
= FindImage(wPreferences
.icon_path
, file
);
384 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
389 if (!error
&& image
) {
390 /* Remove the old one */
391 unset_icon_image(icon
);
393 /* Set the new image */
394 icon
->file_image
= image
;
395 icon
->file
= wstrdup(path
);
407 static char *get_name_for_wwin(WWindow
*wwin
)
409 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
412 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
417 if (wm_class
&& wm_instance
) {
418 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
419 suffix
= wmalloc(len
);
420 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
421 } else if (wm_class
) {
422 len
= strlen(wm_class
) + 1;
423 suffix
= wmalloc(len
);
424 snprintf(suffix
, len
, "%s", wm_class
);
425 } else if (wm_instance
) {
426 len
= strlen(wm_instance
) + 1;
427 suffix
= wmalloc(len
);
428 snprintf(suffix
, len
, "%s", wm_instance
);
436 static char *get_icon_cache_path(void)
441 prefix
= wusergnusteppath();
442 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
444 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
446 /* If the folder exists, exit */
447 if (access(path
, F_OK
) == 0)
450 /* Create the folder */
451 ret
= wmkdirhier((const char *) path
);
453 /* Exit 1 on success, 0 on failure */
462 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
464 RImage
*image
= NULL
;
465 XWMHints
*hints
= wwin
->wm_hints
;
467 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
468 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
470 (hints
->flags
& IconMaskHint
)
471 ? hints
->icon_mask
: None
);
478 * Stores the client supplied icon at CACHE_ICON_PATH
479 * and returns the path for that icon. Returns NULL if there is no
480 * client supplied icon or on failure.
483 * New directories might be created.
485 char *wIconStore(WIcon
* icon
)
487 char *path
, *dir_path
, *file
;
489 RImage
*image
= NULL
;
490 WWindow
*wwin
= icon
->owner
;
495 dir_path
= get_icon_cache_path();
499 file
= get_name_for_wwin(wwin
);
505 len
= strlen(dir_path
) + strlen(file
) + 5;
507 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
511 /* If icon exists, exit */
512 if (access(path
, F_OK
) == 0)
515 if (wwin
->net_icon_image
)
516 image
= RRetainImage(wwin
->net_icon_image
);
518 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
525 if (!RSaveImage(image
, path
, "XPM")) {
530 RReleaseImage(image
);
535 static void cycleColor(void *data
)
537 WIcon
*icon
= (WIcon
*) data
;
538 WScreen
*scr
= icon
->core
->screen_ptr
;
542 gcv
.dash_offset
= icon
->step
;
543 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
545 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
546 icon
->core
->width
- 1, icon
->core
->height
- 1);
547 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
551 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
553 if (icon
->highlighted
== flag
)
556 icon
->highlighted
= flag
;
557 update_icon_pixmap(icon
);
561 void wIconSelect(WIcon
* icon
)
563 WScreen
*scr
= icon
->core
->screen_ptr
;
564 icon
->selected
= !icon
->selected
;
566 if (icon
->selected
) {
568 if (!wPreferences
.dont_blink
)
569 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
571 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
572 icon
->core
->width
- 1, icon
->core
->height
- 1);
574 if (icon
->handlerID
) {
575 WMDeleteTimerHandler(icon
->handlerID
);
576 icon
->handlerID
= NULL
;
578 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
582 static void unset_icon_image(WIcon
*icon
)
587 if (icon
->file_image
)
588 RReleaseImage(icon
->file_image
);
591 void wIconUpdate(WIcon
*icon
)
593 WScreen
*scr
= icon
->core
->screen_ptr
;
594 WWindow
*wwin
= icon
->owner
;
596 assert(scr
->icon_tile
!= NULL
);
598 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
599 /* Forced use user_icon */
600 get_rimage_icon_from_user_icon(icon
);
601 } else if (icon
->icon_win
!= None
) {
602 /* Get the Pixmap from the WIcon */
603 get_rimage_icon_from_icon_win(icon
);
604 } else if (wwin
&& wwin
->net_icon_image
) {
605 /* Use _NET_WM_ICON icon */
606 get_rimage_icon_from_x11(icon
);
607 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
608 /* Get the Pixmap from the wm_hints, else, from the user */
609 if (get_rimage_icon_from_wm_hints(icon
))
610 get_rimage_icon_from_user_icon(icon
);
612 /* Get the Pixmap from the user */
613 get_rimage_icon_from_user_icon(icon
);
616 update_icon_pixmap(icon
);
619 void update_icon_pixmap(WIcon
*icon
)
621 if (icon
->pixmap
!= None
)
622 XFreePixmap(dpy
, icon
->pixmap
);
626 /* Create the pixmap */
627 if (icon
->file_image
)
628 icon_update_pixmap(icon
, icon
->file_image
);
630 /* If dockapp, put inside the icon */
631 if (icon
->icon_win
!= None
) {
632 /* file_image is NULL, because is docked app */
633 icon_update_pixmap(icon
, icon
->file_image
);
634 set_dockapp_in_icon(icon
);
637 /* No pixmap, set default background */
638 if (icon
->pixmap
!= None
)
639 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
642 XClearWindow(dpy
, icon
->core
->window
);
646 static void get_rimage_icon_from_x11(WIcon
*icon
)
648 /* Remove the icon image */
649 unset_icon_image(icon
);
651 /* Set the new icon image */
653 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
656 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
658 if (icon
->file_image
)
661 get_rimage_icon_from_default_icon(icon
);
664 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
666 WScreen
*scr
= icon
->core
->screen_ptr
;
668 /* If the icon don't have image, we should use the default image. */
669 if (!scr
->def_icon_rimage
)
670 scr
->def_icon_rimage
= get_default_image(scr
);
672 /* Remove the icon image */
673 unset_icon_image(icon
);
675 /* Set the new icon image */
677 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
680 /* Get the RImage from the WIcon of the WWindow */
681 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
685 /* Create the new RImage */
686 image
= get_window_image_from_x11(icon
->icon_win
);
688 /* Free the icon info */
689 unset_icon_image(icon
);
691 /* Set the new info */
693 icon
->file_image
= image
;
696 /* Set the dockapp in the WIcon */
697 static void set_dockapp_in_icon(WIcon
*icon
)
699 XWindowAttributes attr
;
700 WScreen
*scr
= icon
->core
->screen_ptr
;
701 int title_height
= WMFontHeight(scr
->icon_title_font
);
702 unsigned int w
, h
, d
;
705 /* Reparent the dock application to the icon */
707 /* We need the application size to center it
708 * and show in the correct position */
709 getSize(icon
->icon_win
, &w
, &h
, &d
);
711 /* Set extra space for title */
712 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
713 theight
= title_height
;
714 drawIconTitle(scr
, icon
->pixmap
, theight
);
716 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
719 /* Set the icon border */
720 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
722 /* Put the dock application in the icon */
723 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
724 (wPreferences
.icon_size
- w
) / 2,
725 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
727 /* Show it and save */
728 XMapWindow(dpy
, icon
->icon_win
);
729 XAddToSaveSet(dpy
, icon
->icon_win
);
731 /* Needed to move the icon clicking on the application part */
732 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
733 (attr
.all_event_masks
& ButtonPressMask
))
734 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
735 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
736 None
, wCursor
[WCUR_ARROW
]);
739 /* Get the RImage from the XWindow wm_hints */
740 static int get_rimage_icon_from_wm_hints(WIcon
*icon
)
742 RImage
*image
= NULL
;
743 unsigned int w
, h
, d
;
744 WWindow
*wwin
= icon
->owner
;
746 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
747 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
751 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
755 /* FIXME: If unset_icon_image, pointer double free then crash
756 unset_icon_image(icon); */
757 icon
->file_image
= image
;
762 void wIconPaint(WIcon
* icon
)
764 WScreen
*scr
= icon
->core
->screen_ptr
;
768 if (icon
->force_paint
) {
769 icon
->force_paint
= 0;
774 XClearWindow(dpy
, icon
->core
->window
);
776 /* draw the icon title */
777 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
);