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>
36 #include "WindowMaker.h"
44 #include "application.h"
49 /**** Global varianebles ****/
50 extern WPreferences wPreferences
;
52 #define MOD_MASK wPreferences.modifier_mask
54 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
);
60 /****** Notification Observers ******/
62 static void appearanceObserver(void *self
, WMNotification
* notif
)
64 WIcon
*icon
= (WIcon
*) self
;
65 int flags
= (int)(uintptr_t) WMGetNotificationClientData(notif
);
67 if (flags
& WTextureSettings
) {
68 icon
->force_paint
= 1;
70 if (flags
& WFontSettings
) {
71 icon
->force_paint
= 1;
74 if (flags & WColorSettings) {
80 /* so that the appicon expose handlers will paint the appicon specific
82 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
85 static void tileObserver(void *self
, WMNotification
* notif
)
87 WIcon
*icon
= (WIcon
*) self
;
89 icon
->force_paint
= 1;
92 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
95 /************************************/
97 INLINE
static void getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
103 XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
106 WIcon
*wIconCreate(WWindow
* wwin
)
108 WScreen
*scr
= wwin
->screen_ptr
;
111 unsigned long vmask
= 0;
112 XSetWindowAttributes attribs
;
114 icon
= wmalloc(sizeof(WIcon
));
115 memset(icon
, 0, sizeof(WIcon
));
116 icon
->core
= wCoreCreateTopLevel(scr
, wwin
->icon_x
, wwin
->icon_y
,
117 wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
119 if (wPreferences
.use_saveunders
) {
120 vmask
|= CWSaveUnder
;
121 attribs
.save_under
= True
;
123 /* a white border for selecting it */
124 vmask
|= CWBorderPixel
;
125 attribs
.border_pixel
= scr
->white_pixel
;
127 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
129 /* will be overriden if this is an application icon */
130 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
131 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
132 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
133 icon
->core
->descriptor
.parent
= icon
;
135 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
136 icon
->core
->stacking
->above
= NULL
;
137 icon
->core
->stacking
->under
= NULL
;
138 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
139 icon
->core
->stacking
->child_of
= NULL
;
142 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
143 if (wwin
->client_win
== wwin
->main_window
) {
145 /* do not let miniwindow steal app-icon's icon window */
146 wapp
= wApplicationOf(wwin
->client_win
);
147 if (!wapp
|| wapp
->app_icon
== NULL
)
148 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
150 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
153 #ifdef NO_MINIWINDOW_TITLES
154 icon
->show_title
= 0;
156 icon
->show_title
= 1;
159 if (!icon
->image
&& !WFLAGP(wwin
, always_user_icon
))
160 icon
->image
= RRetainImage(wwin
->net_icon_image
);
163 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
165 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
167 icon
->file
= wstrdup(file
);
170 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
172 wwin
->flags
.net_has_icon_title
= 1;
174 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
176 icon
->tile_type
= TILE_NORMAL
;
182 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
183 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
187 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
190 unsigned long vmask
= 0;
191 XSetWindowAttributes attribs
;
193 icon
= wmalloc(sizeof(WIcon
));
194 memset(icon
, 0, sizeof(WIcon
));
195 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
196 if (wPreferences
.use_saveunders
) {
198 attribs
.save_under
= True
;
200 /* a white border for selecting it */
201 vmask
|= CWBorderPixel
;
202 attribs
.border_pixel
= scr
->white_pixel
;
204 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
206 /* will be overriden if this is a application icon */
207 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
208 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
209 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
210 icon
->core
->descriptor
.parent
= icon
;
212 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
213 icon
->core
->stacking
->above
= NULL
;
214 icon
->core
->stacking
->under
= NULL
;
215 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
216 icon
->core
->stacking
->child_of
= NULL
;
219 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
221 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
224 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
226 icon
->file
= wstrdup(iconfile
);
229 icon
->tile_type
= tile
;
233 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
234 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
239 void wIconDestroy(WIcon
* icon
)
241 WCoreWindow
*core
= icon
->core
;
242 WScreen
*scr
= core
->screen_ptr
;
244 WMRemoveNotificationObserver(icon
);
247 WMDeleteTimerHandler(icon
->handlerID
);
249 if (icon
->icon_win
) {
253 x
= icon
->owner
->icon_x
;
254 y
= icon
->owner
->icon_y
;
256 XUnmapWindow(dpy
, icon
->icon_win
);
257 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
260 XFree(icon
->icon_name
);
263 XFreePixmap(dpy
, icon
->pixmap
);
268 if (icon
->image
!= NULL
)
269 RReleaseImage(icon
->image
);
271 wCoreDestroy(icon
->core
);
275 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
277 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
278 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
279 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
280 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
281 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
284 static Pixmap
makeIcon(WScreen
* scr
, RImage
* icon
, int titled
, int shadowed
, int tileType
)
290 int theight
= WMFontHeight(scr
->icon_title_font
);
292 if (tileType
== TILE_NORMAL
)
293 tile
= RCloneImage(scr
->icon_tile
);
295 assert(scr
->clip_tile
);
296 tile
= RCloneImage(scr
->clip_tile
);
299 w
= (icon
->width
> wPreferences
.icon_size
)
300 ? wPreferences
.icon_size
: icon
->width
;
301 x
= (wPreferences
.icon_size
- w
) / 2;
302 sx
= (icon
->width
- w
) / 2;
305 h
= (icon
->height
> wPreferences
.icon_size
)
306 ? wPreferences
.icon_size
: icon
->height
;
307 y
= (wPreferences
.icon_size
- h
) / 2;
308 sy
= (icon
->height
- h
) / 2;
310 h
= (icon
->height
+ theight
> wPreferences
.icon_size
311 ? wPreferences
.icon_size
- theight
: icon
->height
);
312 y
= theight
+ ((int)wPreferences
.icon_size
- theight
- h
) / 2;
313 sy
= (icon
->height
- h
) / 2;
315 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
321 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
322 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
323 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
324 color
.alpha
= 150; /* about 60% */
325 RClearImage(tile
, &color
);
328 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
329 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
334 drawIconTitle(scr
, pixmap
, theight
);
339 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
343 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
344 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
346 if (icon
->icon_name
!= NULL
)
347 XFree(icon
->icon_name
);
349 icon
->icon_name
= new_title
;
352 icon
->force_paint
= 1;
356 void wIconChangeImage(WIcon
* icon
, RImage
* new_image
)
358 assert(icon
!= NULL
);
361 RReleaseImage(icon
->image
);
363 icon
->image
= new_image
;
368 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
)
375 #ifndef DONT_SCALE_ICONS
376 if (wPreferences
.icon_size
!= 64) {
377 w
= wPreferences
.icon_size
* icon
->width
/ 64;
378 h
= wPreferences
.icon_size
* icon
->height
/ 64;
380 tmp
= RScaleImage(icon
, w
, h
);
386 if (icon
->width
> wPreferences
.icon_size
|| icon
->height
> wPreferences
.icon_size
) {
387 if (icon
->width
> icon
->height
) {
388 w
= wPreferences
.icon_size
- 4;
389 h
= w
* icon
->height
/ icon
->width
;
391 h
= wPreferences
.icon_size
- 4;
392 w
= h
* icon
->width
/ icon
->height
;
394 tmp
= RScaleImage(icon
, w
, h
);
403 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
405 WScreen
*scr
= icon
->core
->screen_ptr
;
411 wIconChangeImage(icon
, NULL
);
415 path
= FindImage(wPreferences
.icon_path
, file
);
417 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
418 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
420 wIconChangeImage(icon
, image
);
431 static char *getnameforicon(WWindow
* wwin
)
433 char *prefix
, *suffix
;
437 if (wwin
->wm_class
&& wwin
->wm_instance
) {
438 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
439 suffix
= wmalloc(len
);
440 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
441 } else if (wwin
->wm_class
) {
442 int len
= strlen(wwin
->wm_class
) + 1;
443 suffix
= wmalloc(len
);
444 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
445 } else if (wwin
->wm_instance
) {
446 int len
= strlen(wwin
->wm_instance
) + 1;
447 suffix
= wmalloc(len
);
448 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
453 prefix
= wusergnusteppath();
454 len
= strlen(prefix
) + 64 + strlen(suffix
);
455 path
= wmalloc(len
+ 1);
456 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
458 if (access(path
, F_OK
) != 0) {
459 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
460 wsyserror(_("could not create directory %s"), path
);
466 strcat(path
, "/CachedPixmaps");
467 if (access(path
, F_OK
) != 0) {
468 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
469 wsyserror(_("could not create directory %s"), path
);
477 strcat(path
, suffix
);
478 strcat(path
, ".xpm");
486 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
487 * and returns the path for that icon. Returns NULL if there is no
488 * client supplied icon or on failure.
491 * New directories might be created.
493 char *wIconStore(WIcon
* icon
)
497 WWindow
*wwin
= icon
->owner
;
499 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
500 || wwin
->wm_hints
->icon_pixmap
== None
)
503 path
= getnameforicon(wwin
);
507 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
508 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
509 ? wwin
->wm_hints
->icon_mask
: None
);
515 if (!RSaveImage(image
, path
, "XPM")) {
519 RReleaseImage(image
);
525 void wIconChangeIconWindow(WIcon *icon, Window new_window);
528 static void cycleColor(void *data
)
530 WIcon
*icon
= (WIcon
*) data
;
531 WScreen
*scr
= icon
->core
->screen_ptr
;
535 gcv
.dash_offset
= icon
->step
;
536 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
538 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
539 icon
->core
->width
- 1, icon
->core
->height
- 1);
540 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
543 void wIconSetHighlited(WIcon
* icon
, Bool flag
)
545 if (icon
->highlighted
== flag
) {
549 icon
->highlighted
= flag
;
553 void wIconSelect(WIcon
* icon
)
555 WScreen
*scr
= icon
->core
->screen_ptr
;
556 icon
->selected
= !icon
->selected
;
558 if (icon
->selected
) {
560 if (!wPreferences
.dont_blink
)
561 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
563 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
564 icon
->core
->width
- 1, icon
->core
->height
- 1);
566 if (icon
->handlerID
) {
567 WMDeleteTimerHandler(icon
->handlerID
);
568 icon
->handlerID
= NULL
;
570 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
574 void wIconUpdate(WIcon
* icon
)
576 WScreen
*scr
= icon
->core
->screen_ptr
;
577 int title_height
= WMFontHeight(scr
->icon_title_font
);
578 WWindow
*wwin
= icon
->owner
;
580 assert(scr
->icon_tile
!= NULL
);
582 if (icon
->pixmap
!= None
)
583 XFreePixmap(dpy
, icon
->pixmap
);
586 if (wwin
&& (WFLAGP(wwin
, always_user_icon
)
588 || wwin
->net_icon_image
593 /* use client specified icon window */
594 if (icon
->icon_win
!= None
) {
595 XWindowAttributes attr
;
597 unsigned int width
, height
, depth
;
601 getSize(icon
->icon_win
, &width
, &height
, &depth
);
603 if (width
> wPreferences
.icon_size
) {
605 width
= wPreferences
.icon_size
;
607 if (height
> wPreferences
.icon_size
) {
609 height
= wPreferences
.icon_size
;
611 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
612 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
613 wPreferences
.icon_size
, scr
->w_depth
);
614 XSetClipMask(dpy
, scr
->copy_gc
, None
);
615 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
616 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
617 drawIconTitle(scr
, pixmap
, title_height
);
618 theight
= title_height
;
622 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
625 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
626 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
627 (wPreferences
.icon_size
- width
) / 2,
628 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
630 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
632 XMapWindow(dpy
, icon
->icon_win
);
634 XAddToSaveSet(dpy
, icon
->icon_win
);
636 icon
->pixmap
= pixmap
;
638 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
639 if (attr
.all_event_masks
& ButtonPressMask
) {
640 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
641 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
642 None
, wCursor
[WCUR_ARROW
]);
645 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
653 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
654 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
658 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, wPreferences
.icon_size
,
659 wPreferences
.icon_size
, scr
->w_depth
);
660 XSetClipMask(dpy
, scr
->copy_gc
, None
);
661 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
662 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
664 if (w
> wPreferences
.icon_size
)
665 w
= wPreferences
.icon_size
;
666 x
= (wPreferences
.icon_size
- w
) / 2;
668 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
669 drawIconTitle(scr
, pixmap
, title_height
);
672 if (h
> wPreferences
.icon_size
- title_height
- 2) {
673 h
= wPreferences
.icon_size
- title_height
- 2;
674 y
= title_height
+ 1;
676 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
680 if (w
> wPreferences
.icon_size
)
681 w
= wPreferences
.icon_size
;
682 y
= (wPreferences
.icon_size
- h
) / 2;
685 if (wwin
->wm_hints
->flags
& IconMaskHint
)
686 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
688 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
690 if (d
!= scr
->w_depth
) {
691 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
692 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
693 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
695 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
698 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
700 icon
->pixmap
= pixmap
;
705 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
706 icon
->shadowed
, icon
->tile_type
);
708 /* make default icons */
710 if (!scr
->def_icon_pixmap
) {
711 RImage
*image
= NULL
;
715 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
717 path
= FindImage(wPreferences
.icon_path
, file
);
719 wwarning(_("could not find default icon \"%s\""), file
);
723 image
= RLoadImage(scr
->rcontext
, path
, 0);
725 wwarning(_("could not load default icon \"%s\":%s"),
726 file
, RMessageForError(RErrorCode
));
732 image
= wIconValidateIconSize(scr
, image
);
733 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
);
734 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
);
736 RReleaseImage(image
);
739 if (icon
->show_title
) {
740 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
742 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
747 if (icon
->pixmap
!= None
) {
748 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
750 XClearWindow(dpy
, icon
->core
->window
);
755 void wIconPaint(WIcon
* icon
)
757 WScreen
*scr
= icon
->core
->screen_ptr
;
761 if (icon
->force_paint
) {
762 icon
->force_paint
= 0;
767 XClearWindow(dpy
, icon
->core
->window
);
769 /* draw the icon title */
770 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
774 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
775 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
777 if (w
> icon
->core
->width
- 4)
778 x
= (icon
->core
->width
- 4) - w
;
780 x
= (icon
->core
->width
- w
) / 2;
782 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
783 scr
->icon_title_font
, x
, 1, tmp
, l
);
788 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
789 icon
->core
->width
- 1, icon
->core
->height
- 1);
792 /******************************************************************/
794 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
796 wIconPaint(desc
->parent
);
799 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
801 WIcon
*icon
= desc
->parent
;
803 assert(icon
->owner
!= NULL
);
805 wDeiconifyWindow(icon
->owner
);
808 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
810 WIcon
*icon
= desc
->parent
;
811 WWindow
*wwin
= icon
->owner
;
813 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
814 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
816 int clickButton
= event
->xbutton
.button
;
818 if (WCHECK_STATE(WSTATE_MODAL
))
821 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
822 miniwindowDblClick(desc
, event
);
826 puts("Moving miniwindow");
828 if (event
->xbutton
.button
== Button1
) {
829 if (event
->xbutton
.state
& MOD_MASK
)
830 wLowerFrame(icon
->core
);
832 wRaiseFrame(icon
->core
);
833 if (event
->xbutton
.state
& ShiftMask
) {
835 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
837 } else if (event
->xbutton
.button
== Button3
) {
838 WObjDescriptor
*desc
;
840 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
842 /* allow drag select of menu */
843 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
844 event
->xbutton
.send_event
= True
;
845 (*desc
->handle_mousedown
) (desc
, event
);
850 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
851 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
852 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
854 wwarning("pointer grab failed for icon move");
858 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
859 | ButtonMotionMask
| ExposureMask
, &ev
);
867 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
868 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
869 XChangeActivePointerGrab(dpy
, ButtonMotionMask
870 | ButtonReleaseMask
| ButtonPressMask
,
871 wCursor
[WCUR_MOVE
], CurrentTime
);
877 x
= ev
.xmotion
.x_root
- dx
;
878 y
= ev
.xmotion
.y_root
- dy
;
879 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
886 if (ev
.xbutton
.button
!= clickButton
)
889 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
890 wwin
->flags
.icon_moved
= 1;
892 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
897 puts("End miniwindow move");
899 XUngrabPointer(dpy
, CurrentTime
);
901 if (wPreferences
.auto_arrange_icons
)
902 wArrangeIcons(wwin
->screen_ptr
, True
);