MenuStyle option
[wmaker-crm.git] / src / appicon.c
blob026475f73b6a27a2ab99c356347a475e3ae3c9a2
1 /* appicon.c- icon for applications (not mini-window)
3 * Window Maker 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 #ifndef REDUCE_APPICONS
157 scr->app_icon_list->prev = aicon;
158 #else
159 /* If we aren't going to have a match, jump straight to new appicon */
160 if (leader_win->wm_class == NULL || leader_win->wm_class == NULL)
161 atmp = NULL;
162 else
163 atmp = scr->app_icon_list;
165 while (atmp != NULL) {
166 if ((tinstance = atmp->wm_instance) == NULL)
167 tinstance = "";
168 if ((tclass = atmp->wm_class) == NULL)
169 tclass = "";
170 if ((strcmp(leader_win->wm_class, tclass) == 0) &&
171 (strcmp(leader_win->wm_instance, tinstance) == 0))
173 /* We have a winner */
174 wrelease(aicon);
175 atmp->num_apps++;
176 applist->next = atmp->applist;
177 if (atmp->applist)
178 atmp->applist->prev = applist;
179 atmp->applist = applist;
181 if (atmp->docked) {
182 wDockSimulateLaunch(atmp->dock, atmp);
185 return atmp;
187 atmp = atmp->next;
189 if (atmp == NULL) {
190 scr->app_icon_list->prev = aicon;
192 #endif /* REDUCE_APPICONS */
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 HIDDENDOT
374 WApplication *wapp;
375 wapp = wApplicationOf(aicon->main_window);
376 if(wapp)
377 if(wapp->flags.hidden){
378 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
379 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
380 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
381 scr->copy_gc, 0, 0, 7,
382 scr->dock_dots->height, 0, 0);
385 #endif /* HIDDENDOT */
387 #ifdef NEWAPPICON
388 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
389 int active=0;
390 if (aicon->main_window==None) {
391 active = (aicon->icon->owner->flags.focused ? 1 : 0);
392 } else {
393 WApplication *wapp;
395 wapp = wApplicationOf(aicon->main_window);
396 if (!wapp) {
397 active = aicon->icon->owner->flags.focused;
398 wwarning("error in wAppIconPaint(). Please report it");
399 } else {
400 active = wapp->main_window_desc->flags.focused;
401 if (wapp->main_window_desc->flags.hidden
402 || !wapp->main_window_desc->flags.mapped)
403 active = -1;
406 if (active>=0)
407 drawCorner(aicon->icon, aicon->icon->owner, active);
409 #endif /* NEWAPPICON */
411 XSetClipMask(dpy, scr->copy_gc, None);
412 if (aicon->launching) {
413 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
414 0, 0, wPreferences.icon_size, wPreferences.icon_size);
420 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
422 #ifdef REDUCE_APPICONS
423 unsigned int
424 wAppIconReduceAppCount(WApplication *wapp)
426 WAppIconAppList *applist;
428 if (wapp == NULL)
429 return 0;
431 if (wapp->app_icon == NULL)
432 return 0;
434 /* If given a main window, check the applist
435 * and remove the if it exists
437 applist = wapp->app_icon->applist;
438 while (applist != NULL) {
439 if (applist->wapp == wapp) {
440 /* If this app owns the appicon, change the appicon's
441 * owner to the next app in the list or NULL
443 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
445 if (applist->next) {
446 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
447 } else if (applist->prev) {
448 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
449 } else {
450 wapp->app_icon->icon->owner = NULL;
453 if (applist->prev)
454 applist->prev->next = applist->next;
456 if (applist->next)
457 applist->next->prev = applist->prev;
459 if (applist == wapp->app_icon->applist)
460 wapp->app_icon->applist = applist->next;
462 free(applist);
464 if (wapp->app_icon->applist != NULL)
465 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
467 return (--wapp->app_icon->num_apps);
469 applist = applist->next;
471 return (--wapp->app_icon->num_apps);
473 #endif
476 static void
477 hideCallback(WMenu *menu, WMenuEntry *entry)
479 WApplication *wapp = (WApplication*)entry->clientdata;
481 if (wapp->flags.hidden) {
482 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
483 wUnhideApplication(wapp, False, False);
484 } else {
485 wHideApplication(wapp);
490 static void
491 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
493 WApplication *wapp = (WApplication*)entry->clientdata;
495 wUnhideApplication(wapp, False, True);
499 static void
500 setIconCallback(WMenu *menu, WMenuEntry *entry)
502 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
503 char *file=NULL;
504 WScreen *scr;
505 int result;
507 assert(icon!=NULL);
509 if (icon->editing)
510 return;
511 icon->editing = 1;
512 scr = icon->icon->core->screen_ptr;
514 wretain(icon);
516 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
518 if (result && !icon->destroyed) {
519 if (file[0]==0) {
520 free(file);
521 file = NULL;
523 if (!wIconChangeImageFile(icon->icon, file)) {
524 wMessageDialog(scr, _("Error"),
525 _("Could not open specified icon file"),
526 _("OK"), NULL, NULL);
527 } else {
528 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
529 wAppIconPaint(icon);
531 if (file)
532 free(file);
534 icon->editing = 0;
535 wrelease(icon);
539 static void
540 killCallback(WMenu *menu, WMenuEntry *entry)
542 WApplication *wapp = (WApplication*)entry->clientdata;
543 char *buffer;
545 if (!WCHECK_STATE(WSTATE_NORMAL))
546 return;
548 WCHANGE_STATE(WSTATE_MODAL);
550 assert(entry->clientdata!=NULL);
552 buffer = wstrappend(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
553 _(" will be forcibly closed.\n"
554 "Any unsaved changes will be lost.\n"
555 "Please confirm."));
557 wretain(wapp->main_window_desc);
558 if (wPreferences.dont_confirm_kill
559 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
560 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
561 if (!wapp->main_window_desc->flags.destroyed)
562 wClientKill(wapp->main_window_desc);
564 wrelease(wapp->main_window_desc);
566 free(buffer);
568 WCHANGE_STATE(WSTATE_NORMAL);
572 static WMenu*
573 createApplicationMenu(WScreen *scr)
575 WMenu *menu;
577 menu = wMenuCreate(scr, NULL, False);
578 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
579 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
580 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
581 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
583 return menu;
587 static void
588 openApplicationMenu(WApplication *wapp, int x, int y)
590 WMenu *menu;
591 WScreen *scr = wapp->main_window_desc->screen_ptr;
592 int i;
594 if (!scr->icon_menu) {
595 scr->icon_menu = createApplicationMenu(scr);
596 free(scr->icon_menu->entries[1]->text);
599 menu = scr->icon_menu;
601 if (wapp->flags.hidden) {
602 menu->entries[1]->text = _("Unhide");
603 } else {
604 menu->entries[1]->text = _("Hide");
607 menu->flags.realized = 0;
608 wMenuRealize(menu);
610 x -= menu->frame->core->width/2;
611 if (x + menu->frame->core->width > scr->scr_width)
612 x = scr->scr_width - menu->frame->core->width;
613 if (x < 0)
614 x = 0;
616 /* set client data */
617 for (i = 0; i < menu->entry_no; i++) {
618 menu->entries[i]->clientdata = wapp;
620 wMenuMapAt(menu, x, y, False);
624 /******************************************************************/
626 static void
627 iconExpose(WObjDescriptor *desc, XEvent *event)
629 wAppIconPaint(desc->parent);
632 static void
633 iconDblClick(WObjDescriptor *desc, XEvent *event)
635 WAppIcon *aicon = desc->parent;
636 WApplication *wapp;
637 WScreen *scr = aicon->icon->core->screen_ptr;
638 int unhideHere;
640 #ifndef REDUCE_APPICONS
641 assert(aicon->icon->owner!=NULL);
642 #else
643 if (aicon->icon->owner == NULL) {
644 fprintf(stderr, "Double-click disabled: missing main window.\n");
645 return;
647 #endif
649 wapp = wApplicationOf(aicon->icon->owner->main_window);
650 #ifdef DEBUG0
651 if (!wapp) {
652 wwarning("could not find application descriptor for app icon!!");
653 return;
655 #endif
656 #ifdef REDUCE_APPICONS
657 if (!wapp) {
658 fprintf(stderr, "Double-click disabled: missing wapp.\n");
659 return;
661 #endif /* REDUCE_APPICONS */
662 #if 0
663 /* aproveita que ta aqui pra atualizar */
664 wapp->main_window = aicon->icon->owner->main_window;
665 #endif
667 unhideHere = (event->xbutton.state & ShiftMask);
669 /* go to the last workspace that the user worked on the app */
670 if (!unhideHere)
671 wWorkspaceChange(scr, wapp->last_workspace);
673 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
675 if (event->xbutton.state & MOD_MASK) {
676 wHideOtherApplications(aicon->icon->owner);
681 void
682 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
684 WAppIcon *aicon = desc->parent;
685 WIcon *icon = aicon->icon;
686 XEvent ev;
687 int x=aicon->x_pos, y=aicon->y_pos;
688 int dx=event->xbutton.x, dy=event->xbutton.y;
689 int grabbed=0;
690 int done=0;
691 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
692 WScreen *scr = icon->core->screen_ptr;
693 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
694 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
695 int ix, iy;
696 int clickButton = event->xbutton.button;
697 Pixmap ghost = None;
699 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
700 return;
702 if (IsDoubleClick(scr, event)) {
703 iconDblClick(desc, event);
704 return;
707 if (event->xbutton.button == Button3) {
708 WObjDescriptor *desc;
709 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
711 if (!wapp)
712 return;
714 openApplicationMenu(wapp, event->xbutton.x_root,
715 event->xbutton.y_root);
717 /* allow drag select of menu */
718 desc = &scr->icon_menu->menu->descriptor;
719 event->xbutton.send_event = True;
720 (*desc->handle_mousedown)(desc, event);
721 return;
724 #ifdef DEBUG
725 puts("Moving icon");
726 #endif
727 if (event->xbutton.state & MOD_MASK)
728 wLowerFrame(icon->core);
729 else
730 wRaiseFrame(icon->core);
733 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
734 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
735 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
736 wwarning("pointer grab failed for appicon move");
739 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
740 dockable = 0;
741 else
742 dockable = canBeDocked(icon->owner);
745 while (!done) {
746 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
747 |ButtonMotionMask|ExposureMask, &ev);
748 switch (ev.type) {
749 case Expose:
750 WMHandleEvent(&ev);
751 break;
753 case MotionNotify:
754 if (!grabbed) {
755 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
756 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
757 XChangeActivePointerGrab(dpy, ButtonMotionMask
758 |ButtonReleaseMask|ButtonPressMask,
759 wCursor[WCUR_MOVE], CurrentTime);
760 grabbed=1;
761 } else {
762 break;
765 x = ev.xmotion.x_root - dx;
766 y = ev.xmotion.y_root - dy;
767 XMoveWindow(dpy, icon->core->window, x, y);
769 if (dockable) {
770 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
771 &ix, &iy, False)) {
772 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
773 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
775 if (scr->last_dock != scr->dock && collapsed) {
776 scr->last_dock->collapsed = 1;
777 wDockHideIcons(scr->last_dock);
778 collapsed = 0;
780 if (!collapsed && (collapsed = scr->dock->collapsed)) {
781 scr->dock->collapsed = 0;
782 wDockShowIcons(scr->dock);
785 if (scr->dock->auto_raise_lower)
786 wDockRaise(scr->dock);
788 scr->last_dock = scr->dock;
790 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
791 if (!docking) {
792 Window wins[2];
794 wins[0] = icon->core->window;
795 wins[1] = scr->dock_shadow;
796 XRestackWindows(dpy, wins, 2);
797 if (superfluous) {
798 if (icon->pixmap!=None)
799 ghost = MakeGhostIcon(scr, icon->pixmap);
800 else
801 ghost = MakeGhostIcon(scr, icon->core->window);
802 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
803 ghost);
804 XClearWindow(dpy, scr->dock_shadow);
806 XMapWindow(dpy, scr->dock_shadow);
808 docking = 1;
809 } else if (workspace->clip &&
810 wDockSnapIcon(workspace->clip, aicon, x, y,
811 &ix, &iy, False)) {
812 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
813 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
815 if (scr->last_dock != workspace->clip && collapsed) {
816 scr->last_dock->collapsed = 1;
817 wDockHideIcons(scr->last_dock);
818 collapsed = 0;
820 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
821 workspace->clip->collapsed = 0;
822 wDockShowIcons(workspace->clip);
825 if (workspace->clip->auto_raise_lower)
826 wDockRaise(workspace->clip);
828 scr->last_dock = workspace->clip;
830 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
831 if (!docking) {
832 Window wins[2];
834 wins[0] = icon->core->window;
835 wins[1] = scr->dock_shadow;
836 XRestackWindows(dpy, wins, 2);
837 if (superfluous) {
838 if (icon->pixmap!=None)
839 ghost = MakeGhostIcon(scr, icon->pixmap);
840 else
841 ghost = MakeGhostIcon(scr, icon->core->window);
842 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
843 ghost);
844 XClearWindow(dpy, scr->dock_shadow);
846 XMapWindow(dpy, scr->dock_shadow);
848 docking = 1;
849 } else if (docking) {
850 XUnmapWindow(dpy, scr->dock_shadow);
851 docking = 0;
855 break;
857 case ButtonPress:
858 break;
860 case ButtonRelease:
861 if (ev.xbutton.button != clickButton)
862 break;
863 XUngrabPointer(dpy, CurrentTime);
865 if (docking) {
866 Bool docked;
868 /* icon is trying to be docked */
869 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
870 XUnmapWindow(dpy, scr->dock_shadow);
871 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
872 if (scr->last_dock->auto_collapse) {
873 collapsed = 0;
875 if (workspace->clip &&
876 workspace->clip != scr->last_dock &&
877 workspace->clip->auto_raise_lower)
878 wDockLower(workspace->clip);
880 if (!docked) {
881 /* If icon could not be docked, slide it back to the old
882 * position */
883 SlideWindow(icon->core->window, x, y, aicon->x_pos,
884 aicon->y_pos);
886 } else {
887 XMoveWindow(dpy, icon->core->window, x, y);
888 aicon->x_pos = x;
889 aicon->y_pos = y;
890 if (workspace->clip && workspace->clip->auto_raise_lower)
891 wDockLower(workspace->clip);
893 if (collapsed) {
894 scr->last_dock->collapsed = 1;
895 wDockHideIcons(scr->last_dock);
896 collapsed = 0;
898 if (superfluous) {
899 if (ghost!=None)
900 XFreePixmap(dpy, ghost);
901 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
903 done = 1;
904 break;
907 #ifdef DEBUG
908 puts("End icon move");
909 #endif