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 void get_rimage_icon_from_user_icon(WIcon
*icon
);
66 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
67 static void get_rimage_icon_from_x11(WIcon
*icon
);
69 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
70 static void unset_icon_image(WIcon
*icon
);
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 /* If the rimage exists, update the icon, else create it */
82 update_icon_pixmap(icon
);
87 /* so that the appicon expose handlers will paint the appicon specific
89 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
92 static void tileObserver(void *self
, WMNotification
*notif
)
94 WIcon
*icon
= (WIcon
*) self
;
96 wIconUpdate(icon
, NULL
);
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
;
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 icon
->tile_type
= TILE_NORMAL
;
145 set_icon_image_from_database(icon
, wwin
->wm_instance
, wwin
->wm_class
, NULL
);
147 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
148 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
153 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
157 icon
= icon_create_core(scr
, 0, 0);
158 icon
->tile_type
= tile
;
160 set_icon_image_from_database(icon
, wm_instance
, wm_class
, command
);
162 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
163 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
168 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
172 icon
= wmalloc(sizeof(WIcon
));
173 icon
->core
= wCoreCreateTopLevel(scr
,
176 wPreferences
.icon_size
,
177 wPreferences
.icon_size
,
178 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
,
181 /* will be overriden if this is a application icon */
182 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
183 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
184 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
185 icon
->core
->descriptor
.parent
= icon
;
187 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
188 icon
->core
->stacking
->above
= NULL
;
189 icon
->core
->stacking
->under
= NULL
;
190 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
191 icon
->core
->stacking
->child_of
= NULL
;
195 icon
->file_image
= NULL
;
200 void wIconDestroy(WIcon
* icon
)
202 WCoreWindow
*core
= icon
->core
;
203 WScreen
*scr
= core
->screen_ptr
;
205 WMRemoveNotificationObserver(icon
);
208 WMDeleteTimerHandler(icon
->handlerID
);
210 if (icon
->icon_win
) {
214 x
= icon
->owner
->icon_x
;
215 y
= icon
->owner
->icon_y
;
217 XUnmapWindow(dpy
, icon
->icon_win
);
218 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
221 XFree(icon
->icon_name
);
224 XFreePixmap(dpy
, icon
->pixmap
);
226 unset_icon_image(icon
);
228 wCoreDestroy(icon
->core
);
232 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
234 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
235 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
236 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
237 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
238 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
241 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
248 WScreen
*scr
= icon
->core
->screen_ptr
;
249 int titled
= icon
->show_title
;
251 if (icon
->tile_type
== TILE_NORMAL
) {
252 tile
= RCloneImage(scr
->icon_tile
);
254 assert(scr
->clip_tile
);
255 tile
= RCloneImage(scr
->clip_tile
);
259 w
= (image
->width
> wPreferences
.icon_size
)
260 ? wPreferences
.icon_size
: image
->width
;
261 x
= (wPreferences
.icon_size
- w
) / 2;
262 sx
= (image
->width
- w
) / 2;
265 theight
= WMFontHeight(scr
->icon_title_font
);
267 h
= (image
->height
+ theight
> wPreferences
.icon_size
268 ? wPreferences
.icon_size
- theight
: image
->height
);
269 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
270 sy
= (image
->height
- h
) / 2;
272 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
275 if (icon
->shadowed
) {
278 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
279 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
280 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
281 color
.alpha
= 150; /* about 60% */
282 RClearImage(tile
, &color
);
285 if (icon
->highlighted
) {
288 color
.red
= color
.green
= color
.blue
= 0;
290 RLightImage(tile
, &color
);
293 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
294 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
299 drawIconTitle(scr
, pixmap
, theight
);
301 icon
->pixmap
= pixmap
;
304 void wIconChangeTitle(WIcon
*icon
, char *new_title
)
308 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
) ||
309 (new_title
!= NULL
&& icon
->icon_name
== NULL
);
311 if (icon
->icon_name
!= NULL
)
312 XFree(icon
->icon_name
);
314 icon
->icon_name
= new_title
;
317 wIconUpdate(icon
, NULL
);
322 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
329 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
330 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
331 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
332 if (icon
->width
> icon
->height
)
333 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
334 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
336 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
337 max_size
- ICON_BORDER
);
345 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
347 WScreen
*scr
= icon
->core
->screen_ptr
;
349 RImage
*image
= NULL
;
352 /* If no new image, don't do nothing */
356 /* Find the new image */
357 path
= FindImage(wPreferences
.icon_path
, file
);
359 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
364 if (!error
&& image
) {
365 /* Set the new image */
366 set_icon_image_from_image(icon
, image
);
367 icon
->file
= wstrdup(path
);
368 update_icon_pixmap(icon
);
379 static char *get_name_for_wwin(WWindow
*wwin
)
381 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
384 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
389 if (wm_class
&& wm_instance
) {
390 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
391 suffix
= wmalloc(len
);
392 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
393 } else if (wm_class
) {
394 len
= strlen(wm_class
) + 1;
395 suffix
= wmalloc(len
);
396 snprintf(suffix
, len
, "%s", wm_class
);
397 } else if (wm_instance
) {
398 len
= strlen(wm_instance
) + 1;
399 suffix
= wmalloc(len
);
400 snprintf(suffix
, len
, "%s", wm_instance
);
408 static char *get_icon_cache_path(void)
413 prefix
= wusergnusteppath();
414 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
416 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
418 /* If the folder exists, exit */
419 if (access(path
, F_OK
) == 0)
422 /* Create the folder */
423 ret
= wmkdirhier((const char *) path
);
425 /* Exit 1 on success, 0 on failure */
434 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
436 RImage
*image
= NULL
;
437 XWMHints
*hints
= wwin
->wm_hints
;
439 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
440 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
442 (hints
->flags
& IconMaskHint
)
443 ? hints
->icon_mask
: None
);
450 * Stores the client supplied icon at CACHE_ICON_PATH
451 * and returns the path for that icon. Returns NULL if there is no
452 * client supplied icon or on failure.
455 * New directories might be created.
457 char *wIconStore(WIcon
* icon
)
459 char *path
, *dir_path
, *file
;
461 RImage
*image
= NULL
;
462 WWindow
*wwin
= icon
->owner
;
467 dir_path
= get_icon_cache_path();
471 file
= get_name_for_wwin(wwin
);
477 len
= strlen(dir_path
) + strlen(file
) + 5;
479 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
483 /* If icon exists, exit */
484 if (access(path
, F_OK
) == 0)
487 if (wwin
->net_icon_image
)
488 image
= RRetainImage(wwin
->net_icon_image
);
490 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
497 if (!RSaveImage(image
, path
, "XPM")) {
502 RReleaseImage(image
);
507 static void cycleColor(void *data
)
509 WIcon
*icon
= (WIcon
*) data
;
510 WScreen
*scr
= icon
->core
->screen_ptr
;
514 gcv
.dash_offset
= icon
->step
;
515 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
517 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
518 icon
->core
->width
- 1, icon
->core
->height
- 1);
519 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
522 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
524 if (icon
->highlighted
== flag
)
527 icon
->highlighted
= flag
;
528 update_icon_pixmap(icon
);
531 void wIconSelect(WIcon
* icon
)
533 WScreen
*scr
= icon
->core
->screen_ptr
;
534 icon
->selected
= !icon
->selected
;
536 if (icon
->selected
) {
538 if (!wPreferences
.dont_blink
)
539 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
541 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
542 icon
->core
->width
- 1, icon
->core
->height
- 1);
544 if (icon
->handlerID
) {
545 WMDeleteTimerHandler(icon
->handlerID
);
546 icon
->handlerID
= NULL
;
548 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
552 static void unset_icon_image(WIcon
*icon
)
559 if (icon
->file_image
) {
560 RReleaseImage(icon
->file_image
);
561 icon
->file_image
= NULL
;
565 void set_icon_image_from_image(WIcon
*icon
, RImage
*image
)
570 unset_icon_image(icon
);
572 icon
->file_image
= NULL
;
573 icon
->file_image
= image
;
576 void wIconUpdate(WIcon
*icon
, RImage
*image
)
578 WWindow
*wwin
= NULL
;
581 icon
->file_image
= image
;
583 if (icon
&& icon
->owner
)
586 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
587 /* Forced use user_icon */
588 get_rimage_icon_from_user_icon(icon
);
589 } else if (icon
->icon_win
!= None
) {
590 /* Get the Pixmap from the WIcon */
591 get_rimage_icon_from_icon_win(icon
);
592 } else if (wwin
&& wwin
->net_icon_image
) {
593 /* Use _NET_WM_ICON icon */
594 get_rimage_icon_from_x11(icon
);
595 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
596 /* Get the Pixmap from the wm_hints, else, from the user */
597 unset_icon_image(icon
);
598 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
599 if (!icon
->file_image
)
600 get_rimage_icon_from_user_icon(icon
);
602 /* Get the Pixmap from the user */
603 get_rimage_icon_from_user_icon(icon
);
607 update_icon_pixmap(icon
);
610 void update_icon_pixmap(WIcon
*icon
)
612 if (icon
->pixmap
!= None
)
613 XFreePixmap(dpy
, icon
->pixmap
);
617 /* Create the pixmap */
618 if (icon
->file_image
)
619 icon_update_pixmap(icon
, icon
->file_image
);
621 /* If dockapp, put inside the icon */
622 if (icon
->icon_win
!= None
) {
623 /* file_image is NULL, because is docked app */
624 icon_update_pixmap(icon
, NULL
);
625 set_dockapp_in_icon(icon
);
628 /* No pixmap, set default background */
629 if (icon
->pixmap
!= None
)
630 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
636 static void get_rimage_icon_from_x11(WIcon
*icon
)
638 /* Remove the icon image */
639 unset_icon_image(icon
);
641 /* Set the new icon image */
642 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
645 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
647 if (icon
->file_image
)
650 get_rimage_icon_from_default_icon(icon
);
653 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
655 WScreen
*scr
= icon
->core
->screen_ptr
;
657 /* If the icon don't have image, we should use the default image. */
658 if (!scr
->def_icon_rimage
)
659 scr
->def_icon_rimage
= get_default_image(scr
);
661 /* Remove the icon image */
662 unset_icon_image(icon
);
664 /* Set the new icon image */
665 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
668 /* Get the RImage from the WIcon of the WWindow */
669 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
673 /* Create the new RImage */
674 image
= get_window_image_from_x11(icon
->icon_win
);
676 /* Free the icon info */
677 unset_icon_image(icon
);
679 /* Set the new info */
680 icon
->file_image
= image
;
683 /* Set the dockapp in the WIcon */
684 static void set_dockapp_in_icon(WIcon
*icon
)
686 XWindowAttributes attr
;
687 WScreen
*scr
= icon
->core
->screen_ptr
;
688 int title_height
= WMFontHeight(scr
->icon_title_font
);
689 unsigned int w
, h
, d
;
692 /* Reparent the dock application to the icon */
694 /* We need the application size to center it
695 * and show in the correct position */
696 getSize(icon
->icon_win
, &w
, &h
, &d
);
698 /* Set extra space for title */
699 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
700 theight
= title_height
;
701 drawIconTitle(scr
, icon
->pixmap
, theight
);
703 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
706 /* Set the icon border */
707 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
709 /* Put the dock application in the icon */
710 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
711 (wPreferences
.icon_size
- w
) / 2,
712 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
714 /* Show it and save */
715 XMapWindow(dpy
, icon
->icon_win
);
716 XAddToSaveSet(dpy
, icon
->icon_win
);
718 /* Needed to move the icon clicking on the application part */
719 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
720 (attr
.all_event_masks
& ButtonPressMask
))
721 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
722 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
723 None
, wCursor
[WCUR_ARROW
]);
726 /* Get the RImage from the XWindow wm_hints */
727 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
729 RImage
*image
= NULL
;
730 unsigned int w
, h
, d
;
731 WWindow
*wwin
= icon
->owner
;
733 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
734 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
738 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
742 /* Resize the icon to the wPreferences.icon_size size */
743 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
748 void wIconPaint(WIcon
*icon
)
750 WScreen
*scr
= icon
->core
->screen_ptr
;
754 XClearWindow(dpy
, icon
->core
->window
);
756 /* draw the icon title */
757 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
758 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
759 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
761 if (w
> icon
->core
->width
- 4)
762 x
= (icon
->core
->width
- 4) - w
;
764 x
= (icon
->core
->width
- w
) / 2;
766 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
767 scr
->icon_title_font
, x
, 1, tmp
, l
);
772 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
773 icon
->core
->width
- 1, icon
->core
->height
- 1);
776 /******************************************************************/
778 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
780 wIconPaint(desc
->parent
);
783 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
785 WIcon
*icon
= desc
->parent
;
787 assert(icon
->owner
!= NULL
);
789 wDeiconifyWindow(icon
->owner
);
792 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
794 WIcon
*icon
= desc
->parent
;
795 WWindow
*wwin
= icon
->owner
;
797 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
798 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
800 int clickButton
= event
->xbutton
.button
;
801 Bool hasMoved
= False
;
803 if (WCHECK_STATE(WSTATE_MODAL
))
806 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
807 miniwindowDblClick(desc
, event
);
811 if (event
->xbutton
.button
== Button1
) {
812 if (event
->xbutton
.state
& MOD_MASK
)
813 wLowerFrame(icon
->core
);
815 wRaiseFrame(icon
->core
);
816 if (event
->xbutton
.state
& ShiftMask
) {
818 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
820 } else if (event
->xbutton
.button
== Button3
) {
821 WObjDescriptor
*desc
;
823 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
825 /* allow drag select of menu */
826 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
827 event
->xbutton
.send_event
= True
;
828 (*desc
->handle_mousedown
) (desc
, event
);
833 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
834 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
835 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
838 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
839 | ButtonMotionMask
| ExposureMask
, &ev
);
848 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
849 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
850 XChangeActivePointerGrab(dpy
, ButtonMotionMask
851 | ButtonReleaseMask
| ButtonPressMask
,
852 wCursor
[WCUR_MOVE
], CurrentTime
);
858 x
= ev
.xmotion
.x_root
- dx
;
859 y
= ev
.xmotion
.y_root
- dy
;
860 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
867 if (ev
.xbutton
.button
!= clickButton
)
870 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
871 wwin
->flags
.icon_moved
= 1;
873 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
877 XUngrabPointer(dpy
, CurrentTime
);
879 if (wPreferences
.auto_arrange_icons
)
880 wArrangeIcons(wwin
->screen_ptr
, True
);
881 if (wPreferences
.single_click
&& !hasMoved
)
882 miniwindowDblClick(desc
, event
);
889 void set_icon_image_from_database(WIcon
*icon
, char *wm_instance
, char *wm_class
, char *command
)
893 file
= get_icon_filename(icon
->core
->screen_ptr
, wm_instance
, wm_class
, command
, False
);
895 icon
->file
= wstrdup(file
);
896 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);
900 wIconUpdate(icon
, NULL
);