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 /****** Notification Observers ******/
61 static void appearanceObserver(void *self
, WMNotification
* notif
)
63 WIcon
*icon
= (WIcon
*) self
;
64 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
66 if (flags
& WTextureSettings
) {
67 icon
->force_paint
= 1;
69 if (flags
& WFontSettings
) {
70 icon
->force_paint
= 1;
73 if (flags & WColorSettings) {
79 /* so that the appicon expose handlers will paint the appicon specific
81 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
84 static void tileObserver(void *self
, WMNotification
* notif
)
86 WIcon
*icon
= (WIcon
*) self
;
88 icon
->force_paint
= 1;
91 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
94 /************************************/
96 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
102 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
105 WIcon
*wIconCreate(WWindow
* wwin
)
107 WScreen
*scr
= wwin
->screen_ptr
;
110 unsigned long vmask
= 0;
111 XSetWindowAttributes attribs
;
113 icon
= wmalloc(sizeof(WIcon
));
114 memset(icon
, 0, sizeof(WIcon
));
115 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
116 wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
118 if (wPreferences
.use_saveunders
) {
119 vmask
|= CWSaveUnder
;
120 attribs
.save_under
= True
;
122 /* a white border for selecting it */
123 vmask
|= CWBorderPixel
;
124 attribs
.border_pixel
= scr
->white_pixel
;
126 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
128 /* will be overriden if this is an application icon */
129 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
130 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
131 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
132 icon
->core
->descriptor
.parent
= icon
;
134 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
135 icon
->core
->stacking
->above
= NULL
;
136 icon
->core
->stacking
->under
= NULL
;
137 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
138 icon
->core
->stacking
->child_of
= NULL
;
141 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
142 if (wwin
->client_win
== wwin
->main_window
) {
144 /* do not let miniwindow steal app-icon's icon window */
145 wapp
= wApplicationOf(wwin
->client_win
);
146 if (!wapp
|| wapp
->app_icon
== NULL
)
147 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
149 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
152 #ifdef NO_MINIWINDOW_TITLES
153 icon
->show_title
= 0;
155 icon
->show_title
= 1;
157 if (!icon
->image
&& !WFLAGP(wwin
, always_user_icon
))
158 icon
->image
= RRetainImage(wwin
->net_icon_image
);
160 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
162 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
164 icon
->file
= wstrdup(file
);
167 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
169 wwin
->flags
.net_has_icon_title
= 1;
171 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
173 icon
->tile_type
= TILE_NORMAL
;
179 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
180 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
184 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
187 unsigned long vmask
= 0;
188 XSetWindowAttributes attribs
;
190 icon
= wmalloc(sizeof(WIcon
));
191 memset(icon
, 0, sizeof(WIcon
));
192 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
193 if (wPreferences
.use_saveunders
) {
195 attribs
.save_under
= True
;
197 /* a white border for selecting it */
198 vmask
|= CWBorderPixel
;
199 attribs
.border_pixel
= scr
->white_pixel
;
201 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
203 /* will be overriden if this is a application icon */
204 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
205 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
206 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
207 icon
->core
->descriptor
.parent
= icon
;
209 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
210 icon
->core
->stacking
->above
= NULL
;
211 icon
->core
->stacking
->under
= NULL
;
212 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
213 icon
->core
->stacking
->child_of
= NULL
;
216 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
218 wwarning(_("error loading image file \"%s\": %s"), iconfile
, RMessageForError(RErrorCode
));
221 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
223 icon
->file
= wstrdup(iconfile
);
226 icon
->tile_type
= tile
;
230 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
231 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
236 void wIconDestroy(WIcon
* icon
)
238 WCoreWindow
*core
= icon
->core
;
239 WScreen
*scr
= core
->screen_ptr
;
241 WMRemoveNotificationObserver(icon
);
244 WMDeleteTimerHandler(icon
->handlerID
);
246 if (icon
->icon_win
) {
250 x
= icon
->owner
->icon_x
;
251 y
= icon
->owner
->icon_y
;
253 XUnmapWindow(dpy
, icon
->icon_win
);
254 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
257 XFree(icon
->icon_name
);
260 XFreePixmap(dpy
, icon
->pixmap
);
265 if (icon
->image
!= NULL
)
266 RReleaseImage(icon
->image
);
268 wCoreDestroy(icon
->core
);
272 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
274 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
275 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
276 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
277 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
278 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
281 static Pixmap
makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
, int highlighted
)
287 int theight
= WMFontHeight(scr
->icon_title_font
);
289 if (tileType
== TILE_NORMAL
)
290 tile
= RCloneImage(scr
->icon_tile
);
292 assert(scr
->clip_tile
);
293 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 h
= (icon
->height
> wPreferences
.icon_size
)
303 ? wPreferences
.icon_size
: icon
->height
;
304 y
= (wPreferences
.icon_size
- h
) / 2;
305 sy
= (icon
->height
- h
) / 2;
307 h
= (icon
->height
+ theight
> wPreferences
.icon_size
308 ? wPreferences
.icon_size
- theight
: icon
->height
);
309 y
= theight
+ ((int)wPreferences
.icon_size
- theight
- h
) / 2;
310 sy
= (icon
->height
- h
) / 2;
312 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
318 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
319 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
320 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
321 color
.alpha
= 150; /* about 60% */
322 RClearImage(tile
, &color
);
327 color
.red
= color
.green
= color
.blue
= 0;
329 RLightImage(tile
, &color
);
332 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
333 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
338 drawIconTitle(scr
, pixmap
, theight
);
343 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
347 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
348 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
350 if (icon
->icon_name
!= NULL
)
351 XFree(icon
->icon_name
);
353 icon
->icon_name
= new_title
;
356 icon
->force_paint
= 1;
360 void wIconChangeImage(WIcon
* icon
, RImage
* new_image
)
362 assert(icon
!= NULL
);
365 RReleaseImage(icon
->image
);
367 icon
->image
= new_image
;
372 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
)
379 #ifndef DONT_SCALE_ICONS
380 if (wPreferences
.icon_size
!= 64) {
381 w
= wPreferences
.icon_size
* icon
->width
/ 64;
382 h
= wPreferences
.icon_size
* icon
->height
/ 64;
384 tmp
= RScaleImage(icon
, w
, h
);
393 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
395 WScreen
*scr
= icon
->core
->screen_ptr
;
401 wIconChangeImage(icon
, NULL
);
405 path
= FindImage(wPreferences
.icon_path
, file
);
407 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
408 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
410 wIconChangeImage(icon
, image
);
421 static char *getnameforicon(WWindow
* wwin
)
423 char *prefix
, *suffix
;
427 if (wwin
->wm_class
&& wwin
->wm_instance
) {
428 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
429 suffix
= wmalloc(len
);
430 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
431 } else if (wwin
->wm_class
) {
432 int len
= strlen(wwin
->wm_class
) + 1;
433 suffix
= wmalloc(len
);
434 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
435 } else if (wwin
->wm_instance
) {
436 int len
= strlen(wwin
->wm_instance
) + 1;
437 suffix
= wmalloc(len
);
438 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
443 prefix
= wusergnusteppath();
444 len
= strlen(prefix
) + 64 + strlen(suffix
);
445 path
= wmalloc(len
+ 1);
446 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
448 if (access(path
, F_OK
) != 0) {
449 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
450 werror(_("could not create directory %s"), path
);
456 strcat(path
, "/CachedPixmaps");
457 if (access(path
, F_OK
) != 0) {
458 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
459 werror(_("could not create directory %s"), path
);
467 strcat(path
, suffix
);
468 strcat(path
, ".xpm");
476 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
477 * and returns the path for that icon. Returns NULL if there is no
478 * client supplied icon or on failure.
481 * New directories might be created.
483 char *wIconStore(WIcon
* icon
)
487 WWindow
*wwin
= icon
->owner
;
489 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
490 || wwin
->wm_hints
->icon_pixmap
== None
)
493 path
= getnameforicon(wwin
);
497 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
498 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
499 ? wwin
->wm_hints
->icon_mask
: None
);
505 if (!RSaveImage(image
, path
, "XPM")) {
509 RReleaseImage(image
);
514 static void cycleColor(void *data
)
516 WIcon
*icon
= (WIcon
*) data
;
517 WScreen
*scr
= icon
->core
->screen_ptr
;
521 gcv
.dash_offset
= icon
->step
;
522 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
524 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
525 icon
->core
->width
- 1, icon
->core
->height
- 1);
526 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
530 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
532 if (icon
->highlighted
== flag
)
535 icon
->highlighted
= flag
;
536 icon
->force_paint
= True
;
541 void wIconSelect(WIcon
* icon
)
543 WScreen
*scr
= icon
->core
->screen_ptr
;
544 icon
->selected
= !icon
->selected
;
546 if (icon
->selected
) {
548 if (!wPreferences
.dont_blink
)
549 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
551 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
552 icon
->core
->width
- 1, icon
->core
->height
- 1);
554 if (icon
->handlerID
) {
555 WMDeleteTimerHandler(icon
->handlerID
);
556 icon
->handlerID
= NULL
;
558 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
562 void wIconUpdate(WIcon
* icon
)
564 WScreen
*scr
= icon
->core
->screen_ptr
;
565 int title_height
= WMFontHeight(scr
->icon_title_font
);
566 WWindow
*wwin
= icon
->owner
;
568 assert(scr
->icon_tile
!= NULL
);
570 if (icon
->pixmap
!= None
)
571 XFreePixmap(dpy
, icon
->pixmap
);
574 if (wwin
&& (WFLAGP(wwin
, always_user_icon
) || wwin
->net_icon_image
))
577 /* use client specified icon window */
578 if (icon
->icon_win
!= None
) {
579 XWindowAttributes attr
;
581 unsigned int width
, height
, depth
;
585 getSize(icon
->icon_win
, &width
, &height
, &depth
);
587 if (width
> wPreferences
.icon_size
) {
589 width
= wPreferences
.icon_size
;
591 if (height
> wPreferences
.icon_size
) {
593 height
= wPreferences
.icon_size
;
595 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
596 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
597 wPreferences
.icon_size
, scr
->w_depth
);
598 XSetClipMask(dpy
, scr
->copy_gc
, None
);
599 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
600 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
601 drawIconTitle(scr
, pixmap
, title_height
);
602 theight
= title_height
;
606 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
609 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
610 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
611 (wPreferences
.icon_size
- width
) / 2,
612 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
614 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
616 XMapWindow(dpy
, icon
->icon_win
);
618 XAddToSaveSet(dpy
, icon
->icon_win
);
620 icon
->pixmap
= pixmap
;
622 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
623 if (attr
.all_event_masks
& ButtonPressMask
) {
624 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
625 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
626 None
, wCursor
[WCUR_ARROW
]);
629 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
637 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
638 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
642 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
643 wPreferences
.icon_size
, scr
->w_depth
);
644 XSetClipMask(dpy
, scr
->copy_gc
, None
);
645 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
646 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
648 if (w
> wPreferences
.icon_size
)
649 w
= wPreferences
.icon_size
;
650 x
= (wPreferences
.icon_size
- w
) / 2;
652 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
653 drawIconTitle(scr
, pixmap
, title_height
);
656 if (h
> wPreferences
.icon_size
- title_height
- 2) {
657 h
= wPreferences
.icon_size
- title_height
- 2;
658 y
= title_height
+ 1;
660 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
664 if (w
> wPreferences
.icon_size
)
665 w
= wPreferences
.icon_size
;
666 y
= (wPreferences
.icon_size
- h
) / 2;
669 if (wwin
->wm_hints
->flags
& IconMaskHint
)
670 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
672 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
674 if (d
!= scr
->w_depth
) {
675 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
676 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
677 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
679 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
682 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
684 icon
->pixmap
= pixmap
;
689 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
690 icon
->shadowed
, icon
->tile_type
, icon
->highlighted
);
692 /* make default icons */
694 if (!scr
->def_icon_pixmap
) {
695 RImage
*image
= NULL
;
699 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
701 path
= FindImage(wPreferences
.icon_path
, file
);
703 wwarning(_("could not find default icon \"%s\""), file
);
707 image
= RLoadImage(scr
->rcontext
, path
, 0);
709 wwarning(_("could not load default icon \"%s\":%s"),
710 file
, RMessageForError(RErrorCode
));
716 image
= wIconValidateIconSize(scr
, image
);
717 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
, icon
->highlighted
);
718 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
, icon
->highlighted
);
720 RReleaseImage(image
);
723 if (icon
->show_title
) {
724 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
726 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
731 if (icon
->pixmap
!= None
) {
732 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
734 XClearWindow(dpy
, icon
->core
->window
);
739 void wIconPaint(WIcon
* icon
)
741 WScreen
*scr
= icon
->core
->screen_ptr
;
745 if (icon
->force_paint
) {
746 icon
->force_paint
= 0;
751 XClearWindow(dpy
, icon
->core
->window
);
753 /* draw the icon title */
754 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
758 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
759 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
761 if (w
> icon
->core
->width
- 4)
762 x
= (icon
->core
->width
- 4) - w
;
764 x
= (icon
->core
->width
- w
) / 2;
766 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
767 scr
->icon_title_font
, x
, 1, tmp
, l
);
772 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
773 icon
->core
->width
- 1, icon
->core
->height
- 1);
776 /******************************************************************/
778 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
780 wIconPaint(desc
->parent
);
783 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
785 WIcon
*icon
= desc
->parent
;
787 assert(icon
->owner
!= NULL
);
789 wDeiconifyWindow(icon
->owner
);
792 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
794 WIcon
*icon
= desc
->parent
;
795 WWindow
*wwin
= icon
->owner
;
797 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
798 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
800 int clickButton
= event
->xbutton
.button
;
801 Bool hasMoved
= False
;
803 if (WCHECK_STATE(WSTATE_MODAL
))
806 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
807 miniwindowDblClick(desc
, event
);
811 if (event
->xbutton
.button
== Button1
) {
812 if (event
->xbutton
.state
& MOD_MASK
)
813 wLowerFrame(icon
->core
);
815 wRaiseFrame(icon
->core
);
816 if (event
->xbutton
.state
& ShiftMask
) {
818 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
820 } else if (event
->xbutton
.button
== Button3
) {
821 WObjDescriptor
*desc
;
823 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
825 /* allow drag select of menu */
826 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
827 event
->xbutton
.send_event
= True
;
828 (*desc
->handle_mousedown
) (desc
, event
);
833 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
834 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
835 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
838 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
839 | ButtonMotionMask
| ExposureMask
, &ev
);
848 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
849 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
850 XChangeActivePointerGrab(dpy
, ButtonMotionMask
851 | ButtonReleaseMask
| ButtonPressMask
,
852 wCursor
[WCUR_MOVE
], CurrentTime
);
858 x
= ev
.xmotion
.x_root
- dx
;
859 y
= ev
.xmotion
.y_root
- dy
;
860 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
867 if (ev
.xbutton
.button
!= clickButton
)
870 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
871 wwin
->flags
.icon_moved
= 1;
873 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
877 XUngrabPointer(dpy
, CurrentTime
);
879 if (wPreferences
.auto_arrange_icons
)
880 wArrangeIcons(wwin
->screen_ptr
, True
);
881 if (wPreferences
.single_click
&& !hasMoved
)
882 miniwindowDblClick(desc
, event
);