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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #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
52 #define CACHE_ICON_PATH "/Library/WindowMaker/CachedPixmaps"
55 extern Cursor wCursor
[WCUR_LAST
];
57 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
);
58 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
59 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
);
61 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
);
63 static void set_dockapp_in_icon(WIcon
*icon
);
64 static void get_rimage_icon_from_icon_win(WIcon
*icon
);
65 static int get_rimage_icon_from_wm_hints(WIcon
*icon
);
66 static void get_rimage_icon_from_user_icon(WIcon
*icon
);
67 static void get_rimage_icon_from_default_icon(WIcon
*icon
);
68 static void get_rimage_icon_from_x11(WIcon
*icon
);
70 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
);
71 static void unset_icon_image(WIcon
*icon
);
73 /****** Notification Observers ******/
75 static void appearanceObserver(void *self
, WMNotification
*notif
)
77 WIcon
*icon
= (WIcon
*) self
;
78 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
80 if ((flags
& WTextureSettings
) || (flags
& WFontSettings
)) {
81 /* If the rimage exists, update the icon, else create it */
83 update_icon_pixmap(icon
);
88 /* so that the appicon expose handlers will paint the appicon specific
90 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
93 static void tileObserver(void *self
, WMNotification
*notif
)
95 WIcon
*icon
= (WIcon
*) self
;
99 XClearArea(dpy
, icon
->core
->window
, 0, 0, 1, 1, True
);
102 /************************************/
104 static int getSize(Drawable d
, unsigned int *w
, unsigned int *h
, unsigned int *dep
)
110 return XGetGeometry(dpy
, d
, &rjunk
, &xjunk
, &yjunk
, w
, h
, &bjunk
, dep
);
113 WIcon
*icon_create_for_wwindow(WWindow
*wwin
)
115 WScreen
*scr
= wwin
->screen_ptr
;
119 icon
= icon_create_core(scr
, wwin
->icon_x
, wwin
->icon_y
);
122 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconWindowHint
)) {
123 if (wwin
->client_win
== wwin
->main_window
) {
125 /* do not let miniwindow steal app-icon's icon window */
126 wapp
= wApplicationOf(wwin
->client_win
);
127 if (!wapp
|| wapp
->app_icon
== NULL
)
128 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
130 icon
->icon_win
= wwin
->wm_hints
->icon_window
;
133 #ifdef NO_MINIWINDOW_TITLES
134 icon
->show_title
= 0;
136 icon
->show_title
= 1;
139 icon
->icon_name
= wNETWMGetIconName(wwin
->client_win
);
141 wwin
->flags
.net_has_icon_title
= 1;
143 wGetIconName(dpy
, wwin
->client_win
, &icon
->icon_name
);
145 /* Get the application icon, default included */
146 file
= get_icon_filename(scr
, wwin
->wm_instance
, wwin
->wm_class
, NULL
, True
);
148 icon
->file
= wstrdup(file
);
149 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
153 icon
->tile_type
= TILE_NORMAL
;
157 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
158 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
163 WIcon
*icon_create_for_dock(WScreen
*scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
168 icon
= icon_create_core(scr
, 0, 0);
170 /* Search the icon using instance and class, without default icon */
171 file
= get_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
173 icon
->file
= wstrdup(file
);
174 icon
->file_image
= get_rimage_from_file(scr
, icon
->file
, wPreferences
.icon_size
);
178 icon
->tile_type
= tile
;
182 WMAddNotificationObserver(appearanceObserver
, icon
, WNIconAppearanceSettingsChanged
, icon
);
183 WMAddNotificationObserver(tileObserver
, icon
, WNIconTileSettingsChanged
, icon
);
188 static WIcon
*icon_create_core(WScreen
*scr
, int coord_x
, int coord_y
)
191 unsigned long vmask
= 0;
192 XSetWindowAttributes attribs
;
194 icon
= wmalloc(sizeof(WIcon
));
195 icon
->core
= wCoreCreateTopLevel(scr
,
198 wPreferences
.icon_size
,
199 wPreferences
.icon_size
,
200 0, scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
202 if (wPreferences
.use_saveunders
) {
204 attribs
.save_under
= True
;
207 /* a white border for selecting it */
208 vmask
|= CWBorderPixel
;
209 attribs
.border_pixel
= scr
->white_pixel
;
211 XChangeWindowAttributes(dpy
, icon
->core
->window
, vmask
, &attribs
);
213 /* will be overriden if this is a application icon */
214 icon
->core
->descriptor
.handle_mousedown
= miniwindowMouseDown
;
215 icon
->core
->descriptor
.handle_expose
= miniwindowExpose
;
216 icon
->core
->descriptor
.parent_type
= WCLASS_MINIWINDOW
;
217 icon
->core
->descriptor
.parent
= icon
;
219 icon
->core
->stacking
= wmalloc(sizeof(WStacking
));
220 icon
->core
->stacking
->above
= NULL
;
221 icon
->core
->stacking
->under
= NULL
;
222 icon
->core
->stacking
->window_level
= NORMAL_ICON_LEVEL
;
223 icon
->core
->stacking
->child_of
= NULL
;
227 icon
->file_image
= NULL
;
232 void wIconDestroy(WIcon
* icon
)
234 WCoreWindow
*core
= icon
->core
;
235 WScreen
*scr
= core
->screen_ptr
;
237 WMRemoveNotificationObserver(icon
);
240 WMDeleteTimerHandler(icon
->handlerID
);
242 if (icon
->icon_win
) {
246 x
= icon
->owner
->icon_x
;
247 y
= icon
->owner
->icon_y
;
249 XUnmapWindow(dpy
, icon
->icon_win
);
250 XReparentWindow(dpy
, icon
->icon_win
, scr
->root_win
, x
, y
);
253 XFree(icon
->icon_name
);
256 XFreePixmap(dpy
, icon
->pixmap
);
258 unset_icon_image(icon
);
260 wCoreDestroy(icon
->core
);
264 static void drawIconTitle(WScreen
* scr
, Pixmap pixmap
, int height
)
266 XFillRectangle(dpy
, pixmap
, scr
->icon_title_texture
->normal_gc
, 0, 0, wPreferences
.icon_size
, height
+ 1);
267 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, wPreferences
.icon_size
, 0);
268 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, height
+ 1);
269 XDrawLine(dpy
, pixmap
, scr
->icon_title_texture
->dim_gc
,
270 wPreferences
.icon_size
- 1, 0, wPreferences
.icon_size
- 1, height
+ 1);
273 static void icon_update_pixmap(WIcon
*icon
, RImage
*image
)
280 WScreen
*scr
= icon
->core
->screen_ptr
;
281 int titled
= icon
->show_title
;
283 if (icon
->tile_type
== TILE_NORMAL
) {
284 tile
= RCloneImage(scr
->icon_tile
);
286 assert(scr
->clip_tile
);
287 tile
= RCloneImage(scr
->clip_tile
);
291 w
= (image
->width
> wPreferences
.icon_size
)
292 ? wPreferences
.icon_size
: image
->width
;
293 x
= (wPreferences
.icon_size
- w
) / 2;
294 sx
= (image
->width
- w
) / 2;
297 theight
= WMFontHeight(scr
->icon_title_font
);
299 h
= (image
->height
+ theight
> wPreferences
.icon_size
300 ? wPreferences
.icon_size
- theight
: image
->height
);
301 y
= theight
+ (wPreferences
.icon_size
- theight
- h
) / 2;
302 sy
= (image
->height
- h
) / 2;
304 RCombineArea(tile
, image
, sx
, sy
, w
, h
, x
, y
);
307 if (icon
->shadowed
) {
310 color
.red
= scr
->icon_back_texture
->light
.red
>> 8;
311 color
.green
= scr
->icon_back_texture
->light
.green
>> 8;
312 color
.blue
= scr
->icon_back_texture
->light
.blue
>> 8;
313 color
.alpha
= 150; /* about 60% */
314 RClearImage(tile
, &color
);
317 if (icon
->highlighted
) {
320 color
.red
= color
.green
= color
.blue
= 0;
322 RLightImage(tile
, &color
);
325 if (!RConvertImage(scr
->rcontext
, tile
, &pixmap
))
326 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
331 drawIconTitle(scr
, pixmap
, theight
);
333 icon
->pixmap
= pixmap
;
336 void wIconChangeTitle(WIcon
*icon
, char *new_title
)
340 changed
= (new_title
== NULL
&& icon
->icon_name
!= NULL
) ||
341 (new_title
!= NULL
&& icon
->icon_name
== NULL
);
343 if (icon
->icon_name
!= NULL
)
344 XFree(icon
->icon_name
);
346 icon
->icon_name
= new_title
;
354 RImage
*wIconValidateIconSize(RImage
*icon
, int max_size
)
361 /* We should hold "ICON_BORDER" (~2) pixels to include the icon border */
362 if (((max_size
+ ICON_BORDER
) < icon
->width
) ||
363 ((max_size
+ ICON_BORDER
) < icon
->height
)) {
364 if (icon
->width
> icon
->height
)
365 nimage
= RScaleImage(icon
, max_size
- ICON_BORDER
,
366 (icon
->height
* (max_size
- ICON_BORDER
) / icon
->width
));
368 nimage
= RScaleImage(icon
, (icon
->width
* (max_size
- ICON_BORDER
) / icon
->height
),
369 max_size
- ICON_BORDER
);
377 Bool
wIconChangeImageFile(WIcon
*icon
, char *file
)
379 WScreen
*scr
= icon
->core
->screen_ptr
;
381 RImage
*image
= NULL
;
384 /* If no new image, don't do nothing */
388 /* Find the new image */
389 path
= FindImage(wPreferences
.icon_path
, file
);
391 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
396 if (!error
&& image
) {
397 /* Remove the old one */
398 unset_icon_image(icon
);
400 /* Set the new image */
401 icon
->file_image
= image
;
402 icon
->file
= wstrdup(path
);
414 static char *get_name_for_wwin(WWindow
*wwin
)
416 return get_name_for_instance_class(wwin
->wm_instance
, wwin
->wm_class
);
419 char *get_name_for_instance_class(char *wm_instance
, char *wm_class
)
424 if (wm_class
&& wm_instance
) {
425 len
= strlen(wm_class
) + strlen(wm_instance
) + 2;
426 suffix
= wmalloc(len
);
427 snprintf(suffix
, len
, "%s.%s", wm_instance
, wm_class
);
428 } else if (wm_class
) {
429 len
= strlen(wm_class
) + 1;
430 suffix
= wmalloc(len
);
431 snprintf(suffix
, len
, "%s", wm_class
);
432 } else if (wm_instance
) {
433 len
= strlen(wm_instance
) + 1;
434 suffix
= wmalloc(len
);
435 snprintf(suffix
, len
, "%s", wm_instance
);
443 static char *get_icon_cache_path(void)
448 prefix
= wusergnusteppath();
449 len
= strlen(prefix
) + strlen(CACHE_ICON_PATH
) + 2;
451 snprintf(path
, len
, "%s%s/", prefix
, CACHE_ICON_PATH
);
453 /* If the folder exists, exit */
454 if (access(path
, F_OK
) == 0)
457 /* Create the folder */
458 ret
= wmkdirhier((const char *) path
);
460 /* Exit 1 on success, 0 on failure */
469 static RImage
*get_wwindow_image_from_wmhints(WWindow
*wwin
, WIcon
*icon
)
471 RImage
*image
= NULL
;
472 XWMHints
*hints
= wwin
->wm_hints
;
474 if (hints
&& (hints
->flags
& IconPixmapHint
) && hints
->icon_pixmap
!= None
)
475 image
= RCreateImageFromDrawable(icon
->core
->screen_ptr
->rcontext
,
477 (hints
->flags
& IconMaskHint
)
478 ? hints
->icon_mask
: None
);
485 * Stores the client supplied icon at CACHE_ICON_PATH
486 * and returns the path for that icon. Returns NULL if there is no
487 * client supplied icon or on failure.
490 * New directories might be created.
492 char *wIconStore(WIcon
* icon
)
494 char *path
, *dir_path
, *file
;
496 RImage
*image
= NULL
;
497 WWindow
*wwin
= icon
->owner
;
502 dir_path
= get_icon_cache_path();
506 file
= get_name_for_wwin(wwin
);
512 len
= strlen(dir_path
) + strlen(file
) + 5;
514 snprintf(path
, len
, "%s%s.xpm", dir_path
, file
);
518 /* If icon exists, exit */
519 if (access(path
, F_OK
) == 0)
522 if (wwin
->net_icon_image
)
523 image
= RRetainImage(wwin
->net_icon_image
);
525 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
532 if (!RSaveImage(image
, path
, "XPM")) {
537 RReleaseImage(image
);
542 static void cycleColor(void *data
)
544 WIcon
*icon
= (WIcon
*) data
;
545 WScreen
*scr
= icon
->core
->screen_ptr
;
549 gcv
.dash_offset
= icon
->step
;
550 XChangeGC(dpy
, scr
->icon_select_gc
, GCDashOffset
, &gcv
);
552 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
553 icon
->core
->width
- 1, icon
->core
->height
- 1);
554 icon
->handlerID
= WMAddTimerHandler(COLOR_CYCLE_DELAY
, cycleColor
, icon
);
557 void wIconSetHighlited(WIcon
*icon
, Bool flag
)
559 if (icon
->highlighted
== flag
)
562 icon
->highlighted
= flag
;
563 update_icon_pixmap(icon
);
566 void wIconSelect(WIcon
* icon
)
568 WScreen
*scr
= icon
->core
->screen_ptr
;
569 icon
->selected
= !icon
->selected
;
571 if (icon
->selected
) {
573 if (!wPreferences
.dont_blink
)
574 icon
->handlerID
= WMAddTimerHandler(10, cycleColor
, icon
);
576 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
577 icon
->core
->width
- 1, icon
->core
->height
- 1);
579 if (icon
->handlerID
) {
580 WMDeleteTimerHandler(icon
->handlerID
);
581 icon
->handlerID
= NULL
;
583 XClearArea(dpy
, icon
->core
->window
, 0, 0, icon
->core
->width
, icon
->core
->height
, True
);
587 static void unset_icon_image(WIcon
*icon
)
594 if (icon
->file_image
) {
595 RReleaseImage(icon
->file_image
);
596 icon
->file_image
= NULL
;
600 void wIconUpdate(WIcon
*icon
)
602 WWindow
*wwin
= icon
->owner
;
604 if (wwin
&& WFLAGP(wwin
, always_user_icon
)) {
605 /* Forced use user_icon */
606 get_rimage_icon_from_user_icon(icon
);
607 } else if (icon
->icon_win
!= None
) {
608 /* Get the Pixmap from the WIcon */
609 get_rimage_icon_from_icon_win(icon
);
610 } else if (wwin
&& wwin
->net_icon_image
) {
611 /* Use _NET_WM_ICON icon */
612 get_rimage_icon_from_x11(icon
);
613 } else if (wwin
&& wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& IconPixmapHint
)) {
614 /* Get the Pixmap from the wm_hints, else, from the user */
615 if (get_rimage_icon_from_wm_hints(icon
))
616 get_rimage_icon_from_user_icon(icon
);
618 /* Get the Pixmap from the user */
619 get_rimage_icon_from_user_icon(icon
);
622 update_icon_pixmap(icon
);
625 void update_icon_pixmap(WIcon
*icon
)
627 if (icon
->pixmap
!= None
)
628 XFreePixmap(dpy
, icon
->pixmap
);
632 /* Create the pixmap */
633 if (icon
->file_image
)
634 icon_update_pixmap(icon
, icon
->file_image
);
636 /* If dockapp, put inside the icon */
637 if (icon
->icon_win
!= None
) {
638 /* file_image is NULL, because is docked app */
639 icon_update_pixmap(icon
, icon
->file_image
);
640 set_dockapp_in_icon(icon
);
643 /* No pixmap, set default background */
644 if (icon
->pixmap
!= None
)
645 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, icon
->pixmap
);
648 XClearWindow(dpy
, icon
->core
->window
);
652 static void get_rimage_icon_from_x11(WIcon
*icon
)
654 /* Remove the icon image */
655 unset_icon_image(icon
);
657 /* Set the new icon image */
658 icon
->file_image
= RRetainImage(icon
->owner
->net_icon_image
);
661 static void get_rimage_icon_from_user_icon(WIcon
*icon
)
663 if (icon
->file_image
)
666 get_rimage_icon_from_default_icon(icon
);
669 static void get_rimage_icon_from_default_icon(WIcon
*icon
)
671 WScreen
*scr
= icon
->core
->screen_ptr
;
673 /* If the icon don't have image, we should use the default image. */
674 if (!scr
->def_icon_rimage
)
675 scr
->def_icon_rimage
= get_default_image(scr
);
677 /* Remove the icon image */
678 unset_icon_image(icon
);
680 /* Set the new icon image */
681 icon
->file_image
= RRetainImage(scr
->def_icon_rimage
);
684 /* Get the RImage from the WIcon of the WWindow */
685 static void get_rimage_icon_from_icon_win(WIcon
*icon
)
689 /* Create the new RImage */
690 image
= get_window_image_from_x11(icon
->icon_win
);
692 /* Free the icon info */
693 unset_icon_image(icon
);
695 /* Set the new info */
696 icon
->file_image
= image
;
699 /* Set the dockapp in the WIcon */
700 static void set_dockapp_in_icon(WIcon
*icon
)
702 XWindowAttributes attr
;
703 WScreen
*scr
= icon
->core
->screen_ptr
;
704 int title_height
= WMFontHeight(scr
->icon_title_font
);
705 unsigned int w
, h
, d
;
708 /* Reparent the dock application to the icon */
710 /* We need the application size to center it
711 * and show in the correct position */
712 getSize(icon
->icon_win
, &w
, &h
, &d
);
714 /* Set extra space for title */
715 if (icon
->show_title
&& (h
+ title_height
< wPreferences
.icon_size
)) {
716 theight
= title_height
;
717 drawIconTitle(scr
, icon
->pixmap
, theight
);
719 XSetWindowBackgroundPixmap(dpy
, icon
->core
->window
, scr
->icon_tile_pixmap
);
722 /* Set the icon border */
723 XSetWindowBorderWidth(dpy
, icon
->icon_win
, 0);
725 /* Put the dock application in the icon */
726 XReparentWindow(dpy
, icon
->icon_win
, icon
->core
->window
,
727 (wPreferences
.icon_size
- w
) / 2,
728 theight
+ (wPreferences
.icon_size
- h
- theight
) / 2);
730 /* Show it and save */
731 XMapWindow(dpy
, icon
->icon_win
);
732 XAddToSaveSet(dpy
, icon
->icon_win
);
734 /* Needed to move the icon clicking on the application part */
735 if ((XGetWindowAttributes(dpy
, icon
->icon_win
, &attr
)) &&
736 (attr
.all_event_masks
& ButtonPressMask
))
737 wHackedGrabButton(Button1
, MOD_MASK
, icon
->core
->window
, True
,
738 ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
739 None
, wCursor
[WCUR_ARROW
]);
742 /* Get the RImage from the XWindow wm_hints */
743 static int get_rimage_icon_from_wm_hints(WIcon
*icon
)
745 RImage
*image
= NULL
;
746 unsigned int w
, h
, d
;
747 WWindow
*wwin
= icon
->owner
;
749 if (!getSize(wwin
->wm_hints
->icon_pixmap
, &w
, &h
, &d
)) {
750 icon
->owner
->wm_hints
->flags
&= ~IconPixmapHint
;
754 image
= get_wwindow_image_from_wmhints(wwin
, icon
);
758 /* Resize the icon to the wPreferences.icon_size size */
759 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
761 unset_icon_image(icon
);
762 icon
->file_image
= image
;
767 void wIconPaint(WIcon
*icon
)
769 WScreen
*scr
= icon
->core
->screen_ptr
;
773 XClearWindow(dpy
, icon
->core
->window
);
775 /* draw the icon title */
776 if (icon
->show_title
&& icon
->icon_name
!= NULL
) {
777 tmp
= ShrinkString(scr
->icon_title_font
, icon
->icon_name
, wPreferences
.icon_size
- 4);
778 w
= WMWidthOfString(scr
->icon_title_font
, tmp
, l
= strlen(tmp
));
780 if (w
> icon
->core
->width
- 4)
781 x
= (icon
->core
->width
- 4) - w
;
783 x
= (icon
->core
->width
- w
) / 2;
785 WMDrawString(scr
->wmscreen
, icon
->core
->window
, scr
->icon_title_color
,
786 scr
->icon_title_font
, x
, 1, tmp
, l
);
791 XDrawRectangle(dpy
, icon
->core
->window
, scr
->icon_select_gc
, 0, 0,
792 icon
->core
->width
- 1, icon
->core
->height
- 1);
795 /******************************************************************/
797 static void miniwindowExpose(WObjDescriptor
* desc
, XEvent
* event
)
799 wIconPaint(desc
->parent
);
802 static void miniwindowDblClick(WObjDescriptor
* desc
, XEvent
* event
)
804 WIcon
*icon
= desc
->parent
;
806 assert(icon
->owner
!= NULL
);
808 wDeiconifyWindow(icon
->owner
);
811 static void miniwindowMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
813 WIcon
*icon
= desc
->parent
;
814 WWindow
*wwin
= icon
->owner
;
816 int x
= wwin
->icon_x
, y
= wwin
->icon_y
;
817 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
819 int clickButton
= event
->xbutton
.button
;
820 Bool hasMoved
= False
;
822 if (WCHECK_STATE(WSTATE_MODAL
))
825 if (IsDoubleClick(icon
->core
->screen_ptr
, event
)) {
826 miniwindowDblClick(desc
, event
);
830 if (event
->xbutton
.button
== Button1
) {
831 if (event
->xbutton
.state
& MOD_MASK
)
832 wLowerFrame(icon
->core
);
834 wRaiseFrame(icon
->core
);
835 if (event
->xbutton
.state
& ShiftMask
) {
837 wSelectWindow(icon
->owner
, !wwin
->flags
.selected
);
839 } else if (event
->xbutton
.button
== Button3
) {
840 WObjDescriptor
*desc
;
842 OpenMiniwindowMenu(wwin
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
844 /* allow drag select of menu */
845 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
846 event
->xbutton
.send_event
= True
;
847 (*desc
->handle_mousedown
) (desc
, event
);
852 if (XGrabPointer(dpy
, icon
->core
->window
, False
, ButtonMotionMask
853 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
854 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
857 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
858 | 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
);
896 XUngrabPointer(dpy
, CurrentTime
);
898 if (wPreferences
.auto_arrange_icons
)
899 wArrangeIcons(wwin
->screen_ptr
, True
);
900 if (wPreferences
.single_click
&& !hasMoved
)
901 miniwindowDblClick(desc
, event
);