Added the crash dialog panel
[wmaker-crm.git] / src / appicon.c
blobf79072be3456792e07c47d9205c4d8ba970d0e06
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
110 /* will be overriden by dock */
111 dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
112 dicon->icon->core->descriptor.handle_expose = iconExpose;
113 dicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
114 dicon->icon->core->descriptor.parent = dicon;
115 AddToStackList(dicon->icon->core);
117 return dicon;
122 WAppIcon*
123 wAppIconCreate(WWindow *leader_win)
125 WAppIcon *aicon;
126 #ifdef REDUCE_APPICONS
127 WAppIcon *atmp;
128 WAppIconAppList *applist;
129 char *tinstance, *tclass;
130 #endif
131 WScreen *scr = leader_win->screen_ptr;
133 aicon = wmalloc(sizeof(WAppIcon));
134 wretain(aicon);
135 memset(aicon, 0, sizeof(WAppIcon));
136 #ifdef REDUCE_APPICONS
137 applist = wmalloc(sizeof(WAppIconAppList));
138 memset(applist, 0, sizeof(WAppIconAppList));
139 applist->wapp = wApplicationOf(leader_win->main_window);
140 aicon->applist = applist;
141 if (applist->wapp == NULL) {
142 /* Something's wrong. wApplicationOf() should always return a
143 * valid structure. Rather than violate assumptions, bail. -cls
145 free(applist);
146 wrelease(aicon);
147 return NULL;
149 #endif
151 aicon->yindex = -1;
152 aicon->xindex = -1;
154 aicon->prev = NULL;
155 aicon->next = scr->app_icon_list;
156 if (scr->app_icon_list) {
157 #ifndef REDUCE_APPICONS
158 scr->app_icon_list->prev = aicon;
159 #else
160 /* If we aren't going to have a match, jump straight to new appicon */
161 if (leader_win->wm_class == NULL || leader_win->wm_class == NULL)
162 atmp = NULL;
163 else
164 atmp = scr->app_icon_list;
166 while (atmp != NULL) {
167 if ((tinstance = atmp->wm_instance) == NULL)
168 tinstance = "";
169 if ((tclass = atmp->wm_class) == NULL)
170 tclass = "";
171 if ((strcmp(leader_win->wm_class, tclass) == 0) &&
172 (strcmp(leader_win->wm_instance, tinstance) == 0))
174 /* We have a winner */
175 wrelease(aicon);
176 atmp->num_apps++;
177 applist->next = atmp->applist;
178 if (atmp->applist)
179 atmp->applist->prev = applist;
180 atmp->applist = applist;
182 if (atmp->docked) {
183 wDockSimulateLaunch(atmp->dock, atmp);
186 return atmp;
188 atmp = atmp->next;
190 if (atmp == NULL) {
191 scr->app_icon_list->prev = aicon;
193 #endif /* REDUCE_APPICONS */
195 scr->app_icon_list = aicon;
197 if (leader_win->wm_class)
198 aicon->wm_class = wstrdup(leader_win->wm_class);
199 if (leader_win->wm_instance)
200 aicon->wm_instance = wstrdup(leader_win->wm_instance);
201 #ifdef REDUCE_APPICONS
202 aicon->num_apps = 1;
203 #endif
205 aicon->icon = wIconCreate(leader_win);
207 /* will be overriden if docked */
208 aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
209 aicon->icon->core->descriptor.handle_expose = iconExpose;
210 aicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
211 aicon->icon->core->descriptor.parent = aicon;
212 AddToStackList(aicon->icon->core);
213 aicon->icon->show_title = 0;
214 wIconUpdate(aicon->icon);
216 return aicon;
220 void
221 wAppIconDestroy(WAppIcon *aicon)
223 WScreen *scr = aicon->icon->core->screen_ptr;
224 #ifdef REDUCE_APPICONS
225 WAppIconAppList *aptmp;
226 #endif
228 RemoveFromStackList(aicon->icon->core);
229 wIconDestroy(aicon->icon);
230 if (aicon->command)
231 free(aicon->command);
232 #ifdef OFFIX_DND
233 if (aicon->dnd_command)
234 free(aicon->dnd_command);
235 #endif
236 if (aicon->wm_instance)
237 free(aicon->wm_instance);
238 if (aicon->wm_class)
239 free(aicon->wm_class);
240 #ifdef REDUCE_APPICONS
241 /* There should never be a list but just in case */
242 if (aicon->applist != NULL) {
243 aptmp = aicon->applist;
244 while (aptmp->next) {
245 aptmp = aptmp->next;
246 free(aptmp->prev);
248 free(aptmp);
250 #endif
252 if (aicon == scr->app_icon_list) {
253 if (aicon->next)
254 aicon->next->prev = NULL;
255 scr->app_icon_list = aicon->next;
257 else {
258 if (aicon->next)
259 aicon->next->prev = aicon->prev;
260 if (aicon->prev)
261 aicon->prev->next = aicon->next;
264 aicon->destroyed = 1;
265 wrelease(aicon);
270 #ifdef NEWAPPICON
271 static void
272 drawCorner(WIcon *icon, WWindow *wwin, int active)
274 WScreen *scr = wwin->screen_ptr;
275 XPoint points[3];
276 GC gc;
278 points[0].x = 2;
279 points[0].y = 2;
280 points[1].x = 12;
281 points[1].y = 2;
282 points[2].x = 2;
283 points[2].y = 12;
284 if (active) {
285 gc=scr->focused_texture->any.gc;
286 } else {
287 gc=scr->unfocused_texture->any.gc;
289 XFillPolygon(dpy, icon->core->window, gc, points, 3,
290 Convex, CoordModeOrigin);
292 #endif /* NEWAPPICON */
295 void
296 wAppIconMove(WAppIcon *aicon, int x, int y)
298 XMoveWindow(dpy, aicon->icon->core->window, x, y);
299 aicon->x_pos = x;
300 aicon->y_pos = y;
304 #ifdef WS_INDICATOR
305 static void
306 updateDockNumbers(WScreen *scr)
308 int length;
309 char *ws_numbers;
310 GC numbers_gc;
311 XGCValues my_gc_values;
312 unsigned long my_v_mask = (GCForeground);
313 WAppIcon *dicon = scr->dock->icon_array[0];
315 my_gc_values.foreground = scr->white_pixel;
316 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
317 my_v_mask, &my_gc_values);
319 ws_numbers = malloc(20);
320 sprintf(ws_numbers, "%i [ %i ]", scr->current_workspace+1,
321 ((scr->current_workspace/10)+1));
322 length = strlen(ws_numbers);
324 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
325 scr->icon_title_font->y+1, False);
327 #ifndef I18N_MB
328 XSetFont(dpy, numbers_gc, scr->icon_title_font->font->fid);
329 XSetForeground(dpy, numbers_gc, scr->black_pixel);
330 XDrawString(dpy, dicon->icon->core->window,
331 numbers_gc, 4, scr->icon_title_font->y+3, ws_numbers, length);
332 XSetForeground(dpy, numbers_gc, scr->white_pixel);
333 XDrawString(dpy, dicon->icon->core->window,
334 numbers_gc, 3, scr->icon_title_font->y+2, ws_numbers, length);
335 #else
336 XSetForeground(dpy, numbers_gc, scr->black_pixel);
337 XmbDrawString(dpy, dicon->icon->core->window,
338 scr->icon_title_font->font, numbers_gc, 4,
339 scr->icon_title_font->y+3, ws_numbers, length);
340 XSetForeground(dpy, numbers_gc, scr->white_pixel);
341 XmbDrawString(dpy, dicon->icon->core->window,
342 scr->icon_title_font->font, numbers_gc, 3,
343 scr->icon_title_font->y+2, ws_numbers, length);
344 #endif /* I18N_MB */
346 XFreeGC(dpy, numbers_gc);
347 free(ws_numbers);
349 #endif /* WS_INDICATOR */
352 void
353 wAppIconPaint(WAppIcon *aicon)
355 WScreen *scr = aicon->icon->core->screen_ptr;
357 wIconPaint(aicon->icon);
360 # ifdef WS_INDICATOR
361 if (aicon->docked && scr->dock && aicon->yindex==0)
362 updateDockNumbers(scr);
363 # endif
364 if (scr->dock_dots && aicon->docked && !aicon->running
365 && aicon->command!=NULL) {
366 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
367 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
368 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
369 scr->copy_gc, 0, 0, scr->dock_dots->width,
370 scr->dock_dots->height, 0, 0);
373 #ifdef HIDDENDOT
375 WApplication *wapp;
376 wapp = wApplicationOf(aicon->main_window);
377 if(wapp)
378 if(wapp->flags.hidden){
379 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
380 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
381 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
382 scr->copy_gc, 0, 0, 7,
383 scr->dock_dots->height, 0, 0);
386 #endif /* HIDDENDOT */
388 #ifdef NEWAPPICON
389 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
390 int active=0;
391 if (aicon->main_window==None) {
392 active = (aicon->icon->owner->flags.focused ? 1 : 0);
393 } else {
394 WApplication *wapp;
396 wapp = wApplicationOf(aicon->main_window);
397 if (!wapp) {
398 active = aicon->icon->owner->flags.focused;
399 wwarning("error in wAppIconPaint(). Please report it");
400 } else {
401 active = wapp->main_window_desc->flags.focused;
402 if (wapp->main_window_desc->flags.hidden
403 || !wapp->main_window_desc->flags.mapped)
404 active = -1;
407 if (active>=0)
408 drawCorner(aicon->icon, aicon->icon->owner, active);
410 #endif /* NEWAPPICON */
412 XSetClipMask(dpy, scr->copy_gc, None);
413 if (aicon->launching) {
414 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
415 0, 0, wPreferences.icon_size, wPreferences.icon_size);
421 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
423 #ifdef REDUCE_APPICONS
424 unsigned int
425 wAppIconReduceAppCount(WApplication *wapp)
427 WAppIconAppList *applist;
429 if (wapp == NULL)
430 return 0;
432 if (wapp->app_icon == NULL)
433 return 0;
435 /* If given a main window, check the applist
436 * and remove the if it exists
438 applist = wapp->app_icon->applist;
439 while (applist != NULL) {
440 if (applist->wapp == wapp) {
441 /* If this app owns the appicon, change the appicon's
442 * owner to the next app in the list or NULL
444 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
446 if (applist->next) {
447 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
448 } else if (applist->prev) {
449 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
450 } else {
451 wapp->app_icon->icon->owner = NULL;
454 if (applist->prev)
455 applist->prev->next = applist->next;
457 if (applist->next)
458 applist->next->prev = applist->prev;
460 if (applist == wapp->app_icon->applist)
461 wapp->app_icon->applist = applist->next;
463 free(applist);
465 if (wapp->app_icon->applist != NULL)
466 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
468 return (--wapp->app_icon->num_apps);
470 applist = applist->next;
472 return (--wapp->app_icon->num_apps);
474 #endif
477 static void
478 hideCallback(WMenu *menu, WMenuEntry *entry)
480 WApplication *wapp = (WApplication*)entry->clientdata;
482 if (wapp->flags.hidden) {
483 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
484 wUnhideApplication(wapp, False, False);
485 } else {
486 wHideApplication(wapp);
491 static void
492 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
494 WApplication *wapp = (WApplication*)entry->clientdata;
496 wUnhideApplication(wapp, False, True);
500 static void
501 setIconCallback(WMenu *menu, WMenuEntry *entry)
503 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
504 char *file=NULL;
505 WScreen *scr;
506 int result;
508 assert(icon!=NULL);
510 if (icon->editing)
511 return;
512 icon->editing = 1;
513 scr = icon->icon->core->screen_ptr;
515 wretain(icon);
517 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
519 if (result && !icon->destroyed) {
520 if (file[0]==0) {
521 free(file);
522 file = NULL;
524 if (!wIconChangeImageFile(icon->icon, file)) {
525 wMessageDialog(scr, _("Error"),
526 _("Could not open specified icon file"),
527 _("OK"), NULL, NULL);
528 } else {
529 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
530 wAppIconPaint(icon);
532 if (file)
533 free(file);
535 icon->editing = 0;
536 wrelease(icon);
540 static void
541 killCallback(WMenu *menu, WMenuEntry *entry)
543 WApplication *wapp = (WApplication*)entry->clientdata;
544 char *buffer;
546 if (!WCHECK_STATE(WSTATE_NORMAL))
547 return;
549 WCHANGE_STATE(WSTATE_MODAL);
551 assert(entry->clientdata!=NULL);
553 buffer = wstrappend(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
554 _(" will be forcibly closed.\n"
555 "Any unsaved changes will be lost.\n"
556 "Please confirm."));
558 wretain(wapp->main_window_desc);
559 if (wPreferences.dont_confirm_kill
560 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
561 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
562 if (!wapp->main_window_desc->flags.destroyed)
563 wClientKill(wapp->main_window_desc);
565 wrelease(wapp->main_window_desc);
567 free(buffer);
569 WCHANGE_STATE(WSTATE_NORMAL);
573 static WMenu*
574 createApplicationMenu(WScreen *scr)
576 WMenu *menu;
578 menu = wMenuCreate(scr, NULL, False);
579 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
580 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
581 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
582 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
584 return menu;
588 static void
589 openApplicationMenu(WApplication *wapp, int x, int y)
591 WMenu *menu;
592 WScreen *scr = wapp->main_window_desc->screen_ptr;
593 int i;
595 if (!scr->icon_menu) {
596 scr->icon_menu = createApplicationMenu(scr);
597 free(scr->icon_menu->entries[1]->text);
600 menu = scr->icon_menu;
602 if (wapp->flags.hidden) {
603 menu->entries[1]->text = _("Unhide");
604 } else {
605 menu->entries[1]->text = _("Hide");
608 menu->flags.realized = 0;
609 wMenuRealize(menu);
611 x -= menu->frame->core->width/2;
612 if (x + menu->frame->core->width > scr->scr_width)
613 x = scr->scr_width - menu->frame->core->width;
614 if (x < 0)
615 x = 0;
617 /* set client data */
618 for (i = 0; i < menu->entry_no; i++) {
619 menu->entries[i]->clientdata = wapp;
621 wMenuMapAt(menu, x, y, False);
625 /******************************************************************/
627 static void
628 iconExpose(WObjDescriptor *desc, XEvent *event)
630 wAppIconPaint(desc->parent);
633 static void
634 iconDblClick(WObjDescriptor *desc, XEvent *event)
636 WAppIcon *aicon = desc->parent;
637 WApplication *wapp;
638 WScreen *scr = aicon->icon->core->screen_ptr;
639 int unhideHere;
641 #ifndef REDUCE_APPICONS
642 assert(aicon->icon->owner!=NULL);
643 #else
644 if (aicon->icon->owner == NULL) {
645 fprintf(stderr, "Double-click disabled: missing main window.\n");
646 return;
648 #endif
650 wapp = wApplicationOf(aicon->icon->owner->main_window);
651 #ifdef DEBUG0
652 if (!wapp) {
653 wwarning("could not find application descriptor for app icon!!");
654 return;
656 #endif
657 #ifdef REDUCE_APPICONS
658 if (!wapp) {
659 fprintf(stderr, "Double-click disabled: missing wapp.\n");
660 return;
662 #endif /* REDUCE_APPICONS */
663 #if 0
664 /* aproveita que ta aqui pra atualizar */
665 wapp->main_window = aicon->icon->owner->main_window;
666 #endif
668 unhideHere = (event->xbutton.state & ShiftMask);
670 /* go to the last workspace that the user worked on the app */
671 if (!unhideHere)
672 wWorkspaceChange(scr, wapp->last_workspace);
674 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
676 if (event->xbutton.state & MOD_MASK) {
677 wHideOtherApplications(aicon->icon->owner);
682 void
683 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
685 WAppIcon *aicon = desc->parent;
686 WIcon *icon = aicon->icon;
687 XEvent ev;
688 int x=aicon->x_pos, y=aicon->y_pos;
689 int dx=event->xbutton.x, dy=event->xbutton.y;
690 int grabbed=0;
691 int done=0;
692 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
693 WScreen *scr = icon->core->screen_ptr;
694 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
695 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
696 int ix, iy;
697 int clickButton = event->xbutton.button;
698 Pixmap ghost = None;
700 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
701 return;
703 if (IsDoubleClick(scr, event)) {
704 iconDblClick(desc, event);
705 return;
708 if (event->xbutton.button == Button3) {
709 WObjDescriptor *desc;
710 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
712 if (!wapp)
713 return;
715 openApplicationMenu(wapp, event->xbutton.x_root,
716 event->xbutton.y_root);
718 /* allow drag select of menu */
719 desc = &scr->icon_menu->menu->descriptor;
720 event->xbutton.send_event = True;
721 (*desc->handle_mousedown)(desc, event);
722 return;
725 #ifdef DEBUG
726 puts("Moving icon");
727 #endif
728 if (event->xbutton.state & MOD_MASK)
729 wLowerFrame(icon->core);
730 else
731 wRaiseFrame(icon->core);
734 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
735 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
736 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
737 wwarning("pointer grab failed for appicon move");
740 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
741 dockable = 0;
742 else
743 dockable = canBeDocked(icon->owner);
746 while (!done) {
747 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
748 |ButtonMotionMask|ExposureMask, &ev);
749 switch (ev.type) {
750 case Expose:
751 WMHandleEvent(&ev);
752 break;
754 case MotionNotify:
755 if (!grabbed) {
756 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
757 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
758 XChangeActivePointerGrab(dpy, ButtonMotionMask
759 |ButtonReleaseMask|ButtonPressMask,
760 wCursor[WCUR_MOVE], CurrentTime);
761 grabbed=1;
762 } else {
763 break;
766 x = ev.xmotion.x_root - dx;
767 y = ev.xmotion.y_root - dy;
768 XMoveWindow(dpy, icon->core->window, x, y);
770 if (dockable) {
771 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
772 &ix, &iy, False)) {
773 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
774 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
776 if (scr->last_dock != scr->dock && collapsed) {
777 scr->last_dock->collapsed = 1;
778 wDockHideIcons(scr->last_dock);
779 collapsed = 0;
781 if (!collapsed && (collapsed = scr->dock->collapsed)) {
782 scr->dock->collapsed = 0;
783 wDockShowIcons(scr->dock);
786 if (scr->dock->auto_raise_lower)
787 wDockRaise(scr->dock);
789 scr->last_dock = scr->dock;
791 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
792 if (!docking) {
793 Window wins[2];
795 wins[0] = icon->core->window;
796 wins[1] = scr->dock_shadow;
797 XRestackWindows(dpy, wins, 2);
798 if (superfluous) {
799 if (icon->pixmap!=None)
800 ghost = MakeGhostIcon(scr, icon->pixmap);
801 else
802 ghost = MakeGhostIcon(scr, icon->core->window);
803 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
804 ghost);
805 XClearWindow(dpy, scr->dock_shadow);
807 XMapWindow(dpy, scr->dock_shadow);
809 docking = 1;
810 } else if (workspace->clip &&
811 wDockSnapIcon(workspace->clip, aicon, x, y,
812 &ix, &iy, False)) {
813 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
814 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
816 if (scr->last_dock != workspace->clip && collapsed) {
817 scr->last_dock->collapsed = 1;
818 wDockHideIcons(scr->last_dock);
819 collapsed = 0;
821 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
822 workspace->clip->collapsed = 0;
823 wDockShowIcons(workspace->clip);
826 if (workspace->clip->auto_raise_lower)
827 wDockRaise(workspace->clip);
829 scr->last_dock = workspace->clip;
831 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
832 if (!docking) {
833 Window wins[2];
835 wins[0] = icon->core->window;
836 wins[1] = scr->dock_shadow;
837 XRestackWindows(dpy, wins, 2);
838 if (superfluous) {
839 if (icon->pixmap!=None)
840 ghost = MakeGhostIcon(scr, icon->pixmap);
841 else
842 ghost = MakeGhostIcon(scr, icon->core->window);
843 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
844 ghost);
845 XClearWindow(dpy, scr->dock_shadow);
847 XMapWindow(dpy, scr->dock_shadow);
849 docking = 1;
850 } else if (docking) {
851 XUnmapWindow(dpy, scr->dock_shadow);
852 docking = 0;
856 break;
858 case ButtonPress:
859 break;
861 case ButtonRelease:
862 if (ev.xbutton.button != clickButton)
863 break;
864 XUngrabPointer(dpy, CurrentTime);
866 if (docking) {
867 Bool docked;
869 /* icon is trying to be docked */
870 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
871 XUnmapWindow(dpy, scr->dock_shadow);
872 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
873 if (scr->last_dock->auto_collapse) {
874 collapsed = 0;
876 if (workspace->clip &&
877 workspace->clip != scr->last_dock &&
878 workspace->clip->auto_raise_lower)
879 wDockLower(workspace->clip);
881 if (!docked) {
882 /* If icon could not be docked, slide it back to the old
883 * position */
884 SlideWindow(icon->core->window, x, y, aicon->x_pos,
885 aicon->y_pos);
887 } else {
888 XMoveWindow(dpy, icon->core->window, x, y);
889 aicon->x_pos = x;
890 aicon->y_pos = y;
891 if (workspace->clip && workspace->clip->auto_raise_lower)
892 wDockLower(workspace->clip);
894 if (collapsed) {
895 scr->last_dock->collapsed = 1;
896 wDockHideIcons(scr->last_dock);
897 collapsed = 0;
899 if (superfluous) {
900 if (ghost!=None)
901 XFreePixmap(dpy, ghost);
902 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
904 done = 1;
905 break;
908 #ifdef DEBUG
909 puts("End icon move");
910 #endif