Initial revision
[wmaker-crm.git] / src / appicon.c
blob183f9061b08198df4794fecbf3737bb7edd54549
1 /* appicon.c- icon for applications (not mini-window)
3 * WindowMaker 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 <string.h>
30 #include "WindowMaker.h"
31 #include "wcore.h"
32 #include "window.h"
33 #include "icon.h"
34 #include "appicon.h"
35 #include "actions.h"
36 #include "stacking.h"
37 #include "dock.h"
38 #include "funcs.h"
39 #include "defaults.h"
40 #include "workspace.h"
41 #include "superfluous.h"
42 #include "menu.h"
43 #include "framewin.h"
44 #include "dialog.h"
45 #include "client.h"
47 /*
48 * icon_file for the dock is got from the preferences file by
49 * using the classname/instancename
52 /**** Global variables ****/
53 extern Cursor wCursor[WCUR_LAST];
54 extern WPreferences wPreferences;
56 #define MOD_MASK wPreferences.modifier_mask
58 void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
59 static void iconDblClick(WObjDescriptor *desc, XEvent *event);
60 static void iconExpose(WObjDescriptor *desc, XEvent *event);
64 WAppIcon*
65 wAppIconCreateForDock(WScreen *scr, char *command, char *wm_instance,
66 char *wm_class, int tile)
68 WAppIcon *dicon;
69 char *path;
71 dicon = wmalloc(sizeof(WAppIcon));
72 wretain(dicon);
73 memset(dicon, 0, sizeof(WAppIcon));
74 dicon->yindex = -1;
75 dicon->xindex = -1;
77 dicon->prev = NULL;
78 dicon->next = scr->app_icon_list;
79 if (scr->app_icon_list) {
80 scr->app_icon_list->prev = dicon;
82 scr->app_icon_list = dicon;
84 if (command) {
85 dicon->command = wstrdup(command);
87 if (wm_class)
88 dicon->wm_class = wstrdup(wm_class);
89 if (wm_instance)
90 dicon->wm_instance = wstrdup(wm_instance);
92 path = wDefaultGetIconFile(scr, wm_instance, wm_class, True);
93 if (!path && command) {
94 wApplicationExtractDirPackIcon(scr, command, wm_instance, wm_class);
96 path = wDefaultGetIconFile(scr, wm_instance, wm_class, False);
99 if (path)
100 path = FindImage(wPreferences.icon_path, path);
102 dicon->icon = wIconCreateWithIconFile(scr, path, tile);
103 if (path)
104 free(path);
105 #ifdef REDUCE_APPICONS
106 dicon->num_apps = 0;
107 #endif
109 /* will be overriden by dock */
110 dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
111 dicon->icon->core->descriptor.handle_expose = iconExpose;
112 dicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
113 dicon->icon->core->descriptor.parent = dicon;
114 AddToStackList(dicon->icon->core);
116 return dicon;
121 WAppIcon*
122 wAppIconCreate(WWindow *leader_win)
124 WAppIcon *aicon;
125 #ifdef REDUCE_APPICONS
126 WAppIcon *atmp;
127 WAppIconAppList *applist;
128 char *tinstance, *tclass;
129 #endif
130 WScreen *scr = leader_win->screen_ptr;
132 aicon = wmalloc(sizeof(WAppIcon));
133 wretain(aicon);
134 memset(aicon, 0, sizeof(WAppIcon));
135 #ifdef REDUCE_APPICONS
136 applist = wmalloc(sizeof(WAppIconAppList));
137 memset(applist, 0, sizeof(WAppIconAppList));
138 applist->wapp = wApplicationOf(leader_win->main_window);
139 aicon->applist = applist;
140 if (applist->wapp == NULL) {
141 /* Something's wrong. wApplicationOf() should always return a
142 * valid structure. Rather than violate assumptions, bail. -cls
144 free(applist);
145 wrelease(aicon);
146 return NULL;
148 #endif
150 aicon->yindex = -1;
151 aicon->xindex = -1;
153 aicon->prev = NULL;
154 aicon->next = scr->app_icon_list;
155 if (scr->app_icon_list) {
156 #ifdef REDUCE_APPICONS
157 /* If we aren't going to have a match, jump straight to new appicon */
158 if (leader_win->wm_class == NULL || leader_win->wm_class == NULL)
159 atmp = NULL;
160 else
161 atmp = scr->app_icon_list;
163 while (atmp != NULL) {
164 if ((tinstance = atmp->wm_instance) == NULL)
165 tinstance = "";
166 if ((tclass = atmp->wm_class) == NULL)
167 tclass = "";
168 if ((strcmp(leader_win->wm_class, tclass) == 0) &&
169 (strcmp(leader_win->wm_instance, tinstance) == 0))
171 /* We have a winner */
172 wrelease(aicon);
173 atmp->num_apps++;
174 applist->next = atmp->applist;
175 if (atmp->applist)
176 atmp->applist->prev = applist;
177 atmp->applist = applist;
179 if (atmp->docked) {
180 wDockSimulateLaunch(atmp->dock, atmp);
183 return atmp;
185 atmp = atmp->next;
187 if (atmp == NULL) {
188 #endif
189 scr->app_icon_list->prev = aicon;
190 #ifdef REDUCE_APPICONS
192 #endif
194 scr->app_icon_list = aicon;
196 if (leader_win->wm_class)
197 aicon->wm_class = wstrdup(leader_win->wm_class);
198 if (leader_win->wm_instance)
199 aicon->wm_instance = wstrdup(leader_win->wm_instance);
200 #ifdef REDUCE_APPICONS
201 aicon->num_apps = 1;
202 #endif
204 aicon->icon = wIconCreate(leader_win);
206 /* will be overriden if docked */
207 aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
208 aicon->icon->core->descriptor.handle_expose = iconExpose;
209 aicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
210 aicon->icon->core->descriptor.parent = aicon;
211 AddToStackList(aicon->icon->core);
212 aicon->icon->show_title = 0;
213 wIconUpdate(aicon->icon);
215 return aicon;
219 void
220 wAppIconDestroy(WAppIcon *aicon)
222 WScreen *scr = aicon->icon->core->screen_ptr;
223 #ifdef REDUCE_APPICONS
224 WAppIconAppList *aptmp;
225 #endif
227 RemoveFromStackList(aicon->icon->core);
228 wIconDestroy(aicon->icon);
229 if (aicon->command)
230 free(aicon->command);
231 #ifdef OFFIX_DND
232 if (aicon->dnd_command)
233 free(aicon->dnd_command);
234 #endif
235 if (aicon->wm_instance)
236 free(aicon->wm_instance);
237 if (aicon->wm_class)
238 free(aicon->wm_class);
239 #ifdef REDUCE_APPICONS
240 /* There should never be a list but just in case */
241 if (aicon->applist != NULL) {
242 aptmp = aicon->applist;
243 while (aptmp->next) {
244 aptmp = aptmp->next;
245 free(aptmp->prev);
247 free(aptmp);
249 #endif
251 if (aicon == scr->app_icon_list) {
252 if (aicon->next)
253 aicon->next->prev = NULL;
254 scr->app_icon_list = aicon->next;
256 else {
257 if (aicon->next)
258 aicon->next->prev = aicon->prev;
259 if (aicon->prev)
260 aicon->prev->next = aicon->next;
263 aicon->destroyed = 1;
264 wrelease(aicon);
269 #ifdef NEWAPPICON
270 static void
271 drawCorner(WIcon *icon, WWindow *wwin, int active)
273 WScreen *scr = wwin->screen_ptr;
274 XPoint points[3];
275 GC gc;
277 points[0].x = 2;
278 points[0].y = 2;
279 points[1].x = 12;
280 points[1].y = 2;
281 points[2].x = 2;
282 points[2].y = 12;
283 if (active) {
284 gc=scr->focused_texture->any.gc;
285 } else {
286 gc=scr->unfocused_texture->any.gc;
288 XFillPolygon(dpy, icon->core->window, gc, points, 3,
289 Convex, CoordModeOrigin);
291 #endif /* NEWAPPICON */
294 void
295 wAppIconMove(WAppIcon *aicon, int x, int y)
297 XMoveWindow(dpy, aicon->icon->core->window, x, y);
298 aicon->x_pos = x;
299 aicon->y_pos = y;
303 #ifdef WS_INDICATOR
304 static void
305 updateDockNumbers(WScreen *scr)
307 int length;
308 char *ws_numbers;
309 GC numbers_gc;
310 XGCValues my_gc_values;
311 unsigned long my_v_mask = (GCForeground);
312 WAppIcon *dicon = scr->dock->icon_array[0];
314 my_gc_values.foreground = scr->white_pixel;
315 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
316 my_v_mask, &my_gc_values);
318 ws_numbers = malloc(20);
319 sprintf(ws_numbers, "%i [ %i ]", scr->current_workspace+1,
320 ((scr->current_workspace/10)+1));
321 length = strlen(ws_numbers);
323 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
324 scr->icon_title_font->y+1, False);
326 #ifndef I18N_MB
327 XSetFont(dpy, numbers_gc, scr->icon_title_font->font->fid);
328 XSetForeground(dpy, numbers_gc, scr->black_pixel);
329 XDrawString(dpy, dicon->icon->core->window,
330 numbers_gc, 4, scr->icon_title_font->y+3, ws_numbers, length);
331 XSetForeground(dpy, numbers_gc, scr->white_pixel);
332 XDrawString(dpy, dicon->icon->core->window,
333 numbers_gc, 3, scr->icon_title_font->y+2, ws_numbers, length);
334 #else
335 XSetForeground(dpy, numbers_gc, scr->black_pixel);
336 XmbDrawString(dpy, dicon->icon->core->window,
337 scr->icon_title_font->font, numbers_gc, 4,
338 scr->icon_title_font->y+3, ws_numbers, length);
339 XSetForeground(dpy, numbers_gc, scr->white_pixel);
340 XmbDrawString(dpy, dicon->icon->core->window,
341 scr->icon_title_font->font, numbers_gc, 3,
342 scr->icon_title_font->y+2, ws_numbers, length);
343 #endif /* I18N_MB */
345 XFreeGC(dpy, numbers_gc);
346 free(ws_numbers);
348 #endif /* WS_INDICATOR */
351 void
352 wAppIconPaint(WAppIcon *aicon)
354 WScreen *scr = aicon->icon->core->screen_ptr;
356 wIconPaint(aicon->icon);
359 # ifdef WS_INDICATOR
360 if (aicon->docked && scr->dock && aicon->yindex==0)
361 updateDockNumbers(scr);
362 # endif
363 if (scr->dock_dots && aicon->docked && !aicon->running
364 && aicon->command!=NULL) {
365 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
366 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
367 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
368 scr->copy_gc, 0, 0, scr->dock_dots->width,
369 scr->dock_dots->height, 0, 0);
372 #ifdef NEWAPPICON
373 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
374 int active=0;
375 if (aicon->main_window==None) {
376 active = (aicon->icon->owner->flags.focused ? 1 : 0);
377 } else {
378 WApplication *wapp;
380 wapp = wApplicationOf(aicon->main_window);
381 if (!wapp) {
382 active = aicon->icon->owner->flags.focused;
383 wwarning("error in wAppIconPaint(). Please report it");
384 } else {
385 active = wapp->main_window_desc->flags.focused;
386 if (wapp->main_window_desc->flags.hidden
387 || !wapp->main_window_desc->flags.mapped)
388 active = -1;
391 if (active>=0)
392 drawCorner(aicon->icon, aicon->icon->owner, active);
394 #endif /* NEWAPPICON */
396 XSetClipMask(dpy, scr->copy_gc, None);
397 if (aicon->launching) {
398 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
399 0, 0, wPreferences.icon_size, wPreferences.icon_size);
405 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
407 #ifdef REDUCE_APPICONS
408 unsigned int
409 wAppIconReduceAppCount(WApplication *wapp)
411 WAppIconAppList *applist;
413 if (wapp == NULL)
414 return 0;
416 if (wapp->app_icon == NULL)
417 return 0;
419 /* If given a main window, check the applist
420 * and remove the if it exists
422 applist = wapp->app_icon->applist;
423 while (applist != NULL) {
424 if (applist->wapp == wapp) {
425 /* If this app owns the appicon, change the appicon's
426 * owner to the next app in the list or NULL
428 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
430 if (applist->next) {
431 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
432 } else if (applist->prev) {
433 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
434 } else {
435 wapp->app_icon->icon->owner = NULL;
438 if (applist->prev)
439 applist->prev->next = applist->next;
441 if (applist->next)
442 applist->next->prev = applist->prev;
444 if (applist == wapp->app_icon->applist)
445 wapp->app_icon->applist = applist->next;
447 free(applist);
449 if (wapp->app_icon->applist != NULL)
450 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
452 return (--wapp->app_icon->num_apps);
454 applist = applist->next;
456 return (--wapp->app_icon->num_apps);
458 #endif
461 static void
462 hideCallback(WMenu *menu, WMenuEntry *entry)
464 WApplication *wapp = (WApplication*)entry->clientdata;
466 if (wapp->flags.hidden) {
467 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
468 wUnhideApplication(wapp, False, False);
469 } else {
470 wHideApplication(wapp);
475 static void
476 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
478 WApplication *wapp = (WApplication*)entry->clientdata;
480 wUnhideApplication(wapp, False, True);
484 static void
485 setIconCallback(WMenu *menu, WMenuEntry *entry)
487 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
488 char *file=NULL;
489 WScreen *scr;
490 int result;
492 assert(icon!=NULL);
494 if (icon->editing)
495 return;
496 icon->editing = 1;
497 scr = icon->icon->core->screen_ptr;
499 wretain(icon);
501 result = wIconChooserDialog(scr, &file);
503 if (result && !icon->destroyed) {
504 if (file[0]==0) {
505 free(file);
506 file = NULL;
508 if (!wIconChangeImageFile(icon->icon, file)) {
509 wMessageDialog(scr, _("Error"),
510 _("Could not open specified icon file"),
511 _("OK"), NULL, NULL);
512 } else {
513 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
514 wAppIconPaint(icon);
516 if (file)
517 free(file);
519 icon->editing = 0;
520 wrelease(icon);
524 static void
525 killCallback(WMenu *menu, WMenuEntry *entry)
527 WApplication *wapp = (WApplication*)entry->clientdata;
528 assert(entry->clientdata!=NULL);
530 wretain(wapp->main_window_desc);
531 if (wPreferences.dont_confirm_kill
532 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
533 _("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
534 _("Yes"), _("No"), NULL)==WAPRDefault) {
535 if (!wapp->main_window_desc->flags.destroyed)
536 wClientKill(wapp->main_window_desc);
538 wrelease(wapp->main_window_desc);
542 static WMenu*
543 createApplicationMenu(WScreen *scr)
545 WMenu *menu;
547 menu = wMenuCreate(scr, NULL, False);
548 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
549 wMenuAddCallback(menu, _("(Un)Hide"), hideCallback, NULL);
550 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
551 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
553 return menu;
557 static void
558 openApplicationMenu(WApplication *wapp, int x, int y)
560 WMenu *menu;
561 WScreen *scr = wapp->main_window_desc->screen_ptr;
562 int i;
564 if (!scr->icon_menu) {
565 scr->icon_menu = createApplicationMenu(scr);
568 menu = scr->icon_menu;
569 if (!menu->flags.realized)
570 wMenuRealize(menu);
572 x -= menu->frame->core->width/2;
573 if (x + menu->frame->core->width > scr->scr_width)
574 x = scr->scr_width - menu->frame->core->width;
575 if (x < 0)
576 x = 0;
578 /* set client data */
579 for (i = 0; i < menu->entry_no; i++) {
580 menu->entries[i]->clientdata = wapp;
582 wMenuMapAt(menu, x, y, False);
586 /******************************************************************/
588 static void
589 iconExpose(WObjDescriptor *desc, XEvent *event)
591 wAppIconPaint(desc->parent);
594 static void
595 iconDblClick(WObjDescriptor *desc, XEvent *event)
597 WAppIcon *aicon = desc->parent;
598 WApplication *wapp;
599 WScreen *scr = aicon->icon->core->screen_ptr;
600 int unhideHere;
602 #ifndef REDUCE_APPICONS
603 assert(aicon->icon->owner!=NULL);
604 #else
605 if (aicon->icon->owner == NULL) {
606 fprintf(stderr, "Double-click disabled: missing main window.\n");
607 return;
609 #endif
611 wapp = wApplicationOf(aicon->icon->owner->main_window);
612 #ifdef DEBUG0
613 if (!wapp) {
614 wwarning("could not find application descriptor for app icon!!");
615 return;
617 #endif
618 #ifdef REDUCE_APPICONS
619 if (!wapp) {
620 fprintf(stderr, "Double-click disabled: missing wapp.\n");
621 return;
623 #endif /* REDUCE_APPICONS */
624 #if 0
625 /* aproveita que ta aqui pra atualizar */
626 wapp->main_window = aicon->icon->owner->main_window;
627 #endif
629 unhideHere = (event->xbutton.state & ShiftMask);
631 /* go to the last workspace that the user worked on the app */
632 if (!unhideHere)
633 wWorkspaceChange(scr, wapp->last_workspace);
635 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
637 if (event->xbutton.state & MOD_MASK) {
638 wHideOtherApplications(aicon->icon->owner);
643 void
644 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
646 WAppIcon *aicon = desc->parent;
647 WIcon *icon = aicon->icon;
648 XEvent ev;
649 int x=aicon->x_pos, y=aicon->y_pos;
650 int dx=event->xbutton.x, dy=event->xbutton.y;
651 int grabbed=0;
652 int done=0;
653 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
654 WScreen *scr = icon->core->screen_ptr;
655 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
656 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
657 int ix, iy;
658 int clickButton = event->xbutton.button;
659 Pixmap ghost = None;
661 if (IsDoubleClick(scr, event)) {
662 iconDblClick(desc, event);
663 return;
666 if (event->xbutton.button == Button3) {
667 WObjDescriptor *desc;
668 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
670 openApplicationMenu(wapp, event->xbutton.x_root,
671 event->xbutton.y_root);
673 /* allow drag select of menu */
674 desc = &scr->icon_menu->menu->descriptor;
675 event->xbutton.send_event = True;
676 (*desc->handle_mousedown)(desc, event);
677 return;
680 #ifdef DEBUG
681 puts("Moving icon");
682 #endif
683 if (event->xbutton.state & MOD_MASK)
684 wLowerFrame(icon->core);
685 else
686 wRaiseFrame(icon->core);
689 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
690 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
691 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
692 wwarning("pointer grab failed for appicon move");
695 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
696 dockable = 0;
697 else
698 dockable = canBeDocked(icon->owner);
701 while (!done) {
702 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
703 |ButtonMotionMask|ExposureMask, &ev);
704 switch (ev.type) {
705 case Expose:
706 WMHandleEvent(&ev);
707 break;
709 case MotionNotify:
710 if (!grabbed) {
711 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
712 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
713 XChangeActivePointerGrab(dpy, ButtonMotionMask
714 |ButtonReleaseMask|ButtonPressMask,
715 wCursor[WCUR_MOVE], CurrentTime);
716 grabbed=1;
717 } else {
718 break;
721 x = ev.xmotion.x_root - dx;
722 y = ev.xmotion.y_root - dy;
723 XMoveWindow(dpy, icon->core->window, x, y);
725 if (dockable) {
726 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
727 &ix, &iy, False)) {
728 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
729 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
731 if (scr->last_dock != scr->dock && collapsed) {
732 scr->last_dock->collapsed = 1;
733 wDockHideIcons(scr->last_dock);
734 collapsed = 0;
736 if (!collapsed && (collapsed = scr->dock->collapsed)) {
737 scr->dock->collapsed = 0;
738 wDockShowIcons(scr->dock);
741 scr->last_dock = scr->dock;
743 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
744 if (!docking) {
745 Window wins[2];
747 wins[0] = icon->core->window;
748 wins[1] = scr->dock_shadow;
749 XRestackWindows(dpy, wins, 2);
750 if (superfluous) {
751 if (icon->pixmap!=None)
752 ghost = MakeGhostIcon(scr, icon->pixmap);
753 else
754 ghost = MakeGhostIcon(scr, icon->core->window);
755 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
756 ghost);
757 XClearWindow(dpy, scr->dock_shadow);
759 XMapWindow(dpy, scr->dock_shadow);
761 docking = 1;
762 } else if (workspace->clip &&
763 wDockSnapIcon(workspace->clip, aicon, x, y,
764 &ix, &iy, False)) {
765 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
766 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
768 if (scr->last_dock != workspace->clip && collapsed) {
769 scr->last_dock->collapsed = 1;
770 wDockHideIcons(scr->last_dock);
771 collapsed = 0;
773 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
774 workspace->clip->collapsed = 0;
775 wDockShowIcons(workspace->clip);
778 scr->last_dock = workspace->clip;
780 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
781 if (!docking) {
782 Window wins[2];
784 wins[0] = icon->core->window;
785 wins[1] = scr->dock_shadow;
786 XRestackWindows(dpy, wins, 2);
787 if (superfluous) {
788 if (icon->pixmap!=None)
789 ghost = MakeGhostIcon(scr, icon->pixmap);
790 else
791 ghost = MakeGhostIcon(scr, icon->core->window);
792 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
793 ghost);
794 XClearWindow(dpy, scr->dock_shadow);
796 XMapWindow(dpy, scr->dock_shadow);
798 docking = 1;
799 } else if (docking) {
800 XUnmapWindow(dpy, scr->dock_shadow);
801 docking = 0;
805 break;
807 case ButtonPress:
808 break;
810 case ButtonRelease:
811 if (ev.xbutton.button != clickButton)
812 break;
813 XUngrabPointer(dpy, CurrentTime);
815 if (docking) {
816 Bool docked;
818 /* icon is trying to be docked */
819 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
820 XUnmapWindow(dpy, scr->dock_shadow);
821 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
822 if (scr->last_dock->auto_collapse) {
823 collapsed = 0;
826 if (!docked) {
827 /* If icon could not be docked, slide it back to the old
828 * position */
829 SlideWindow(icon->core->window, x, y, aicon->x_pos,
830 aicon->y_pos);
832 } else {
833 XMoveWindow(dpy, icon->core->window, x, y);
834 aicon->x_pos = x;
835 aicon->y_pos = y;
837 if (collapsed) {
838 scr->last_dock->collapsed = 1;
839 wDockHideIcons(scr->last_dock);
840 collapsed = 0;
842 if (superfluous) {
843 if (ghost!=None)
844 XFreePixmap(dpy, ghost);
845 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
847 done = 1;
848 break;
851 #ifdef DEBUG
852 puts("End icon move");
853 #endif