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 /* If the rimage exists, update the icon, else create it */
83 update_icon_pixmap(icon
);
88 /* so that the appicon expose handlers will paint the appicon specific
90 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
93 static void tileObserver(void *self
, WMNotification
*notif
)
95 WIcon
*icon
= (WIcon
*) self
;
99 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
102 /************************************/
104 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
110 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
113 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
115 WScreen
*scr
= wwin
->screen_ptr
;
119 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
122 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
123 if (wwin
->client_win
== wwin
->main_window
) {
125 /* do not let miniwindow steal app-icon's icon window */
126 wapp
= wApplicationOf(wwin
->client_win
);
127 if (!wapp
|| wapp
->app_icon
== NULL
)
128 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
130 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
133 #ifdef NO_MINIWINDOW_TITLES
134 icon
->show_title
= 0;
136 icon
->show_title
= 1;
139 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
141 wwin
->flags
.net_has_icon_title
= 1;
143 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
145 /* Get the application icon, default included */
146 file
= get_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
148 icon
->file
= wstrdup(file
);
149 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
153 icon
->tile_type
= TILE_NORMAL
;
157 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
158 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
163 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
168 icon
= icon_create_core(scr
, 0, 0);
170 /* Search the icon using instance and class, without default icon */
171 file
= get_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
173 icon
->file
= wstrdup(file
);
174 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
178 icon
->tile_type
= tile
;
182 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
183 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
188 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
191 unsigned long vmask
= 0;
192 XSetWindowAttributes attribs
;
194 icon
= wmalloc(sizeof(WIcon
));
195 icon
->core
= wCoreCreateTopLevel(scr
,
198 wPreferences
.icon_size
,
199 wPreferences
.icon_size
,
200 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
202 if (wPreferences
.use_saveunders
) {
204 attribs
.save_under
= True
;
207 /* a white border for selecting it */
208 vmask
|= CWBorderPixel
;
209 attribs
.border_pixel
= scr
->white_pixel
;
211 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
213 /* will be overriden if this is a application icon */
214 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
215 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
216 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
217 icon
->core
->descriptor
.parent
= icon
;
219 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
220 icon
->core
->stacking
->above
= NULL
;
221 icon
->core
->stacking
->under
= NULL
;
222 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
223 icon
->core
->stacking
->child_of
= NULL
;
227 icon
->file_image
= NULL
;
232 void wIconDestroy(WIcon
* icon
)
234 WCoreWindow
*core
= icon
->core
;
235 WScreen
*scr
= core
->screen_ptr
;
237 WMRemoveNotificationObserver(icon
);
240 WMDeleteTimerHandler(icon
->handlerID
);
242 if (icon
->icon_win
) {
246 x
= icon
->owner
->icon_x
;
247 y
= icon
->owner
->icon_y
;
249 XUnmapWindow(dpy
, icon
->icon_win
);
250 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
253 XFree(icon
->icon_name
);
256 XFreePixmap(dpy
, icon
->pixmap
);
258 unset_icon_image(icon
);
260 wCoreDestroy(icon
->core
);
264 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
266 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
267 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
268 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
269 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
270 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
273 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
280 WScreen
*scr
= icon
->core
->screen_ptr
;
281 int titled
= icon
->show_title
;
283 if (icon
->tile_type
== TILE_NORMAL
) {
284 tile
= RCloneImage(scr
->icon_tile
);
286 assert(scr
->clip_tile
);
287 tile
= RCloneImage(scr
->clip_tile
);
291 w
= (image
->width
> wPreferences
.icon_size
)
292 ? wPreferences
.icon_size
: image
->width
;
293 x
= (wPreferences
.icon_size
- w
) / 2;
294 sx
= (image
->width
- w
) / 2;
297 theight
= WMFontHeight(scr
->icon_title_font
);
299 h
= (image
->height
+ theight
> wPreferences
.icon_size
300 ? wPreferences
.icon_size
- theight
: image
->height
);
301 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
302 sy
= (image
->height
- h
) / 2;
304 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
307 if (icon
->shadowed
) {
310 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
311 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
312 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
313 color
.alpha
= 150; /* about 60% */
314 RClearImage(tile
, &color
);
317 if (icon
->highlighted
) {
320 color
.red
= color
.green
= color
.blue
= 0;
322 RLightImage(tile
, &color
);
325 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
326 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
331 drawIconTitle(scr
, pixmap
, theight
);
333 icon
->pixmap
= pixmap
;
336 void wIconChangeTitle(WIcon
*icon
, char *new_title
)
340 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
) ||
341 (new_title
!= NULL
&& icon
->icon_name
== NULL
);
343 if (icon
->icon_name
!= NULL
)
344 XFree(icon
->icon_name
);
346 icon
->icon_name
= new_title
;
354 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
361 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
362 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
363 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
364 if (icon
->width
> icon
->height
)
365 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
366 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
368 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
369 max_size
- ICON_BORDER
);
377 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
379 WScreen
*scr
= icon
->core
->screen_ptr
;
381 RImage
*image
= NULL
;
384 /* If no new image, don't do nothing */
388 /* Find the new image */
389 path
= FindImage(wPreferences
.icon_path
, file
);
391 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
396 if (!error
&& image
) {
397 /* Remove the old one */
398 unset_icon_image(icon
);
400 /* Set the new image */
401 icon
->file_image
= image
;
402 icon
->file
= wstrdup(path
);
414 static char *get_name_for_wwin(WWindow
*wwin
)
416 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
419 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
424 if (wm_class
&& wm_instance
) {
425 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
426 suffix
= wmalloc(len
);
427 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
428 } else if (wm_class
) {
429 len
= strlen(wm_class
) + 1;
430 suffix
= wmalloc(len
);
431 snprintf(suffix
, len
, "%s", wm_class
);
432 } else if (wm_instance
) {
433 len
= strlen(wm_instance
) + 1;
434 suffix
= wmalloc(len
);
435 snprintf(suffix
, len
, "%s", wm_instance
);
443 static char *get_icon_cache_path(void)
448 prefix
= wusergnusteppath();
449 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
451 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
453 /* If the folder exists, exit */
454 if (access(path
, F_OK
) == 0)
457 /* Create the folder */
458 ret
= wmkdirhier((const char *) path
);
460 /* Exit 1 on success, 0 on failure */
469 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
471 RImage
*image
= NULL
;
472 XWMHints
*hints
= wwin
->wm_hints
;
474 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
475 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
477 (hints
->flags
& IconMaskHint
)
478 ? hints
->icon_mask
: None
);
485 * Stores the client supplied icon at CACHE_ICON_PATH
486 * and returns the path for that icon. Returns NULL if there is no
487 * client supplied icon or on failure.
490 * New directories might be created.
492 char *wIconStore(WIcon
* icon
)
494 char *path
, *dir_path
, *file
;
496 RImage
*image
= NULL
;
497 WWindow
*wwin
= icon
->owner
;
502 dir_path
= get_icon_cache_path();
506 file
= get_name_for_wwin(wwin
);
512 len
= strlen(dir_path
) + strlen(file
) + 5;
514 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
518 /* If icon exists, exit */
519 if (access(path
, F_OK
) == 0)
522 if (wwin
->net_icon_image
)
523 image
= RRetainImage(wwin
->net_icon_image
);
525 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
532 if (!RSaveImage(image
, path
, "XPM")) {
537 RReleaseImage(image
);
542 static void cycleColor(void *data
)
544 WIcon
*icon
= (WIcon
*) data
;
545 WScreen
*scr
= icon
->core
->screen_ptr
;
549 gcv
.dash_offset
= icon
->step
;
550 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
552 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
553 icon
->core
->width
- 1, icon
->core
->height
- 1);
554 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
558 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
560 if (icon
->highlighted
== flag
)
563 icon
->highlighted
= flag
;
564 update_icon_pixmap(icon
);
568 void wIconSelect(WIcon
* icon
)
570 WScreen
*scr
= icon
->core
->screen_ptr
;
571 icon
->selected
= !icon
->selected
;
573 if (icon
->selected
) {
575 if (!wPreferences
.dont_blink
)
576 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
578 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
579 icon
->core
->width
- 1, icon
->core
->height
- 1);
581 if (icon
->handlerID
) {
582 WMDeleteTimerHandler(icon
->handlerID
);
583 icon
->handlerID
= NULL
;
585 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
589 static void unset_icon_image(WIcon
*icon
)
596 if (icon
->file_image
) {
597 RReleaseImage(icon
->file_image
);
598 icon
->file_image
= NULL
;
602 void wIconUpdate(WIcon
*icon
)
604 WWindow
*wwin
= icon
->owner
;
606 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
607 /* Forced use user_icon */
608 get_rimage_icon_from_user_icon(icon
);
609 } else if (icon
->icon_win
!= None
) {
610 /* Get the Pixmap from the WIcon */
611 get_rimage_icon_from_icon_win(icon
);
612 } else if (wwin
&& wwin
->net_icon_image
) {
613 /* Use _NET_WM_ICON icon */
614 get_rimage_icon_from_x11(icon
);
615 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
616 /* Get the Pixmap from the wm_hints, else, from the user */
617 if (get_rimage_icon_from_wm_hints(icon
))
618 get_rimage_icon_from_user_icon(icon
);
620 /* Get the Pixmap from the user */
621 get_rimage_icon_from_user_icon(icon
);
624 update_icon_pixmap(icon
);
627 void update_icon_pixmap(WIcon
*icon
)
629 if (icon
->pixmap
!= None
)
630 XFreePixmap(dpy
, icon
->pixmap
);
634 /* Create the pixmap */
635 if (icon
->file_image
)
636 icon_update_pixmap(icon
, icon
->file_image
);
638 /* If dockapp, put inside the icon */
639 if (icon
->icon_win
!= None
) {
640 /* file_image is NULL, because is docked app */
641 icon_update_pixmap(icon
, icon
->file_image
);
642 set_dockapp_in_icon(icon
);
645 /* No pixmap, set default background */
646 if (icon
->pixmap
!= None
)
647 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
650 XClearWindow(dpy
, icon
->core
->window
);
654 static void get_rimage_icon_from_x11(WIcon
*icon
)
656 /* Remove the icon image */
657 unset_icon_image(icon
);
659 /* Set the new icon image */
660 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
663 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
665 if (icon
->file_image
)
668 get_rimage_icon_from_default_icon(icon
);
671 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
673 WScreen
*scr
= icon
->core
->screen_ptr
;
675 /* If the icon don't have image, we should use the default image. */
676 if (!scr
->def_icon_rimage
)
677 scr
->def_icon_rimage
= get_default_image(scr
);
679 /* Remove the icon image */
680 unset_icon_image(icon
);
682 /* Set the new icon image */
683 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
686 /* Get the RImage from the WIcon of the WWindow */
687 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
691 /* Create the new RImage */
692 image
= get_window_image_from_x11(icon
->icon_win
);
694 /* Free the icon info */
695 unset_icon_image(icon
);
697 /* Set the new info */
698 icon
->file_image
= image
;
701 /* Set the dockapp in the WIcon */
702 static void set_dockapp_in_icon(WIcon
*icon
)
704 XWindowAttributes attr
;
705 WScreen
*scr
= icon
->core
->screen_ptr
;
706 int title_height
= WMFontHeight(scr
->icon_title_font
);
707 unsigned int w
, h
, d
;
710 /* Reparent the dock application to the icon */
712 /* We need the application size to center it
713 * and show in the correct position */
714 getSize(icon
->icon_win
, &w
, &h
, &d
);
716 /* Set extra space for title */
717 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
718 theight
= title_height
;
719 drawIconTitle(scr
, icon
->pixmap
, theight
);
721 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
724 /* Set the icon border */
725 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
727 /* Put the dock application in the icon */
728 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
729 (wPreferences
.icon_size
- w
) / 2,
730 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
732 /* Show it and save */
733 XMapWindow(dpy
, icon
->icon_win
);
734 XAddToSaveSet(dpy
, icon
->icon_win
);
736 /* Needed to move the icon clicking on the application part */
737 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
738 (attr
.all_event_masks
& ButtonPressMask
))
739 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
740 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
741 None
, wCursor
[WCUR_ARROW
]);
744 /* Get the RImage from the XWindow wm_hints */
745 static int get_rimage_icon_from_wm_hints(WIcon
*icon
)
747 RImage
*image
= NULL
;
748 unsigned int w
, h
, d
;
749 WWindow
*wwin
= icon
->owner
;
751 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
752 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
756 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
760 /* Resize the icon to the wPreferences.icon_size size */
761 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
763 unset_icon_image(icon
);
764 icon
->file_image
= image
;
769 void wIconPaint(WIcon
*icon
)
771 WScreen
*scr
= icon
->core
->screen_ptr
;
775 XClearWindow(dpy
, icon
->core
->window
);
777 /* draw the icon title */
778 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
779 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
780 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
782 if (w
> icon
->core
->width
- 4)
783 x
= (icon
->core
->width
- 4) - w
;
785 x
= (icon
->core
->width
- w
) / 2;
787 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
788 scr
->icon_title_font
, x
, 1, tmp
, l
);
793 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
794 icon
->core
->width
- 1, icon
->core
->height
- 1);
797 /******************************************************************/
799 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
801 wIconPaint(desc
->parent
);
804 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
806 WIcon
*icon
= desc
->parent
;
808 assert(icon
->owner
!= NULL
);
810 wDeiconifyWindow(icon
->owner
);
813 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
815 WIcon
*icon
= desc
->parent
;
816 WWindow
*wwin
= icon
->owner
;
818 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
819 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
821 int clickButton
= event
->xbutton
.button
;
822 Bool hasMoved
= False
;
824 if (WCHECK_STATE(WSTATE_MODAL
))
827 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
828 miniwindowDblClick(desc
, event
);
832 if (event
->xbutton
.button
== Button1
) {
833 if (event
->xbutton
.state
& MOD_MASK
)
834 wLowerFrame(icon
->core
);
836 wRaiseFrame(icon
->core
);
837 if (event
->xbutton
.state
& ShiftMask
) {
839 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
841 } else if (event
->xbutton
.button
== Button3
) {
842 WObjDescriptor
*desc
;
844 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
846 /* allow drag select of menu */
847 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
848 event
->xbutton
.send_event
= True
;
849 (*desc
->handle_mousedown
) (desc
, event
);
854 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
855 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
856 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
859 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
860 | ButtonMotionMask
| ExposureMask
, &ev
);
869 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
870 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
871 XChangeActivePointerGrab(dpy
, ButtonMotionMask
872 | ButtonReleaseMask
| ButtonPressMask
,
873 wCursor
[WCUR_MOVE
], CurrentTime
);
879 x
= ev
.xmotion
.x_root
- dx
;
880 y
= ev
.xmotion
.y_root
- dy
;
881 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
888 if (ev
.xbutton
.button
!= clickButton
)
891 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
892 wwin
->flags
.icon_moved
= 1;
894 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
898 XUngrabPointer(dpy
, CurrentTime
);
900 if (wPreferences
.auto_arrange_icons
)
901 wArrangeIcons(wwin
->screen_ptr
, True
);
902 if (wPreferences
.single_click
&& !hasMoved
)
903 miniwindowDblClick(desc
, event
);