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 int get_rimage_icon_from_wm_hints(WIcon
*icon
);
66 static void get_pixmap_icon_from_user_icon(WIcon
*icon
);
67 static void get_rimage_icon_from_user_icon(WIcon
*icon
);
68 static void get_pixmap_icon_from_default_icon(WIcon
*icon
);
69 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
70 static void get_pixmap_icon_from_x11(WIcon
*icon
);
71 static void get_rimage_icon_from_x11(WIcon
*icon
);
73 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
74 static void unset_icon_image(WIcon
*icon
);
76 static RImage
*get_default_image(WScreen
*scr
);
77 /****** Notification Observers ******/
79 static void appearanceObserver(void *self
, WMNotification
* notif
)
81 WIcon
*icon
= (WIcon
*) self
;
82 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
84 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
))
85 icon
->force_paint
= 1;
89 /* so that the appicon expose handlers will paint the appicon specific
91 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
94 static void tileObserver(void *self
, WMNotification
* notif
)
96 WIcon
*icon
= (WIcon
*) self
;
98 icon
->force_paint
= 1;
101 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
104 /************************************/
106 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
112 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
115 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
117 WScreen
*scr
= wwin
->screen_ptr
;
121 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
124 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
125 if (wwin
->client_win
== wwin
->main_window
) {
127 /* do not let miniwindow steal app-icon's icon window */
128 wapp
= wApplicationOf(wwin
->client_win
);
129 if (!wapp
|| wapp
->app_icon
== NULL
)
130 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
132 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
135 #ifdef NO_MINIWINDOW_TITLES
136 icon
->show_title
= 0;
138 icon
->show_title
= 1;
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 /* Get the application icon, default included */
148 file
= get_default_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
150 icon
->file
= wstrdup(file
);
151 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
155 icon
->tile_type
= TILE_NORMAL
;
159 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
160 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
165 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
170 icon
= icon_create_core(scr
, 0, 0);
172 /* Search the icon using instance and class, without default icon */
173 file
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
175 icon
->file
= wstrdup(file
);
176 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
180 icon
->tile_type
= tile
;
184 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
185 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
190 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
193 unsigned long vmask
= 0;
194 XSetWindowAttributes attribs
;
196 icon
= wmalloc(sizeof(WIcon
));
197 icon
->core
= wCoreCreateTopLevel(scr
,
200 wPreferences
.icon_size
,
201 wPreferences
.icon_size
,
202 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
204 if (wPreferences
.use_saveunders
) {
206 attribs
.save_under
= True
;
209 /* a white border for selecting it */
210 vmask
|= CWBorderPixel
;
211 attribs
.border_pixel
= scr
->white_pixel
;
213 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
215 /* will be overriden if this is a application icon */
216 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
217 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
218 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
219 icon
->core
->descriptor
.parent
= icon
;
221 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
222 icon
->core
->stacking
->above
= NULL
;
223 icon
->core
->stacking
->under
= NULL
;
224 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
225 icon
->core
->stacking
->child_of
= NULL
;
229 icon
->file_image
= NULL
;
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
);
260 unset_icon_image(icon
);
262 wCoreDestroy(icon
->core
);
266 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
268 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
269 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
270 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
271 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
272 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
275 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
282 WScreen
*scr
= icon
->core
->screen_ptr
;
283 int titled
= icon
->show_title
;
285 if (icon
->tile_type
== TILE_NORMAL
) {
286 tile
= RCloneImage(scr
->icon_tile
);
288 assert(scr
->clip_tile
);
289 tile
= RCloneImage(scr
->clip_tile
);
293 w
= (image
->width
> wPreferences
.icon_size
)
294 ? wPreferences
.icon_size
: image
->width
;
295 x
= (wPreferences
.icon_size
- w
) / 2;
296 sx
= (image
->width
- w
) / 2;
299 theight
= WMFontHeight(scr
->icon_title_font
);
301 h
= (image
->height
+ theight
> wPreferences
.icon_size
302 ? wPreferences
.icon_size
- theight
: image
->height
);
303 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
304 sy
= (image
->height
- h
) / 2;
306 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
309 if (icon
->shadowed
) {
312 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
313 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
314 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
315 color
.alpha
= 150; /* about 60% */
316 RClearImage(tile
, &color
);
319 if (icon
->highlighted
) {
322 color
.red
= color
.green
= color
.blue
= 0;
324 RLightImage(tile
, &color
);
327 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
328 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
333 drawIconTitle(scr
, pixmap
, theight
);
335 icon
->pixmap
= pixmap
;
338 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
342 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
343 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
345 if (icon
->icon_name
!= NULL
)
346 XFree(icon
->icon_name
);
348 icon
->icon_name
= new_title
;
351 icon
->force_paint
= 1;
355 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
362 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
363 if ((icon
->width
- max_size
) > -ICON_BORDER
||
364 (icon
->height
- max_size
) > -ICON_BORDER
) {
365 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
366 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
374 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
376 WScreen
*scr
= icon
->core
->screen_ptr
;
378 RImage
*image
= NULL
;
381 /* If no new image, don't do nothing */
385 /* Find the new image */
386 path
= FindImage(wPreferences
.icon_path
, file
);
388 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
393 if (!error
&& image
) {
394 /* Remove the old one */
395 unset_icon_image(icon
);
397 /* Set the new image */
398 icon
->file_image
= image
;
399 icon
->file
= wstrdup(path
);
411 static char *get_name_for_wwin(WWindow
*wwin
)
413 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
416 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
421 if (wm_class
&& wm_instance
) {
422 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
423 suffix
= wmalloc(len
);
424 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
425 } else if (wm_class
) {
426 len
= strlen(wm_class
) + 1;
427 suffix
= wmalloc(len
);
428 snprintf(suffix
, len
, "%s", wm_class
);
429 } else if (wm_instance
) {
430 len
= strlen(wm_instance
) + 1;
431 suffix
= wmalloc(len
);
432 snprintf(suffix
, len
, "%s", wm_instance
);
440 static char *get_icon_cache_path(void)
445 prefix
= wusergnusteppath();
446 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
448 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
450 /* If the folder exists, exit */
451 if (access(path
, F_OK
) == 0)
454 /* Create the folder */
455 ret
= wmkdirhier((const char *) path
);
457 /* Exit 1 on success, 0 on failure */
466 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
468 RImage
*image
= NULL
;
469 XWMHints
*hints
= wwin
->wm_hints
;
471 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
472 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
474 (hints
->flags
& IconMaskHint
)
475 ? hints
->icon_mask
: None
);
482 * Stores the client supplied icon at CACHE_ICON_PATH
483 * and returns the path for that icon. Returns NULL if there is no
484 * client supplied icon or on failure.
487 * New directories might be created.
489 char *wIconStore(WIcon
* icon
)
491 char *path
, *dir_path
, *file
;
493 RImage
*image
= NULL
;
494 WWindow
*wwin
= icon
->owner
;
499 dir_path
= get_icon_cache_path();
503 file
= get_name_for_wwin(wwin
);
509 len
= strlen(dir_path
) + strlen(file
) + 5;
511 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
515 /* If icon exists, exit */
516 if (access(path
, F_OK
) == 0)
519 if (wwin
->net_icon_image
)
520 image
= RRetainImage(wwin
->net_icon_image
);
522 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
529 if (!RSaveImage(image
, path
, "XPM")) {
534 RReleaseImage(image
);
539 static void cycleColor(void *data
)
541 WIcon
*icon
= (WIcon
*) data
;
542 WScreen
*scr
= icon
->core
->screen_ptr
;
546 gcv
.dash_offset
= icon
->step
;
547 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
549 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
550 icon
->core
->width
- 1, icon
->core
->height
- 1);
551 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
555 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
557 if (icon
->highlighted
== flag
)
560 icon
->highlighted
= flag
;
561 icon
->force_paint
= True
;
566 void wIconSelect(WIcon
* icon
)
568 WScreen
*scr
= icon
->core
->screen_ptr
;
569 icon
->selected
= !icon
->selected
;
571 if (icon
->selected
) {
573 if (!wPreferences
.dont_blink
)
574 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
576 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
577 icon
->core
->width
- 1, icon
->core
->height
- 1);
579 if (icon
->handlerID
) {
580 WMDeleteTimerHandler(icon
->handlerID
);
581 icon
->handlerID
= NULL
;
583 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
587 static void unset_icon_image(WIcon
*icon
)
592 if (icon
->file_image
)
593 RReleaseImage(icon
->file_image
);
596 void wIconUpdate(WIcon
*icon
)
598 WScreen
*scr
= icon
->core
->screen_ptr
;
599 WWindow
*wwin
= icon
->owner
;
601 assert(scr
->icon_tile
!= NULL
);
603 if (icon
->pixmap
!= None
)
604 XFreePixmap(dpy
, icon
->pixmap
);
608 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
609 /* Forced use user_icon */
610 get_pixmap_icon_from_user_icon(icon
);
611 } else if (icon
->icon_win
!= None
) {
612 /* Get the Pixmap from the WIcon */
613 get_pixmap_icon_from_icon_win(icon
);
614 } else if (wwin
&& wwin
->net_icon_image
) {
615 /* Use _NET_WM_ICON icon */
616 get_pixmap_icon_from_x11(icon
);
617 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
618 /* Get the Pixmap from the wm_hints, else, from the user */
619 if (get_pixmap_icon_from_wm_hints(icon
))
620 get_pixmap_icon_from_user_icon(icon
);
622 /* Get the Pixmap from the user */
623 get_pixmap_icon_from_user_icon(icon
);
626 /* No pixmap, set default background */
627 if (icon
->pixmap
!= None
)
628 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
631 XClearWindow(dpy
, icon
->core
->window
);
635 static void get_pixmap_icon_from_x11(WIcon
*icon
)
637 /* Set the icon->file_image */
638 get_rimage_icon_from_x11(icon
);
640 /* Update icon->pixmap */
641 icon_update_pixmap(icon
, icon
->file_image
);
644 static void get_rimage_icon_from_x11(WIcon
*icon
)
646 /* Remove the icon image */
647 unset_icon_image(icon
);
649 /* Set the new icon image */
651 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
654 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
656 if (icon
->file_image
)
659 get_rimage_icon_from_default_icon(icon
);
662 static void get_pixmap_icon_from_user_icon(WIcon
*icon
)
664 /* Set the icon->file_image */
665 get_rimage_icon_from_user_icon(icon
);
667 /* Update icon->pixmap */
668 icon_update_pixmap(icon
, icon
->file_image
);
671 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
673 WScreen
*scr
= icon
->core
->screen_ptr
;
675 /* If the icon don't have image, we should use the default image. */
676 if (!scr
->def_icon_rimage
)
677 scr
->def_icon_rimage
= get_default_image(scr
);
679 /* Remove the icon image */
680 unset_icon_image(icon
);
682 /* Set the new icon image */
684 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
687 static void get_pixmap_icon_from_default_icon(WIcon
*icon
)
689 /* Update icon->file image */
690 get_rimage_icon_from_default_icon(icon
);
692 /* Now, create the pixmap using the default (saved) image */
693 icon_update_pixmap(icon
, icon
->file_image
);
696 /* This function creates the RImage using the default icon */
697 static RImage
*get_default_image(WScreen
*scr
)
699 RImage
*image
= NULL
;
702 /* Get the default icon */
703 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
705 path
= FindImage(wPreferences
.icon_path
, file
);
706 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
709 wwarning(_("could not find default icon \"%s\""), file
);
717 /* Get the Pixmap from the WIcon of the WWindow */
718 static void get_pixmap_icon_from_icon_win(WIcon
* icon
)
720 XWindowAttributes attr
;
721 WScreen
*scr
= icon
->core
->screen_ptr
;
722 int title_height
= WMFontHeight(scr
->icon_title_font
);
723 unsigned int width
, height
, depth
;
728 getSize(icon
->icon_win
, &width
, &height
, &depth
);
730 if (width
> wPreferences
.icon_size
) {
732 width
= wPreferences
.icon_size
;
735 if (height
> wPreferences
.icon_size
) {
737 height
= wPreferences
.icon_size
;
740 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
741 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
742 wPreferences
.icon_size
, scr
->w_depth
);
743 XSetClipMask(dpy
, scr
->copy_gc
, None
);
744 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
745 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
746 drawIconTitle(scr
, pixmap
, title_height
);
747 theight
= title_height
;
751 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
754 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
755 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
756 (wPreferences
.icon_size
- width
) / 2,
757 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
759 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
761 XMapWindow(dpy
, icon
->icon_win
);
762 XAddToSaveSet(dpy
, icon
->icon_win
);
765 icon
->pixmap
= pixmap
;
767 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
768 (attr
.all_event_masks
& ButtonPressMask
))
769 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
770 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
771 None
, wCursor
[WCUR_ARROW
]);
774 /* Get the RImage from the XWindow wm_hints */
775 static int get_rimage_icon_from_wm_hints(WIcon
*icon
)
777 RImage
*image
= NULL
;
778 unsigned int w
, h
, d
;
779 WWindow
*wwin
= icon
->owner
;
781 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
782 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
786 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
790 /* FIXME: If unset_icon_image, pointer double free then crash
791 unset_icon_image(icon); */
792 icon
->file_image
= image
;
797 /* Get the Pixmap from the XWindow wm_hints */
798 static int get_pixmap_icon_from_wm_hints(WIcon
*icon
)
802 ret
= get_rimage_icon_from_wm_hints(icon
);
804 icon_update_pixmap(icon
, icon
->file_image
);
809 void wIconPaint(WIcon
* icon
)
811 WScreen
*scr
= icon
->core
->screen_ptr
;
815 if (icon
->force_paint
) {
816 icon
->force_paint
= 0;
821 XClearWindow(dpy
, icon
->core
->window
);
823 /* draw the icon title */
824 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
828 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
829 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
831 if (w
> icon
->core
->width
- 4)
832 x
= (icon
->core
->width
- 4) - w
;
834 x
= (icon
->core
->width
- w
) / 2;
836 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
837 scr
->icon_title_font
, x
, 1, tmp
, l
);
842 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
843 icon
->core
->width
- 1, icon
->core
->height
- 1);
846 /******************************************************************/
848 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
850 wIconPaint(desc
->parent
);
853 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
855 WIcon
*icon
= desc
->parent
;
857 assert(icon
->owner
!= NULL
);
859 wDeiconifyWindow(icon
->owner
);
862 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
864 WIcon
*icon
= desc
->parent
;
865 WWindow
*wwin
= icon
->owner
;
867 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
868 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
870 int clickButton
= event
->xbutton
.button
;
871 Bool hasMoved
= False
;
873 if (WCHECK_STATE(WSTATE_MODAL
))
876 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
877 miniwindowDblClick(desc
, event
);
881 if (event
->xbutton
.button
== Button1
) {
882 if (event
->xbutton
.state
& MOD_MASK
)
883 wLowerFrame(icon
->core
);
885 wRaiseFrame(icon
->core
);
886 if (event
->xbutton
.state
& ShiftMask
) {
888 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
890 } else if (event
->xbutton
.button
== Button3
) {
891 WObjDescriptor
*desc
;
893 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
895 /* allow drag select of menu */
896 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
897 event
->xbutton
.send_event
= True
;
898 (*desc
->handle_mousedown
) (desc
, event
);
903 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
904 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
905 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
908 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
909 | ButtonMotionMask
| ExposureMask
, &ev
);
918 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
919 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
920 XChangeActivePointerGrab(dpy
, ButtonMotionMask
921 | ButtonReleaseMask
| ButtonPressMask
,
922 wCursor
[WCUR_MOVE
], CurrentTime
);
928 x
= ev
.xmotion
.x_root
- dx
;
929 y
= ev
.xmotion
.y_root
- dy
;
930 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
937 if (ev
.xbutton
.button
!= clickButton
)
940 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
941 wwin
->flags
.icon_moved
= 1;
943 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
947 XUngrabPointer(dpy
, CurrentTime
);
949 if (wPreferences
.auto_arrange_icons
)
950 wArrangeIcons(wwin
->screen_ptr
, True
);
951 if (wPreferences
.single_click
&& !hasMoved
)
952 miniwindowDblClick(desc
, event
);