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 /* Remove the old one */
366 unset_icon_image(icon
);
368 /* Set the new image */
369 icon
->file
= wstrdup(path
);
370 wIconUpdate(icon
, image
);
381 static char *get_name_for_wwin(WWindow
*wwin
)
383 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
386 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
391 if (wm_class
&& wm_instance
) {
392 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
393 suffix
= wmalloc(len
);
394 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
395 } else if (wm_class
) {
396 len
= strlen(wm_class
) + 1;
397 suffix
= wmalloc(len
);
398 snprintf(suffix
, len
, "%s", wm_class
);
399 } else if (wm_instance
) {
400 len
= strlen(wm_instance
) + 1;
401 suffix
= wmalloc(len
);
402 snprintf(suffix
, len
, "%s", wm_instance
);
410 static char *get_icon_cache_path(void)
415 prefix
= wusergnusteppath();
416 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
418 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
420 /* If the folder exists, exit */
421 if (access(path
, F_OK
) == 0)
424 /* Create the folder */
425 ret
= wmkdirhier((const char *) path
);
427 /* Exit 1 on success, 0 on failure */
436 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
438 RImage
*image
= NULL
;
439 XWMHints
*hints
= wwin
->wm_hints
;
441 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
442 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
444 (hints
->flags
& IconMaskHint
)
445 ? hints
->icon_mask
: None
);
452 * Stores the client supplied icon at CACHE_ICON_PATH
453 * and returns the path for that icon. Returns NULL if there is no
454 * client supplied icon or on failure.
457 * New directories might be created.
459 char *wIconStore(WIcon
* icon
)
461 char *path
, *dir_path
, *file
;
463 RImage
*image
= NULL
;
464 WWindow
*wwin
= icon
->owner
;
469 dir_path
= get_icon_cache_path();
473 file
= get_name_for_wwin(wwin
);
479 len
= strlen(dir_path
) + strlen(file
) + 5;
481 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
485 /* If icon exists, exit */
486 if (access(path
, F_OK
) == 0)
489 if (wwin
->net_icon_image
)
490 image
= RRetainImage(wwin
->net_icon_image
);
492 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
499 if (!RSaveImage(image
, path
, "XPM")) {
504 RReleaseImage(image
);
509 static void cycleColor(void *data
)
511 WIcon
*icon
= (WIcon
*) data
;
512 WScreen
*scr
= icon
->core
->screen_ptr
;
516 gcv
.dash_offset
= icon
->step
;
517 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
519 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
520 icon
->core
->width
- 1, icon
->core
->height
- 1);
521 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
524 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
526 if (icon
->highlighted
== flag
)
529 icon
->highlighted
= flag
;
530 update_icon_pixmap(icon
);
533 void wIconSelect(WIcon
* icon
)
535 WScreen
*scr
= icon
->core
->screen_ptr
;
536 icon
->selected
= !icon
->selected
;
538 if (icon
->selected
) {
540 if (!wPreferences
.dont_blink
)
541 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
543 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
544 icon
->core
->width
- 1, icon
->core
->height
- 1);
546 if (icon
->handlerID
) {
547 WMDeleteTimerHandler(icon
->handlerID
);
548 icon
->handlerID
= NULL
;
550 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
554 static void unset_icon_image(WIcon
*icon
)
561 if (icon
->file_image
) {
562 RReleaseImage(icon
->file_image
);
563 icon
->file_image
= NULL
;
567 void wIconUpdate(WIcon
*icon
, RImage
*image
)
569 WWindow
*wwin
= NULL
;
572 icon
->file_image
= image
;
574 if (icon
&& icon
->owner
)
577 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
578 /* Forced use user_icon */
579 get_rimage_icon_from_user_icon(icon
);
580 } else if (icon
->icon_win
!= None
) {
581 /* Get the Pixmap from the WIcon */
582 get_rimage_icon_from_icon_win(icon
);
583 } else if (wwin
&& wwin
->net_icon_image
) {
584 /* Use _NET_WM_ICON icon */
585 get_rimage_icon_from_x11(icon
);
586 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
587 /* Get the Pixmap from the wm_hints, else, from the user */
588 unset_icon_image(icon
);
589 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
590 if (!icon
->file_image
)
591 get_rimage_icon_from_user_icon(icon
);
593 /* Get the Pixmap from the user */
594 get_rimage_icon_from_user_icon(icon
);
598 update_icon_pixmap(icon
);
601 void update_icon_pixmap(WIcon
*icon
)
603 if (icon
->pixmap
!= None
)
604 XFreePixmap(dpy
, icon
->pixmap
);
608 /* Create the pixmap */
609 if (icon
->file_image
)
610 icon_update_pixmap(icon
, icon
->file_image
);
612 /* If dockapp, put inside the icon */
613 if (icon
->icon_win
!= None
) {
614 /* file_image is NULL, because is docked app */
615 icon_update_pixmap(icon
, NULL
);
616 set_dockapp_in_icon(icon
);
619 /* No pixmap, set default background */
620 if (icon
->pixmap
!= None
)
621 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
627 static void get_rimage_icon_from_x11(WIcon
*icon
)
629 /* Remove the icon image */
630 unset_icon_image(icon
);
632 /* Set the new icon image */
633 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
636 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
638 if (icon
->file_image
)
641 get_rimage_icon_from_default_icon(icon
);
644 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
646 WScreen
*scr
= icon
->core
->screen_ptr
;
648 /* If the icon don't have image, we should use the default image. */
649 if (!scr
->def_icon_rimage
)
650 scr
->def_icon_rimage
= get_default_image(scr
);
652 /* Remove the icon image */
653 unset_icon_image(icon
);
655 /* Set the new icon image */
656 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
659 /* Get the RImage from the WIcon of the WWindow */
660 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
664 /* Create the new RImage */
665 image
= get_window_image_from_x11(icon
->icon_win
);
667 /* Free the icon info */
668 unset_icon_image(icon
);
670 /* Set the new info */
671 icon
->file_image
= image
;
674 /* Set the dockapp in the WIcon */
675 static void set_dockapp_in_icon(WIcon
*icon
)
677 XWindowAttributes attr
;
678 WScreen
*scr
= icon
->core
->screen_ptr
;
679 int title_height
= WMFontHeight(scr
->icon_title_font
);
680 unsigned int w
, h
, d
;
683 /* Reparent the dock application to the icon */
685 /* We need the application size to center it
686 * and show in the correct position */
687 getSize(icon
->icon_win
, &w
, &h
, &d
);
689 /* Set extra space for title */
690 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
691 theight
= title_height
;
692 drawIconTitle(scr
, icon
->pixmap
, theight
);
694 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
697 /* Set the icon border */
698 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
700 /* Put the dock application in the icon */
701 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
702 (wPreferences
.icon_size
- w
) / 2,
703 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
705 /* Show it and save */
706 XMapWindow(dpy
, icon
->icon_win
);
707 XAddToSaveSet(dpy
, icon
->icon_win
);
709 /* Needed to move the icon clicking on the application part */
710 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
711 (attr
.all_event_masks
& ButtonPressMask
))
712 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
713 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
714 None
, wCursor
[WCUR_ARROW
]);
717 /* Get the RImage from the XWindow wm_hints */
718 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
720 RImage
*image
= NULL
;
721 unsigned int w
, h
, d
;
722 WWindow
*wwin
= icon
->owner
;
724 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
725 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
729 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
733 /* Resize the icon to the wPreferences.icon_size size */
734 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
739 void wIconPaint(WIcon
*icon
)
741 WScreen
*scr
= icon
->core
->screen_ptr
;
745 XClearWindow(dpy
, icon
->core
->window
);
747 /* draw the icon title */
748 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
749 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
750 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
752 if (w
> icon
->core
->width
- 4)
753 x
= (icon
->core
->width
- 4) - w
;
755 x
= (icon
->core
->width
- w
) / 2;
757 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
758 scr
->icon_title_font
, x
, 1, tmp
, l
);
763 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
764 icon
->core
->width
- 1, icon
->core
->height
- 1);
767 /******************************************************************/
769 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
771 wIconPaint(desc
->parent
);
774 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
776 WIcon
*icon
= desc
->parent
;
778 assert(icon
->owner
!= NULL
);
780 wDeiconifyWindow(icon
->owner
);
783 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
785 WIcon
*icon
= desc
->parent
;
786 WWindow
*wwin
= icon
->owner
;
788 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
789 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
791 int clickButton
= event
->xbutton
.button
;
792 Bool hasMoved
= False
;
794 if (WCHECK_STATE(WSTATE_MODAL
))
797 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
798 miniwindowDblClick(desc
, event
);
802 if (event
->xbutton
.button
== Button1
) {
803 if (event
->xbutton
.state
& MOD_MASK
)
804 wLowerFrame(icon
->core
);
806 wRaiseFrame(icon
->core
);
807 if (event
->xbutton
.state
& ShiftMask
) {
809 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
811 } else if (event
->xbutton
.button
== Button3
) {
812 WObjDescriptor
*desc
;
814 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
816 /* allow drag select of menu */
817 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
818 event
->xbutton
.send_event
= True
;
819 (*desc
->handle_mousedown
) (desc
, event
);
824 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
825 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
826 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
829 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
830 | ButtonMotionMask
| ExposureMask
, &ev
);
839 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
840 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
841 XChangeActivePointerGrab(dpy
, ButtonMotionMask
842 | ButtonReleaseMask
| ButtonPressMask
,
843 wCursor
[WCUR_MOVE
], CurrentTime
);
849 x
= ev
.xmotion
.x_root
- dx
;
850 y
= ev
.xmotion
.y_root
- dy
;
851 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
858 if (ev
.xbutton
.button
!= clickButton
)
861 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
862 wwin
->flags
.icon_moved
= 1;
864 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
868 XUngrabPointer(dpy
, CurrentTime
);
870 if (wPreferences
.auto_arrange_icons
)
871 wArrangeIcons(wwin
->screen_ptr
, True
);
872 if (wPreferences
.single_click
&& !hasMoved
)
873 miniwindowDblClick(desc
, event
);
880 void set_icon_image_from_database(WIcon
*icon
, char *wm_instance
, char *wm_class
, char *command
)
884 file
= get_icon_filename(icon
->core
->screen_ptr
, wm_instance
, wm_class
, command
, False
);
886 icon
->file
= wstrdup(file
);
887 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);
891 wIconUpdate(icon
, NULL
);