show workspace name when changing workspace
[wmaker-crm.git] / src / appicon.c
blob942c419672cda91c54a483ab80168d90aa75faf2
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);
649 static void
650 iconDblClick(WObjDescriptor *desc, XEvent *event)
652 WAppIcon *aicon = desc->parent;
653 WApplication *wapp;
654 WScreen *scr = aicon->icon->core->screen_ptr;
655 int unhideHere;
657 #ifndef REDUCE_APPICONS
658 assert(aicon->icon->owner!=NULL);
659 #else
660 if (aicon->icon->owner == NULL) {
661 fprintf(stderr, "Double-click disabled: missing main window.\n");
662 return;
664 #endif
666 wapp = wApplicationOf(aicon->icon->owner->main_window);
667 #ifdef DEBUG0
668 if (!wapp) {
669 wwarning("could not find application descriptor for app icon!!");
670 return;
672 #endif
673 #ifdef REDUCE_APPICONS
674 if (!wapp) {
675 fprintf(stderr, "Double-click disabled: missing wapp.\n");
676 return;
678 #endif /* REDUCE_APPICONS */
680 printf("%i\n",wapp->refcount);
682 unhideHere = (event->xbutton.state & ShiftMask);
684 /* go to the last workspace that the user worked on the app */
685 if (!unhideHere)
686 wWorkspaceChange(scr, wapp->last_workspace);
688 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
690 if (event->xbutton.state & MOD_MASK) {
691 wHideOtherApplications(aicon->icon->owner);
696 void
697 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
699 WAppIcon *aicon = desc->parent;
700 WIcon *icon = aicon->icon;
701 XEvent ev;
702 int x=aicon->x_pos, y=aicon->y_pos;
703 int dx=event->xbutton.x, dy=event->xbutton.y;
704 int grabbed=0;
705 int done=0;
706 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
707 WScreen *scr = icon->core->screen_ptr;
708 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
709 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
710 int ix, iy;
711 int clickButton = event->xbutton.button;
712 Pixmap ghost = None;
714 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
715 return;
717 if (IsDoubleClick(scr, event)) {
718 iconDblClick(desc, event);
719 return;
722 if (event->xbutton.button == Button3) {
723 WObjDescriptor *desc;
724 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
726 if (!wapp)
727 return;
729 openApplicationMenu(wapp, event->xbutton.x_root,
730 event->xbutton.y_root);
732 /* allow drag select of menu */
733 desc = &scr->icon_menu->menu->descriptor;
734 event->xbutton.send_event = True;
735 (*desc->handle_mousedown)(desc, event);
736 return;
739 #ifdef DEBUG
740 puts("Moving icon");
741 #endif
742 if (event->xbutton.state & MOD_MASK)
743 wLowerFrame(icon->core);
744 else
745 wRaiseFrame(icon->core);
748 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
749 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
750 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
751 wwarning("pointer grab failed for appicon move");
754 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
755 dockable = 0;
756 else
757 dockable = canBeDocked(icon->owner);
760 while (!done) {
761 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
762 |ButtonMotionMask|ExposureMask, &ev);
763 switch (ev.type) {
764 case Expose:
765 WMHandleEvent(&ev);
766 break;
768 case MotionNotify:
769 if (!grabbed) {
770 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
771 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
772 XChangeActivePointerGrab(dpy, ButtonMotionMask
773 |ButtonReleaseMask|ButtonPressMask,
774 wCursor[WCUR_MOVE], CurrentTime);
775 grabbed=1;
776 } else {
777 break;
780 x = ev.xmotion.x_root - dx;
781 y = ev.xmotion.y_root - dy;
782 XMoveWindow(dpy, icon->core->window, x, y);
784 if (dockable) {
785 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
786 &ix, &iy, False)) {
787 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
788 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
790 if (scr->last_dock != scr->dock && collapsed) {
791 scr->last_dock->collapsed = 1;
792 wDockHideIcons(scr->last_dock);
793 collapsed = 0;
795 if (!collapsed && (collapsed = scr->dock->collapsed)) {
796 scr->dock->collapsed = 0;
797 wDockShowIcons(scr->dock);
800 if (scr->dock->auto_raise_lower)
801 wDockRaise(scr->dock);
803 scr->last_dock = scr->dock;
805 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
806 if (!docking) {
807 Window wins[2];
809 wins[0] = icon->core->window;
810 wins[1] = scr->dock_shadow;
811 XRestackWindows(dpy, wins, 2);
812 if (superfluous) {
813 if (icon->pixmap!=None)
814 ghost = MakeGhostIcon(scr, icon->pixmap);
815 else
816 ghost = MakeGhostIcon(scr, icon->core->window);
817 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
818 ghost);
819 XClearWindow(dpy, scr->dock_shadow);
821 XMapWindow(dpy, scr->dock_shadow);
823 docking = 1;
824 } else if (workspace->clip &&
825 wDockSnapIcon(workspace->clip, aicon, x, y,
826 &ix, &iy, False)) {
827 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
828 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
830 if (scr->last_dock != workspace->clip && collapsed) {
831 scr->last_dock->collapsed = 1;
832 wDockHideIcons(scr->last_dock);
833 collapsed = 0;
835 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
836 workspace->clip->collapsed = 0;
837 wDockShowIcons(workspace->clip);
840 if (workspace->clip->auto_raise_lower)
841 wDockRaise(workspace->clip);
843 scr->last_dock = workspace->clip;
845 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
846 if (!docking) {
847 Window wins[2];
849 wins[0] = icon->core->window;
850 wins[1] = scr->dock_shadow;
851 XRestackWindows(dpy, wins, 2);
852 if (superfluous) {
853 if (icon->pixmap!=None)
854 ghost = MakeGhostIcon(scr, icon->pixmap);
855 else
856 ghost = MakeGhostIcon(scr, icon->core->window);
857 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
858 ghost);
859 XClearWindow(dpy, scr->dock_shadow);
861 XMapWindow(dpy, scr->dock_shadow);
863 docking = 1;
864 } else if (docking) {
865 XUnmapWindow(dpy, scr->dock_shadow);
866 docking = 0;
870 break;
872 case ButtonPress:
873 break;
875 case ButtonRelease:
876 if (ev.xbutton.button != clickButton)
877 break;
878 XUngrabPointer(dpy, CurrentTime);
880 if (docking) {
881 Bool docked;
883 /* icon is trying to be docked */
884 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
885 XUnmapWindow(dpy, scr->dock_shadow);
886 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
887 if (scr->last_dock->auto_collapse) {
888 collapsed = 0;
890 if (workspace->clip &&
891 workspace->clip != scr->last_dock &&
892 workspace->clip->auto_raise_lower)
893 wDockLower(workspace->clip);
895 if (!docked) {
896 /* If icon could not be docked, slide it back to the old
897 * position */
898 SlideWindow(icon->core->window, x, y, aicon->x_pos,
899 aicon->y_pos);
901 } else {
902 XMoveWindow(dpy, icon->core->window, x, y);
903 aicon->x_pos = x;
904 aicon->y_pos = y;
905 if (workspace->clip && workspace->clip->auto_raise_lower)
906 wDockLower(workspace->clip);
908 if (collapsed) {
909 scr->last_dock->collapsed = 1;
910 wDockHideIcons(scr->last_dock);
911 collapsed = 0;
913 if (superfluous) {
914 if (ghost!=None)
915 XFreePixmap(dpy, ghost);
916 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
918 done = 1;
919 break;
922 #ifdef DEBUG
923 puts("End icon move");
924 #endif