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 icon
->force_paint
= True
;
562 void wIconSelect(WIcon
* icon
)
564 WScreen
*scr
= icon
->core
->screen_ptr
;
565 icon
->selected
= !icon
->selected
;
567 if (icon
->selected
) {
569 if (!wPreferences
.dont_blink
)
570 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
572 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
573 icon
->core
->width
- 1, icon
->core
->height
- 1);
575 if (icon
->handlerID
) {
576 WMDeleteTimerHandler(icon
->handlerID
);
577 icon
->handlerID
= NULL
;
579 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
583 static void unset_icon_image(WIcon
*icon
)
588 if (icon
->file_image
)
589 RReleaseImage(icon
->file_image
);
592 void wIconUpdate(WIcon
*icon
)
594 WScreen
*scr
= icon
->core
->screen_ptr
;
595 WWindow
*wwin
= icon
->owner
;
597 assert(scr
->icon_tile
!= NULL
);
599 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
600 /* Forced use user_icon */
601 get_rimage_icon_from_user_icon(icon
);
602 } else if (icon
->icon_win
!= None
) {
603 /* Get the Pixmap from the WIcon */
604 get_rimage_icon_from_icon_win(icon
);
605 } else if (wwin
&& wwin
->net_icon_image
) {
606 /* Use _NET_WM_ICON icon */
607 get_rimage_icon_from_x11(icon
);
608 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
609 /* Get the Pixmap from the wm_hints, else, from the user */
610 if (get_rimage_icon_from_wm_hints(icon
))
611 get_rimage_icon_from_user_icon(icon
);
613 /* Get the Pixmap from the user */
614 get_rimage_icon_from_user_icon(icon
);
617 update_icon_pixmap(icon
);
620 void update_icon_pixmap(WIcon
*icon
)
622 if (icon
->pixmap
!= None
)
623 XFreePixmap(dpy
, icon
->pixmap
);
627 /* Create the pixmap */
628 if (icon
->file_image
)
629 icon_update_pixmap(icon
, icon
->file_image
);
631 /* If dockapp, put inside the icon */
632 if (icon
->icon_win
!= None
) {
633 /* file_image is NULL, because is docked app */
634 icon_update_pixmap(icon
, icon
->file_image
);
635 set_dockapp_in_icon(icon
);
638 /* No pixmap, set default background */
639 if (icon
->pixmap
!= None
)
640 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
643 XClearWindow(dpy
, icon
->core
->window
);
647 static void get_rimage_icon_from_x11(WIcon
*icon
)
649 /* Remove the icon image */
650 unset_icon_image(icon
);
652 /* Set the new icon image */
654 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
657 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
659 if (icon
->file_image
)
662 get_rimage_icon_from_default_icon(icon
);
665 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
667 WScreen
*scr
= icon
->core
->screen_ptr
;
669 /* If the icon don't have image, we should use the default image. */
670 if (!scr
->def_icon_rimage
)
671 scr
->def_icon_rimage
= get_default_image(scr
);
673 /* Remove the icon image */
674 unset_icon_image(icon
);
676 /* Set the new icon image */
678 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
681 /* Get the RImage from the WIcon of the WWindow */
682 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
686 /* Create the new RImage */
687 image
= get_window_image_from_x11(icon
->icon_win
);
689 /* Free the icon info */
690 unset_icon_image(icon
);
692 /* Set the new info */
694 icon
->file_image
= image
;
697 /* Set the dockapp in the WIcon */
698 static void set_dockapp_in_icon(WIcon
*icon
)
700 XWindowAttributes attr
;
701 WScreen
*scr
= icon
->core
->screen_ptr
;
702 int title_height
= WMFontHeight(scr
->icon_title_font
);
703 unsigned int w
, h
, d
;
706 /* Reparent the dock application to the icon */
708 /* We need the application size to center it
709 * and show in the correct position */
710 getSize(icon
->icon_win
, &w
, &h
, &d
);
712 /* Set extra space for title */
713 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
714 theight
= title_height
;
715 drawIconTitle(scr
, icon
->pixmap
, theight
);
717 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
720 /* Set the icon border */
721 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
723 /* Put the dock application in the icon */
724 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
725 (wPreferences
.icon_size
- w
) / 2,
726 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
728 /* Show it and save */
729 XMapWindow(dpy
, icon
->icon_win
);
730 XAddToSaveSet(dpy
, icon
->icon_win
);
732 /* Needed to move the icon clicking on the application part */
733 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
734 (attr
.all_event_masks
& ButtonPressMask
))
735 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
736 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
737 None
, wCursor
[WCUR_ARROW
]);
740 /* Get the RImage from the XWindow wm_hints */
741 static int get_rimage_icon_from_wm_hints(WIcon
*icon
)
743 RImage
*image
= NULL
;
744 unsigned int w
, h
, d
;
745 WWindow
*wwin
= icon
->owner
;
747 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
748 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
752 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
756 /* FIXME: If unset_icon_image, pointer double free then crash
757 unset_icon_image(icon); */
758 icon
->file_image
= image
;
763 void wIconPaint(WIcon
* icon
)
765 WScreen
*scr
= icon
->core
->screen_ptr
;
769 if (icon
->force_paint
) {
770 icon
->force_paint
= 0;
775 XClearWindow(dpy
, icon
->core
->window
);
777 /* draw the icon title */
778 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
782 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
783 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
785 if (w
> icon
->core
->width
- 4)
786 x
= (icon
->core
->width
- 4) - w
;
788 x
= (icon
->core
->width
- w
) / 2;
790 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
791 scr
->icon_title_font
, x
, 1, tmp
, l
);
796 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
797 icon
->core
->width
- 1, icon
->core
->height
- 1);
800 /******************************************************************/
802 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
804 wIconPaint(desc
->parent
);
807 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
809 WIcon
*icon
= desc
->parent
;
811 assert(icon
->owner
!= NULL
);
813 wDeiconifyWindow(icon
->owner
);
816 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
818 WIcon
*icon
= desc
->parent
;
819 WWindow
*wwin
= icon
->owner
;
821 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
822 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
824 int clickButton
= event
->xbutton
.button
;
825 Bool hasMoved
= False
;
827 if (WCHECK_STATE(WSTATE_MODAL
))
830 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
831 miniwindowDblClick(desc
, event
);
835 if (event
->xbutton
.button
== Button1
) {
836 if (event
->xbutton
.state
& MOD_MASK
)
837 wLowerFrame(icon
->core
);
839 wRaiseFrame(icon
->core
);
840 if (event
->xbutton
.state
& ShiftMask
) {
842 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
844 } else if (event
->xbutton
.button
== Button3
) {
845 WObjDescriptor
*desc
;
847 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
849 /* allow drag select of menu */
850 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
851 event
->xbutton
.send_event
= True
;
852 (*desc
->handle_mousedown
) (desc
, event
);
857 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
858 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
859 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
862 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
863 | ButtonMotionMask
| ExposureMask
, &ev
);
872 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
873 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
874 XChangeActivePointerGrab(dpy
, ButtonMotionMask
875 | ButtonReleaseMask
| ButtonPressMask
,
876 wCursor
[WCUR_MOVE
], CurrentTime
);
882 x
= ev
.xmotion
.x_root
- dx
;
883 y
= ev
.xmotion
.y_root
- dy
;
884 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
891 if (ev
.xbutton
.button
!= clickButton
)
894 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
895 wwin
->flags
.icon_moved
= 1;
897 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
901 XUngrabPointer(dpy
, CurrentTime
);
903 if (wPreferences
.auto_arrange_icons
)
904 wArrangeIcons(wwin
->screen_ptr
, True
);
905 if (wPreferences
.single_click
&& !hasMoved
)
906 miniwindowDblClick(desc
, event
);