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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
36 #include "WindowMaker.h"
44 #include "application.h"
49 /**** Global varianebles ****/
50 extern WPreferences wPreferences
;
52 #define MOD_MASK wPreferences.modifier_mask
54 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
);
62 /****** Notification Observers ******/
65 appearanceObserver(void *self
, WMNotification
*notif
)
67 WIcon
*icon
= (WIcon
*)self
;
68 int flags
= (int)(uintptr_t)WMGetNotificationClientData(notif
);
70 if (flags
& WTextureSettings
) {
71 icon
->force_paint
= 1;
73 if (flags
& WFontSettings
) {
74 icon
->force_paint
= 1;
77 if (flags & WColorSettings) {
83 /* so that the appicon expose handlers will paint the appicon specific
85 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
86 icon
->core
->height
, True
);
91 tileObserver(void *self
, WMNotification
*notif
)
93 WIcon
*icon
= (WIcon
*)self
;
95 icon
->force_paint
= 1;
98 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
101 /************************************/
106 getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
112 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
117 wIconCreate(WWindow
*wwin
)
119 WScreen
*scr
=wwin
->screen_ptr
;
122 unsigned long vmask
= 0;
123 XSetWindowAttributes attribs
;
125 icon
= wmalloc(sizeof(WIcon
));
126 memset(icon
, 0, sizeof(WIcon
));
127 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
128 wPreferences
.icon_size
,
129 wPreferences
.icon_size
, 0);
131 if (wPreferences
.use_saveunders
) {
132 vmask
|= CWSaveUnder
;
133 attribs
.save_under
= True
;
135 /* a white border for selecting it */
136 vmask
|= CWBorderPixel
;
137 attribs
.border_pixel
= scr
->white_pixel
;
139 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
142 /* will be overriden if this is an application icon */
143 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
144 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
145 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
146 icon
->core
->descriptor
.parent
= icon
;
148 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
149 icon
->core
->stacking
->above
= NULL
;
150 icon
->core
->stacking
->under
= NULL
;
151 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
152 icon
->core
->stacking
->child_of
= NULL
;
155 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
156 if (wwin
->client_win
== wwin
->main_window
) {
158 /* do not let miniwindow steal app-icon's icon window */
159 wapp
= wApplicationOf(wwin
->client_win
);
160 if (!wapp
|| wapp
->app_icon
==NULL
)
161 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
163 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
166 #ifdef NO_MINIWINDOW_TITLES
167 icon
->show_title
= 0;
169 icon
->show_title
= 1;
172 if (!icon
->image
&& !WFLAGP(wwin
, always_user_icon
))
173 icon
->image
= RRetainImage(wwin
->net_icon_image
);
176 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
178 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
,
181 icon
->file
= wstrdup(file
);
184 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
186 wwin
->flags
.net_has_icon_title
= 1;
188 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
190 icon
->tile_type
= TILE_NORMAL
;
196 WMAddNotificationObserver(appearanceObserver
, icon
,
197 WNIconAppearanceSettingsChanged
, icon
);
198 WMAddNotificationObserver(tileObserver
, icon
,
199 WNIconTileSettingsChanged
, icon
);
205 wIconCreateWithIconFile(WScreen
*scr
, char *iconfile
, int tile
)
208 unsigned long vmask
= 0;
209 XSetWindowAttributes attribs
;
211 icon
= wmalloc(sizeof(WIcon
));
212 memset(icon
, 0, sizeof(WIcon
));
213 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
,
214 wPreferences
.icon_size
, 0);
215 if (wPreferences
.use_saveunders
) {
217 attribs
.save_under
= True
;
219 /* a white border for selecting it */
220 vmask
|= CWBorderPixel
;
221 attribs
.border_pixel
= scr
->white_pixel
;
223 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
225 /* will be overriden if this is a application icon */
226 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
227 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
228 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
229 icon
->core
->descriptor
.parent
= icon
;
231 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
232 icon
->core
->stacking
->above
= NULL
;
233 icon
->core
->stacking
->under
= NULL
;
234 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
235 icon
->core
->stacking
->child_of
= NULL
;
238 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
240 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
243 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
245 icon
->file
= wstrdup(iconfile
);
248 icon
->tile_type
= tile
;
252 WMAddNotificationObserver(appearanceObserver
, icon
,
253 WNIconAppearanceSettingsChanged
, icon
);
254 WMAddNotificationObserver(tileObserver
, icon
,
255 WNIconTileSettingsChanged
, icon
);
263 wIconDestroy(WIcon
*icon
)
265 WCoreWindow
*core
= icon
->core
;
266 WScreen
*scr
= core
->screen_ptr
;
268 WMRemoveNotificationObserver(icon
);
271 WMDeleteTimerHandler(icon
->handlerID
);
273 if (icon
->icon_win
) {
277 x
= icon
->owner
->icon_x
;
278 y
= icon
->owner
->icon_y
;
280 XUnmapWindow(dpy
, icon
->icon_win
);
281 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
284 XFree(icon
->icon_name
);
287 XFreePixmap(dpy
, icon
->pixmap
);
292 if (icon
->image
!=NULL
)
293 RReleaseImage(icon
->image
);
295 wCoreDestroy(icon
->core
);
302 drawIconTitle(WScreen
*scr
, Pixmap pixmap
, int height
)
304 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
,
305 0, 0, wPreferences
.icon_size
, height
+1);
306 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
307 wPreferences
.icon_size
, 0);
308 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
310 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
311 wPreferences
.icon_size
-1, 0, wPreferences
.icon_size
-1, height
+1);
316 makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
)
322 int theight
= WMFontHeight(scr
->icon_title_font
);
324 if (tileType
== TILE_NORMAL
)
325 tile
= RCloneImage(scr
->icon_tile
);
327 assert(scr
->clip_tile
);
328 tile
= RCloneImage(scr
->clip_tile
);
331 w
= (icon
->width
> wPreferences
.icon_size
)
332 ? wPreferences
.icon_size
: icon
->width
;
333 x
= (wPreferences
.icon_size
- w
) / 2;
334 sx
= (icon
->width
- w
)/2;
337 h
= (icon
->height
> wPreferences
.icon_size
)
338 ? wPreferences
.icon_size
: icon
->height
;
339 y
= (wPreferences
.icon_size
- h
) / 2;
340 sy
= (icon
->height
- h
)/2;
342 h
= (icon
->height
+theight
> wPreferences
.icon_size
343 ? wPreferences
.icon_size
-theight
: icon
->height
);
344 y
= theight
+((int)wPreferences
.icon_size
-theight
-h
)/2;
345 sy
= (icon
->height
- h
)/2;
347 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
353 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
354 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
355 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
356 color
.alpha
= 150; /* about 60% */
357 RClearImage(tile
, &color
);
360 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
361 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
366 drawIconTitle(scr
, pixmap
, theight
);
373 wIconChangeTitle(WIcon
*icon
, char *new_title
)
377 changed
= (new_title
==NULL
&& icon
->icon_name
!=NULL
)
378 || (new_title
!=NULL
&& icon
->icon_name
==NULL
);
380 if (icon
->icon_name
!=NULL
)
381 XFree(icon
->icon_name
);
383 icon
->icon_name
= new_title
;
386 icon
->force_paint
= 1;
392 wIconChangeImage(WIcon
*icon
, RImage
*new_image
)
394 assert(icon
!= NULL
);
397 RReleaseImage(icon
->image
);
399 icon
->image
= new_image
;
406 wIconValidateIconSize(WScreen
*scr
, RImage
*icon
)
413 #ifndef DONT_SCALE_ICONS
414 if (wPreferences
.icon_size
!= 64) {
415 w
= wPreferences
.icon_size
* icon
->width
/ 64;
416 h
= wPreferences
.icon_size
* icon
->height
/ 64;
418 tmp
= RScaleImage(icon
, w
, h
);
424 if (icon
->width
> wPreferences
.icon_size
425 || icon
->height
> wPreferences
.icon_size
) {
426 if (icon
->width
> icon
->height
) {
427 w
= wPreferences
.icon_size
- 4;
428 h
= w
*icon
->height
/icon
->width
;
430 h
= wPreferences
.icon_size
- 4;
431 w
= h
*icon
->width
/icon
->height
;
433 tmp
= RScaleImage(icon
, w
, h
);
444 wIconChangeImageFile(WIcon
*icon
, char *file
)
446 WScreen
*scr
= icon
->core
->screen_ptr
;
452 wIconChangeImage(icon
, NULL
);
456 path
= FindImage(wPreferences
.icon_path
, file
);
458 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
459 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
461 wIconChangeImage(icon
, image
);
475 getnameforicon(WWindow
*wwin
)
477 char *prefix
, *suffix
;
481 if (wwin
->wm_class
&& wwin
->wm_instance
) {
482 int len
= strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2;
483 suffix
= wmalloc(len
);
484 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
485 } else if (wwin
->wm_class
) {
486 int len
= strlen(wwin
->wm_class
)+1;
487 suffix
= wmalloc(len
);
488 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
489 } else if (wwin
->wm_instance
) {
490 int len
= strlen(wwin
->wm_instance
)+1;
491 suffix
= wmalloc(len
);
492 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
497 prefix
= wusergnusteppath();
498 len
= strlen(prefix
)+64+strlen(suffix
);
499 path
= wmalloc(len
+1);
500 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
502 if (access(path
, F_OK
)!=0) {
503 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
504 wsyserror(_("could not create directory %s"), path
);
510 strcat(path
, "/CachedPixmaps");
511 if (access(path
, F_OK
)!=0) {
512 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
513 wsyserror(_("could not create directory %s"), path
);
521 strcat(path
, suffix
);
522 strcat(path
, ".xpm");
531 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
532 * and returns the path for that icon. Returns NULL if there is no
533 * client supplied icon or on failure.
536 * New directories might be created.
539 wIconStore(WIcon
*icon
)
543 WWindow
*wwin
= icon
->owner
;
545 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
546 || wwin
->wm_hints
->icon_pixmap
== None
)
549 path
= getnameforicon(wwin
);
553 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
554 wwin
->wm_hints
->icon_pixmap
,
555 (wwin
->wm_hints
->flags
& IconMaskHint
)
556 ? wwin
->wm_hints
->icon_mask
: None
);
562 if (!RSaveImage(image
, path
, "XPM")) {
566 RReleaseImage(image
);
573 void wIconChangeIconWindow(WIcon *icon, Window new_window);
577 cycleColor(void *data
)
579 WIcon
*icon
= (WIcon
*)data
;
580 WScreen
*scr
= icon
->core
->screen_ptr
;
584 gcv
.dash_offset
= icon
->step
;
585 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
587 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
588 icon
->core
->width
-1, icon
->core
->height
-1);
589 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
594 wIconSetHighlited(WIcon
*icon
, Bool flag
)
596 if (icon
->highlighted
== flag
) {
600 icon
->highlighted
= flag
;
607 wIconSelect(WIcon
*icon
)
609 WScreen
*scr
= icon
->core
->screen_ptr
;
610 icon
->selected
= !icon
->selected
;
612 if (icon
->selected
) {
614 if (!wPreferences
.dont_blink
)
615 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
617 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
618 icon
->core
->width
-1, icon
->core
->height
-1);
620 if (icon
->handlerID
) {
621 WMDeleteTimerHandler(icon
->handlerID
);
622 icon
->handlerID
= NULL
;
624 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
625 icon
->core
->height
, True
);
631 wIconUpdate(WIcon
*icon
)
633 WScreen
*scr
= icon
->core
->screen_ptr
;
634 int title_height
= WMFontHeight(scr
->icon_title_font
);
635 WWindow
*wwin
= icon
->owner
;
637 assert(scr
->icon_tile
!=NULL
);
639 if (icon
->pixmap
!=None
)
640 XFreePixmap(dpy
, icon
->pixmap
);
644 if (wwin
&& (WFLAGP(wwin
, always_user_icon
)
646 || wwin
->net_icon_image
651 /* use client specified icon window */
652 if (icon
->icon_win
!=None
) {
653 XWindowAttributes attr
;
655 unsigned int width
, height
, depth
;
659 getSize(icon
->icon_win
, &width
, &height
, &depth
);
661 if (width
> wPreferences
.icon_size
) {
663 width
= wPreferences
.icon_size
;
665 if (height
> wPreferences
.icon_size
) {
667 height
= wPreferences
.icon_size
;
670 && (height
+title_height
< wPreferences
.icon_size
)) {
671 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
672 wPreferences
.icon_size
, scr
->w_depth
);
673 XSetClipMask(dpy
, scr
->copy_gc
, None
);
674 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
675 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
676 drawIconTitle(scr
, pixmap
, title_height
);
677 theight
= title_height
;
681 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
682 scr
->icon_tile_pixmap
);
685 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
686 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
687 (wPreferences
.icon_size
-width
)/2,
688 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
690 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
692 XMapWindow(dpy
, icon
->icon_win
);
694 XAddToSaveSet(dpy
, icon
->icon_win
);
696 icon
->pixmap
= pixmap
;
698 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
699 if (attr
.all_event_masks
& ButtonPressMask
) {
700 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
701 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
702 None
, wCursor
[WCUR_ARROW
]);
705 } else if (wwin
&& wwin
->wm_hints
706 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
714 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
715 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
716 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
720 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
721 wPreferences
.icon_size
, scr
->w_depth
);
722 XSetClipMask(dpy
, scr
->copy_gc
, None
);
723 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
724 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
726 if (w
> wPreferences
.icon_size
)
727 w
= wPreferences
.icon_size
;
728 x
= (wPreferences
.icon_size
-w
)/2;
730 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
731 drawIconTitle(scr
, pixmap
, title_height
);
734 if (h
> wPreferences
.icon_size
- title_height
- 2) {
735 h
= wPreferences
.icon_size
- title_height
- 2;
736 y
= title_height
+ 1;
738 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
742 if (w
> wPreferences
.icon_size
)
743 w
= wPreferences
.icon_size
;
744 y
= (wPreferences
.icon_size
-h
)/2;
747 if (wwin
->wm_hints
->flags
& IconMaskHint
)
748 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
750 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
752 if (d
!= scr
->w_depth
) {
753 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
754 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
755 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
756 0, 0, w
, h
, x
, y
, 1);
758 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
762 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
764 icon
->pixmap
= pixmap
;
769 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
770 icon
->shadowed
, icon
->tile_type
);
772 /* make default icons */
774 if (!scr
->def_icon_pixmap
) {
775 RImage
*image
= NULL
;
779 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
781 path
= FindImage(wPreferences
.icon_path
, file
);
783 wwarning(_("could not find default icon \"%s\""),file
);
787 image
= RLoadImage(scr
->rcontext
, path
, 0);
789 wwarning(_("could not load default icon \"%s\":%s"),
790 file
, RMessageForError(RErrorCode
));
796 image
= wIconValidateIconSize(scr
, image
);
797 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
799 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
802 RReleaseImage(image
);
805 if (icon
->show_title
) {
806 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
807 scr
->def_ticon_pixmap
);
809 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
810 scr
->def_icon_pixmap
);
815 if (icon
->pixmap
!= None
) {
816 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
818 XClearWindow(dpy
, icon
->core
->window
);
826 wIconPaint(WIcon
*icon
)
828 WScreen
*scr
=icon
->core
->screen_ptr
;
832 if (icon
->force_paint
) {
833 icon
->force_paint
= 0;
838 XClearWindow(dpy
, icon
->core
->window
);
840 /* draw the icon title */
841 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
845 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
846 wPreferences
.icon_size
-4);
847 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
=strlen(tmp
));
849 if (w
> icon
->core
->width
- 4)
850 x
= (icon
->core
->width
- 4) - w
;
852 x
= (icon
->core
->width
- w
)/2;
854 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
855 scr
->icon_title_font
, x
, 1, tmp
, l
);
860 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
861 icon
->core
->width
-1, icon
->core
->height
-1);
865 /******************************************************************/
868 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
870 wIconPaint(desc
->parent
);
875 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
877 WIcon
*icon
= desc
->parent
;
879 assert(icon
->owner
!=NULL
);
881 wDeiconifyWindow(icon
->owner
);
886 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
888 WIcon
*icon
= desc
->parent
;
889 WWindow
*wwin
= icon
->owner
;
891 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
892 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
894 int clickButton
=event
->xbutton
.button
;
896 if (WCHECK_STATE(WSTATE_MODAL
))
899 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
900 miniwindowDblClick(desc
, event
);
905 puts("Moving miniwindow");
907 if (event
->xbutton
.button
== Button1
) {
908 if (event
->xbutton
.state
& MOD_MASK
)
909 wLowerFrame(icon
->core
);
911 wRaiseFrame(icon
->core
);
912 if (event
->xbutton
.state
& ShiftMask
) {
914 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
916 } else if (event
->xbutton
.button
== Button3
) {
917 WObjDescriptor
*desc
;
919 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
920 event
->xbutton
.y_root
);
922 /* allow drag select of menu */
923 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
924 event
->xbutton
.send_event
= True
;
925 (*desc
->handle_mousedown
)(desc
, event
);
930 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
931 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
932 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
934 wwarning("pointer grab failed for icon move");
938 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
939 |ButtonMotionMask
|ExposureMask
, &ev
);
947 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
948 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
949 XChangeActivePointerGrab(dpy
, ButtonMotionMask
950 |ButtonReleaseMask
|ButtonPressMask
,
951 wCursor
[WCUR_MOVE
], CurrentTime
);
957 x
= ev
.xmotion
.x_root
- dx
;
958 y
= ev
.xmotion
.y_root
- dy
;
959 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
966 if (ev
.xbutton
.button
!= clickButton
)
969 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
970 wwin
->flags
.icon_moved
= 1;
972 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
977 puts("End miniwindow move");
979 XUngrabPointer(dpy
, CurrentTime
);
981 if (wPreferences
.auto_arrange_icons
)
982 wArrangeIcons(wwin
->screen_ptr
, True
);