1 /* icon.c - window icon and dock and appicon parent
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 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;
169 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
171 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
,
174 icon
->file
= wstrdup(file
);
177 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
179 icon
->tile_type
= TILE_NORMAL
;
185 WMAddNotificationObserver(appearanceObserver
, icon
,
186 WNIconAppearanceSettingsChanged
, icon
);
187 WMAddNotificationObserver(tileObserver
, icon
,
188 WNIconTileSettingsChanged
, icon
);
194 wIconCreateWithIconFile(WScreen
*scr
, char *iconfile
, int tile
)
197 unsigned long vmask
= 0;
198 XSetWindowAttributes attribs
;
200 icon
= wmalloc(sizeof(WIcon
));
201 memset(icon
, 0, sizeof(WIcon
));
202 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
,
203 wPreferences
.icon_size
, 0);
204 if (wPreferences
.use_saveunders
) {
206 attribs
.save_under
= True
;
208 /* a white border for selecting it */
209 vmask
|= CWBorderPixel
;
210 attribs
.border_pixel
= scr
->white_pixel
;
212 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
214 /* will be overriden if this is a application icon */
215 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
216 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
217 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
218 icon
->core
->descriptor
.parent
= icon
;
220 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
221 icon
->core
->stacking
->above
= NULL
;
222 icon
->core
->stacking
->under
= NULL
;
223 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
224 icon
->core
->stacking
->child_of
= NULL
;
227 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
229 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
232 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
234 icon
->file
= wstrdup(iconfile
);
237 icon
->tile_type
= tile
;
241 WMAddNotificationObserver(appearanceObserver
, icon
,
242 WNIconAppearanceSettingsChanged
, icon
);
243 WMAddNotificationObserver(tileObserver
, icon
,
244 WNIconTileSettingsChanged
, icon
);
252 wIconDestroy(WIcon
*icon
)
254 WCoreWindow
*core
= icon
->core
;
255 WScreen
*scr
= core
->screen_ptr
;
257 WMRemoveNotificationObserver(icon
);
260 WMDeleteTimerHandler(icon
->handlerID
);
262 if (icon
->icon_win
) {
266 x
= icon
->owner
->icon_x
;
267 y
= icon
->owner
->icon_y
;
269 XUnmapWindow(dpy
, icon
->icon_win
);
270 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
273 XFree(icon
->icon_name
);
276 XFreePixmap(dpy
, icon
->pixmap
);
281 if (icon
->image
!=NULL
)
282 RReleaseImage(icon
->image
);
284 wCoreDestroy(icon
->core
);
291 drawIconTitle(WScreen
*scr
, Pixmap pixmap
, int height
)
293 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
,
294 0, 0, wPreferences
.icon_size
, height
+1);
295 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
296 wPreferences
.icon_size
, 0);
297 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
299 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
300 wPreferences
.icon_size
-1, 0, wPreferences
.icon_size
-1, height
+1);
305 makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
)
311 int theight
= WMFontHeight(scr
->icon_title_font
);
313 if (tileType
== TILE_NORMAL
)
314 tile
= RCloneImage(scr
->icon_tile
);
316 assert(scr
->clip_tile
);
317 tile
= RCloneImage(scr
->clip_tile
);
320 w
= (icon
->width
> wPreferences
.icon_size
)
321 ? wPreferences
.icon_size
: icon
->width
;
322 x
= (wPreferences
.icon_size
- w
) / 2;
323 sx
= (icon
->width
- w
)/2;
326 h
= (icon
->height
> wPreferences
.icon_size
)
327 ? wPreferences
.icon_size
: icon
->height
;
328 y
= (wPreferences
.icon_size
- h
) / 2;
329 sy
= (icon
->height
- h
)/2;
331 h
= (icon
->height
+theight
> wPreferences
.icon_size
332 ? wPreferences
.icon_size
-theight
: icon
->height
);
333 y
= theight
+((int)wPreferences
.icon_size
-theight
-h
)/2;
334 sy
= (icon
->height
- h
)/2;
336 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
342 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
343 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
344 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
345 color
.alpha
= 150; /* about 60% */
346 RClearImage(tile
, &color
);
349 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
350 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
355 drawIconTitle(scr
, pixmap
, theight
);
362 wIconChangeTitle(WIcon
*icon
, char *new_title
)
366 changed
= (new_title
==NULL
&& icon
->icon_name
!=NULL
)
367 || (new_title
!=NULL
&& icon
->icon_name
==NULL
);
369 if (icon
->icon_name
!=NULL
)
370 XFree(icon
->icon_name
);
372 icon
->icon_name
= new_title
;
375 icon
->force_paint
= 1;
381 wIconChangeImage(WIcon
*icon
, RImage
*new_image
)
383 assert(icon
!= NULL
);
386 RReleaseImage(icon
->image
);
388 icon
->image
= new_image
;
395 wIconValidateIconSize(WScreen
*scr
, RImage
*icon
)
402 #ifndef DONT_SCALE_ICONS
403 if (wPreferences
.icon_size
!= 64) {
404 w
= wPreferences
.icon_size
* icon
->width
/ 64;
405 h
= wPreferences
.icon_size
* icon
->height
/ 64;
407 tmp
= RScaleImage(icon
, w
, h
);
413 if (icon
->width
> wPreferences
.icon_size
414 || icon
->height
> wPreferences
.icon_size
) {
415 if (icon
->width
> icon
->height
) {
416 w
= wPreferences
.icon_size
- 4;
417 h
= w
*icon
->height
/icon
->width
;
419 h
= wPreferences
.icon_size
- 4;
420 w
= h
*icon
->width
/icon
->height
;
422 tmp
= RScaleImage(icon
, w
, h
);
433 wIconChangeImageFile(WIcon
*icon
, char *file
)
435 WScreen
*scr
= icon
->core
->screen_ptr
;
441 wIconChangeImage(icon
, NULL
);
445 path
= FindImage(wPreferences
.icon_path
, file
);
447 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
448 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
450 wIconChangeImage(icon
, image
);
464 getnameforicon(WWindow
*wwin
)
466 char *prefix
, *suffix
;
470 if (wwin
->wm_class
&& wwin
->wm_instance
) {
471 int len
= strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2;
472 suffix
= wmalloc(len
);
473 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
474 } else if (wwin
->wm_class
) {
475 int len
= strlen(wwin
->wm_class
)+1;
476 suffix
= wmalloc(len
);
477 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
478 } else if (wwin
->wm_instance
) {
479 int len
= strlen(wwin
->wm_instance
)+1;
480 suffix
= wmalloc(len
);
481 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
486 prefix
= wusergnusteppath();
487 len
= strlen(prefix
)+64+strlen(suffix
);
488 path
= wmalloc(len
+1);
489 snprintf(path
, len
, "%s/.AppInfo", prefix
);
491 if (access(path
, F_OK
)!=0) {
492 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
493 wsyserror(_("could not create directory %s"), path
);
499 strcat(path
, "/WindowMaker");
500 if (access(path
, F_OK
)!=0) {
501 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
502 wsyserror(_("could not create directory %s"), path
);
510 strcat(path
, suffix
);
511 strcat(path
, ".xpm");
520 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
521 * and returns the path for that icon. Returns NULL if there is no
522 * client supplied icon or on failure.
525 * New directories might be created.
528 wIconStore(WIcon
*icon
)
532 WWindow
*wwin
= icon
->owner
;
534 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
535 || wwin
->wm_hints
->icon_pixmap
== None
)
538 path
= getnameforicon(wwin
);
542 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
543 wwin
->wm_hints
->icon_pixmap
,
544 (wwin
->wm_hints
->flags
& IconMaskHint
)
545 ? wwin
->wm_hints
->icon_mask
: None
);
551 if (!RSaveImage(image
, path
, "XPM")) {
555 RReleaseImage(image
);
563 wIconChangeIconWindow(WIcon *icon, Window new_window);
567 cycleColor(void *data
)
569 WIcon
*icon
= (WIcon
*)data
;
570 WScreen
*scr
= icon
->core
->screen_ptr
;
574 gcv
.dash_offset
= icon
->step
;
575 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
577 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
578 icon
->core
->width
-1, icon
->core
->height
-1);
579 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
584 wIconSetHighlited(WIcon
*icon
, Bool flag
)
586 if (icon
->highlighted
== flag
) {
590 icon
->highlighted
= flag
;
597 wIconSelect(WIcon
*icon
)
599 WScreen
*scr
= icon
->core
->screen_ptr
;
600 icon
->selected
= !icon
->selected
;
602 if (icon
->selected
) {
604 if (!wPreferences
.dont_blink
)
605 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
607 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
608 icon
->core
->width
-1, icon
->core
->height
-1);
610 if (icon
->handlerID
) {
611 WMDeleteTimerHandler(icon
->handlerID
);
612 icon
->handlerID
= NULL
;
614 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
615 icon
->core
->height
, True
);
621 wIconUpdate(WIcon
*icon
)
623 WScreen
*scr
= icon
->core
->screen_ptr
;
624 int title_height
= WMFontHeight(scr
->icon_title_font
);
625 WWindow
*wwin
= icon
->owner
;
627 assert(scr
->icon_tile
!=NULL
);
629 if (icon
->pixmap
!=None
)
630 XFreePixmap(dpy
, icon
->pixmap
);
634 if (wwin
&& WFLAGP(wwin
, always_user_icon
))
637 /* use client specified icon window */
638 if (icon
->icon_win
!=None
) {
639 XWindowAttributes attr
;
641 int width
, height
, depth
;
645 getSize(icon
->icon_win
, &width
, &height
, &depth
);
647 if (width
> wPreferences
.icon_size
) {
649 width
= wPreferences
.icon_size
;
651 if (height
> wPreferences
.icon_size
) {
653 height
= wPreferences
.icon_size
;
656 && (height
+title_height
< wPreferences
.icon_size
)) {
657 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
658 wPreferences
.icon_size
, scr
->w_depth
);
659 XSetClipMask(dpy
, scr
->copy_gc
, None
);
660 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
661 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
662 drawIconTitle(scr
, pixmap
, title_height
);
663 theight
= title_height
;
667 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
668 scr
->icon_tile_pixmap
);
671 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
672 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
673 (wPreferences
.icon_size
-width
)/2,
674 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
676 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
678 XMapWindow(dpy
, icon
->icon_win
);
680 XAddToSaveSet(dpy
, icon
->icon_win
);
682 icon
->pixmap
= pixmap
;
684 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
685 if (attr
.all_event_masks
& ButtonPressMask
) {
686 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
687 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
688 None
, wCursor
[WCUR_ARROW
]);
691 } else if (wwin
&& wwin
->wm_hints
692 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
700 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
701 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
702 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
706 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
707 wPreferences
.icon_size
, scr
->w_depth
);
708 XSetClipMask(dpy
, scr
->copy_gc
, None
);
709 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
710 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
712 if (w
> wPreferences
.icon_size
)
713 w
= wPreferences
.icon_size
;
714 x
= (wPreferences
.icon_size
-w
)/2;
716 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
717 drawIconTitle(scr
, pixmap
, title_height
);
720 if (h
> wPreferences
.icon_size
- title_height
- 2) {
721 h
= wPreferences
.icon_size
- title_height
- 2;
722 y
= title_height
+ 1;
724 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
728 if (w
> wPreferences
.icon_size
)
729 w
= wPreferences
.icon_size
;
730 y
= (wPreferences
.icon_size
-h
)/2;
733 if (wwin
->wm_hints
->flags
& IconMaskHint
)
734 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
736 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
738 if (d
!= scr
->w_depth
) {
739 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
740 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
741 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
742 0, 0, w
, h
, x
, y
, 1);
744 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
748 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
750 icon
->pixmap
= pixmap
;
755 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
756 icon
->shadowed
, icon
->tile_type
);
758 /* make default icons */
760 if (!scr
->def_icon_pixmap
) {
761 RImage
*image
= NULL
;
765 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
767 path
= FindImage(wPreferences
.icon_path
, file
);
769 wwarning(_("could not find default icon \"%s\""),file
);
773 image
= RLoadImage(scr
->rcontext
, path
, 0);
775 wwarning(_("could not load default icon \"%s\":%s"),
776 file
, RMessageForError(RErrorCode
));
782 image
= wIconValidateIconSize(scr
, image
);
783 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
785 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
788 RReleaseImage(image
);
791 if (icon
->show_title
) {
792 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
793 scr
->def_ticon_pixmap
);
795 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
796 scr
->def_icon_pixmap
);
801 if (icon
->pixmap
!= None
) {
802 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
804 XClearWindow(dpy
, icon
->core
->window
);
812 wIconPaint(WIcon
*icon
)
814 WScreen
*scr
=icon
->core
->screen_ptr
;
818 if (icon
->force_paint
) {
819 icon
->force_paint
= 0;
824 XClearWindow(dpy
, icon
->core
->window
);
826 /* draw the icon title */
827 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
831 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
832 wPreferences
.icon_size
-4);
833 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
=strlen(tmp
));
835 if (w
> icon
->core
->width
- 4)
836 x
= (icon
->core
->width
- 4) - w
;
838 x
= (icon
->core
->width
- w
)/2;
840 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
841 scr
->icon_title_font
, x
, 1, tmp
, l
);
846 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
847 icon
->core
->width
-1, icon
->core
->height
-1);
851 /******************************************************************/
854 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
856 wIconPaint(desc
->parent
);
861 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
863 WIcon
*icon
= desc
->parent
;
865 assert(icon
->owner
!=NULL
);
867 wDeiconifyWindow(icon
->owner
);
872 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
874 WIcon
*icon
= desc
->parent
;
875 WWindow
*wwin
= icon
->owner
;
877 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
878 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
880 int clickButton
=event
->xbutton
.button
;
882 if (WCHECK_STATE(WSTATE_MODAL
))
885 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
886 miniwindowDblClick(desc
, event
);
891 puts("Moving miniwindow");
893 if (event
->xbutton
.button
== Button1
) {
894 if (event
->xbutton
.state
& MOD_MASK
)
895 wLowerFrame(icon
->core
);
897 wRaiseFrame(icon
->core
);
898 if (event
->xbutton
.state
& ShiftMask
) {
900 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
902 } else if (event
->xbutton
.button
== Button3
) {
903 WObjDescriptor
*desc
;
905 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
906 event
->xbutton
.y_root
);
908 /* allow drag select of menu */
909 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
910 event
->xbutton
.send_event
= True
;
911 (*desc
->handle_mousedown
)(desc
, event
);
916 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
917 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
918 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
920 wwarning("pointer grab failed for icon move");
924 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
925 |ButtonMotionMask
|ExposureMask
, &ev
);
933 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
934 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
935 XChangeActivePointerGrab(dpy
, ButtonMotionMask
936 |ButtonReleaseMask
|ButtonPressMask
,
937 wCursor
[WCUR_MOVE
], CurrentTime
);
943 x
= ev
.xmotion
.x_root
- dx
;
944 y
= ev
.xmotion
.y_root
- dy
;
945 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
952 if (ev
.xbutton
.button
!= clickButton
)
955 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
956 wwin
->flags
.icon_moved
= 1;
958 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
963 puts("End miniwindow move");
965 XUngrabPointer(dpy
, CurrentTime
);
967 if (wPreferences
.auto_arrange_icons
)
968 wArrangeIcons(wwin
->screen_ptr
, True
);