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
;
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 drawIconTitleBackground(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
;
250 if (icon
->tile_type
== TILE_NORMAL
) {
251 tile
= RCloneImage(scr
->icon_tile
);
253 assert(scr
->clip_tile
);
254 tile
= RCloneImage(scr
->clip_tile
);
258 w
= (image
->width
> wPreferences
.icon_size
)
259 ? wPreferences
.icon_size
: image
->width
;
260 x
= (wPreferences
.icon_size
- w
) / 2;
261 sx
= (image
->width
- w
) / 2;
263 if (icon
->show_title
)
264 theight
= WMFontHeight(scr
->icon_title_font
);
266 h
= (image
->height
+ theight
> wPreferences
.icon_size
267 ? wPreferences
.icon_size
- theight
: image
->height
);
268 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
269 sy
= (image
->height
- h
) / 2;
271 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
274 if (icon
->shadowed
) {
277 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
278 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
279 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
280 color
.alpha
= 150; /* about 60% */
281 RClearImage(tile
, &color
);
284 if (icon
->highlighted
) {
287 color
.red
= color
.green
= color
.blue
= 0;
289 RLightImage(tile
, &color
);
292 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
293 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
297 /* Draw the icon's title background (without text) */
298 if (icon
->show_title
)
299 drawIconTitleBackground(scr
, pixmap
, theight
);
301 icon
->pixmap
= pixmap
;
304 void wIconChangeTitle(WIcon
*icon
, char *new_title
)
306 if (icon
->icon_name
!= NULL
)
307 XFree(icon
->icon_name
);
309 icon
->icon_name
= new_title
;
313 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
320 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
321 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
322 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
323 if (icon
->width
> icon
->height
)
324 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
325 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
327 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
328 max_size
- ICON_BORDER
);
336 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
338 WScreen
*scr
= icon
->core
->screen_ptr
;
340 RImage
*image
= NULL
;
343 /* If no new image, don't do nothing */
347 /* Find the new image */
348 path
= FindImage(wPreferences
.icon_path
, file
);
350 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
355 if (!error
&& image
) {
356 /* Set the new image */
357 set_icon_image_from_image(icon
, image
);
358 icon
->file
= wstrdup(path
);
359 update_icon_pixmap(icon
);
370 static char *get_name_for_wwin(WWindow
*wwin
)
372 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
375 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
380 if (wm_class
&& wm_instance
) {
381 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
382 suffix
= wmalloc(len
);
383 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
384 } else if (wm_class
) {
385 len
= strlen(wm_class
) + 1;
386 suffix
= wmalloc(len
);
387 snprintf(suffix
, len
, "%s", wm_class
);
388 } else if (wm_instance
) {
389 len
= strlen(wm_instance
) + 1;
390 suffix
= wmalloc(len
);
391 snprintf(suffix
, len
, "%s", wm_instance
);
399 static char *get_icon_cache_path(void)
404 prefix
= wusergnusteppath();
405 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
407 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
409 /* If the folder exists, exit */
410 if (access(path
, F_OK
) == 0)
413 /* Create the folder */
414 ret
= wmkdirhier((const char *) path
);
416 /* Exit 1 on success, 0 on failure */
425 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
427 RImage
*image
= NULL
;
428 XWMHints
*hints
= wwin
->wm_hints
;
430 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
431 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
433 (hints
->flags
& IconMaskHint
)
434 ? hints
->icon_mask
: None
);
441 * Stores the client supplied icon at CACHE_ICON_PATH
442 * and returns the path for that icon. Returns NULL if there is no
443 * client supplied icon or on failure.
446 * New directories might be created.
448 char *wIconStore(WIcon
* icon
)
450 char *path
, *dir_path
, *file
;
452 RImage
*image
= NULL
;
453 WWindow
*wwin
= icon
->owner
;
458 dir_path
= get_icon_cache_path();
462 file
= get_name_for_wwin(wwin
);
468 len
= strlen(dir_path
) + strlen(file
) + 5;
470 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
474 /* If icon exists, exit */
475 if (access(path
, F_OK
) == 0)
478 if (wwin
->net_icon_image
)
479 image
= RRetainImage(wwin
->net_icon_image
);
481 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
488 if (!RSaveImage(image
, path
, "XPM")) {
493 RReleaseImage(image
);
498 static void cycleColor(void *data
)
500 WIcon
*icon
= (WIcon
*) data
;
501 WScreen
*scr
= icon
->core
->screen_ptr
;
505 gcv
.dash_offset
= icon
->step
;
506 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
508 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
509 icon
->core
->width
- 1, icon
->core
->height
- 1);
510 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
513 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
515 if (icon
->highlighted
== flag
)
518 icon
->highlighted
= flag
;
519 update_icon_pixmap(icon
);
522 void wIconSelect(WIcon
* icon
)
524 WScreen
*scr
= icon
->core
->screen_ptr
;
525 icon
->selected
= !icon
->selected
;
527 if (icon
->selected
) {
529 if (!wPreferences
.dont_blink
)
530 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
532 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
533 icon
->core
->width
- 1, icon
->core
->height
- 1);
535 if (icon
->handlerID
) {
536 WMDeleteTimerHandler(icon
->handlerID
);
537 icon
->handlerID
= NULL
;
539 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
543 static void unset_icon_image(WIcon
*icon
)
550 if (icon
->file_image
) {
551 RReleaseImage(icon
->file_image
);
552 icon
->file_image
= NULL
;
556 void set_icon_image_from_image(WIcon
*icon
, RImage
*image
)
561 unset_icon_image(icon
);
563 icon
->file_image
= NULL
;
564 icon
->file_image
= image
;
567 void wIconUpdate(WIcon
*icon
)
569 WWindow
*wwin
= NULL
;
571 if (icon
&& icon
->owner
)
574 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
575 /* Forced use user_icon */
576 get_rimage_icon_from_user_icon(icon
);
577 } else if (icon
->icon_win
!= None
) {
578 /* Get the Pixmap from the WIcon */
579 get_rimage_icon_from_icon_win(icon
);
580 } else if (wwin
&& wwin
->net_icon_image
) {
581 /* Use _NET_WM_ICON icon */
582 get_rimage_icon_from_x11(icon
);
583 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
584 /* Get the Pixmap from the wm_hints, else, from the user */
585 unset_icon_image(icon
);
586 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
587 if (!icon
->file_image
)
588 get_rimage_icon_from_user_icon(icon
);
590 /* Get the Pixmap from the user */
591 get_rimage_icon_from_user_icon(icon
);
594 update_icon_pixmap(icon
);
597 void update_icon_pixmap(WIcon
*icon
)
599 if (icon
->pixmap
!= None
)
600 XFreePixmap(dpy
, icon
->pixmap
);
604 /* Create the pixmap */
605 if (icon
->file_image
)
606 icon_update_pixmap(icon
, icon
->file_image
);
608 /* If dockapp, put inside the icon */
609 if (icon
->icon_win
!= None
) {
610 /* file_image is NULL, because is docked app */
611 icon_update_pixmap(icon
, NULL
);
612 set_dockapp_in_icon(icon
);
615 /* No pixmap, set default background */
616 if (icon
->pixmap
!= None
)
617 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
623 static void get_rimage_icon_from_x11(WIcon
*icon
)
625 /* Remove the icon image */
626 unset_icon_image(icon
);
628 /* Set the new icon image */
629 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
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_rimage_icon_from_default_icon(WIcon
*icon
)
642 WScreen
*scr
= icon
->core
->screen_ptr
;
644 /* If the icon don't have image, we should use the default image. */
645 if (!scr
->def_icon_rimage
)
646 scr
->def_icon_rimage
= get_default_image(scr
);
648 /* Remove the icon image */
649 unset_icon_image(icon
);
651 /* Set the new icon image */
652 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
655 /* Get the RImage from the WIcon of the WWindow */
656 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
660 /* Create the new RImage */
661 image
= get_window_image_from_x11(icon
->icon_win
);
663 /* Free the icon info */
664 unset_icon_image(icon
);
666 /* Set the new info */
667 icon
->file_image
= image
;
670 /* Set the dockapp in the WIcon */
671 static void set_dockapp_in_icon(WIcon
*icon
)
673 XWindowAttributes attr
;
674 WScreen
*scr
= icon
->core
->screen_ptr
;
675 unsigned int w
, h
, d
;
677 /* Reparent the dock application to the icon */
679 /* We need the application size to center it
680 * and show in the correct position */
681 getSize(icon
->icon_win
, &w
, &h
, &d
);
683 /* Set the background pixmap */
684 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
686 /* Set the icon border */
687 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
689 /* Put the dock application in the icon */
690 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
691 (wPreferences
.icon_size
- w
) / 2,
692 (wPreferences
.icon_size
- h
) / 2);
694 /* Show it and save */
695 XMapWindow(dpy
, icon
->icon_win
);
696 XAddToSaveSet(dpy
, icon
->icon_win
);
698 /* Needed to move the icon clicking on the application part */
699 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
700 (attr
.all_event_masks
& ButtonPressMask
))
701 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
702 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
703 None
, wCursor
[WCUR_ARROW
]);
706 /* Get the RImage from the XWindow wm_hints */
707 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
709 RImage
*image
= NULL
;
710 unsigned int w
, h
, d
;
711 WWindow
*wwin
= icon
->owner
;
713 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
714 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
718 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
722 /* Resize the icon to the wPreferences.icon_size size */
723 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
728 /* This function updates in the screen the icon title */
729 static void update_icon_title(WIcon
*icon
)
731 WScreen
*scr
= icon
->core
->screen_ptr
;
735 /* draw the icon title */
736 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
737 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
738 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
740 if (w
> icon
->core
->width
- 4)
741 x
= (icon
->core
->width
- 4) - w
;
743 x
= (icon
->core
->width
- w
) / 2;
745 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
746 scr
->icon_title_font
, x
, 1, tmp
, l
);
752 void wIconPaint(WIcon
*icon
)
754 WScreen
*scr
= icon
->core
->screen_ptr
;
756 XClearWindow(dpy
, icon
->core
->window
);
758 update_icon_title(icon
);
761 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
762 icon
->core
->width
- 1, icon
->core
->height
- 1);
765 /******************************************************************/
767 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
769 wIconPaint(desc
->parent
);
772 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
774 WIcon
*icon
= desc
->parent
;
776 assert(icon
->owner
!= NULL
);
778 wDeiconifyWindow(icon
->owner
);
781 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
783 WIcon
*icon
= desc
->parent
;
784 WWindow
*wwin
= icon
->owner
;
786 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
787 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
789 int clickButton
= event
->xbutton
.button
;
790 Bool hasMoved
= False
;
792 if (WCHECK_STATE(WSTATE_MODAL
))
795 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
796 miniwindowDblClick(desc
, event
);
800 if (event
->xbutton
.button
== Button1
) {
801 if (event
->xbutton
.state
& MOD_MASK
)
802 wLowerFrame(icon
->core
);
804 wRaiseFrame(icon
->core
);
805 if (event
->xbutton
.state
& ShiftMask
) {
807 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
809 } else if (event
->xbutton
.button
== Button3
) {
810 WObjDescriptor
*desc
;
812 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
814 /* allow drag select of menu */
815 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
816 event
->xbutton
.send_event
= True
;
817 (*desc
->handle_mousedown
) (desc
, event
);
822 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
823 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
824 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
827 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
828 | ButtonMotionMask
| ExposureMask
, &ev
);
837 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
838 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
839 XChangeActivePointerGrab(dpy
, ButtonMotionMask
840 | ButtonReleaseMask
| ButtonPressMask
,
841 wCursor
[WCUR_MOVE
], CurrentTime
);
847 x
= ev
.xmotion
.x_root
- dx
;
848 y
= ev
.xmotion
.y_root
- dy
;
849 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
856 if (ev
.xbutton
.button
!= clickButton
)
859 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
860 wwin
->flags
.icon_moved
= 1;
862 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
866 XUngrabPointer(dpy
, CurrentTime
);
868 if (wPreferences
.auto_arrange_icons
)
869 wArrangeIcons(wwin
->screen_ptr
, True
);
870 if (wPreferences
.single_click
&& !hasMoved
)
871 miniwindowDblClick(desc
, event
);
878 void set_icon_image_from_database(WIcon
*icon
, char *wm_instance
, char *wm_class
, char *command
)
882 file
= get_icon_filename(icon
->core
->screen_ptr
, wm_instance
, wm_class
, command
, False
);
884 icon
->file
= wstrdup(file
);
885 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);