Update to Window Maker 0.50.2
[wmaker-crm.git] / src / icon.c
blob567109a13dceb9262ada60bb471954acff10e33a
1 /* icon.c - window icon and dock and appicon parent
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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,
20 * USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <ctype.h>
32 #include <wraster.h>
33 #include <sys/stat.h>
35 #include "WindowMaker.h"
36 #include "wcore.h"
37 #include "texture.h"
38 #include "window.h"
39 #include "icon.h"
40 #include "actions.h"
41 #include "funcs.h"
42 #include "stacking.h"
43 #include "application.h"
44 #include "defaults.h"
45 #include "appicon.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 INLINE static void
61 getSize(Drawable d, unsigned int *w, unsigned int *h, unsigned int *dep)
63 Window rjunk;
64 int xjunk, yjunk;
65 unsigned int bjunk;
67 XGetGeometry(dpy, d, &rjunk, &xjunk, &yjunk, w, h, &bjunk, dep);
71 WIcon*
72 wIconCreate(WWindow *wwin)
74 WScreen *scr=wwin->screen_ptr;
75 WIcon *icon;
76 char *file;
77 unsigned long vmask = 0;
78 XSetWindowAttributes attribs;
80 icon = wmalloc(sizeof(WIcon));
81 memset(icon, 0, sizeof(WIcon));
82 icon->core = wCoreCreateTopLevel(scr, wwin->icon_x, wwin->icon_y,
83 wPreferences.icon_size,
84 wPreferences.icon_size, 0);
86 if (wPreferences.use_saveunders) {
87 vmask |= CWSaveUnder;
88 attribs.save_under = True;
90 /* a white border for selecting it */
91 vmask |= CWBorderPixel;
92 attribs.border_pixel = scr->white_pixel;
94 XChangeWindowAttributes(dpy, icon->core->window, vmask, &attribs);
97 /* will be overriden if this is an application icon */
98 icon->core->descriptor.handle_mousedown = miniwindowMouseDown;
99 icon->core->descriptor.handle_expose = miniwindowExpose;
100 icon->core->descriptor.parent_type = WCLASS_MINIWINDOW;
101 icon->core->descriptor.parent = icon;
103 icon->core->stacking = wmalloc(sizeof(WStacking));
104 icon->core->stacking->above = NULL;
105 icon->core->stacking->under = NULL;
106 icon->core->stacking->window_level = NORMAL_ICON_LEVEL;
107 icon->core->stacking->child_of = NULL;
109 icon->owner = wwin;
110 if (wwin->wm_hints && (wwin->wm_hints->flags & IconWindowHint)) {
111 if (wwin->client_win == wwin->main_window) {
112 WApplication *wapp;
113 /* do not let miniwindow steal app-icon's icon window */
114 wapp = wApplicationOf(wwin->client_win);
115 if (!wapp || wapp->app_icon==NULL)
116 icon->icon_win = wwin->wm_hints->icon_window;
117 } else {
118 icon->icon_win = wwin->wm_hints->icon_window;
121 #ifdef NO_MINIWINDOW_TITLES
122 icon->show_title = 0;
123 #else
124 icon->show_title = 1;
125 #endif
126 icon->image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
128 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
129 False);
130 if (file) {
131 icon->file = wstrdup(file);
134 wGetIconName(dpy, wwin->client_win, &icon->icon_name);
136 icon->tile_type = TILE_NORMAL;
138 wIconUpdate(icon);
140 XFlush(dpy);
142 return icon;
146 WIcon*
147 wIconCreateWithIconFile(WScreen *scr, char *iconfile, int tile)
149 WIcon *icon;
150 unsigned long vmask = 0;
151 XSetWindowAttributes attribs;
153 icon = wmalloc(sizeof(WIcon));
154 memset(icon, 0, sizeof(WIcon));
155 icon->core = wCoreCreateTopLevel(scr, 0, 0, wPreferences.icon_size,
156 wPreferences.icon_size, 0);
157 if (wPreferences.use_saveunders) {
158 vmask = CWSaveUnder;
159 attribs.save_under = True;
161 /* a white border for selecting it */
162 vmask |= CWBorderPixel;
163 attribs.border_pixel = scr->white_pixel;
165 XChangeWindowAttributes(dpy, icon->core->window, vmask, &attribs);
167 /* will be overriden if this is a application icon */
168 icon->core->descriptor.handle_mousedown = miniwindowMouseDown;
169 icon->core->descriptor.handle_expose = miniwindowExpose;
170 icon->core->descriptor.parent_type = WCLASS_MINIWINDOW;
171 icon->core->descriptor.parent = icon;
173 icon->core->stacking = wmalloc(sizeof(WStacking));
174 icon->core->stacking->above = NULL;
175 icon->core->stacking->under = NULL;
176 icon->core->stacking->window_level = NORMAL_ICON_LEVEL;
177 icon->core->stacking->child_of = NULL;
179 if (iconfile) {
180 icon->image = RLoadImage(scr->rcontext, iconfile, 0);
181 if (!icon->image) {
182 wwarning(_("error loading image file \"%s\""), iconfile, RMessageForError(RErrorCode));
185 icon->image = wIconValidateIconSize(scr, icon->image);
187 icon->file = wstrdup(iconfile);
190 icon->tile_type = tile;
192 wIconUpdate(icon);
194 return icon;
199 void
200 wIconDestroy(WIcon *icon)
202 WCoreWindow *core = icon->core;
203 WScreen *scr = core->screen_ptr;
205 if (icon->handlerID)
206 WMDeleteTimerHandler(icon->handlerID);
208 if (icon->icon_win) {
209 int x=0, y=0;
211 if (icon->owner) {
212 x = icon->owner->icon_x;
213 y = icon->owner->icon_y;
215 XUnmapWindow(dpy, icon->icon_win);
216 XReparentWindow(dpy, icon->icon_win, scr->root_win, x, y);
218 if (icon->icon_name)
219 XFree(icon->icon_name);
221 if (icon->pixmap)
222 XFreePixmap(dpy, icon->pixmap);
224 if (icon->file)
225 free(icon->file);
227 if (icon->image!=NULL)
228 RDestroyImage(icon->image);
230 wCoreDestroy(icon->core);
231 free(icon);
236 static void
237 drawIconTitle(WScreen *scr, Pixmap pixmap, int height)
239 XFillRectangle(dpy, pixmap, scr->icon_title_texture->normal_gc,
240 0, 0, wPreferences.icon_size, height+1);
241 XDrawLine(dpy, pixmap, scr->icon_title_texture->light_gc, 0, 0,
242 wPreferences.icon_size, 0);
243 XDrawLine(dpy, pixmap, scr->icon_title_texture->light_gc, 0, 0,
244 0, height+1);
245 XDrawLine(dpy, pixmap, scr->icon_title_texture->dim_gc,
246 wPreferences.icon_size-1, 0, wPreferences.icon_size-1, height+1);
250 static Pixmap
251 makeIcon(WScreen *scr, RImage *icon, int titled, int shadowed, int tileType)
253 RImage *tile;
254 Pixmap pixmap;
255 int x, y, sx, sy;
256 unsigned w, h;
257 int theight = scr->icon_title_font->height;
259 if (tileType == TILE_NORMAL)
260 tile = RCloneImage(scr->icon_tile);
261 else {
262 assert(scr->clip_tile);
263 tile = RCloneImage(scr->clip_tile);
265 if (icon) {
266 w = (icon->width > wPreferences.icon_size)
267 ? wPreferences.icon_size : icon->width;
268 x = (wPreferences.icon_size - w) / 2;
269 sx = (icon->width - w)/2;
271 if (!titled) {
272 h = (icon->height > wPreferences.icon_size)
273 ? wPreferences.icon_size : icon->height;
274 y = (wPreferences.icon_size - h) / 2;
275 sy = (icon->height - h)/2;
276 } else {
277 h = (icon->height+theight > wPreferences.icon_size
278 ? wPreferences.icon_size-theight : icon->height);
279 y = theight+((int)wPreferences.icon_size-theight-h)/2;
280 sy = (icon->height - h)/2;
282 RCombineArea(tile, icon, sx, sy, w, h, x, y);
285 if (shadowed) {
286 RColor color;
288 color.red = scr->icon_back_texture->light.red >> 8;
289 color.green = scr->icon_back_texture->light.green >> 8;
290 color.blue = scr->icon_back_texture->light.blue >> 8;
291 color.alpha = 150; /* about 60% */
292 RClearImage(tile, &color);
295 if (!RConvertImage(scr->rcontext, tile, &pixmap)) {
296 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
298 RDestroyImage(tile);
300 if (titled)
301 drawIconTitle(scr, pixmap, theight);
303 return pixmap;
307 void
308 wIconChangeTitle(WIcon *icon, char *new_title)
310 int changed;
312 changed = (new_title==NULL && icon->icon_name!=NULL)
313 || (new_title!=NULL && icon->icon_name==NULL);
315 if (icon->icon_name!=NULL)
316 XFree(icon->icon_name);
318 icon->icon_name = new_title;
320 if (changed)
321 icon->force_paint = 1;
322 wIconPaint(icon);
326 void
327 wIconChangeImage(WIcon *icon, RImage *new_image)
329 assert(icon != NULL);
331 if (icon->image)
332 RDestroyImage(icon->image);
334 icon->image = wIconValidateIconSize(icon->core->screen_ptr, new_image);
336 wIconUpdate(icon);
340 RImage*
341 wIconValidateIconSize(WScreen *scr, RImage *icon)
343 RImage *tmp;
344 int w, h;
346 if (!icon)
347 return NULL;
349 if (icon->width > wPreferences.icon_size
350 || icon->height > wPreferences.icon_size) {
351 if (icon->width > icon->height) {
352 w = wPreferences.icon_size - 4;
353 h = w*icon->height/icon->width;
354 } else {
355 h = wPreferences.icon_size - 4;
356 w = h*icon->width/icon->height;
358 tmp = RScaleImage(icon, w, h);
359 RDestroyImage(icon);
360 icon = tmp;
363 return icon;
367 Bool
368 wIconChangeImageFile(WIcon *icon, char *file)
370 WScreen *scr = icon->core->screen_ptr;
371 RImage *image;
372 char *path;
373 int error = 0;
375 if (!file) {
376 wIconChangeImage(icon, NULL);
377 return True;
380 path = FindImage(wPreferences.icon_path, file);
382 if (path && (image = RLoadImage(scr->rcontext, path, 0))) {
383 wIconChangeImage(icon, image);
384 } else {
385 error = 1;
388 if (path)
389 free(path);
391 return !error;
396 static char*
397 getnameforicon(WWindow *wwin)
399 char *prefix, *suffix;
400 char *path;
401 int len;
403 if (wwin->wm_class && wwin->wm_instance) {
404 suffix = wmalloc(strlen(wwin->wm_class)+strlen(wwin->wm_instance)+2);
405 sprintf(suffix, "%s.%s", wwin->wm_instance, wwin->wm_class);
406 } else if (wwin->wm_class) {
407 suffix = wmalloc(strlen(wwin->wm_class)+1);
408 strcpy(suffix, wwin->wm_class);
409 } else if (wwin->wm_instance) {
410 suffix = wmalloc(strlen(wwin->wm_instance)+1);
411 strcpy(suffix, wwin->wm_instance);
412 } else {
413 return NULL;
416 prefix = getenv("GNUSTEP_USER_PATH");
417 if (!prefix) {
418 len = strlen(wgethomedir())+64+strlen(suffix);
419 path = wmalloc(len+1);
420 sprintf(path, "%s/GNUstep/.AppInfo", wgethomedir());
421 } else {
422 prefix = wexpandpath(prefix);
423 len = strlen(prefix)+64+strlen(suffix);
424 path = wmalloc(len+1);
425 sprintf(path, "%s/.AppInfo", prefix);
426 free(prefix);
428 if (access(path, F_OK)!=0) {
429 if (mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR)) {
430 wsyserror(_("could not create directory %s"), path);
431 free(path);
432 free(suffix);
433 return NULL;
436 strcat(path, "/WindowMaker");
437 if (access(path, F_OK)!=0) {
438 if (mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR)!=0) {
439 wsyserror(_("could not create directory %s"), path);
440 free(path);
441 free(suffix);
442 return NULL;
446 strcat(path, "/");
447 strcat(path, suffix);
448 strcat(path, ".xpm");
449 free(suffix);
451 return path;
456 * wIconStore--
457 * Stores the client supplied icon at ~/GNUstep/.AppInfo/WindowMaker
458 * and returns the path for that icon. Returns NULL if there is no
459 * client supplied icon or on failure.
461 * Side effects:
462 * New directories might be created.
464 char*
465 wIconStore(WIcon *icon)
467 char *path;
468 RImage *image;
469 WWindow *wwin = icon->owner;
471 if (!wwin || !wwin->wm_hints || !(wwin->wm_hints->flags & IconPixmapHint)
472 || wwin->wm_hints->icon_pixmap == None)
473 return NULL;
475 path = getnameforicon(wwin);
476 if (!path)
477 return NULL;
479 image = RCreateImageFromDrawable(icon->core->screen_ptr->rcontext,
480 wwin->wm_hints->icon_pixmap,
481 (wwin->wm_hints->flags & IconMaskHint)
482 ? wwin->wm_hints->icon_mask : None);
483 if (!image) {
484 free(path);
485 return NULL;
488 if (!RSaveImage(image, path, "XPM")) {
489 free(path);
490 path = NULL;
492 RDestroyImage(image);
494 return path;
499 void
500 wIconChangeIconWindow(WIcon *icon, Window new_window);
503 static void
504 cycleColor(void *data)
506 WIcon *icon = (WIcon*)data;
507 WScreen *scr = icon->core->screen_ptr;
508 XGCValues gcv;
510 icon->step--;
511 gcv.dash_offset = icon->step;
512 XChangeGC(dpy, scr->icon_select_gc, GCDashOffset, &gcv);
514 XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
515 icon->core->width-1, icon->core->height-1);
516 icon->handlerID = WMAddTimerHandler(COLOR_CYCLE_DELAY, cycleColor, icon);
520 void
521 wIconSetHighlited(WIcon *icon, Bool flag)
523 if (icon->highlighted == flag) {
524 return;
527 icon->highlighted = flag;
528 wIconPaint(icon);
533 void
534 wIconSelect(WIcon *icon)
536 WScreen *scr = icon->core->screen_ptr;
537 icon->selected = !icon->selected;
539 if (icon->selected) {
540 icon->step = 0;
541 if (!wPreferences.dont_blink)
542 icon->handlerID = WMAddTimerHandler(10, cycleColor, icon);
543 else
544 XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
545 icon->core->width-1, icon->core->height-1);
546 } else {
547 if (icon->handlerID) {
548 WMDeleteTimerHandler(icon->handlerID);
549 icon->handlerID = NULL;
551 XClearArea(dpy, icon->core->window, 0, 0, icon->core->width,
552 icon->core->height, True);
557 void
558 wIconUpdate(WIcon *icon)
560 WScreen *scr = icon->core->screen_ptr;
561 int title_height = scr->icon_title_font->height;
562 WWindow *wwin = icon->owner;
564 assert(scr->icon_tile!=NULL);
566 if (icon->pixmap!=None)
567 XFreePixmap(dpy, icon->pixmap);
568 icon->pixmap = None;
571 if (wwin && WFLAGP(wwin, always_user_icon))
572 goto user_icon;
574 /* use client specified icon window */
575 if (icon->icon_win!=None) {
576 XWindowAttributes attr;
577 int resize=0;
578 int width, height, depth;
579 int theight;
580 Pixmap pixmap;
582 getSize(icon->icon_win, &width, &height, &depth);
584 if (width > wPreferences.icon_size) {
585 resize = 1;
586 width = wPreferences.icon_size;
588 if (height > wPreferences.icon_size) {
589 resize = 1;
590 height = wPreferences.icon_size;
592 if (icon->show_title
593 && (height+title_height < wPreferences.icon_size)) {
594 pixmap = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
595 wPreferences.icon_size, scr->w_depth);
596 XSetClipMask(dpy, scr->copy_gc, None);
597 XCopyArea(dpy, scr->icon_tile_pixmap, pixmap, scr->copy_gc, 0, 0,
598 wPreferences.icon_size, wPreferences.icon_size, 0, 0);
599 drawIconTitle(scr, pixmap, title_height);
600 theight = title_height;
601 } else {
602 pixmap = None;
603 theight = 0;
604 XSetWindowBackgroundPixmap(dpy, icon->core->window,
605 scr->icon_tile_pixmap);
608 XSetWindowBorderWidth(dpy, icon->icon_win, 0);
609 XReparentWindow(dpy, icon->icon_win, icon->core->window,
610 (wPreferences.icon_size-width)/2,
611 theight+(wPreferences.icon_size-height-theight)/2);
612 if (resize)
613 XResizeWindow(dpy, icon->icon_win, width, height);
615 XMapWindow(dpy, icon->icon_win);
617 XAddToSaveSet(dpy, icon->icon_win);
619 icon->pixmap = pixmap;
621 if (XGetWindowAttributes(dpy, icon->icon_win, &attr)) {
622 if (attr.all_event_masks & ButtonPressMask) {
623 wHackedGrabButton(Button1, MOD_MASK, icon->core->window, True,
624 ButtonPressMask, GrabModeSync, GrabModeAsync,
625 None, wCursor[WCUR_ARROW]);
628 } else if (wwin && wwin->wm_hints
629 && (wwin->wm_hints->flags & IconPixmapHint)) {
630 int x, y;
631 unsigned int w, h;
632 Window jw;
633 int ji, dotitle;
634 unsigned int ju, d;
635 Pixmap pixmap;
637 if (!XGetGeometry(dpy, wwin->wm_hints->icon_pixmap, &jw,
638 &ji, &ji, &w, &h, &ju, &d)) {
639 icon->owner->wm_hints->flags &= ~IconPixmapHint;
640 goto user_icon;
643 pixmap = XCreatePixmap(dpy, icon->core->window, wPreferences.icon_size,
644 wPreferences.icon_size, scr->w_depth);
645 XSetClipMask(dpy, scr->copy_gc, None);
646 XCopyArea(dpy, scr->icon_tile_pixmap, pixmap, scr->copy_gc, 0, 0,
647 wPreferences.icon_size, wPreferences.icon_size, 0, 0);
649 if (w > wPreferences.icon_size)
650 w = wPreferences.icon_size;
651 x = (wPreferences.icon_size-w)/2;
653 if (icon->show_title && (title_height < wPreferences.icon_size)) {
654 drawIconTitle(scr, pixmap, title_height);
655 dotitle = 1;
657 if (h > wPreferences.icon_size - title_height - 2) {
658 h = wPreferences.icon_size - title_height - 2;
659 y = title_height + 1;
660 } else {
661 y = (wPreferences.icon_size-h-title_height)/2+title_height + 1;
663 } else {
664 dotitle = 0;
665 if (w > wPreferences.icon_size)
666 w = wPreferences.icon_size;
667 y = (wPreferences.icon_size-h)/2;
670 if (wwin->wm_hints->flags & IconMaskHint)
671 XSetClipMask(dpy, scr->copy_gc, wwin->wm_hints->icon_mask);
673 XSetClipOrigin(dpy, scr->copy_gc, x, y);
675 if (d != scr->w_depth) {
676 XSetForeground(dpy, scr->copy_gc, scr->black_pixel);
677 XSetBackground(dpy, scr->copy_gc, scr->white_pixel);
678 XCopyPlane(dpy, wwin->wm_hints->icon_pixmap, pixmap, scr->copy_gc,
679 0, 0, w, h, x, y, 1);
680 } else {
681 XCopyArea(dpy, wwin->wm_hints->icon_pixmap, pixmap, scr->copy_gc,
682 0, 0, w, h, x, y);
685 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
687 icon->pixmap = pixmap;
688 } else {
689 user_icon:
691 if (icon->image) {
692 icon->pixmap = makeIcon(scr, icon->image, icon->show_title,
693 icon->shadowed, icon->tile_type);
694 } else {
695 /* make default icons */
697 if (!scr->def_icon_pixmap) {
698 RImage *image = NULL;
699 char *path;
700 char *file;
702 file = wDefaultGetIconFile(scr, NULL, NULL, False);
703 if (file) {
704 path = FindImage(wPreferences.icon_path, file);
705 if (!path) {
706 wwarning(_("could not find default icon \"%s\""),file);
707 goto make_icons;
710 image = RLoadImage(scr->rcontext, path, 0);
711 if (!image) {
712 wwarning(_("could not load default icon \"%s\":%s"),
713 file, RMessageForError(RErrorCode));
715 free(path);
717 make_icons:
719 image = wIconValidateIconSize(scr, image);
720 scr->def_icon_pixmap = makeIcon(scr, image, False, False,
721 icon->tile_type);
722 scr->def_ticon_pixmap = makeIcon(scr, image, True, False,
723 icon->tile_type);
724 if (image)
725 RDestroyImage(image);
728 if (icon->show_title) {
729 XSetWindowBackgroundPixmap(dpy, icon->core->window,
730 scr->def_ticon_pixmap);
731 } else {
732 XSetWindowBackgroundPixmap(dpy, icon->core->window,
733 scr->def_icon_pixmap);
735 icon->pixmap = None;
738 if (icon->pixmap != None) {
739 XSetWindowBackgroundPixmap(dpy, icon->core->window, icon->pixmap);
741 XClearWindow(dpy, icon->core->window);
743 wIconPaint(icon);
748 void
749 wIconPaint(WIcon *icon)
751 WScreen *scr=icon->core->screen_ptr;
752 GC gc = scr->icon_title_gc;
753 int x;
754 char *tmp;
756 if (icon->force_paint) {
757 icon->force_paint = 0;
758 wIconUpdate(icon);
759 return;
762 XClearWindow(dpy, icon->core->window);
764 /* draw the icon title */
765 if (icon->show_title && icon->icon_name!=NULL) {
766 int l;
767 int w;
769 tmp = ShrinkString(scr->icon_title_font, icon->icon_name,
770 wPreferences.icon_size-4);
771 w = wTextWidth(scr->icon_title_font->font, tmp, l=strlen(tmp));
773 if (w > icon->core->width - 4)
774 x = (icon->core->width - 4) - w;
775 else
776 x = (icon->core->width - w)/2;
778 wDrawString(icon->core->window, scr->icon_title_font, gc,
779 x, 1 + scr->icon_title_font->y, tmp, l);
780 free(tmp);
783 if (icon->selected)
784 XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
785 icon->core->width-1, icon->core->height-1);
789 /******************************************************************/
791 static void
792 miniwindowExpose(WObjDescriptor *desc, XEvent *event)
794 wIconPaint(desc->parent);
798 static void
799 miniwindowDblClick(WObjDescriptor *desc, XEvent *event)
801 WIcon *icon = desc->parent;
803 assert(icon->owner!=NULL);
805 wDeiconifyWindow(icon->owner);
809 static void
810 miniwindowMouseDown(WObjDescriptor *desc, XEvent *event)
812 WIcon *icon = desc->parent;
813 WWindow *wwin = icon->owner;
814 XEvent ev;
815 int x=wwin->icon_x, y=wwin->icon_y;
816 int dx=event->xbutton.x, dy=event->xbutton.y;
817 int grabbed=0;
818 int clickButton=event->xbutton.button;
821 if (IsDoubleClick(icon->core->screen_ptr, event)) {
822 miniwindowDblClick(desc, event);
823 return;
826 #ifdef DEBUG
827 puts("Moving miniwindow");
828 #endif
829 if (event->xbutton.button==Button1) {
830 if (event->xbutton.state & MOD_MASK)
831 wLowerFrame(icon->core);
832 else
833 wRaiseFrame(icon->core);
834 if (event->xbutton.state & ShiftMask) {
835 wIconSelect(icon);
836 wSelectWindow(icon->owner, !wwin->flags.selected);
839 #if 0
840 else if (event->xbutton.button==Button3) {
841 WObjDescriptor *desc;
843 OpenMiniwindowMenu(wwin, event->xbutton.x_root,
844 event->xbutton.y_root);
846 /* allow drag select of menu */
847 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
848 event->xbutton.send_event = True;
849 (*desc->handle_mousedown)(desc, event);
851 return;
853 #endif
854 if (XGrabPointer(dpy, icon->core->window, False, ButtonMotionMask
855 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
856 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
857 #ifdef DEBUG0
858 wwarning("pointer grab failed for icon move");
859 #endif
861 while(1) {
862 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
863 |ButtonMotionMask|ExposureMask, &ev);
864 switch (ev.type) {
865 case Expose:
866 WMHandleEvent(&ev);
867 break;
869 case MotionNotify:
870 if (!grabbed) {
871 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
872 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
873 XChangeActivePointerGrab(dpy, ButtonMotionMask
874 |ButtonReleaseMask|ButtonPressMask,
875 wCursor[WCUR_MOVE], CurrentTime);
876 grabbed=1;
877 } else {
878 break;
881 x = ev.xmotion.x_root - dx;
882 y = ev.xmotion.y_root - dy;
883 XMoveWindow(dpy, icon->core->window, x, y);
884 break;
886 case ButtonPress:
887 break;
889 case ButtonRelease:
890 if (ev.xbutton.button != clickButton)
891 break;
893 if (wwin->icon_x!=x || wwin->icon_y!=y)
894 wwin->flags.icon_moved = 1;
896 XMoveWindow(dpy, icon->core->window, x, y);
898 wwin->icon_x = x;
899 wwin->icon_y = y;
900 #ifdef DEBUG
901 puts("End miniwindow move");
902 #endif
903 XUngrabPointer(dpy, CurrentTime);
904 return;