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 static WIcon
*wIconCreateCore(WScreen
*scr
, int coord_x
, int coord_y
);
61 void get_pixmap_icon_from_icon_win(WIcon
*icon
);
62 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
);
63 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
);
64 /****** Notification Observers ******/
66 static void appearanceObserver(void *self
, WMNotification
* notif
)
68 WIcon
*icon
= (WIcon
*) self
;
69 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
71 if (flags
& WTextureSettings
) {
72 icon
->force_paint
= 1;
74 if (flags
& WFontSettings
) {
75 icon
->force_paint
= 1;
78 if (flags & WColorSettings) {
84 /* so that the appicon expose handlers will paint the appicon specific
86 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
89 static void tileObserver(void *self
, WMNotification
* notif
)
91 WIcon
*icon
= (WIcon
*) self
;
93 icon
->force_paint
= 1;
96 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
99 /************************************/
101 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
107 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
110 WIcon
*wIconCreate(WWindow
* wwin
)
112 WScreen
*scr
= wwin
->screen_ptr
;
116 icon
= wIconCreateCore(scr
, wwin
->icon_x
, wwin
->icon_y
);
119 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
120 if (wwin
->client_win
== wwin
->main_window
) {
122 /* do not let miniwindow steal app-icon's icon window */
123 wapp
= wApplicationOf(wwin
->client_win
);
124 if (!wapp
|| wapp
->app_icon
== NULL
)
125 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
127 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
130 #ifdef NO_MINIWINDOW_TITLES
131 icon
->show_title
= 0;
133 icon
->show_title
= 1;
135 icon
->file_image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
, wPreferences
.icon_size
);
137 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
139 icon
->file
= wstrdup(file
);
141 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
143 wwin
->flags
.net_has_icon_title
= 1;
145 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
147 icon
->tile_type
= TILE_NORMAL
;
153 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
154 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
158 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
162 icon
= wIconCreateCore(scr
, 0, 0);
165 icon
->file_image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
166 if (!icon
->file_image
) {
167 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
170 icon
->file_image
= wIconValidateIconSize(scr
, icon
->file_image
, wPreferences
.icon_size
);
172 icon
->file
= wstrdup(iconfile
);
175 icon
->tile_type
= tile
;
179 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
180 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
185 static WIcon
*wIconCreateCore(WScreen
*scr
, int coord_x
, int coord_y
)
188 unsigned long vmask
= 0;
189 XSetWindowAttributes attribs
;
191 icon
= wmalloc(sizeof(WIcon
));
192 memset(icon
, 0, 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 *getnameforicon(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");
456 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
457 * and returns the path for that icon. Returns NULL if there is no
458 * client supplied icon or on failure.
461 * New directories might be created.
463 char *wIconStore(WIcon
* icon
)
466 RImage
*image
= NULL
;
467 WWindow
*wwin
= icon
->owner
;
472 path
= getnameforicon(wwin
);
476 /* If icon exists, exit */
477 if (access(path
, F_OK
) == 0)
480 if (wwin
->net_icon_image
) {
481 image
= RRetainImage(wwin
->net_icon_image
);
482 } else if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)
483 && wwin
->wm_hints
->icon_pixmap
!= None
) {
484 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
485 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
486 ? wwin
->wm_hints
->icon_mask
: None
);
494 if (!RSaveImage(image
, path
, "XPM")) {
499 RReleaseImage(image
);
504 static void cycleColor(void *data
)
506 WIcon
*icon
= (WIcon
*) data
;
507 WScreen
*scr
= icon
->core
->screen_ptr
;
511 gcv
.dash_offset
= icon
->step
;
512 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
514 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
515 icon
->core
->width
- 1, icon
->core
->height
- 1);
516 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
520 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
522 if (icon
->highlighted
== flag
)
525 icon
->highlighted
= flag
;
526 icon
->force_paint
= True
;
531 void wIconSelect(WIcon
* icon
)
533 WScreen
*scr
= icon
->core
->screen_ptr
;
534 icon
->selected
= !icon
->selected
;
536 if (icon
->selected
) {
538 if (!wPreferences
.dont_blink
)
539 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
541 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
542 icon
->core
->width
- 1, icon
->core
->height
- 1);
544 if (icon
->handlerID
) {
545 WMDeleteTimerHandler(icon
->handlerID
);
546 icon
->handlerID
= NULL
;
548 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
552 void wIconUpdate(WIcon
* icon
)
554 WScreen
*scr
= icon
->core
->screen_ptr
;
555 WWindow
*wwin
= icon
->owner
;
557 assert(scr
->icon_tile
!= NULL
);
559 if (icon
->pixmap
!= None
)
560 XFreePixmap(dpy
, icon
->pixmap
);
564 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
565 /* Forced use user_icon */
566 get_pixmap_icon_from_user_icon(scr
, icon
);
567 } else if (icon
->icon_win
!= None
) {
568 /* Get the Pixmap from the WIcon */
569 get_pixmap_icon_from_icon_win(icon
);
570 } else if (wwin
&& wwin
->net_icon_image
) {
571 /* Use _NET_WM_ICON icon */
572 icon
->pixmap
= makeIcon(scr
, wwin
->net_icon_image
, icon
->show_title
,
573 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
574 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
575 /* Get the Pixmap from the wm_hints, else, from the user */
576 if (get_pixmap_icon_from_wm_hints(scr
, wwin
, icon
))
577 get_pixmap_icon_from_user_icon(scr
, icon
);
579 /* Get the Pixmap from the user */
580 get_pixmap_icon_from_user_icon(scr
, icon
);
583 /* No pixmap, set default background */
584 if (icon
->pixmap
!= None
)
585 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
588 XClearWindow(dpy
, icon
->core
->window
);
592 void get_pixmap_icon_from_user_icon(WScreen
*scr
, WIcon
* icon
)
594 RImage
*image
= NULL
;
598 if (icon
->file_image
) {
599 icon
->pixmap
= makeIcon(scr
, icon
->file_image
, icon
->show_title
,
600 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
602 /* make default icons */
603 if (!scr
->def_icon_pixmap
) {
604 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
606 path
= FindImage(wPreferences
.icon_path
, file
);
608 image
= RLoadImage(scr
->rcontext
, path
, 0);
610 wwarning(_("could not load default icon \"%s\":%s"),
611 file
, RMessageForError(RErrorCode
));
614 wwarning(_("could not find default icon \"%s\""), file
);
616 /* FIXME: Probably wfree(file) here! */
619 image
= wIconValidateIconSize(scr
, image
, wPreferences
.icon_size
);
620 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
621 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
623 RReleaseImage(image
);
626 if (icon
->show_title
)
627 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
629 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
635 /* Get the Pixmap from the WIcon of the WWindow */
636 void get_pixmap_icon_from_icon_win(WIcon
* icon
)
638 XWindowAttributes attr
;
639 WScreen
*scr
= icon
->core
->screen_ptr
;
640 int title_height
= WMFontHeight(scr
->icon_title_font
);
641 unsigned int width
, height
, depth
;
646 getSize(icon
->icon_win
, &width
, &height
, &depth
);
648 if (width
> wPreferences
.icon_size
) {
650 width
= wPreferences
.icon_size
;
653 if (height
> wPreferences
.icon_size
) {
655 height
= wPreferences
.icon_size
;
658 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
659 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
660 wPreferences
.icon_size
, scr
->w_depth
);
661 XSetClipMask(dpy
, scr
->copy_gc
, None
);
662 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
663 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
664 drawIconTitle(scr
, pixmap
, title_height
);
665 theight
= title_height
;
669 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
672 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
673 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
674 (wPreferences
.icon_size
- width
) / 2,
675 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
677 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
679 XMapWindow(dpy
, icon
->icon_win
);
680 XAddToSaveSet(dpy
, icon
->icon_win
);
683 icon
->pixmap
= pixmap
;
685 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
686 (attr
.all_event_masks
& ButtonPressMask
))
687 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
688 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
689 None
, wCursor
[WCUR_ARROW
]);
692 /* Get the Pixmap from the XWindow wm_hints */
693 int get_pixmap_icon_from_wm_hints(WScreen
*scr
, WWindow
*wwin
, WIcon
*icon
)
697 unsigned int w
, h
, ju
, d
;
699 int title_height
= WMFontHeight(scr
->icon_title_font
);
701 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
702 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
706 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, 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);
712 if (w
> wPreferences
.icon_size
)
713 w
= wPreferences
.icon_size
;
714 x
= (wPreferences
.icon_size
- w
) / 2;
716 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
717 drawIconTitle(scr
, pixmap
, title_height
);
719 if (h
> wPreferences
.icon_size
- title_height
- 2) {
720 h
= wPreferences
.icon_size
- title_height
- 2;
721 y
= title_height
+ 1;
723 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
726 if (w
> wPreferences
.icon_size
)
727 w
= wPreferences
.icon_size
;
728 y
= (wPreferences
.icon_size
- h
) / 2;
731 if (wwin
->wm_hints
->flags
& IconMaskHint
)
732 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
734 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
736 if (d
!= scr
->w_depth
) {
737 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
738 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
739 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
741 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
744 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
746 icon
->pixmap
= pixmap
;
750 void wIconPaint(WIcon
* icon
)
752 WScreen
*scr
= icon
->core
->screen_ptr
;
756 if (icon
->force_paint
) {
757 icon
->force_paint
= 0;
762 XClearWindow(dpy
, icon
->core
->window
);
764 /* draw the icon title */
765 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
769 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
770 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
772 if (w
> icon
->core
->width
- 4)
773 x
= (icon
->core
->width
- 4) - w
;
775 x
= (icon
->core
->width
- w
) / 2;
777 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
778 scr
->icon_title_font
, x
, 1, tmp
, l
);
783 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
784 icon
->core
->width
- 1, icon
->core
->height
- 1);
787 /******************************************************************/
789 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
791 wIconPaint(desc
->parent
);
794 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
796 WIcon
*icon
= desc
->parent
;
798 assert(icon
->owner
!= NULL
);
800 wDeiconifyWindow(icon
->owner
);
803 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
805 WIcon
*icon
= desc
->parent
;
806 WWindow
*wwin
= icon
->owner
;
808 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
809 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
811 int clickButton
= event
->xbutton
.button
;
812 Bool hasMoved
= False
;
814 if (WCHECK_STATE(WSTATE_MODAL
))
817 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
818 miniwindowDblClick(desc
, event
);
822 if (event
->xbutton
.button
== Button1
) {
823 if (event
->xbutton
.state
& MOD_MASK
)
824 wLowerFrame(icon
->core
);
826 wRaiseFrame(icon
->core
);
827 if (event
->xbutton
.state
& ShiftMask
) {
829 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
831 } else if (event
->xbutton
.button
== Button3
) {
832 WObjDescriptor
*desc
;
834 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
836 /* allow drag select of menu */
837 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
838 event
->xbutton
.send_event
= True
;
839 (*desc
->handle_mousedown
) (desc
, event
);
844 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
845 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
846 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
849 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
850 | ButtonMotionMask
| ExposureMask
, &ev
);
859 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
860 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
861 XChangeActivePointerGrab(dpy
, ButtonMotionMask
862 | ButtonReleaseMask
| ButtonPressMask
,
863 wCursor
[WCUR_MOVE
], CurrentTime
);
869 x
= ev
.xmotion
.x_root
- dx
;
870 y
= ev
.xmotion
.y_root
- dy
;
871 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
878 if (ev
.xbutton
.button
!= clickButton
)
881 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
882 wwin
->flags
.icon_moved
= 1;
884 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
888 XUngrabPointer(dpy
, CurrentTime
);
890 if (wPreferences
.auto_arrange_icons
)
891 wArrangeIcons(wwin
->screen_ptr
, True
);
892 if (wPreferences
.single_click
&& !hasMoved
)
893 miniwindowDblClick(desc
, event
);