bug fixes
[wmaker-crm.git] / src / appicon.c
blob87b8c6072325d016e61eb874cbcc0ed26077506c
1 /* appicon.c- icon for applications (not mini-window)
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
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"
48 /*
49 * icon_file for the dock is got from the preferences file by
50 * using the classname/instancename
53 /**** Global variables ****/
54 extern Cursor wCursor[WCUR_LAST];
55 extern WPreferences wPreferences;
57 #define MOD_MASK wPreferences.modifier_mask
59 void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
60 static void iconDblClick(WObjDescriptor *desc, XEvent *event);
61 static void iconExpose(WObjDescriptor *desc, XEvent *event);
65 WAppIcon*
66 wAppIconCreateForDock(WScreen *scr, char *command, char *wm_instance,
67 char *wm_class, int tile)
69 WAppIcon *dicon;
70 char *path;
72 dicon = wmalloc(sizeof(WAppIcon));
73 wretain(dicon);
74 memset(dicon, 0, sizeof(WAppIcon));
75 dicon->yindex = -1;
76 dicon->xindex = -1;
78 dicon->prev = NULL;
79 dicon->next = scr->app_icon_list;
80 if (scr->app_icon_list) {
81 scr->app_icon_list->prev = dicon;
83 scr->app_icon_list = dicon;
85 if (command) {
86 dicon->command = wstrdup(command);
88 if (wm_class)
89 dicon->wm_class = wstrdup(wm_class);
90 if (wm_instance)
91 dicon->wm_instance = wstrdup(wm_instance);
93 path = wDefaultGetIconFile(scr, wm_instance, wm_class, True);
94 if (!path && command) {
95 wApplicationExtractDirPackIcon(scr, command, wm_instance, wm_class);
97 path = wDefaultGetIconFile(scr, wm_instance, wm_class, False);
100 if (path)
101 path = FindImage(wPreferences.icon_path, path);
103 dicon->icon = wIconCreateWithIconFile(scr, path, tile);
104 if (path)
105 free(path);
106 #ifdef REDUCE_APPICONS
107 dicon->num_apps = 0;
108 #endif
109 #ifdef DEMATERIALIZE_ICON
111 XSetWindowAttributes attribs;
112 attribs.save_under = True;
113 XChangeWindowAttributes(dpy, dicon->icon->core->window,
114 CWSaveUnder, &attribs);
116 #endif
118 /* will be overriden by dock */
119 dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
120 dicon->icon->core->descriptor.handle_expose = iconExpose;
121 dicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
122 dicon->icon->core->descriptor.parent = dicon;
123 AddToStackList(dicon->icon->core);
125 return dicon;
130 WAppIcon*
131 wAppIconCreate(WWindow *leader_win)
133 WAppIcon *aicon;
134 #ifdef REDUCE_APPICONS
135 WAppIcon *atmp;
136 WAppIconAppList *applist;
137 char *tinstance, *tclass;
138 #endif
139 WScreen *scr = leader_win->screen_ptr;
141 aicon = wmalloc(sizeof(WAppIcon));
142 wretain(aicon);
143 memset(aicon, 0, sizeof(WAppIcon));
144 #ifdef REDUCE_APPICONS
145 applist = wmalloc(sizeof(WAppIconAppList));
146 memset(applist, 0, sizeof(WAppIconAppList));
147 applist->wapp = wApplicationOf(leader_win->main_window);
148 aicon->applist = applist;
149 if (applist->wapp == NULL) {
150 /* Something's wrong. wApplicationOf() should always return a
151 * valid structure. Rather than violate assumptions, bail. -cls
153 free(applist);
154 wrelease(aicon);
155 return NULL;
157 #endif
159 aicon->yindex = -1;
160 aicon->xindex = -1;
162 aicon->prev = NULL;
163 aicon->next = scr->app_icon_list;
164 if (scr->app_icon_list) {
165 #ifndef REDUCE_APPICONS
166 scr->app_icon_list->prev = aicon;
167 #else
168 /* If we aren't going to have a match, jump straight to new appicon */
169 if (leader_win->wm_class == NULL || leader_win->wm_class == NULL)
170 atmp = NULL;
171 else
172 atmp = scr->app_icon_list;
174 while (atmp != NULL) {
175 if ((tinstance = atmp->wm_instance) == NULL)
176 tinstance = "";
177 if ((tclass = atmp->wm_class) == NULL)
178 tclass = "";
179 if ((strcmp(leader_win->wm_class, tclass) == 0) &&
180 (strcmp(leader_win->wm_instance, tinstance) == 0))
182 /* We have a winner */
183 wrelease(aicon);
184 atmp->num_apps++;
185 applist->next = atmp->applist;
186 if (atmp->applist)
187 atmp->applist->prev = applist;
188 atmp->applist = applist;
190 if (atmp->docked) {
191 wDockSimulateLaunch(atmp->dock, atmp);
194 return atmp;
196 atmp = atmp->next;
198 if (atmp == NULL) {
199 scr->app_icon_list->prev = aicon;
201 #endif /* REDUCE_APPICONS */
203 scr->app_icon_list = aicon;
205 if (leader_win->wm_class)
206 aicon->wm_class = wstrdup(leader_win->wm_class);
207 if (leader_win->wm_instance)
208 aicon->wm_instance = wstrdup(leader_win->wm_instance);
209 #ifdef REDUCE_APPICONS
210 aicon->num_apps = 1;
211 #endif
213 aicon->icon = wIconCreate(leader_win);
214 #ifdef DEMATERIALIZE_ICON
216 XSetWindowAttributes attribs;
217 attribs.save_under = True;
218 XChangeWindowAttributes(dpy, aicon->icon->core->window,
219 CWSaveUnder, &attribs);
221 #endif
223 /* will be overriden if docked */
224 aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
225 aicon->icon->core->descriptor.handle_expose = iconExpose;
226 aicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
227 aicon->icon->core->descriptor.parent = aicon;
228 AddToStackList(aicon->icon->core);
229 aicon->icon->show_title = 0;
230 wIconUpdate(aicon->icon);
232 return aicon;
236 void
237 wAppIconDestroy(WAppIcon *aicon)
239 WScreen *scr = aicon->icon->core->screen_ptr;
240 #ifdef REDUCE_APPICONS
241 WAppIconAppList *aptmp;
242 #endif
244 RemoveFromStackList(aicon->icon->core);
245 wIconDestroy(aicon->icon);
246 if (aicon->command)
247 free(aicon->command);
248 #ifdef OFFIX_DND
249 if (aicon->dnd_command)
250 free(aicon->dnd_command);
251 #endif
252 if (aicon->wm_instance)
253 free(aicon->wm_instance);
254 if (aicon->wm_class)
255 free(aicon->wm_class);
256 #ifdef REDUCE_APPICONS
257 /* There should never be a list but just in case */
258 if (aicon->applist != NULL) {
259 aptmp = aicon->applist;
260 while (aptmp->next) {
261 aptmp = aptmp->next;
262 free(aptmp->prev);
264 free(aptmp);
266 #endif
268 if (aicon == scr->app_icon_list) {
269 if (aicon->next)
270 aicon->next->prev = NULL;
271 scr->app_icon_list = aicon->next;
273 else {
274 if (aicon->next)
275 aicon->next->prev = aicon->prev;
276 if (aicon->prev)
277 aicon->prev->next = aicon->next;
280 aicon->destroyed = 1;
281 wrelease(aicon);
286 #ifdef NEWAPPICON
287 static void
288 drawCorner(WIcon *icon, WWindow *wwin, int active)
290 WScreen *scr = wwin->screen_ptr;
291 XPoint points[3];
292 GC gc;
294 points[0].x = 2;
295 points[0].y = 2;
296 points[1].x = 12;
297 points[1].y = 2;
298 points[2].x = 2;
299 points[2].y = 12;
300 if (active) {
301 gc=scr->focused_texture->any.gc;
302 } else {
303 gc=scr->unfocused_texture->any.gc;
305 XFillPolygon(dpy, icon->core->window, gc, points, 3,
306 Convex, CoordModeOrigin);
308 #endif /* NEWAPPICON */
311 void
312 wAppIconMove(WAppIcon *aicon, int x, int y)
314 XMoveWindow(dpy, aicon->icon->core->window, x, y);
315 aicon->x_pos = x;
316 aicon->y_pos = y;
320 #ifdef WS_INDICATOR
321 static void
322 updateDockNumbers(WScreen *scr)
324 int length;
325 char *ws_numbers;
326 GC numbers_gc;
327 XGCValues my_gc_values;
328 unsigned long my_v_mask = (GCForeground);
329 WAppIcon *dicon = scr->dock->icon_array[0];
331 my_gc_values.foreground = scr->white_pixel;
332 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
333 my_v_mask, &my_gc_values);
335 ws_numbers = malloc(20);
336 sprintf(ws_numbers, "%i [ %i ]", scr->current_workspace+1,
337 ((scr->current_workspace/10)+1));
338 length = strlen(ws_numbers);
340 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
341 scr->icon_title_font->y+1, False);
343 #ifndef I18N_MB
344 XSetFont(dpy, numbers_gc, scr->icon_title_font->font->fid);
345 XSetForeground(dpy, numbers_gc, scr->black_pixel);
346 XDrawString(dpy, dicon->icon->core->window,
347 numbers_gc, 4, scr->icon_title_font->y+3, ws_numbers, length);
348 XSetForeground(dpy, numbers_gc, scr->white_pixel);
349 XDrawString(dpy, dicon->icon->core->window,
350 numbers_gc, 3, scr->icon_title_font->y+2, ws_numbers, length);
351 #else
352 XSetForeground(dpy, numbers_gc, scr->black_pixel);
353 XmbDrawString(dpy, dicon->icon->core->window,
354 scr->icon_title_font->font, numbers_gc, 4,
355 scr->icon_title_font->y+3, ws_numbers, length);
356 XSetForeground(dpy, numbers_gc, scr->white_pixel);
357 XmbDrawString(dpy, dicon->icon->core->window,
358 scr->icon_title_font->font, numbers_gc, 3,
359 scr->icon_title_font->y+2, ws_numbers, length);
360 #endif /* I18N_MB */
362 XFreeGC(dpy, numbers_gc);
363 free(ws_numbers);
365 #endif /* WS_INDICATOR */
368 void
369 wAppIconPaint(WAppIcon *aicon)
371 WScreen *scr = aicon->icon->core->screen_ptr;
373 wIconPaint(aicon->icon);
376 # ifdef WS_INDICATOR
377 if (aicon->docked && scr->dock && aicon->yindex==0)
378 updateDockNumbers(scr);
379 # endif
380 if (scr->dock_dots && aicon->docked && !aicon->running
381 && aicon->command!=NULL) {
382 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
383 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
384 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
385 scr->copy_gc, 0, 0, scr->dock_dots->width,
386 scr->dock_dots->height, 0, 0);
389 #ifdef HIDDENDOT
391 WApplication *wapp;
392 wapp = wApplicationOf(aicon->main_window);
393 if (wapp) {
394 if (wapp->flags.hidden) {
395 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
396 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
397 XCopyArea(dpy, scr->dock_dots->image,
398 aicon->icon->core->window,
399 scr->copy_gc, 0, 0, 7,
400 scr->dock_dots->height, 0, 0);
404 #endif /* HIDDENDOT */
406 #ifdef NEWAPPICON
407 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
408 int active=0;
409 if (aicon->main_window==None) {
410 active = (aicon->icon->owner->flags.focused ? 1 : 0);
411 } else {
412 WApplication *wapp;
414 wapp = wApplicationOf(aicon->main_window);
415 if (!wapp) {
416 active = aicon->icon->owner->flags.focused;
417 wwarning("error in wAppIconPaint(). Please report it");
418 } else {
419 active = wapp->main_window_desc->flags.focused;
420 if (wapp->main_window_desc->flags.hidden
421 || !wapp->main_window_desc->flags.mapped)
422 active = -1;
425 if (active>=0)
426 drawCorner(aicon->icon, aicon->icon->owner, active);
428 #endif /* NEWAPPICON */
430 XSetClipMask(dpy, scr->copy_gc, None);
431 if (aicon->launching) {
432 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
433 0, 0, wPreferences.icon_size, wPreferences.icon_size);
439 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
441 #ifdef REDUCE_APPICONS
442 unsigned int
443 wAppIconReduceAppCount(WApplication *wapp)
445 WAppIconAppList *applist;
447 if (wapp == NULL)
448 return 0;
450 if (wapp->app_icon == NULL)
451 return 0;
453 /* If given a main window, check the applist
454 * and remove the if it exists
456 applist = wapp->app_icon->applist;
457 while (applist != NULL) {
458 if (applist->wapp == wapp) {
459 /* If this app owns the appicon, change the appicon's
460 * owner to the next app in the list or NULL
462 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
464 if (applist->next) {
465 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
466 } else if (applist->prev) {
467 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
468 } else {
469 wapp->app_icon->icon->owner = NULL;
472 if (applist->prev)
473 applist->prev->next = applist->next;
475 if (applist->next)
476 applist->next->prev = applist->prev;
478 if (applist == wapp->app_icon->applist)
479 wapp->app_icon->applist = applist->next;
481 free(applist);
483 if (wapp->app_icon->applist != NULL)
484 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
486 return (--wapp->app_icon->num_apps);
488 applist = applist->next;
490 return (--wapp->app_icon->num_apps);
492 #endif
495 static void
496 hideCallback(WMenu *menu, WMenuEntry *entry)
498 WApplication *wapp = (WApplication*)entry->clientdata;
500 if (wapp->flags.hidden) {
501 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
502 wUnhideApplication(wapp, False, False);
503 } else {
504 wHideApplication(wapp);
509 static void
510 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
512 WApplication *wapp = (WApplication*)entry->clientdata;
514 wUnhideApplication(wapp, False, True);
518 static void
519 setIconCallback(WMenu *menu, WMenuEntry *entry)
521 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
522 char *file=NULL;
523 WScreen *scr;
524 int result;
526 assert(icon!=NULL);
528 if (icon->editing)
529 return;
530 icon->editing = 1;
531 scr = icon->icon->core->screen_ptr;
533 wretain(icon);
535 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
537 if (result && !icon->destroyed) {
538 if (file[0]==0) {
539 free(file);
540 file = NULL;
542 if (!wIconChangeImageFile(icon->icon, file)) {
543 wMessageDialog(scr, _("Error"),
544 _("Could not open specified icon file"),
545 _("OK"), NULL, NULL);
546 } else {
547 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
548 wAppIconPaint(icon);
550 if (file)
551 free(file);
553 icon->editing = 0;
554 wrelease(icon);
558 static void
559 killCallback(WMenu *menu, WMenuEntry *entry)
561 WApplication *wapp = (WApplication*)entry->clientdata;
562 char *buffer;
564 if (!WCHECK_STATE(WSTATE_NORMAL))
565 return;
567 WCHANGE_STATE(WSTATE_MODAL);
569 assert(entry->clientdata!=NULL);
571 buffer = wstrappend(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
572 _(" will be forcibly closed.\n"
573 "Any unsaved changes will be lost.\n"
574 "Please confirm."));
576 wretain(wapp->main_window_desc);
577 if (wPreferences.dont_confirm_kill
578 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
579 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
580 if (!wapp->main_window_desc->flags.destroyed)
581 wClientKill(wapp->main_window_desc);
583 wrelease(wapp->main_window_desc);
585 free(buffer);
587 WCHANGE_STATE(WSTATE_NORMAL);
591 static WMenu*
592 createApplicationMenu(WScreen *scr)
594 WMenu *menu;
596 menu = wMenuCreate(scr, NULL, False);
597 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
598 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
599 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
600 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
602 return menu;
606 static void
607 openApplicationMenu(WApplication *wapp, int x, int y)
609 WMenu *menu;
610 WScreen *scr = wapp->main_window_desc->screen_ptr;
611 int i;
613 if (!scr->icon_menu) {
614 scr->icon_menu = createApplicationMenu(scr);
615 free(scr->icon_menu->entries[1]->text);
618 menu = scr->icon_menu;
620 if (wapp->flags.hidden) {
621 menu->entries[1]->text = _("Unhide");
622 } else {
623 menu->entries[1]->text = _("Hide");
626 menu->flags.realized = 0;
627 wMenuRealize(menu);
629 x -= menu->frame->core->width/2;
630 if (x + menu->frame->core->width > scr->scr_width)
631 x = scr->scr_width - menu->frame->core->width;
632 if (x < 0)
633 x = 0;
635 /* set client data */
636 for (i = 0; i < menu->entry_no; i++) {
637 menu->entries[i]->clientdata = wapp;
639 wMenuMapAt(menu, x, y, False);
643 /******************************************************************/
645 static void
646 iconExpose(WObjDescriptor *desc, XEvent *event)
648 wAppIconPaint(desc->parent);
652 static void
653 iconDblClick(WObjDescriptor *desc, XEvent *event)
655 WAppIcon *aicon = desc->parent;
656 WApplication *wapp;
657 WScreen *scr = aicon->icon->core->screen_ptr;
658 int unhideHere;
660 #ifndef REDUCE_APPICONS
661 assert(aicon->icon->owner!=NULL);
662 #else
663 if (aicon->icon->owner == NULL) {
664 fprintf(stderr, "Double-click disabled: missing main window.\n");
665 return;
667 #endif
669 wapp = wApplicationOf(aicon->icon->owner->main_window);
670 #ifdef DEBUG0
671 if (!wapp) {
672 wwarning("could not find application descriptor for app icon!!");
673 return;
675 #endif
676 #ifdef REDUCE_APPICONS
677 if (!wapp) {
678 fprintf(stderr, "Double-click disabled: missing wapp.\n");
679 return;
681 #endif /* REDUCE_APPICONS */
683 unhideHere = (event->xbutton.state & ShiftMask);
685 /* go to the last workspace that the user worked on the app */
686 if (!unhideHere && wapp->last_workspace != scr->current_workspace)
687 wWorkspaceChange(scr, wapp->last_workspace);
689 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
691 if (event->xbutton.state & MOD_MASK) {
692 wHideOtherApplications(aicon->icon->owner);
697 void
698 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
700 WAppIcon *aicon = desc->parent;
701 WIcon *icon = aicon->icon;
702 XEvent ev;
703 int x=aicon->x_pos, y=aicon->y_pos;
704 int dx=event->xbutton.x, dy=event->xbutton.y;
705 int grabbed=0;
706 int done=0;
707 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
708 WScreen *scr = icon->core->screen_ptr;
709 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
710 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
711 int ix, iy;
712 int clickButton = event->xbutton.button;
713 Pixmap ghost = None;
715 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
716 return;
718 if (IsDoubleClick(scr, event)) {
719 iconDblClick(desc, event);
720 return;
723 if (event->xbutton.button == Button3) {
724 WObjDescriptor *desc;
725 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
727 if (!wapp)
728 return;
730 openApplicationMenu(wapp, event->xbutton.x_root,
731 event->xbutton.y_root);
733 /* allow drag select of menu */
734 desc = &scr->icon_menu->menu->descriptor;
735 event->xbutton.send_event = True;
736 (*desc->handle_mousedown)(desc, event);
737 return;
740 #ifdef DEBUG
741 puts("Moving icon");
742 #endif
743 if (event->xbutton.state & MOD_MASK)
744 wLowerFrame(icon->core);
745 else
746 wRaiseFrame(icon->core);
749 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
750 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
751 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
752 wwarning("pointer grab failed for appicon move");
755 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
756 dockable = 0;
757 else
758 dockable = canBeDocked(icon->owner);
761 while (!done) {
762 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
763 |ButtonMotionMask|ExposureMask, &ev);
764 switch (ev.type) {
765 case Expose:
766 WMHandleEvent(&ev);
767 break;
769 case MotionNotify:
770 if (!grabbed) {
771 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
772 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
773 XChangeActivePointerGrab(dpy, ButtonMotionMask
774 |ButtonReleaseMask|ButtonPressMask,
775 wCursor[WCUR_MOVE], CurrentTime);
776 grabbed=1;
777 } else {
778 break;
781 x = ev.xmotion.x_root - dx;
782 y = ev.xmotion.y_root - dy;
783 XMoveWindow(dpy, icon->core->window, x, y);
785 if (dockable) {
786 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
787 &ix, &iy, False)) {
788 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
789 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
791 if (scr->last_dock != scr->dock && collapsed) {
792 scr->last_dock->collapsed = 1;
793 wDockHideIcons(scr->last_dock);
794 collapsed = 0;
796 if (!collapsed && (collapsed = scr->dock->collapsed)) {
797 scr->dock->collapsed = 0;
798 wDockShowIcons(scr->dock);
801 if (scr->dock->auto_raise_lower)
802 wDockRaise(scr->dock);
804 scr->last_dock = scr->dock;
806 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
807 if (!docking) {
808 Window wins[2];
810 wins[0] = icon->core->window;
811 wins[1] = scr->dock_shadow;
812 XRestackWindows(dpy, wins, 2);
813 if (superfluous) {
814 if (icon->pixmap!=None)
815 ghost = MakeGhostIcon(scr, icon->pixmap);
816 else
817 ghost = MakeGhostIcon(scr, icon->core->window);
818 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
819 ghost);
820 XClearWindow(dpy, scr->dock_shadow);
822 XMapWindow(dpy, scr->dock_shadow);
824 docking = 1;
825 } else if (workspace->clip &&
826 wDockSnapIcon(workspace->clip, aicon, x, y,
827 &ix, &iy, False)) {
828 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
829 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
831 if (scr->last_dock != workspace->clip && collapsed) {
832 scr->last_dock->collapsed = 1;
833 wDockHideIcons(scr->last_dock);
834 collapsed = 0;
836 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
837 workspace->clip->collapsed = 0;
838 wDockShowIcons(workspace->clip);
841 if (workspace->clip->auto_raise_lower)
842 wDockRaise(workspace->clip);
844 scr->last_dock = workspace->clip;
846 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
847 if (!docking) {
848 Window wins[2];
850 wins[0] = icon->core->window;
851 wins[1] = scr->dock_shadow;
852 XRestackWindows(dpy, wins, 2);
853 if (superfluous) {
854 if (icon->pixmap!=None)
855 ghost = MakeGhostIcon(scr, icon->pixmap);
856 else
857 ghost = MakeGhostIcon(scr, icon->core->window);
858 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
859 ghost);
860 XClearWindow(dpy, scr->dock_shadow);
862 XMapWindow(dpy, scr->dock_shadow);
864 docking = 1;
865 } else if (docking) {
866 XUnmapWindow(dpy, scr->dock_shadow);
867 docking = 0;
871 break;
873 case ButtonPress:
874 break;
876 case ButtonRelease:
877 if (ev.xbutton.button != clickButton)
878 break;
879 XUngrabPointer(dpy, CurrentTime);
881 if (docking) {
882 Bool docked;
884 /* icon is trying to be docked */
885 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
886 XUnmapWindow(dpy, scr->dock_shadow);
887 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
888 if (scr->last_dock->auto_collapse) {
889 collapsed = 0;
891 if (workspace->clip &&
892 workspace->clip != scr->last_dock &&
893 workspace->clip->auto_raise_lower)
894 wDockLower(workspace->clip);
896 if (!docked) {
897 /* If icon could not be docked, slide it back to the old
898 * position */
899 SlideWindow(icon->core->window, x, y, aicon->x_pos,
900 aicon->y_pos);
902 } else {
903 XMoveWindow(dpy, icon->core->window, x, y);
904 aicon->x_pos = x;
905 aicon->y_pos = y;
906 if (workspace->clip && workspace->clip->auto_raise_lower)
907 wDockLower(workspace->clip);
909 if (collapsed) {
910 scr->last_dock->collapsed = 1;
911 wDockHideIcons(scr->last_dock);
912 collapsed = 0;
914 if (superfluous) {
915 if (ghost!=None)
916 XFreePixmap(dpy, ghost);
917 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
920 if (wPreferences.auto_arrange_icons)
921 wArrangeIcons(scr, True);
923 done = 1;
924 break;
927 #ifdef DEBUG
928 puts("End icon move");
929 #endif