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"
42 #include "application.h"
51 /**** Global varianebles ****/
53 #define MOD_MASK wPreferences.modifier_mask
54 #define CACHE_ICON_PATH "/Library/WindowMaker/CachedPixmaps"
57 extern Cursor wCursor
[WCUR_LAST
];
59 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
60 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
61 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
63 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
);
65 static void set_dockapp_in_icon(WIcon
*icon
);
66 static void get_rimage_icon_from_icon_win(WIcon
*icon
);
67 static void get_rimage_icon_from_user_icon(WIcon
*icon
);
68 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
69 static void get_rimage_icon_from_x11(WIcon
*icon
);
71 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
72 static void unset_icon_image(WIcon
*icon
);
74 /****** Notification Observers ******/
76 static void appearanceObserver(void *self
, WMNotification
*notif
)
78 WIcon
*icon
= (WIcon
*) self
;
79 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
81 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
)) {
82 /* If the rimage exists, update the icon, else create it */
84 update_icon_pixmap(icon
);
89 /* so that the appicon expose handlers will paint the appicon specific
91 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
94 static void tileObserver(void *self
, WMNotification
*notif
)
96 WIcon
*icon
= (WIcon
*) self
;
98 update_icon_pixmap(icon
);
100 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
103 /************************************/
105 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
111 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
114 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
116 WScreen
*scr
= wwin
->screen_ptr
;
119 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
122 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
123 if (wwin
->client_win
== wwin
->main_window
) {
125 /* do not let miniwindow steal app-icon's icon window */
126 wapp
= wApplicationOf(wwin
->client_win
);
127 if (!wapp
|| wapp
->app_icon
== NULL
)
128 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
130 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
133 #ifdef NO_MINIWINDOW_TITLES
134 icon
->show_title
= 0;
136 icon
->show_title
= 1;
139 wIconChangeTitle(icon
, wwin
);
140 icon
->tile_type
= TILE_NORMAL
;
142 set_icon_image_from_database(icon
, wwin
->wm_instance
, wwin
->wm_class
, NULL
);
143 /* Update the icon, because icon could be NULL */
146 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
147 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
152 WIcon
*icon_create_for_dock(WScreen
*scr
, const char *command
, const char *wm_instance
, const char *wm_class
, int tile
)
156 icon
= icon_create_core(scr
, 0, 0);
157 icon
->tile_type
= tile
;
159 set_icon_image_from_database(icon
, wm_instance
, wm_class
, command
);
160 /* Update the icon, because icon could be NULL */
163 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
164 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
169 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
173 icon
= wmalloc(sizeof(WIcon
));
174 icon
->core
= wCoreCreateTopLevel(scr
,
177 wPreferences
.icon_size
,
178 wPreferences
.icon_size
,
179 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
,
182 /* will be overriden if this is a application icon */
183 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
184 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
185 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
186 icon
->core
->descriptor
.parent
= icon
;
188 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
189 icon
->core
->stacking
->above
= NULL
;
190 icon
->core
->stacking
->under
= NULL
;
191 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
192 icon
->core
->stacking
->child_of
= NULL
;
196 icon
->file_image
= NULL
;
201 void wIconDestroy(WIcon
* icon
)
203 WCoreWindow
*core
= icon
->core
;
204 WScreen
*scr
= core
->screen_ptr
;
206 WMRemoveNotificationObserver(icon
);
209 WMDeleteTimerHandler(icon
->handlerID
);
211 if (icon
->icon_win
) {
215 x
= icon
->owner
->icon_x
;
216 y
= icon
->owner
->icon_y
;
218 XUnmapWindow(dpy
, icon
->icon_win
);
219 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
222 XFree(icon
->icon_name
);
225 XFreePixmap(dpy
, icon
->pixmap
);
227 unset_icon_image(icon
);
229 wCoreDestroy(icon
->core
);
233 static void drawIconTitleBackground(WScreen
*scr
, Pixmap pixmap
, int height
)
235 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
236 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
237 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
238 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
239 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
242 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
249 WScreen
*scr
= icon
->core
->screen_ptr
;
251 switch (icon
->tile_type
) {
253 tile
= RCloneImage(scr
->icon_tile
);
256 tile
= RCloneImage(scr
->clip_tile
);
259 tile
= RCloneImage(scr
->drawer_tile
);
263 * The icon has always rigth value, this case is
264 * only to avoid a compiler warning with "tile"
265 * "may be used uninitialized"
267 wwarning("Unknown tile type: %d.\n", icon
->tile_type
);
268 tile
= RCloneImage(scr
->icon_tile
);
272 w
= (image
->width
> wPreferences
.icon_size
)
273 ? wPreferences
.icon_size
: image
->width
;
274 x
= (wPreferences
.icon_size
- w
) / 2;
275 sx
= (image
->width
- w
) / 2;
277 if (icon
->show_title
)
278 theight
= WMFontHeight(scr
->icon_title_font
);
280 h
= (image
->height
+ theight
> wPreferences
.icon_size
281 ? wPreferences
.icon_size
- theight
: image
->height
);
282 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
283 sy
= (image
->height
- h
) / 2;
285 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
288 if (icon
->shadowed
) {
291 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
292 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
293 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
294 color
.alpha
= 150; /* about 60% */
295 RClearImage(tile
, &color
);
298 if (icon
->highlighted
) {
301 color
.red
= color
.green
= color
.blue
= 0;
303 RLightImage(tile
, &color
);
306 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
307 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
311 /* Draw the icon's title background (without text) */
312 if (icon
->show_title
)
313 drawIconTitleBackground(scr
, pixmap
, theight
);
315 icon
->pixmap
= pixmap
;
318 void wIconChangeTitle(WIcon
*icon
, WWindow
*wwin
)
323 /* Remove the previous icon title */
324 if (icon
->icon_name
!= NULL
)
325 XFree(icon
->icon_name
);
327 /* Set the new one, using two methods */
328 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
329 if (!icon
->icon_name
)
330 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
333 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
340 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
341 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
342 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
343 if (icon
->width
> icon
->height
)
344 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
345 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
347 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
348 max_size
- ICON_BORDER
);
356 Bool
wIconChangeImageFile(WIcon
*icon
, const char *file
)
358 WScreen
*scr
= icon
->core
->screen_ptr
;
360 RImage
*image
= NULL
;
363 /* If no new image, don't do nothing */
367 /* Find the new image */
368 path
= FindImage(wPreferences
.icon_path
, file
);
370 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
375 if (!error
&& image
) {
376 /* Set the new image */
377 set_icon_image_from_image(icon
, image
);
378 icon
->file
= wstrdup(path
);
379 update_icon_pixmap(icon
);
390 static char *get_name_for_wwin(WWindow
*wwin
)
392 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
395 char *get_name_for_instance_class(const char *wm_instance
, const char *wm_class
)
400 if (wm_class
&& wm_instance
) {
401 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
402 suffix
= wmalloc(len
);
403 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
404 } else if (wm_class
) {
405 len
= strlen(wm_class
) + 1;
406 suffix
= wmalloc(len
);
407 snprintf(suffix
, len
, "%s", wm_class
);
408 } else if (wm_instance
) {
409 len
= strlen(wm_instance
) + 1;
410 suffix
= wmalloc(len
);
411 snprintf(suffix
, len
, "%s", wm_instance
);
419 static char *get_icon_cache_path(void)
425 prefix
= wusergnusteppath();
426 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
428 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
430 /* If the folder exists, exit */
431 if (access(path
, F_OK
) == 0)
434 /* Create the folder */
435 ret
= wmkdirhier((const char *) path
);
437 /* Exit 1 on success, 0 on failure */
446 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
448 RImage
*image
= NULL
;
449 XWMHints
*hints
= wwin
->wm_hints
;
451 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
452 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
454 (hints
->flags
& IconMaskHint
)
455 ? hints
->icon_mask
: None
);
462 * Stores the client supplied icon at CACHE_ICON_PATH
463 * and returns the path for that icon. Returns NULL if there is no
464 * client supplied icon or on failure.
467 * New directories might be created.
469 char *wIconStore(WIcon
* icon
)
471 char *path
, *dir_path
, *file
;
473 RImage
*image
= NULL
;
474 WWindow
*wwin
= icon
->owner
;
479 dir_path
= get_icon_cache_path();
483 file
= get_name_for_wwin(wwin
);
489 len
= strlen(dir_path
) + strlen(file
) + 5;
491 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
495 /* If icon exists, exit */
496 if (access(path
, F_OK
) == 0)
499 if (wwin
->net_icon_image
)
500 image
= RRetainImage(wwin
->net_icon_image
);
502 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
509 if (!RSaveImage(image
, path
, "XPM")) {
514 RReleaseImage(image
);
519 static void cycleColor(void *data
)
521 WIcon
*icon
= (WIcon
*) data
;
522 WScreen
*scr
= icon
->core
->screen_ptr
;
526 gcv
.dash_offset
= icon
->step
;
527 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
529 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
530 icon
->core
->width
- 1, icon
->core
->height
- 1);
531 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
534 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
536 if (icon
->highlighted
== flag
)
539 icon
->highlighted
= flag
;
540 update_icon_pixmap(icon
);
543 void wIconSelect(WIcon
* icon
)
545 WScreen
*scr
= icon
->core
->screen_ptr
;
546 icon
->selected
= !icon
->selected
;
548 if (icon
->selected
) {
550 if (!wPreferences
.dont_blink
)
551 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
553 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
554 icon
->core
->width
- 1, icon
->core
->height
- 1);
556 if (icon
->handlerID
) {
557 WMDeleteTimerHandler(icon
->handlerID
);
558 icon
->handlerID
= NULL
;
560 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
564 static void unset_icon_image(WIcon
*icon
)
571 if (icon
->file_image
) {
572 RReleaseImage(icon
->file_image
);
573 icon
->file_image
= NULL
;
577 void set_icon_image_from_image(WIcon
*icon
, RImage
*image
)
582 unset_icon_image(icon
);
584 icon
->file_image
= NULL
;
585 icon
->file_image
= image
;
588 void wIconUpdate(WIcon
*icon
)
590 WWindow
*wwin
= NULL
;
592 if (icon
&& icon
->owner
)
595 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
596 /* Forced use user_icon */
597 get_rimage_icon_from_user_icon(icon
);
598 } else if (icon
->icon_win
!= None
) {
599 /* Get the Pixmap from the WIcon */
600 get_rimage_icon_from_icon_win(icon
);
601 } else if (wwin
&& wwin
->net_icon_image
) {
602 /* Use _NET_WM_ICON icon */
603 get_rimage_icon_from_x11(icon
);
604 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
605 /* Get the Pixmap from the wm_hints, else, from the user */
606 unset_icon_image(icon
);
607 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
608 if (!icon
->file_image
)
609 get_rimage_icon_from_user_icon(icon
);
611 /* Get the Pixmap from the user */
612 get_rimage_icon_from_user_icon(icon
);
615 update_icon_pixmap(icon
);
618 void update_icon_pixmap(WIcon
*icon
)
620 if (icon
->pixmap
!= None
)
621 XFreePixmap(dpy
, icon
->pixmap
);
625 /* Create the pixmap */
626 if (icon
->file_image
)
627 icon_update_pixmap(icon
, icon
->file_image
);
629 /* If dockapp, put inside the icon */
630 if (icon
->icon_win
!= None
) {
631 /* file_image is NULL, because is docked app */
632 icon_update_pixmap(icon
, NULL
);
633 set_dockapp_in_icon(icon
);
636 /* No pixmap, set default background */
637 if (icon
->pixmap
!= None
)
638 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
644 static void get_rimage_icon_from_x11(WIcon
*icon
)
646 /* Remove the icon image */
647 unset_icon_image(icon
);
649 /* Set the new icon image */
650 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
653 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
655 if (icon
->file_image
)
658 get_rimage_icon_from_default_icon(icon
);
661 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
663 WScreen
*scr
= icon
->core
->screen_ptr
;
665 /* If the icon don't have image, we should use the default image. */
666 if (!scr
->def_icon_rimage
)
667 scr
->def_icon_rimage
= get_default_image(scr
);
669 /* Remove the icon image */
670 unset_icon_image(icon
);
672 /* Set the new icon image */
673 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
676 /* Get the RImage from the WIcon of the WWindow */
677 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
681 /* Create the new RImage */
682 image
= get_window_image_from_x11(icon
->icon_win
);
684 /* Free the icon info */
685 unset_icon_image(icon
);
687 /* Set the new info */
688 icon
->file_image
= image
;
691 /* Set the dockapp in the WIcon */
692 static void set_dockapp_in_icon(WIcon
*icon
)
694 XWindowAttributes attr
;
695 WScreen
*scr
= icon
->core
->screen_ptr
;
696 unsigned int w
, h
, d
;
698 /* Reparent the dock application to the icon */
700 /* We need the application size to center it
701 * and show in the correct position */
702 getSize(icon
->icon_win
, &w
, &h
, &d
);
704 /* Set the background pixmap */
705 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
707 /* Set the icon border */
708 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
710 /* Put the dock application in the icon */
711 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
712 (wPreferences
.icon_size
- w
) / 2,
713 (wPreferences
.icon_size
- h
) / 2);
715 /* Show it and save */
716 XMapWindow(dpy
, icon
->icon_win
);
717 XAddToSaveSet(dpy
, icon
->icon_win
);
719 /* Needed to move the icon clicking on the application part */
720 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
721 (attr
.all_event_masks
& ButtonPressMask
))
722 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
723 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
724 None
, wCursor
[WCUR_ARROW
]);
727 /* Get the RImage from the XWindow wm_hints */
728 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
730 RImage
*image
= NULL
;
731 unsigned int w
, h
, d
;
732 WWindow
*wwin
= icon
->owner
;
734 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
735 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
739 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
743 /* Resize the icon to the wPreferences.icon_size size */
744 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
749 /* This function updates in the screen the icon title */
750 static void update_icon_title(WIcon
*icon
)
752 WScreen
*scr
= icon
->core
->screen_ptr
;
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
);
773 void wIconPaint(WIcon
*icon
)
775 if (!icon
|| !icon
->core
|| !icon
->core
->screen_ptr
)
778 WScreen
*scr
= icon
->core
->screen_ptr
;
780 XClearWindow(dpy
, icon
->core
->window
);
782 update_icon_title(icon
);
785 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
786 icon
->core
->width
- 1, icon
->core
->height
- 1);
789 /******************************************************************/
791 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
793 wIconPaint(desc
->parent
);
796 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
798 WIcon
*icon
= desc
->parent
;
800 assert(icon
->owner
!= NULL
);
802 wDeiconifyWindow(icon
->owner
);
805 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
807 WIcon
*icon
= desc
->parent
;
808 WWindow
*wwin
= icon
->owner
;
810 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
811 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
813 int clickButton
= event
->xbutton
.button
;
814 Bool hasMoved
= False
;
816 if (WCHECK_STATE(WSTATE_MODAL
))
819 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
820 miniwindowDblClick(desc
, event
);
824 if (event
->xbutton
.button
== Button1
) {
825 if (event
->xbutton
.state
& MOD_MASK
)
826 wLowerFrame(icon
->core
);
828 wRaiseFrame(icon
->core
);
829 if (event
->xbutton
.state
& ShiftMask
) {
831 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
833 } else if (event
->xbutton
.button
== Button3
) {
834 WObjDescriptor
*desc
;
836 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
838 /* allow drag select of menu */
839 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
840 event
->xbutton
.send_event
= True
;
841 (*desc
->handle_mousedown
) (desc
, event
);
846 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
847 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
848 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
851 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
852 | ButtonMotionMask
| ExposureMask
, &ev
);
861 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
862 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
863 XChangeActivePointerGrab(dpy
, ButtonMotionMask
864 | ButtonReleaseMask
| ButtonPressMask
,
865 wCursor
[WCUR_MOVE
], CurrentTime
);
871 x
= ev
.xmotion
.x_root
- dx
;
872 y
= ev
.xmotion
.y_root
- dy
;
873 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
880 if (ev
.xbutton
.button
!= clickButton
)
883 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
884 wwin
->flags
.icon_moved
= 1;
886 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
890 XUngrabPointer(dpy
, CurrentTime
);
892 if (wPreferences
.auto_arrange_icons
)
893 wArrangeIcons(wwin
->screen_ptr
, True
);
894 if (wPreferences
.single_click
&& !hasMoved
)
895 miniwindowDblClick(desc
, event
);
902 void set_icon_image_from_database(WIcon
*icon
, const char *wm_instance
, const char *wm_class
, const char *command
)
906 file
= get_icon_filename(icon
->core
->screen_ptr
, wm_instance
, wm_class
, command
, False
);
908 icon
->file
= wstrdup(file
);
909 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);