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 update_icon_pixmap(icon
);
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
);
146 /* Update the icon, because icon could be NULL */
149 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
150 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
155 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
159 icon
= icon_create_core(scr
, 0, 0);
160 icon
->tile_type
= tile
;
162 set_icon_image_from_database(icon
, wm_instance
, wm_class
, command
);
163 /* Update the icon, because icon could be NULL */
166 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
167 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
172 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
176 icon
= wmalloc(sizeof(WIcon
));
177 icon
->core
= wCoreCreateTopLevel(scr
,
180 wPreferences
.icon_size
,
181 wPreferences
.icon_size
,
182 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
,
185 /* will be overriden if this is a application icon */
186 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
187 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
188 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
189 icon
->core
->descriptor
.parent
= icon
;
191 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
192 icon
->core
->stacking
->above
= NULL
;
193 icon
->core
->stacking
->under
= NULL
;
194 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
195 icon
->core
->stacking
->child_of
= NULL
;
199 icon
->file_image
= NULL
;
204 void wIconDestroy(WIcon
* icon
)
206 WCoreWindow
*core
= icon
->core
;
207 WScreen
*scr
= core
->screen_ptr
;
209 WMRemoveNotificationObserver(icon
);
212 WMDeleteTimerHandler(icon
->handlerID
);
214 if (icon
->icon_win
) {
218 x
= icon
->owner
->icon_x
;
219 y
= icon
->owner
->icon_y
;
221 XUnmapWindow(dpy
, icon
->icon_win
);
222 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
225 XFree(icon
->icon_name
);
228 XFreePixmap(dpy
, icon
->pixmap
);
230 unset_icon_image(icon
);
232 wCoreDestroy(icon
->core
);
236 static void drawIconTitleBackground(WScreen
*scr
, Pixmap pixmap
, int height
)
238 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
239 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
240 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
241 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
242 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
245 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
252 WScreen
*scr
= icon
->core
->screen_ptr
;
254 if (icon
->tile_type
== TILE_NORMAL
) {
255 tile
= RCloneImage(scr
->icon_tile
);
257 assert(scr
->clip_tile
);
258 tile
= RCloneImage(scr
->clip_tile
);
262 w
= (image
->width
> wPreferences
.icon_size
)
263 ? wPreferences
.icon_size
: image
->width
;
264 x
= (wPreferences
.icon_size
- w
) / 2;
265 sx
= (image
->width
- w
) / 2;
267 if (icon
->show_title
)
268 theight
= WMFontHeight(scr
->icon_title_font
);
270 h
= (image
->height
+ theight
> wPreferences
.icon_size
271 ? wPreferences
.icon_size
- theight
: image
->height
);
272 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
273 sy
= (image
->height
- h
) / 2;
275 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
278 if (icon
->shadowed
) {
281 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
282 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
283 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
284 color
.alpha
= 150; /* about 60% */
285 RClearImage(tile
, &color
);
288 if (icon
->highlighted
) {
291 color
.red
= color
.green
= color
.blue
= 0;
293 RLightImage(tile
, &color
);
296 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
297 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
301 /* Draw the icon's title background (without text) */
302 if (icon
->show_title
)
303 drawIconTitleBackground(scr
, pixmap
, theight
);
305 icon
->pixmap
= pixmap
;
308 void wIconChangeTitle(WIcon
*icon
, char *new_title
)
310 if (icon
->icon_name
!= NULL
)
311 XFree(icon
->icon_name
);
313 icon
->icon_name
= new_title
;
317 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
324 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
325 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
326 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
327 if (icon
->width
> icon
->height
)
328 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
329 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
331 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
332 max_size
- ICON_BORDER
);
340 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
342 WScreen
*scr
= icon
->core
->screen_ptr
;
344 RImage
*image
= NULL
;
347 /* If no new image, don't do nothing */
351 /* Find the new image */
352 path
= FindImage(wPreferences
.icon_path
, file
);
354 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
359 if (!error
&& image
) {
360 /* Set the new image */
361 set_icon_image_from_image(icon
, image
);
362 icon
->file
= wstrdup(path
);
363 update_icon_pixmap(icon
);
374 static char *get_name_for_wwin(WWindow
*wwin
)
376 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
379 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
384 if (wm_class
&& wm_instance
) {
385 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
386 suffix
= wmalloc(len
);
387 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
388 } else if (wm_class
) {
389 len
= strlen(wm_class
) + 1;
390 suffix
= wmalloc(len
);
391 snprintf(suffix
, len
, "%s", wm_class
);
392 } else if (wm_instance
) {
393 len
= strlen(wm_instance
) + 1;
394 suffix
= wmalloc(len
);
395 snprintf(suffix
, len
, "%s", wm_instance
);
403 static char *get_icon_cache_path(void)
408 prefix
= wusergnusteppath();
409 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
411 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
413 /* If the folder exists, exit */
414 if (access(path
, F_OK
) == 0)
417 /* Create the folder */
418 ret
= wmkdirhier((const char *) path
);
420 /* Exit 1 on success, 0 on failure */
429 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
431 RImage
*image
= NULL
;
432 XWMHints
*hints
= wwin
->wm_hints
;
434 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
435 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
437 (hints
->flags
& IconMaskHint
)
438 ? hints
->icon_mask
: None
);
445 * Stores the client supplied icon at CACHE_ICON_PATH
446 * and returns the path for that icon. Returns NULL if there is no
447 * client supplied icon or on failure.
450 * New directories might be created.
452 char *wIconStore(WIcon
* icon
)
454 char *path
, *dir_path
, *file
;
456 RImage
*image
= NULL
;
457 WWindow
*wwin
= icon
->owner
;
462 dir_path
= get_icon_cache_path();
466 file
= get_name_for_wwin(wwin
);
472 len
= strlen(dir_path
) + strlen(file
) + 5;
474 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
478 /* If icon exists, exit */
479 if (access(path
, F_OK
) == 0)
482 if (wwin
->net_icon_image
)
483 image
= RRetainImage(wwin
->net_icon_image
);
485 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
492 if (!RSaveImage(image
, path
, "XPM")) {
497 RReleaseImage(image
);
502 static void cycleColor(void *data
)
504 WIcon
*icon
= (WIcon
*) data
;
505 WScreen
*scr
= icon
->core
->screen_ptr
;
509 gcv
.dash_offset
= icon
->step
;
510 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
512 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
513 icon
->core
->width
- 1, icon
->core
->height
- 1);
514 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
517 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
519 if (icon
->highlighted
== flag
)
522 icon
->highlighted
= flag
;
523 update_icon_pixmap(icon
);
526 void wIconSelect(WIcon
* icon
)
528 WScreen
*scr
= icon
->core
->screen_ptr
;
529 icon
->selected
= !icon
->selected
;
531 if (icon
->selected
) {
533 if (!wPreferences
.dont_blink
)
534 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
536 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
537 icon
->core
->width
- 1, icon
->core
->height
- 1);
539 if (icon
->handlerID
) {
540 WMDeleteTimerHandler(icon
->handlerID
);
541 icon
->handlerID
= NULL
;
543 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
547 static void unset_icon_image(WIcon
*icon
)
554 if (icon
->file_image
) {
555 RReleaseImage(icon
->file_image
);
556 icon
->file_image
= NULL
;
560 void set_icon_image_from_image(WIcon
*icon
, RImage
*image
)
565 unset_icon_image(icon
);
567 icon
->file_image
= NULL
;
568 icon
->file_image
= image
;
571 void wIconUpdate(WIcon
*icon
)
573 WWindow
*wwin
= NULL
;
575 if (icon
&& icon
->owner
)
578 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
579 /* Forced use user_icon */
580 get_rimage_icon_from_user_icon(icon
);
581 } else if (icon
->icon_win
!= None
) {
582 /* Get the Pixmap from the WIcon */
583 get_rimage_icon_from_icon_win(icon
);
584 } else if (wwin
&& wwin
->net_icon_image
) {
585 /* Use _NET_WM_ICON icon */
586 get_rimage_icon_from_x11(icon
);
587 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
588 /* Get the Pixmap from the wm_hints, else, from the user */
589 unset_icon_image(icon
);
590 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
591 if (!icon
->file_image
)
592 get_rimage_icon_from_user_icon(icon
);
594 /* Get the Pixmap from the user */
595 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 unsigned int w
, h
, d
;
681 /* Reparent the dock application to the icon */
683 /* We need the application size to center it
684 * and show in the correct position */
685 getSize(icon
->icon_win
, &w
, &h
, &d
);
687 /* Set the background pixmap */
688 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
690 /* Set the icon border */
691 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
693 /* Put the dock application in the icon */
694 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
695 (wPreferences
.icon_size
- w
) / 2,
696 (wPreferences
.icon_size
- h
) / 2);
698 /* Show it and save */
699 XMapWindow(dpy
, icon
->icon_win
);
700 XAddToSaveSet(dpy
, icon
->icon_win
);
702 /* Needed to move the icon clicking on the application part */
703 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
704 (attr
.all_event_masks
& ButtonPressMask
))
705 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
706 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
707 None
, wCursor
[WCUR_ARROW
]);
710 /* Get the RImage from the XWindow wm_hints */
711 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
713 RImage
*image
= NULL
;
714 unsigned int w
, h
, d
;
715 WWindow
*wwin
= icon
->owner
;
717 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
718 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
722 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
726 /* Resize the icon to the wPreferences.icon_size size */
727 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
732 /* This function updates in the screen the icon title */
733 static void update_icon_title(WIcon
*icon
)
735 WScreen
*scr
= icon
->core
->screen_ptr
;
739 /* draw the icon title */
740 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
741 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
742 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
744 if (w
> icon
->core
->width
- 4)
745 x
= (icon
->core
->width
- 4) - w
;
747 x
= (icon
->core
->width
- w
) / 2;
749 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
750 scr
->icon_title_font
, x
, 1, tmp
, l
);
756 void wIconPaint(WIcon
*icon
)
758 if (!icon
|| !icon
->core
|| !icon
->core
->screen_ptr
)
761 WScreen
*scr
= icon
->core
->screen_ptr
;
763 XClearWindow(dpy
, icon
->core
->window
);
765 update_icon_title(icon
);
768 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
769 icon
->core
->width
- 1, icon
->core
->height
- 1);
772 /******************************************************************/
774 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
776 wIconPaint(desc
->parent
);
779 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
781 WIcon
*icon
= desc
->parent
;
783 assert(icon
->owner
!= NULL
);
785 wDeiconifyWindow(icon
->owner
);
788 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
790 WIcon
*icon
= desc
->parent
;
791 WWindow
*wwin
= icon
->owner
;
793 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
794 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
796 int clickButton
= event
->xbutton
.button
;
797 Bool hasMoved
= False
;
799 if (WCHECK_STATE(WSTATE_MODAL
))
802 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
803 miniwindowDblClick(desc
, event
);
807 if (event
->xbutton
.button
== Button1
) {
808 if (event
->xbutton
.state
& MOD_MASK
)
809 wLowerFrame(icon
->core
);
811 wRaiseFrame(icon
->core
);
812 if (event
->xbutton
.state
& ShiftMask
) {
814 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
816 } else if (event
->xbutton
.button
== Button3
) {
817 WObjDescriptor
*desc
;
819 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
821 /* allow drag select of menu */
822 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
823 event
->xbutton
.send_event
= True
;
824 (*desc
->handle_mousedown
) (desc
, event
);
829 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
830 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
831 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
834 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
835 | ButtonMotionMask
| ExposureMask
, &ev
);
844 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
845 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
846 XChangeActivePointerGrab(dpy
, ButtonMotionMask
847 | ButtonReleaseMask
| ButtonPressMask
,
848 wCursor
[WCUR_MOVE
], CurrentTime
);
854 x
= ev
.xmotion
.x_root
- dx
;
855 y
= ev
.xmotion
.y_root
- dy
;
856 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
863 if (ev
.xbutton
.button
!= clickButton
)
866 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
867 wwin
->flags
.icon_moved
= 1;
869 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
873 XUngrabPointer(dpy
, CurrentTime
);
875 if (wPreferences
.auto_arrange_icons
)
876 wArrangeIcons(wwin
->screen_ptr
, True
);
877 if (wPreferences
.single_click
&& !hasMoved
)
878 miniwindowDblClick(desc
, event
);
885 void set_icon_image_from_database(WIcon
*icon
, char *wm_instance
, char *wm_class
, char *command
)
889 file
= get_icon_filename(icon
->core
->screen_ptr
, wm_instance
, wm_class
, command
, False
);
891 icon
->file
= wstrdup(file
);
892 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);