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
53 extern Cursor wCursor
[WCUR_LAST
];
55 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
56 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
57 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
59 void get_pixmap_icon_from_icon_win(WIcon
*icon
);
60 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
);
61 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
);
62 /****** Notification Observers ******/
64 static void appearanceObserver(void *self
, WMNotification
* notif
)
66 WIcon
*icon
= (WIcon
*) self
;
67 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
69 if (flags
& WTextureSettings
) {
70 icon
->force_paint
= 1;
72 if (flags
& WFontSettings
) {
73 icon
->force_paint
= 1;
76 if (flags & WColorSettings) {
82 /* so that the appicon expose handlers will paint the appicon specific
84 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
87 static void tileObserver(void *self
, WMNotification
* notif
)
89 WIcon
*icon
= (WIcon
*) self
;
91 icon
->force_paint
= 1;
94 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
97 /************************************/
99 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
105 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
108 WIcon
*wIconCreate(WWindow
* wwin
)
110 WScreen
*scr
= wwin
->screen_ptr
;
113 unsigned long vmask
= 0;
114 XSetWindowAttributes attribs
;
116 icon
= wmalloc(sizeof(WIcon
));
117 memset(icon
, 0, sizeof(WIcon
));
118 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
119 wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
121 if (wPreferences
.use_saveunders
) {
122 vmask
|= CWSaveUnder
;
123 attribs
.save_under
= True
;
125 /* a white border for selecting it */
126 vmask
|= CWBorderPixel
;
127 attribs
.border_pixel
= scr
->white_pixel
;
129 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
131 /* will be overriden if this is an application icon */
132 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
133 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
134 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
135 icon
->core
->descriptor
.parent
= icon
;
137 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
138 icon
->core
->stacking
->above
= NULL
;
139 icon
->core
->stacking
->under
= NULL
;
140 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
141 icon
->core
->stacking
->child_of
= NULL
;
144 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
145 if (wwin
->client_win
== wwin
->main_window
) {
147 /* do not let miniwindow steal app-icon's icon window */
148 wapp
= wApplicationOf(wwin
->client_win
);
149 if (!wapp
|| wapp
->app_icon
== NULL
)
150 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
152 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
155 #ifdef NO_MINIWINDOW_TITLES
156 icon
->show_title
= 0;
158 icon
->show_title
= 1;
160 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
162 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
164 icon
->file
= wstrdup(file
);
166 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
168 wwin
->flags
.net_has_icon_title
= 1;
170 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
172 icon
->tile_type
= TILE_NORMAL
;
178 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
179 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
183 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
186 unsigned long vmask
= 0;
187 XSetWindowAttributes attribs
;
189 icon
= wmalloc(sizeof(WIcon
));
190 memset(icon
, 0, sizeof(WIcon
));
191 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
192 if (wPreferences
.use_saveunders
) {
194 attribs
.save_under
= True
;
196 /* a white border for selecting it */
197 vmask
|= CWBorderPixel
;
198 attribs
.border_pixel
= scr
->white_pixel
;
200 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
202 /* will be overriden if this is a application icon */
203 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
204 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
205 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
206 icon
->core
->descriptor
.parent
= icon
;
208 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
209 icon
->core
->stacking
->above
= NULL
;
210 icon
->core
->stacking
->under
= NULL
;
211 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
212 icon
->core
->stacking
->child_of
= NULL
;
215 icon
->file_image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
216 if (!icon
->file_image
) {
217 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
220 icon
->file_image
= wIconValidateIconSize(scr
, icon
->file_image
, wPreferences
.icon_size
);
222 icon
->file
= wstrdup(iconfile
);
225 icon
->tile_type
= tile
;
229 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
230 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
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
);
264 if (icon
->file_image
!= NULL
)
265 RReleaseImage(icon
->file_image
);
267 wCoreDestroy(icon
->core
);
271 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
273 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
274 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
275 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
276 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
277 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
280 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
288 if (tileType
== TILE_NORMAL
) {
289 tile
= RCloneImage(scr
->icon_tile
);
291 assert(scr
->clip_tile
);
292 tile
= RCloneImage(scr
->clip_tile
);
296 w
= (icon
->width
> wPreferences
.icon_size
)
297 ? wPreferences
.icon_size
: icon
->width
;
298 x
= (wPreferences
.icon_size
- w
) / 2;
299 sx
= (icon
->width
- w
) / 2;
302 theight
= WMFontHeight(scr
->icon_title_font
);
304 h
= (icon
->height
+ theight
> wPreferences
.icon_size
305 ? wPreferences
.icon_size
- theight
: icon
->height
);
306 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
307 sy
= (icon
->height
- h
) / 2;
309 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
315 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
316 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
317 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
318 color
.alpha
= 150; /* about 60% */
319 RClearImage(tile
, &color
);
325 color
.red
= color
.green
= color
.blue
= 0;
327 RLightImage(tile
, &color
);
330 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
331 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
336 drawIconTitle(scr
, pixmap
, theight
);
341 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
345 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
346 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
348 if (icon
->icon_name
!= NULL
)
349 XFree(icon
->icon_name
);
351 icon
->icon_name
= new_title
;
354 icon
->force_paint
= 1;
358 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
, int max_size
)
365 #ifndef DONT_SCALE_ICONS
366 if (max_size
!= 64) {
367 w
= max_size
* icon
->width
/ 64;
368 h
= max_size
* icon
->height
/ 64;
370 tmp
= RScaleImage(icon
, w
, h
);
379 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
381 WScreen
*scr
= icon
->core
->screen_ptr
;
386 if (icon
->file_image
)
387 RReleaseImage(icon
->file_image
);
390 icon
->file_image
= NULL
;
395 path
= FindImage(wPreferences
.icon_path
, file
);
397 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
398 icon
->file_image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
, wPreferences
.icon_size
);
410 static char *getnameforicon(WWindow
* wwin
)
412 char *prefix
, *suffix
;
416 if (wwin
->wm_class
&& wwin
->wm_instance
) {
417 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
418 suffix
= wmalloc(len
);
419 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
420 } else if (wwin
->wm_class
) {
421 int len
= strlen(wwin
->wm_class
) + 1;
422 suffix
= wmalloc(len
);
423 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
424 } else if (wwin
->wm_instance
) {
425 int len
= strlen(wwin
->wm_instance
) + 1;
426 suffix
= wmalloc(len
);
427 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
432 prefix
= wusergnusteppath();
433 len
= strlen(prefix
) + 64 + strlen(suffix
);
434 path
= wmalloc(len
+ 1);
435 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
437 if (access(path
, F_OK
) != 0) {
438 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
439 werror(_("could not create directory %s"), path
);
445 strcat(path
, "/CachedPixmaps");
446 if (access(path
, F_OK
) != 0) {
447 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
448 werror(_("could not create directory %s"), path
);
456 strcat(path
, suffix
);
457 strcat(path
, ".xpm");
465 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
466 * and returns the path for that icon. Returns NULL if there is no
467 * client supplied icon or on failure.
470 * New directories might be created.
472 char *wIconStore(WIcon
* icon
)
475 RImage
*image
= NULL
;
476 WWindow
*wwin
= icon
->owner
;
481 path
= getnameforicon(wwin
);
485 if (wwin
->net_icon_image
) {
486 image
= RRetainImage(wwin
->net_icon_image
);
487 } else if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)
488 && wwin
->wm_hints
->icon_pixmap
!= None
) {
489 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
490 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
491 ? wwin
->wm_hints
->icon_mask
: None
);
499 if (!RSaveImage(image
, path
, "XPM")) {
504 RReleaseImage(image
);
509 static void cycleColor(void *data
)
511 WIcon
*icon
= (WIcon
*) data
;
512 WScreen
*scr
= icon
->core
->screen_ptr
;
516 gcv
.dash_offset
= icon
->step
;
517 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
519 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
520 icon
->core
->width
- 1, icon
->core
->height
- 1);
521 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
525 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
527 if (icon
->highlighted
== flag
)
530 icon
->highlighted
= flag
;
531 icon
->force_paint
= True
;
536 void wIconSelect(WIcon
* icon
)
538 WScreen
*scr
= icon
->core
->screen_ptr
;
539 icon
->selected
= !icon
->selected
;
541 if (icon
->selected
) {
543 if (!wPreferences
.dont_blink
)
544 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
546 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
547 icon
->core
->width
- 1, icon
->core
->height
- 1);
549 if (icon
->handlerID
) {
550 WMDeleteTimerHandler(icon
->handlerID
);
551 icon
->handlerID
= NULL
;
553 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
557 void wIconUpdate(WIcon
* icon
)
559 WScreen
*scr
= icon
->core
->screen_ptr
;
560 WWindow
*wwin
= icon
->owner
;
562 assert(scr
->icon_tile
!= NULL
);
564 if (icon
->pixmap
!= None
)
565 XFreePixmap(dpy
, icon
->pixmap
);
569 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
570 /* Forced use user_icon */
571 get_pixmap_icon_from_user_icon(scr
, icon
);
572 } else if (icon
->icon_win
!= None
) {
573 /* Get the Pixmap from the WIcon */
574 get_pixmap_icon_from_icon_win(icon
);
575 } else if (wwin
&& wwin
->net_icon_image
) {
576 /* Use _NET_WM_ICON icon */
577 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
578 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
579 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
580 /* Get the Pixmap from the wm_hints, else, from the user */
581 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
582 get_pixmap_icon_from_user_icon(scr
, icon
);
584 /* Get the Pixmap from the user */
585 get_pixmap_icon_from_user_icon(scr
, icon
);
588 /* No pixmap, set default background */
589 if (icon
->pixmap
!= None
)
590 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
593 XClearWindow(dpy
, icon
->core
->window
);
597 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
)
599 RImage
*image
= NULL
;
603 if (icon
->file_image
) {
604 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
605 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
607 /* make default icons */
608 if (!scr
->def_icon_pixmap
) {
609 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
611 path
= FindImage(wPreferences
.icon_path
, file
);
613 image
= RLoadImage(scr
->rcontext
, path
, 0);
615 wwarning(_("could not load default icon \"%s\":%s"),
616 file
, RMessageForError(RErrorCode
));
619 wwarning(_("could not find default icon \"%s\""), file
);
621 /* FIXME: Probably wfree(file) here! */
624 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
625 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
626 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
628 RReleaseImage(image
);
631 if (icon
->show_title
)
632 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
634 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
640 /* Get the Pixmap from the WIcon of the WWindow */
641 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
643 XWindowAttributes attr
;
644 WScreen
*scr
= icon
->core
->screen_ptr
;
645 int title_height
= WMFontHeight(scr
->icon_title_font
);
646 unsigned int width
, height
, depth
;
651 getSize(icon
->icon_win
, &width
, &height
, &depth
);
653 if (width
> wPreferences
.icon_size
) {
655 width
= wPreferences
.icon_size
;
658 if (height
> wPreferences
.icon_size
) {
660 height
= wPreferences
.icon_size
;
663 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
664 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
665 wPreferences
.icon_size
, scr
->w_depth
);
666 XSetClipMask(dpy
, scr
->copy_gc
, None
);
667 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
668 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
669 drawIconTitle(scr
, pixmap
, title_height
);
670 theight
= title_height
;
674 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
677 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
678 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
679 (wPreferences
.icon_size
- width
) / 2,
680 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
682 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
684 XMapWindow(dpy
, icon
->icon_win
);
685 XAddToSaveSet(dpy
, icon
->icon_win
);
688 icon
->pixmap
= pixmap
;
690 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
691 (attr
.all_event_masks
& ButtonPressMask
))
692 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
693 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
694 None
, wCursor
[WCUR_ARROW
]);
697 /* Get the Pixmap from the XWindow wm_hints */
698 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
702 unsigned int w
, h
, ju
, d
;
704 int title_height
= WMFontHeight(scr
->icon_title_font
);
706 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
707 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
711 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
712 wPreferences
.icon_size
, scr
->w_depth
);
713 XSetClipMask(dpy
, scr
->copy_gc
, None
);
714 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
715 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
717 if (w
> wPreferences
.icon_size
)
718 w
= wPreferences
.icon_size
;
719 x
= (wPreferences
.icon_size
- w
) / 2;
721 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
722 drawIconTitle(scr
, pixmap
, title_height
);
724 if (h
> wPreferences
.icon_size
- title_height
- 2) {
725 h
= wPreferences
.icon_size
- title_height
- 2;
726 y
= title_height
+ 1;
728 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
731 if (w
> wPreferences
.icon_size
)
732 w
= wPreferences
.icon_size
;
733 y
= (wPreferences
.icon_size
- h
) / 2;
736 if (wwin
->wm_hints
->flags
& IconMaskHint
)
737 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
739 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
741 if (d
!= scr
->w_depth
) {
742 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
743 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
744 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
746 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
749 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
751 icon
->pixmap
= pixmap
;
755 void wIconPaint(WIcon
* icon
)
757 WScreen
*scr
= icon
->core
->screen_ptr
;
761 if (icon
->force_paint
) {
762 icon
->force_paint
= 0;
767 XClearWindow(dpy
, icon
->core
->window
);
769 /* draw the icon title */
770 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
774 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
775 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
777 if (w
> icon
->core
->width
- 4)
778 x
= (icon
->core
->width
- 4) - w
;
780 x
= (icon
->core
->width
- w
) / 2;
782 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
783 scr
->icon_title_font
, x
, 1, tmp
, l
);
788 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
789 icon
->core
->width
- 1, icon
->core
->height
- 1);
792 /******************************************************************/
794 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
796 wIconPaint(desc
->parent
);
799 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
801 WIcon
*icon
= desc
->parent
;
803 assert(icon
->owner
!= NULL
);
805 wDeiconifyWindow(icon
->owner
);
808 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
810 WIcon
*icon
= desc
->parent
;
811 WWindow
*wwin
= icon
->owner
;
813 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
814 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
816 int clickButton
= event
->xbutton
.button
;
817 Bool hasMoved
= False
;
819 if (WCHECK_STATE(WSTATE_MODAL
))
822 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
823 miniwindowDblClick(desc
, event
);
827 if (event
->xbutton
.button
== Button1
) {
828 if (event
->xbutton
.state
& MOD_MASK
)
829 wLowerFrame(icon
->core
);
831 wRaiseFrame(icon
->core
);
832 if (event
->xbutton
.state
& ShiftMask
) {
834 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
836 } else if (event
->xbutton
.button
== Button3
) {
837 WObjDescriptor
*desc
;
839 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
841 /* allow drag select of menu */
842 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
843 event
->xbutton
.send_event
= True
;
844 (*desc
->handle_mousedown
) (desc
, event
);
849 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
850 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
851 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
854 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
855 | ButtonMotionMask
| ExposureMask
, &ev
);
864 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
865 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
866 XChangeActivePointerGrab(dpy
, ButtonMotionMask
867 | ButtonReleaseMask
| ButtonPressMask
,
868 wCursor
[WCUR_MOVE
], CurrentTime
);
874 x
= ev
.xmotion
.x_root
- dx
;
875 y
= ev
.xmotion
.y_root
- dy
;
876 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
883 if (ev
.xbutton
.button
!= clickButton
)
886 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
887 wwin
->flags
.icon_moved
= 1;
889 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
893 XUngrabPointer(dpy
, CurrentTime
);
895 if (wPreferences
.auto_arrange_icons
)
896 wArrangeIcons(wwin
->screen_ptr
, True
);
897 if (wPreferences
.single_click
&& !hasMoved
)
898 miniwindowDblClick(desc
, event
);