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) {
78 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
79 /* wIconPaint(icon);*/
84 tileObserver(void *self
, WMNotification
*notif
)
86 WIcon
*icon
= (WIcon
*)self
;
88 icon
->force_paint
= 1;
89 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
90 /* wIconPaint(icon);*/
93 /************************************/
98 getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
104 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
109 wIconCreate(WWindow
*wwin
)
111 WScreen
*scr
=wwin
->screen_ptr
;
114 unsigned long vmask
= 0;
115 XSetWindowAttributes attribs
;
117 icon
= wmalloc(sizeof(WIcon
));
118 memset(icon
, 0, sizeof(WIcon
));
119 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
120 wPreferences
.icon_size
,
121 wPreferences
.icon_size
, 0);
123 if (wPreferences
.use_saveunders
) {
124 vmask
|= CWSaveUnder
;
125 attribs
.save_under
= True
;
127 /* a white border for selecting it */
128 vmask
|= CWBorderPixel
;
129 attribs
.border_pixel
= scr
->white_pixel
;
131 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
134 /* will be overriden if this is an application icon */
135 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
136 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
137 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
138 icon
->core
->descriptor
.parent
= icon
;
140 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
141 icon
->core
->stacking
->above
= NULL
;
142 icon
->core
->stacking
->under
= NULL
;
143 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
144 icon
->core
->stacking
->child_of
= NULL
;
147 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
148 if (wwin
->client_win
== wwin
->main_window
) {
150 /* do not let miniwindow steal app-icon's icon window */
151 wapp
= wApplicationOf(wwin
->client_win
);
152 if (!wapp
|| wapp
->app_icon
==NULL
)
153 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
155 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
158 #ifdef NO_MINIWINDOW_TITLES
159 icon
->show_title
= 0;
161 icon
->show_title
= 1;
163 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
165 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
,
168 icon
->file
= wstrdup(file
);
171 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
173 icon
->tile_type
= TILE_NORMAL
;
179 WMAddNotificationObserver(appearanceObserver
, icon
,
180 WNIconAppearanceSettingsChanged
, icon
);
181 WMAddNotificationObserver(tileObserver
, icon
,
182 WNIconTileSettingsChanged
, icon
);
188 wIconCreateWithIconFile(WScreen
*scr
, char *iconfile
, int tile
)
191 unsigned long vmask
= 0;
192 XSetWindowAttributes attribs
;
194 icon
= wmalloc(sizeof(WIcon
));
195 memset(icon
, 0, sizeof(WIcon
));
196 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
,
197 wPreferences
.icon_size
, 0);
198 if (wPreferences
.use_saveunders
) {
200 attribs
.save_under
= True
;
202 /* a white border for selecting it */
203 vmask
|= CWBorderPixel
;
204 attribs
.border_pixel
= scr
->white_pixel
;
206 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
208 /* will be overriden if this is a application icon */
209 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
210 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
211 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
212 icon
->core
->descriptor
.parent
= icon
;
214 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
215 icon
->core
->stacking
->above
= NULL
;
216 icon
->core
->stacking
->under
= NULL
;
217 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
218 icon
->core
->stacking
->child_of
= NULL
;
221 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
223 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
226 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
228 icon
->file
= wstrdup(iconfile
);
231 icon
->tile_type
= tile
;
235 WMAddNotificationObserver(tileObserver
, icon
,
236 WNIconTileSettingsChanged
, icon
);
244 wIconDestroy(WIcon
*icon
)
246 WCoreWindow
*core
= icon
->core
;
247 WScreen
*scr
= core
->screen_ptr
;
249 WMRemoveNotificationObserver(icon
);
252 WMDeleteTimerHandler(icon
->handlerID
);
254 if (icon
->icon_win
) {
258 x
= icon
->owner
->icon_x
;
259 y
= icon
->owner
->icon_y
;
261 XUnmapWindow(dpy
, icon
->icon_win
);
262 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
265 XFree(icon
->icon_name
);
268 XFreePixmap(dpy
, icon
->pixmap
);
273 if (icon
->image
!=NULL
)
274 RDestroyImage(icon
->image
);
276 wCoreDestroy(icon
->core
);
283 drawIconTitle(WScreen
*scr
, Pixmap pixmap
, int height
)
285 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
,
286 0, 0, wPreferences
.icon_size
, height
+1);
287 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
288 wPreferences
.icon_size
, 0);
289 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
291 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
292 wPreferences
.icon_size
-1, 0, wPreferences
.icon_size
-1, height
+1);
297 makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
)
303 int theight
= scr
->icon_title_font
->height
;
305 if (tileType
== TILE_NORMAL
)
306 tile
= RCloneImage(scr
->icon_tile
);
308 assert(scr
->clip_tile
);
309 tile
= RCloneImage(scr
->clip_tile
);
312 w
= (icon
->width
> wPreferences
.icon_size
)
313 ? wPreferences
.icon_size
: icon
->width
;
314 x
= (wPreferences
.icon_size
- w
) / 2;
315 sx
= (icon
->width
- w
)/2;
318 h
= (icon
->height
> wPreferences
.icon_size
)
319 ? wPreferences
.icon_size
: icon
->height
;
320 y
= (wPreferences
.icon_size
- h
) / 2;
321 sy
= (icon
->height
- h
)/2;
323 h
= (icon
->height
+theight
> wPreferences
.icon_size
324 ? wPreferences
.icon_size
-theight
: icon
->height
);
325 y
= theight
+((int)wPreferences
.icon_size
-theight
-h
)/2;
326 sy
= (icon
->height
- h
)/2;
328 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
334 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
335 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
336 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
337 color
.alpha
= 150; /* about 60% */
338 RClearImage(tile
, &color
);
341 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
342 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
347 drawIconTitle(scr
, pixmap
, theight
);
354 wIconChangeTitle(WIcon
*icon
, char *new_title
)
358 changed
= (new_title
==NULL
&& icon
->icon_name
!=NULL
)
359 || (new_title
!=NULL
&& icon
->icon_name
==NULL
);
361 if (icon
->icon_name
!=NULL
)
362 XFree(icon
->icon_name
);
364 icon
->icon_name
= new_title
;
367 icon
->force_paint
= 1;
373 wIconChangeImage(WIcon
*icon
, RImage
*new_image
)
375 assert(icon
!= NULL
);
378 RDestroyImage(icon
->image
);
380 icon
->image
= wIconValidateIconSize(icon
->core
->screen_ptr
, new_image
);
387 wIconValidateIconSize(WScreen
*scr
, RImage
*icon
)
395 if (icon
->width
> wPreferences
.icon_size
396 || icon
->height
> wPreferences
.icon_size
) {
397 if (icon
->width
> icon
->height
) {
398 w
= wPreferences
.icon_size
- 4;
399 h
= w
*icon
->height
/icon
->width
;
401 h
= wPreferences
.icon_size
- 4;
402 w
= h
*icon
->width
/icon
->height
;
404 tmp
= RScaleImage(icon
, w
, h
);
414 wIconChangeImageFile(WIcon
*icon
, char *file
)
416 WScreen
*scr
= icon
->core
->screen_ptr
;
422 wIconChangeImage(icon
, NULL
);
426 path
= FindImage(wPreferences
.icon_path
, file
);
428 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
429 wIconChangeImage(icon
, image
);
443 getnameforicon(WWindow
*wwin
)
445 char *prefix
, *suffix
;
449 if (wwin
->wm_class
&& wwin
->wm_instance
) {
450 suffix
= wmalloc(strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2);
451 sprintf(suffix
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
452 } else if (wwin
->wm_class
) {
453 suffix
= wmalloc(strlen(wwin
->wm_class
)+1);
454 strcpy(suffix
, wwin
->wm_class
);
455 } else if (wwin
->wm_instance
) {
456 suffix
= wmalloc(strlen(wwin
->wm_instance
)+1);
457 strcpy(suffix
, wwin
->wm_instance
);
462 prefix
= wusergnusteppath();
463 len
= strlen(prefix
)+64+strlen(suffix
);
464 path
= wmalloc(len
+1);
465 sprintf(path
, "%s/.AppInfo", prefix
);
467 if (access(path
, F_OK
)!=0) {
468 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
469 wsyserror(_("could not create directory %s"), path
);
475 strcat(path
, "/WindowMaker");
476 if (access(path
, F_OK
)!=0) {
477 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
478 wsyserror(_("could not create directory %s"), path
);
486 strcat(path
, suffix
);
487 strcat(path
, ".xpm");
496 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
497 * and returns the path for that icon. Returns NULL if there is no
498 * client supplied icon or on failure.
501 * New directories might be created.
504 wIconStore(WIcon
*icon
)
508 WWindow
*wwin
= icon
->owner
;
510 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
511 || wwin
->wm_hints
->icon_pixmap
== None
)
514 path
= getnameforicon(wwin
);
518 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
519 wwin
->wm_hints
->icon_pixmap
,
520 (wwin
->wm_hints
->flags
& IconMaskHint
)
521 ? wwin
->wm_hints
->icon_mask
: None
);
527 if (!RSaveImage(image
, path
, "XPM")) {
531 RDestroyImage(image
);
539 wIconChangeIconWindow(WIcon *icon, Window new_window);
543 cycleColor(void *data
)
545 WIcon
*icon
= (WIcon
*)data
;
546 WScreen
*scr
= icon
->core
->screen_ptr
;
550 gcv
.dash_offset
= icon
->step
;
551 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
553 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
554 icon
->core
->width
-1, icon
->core
->height
-1);
555 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
560 wIconSetHighlited(WIcon
*icon
, Bool flag
)
562 if (icon
->highlighted
== flag
) {
566 icon
->highlighted
= flag
;
573 wIconSelect(WIcon
*icon
)
575 WScreen
*scr
= icon
->core
->screen_ptr
;
576 icon
->selected
= !icon
->selected
;
578 if (icon
->selected
) {
580 if (!wPreferences
.dont_blink
)
581 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
583 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
584 icon
->core
->width
-1, icon
->core
->height
-1);
586 if (icon
->handlerID
) {
587 WMDeleteTimerHandler(icon
->handlerID
);
588 icon
->handlerID
= NULL
;
590 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
591 icon
->core
->height
, True
);
597 wIconUpdate(WIcon
*icon
)
599 WScreen
*scr
= icon
->core
->screen_ptr
;
600 int title_height
= scr
->icon_title_font
->height
;
601 WWindow
*wwin
= icon
->owner
;
603 assert(scr
->icon_tile
!=NULL
);
605 if (icon
->pixmap
!=None
)
606 XFreePixmap(dpy
, icon
->pixmap
);
610 if (wwin
&& WFLAGP(wwin
, always_user_icon
))
613 /* use client specified icon window */
614 if (icon
->icon_win
!=None
) {
615 XWindowAttributes attr
;
617 int width
, height
, depth
;
621 getSize(icon
->icon_win
, &width
, &height
, &depth
);
623 if (width
> wPreferences
.icon_size
) {
625 width
= wPreferences
.icon_size
;
627 if (height
> wPreferences
.icon_size
) {
629 height
= wPreferences
.icon_size
;
632 && (height
+title_height
< wPreferences
.icon_size
)) {
633 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
634 wPreferences
.icon_size
, scr
->w_depth
);
635 XSetClipMask(dpy
, scr
->copy_gc
, None
);
636 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
637 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
638 drawIconTitle(scr
, pixmap
, title_height
);
639 theight
= title_height
;
643 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
644 scr
->icon_tile_pixmap
);
647 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
648 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
649 (wPreferences
.icon_size
-width
)/2,
650 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
652 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
654 XMapWindow(dpy
, icon
->icon_win
);
656 XAddToSaveSet(dpy
, icon
->icon_win
);
658 icon
->pixmap
= pixmap
;
660 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
661 if (attr
.all_event_masks
& ButtonPressMask
) {
662 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
663 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
664 None
, wCursor
[WCUR_ARROW
]);
667 } else if (wwin
&& wwin
->wm_hints
668 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
676 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
677 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
678 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
682 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
683 wPreferences
.icon_size
, scr
->w_depth
);
684 XSetClipMask(dpy
, scr
->copy_gc
, None
);
685 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
686 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
688 if (w
> wPreferences
.icon_size
)
689 w
= wPreferences
.icon_size
;
690 x
= (wPreferences
.icon_size
-w
)/2;
692 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
693 drawIconTitle(scr
, pixmap
, title_height
);
696 if (h
> wPreferences
.icon_size
- title_height
- 2) {
697 h
= wPreferences
.icon_size
- title_height
- 2;
698 y
= title_height
+ 1;
700 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
704 if (w
> wPreferences
.icon_size
)
705 w
= wPreferences
.icon_size
;
706 y
= (wPreferences
.icon_size
-h
)/2;
709 if (wwin
->wm_hints
->flags
& IconMaskHint
)
710 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
712 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
714 if (d
!= scr
->w_depth
) {
715 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
716 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
717 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
718 0, 0, w
, h
, x
, y
, 1);
720 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
724 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
726 icon
->pixmap
= pixmap
;
731 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
732 icon
->shadowed
, icon
->tile_type
);
734 /* make default icons */
736 if (!scr
->def_icon_pixmap
) {
737 RImage
*image
= NULL
;
741 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
743 path
= FindImage(wPreferences
.icon_path
, file
);
745 wwarning(_("could not find default icon \"%s\""),file
);
749 image
= RLoadImage(scr
->rcontext
, path
, 0);
751 wwarning(_("could not load default icon \"%s\":%s"),
752 file
, RMessageForError(RErrorCode
));
758 image
= wIconValidateIconSize(scr
, image
);
759 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
761 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
764 RDestroyImage(image
);
767 if (icon
->show_title
) {
768 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
769 scr
->def_ticon_pixmap
);
771 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
772 scr
->def_icon_pixmap
);
777 if (icon
->pixmap
!= None
) {
778 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
780 XClearWindow(dpy
, icon
->core
->window
);
788 wIconPaint(WIcon
*icon
)
790 WScreen
*scr
=icon
->core
->screen_ptr
;
791 GC gc
= scr
->icon_title_gc
;
795 if (icon
->force_paint
) {
796 icon
->force_paint
= 0;
801 XClearWindow(dpy
, icon
->core
->window
);
803 /* draw the icon title */
804 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
808 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
809 wPreferences
.icon_size
-4);
810 w
= wTextWidth(scr
->icon_title_font
->font
, tmp
, l
=strlen(tmp
));
812 if (w
> icon
->core
->width
- 4)
813 x
= (icon
->core
->width
- 4) - w
;
815 x
= (icon
->core
->width
- w
)/2;
817 wDrawString(icon
->core
->window
, scr
->icon_title_font
, gc
,
818 x
, 1 + scr
->icon_title_font
->y
, tmp
, l
);
823 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
824 icon
->core
->width
-1, icon
->core
->height
-1);
828 /******************************************************************/
831 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
833 wIconPaint(desc
->parent
);
838 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
840 WIcon
*icon
= desc
->parent
;
842 assert(icon
->owner
!=NULL
);
844 wDeiconifyWindow(icon
->owner
);
849 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
851 WIcon
*icon
= desc
->parent
;
852 WWindow
*wwin
= icon
->owner
;
854 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
855 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
857 int clickButton
=event
->xbutton
.button
;
859 if (WCHECK_STATE(WSTATE_MODAL
))
862 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
863 miniwindowDblClick(desc
, event
);
868 puts("Moving miniwindow");
870 if (event
->xbutton
.button
== Button1
) {
871 if (event
->xbutton
.state
& MOD_MASK
)
872 wLowerFrame(icon
->core
);
874 wRaiseFrame(icon
->core
);
875 if (event
->xbutton
.state
& ShiftMask
) {
877 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
879 } else if (event
->xbutton
.button
== Button3
) {
880 WObjDescriptor
*desc
;
882 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
883 event
->xbutton
.y_root
);
885 /* allow drag select of menu */
886 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
887 event
->xbutton
.send_event
= True
;
888 (*desc
->handle_mousedown
)(desc
, event
);
893 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
894 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
895 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
897 wwarning("pointer grab failed for icon move");
901 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
902 |ButtonMotionMask
|ExposureMask
, &ev
);
910 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
911 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
912 XChangeActivePointerGrab(dpy
, ButtonMotionMask
913 |ButtonReleaseMask
|ButtonPressMask
,
914 wCursor
[WCUR_MOVE
], CurrentTime
);
920 x
= ev
.xmotion
.x_root
- dx
;
921 y
= ev
.xmotion
.y_root
- dy
;
922 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
929 if (ev
.xbutton
.button
!= clickButton
)
932 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
933 wwin
->flags
.icon_moved
= 1;
935 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
940 puts("End miniwindow move");
942 XUngrabPointer(dpy
, CurrentTime
);
944 if (wPreferences
.auto_arrange_icons
)
945 wArrangeIcons(wwin
->screen_ptr
, True
);