1 /* icon.c - window icon and dock and appicon parent
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 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, 1, 1, True
);
88 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 /************************************/
103 getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
109 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
114 wIconCreate(WWindow
*wwin
)
116 WScreen
*scr
=wwin
->screen_ptr
;
119 unsigned long vmask
= 0;
120 XSetWindowAttributes attribs
;
122 icon
= wmalloc(sizeof(WIcon
));
123 memset(icon
, 0, sizeof(WIcon
));
124 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
125 wPreferences
.icon_size
,
126 wPreferences
.icon_size
, 0);
128 if (wPreferences
.use_saveunders
) {
129 vmask
|= CWSaveUnder
;
130 attribs
.save_under
= True
;
132 /* a white border for selecting it */
133 vmask
|= CWBorderPixel
;
134 attribs
.border_pixel
= scr
->white_pixel
;
136 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
139 /* will be overriden if this is an application icon */
140 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
141 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
142 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
143 icon
->core
->descriptor
.parent
= icon
;
145 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
146 icon
->core
->stacking
->above
= NULL
;
147 icon
->core
->stacking
->under
= NULL
;
148 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
149 icon
->core
->stacking
->child_of
= NULL
;
152 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
153 if (wwin
->client_win
== wwin
->main_window
) {
155 /* do not let miniwindow steal app-icon's icon window */
156 wapp
= wApplicationOf(wwin
->client_win
);
157 if (!wapp
|| wapp
->app_icon
==NULL
)
158 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
160 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
163 #ifdef NO_MINIWINDOW_TITLES
164 icon
->show_title
= 0;
166 icon
->show_title
= 1;
168 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
170 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
,
173 icon
->file
= wstrdup(file
);
176 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
178 icon
->tile_type
= TILE_NORMAL
;
184 WMAddNotificationObserver(appearanceObserver
, icon
,
185 WNIconAppearanceSettingsChanged
, icon
);
186 WMAddNotificationObserver(tileObserver
, icon
,
187 WNIconTileSettingsChanged
, icon
);
193 wIconCreateWithIconFile(WScreen
*scr
, char *iconfile
, int tile
)
196 unsigned long vmask
= 0;
197 XSetWindowAttributes attribs
;
199 icon
= wmalloc(sizeof(WIcon
));
200 memset(icon
, 0, sizeof(WIcon
));
201 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
,
202 wPreferences
.icon_size
, 0);
203 if (wPreferences
.use_saveunders
) {
205 attribs
.save_under
= True
;
207 /* a white border for selecting it */
208 vmask
|= CWBorderPixel
;
209 attribs
.border_pixel
= scr
->white_pixel
;
211 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
213 /* will be overriden if this is a application icon */
214 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
215 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
216 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
217 icon
->core
->descriptor
.parent
= icon
;
219 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
220 icon
->core
->stacking
->above
= NULL
;
221 icon
->core
->stacking
->under
= NULL
;
222 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
223 icon
->core
->stacking
->child_of
= NULL
;
226 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
228 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
231 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
233 icon
->file
= wstrdup(iconfile
);
236 icon
->tile_type
= tile
;
240 WMAddNotificationObserver(tileObserver
, icon
,
241 WNIconTileSettingsChanged
, icon
);
249 wIconDestroy(WIcon
*icon
)
251 WCoreWindow
*core
= icon
->core
;
252 WScreen
*scr
= core
->screen_ptr
;
254 WMRemoveNotificationObserver(icon
);
257 WMDeleteTimerHandler(icon
->handlerID
);
259 if (icon
->icon_win
) {
263 x
= icon
->owner
->icon_x
;
264 y
= icon
->owner
->icon_y
;
266 XUnmapWindow(dpy
, icon
->icon_win
);
267 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
270 XFree(icon
->icon_name
);
273 XFreePixmap(dpy
, icon
->pixmap
);
278 if (icon
->image
!=NULL
)
279 RDestroyImage(icon
->image
);
281 wCoreDestroy(icon
->core
);
288 drawIconTitle(WScreen
*scr
, Pixmap pixmap
, int height
)
290 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
,
291 0, 0, wPreferences
.icon_size
, height
+1);
292 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
293 wPreferences
.icon_size
, 0);
294 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
296 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
297 wPreferences
.icon_size
-1, 0, wPreferences
.icon_size
-1, height
+1);
302 makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
)
308 int theight
= scr
->icon_title_font
->height
;
310 if (tileType
== TILE_NORMAL
)
311 tile
= RCloneImage(scr
->icon_tile
);
313 assert(scr
->clip_tile
);
314 tile
= RCloneImage(scr
->clip_tile
);
317 w
= (icon
->width
> wPreferences
.icon_size
)
318 ? wPreferences
.icon_size
: icon
->width
;
319 x
= (wPreferences
.icon_size
- w
) / 2;
320 sx
= (icon
->width
- w
)/2;
323 h
= (icon
->height
> wPreferences
.icon_size
)
324 ? wPreferences
.icon_size
: icon
->height
;
325 y
= (wPreferences
.icon_size
- h
) / 2;
326 sy
= (icon
->height
- h
)/2;
328 h
= (icon
->height
+theight
> wPreferences
.icon_size
329 ? wPreferences
.icon_size
-theight
: icon
->height
);
330 y
= theight
+((int)wPreferences
.icon_size
-theight
-h
)/2;
331 sy
= (icon
->height
- h
)/2;
333 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
339 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
340 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
341 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
342 color
.alpha
= 150; /* about 60% */
343 RClearImage(tile
, &color
);
346 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
347 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
352 drawIconTitle(scr
, pixmap
, theight
);
359 wIconChangeTitle(WIcon
*icon
, char *new_title
)
363 changed
= (new_title
==NULL
&& icon
->icon_name
!=NULL
)
364 || (new_title
!=NULL
&& icon
->icon_name
==NULL
);
366 if (icon
->icon_name
!=NULL
)
367 XFree(icon
->icon_name
);
369 icon
->icon_name
= new_title
;
372 icon
->force_paint
= 1;
378 wIconChangeImage(WIcon
*icon
, RImage
*new_image
)
380 assert(icon
!= NULL
);
383 RDestroyImage(icon
->image
);
385 icon
->image
= wIconValidateIconSize(icon
->core
->screen_ptr
, new_image
);
392 wIconValidateIconSize(WScreen
*scr
, RImage
*icon
)
400 if (icon
->width
> wPreferences
.icon_size
401 || icon
->height
> wPreferences
.icon_size
) {
402 if (icon
->width
> icon
->height
) {
403 w
= wPreferences
.icon_size
- 4;
404 h
= w
*icon
->height
/icon
->width
;
406 h
= wPreferences
.icon_size
- 4;
407 w
= h
*icon
->width
/icon
->height
;
409 tmp
= RScaleImage(icon
, w
, h
);
419 wIconChangeImageFile(WIcon
*icon
, char *file
)
421 WScreen
*scr
= icon
->core
->screen_ptr
;
427 wIconChangeImage(icon
, NULL
);
431 path
= FindImage(wPreferences
.icon_path
, file
);
433 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
434 wIconChangeImage(icon
, image
);
448 getnameforicon(WWindow
*wwin
)
450 char *prefix
, *suffix
;
454 if (wwin
->wm_class
&& wwin
->wm_instance
) {
455 suffix
= wmalloc(strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2);
456 sprintf(suffix
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
457 } else if (wwin
->wm_class
) {
458 suffix
= wmalloc(strlen(wwin
->wm_class
)+1);
459 strcpy(suffix
, wwin
->wm_class
);
460 } else if (wwin
->wm_instance
) {
461 suffix
= wmalloc(strlen(wwin
->wm_instance
)+1);
462 strcpy(suffix
, wwin
->wm_instance
);
467 prefix
= wusergnusteppath();
468 len
= strlen(prefix
)+64+strlen(suffix
);
469 path
= wmalloc(len
+1);
470 sprintf(path
, "%s/.AppInfo", prefix
);
472 if (access(path
, F_OK
)!=0) {
473 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
474 wsyserror(_("could not create directory %s"), path
);
480 strcat(path
, "/WindowMaker");
481 if (access(path
, F_OK
)!=0) {
482 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
483 wsyserror(_("could not create directory %s"), path
);
491 strcat(path
, suffix
);
492 strcat(path
, ".xpm");
501 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
502 * and returns the path for that icon. Returns NULL if there is no
503 * client supplied icon or on failure.
506 * New directories might be created.
509 wIconStore(WIcon
*icon
)
513 WWindow
*wwin
= icon
->owner
;
515 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
516 || wwin
->wm_hints
->icon_pixmap
== None
)
519 path
= getnameforicon(wwin
);
523 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
524 wwin
->wm_hints
->icon_pixmap
,
525 (wwin
->wm_hints
->flags
& IconMaskHint
)
526 ? wwin
->wm_hints
->icon_mask
: None
);
532 if (!RSaveImage(image
, path
, "XPM")) {
536 RDestroyImage(image
);
544 wIconChangeIconWindow(WIcon *icon, Window new_window);
548 cycleColor(void *data
)
550 WIcon
*icon
= (WIcon
*)data
;
551 WScreen
*scr
= icon
->core
->screen_ptr
;
555 gcv
.dash_offset
= icon
->step
;
556 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
558 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
559 icon
->core
->width
-1, icon
->core
->height
-1);
560 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
565 wIconSetHighlited(WIcon
*icon
, Bool flag
)
567 if (icon
->highlighted
== flag
) {
571 icon
->highlighted
= flag
;
578 wIconSelect(WIcon
*icon
)
580 WScreen
*scr
= icon
->core
->screen_ptr
;
581 icon
->selected
= !icon
->selected
;
583 if (icon
->selected
) {
585 if (!wPreferences
.dont_blink
)
586 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
588 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
589 icon
->core
->width
-1, icon
->core
->height
-1);
591 if (icon
->handlerID
) {
592 WMDeleteTimerHandler(icon
->handlerID
);
593 icon
->handlerID
= NULL
;
595 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
596 icon
->core
->height
, True
);
602 wIconUpdate(WIcon
*icon
)
604 WScreen
*scr
= icon
->core
->screen_ptr
;
605 int title_height
= scr
->icon_title_font
->height
;
606 WWindow
*wwin
= icon
->owner
;
608 assert(scr
->icon_tile
!=NULL
);
610 if (icon
->pixmap
!=None
)
611 XFreePixmap(dpy
, icon
->pixmap
);
615 if (wwin
&& WFLAGP(wwin
, always_user_icon
))
618 /* use client specified icon window */
619 if (icon
->icon_win
!=None
) {
620 XWindowAttributes attr
;
622 int width
, height
, depth
;
626 getSize(icon
->icon_win
, &width
, &height
, &depth
);
628 if (width
> wPreferences
.icon_size
) {
630 width
= wPreferences
.icon_size
;
632 if (height
> wPreferences
.icon_size
) {
634 height
= wPreferences
.icon_size
;
637 && (height
+title_height
< wPreferences
.icon_size
)) {
638 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
639 wPreferences
.icon_size
, scr
->w_depth
);
640 XSetClipMask(dpy
, scr
->copy_gc
, None
);
641 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
642 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
643 drawIconTitle(scr
, pixmap
, title_height
);
644 theight
= title_height
;
648 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
649 scr
->icon_tile_pixmap
);
652 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
653 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
654 (wPreferences
.icon_size
-width
)/2,
655 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
657 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
659 XMapWindow(dpy
, icon
->icon_win
);
661 XAddToSaveSet(dpy
, icon
->icon_win
);
663 icon
->pixmap
= pixmap
;
665 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
666 if (attr
.all_event_masks
& ButtonPressMask
) {
667 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
668 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
669 None
, wCursor
[WCUR_ARROW
]);
672 } else if (wwin
&& wwin
->wm_hints
673 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
681 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
682 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
683 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
687 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
688 wPreferences
.icon_size
, scr
->w_depth
);
689 XSetClipMask(dpy
, scr
->copy_gc
, None
);
690 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
691 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
693 if (w
> wPreferences
.icon_size
)
694 w
= wPreferences
.icon_size
;
695 x
= (wPreferences
.icon_size
-w
)/2;
697 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
698 drawIconTitle(scr
, pixmap
, title_height
);
701 if (h
> wPreferences
.icon_size
- title_height
- 2) {
702 h
= wPreferences
.icon_size
- title_height
- 2;
703 y
= title_height
+ 1;
705 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
709 if (w
> wPreferences
.icon_size
)
710 w
= wPreferences
.icon_size
;
711 y
= (wPreferences
.icon_size
-h
)/2;
714 if (wwin
->wm_hints
->flags
& IconMaskHint
)
715 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
717 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
719 if (d
!= scr
->w_depth
) {
720 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
721 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
722 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
723 0, 0, w
, h
, x
, y
, 1);
725 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
729 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
731 icon
->pixmap
= pixmap
;
736 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
737 icon
->shadowed
, icon
->tile_type
);
739 /* make default icons */
741 if (!scr
->def_icon_pixmap
) {
742 RImage
*image
= NULL
;
746 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
748 path
= FindImage(wPreferences
.icon_path
, file
);
750 wwarning(_("could not find default icon \"%s\""),file
);
754 image
= RLoadImage(scr
->rcontext
, path
, 0);
756 wwarning(_("could not load default icon \"%s\":%s"),
757 file
, RMessageForError(RErrorCode
));
763 image
= wIconValidateIconSize(scr
, image
);
764 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
766 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
769 RDestroyImage(image
);
772 if (icon
->show_title
) {
773 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
774 scr
->def_ticon_pixmap
);
776 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
777 scr
->def_icon_pixmap
);
782 if (icon
->pixmap
!= None
) {
783 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
785 XClearWindow(dpy
, icon
->core
->window
);
793 wIconPaint(WIcon
*icon
)
795 WScreen
*scr
=icon
->core
->screen_ptr
;
796 GC gc
= scr
->icon_title_gc
;
800 if (icon
->force_paint
) {
801 icon
->force_paint
= 0;
806 XClearWindow(dpy
, icon
->core
->window
);
808 /* draw the icon title */
809 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
813 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
814 wPreferences
.icon_size
-4);
815 w
= wTextWidth(scr
->icon_title_font
->font
, tmp
, l
=strlen(tmp
));
817 if (w
> icon
->core
->width
- 4)
818 x
= (icon
->core
->width
- 4) - w
;
820 x
= (icon
->core
->width
- w
)/2;
822 wDrawString(icon
->core
->window
, scr
->icon_title_font
, gc
,
823 x
, 1 + scr
->icon_title_font
->y
, tmp
, l
);
828 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
829 icon
->core
->width
-1, icon
->core
->height
-1);
833 /******************************************************************/
836 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
838 wIconPaint(desc
->parent
);
843 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
845 WIcon
*icon
= desc
->parent
;
847 assert(icon
->owner
!=NULL
);
849 wDeiconifyWindow(icon
->owner
);
854 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
856 WIcon
*icon
= desc
->parent
;
857 WWindow
*wwin
= icon
->owner
;
859 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
860 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
862 int clickButton
=event
->xbutton
.button
;
864 if (WCHECK_STATE(WSTATE_MODAL
))
867 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
868 miniwindowDblClick(desc
, event
);
873 puts("Moving miniwindow");
875 if (event
->xbutton
.button
== Button1
) {
876 if (event
->xbutton
.state
& MOD_MASK
)
877 wLowerFrame(icon
->core
);
879 wRaiseFrame(icon
->core
);
880 if (event
->xbutton
.state
& ShiftMask
) {
882 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
884 } else if (event
->xbutton
.button
== Button3
) {
885 WObjDescriptor
*desc
;
887 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
888 event
->xbutton
.y_root
);
890 /* allow drag select of menu */
891 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
892 event
->xbutton
.send_event
= True
;
893 (*desc
->handle_mousedown
)(desc
, event
);
898 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
899 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
900 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
902 wwarning("pointer grab failed for icon move");
906 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
907 |ButtonMotionMask
|ExposureMask
, &ev
);
915 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
916 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
917 XChangeActivePointerGrab(dpy
, ButtonMotionMask
918 |ButtonReleaseMask
|ButtonPressMask
,
919 wCursor
[WCUR_MOVE
], CurrentTime
);
925 x
= ev
.xmotion
.x_root
- dx
;
926 y
= ev
.xmotion
.y_root
- dy
;
927 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
934 if (ev
.xbutton
.button
!= clickButton
)
937 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
938 wwin
->flags
.icon_moved
= 1;
940 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
945 puts("End miniwindow move");
947 XUngrabPointer(dpy
, CurrentTime
);
949 if (wPreferences
.auto_arrange_icons
)
950 wArrangeIcons(wwin
->screen_ptr
, True
);