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
);
568 wIconChangeIconWindow(WIcon *icon, Window new_window);
572 cycleColor(void *data
)
574 WIcon
*icon
= (WIcon
*)data
;
575 WScreen
*scr
= icon
->core
->screen_ptr
;
579 gcv
.dash_offset
= icon
->step
;
580 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
582 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
583 icon
->core
->width
-1, icon
->core
->height
-1);
584 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
589 wIconSetHighlited(WIcon
*icon
, Bool flag
)
591 if (icon
->highlighted
== flag
) {
595 icon
->highlighted
= flag
;
602 wIconSelect(WIcon
*icon
)
604 WScreen
*scr
= icon
->core
->screen_ptr
;
605 icon
->selected
= !icon
->selected
;
607 if (icon
->selected
) {
609 if (!wPreferences
.dont_blink
)
610 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
612 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
613 icon
->core
->width
-1, icon
->core
->height
-1);
615 if (icon
->handlerID
) {
616 WMDeleteTimerHandler(icon
->handlerID
);
617 icon
->handlerID
= NULL
;
619 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
620 icon
->core
->height
, True
);
626 wIconUpdate(WIcon
*icon
)
628 WScreen
*scr
= icon
->core
->screen_ptr
;
629 int title_height
= WMFontHeight(scr
->icon_title_font
);
630 WWindow
*wwin
= icon
->owner
;
632 assert(scr
->icon_tile
!=NULL
);
634 if (icon
->pixmap
!=None
)
635 XFreePixmap(dpy
, icon
->pixmap
);
639 if (wwin
&& (WFLAGP(wwin
, always_user_icon
)
641 || wwin
->net_icon_image
646 /* use client specified icon window */
647 if (icon
->icon_win
!=None
) {
648 XWindowAttributes attr
;
650 int width
, height
, depth
;
654 getSize(icon
->icon_win
, &width
, &height
, &depth
);
656 if (width
> wPreferences
.icon_size
) {
658 width
= wPreferences
.icon_size
;
660 if (height
> wPreferences
.icon_size
) {
662 height
= wPreferences
.icon_size
;
665 && (height
+title_height
< wPreferences
.icon_size
)) {
666 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
667 wPreferences
.icon_size
, scr
->w_depth
);
668 XSetClipMask(dpy
, scr
->copy_gc
, None
);
669 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
670 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
671 drawIconTitle(scr
, pixmap
, title_height
);
672 theight
= title_height
;
676 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
677 scr
->icon_tile_pixmap
);
680 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
681 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
682 (wPreferences
.icon_size
-width
)/2,
683 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
685 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
687 XMapWindow(dpy
, icon
->icon_win
);
689 XAddToSaveSet(dpy
, icon
->icon_win
);
691 icon
->pixmap
= pixmap
;
693 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
694 if (attr
.all_event_masks
& ButtonPressMask
) {
695 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
696 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
697 None
, wCursor
[WCUR_ARROW
]);
700 } else if (wwin
&& wwin
->wm_hints
701 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
709 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
710 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
711 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
715 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
716 wPreferences
.icon_size
, scr
->w_depth
);
717 XSetClipMask(dpy
, scr
->copy_gc
, None
);
718 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
719 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
721 if (w
> wPreferences
.icon_size
)
722 w
= wPreferences
.icon_size
;
723 x
= (wPreferences
.icon_size
-w
)/2;
725 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
726 drawIconTitle(scr
, pixmap
, title_height
);
729 if (h
> wPreferences
.icon_size
- title_height
- 2) {
730 h
= wPreferences
.icon_size
- title_height
- 2;
731 y
= title_height
+ 1;
733 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
737 if (w
> wPreferences
.icon_size
)
738 w
= wPreferences
.icon_size
;
739 y
= (wPreferences
.icon_size
-h
)/2;
742 if (wwin
->wm_hints
->flags
& IconMaskHint
)
743 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
745 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
747 if (d
!= scr
->w_depth
) {
748 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
749 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
750 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
751 0, 0, w
, h
, x
, y
, 1);
753 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
757 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
759 icon
->pixmap
= pixmap
;
764 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
765 icon
->shadowed
, icon
->tile_type
);
767 /* make default icons */
769 if (!scr
->def_icon_pixmap
) {
770 RImage
*image
= NULL
;
774 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
776 path
= FindImage(wPreferences
.icon_path
, file
);
778 wwarning(_("could not find default icon \"%s\""),file
);
782 image
= RLoadImage(scr
->rcontext
, path
, 0);
784 wwarning(_("could not load default icon \"%s\":%s"),
785 file
, RMessageForError(RErrorCode
));
791 image
= wIconValidateIconSize(scr
, image
);
792 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
794 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
797 RReleaseImage(image
);
800 if (icon
->show_title
) {
801 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
802 scr
->def_ticon_pixmap
);
804 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
805 scr
->def_icon_pixmap
);
810 if (icon
->pixmap
!= None
) {
811 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
813 XClearWindow(dpy
, icon
->core
->window
);
821 wIconPaint(WIcon
*icon
)
823 WScreen
*scr
=icon
->core
->screen_ptr
;
827 if (icon
->force_paint
) {
828 icon
->force_paint
= 0;
833 XClearWindow(dpy
, icon
->core
->window
);
835 /* draw the icon title */
836 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
840 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
841 wPreferences
.icon_size
-4);
842 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
=strlen(tmp
));
844 if (w
> icon
->core
->width
- 4)
845 x
= (icon
->core
->width
- 4) - w
;
847 x
= (icon
->core
->width
- w
)/2;
849 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
850 scr
->icon_title_font
, x
, 1, tmp
, l
);
855 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
856 icon
->core
->width
-1, icon
->core
->height
-1);
860 /******************************************************************/
863 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
865 wIconPaint(desc
->parent
);
870 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
872 WIcon
*icon
= desc
->parent
;
874 assert(icon
->owner
!=NULL
);
876 wDeiconifyWindow(icon
->owner
);
881 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
883 WIcon
*icon
= desc
->parent
;
884 WWindow
*wwin
= icon
->owner
;
886 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
887 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
889 int clickButton
=event
->xbutton
.button
;
891 if (WCHECK_STATE(WSTATE_MODAL
))
894 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
895 miniwindowDblClick(desc
, event
);
900 puts("Moving miniwindow");
902 if (event
->xbutton
.button
== Button1
) {
903 if (event
->xbutton
.state
& MOD_MASK
)
904 wLowerFrame(icon
->core
);
906 wRaiseFrame(icon
->core
);
907 if (event
->xbutton
.state
& ShiftMask
) {
909 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
911 } else if (event
->xbutton
.button
== Button3
) {
912 WObjDescriptor
*desc
;
914 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
915 event
->xbutton
.y_root
);
917 /* allow drag select of menu */
918 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
919 event
->xbutton
.send_event
= True
;
920 (*desc
->handle_mousedown
)(desc
, event
);
925 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
926 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
927 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
929 wwarning("pointer grab failed for icon move");
933 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
934 |ButtonMotionMask
|ExposureMask
, &ev
);
942 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
943 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
944 XChangeActivePointerGrab(dpy
, ButtonMotionMask
945 |ButtonReleaseMask
|ButtonPressMask
,
946 wCursor
[WCUR_MOVE
], CurrentTime
);
952 x
= ev
.xmotion
.x_root
- dx
;
953 y
= ev
.xmotion
.y_root
- dy
;
954 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
961 if (ev
.xbutton
.button
!= clickButton
)
964 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
965 wwin
->flags
.icon_moved
= 1;
967 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
972 puts("End miniwindow move");
974 XUngrabPointer(dpy
, CurrentTime
);
976 if (wPreferences
.auto_arrange_icons
)
977 wArrangeIcons(wwin
->screen_ptr
, True
);