Simplified code for XK_ISO_Left_Tab
[wmaker-crm.git] / src / appicon.c
blobccac19907eb82b3319f2b70aaf27165468e08ae8
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, aicon->icon->core->window,
398 scr->copy_gc, 0, 0, 7,
399 scr->dock_dots->height, 0, 0);
402 #endif /* HIDDENDOT */
404 #ifdef NEWAPPICON
405 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
406 int active=0;
407 if (aicon->main_window==None) {
408 active = (aicon->icon->owner->flags.focused ? 1 : 0);
409 } else {
410 WApplication *wapp;
412 wapp = wApplicationOf(aicon->main_window);
413 if (!wapp) {
414 active = aicon->icon->owner->flags.focused;
415 wwarning("error in wAppIconPaint(). Please report it");
416 } else {
417 active = wapp->main_window_desc->flags.focused;
418 if (wapp->main_window_desc->flags.hidden
419 || !wapp->main_window_desc->flags.mapped)
420 active = -1;
423 if (active>=0)
424 drawCorner(aicon->icon, aicon->icon->owner, active);
426 #endif /* NEWAPPICON */
428 XSetClipMask(dpy, scr->copy_gc, None);
429 if (aicon->launching) {
430 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
431 0, 0, wPreferences.icon_size, wPreferences.icon_size);
437 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
439 #ifdef REDUCE_APPICONS
440 unsigned int
441 wAppIconReduceAppCount(WApplication *wapp)
443 WAppIconAppList *applist;
445 if (wapp == NULL)
446 return 0;
448 if (wapp->app_icon == NULL)
449 return 0;
451 /* If given a main window, check the applist
452 * and remove the if it exists
454 applist = wapp->app_icon->applist;
455 while (applist != NULL) {
456 if (applist->wapp == wapp) {
457 /* If this app owns the appicon, change the appicon's
458 * owner to the next app in the list or NULL
460 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
462 if (applist->next) {
463 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
464 } else if (applist->prev) {
465 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
466 } else {
467 wapp->app_icon->icon->owner = NULL;
470 if (applist->prev)
471 applist->prev->next = applist->next;
473 if (applist->next)
474 applist->next->prev = applist->prev;
476 if (applist == wapp->app_icon->applist)
477 wapp->app_icon->applist = applist->next;
479 free(applist);
481 if (wapp->app_icon->applist != NULL)
482 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
484 return (--wapp->app_icon->num_apps);
486 applist = applist->next;
488 return (--wapp->app_icon->num_apps);
490 #endif
493 static void
494 hideCallback(WMenu *menu, WMenuEntry *entry)
496 WApplication *wapp = (WApplication*)entry->clientdata;
498 if (wapp->flags.hidden) {
499 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
500 wUnhideApplication(wapp, False, False);
501 } else {
502 wHideApplication(wapp);
507 static void
508 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
510 WApplication *wapp = (WApplication*)entry->clientdata;
512 wUnhideApplication(wapp, False, True);
516 static void
517 setIconCallback(WMenu *menu, WMenuEntry *entry)
519 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
520 char *file=NULL;
521 WScreen *scr;
522 int result;
524 assert(icon!=NULL);
526 if (icon->editing)
527 return;
528 icon->editing = 1;
529 scr = icon->icon->core->screen_ptr;
531 wretain(icon);
533 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
535 if (result && !icon->destroyed) {
536 if (file[0]==0) {
537 free(file);
538 file = NULL;
540 if (!wIconChangeImageFile(icon->icon, file)) {
541 wMessageDialog(scr, _("Error"),
542 _("Could not open specified icon file"),
543 _("OK"), NULL, NULL);
544 } else {
545 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
546 wAppIconPaint(icon);
548 if (file)
549 free(file);
551 icon->editing = 0;
552 wrelease(icon);
556 static void
557 killCallback(WMenu *menu, WMenuEntry *entry)
559 WApplication *wapp = (WApplication*)entry->clientdata;
560 char *buffer;
562 if (!WCHECK_STATE(WSTATE_NORMAL))
563 return;
565 WCHANGE_STATE(WSTATE_MODAL);
567 assert(entry->clientdata!=NULL);
569 buffer = wstrappend(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
570 _(" will be forcibly closed.\n"
571 "Any unsaved changes will be lost.\n"
572 "Please confirm."));
574 wretain(wapp->main_window_desc);
575 if (wPreferences.dont_confirm_kill
576 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
577 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
578 if (!wapp->main_window_desc->flags.destroyed)
579 wClientKill(wapp->main_window_desc);
581 wrelease(wapp->main_window_desc);
583 free(buffer);
585 WCHANGE_STATE(WSTATE_NORMAL);
589 static WMenu*
590 createApplicationMenu(WScreen *scr)
592 WMenu *menu;
594 menu = wMenuCreate(scr, NULL, False);
595 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
596 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
597 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
598 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
600 return menu;
604 static void
605 openApplicationMenu(WApplication *wapp, int x, int y)
607 WMenu *menu;
608 WScreen *scr = wapp->main_window_desc->screen_ptr;
609 int i;
611 if (!scr->icon_menu) {
612 scr->icon_menu = createApplicationMenu(scr);
613 free(scr->icon_menu->entries[1]->text);
616 menu = scr->icon_menu;
618 if (wapp->flags.hidden) {
619 menu->entries[1]->text = _("Unhide");
620 } else {
621 menu->entries[1]->text = _("Hide");
624 menu->flags.realized = 0;
625 wMenuRealize(menu);
627 x -= menu->frame->core->width/2;
628 if (x + menu->frame->core->width > scr->scr_width)
629 x = scr->scr_width - menu->frame->core->width;
630 if (x < 0)
631 x = 0;
633 /* set client data */
634 for (i = 0; i < menu->entry_no; i++) {
635 menu->entries[i]->clientdata = wapp;
637 wMenuMapAt(menu, x, y, False);
641 /******************************************************************/
643 static void
644 iconExpose(WObjDescriptor *desc, XEvent *event)
646 wAppIconPaint(desc->parent);
650 static void
651 iconDblClick(WObjDescriptor *desc, XEvent *event)
653 WAppIcon *aicon = desc->parent;
654 WApplication *wapp;
655 WScreen *scr = aicon->icon->core->screen_ptr;
656 int unhideHere;
658 #ifndef REDUCE_APPICONS
659 assert(aicon->icon->owner!=NULL);
660 #else
661 if (aicon->icon->owner == NULL) {
662 fprintf(stderr, "Double-click disabled: missing main window.\n");
663 return;
665 #endif
667 wapp = wApplicationOf(aicon->icon->owner->main_window);
668 #ifdef DEBUG0
669 if (!wapp) {
670 wwarning("could not find application descriptor for app icon!!");
671 return;
673 #endif
674 #ifdef REDUCE_APPICONS
675 if (!wapp) {
676 fprintf(stderr, "Double-click disabled: missing wapp.\n");
677 return;
679 #endif /* REDUCE_APPICONS */
681 unhideHere = (event->xbutton.state & ShiftMask);
683 /* go to the last workspace that the user worked on the app */
684 if (!unhideHere && wapp->last_workspace != scr->current_workspace)
685 wWorkspaceChange(scr, wapp->last_workspace);
687 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
689 if (event->xbutton.state & MOD_MASK) {
690 wHideOtherApplications(aicon->icon->owner);
695 void
696 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
698 WAppIcon *aicon = desc->parent;
699 WIcon *icon = aicon->icon;
700 XEvent ev;
701 int x=aicon->x_pos, y=aicon->y_pos;
702 int dx=event->xbutton.x, dy=event->xbutton.y;
703 int grabbed=0;
704 int done=0;
705 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
706 WScreen *scr = icon->core->screen_ptr;
707 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
708 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
709 int ix, iy;
710 int clickButton = event->xbutton.button;
711 Pixmap ghost = None;
713 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
714 return;
716 if (IsDoubleClick(scr, event)) {
717 iconDblClick(desc, event);
718 return;
721 if (event->xbutton.button == Button3) {
722 WObjDescriptor *desc;
723 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
725 if (!wapp)
726 return;
728 openApplicationMenu(wapp, event->xbutton.x_root,
729 event->xbutton.y_root);
731 /* allow drag select of menu */
732 desc = &scr->icon_menu->menu->descriptor;
733 event->xbutton.send_event = True;
734 (*desc->handle_mousedown)(desc, event);
735 return;
738 #ifdef DEBUG
739 puts("Moving icon");
740 #endif
741 if (event->xbutton.state & MOD_MASK)
742 wLowerFrame(icon->core);
743 else
744 wRaiseFrame(icon->core);
747 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
748 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
749 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
750 wwarning("pointer grab failed for appicon move");
753 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
754 dockable = 0;
755 else
756 dockable = canBeDocked(icon->owner);
759 while (!done) {
760 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
761 |ButtonMotionMask|ExposureMask, &ev);
762 switch (ev.type) {
763 case Expose:
764 WMHandleEvent(&ev);
765 break;
767 case MotionNotify:
768 if (!grabbed) {
769 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
770 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
771 XChangeActivePointerGrab(dpy, ButtonMotionMask
772 |ButtonReleaseMask|ButtonPressMask,
773 wCursor[WCUR_MOVE], CurrentTime);
774 grabbed=1;
775 } else {
776 break;
779 x = ev.xmotion.x_root - dx;
780 y = ev.xmotion.y_root - dy;
781 XMoveWindow(dpy, icon->core->window, x, y);
783 if (dockable) {
784 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
785 &ix, &iy, False)) {
786 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
787 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
789 if (scr->last_dock != scr->dock && collapsed) {
790 scr->last_dock->collapsed = 1;
791 wDockHideIcons(scr->last_dock);
792 collapsed = 0;
794 if (!collapsed && (collapsed = scr->dock->collapsed)) {
795 scr->dock->collapsed = 0;
796 wDockShowIcons(scr->dock);
799 if (scr->dock->auto_raise_lower)
800 wDockRaise(scr->dock);
802 scr->last_dock = scr->dock;
804 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
805 if (!docking) {
806 Window wins[2];
808 wins[0] = icon->core->window;
809 wins[1] = scr->dock_shadow;
810 XRestackWindows(dpy, wins, 2);
811 if (superfluous) {
812 if (icon->pixmap!=None)
813 ghost = MakeGhostIcon(scr, icon->pixmap);
814 else
815 ghost = MakeGhostIcon(scr, icon->core->window);
816 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
817 ghost);
818 XClearWindow(dpy, scr->dock_shadow);
820 XMapWindow(dpy, scr->dock_shadow);
822 docking = 1;
823 } else if (workspace->clip &&
824 wDockSnapIcon(workspace->clip, aicon, x, y,
825 &ix, &iy, False)) {
826 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
827 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
829 if (scr->last_dock != workspace->clip && collapsed) {
830 scr->last_dock->collapsed = 1;
831 wDockHideIcons(scr->last_dock);
832 collapsed = 0;
834 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
835 workspace->clip->collapsed = 0;
836 wDockShowIcons(workspace->clip);
839 if (workspace->clip->auto_raise_lower)
840 wDockRaise(workspace->clip);
842 scr->last_dock = workspace->clip;
844 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
845 if (!docking) {
846 Window wins[2];
848 wins[0] = icon->core->window;
849 wins[1] = scr->dock_shadow;
850 XRestackWindows(dpy, wins, 2);
851 if (superfluous) {
852 if (icon->pixmap!=None)
853 ghost = MakeGhostIcon(scr, icon->pixmap);
854 else
855 ghost = MakeGhostIcon(scr, icon->core->window);
856 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
857 ghost);
858 XClearWindow(dpy, scr->dock_shadow);
860 XMapWindow(dpy, scr->dock_shadow);
862 docking = 1;
863 } else if (docking) {
864 XUnmapWindow(dpy, scr->dock_shadow);
865 docking = 0;
869 break;
871 case ButtonPress:
872 break;
874 case ButtonRelease:
875 if (ev.xbutton.button != clickButton)
876 break;
877 XUngrabPointer(dpy, CurrentTime);
879 if (docking) {
880 Bool docked;
882 /* icon is trying to be docked */
883 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
884 XUnmapWindow(dpy, scr->dock_shadow);
885 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
886 if (scr->last_dock->auto_collapse) {
887 collapsed = 0;
889 if (workspace->clip &&
890 workspace->clip != scr->last_dock &&
891 workspace->clip->auto_raise_lower)
892 wDockLower(workspace->clip);
894 if (!docked) {
895 /* If icon could not be docked, slide it back to the old
896 * position */
897 SlideWindow(icon->core->window, x, y, aicon->x_pos,
898 aicon->y_pos);
900 } else {
901 XMoveWindow(dpy, icon->core->window, x, y);
902 aicon->x_pos = x;
903 aicon->y_pos = y;
904 if (workspace->clip && workspace->clip->auto_raise_lower)
905 wDockLower(workspace->clip);
907 if (collapsed) {
908 scr->last_dock->collapsed = 1;
909 wDockHideIcons(scr->last_dock);
910 collapsed = 0;
912 if (superfluous) {
913 if (ghost!=None)
914 XFreePixmap(dpy, ghost);
915 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
918 if (wPreferences.auto_arrange_icons)
919 wArrangeIcons(scr, True);
921 done = 1;
922 break;
925 #ifdef DEBUG
926 puts("End icon move");
927 #endif