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 get_pixmap_icon_from_icon_win(WIcon
*icon
);
64 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
);
65 static void get_pixmap_icon_from_user_icon(WIcon
*icon
);
67 static Pixmap
makeIcon(WScreen
*scr
, RImage
*image
,
68 int titled
, int shadowed
,
69 int tileType
, int highlighted
);
70 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
72 static RImage
*get_default_image(WScreen
*scr
);
73 /****** Notification Observers ******/
75 static void appearanceObserver(void *self
, WMNotification
* notif
)
77 WIcon
*icon
= (WIcon
*) self
;
78 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
80 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
81 icon
->force_paint
= 1;
85 /* so that the appicon expose handlers will paint the appicon specific
87 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
90 static void tileObserver(void *self
, WMNotification
* notif
)
92 WIcon
*icon
= (WIcon
*) self
;
94 icon
->force_paint
= 1;
97 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
100 /************************************/
102 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
108 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
111 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
113 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 /* Get the application icon, default included */
144 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
146 icon
->file
= wstrdup(file
);
147 icon
->file_image
= get_default_icon_rimage(scr
, icon
->file
, wPreferences
.icon_size
);
151 icon
->tile_type
= TILE_NORMAL
;
155 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
156 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
161 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
166 icon
= icon_create_core(scr
, 0, 0);
168 /* Search the icon using instance and class, without default icon */
169 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
171 icon
->file
= wstrdup(file
);
172 icon
->file_image
= get_default_icon_rimage(scr
, icon
->file
, wPreferences
.icon_size
);
176 icon
->tile_type
= tile
;
180 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
181 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
186 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
189 unsigned long vmask
= 0;
190 XSetWindowAttributes attribs
;
192 icon
= wmalloc(sizeof(WIcon
));
193 icon
->core
= wCoreCreateTopLevel(scr
,
196 wPreferences
.icon_size
,
197 wPreferences
.icon_size
,
198 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
200 if (wPreferences
.use_saveunders
) {
202 attribs
.save_under
= True
;
205 /* a white border for selecting it */
206 vmask
|= CWBorderPixel
;
207 attribs
.border_pixel
= scr
->white_pixel
;
209 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
211 /* will be overriden if this is a application icon */
212 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
213 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
214 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
215 icon
->core
->descriptor
.parent
= icon
;
217 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
218 icon
->core
->stacking
->above
= NULL
;
219 icon
->core
->stacking
->under
= NULL
;
220 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
221 icon
->core
->stacking
->child_of
= NULL
;
225 icon
->file_image
= NULL
;
230 void wIconDestroy(WIcon
* icon
)
232 WCoreWindow
*core
= icon
->core
;
233 WScreen
*scr
= core
->screen_ptr
;
235 WMRemoveNotificationObserver(icon
);
238 WMDeleteTimerHandler(icon
->handlerID
);
240 if (icon
->icon_win
) {
244 x
= icon
->owner
->icon_x
;
245 y
= icon
->owner
->icon_y
;
247 XUnmapWindow(dpy
, icon
->icon_win
);
248 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
251 XFree(icon
->icon_name
);
254 XFreePixmap(dpy
, icon
->pixmap
);
259 if (icon
->file_image
!= NULL
)
260 RReleaseImage(icon
->file_image
);
262 wCoreDestroy(icon
->core
);
266 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
268 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
269 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
270 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
271 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
272 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
275 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
277 WScreen
*scr
= icon
->core
->screen_ptr
;
279 /* Update the WIcon pixmap */
280 icon
->pixmap
= makeIcon(scr
, image
,
281 icon
->show_title
, icon
->shadowed
,
282 icon
->tile_type
, icon
->highlighted
);
285 static Pixmap
makeIcon(WScreen
*scr
, RImage
*image
, int titled
, int shadowed
, int tileType
, int highlighted
)
293 if (tileType
== TILE_NORMAL
) {
294 tile
= RCloneImage(scr
->icon_tile
);
296 assert(scr
->clip_tile
);
297 tile
= RCloneImage(scr
->clip_tile
);
301 w
= (image
->width
> wPreferences
.icon_size
)
302 ? wPreferences
.icon_size
: image
->width
;
303 x
= (wPreferences
.icon_size
- w
) / 2;
304 sx
= (image
->width
- w
) / 2;
307 theight
= WMFontHeight(scr
->icon_title_font
);
309 h
= (image
->height
+ theight
> wPreferences
.icon_size
310 ? wPreferences
.icon_size
- theight
: image
->height
);
311 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
312 sy
= (image
->height
- h
) / 2;
314 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
320 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
321 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
322 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
323 color
.alpha
= 150; /* about 60% */
324 RClearImage(tile
, &color
);
330 color
.red
= color
.green
= color
.blue
= 0;
332 RLightImage(tile
, &color
);
335 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
336 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
341 drawIconTitle(scr
, pixmap
, theight
);
346 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
350 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
351 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
353 if (icon
->icon_name
!= NULL
)
354 XFree(icon
->icon_name
);
356 icon
->icon_name
= new_title
;
359 icon
->force_paint
= 1;
363 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
370 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
371 if ((icon
->width
- max_size
) > -ICON_BORDER
||
372 (icon
->height
- max_size
) > -ICON_BORDER
) {
373 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
374 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
382 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
384 WScreen
*scr
= icon
->core
->screen_ptr
;
389 if (icon
->file_image
) {
390 RReleaseImage(icon
->file_image
);
391 icon
->file_image
= NULL
;
399 path
= FindImage(wPreferences
.icon_path
, file
);
401 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
402 icon
->file_image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
414 static char *get_name_for_wwin(WWindow
*wwin
)
416 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
419 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
424 if (wm_class
&& wm_instance
) {
425 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
426 suffix
= wmalloc(len
);
427 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
428 } else if (wm_class
) {
429 len
= strlen(wm_class
) + 1;
430 suffix
= wmalloc(len
);
431 snprintf(suffix
, len
, "%s", wm_class
);
432 } else if (wm_instance
) {
433 len
= strlen(wm_instance
) + 1;
434 suffix
= wmalloc(len
);
435 snprintf(suffix
, len
, "%s", wm_instance
);
443 static char *get_icon_cache_path(void)
448 prefix
= wusergnusteppath();
449 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
451 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
453 /* If the folder exists, exit */
454 if (access(path
, F_OK
) == 0)
457 /* Create the folder */
458 ret
= wmkdirhier((const char *) path
);
460 /* Exit 1 on success, 0 on failure */
469 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
471 RImage
*image
= NULL
;
472 XWMHints
*hints
= wwin
->wm_hints
;
474 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
475 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
477 (hints
->flags
& IconMaskHint
)
478 ? hints
->icon_mask
: None
);
485 * Stores the client supplied icon at CACHE_ICON_PATH
486 * and returns the path for that icon. Returns NULL if there is no
487 * client supplied icon or on failure.
490 * New directories might be created.
492 char *wIconStore(WIcon
* icon
)
494 char *path
, *dir_path
, *file
;
496 RImage
*image
= NULL
;
497 WWindow
*wwin
= icon
->owner
;
502 dir_path
= get_icon_cache_path();
506 file
= get_name_for_wwin(wwin
);
512 len
= strlen(dir_path
) + strlen(file
) + 5;
514 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
518 /* If icon exists, exit */
519 if (access(path
, F_OK
) == 0)
522 if (wwin
->net_icon_image
)
523 image
= RRetainImage(wwin
->net_icon_image
);
525 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
532 if (!RSaveImage(image
, path
, "XPM")) {
537 RReleaseImage(image
);
542 static void cycleColor(void *data
)
544 WIcon
*icon
= (WIcon
*) data
;
545 WScreen
*scr
= icon
->core
->screen_ptr
;
549 gcv
.dash_offset
= icon
->step
;
550 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
552 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
553 icon
->core
->width
- 1, icon
->core
->height
- 1);
554 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
558 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
560 if (icon
->highlighted
== flag
)
563 icon
->highlighted
= flag
;
564 icon
->force_paint
= True
;
569 void wIconSelect(WIcon
* icon
)
571 WScreen
*scr
= icon
->core
->screen_ptr
;
572 icon
->selected
= !icon
->selected
;
574 if (icon
->selected
) {
576 if (!wPreferences
.dont_blink
)
577 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
579 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
580 icon
->core
->width
- 1, icon
->core
->height
- 1);
582 if (icon
->handlerID
) {
583 WMDeleteTimerHandler(icon
->handlerID
);
584 icon
->handlerID
= NULL
;
586 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
590 void wIconUpdate(WIcon
*icon
)
592 WScreen
*scr
= icon
->core
->screen_ptr
;
593 WWindow
*wwin
= icon
->owner
;
595 assert(scr
->icon_tile
!= NULL
);
597 if (icon
->pixmap
!= None
)
598 XFreePixmap(dpy
, icon
->pixmap
);
602 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
603 /* Forced use user_icon */
604 get_pixmap_icon_from_user_icon(icon
);
605 } else if (icon
->icon_win
!= None
) {
606 /* Get the Pixmap from the WIcon */
607 get_pixmap_icon_from_icon_win(icon
);
608 } else if (wwin
&& wwin
->net_icon_image
) {
609 /* Use _NET_WM_ICON icon */
610 icon_update_pixmap(icon
, wwin
->net_icon_image
);
611 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
612 /* Get the Pixmap from the wm_hints, else, from the user */
613 if (get_pixmap_icon_from_wm_hints(icon
))
614 get_pixmap_icon_from_user_icon(icon
);
616 /* Get the Pixmap from the user */
617 get_pixmap_icon_from_user_icon(icon
);
620 /* No pixmap, set default background */
621 if (icon
->pixmap
!= None
)
622 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
625 XClearWindow(dpy
, icon
->core
->window
);
629 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
631 RImage
*image
= NULL
;
632 WScreen
*scr
= icon
->core
->screen_ptr
;
634 if (icon
->file_image
) {
635 icon_update_pixmap(icon
, icon
->file_image
);
637 /* make default icons */
638 if (!scr
->def_icon_pixmap
) {
639 image
= get_default_image(scr
);
640 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
641 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
643 RReleaseImage(image
);
646 if (icon
->show_title
)
647 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
649 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
655 /* This function creates the RImage using the default icon */
656 static RImage
*get_default_image(WScreen
*scr
)
658 RImage
*image
= NULL
;
661 /* Get the default icon */
662 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
664 path
= FindImage(wPreferences
.icon_path
, file
);
666 image
= RLoadImage(scr
->rcontext
, path
, 0);
668 wwarning(_("could not load default icon \"%s\":%s"),
669 file
, RMessageForError(RErrorCode
));
672 wwarning(_("could not find default icon \"%s\""), file
);
676 /* Validate the icon size */
677 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
682 /* Get the Pixmap from the WIcon of the WWindow */
683 static void get_pixmap_icon_from_icon_win(WIcon
* icon
)
685 XWindowAttributes attr
;
686 WScreen
*scr
= icon
->core
->screen_ptr
;
687 int title_height
= WMFontHeight(scr
->icon_title_font
);
688 unsigned int width
, height
, depth
;
693 getSize(icon
->icon_win
, &width
, &height
, &depth
);
695 if (width
> wPreferences
.icon_size
) {
697 width
= wPreferences
.icon_size
;
700 if (height
> wPreferences
.icon_size
) {
702 height
= wPreferences
.icon_size
;
705 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
706 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
707 wPreferences
.icon_size
, scr
->w_depth
);
708 XSetClipMask(dpy
, scr
->copy_gc
, None
);
709 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
710 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
711 drawIconTitle(scr
, pixmap
, title_height
);
712 theight
= title_height
;
716 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
719 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
720 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
721 (wPreferences
.icon_size
- width
) / 2,
722 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
724 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
726 XMapWindow(dpy
, icon
->icon_win
);
727 XAddToSaveSet(dpy
, icon
->icon_win
);
730 icon
->pixmap
= pixmap
;
732 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
733 (attr
.all_event_masks
& ButtonPressMask
))
734 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
735 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
736 None
, wCursor
[WCUR_ARROW
]);
739 /* Get the Pixmap from the XWindow wm_hints */
740 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
744 unsigned int w
, h
, ju
, d
;
746 WWindow
*wwin
= icon
->owner
;
747 WScreen
*scr
= icon
->core
->screen_ptr
;
748 int title_height
= WMFontHeight(scr
->icon_title_font
);
750 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
751 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
755 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
756 wPreferences
.icon_size
, scr
->w_depth
);
757 XSetClipMask(dpy
, scr
->copy_gc
, None
);
758 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
759 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
761 if (w
> wPreferences
.icon_size
)
762 w
= wPreferences
.icon_size
;
763 x
= (wPreferences
.icon_size
- w
) / 2;
765 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
766 drawIconTitle(scr
, pixmap
, title_height
);
768 if (h
> wPreferences
.icon_size
- title_height
- 2) {
769 h
= wPreferences
.icon_size
- title_height
- 2;
770 y
= title_height
+ 1;
772 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
775 if (w
> wPreferences
.icon_size
)
776 w
= wPreferences
.icon_size
;
777 y
= (wPreferences
.icon_size
- h
) / 2;
780 if (wwin
->wm_hints
->flags
& IconMaskHint
)
781 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
783 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
785 if (d
!= scr
->w_depth
) {
786 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
787 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
788 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
790 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
793 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
795 icon
->pixmap
= pixmap
;
799 void wIconPaint(WIcon
* icon
)
801 WScreen
*scr
= icon
->core
->screen_ptr
;
805 if (icon
->force_paint
) {
806 icon
->force_paint
= 0;
811 XClearWindow(dpy
, icon
->core
->window
);
813 /* draw the icon title */
814 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
818 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
819 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
821 if (w
> icon
->core
->width
- 4)
822 x
= (icon
->core
->width
- 4) - w
;
824 x
= (icon
->core
->width
- w
) / 2;
826 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
827 scr
->icon_title_font
, x
, 1, tmp
, l
);
832 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
833 icon
->core
->width
- 1, icon
->core
->height
- 1);
836 /******************************************************************/
838 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
840 wIconPaint(desc
->parent
);
843 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
845 WIcon
*icon
= desc
->parent
;
847 assert(icon
->owner
!= NULL
);
849 wDeiconifyWindow(icon
->owner
);
852 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
854 WIcon
*icon
= desc
->parent
;
855 WWindow
*wwin
= icon
->owner
;
857 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
858 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
860 int clickButton
= event
->xbutton
.button
;
861 Bool hasMoved
= False
;
863 if (WCHECK_STATE(WSTATE_MODAL
))
866 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
867 miniwindowDblClick(desc
, event
);
871 if (event
->xbutton
.button
== Button1
) {
872 if (event
->xbutton
.state
& MOD_MASK
)
873 wLowerFrame(icon
->core
);
875 wRaiseFrame(icon
->core
);
876 if (event
->xbutton
.state
& ShiftMask
) {
878 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
880 } else if (event
->xbutton
.button
== Button3
) {
881 WObjDescriptor
*desc
;
883 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
885 /* allow drag select of menu */
886 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
887 event
->xbutton
.send_event
= True
;
888 (*desc
->handle_mousedown
) (desc
, event
);
893 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
894 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
895 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
898 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
899 | ButtonMotionMask
| ExposureMask
, &ev
);
908 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
909 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
910 XChangeActivePointerGrab(dpy
, ButtonMotionMask
911 | ButtonReleaseMask
| ButtonPressMask
,
912 wCursor
[WCUR_MOVE
], CurrentTime
);
918 x
= ev
.xmotion
.x_root
- dx
;
919 y
= ev
.xmotion
.y_root
- dy
;
920 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
927 if (ev
.xbutton
.button
!= clickButton
)
930 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
931 wwin
->flags
.icon_moved
= 1;
933 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
937 XUngrabPointer(dpy
, CurrentTime
);
939 if (wPreferences
.auto_arrange_icons
)
940 wArrangeIcons(wwin
->screen_ptr
, True
);
941 if (wPreferences
.single_click
&& !hasMoved
)
942 miniwindowDblClick(desc
, event
);