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"
48 /**** Global varianebles ****/
49 extern WPreferences wPreferences
;
51 #define MOD_MASK wPreferences.modifier_mask
53 extern Cursor wCursor
[WCUR_LAST
];
56 static void miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
);
57 static void miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
58 static void miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
);
61 /****** Notification Observers ******/
64 appearanceObserver(void *self
, WMNotification
*notif
)
66 WIcon
*icon
= (WIcon
*)self
;
67 int flags
= (int)WMGetNotificationClientData(notif
);
69 if (flags
& WTextureSettings
) {
70 icon
->force_paint
= 1;
72 if (flags
& WFontSettings
) {
73 icon
->force_paint
= 1;
76 if (flags & WColorSettings) {
82 /* so that the appicon expose handlers will paint the appicon specific
84 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
85 icon
->core
->height
, True
);
90 tileObserver(void *self
, WMNotification
*notif
)
92 WIcon
*icon
= (WIcon
*)self
;
94 icon
->force_paint
= 1;
97 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
100 /************************************/
105 getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
111 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
116 wIconCreate(WWindow
*wwin
)
118 WScreen
*scr
=wwin
->screen_ptr
;
121 unsigned long vmask
= 0;
122 XSetWindowAttributes attribs
;
124 icon
= wmalloc(sizeof(WIcon
));
125 memset(icon
, 0, sizeof(WIcon
));
126 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
127 wPreferences
.icon_size
,
128 wPreferences
.icon_size
, 0);
130 if (wPreferences
.use_saveunders
) {
131 vmask
|= CWSaveUnder
;
132 attribs
.save_under
= True
;
134 /* a white border for selecting it */
135 vmask
|= CWBorderPixel
;
136 attribs
.border_pixel
= scr
->white_pixel
;
138 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
141 /* will be overriden if this is an application icon */
142 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
143 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
144 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
145 icon
->core
->descriptor
.parent
= icon
;
147 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
148 icon
->core
->stacking
->above
= NULL
;
149 icon
->core
->stacking
->under
= NULL
;
150 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
151 icon
->core
->stacking
->child_of
= NULL
;
154 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
155 if (wwin
->client_win
== wwin
->main_window
) {
157 /* do not let miniwindow steal app-icon's icon window */
158 wapp
= wApplicationOf(wwin
->client_win
);
159 if (!wapp
|| wapp
->app_icon
==NULL
)
160 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
162 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
165 #ifdef NO_MINIWINDOW_TITLES
166 icon
->show_title
= 0;
168 icon
->show_title
= 1;
171 if (!icon
->image
&& !WFLAGP(wwin
, always_user_icon
))
172 icon
->image
= RRetainImage(wwin
->net_icon_image
);
175 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
177 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
,
180 icon
->file
= wstrdup(file
);
183 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
185 wwin
->flags
.net_has_icon_title
= 1;
187 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
189 icon
->tile_type
= TILE_NORMAL
;
195 WMAddNotificationObserver(appearanceObserver
, icon
,
196 WNIconAppearanceSettingsChanged
, icon
);
197 WMAddNotificationObserver(tileObserver
, icon
,
198 WNIconTileSettingsChanged
, icon
);
204 wIconCreateWithIconFile(WScreen
*scr
, char *iconfile
, int tile
)
207 unsigned long vmask
= 0;
208 XSetWindowAttributes attribs
;
210 icon
= wmalloc(sizeof(WIcon
));
211 memset(icon
, 0, sizeof(WIcon
));
212 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
,
213 wPreferences
.icon_size
, 0);
214 if (wPreferences
.use_saveunders
) {
216 attribs
.save_under
= True
;
218 /* a white border for selecting it */
219 vmask
|= CWBorderPixel
;
220 attribs
.border_pixel
= scr
->white_pixel
;
222 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
224 /* will be overriden if this is a application icon */
225 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
226 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
227 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
228 icon
->core
->descriptor
.parent
= icon
;
230 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
231 icon
->core
->stacking
->above
= NULL
;
232 icon
->core
->stacking
->under
= NULL
;
233 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
234 icon
->core
->stacking
->child_of
= NULL
;
237 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
239 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
242 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
244 icon
->file
= wstrdup(iconfile
);
247 icon
->tile_type
= tile
;
251 WMAddNotificationObserver(appearanceObserver
, icon
,
252 WNIconAppearanceSettingsChanged
, icon
);
253 WMAddNotificationObserver(tileObserver
, icon
,
254 WNIconTileSettingsChanged
, icon
);
262 wIconDestroy(WIcon
*icon
)
264 WCoreWindow
*core
= icon
->core
;
265 WScreen
*scr
= core
->screen_ptr
;
267 WMRemoveNotificationObserver(icon
);
270 WMDeleteTimerHandler(icon
->handlerID
);
272 if (icon
->icon_win
) {
276 x
= icon
->owner
->icon_x
;
277 y
= icon
->owner
->icon_y
;
279 XUnmapWindow(dpy
, icon
->icon_win
);
280 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
283 XFree(icon
->icon_name
);
286 XFreePixmap(dpy
, icon
->pixmap
);
291 if (icon
->image
!=NULL
)
292 RReleaseImage(icon
->image
);
294 wCoreDestroy(icon
->core
);
301 drawIconTitle(WScreen
*scr
, Pixmap pixmap
, int height
)
303 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
,
304 0, 0, wPreferences
.icon_size
, height
+1);
305 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
306 wPreferences
.icon_size
, 0);
307 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0,
309 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
310 wPreferences
.icon_size
-1, 0, wPreferences
.icon_size
-1, height
+1);
315 makeIcon(WScreen
*scr
, RImage
*icon
, int titled
, int shadowed
, int tileType
)
321 int theight
= WMFontHeight(scr
->icon_title_font
);
323 if (tileType
== TILE_NORMAL
)
324 tile
= RCloneImage(scr
->icon_tile
);
326 assert(scr
->clip_tile
);
327 tile
= RCloneImage(scr
->clip_tile
);
330 w
= (icon
->width
> wPreferences
.icon_size
)
331 ? wPreferences
.icon_size
: icon
->width
;
332 x
= (wPreferences
.icon_size
- w
) / 2;
333 sx
= (icon
->width
- w
)/2;
336 h
= (icon
->height
> wPreferences
.icon_size
)
337 ? wPreferences
.icon_size
: icon
->height
;
338 y
= (wPreferences
.icon_size
- h
) / 2;
339 sy
= (icon
->height
- h
)/2;
341 h
= (icon
->height
+theight
> wPreferences
.icon_size
342 ? wPreferences
.icon_size
-theight
: icon
->height
);
343 y
= theight
+((int)wPreferences
.icon_size
-theight
-h
)/2;
344 sy
= (icon
->height
- h
)/2;
346 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
352 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
353 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
354 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
355 color
.alpha
= 150; /* about 60% */
356 RClearImage(tile
, &color
);
359 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
360 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
365 drawIconTitle(scr
, pixmap
, theight
);
372 wIconChangeTitle(WIcon
*icon
, char *new_title
)
376 changed
= (new_title
==NULL
&& icon
->icon_name
!=NULL
)
377 || (new_title
!=NULL
&& icon
->icon_name
==NULL
);
379 if (icon
->icon_name
!=NULL
)
380 XFree(icon
->icon_name
);
382 icon
->icon_name
= new_title
;
385 icon
->force_paint
= 1;
391 wIconChangeImage(WIcon
*icon
, RImage
*new_image
)
393 assert(icon
!= NULL
);
396 RReleaseImage(icon
->image
);
398 icon
->image
= new_image
;
405 wIconValidateIconSize(WScreen
*scr
, RImage
*icon
)
412 #ifndef DONT_SCALE_ICONS
413 if (wPreferences
.icon_size
!= 64) {
414 w
= wPreferences
.icon_size
* icon
->width
/ 64;
415 h
= wPreferences
.icon_size
* icon
->height
/ 64;
417 tmp
= RScaleImage(icon
, w
, h
);
423 if (icon
->width
> wPreferences
.icon_size
424 || icon
->height
> wPreferences
.icon_size
) {
425 if (icon
->width
> icon
->height
) {
426 w
= wPreferences
.icon_size
- 4;
427 h
= w
*icon
->height
/icon
->width
;
429 h
= wPreferences
.icon_size
- 4;
430 w
= h
*icon
->width
/icon
->height
;
432 tmp
= RScaleImage(icon
, w
, h
);
443 wIconChangeImageFile(WIcon
*icon
, char *file
)
445 WScreen
*scr
= icon
->core
->screen_ptr
;
451 wIconChangeImage(icon
, NULL
);
455 path
= FindImage(wPreferences
.icon_path
, file
);
457 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
458 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
460 wIconChangeImage(icon
, image
);
474 getnameforicon(WWindow
*wwin
)
476 char *prefix
, *suffix
;
480 if (wwin
->wm_class
&& wwin
->wm_instance
) {
481 int len
= strlen(wwin
->wm_class
)+strlen(wwin
->wm_instance
)+2;
482 suffix
= wmalloc(len
);
483 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
484 } else if (wwin
->wm_class
) {
485 int len
= strlen(wwin
->wm_class
)+1;
486 suffix
= wmalloc(len
);
487 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
488 } else if (wwin
->wm_instance
) {
489 int len
= strlen(wwin
->wm_instance
)+1;
490 suffix
= wmalloc(len
);
491 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
496 prefix
= wusergnusteppath();
497 len
= strlen(prefix
)+64+strlen(suffix
);
498 path
= wmalloc(len
+1);
499 snprintf(path
, len
, "%s/.AppInfo", prefix
);
501 if (access(path
, F_OK
)!=0) {
502 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)) {
503 wsyserror(_("could not create directory %s"), path
);
509 strcat(path
, "/WindowMaker");
510 if (access(path
, F_OK
)!=0) {
511 if (mkdir(path
, S_IRUSR
|S_IWUSR
|S_IXUSR
)!=0) {
512 wsyserror(_("could not create directory %s"), path
);
520 strcat(path
, suffix
);
521 strcat(path
, ".xpm");
530 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
531 * and returns the path for that icon. Returns NULL if there is no
532 * client supplied icon or on failure.
535 * New directories might be created.
538 wIconStore(WIcon
*icon
)
542 WWindow
*wwin
= icon
->owner
;
544 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
545 || wwin
->wm_hints
->icon_pixmap
== None
)
548 path
= getnameforicon(wwin
);
552 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
553 wwin
->wm_hints
->icon_pixmap
,
554 (wwin
->wm_hints
->flags
& IconMaskHint
)
555 ? wwin
->wm_hints
->icon_mask
: None
);
561 if (!RSaveImage(image
, path
, "XPM")) {
565 RReleaseImage(image
);
572 void wIconChangeIconWindow(WIcon *icon, Window new_window);
576 cycleColor(void *data
)
578 WIcon
*icon
= (WIcon
*)data
;
579 WScreen
*scr
= icon
->core
->screen_ptr
;
583 gcv
.dash_offset
= icon
->step
;
584 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
586 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
587 icon
->core
->width
-1, icon
->core
->height
-1);
588 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
593 wIconSetHighlited(WIcon
*icon
, Bool flag
)
595 if (icon
->highlighted
== flag
) {
599 icon
->highlighted
= flag
;
606 wIconSelect(WIcon
*icon
)
608 WScreen
*scr
= icon
->core
->screen_ptr
;
609 icon
->selected
= !icon
->selected
;
611 if (icon
->selected
) {
613 if (!wPreferences
.dont_blink
)
614 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
616 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
617 icon
->core
->width
-1, icon
->core
->height
-1);
619 if (icon
->handlerID
) {
620 WMDeleteTimerHandler(icon
->handlerID
);
621 icon
->handlerID
= NULL
;
623 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
,
624 icon
->core
->height
, True
);
630 wIconUpdate(WIcon
*icon
)
632 WScreen
*scr
= icon
->core
->screen_ptr
;
633 int title_height
= WMFontHeight(scr
->icon_title_font
);
634 WWindow
*wwin
= icon
->owner
;
636 assert(scr
->icon_tile
!=NULL
);
638 if (icon
->pixmap
!=None
)
639 XFreePixmap(dpy
, icon
->pixmap
);
643 if (wwin
&& (WFLAGP(wwin
, always_user_icon
)
645 || wwin
->net_icon_image
650 /* use client specified icon window */
651 if (icon
->icon_win
!=None
) {
652 XWindowAttributes attr
;
654 int width
, height
, depth
;
658 getSize(icon
->icon_win
, &width
, &height
, &depth
);
660 if (width
> wPreferences
.icon_size
) {
662 width
= wPreferences
.icon_size
;
664 if (height
> wPreferences
.icon_size
) {
666 height
= wPreferences
.icon_size
;
669 && (height
+title_height
< wPreferences
.icon_size
)) {
670 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
671 wPreferences
.icon_size
, scr
->w_depth
);
672 XSetClipMask(dpy
, scr
->copy_gc
, None
);
673 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
674 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
675 drawIconTitle(scr
, pixmap
, title_height
);
676 theight
= title_height
;
680 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
681 scr
->icon_tile_pixmap
);
684 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
685 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
686 (wPreferences
.icon_size
-width
)/2,
687 theight
+(wPreferences
.icon_size
-height
-theight
)/2);
689 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
691 XMapWindow(dpy
, icon
->icon_win
);
693 XAddToSaveSet(dpy
, icon
->icon_win
);
695 icon
->pixmap
= pixmap
;
697 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
698 if (attr
.all_event_masks
& ButtonPressMask
) {
699 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
700 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
701 None
, wCursor
[WCUR_ARROW
]);
704 } else if (wwin
&& wwin
->wm_hints
705 && (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
713 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
,
714 &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
715 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
719 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
720 wPreferences
.icon_size
, scr
->w_depth
);
721 XSetClipMask(dpy
, scr
->copy_gc
, None
);
722 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
723 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
725 if (w
> wPreferences
.icon_size
)
726 w
= wPreferences
.icon_size
;
727 x
= (wPreferences
.icon_size
-w
)/2;
729 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
730 drawIconTitle(scr
, pixmap
, title_height
);
733 if (h
> wPreferences
.icon_size
- title_height
- 2) {
734 h
= wPreferences
.icon_size
- title_height
- 2;
735 y
= title_height
+ 1;
737 y
= (wPreferences
.icon_size
-h
-title_height
)/2+title_height
+ 1;
741 if (w
> wPreferences
.icon_size
)
742 w
= wPreferences
.icon_size
;
743 y
= (wPreferences
.icon_size
-h
)/2;
746 if (wwin
->wm_hints
->flags
& IconMaskHint
)
747 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
749 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
751 if (d
!= scr
->w_depth
) {
752 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
753 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
754 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
755 0, 0, w
, h
, x
, y
, 1);
757 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
,
761 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
763 icon
->pixmap
= pixmap
;
768 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
769 icon
->shadowed
, icon
->tile_type
);
771 /* make default icons */
773 if (!scr
->def_icon_pixmap
) {
774 RImage
*image
= NULL
;
778 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
780 path
= FindImage(wPreferences
.icon_path
, file
);
782 wwarning(_("could not find default icon \"%s\""),file
);
786 image
= RLoadImage(scr
->rcontext
, path
, 0);
788 wwarning(_("could not load default icon \"%s\":%s"),
789 file
, RMessageForError(RErrorCode
));
795 image
= wIconValidateIconSize(scr
, image
);
796 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
,
798 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
,
801 RReleaseImage(image
);
804 if (icon
->show_title
) {
805 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
806 scr
->def_ticon_pixmap
);
808 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
,
809 scr
->def_icon_pixmap
);
814 if (icon
->pixmap
!= None
) {
815 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
817 XClearWindow(dpy
, icon
->core
->window
);
825 wIconPaint(WIcon
*icon
)
827 WScreen
*scr
=icon
->core
->screen_ptr
;
831 if (icon
->force_paint
) {
832 icon
->force_paint
= 0;
837 XClearWindow(dpy
, icon
->core
->window
);
839 /* draw the icon title */
840 if (icon
->show_title
&& icon
->icon_name
!=NULL
) {
844 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
,
845 wPreferences
.icon_size
-4);
846 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
=strlen(tmp
));
848 if (w
> icon
->core
->width
- 4)
849 x
= (icon
->core
->width
- 4) - w
;
851 x
= (icon
->core
->width
- w
)/2;
853 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
854 scr
->icon_title_font
, x
, 1, tmp
, l
);
859 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
860 icon
->core
->width
-1, icon
->core
->height
-1);
864 /******************************************************************/
867 miniwindowExpose(WObjDescriptor
*desc
, XEvent
*event
)
869 wIconPaint(desc
->parent
);
874 miniwindowDblClick(WObjDescriptor
*desc
, XEvent
*event
)
876 WIcon
*icon
= desc
->parent
;
878 assert(icon
->owner
!=NULL
);
880 wDeiconifyWindow(icon
->owner
);
885 miniwindowMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
887 WIcon
*icon
= desc
->parent
;
888 WWindow
*wwin
= icon
->owner
;
890 int x
=wwin
->icon_x
, y
=wwin
->icon_y
;
891 int dx
=event
->xbutton
.x
, dy
=event
->xbutton
.y
;
893 int clickButton
=event
->xbutton
.button
;
895 if (WCHECK_STATE(WSTATE_MODAL
))
898 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
899 miniwindowDblClick(desc
, event
);
904 puts("Moving miniwindow");
906 if (event
->xbutton
.button
== Button1
) {
907 if (event
->xbutton
.state
& MOD_MASK
)
908 wLowerFrame(icon
->core
);
910 wRaiseFrame(icon
->core
);
911 if (event
->xbutton
.state
& ShiftMask
) {
913 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
915 } else if (event
->xbutton
.button
== Button3
) {
916 WObjDescriptor
*desc
;
918 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
,
919 event
->xbutton
.y_root
);
921 /* allow drag select of menu */
922 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
923 event
->xbutton
.send_event
= True
;
924 (*desc
->handle_mousedown
)(desc
, event
);
929 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
930 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
931 GrabModeAsync
, None
, None
, CurrentTime
) !=GrabSuccess
) {
933 wwarning("pointer grab failed for icon move");
937 WMMaskEvent(dpy
, PointerMotionMask
|ButtonReleaseMask
|ButtonPressMask
938 |ButtonMotionMask
|ExposureMask
, &ev
);
946 if (abs(dx
-ev
.xmotion
.x
)>=MOVE_THRESHOLD
947 || abs(dy
-ev
.xmotion
.y
)>=MOVE_THRESHOLD
) {
948 XChangeActivePointerGrab(dpy
, ButtonMotionMask
949 |ButtonReleaseMask
|ButtonPressMask
,
950 wCursor
[WCUR_MOVE
], CurrentTime
);
956 x
= ev
.xmotion
.x_root
- dx
;
957 y
= ev
.xmotion
.y_root
- dy
;
958 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
965 if (ev
.xbutton
.button
!= clickButton
)
968 if (wwin
->icon_x
!=x
|| wwin
->icon_y
!=y
)
969 wwin
->flags
.icon_moved
= 1;
971 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
976 puts("End miniwindow move");
978 XUngrabPointer(dpy
, CurrentTime
);
980 if (wPreferences
.auto_arrange_icons
)
981 wArrangeIcons(wwin
->screen_ptr
, True
);