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_pixmap_icon_from_icon_win(WIcon
*icon
);
65 static void get_rimage_icon_from_icon_win(WIcon
*icon
);
66 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
);
67 static int get_rimage_icon_from_wm_hints(WIcon
*icon
);
68 static void get_pixmap_icon_from_user_icon(WIcon
*icon
);
69 static void get_rimage_icon_from_user_icon(WIcon
*icon
);
70 static void get_pixmap_icon_from_default_icon(WIcon
*icon
);
71 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
72 static void get_pixmap_icon_from_x11(WIcon
*icon
);
73 static void get_rimage_icon_from_x11(WIcon
*icon
);
75 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
76 static void unset_icon_image(WIcon
*icon
);
78 /****** Notification Observers ******/
80 static void appearanceObserver(void *self
, WMNotification
* notif
)
82 WIcon
*icon
= (WIcon
*) self
;
83 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
85 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
86 icon
->force_paint
= 1;
90 /* so that the appicon expose handlers will paint the appicon specific
92 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
95 static void tileObserver(void *self
, WMNotification
* notif
)
97 WIcon
*icon
= (WIcon
*) self
;
99 icon
->force_paint
= 1;
102 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
105 /************************************/
107 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
113 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
116 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
118 WScreen
*scr
= wwin
->screen_ptr
;
122 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
125 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
126 if (wwin
->client_win
== wwin
->main_window
) {
128 /* do not let miniwindow steal app-icon's icon window */
129 wapp
= wApplicationOf(wwin
->client_win
);
130 if (!wapp
|| wapp
->app_icon
== NULL
)
131 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
133 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
136 #ifdef NO_MINIWINDOW_TITLES
137 icon
->show_title
= 0;
139 icon
->show_title
= 1;
142 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
144 wwin
->flags
.net_has_icon_title
= 1;
146 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
148 /* Get the application icon, default included */
149 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
151 icon
->file
= wstrdup(file
);
152 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
156 icon
->tile_type
= TILE_NORMAL
;
160 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
161 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
166 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
171 icon
= icon_create_core(scr
, 0, 0);
173 /* Search the icon using instance and class, without default icon */
174 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
176 icon
->file
= wstrdup(file
);
177 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
181 icon
->tile_type
= tile
;
185 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
186 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
191 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
194 unsigned long vmask
= 0;
195 XSetWindowAttributes attribs
;
197 icon
= wmalloc(sizeof(WIcon
));
198 icon
->core
= wCoreCreateTopLevel(scr
,
201 wPreferences
.icon_size
,
202 wPreferences
.icon_size
,
203 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
205 if (wPreferences
.use_saveunders
) {
207 attribs
.save_under
= True
;
210 /* a white border for selecting it */
211 vmask
|= CWBorderPixel
;
212 attribs
.border_pixel
= scr
->white_pixel
;
214 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
216 /* will be overriden if this is a application icon */
217 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
218 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
219 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
220 icon
->core
->descriptor
.parent
= icon
;
222 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
223 icon
->core
->stacking
->above
= NULL
;
224 icon
->core
->stacking
->under
= NULL
;
225 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
226 icon
->core
->stacking
->child_of
= NULL
;
230 icon
->file_image
= NULL
;
235 void wIconDestroy(WIcon
* icon
)
237 WCoreWindow
*core
= icon
->core
;
238 WScreen
*scr
= core
->screen_ptr
;
240 WMRemoveNotificationObserver(icon
);
243 WMDeleteTimerHandler(icon
->handlerID
);
245 if (icon
->icon_win
) {
249 x
= icon
->owner
->icon_x
;
250 y
= icon
->owner
->icon_y
;
252 XUnmapWindow(dpy
, icon
->icon_win
);
253 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
256 XFree(icon
->icon_name
);
259 XFreePixmap(dpy
, icon
->pixmap
);
261 unset_icon_image(icon
);
263 wCoreDestroy(icon
->core
);
267 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
269 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
270 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
271 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
272 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
273 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
276 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
283 WScreen
*scr
= icon
->core
->screen_ptr
;
284 int titled
= icon
->show_title
;
286 if (icon
->tile_type
== TILE_NORMAL
) {
287 tile
= RCloneImage(scr
->icon_tile
);
289 assert(scr
->clip_tile
);
290 tile
= RCloneImage(scr
->clip_tile
);
294 w
= (image
->width
> wPreferences
.icon_size
)
295 ? wPreferences
.icon_size
: image
->width
;
296 x
= (wPreferences
.icon_size
- w
) / 2;
297 sx
= (image
->width
- w
) / 2;
300 theight
= WMFontHeight(scr
->icon_title_font
);
302 h
= (image
->height
+ theight
> wPreferences
.icon_size
303 ? wPreferences
.icon_size
- theight
: image
->height
);
304 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
305 sy
= (image
->height
- h
) / 2;
307 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
310 if (icon
->shadowed
) {
313 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
314 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
315 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
316 color
.alpha
= 150; /* about 60% */
317 RClearImage(tile
, &color
);
320 if (icon
->highlighted
) {
323 color
.red
= color
.green
= color
.blue
= 0;
325 RLightImage(tile
, &color
);
328 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
329 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
334 drawIconTitle(scr
, pixmap
, theight
);
336 icon
->pixmap
= pixmap
;
339 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
343 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
344 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
346 if (icon
->icon_name
!= NULL
)
347 XFree(icon
->icon_name
);
349 icon
->icon_name
= new_title
;
352 icon
->force_paint
= 1;
356 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
363 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
364 if ((icon
->width
- max_size
) > -ICON_BORDER
||
365 (icon
->height
- max_size
) > -ICON_BORDER
) {
366 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
367 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
375 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
377 WScreen
*scr
= icon
->core
->screen_ptr
;
379 RImage
*image
= NULL
;
382 /* If no new image, don't do nothing */
386 /* Find the new image */
387 path
= FindImage(wPreferences
.icon_path
, file
);
389 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
394 if (!error
&& image
) {
395 /* Remove the old one */
396 unset_icon_image(icon
);
398 /* Set the new image */
399 icon
->file_image
= image
;
400 icon
->file
= wstrdup(path
);
412 static char *get_name_for_wwin(WWindow
*wwin
)
414 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
417 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
422 if (wm_class
&& wm_instance
) {
423 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
424 suffix
= wmalloc(len
);
425 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
426 } else if (wm_class
) {
427 len
= strlen(wm_class
) + 1;
428 suffix
= wmalloc(len
);
429 snprintf(suffix
, len
, "%s", wm_class
);
430 } else if (wm_instance
) {
431 len
= strlen(wm_instance
) + 1;
432 suffix
= wmalloc(len
);
433 snprintf(suffix
, len
, "%s", wm_instance
);
441 static char *get_icon_cache_path(void)
446 prefix
= wusergnusteppath();
447 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
449 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
451 /* If the folder exists, exit */
452 if (access(path
, F_OK
) == 0)
455 /* Create the folder */
456 ret
= wmkdirhier((const char *) path
);
458 /* Exit 1 on success, 0 on failure */
467 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
469 RImage
*image
= NULL
;
470 XWMHints
*hints
= wwin
->wm_hints
;
472 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
473 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
475 (hints
->flags
& IconMaskHint
)
476 ? hints
->icon_mask
: None
);
483 * Stores the client supplied icon at CACHE_ICON_PATH
484 * and returns the path for that icon. Returns NULL if there is no
485 * client supplied icon or on failure.
488 * New directories might be created.
490 char *wIconStore(WIcon
* icon
)
492 char *path
, *dir_path
, *file
;
494 RImage
*image
= NULL
;
495 WWindow
*wwin
= icon
->owner
;
500 dir_path
= get_icon_cache_path();
504 file
= get_name_for_wwin(wwin
);
510 len
= strlen(dir_path
) + strlen(file
) + 5;
512 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
516 /* If icon exists, exit */
517 if (access(path
, F_OK
) == 0)
520 if (wwin
->net_icon_image
)
521 image
= RRetainImage(wwin
->net_icon_image
);
523 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
530 if (!RSaveImage(image
, path
, "XPM")) {
535 RReleaseImage(image
);
540 static void cycleColor(void *data
)
542 WIcon
*icon
= (WIcon
*) data
;
543 WScreen
*scr
= icon
->core
->screen_ptr
;
547 gcv
.dash_offset
= icon
->step
;
548 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
550 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
551 icon
->core
->width
- 1, icon
->core
->height
- 1);
552 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
556 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
558 if (icon
->highlighted
== flag
)
561 icon
->highlighted
= flag
;
562 icon
->force_paint
= True
;
567 void wIconSelect(WIcon
* icon
)
569 WScreen
*scr
= icon
->core
->screen_ptr
;
570 icon
->selected
= !icon
->selected
;
572 if (icon
->selected
) {
574 if (!wPreferences
.dont_blink
)
575 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
577 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
578 icon
->core
->width
- 1, icon
->core
->height
- 1);
580 if (icon
->handlerID
) {
581 WMDeleteTimerHandler(icon
->handlerID
);
582 icon
->handlerID
= NULL
;
584 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
588 static void unset_icon_image(WIcon
*icon
)
593 if (icon
->file_image
)
594 RReleaseImage(icon
->file_image
);
597 void wIconUpdate(WIcon
*icon
)
599 WScreen
*scr
= icon
->core
->screen_ptr
;
600 WWindow
*wwin
= icon
->owner
;
602 assert(scr
->icon_tile
!= NULL
);
604 if (icon
->pixmap
!= None
)
605 XFreePixmap(dpy
, icon
->pixmap
);
609 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
610 /* Forced use user_icon */
611 get_pixmap_icon_from_user_icon(icon
);
612 } else if (icon
->icon_win
!= None
) {
613 /* Get the Pixmap from the WIcon */
614 get_pixmap_icon_from_icon_win(icon
);
615 } else if (wwin
&& wwin
->net_icon_image
) {
616 /* Use _NET_WM_ICON icon */
617 get_pixmap_icon_from_x11(icon
);
618 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
619 /* Get the Pixmap from the wm_hints, else, from the user */
620 if (get_pixmap_icon_from_wm_hints(icon
))
621 get_pixmap_icon_from_user_icon(icon
);
623 /* Get the Pixmap from the user */
624 get_pixmap_icon_from_user_icon(icon
);
627 /* No pixmap, set default background */
628 if (icon
->pixmap
!= None
)
629 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
632 XClearWindow(dpy
, icon
->core
->window
);
636 static void get_pixmap_icon_from_x11(WIcon
*icon
)
638 /* Set the icon->file_image */
639 get_rimage_icon_from_x11(icon
);
641 /* Update icon->pixmap */
642 icon_update_pixmap(icon
, icon
->file_image
);
645 static void get_rimage_icon_from_x11(WIcon
*icon
)
647 /* Remove the icon image */
648 unset_icon_image(icon
);
650 /* Set the new icon image */
652 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
655 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
657 if (icon
->file_image
)
660 get_rimage_icon_from_default_icon(icon
);
663 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
665 /* Set the icon->file_image */
666 get_rimage_icon_from_user_icon(icon
);
668 /* Update icon->pixmap */
669 icon_update_pixmap(icon
, icon
->file_image
);
672 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
674 WScreen
*scr
= icon
->core
->screen_ptr
;
676 /* If the icon don't have image, we should use the default image. */
677 if (!scr
->def_icon_rimage
)
678 scr
->def_icon_rimage
= get_default_image(scr
);
680 /* Remove the icon image */
681 unset_icon_image(icon
);
683 /* Set the new icon image */
685 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
688 static void get_pixmap_icon_from_default_icon(WIcon
*icon
)
690 /* Update icon->file image */
691 get_rimage_icon_from_default_icon(icon
);
693 /* Now, create the pixmap using the default (saved) image */
694 icon_update_pixmap(icon
, icon
->file_image
);
697 /* Get the RImage from the WIcon of the WWindow */
698 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
702 /* Create the new RImage */
703 image
= get_window_image_from_x11(icon
->icon_win
);
705 /* Free the icon info */
706 unset_icon_image(icon
);
708 /* Set the new info */
710 icon
->file_image
= image
;
713 /* Get the Pixmap from the WIcon of the WWindow */
714 static void get_pixmap_icon_from_icon_win(WIcon
*icon
)
716 /* Get the RImage and set in icon->file_image */
717 get_rimage_icon_from_icon_win(icon
);
719 /* Paint the image at the icon */
720 icon_update_pixmap(icon
, icon
->file_image
);
722 /* Put the dockapp in the icon */
723 set_dockapp_in_icon(icon
);
726 /* Set the dockapp in the WIcon */
727 static void set_dockapp_in_icon(WIcon
*icon
)
729 XWindowAttributes attr
;
730 WScreen
*scr
= icon
->core
->screen_ptr
;
731 int title_height
= WMFontHeight(scr
->icon_title_font
);
732 unsigned int w
, h
, d
;
735 /* Reparent the dock application to the icon */
737 /* We need the application size to center it
738 * and show in the correct position */
739 getSize(icon
->icon_win
, &w
, &h
, &d
);
741 /* Set extra space for title */
742 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
743 theight
= title_height
;
744 drawIconTitle(scr
, icon
->pixmap
, theight
);
746 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
749 /* Set the icon border */
750 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
752 /* Put the dock application in the icon */
753 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
754 (wPreferences
.icon_size
- w
) / 2,
755 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
757 /* Show it and save */
758 XMapWindow(dpy
, icon
->icon_win
);
759 XAddToSaveSet(dpy
, icon
->icon_win
);
761 /* Needed to move the icon clicking on the application part */
762 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
763 (attr
.all_event_masks
& ButtonPressMask
))
764 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
765 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
766 None
, wCursor
[WCUR_ARROW
]);
769 /* Get the RImage from the XWindow wm_hints */
770 static int get_rimage_icon_from_wm_hints(WIcon
*icon
)
772 RImage
*image
= NULL
;
773 unsigned int w
, h
, d
;
774 WWindow
*wwin
= icon
->owner
;
776 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
777 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
781 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
785 /* FIXME: If unset_icon_image, pointer double free then crash
786 unset_icon_image(icon); */
787 icon
->file_image
= image
;
792 /* Get the Pixmap from the XWindow wm_hints */
793 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
797 ret
= get_rimage_icon_from_wm_hints(icon
);
799 icon_update_pixmap(icon
, icon
->file_image
);
804 void wIconPaint(WIcon
* icon
)
806 WScreen
*scr
= icon
->core
->screen_ptr
;
810 if (icon
->force_paint
) {
811 icon
->force_paint
= 0;
816 XClearWindow(dpy
, icon
->core
->window
);
818 /* draw the icon title */
819 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
823 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
824 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
826 if (w
> icon
->core
->width
- 4)
827 x
= (icon
->core
->width
- 4) - w
;
829 x
= (icon
->core
->width
- w
) / 2;
831 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
832 scr
->icon_title_font
, x
, 1, tmp
, l
);
837 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
838 icon
->core
->width
- 1, icon
->core
->height
- 1);
841 /******************************************************************/
843 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
845 wIconPaint(desc
->parent
);
848 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
850 WIcon
*icon
= desc
->parent
;
852 assert(icon
->owner
!= NULL
);
854 wDeiconifyWindow(icon
->owner
);
857 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
859 WIcon
*icon
= desc
->parent
;
860 WWindow
*wwin
= icon
->owner
;
862 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
863 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
865 int clickButton
= event
->xbutton
.button
;
866 Bool hasMoved
= False
;
868 if (WCHECK_STATE(WSTATE_MODAL
))
871 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
872 miniwindowDblClick(desc
, event
);
876 if (event
->xbutton
.button
== Button1
) {
877 if (event
->xbutton
.state
& MOD_MASK
)
878 wLowerFrame(icon
->core
);
880 wRaiseFrame(icon
->core
);
881 if (event
->xbutton
.state
& ShiftMask
) {
883 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
885 } else if (event
->xbutton
.button
== Button3
) {
886 WObjDescriptor
*desc
;
888 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
890 /* allow drag select of menu */
891 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
892 event
->xbutton
.send_event
= True
;
893 (*desc
->handle_mousedown
) (desc
, event
);
898 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
899 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
900 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
903 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
904 | ButtonMotionMask
| ExposureMask
, &ev
);
913 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
914 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
915 XChangeActivePointerGrab(dpy
, ButtonMotionMask
916 | ButtonReleaseMask
| ButtonPressMask
,
917 wCursor
[WCUR_MOVE
], CurrentTime
);
923 x
= ev
.xmotion
.x_root
- dx
;
924 y
= ev
.xmotion
.y_root
- dy
;
925 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
932 if (ev
.xbutton
.button
!= clickButton
)
935 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
936 wwin
->flags
.icon_moved
= 1;
938 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
942 XUngrabPointer(dpy
, CurrentTime
);
944 if (wPreferences
.auto_arrange_icons
)
945 wArrangeIcons(wwin
->screen_ptr
, True
);
946 if (wPreferences
.single_click
&& !hasMoved
)
947 miniwindowDblClick(desc
, event
);