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 get_pixmap_icon_from_icon_win(WIcon
*icon
);
64 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
);
65 static void get_pixmap_icon_from_user_icon(WIcon
*icon
);
66 static void get_pixmap_icon_from_default_icon(WIcon
*icon
);
68 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
69 static void unset_icon_image(WIcon
*icon
);
71 static RImage
*get_default_image(WScreen
*scr
);
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 icon
->force_paint
= 1;
84 /* so that the appicon expose handlers will paint the appicon specific
86 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
89 static void tileObserver(void *self
, WMNotification
* notif
)
91 WIcon
*icon
= (WIcon
*) self
;
93 icon
->force_paint
= 1;
96 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
99 /************************************/
101 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
107 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
110 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
112 WScreen
*scr
= wwin
->screen_ptr
;
116 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
119 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
120 if (wwin
->client_win
== wwin
->main_window
) {
122 /* do not let miniwindow steal app-icon's icon window */
123 wapp
= wApplicationOf(wwin
->client_win
);
124 if (!wapp
|| wapp
->app_icon
== NULL
)
125 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
127 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
130 #ifdef NO_MINIWINDOW_TITLES
131 icon
->show_title
= 0;
133 icon
->show_title
= 1;
136 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
138 wwin
->flags
.net_has_icon_title
= 1;
140 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
142 /* Get the application icon, default included */
143 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
145 icon
->file
= wstrdup(file
);
146 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
150 icon
->tile_type
= TILE_NORMAL
;
154 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
155 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
160 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
165 icon
= icon_create_core(scr
, 0, 0);
167 /* Search the icon using instance and class, without default icon */
168 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
170 icon
->file
= wstrdup(file
);
171 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
175 icon
->tile_type
= tile
;
179 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
180 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
185 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
188 unsigned long vmask
= 0;
189 XSetWindowAttributes attribs
;
191 icon
= wmalloc(sizeof(WIcon
));
192 icon
->core
= wCoreCreateTopLevel(scr
,
195 wPreferences
.icon_size
,
196 wPreferences
.icon_size
,
197 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
199 if (wPreferences
.use_saveunders
) {
201 attribs
.save_under
= True
;
204 /* a white border for selecting it */
205 vmask
|= CWBorderPixel
;
206 attribs
.border_pixel
= scr
->white_pixel
;
208 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
210 /* will be overriden if this is a application icon */
211 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
212 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
213 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
214 icon
->core
->descriptor
.parent
= icon
;
216 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
217 icon
->core
->stacking
->above
= NULL
;
218 icon
->core
->stacking
->under
= NULL
;
219 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
220 icon
->core
->stacking
->child_of
= NULL
;
224 icon
->file_image
= NULL
;
229 void wIconDestroy(WIcon
* icon
)
231 WCoreWindow
*core
= icon
->core
;
232 WScreen
*scr
= core
->screen_ptr
;
234 WMRemoveNotificationObserver(icon
);
237 WMDeleteTimerHandler(icon
->handlerID
);
239 if (icon
->icon_win
) {
243 x
= icon
->owner
->icon_x
;
244 y
= icon
->owner
->icon_y
;
246 XUnmapWindow(dpy
, icon
->icon_win
);
247 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
250 XFree(icon
->icon_name
);
253 XFreePixmap(dpy
, icon
->pixmap
);
255 unset_icon_image(icon
);
257 wCoreDestroy(icon
->core
);
261 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
263 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
264 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
265 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
266 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
267 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
270 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
277 WScreen
*scr
= icon
->core
->screen_ptr
;
278 int titled
= icon
->show_title
;
280 if (icon
->tile_type
== TILE_NORMAL
) {
281 tile
= RCloneImage(scr
->icon_tile
);
283 assert(scr
->clip_tile
);
284 tile
= RCloneImage(scr
->clip_tile
);
288 w
= (image
->width
> wPreferences
.icon_size
)
289 ? wPreferences
.icon_size
: image
->width
;
290 x
= (wPreferences
.icon_size
- w
) / 2;
291 sx
= (image
->width
- w
) / 2;
294 theight
= WMFontHeight(scr
->icon_title_font
);
296 h
= (image
->height
+ theight
> wPreferences
.icon_size
297 ? wPreferences
.icon_size
- theight
: image
->height
);
298 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
299 sy
= (image
->height
- h
) / 2;
301 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
304 if (icon
->shadowed
) {
307 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
308 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
309 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
310 color
.alpha
= 150; /* about 60% */
311 RClearImage(tile
, &color
);
314 if (icon
->highlighted
) {
317 color
.red
= color
.green
= color
.blue
= 0;
319 RLightImage(tile
, &color
);
322 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
323 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
328 drawIconTitle(scr
, pixmap
, theight
);
330 icon
->pixmap
= pixmap
;
333 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
337 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
338 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
340 if (icon
->icon_name
!= NULL
)
341 XFree(icon
->icon_name
);
343 icon
->icon_name
= new_title
;
346 icon
->force_paint
= 1;
350 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
357 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
358 if ((icon
->width
- max_size
) > -ICON_BORDER
||
359 (icon
->height
- max_size
) > -ICON_BORDER
) {
360 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
361 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
369 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
371 WScreen
*scr
= icon
->core
->screen_ptr
;
373 RImage
*image
= NULL
;
376 /* If no new image, don't do nothing */
380 /* Find the new image */
381 path
= FindImage(wPreferences
.icon_path
, file
);
383 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
388 if (!error
&& image
) {
389 /* Remove the old one */
390 unset_icon_image(icon
);
392 /* Set the new image */
393 icon
->file_image
= image
;
394 icon
->file
= wstrdup(path
);
406 static char *get_name_for_wwin(WWindow
*wwin
)
408 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
411 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
416 if (wm_class
&& wm_instance
) {
417 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
418 suffix
= wmalloc(len
);
419 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
420 } else if (wm_class
) {
421 len
= strlen(wm_class
) + 1;
422 suffix
= wmalloc(len
);
423 snprintf(suffix
, len
, "%s", wm_class
);
424 } else if (wm_instance
) {
425 len
= strlen(wm_instance
) + 1;
426 suffix
= wmalloc(len
);
427 snprintf(suffix
, len
, "%s", wm_instance
);
435 static char *get_icon_cache_path(void)
440 prefix
= wusergnusteppath();
441 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
443 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
445 /* If the folder exists, exit */
446 if (access(path
, F_OK
) == 0)
449 /* Create the folder */
450 ret
= wmkdirhier((const char *) path
);
452 /* Exit 1 on success, 0 on failure */
461 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
463 RImage
*image
= NULL
;
464 XWMHints
*hints
= wwin
->wm_hints
;
466 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
467 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
469 (hints
->flags
& IconMaskHint
)
470 ? hints
->icon_mask
: None
);
477 * Stores the client supplied icon at CACHE_ICON_PATH
478 * and returns the path for that icon. Returns NULL if there is no
479 * client supplied icon or on failure.
482 * New directories might be created.
484 char *wIconStore(WIcon
* icon
)
486 char *path
, *dir_path
, *file
;
488 RImage
*image
= NULL
;
489 WWindow
*wwin
= icon
->owner
;
494 dir_path
= get_icon_cache_path();
498 file
= get_name_for_wwin(wwin
);
504 len
= strlen(dir_path
) + strlen(file
) + 5;
506 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
510 /* If icon exists, exit */
511 if (access(path
, F_OK
) == 0)
514 if (wwin
->net_icon_image
)
515 image
= RRetainImage(wwin
->net_icon_image
);
517 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
524 if (!RSaveImage(image
, path
, "XPM")) {
529 RReleaseImage(image
);
534 static void cycleColor(void *data
)
536 WIcon
*icon
= (WIcon
*) data
;
537 WScreen
*scr
= icon
->core
->screen_ptr
;
541 gcv
.dash_offset
= icon
->step
;
542 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
544 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
545 icon
->core
->width
- 1, icon
->core
->height
- 1);
546 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
550 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
552 if (icon
->highlighted
== flag
)
555 icon
->highlighted
= flag
;
556 icon
->force_paint
= True
;
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 (icon
->pixmap
!= None
)
599 XFreePixmap(dpy
, icon
->pixmap
);
603 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
604 /* Forced use user_icon */
605 get_pixmap_icon_from_user_icon(icon
);
606 } else if (icon
->icon_win
!= None
) {
607 /* Get the Pixmap from the WIcon */
608 get_pixmap_icon_from_icon_win(icon
);
609 } else if (wwin
&& wwin
->net_icon_image
) {
610 /* Use _NET_WM_ICON icon */
611 icon_update_pixmap(icon
, wwin
->net_icon_image
);
612 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
613 /* Get the Pixmap from the wm_hints, else, from the user */
614 if (get_pixmap_icon_from_wm_hints(icon
))
615 get_pixmap_icon_from_user_icon(icon
);
617 /* Get the Pixmap from the user */
618 get_pixmap_icon_from_user_icon(icon
);
621 /* No pixmap, set default background */
622 if (icon
->pixmap
!= None
)
623 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
626 XClearWindow(dpy
, icon
->core
->window
);
630 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
632 /* If the icon has image, update it and continue */
633 if (icon
->file_image
) {
634 icon_update_pixmap(icon
, icon
->file_image
);
638 get_pixmap_icon_from_default_icon(icon
);
641 static void get_pixmap_icon_from_default_icon(WIcon
*icon
)
643 WScreen
*scr
= icon
->core
->screen_ptr
;
645 /* If the icon don't have image, we should use the default image. */
646 if (!scr
->def_icon_rimage
)
647 scr
->def_icon_rimage
= get_default_image(scr
);
649 /* Now, create the pixmap using the default (saved) image */
650 icon_update_pixmap(icon
, scr
->def_icon_rimage
);
653 /* This function creates the RImage using the default icon */
654 static RImage
*get_default_image(WScreen
*scr
)
656 RImage
*image
= NULL
;
659 /* Get the default icon */
660 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
662 path
= FindImage(wPreferences
.icon_path
, file
);
663 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
666 wwarning(_("could not find default icon \"%s\""), file
);
674 /* Get the Pixmap from the WIcon of the WWindow */
675 static void get_pixmap_icon_from_icon_win(WIcon
* icon
)
677 XWindowAttributes attr
;
678 WScreen
*scr
= icon
->core
->screen_ptr
;
679 int title_height
= WMFontHeight(scr
->icon_title_font
);
680 unsigned int width
, height
, depth
;
685 getSize(icon
->icon_win
, &width
, &height
, &depth
);
687 if (width
> wPreferences
.icon_size
) {
689 width
= wPreferences
.icon_size
;
692 if (height
> wPreferences
.icon_size
) {
694 height
= wPreferences
.icon_size
;
697 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
698 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
699 wPreferences
.icon_size
, scr
->w_depth
);
700 XSetClipMask(dpy
, scr
->copy_gc
, None
);
701 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
702 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
703 drawIconTitle(scr
, pixmap
, title_height
);
704 theight
= title_height
;
708 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
711 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
712 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
713 (wPreferences
.icon_size
- width
) / 2,
714 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
716 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
718 XMapWindow(dpy
, icon
->icon_win
);
719 XAddToSaveSet(dpy
, icon
->icon_win
);
722 icon
->pixmap
= pixmap
;
724 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
725 (attr
.all_event_masks
& ButtonPressMask
))
726 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
727 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
728 None
, wCursor
[WCUR_ARROW
]);
731 /* Get the Pixmap from the XWindow wm_hints */
732 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
734 RImage
*image
= NULL
;
735 unsigned int w
, h
, d
;
736 WWindow
*wwin
= icon
->owner
;
738 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
739 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
743 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
747 icon_update_pixmap(icon
, image
);
752 void wIconPaint(WIcon
* icon
)
754 WScreen
*scr
= icon
->core
->screen_ptr
;
758 if (icon
->force_paint
) {
759 icon
->force_paint
= 0;
764 XClearWindow(dpy
, icon
->core
->window
);
766 /* draw the icon title */
767 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
771 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
772 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
774 if (w
> icon
->core
->width
- 4)
775 x
= (icon
->core
->width
- 4) - w
;
777 x
= (icon
->core
->width
- w
) / 2;
779 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
780 scr
->icon_title_font
, x
, 1, tmp
, l
);
785 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
786 icon
->core
->width
- 1, icon
->core
->height
- 1);
789 /******************************************************************/
791 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
793 wIconPaint(desc
->parent
);
796 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
798 WIcon
*icon
= desc
->parent
;
800 assert(icon
->owner
!= NULL
);
802 wDeiconifyWindow(icon
->owner
);
805 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
807 WIcon
*icon
= desc
->parent
;
808 WWindow
*wwin
= icon
->owner
;
810 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
811 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
813 int clickButton
= event
->xbutton
.button
;
814 Bool hasMoved
= False
;
816 if (WCHECK_STATE(WSTATE_MODAL
))
819 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
820 miniwindowDblClick(desc
, event
);
824 if (event
->xbutton
.button
== Button1
) {
825 if (event
->xbutton
.state
& MOD_MASK
)
826 wLowerFrame(icon
->core
);
828 wRaiseFrame(icon
->core
);
829 if (event
->xbutton
.state
& ShiftMask
) {
831 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
833 } else if (event
->xbutton
.button
== Button3
) {
834 WObjDescriptor
*desc
;
836 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
838 /* allow drag select of menu */
839 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
840 event
->xbutton
.send_event
= True
;
841 (*desc
->handle_mousedown
) (desc
, event
);
846 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
847 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
848 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
851 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
852 | ButtonMotionMask
| ExposureMask
, &ev
);
861 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
862 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
863 XChangeActivePointerGrab(dpy
, ButtonMotionMask
864 | ButtonReleaseMask
| ButtonPressMask
,
865 wCursor
[WCUR_MOVE
], CurrentTime
);
871 x
= ev
.xmotion
.x_root
- dx
;
872 y
= ev
.xmotion
.y_root
- dy
;
873 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
880 if (ev
.xbutton
.button
!= clickButton
)
883 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
884 wwin
->flags
.icon_moved
= 1;
886 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
890 XUngrabPointer(dpy
, CurrentTime
);
892 if (wPreferences
.auto_arrange_icons
)
893 wArrangeIcons(wwin
->screen_ptr
, True
);
894 if (wPreferences
.single_click
&& !hasMoved
)
895 miniwindowDblClick(desc
, event
);