- Finished moving to the new proplist handling code in WINGs.
[wmaker-crm.git] / src / appicon.c
bloba6bcb29e49f84e1730039d95250f02d88cbf9d8d
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 WApplication *app;
281 WAppIcon *tmp;
283 app = wApplicationOf(aicon->icon->owner->main_window);
285 if (!WFLAGP(app->main_window_desc, collapse_appicons)) {
286 XMoveWindow(dpy, aicon->icon->core->window, x, y);
287 aicon->x_pos = x;
288 aicon->y_pos = y;
289 } else {
290 tmp = aicon->icon->core->screen_ptr->app_icon_list;
292 /* move all icons of the same class/name to the same pos */
293 while (tmp) {
294 if (strcmp(tmp->wm_class, aicon->wm_class) == 0 &&
295 strcmp(tmp->wm_instance, aicon->wm_instance) == 0 &&
296 !tmp->docked) {
297 XMoveWindow(dpy, tmp->icon->core->window, x, y);
298 tmp->x_pos = x;
299 tmp->y_pos = y;
301 tmp = tmp->next;
307 #ifdef WS_INDICATOR
308 static void
309 updateDockNumbers(WScreen *scr)
311 int length;
312 char *ws_numbers;
313 GC numbers_gc;
314 XGCValues my_gc_values;
315 unsigned long my_v_mask = (GCForeground);
316 WAppIcon *dicon = scr->dock->icon_array[0];
318 my_gc_values.foreground = scr->white_pixel;
319 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
320 my_v_mask, &my_gc_values);
322 ws_numbers = wmalloc(20);
323 snprintf(ws_numbers, 20, "%i [ %i ]", scr->current_workspace+1,
324 ((scr->current_workspace/10)+1));
325 length = strlen(ws_numbers);
327 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
328 WMFontHeight(scr->icon_title_font)+1, False);
330 XSetForeground(dpy, numbers_gc, scr->black_pixel);
331 WMDrawString(scr->wmscreen, dicon->icon->core->window, numbers_gc,
332 scr->icon_title_font, 4, 3, ws_numbers, length);
334 XSetForeground(dpy, numbers_gc, scr->white_pixel);
335 WMDrawString(scr->wmscreen, dicon->icon->core->window, numbers_gc,
336 scr->icon_title_font, 3, 2, ws_numbers, length);
338 XFreeGC(dpy, numbers_gc);
339 wfree(ws_numbers);
341 #endif /* WS_INDICATOR */
345 WAppIcon*
346 wAppIconNextSibling(WAppIcon *icon)
348 WApplication *app;
349 WAppIcon *tmp;
351 app = wApplicationOf(icon->icon->owner->main_window);
353 if (!WFLAGP(app->main_window_desc, collapse_appicons)) {
354 return NULL;
357 tmp = icon->next;
358 while (tmp) {
359 if (strcmp(tmp->wm_class, icon->wm_class) == 0
360 && strcmp(tmp->wm_instance, icon->wm_instance) == 0
361 && !tmp->docked) {
362 return tmp;
364 tmp = tmp->next;
367 tmp = icon->icon->core->screen_ptr->app_icon_list;
368 while (tmp && tmp != icon) {
369 if (strcmp(tmp->wm_class, icon->wm_class) == 0
370 && strcmp(tmp->wm_instance, icon->wm_instance) == 0
371 && !tmp->docked) {
372 return tmp;
374 tmp = tmp->next;
377 return NULL;
381 Bool
382 wAppIconIsFirstInstance(WAppIcon *icon)
384 WAppIcon *list = icon->icon->core->screen_ptr->app_icon_list;
386 if (!WFLAGP(icon->icon->owner, collapse_appicons))
387 return True;
389 while (list) {
390 if (icon == list)
391 return True;
393 if (strcmp(icon->wm_instance,
394 list->wm_instance) == 0
396 strcmp(icon->wm_class,
397 list->wm_class) == 0
398 && !icon->docked)
399 return False;
401 list = list->next;
404 puts("OH SHIT!?!?!? HOW THE FUCK DID WE GET HERE!?!?!?!?!");
406 return 0;
411 void
412 wAppIconPaint(WAppIcon *aicon)
414 WApplication *wapp;
415 WScreen *scr = aicon->icon->core->screen_ptr;
416 int index;
418 if (aicon->icon->owner)
419 wapp = wApplicationOf(aicon->icon->owner->main_window);
420 else
421 wapp = NULL;
423 wIconPaint(aicon->icon);
426 # ifdef WS_INDICATOR
427 if (aicon->docked && scr->dock && scr->dock==aicon->dock &&
428 aicon->yindex==0)
429 updateDockNumbers(scr);
430 # endif
431 if (scr->dock_dots && aicon->docked && !aicon->running
432 && aicon->command!=NULL) {
433 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
434 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
435 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
436 scr->copy_gc, 0, 0, scr->dock_dots->width,
437 scr->dock_dots->height, 0, 0);
440 #ifdef HIDDENDOT
441 if (wapp && wapp->flags.hidden) {
442 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
443 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
444 XCopyArea(dpy, scr->dock_dots->image,
445 aicon->icon->core->window,
446 scr->copy_gc, 0, 0, 7,
447 scr->dock_dots->height, 0, 0);
449 #endif /* HIDDENDOT */
451 if (wapp)
452 index = wApplicationIndexOfGroup(wapp);
453 else
454 index = 0;
456 if (index > 0) {
457 char buf[16];
459 snprintf(buf, sizeof(buf), "%i", index);
461 WMDrawString(scr->wmscreen, aicon->icon->core->window,
462 scr->clip_title_gc, scr->title_font,
463 3, 3, buf, strlen(buf));
467 if (aicon->omnipresent)
468 drawCorner(aicon->icon);
470 XSetClipMask(dpy, scr->copy_gc, None);
471 if (aicon->launching) {
472 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
473 0, 0, wPreferences.icon_size, wPreferences.icon_size);
479 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
483 static void
484 hideCallback(WMenu *menu, WMenuEntry *entry)
486 WApplication *wapp = (WApplication*)entry->clientdata;
488 if (wapp->flags.hidden) {
489 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
490 wUnhideApplication(wapp, False, False);
491 } else {
492 wHideApplication(wapp);
497 static void
498 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
500 WApplication *wapp = (WApplication*)entry->clientdata;
502 wUnhideApplication(wapp, False, True);
506 static void
507 collapseCallback(WMenu *menu, WMenuEntry *entry)
509 WApplication *wapp = (WApplication*)entry->clientdata;
511 wApplicationSetCollapse(wapp,
512 !WFLAGP(wapp->main_window_desc, collapse_appicons));
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 wfree(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 wfree(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 = wstrconcat(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 wfree(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, _("Collapse"), collapseCallback, NULL);
598 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
599 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
601 return menu;
605 static void
606 openApplicationMenu(WApplication *wapp, int x, int y)
608 WMenu *menu;
609 WScreen *scr = wapp->main_window_desc->screen_ptr;
610 int i;
612 if (!scr->icon_menu) {
613 scr->icon_menu = createApplicationMenu(scr);
614 wfree(scr->icon_menu->entries[1]->text);
617 menu = scr->icon_menu;
619 if (wapp->flags.hidden) {
620 menu->entries[1]->text = _("Unhide");
621 } else {
622 menu->entries[1]->text = _("Hide");
625 if (WFLAGP(wapp->main_window_desc, collapse_appicons)) {
626 menu->entries[2]->text = _("Uncollapse");
627 } else {
628 menu->entries[2]->text = _("Collapse");
631 menu->flags.realized = 0;
632 wMenuRealize(menu);
634 x -= menu->frame->core->width/2;
635 if (x + menu->frame->core->width > scr->scr_width)
636 x = scr->scr_width - menu->frame->core->width;
637 if (x < 0)
638 x = 0;
640 /* set client data */
641 for (i = 0; i < menu->entry_no; i++) {
642 menu->entries[i]->clientdata = wapp;
644 wMenuMapAt(menu, x, y, False);
648 /******************************************************************/
650 static void
651 iconExpose(WObjDescriptor *desc, XEvent *event)
653 wAppIconPaint(desc->parent);
657 static void
658 iconDblClick(WObjDescriptor *desc, XEvent *event)
660 WAppIcon *aicon = desc->parent;
661 WApplication *wapp;
662 WScreen *scr = aicon->icon->core->screen_ptr;
663 int unhideHere;
665 assert(aicon->icon->owner!=NULL);
667 wapp = wApplicationOf(aicon->icon->owner->main_window);
668 #ifdef DEBUG0
669 if (!wapp) {
670 wwarning("could not find application descriptor for app icon!!");
671 return;
673 #endif
675 unhideHere = (event->xbutton.state & ShiftMask);
677 /* go to the last workspace that the user worked on the app */
678 if (!unhideHere && wapp->last_workspace != scr->current_workspace)
679 wWorkspaceChange(scr, wapp->last_workspace);
681 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
683 if (event->xbutton.state & MOD_MASK) {
684 wHideOtherApplications(aicon->icon->owner);
690 void
691 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
693 WAppIcon *aicon = desc->parent;
694 WIcon *icon = aicon->icon;
695 XEvent ev;
696 int x=aicon->x_pos, y=aicon->y_pos;
697 int dx=event->xbutton.x, dy=event->xbutton.y;
698 int grabbed=0;
699 int done=0;
700 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
701 WScreen *scr = icon->core->screen_ptr;
702 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
703 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
704 int ix, iy;
705 int clickButton = event->xbutton.button;
706 Pixmap ghost = None;
707 Window wins[2];
708 Bool movingSingle = False;
709 int oldX = x;
710 int oldY = y;
712 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
713 return;
715 if (event->xbutton.button == Button1 && IsDoubleClick(scr, event)) {
716 iconDblClick(desc, event);
717 return;
720 if (event->xbutton.button == Button3) {
721 WObjDescriptor *desc;
722 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
724 if (!wapp)
725 return;
727 if (event->xbutton.send_event &&
728 XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
729 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
730 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
731 wwarning("pointer grab failed for appicon menu");
732 return;
735 openApplicationMenu(wapp, event->xbutton.x_root,
736 event->xbutton.y_root);
738 /* allow drag select of menu */
739 desc = &scr->icon_menu->menu->descriptor;
740 event->xbutton.send_event = True;
741 (*desc->handle_mousedown)(desc, event);
742 return;
745 #ifdef DEBUG
746 puts("Moving icon");
747 #endif
748 if (event->xbutton.state & MOD_MASK)
749 wLowerFrame(icon->core);
750 else
751 wRaiseFrame(icon->core);
754 if (clickButton == Button2) {
755 WAppIcon *next = wAppIconNextSibling(aicon);
757 if (next) {
758 wRaiseFrame(next->icon->core);
760 return;
763 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
764 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
765 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
766 wwarning("pointer grab failed for appicon move");
769 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
770 dockable = 0;
771 else
772 dockable = canBeDocked(icon->owner);
774 wins[0] = icon->core->window;
775 wins[1] = scr->dock_shadow;
776 XRestackWindows(dpy, wins, 2);
777 if (superfluous) {
778 if (icon->pixmap!=None)
779 ghost = MakeGhostIcon(scr, icon->pixmap);
780 else
781 ghost = MakeGhostIcon(scr, icon->core->window);
782 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
783 ghost);
784 XClearWindow(dpy, scr->dock_shadow);
787 while (!done) {
788 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
789 |ButtonMotionMask|ExposureMask, &ev);
790 switch (ev.type) {
791 case Expose:
792 WMHandleEvent(&ev);
793 break;
795 case MotionNotify:
796 if (!grabbed) {
797 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
798 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
799 XChangeActivePointerGrab(dpy, ButtonMotionMask
800 |ButtonReleaseMask|ButtonPressMask,
801 wCursor[WCUR_MOVE], CurrentTime);
802 grabbed=1;
803 } else {
804 break;
807 x = ev.xmotion.x_root - dx;
808 y = ev.xmotion.y_root - dy;
810 if (movingSingle) {
811 XMoveWindow(dpy, icon->core->window, x, y);
812 } else {
813 wAppIconMove(aicon, x, y);
816 if (dockable) {
817 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
818 &ix, &iy, False)) {
819 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
820 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
822 if (scr->last_dock != scr->dock && collapsed) {
823 scr->last_dock->collapsed = 1;
824 wDockHideIcons(scr->last_dock);
825 collapsed = 0;
827 if (!collapsed && (collapsed = scr->dock->collapsed)) {
828 scr->dock->collapsed = 0;
829 wDockShowIcons(scr->dock);
832 if (scr->dock->auto_raise_lower)
833 wDockRaise(scr->dock);
835 scr->last_dock = scr->dock;
837 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
838 if (!docking) {
839 XMapWindow(dpy, scr->dock_shadow);
841 docking = 1;
842 } else if (workspace->clip &&
843 wDockSnapIcon(workspace->clip, aicon, x, y,
844 &ix, &iy, False)) {
845 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
846 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
848 if (scr->last_dock != workspace->clip && collapsed) {
849 scr->last_dock->collapsed = 1;
850 wDockHideIcons(scr->last_dock);
851 collapsed = 0;
853 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
854 workspace->clip->collapsed = 0;
855 wDockShowIcons(workspace->clip);
858 if (workspace->clip->auto_raise_lower)
859 wDockRaise(workspace->clip);
861 scr->last_dock = workspace->clip;
863 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
864 if (!docking) {
865 XMapWindow(dpy, scr->dock_shadow);
867 docking = 1;
868 } else if (docking) {
869 XUnmapWindow(dpy, scr->dock_shadow);
870 docking = 0;
874 break;
876 case ButtonPress:
877 break;
879 case ButtonRelease:
880 if (ev.xbutton.button != clickButton)
881 break;
882 XUngrabPointer(dpy, CurrentTime);
884 if (docking) {
885 Bool docked;
887 /* icon is trying to be docked */
888 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
889 XUnmapWindow(dpy, scr->dock_shadow);
890 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
891 if (scr->last_dock->auto_collapse) {
892 collapsed = 0;
894 if (workspace->clip &&
895 workspace->clip != scr->last_dock &&
896 workspace->clip->auto_raise_lower)
897 wDockLower(workspace->clip);
899 if (!docked) {
900 /* If icon could not be docked, slide it back to the old
901 * position */
902 SlideWindow(icon->core->window, x, y, oldX, oldY);
903 } else {
904 WAppIcon *nextIcon = wAppIconNextSibling(aicon);
906 if (nextIcon) {
907 /* move the next instance back to the old position */
908 SlideWindow(nextIcon->icon->core->window, x, y,
909 oldX, oldY);
910 wAppIconMove(nextIcon, oldX, oldY);
914 wSoundPlay(WSOUND_DOCK);
915 } else {
916 if (movingSingle) {
917 /* move back to its place */
918 SlideWindow(icon->core->window, x, y, oldX, oldY);
919 wAppIconMove(aicon, oldX, oldY);
920 } else {
921 XMoveWindow(dpy, icon->core->window, x, y);
922 aicon->x_pos = x;
923 aicon->y_pos = y;
925 if (workspace->clip && workspace->clip->auto_raise_lower)
926 wDockLower(workspace->clip);
928 if (collapsed) {
929 scr->last_dock->collapsed = 1;
930 wDockHideIcons(scr->last_dock);
931 collapsed = 0;
933 if (superfluous) {
934 if (ghost!=None)
935 XFreePixmap(dpy, ghost);
936 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
939 if (wPreferences.auto_arrange_icons)
940 wArrangeIcons(scr, True);
942 done = 1;
943 break;
946 #ifdef DEBUG
947 puts("End icon move");
948 #endif