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 uintptr_t flags
= (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;
158 if (!icon
->image
&& !WFLAGP(wwin
, always_user_icon
))
159 icon
->image
= RRetainImage(wwin
->net_icon_image
);
161 icon
->image
= wDefaultGetImage(scr
, wwin
->wm_instance
, wwin
->wm_class
);
163 file
= wDefaultGetIconFile(scr
, wwin
->wm_instance
, wwin
->wm_class
, False
);
165 icon
->file
= wstrdup(file
);
168 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
170 wwin
->flags
.net_has_icon_title
= 1;
172 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
174 icon
->tile_type
= TILE_NORMAL
;
180 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
181 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
185 WIcon
*wIconCreateWithIconFile(WScreen
* scr
, char *iconfile
, int tile
)
188 unsigned long vmask
= 0;
189 XSetWindowAttributes attribs
;
191 icon
= wmalloc(sizeof(WIcon
));
192 memset(icon
, 0, sizeof(WIcon
));
193 icon
->core
= wCoreCreateTopLevel(scr
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
, 0);
194 if (wPreferences
.use_saveunders
) {
196 attribs
.save_under
= True
;
198 /* a white border for selecting it */
199 vmask
|= CWBorderPixel
;
200 attribs
.border_pixel
= scr
->white_pixel
;
202 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
204 /* will be overriden if this is a application icon */
205 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
206 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
207 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
208 icon
->core
->descriptor
.parent
= icon
;
210 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
211 icon
->core
->stacking
->above
= NULL
;
212 icon
->core
->stacking
->under
= NULL
;
213 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
214 icon
->core
->stacking
->child_of
= NULL
;
217 icon
->image
= RLoadImage(scr
->rcontext
, iconfile
, 0);
219 wwarning(_("error loading image file \"%s\""), iconfile
, RMessageForError(RErrorCode
));
222 icon
->image
= wIconValidateIconSize(scr
, icon
->image
);
224 icon
->file
= wstrdup(iconfile
);
227 icon
->tile_type
= tile
;
231 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
232 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
237 void wIconDestroy(WIcon
* icon
)
239 WCoreWindow
*core
= icon
->core
;
240 WScreen
*scr
= core
->screen_ptr
;
242 WMRemoveNotificationObserver(icon
);
245 WMDeleteTimerHandler(icon
->handlerID
);
247 if (icon
->icon_win
) {
251 x
= icon
->owner
->icon_x
;
252 y
= icon
->owner
->icon_y
;
254 XUnmapWindow(dpy
, icon
->icon_win
);
255 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
258 XFree(icon
->icon_name
);
261 XFreePixmap(dpy
, icon
->pixmap
);
266 if (icon
->image
!= NULL
)
267 RReleaseImage(icon
->image
);
269 wCoreDestroy(icon
->core
);
273 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
275 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
276 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
277 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
278 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
279 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
282 static Pixmap
makeIcon(WScreen
* scr
, RImage
* icon
, int titled
, int shadowed
, int tileType
)
288 int theight
= WMFontHeight(scr
->icon_title_font
);
290 if (tileType
== TILE_NORMAL
)
291 tile
= RCloneImage(scr
->icon_tile
);
293 assert(scr
->clip_tile
);
294 tile
= RCloneImage(scr
->clip_tile
);
297 w
= (icon
->width
> wPreferences
.icon_size
)
298 ? wPreferences
.icon_size
: icon
->width
;
299 x
= (wPreferences
.icon_size
- w
) / 2;
300 sx
= (icon
->width
- w
) / 2;
303 h
= (icon
->height
> wPreferences
.icon_size
)
304 ? wPreferences
.icon_size
: icon
->height
;
305 y
= (wPreferences
.icon_size
- h
) / 2;
306 sy
= (icon
->height
- h
) / 2;
308 h
= (icon
->height
+ theight
> wPreferences
.icon_size
309 ? wPreferences
.icon_size
- theight
: icon
->height
);
310 y
= theight
+ ((int)wPreferences
.icon_size
- theight
- h
) / 2;
311 sy
= (icon
->height
- h
) / 2;
313 RCombineArea(tile
, icon
, sx
, sy
, w
, h
, x
, y
);
319 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
320 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
321 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
322 color
.alpha
= 150; /* about 60% */
323 RClearImage(tile
, &color
);
326 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
)) {
327 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
332 drawIconTitle(scr
, pixmap
, theight
);
337 void wIconChangeTitle(WIcon
* icon
, char *new_title
)
341 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
)
342 || (new_title
!= NULL
&& icon
->icon_name
== NULL
);
344 if (icon
->icon_name
!= NULL
)
345 XFree(icon
->icon_name
);
347 icon
->icon_name
= new_title
;
350 icon
->force_paint
= 1;
354 void wIconChangeImage(WIcon
* icon
, RImage
* new_image
)
356 assert(icon
!= NULL
);
359 RReleaseImage(icon
->image
);
361 icon
->image
= new_image
;
366 RImage
*wIconValidateIconSize(WScreen
* scr
, RImage
* icon
)
373 #ifndef DONT_SCALE_ICONS
374 if (wPreferences
.icon_size
!= 64) {
375 w
= wPreferences
.icon_size
* icon
->width
/ 64;
376 h
= wPreferences
.icon_size
* icon
->height
/ 64;
378 tmp
= RScaleImage(icon
, w
, h
);
384 if (icon
->width
> wPreferences
.icon_size
|| icon
->height
> wPreferences
.icon_size
) {
385 if (icon
->width
> icon
->height
) {
386 w
= wPreferences
.icon_size
- 4;
387 h
= w
* icon
->height
/ icon
->width
;
389 h
= wPreferences
.icon_size
- 4;
390 w
= h
* icon
->width
/ icon
->height
;
392 tmp
= RScaleImage(icon
, w
, h
);
401 Bool
wIconChangeImageFile(WIcon
* icon
, char *file
)
403 WScreen
*scr
= icon
->core
->screen_ptr
;
409 wIconChangeImage(icon
, NULL
);
413 path
= FindImage(wPreferences
.icon_path
, file
);
415 if (path
&& (image
= RLoadImage(scr
->rcontext
, path
, 0))) {
416 image
= wIconValidateIconSize(icon
->core
->screen_ptr
, image
);
418 wIconChangeImage(icon
, image
);
429 static char *getnameforicon(WWindow
* wwin
)
431 char *prefix
, *suffix
;
435 if (wwin
->wm_class
&& wwin
->wm_instance
) {
436 int len
= strlen(wwin
->wm_class
) + strlen(wwin
->wm_instance
) + 2;
437 suffix
= wmalloc(len
);
438 snprintf(suffix
, len
, "%s.%s", wwin
->wm_instance
, wwin
->wm_class
);
439 } else if (wwin
->wm_class
) {
440 int len
= strlen(wwin
->wm_class
) + 1;
441 suffix
= wmalloc(len
);
442 snprintf(suffix
, len
, "%s", wwin
->wm_class
);
443 } else if (wwin
->wm_instance
) {
444 int len
= strlen(wwin
->wm_instance
) + 1;
445 suffix
= wmalloc(len
);
446 snprintf(suffix
, len
, "%s", wwin
->wm_instance
);
451 prefix
= wusergnusteppath();
452 len
= strlen(prefix
) + 64 + strlen(suffix
);
453 path
= wmalloc(len
+ 1);
454 snprintf(path
, len
, "%s/Library/WindowMaker", prefix
);
456 if (access(path
, F_OK
) != 0) {
457 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
)) {
458 wsyserror(_("could not create directory %s"), path
);
464 strcat(path
, "/CachedPixmaps");
465 if (access(path
, F_OK
) != 0) {
466 if (mkdir(path
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0) {
467 wsyserror(_("could not create directory %s"), path
);
475 strcat(path
, suffix
);
476 strcat(path
, ".xpm");
484 * Stores the client supplied icon at ~/GNUstep/Library/WindowMaker/CachedPixmaps
485 * and returns the path for that icon. Returns NULL if there is no
486 * client supplied icon or on failure.
489 * New directories might be created.
491 char *wIconStore(WIcon
* icon
)
495 WWindow
*wwin
= icon
->owner
;
497 if (!wwin
|| !wwin
->wm_hints
|| !(wwin
->wm_hints
->flags
& IconPixmapHint
)
498 || wwin
->wm_hints
->icon_pixmap
== None
)
501 path
= getnameforicon(wwin
);
505 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
506 wwin
->wm_hints
->icon_pixmap
, (wwin
->wm_hints
->flags
& IconMaskHint
)
507 ? wwin
->wm_hints
->icon_mask
: None
);
513 if (!RSaveImage(image
, path
, "XPM")) {
517 RReleaseImage(image
);
523 void wIconChangeIconWindow(WIcon *icon, Window new_window);
526 static void cycleColor(void *data
)
528 WIcon
*icon
= (WIcon
*) data
;
529 WScreen
*scr
= icon
->core
->screen_ptr
;
533 gcv
.dash_offset
= icon
->step
;
534 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
536 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
537 icon
->core
->width
- 1, icon
->core
->height
- 1);
538 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
541 void wIconSetHighlited(WIcon
* icon
, Bool flag
)
543 if (icon
->highlighted
== flag
) {
547 icon
->highlighted
= flag
;
551 void wIconSelect(WIcon
* icon
)
553 WScreen
*scr
= icon
->core
->screen_ptr
;
554 icon
->selected
= !icon
->selected
;
556 if (icon
->selected
) {
558 if (!wPreferences
.dont_blink
)
559 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
561 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
562 icon
->core
->width
- 1, icon
->core
->height
- 1);
564 if (icon
->handlerID
) {
565 WMDeleteTimerHandler(icon
->handlerID
);
566 icon
->handlerID
= NULL
;
568 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
572 void wIconUpdate(WIcon
* icon
)
574 WScreen
*scr
= icon
->core
->screen_ptr
;
575 int title_height
= WMFontHeight(scr
->icon_title_font
);
576 WWindow
*wwin
= icon
->owner
;
578 assert(scr
->icon_tile
!= NULL
);
580 if (icon
->pixmap
!= None
)
581 XFreePixmap(dpy
, icon
->pixmap
);
584 if (wwin
&& (WFLAGP(wwin
, always_user_icon
) || wwin
->net_icon_image
))
587 /* use client specified icon window */
588 if (icon
->icon_win
!= None
) {
589 XWindowAttributes attr
;
591 unsigned int width
, height
, depth
;
595 getSize(icon
->icon_win
, &width
, &height
, &depth
);
597 if (width
> wPreferences
.icon_size
) {
599 width
= wPreferences
.icon_size
;
601 if (height
> wPreferences
.icon_size
) {
603 height
= wPreferences
.icon_size
;
605 if (icon
->show_title
&& (height
+ title_height
< wPreferences
.icon_size
)) {
606 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
607 wPreferences
.icon_size
, scr
->w_depth
);
608 XSetClipMask(dpy
, scr
->copy_gc
, None
);
609 XCopyArea(dpy
, scr
->icon_tile_pixmap
, pixmap
, scr
->copy_gc
, 0, 0,
610 wPreferences
.icon_size
, wPreferences
.icon_size
, 0, 0);
611 drawIconTitle(scr
, pixmap
, title_height
);
612 theight
= title_height
;
616 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
619 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
620 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
621 (wPreferences
.icon_size
- width
) / 2,
622 theight
+ (wPreferences
.icon_size
- height
- theight
) / 2);
624 XResizeWindow(dpy
, icon
->icon_win
, width
, height
);
626 XMapWindow(dpy
, icon
->icon_win
);
628 XAddToSaveSet(dpy
, icon
->icon_win
);
630 icon
->pixmap
= pixmap
;
632 if (XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) {
633 if (attr
.all_event_masks
& ButtonPressMask
) {
634 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
635 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
636 None
, wCursor
[WCUR_ARROW
]);
639 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
647 if (!XGetGeometry(dpy
, wwin
->wm_hints
->icon_pixmap
, &jw
, &ji
, &ji
, &w
, &h
, &ju
, &d
)) {
648 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
652 pixmap
= XCreatePixmap(dpy
, icon
->core
->window
, 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);
658 if (w
> wPreferences
.icon_size
)
659 w
= wPreferences
.icon_size
;
660 x
= (wPreferences
.icon_size
- w
) / 2;
662 if (icon
->show_title
&& (title_height
< wPreferences
.icon_size
)) {
663 drawIconTitle(scr
, pixmap
, title_height
);
666 if (h
> wPreferences
.icon_size
- title_height
- 2) {
667 h
= wPreferences
.icon_size
- title_height
- 2;
668 y
= title_height
+ 1;
670 y
= (wPreferences
.icon_size
- h
- title_height
) / 2 + title_height
+ 1;
674 if (w
> wPreferences
.icon_size
)
675 w
= wPreferences
.icon_size
;
676 y
= (wPreferences
.icon_size
- h
) / 2;
679 if (wwin
->wm_hints
->flags
& IconMaskHint
)
680 XSetClipMask(dpy
, scr
->copy_gc
, wwin
->wm_hints
->icon_mask
);
682 XSetClipOrigin(dpy
, scr
->copy_gc
, x
, y
);
684 if (d
!= scr
->w_depth
) {
685 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
686 XSetBackground(dpy
, scr
->copy_gc
, scr
->white_pixel
);
687 XCopyPlane(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
, 1);
689 XCopyArea(dpy
, wwin
->wm_hints
->icon_pixmap
, pixmap
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
692 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
694 icon
->pixmap
= pixmap
;
699 icon
->pixmap
= makeIcon(scr
, icon
->image
, icon
->show_title
,
700 icon
->shadowed
, icon
->tile_type
);
702 /* make default icons */
704 if (!scr
->def_icon_pixmap
) {
705 RImage
*image
= NULL
;
709 file
= wDefaultGetIconFile(scr
, NULL
, NULL
, False
);
711 path
= FindImage(wPreferences
.icon_path
, file
);
713 wwarning(_("could not find default icon \"%s\""), file
);
717 image
= RLoadImage(scr
->rcontext
, path
, 0);
719 wwarning(_("could not load default icon \"%s\":%s"),
720 file
, RMessageForError(RErrorCode
));
726 image
= wIconValidateIconSize(scr
, image
);
727 scr
->def_icon_pixmap
= makeIcon(scr
, image
, False
, False
, icon
->tile_type
);
728 scr
->def_ticon_pixmap
= makeIcon(scr
, image
, True
, False
, icon
->tile_type
);
730 RReleaseImage(image
);
733 if (icon
->show_title
) {
734 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_ticon_pixmap
);
736 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->def_icon_pixmap
);
741 if (icon
->pixmap
!= None
) {
742 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
744 XClearWindow(dpy
, icon
->core
->window
);
749 void wIconPaint(WIcon
* icon
)
751 WScreen
*scr
= icon
->core
->screen_ptr
;
755 if (icon
->force_paint
) {
756 icon
->force_paint
= 0;
761 XClearWindow(dpy
, icon
->core
->window
);
763 /* draw the icon title */
764 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
768 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
769 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
771 if (w
> icon
->core
->width
- 4)
772 x
= (icon
->core
->width
- 4) - w
;
774 x
= (icon
->core
->width
- w
) / 2;
776 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
777 scr
->icon_title_font
, x
, 1, tmp
, l
);
782 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
783 icon
->core
->width
- 1, icon
->core
->height
- 1);
786 /******************************************************************/
788 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
790 wIconPaint(desc
->parent
);
793 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
795 WIcon
*icon
= desc
->parent
;
797 assert(icon
->owner
!= NULL
);
799 wDeiconifyWindow(icon
->owner
);
802 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
804 WIcon
*icon
= desc
->parent
;
805 WWindow
*wwin
= icon
->owner
;
807 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
808 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
810 int clickButton
= event
->xbutton
.button
;
811 Bool hasMoved
= False
;
813 if (WCHECK_STATE(WSTATE_MODAL
))
816 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
817 miniwindowDblClick(desc
, event
);
821 puts("Moving miniwindow");
823 if (event
->xbutton
.button
== Button1
) {
824 if (event
->xbutton
.state
& MOD_MASK
)
825 wLowerFrame(icon
->core
);
827 wRaiseFrame(icon
->core
);
828 if (event
->xbutton
.state
& ShiftMask
) {
830 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
832 } else if (event
->xbutton
.button
== Button3
) {
833 WObjDescriptor
*desc
;
835 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
837 /* allow drag select of menu */
838 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
839 event
->xbutton
.send_event
= True
;
840 (*desc
->handle_mousedown
) (desc
, event
);
845 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
846 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
847 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
849 wwarning("pointer grab failed for icon move");
853 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
854 | ButtonMotionMask
| ExposureMask
, &ev
);
863 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
864 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
865 XChangeActivePointerGrab(dpy
, ButtonMotionMask
866 | ButtonReleaseMask
| ButtonPressMask
,
867 wCursor
[WCUR_MOVE
], CurrentTime
);
873 x
= ev
.xmotion
.x_root
- dx
;
874 y
= ev
.xmotion
.y_root
- dy
;
875 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
882 if (ev
.xbutton
.button
!= clickButton
)
885 if (wwin
->icon_x
!= x
|| wwin
->icon_y
!= y
)
886 wwin
->flags
.icon_moved
= 1;
888 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
893 puts("End miniwindow move");
895 XUngrabPointer(dpy
, CurrentTime
);
897 if (wPreferences
.auto_arrange_icons
)
898 wArrangeIcons(wwin
->screen_ptr
, True
);
899 if (wPreferences
.single_click
&& !hasMoved
)
900 miniwindowDblClick(desc
, event
);