Added ability to set omnipresent icons in Clip.
[wmaker-crm.git] / src / appicon.c
blob1fc2e8b826072a4af321ba8233099cdb8f5f2ea1
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"
49 * icon_file for the dock is got from the preferences file by
50 * using the classname/instancename
53 /**** Global variables ****/
54 extern Cursor wCursor[WCUR_LAST];
55 extern WPreferences wPreferences;
57 #define MOD_MASK wPreferences.modifier_mask
59 void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
60 static void iconDblClick(WObjDescriptor *desc, XEvent *event);
61 static void iconExpose(WObjDescriptor *desc, XEvent *event);
65 WAppIcon*
66 wAppIconCreateForDock(WScreen *scr, char *command, char *wm_instance,
67 char *wm_class, int tile)
69 WAppIcon *dicon;
70 char *path;
72 dicon = wmalloc(sizeof(WAppIcon));
73 wretain(dicon);
74 memset(dicon, 0, sizeof(WAppIcon));
75 dicon->yindex = -1;
76 dicon->xindex = -1;
78 dicon->prev = NULL;
79 dicon->next = scr->app_icon_list;
80 if (scr->app_icon_list) {
81 scr->app_icon_list->prev = dicon;
83 scr->app_icon_list = dicon;
85 if (command) {
86 dicon->command = wstrdup(command);
88 if (wm_class)
89 dicon->wm_class = wstrdup(wm_class);
90 if (wm_instance)
91 dicon->wm_instance = wstrdup(wm_instance);
93 path = wDefaultGetIconFile(scr, wm_instance, wm_class, True);
94 if (!path && command) {
95 wApplicationExtractDirPackIcon(scr, command, wm_instance, wm_class);
97 path = wDefaultGetIconFile(scr, wm_instance, wm_class, False);
100 if (path)
101 path = FindImage(wPreferences.icon_path, path);
103 dicon->icon = wIconCreateWithIconFile(scr, path, tile);
104 if (path)
105 free(path);
106 #ifdef REDUCE_APPICONS
107 dicon->num_apps = 0;
108 #endif
109 #ifdef DEMATERIALIZE_ICON
111 XSetWindowAttributes attribs;
112 attribs.save_under = True;
113 XChangeWindowAttributes(dpy, dicon->icon->core->window,
114 CWSaveUnder, &attribs);
116 #endif
118 /* will be overriden by dock */
119 dicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
120 dicon->icon->core->descriptor.handle_expose = iconExpose;
121 dicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
122 dicon->icon->core->descriptor.parent = dicon;
123 AddToStackList(dicon->icon->core);
125 return dicon;
130 WAppIcon*
131 wAppIconCreate(WWindow *leader_win)
133 WAppIcon *aicon;
134 #ifdef REDUCE_APPICONS
135 WAppIcon *atmp;
136 WAppIconAppList *applist;
137 char *tinstance, *tclass;
138 #endif
139 WScreen *scr = leader_win->screen_ptr;
141 aicon = wmalloc(sizeof(WAppIcon));
142 wretain(aicon);
143 memset(aicon, 0, sizeof(WAppIcon));
144 #ifdef REDUCE_APPICONS
145 applist = wmalloc(sizeof(WAppIconAppList));
146 memset(applist, 0, sizeof(WAppIconAppList));
147 applist->wapp = wApplicationOf(leader_win->main_window);
148 aicon->applist = applist;
149 if (applist->wapp == NULL) {
150 /* Something's wrong. wApplicationOf() should always return a
151 * valid structure. Rather than violate assumptions, bail. -cls
153 free(applist);
154 wrelease(aicon);
155 return NULL;
157 #endif
159 aicon->yindex = -1;
160 aicon->xindex = -1;
162 aicon->prev = NULL;
163 aicon->next = scr->app_icon_list;
164 if (scr->app_icon_list) {
165 #ifndef REDUCE_APPICONS
166 scr->app_icon_list->prev = aicon;
167 #else
168 /* If we aren't going to have a match, jump straight to new appicon */
169 if (leader_win->wm_class == NULL || leader_win->wm_class == NULL)
170 atmp = NULL;
171 else
172 atmp = scr->app_icon_list;
174 while (atmp != NULL) {
175 if ((tinstance = atmp->wm_instance) == NULL)
176 tinstance = "";
177 if ((tclass = atmp->wm_class) == NULL)
178 tclass = "";
179 if ((strcmp(leader_win->wm_class, tclass) == 0) &&
180 (strcmp(leader_win->wm_instance, tinstance) == 0))
182 /* We have a winner */
183 wrelease(aicon);
184 atmp->num_apps++;
185 applist->next = atmp->applist;
186 if (atmp->applist)
187 atmp->applist->prev = applist;
188 atmp->applist = applist;
190 if (atmp->docked) {
191 wDockSimulateLaunch(atmp->dock, atmp);
194 return atmp;
196 atmp = atmp->next;
198 if (atmp == NULL) {
199 scr->app_icon_list->prev = aicon;
201 #endif /* REDUCE_APPICONS */
203 scr->app_icon_list = aicon;
205 if (leader_win->wm_class)
206 aicon->wm_class = wstrdup(leader_win->wm_class);
207 if (leader_win->wm_instance)
208 aicon->wm_instance = wstrdup(leader_win->wm_instance);
209 #ifdef REDUCE_APPICONS
210 aicon->num_apps = 1;
211 #endif
213 aicon->icon = wIconCreate(leader_win);
214 #ifdef DEMATERIALIZE_ICON
216 XSetWindowAttributes attribs;
217 attribs.save_under = True;
218 XChangeWindowAttributes(dpy, aicon->icon->core->window,
219 CWSaveUnder, &attribs);
221 #endif
223 /* will be overriden if docked */
224 aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
225 aicon->icon->core->descriptor.handle_expose = iconExpose;
226 aicon->icon->core->descriptor.parent_type = WCLASS_APPICON;
227 aicon->icon->core->descriptor.parent = aicon;
228 AddToStackList(aicon->icon->core);
229 aicon->icon->show_title = 0;
230 wIconUpdate(aicon->icon);
232 return aicon;
236 void
237 wAppIconDestroy(WAppIcon *aicon)
239 WScreen *scr = aicon->icon->core->screen_ptr;
240 #ifdef REDUCE_APPICONS
241 WAppIconAppList *aptmp;
242 #endif
244 RemoveFromStackList(aicon->icon->core);
245 wIconDestroy(aicon->icon);
246 if (aicon->command)
247 free(aicon->command);
248 #ifdef OFFIX_DND
249 if (aicon->dnd_command)
250 free(aicon->dnd_command);
251 #endif
252 if (aicon->wm_instance)
253 free(aicon->wm_instance);
254 if (aicon->wm_class)
255 free(aicon->wm_class);
256 #ifdef REDUCE_APPICONS
257 /* There should never be a list but just in case */
258 if (aicon->applist != NULL) {
259 aptmp = aicon->applist;
260 while (aptmp->next) {
261 aptmp = aptmp->next;
262 free(aptmp->prev);
264 free(aptmp);
266 #endif
268 if (aicon == scr->app_icon_list) {
269 if (aicon->next)
270 aicon->next->prev = NULL;
271 scr->app_icon_list = aicon->next;
273 else {
274 if (aicon->next)
275 aicon->next->prev = aicon->prev;
276 if (aicon->prev)
277 aicon->prev->next = aicon->next;
280 aicon->destroyed = 1;
281 wrelease(aicon);
286 #ifdef NEWAPPICON
287 static void
288 drawCorner(WIcon *icon, WWindow *wwin, int active)
290 WScreen *scr = wwin->screen_ptr;
291 XPoint points[3];
292 GC gc;
294 points[0].x = 2;
295 points[0].y = 2;
296 points[1].x = 12;
297 points[1].y = 2;
298 points[2].x = 2;
299 points[2].y = 12;
300 if (active) {
301 gc=scr->focused_texture->any.gc;
302 } else {
303 gc=scr->unfocused_texture->any.gc;
305 XFillPolygon(dpy, icon->core->window, gc, points, 3,
306 Convex, CoordModeOrigin);
308 #endif /* NEWAPPICON */
311 void
312 wAppIconMove(WAppIcon *aicon, int x, int y)
314 XMoveWindow(dpy, aicon->icon->core->window, x, y);
315 aicon->x_pos = x;
316 aicon->y_pos = y;
320 #ifdef WS_INDICATOR
321 static void
322 updateDockNumbers(WScreen *scr)
324 int length;
325 char *ws_numbers;
326 GC numbers_gc;
327 XGCValues my_gc_values;
328 unsigned long my_v_mask = (GCForeground);
329 WAppIcon *dicon = scr->dock->icon_array[0];
331 my_gc_values.foreground = scr->white_pixel;
332 numbers_gc = XCreateGC(dpy, dicon->icon->core->window,
333 my_v_mask, &my_gc_values);
335 ws_numbers = malloc(20);
336 sprintf(ws_numbers, "%i [ %i ]", scr->current_workspace+1,
337 ((scr->current_workspace/10)+1));
338 length = strlen(ws_numbers);
340 XClearArea(dpy, dicon->icon->core->window, 2, 2, 50,
341 scr->icon_title_font->y+1, False);
343 #ifndef I18N_MB
344 XSetFont(dpy, numbers_gc, scr->icon_title_font->font->fid);
345 XSetForeground(dpy, numbers_gc, scr->black_pixel);
346 XDrawString(dpy, dicon->icon->core->window,
347 numbers_gc, 4, scr->icon_title_font->y+3, ws_numbers, length);
348 XSetForeground(dpy, numbers_gc, scr->white_pixel);
349 XDrawString(dpy, dicon->icon->core->window,
350 numbers_gc, 3, scr->icon_title_font->y+2, ws_numbers, length);
351 #else
352 XSetForeground(dpy, numbers_gc, scr->black_pixel);
353 XmbDrawString(dpy, dicon->icon->core->window,
354 scr->icon_title_font->font, numbers_gc, 4,
355 scr->icon_title_font->y+3, ws_numbers, length);
356 XSetForeground(dpy, numbers_gc, scr->white_pixel);
357 XmbDrawString(dpy, dicon->icon->core->window,
358 scr->icon_title_font->font, numbers_gc, 3,
359 scr->icon_title_font->y+2, ws_numbers, length);
360 #endif /* I18N_MB */
362 XFreeGC(dpy, numbers_gc);
363 free(ws_numbers);
365 #endif /* WS_INDICATOR */
368 void
369 wAppIconPaint(WAppIcon *aicon)
371 WScreen *scr = aicon->icon->core->screen_ptr;
373 wIconPaint(aicon->icon);
376 # ifdef WS_INDICATOR
377 if (aicon->docked && scr->dock && aicon->yindex==0)
378 updateDockNumbers(scr);
379 # endif
380 if (scr->dock_dots && aicon->docked && !aicon->running
381 && aicon->command!=NULL) {
382 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
383 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
384 XCopyArea(dpy, scr->dock_dots->image, aicon->icon->core->window,
385 scr->copy_gc, 0, 0, scr->dock_dots->width,
386 scr->dock_dots->height, 0, 0);
389 #ifdef HIDDENDOT
391 WApplication *wapp;
392 wapp = wApplicationOf(aicon->main_window);
393 if (wapp && wapp->flags.hidden) {
394 XSetClipMask(dpy, scr->copy_gc, scr->dock_dots->mask);
395 XSetClipOrigin(dpy, scr->copy_gc, 0, 0);
396 XCopyArea(dpy, scr->dock_dots->image,
397 aicon->icon->core->window,
398 scr->copy_gc, 0, 0, 7,
399 scr->dock_dots->height, 0, 0);
402 #endif /* HIDDENDOT */
404 #ifdef NEWAPPICON
405 if (!wPreferences.strict_ns && aicon->icon->owner!=NULL) {
406 int active=0;
407 if (aicon->main_window==None) {
408 active = (aicon->icon->owner->flags.focused ? 1 : 0);
409 } else {
410 WApplication *wapp;
412 wapp = wApplicationOf(aicon->main_window);
413 if (!wapp) {
414 active = aicon->icon->owner->flags.focused;
415 wwarning("error in wAppIconPaint(). Please report it");
416 } else {
417 active = wapp->main_window_desc->flags.focused;
418 if (wapp->main_window_desc->flags.hidden
419 || !wapp->main_window_desc->flags.mapped)
420 active = -1;
423 if (active>=0)
424 drawCorner(aicon->icon, aicon->icon->owner, active);
426 #endif /* NEWAPPICON */
428 XSetClipMask(dpy, scr->copy_gc, None);
429 if (aicon->launching) {
430 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
431 0, 0, wPreferences.icon_size, wPreferences.icon_size);
437 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
439 #ifdef REDUCE_APPICONS
440 unsigned int
441 wAppIconReduceAppCount(WApplication *wapp)
443 WAppIconAppList *applist;
445 if (wapp == NULL)
446 return 0;
448 if (wapp->app_icon == NULL)
449 return 0;
451 /* If given a main window, check the applist
452 * and remove the if it exists
454 applist = wapp->app_icon->applist;
455 while (applist != NULL) {
456 if (applist->wapp == wapp) {
457 /* If this app owns the appicon, change the appicon's
458 * owner to the next app in the list or NULL
460 if (wapp->app_icon->icon->owner == applist->wapp->main_window_desc)
462 if (applist->next) {
463 wapp->app_icon->icon->owner = applist->next->wapp->main_window_desc;
464 } else if (applist->prev) {
465 wapp->app_icon->icon->owner = applist->prev->wapp->main_window_desc;
466 } else {
467 wapp->app_icon->icon->owner = NULL;
470 if (applist->prev)
471 applist->prev->next = applist->next;
473 if (applist->next)
474 applist->next->prev = applist->prev;
476 if (applist == wapp->app_icon->applist)
477 wapp->app_icon->applist = applist->next;
479 free(applist);
481 if (wapp->app_icon->applist != NULL)
482 wapp->app_icon->main_window = wapp->app_icon->applist->wapp->main_window;
484 return (--wapp->app_icon->num_apps);
486 applist = applist->next;
488 return (--wapp->app_icon->num_apps);
490 #endif
493 static void
494 hideCallback(WMenu *menu, WMenuEntry *entry)
496 WApplication *wapp = (WApplication*)entry->clientdata;
498 if (wapp->flags.hidden) {
499 wWorkspaceChange(menu->menu->screen_ptr, wapp->last_workspace);
500 wUnhideApplication(wapp, False, False);
501 } else {
502 wHideApplication(wapp);
507 static void
508 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
510 WApplication *wapp = (WApplication*)entry->clientdata;
512 wUnhideApplication(wapp, False, True);
516 static void
517 setIconCallback(WMenu *menu, WMenuEntry *entry)
519 WAppIcon *icon = ((WApplication*)entry->clientdata)->app_icon;
520 char *file=NULL;
521 WScreen *scr;
522 int result;
524 assert(icon!=NULL);
526 if (icon->editing)
527 return;
528 icon->editing = 1;
529 scr = icon->icon->core->screen_ptr;
531 wretain(icon);
533 result = wIconChooserDialog(scr, &file, icon->wm_instance, icon->wm_class);
535 if (result && !icon->destroyed) {
536 if (file[0]==0) {
537 free(file);
538 file = NULL;
540 if (!wIconChangeImageFile(icon->icon, file)) {
541 wMessageDialog(scr, _("Error"),
542 _("Could not open specified icon file"),
543 _("OK"), NULL, NULL);
544 } else {
545 wDefaultChangeIcon(scr, icon->wm_instance, icon->wm_class, file);
546 wAppIconPaint(icon);
548 if (file)
549 free(file);
551 icon->editing = 0;
552 wrelease(icon);
556 static void
557 killCallback(WMenu *menu, WMenuEntry *entry)
559 WApplication *wapp = (WApplication*)entry->clientdata;
560 char *buffer;
562 if (!WCHECK_STATE(WSTATE_NORMAL))
563 return;
565 WCHANGE_STATE(WSTATE_MODAL);
567 assert(entry->clientdata!=NULL);
569 buffer = wstrappend(wapp->app_icon ? wapp->app_icon->wm_class : NULL,
570 _(" will be forcibly closed.\n"
571 "Any unsaved changes will be lost.\n"
572 "Please confirm."));
574 wretain(wapp->main_window_desc);
575 if (wPreferences.dont_confirm_kill
576 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
577 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
578 if (!wapp->main_window_desc->flags.destroyed)
579 wClientKill(wapp->main_window_desc);
581 wrelease(wapp->main_window_desc);
583 free(buffer);
585 WCHANGE_STATE(WSTATE_NORMAL);
589 static WMenu*
590 createApplicationMenu(WScreen *scr)
592 WMenu *menu;
594 menu = wMenuCreate(scr, NULL, False);
595 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
596 wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
597 wMenuAddCallback(menu, _("Set Icon..."), setIconCallback, NULL);
598 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
600 return menu;
604 static void
605 openApplicationMenu(WApplication *wapp, int x, int y)
607 WMenu *menu;
608 WScreen *scr = wapp->main_window_desc->screen_ptr;
609 int i;
611 if (!scr->icon_menu) {
612 scr->icon_menu = createApplicationMenu(scr);
613 free(scr->icon_menu->entries[1]->text);
616 menu = scr->icon_menu;
618 if (wapp->flags.hidden) {
619 menu->entries[1]->text = _("Unhide");
620 } else {
621 menu->entries[1]->text = _("Hide");
624 menu->flags.realized = 0;
625 wMenuRealize(menu);
627 x -= menu->frame->core->width/2;
628 if (x + menu->frame->core->width > scr->scr_width)
629 x = scr->scr_width - menu->frame->core->width;
630 if (x < 0)
631 x = 0;
633 /* set client data */
634 for (i = 0; i < menu->entry_no; i++) {
635 menu->entries[i]->clientdata = wapp;
637 wMenuMapAt(menu, x, y, False);
641 /******************************************************************/
643 static void
644 iconExpose(WObjDescriptor *desc, XEvent *event)
646 wAppIconPaint(desc->parent);
650 static void
651 iconDblClick(WObjDescriptor *desc, XEvent *event)
653 WAppIcon *aicon = desc->parent;
654 WApplication *wapp;
655 WScreen *scr = aicon->icon->core->screen_ptr;
656 int unhideHere;
658 #ifndef REDUCE_APPICONS
659 assert(aicon->icon->owner!=NULL);
660 #else
661 if (aicon->icon->owner == NULL) {
662 fprintf(stderr, "Double-click disabled: missing main window.\n");
663 return;
665 #endif
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
674 #ifdef REDUCE_APPICONS
675 if (!wapp) {
676 fprintf(stderr, "Double-click disabled: missing wapp.\n");
677 return;
679 #endif /* REDUCE_APPICONS */
681 unhideHere = (event->xbutton.state & ShiftMask);
683 /* go to the last workspace that the user worked on the app */
684 if (!unhideHere && wapp->last_workspace != scr->current_workspace)
685 wWorkspaceChange(scr, wapp->last_workspace);
687 wUnhideApplication(wapp, event->xbutton.button==Button2, unhideHere);
689 if (event->xbutton.state & MOD_MASK) {
690 wHideOtherApplications(aicon->icon->owner);
695 void
696 appIconMouseDown(WObjDescriptor *desc, XEvent *event)
698 WAppIcon *aicon = desc->parent;
699 WIcon *icon = aicon->icon;
700 XEvent ev;
701 int x=aicon->x_pos, y=aicon->y_pos;
702 int dx=event->xbutton.x, dy=event->xbutton.y;
703 int grabbed=0;
704 int done=0;
705 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
706 WScreen *scr = icon->core->screen_ptr;
707 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
708 int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
709 int ix, iy;
710 int clickButton = event->xbutton.button;
711 Pixmap ghost = None;
712 Window wins[2];
714 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
715 return;
717 if (IsDoubleClick(scr, event)) {
718 iconDblClick(desc, event);
719 return;
722 if (event->xbutton.button == Button3) {
723 WObjDescriptor *desc;
724 WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);
726 if (!wapp)
727 return;
729 openApplicationMenu(wapp, event->xbutton.x_root,
730 event->xbutton.y_root);
732 /* allow drag select of menu */
733 desc = &scr->icon_menu->menu->descriptor;
734 event->xbutton.send_event = True;
735 (*desc->handle_mousedown)(desc, event);
736 return;
739 #ifdef DEBUG
740 puts("Moving icon");
741 #endif
742 if (event->xbutton.state & MOD_MASK)
743 wLowerFrame(icon->core);
744 else
745 wRaiseFrame(icon->core);
748 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
749 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
750 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
751 wwarning("pointer grab failed for appicon move");
754 if (wPreferences.flags.nodock && wPreferences.flags.noclip)
755 dockable = 0;
756 else
757 dockable = canBeDocked(icon->owner);
759 wins[0] = icon->core->window;
760 wins[1] = scr->dock_shadow;
761 XRestackWindows(dpy, wins, 2);
762 if (superfluous) {
763 if (icon->pixmap!=None)
764 ghost = MakeGhostIcon(scr, icon->pixmap);
765 else
766 ghost = MakeGhostIcon(scr, icon->core->window);
767 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
768 ghost);
769 XClearWindow(dpy, scr->dock_shadow);
772 while (!done) {
773 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
774 |ButtonMotionMask|ExposureMask, &ev);
775 switch (ev.type) {
776 case Expose:
777 WMHandleEvent(&ev);
778 break;
780 case MotionNotify:
781 if (!grabbed) {
782 if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
783 || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
784 XChangeActivePointerGrab(dpy, ButtonMotionMask
785 |ButtonReleaseMask|ButtonPressMask,
786 wCursor[WCUR_MOVE], CurrentTime);
787 grabbed=1;
788 } else {
789 break;
792 x = ev.xmotion.x_root - dx;
793 y = ev.xmotion.y_root - dy;
794 XMoveWindow(dpy, icon->core->window, x, y);
796 if (dockable) {
797 if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
798 &ix, &iy, False)) {
799 shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
800 shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;
802 if (scr->last_dock != scr->dock && collapsed) {
803 scr->last_dock->collapsed = 1;
804 wDockHideIcons(scr->last_dock);
805 collapsed = 0;
807 if (!collapsed && (collapsed = scr->dock->collapsed)) {
808 scr->dock->collapsed = 0;
809 wDockShowIcons(scr->dock);
812 if (scr->dock->auto_raise_lower)
813 wDockRaise(scr->dock);
815 scr->last_dock = scr->dock;
817 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
818 if (!docking) {
819 XMapWindow(dpy, scr->dock_shadow);
821 docking = 1;
822 } else if (workspace->clip &&
823 wDockSnapIcon(workspace->clip, aicon, x, y,
824 &ix, &iy, False)) {
825 shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
826 shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;
828 if (scr->last_dock != workspace->clip && collapsed) {
829 scr->last_dock->collapsed = 1;
830 wDockHideIcons(scr->last_dock);
831 collapsed = 0;
833 if (!collapsed && (collapsed = workspace->clip->collapsed)) {
834 workspace->clip->collapsed = 0;
835 wDockShowIcons(workspace->clip);
838 if (workspace->clip->auto_raise_lower)
839 wDockRaise(workspace->clip);
841 scr->last_dock = workspace->clip;
843 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
844 if (!docking) {
845 XMapWindow(dpy, scr->dock_shadow);
847 docking = 1;
848 } else if (docking) {
849 XUnmapWindow(dpy, scr->dock_shadow);
850 docking = 0;
854 break;
856 case ButtonPress:
857 break;
859 case ButtonRelease:
860 if (ev.xbutton.button != clickButton)
861 break;
862 XUngrabPointer(dpy, CurrentTime);
864 if (docking) {
865 Bool docked;
867 /* icon is trying to be docked */
868 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
869 XUnmapWindow(dpy, scr->dock_shadow);
870 docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
871 if (scr->last_dock->auto_collapse) {
872 collapsed = 0;
874 if (workspace->clip &&
875 workspace->clip != scr->last_dock &&
876 workspace->clip->auto_raise_lower)
877 wDockLower(workspace->clip);
879 if (!docked) {
880 /* If icon could not be docked, slide it back to the old
881 * position */
882 SlideWindow(icon->core->window, x, y, aicon->x_pos,
883 aicon->y_pos);
885 } else {
886 XMoveWindow(dpy, icon->core->window, x, y);
887 aicon->x_pos = x;
888 aicon->y_pos = y;
889 if (workspace->clip && workspace->clip->auto_raise_lower)
890 wDockLower(workspace->clip);
892 if (collapsed) {
893 scr->last_dock->collapsed = 1;
894 wDockHideIcons(scr->last_dock);
895 collapsed = 0;
897 if (superfluous) {
898 if (ghost!=None)
899 XFreePixmap(dpy, ghost);
900 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
903 if (wPreferences.auto_arrange_icons)
904 wArrangeIcons(scr, True);
906 done = 1;
907 break;
910 #ifdef DEBUG
911 puts("End icon move");
912 #endif