xdnd drop support on dock.
[wmaker-crm.git] / src / appicon.c
blobe55e8574d943e47913da27e02c36090d6ccfeab0
1 /* appicon.c- icon for applications (not mini-window)
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <string.h>
31 #include "WindowMaker.h"
32 #include "wcore.h"
33 #include "window.h"
34 #include "icon.h"
35 #include "appicon.h"
36 #include "actions.h"
37 #include "stacking.h"
38 #include "dock.h"
39 #include "funcs.h"
40 #include "defaults.h"
41 #include "workspace.h"
42 #include "superfluous.h"
43 #include "menu.h"
44 #include "framewin.h"
45 #include "dialog.h"
46 #include "client.h"
47 #ifdef XDND
48 #include "xdnd.h"
49 #endif
52 * icon_file for the dock is got from the preferences file by
53 * using the classname/instancename
56 /**** Global variables ****/
57 extern Cursor wCursor[WCUR_LAST];
58 extern WPreferences wPreferences;
60 #define MOD_MASK wPreferences.modifier_mask
62 void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
63 static void iconDblClick(WObjDescriptor *desc, XEvent *event);
64 static void iconExpose(WObjDescriptor *desc, XEvent *event);
68 WAppIcon*
69 wAppIconCreateForDock(WScreen *scr, char *command, char *wm_instance,
70 char *wm_class, int tile)
72 WAppIcon *dicon;
73 char *path;
75 dicon = wmalloc(sizeof(WAppIcon));
76 wretain(dicon);
77 memset(dicon, 0, sizeof(WAppIcon));
78 dicon->yindex = -1;
79 dicon->xindex = -1;
81 dicon->prev = NULL;
82 dicon->next = scr->app_icon_list;
83 if (scr->app_icon_list) {
84 scr->app_icon_list->prev = dicon;
86 scr->app_icon_list = dicon;
88 if (command) {
89 dicon->command = wstrdup(command);
91 if (wm_class)
92 dicon->wm_class = wstrdup(wm_class);
93 if (wm_instance)
94 dicon->wm_instance = wstrdup(wm_instance);
96 path = wDefaultGetIconFile(scr, wm_instance, wm_class, True);
97 if (!path && command) {
98 wApplicationExtractDirPackIcon(scr, command, wm_instance, wm_class);
100 path = wDefaultGetIconFile(scr, wm_instance, wm_class, False);
103 if (path)
104 path = FindImage(wPreferences.icon_path, path);
106 dicon->icon = wIconCreateWithIconFile(scr, path, tile);
107 if (path)
108 free(path);
109 #ifdef XDND
110 wXDNDMakeAwareness(dicon->icon->core->window);
111 #endif
112 #ifdef REDUCE_APPICONS
113 dicon->num_apps = 0;
114 #endif
115 #ifdef DEMATERIALIZE_ICON
117 XSetWindowAttributes attribs;
118 attribs.save_under = True;
119 XChangeWindowAttributes(dpy, dicon->icon->core->window,
120 CWSaveUnder, &attribs);
122 #endif
124 /* will be overriden by dock */
125 dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
126 dicon->icon->core->descriptor.handle_expose = iconExpose;
127 dicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
128 dicon->icon->core->descriptor.parent = dicon;
129 AddToStackList(dicon->icon->core);
131 return dicon;
136 WAppIcon*
137 wAppIconCreate(WWindow *leader_win)
139 WAppIcon *aicon;
140 #ifdef REDUCE_APPICONS
141 WAppIcon *atmp;
142 WAppIconAppList *applist;
143 char *tinstance, *tclass;
144 #endif
145 WScreen *scr = leader_win->screen_ptr;
147 aicon = wmalloc(sizeof(WAppIcon));
148 wretain(aicon);
149 memset(aicon, 0, sizeof(WAppIcon));
150 #ifdef REDUCE_APPICONS
151 applist = wmalloc(sizeof(WAppIconAppList));
152 memset(applist, 0, sizeof(WAppIconAppList));
153 applist->wapp = wApplicationOf(leader_win->main_window);
154 aicon->applist = applist;
155 if (applist->wapp == NULL) {
156 /* Something's wrong. wApplicationOf() should always return a
157 * valid structure. Rather than violate assumptions, bail. -cls
159 free(applist);
160 wrelease(aicon);
161 return NULL;
163 #endif
165 aicon->yindex = -1;
166 aicon->xindex = -1;
168 aicon->prev = NULL;
169 aicon->next = scr->app_icon_list;
170 if (scr->app_icon_list) {
171 #ifndef REDUCE_APPICONS
172 scr->app_icon_list->prev = aicon;
173 #else
174 /* If we aren't going to have a match, jump straight to new appicon */
175 if (leader_win->wm_class == NULL || leader_win->wm_class == NULL)
176 atmp = NULL;
177 else
178 atmp = scr->app_icon_list;
180 while (atmp != NULL) {
181 if ((tinstance = atmp->wm_instance) == NULL)
182 tinstance = "";
183 if ((tclass = atmp->wm_class) == NULL)
184 tclass = "";
185 if ((strcmp(leader_win->wm_class, tclass) == 0) &&
186 (strcmp(leader_win->wm_instance, tinstance) == 0))
188 /* We have a winner */
189 wrelease(aicon);
190 atmp->num_apps++;
191 applist->next = atmp->applist;
192 if (atmp->applist)
193 atmp->applist->prev = applist;
194 atmp->applist = applist;
196 if (atmp->docked) {
197 wDockSimulateLaunch(atmp->dock, atmp);
200 return atmp;
202 atmp = atmp->next;
204 if (atmp == NULL) {
205 scr->app_icon_list->prev = aicon;
207 #endif /* REDUCE_APPICONS */
209 scr->app_icon_list = aicon;
211 if (leader_win->wm_class)
212 aicon->wm_class = wstrdup(leader_win->wm_class);
213 if (leader_win->wm_instance)
214 aicon->wm_instance = wstrdup(leader_win->wm_instance);
215 #ifdef REDUCE_APPICONS
216 aicon->num_apps = 1;
217 #endif
219 aicon->icon = wIconCreate(leader_win);
220 #ifdef DEMATERIALIZE_ICON
222 XSetWindowAttributes attribs;
223 attribs.save_under = True;
224 XChangeWindowAttributes(dpy, aicon->icon->core->window,
225 CWSaveUnder, &attribs);
227 #endif
228 #ifdef XDND
229 wXDNDMakeAwareness(aicon->icon->core->window);
230 #endif
232 /* will be overriden if docked */
233 aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
234 aicon->icon->core->descriptor.handle_expose = iconExpose;
235 aicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
236 aicon->icon->core->descriptor.parent = aicon;
237 AddToStackList(aicon->icon->core);
238 aicon->icon->show_title = 0;
239 wIconUpdate(aicon->icon);
241 return aicon;
245 void
246 wAppIconDestroy(WAppIcon *aicon)
248 WScreen *scr = aicon->icon->core->screen_ptr;
249 #ifdef REDUCE_APPICONS
250 WAppIconAppList *aptmp;
251 #endif
253 RemoveFromStackList(aicon->icon->core);
254 wIconDestroy(aicon->icon);
255 if (aicon->command)
256 free(aicon->command);
257 #ifdef OFFIX_DND
258 if (aicon->dnd_command)
259 free(aicon->dnd_command);
260 #endif
261 if (aicon->wm_instance)
262 free(aicon->wm_instance);
263 if (aicon->wm_class)
264 free(aicon->wm_class);
265 #ifdef REDUCE_APPICONS
266 /* There should never be a list but just in case */
267 if (aicon->applist != NULL) {
268 aptmp = aicon->applist;
269 while (aptmp->next) {
270 aptmp = aptmp->next;
271 free(aptmp->prev);
273 free(aptmp);
275 #endif
277 if (aicon == scr->app_icon_list) {
278 if (aicon->next)
279 aicon->next->prev = NULL;
280 scr->app_icon_list = aicon->next;
282 else {
283 if (aicon->next)
284 aicon->next->prev = aicon->prev;
285 if (aicon->prev)
286 aicon->prev->next = aicon->next;
289 aicon->destroyed = 1;
290 wrelease(aicon);
295 #ifdef NEWAPPICON
296 static void
297 drawCorner(WIcon *icon, WWindow *wwin, int active)
299 WScreen *scr = wwin->screen_ptr;
300 XPoint points[3];
301 GC gc;
303 points[0].x = 2;
304 points[0].y = 2;
305 points[1].x = 12;
306 points[1].y = 2;
307 points[2].x = 2;
308 points[2].y = 12;
309 if (active) {
310 gc=scr->focused_texture->any.gc;
311 } else {
312 gc=scr->unfocused_texture->any.gc;
314 XFillPolygon(dpy, icon->core->window, gc, points, 3,
315 Convex, CoordModeOrigin);
317 #endif /* NEWAPPICON */
320 void
321 wAppIconMove(WAppIcon *aicon, int x, int y)
323 XMoveWindow(dpy, aicon->icon->core->window, x, y);
324 aicon->x_pos = x;
325 aicon->y_pos = y;
329 #ifdef WS_INDICATOR
330 static void
331 updateDockNumbers(WScreen *scr)
333 int length;
334 char *ws_numbers;
335 GC numbers_gc;
336 XGCValues my_gc_values;
337 unsigned long my_v_mask = (GCForeground);
338 WAppIcon *dicon = scr->dock->icon_array[0];
340 my_gc_values.foreground = scr->white_pixel;
341 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
342 my_v_mask, &my_gc_values);
344 ws_numbers = malloc(20);
345 sprintf(ws_numbers, "%i [ %i ]", scr->current_workspace+1,
346 ((scr->current_workspace/10)+1));
347 length = strlen(ws_numbers);
349 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
350 scr->icon_title_font->y+1, False);
352 #ifndef I18N_MB
353 XSetFont(dpy, numbers_gc, scr->icon_title_font->font->fid);
354 XSetForeground(dpy, numbers_gc, scr->black_pixel);
355 XDrawString(dpy, dicon->icon->core->window,
356 numbers_gc, 4, scr->icon_title_font->y+3, ws_numbers, length);
357 XSetForeground(dpy, numbers_gc, scr->white_pixel);
358 XDrawString(dpy, dicon->icon->core->window,
359 numbers_gc, 3, scr->icon_title_font->y+2, ws_numbers, length);
360 #else
361 XSetForeground(dpy, numbers_gc, scr->black_pixel);
362 XmbDrawString(dpy, dicon->icon->core->window,
363 scr->icon_title_font->font, numbers_gc, 4,
364 scr->icon_title_font->y+3, ws_numbers, length);
365 XSetForeground(dpy, numbers_gc, scr->white_pixel);
366 XmbDrawString(dpy, dicon->icon->core->window,
367 scr->icon_title_font->font, numbers_gc, 3,
368 scr->icon_title_font->y+2, ws_numbers, length);
369 #endif /* I18N_MB */
371 XFreeGC(dpy, numbers_gc);
372 free(ws_numbers);
374 #endif /* WS_INDICATOR */
377 void
378 wAppIconPaint(WAppIcon *aicon)
380 WScreen *scr = aicon->icon->core->screen_ptr;
382 wIconPaint(aicon->icon);
385 # ifdef WS_INDICATOR
386 if (aicon->docked && scr->dock && aicon->yindex==0)
387 updateDockNumbers(scr);
388 # endif
389 if (scr->dock_dots && aicon->docked && !aicon->running
390 && aicon->command!=NULL) {
391 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
392 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
393 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
394 scr->copy_gc, 0, 0, scr->dock_dots->width,
395 scr->dock_dots->height, 0, 0);
398 #ifdef HIDDENDOT
400 WApplication *wapp;
401 wapp = wApplicationOf(aicon->main_window);
402 if (wapp && wapp->flags.hidden) {
403 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
404 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
405 XCopyArea(dpy, scr->dock_dots->image,
406 aicon->icon->core->window,
407 scr->copy_gc, 0, 0, 7,
408 scr->dock_dots->height, 0, 0);
411 #endif /* HIDDENDOT */
413 #ifdef NEWAPPICON
414 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
415 int active=0;
416 if (aicon->main_window==None) {
417 active = (aicon->icon->owner->flags.focused ? 1 : 0);
418 } else {
419 WApplication *wapp;
421 wapp = wApplicationOf(aicon->main_window);
422 if (!wapp) {
423 active = aicon->icon->owner->flags.focused;
424 wwarning("error in wAppIconPaint(). Please report it");
425 } else {
426 active = wapp->main_window_desc->flags.focused;
427 if (wapp->main_window_desc->flags.hidden
428 || !wapp->main_window_desc->flags.mapped)
429 active = -1;
432 if (active>=0)
433 drawCorner(aicon->icon, aicon->icon->owner, active);
435 #endif /* NEWAPPICON */
437 XSetClipMask(dpy, scr->copy_gc, None);
438 if (aicon->launching) {
439 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
440 0, 0, wPreferences.icon_size, wPreferences.icon_size);
446 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
448 #ifdef REDUCE_APPICONS
449 unsigned int
450 wAppIconReduceAppCount(WApplication *wapp)
452 WAppIconAppList *applist;
454 if (wapp == NULL)
455 return 0;
457 if (wapp->app_icon == NULL)
458 return 0;
460 /* If given a main window, check the applist
461 * and remove the if it exists
463 applist = wapp->app_icon->applist;
464 while (applist != NULL) {
465 if (applist->wapp == wapp) {
466 /* If this app owns the appicon, change the appicon's
467 * owner to the next app in the list or NULL
469 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
471 if (applist->next) {
472 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
473 } else if (applist->prev) {
474 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
475 } else {
476 wapp->app_icon->icon->owner = NULL;
479 if (applist->prev)
480 applist->prev->next = applist->next;
482 if (applist->next)
483 applist->next->prev = applist->prev;
485 if (applist == wapp->app_icon->applist)
486 wapp->app_icon->applist = applist->next;
488 free(applist);
490 if (wapp->app_icon->applist != NULL)
491 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
493 return (--wapp->app_icon->num_apps);
495 applist = applist->next;
497 return (--wapp->app_icon->num_apps);
499 #endif
502 static void
503 hideCallback(WMenu *menu, WMenuEntry *entry)
505 WApplication *wapp = (WApplication*)entry->clientdata;
507 if (wapp->flags.hidden) {
508 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
509 wUnhideApplication(wapp, False, False);
510 } else {
511 wHideApplication(wapp);
516 static void
517 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
519 WApplication *wapp = (WApplication*)entry->clientdata;
521 wUnhideApplication(wapp, False, True);
525 static void
526 setIconCallback(WMenu *menu, WMenuEntry *entry)
528 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
529 char *file=NULL;
530 WScreen *scr;
531 int result;
533 assert(icon!=NULL);
535 if (icon->editing)
536 return;
537 icon->editing = 1;
538 scr = icon->icon->core->screen_ptr;
540 wretain(icon);
542 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
544 if (result && !icon->destroyed) {
545 if (file[0]==0) {
546 free(file);
547 file = NULL;
549 if (!wIconChangeImageFile(icon->icon, file)) {
550 wMessageDialog(scr, _("Error"),
551 _("Could not open specified icon file"),
552 _("OK"), NULL, NULL);
553 } else {
554 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
555 wAppIconPaint(icon);
557 if (file)
558 free(file);
560 icon->editing = 0;
561 wrelease(icon);
565 static void
566 killCallback(WMenu *menu, WMenuEntry *entry)
568 WApplication *wapp = (WApplication*)entry->clientdata;
569 char *buffer;
571 if (!WCHECK_STATE(WSTATE_NORMAL))
572 return;
574 WCHANGE_STATE(WSTATE_MODAL);
576 assert(entry->clientdata!=NULL);
578 buffer = wstrappend(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
579 _(" will be forcibly closed.\n"
580 "Any unsaved changes will be lost.\n"
581 "Please confirm."));
583 wretain(wapp->main_window_desc);
584 if (wPreferences.dont_confirm_kill
585 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
586 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
587 if (!wapp->main_window_desc->flags.destroyed)
588 wClientKill(wapp->main_window_desc);
590 wrelease(wapp->main_window_desc);
592 free(buffer);
594 WCHANGE_STATE(WSTATE_NORMAL);
598 static WMenu*
599 createApplicationMenu(WScreen *scr)
601 WMenu *menu;
603 menu = wMenuCreate(scr, NULL, False);
604 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
605 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
606 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
607 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
609 return menu;
613 static void
614 openApplicationMenu(WApplication *wapp, int x, int y)
616 WMenu *menu;
617 WScreen *scr = wapp->main_window_desc->screen_ptr;
618 int i;
620 if (!scr->icon_menu) {
621 scr->icon_menu = createApplicationMenu(scr);
622 free(scr->icon_menu->entries[1]->text);
625 menu = scr->icon_menu;
627 if (wapp->flags.hidden) {
628 menu->entries[1]->text = _("Unhide");
629 } else {
630 menu->entries[1]->text = _("Hide");
633 menu->flags.realized = 0;
634 wMenuRealize(menu);
636 x -= menu->frame->core->width/2;
637 if (x + menu->frame->core->width > scr->scr_width)
638 x = scr->scr_width - menu->frame->core->width;
639 if (x < 0)
640 x = 0;
642 /* set client data */
643 for (i = 0; i < menu->entry_no; i++) {
644 menu->entries[i]->clientdata = wapp;
646 wMenuMapAt(menu, x, y, False);
650 /******************************************************************/
652 static void
653 iconExpose(WObjDescriptor *desc, XEvent *event)
655 wAppIconPaint(desc->parent);
659 static void
660 iconDblClick(WObjDescriptor *desc, XEvent *event)
662 WAppIcon *aicon = desc->parent;
663 WApplication *wapp;
664 WScreen *scr = aicon->icon->core->screen_ptr;
665 int unhideHere;
667 #ifndef REDUCE_APPICONS
668 assert(aicon->icon->owner!=NULL);
669 #else
670 if (aicon->icon->owner == NULL) {
671 fprintf(stderr, "Double-click disabled: missing main window.\n");
672 return;
674 #endif
676 wapp = wApplicationOf(aicon->icon->owner->main_window);
677 #ifdef DEBUG0
678 if (!wapp) {
679 wwarning("could not find application descriptor for app icon!!");
680 return;
682 #endif
683 #ifdef REDUCE_APPICONS
684 if (!wapp) {
685 fprintf(stderr, "Double-click disabled: missing wapp.\n");
686 return;
688 #endif /* REDUCE_APPICONS */
690 unhideHere = (event->xbutton.state & ShiftMask);
692 /* go to the last workspace that the user worked on the app */
693 if (!unhideHere && wapp->last_workspace != scr->current_workspace)
694 wWorkspaceChange(scr, wapp->last_workspace);
696 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
698 if (event->xbutton.state & MOD_MASK) {
699 wHideOtherApplications(aicon->icon->owner);
704 void
705 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
707 WAppIcon *aicon = desc->parent;
708 WIcon *icon = aicon->icon;
709 XEvent ev;
710 int x=aicon->x_pos, y=aicon->y_pos;
711 int dx=event->xbutton.x, dy=event->xbutton.y;
712 int grabbed=0;
713 int done=0;
714 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
715 WScreen *scr = icon->core->screen_ptr;
716 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
717 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
718 int ix, iy;
719 int clickButton = event->xbutton.button;
720 Pixmap ghost = None;
721 Window wins[2];
723 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
724 return;
726 if (IsDoubleClick(scr, event)) {
727 iconDblClick(desc, event);
728 return;
731 if (event->xbutton.button == Button3) {
732 WObjDescriptor *desc;
733 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
735 if (!wapp)
736 return;
738 openApplicationMenu(wapp, event->xbutton.x_root,
739 event->xbutton.y_root);
741 /* allow drag select of menu */
742 desc = &scr->icon_menu->menu->descriptor;
743 event->xbutton.send_event = True;
744 (*desc->handle_mousedown)(desc, event);
745 return;
748 #ifdef DEBUG
749 puts("Moving icon");
750 #endif
751 if (event->xbutton.state & MOD_MASK)
752 wLowerFrame(icon->core);
753 else
754 wRaiseFrame(icon->core);
757 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
758 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
759 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
760 wwarning("pointer grab failed for appicon move");
763 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
764 dockable = 0;
765 else
766 dockable = canBeDocked(icon->owner);
768 wins[0] = icon->core->window;
769 wins[1] = scr->dock_shadow;
770 XRestackWindows(dpy, wins, 2);
771 if (superfluous) {
772 if (icon->pixmap!=None)
773 ghost = MakeGhostIcon(scr, icon->pixmap);
774 else
775 ghost = MakeGhostIcon(scr, icon->core->window);
776 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
777 ghost);
778 XClearWindow(dpy, scr->dock_shadow);
781 while (!done) {
782 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
783 |ButtonMotionMask|ExposureMask, &ev);
784 switch (ev.type) {
785 case Expose:
786 WMHandleEvent(&ev);
787 break;
789 case MotionNotify:
790 if (!grabbed) {
791 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
792 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
793 XChangeActivePointerGrab(dpy, ButtonMotionMask
794 |ButtonReleaseMask|ButtonPressMask,
795 wCursor[WCUR_MOVE], CurrentTime);
796 grabbed=1;
797 } else {
798 break;
801 x = ev.xmotion.x_root - dx;
802 y = ev.xmotion.y_root - dy;
803 XMoveWindow(dpy, icon->core->window, x, y);
805 if (dockable) {
806 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
807 &ix, &iy, False)) {
808 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
809 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
811 if (scr->last_dock != scr->dock && collapsed) {
812 scr->last_dock->collapsed = 1;
813 wDockHideIcons(scr->last_dock);
814 collapsed = 0;
816 if (!collapsed && (collapsed = scr->dock->collapsed)) {
817 scr->dock->collapsed = 0;
818 wDockShowIcons(scr->dock);
821 if (scr->dock->auto_raise_lower)
822 wDockRaise(scr->dock);
824 scr->last_dock = scr->dock;
826 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
827 if (!docking) {
828 XMapWindow(dpy, scr->dock_shadow);
830 docking = 1;
831 } else if (workspace->clip &&
832 wDockSnapIcon(workspace->clip, aicon, x, y,
833 &ix, &iy, False)) {
834 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
835 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
837 if (scr->last_dock != workspace->clip && collapsed) {
838 scr->last_dock->collapsed = 1;
839 wDockHideIcons(scr->last_dock);
840 collapsed = 0;
842 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
843 workspace->clip->collapsed = 0;
844 wDockShowIcons(workspace->clip);
847 if (workspace->clip->auto_raise_lower)
848 wDockRaise(workspace->clip);
850 scr->last_dock = workspace->clip;
852 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
853 if (!docking) {
854 XMapWindow(dpy, scr->dock_shadow);
856 docking = 1;
857 } else if (docking) {
858 XUnmapWindow(dpy, scr->dock_shadow);
859 docking = 0;
863 break;
865 case ButtonPress:
866 break;
868 case ButtonRelease:
869 if (ev.xbutton.button != clickButton)
870 break;
871 XUngrabPointer(dpy, CurrentTime);
873 if (docking) {
874 Bool docked;
876 /* icon is trying to be docked */
877 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
878 XUnmapWindow(dpy, scr->dock_shadow);
879 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
880 if (scr->last_dock->auto_collapse) {
881 collapsed = 0;
883 if (workspace->clip &&
884 workspace->clip != scr->last_dock &&
885 workspace->clip->auto_raise_lower)
886 wDockLower(workspace->clip);
888 if (!docked) {
889 /* If icon could not be docked, slide it back to the old
890 * position */
891 SlideWindow(icon->core->window, x, y, aicon->x_pos,
892 aicon->y_pos);
894 } else {
895 XMoveWindow(dpy, icon->core->window, x, y);
896 aicon->x_pos = x;
897 aicon->y_pos = y;
898 if (workspace->clip && workspace->clip->auto_raise_lower)
899 wDockLower(workspace->clip);
901 if (collapsed) {
902 scr->last_dock->collapsed = 1;
903 wDockHideIcons(scr->last_dock);
904 collapsed = 0;
906 if (superfluous) {
907 if (ghost!=None)
908 XFreePixmap(dpy, ghost);
909 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
912 if (wPreferences.auto_arrange_icons)
913 wArrangeIcons(scr, True);
915 done = 1;
916 break;
919 #ifdef DEBUG
920 puts("End icon move");
921 #endif