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 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 /* Parameter not used, but tell the compiler that it is ok */
99 update_icon_pixmap(icon
);
101 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
104 /************************************/
106 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
112 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
115 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
117 WScreen
*scr
= wwin
->screen_ptr
;
120 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
123 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
124 if (wwin
->client_win
== wwin
->main_window
) {
126 /* do not let miniwindow steal app-icon's icon window */
127 wapp
= wApplicationOf(wwin
->client_win
);
128 if (!wapp
|| wapp
->app_icon
== NULL
)
129 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
131 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
134 #ifdef NO_MINIWINDOW_TITLES
135 icon
->show_title
= 0;
137 icon
->show_title
= 1;
140 wIconChangeTitle(icon
, wwin
);
141 icon
->tile_type
= TILE_NORMAL
;
143 set_icon_image_from_database(icon
, wwin
->wm_instance
, wwin
->wm_class
, NULL
);
144 /* Update the icon, because icon could be NULL */
147 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
148 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
153 WIcon
*icon_create_for_dock(WScreen
*scr
, const char *command
, const char *wm_instance
, const 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
);
161 /* Update the icon, because icon could be NULL */
164 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
165 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
170 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
174 icon
= wmalloc(sizeof(WIcon
));
175 icon
->core
= wCoreCreateTopLevel(scr
,
178 wPreferences
.icon_size
,
179 wPreferences
.icon_size
,
180 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
,
183 /* will be overriden if this is a application icon */
184 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
185 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
186 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
187 icon
->core
->descriptor
.parent
= icon
;
189 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
190 icon
->core
->stacking
->above
= NULL
;
191 icon
->core
->stacking
->under
= NULL
;
192 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
193 icon
->core
->stacking
->child_of
= NULL
;
197 icon
->file_image
= NULL
;
202 void wIconDestroy(WIcon
*icon
)
204 WCoreWindow
*core
= icon
->core
;
205 WScreen
*scr
= core
->screen_ptr
;
207 WMRemoveNotificationObserver(icon
);
210 WMDeleteTimerHandler(icon
->handlerID
);
212 if (icon
->icon_win
) {
216 x
= icon
->owner
->icon_x
;
217 y
= icon
->owner
->icon_y
;
219 XUnmapWindow(dpy
, icon
->icon_win
);
220 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
223 XFree(icon
->icon_name
);
226 XFreePixmap(dpy
, icon
->pixmap
);
229 XFreePixmap(dpy
, icon
->apercu
);
231 unset_icon_image(icon
);
233 wCoreDestroy(icon
->core
);
237 static void drawIconTitleBackground(WScreen
*scr
, Pixmap pixmap
, int height
)
239 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
240 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
241 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
242 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
243 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
246 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
253 WScreen
*scr
= icon
->core
->screen_ptr
;
255 switch (icon
->tile_type
) {
257 tile
= RCloneImage(scr
->icon_tile
);
260 tile
= RCloneImage(scr
->clip_tile
);
263 tile
= RCloneImage(scr
->drawer_tile
);
267 * The icon has always rigth value, this case is
268 * only to avoid a compiler warning with "tile"
269 * "may be used uninitialized"
271 wwarning("Unknown tile type: %d.\n", icon
->tile_type
);
272 tile
= RCloneImage(scr
->icon_tile
);
276 w
= (image
->width
> wPreferences
.icon_size
)
277 ? wPreferences
.icon_size
: image
->width
;
278 x
= (wPreferences
.icon_size
- w
) / 2;
279 sx
= (image
->width
- w
) / 2;
281 if (icon
->show_title
)
282 theight
= WMFontHeight(scr
->icon_title_font
);
284 h
= (image
->height
+ theight
> wPreferences
.icon_size
285 ? wPreferences
.icon_size
- theight
: image
->height
);
286 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
287 sy
= (image
->height
- h
) / 2;
289 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
292 if (icon
->shadowed
) {
295 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
296 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
297 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
298 color
.alpha
= 150; /* about 60% */
299 RClearImage(tile
, &color
);
302 if (icon
->highlighted
) {
305 color
.red
= color
.green
= color
.blue
= 0;
307 RLightImage(tile
, &color
);
310 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
311 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
315 /* Draw the icon's title background (without text) */
316 if (icon
->show_title
)
317 drawIconTitleBackground(scr
, pixmap
, theight
);
319 icon
->pixmap
= pixmap
;
322 void wIconChangeTitle(WIcon
*icon
, WWindow
*wwin
)
327 /* Remove the previous icon title */
328 if (icon
->icon_name
!= NULL
)
329 XFree(icon
->icon_name
);
331 /* Set the new one, using two methods to identify
332 the icon name or switch back to window name */
333 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
334 if (!icon
->icon_name
)
335 if (!wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
))
336 icon
->icon_name
= wNETWMGetWindowName(wwin
->client_win
);
339 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
346 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
347 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
348 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
349 if (icon
->width
> icon
->height
)
350 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
351 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
353 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
354 max_size
- ICON_BORDER
);
362 int wIconChangeImageFile(WIcon
*icon
, const char *file
)
364 WScreen
*scr
= icon
->core
->screen_ptr
;
366 RImage
*image
= NULL
;
368 /* If no new image, don't do nothing */
372 /* Find the new image */
373 path
= FindImage(wPreferences
.icon_path
, file
);
377 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
383 /* Set the new image */
384 set_icon_image_from_image(icon
, image
);
385 icon
->file
= wstrdup(path
);
386 update_icon_pixmap(icon
);
392 static char *get_name_for_wwin(WWindow
*wwin
)
394 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
397 char *get_name_for_instance_class(const char *wm_instance
, const char *wm_class
)
402 if (wm_class
&& wm_instance
) {
403 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
404 suffix
= wmalloc(len
);
405 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
406 } else if (wm_class
) {
407 len
= strlen(wm_class
) + 1;
408 suffix
= wmalloc(len
);
409 snprintf(suffix
, len
, "%s", wm_class
);
410 } else if (wm_instance
) {
411 len
= strlen(wm_instance
) + 1;
412 suffix
= wmalloc(len
);
413 snprintf(suffix
, len
, "%s", wm_instance
);
421 static char *get_icon_cache_path(void)
427 prefix
= wusergnusteppath();
428 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
430 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
432 /* If the folder exists, exit */
433 if (access(path
, F_OK
) == 0)
436 /* Create the folder */
437 ret
= wmkdirhier((const char *) path
);
439 /* Exit 1 on success, 0 on failure */
448 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
450 RImage
*image
= NULL
;
451 XWMHints
*hints
= wwin
->wm_hints
;
453 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
454 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
456 (hints
->flags
& IconMaskHint
)
457 ? hints
->icon_mask
: None
);
464 * Stores the client supplied icon at CACHE_ICON_PATH
465 * and returns the path for that icon. Returns NULL if there is no
466 * client supplied icon or on failure.
469 * New directories might be created.
471 char *wIconStore(WIcon
*icon
)
473 char *path
, *dir_path
, *file
;
475 RImage
*image
= NULL
;
476 WWindow
*wwin
= icon
->owner
;
481 dir_path
= get_icon_cache_path();
485 file
= get_name_for_wwin(wwin
);
491 len
= strlen(dir_path
) + strlen(file
) + 5;
493 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
497 /* If icon exists, exit */
498 if (access(path
, F_OK
) == 0)
501 if (wwin
->net_icon_image
)
502 image
= RRetainImage(wwin
->net_icon_image
);
504 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
511 if (!RSaveImage(image
, path
, "XPM")) {
516 RReleaseImage(image
);
521 static void cycleColor(void *data
)
523 WIcon
*icon
= (WIcon
*) data
;
524 WScreen
*scr
= icon
->core
->screen_ptr
;
528 gcv
.dash_offset
= icon
->step
;
529 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
531 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
532 icon
->core
->width
- 1, icon
->core
->height
- 1);
533 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
536 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
538 if (icon
->highlighted
== flag
)
541 icon
->highlighted
= flag
;
542 update_icon_pixmap(icon
);
545 void wIconSelect(WIcon
*icon
)
547 WScreen
*scr
= icon
->core
->screen_ptr
;
548 icon
->selected
= !icon
->selected
;
550 if (icon
->selected
) {
552 if (!wPreferences
.dont_blink
)
553 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
555 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
556 icon
->core
->width
- 1, icon
->core
->height
- 1);
558 if (icon
->handlerID
) {
559 WMDeleteTimerHandler(icon
->handlerID
);
560 icon
->handlerID
= NULL
;
562 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
566 static void unset_icon_image(WIcon
*icon
)
573 if (icon
->file_image
) {
574 RReleaseImage(icon
->file_image
);
575 icon
->file_image
= NULL
;
579 void set_icon_image_from_image(WIcon
*icon
, RImage
*image
)
584 unset_icon_image(icon
);
586 icon
->file_image
= NULL
;
587 icon
->file_image
= image
;
590 void set_icon_apercu(WIcon
*icon
, RImage
*image
)
593 RImage
*scaled_apercu
;
594 WScreen
*scr
= icon
->core
->screen_ptr
;
596 scaled_apercu
= RSmoothScaleImage(image
, (wPreferences
.icon_size
- 1 - APERCU_BORDER
) * wPreferences
.apercu_size
,
597 (wPreferences
.icon_size
- 1 - APERCU_BORDER
) * wPreferences
.apercu_size
);
599 if (RConvertImage(scr
->rcontext
, scaled_apercu
, &tmp
)) {
600 if (icon
->apercu
!= None
)
601 XFreePixmap(dpy
, icon
->apercu
);
604 RReleaseImage(scaled_apercu
);
607 void wIconUpdate(WIcon
*icon
)
609 WWindow
*wwin
= NULL
;
611 if (icon
&& icon
->owner
)
614 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
615 /* Forced use user_icon */
616 get_rimage_icon_from_user_icon(icon
);
617 } else if (icon
->icon_win
!= None
) {
618 /* Get the Pixmap from the WIcon */
619 get_rimage_icon_from_icon_win(icon
);
620 } else if (wwin
&& wwin
->net_icon_image
) {
621 /* Use _NET_WM_ICON icon */
622 get_rimage_icon_from_x11(icon
);
623 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
624 /* Get the Pixmap from the wm_hints, else, from the user */
625 unset_icon_image(icon
);
626 icon
->file_image
= get_rimage_icon_from_wm_hints(icon
);
627 if (!icon
->file_image
)
628 get_rimage_icon_from_user_icon(icon
);
630 /* Get the Pixmap from the user */
631 get_rimage_icon_from_user_icon(icon
);
634 update_icon_pixmap(icon
);
637 void update_icon_pixmap(WIcon
*icon
)
639 if (icon
->pixmap
!= None
)
640 XFreePixmap(dpy
, icon
->pixmap
);
644 /* Create the pixmap */
645 if (icon
->file_image
)
646 icon_update_pixmap(icon
, icon
->file_image
);
648 /* If dockapp, put inside the icon */
649 if (icon
->icon_win
!= None
) {
650 /* file_image is NULL, because is docked app */
651 icon_update_pixmap(icon
, NULL
);
652 set_dockapp_in_icon(icon
);
655 /* No pixmap, set default background */
656 if (icon
->pixmap
!= None
)
657 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
663 static void get_rimage_icon_from_x11(WIcon
*icon
)
665 /* Remove the icon image */
666 unset_icon_image(icon
);
668 /* Set the new icon image */
669 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
672 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
674 if (icon
->file_image
)
677 get_rimage_icon_from_default_icon(icon
);
680 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
682 WScreen
*scr
= icon
->core
->screen_ptr
;
684 /* If the icon don't have image, we should use the default image. */
685 if (!scr
->def_icon_rimage
)
686 scr
->def_icon_rimage
= get_default_image(scr
);
688 /* Remove the icon image */
689 unset_icon_image(icon
);
691 /* Set the new icon image */
692 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
695 /* Get the RImage from the WIcon of the WWindow */
696 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
700 /* Create the new RImage */
701 image
= get_window_image_from_x11(icon
->icon_win
);
703 /* Free the icon info */
704 unset_icon_image(icon
);
706 /* Set the new info */
707 icon
->file_image
= image
;
710 /* Set the dockapp in the WIcon */
711 static void set_dockapp_in_icon(WIcon
*icon
)
713 XWindowAttributes attr
;
714 WScreen
*scr
= icon
->core
->screen_ptr
;
715 unsigned int w
, h
, d
;
717 /* Reparent the dock application to the icon */
719 /* We need the application size to center it
720 * and show in the correct position */
721 getSize(icon
->icon_win
, &w
, &h
, &d
);
723 /* Set the background pixmap */
724 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
726 /* Set the icon border */
727 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
729 /* Put the dock application in the icon */
730 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
731 (wPreferences
.icon_size
- w
) / 2,
732 (wPreferences
.icon_size
- h
) / 2);
734 /* Show it and save */
735 XMapWindow(dpy
, icon
->icon_win
);
736 XAddToSaveSet(dpy
, icon
->icon_win
);
738 /* Needed to move the icon clicking on the application part */
739 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
740 (attr
.all_event_masks
& ButtonPressMask
))
741 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
742 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
743 None
, wPreferences
.cursor
[WCUR_ARROW
]);
746 /* Get the RImage from the XWindow wm_hints */
747 RImage
*get_rimage_icon_from_wm_hints(WIcon
*icon
)
749 RImage
*image
= NULL
;
750 unsigned int w
, h
, d
;
751 WWindow
*wwin
= icon
->owner
;
753 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
754 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
758 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
762 /* Resize the icon to the wPreferences.icon_size size */
763 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
768 /* This function updates in the screen the icon title */
769 static void update_icon_title(WIcon
*icon
)
771 WScreen
*scr
= icon
->core
->screen_ptr
;
775 /* draw the icon title */
776 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
777 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
778 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
780 if (w
> icon
->core
->width
- 4)
781 x
= (icon
->core
->width
- 4) - w
;
783 x
= (icon
->core
->width
- w
) / 2;
785 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
786 scr
->icon_title_font
, x
, 1, tmp
, l
);
792 void wIconPaint(WIcon
*icon
)
794 if (!icon
|| !icon
->core
|| !icon
->core
->screen_ptr
)
797 WScreen
*scr
= icon
->core
->screen_ptr
;
799 XClearWindow(dpy
, icon
->core
->window
);
801 update_icon_title(icon
);
804 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
805 icon
->core
->width
- 1, icon
->core
->height
- 1);
808 /******************************************************************/
810 static void miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
812 /* Parameter not used, but tell the compiler that it is ok */
815 wIconPaint(desc
->parent
);
818 static void miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
820 WIcon
*icon
= desc
->parent
;
822 /* Parameter not used, but tell the compiler that it is ok */
825 assert(icon
->owner
!= NULL
);
827 wDeiconifyWindow(icon
->owner
);
830 static void miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
832 WIcon
*icon
= desc
->parent
;
833 WWindow
*wwin
= icon
->owner
;
835 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
836 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
838 int clickButton
= event
->xbutton
.button
;
839 Bool hasMoved
= False
;
841 if (WCHECK_STATE(WSTATE_MODAL
))
844 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
845 miniwindowDblClick(desc
, event
);
849 if (event
->xbutton
.button
== Button1
) {
850 if (event
->xbutton
.state
& MOD_MASK
)
851 wLowerFrame(icon
->core
);
853 wRaiseFrame(icon
->core
);
854 if (event
->xbutton
.state
& ShiftMask
) {
856 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
858 } else if (event
->xbutton
.button
== Button3
) {
859 WObjDescriptor
*desc
;
861 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
863 /* allow drag select of menu */
864 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
865 event
->xbutton
.send_event
= True
;
866 (*desc
->handle_mousedown
) (desc
, event
);
871 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
872 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
873 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
876 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
877 | ButtonMotionMask
| ExposureMask
, &ev
);
886 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
887 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
888 XChangeActivePointerGrab(dpy
, ButtonMotionMask
889 | ButtonReleaseMask
| ButtonPressMask
,
890 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
896 x
= ev
.xmotion
.x_root
- dx
;
897 y
= ev
.xmotion
.y_root
- dy
;
898 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
905 if (ev
.xbutton
.button
!= clickButton
)
908 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
909 wwin
->flags
.icon_moved
= 1;
911 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
915 XUngrabPointer(dpy
, CurrentTime
);
917 if (wPreferences
.auto_arrange_icons
)
918 wArrangeIcons(wwin
->screen_ptr
, True
);
919 if (wPreferences
.single_click
&& !hasMoved
)
920 miniwindowDblClick(desc
, event
);
927 void set_icon_image_from_database(WIcon
*icon
, const char *wm_instance
, const char *wm_class
, const char *command
)
931 file
= get_icon_filename(wm_instance
, wm_class
, command
, False
);
933 icon
->file
= wstrdup(file
);
934 icon
->file_image
= get_rimage_from_file(icon
->core
->screen_ptr
, icon
->file
, wPreferences
.icon_size
);