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"
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 wIconChangeTitle(icon
, wwin
);
138 icon
->tile_type
= TILE_NORMAL
;
140 set_icon_image_from_database(icon
, wwin
->wm_instance
, wwin
->wm_class
, NULL
);
141 /* Update the icon, because icon could be NULL */
144 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
145 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
150 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
154 icon
= icon_create_core(scr
, 0, 0);
155 icon
->tile_type
= tile
;
157 set_icon_image_from_database(icon
, wm_instance
, wm_class
, command
);
158 /* Update the icon, because icon could be NULL */
161 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
162 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
167 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
171 icon
= wmalloc(sizeof(WIcon
));
172 icon
->core
= wCoreCreateTopLevel(scr
,
175 wPreferences
.icon_size
,
176 wPreferences
.icon_size
,
177 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
,
180 /* will be overriden if this is a application icon */
181 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
182 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
183 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
184 icon
->core
->descriptor
.parent
= icon
;
186 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
187 icon
->core
->stacking
->above
= NULL
;
188 icon
->core
->stacking
->under
= NULL
;
189 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
190 icon
->core
->stacking
->child_of
= NULL
;
194 icon
->file_image
= NULL
;
199 void wIconDestroy(WIcon
* icon
)
201 WCoreWindow
*core
= icon
->core
;
202 WScreen
*scr
= core
->screen_ptr
;
204 WMRemoveNotificationObserver(icon
);
207 WMDeleteTimerHandler(icon
->handlerID
);
209 if (icon
->icon_win
) {
213 x
= icon
->owner
->icon_x
;
214 y
= icon
->owner
->icon_y
;
216 XUnmapWindow(dpy
, icon
->icon_win
);
217 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
220 XFree(icon
->icon_name
);
223 XFreePixmap(dpy
, icon
->pixmap
);
225 unset_icon_image(icon
);
227 wCoreDestroy(icon
->core
);
231 static void drawIconTitleBackground(WScreen
*scr
, Pixmap pixmap
, int height
)
233 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
234 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
235 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
236 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
237 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
240 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
247 WScreen
*scr
= icon
->core
->screen_ptr
;
249 switch (icon
->tile_type
) {
251 tile
= RCloneImage(scr
->icon_tile
);
254 tile
= RCloneImage(scr
->clip_tile
);
257 tile
= RCloneImage(scr
->drawer_tile
);
261 * The icon has always rigth value, this case is
262 * only to avoid a compiler warning with "tile"
263 * "may be used uninitialized"
265 wwarning("Unknown tile type: %d.\n", icon
->tile_type
);
266 tile
= RCloneImage(scr
->icon_tile
);
270 w
= (image
->width
> wPreferences
.icon_size
)
271 ? wPreferences
.icon_size
: image
->width
;
272 x
= (wPreferences
.icon_size
- w
) / 2;
273 sx
= (image
->width
- w
) / 2;
275 if (icon
->show_title
)
276 theight
= WMFontHeight(scr
->icon_title_font
);
278 h
= (image
->height
+ theight
> wPreferences
.icon_size
279 ? wPreferences
.icon_size
- theight
: image
->height
);
280 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
281 sy
= (image
->height
- h
) / 2;
283 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
286 if (icon
->shadowed
) {
289 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
290 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
291 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
292 color
.alpha
= 150; /* about 60% */
293 RClearImage(tile
, &color
);
296 if (icon
->highlighted
) {
299 color
.red
= color
.green
= color
.blue
= 0;
301 RLightImage(tile
, &color
);
304 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
305 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
309 /* Draw the icon's title background (without text) */
310 if (icon
->show_title
)
311 drawIconTitleBackground(scr
, pixmap
, theight
);
313 icon
->pixmap
= pixmap
;
316 void wIconChangeTitle(WIcon
*icon
, WWindow
*wwin
)
321 /* Remove the previous icon title */
322 if (icon
->icon_name
!= NULL
)
323 XFree(icon
->icon_name
);
325 /* Set the new one, using two methods */
326 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
327 if (!icon
->icon_name
)
328 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
331 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
338 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
339 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
340 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
341 if (icon
->width
> icon
->height
)
342 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
343 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
345 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
346 max_size
- ICON_BORDER
);
354 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
356 WScreen
*scr
= icon
->core
->screen_ptr
;
358 RImage
*image
= NULL
;
361 /* If no new image, don't do nothing */
365 /* Find the new image */
366 path
= FindImage(wPreferences
.icon_path
, file
);
368 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
373 if (!error
&& image
) {
374 /* Set the new image */
375 set_icon_image_from_image(icon
, image
);
376 icon
->file
= wstrdup(path
);
377 update_icon_pixmap(icon
);
388 static char *get_name_for_wwin(WWindow
*wwin
)
390 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
393 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
398 if (wm_class
&& wm_instance
) {
399 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
400 suffix
= wmalloc(len
);
401 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
402 } else if (wm_class
) {
403 len
= strlen(wm_class
) + 1;
404 suffix
= wmalloc(len
);
405 snprintf(suffix
, len
, "%s", wm_class
);
406 } else if (wm_instance
) {
407 len
= strlen(wm_instance
) + 1;
408 suffix
= wmalloc(len
);
409 snprintf(suffix
, len
, "%s", wm_instance
);
417 static char *get_icon_cache_path(void)
423 prefix
= wusergnusteppath();
424 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
426 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
428 /* If the folder exists, exit */
429 if (access(path
, F_OK
) == 0)
432 /* Create the folder */
433 ret
= wmkdirhier((const char *) path
);
435 /* Exit 1 on success, 0 on failure */
444 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
446 RImage
*image
= NULL
;
447 XWMHints
*hints
= wwin
->wm_hints
;
449 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
450 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
452 (hints
->flags
& IconMaskHint
)
453 ? hints
->icon_mask
: None
);
460 * Stores the client supplied icon at CACHE_ICON_PATH
461 * and returns the path for that icon. Returns NULL if there is no
462 * client supplied icon or on failure.
465 * New directories might be created.
467 char *wIconStore(WIcon
* icon
)
469 char *path
, *dir_path
, *file
;
471 RImage
*image
= NULL
;
472 WWindow
*wwin
= icon
->owner
;
477 dir_path
= get_icon_cache_path();
481 file
= get_name_for_wwin(wwin
);
487 len
= strlen(dir_path
) + strlen(file
) + 5;
489 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
493 /* If icon exists, exit */
494 if (access(path
, F_OK
) == 0)
497 if (wwin
->net_icon_image
)
498 image
= RRetainImage(wwin
->net_icon_image
);
500 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
507 if (!RSaveImage(image
, path
, "XPM")) {
512 RReleaseImage(image
);
517 static void cycleColor(void *data
)
519 WIcon
*icon
= (WIcon
*) data
;
520 WScreen
*scr
= icon
->core
->screen_ptr
;
524 gcv
.dash_offset
= icon
->step
;
525 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
527 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
528 icon
->core
->width
- 1, icon
->core
->height
- 1);
529 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
532 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
534 if (icon
->highlighted
== flag
)
537 icon
->highlighted
= flag
;
538 update_icon_pixmap(icon
);
541 void wIconSelect(WIcon
* icon
)
543 WScreen
*scr
= icon
->core
->screen_ptr
;
544 icon
->selected
= !icon
->selected
;
546 if (icon
->selected
) {
548 if (!wPreferences
.dont_blink
)
549 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
551 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
552 icon
->core
->width
- 1, icon
->core
->height
- 1);
554 if (icon
->handlerID
) {
555 WMDeleteTimerHandler(icon
->handlerID
);
556 icon
->handlerID
= NULL
;
558 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
562 static void unset_icon_image(WIcon
*icon
)
569 if (icon
->file_image
) {
570 RReleaseImage(icon
->file_image
);
571 icon
->file_image
= NULL
;
575 void set_icon_image_from_image(WIcon
*icon
, RImage
*image
)
580 unset_icon_image(icon
);
582 icon
->file_image
= NULL
;
583 icon
->file_image
= image
;
586 void wIconUpdate(WIcon
*icon
)
588 WWindow
*wwin
= NULL
;
590 if (icon
&& icon
->owner
)
593 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
594 /* Forced use user_icon */
595 get_rimage_icon_from_user_icon(icon
);
596 } else if (icon
->icon_win
!= None
) {
597 /* Get the Pixmap from the WIcon */
598 get_rimage_icon_from_icon_win(icon
);
599 } else if (wwin
&& wwin
->net_icon_image
) {
600 /* Use _NET_WM_ICON icon */
601 get_rimage_icon_from_x11(icon
);
602 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
603 /* Get the Pixmap from the wm_hints, else, from the user */
604 unset_icon_image(icon
);
605 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
606 if (!icon
->file_image
)
607 get_rimage_icon_from_user_icon(icon
);
609 /* Get the Pixmap from the user */
610 get_rimage_icon_from_user_icon(icon
);
613 update_icon_pixmap(icon
);
616 void update_icon_pixmap(WIcon
*icon
)
618 if (icon
->pixmap
!= None
)
619 XFreePixmap(dpy
, icon
->pixmap
);
623 /* Create the pixmap */
624 if (icon
->file_image
)
625 icon_update_pixmap(icon
, icon
->file_image
);
627 /* If dockapp, put inside the icon */
628 if (icon
->icon_win
!= None
) {
629 /* file_image is NULL, because is docked app */
630 icon_update_pixmap(icon
, NULL
);
631 set_dockapp_in_icon(icon
);
634 /* No pixmap, set default background */
635 if (icon
->pixmap
!= None
)
636 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
642 static void get_rimage_icon_from_x11(WIcon
*icon
)
644 /* Remove the icon image */
645 unset_icon_image(icon
);
647 /* Set the new icon image */
648 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
651 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
653 if (icon
->file_image
)
656 get_rimage_icon_from_default_icon(icon
);
659 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
661 WScreen
*scr
= icon
->core
->screen_ptr
;
663 /* If the icon don't have image, we should use the default image. */
664 if (!scr
->def_icon_rimage
)
665 scr
->def_icon_rimage
= get_default_image(scr
);
667 /* Remove the icon image */
668 unset_icon_image(icon
);
670 /* Set the new icon image */
671 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
674 /* Get the RImage from the WIcon of the WWindow */
675 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
679 /* Create the new RImage */
680 image
= get_window_image_from_x11(icon
->icon_win
);
682 /* Free the icon info */
683 unset_icon_image(icon
);
685 /* Set the new info */
686 icon
->file_image
= image
;
689 /* Set the dockapp in the WIcon */
690 static void set_dockapp_in_icon(WIcon
*icon
)
692 XWindowAttributes attr
;
693 WScreen
*scr
= icon
->core
->screen_ptr
;
694 unsigned int w
, h
, d
;
696 /* Reparent the dock application to the icon */
698 /* We need the application size to center it
699 * and show in the correct position */
700 getSize(icon
->icon_win
, &w
, &h
, &d
);
702 /* Set the background pixmap */
703 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
705 /* Set the icon border */
706 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
708 /* Put the dock application in the icon */
709 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
710 (wPreferences
.icon_size
- w
) / 2,
711 (wPreferences
.icon_size
- h
) / 2);
713 /* Show it and save */
714 XMapWindow(dpy
, icon
->icon_win
);
715 XAddToSaveSet(dpy
, icon
->icon_win
);
717 /* Needed to move the icon clicking on the application part */
718 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
719 (attr
.all_event_masks
& ButtonPressMask
))
720 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
721 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
722 None
, wCursor
[WCUR_ARROW
]);
725 /* Get the RImage from the XWindow wm_hints */
726 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
728 RImage
*image
= NULL
;
729 unsigned int w
, h
, d
;
730 WWindow
*wwin
= icon
->owner
;
732 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
733 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
737 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
741 /* Resize the icon to the wPreferences.icon_size size */
742 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
747 /* This function updates in the screen the icon title */
748 static void update_icon_title(WIcon
*icon
)
750 WScreen
*scr
= icon
->core
->screen_ptr
;
754 /* draw the icon title */
755 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
756 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
757 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
759 if (w
> icon
->core
->width
- 4)
760 x
= (icon
->core
->width
- 4) - w
;
762 x
= (icon
->core
->width
- w
) / 2;
764 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
765 scr
->icon_title_font
, x
, 1, tmp
, l
);
771 void wIconPaint(WIcon
*icon
)
773 if (!icon
|| !icon
->core
|| !icon
->core
->screen_ptr
)
776 WScreen
*scr
= icon
->core
->screen_ptr
;
778 XClearWindow(dpy
, icon
->core
->window
);
780 update_icon_title(icon
);
783 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
784 icon
->core
->width
- 1, icon
->core
->height
- 1);
787 /******************************************************************/
789 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
791 wIconPaint(desc
->parent
);
794 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
796 WIcon
*icon
= desc
->parent
;
798 assert(icon
->owner
!= NULL
);
800 wDeiconifyWindow(icon
->owner
);
803 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
805 WIcon
*icon
= desc
->parent
;
806 WWindow
*wwin
= icon
->owner
;
808 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
809 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
811 int clickButton
= event
->xbutton
.button
;
812 Bool hasMoved
= False
;
814 if (WCHECK_STATE(WSTATE_MODAL
))
817 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
818 miniwindowDblClick(desc
, event
);
822 if (event
->xbutton
.button
== Button1
) {
823 if (event
->xbutton
.state
& MOD_MASK
)
824 wLowerFrame(icon
->core
);
826 wRaiseFrame(icon
->core
);
827 if (event
->xbutton
.state
& ShiftMask
) {
829 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
831 } else if (event
->xbutton
.button
== Button3
) {
832 WObjDescriptor
*desc
;
834 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
836 /* allow drag select of menu */
837 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
838 event
->xbutton
.send_event
= True
;
839 (*desc
->handle_mousedown
) (desc
, event
);
844 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
845 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
846 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
849 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
850 | ButtonMotionMask
| ExposureMask
, &ev
);
859 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
860 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
861 XChangeActivePointerGrab(dpy
, ButtonMotionMask
862 | ButtonReleaseMask
| ButtonPressMask
,
863 wCursor
[WCUR_MOVE
], CurrentTime
);
869 x
= ev
.xmotion
.x_root
- dx
;
870 y
= ev
.xmotion
.y_root
- dy
;
871 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
878 if (ev
.xbutton
.button
!= clickButton
)
881 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
882 wwin
->flags
.icon_moved
= 1;
884 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
888 XUngrabPointer(dpy
, CurrentTime
);
890 if (wPreferences
.auto_arrange_icons
)
891 wArrangeIcons(wwin
->screen_ptr
, True
);
892 if (wPreferences
.single_click
&& !hasMoved
)
893 miniwindowDblClick(desc
, event
);
900 void set_icon_image_from_database(WIcon
*icon
, char *wm_instance
, char *wm_class
, char *command
)
904 file
= get_icon_filename(icon
->core
->screen_ptr
, wm_instance
, wm_class
, command
, False
);
906 icon
->file
= wstrdup(file
);
907 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);