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>
35 #include "WindowMaker.h"
43 #include "application.h"
47 /**** Global variables ****/
48 extern WPreferences wPreferences
;
50 #define MOD_MASK wPreferences.modifier_mask
52 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
);
60 /****** Notification Observers ******/
63 appearanceObserver(void *self
, WMNotification
*notif
)
65 WIcon
*icon
= (WIcon
*)self
;
66 int flags
= (int)WMGetNotificationClientData(notif
);
68 if (flags
& WTextureSettings
) {
69 icon
->force_paint
= 1;
71 if (flags
& WFontSettings
) {
72 icon
->force_paint
= 1;
75 if (flags & WColorSettings) {
81 /* so that the appicon expose handlers will paint the appicon specific
83 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
84 icon
->core
->height
, True
);
89 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 /************************************/
104 getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
110 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
115 wIconCreate(WWindow
*wwin
)
117 WScreen
*scr
=wwin
->screen_ptr
;
120 unsigned long vmask
= 0;
121 XSetWindowAttributes attribs
;
123 icon
= wmalloc(sizeof(WIcon
));
124 memset(icon
, 0, sizeof(WIcon
));
125 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
126 wPreferences
.icon_size
,
127 wPreferences
.icon_size
, 0);
129 if (wPreferences
.use_saveunders
) {
130 vmask
|= CWSaveUnder
;
131 attribs
.save_under
= True
;
133 /* a white border for selecting it */
134 vmask
|= CWBorderPixel
;
135 attribs
.border_pixel
= scr
->white_pixel
;
137 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
140 /* will be overriden if this is an application icon */
141 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
142 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
143 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
144 icon
->core
->descriptor
.parent
= icon
;
146 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
147 icon
->core
->stacking
->above
= NULL
;
148 icon
->core
->stacking
->under
= NULL
;
149 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
150 icon
->core
->stacking
->child_of
= NULL
;
153 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
154 if (wwin
->client_win
== wwin
->main_window
) {
156 /* do not let miniwindow steal app-icon's icon window */
157 wapp
= wApplicationOf(wwin
->client_win
);
158 if (!wapp
|| wapp
->app_icon
==NULL
)
159 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
161 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
164 #ifdef NO_MINIWINDOW_TITLES
165 icon
->show_title
= 0;
167 icon
->show_title
= 1;
170 if (!icon
->image
&& !WFLAGP(wwin
, always_user_icon
))
171 icon
->image
= RRetainImage(wwin
->net_icon_image
);
174 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
176 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
,
179 icon
->file
= wstrdup(file
);
182 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
184 icon
->tile_type
= TILE_NORMAL
;
190 WMAddNotificationObserver(appearanceObserver
, icon
,
191 WNIconAppearanceSettingsChanged
, icon
);
192 WMAddNotificationObserver(tileObserver
, icon
,
193 WNIconTileSettingsChanged
, icon
);
199 wIconCreateWithIconFile(WScreen
*scr
, char *iconfile
, int tile
)
202 unsigned long vmask
= 0;
203 XSetWindowAttributes attribs
;
205 icon
= wmalloc(sizeof(WIcon
));
206 memset(icon
, 0, sizeof(WIcon
));
207 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
,
208 wPreferences
.icon_size
, 0);
209 if (wPreferences
.use_saveunders
) {
211 attribs
.save_under
= True
;
213 /* a white border for selecting it */
214 vmask
|= CWBorderPixel
;
215 attribs
.border_pixel
= scr
->white_pixel
;
217 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
219 /* will be overriden if this is a application icon */
220 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
221 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
222 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
223 icon
->core
->descriptor
.parent
= icon
;
225 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
226 icon
->core
->stacking
->above
= NULL
;
227 icon
->core
->stacking
->under
= NULL
;
228 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
229 icon
->core
->stacking
->child_of
= NULL
;
232 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
234 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
237 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
239 icon
->file
= wstrdup(iconfile
);
242 icon
->tile_type
= tile
;
246 WMAddNotificationObserver(appearanceObserver
, icon
,
247 WNIconAppearanceSettingsChanged
, icon
);
248 WMAddNotificationObserver(tileObserver
, icon
,
249 WNIconTileSettingsChanged
, icon
);
257 wIconDestroy(WIcon
*icon
)
259 WCoreWindow
*core
= icon
->core
;
260 WScreen
*scr
= core
->screen_ptr
;
262 WMRemoveNotificationObserver(icon
);
265 WMDeleteTimerHandler(icon
->handlerID
);
267 if (icon
->icon_win
) {
271 x
= icon
->owner
->icon_x
;
272 y
= icon
->owner
->icon_y
;
274 XUnmapWindow(dpy
, icon
->icon_win
);
275 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
278 XFree(icon
->icon_name
);
281 XFreePixmap(dpy
, icon
->pixmap
);
286 if (icon
->image
!=NULL
)
287 RReleaseImage(icon
->image
);
289 wCoreDestroy(icon
->core
);
296 drawIconTitle(WScreen
*scr
, Pixmap pixmap
, int height
)
298 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
,
299 0, 0, wPreferences
.icon_size
, height
+1);
300 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
301 wPreferences
.icon_size
, 0);
302 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
304 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
305 wPreferences
.icon_size
-1, 0, wPreferences
.icon_size
-1, height
+1);
310 makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
)
316 int theight
= WMFontHeight(scr
->icon_title_font
);
318 if (tileType
== TILE_NORMAL
)
319 tile
= RCloneImage(scr
->icon_tile
);
321 assert(scr
->clip_tile
);
322 tile
= RCloneImage(scr
->clip_tile
);
325 w
= (icon
->width
> wPreferences
.icon_size
)
326 ? wPreferences
.icon_size
: icon
->width
;
327 x
= (wPreferences
.icon_size
- w
) / 2;
328 sx
= (icon
->width
- w
)/2;
331 h
= (icon
->height
> wPreferences
.icon_size
)
332 ? wPreferences
.icon_size
: icon
->height
;
333 y
= (wPreferences
.icon_size
- h
) / 2;
334 sy
= (icon
->height
- h
)/2;
336 h
= (icon
->height
+theight
> wPreferences
.icon_size
337 ? wPreferences
.icon_size
-theight
: icon
->height
);
338 y
= theight
+((int)wPreferences
.icon_size
-theight
-h
)/2;
339 sy
= (icon
->height
- h
)/2;
341 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
347 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
348 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
349 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
350 color
.alpha
= 150; /* about 60% */
351 RClearImage(tile
, &color
);
354 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
355 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
360 drawIconTitle(scr
, pixmap
, theight
);
367 wIconChangeTitle(WIcon
*icon
, char *new_title
)
371 changed
= (new_title
==NULL
&& icon
->icon_name
!=NULL
)
372 || (new_title
!=NULL
&& icon
->icon_name
==NULL
);
374 if (icon
->icon_name
!=NULL
)
375 XFree(icon
->icon_name
);
377 icon
->icon_name
= new_title
;
380 icon
->force_paint
= 1;
386 wIconChangeImage(WIcon
*icon
, RImage
*new_image
)
388 assert(icon
!= NULL
);
391 RReleaseImage(icon
->image
);
393 icon
->image
= new_image
;
400 wIconValidateIconSize(WScreen
*scr
, RImage
*icon
)
407 #ifndef DONT_SCALE_ICONS
408 if (wPreferences
.icon_size
!= 64) {
409 w
= wPreferences
.icon_size
* icon
->width
/ 64;
410 h
= wPreferences
.icon_size
* icon
->height
/ 64;
412 tmp
= RScaleImage(icon
, w
, h
);
418 if (icon
->width
> wPreferences
.icon_size
419 || icon
->height
> wPreferences
.icon_size
) {
420 if (icon
->width
> icon
->height
) {
421 w
= wPreferences
.icon_size
- 4;
422 h
= w
*icon
->height
/icon
->width
;
424 h
= wPreferences
.icon_size
- 4;
425 w
= h
*icon
->width
/icon
->height
;
427 tmp
= RScaleImage(icon
, w
, h
);
438 wIconChangeImageFile(WIcon
*icon
, char *file
)
440 WScreen
*scr
= icon
->core
->screen_ptr
;
446 wIconChangeImage(icon
, NULL
);
450 path
= FindImage(wPreferences
.icon_path
, file
);
452 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
453 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
455 wIconChangeImage(icon
, image
);
469 getnameforicon(WWindow
*wwin
)
471 char *prefix
, *suffix
;
475 if (wwin
->wm_class
&& wwin
->wm_instance
) {
476 int len
= strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2;
477 suffix
= wmalloc(len
);
478 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
479 } else if (wwin
->wm_class
) {
480 int len
= strlen(wwin
->wm_class
)+1;
481 suffix
= wmalloc(len
);
482 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
483 } else if (wwin
->wm_instance
) {
484 int len
= strlen(wwin
->wm_instance
)+1;
485 suffix
= wmalloc(len
);
486 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
491 prefix
= wusergnusteppath();
492 len
= strlen(prefix
)+64+strlen(suffix
);
493 path
= wmalloc(len
+1);
494 snprintf(path
, len
, "%s/.AppInfo", prefix
);
496 if (access(path
, F_OK
)!=0) {
497 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
498 wsyserror(_("could not create directory %s"), path
);
504 strcat(path
, "/WindowMaker");
505 if (access(path
, F_OK
)!=0) {
506 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
507 wsyserror(_("could not create directory %s"), path
);
515 strcat(path
, suffix
);
516 strcat(path
, ".xpm");
525 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
526 * and returns the path for that icon. Returns NULL if there is no
527 * client supplied icon or on failure.
530 * New directories might be created.
533 wIconStore(WIcon
*icon
)
537 WWindow
*wwin
= icon
->owner
;
539 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
540 || wwin
->wm_hints
->icon_pixmap
== None
)
543 path
= getnameforicon(wwin
);
547 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
548 wwin
->wm_hints
->icon_pixmap
,
549 (wwin
->wm_hints
->flags
& IconMaskHint
)
550 ? wwin
->wm_hints
->icon_mask
: None
);
556 if (!RSaveImage(image
, path
, "XPM")) {
560 RReleaseImage(image
);
567 void wIconChangeIconWindow(WIcon *icon, Window new_window);
571 cycleColor(void *data
)
573 WIcon
*icon
= (WIcon
*)data
;
574 WScreen
*scr
= icon
->core
->screen_ptr
;
578 gcv
.dash_offset
= icon
->step
;
579 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
581 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
582 icon
->core
->width
-1, icon
->core
->height
-1);
583 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
588 wIconSetHighlited(WIcon
*icon
, Bool flag
)
590 if (icon
->highlighted
== flag
) {
594 icon
->highlighted
= flag
;
601 wIconSelect(WIcon
*icon
)
603 WScreen
*scr
= icon
->core
->screen_ptr
;
604 icon
->selected
= !icon
->selected
;
606 if (icon
->selected
) {
608 if (!wPreferences
.dont_blink
)
609 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
611 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
612 icon
->core
->width
-1, icon
->core
->height
-1);
614 if (icon
->handlerID
) {
615 WMDeleteTimerHandler(icon
->handlerID
);
616 icon
->handlerID
= NULL
;
618 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
619 icon
->core
->height
, True
);
625 wIconUpdate(WIcon
*icon
)
627 WScreen
*scr
= icon
->core
->screen_ptr
;
628 int title_height
= WMFontHeight(scr
->icon_title_font
);
629 WWindow
*wwin
= icon
->owner
;
631 assert(scr
->icon_tile
!=NULL
);
633 if (icon
->pixmap
!=None
)
634 XFreePixmap(dpy
, icon
->pixmap
);
638 if (wwin
&& (WFLAGP(wwin
, always_user_icon
)
640 || wwin
->net_icon_image
645 /* use client specified icon window */
646 if (icon
->icon_win
!=None
) {
647 XWindowAttributes attr
;
649 int width
, height
, depth
;
653 getSize(icon
->icon_win
, &width
, &height
, &depth
);
655 if (width
> wPreferences
.icon_size
) {
657 width
= wPreferences
.icon_size
;
659 if (height
> wPreferences
.icon_size
) {
661 height
= wPreferences
.icon_size
;
664 && (height
+title_height
< wPreferences
.icon_size
)) {
665 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
666 wPreferences
.icon_size
, scr
->w_depth
);
667 XSetClipMask(dpy
, scr
->copy_gc
, None
);
668 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
669 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
670 drawIconTitle(scr
, pixmap
, title_height
);
671 theight
= title_height
;
675 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
676 scr
->icon_tile_pixmap
);
679 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
680 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
681 (wPreferences
.icon_size
-width
)/2,
682 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
684 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
686 XMapWindow(dpy
, icon
->icon_win
);
688 XAddToSaveSet(dpy
, icon
->icon_win
);
690 icon
->pixmap
= pixmap
;
692 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
693 if (attr
.all_event_masks
& ButtonPressMask
) {
694 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
695 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
696 None
, wCursor
[WCUR_ARROW
]);
699 } else if (wwin
&& wwin
->wm_hints
700 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
708 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
709 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
710 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
714 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
715 wPreferences
.icon_size
, scr
->w_depth
);
716 XSetClipMask(dpy
, scr
->copy_gc
, None
);
717 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
718 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
720 if (w
> wPreferences
.icon_size
)
721 w
= wPreferences
.icon_size
;
722 x
= (wPreferences
.icon_size
-w
)/2;
724 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
725 drawIconTitle(scr
, pixmap
, title_height
);
728 if (h
> wPreferences
.icon_size
- title_height
- 2) {
729 h
= wPreferences
.icon_size
- title_height
- 2;
730 y
= title_height
+ 1;
732 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
736 if (w
> wPreferences
.icon_size
)
737 w
= wPreferences
.icon_size
;
738 y
= (wPreferences
.icon_size
-h
)/2;
741 if (wwin
->wm_hints
->flags
& IconMaskHint
)
742 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
744 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
746 if (d
!= scr
->w_depth
) {
747 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
748 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
749 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
750 0, 0, w
, h
, x
, y
, 1);
752 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
756 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
758 icon
->pixmap
= pixmap
;
763 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
764 icon
->shadowed
, icon
->tile_type
);
766 /* make default icons */
768 if (!scr
->def_icon_pixmap
) {
769 RImage
*image
= NULL
;
773 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
775 path
= FindImage(wPreferences
.icon_path
, file
);
777 wwarning(_("could not find default icon \"%s\""),file
);
781 image
= RLoadImage(scr
->rcontext
, path
, 0);
783 wwarning(_("could not load default icon \"%s\":%s"),
784 file
, RMessageForError(RErrorCode
));
790 image
= wIconValidateIconSize(scr
, image
);
791 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
793 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
796 RReleaseImage(image
);
799 if (icon
->show_title
) {
800 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
801 scr
->def_ticon_pixmap
);
803 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
804 scr
->def_icon_pixmap
);
809 if (icon
->pixmap
!= None
) {
810 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
812 XClearWindow(dpy
, icon
->core
->window
);
820 wIconPaint(WIcon
*icon
)
822 WScreen
*scr
=icon
->core
->screen_ptr
;
826 if (icon
->force_paint
) {
827 icon
->force_paint
= 0;
832 XClearWindow(dpy
, icon
->core
->window
);
834 /* draw the icon title */
835 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
839 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
840 wPreferences
.icon_size
-4);
841 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
=strlen(tmp
));
843 if (w
> icon
->core
->width
- 4)
844 x
= (icon
->core
->width
- 4) - w
;
846 x
= (icon
->core
->width
- w
)/2;
848 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
849 scr
->icon_title_font
, x
, 1, tmp
, l
);
854 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
855 icon
->core
->width
-1, icon
->core
->height
-1);
859 /******************************************************************/
862 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
864 wIconPaint(desc
->parent
);
869 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
871 WIcon
*icon
= desc
->parent
;
873 assert(icon
->owner
!=NULL
);
875 wDeiconifyWindow(icon
->owner
);
880 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
882 WIcon
*icon
= desc
->parent
;
883 WWindow
*wwin
= icon
->owner
;
885 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
886 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
888 int clickButton
=event
->xbutton
.button
;
890 if (WCHECK_STATE(WSTATE_MODAL
))
893 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
894 miniwindowDblClick(desc
, event
);
899 puts("Moving miniwindow");
901 if (event
->xbutton
.button
== Button1
) {
902 if (event
->xbutton
.state
& MOD_MASK
)
903 wLowerFrame(icon
->core
);
905 wRaiseFrame(icon
->core
);
906 if (event
->xbutton
.state
& ShiftMask
) {
908 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
910 } else if (event
->xbutton
.button
== Button3
) {
911 WObjDescriptor
*desc
;
913 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
914 event
->xbutton
.y_root
);
916 /* allow drag select of menu */
917 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
918 event
->xbutton
.send_event
= True
;
919 (*desc
->handle_mousedown
)(desc
, event
);
924 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
925 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
926 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
928 wwarning("pointer grab failed for icon move");
932 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
933 |ButtonMotionMask
|ExposureMask
, &ev
);
941 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
942 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
943 XChangeActivePointerGrab(dpy
, ButtonMotionMask
944 |ButtonReleaseMask
|ButtonPressMask
,
945 wCursor
[WCUR_MOVE
], CurrentTime
);
951 x
= ev
.xmotion
.x_root
- dx
;
952 y
= ev
.xmotion
.y_root
- dy
;
953 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
960 if (ev
.xbutton
.button
!= clickButton
)
963 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
964 wwin
->flags
.icon_moved
= 1;
966 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
971 puts("End miniwindow move");
973 XUngrabPointer(dpy
, CurrentTime
);
975 if (wPreferences
.auto_arrange_icons
)
976 wArrangeIcons(wwin
->screen_ptr
, True
);