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"
55 extern Cursor wCursor
[WCUR_LAST
];
57 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
58 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
59 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
61 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
);
63 static void get_pixmap_icon_from_icon_win(WIcon
*icon
);
64 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
);
65 static void get_pixmap_icon_from_user_icon(WIcon
*icon
);
66 static void get_pixmap_icon_from_default_icon(WIcon
*icon
);
68 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
70 static RImage
*get_default_image(WScreen
*scr
);
71 /****** Notification Observers ******/
73 static void appearanceObserver(void *self
, WMNotification
* notif
)
75 WIcon
*icon
= (WIcon
*) self
;
76 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
78 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
79 icon
->force_paint
= 1;
83 /* so that the appicon expose handlers will paint the appicon specific
85 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
88 static void tileObserver(void *self
, WMNotification
* notif
)
90 WIcon
*icon
= (WIcon
*) self
;
92 icon
->force_paint
= 1;
95 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
98 /************************************/
100 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
106 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
109 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
111 WScreen
*scr
= wwin
->screen_ptr
;
115 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
118 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
119 if (wwin
->client_win
== wwin
->main_window
) {
121 /* do not let miniwindow steal app-icon's icon window */
122 wapp
= wApplicationOf(wwin
->client_win
);
123 if (!wapp
|| wapp
->app_icon
== NULL
)
124 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
126 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
129 #ifdef NO_MINIWINDOW_TITLES
130 icon
->show_title
= 0;
132 icon
->show_title
= 1;
135 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
137 wwin
->flags
.net_has_icon_title
= 1;
139 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
141 /* Get the application icon, default included */
142 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
144 icon
->file
= wstrdup(file
);
145 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
149 icon
->tile_type
= TILE_NORMAL
;
153 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
154 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
159 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
164 icon
= icon_create_core(scr
, 0, 0);
166 /* Search the icon using instance and class, without default icon */
167 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
169 icon
->file
= wstrdup(file
);
170 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
174 icon
->tile_type
= tile
;
178 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
179 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
184 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
187 unsigned long vmask
= 0;
188 XSetWindowAttributes attribs
;
190 icon
= wmalloc(sizeof(WIcon
));
191 icon
->core
= wCoreCreateTopLevel(scr
,
194 wPreferences
.icon_size
,
195 wPreferences
.icon_size
,
196 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
198 if (wPreferences
.use_saveunders
) {
200 attribs
.save_under
= True
;
203 /* a white border for selecting it */
204 vmask
|= CWBorderPixel
;
205 attribs
.border_pixel
= scr
->white_pixel
;
207 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
209 /* will be overriden if this is a application icon */
210 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
211 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
212 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
213 icon
->core
->descriptor
.parent
= icon
;
215 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
216 icon
->core
->stacking
->above
= NULL
;
217 icon
->core
->stacking
->under
= NULL
;
218 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
219 icon
->core
->stacking
->child_of
= NULL
;
223 icon
->file_image
= NULL
;
228 void wIconDestroy(WIcon
* icon
)
230 WCoreWindow
*core
= icon
->core
;
231 WScreen
*scr
= core
->screen_ptr
;
233 WMRemoveNotificationObserver(icon
);
236 WMDeleteTimerHandler(icon
->handlerID
);
238 if (icon
->icon_win
) {
242 x
= icon
->owner
->icon_x
;
243 y
= icon
->owner
->icon_y
;
245 XUnmapWindow(dpy
, icon
->icon_win
);
246 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
249 XFree(icon
->icon_name
);
252 XFreePixmap(dpy
, icon
->pixmap
);
257 if (icon
->file_image
!= NULL
)
258 RReleaseImage(icon
->file_image
);
260 wCoreDestroy(icon
->core
);
264 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
266 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
267 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
268 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
269 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
270 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
273 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
280 WScreen
*scr
= icon
->core
->screen_ptr
;
281 int titled
= icon
->show_title
;
283 if (icon
->tile_type
== TILE_NORMAL
) {
284 tile
= RCloneImage(scr
->icon_tile
);
286 assert(scr
->clip_tile
);
287 tile
= RCloneImage(scr
->clip_tile
);
291 w
= (image
->width
> wPreferences
.icon_size
)
292 ? wPreferences
.icon_size
: image
->width
;
293 x
= (wPreferences
.icon_size
- w
) / 2;
294 sx
= (image
->width
- w
) / 2;
297 theight
= WMFontHeight(scr
->icon_title_font
);
299 h
= (image
->height
+ theight
> wPreferences
.icon_size
300 ? wPreferences
.icon_size
- theight
: image
->height
);
301 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
302 sy
= (image
->height
- h
) / 2;
304 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
307 if (icon
->shadowed
) {
310 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
311 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
312 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
313 color
.alpha
= 150; /* about 60% */
314 RClearImage(tile
, &color
);
317 if (icon
->highlighted
) {
320 color
.red
= color
.green
= color
.blue
= 0;
322 RLightImage(tile
, &color
);
325 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
326 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
331 drawIconTitle(scr
, pixmap
, theight
);
333 icon
->pixmap
= pixmap
;
336 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
340 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
341 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
343 if (icon
->icon_name
!= NULL
)
344 XFree(icon
->icon_name
);
346 icon
->icon_name
= new_title
;
349 icon
->force_paint
= 1;
353 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
360 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
361 if ((icon
->width
- max_size
) > -ICON_BORDER
||
362 (icon
->height
- max_size
) > -ICON_BORDER
) {
363 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
364 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
372 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
374 WScreen
*scr
= icon
->core
->screen_ptr
;
382 if (icon
->file_image
) {
383 RReleaseImage(icon
->file_image
);
384 icon
->file_image
= NULL
;
387 path
= FindImage(wPreferences
.icon_path
, file
);
389 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
390 icon
->file_image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
402 static char *get_name_for_wwin(WWindow
*wwin
)
404 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
407 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
412 if (wm_class
&& wm_instance
) {
413 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
414 suffix
= wmalloc(len
);
415 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
416 } else if (wm_class
) {
417 len
= strlen(wm_class
) + 1;
418 suffix
= wmalloc(len
);
419 snprintf(suffix
, len
, "%s", wm_class
);
420 } else if (wm_instance
) {
421 len
= strlen(wm_instance
) + 1;
422 suffix
= wmalloc(len
);
423 snprintf(suffix
, len
, "%s", wm_instance
);
431 static char *get_icon_cache_path(void)
436 prefix
= wusergnusteppath();
437 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
439 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
441 /* If the folder exists, exit */
442 if (access(path
, F_OK
) == 0)
445 /* Create the folder */
446 ret
= wmkdirhier((const char *) path
);
448 /* Exit 1 on success, 0 on failure */
457 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
459 RImage
*image
= NULL
;
460 XWMHints
*hints
= wwin
->wm_hints
;
462 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
463 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
465 (hints
->flags
& IconMaskHint
)
466 ? hints
->icon_mask
: None
);
473 * Stores the client supplied icon at CACHE_ICON_PATH
474 * and returns the path for that icon. Returns NULL if there is no
475 * client supplied icon or on failure.
478 * New directories might be created.
480 char *wIconStore(WIcon
* icon
)
482 char *path
, *dir_path
, *file
;
484 RImage
*image
= NULL
;
485 WWindow
*wwin
= icon
->owner
;
490 dir_path
= get_icon_cache_path();
494 file
= get_name_for_wwin(wwin
);
500 len
= strlen(dir_path
) + strlen(file
) + 5;
502 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
506 /* If icon exists, exit */
507 if (access(path
, F_OK
) == 0)
510 if (wwin
->net_icon_image
)
511 image
= RRetainImage(wwin
->net_icon_image
);
513 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
520 if (!RSaveImage(image
, path
, "XPM")) {
525 RReleaseImage(image
);
530 static void cycleColor(void *data
)
532 WIcon
*icon
= (WIcon
*) data
;
533 WScreen
*scr
= icon
->core
->screen_ptr
;
537 gcv
.dash_offset
= icon
->step
;
538 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
540 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
541 icon
->core
->width
- 1, icon
->core
->height
- 1);
542 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
546 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
548 if (icon
->highlighted
== flag
)
551 icon
->highlighted
= flag
;
552 icon
->force_paint
= True
;
557 void wIconSelect(WIcon
* icon
)
559 WScreen
*scr
= icon
->core
->screen_ptr
;
560 icon
->selected
= !icon
->selected
;
562 if (icon
->selected
) {
564 if (!wPreferences
.dont_blink
)
565 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
567 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
568 icon
->core
->width
- 1, icon
->core
->height
- 1);
570 if (icon
->handlerID
) {
571 WMDeleteTimerHandler(icon
->handlerID
);
572 icon
->handlerID
= NULL
;
574 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
578 void wIconUpdate(WIcon
*icon
)
580 WScreen
*scr
= icon
->core
->screen_ptr
;
581 WWindow
*wwin
= icon
->owner
;
583 assert(scr
->icon_tile
!= NULL
);
585 if (icon
->pixmap
!= None
)
586 XFreePixmap(dpy
, icon
->pixmap
);
590 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
591 /* Forced use user_icon */
592 get_pixmap_icon_from_user_icon(icon
);
593 } else if (icon
->icon_win
!= None
) {
594 /* Get the Pixmap from the WIcon */
595 get_pixmap_icon_from_icon_win(icon
);
596 } else if (wwin
&& wwin
->net_icon_image
) {
597 /* Use _NET_WM_ICON icon */
598 icon_update_pixmap(icon
, wwin
->net_icon_image
);
599 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
600 /* Get the Pixmap from the wm_hints, else, from the user */
601 if (get_pixmap_icon_from_wm_hints(icon
))
602 get_pixmap_icon_from_user_icon(icon
);
604 /* Get the Pixmap from the user */
605 get_pixmap_icon_from_user_icon(icon
);
608 /* No pixmap, set default background */
609 if (icon
->pixmap
!= None
)
610 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
613 XClearWindow(dpy
, icon
->core
->window
);
617 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
619 /* If the icon has image, update it and continue */
620 if (icon
->file_image
) {
621 icon_update_pixmap(icon
, icon
->file_image
);
625 get_pixmap_icon_from_default_icon(icon
);
628 static void get_pixmap_icon_from_default_icon(WIcon
*icon
)
630 WScreen
*scr
= icon
->core
->screen_ptr
;
632 /* If the icon don't have image, we should use the default image. */
633 if (!scr
->def_icon_rimage
)
634 scr
->def_icon_rimage
= get_default_image(scr
);
636 /* Now, create the pixmap using the default (saved) image */
637 icon_update_pixmap(icon
, scr
->def_icon_rimage
);
640 /* This function creates the RImage using the default icon */
641 static RImage
*get_default_image(WScreen
*scr
)
643 RImage
*image
= NULL
;
646 /* Get the default icon */
647 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
649 path
= FindImage(wPreferences
.icon_path
, file
);
650 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
653 wwarning(_("could not find default icon \"%s\""), file
);
661 /* Get the Pixmap from the WIcon of the WWindow */
662 static void get_pixmap_icon_from_icon_win(WIcon
* icon
)
664 XWindowAttributes attr
;
665 WScreen
*scr
= icon
->core
->screen_ptr
;
666 int title_height
= WMFontHeight(scr
->icon_title_font
);
667 unsigned int width
, height
, depth
;
672 getSize(icon
->icon_win
, &width
, &height
, &depth
);
674 if (width
> wPreferences
.icon_size
) {
676 width
= wPreferences
.icon_size
;
679 if (height
> wPreferences
.icon_size
) {
681 height
= wPreferences
.icon_size
;
684 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
685 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
686 wPreferences
.icon_size
, scr
->w_depth
);
687 XSetClipMask(dpy
, scr
->copy_gc
, None
);
688 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
689 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
690 drawIconTitle(scr
, pixmap
, title_height
);
691 theight
= title_height
;
695 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
698 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
699 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
700 (wPreferences
.icon_size
- width
) / 2,
701 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
703 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
705 XMapWindow(dpy
, icon
->icon_win
);
706 XAddToSaveSet(dpy
, icon
->icon_win
);
709 icon
->pixmap
= pixmap
;
711 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
712 (attr
.all_event_masks
& ButtonPressMask
))
713 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
714 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
715 None
, wCursor
[WCUR_ARROW
]);
718 /* Get the Pixmap from the XWindow wm_hints */
719 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
723 unsigned int w
, h
, ju
, d
;
725 WWindow
*wwin
= icon
->owner
;
726 WScreen
*scr
= icon
->core
->screen_ptr
;
727 int title_height
= WMFontHeight(scr
->icon_title_font
);
729 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
730 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
734 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
735 wPreferences
.icon_size
, scr
->w_depth
);
736 XSetClipMask(dpy
, scr
->copy_gc
, None
);
737 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
738 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
740 if (w
> wPreferences
.icon_size
)
741 w
= wPreferences
.icon_size
;
742 x
= (wPreferences
.icon_size
- w
) / 2;
744 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
745 drawIconTitle(scr
, pixmap
, title_height
);
747 if (h
> wPreferences
.icon_size
- title_height
- 2) {
748 h
= wPreferences
.icon_size
- title_height
- 2;
749 y
= title_height
+ 1;
751 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
754 if (w
> wPreferences
.icon_size
)
755 w
= wPreferences
.icon_size
;
756 y
= (wPreferences
.icon_size
- h
) / 2;
759 if (wwin
->wm_hints
->flags
& IconMaskHint
)
760 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
762 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
764 if (d
!= scr
->w_depth
) {
765 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
766 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
767 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
769 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
772 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
774 icon
->pixmap
= pixmap
;
778 void wIconPaint(WIcon
* icon
)
780 WScreen
*scr
= icon
->core
->screen_ptr
;
784 if (icon
->force_paint
) {
785 icon
->force_paint
= 0;
790 XClearWindow(dpy
, icon
->core
->window
);
792 /* draw the icon title */
793 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
797 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
798 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
800 if (w
> icon
->core
->width
- 4)
801 x
= (icon
->core
->width
- 4) - w
;
803 x
= (icon
->core
->width
- w
) / 2;
805 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
806 scr
->icon_title_font
, x
, 1, tmp
, l
);
811 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
812 icon
->core
->width
- 1, icon
->core
->height
- 1);
815 /******************************************************************/
817 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
819 wIconPaint(desc
->parent
);
822 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
824 WIcon
*icon
= desc
->parent
;
826 assert(icon
->owner
!= NULL
);
828 wDeiconifyWindow(icon
->owner
);
831 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
833 WIcon
*icon
= desc
->parent
;
834 WWindow
*wwin
= icon
->owner
;
836 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
837 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
839 int clickButton
= event
->xbutton
.button
;
840 Bool hasMoved
= False
;
842 if (WCHECK_STATE(WSTATE_MODAL
))
845 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
846 miniwindowDblClick(desc
, event
);
850 if (event
->xbutton
.button
== Button1
) {
851 if (event
->xbutton
.state
& MOD_MASK
)
852 wLowerFrame(icon
->core
);
854 wRaiseFrame(icon
->core
);
855 if (event
->xbutton
.state
& ShiftMask
) {
857 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
859 } else if (event
->xbutton
.button
== Button3
) {
860 WObjDescriptor
*desc
;
862 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
864 /* allow drag select of menu */
865 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
866 event
->xbutton
.send_event
= True
;
867 (*desc
->handle_mousedown
) (desc
, event
);
872 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
873 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
874 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
877 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
878 | ButtonMotionMask
| ExposureMask
, &ev
);
887 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
888 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
889 XChangeActivePointerGrab(dpy
, ButtonMotionMask
890 | ButtonReleaseMask
| ButtonPressMask
,
891 wCursor
[WCUR_MOVE
], CurrentTime
);
897 x
= ev
.xmotion
.x_root
- dx
;
898 y
= ev
.xmotion
.y_root
- dy
;
899 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
906 if (ev
.xbutton
.button
!= clickButton
)
909 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
910 wwin
->flags
.icon_moved
= 1;
912 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
916 XUngrabPointer(dpy
, CurrentTime
);
918 if (wPreferences
.auto_arrange_icons
)
919 wArrangeIcons(wwin
->screen_ptr
, True
);
920 if (wPreferences
.single_click
&& !hasMoved
)
921 miniwindowDblClick(desc
, event
);