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 /****** Notification Observers ******/
62 static void appearanceObserver(void *self
, WMNotification
* notif
)
64 WIcon
*icon
= (WIcon
*) self
;
65 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
67 if (flags
& WTextureSettings
) {
68 icon
->force_paint
= 1;
70 if (flags
& WFontSettings
) {
71 icon
->force_paint
= 1;
74 if (flags & WColorSettings) {
80 /* so that the appicon expose handlers will paint the appicon specific
82 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
85 static void tileObserver(void *self
, WMNotification
* notif
)
87 WIcon
*icon
= (WIcon
*) self
;
89 icon
->force_paint
= 1;
92 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
95 /************************************/
97 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
103 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
106 WIcon
*wIconCreate(WWindow
* wwin
)
108 WScreen
*scr
= wwin
->screen_ptr
;
111 unsigned long vmask
= 0;
112 XSetWindowAttributes attribs
;
114 icon
= wmalloc(sizeof(WIcon
));
115 memset(icon
, 0, sizeof(WIcon
));
116 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
117 wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
119 if (wPreferences
.use_saveunders
) {
120 vmask
|= CWSaveUnder
;
121 attribs
.save_under
= True
;
123 /* a white border for selecting it */
124 vmask
|= CWBorderPixel
;
125 attribs
.border_pixel
= scr
->white_pixel
;
127 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
129 /* will be overriden if this is an application icon */
130 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
131 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
132 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
133 icon
->core
->descriptor
.parent
= icon
;
135 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
136 icon
->core
->stacking
->above
= NULL
;
137 icon
->core
->stacking
->under
= NULL
;
138 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
139 icon
->core
->stacking
->child_of
= NULL
;
142 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
143 if (wwin
->client_win
== wwin
->main_window
) {
145 /* do not let miniwindow steal app-icon's icon window */
146 wapp
= wApplicationOf(wwin
->client_win
);
147 if (!wapp
|| wapp
->app_icon
== NULL
)
148 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
150 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
153 #ifdef NO_MINIWINDOW_TITLES
154 icon
->show_title
= 0;
156 icon
->show_title
= 1;
158 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
160 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
162 icon
->file
= wstrdup(file
);
165 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
167 wwin
->flags
.net_has_icon_title
= 1;
169 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
171 icon
->tile_type
= TILE_NORMAL
;
177 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
178 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
182 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
185 unsigned long vmask
= 0;
186 XSetWindowAttributes attribs
;
188 icon
= wmalloc(sizeof(WIcon
));
189 memset(icon
, 0, sizeof(WIcon
));
190 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
191 if (wPreferences
.use_saveunders
) {
193 attribs
.save_under
= True
;
195 /* a white border for selecting it */
196 vmask
|= CWBorderPixel
;
197 attribs
.border_pixel
= scr
->white_pixel
;
199 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
201 /* will be overriden if this is a application icon */
202 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
203 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
204 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
205 icon
->core
->descriptor
.parent
= icon
;
207 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
208 icon
->core
->stacking
->above
= NULL
;
209 icon
->core
->stacking
->under
= NULL
;
210 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
211 icon
->core
->stacking
->child_of
= NULL
;
214 icon
->file_image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
215 if (!icon
->file_image
) {
216 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
219 icon
->file_image
= wIconValidateIconSize(scr
, icon
->file_image
, wPreferences
.icon_size
);
221 icon
->file
= wstrdup(iconfile
);
224 icon
->tile_type
= tile
;
228 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
229 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
234 void wIconDestroy(WIcon
* icon
)
236 WCoreWindow
*core
= icon
->core
;
237 WScreen
*scr
= core
->screen_ptr
;
239 WMRemoveNotificationObserver(icon
);
242 WMDeleteTimerHandler(icon
->handlerID
);
244 if (icon
->icon_win
) {
248 x
= icon
->owner
->icon_x
;
249 y
= icon
->owner
->icon_y
;
251 XUnmapWindow(dpy
, icon
->icon_win
);
252 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
255 XFree(icon
->icon_name
);
258 XFreePixmap(dpy
, icon
->pixmap
);
263 if (icon
->file_image
!= NULL
)
264 RReleaseImage(icon
->file_image
);
266 wCoreDestroy(icon
->core
);
270 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
272 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
273 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
274 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
275 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
276 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
279 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
287 if (tileType
== TILE_NORMAL
) {
288 tile
= RCloneImage(scr
->icon_tile
);
290 assert(scr
->clip_tile
);
291 tile
= RCloneImage(scr
->clip_tile
);
295 w
= (icon
->width
> wPreferences
.icon_size
)
296 ? wPreferences
.icon_size
: icon
->width
;
297 x
= (wPreferences
.icon_size
- w
) / 2;
298 sx
= (icon
->width
- w
) / 2;
301 theight
= WMFontHeight(scr
->icon_title_font
);
303 h
= (icon
->height
+ theight
> wPreferences
.icon_size
304 ? wPreferences
.icon_size
- theight
: icon
->height
);
305 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
306 sy
= (icon
->height
- h
) / 2;
308 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
314 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
315 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
316 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
317 color
.alpha
= 150; /* about 60% */
318 RClearImage(tile
, &color
);
324 color
.red
= color
.green
= color
.blue
= 0;
326 RLightImage(tile
, &color
);
329 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
330 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
335 drawIconTitle(scr
, pixmap
, theight
);
340 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
344 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
345 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
347 if (icon
->icon_name
!= NULL
)
348 XFree(icon
->icon_name
);
350 icon
->icon_name
= new_title
;
353 icon
->force_paint
= 1;
357 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
, int max_size
)
364 #ifndef DONT_SCALE_ICONS
365 if (max_size
!= 64) {
366 w
= max_size
* icon
->width
/ 64;
367 h
= max_size
* icon
->height
/ 64;
369 tmp
= RScaleImage(icon
, w
, h
);
378 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
380 WScreen
*scr
= icon
->core
->screen_ptr
;
385 if (icon
->file_image
)
386 RReleaseImage(icon
->file_image
);
389 icon
->file_image
= NULL
;
394 path
= FindImage(wPreferences
.icon_path
, file
);
396 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
397 icon
->file_image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
, wPreferences
.icon_size
);
409 static char *getnameforicon(WWindow
* wwin
)
411 char *prefix
, *suffix
;
415 if (wwin
->wm_class
&& wwin
->wm_instance
) {
416 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
417 suffix
= wmalloc(len
);
418 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
419 } else if (wwin
->wm_class
) {
420 int len
= strlen(wwin
->wm_class
) + 1;
421 suffix
= wmalloc(len
);
422 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
423 } else if (wwin
->wm_instance
) {
424 int len
= strlen(wwin
->wm_instance
) + 1;
425 suffix
= wmalloc(len
);
426 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
431 prefix
= wusergnusteppath();
432 len
= strlen(prefix
) + 64 + strlen(suffix
);
433 path
= wmalloc(len
+ 1);
434 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
436 if (access(path
, F_OK
) != 0) {
437 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
438 werror(_("could not create directory %s"), path
);
444 strcat(path
, "/CachedPixmaps");
445 if (access(path
, F_OK
) != 0) {
446 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
447 werror(_("could not create directory %s"), path
);
455 strcat(path
, suffix
);
456 strcat(path
, ".xpm");
464 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
465 * and returns the path for that icon. Returns NULL if there is no
466 * client supplied icon or on failure.
469 * New directories might be created.
471 char *wIconStore(WIcon
* icon
)
474 RImage
*image
= NULL
;
475 WWindow
*wwin
= icon
->owner
;
477 if (!wwin
) return NULL
;
479 path
= getnameforicon(wwin
);
483 if (wwin
->net_icon_image
) {
484 image
= RRetainImage(wwin
->net_icon_image
);
485 } else if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)
486 && wwin
->wm_hints
->icon_pixmap
!= None
) {
487 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
488 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
489 ? wwin
->wm_hints
->icon_mask
: None
);
496 if (!RSaveImage(image
, path
, "XPM")) {
500 RReleaseImage(image
);
505 static void cycleColor(void *data
)
507 WIcon
*icon
= (WIcon
*) data
;
508 WScreen
*scr
= icon
->core
->screen_ptr
;
512 gcv
.dash_offset
= icon
->step
;
513 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
515 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
516 icon
->core
->width
- 1, icon
->core
->height
- 1);
517 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
521 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
523 if (icon
->highlighted
== flag
)
526 icon
->highlighted
= flag
;
527 icon
->force_paint
= True
;
532 void wIconSelect(WIcon
* icon
)
534 WScreen
*scr
= icon
->core
->screen_ptr
;
535 icon
->selected
= !icon
->selected
;
537 if (icon
->selected
) {
539 if (!wPreferences
.dont_blink
)
540 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
542 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
543 icon
->core
->width
- 1, icon
->core
->height
- 1);
545 if (icon
->handlerID
) {
546 WMDeleteTimerHandler(icon
->handlerID
);
547 icon
->handlerID
= NULL
;
549 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
553 void wIconUpdate(WIcon
* icon
)
555 WScreen
*scr
= icon
->core
->screen_ptr
;
556 int title_height
= WMFontHeight(scr
->icon_title_font
);
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
)) {
583 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
584 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
588 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
589 wPreferences
.icon_size
, scr
->w_depth
);
590 XSetClipMask(dpy
, scr
->copy_gc
, None
);
591 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
592 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
594 if (w
> wPreferences
.icon_size
)
595 w
= wPreferences
.icon_size
;
596 x
= (wPreferences
.icon_size
- w
) / 2;
598 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
599 drawIconTitle(scr
, pixmap
, title_height
);
601 if (h
> wPreferences
.icon_size
- title_height
- 2) {
602 h
= wPreferences
.icon_size
- title_height
- 2;
603 y
= title_height
+ 1;
605 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
608 if (w
> wPreferences
.icon_size
)
609 w
= wPreferences
.icon_size
;
610 y
= (wPreferences
.icon_size
- h
) / 2;
613 if (wwin
->wm_hints
->flags
& IconMaskHint
)
614 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
616 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
618 if (d
!= scr
->w_depth
) {
619 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
620 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
621 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
623 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
626 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
628 icon
->pixmap
= pixmap
;
631 if (icon
->file_image
) {
632 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
633 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
635 /* make default icons */
636 if (!scr
->def_icon_pixmap
) {
637 RImage
*image
= NULL
;
641 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
643 path
= FindImage(wPreferences
.icon_path
, file
);
645 wwarning(_("could not find default icon \"%s\""), file
);
649 image
= RLoadImage(scr
->rcontext
, path
, 0);
651 wwarning(_("could not load default icon \"%s\":%s"),
652 file
, RMessageForError(RErrorCode
));
657 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
658 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
659 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
661 RReleaseImage(image
);
664 if (icon
->show_title
)
665 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
667 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
672 if (icon
->pixmap
!= None
)
673 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
675 XClearWindow(dpy
, icon
->core
->window
);
679 /* Get the Pixmap from the WIcon of the WWindow */
680 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
682 XWindowAttributes attr
;
683 WScreen
*scr
= icon
->core
->screen_ptr
;
684 int title_height
= WMFontHeight(scr
->icon_title_font
);
685 unsigned int width
, height
, depth
;
690 getSize(icon
->icon_win
, &width
, &height
, &depth
);
692 if (width
> wPreferences
.icon_size
) {
694 width
= wPreferences
.icon_size
;
697 if (height
> wPreferences
.icon_size
) {
699 height
= wPreferences
.icon_size
;
702 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
703 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
704 wPreferences
.icon_size
, scr
->w_depth
);
705 XSetClipMask(dpy
, scr
->copy_gc
, None
);
706 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
707 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
708 drawIconTitle(scr
, pixmap
, title_height
);
709 theight
= title_height
;
713 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
716 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
717 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
718 (wPreferences
.icon_size
- width
) / 2,
719 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
721 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
723 XMapWindow(dpy
, icon
->icon_win
);
724 XAddToSaveSet(dpy
, icon
->icon_win
);
727 icon
->pixmap
= pixmap
;
729 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
730 (attr
.all_event_masks
& ButtonPressMask
))
731 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
732 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
733 None
, wCursor
[WCUR_ARROW
]);
737 void wIconPaint(WIcon
* icon
)
739 WScreen
*scr
= icon
->core
->screen_ptr
;
743 if (icon
->force_paint
) {
744 icon
->force_paint
= 0;
749 XClearWindow(dpy
, icon
->core
->window
);
751 /* draw the icon title */
752 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
756 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
757 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
759 if (w
> icon
->core
->width
- 4)
760 x
= (icon
->core
->width
- 4) - w
;
762 x
= (icon
->core
->width
- w
) / 2;
764 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
765 scr
->icon_title_font
, x
, 1, tmp
, l
);
770 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
771 icon
->core
->width
- 1, icon
->core
->height
- 1);
774 /******************************************************************/
776 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
778 wIconPaint(desc
->parent
);
781 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
783 WIcon
*icon
= desc
->parent
;
785 assert(icon
->owner
!= NULL
);
787 wDeiconifyWindow(icon
->owner
);
790 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
792 WIcon
*icon
= desc
->parent
;
793 WWindow
*wwin
= icon
->owner
;
795 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
796 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
798 int clickButton
= event
->xbutton
.button
;
799 Bool hasMoved
= False
;
801 if (WCHECK_STATE(WSTATE_MODAL
))
804 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
805 miniwindowDblClick(desc
, event
);
809 if (event
->xbutton
.button
== Button1
) {
810 if (event
->xbutton
.state
& MOD_MASK
)
811 wLowerFrame(icon
->core
);
813 wRaiseFrame(icon
->core
);
814 if (event
->xbutton
.state
& ShiftMask
) {
816 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
818 } else if (event
->xbutton
.button
== Button3
) {
819 WObjDescriptor
*desc
;
821 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
823 /* allow drag select of menu */
824 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
825 event
->xbutton
.send_event
= True
;
826 (*desc
->handle_mousedown
) (desc
, event
);
831 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
832 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
833 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
836 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
837 | ButtonMotionMask
| ExposureMask
, &ev
);
846 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
847 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
848 XChangeActivePointerGrab(dpy
, ButtonMotionMask
849 | ButtonReleaseMask
| ButtonPressMask
,
850 wCursor
[WCUR_MOVE
], CurrentTime
);
856 x
= ev
.xmotion
.x_root
- dx
;
857 y
= ev
.xmotion
.y_root
- dy
;
858 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
865 if (ev
.xbutton
.button
!= clickButton
)
868 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
869 wwin
->flags
.icon_moved
= 1;
871 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
875 XUngrabPointer(dpy
, CurrentTime
);
877 if (wPreferences
.auto_arrange_icons
)
878 wArrangeIcons(wwin
->screen_ptr
, True
);
879 if (wPreferences
.single_click
&& !hasMoved
)
880 miniwindowDblClick(desc
, event
);