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
);
67 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
69 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
70 static void unset_icon_image(WIcon
*icon
);
72 static RImage
*get_default_image(WScreen
*scr
);
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 (icon
->pixmap
!= None
)
600 XFreePixmap(dpy
, icon
->pixmap
);
604 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
605 /* Forced use user_icon */
606 get_pixmap_icon_from_user_icon(icon
);
607 } else if (icon
->icon_win
!= None
) {
608 /* Get the Pixmap from the WIcon */
609 get_pixmap_icon_from_icon_win(icon
);
610 } else if (wwin
&& wwin
->net_icon_image
) {
611 /* Use _NET_WM_ICON icon */
612 icon_update_pixmap(icon
, wwin
->net_icon_image
);
613 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
614 /* Get the Pixmap from the wm_hints, else, from the user */
615 if (get_pixmap_icon_from_wm_hints(icon
))
616 get_pixmap_icon_from_user_icon(icon
);
618 /* Get the Pixmap from the user */
619 get_pixmap_icon_from_user_icon(icon
);
622 /* No pixmap, set default background */
623 if (icon
->pixmap
!= None
)
624 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
627 XClearWindow(dpy
, icon
->core
->window
);
631 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
633 /* If the icon has image, update it and continue */
634 if (icon
->file_image
) {
635 icon_update_pixmap(icon
, icon
->file_image
);
639 get_pixmap_icon_from_default_icon(icon
);
642 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
644 WScreen
*scr
= icon
->core
->screen_ptr
;
646 /* If the icon don't have image, we should use the default image. */
647 if (!scr
->def_icon_rimage
)
648 scr
->def_icon_rimage
= get_default_image(scr
);
650 /* Remove the icon image */
651 unset_icon_image(icon
);
653 /* Set the new icon image */
655 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
658 static void get_pixmap_icon_from_default_icon(WIcon
*icon
)
660 /* Update icon->file image */
661 get_rimage_icon_from_default_icon(icon
);
663 /* Now, create the pixmap using the default (saved) image */
664 icon_update_pixmap(icon
, icon
->file_image
);
667 /* This function creates the RImage using the default icon */
668 static RImage
*get_default_image(WScreen
*scr
)
670 RImage
*image
= NULL
;
673 /* Get the default icon */
674 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
676 path
= FindImage(wPreferences
.icon_path
, file
);
677 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
680 wwarning(_("could not find default icon \"%s\""), file
);
688 /* Get the Pixmap from the WIcon of the WWindow */
689 static void get_pixmap_icon_from_icon_win(WIcon
* icon
)
691 XWindowAttributes attr
;
692 WScreen
*scr
= icon
->core
->screen_ptr
;
693 int title_height
= WMFontHeight(scr
->icon_title_font
);
694 unsigned int width
, height
, depth
;
699 getSize(icon
->icon_win
, &width
, &height
, &depth
);
701 if (width
> wPreferences
.icon_size
) {
703 width
= wPreferences
.icon_size
;
706 if (height
> wPreferences
.icon_size
) {
708 height
= wPreferences
.icon_size
;
711 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
712 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
713 wPreferences
.icon_size
, scr
->w_depth
);
714 XSetClipMask(dpy
, scr
->copy_gc
, None
);
715 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
716 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
717 drawIconTitle(scr
, pixmap
, title_height
);
718 theight
= title_height
;
722 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
725 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
726 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
727 (wPreferences
.icon_size
- width
) / 2,
728 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
730 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
732 XMapWindow(dpy
, icon
->icon_win
);
733 XAddToSaveSet(dpy
, icon
->icon_win
);
736 icon
->pixmap
= pixmap
;
738 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
739 (attr
.all_event_masks
& ButtonPressMask
))
740 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
741 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
742 None
, wCursor
[WCUR_ARROW
]);
745 /* Get the Pixmap from the XWindow wm_hints */
746 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
748 RImage
*image
= NULL
;
749 unsigned int w
, h
, d
;
750 WWindow
*wwin
= icon
->owner
;
752 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
753 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
757 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
761 icon_update_pixmap(icon
, image
);
766 void wIconPaint(WIcon
* icon
)
768 WScreen
*scr
= icon
->core
->screen_ptr
;
772 if (icon
->force_paint
) {
773 icon
->force_paint
= 0;
778 XClearWindow(dpy
, icon
->core
->window
);
780 /* draw the icon title */
781 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
785 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
786 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
788 if (w
> icon
->core
->width
- 4)
789 x
= (icon
->core
->width
- 4) - w
;
791 x
= (icon
->core
->width
- w
) / 2;
793 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
794 scr
->icon_title_font
, x
, 1, tmp
, l
);
799 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
800 icon
->core
->width
- 1, icon
->core
->height
- 1);
803 /******************************************************************/
805 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
807 wIconPaint(desc
->parent
);
810 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
812 WIcon
*icon
= desc
->parent
;
814 assert(icon
->owner
!= NULL
);
816 wDeiconifyWindow(icon
->owner
);
819 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
821 WIcon
*icon
= desc
->parent
;
822 WWindow
*wwin
= icon
->owner
;
824 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
825 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
827 int clickButton
= event
->xbutton
.button
;
828 Bool hasMoved
= False
;
830 if (WCHECK_STATE(WSTATE_MODAL
))
833 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
834 miniwindowDblClick(desc
, event
);
838 if (event
->xbutton
.button
== Button1
) {
839 if (event
->xbutton
.state
& MOD_MASK
)
840 wLowerFrame(icon
->core
);
842 wRaiseFrame(icon
->core
);
843 if (event
->xbutton
.state
& ShiftMask
) {
845 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
847 } else if (event
->xbutton
.button
== Button3
) {
848 WObjDescriptor
*desc
;
850 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
852 /* allow drag select of menu */
853 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
854 event
->xbutton
.send_event
= True
;
855 (*desc
->handle_mousedown
) (desc
, event
);
860 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
861 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
862 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
865 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
866 | ButtonMotionMask
| ExposureMask
, &ev
);
875 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
876 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
877 XChangeActivePointerGrab(dpy
, ButtonMotionMask
878 | ButtonReleaseMask
| ButtonPressMask
,
879 wCursor
[WCUR_MOVE
], CurrentTime
);
885 x
= ev
.xmotion
.x_root
- dx
;
886 y
= ev
.xmotion
.y_root
- dy
;
887 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
894 if (ev
.xbutton
.button
!= clickButton
)
897 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
898 wwin
->flags
.icon_moved
= 1;
900 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
904 XUngrabPointer(dpy
, CurrentTime
);
906 if (wPreferences
.auto_arrange_icons
)
907 wArrangeIcons(wwin
->screen_ptr
, True
);
908 if (wPreferences
.single_click
&& !hasMoved
)
909 miniwindowDblClick(desc
, event
);