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"
54 extern Cursor wCursor
[WCUR_LAST
];
56 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
57 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
58 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
60 static WIcon
*wIconCreateCore(WScreen
*scr
, int coord_x
, int coord_y
);
62 void get_pixmap_icon_from_icon_win(WIcon
*icon
);
63 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
);
64 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
);
65 /****** Notification Observers ******/
67 static void appearanceObserver(void *self
, WMNotification
* notif
)
69 WIcon
*icon
= (WIcon
*) self
;
70 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
72 if (flags
& WTextureSettings
) {
73 icon
->force_paint
= 1;
75 if (flags
& WFontSettings
) {
76 icon
->force_paint
= 1;
79 if (flags & WColorSettings) {
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
*wIconCreate(WWindow
* wwin
)
113 WScreen
*scr
= wwin
->screen_ptr
;
117 icon
= wIconCreateCore(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;
136 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
138 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
140 icon
->file
= wstrdup(file
);
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 icon
->tile_type
= TILE_NORMAL
;
154 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
155 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
159 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
163 icon
= wIconCreateCore(scr
, 0, 0);
166 icon
->file_image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
167 if (!icon
->file_image
) {
168 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
171 icon
->file_image
= wIconValidateIconSize(scr
, icon
->file_image
, wPreferences
.icon_size
);
173 icon
->file
= wstrdup(iconfile
);
176 icon
->tile_type
= tile
;
180 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
181 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
186 static WIcon
*wIconCreateCore(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
,
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
;
226 void wIconDestroy(WIcon
* icon
)
228 WCoreWindow
*core
= icon
->core
;
229 WScreen
*scr
= core
->screen_ptr
;
231 WMRemoveNotificationObserver(icon
);
234 WMDeleteTimerHandler(icon
->handlerID
);
236 if (icon
->icon_win
) {
240 x
= icon
->owner
->icon_x
;
241 y
= icon
->owner
->icon_y
;
243 XUnmapWindow(dpy
, icon
->icon_win
);
244 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
247 XFree(icon
->icon_name
);
250 XFreePixmap(dpy
, icon
->pixmap
);
255 if (icon
->file_image
!= NULL
)
256 RReleaseImage(icon
->file_image
);
258 wCoreDestroy(icon
->core
);
262 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
264 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
265 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
266 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
267 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
268 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
271 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
279 if (tileType
== TILE_NORMAL
) {
280 tile
= RCloneImage(scr
->icon_tile
);
282 assert(scr
->clip_tile
);
283 tile
= RCloneImage(scr
->clip_tile
);
287 w
= (icon
->width
> wPreferences
.icon_size
)
288 ? wPreferences
.icon_size
: icon
->width
;
289 x
= (wPreferences
.icon_size
- w
) / 2;
290 sx
= (icon
->width
- w
) / 2;
293 theight
= WMFontHeight(scr
->icon_title_font
);
295 h
= (icon
->height
+ theight
> wPreferences
.icon_size
296 ? wPreferences
.icon_size
- theight
: icon
->height
);
297 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
298 sy
= (icon
->height
- h
) / 2;
300 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
306 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
307 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
308 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
309 color
.alpha
= 150; /* about 60% */
310 RClearImage(tile
, &color
);
316 color
.red
= color
.green
= color
.blue
= 0;
318 RLightImage(tile
, &color
);
321 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
322 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
327 drawIconTitle(scr
, pixmap
, theight
);
332 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
336 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
337 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
339 if (icon
->icon_name
!= NULL
)
340 XFree(icon
->icon_name
);
342 icon
->icon_name
= new_title
;
345 icon
->force_paint
= 1;
349 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
, int max_size
)
356 #ifndef DONT_SCALE_ICONS
357 if (max_size
!= 64) {
358 w
= max_size
* icon
->width
/ 64;
359 h
= max_size
* icon
->height
/ 64;
361 tmp
= RScaleImage(icon
, w
, h
);
370 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
372 WScreen
*scr
= icon
->core
->screen_ptr
;
377 if (icon
->file_image
)
378 RReleaseImage(icon
->file_image
);
381 icon
->file_image
= NULL
;
386 path
= FindImage(wPreferences
.icon_path
, file
);
388 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
389 icon
->file_image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
, wPreferences
.icon_size
);
401 static char *get_name_for_icon(WWindow
* wwin
)
403 char *prefix
, *suffix
;
407 if (wwin
->wm_class
&& wwin
->wm_instance
) {
408 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
409 suffix
= wmalloc(len
);
410 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
411 } else if (wwin
->wm_class
) {
412 int len
= strlen(wwin
->wm_class
) + 1;
413 suffix
= wmalloc(len
);
414 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
415 } else if (wwin
->wm_instance
) {
416 int len
= strlen(wwin
->wm_instance
) + 1;
417 suffix
= wmalloc(len
);
418 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
423 prefix
= wusergnusteppath();
424 len
= strlen(prefix
) + 64 + strlen(suffix
);
425 path
= wmalloc(len
+ 1);
426 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
428 if (access(path
, F_OK
) != 0) {
429 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
430 werror(_("could not create directory %s"), path
);
436 strcat(path
, "/CachedPixmaps");
437 if (access(path
, F_OK
) != 0) {
438 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
439 werror(_("could not create directory %s"), path
);
447 strcat(path
, suffix
);
448 strcat(path
, ".xpm");
454 static char *get_icon_cache_path(void)
459 prefix
= wusergnusteppath();
460 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
462 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
464 /* If the folder exists, exit */
465 if (access(path
, F_OK
) == 0)
468 /* Create the folder */
469 ret
= wmkdirhier((const char *) path
);
471 /* Exit 1 on success, 0 on failure */
480 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
482 RImage
*image
= NULL
;
483 XWMHints
*hints
= wwin
->wm_hints
;
485 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
486 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
488 (hints
->flags
& IconMaskHint
)
489 ? hints
->icon_mask
: None
);
496 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
497 * and returns the path for that icon. Returns NULL if there is no
498 * client supplied icon or on failure.
501 * New directories might be created.
503 char *wIconStore(WIcon
* icon
)
506 RImage
*image
= NULL
;
507 WWindow
*wwin
= icon
->owner
;
512 path
= get_name_for_icon(wwin
);
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 void wIconUpdate(WIcon
* icon
)
590 WScreen
*scr
= icon
->core
->screen_ptr
;
591 WWindow
*wwin
= icon
->owner
;
593 assert(scr
->icon_tile
!= NULL
);
595 if (icon
->pixmap
!= None
)
596 XFreePixmap(dpy
, icon
->pixmap
);
600 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
601 /* Forced use user_icon */
602 get_pixmap_icon_from_user_icon(scr
, icon
);
603 } else if (icon
->icon_win
!= None
) {
604 /* Get the Pixmap from the WIcon */
605 get_pixmap_icon_from_icon_win(icon
);
606 } else if (wwin
&& wwin
->net_icon_image
) {
607 /* Use _NET_WM_ICON icon */
608 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
609 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
610 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
611 /* Get the Pixmap from the wm_hints, else, from the user */
612 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
613 get_pixmap_icon_from_user_icon(scr
, icon
);
615 /* Get the Pixmap from the user */
616 get_pixmap_icon_from_user_icon(scr
, icon
);
619 /* No pixmap, set default background */
620 if (icon
->pixmap
!= None
)
621 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
624 XClearWindow(dpy
, icon
->core
->window
);
628 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
)
630 RImage
*image
= NULL
;
634 if (icon
->file_image
) {
635 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
636 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
638 /* make default icons */
639 if (!scr
->def_icon_pixmap
) {
640 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
642 path
= FindImage(wPreferences
.icon_path
, file
);
644 image
= RLoadImage(scr
->rcontext
, path
, 0);
646 wwarning(_("could not load default icon \"%s\":%s"),
647 file
, RMessageForError(RErrorCode
));
650 wwarning(_("could not find default icon \"%s\""), file
);
652 /* FIXME: Probably wfree(file) here! */
655 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
656 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
657 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
659 RReleaseImage(image
);
662 if (icon
->show_title
)
663 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
665 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
671 /* Get the Pixmap from the WIcon of the WWindow */
672 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
674 XWindowAttributes attr
;
675 WScreen
*scr
= icon
->core
->screen_ptr
;
676 int title_height
= WMFontHeight(scr
->icon_title_font
);
677 unsigned int width
, height
, depth
;
682 getSize(icon
->icon_win
, &width
, &height
, &depth
);
684 if (width
> wPreferences
.icon_size
) {
686 width
= wPreferences
.icon_size
;
689 if (height
> wPreferences
.icon_size
) {
691 height
= wPreferences
.icon_size
;
694 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
695 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
696 wPreferences
.icon_size
, scr
->w_depth
);
697 XSetClipMask(dpy
, scr
->copy_gc
, None
);
698 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
699 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
700 drawIconTitle(scr
, pixmap
, title_height
);
701 theight
= title_height
;
705 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
708 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
709 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
710 (wPreferences
.icon_size
- width
) / 2,
711 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
713 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
715 XMapWindow(dpy
, icon
->icon_win
);
716 XAddToSaveSet(dpy
, icon
->icon_win
);
719 icon
->pixmap
= pixmap
;
721 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
722 (attr
.all_event_masks
& ButtonPressMask
))
723 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
724 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
725 None
, wCursor
[WCUR_ARROW
]);
728 /* Get the Pixmap from the XWindow wm_hints */
729 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
733 unsigned int w
, h
, ju
, d
;
735 int title_height
= WMFontHeight(scr
->icon_title_font
);
737 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
738 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
742 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
743 wPreferences
.icon_size
, scr
->w_depth
);
744 XSetClipMask(dpy
, scr
->copy_gc
, None
);
745 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
746 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
748 if (w
> wPreferences
.icon_size
)
749 w
= wPreferences
.icon_size
;
750 x
= (wPreferences
.icon_size
- w
) / 2;
752 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
753 drawIconTitle(scr
, pixmap
, title_height
);
755 if (h
> wPreferences
.icon_size
- title_height
- 2) {
756 h
= wPreferences
.icon_size
- title_height
- 2;
757 y
= title_height
+ 1;
759 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
762 if (w
> wPreferences
.icon_size
)
763 w
= wPreferences
.icon_size
;
764 y
= (wPreferences
.icon_size
- h
) / 2;
767 if (wwin
->wm_hints
->flags
& IconMaskHint
)
768 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
770 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
772 if (d
!= scr
->w_depth
) {
773 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
774 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
775 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
777 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
780 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
782 icon
->pixmap
= pixmap
;
786 void wIconPaint(WIcon
* icon
)
788 WScreen
*scr
= icon
->core
->screen_ptr
;
792 if (icon
->force_paint
) {
793 icon
->force_paint
= 0;
798 XClearWindow(dpy
, icon
->core
->window
);
800 /* draw the icon title */
801 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
805 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
806 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
808 if (w
> icon
->core
->width
- 4)
809 x
= (icon
->core
->width
- 4) - w
;
811 x
= (icon
->core
->width
- w
) / 2;
813 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
814 scr
->icon_title_font
, x
, 1, tmp
, l
);
819 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
820 icon
->core
->width
- 1, icon
->core
->height
- 1);
823 /******************************************************************/
825 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
827 wIconPaint(desc
->parent
);
830 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
832 WIcon
*icon
= desc
->parent
;
834 assert(icon
->owner
!= NULL
);
836 wDeiconifyWindow(icon
->owner
);
839 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
841 WIcon
*icon
= desc
->parent
;
842 WWindow
*wwin
= icon
->owner
;
844 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
845 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
847 int clickButton
= event
->xbutton
.button
;
848 Bool hasMoved
= False
;
850 if (WCHECK_STATE(WSTATE_MODAL
))
853 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
854 miniwindowDblClick(desc
, event
);
858 if (event
->xbutton
.button
== Button1
) {
859 if (event
->xbutton
.state
& MOD_MASK
)
860 wLowerFrame(icon
->core
);
862 wRaiseFrame(icon
->core
);
863 if (event
->xbutton
.state
& ShiftMask
) {
865 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
867 } else if (event
->xbutton
.button
== Button3
) {
868 WObjDescriptor
*desc
;
870 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
872 /* allow drag select of menu */
873 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
874 event
->xbutton
.send_event
= True
;
875 (*desc
->handle_mousedown
) (desc
, event
);
880 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
881 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
882 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
885 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
886 | ButtonMotionMask
| ExposureMask
, &ev
);
895 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
896 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
897 XChangeActivePointerGrab(dpy
, ButtonMotionMask
898 | ButtonReleaseMask
| ButtonPressMask
,
899 wCursor
[WCUR_MOVE
], CurrentTime
);
905 x
= ev
.xmotion
.x_root
- dx
;
906 y
= ev
.xmotion
.y_root
- dy
;
907 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
914 if (ev
.xbutton
.button
!= clickButton
)
917 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
918 wwin
->flags
.icon_moved
= 1;
920 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
924 XUngrabPointer(dpy
, CurrentTime
);
926 if (wPreferences
.auto_arrange_icons
)
927 wArrangeIcons(wwin
->screen_ptr
, True
);
928 if (wPreferences
.single_click
&& !hasMoved
)
929 miniwindowDblClick(desc
, event
);