added stack cycling
[wmaker-crm.git] / src / appicon.c
blob4cfcb834edba61ed4c026b2fd2abb665fa1d9c17
1 /* appicon.c- icon for applications (not mini-window)
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
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"
47 #ifdef XDND
48 #include "xdnd.h"
49 #endif
50 #include "wsound.h"
51 #include <WINGs/WINGsP.h>
55 * icon_file for the dock is got from the preferences file by
56 * using the classname/instancename
59 /**** Global variables ****/
60 extern Cursor wCursor[WCUR_LAST];
61 extern WPreferences wPreferences;
63 #define MOD_MASK wPreferences.modifier_mask
65 void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
66 static void iconDblClick(WObjDescriptor *desc, XEvent *event);
67 static void iconExpose(WObjDescriptor *desc, XEvent *event);
71 WAppIcon*
72 wAppIconCreateForDock(WScreen *scr, char *command, char *wm_instance,
73 char *wm_class, int tile)
75 WAppIcon *dicon;
76 char *path;
78 dicon = wmalloc(sizeof(WAppIcon));
79 wretain(dicon);
80 memset(dicon, 0, sizeof(WAppIcon));
81 dicon->yindex = -1;
82 dicon->xindex = -1;
84 dicon->prev = NULL;
85 dicon->next = scr->app_icon_list;
86 if (scr->app_icon_list) {
87 scr->app_icon_list->prev = dicon;
89 scr->app_icon_list = dicon;
91 if (command) {
92 dicon->command = wstrdup(command);
94 if (wm_class)
95 dicon->wm_class = wstrdup(wm_class);
96 if (wm_instance)
97 dicon->wm_instance = wstrdup(wm_instance);
99 path = wDefaultGetIconFile(scr, wm_instance, wm_class, True);
100 if (!path && command) {
101 wApplicationExtractDirPackIcon(scr, command, wm_instance, wm_class);
103 path = wDefaultGetIconFile(scr, wm_instance, wm_class, False);
106 if (path)
107 path = FindImage(wPreferences.icon_path, path);
109 dicon->icon = wIconCreateWithIconFile(scr, path, tile);
110 if (path)
111 wfree(path);
112 #ifdef XDND
113 wXDNDMakeAwareness(dicon->icon->core->window);
114 #endif
116 #ifdef DEMATERIALIZE_ICON
118 XSetWindowAttributes attribs;
119 attribs.save_under = True;
120 XChangeWindowAttributes(dpy, dicon->icon->core->window,
121 CWSaveUnder, &attribs);
123 #endif
125 /* will be overriden by dock */
126 dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
127 dicon->icon->core->descriptor.handle_expose = iconExpose;
128 dicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
129 dicon->icon->core->descriptor.parent = dicon;
130 AddToStackList(dicon->icon->core);
132 return dicon;
137 WAppIcon*
138 wAppIconCreate(WWindow *leader_win)
140 WAppIcon *aicon;
141 WScreen *scr = leader_win->screen_ptr;
143 aicon = wmalloc(sizeof(WAppIcon));
144 wretain(aicon);
145 memset(aicon, 0, sizeof(WAppIcon));
147 aicon->yindex = -1;
148 aicon->xindex = -1;
150 aicon->prev = NULL;
151 aicon->next = scr->app_icon_list;
152 if (scr->app_icon_list) {
153 scr->app_icon_list->prev = aicon;
155 scr->app_icon_list = aicon;
157 if (leader_win->wm_class)
158 aicon->wm_class = wstrdup(leader_win->wm_class);
159 if (leader_win->wm_instance)
160 aicon->wm_instance = wstrdup(leader_win->wm_instance);
162 aicon->icon = wIconCreate(leader_win);
163 #ifdef DEMATERIALIZE_ICON
165 XSetWindowAttributes attribs;
166 attribs.save_under = True;
167 XChangeWindowAttributes(dpy, aicon->icon->core->window,
168 CWSaveUnder, &attribs);
170 #endif
171 #ifdef XDND
172 wXDNDMakeAwareness(aicon->icon->core->window);
173 #endif
175 /* will be overriden if docked */
176 aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
177 aicon->icon->core->descriptor.handle_expose = iconExpose;
178 aicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
179 aicon->icon->core->descriptor.parent = aicon;
180 AddToStackList(aicon->icon->core);
181 aicon->icon->show_title = 0;
182 wIconUpdate(aicon->icon);
184 return aicon;
188 void
189 wAppIconDestroy(WAppIcon *aicon)
191 WScreen *scr = aicon->icon->core->screen_ptr;
193 RemoveFromStackList(aicon->icon->core);
194 wIconDestroy(aicon->icon);
195 if (aicon->command)
196 wfree(aicon->command);
197 #ifdef OFFIX_DND
198 if (aicon->dnd_command)
199 wfree(aicon->dnd_command);
200 #endif
201 if (aicon->wm_instance)
202 wfree(aicon->wm_instance);
203 if (aicon->wm_class)
204 wfree(aicon->wm_class);
206 if (aicon == scr->app_icon_list) {
207 if (aicon->next)
208 aicon->next->prev = NULL;
209 scr->app_icon_list = aicon->next;
211 else {
212 if (aicon->next)
213 aicon->next->prev = aicon->prev;
214 if (aicon->prev)
215 aicon->prev->next = aicon->next;
218 aicon->destroyed = 1;
219 wrelease(aicon);
224 #ifdef NEWAPPICON
225 static void
226 drawCorner(WIcon *icon, WWindow *wwin, int active)
228 WScreen *scr = wwin->screen_ptr;
229 XPoint points[3];
230 GC gc;
232 points[0].x = 2;
233 points[0].y = 2;
234 points[1].x = 12;
235 points[1].y = 2;
236 points[2].x = 2;
237 points[2].y = 12;
238 if (active) {
239 gc=scr->focused_texture->any.gc;
240 } else {
241 gc=scr->unfocused_texture->any.gc;
243 XFillPolygon(dpy, icon->core->window, gc, points, 3,
244 Convex, CoordModeOrigin);
246 #endif /* NEWAPPICON */
249 static void
250 drawCorner(WIcon *icon)
252 WScreen *scr = icon->core->screen_ptr;
253 XPoint points[3];
255 points[0].x = 1;
256 points[0].y = 1;
257 points[1].x = 12;
258 points[1].y = 1;
259 points[2].x = 1;
260 points[2].y = 12;
261 XFillPolygon(dpy, icon->core->window, scr->icon_title_texture->normal_gc,
262 points, 3, Convex, CoordModeOrigin);
263 XDrawLine(dpy, icon->core->window, scr->icon_title_texture->light_gc,
264 0, 0, 0, 12);
265 XDrawLine(dpy, icon->core->window, scr->icon_title_texture->light_gc,
266 0, 0, 12, 0);
267 /* drawing the second line gives a weird concave look. -Dan */
268 #if 0
269 XDrawLine(dpy, icon->core->window, scr->icon_title_texture->light_gc,
270 1, 1, 1, 11);
271 XDrawLine(dpy, icon->core->window, scr->icon_title_texture->light_gc,
272 1, 1, 11, 1);
273 #endif
277 void
278 wAppIconMove(WAppIcon *aicon, int x, int y)
280 WAppIcon *tmp;
282 tmp = aicon->icon->core->screen_ptr->app_icon_list;
284 /* move all icons of the same class/name to the same pos */
285 while (tmp) {
286 if (strcmp(tmp->wm_class, aicon->wm_class) == 0 &&
287 strcmp(tmp->wm_instance, aicon->wm_instance) == 0 &&
288 !tmp->docked) {
289 XMoveWindow(dpy, tmp->icon->core->window, x, y);
290 tmp->x_pos = x;
291 tmp->y_pos = y;
293 tmp = tmp->next;
298 #ifdef WS_INDICATOR
299 static void
300 updateDockNumbers(WScreen *scr)
302 int length;
303 char *ws_numbers;
304 GC numbers_gc;
305 XGCValues my_gc_values;
306 unsigned long my_v_mask = (GCForeground);
307 WAppIcon *dicon = scr->dock->icon_array[0];
309 my_gc_values.foreground = scr->white_pixel;
310 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
311 my_v_mask, &my_gc_values);
313 ws_numbers = malloc(20);
314 sprintf(ws_numbers, "%i [ %i ]", scr->current_workspace+1,
315 ((scr->current_workspace/10)+1));
316 length = strlen(ws_numbers);
318 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
319 WMFontHeight(scr->icon_title_font)+1, False);
321 XSetForeground(dpy, numbers_gc, scr->black_pixel);
322 WMDrawString(scr->wmscreen, dicon->icon->core->window, numbers_gc,
323 scr->icon_title_font, 4, 3, ws_numbers, length);
325 XSetForeground(dpy, numbers_gc, scr->white_pixel);
326 WMDrawString(scr->wmscreen, dicon->icon->core->window, numbers_gc,
327 scr->icon_title_font, 3, 2, ws_numbers, length);
329 XFreeGC(dpy, numbers_gc);
330 wfree(ws_numbers);
332 #endif /* WS_INDICATOR */
336 WAppIcon*
337 wAppIconNextSibling(WAppIcon *icon)
339 WAppIcon *tmp;
341 tmp = icon->next;
342 while (tmp) {
343 if (strcmp(tmp->wm_class, icon->wm_class) == 0
344 && strcmp(tmp->wm_instance, icon->wm_instance) == 0
345 && !tmp->docked) {
346 return tmp;
348 tmp = tmp->next;
351 tmp = icon->icon->core->screen_ptr->app_icon_list;
352 while (tmp && tmp != icon) {
353 if (strcmp(tmp->wm_class, icon->wm_class) == 0
354 && strcmp(tmp->wm_instance, icon->wm_instance) == 0
355 && !tmp->docked) {
356 return tmp;
358 tmp = tmp->next;
361 return NULL;
366 wAppIconIndexOfInstance(WAppIcon *icon)
368 WAppIcon *list = icon->icon->core->screen_ptr->app_icon_list;
369 int index = 0;
371 while (list) {
372 if (icon == list)
373 return index;
375 if (strcmp(icon->wm_instance,
376 list->wm_instance) == 0
378 strcmp(icon->wm_class,
379 list->wm_class) == 0
380 && !icon->docked)
381 index++;
383 list = list->next;
386 puts("OH SHIT!?!?!? HOW THE FUCK DID WE GET HERE!?!?!?!?!");
388 return 0;
393 void
394 wAppIconPaint(WAppIcon *aicon)
396 WApplication *wapp;
397 WScreen *scr = aicon->icon->core->screen_ptr;
398 int index;
400 if (aicon->icon->owner)
401 wapp = wApplicationOf(aicon->icon->owner->main_window);
402 else
403 wapp = NULL;
405 wIconPaint(aicon->icon);
408 # ifdef WS_INDICATOR
409 if (aicon->docked && scr->dock && scr->dock==aicon->dock &&
410 aicon->yindex==0)
411 updateDockNumbers(scr);
412 # endif
413 if (scr->dock_dots && aicon->docked && !aicon->running
414 && aicon->command!=NULL) {
415 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
416 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
417 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
418 scr->copy_gc, 0, 0, scr->dock_dots->width,
419 scr->dock_dots->height, 0, 0);
422 #ifdef HIDDENDOT
423 if (wapp && wapp->flags.hidden) {
424 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
425 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
426 XCopyArea(dpy, scr->dock_dots->image,
427 aicon->icon->core->window,
428 scr->copy_gc, 0, 0, 7,
429 scr->dock_dots->height, 0, 0);
431 #endif /* HIDDENDOT */
433 if (wapp)
434 index = wApplicationIndexOfInstance(wapp);
435 else
436 index = 0;
438 if (index > 0) {
439 char buf[16];
441 sprintf(buf, "%i", index);
443 WMDrawString(scr->wmscreen, aicon->icon->core->window,
444 scr->clip_title_gc, scr->title_font,
445 1, 1, buf, strlen(buf));
449 if (aicon->omnipresent)
450 drawCorner(aicon->icon);
452 XSetClipMask(dpy, scr->copy_gc, None);
453 if (aicon->launching) {
454 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
455 0, 0, wPreferences.icon_size, wPreferences.icon_size);
461 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
465 static void
466 hideCallback(WMenu *menu, WMenuEntry *entry)
468 WApplication *wapp = (WApplication*)entry->clientdata;
470 if (wapp->flags.hidden) {
471 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
472 wUnhideApplication(wapp, False, False);
473 } else {
474 wHideApplication(wapp);
479 static void
480 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
482 WApplication *wapp = (WApplication*)entry->clientdata;
484 wUnhideApplication(wapp, False, True);
488 static void
489 setIconCallback(WMenu *menu, WMenuEntry *entry)
491 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
492 char *file=NULL;
493 WScreen *scr;
494 int result;
496 assert(icon!=NULL);
498 if (icon->editing)
499 return;
500 icon->editing = 1;
501 scr = icon->icon->core->screen_ptr;
503 wretain(icon);
505 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
507 if (result && !icon->destroyed) {
508 if (file[0]==0) {
509 wfree(file);
510 file = NULL;
512 if (!wIconChangeImageFile(icon->icon, file)) {
513 wMessageDialog(scr, _("Error"),
514 _("Could not open specified icon file"),
515 _("OK"), NULL, NULL);
516 } else {
517 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
518 wAppIconPaint(icon);
520 if (file)
521 wfree(file);
523 icon->editing = 0;
524 wrelease(icon);
528 static void
529 killCallback(WMenu *menu, WMenuEntry *entry)
531 WApplication *wapp = (WApplication*)entry->clientdata;
532 char *buffer;
534 if (!WCHECK_STATE(WSTATE_NORMAL))
535 return;
537 WCHANGE_STATE(WSTATE_MODAL);
539 assert(entry->clientdata!=NULL);
541 buffer = wstrconcat(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
542 _(" will be forcibly closed.\n"
543 "Any unsaved changes will be lost.\n"
544 "Please confirm."));
546 wretain(wapp->main_window_desc);
547 if (wPreferences.dont_confirm_kill
548 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
549 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
550 if (!wapp->main_window_desc->flags.destroyed)
551 wClientKill(wapp->main_window_desc);
553 wrelease(wapp->main_window_desc);
555 wfree(buffer);
557 WCHANGE_STATE(WSTATE_NORMAL);
561 static WMenu*
562 createApplicationMenu(WScreen *scr)
564 WMenu *menu;
566 menu = wMenuCreate(scr, NULL, False);
567 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
568 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
569 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
570 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
572 return menu;
576 static void
577 openApplicationMenu(WApplication *wapp, int x, int y)
579 WMenu *menu;
580 WScreen *scr = wapp->main_window_desc->screen_ptr;
581 int i;
583 if (!scr->icon_menu) {
584 scr->icon_menu = createApplicationMenu(scr);
585 wfree(scr->icon_menu->entries[1]->text);
588 menu = scr->icon_menu;
590 if (wapp->flags.hidden) {
591 menu->entries[1]->text = _("Unhide");
592 } else {
593 menu->entries[1]->text = _("Hide");
596 menu->flags.realized = 0;
597 wMenuRealize(menu);
599 x -= menu->frame->core->width/2;
600 if (x + menu->frame->core->width > scr->scr_width)
601 x = scr->scr_width - menu->frame->core->width;
602 if (x < 0)
603 x = 0;
605 /* set client data */
606 for (i = 0; i < menu->entry_no; i++) {
607 menu->entries[i]->clientdata = wapp;
609 wMenuMapAt(menu, x, y, False);
613 /******************************************************************/
615 static void
616 iconExpose(WObjDescriptor *desc, XEvent *event)
618 wAppIconPaint(desc->parent);
622 static void
623 iconDblClick(WObjDescriptor *desc, XEvent *event)
625 WAppIcon *aicon = desc->parent;
626 WApplication *wapp;
627 WScreen *scr = aicon->icon->core->screen_ptr;
628 int unhideHere;
630 assert(aicon->icon->owner!=NULL);
632 wapp = wApplicationOf(aicon->icon->owner->main_window);
633 #ifdef DEBUG0
634 if (!wapp) {
635 wwarning("could not find application descriptor for app icon!!");
636 return;
638 #endif
640 unhideHere = (event->xbutton.state & ShiftMask);
642 /* go to the last workspace that the user worked on the app */
643 if (!unhideHere && wapp->last_workspace != scr->current_workspace)
644 wWorkspaceChange(scr, wapp->last_workspace);
646 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
648 if (event->xbutton.state & MOD_MASK) {
649 wHideOtherApplications(aicon->icon->owner);
655 void
656 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
658 WAppIcon *aicon = desc->parent;
659 WIcon *icon = aicon->icon;
660 XEvent ev;
661 int x=aicon->x_pos, y=aicon->y_pos;
662 int dx=event->xbutton.x, dy=event->xbutton.y;
663 int grabbed=0;
664 int done=0;
665 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
666 WScreen *scr = icon->core->screen_ptr;
667 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
668 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
669 int ix, iy;
670 int clickButton = event->xbutton.button;
671 Pixmap ghost = None;
672 Window wins[2];
673 Bool movingSingle = False;
674 int oldX = x;
675 int oldY = y;
677 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
678 return;
680 if (event->xbutton.button == Button1 && IsDoubleClick(scr, event)) {
681 iconDblClick(desc, event);
682 return;
685 if (event->xbutton.button == Button3) {
686 WObjDescriptor *desc;
687 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
689 if (!wapp)
690 return;
692 if (event->xbutton.send_event &&
693 XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
694 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
695 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
696 wwarning("pointer grab failed for appicon menu");
697 return;
700 openApplicationMenu(wapp, event->xbutton.x_root,
701 event->xbutton.y_root);
703 /* allow drag select of menu */
704 desc = &scr->icon_menu->menu->descriptor;
705 event->xbutton.send_event = True;
706 (*desc->handle_mousedown)(desc, event);
707 return;
710 #ifdef DEBUG
711 puts("Moving icon");
712 #endif
713 if (event->xbutton.state & MOD_MASK)
714 wLowerFrame(icon->core);
715 else
716 wRaiseFrame(icon->core);
719 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
720 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
721 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
722 wwarning("pointer grab failed for appicon move");
725 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
726 dockable = 0;
727 else
728 dockable = canBeDocked(icon->owner);
730 wins[0] = icon->core->window;
731 wins[1] = scr->dock_shadow;
732 XRestackWindows(dpy, wins, 2);
733 if (superfluous) {
734 if (icon->pixmap!=None)
735 ghost = MakeGhostIcon(scr, icon->pixmap);
736 else
737 ghost = MakeGhostIcon(scr, icon->core->window);
738 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
739 ghost);
740 XClearWindow(dpy, scr->dock_shadow);
743 if (clickButton != Button1) {
744 done = True;
746 if (clickButton == Button2) {
747 WAppIcon *next = wAppIconNextSibling(aicon);
749 if (next) {
750 XRaiseWindow(dpy, next->icon->core->window);
751 XFlush(dpy);
756 while (!done) {
757 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
758 |ButtonMotionMask|ExposureMask, &ev);
759 switch (ev.type) {
760 case Expose:
761 WMHandleEvent(&ev);
762 break;
764 case MotionNotify:
765 if (!grabbed) {
766 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
767 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
768 XChangeActivePointerGrab(dpy, ButtonMotionMask
769 |ButtonReleaseMask|ButtonPressMask,
770 wCursor[WCUR_MOVE], CurrentTime);
771 grabbed=1;
772 } else {
773 break;
776 x = ev.xmotion.x_root - dx;
777 y = ev.xmotion.y_root - dy;
779 if (movingSingle) {
780 XMoveWindow(dpy, icon->core->window, x, y);
781 } else {
782 wAppIconMove(aicon, x, y);
785 if (dockable) {
786 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
787 &ix, &iy, False)) {
788 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
789 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
791 if (scr->last_dock != scr->dock && collapsed) {
792 scr->last_dock->collapsed = 1;
793 wDockHideIcons(scr->last_dock);
794 collapsed = 0;
796 if (!collapsed && (collapsed = scr->dock->collapsed)) {
797 scr->dock->collapsed = 0;
798 wDockShowIcons(scr->dock);
801 if (scr->dock->auto_raise_lower)
802 wDockRaise(scr->dock);
804 scr->last_dock = scr->dock;
806 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
807 if (!docking) {
808 XMapWindow(dpy, scr->dock_shadow);
810 docking = 1;
811 } else if (workspace->clip &&
812 wDockSnapIcon(workspace->clip, aicon, x, y,
813 &ix, &iy, False)) {
814 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
815 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
817 if (scr->last_dock != workspace->clip && collapsed) {
818 scr->last_dock->collapsed = 1;
819 wDockHideIcons(scr->last_dock);
820 collapsed = 0;
822 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
823 workspace->clip->collapsed = 0;
824 wDockShowIcons(workspace->clip);
827 if (workspace->clip->auto_raise_lower)
828 wDockRaise(workspace->clip);
830 scr->last_dock = workspace->clip;
832 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
833 if (!docking) {
834 XMapWindow(dpy, scr->dock_shadow);
836 docking = 1;
837 } else if (docking) {
838 XUnmapWindow(dpy, scr->dock_shadow);
839 docking = 0;
843 break;
845 case ButtonPress:
846 break;
848 case ButtonRelease:
849 if (ev.xbutton.button != clickButton)
850 break;
851 XUngrabPointer(dpy, CurrentTime);
853 if (docking) {
854 Bool docked;
856 /* icon is trying to be docked */
857 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
858 XUnmapWindow(dpy, scr->dock_shadow);
859 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
860 if (scr->last_dock->auto_collapse) {
861 collapsed = 0;
863 if (workspace->clip &&
864 workspace->clip != scr->last_dock &&
865 workspace->clip->auto_raise_lower)
866 wDockLower(workspace->clip);
868 if (!docked) {
869 /* If icon could not be docked, slide it back to the old
870 * position */
871 SlideWindow(icon->core->window, x, y, oldX, oldY);
872 } else {
873 WAppIcon *nextIcon = wAppIconNextSibling(aicon);
875 if (nextIcon) {
876 /* move the next instance back to the old position */
877 SlideWindow(nextIcon->icon->core->window, x, y,
878 oldX, oldY);
879 wAppIconMove(nextIcon, oldX, oldY);
883 #ifdef WSOUND
884 wSoundPlay(WSOUND_DOCK);
885 #endif
886 } else {
887 if (movingSingle) {
888 /* move back to its place */
889 SlideWindow(icon->core->window, x, y, oldX, oldY);
890 wAppIconMove(aicon, oldX, oldY);
891 } else {
892 XMoveWindow(dpy, icon->core->window, x, y);
893 aicon->x_pos = x;
894 aicon->y_pos = y;
896 if (workspace->clip && workspace->clip->auto_raise_lower)
897 wDockLower(workspace->clip);
899 if (collapsed) {
900 scr->last_dock->collapsed = 1;
901 wDockHideIcons(scr->last_dock);
902 collapsed = 0;
904 if (superfluous) {
905 if (ghost!=None)
906 XFreePixmap(dpy, ghost);
907 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
910 if (wPreferences.auto_arrange_icons)
911 wArrangeIcons(scr, True);
913 done = 1;
914 break;
917 #ifdef DEBUG
918 puts("End icon move");
919 #endif