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_rimage_icon_from_user_icon(WIcon
*icon
);
67 static void get_pixmap_icon_from_default_icon(WIcon
*icon
);
68 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
70 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
71 static void unset_icon_image(WIcon
*icon
);
73 static RImage
*get_default_image(WScreen
*scr
);
74 /****** Notification Observers ******/
76 static void appearanceObserver(void *self
, WMNotification
* notif
)
78 WIcon
*icon
= (WIcon
*) self
;
79 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
81 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
82 icon
->force_paint
= 1;
86 /* so that the appicon expose handlers will paint the appicon specific
88 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
91 static void tileObserver(void *self
, WMNotification
* notif
)
93 WIcon
*icon
= (WIcon
*) self
;
95 icon
->force_paint
= 1;
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_default_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
;
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_default_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
;
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 icon
->force_paint
= 1;
352 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
359 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
360 if ((icon
->width
- max_size
) > -ICON_BORDER
||
361 (icon
->height
- max_size
) > -ICON_BORDER
) {
362 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
363 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
371 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
373 WScreen
*scr
= icon
->core
->screen_ptr
;
375 RImage
*image
= NULL
;
378 /* If no new image, don't do nothing */
382 /* Find the new image */
383 path
= FindImage(wPreferences
.icon_path
, file
);
385 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
390 if (!error
&& image
) {
391 /* Remove the old one */
392 unset_icon_image(icon
);
394 /* Set the new image */
395 icon
->file_image
= image
;
396 icon
->file
= wstrdup(path
);
408 static char *get_name_for_wwin(WWindow
*wwin
)
410 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
413 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
418 if (wm_class
&& wm_instance
) {
419 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
420 suffix
= wmalloc(len
);
421 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
422 } else if (wm_class
) {
423 len
= strlen(wm_class
) + 1;
424 suffix
= wmalloc(len
);
425 snprintf(suffix
, len
, "%s", wm_class
);
426 } else if (wm_instance
) {
427 len
= strlen(wm_instance
) + 1;
428 suffix
= wmalloc(len
);
429 snprintf(suffix
, len
, "%s", wm_instance
);
437 static char *get_icon_cache_path(void)
442 prefix
= wusergnusteppath();
443 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
445 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
447 /* If the folder exists, exit */
448 if (access(path
, F_OK
) == 0)
451 /* Create the folder */
452 ret
= wmkdirhier((const char *) path
);
454 /* Exit 1 on success, 0 on failure */
463 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
465 RImage
*image
= NULL
;
466 XWMHints
*hints
= wwin
->wm_hints
;
468 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
469 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
471 (hints
->flags
& IconMaskHint
)
472 ? hints
->icon_mask
: None
);
479 * Stores the client supplied icon at CACHE_ICON_PATH
480 * and returns the path for that icon. Returns NULL if there is no
481 * client supplied icon or on failure.
484 * New directories might be created.
486 char *wIconStore(WIcon
* icon
)
488 char *path
, *dir_path
, *file
;
490 RImage
*image
= NULL
;
491 WWindow
*wwin
= icon
->owner
;
496 dir_path
= get_icon_cache_path();
500 file
= get_name_for_wwin(wwin
);
506 len
= strlen(dir_path
) + strlen(file
) + 5;
508 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
512 /* If icon exists, exit */
513 if (access(path
, F_OK
) == 0)
516 if (wwin
->net_icon_image
)
517 image
= RRetainImage(wwin
->net_icon_image
);
519 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
526 if (!RSaveImage(image
, path
, "XPM")) {
531 RReleaseImage(image
);
536 static void cycleColor(void *data
)
538 WIcon
*icon
= (WIcon
*) data
;
539 WScreen
*scr
= icon
->core
->screen_ptr
;
543 gcv
.dash_offset
= icon
->step
;
544 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
546 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
547 icon
->core
->width
- 1, icon
->core
->height
- 1);
548 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
552 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
554 if (icon
->highlighted
== flag
)
557 icon
->highlighted
= flag
;
558 icon
->force_paint
= True
;
563 void wIconSelect(WIcon
* icon
)
565 WScreen
*scr
= icon
->core
->screen_ptr
;
566 icon
->selected
= !icon
->selected
;
568 if (icon
->selected
) {
570 if (!wPreferences
.dont_blink
)
571 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
573 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
574 icon
->core
->width
- 1, icon
->core
->height
- 1);
576 if (icon
->handlerID
) {
577 WMDeleteTimerHandler(icon
->handlerID
);
578 icon
->handlerID
= NULL
;
580 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
584 static void unset_icon_image(WIcon
*icon
)
589 if (icon
->file_image
)
590 RReleaseImage(icon
->file_image
);
593 void wIconUpdate(WIcon
*icon
)
595 WScreen
*scr
= icon
->core
->screen_ptr
;
596 WWindow
*wwin
= icon
->owner
;
598 assert(scr
->icon_tile
!= NULL
);
600 if (icon
->pixmap
!= None
)
601 XFreePixmap(dpy
, icon
->pixmap
);
605 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
606 /* Forced use user_icon */
607 get_pixmap_icon_from_user_icon(icon
);
608 } else if (icon
->icon_win
!= None
) {
609 /* Get the Pixmap from the WIcon */
610 get_pixmap_icon_from_icon_win(icon
);
611 } else if (wwin
&& wwin
->net_icon_image
) {
612 /* Use _NET_WM_ICON icon */
613 icon_update_pixmap(icon
, wwin
->net_icon_image
);
614 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
615 /* Get the Pixmap from the wm_hints, else, from the user */
616 if (get_pixmap_icon_from_wm_hints(icon
))
617 get_pixmap_icon_from_user_icon(icon
);
619 /* Get the Pixmap from the user */
620 get_pixmap_icon_from_user_icon(icon
);
623 /* No pixmap, set default background */
624 if (icon
->pixmap
!= None
)
625 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
628 XClearWindow(dpy
, icon
->core
->window
);
632 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
634 if (icon
->file_image
)
637 get_rimage_icon_from_default_icon(icon
);
640 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
642 /* Set the icon->file_image */
643 get_rimage_icon_from_user_icon(icon
);
645 /* Update icon->pixmap */
646 icon_update_pixmap(icon
, icon
->file_image
);
649 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
651 WScreen
*scr
= icon
->core
->screen_ptr
;
653 /* If the icon don't have image, we should use the default image. */
654 if (!scr
->def_icon_rimage
)
655 scr
->def_icon_rimage
= get_default_image(scr
);
657 /* Remove the icon image */
658 unset_icon_image(icon
);
660 /* Set the new icon image */
662 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
665 static void get_pixmap_icon_from_default_icon(WIcon
*icon
)
667 /* Update icon->file image */
668 get_rimage_icon_from_default_icon(icon
);
670 /* Now, create the pixmap using the default (saved) image */
671 icon_update_pixmap(icon
, icon
->file_image
);
674 /* This function creates the RImage using the default icon */
675 static RImage
*get_default_image(WScreen
*scr
)
677 RImage
*image
= NULL
;
680 /* Get the default icon */
681 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
683 path
= FindImage(wPreferences
.icon_path
, file
);
684 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
687 wwarning(_("could not find default icon \"%s\""), file
);
695 /* Get the Pixmap from the WIcon of the WWindow */
696 static void get_pixmap_icon_from_icon_win(WIcon
* icon
)
698 XWindowAttributes attr
;
699 WScreen
*scr
= icon
->core
->screen_ptr
;
700 int title_height
= WMFontHeight(scr
->icon_title_font
);
701 unsigned int width
, height
, depth
;
706 getSize(icon
->icon_win
, &width
, &height
, &depth
);
708 if (width
> wPreferences
.icon_size
) {
710 width
= wPreferences
.icon_size
;
713 if (height
> wPreferences
.icon_size
) {
715 height
= wPreferences
.icon_size
;
718 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
719 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
720 wPreferences
.icon_size
, scr
->w_depth
);
721 XSetClipMask(dpy
, scr
->copy_gc
, None
);
722 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
723 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
724 drawIconTitle(scr
, pixmap
, title_height
);
725 theight
= title_height
;
729 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
732 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
733 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
734 (wPreferences
.icon_size
- width
) / 2,
735 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
737 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
739 XMapWindow(dpy
, icon
->icon_win
);
740 XAddToSaveSet(dpy
, icon
->icon_win
);
743 icon
->pixmap
= pixmap
;
745 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
746 (attr
.all_event_masks
& ButtonPressMask
))
747 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
748 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
749 None
, wCursor
[WCUR_ARROW
]);
752 /* Get the Pixmap from the XWindow wm_hints */
753 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
755 RImage
*image
= NULL
;
756 unsigned int w
, h
, d
;
757 WWindow
*wwin
= icon
->owner
;
759 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
760 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
764 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
768 icon_update_pixmap(icon
, image
);
773 void wIconPaint(WIcon
* icon
)
775 WScreen
*scr
= icon
->core
->screen_ptr
;
779 if (icon
->force_paint
) {
780 icon
->force_paint
= 0;
785 XClearWindow(dpy
, icon
->core
->window
);
787 /* draw the icon title */
788 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
792 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
793 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
795 if (w
> icon
->core
->width
- 4)
796 x
= (icon
->core
->width
- 4) - w
;
798 x
= (icon
->core
->width
- w
) / 2;
800 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
801 scr
->icon_title_font
, x
, 1, tmp
, l
);
806 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
807 icon
->core
->width
- 1, icon
->core
->height
- 1);
810 /******************************************************************/
812 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
814 wIconPaint(desc
->parent
);
817 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
819 WIcon
*icon
= desc
->parent
;
821 assert(icon
->owner
!= NULL
);
823 wDeiconifyWindow(icon
->owner
);
826 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
828 WIcon
*icon
= desc
->parent
;
829 WWindow
*wwin
= icon
->owner
;
831 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
832 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
834 int clickButton
= event
->xbutton
.button
;
835 Bool hasMoved
= False
;
837 if (WCHECK_STATE(WSTATE_MODAL
))
840 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
841 miniwindowDblClick(desc
, event
);
845 if (event
->xbutton
.button
== Button1
) {
846 if (event
->xbutton
.state
& MOD_MASK
)
847 wLowerFrame(icon
->core
);
849 wRaiseFrame(icon
->core
);
850 if (event
->xbutton
.state
& ShiftMask
) {
852 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
854 } else if (event
->xbutton
.button
== Button3
) {
855 WObjDescriptor
*desc
;
857 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
859 /* allow drag select of menu */
860 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
861 event
->xbutton
.send_event
= True
;
862 (*desc
->handle_mousedown
) (desc
, event
);
867 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
868 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
869 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
872 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
873 | ButtonMotionMask
| ExposureMask
, &ev
);
882 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
883 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
884 XChangeActivePointerGrab(dpy
, ButtonMotionMask
885 | ButtonReleaseMask
| ButtonPressMask
,
886 wCursor
[WCUR_MOVE
], CurrentTime
);
892 x
= ev
.xmotion
.x_root
- dx
;
893 y
= ev
.xmotion
.y_root
- dy
;
894 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
901 if (ev
.xbutton
.button
!= clickButton
)
904 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
905 wwin
->flags
.icon_moved
= 1;
907 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
911 XUngrabPointer(dpy
, CurrentTime
);
913 if (wPreferences
.auto_arrange_icons
)
914 wArrangeIcons(wwin
->screen_ptr
, True
);
915 if (wPreferences
.single_click
&& !hasMoved
)
916 miniwindowDblClick(desc
, event
);