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 /****** Notification Observers ******/
63 static void appearanceObserver(void *self
, WMNotification
* notif
)
65 WIcon
*icon
= (WIcon
*) self
;
66 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
68 if (flags
& WTextureSettings
) {
69 icon
->force_paint
= 1;
71 if (flags
& WFontSettings
) {
72 icon
->force_paint
= 1;
75 if (flags & WColorSettings) {
81 /* so that the appicon expose handlers will paint the appicon specific
83 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
86 static void tileObserver(void *self
, WMNotification
* notif
)
88 WIcon
*icon
= (WIcon
*) self
;
90 icon
->force_paint
= 1;
93 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
96 /************************************/
98 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
104 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
107 WIcon
*wIconCreate(WWindow
* wwin
)
109 WScreen
*scr
= wwin
->screen_ptr
;
112 unsigned long vmask
= 0;
113 XSetWindowAttributes attribs
;
115 icon
= wmalloc(sizeof(WIcon
));
116 memset(icon
, 0, sizeof(WIcon
));
117 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
118 wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
120 if (wPreferences
.use_saveunders
) {
121 vmask
|= CWSaveUnder
;
122 attribs
.save_under
= True
;
124 /* a white border for selecting it */
125 vmask
|= CWBorderPixel
;
126 attribs
.border_pixel
= scr
->white_pixel
;
128 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
130 /* will be overriden if this is an application icon */
131 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
132 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
133 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
134 icon
->core
->descriptor
.parent
= icon
;
136 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
137 icon
->core
->stacking
->above
= NULL
;
138 icon
->core
->stacking
->under
= NULL
;
139 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
140 icon
->core
->stacking
->child_of
= NULL
;
143 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
144 if (wwin
->client_win
== wwin
->main_window
) {
146 /* do not let miniwindow steal app-icon's icon window */
147 wapp
= wApplicationOf(wwin
->client_win
);
148 if (!wapp
|| wapp
->app_icon
== NULL
)
149 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
151 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
154 #ifdef NO_MINIWINDOW_TITLES
155 icon
->show_title
= 0;
157 icon
->show_title
= 1;
159 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
161 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
163 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
;
478 if (!wwin
) return NULL
;
480 path
= getnameforicon(wwin
);
484 if (wwin
->net_icon_image
) {
485 image
= RRetainImage(wwin
->net_icon_image
);
486 } else if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)
487 && wwin
->wm_hints
->icon_pixmap
!= None
) {
488 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
489 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
490 ? wwin
->wm_hints
->icon_mask
: None
);
497 if (!RSaveImage(image
, path
, "XPM")) {
501 RReleaseImage(image
);
506 static void cycleColor(void *data
)
508 WIcon
*icon
= (WIcon
*) data
;
509 WScreen
*scr
= icon
->core
->screen_ptr
;
513 gcv
.dash_offset
= icon
->step
;
514 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
516 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
517 icon
->core
->width
- 1, icon
->core
->height
- 1);
518 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
522 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
524 if (icon
->highlighted
== flag
)
527 icon
->highlighted
= flag
;
528 icon
->force_paint
= True
;
533 void wIconSelect(WIcon
* icon
)
535 WScreen
*scr
= icon
->core
->screen_ptr
;
536 icon
->selected
= !icon
->selected
;
538 if (icon
->selected
) {
540 if (!wPreferences
.dont_blink
)
541 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
543 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
544 icon
->core
->width
- 1, icon
->core
->height
- 1);
546 if (icon
->handlerID
) {
547 WMDeleteTimerHandler(icon
->handlerID
);
548 icon
->handlerID
= NULL
;
550 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
554 void wIconUpdate(WIcon
* icon
)
556 WScreen
*scr
= icon
->core
->screen_ptr
;
557 WWindow
*wwin
= icon
->owner
;
559 assert(scr
->icon_tile
!= NULL
);
561 if (icon
->pixmap
!= None
)
562 XFreePixmap(dpy
, icon
->pixmap
);
565 if (wwin
&& WFLAGP(wwin
, always_user_icon
))
568 if (icon
->icon_win
!= None
) {
569 /* Get the Pixmap from the WIcon */
570 get_pixmap_icon_from_icon_win(icon
);
571 } else if (wwin
&& wwin
->net_icon_image
) {
572 /* Use _NET_WM_ICON icon */
573 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
574 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
575 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
576 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
580 if (icon
->file_image
) {
581 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
582 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
584 /* make default icons */
585 if (!scr
->def_icon_pixmap
) {
586 RImage
*image
= NULL
;
590 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
592 path
= FindImage(wPreferences
.icon_path
, file
);
594 wwarning(_("could not find default icon \"%s\""), file
);
598 image
= RLoadImage(scr
->rcontext
, path
, 0);
600 wwarning(_("could not load default icon \"%s\":%s"),
601 file
, RMessageForError(RErrorCode
));
606 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
607 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
608 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
610 RReleaseImage(image
);
613 if (icon
->show_title
)
614 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
616 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
621 if (icon
->pixmap
!= None
)
622 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
624 XClearWindow(dpy
, icon
->core
->window
);
628 /* Get the Pixmap from the WIcon of the WWindow */
629 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
631 XWindowAttributes attr
;
632 WScreen
*scr
= icon
->core
->screen_ptr
;
633 int title_height
= WMFontHeight(scr
->icon_title_font
);
634 unsigned int width
, height
, depth
;
639 getSize(icon
->icon_win
, &width
, &height
, &depth
);
641 if (width
> wPreferences
.icon_size
) {
643 width
= wPreferences
.icon_size
;
646 if (height
> wPreferences
.icon_size
) {
648 height
= wPreferences
.icon_size
;
651 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
652 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
653 wPreferences
.icon_size
, scr
->w_depth
);
654 XSetClipMask(dpy
, scr
->copy_gc
, None
);
655 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
656 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
657 drawIconTitle(scr
, pixmap
, title_height
);
658 theight
= title_height
;
662 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
665 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
666 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
667 (wPreferences
.icon_size
- width
) / 2,
668 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
670 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
672 XMapWindow(dpy
, icon
->icon_win
);
673 XAddToSaveSet(dpy
, icon
->icon_win
);
676 icon
->pixmap
= pixmap
;
678 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
679 (attr
.all_event_masks
& ButtonPressMask
))
680 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
681 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
682 None
, wCursor
[WCUR_ARROW
]);
685 /* Get the Pixmap from the XWindow wm_hints */
686 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
690 unsigned int w
, h
, ju
, d
;
692 int title_height
= WMFontHeight(scr
->icon_title_font
);
694 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
695 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
699 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
700 wPreferences
.icon_size
, scr
->w_depth
);
701 XSetClipMask(dpy
, scr
->copy_gc
, None
);
702 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
703 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
705 if (w
> wPreferences
.icon_size
)
706 w
= wPreferences
.icon_size
;
707 x
= (wPreferences
.icon_size
- w
) / 2;
709 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
710 drawIconTitle(scr
, pixmap
, title_height
);
712 if (h
> wPreferences
.icon_size
- title_height
- 2) {
713 h
= wPreferences
.icon_size
- title_height
- 2;
714 y
= title_height
+ 1;
716 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
719 if (w
> wPreferences
.icon_size
)
720 w
= wPreferences
.icon_size
;
721 y
= (wPreferences
.icon_size
- h
) / 2;
724 if (wwin
->wm_hints
->flags
& IconMaskHint
)
725 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
727 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
729 if (d
!= scr
->w_depth
) {
730 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
731 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
732 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
734 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
737 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
739 icon
->pixmap
= pixmap
;
743 void wIconPaint(WIcon
* icon
)
745 WScreen
*scr
= icon
->core
->screen_ptr
;
749 if (icon
->force_paint
) {
750 icon
->force_paint
= 0;
755 XClearWindow(dpy
, icon
->core
->window
);
757 /* draw the icon title */
758 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
762 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
763 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
765 if (w
> icon
->core
->width
- 4)
766 x
= (icon
->core
->width
- 4) - w
;
768 x
= (icon
->core
->width
- w
) / 2;
770 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
771 scr
->icon_title_font
, x
, 1, tmp
, l
);
776 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
777 icon
->core
->width
- 1, icon
->core
->height
- 1);
780 /******************************************************************/
782 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
784 wIconPaint(desc
->parent
);
787 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
789 WIcon
*icon
= desc
->parent
;
791 assert(icon
->owner
!= NULL
);
793 wDeiconifyWindow(icon
->owner
);
796 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
798 WIcon
*icon
= desc
->parent
;
799 WWindow
*wwin
= icon
->owner
;
801 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
802 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
804 int clickButton
= event
->xbutton
.button
;
805 Bool hasMoved
= False
;
807 if (WCHECK_STATE(WSTATE_MODAL
))
810 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
811 miniwindowDblClick(desc
, event
);
815 if (event
->xbutton
.button
== Button1
) {
816 if (event
->xbutton
.state
& MOD_MASK
)
817 wLowerFrame(icon
->core
);
819 wRaiseFrame(icon
->core
);
820 if (event
->xbutton
.state
& ShiftMask
) {
822 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
824 } else if (event
->xbutton
.button
== Button3
) {
825 WObjDescriptor
*desc
;
827 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
829 /* allow drag select of menu */
830 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
831 event
->xbutton
.send_event
= True
;
832 (*desc
->handle_mousedown
) (desc
, event
);
837 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
838 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
839 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
842 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
843 | ButtonMotionMask
| ExposureMask
, &ev
);
852 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
853 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
854 XChangeActivePointerGrab(dpy
, ButtonMotionMask
855 | ButtonReleaseMask
| ButtonPressMask
,
856 wCursor
[WCUR_MOVE
], CurrentTime
);
862 x
= ev
.xmotion
.x_root
- dx
;
863 y
= ev
.xmotion
.y_root
- dy
;
864 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
871 if (ev
.xbutton
.button
!= clickButton
)
874 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
875 wwin
->flags
.icon_moved
= 1;
877 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
881 XUngrabPointer(dpy
, CurrentTime
);
883 if (wPreferences
.auto_arrange_icons
)
884 wArrangeIcons(wwin
->screen_ptr
, True
);
885 if (wPreferences
.single_click
&& !hasMoved
)
886 miniwindowDblClick(desc
, event
);