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, 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 RDestroyImage(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 RDestroyImage(icon
->image
);
388 icon
->image
= wIconValidateIconSize(icon
->core
->screen_ptr
, 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 wIconChangeImage(icon
, image
);
462 getnameforicon(WWindow
*wwin
)
464 char *prefix
, *suffix
;
468 if (wwin
->wm_class
&& wwin
->wm_instance
) {
469 suffix
= wmalloc(strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2);
470 sprintf(suffix
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
471 } else if (wwin
->wm_class
) {
472 suffix
= wmalloc(strlen(wwin
->wm_class
)+1);
473 strcpy(suffix
, wwin
->wm_class
);
474 } else if (wwin
->wm_instance
) {
475 suffix
= wmalloc(strlen(wwin
->wm_instance
)+1);
476 strcpy(suffix
, wwin
->wm_instance
);
481 prefix
= wusergnusteppath();
482 len
= strlen(prefix
)+64+strlen(suffix
);
483 path
= wmalloc(len
+1);
484 sprintf(path
, "%s/.AppInfo", prefix
);
486 if (access(path
, F_OK
)!=0) {
487 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
488 wsyserror(_("could not create directory %s"), path
);
494 strcat(path
, "/WindowMaker");
495 if (access(path
, F_OK
)!=0) {
496 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
497 wsyserror(_("could not create directory %s"), path
);
505 strcat(path
, suffix
);
506 strcat(path
, ".xpm");
515 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
516 * and returns the path for that icon. Returns NULL if there is no
517 * client supplied icon or on failure.
520 * New directories might be created.
523 wIconStore(WIcon
*icon
)
527 WWindow
*wwin
= icon
->owner
;
529 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
530 || wwin
->wm_hints
->icon_pixmap
== None
)
533 path
= getnameforicon(wwin
);
537 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
538 wwin
->wm_hints
->icon_pixmap
,
539 (wwin
->wm_hints
->flags
& IconMaskHint
)
540 ? wwin
->wm_hints
->icon_mask
: None
);
546 if (!RSaveImage(image
, path
, "XPM")) {
550 RDestroyImage(image
);
558 wIconChangeIconWindow(WIcon *icon, Window new_window);
562 cycleColor(void *data
)
564 WIcon
*icon
= (WIcon
*)data
;
565 WScreen
*scr
= icon
->core
->screen_ptr
;
569 gcv
.dash_offset
= icon
->step
;
570 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
572 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
573 icon
->core
->width
-1, icon
->core
->height
-1);
574 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
579 wIconSetHighlited(WIcon
*icon
, Bool flag
)
581 if (icon
->highlighted
== flag
) {
585 icon
->highlighted
= flag
;
592 wIconSelect(WIcon
*icon
)
594 WScreen
*scr
= icon
->core
->screen_ptr
;
595 icon
->selected
= !icon
->selected
;
597 if (icon
->selected
) {
599 if (!wPreferences
.dont_blink
)
600 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
602 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
603 icon
->core
->width
-1, icon
->core
->height
-1);
605 if (icon
->handlerID
) {
606 WMDeleteTimerHandler(icon
->handlerID
);
607 icon
->handlerID
= NULL
;
609 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
610 icon
->core
->height
, True
);
616 wIconUpdate(WIcon
*icon
)
618 WScreen
*scr
= icon
->core
->screen_ptr
;
619 int title_height
= WMFontHeight(scr
->icon_title_font
);
620 WWindow
*wwin
= icon
->owner
;
622 assert(scr
->icon_tile
!=NULL
);
624 if (icon
->pixmap
!=None
)
625 XFreePixmap(dpy
, icon
->pixmap
);
629 if (wwin
&& WFLAGP(wwin
, always_user_icon
))
632 /* use client specified icon window */
633 if (icon
->icon_win
!=None
) {
634 XWindowAttributes attr
;
636 int width
, height
, depth
;
640 getSize(icon
->icon_win
, &width
, &height
, &depth
);
642 if (width
> wPreferences
.icon_size
) {
644 width
= wPreferences
.icon_size
;
646 if (height
> wPreferences
.icon_size
) {
648 height
= wPreferences
.icon_size
;
651 && (height
+title_height
< wPreferences
.icon_size
)) {
652 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
653 wPreferences
.icon_size
, scr
->w_depth
);
654 XSetClipMask(dpy
, scr
->copy_gc
, None
);
655 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
656 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
657 drawIconTitle(scr
, pixmap
, title_height
);
658 theight
= title_height
;
662 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
663 scr
->icon_tile_pixmap
);
666 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
667 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
668 (wPreferences
.icon_size
-width
)/2,
669 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
671 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
673 XMapWindow(dpy
, icon
->icon_win
);
675 XAddToSaveSet(dpy
, icon
->icon_win
);
677 icon
->pixmap
= pixmap
;
679 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
680 if (attr
.all_event_masks
& ButtonPressMask
) {
681 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
682 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
683 None
, wCursor
[WCUR_ARROW
]);
686 } else if (wwin
&& wwin
->wm_hints
687 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
695 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
696 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
697 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
701 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
702 wPreferences
.icon_size
, scr
->w_depth
);
703 XSetClipMask(dpy
, scr
->copy_gc
, None
);
704 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
705 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
707 if (w
> wPreferences
.icon_size
)
708 w
= wPreferences
.icon_size
;
709 x
= (wPreferences
.icon_size
-w
)/2;
711 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
712 drawIconTitle(scr
, pixmap
, title_height
);
715 if (h
> wPreferences
.icon_size
- title_height
- 2) {
716 h
= wPreferences
.icon_size
- title_height
- 2;
717 y
= title_height
+ 1;
719 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
723 if (w
> wPreferences
.icon_size
)
724 w
= wPreferences
.icon_size
;
725 y
= (wPreferences
.icon_size
-h
)/2;
728 if (wwin
->wm_hints
->flags
& IconMaskHint
)
729 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
731 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
733 if (d
!= scr
->w_depth
) {
734 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
735 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
736 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
737 0, 0, w
, h
, x
, y
, 1);
739 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
743 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
745 icon
->pixmap
= pixmap
;
750 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
751 icon
->shadowed
, icon
->tile_type
);
753 /* make default icons */
755 if (!scr
->def_icon_pixmap
) {
756 RImage
*image
= NULL
;
760 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
762 path
= FindImage(wPreferences
.icon_path
, file
);
764 wwarning(_("could not find default icon \"%s\""),file
);
768 image
= RLoadImage(scr
->rcontext
, path
, 0);
770 wwarning(_("could not load default icon \"%s\":%s"),
771 file
, RMessageForError(RErrorCode
));
777 image
= wIconValidateIconSize(scr
, image
);
778 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
780 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
783 RDestroyImage(image
);
786 if (icon
->show_title
) {
787 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
788 scr
->def_ticon_pixmap
);
790 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
791 scr
->def_icon_pixmap
);
796 if (icon
->pixmap
!= None
) {
797 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
799 XClearWindow(dpy
, icon
->core
->window
);
807 wIconPaint(WIcon
*icon
)
809 WScreen
*scr
=icon
->core
->screen_ptr
;
810 GC gc
= scr
->icon_title_gc
;
814 if (icon
->force_paint
) {
815 icon
->force_paint
= 0;
820 XClearWindow(dpy
, icon
->core
->window
);
822 /* draw the icon title */
823 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
827 #ifdef DRAWSTRING_PLUGIN
828 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
829 wPreferences
.icon_size
-4, NULL
);
831 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
832 wPreferences
.icon_size
-4);
834 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
=strlen(tmp
));
836 if (w
> icon
->core
->width
- 4)
837 x
= (icon
->core
->width
- 4) - w
;
839 x
= (icon
->core
->width
- w
)/2;
841 WMDrawString(scr
->wmscreen
, icon
->core
->window
, gc
,
842 scr
->icon_title_font
, x
, 1, tmp
, l
);
847 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
848 icon
->core
->width
-1, icon
->core
->height
-1);
852 /******************************************************************/
855 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
857 wIconPaint(desc
->parent
);
862 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
864 WIcon
*icon
= desc
->parent
;
866 assert(icon
->owner
!=NULL
);
868 wDeiconifyWindow(icon
->owner
);
873 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
875 WIcon
*icon
= desc
->parent
;
876 WWindow
*wwin
= icon
->owner
;
878 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
879 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
881 int clickButton
=event
->xbutton
.button
;
883 if (WCHECK_STATE(WSTATE_MODAL
))
886 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
887 miniwindowDblClick(desc
, event
);
892 puts("Moving miniwindow");
894 if (event
->xbutton
.button
== Button1
) {
895 if (event
->xbutton
.state
& MOD_MASK
)
896 wLowerFrame(icon
->core
);
898 wRaiseFrame(icon
->core
);
899 if (event
->xbutton
.state
& ShiftMask
) {
901 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
903 } else if (event
->xbutton
.button
== Button3
) {
904 WObjDescriptor
*desc
;
906 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
907 event
->xbutton
.y_root
);
909 /* allow drag select of menu */
910 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
911 event
->xbutton
.send_event
= True
;
912 (*desc
->handle_mousedown
)(desc
, event
);
917 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
918 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
919 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
921 wwarning("pointer grab failed for icon move");
925 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
926 |ButtonMotionMask
|ExposureMask
, &ev
);
934 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
935 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
936 XChangeActivePointerGrab(dpy
, ButtonMotionMask
937 |ButtonReleaseMask
|ButtonPressMask
,
938 wCursor
[WCUR_MOVE
], CurrentTime
);
944 x
= ev
.xmotion
.x_root
- dx
;
945 y
= ev
.xmotion
.y_root
- dy
;
946 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
953 if (ev
.xbutton
.button
!= clickButton
)
956 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
957 wwin
->flags
.icon_moved
= 1;
959 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
964 puts("End miniwindow move");
966 XUngrabPointer(dpy
, CurrentTime
);
968 if (wPreferences
.auto_arrange_icons
)
969 wArrangeIcons(wwin
->screen_ptr
, True
);