Code update for Window Maker version 0.50.0
[wmaker-crm.git] / src / dock.c
blob7984d99318ea962e4625791c2f13726a08357076
1 /* dock.c- built-in Dock module for WindowMaker
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <limits.h>
34 #ifndef PATH_MAX
35 #define PATH_MAX DEFAULT_PATH_MAX
36 #endif
38 #include "WindowMaker.h"
39 #include "wcore.h"
40 #include "window.h"
41 #include "icon.h"
42 #include "appicon.h"
43 #include "actions.h"
44 #include "stacking.h"
45 #include "dock.h"
46 #include "dialog.h"
47 #include "funcs.h"
48 #include "properties.h"
49 #include "menu.h"
50 #include "client.h"
51 #include "defaults.h"
52 #include "workspace.h"
53 #include "framewin.h"
54 #include "superfluous.h"
56 #include "list.h"
58 #ifdef WMSOUND
59 #include "wmsound.h"
60 #endif
62 #include <proplist.h>
67 /**** Local variables ****/
68 #define CLIP_REWIND 1
69 #define CLIP_IDLE 0
70 #define CLIP_FORWARD 2
72 #define CLIP_BUTTON_SIZE 23
75 /**** Global variables ****/
77 /* in dockedapp.c */
78 extern void DestroyDockAppSettingsPanel();
80 extern void ShowDockAppSettingsPanel(WAppIcon *aicon);
84 extern Cursor wCursor[WCUR_LAST];
86 extern WPreferences wPreferences;
88 extern XContext wWinContext;
90 #ifdef OFFIX_DND
91 extern Atom _XA_DND_PROTOCOL;
92 #endif
95 #define MOD_MASK wPreferences.modifier_mask
97 extern void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
99 #define ICON_SIZE wPreferences.icon_size
102 /***** Local variables ****/
104 static proplist_t dCommand=NULL;
105 #ifdef OFFIX_DND
106 static proplist_t dDropCommand=NULL;
107 #endif
108 static proplist_t dAutoLaunch, dName, dForced, dBuggyApplication, dYes, dNo;
109 static proplist_t dHost, dDock, dClip;
110 static proplist_t dAutoAttractIcons, dKeepAttracted;
112 static proplist_t dPosition, dApplications, dLowered, dCollapsed, dAutoCollapse;
114 static proplist_t dAutoRaiseLower;
116 static void dockIconPaint(WAppIcon *btn);
118 static void iconMouseDown(WObjDescriptor *desc, XEvent *event);
120 static pid_t execCommand(WAppIcon *btn, char *command, WSavedState *state);
122 static void trackDeadProcess(pid_t pid, unsigned char status, WDock *dock);
124 static int getClipButton(int px, int py);
126 static void toggleLowered(WDock *dock);
128 static void toggleCollapsed(WDock *dock);
130 static void clipIconExpose(WObjDescriptor *desc, XEvent *event);
132 static void clipLeave(WDock *dock);
134 static void handleClipChangeWorkspace(WScreen *scr, XEvent *event);
136 Bool moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y);
138 static void clipEnterNotify(WObjDescriptor *desc, XEvent *event);
139 static void clipLeaveNotify(WObjDescriptor *desc, XEvent *event);
140 static void clipAutoCollapse(void *cdata);
141 static void launchDockedApplication(WAppIcon *btn);
143 static void clipAutoLower(void *cdata);
144 static void clipAutoRaise(void *cdata);
146 static void showClipBalloon(WDock *dock, int workspace);
148 #ifdef OFFIX_DND
150 #define DndNotDnd -1
151 #define DndUnknown 0
152 #define DndRawData 1
153 #define DndFile 2
154 #define DndFiles 3
155 #define DndText 4
156 #define DndDir 5
157 #define DndLink 6
158 #define DndExe 7
160 #define DndEND 8
162 #endif /* OFFIX_DND */
166 static void
167 make_keys()
169 if (dCommand!=NULL)
170 return;
172 dCommand = PLRetain(PLMakeString("Command"));
173 #ifdef OFFIX_DND
174 dDropCommand = PLRetain(PLMakeString("DropCommand"));
175 #endif
176 dAutoLaunch = PLRetain(PLMakeString("AutoLaunch"));
177 dName = PLRetain(PLMakeString("Name"));
178 dForced = PLRetain(PLMakeString("Forced"));
179 dBuggyApplication = PLRetain(PLMakeString("BuggyApplication"));
180 dYes = PLRetain(PLMakeString("Yes"));
181 dNo = PLRetain(PLMakeString("No"));
182 dHost = PLRetain(PLMakeString("Host"));
184 dPosition = PLMakeString("Position");
185 dApplications = PLMakeString("Applications");
186 dLowered = PLMakeString("Lowered");
187 dCollapsed = PLMakeString("Collapsed");
188 dAutoCollapse = PLMakeString("AutoCollapse");
189 dAutoRaiseLower = PLMakeString("AutoRaiseLower");
190 dAutoAttractIcons = PLMakeString("AutoAttractIcons");
191 dKeepAttracted = PLMakeString("KeepAttracted");
193 dDock = PLMakeString("Dock");
194 dClip = PLMakeString("Clip");
199 static void
200 renameCallback(WMenu *menu, WMenuEntry *entry)
202 WDock *dock = entry->clientdata;
203 char buffer[128];
204 int wspace;
205 char *name;
207 assert(entry->clientdata!=NULL);
209 wspace = dock->screen_ptr->current_workspace;
211 name = wstrdup(dock->screen_ptr->workspaces[wspace]->name);
213 sprintf(buffer, _("Type the name for workspace %i:"), wspace+1);
214 if (wInputDialog(dock->screen_ptr, _("Rename Workspace"), buffer,
215 &name)) {
216 wWorkspaceRename(dock->screen_ptr, wspace, name);
218 if (name) {
219 free(name);
224 static void
225 toggleLoweredCallback(WMenu *menu, WMenuEntry *entry)
227 assert(entry->clientdata!=NULL);
229 toggleLowered(entry->clientdata);
231 entry->flags.indicator_on = !((WDock*)entry->clientdata)->lowered;
233 wMenuPaint(menu);
238 static void
239 killCallback(WMenu *menu, WMenuEntry *entry)
241 WAppIcon *icon;
242 #ifdef REDUCE_APPICONS
243 WAppIconAppList *tapplist;
245 extern Atom _XA_WM_DELETE_WINDOW;
246 #endif
248 assert(entry->clientdata!=NULL);
250 icon = (WAppIcon*)entry->clientdata;
252 icon->editing = 1;
254 #ifdef REDUCE_APPICONS
255 /* Send a delete message to the main window of each application
256 * bound to this docked appicon. - cls
258 tapplist = icon->applist;
259 while (tapplist != NULL) {
260 if (tapplist->wapp->main_window_desc != NULL) {
261 if (tapplist->wapp->main_window_desc->protocols.DELETE_WINDOW) {
262 wClientSendProtocol(tapplist->wapp->main_window_desc,
263 _XA_WM_DELETE_WINDOW, CurrentTime);
264 } else {
265 wClientKill(tapplist->wapp->main_window_desc);
268 tapplist = tapplist->next;
270 #else
271 if (wPreferences.dont_confirm_kill
272 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
273 _("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
274 _("Yes"), _("No"), NULL)==WAPRDefault) {
275 if (icon->icon && icon->icon->owner) {
276 wClientKill(icon->icon->owner);
279 #endif /* !REDUCE_APPICONS */
281 icon->editing = 0;
285 static LinkedList*
286 getSelected(WDock *dock)
288 LinkedList *ret=NULL;
289 WAppIcon *btn;
290 int i;
292 for (i=1; i<dock->max_icons; i++) {
293 btn = dock->icon_array[i];
294 if (btn && btn->icon->selected) {
295 ret = list_cons(btn, ret);
299 return ret;
303 static void
304 paintClipButtons(WAppIcon *clipIcon, Bool lpushed, Bool rpushed)
306 Window win = clipIcon->icon->core->window;
307 WScreen *scr = clipIcon->icon->core->screen_ptr;
308 XPoint p[4];
309 int pt = CLIP_BUTTON_SIZE*ICON_SIZE/64;
310 int tp = ICON_SIZE - pt;
311 int as = pt - 15; /* 15 = 5+5+5 */
314 if (rpushed) {
315 p[0].x = tp+1;
316 p[0].y = 1;
317 p[1].x = ICON_SIZE-2;
318 p[1].y = 1;
319 p[2].x = ICON_SIZE-2;
320 p[2].y = pt-1;
321 } else if (lpushed) {
322 p[0].x = 1;
323 p[0].y = tp;
324 p[1].x = pt;
325 p[1].y = ICON_SIZE-2;
326 p[2].x = 1;
327 p[2].y = ICON_SIZE-2;
329 if (lpushed || rpushed) {
330 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
331 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
332 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
335 p[0].x = p[3].x = ICON_SIZE-6-as;
336 p[0].y = p[3].y = 5;
337 p[1].x = ICON_SIZE-6;
338 p[1].y = 5;
339 p[2].x = ICON_SIZE-6;
340 p[2].y = 5+as;
341 if (rpushed) {
342 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
343 XDrawLines(dpy, win, scr->draw_gc, p, 4, CoordModeOrigin);
344 } else {
345 XFillPolygon(dpy, win, scr->clip_title_gc, p,3,Convex,CoordModeOrigin);
346 XDrawLines(dpy, win, scr->clip_title_gc, p,4,CoordModeOrigin);
349 p[0].x = p[3].x = 5;
350 p[0].y = p[3].y = ICON_SIZE-6-as;
351 p[1].x = 5;
352 p[1].y = ICON_SIZE-6;
353 p[2].x = 5+as;
354 p[2].y = ICON_SIZE-6;
355 if (lpushed) {
356 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
357 XDrawLines(dpy, win, scr->draw_gc, p, 4, CoordModeOrigin);
358 } else {
359 XFillPolygon(dpy, win, scr->clip_title_gc, p,3,Convex,CoordModeOrigin);
360 XDrawLines(dpy, win, scr->clip_title_gc, p,4,CoordModeOrigin);
365 RImage*
366 wClipMakeTile(WScreen *scr, RImage *normalTile)
368 RImage *tile = RCloneImage(normalTile);
369 RColor black;
370 RColor dark;
371 RColor light;
372 int pt, tp;
374 pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
375 tp = wPreferences.icon_size-1 - pt;
377 black.alpha = 255;
378 black.red = black.green = black.blue = 0;
380 dark.alpha = 0;
381 dark.red = dark.green = dark.blue = 80;
383 light.alpha = 0;
384 light.red = light.green = light.blue = 80;
387 /* top right */
388 ROperateLine(tile, RSubtractOperation, tp, 0, wPreferences.icon_size-2,
389 pt-1, &dark);
390 RDrawLine(tile, tp-1, 0, wPreferences.icon_size-1, pt+1, &black);
391 ROperateLine(tile, RAddOperation, tp, 2, wPreferences.icon_size-3,
392 pt, &light);
395 /* bottom left */
396 ROperateLine(tile, RAddOperation, 2, tp+2, pt-2,
397 wPreferences.icon_size-3, &dark);
398 RDrawLine(tile, 0, tp-1, pt+1, wPreferences.icon_size-1, &black);
399 ROperateLine(tile, RSubtractOperation, 0, tp-2, pt+1,
400 wPreferences.icon_size-2, &light);
402 return tile;
406 static void
407 removeIconsCallback(WMenu *menu, WMenuEntry *entry)
409 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
410 WDock *dock;
411 WAppIcon *aicon;
412 LinkedList *selectedIcons;
413 int keepit;
415 assert(clickedIcon!=NULL);
417 dock = clickedIcon->dock;
419 selectedIcons = getSelected(dock);
421 if (selectedIcons) {
422 if (wMessageDialog(dock->screen_ptr, _("Workspace Clip"),
423 _("All selected icons will be removed!"),
424 _("OK"), _("Cancel"), NULL)!=WAPRDefault) {
425 return;
427 } else {
428 if (clickedIcon->xindex==0 && clickedIcon->yindex==0)
429 return;
430 selectedIcons = list_cons(clickedIcon, NULL);
433 while (selectedIcons) {
434 aicon = selectedIcons->head;
435 keepit = aicon->running && wApplicationOf(aicon->main_window);
436 wDockDetach(dock, aicon);
437 if (keepit) {
438 PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);
439 XMoveWindow(dpy, aicon->icon->core->window,
440 aicon->x_pos, aicon->y_pos);
441 if (!dock->mapped || dock->collapsed)
442 XMapWindow(dpy, aicon->icon->core->window);
444 list_remove_head(&selectedIcons);
447 if (wPreferences.auto_arrange_icons)
448 wArrangeIcons(dock->screen_ptr, True);
452 static void
453 keepIconsCallback(WMenu *menu, WMenuEntry *entry)
455 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
456 WDock *dock;
457 WAppIcon *aicon;
458 LinkedList *selectedIcons;
460 assert(clickedIcon!=NULL);
461 dock = clickedIcon->dock;
463 selectedIcons = getSelected(dock);
465 if (!selectedIcons && clickedIcon!=dock->screen_ptr->clip_icon) {
466 char *command = NULL;
468 if (!clickedIcon->command && !clickedIcon->editing) {
469 clickedIcon->editing = 1;
470 if (wInputDialog(dock->screen_ptr, _("Keep Icon"),
471 _("Type the command used to launch the application"),
472 &command)) {
473 if (command && (command[0]==0 ||
474 (command[0]=='-' && command[1]==0))) {
475 free(command);
476 command = NULL;
478 clickedIcon->command = command;
479 clickedIcon->editing = 0;
480 } else {
481 clickedIcon->editing = 0;
482 if (command)
483 free(command);
484 return;
488 selectedIcons = list_cons(clickedIcon, NULL);
491 while (selectedIcons) {
492 aicon = selectedIcons->head;
493 if (aicon->icon->selected)
494 wIconSelect(aicon->icon);
495 if (aicon && aicon->attracted && aicon->command) {
496 aicon->attracted = 0;
497 if (aicon->icon->shadowed) {
498 aicon->icon->shadowed = 0;
499 aicon->icon->force_paint = 1;
500 wAppIconPaint(aicon);
503 list_remove_head(&selectedIcons);
510 static void
511 toggleAutoAttractCallback(WMenu *menu, WMenuEntry *entry)
513 WDock *dock = (WDock*)entry->clientdata;
515 assert(entry->clientdata!=NULL);
517 dock->attract_icons = !dock->attract_icons;
518 /*if (!dock->attract_icons)
519 dock->keep_attracted = 0;*/
521 entry->flags.indicator_on = dock->attract_icons;
523 wMenuPaint(menu);
527 static void
528 toggleKeepCallback(WMenu *menu, WMenuEntry *entry)
530 WDock *dock = (WDock*)entry->clientdata;
531 WAppIcon *btn;
532 int i;
534 assert(entry->clientdata!=NULL);
536 dock->keep_attracted = !dock->keep_attracted;
538 if (dock->keep_attracted) {
539 for (i=0; i< dock->max_icons; i++) {
540 btn = dock->icon_array[i];
541 if (btn && btn->attracted && btn->command) {
542 btn->attracted = 0;
543 if (btn->icon->shadowed) {
544 btn->icon->shadowed = 0;
545 btn->icon->force_paint = 1;
546 wAppIconPaint(btn);
552 entry->flags.indicator_on = dock->keep_attracted;
554 wMenuPaint(menu);
558 static void
559 selectCallback(WMenu *menu, WMenuEntry *entry)
561 WAppIcon *icon = (WAppIcon*)entry->clientdata;
563 assert(icon!=NULL);
565 wIconSelect(icon->icon);
567 wMenuPaint(menu);
571 static void
572 colectIconsCallback(WMenu *menu, WMenuEntry *entry)
574 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
575 WDock *clip;
576 WAppIcon *aicon;
577 int x, y, x_pos, y_pos;
579 assert(entry->clientdata!=NULL);
580 clip = clickedIcon->dock;
582 aicon = clip->screen_ptr->app_icon_list;
584 while (aicon) {
585 if (!aicon->docked && wDockFindFreeSlot(clip, &x, &y)) {
586 x_pos = clip->x_pos + x*ICON_SIZE;
587 y_pos = clip->y_pos + y*ICON_SIZE;
588 if (aicon->x_pos != x_pos || aicon->y_pos != y_pos) {
589 #ifdef ANIMATIONS
590 if (wPreferences.no_animations) {
591 XMoveWindow(dpy, aicon->icon->core->window, x_pos, y_pos);
592 } else {
593 SlideWindow(aicon->icon->core->window,
594 aicon->x_pos, aicon->y_pos, x_pos, y_pos);
596 #else
597 XMoveWindow(dpy, aicon->icon->core->window, x_pos, y_pos);
598 #endif /* ANIMATIONS */
600 aicon->attracted = 1;
601 if (!clip->keep_attracted && !aicon->icon->shadowed) {
602 aicon->icon->shadowed = 1;
603 aicon->icon->force_paint = 1;
604 /* We don't do an wAppIconPaint() here because it's in
605 * wDockAttachIcon(). -Dan
608 wDockAttachIcon(clip, aicon, x, y);
609 if (clip->collapsed || !clip->mapped)
610 XUnmapWindow(dpy, aicon->icon->core->window);
612 aicon = aicon->next;
617 static void
618 selectIconsCallback(WMenu *menu, WMenuEntry *entry)
620 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
621 WDock *dock;
622 LinkedList *selectedIcons;
623 WAppIcon *btn;
624 int i;
626 assert(clickedIcon!=NULL);
627 dock = clickedIcon->dock;
629 selectedIcons = getSelected(dock);
631 if (!selectedIcons) {
632 for (i=1; i<dock->max_icons; i++) {
633 btn = dock->icon_array[i];
634 if (btn && !btn->icon->selected) {
635 wIconSelect(btn->icon);
638 } else {
639 while(selectedIcons) {
640 btn = selectedIcons->head;
641 wIconSelect(btn->icon);
642 list_remove_head(&selectedIcons);
646 wMenuPaint(menu);
650 static void
651 toggleCollapsedCallback(WMenu *menu, WMenuEntry *entry)
653 assert(entry->clientdata!=NULL);
655 toggleCollapsed(entry->clientdata);
657 entry->flags.indicator_on = ((WDock*)entry->clientdata)->collapsed;
659 wMenuPaint(menu);
663 static void
664 toggleAutoCollapseCallback(WMenu *menu, WMenuEntry *entry)
666 WDock *dock;
667 assert(entry->clientdata!=NULL);
669 dock = (WDock*) entry->clientdata;
671 dock->auto_collapse = !dock->auto_collapse;
672 if (dock->auto_collapse_magic) {
673 WMDeleteTimerHandler(dock->auto_collapse_magic);
674 dock->auto_collapse_magic = NULL;
677 entry->flags.indicator_on = ((WDock*)entry->clientdata)->auto_collapse;
679 wMenuPaint(menu);
683 static void
684 toggleAutoRaiseLowerCallback(WMenu *menu, WMenuEntry *entry)
686 WDock *dock;
687 assert(entry->clientdata!=NULL);
689 dock = (WDock*) entry->clientdata;
691 dock->auto_raise_lower = !dock->auto_raise_lower;
693 entry->flags.indicator_on = ((WDock*)entry->clientdata)->auto_raise_lower;
695 wMenuPaint(menu);
699 static void
700 launchCallback(WMenu *menu, WMenuEntry *entry)
702 WAppIcon *btn = (WAppIcon*)entry->clientdata;
704 launchDockedApplication(btn);
708 static void
709 settingsCallback(WMenu *menu, WMenuEntry *entry)
711 WAppIcon *btn = (WAppIcon*)entry->clientdata;
713 if (btn->editing)
714 return;
715 ShowDockAppSettingsPanel(btn);
719 static void
720 hideCallback(WMenu *menu, WMenuEntry *entry)
722 WApplication *wapp;
723 WAppIcon *btn = (WAppIcon*)entry->clientdata;
725 wapp = wApplicationOf(btn->icon->owner->main_window);
727 if (wapp->flags.hidden) {
728 wWorkspaceChange(btn->icon->core->screen_ptr,wapp->last_workspace);
729 wUnhideApplication(wapp, False, False);
730 } else {
731 wHideApplication(wapp);
736 static void
737 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
739 WApplication *wapp;
740 WAppIcon *btn = (WAppIcon*)entry->clientdata;
742 wapp = wApplicationOf(btn->icon->owner->main_window);
744 wUnhideApplication(wapp, False, True);
748 WAppIcon*
749 mainIconCreate(WScreen *scr, int type)
751 WAppIcon *btn;
752 int x_pos;
754 if (type == WM_CLIP) {
755 if (scr->clip_icon)
756 return scr->clip_icon;
757 btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMClip", TILE_CLIP);
758 btn->icon->core->descriptor.handle_expose = clipIconExpose;
759 btn->icon->core->descriptor.handle_enternotify = clipEnterNotify;
760 btn->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
761 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
762 x_pos = 0;
764 else {
765 btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMDock", TILE_NORMAL);
766 x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
769 btn->xindex = 0;
770 btn->yindex = 0;
772 btn->icon->core->descriptor.handle_mousedown = iconMouseDown;
773 btn->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
774 btn->icon->core->descriptor.parent = btn;
775 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
776 XMapWindow(dpy, btn->icon->core->window);
777 btn->x_pos = x_pos;
778 btn->y_pos = 0;
779 btn->docked = 1;
780 if (type == WM_CLIP)
781 scr->clip_icon = btn;
783 return btn;
787 static void
788 switchWSCommand(WMenu *menu, WMenuEntry *entry)
790 WAppIcon *btn, *icon = (WAppIcon*) entry->clientdata;
791 WScreen *scr = icon->icon->core->screen_ptr;
792 WDock *src, *dest;
793 LinkedList *selectedIcons;
794 int x, y;
796 if (entry->order == scr->current_workspace)
797 return;
798 src = icon->dock;
799 dest = scr->workspaces[entry->order]->clip;
801 selectedIcons = getSelected(src);
803 if (selectedIcons) {
804 while(selectedIcons) {
805 btn = selectedIcons->head;
806 if (wDockFindFreeSlot(dest, &x, &y)) {
807 moveIconBetweenDocks(src, dest, btn, x, y);
808 XUnmapWindow(dpy, btn->icon->core->window);
810 list_remove_head(&selectedIcons);
812 } else if (icon != scr->clip_icon) {
813 if (wDockFindFreeSlot(dest, &x, &y)) {
814 moveIconBetweenDocks(src, dest, icon, x, y);
815 XUnmapWindow(dpy, icon->icon->core->window);
822 static void
823 launchDockedApplication(WAppIcon *btn)
825 WScreen *scr = btn->icon->core->screen_ptr;
827 if (!btn->launching && btn->command!=NULL) {
828 if (!btn->forced_dock) {
829 btn->relaunching = btn->running;
830 btn->running = 1;
832 if (btn->wm_instance || btn->wm_class) {
833 WWindowAttributes attr;
834 memset(&attr, 0, sizeof(WWindowAttributes));
835 wDefaultFillAttributes(scr, btn->wm_instance, btn->wm_class,
836 &attr, NULL, True);
838 if (!attr.no_appicon && !btn->buggy_app)
839 btn->launching = 1;
840 else
841 btn->running = 0;
843 btn->drop_launch = 0;
844 scr->last_dock = btn->dock;
845 btn->pid = execCommand(btn, btn->command, NULL);
846 if (btn->pid>0) {
847 if (btn->buggy_app) {
848 /* give feedback that the app was launched */
849 btn->launching = 1;
850 dockIconPaint(btn);
851 btn->launching = 0;
852 WMAddTimerHandler(200, (WMCallback*)dockIconPaint, btn);
853 } else {
854 dockIconPaint(btn);
856 } else {
857 wwarning(_("could not launch application %s\n"), btn->command);
858 btn->launching = 0;
859 if (!btn->relaunching)
860 btn->running = 0;
867 static void
868 updateWorkspaceMenu(WMenu *menu, WAppIcon *icon)
870 WScreen *scr = menu->frame->screen_ptr;
871 char title[MAX_WORKSPACENAME_WIDTH+1];
872 int i;
874 if (!menu || !icon)
875 return;
877 for (i=0; i<scr->workspace_count; i++) {
878 if (i < menu->entry_no) {
879 if (strcmp(menu->entries[i]->text,scr->workspaces[i]->name)!=0) {
880 free(menu->entries[i]->text);
881 strcpy(title, scr->workspaces[i]->name);
882 menu->entries[i]->text = wstrdup(title);
883 menu->flags.realized = 0;
885 menu->entries[i]->clientdata = (void*)icon;
886 } else {
887 strcpy(title, scr->workspaces[i]->name);
889 wMenuAddCallback(menu, title, switchWSCommand, (void*)icon);
891 menu->flags.realized = 0;
893 if (i == scr->current_workspace) {
894 wMenuSetEnabled(menu, i, False);
895 } else {
896 wMenuSetEnabled(menu, i, True);
900 if (!menu->flags.realized)
901 wMenuRealize(menu);
905 static WMenu*
906 makeWorkspaceMenu(WScreen *scr)
908 WMenu *menu;
910 menu = wMenuCreate(scr, NULL, False);
911 if (!menu)
912 wwarning(_("could not create workspace submenu for Clip menu"));
914 wMenuAddCallback(menu, "", switchWSCommand, (void*)scr->clip_icon);
916 menu->flags.realized = 0;
917 wMenuRealize(menu);
919 return menu;
923 static void
924 updateClipOptionsMenu(WMenu *menu, WDock *dock)
926 WMenuEntry *entry;
927 int index = 0;
929 if (!menu || !dock)
930 return;
932 /* keep on top */
933 entry = menu->entries[index];
934 entry->flags.indicator_on = !dock->lowered;
935 entry->clientdata = dock;
937 /* collapsed */
938 entry = menu->entries[++index];
939 entry->flags.indicator_on = dock->collapsed;
940 entry->clientdata = dock;
942 /* auto-collapse */
943 entry = menu->entries[++index];
944 entry->flags.indicator_on = dock->auto_collapse;
945 entry->clientdata = dock;
947 /* auto-raise/lower */
948 entry = menu->entries[++index];
949 entry->flags.indicator_on = dock->auto_raise_lower;
950 entry->clientdata = dock;
952 /* attract icons */
953 entry = menu->entries[++index];
954 entry->flags.indicator_on = dock->attract_icons;
955 entry->clientdata = dock;
957 /* keep attracted icons */
958 entry = menu->entries[++index];
959 entry->flags.indicator_on = dock->keep_attracted;
960 entry->clientdata = dock;
962 menu->flags.realized = 0;
963 wMenuRealize(menu);
967 static WMenu*
968 makeClipOptionsMenu(WScreen *scr)
970 WMenu *menu;
971 WMenuEntry *entry;
973 menu = wMenuCreate(scr, NULL, False);
974 if (!menu) {
975 wwarning(_("could not create options submenu for Clip menu"));
976 return NULL;
979 entry = wMenuAddCallback(menu, _("Keep on top"),
980 toggleLoweredCallback, NULL);
981 entry->flags.indicator = 1;
982 entry->flags.indicator_on = 1;
983 entry->flags.indicator_type = MI_CHECK;
985 entry = wMenuAddCallback(menu, _("Collapsed"),
986 toggleCollapsedCallback, NULL);
987 entry->flags.indicator = 1;
988 entry->flags.indicator_on = 1;
989 entry->flags.indicator_type = MI_CHECK;
991 entry = wMenuAddCallback(menu, _("AutoCollapse"),
992 toggleAutoCollapseCallback, NULL);
993 entry->flags.indicator = 1;
994 entry->flags.indicator_on = 1;
995 entry->flags.indicator_type = MI_CHECK;
997 entry = wMenuAddCallback(menu, _("AutoRaiseLower"),
998 toggleAutoRaiseLowerCallback, NULL);
999 entry->flags.indicator = 1;
1000 entry->flags.indicator_on = 1;
1001 entry->flags.indicator_type = MI_CHECK;
1003 entry = wMenuAddCallback(menu, _("AutoAttract Icons"),
1004 toggleAutoAttractCallback, NULL);
1005 entry->flags.indicator = 1;
1006 entry->flags.indicator_on = 1;
1007 entry->flags.indicator_type = MI_CHECK;
1009 entry = wMenuAddCallback(menu, _("Keep Attracted Icons"),
1010 toggleKeepCallback, NULL);
1011 entry->flags.indicator = 1;
1012 entry->flags.indicator_on = 1;
1013 entry->flags.indicator_type = MI_CHECK;
1015 menu->flags.realized = 0;
1016 wMenuRealize(menu);
1018 return menu;
1022 static WMenu*
1023 dockMenuCreate(WScreen *scr, int type)
1025 WMenu *menu;
1026 WMenuEntry *entry;
1028 if (type == WM_CLIP && scr->clip_menu)
1029 return scr->clip_menu;
1031 menu = wMenuCreate(scr, NULL, False);
1032 if (type != WM_CLIP) {
1033 entry = wMenuAddCallback(menu, _("Keep on top"),
1034 toggleLoweredCallback, NULL);
1035 entry->flags.indicator = 1;
1036 entry->flags.indicator_on = 1;
1037 entry->flags.indicator_type = MI_CHECK;
1038 } else {
1039 entry = wMenuAddCallback(menu, _("Clip Options"), NULL, NULL);
1040 scr->clip_options = makeClipOptionsMenu(scr);
1041 if (scr->clip_options)
1042 wMenuEntrySetCascade(menu, entry, scr->clip_options);
1044 wMenuAddCallback(menu, _("Rename Workspace"), renameCallback, NULL);
1046 wMenuAddCallback(menu, _("(Un)Select Icon"), selectCallback, NULL);
1048 wMenuAddCallback(menu, _("(Un)Select All Icons"), selectIconsCallback,
1049 NULL);
1051 wMenuAddCallback(menu, _("Keep Icon(s)"), keepIconsCallback, NULL);
1053 entry = wMenuAddCallback(menu, _("Move Icon(s) To"), NULL, NULL);
1054 scr->clip_submenu = makeWorkspaceMenu(scr);
1055 if (scr->clip_submenu)
1056 wMenuEntrySetCascade(menu, entry, scr->clip_submenu);
1058 wMenuAddCallback(menu, _("Remove Icon(s)"), removeIconsCallback, NULL);
1060 wMenuAddCallback(menu, _("Attract Icons"), colectIconsCallback, NULL);
1063 wMenuAddCallback(menu, _("Launch"), launchCallback, NULL);
1065 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
1067 wMenuAddCallback(menu, _("(Un)Hide"), hideCallback, NULL);
1069 wMenuAddCallback(menu, _("Settings..."), settingsCallback, NULL);
1071 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
1073 if (type == WM_CLIP)
1074 scr->clip_menu = menu;
1076 return menu;
1080 WDock*
1081 wDockCreate(WScreen *scr, int type)
1083 WDock *dock;
1084 WAppIcon *btn;
1085 int icon_count;
1087 make_keys();
1089 dock = wmalloc(sizeof(WDock));
1090 memset(dock, 0, sizeof(WDock));
1092 if (type == WM_CLIP)
1093 icon_count = CLIP_MAX_ICONS;
1094 else
1095 icon_count = scr->scr_height/wPreferences.icon_size;
1097 dock->icon_array = wmalloc(sizeof(WAppIcon*)*icon_count);
1098 memset(dock->icon_array, 0, sizeof(WAppIcon*)*icon_count);
1100 dock->max_icons = icon_count;
1102 btn = mainIconCreate(scr, type);
1104 btn->dock = dock;
1106 dock->x_pos = btn->x_pos;
1107 dock->y_pos = btn->y_pos;
1108 dock->screen_ptr = scr;
1109 dock->type = type;
1110 dock->icon_count = 1;
1111 dock->on_right_side = 1;
1112 dock->collapsed = 0;
1113 dock->auto_collapse = 0;
1114 dock->auto_collapse_magic = NULL;
1115 dock->auto_raise_lower = 0;
1116 dock->auto_lower_magic = NULL;
1117 dock->auto_raise_magic = NULL;
1118 dock->attract_icons = 0;
1119 dock->keep_attracted = 0;
1120 dock->lowered = 1;
1121 dock->icon_array[0] = btn;
1122 wRaiseFrame(btn->icon->core);
1123 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
1125 /* create dock menu */
1126 dock->menu = dockMenuCreate(scr, type);
1128 return dock;
1132 void
1133 wDockDestroy(WDock *dock)
1135 int i;
1136 WAppIcon *aicon;
1138 for (i=(dock->type == WM_CLIP) ? 1 : 0; i<dock->max_icons; i++) {
1139 aicon = dock->icon_array[i];
1140 if (aicon) {
1141 int keepit = aicon->running && wApplicationOf(aicon->main_window);
1142 wDockDetach(dock, aicon);
1143 if (keepit) {
1144 PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);
1145 XMoveWindow(dpy, aicon->icon->core->window,
1146 aicon->x_pos, aicon->y_pos);
1147 if (!dock->mapped || dock->collapsed)
1148 XMapWindow(dpy, aicon->icon->core->window);
1152 if (wPreferences.auto_arrange_icons)
1153 wArrangeIcons(dock->screen_ptr, True);
1154 free(dock->icon_array);
1155 if (dock->menu && dock->type!=WM_CLIP)
1156 wMenuDestroy(dock->menu, True);
1157 free(dock);
1161 void
1162 wClipIconPaint(WAppIcon *aicon)
1164 WScreen *scr = aicon->icon->core->screen_ptr;
1165 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
1166 GC gc;
1167 Window win = aicon->icon->core->window;
1168 int length, nlength;
1169 char *ws_name, ws_number[10];
1170 int ty, tx;
1172 wIconPaint(aicon->icon);
1174 length = strlen(workspace->name);
1175 ws_name = malloc(length + 1);
1176 sprintf(ws_name, "%s", workspace->name);
1177 sprintf(ws_number, "%i", scr->current_workspace + 1);
1178 nlength = strlen(ws_number);
1180 gc = scr->clip_title_gc;
1182 if (!workspace->clip->collapsed)
1183 XSetForeground(dpy, gc, scr->clip_title_pixel[CLIP_NORMAL]);
1184 else
1185 XSetForeground(dpy, gc, scr->clip_title_pixel[CLIP_COLLAPSED]);
1187 ty = ICON_SIZE - scr->clip_title_font->height - 3;
1189 tx = CLIP_BUTTON_SIZE*ICON_SIZE/64;
1191 wDrawString(win, scr->clip_title_font, gc, tx,
1192 ty + scr->clip_title_font->y, ws_name, length);
1194 tx = (ICON_SIZE/2 - wTextWidth(scr->clip_title_font->font, ws_number, nlength))/2;
1196 wDrawString(win, scr->clip_title_font, gc, tx,
1197 scr->clip_title_font->y + 2, ws_number, nlength);
1199 free(ws_name);
1201 if (aicon->launching) {
1202 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
1203 0, 0, wPreferences.icon_size, wPreferences.icon_size);
1205 paintClipButtons(aicon, aicon->dock->lclip_button_pushed,
1206 aicon->dock->rclip_button_pushed);
1210 static void
1211 clipIconExpose(WObjDescriptor *desc, XEvent *event)
1213 wClipIconPaint(desc->parent);
1217 static void
1218 dockIconPaint(WAppIcon *btn)
1220 if (btn == btn->icon->core->screen_ptr->clip_icon)
1221 wClipIconPaint(btn);
1222 else
1223 wAppIconPaint(btn);
1227 static proplist_t
1228 make_icon_state(WAppIcon *btn)
1230 proplist_t node = NULL;
1231 proplist_t command, autolaunch, name, forced, host, position, buggy;
1232 char *tmp;
1233 char buffer[64];
1235 if (btn) {
1236 if (!btn->command)
1237 command = PLMakeString("-");
1238 else
1239 command = PLMakeString(btn->command);
1241 autolaunch = btn->auto_launch ? dYes : dNo;
1243 tmp = EscapeWM_CLASS(btn->wm_instance, btn->wm_class);
1245 name = PLMakeString(tmp);
1247 free(tmp);
1249 forced = btn->forced_dock ? dYes : dNo;
1251 buggy = btn->buggy_app ? dYes: dNo;
1253 if (btn == btn->icon->core->screen_ptr->clip_icon)
1254 sprintf(buffer, "%i,%i", btn->x_pos, btn->y_pos);
1255 else
1256 sprintf(buffer, "%hi,%hi", btn->xindex, btn->yindex);
1257 position = PLMakeString(buffer);
1259 node = PLMakeDictionaryFromEntries(dCommand, command,
1260 dName, name,
1261 dAutoLaunch, autolaunch,
1262 dForced, forced,
1263 dBuggyApplication, buggy,
1264 dPosition, position,
1265 NULL);
1266 PLRelease(command);
1267 PLRelease(name);
1268 PLRelease(position);
1269 #ifdef OFFIX_DND
1270 if (btn->dnd_command) {
1271 command = PLMakeString(btn->dnd_command);
1272 PLInsertDictionaryEntry(node, dDropCommand, command);
1273 PLRelease(command);
1275 #endif /* OFFIX_DND */
1277 if (btn->client_machine && btn->remote_start) {
1278 host = PLMakeString(btn->client_machine);
1279 PLInsertDictionaryEntry(node, dHost, host);
1280 PLRelease(host);
1284 return node;
1288 static proplist_t
1289 dockSaveState(WDock *dock)
1291 int i;
1292 proplist_t icon_info;
1293 proplist_t list=NULL, dock_state=NULL;
1294 proplist_t value;
1295 char buffer[256];
1297 list = PLMakeArrayFromElements(NULL);
1299 for (i=(dock->type==WM_DOCK ? 0 : 1); i<dock->max_icons; i++) {
1300 WAppIcon *btn = dock->icon_array[i];
1302 if (!btn || (btn->attracted && !dock->keep_attracted))
1303 continue;
1305 if ((icon_info = make_icon_state(dock->icon_array[i]))) {
1306 list = PLAppendArrayElement(list, icon_info);
1307 PLRelease(icon_info);
1311 dock_state = PLMakeDictionaryFromEntries(dApplications, list, NULL);
1313 PLRelease(list);
1315 if (dock->type == WM_DOCK) {
1316 sprintf(buffer, "%i,%i", (dock->on_right_side ? -ICON_SIZE : 0),
1317 dock->y_pos);
1318 value = PLMakeString(buffer);
1319 PLInsertDictionaryEntry(dock_state, dPosition, value);
1320 PLRelease(value);
1323 value = (dock->lowered ? dYes : dNo);
1324 PLInsertDictionaryEntry(dock_state, dLowered, value);
1326 if (dock->type == WM_CLIP) {
1327 value = (dock->collapsed ? dYes : dNo);
1328 PLInsertDictionaryEntry(dock_state, dCollapsed, value);
1330 value = (dock->auto_collapse ? dYes : dNo);
1331 PLInsertDictionaryEntry(dock_state, dAutoCollapse, value);
1333 value = (dock->auto_raise_lower ? dYes : dNo);
1334 PLInsertDictionaryEntry(dock_state, dAutoRaiseLower, value);
1336 value = (dock->attract_icons ? dYes : dNo);
1337 PLInsertDictionaryEntry(dock_state, dAutoAttractIcons, value);
1339 value = (dock->keep_attracted ? dYes : dNo);
1340 PLInsertDictionaryEntry(dock_state, dKeepAttracted, value);
1343 return dock_state;
1347 void
1348 wDockSaveState(WScreen *scr)
1350 proplist_t dock_state;
1352 dock_state = dockSaveState(scr->dock);
1354 PLInsertDictionaryEntry(scr->session_state, dDock, dock_state);
1356 PLRelease(dock_state);
1360 void
1361 wClipSaveState(WScreen *scr)
1363 proplist_t clip_state;
1365 clip_state = make_icon_state(scr->clip_icon);
1367 PLInsertDictionaryEntry(scr->session_state, dClip, clip_state);
1369 PLRelease(clip_state);
1373 proplist_t
1374 wClipSaveWorkspaceState(WScreen *scr, int workspace)
1376 return dockSaveState(scr->workspaces[workspace]->clip);
1380 static WAppIcon*
1381 restore_icon_state(WScreen *scr, proplist_t info, int type, int index)
1383 WAppIcon *aicon;
1384 char *wclass, *winstance;
1385 proplist_t cmd, value;
1386 char *command;
1389 cmd = PLGetDictionaryEntry(info, dCommand);
1390 if (!cmd || !PLIsString(cmd)) {
1391 return NULL;
1394 /* parse window name */
1395 value = PLGetDictionaryEntry(info, dName);
1396 if (!value)
1397 return NULL;
1399 ParseWindowName(value, &winstance, &wclass, "dock");
1401 if (!winstance && !wclass) {
1402 return NULL;
1405 /* get commands */
1407 if (cmd)
1408 command = wstrdup(PLGetString(cmd));
1409 else
1410 command = NULL;
1412 if (!command || strcmp(command, "-")==0) {
1413 if (command)
1414 free(command);
1415 if (wclass)
1416 free(wclass);
1417 if (winstance)
1418 free(winstance);
1420 return NULL;
1423 aicon = wAppIconCreateForDock(scr, command, winstance, wclass,
1424 TILE_NORMAL);
1425 if (wclass)
1426 free(wclass);
1427 if (winstance)
1428 free(winstance);
1430 aicon->icon->core->descriptor.handle_mousedown = iconMouseDown;
1431 if (type == WM_CLIP) {
1432 aicon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
1433 aicon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
1435 aicon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
1436 aicon->icon->core->descriptor.parent = aicon;
1439 #ifdef OFFIX_DND
1440 cmd = PLGetDictionaryEntry(info, dDropCommand);
1441 if (cmd)
1442 aicon->dnd_command = wstrdup(PLGetString(cmd));
1443 #endif
1445 /* check auto launch */
1446 value = PLGetDictionaryEntry(info, dAutoLaunch);
1448 aicon->auto_launch = 0;
1449 if (value) {
1450 if (PLIsString(value)) {
1451 if (strcasecmp(PLGetString(value), "YES")==0)
1452 aicon->auto_launch = 1;
1453 } else {
1454 wwarning(_("bad value in docked icon state info %s"),
1455 PLGetString(dAutoLaunch));
1459 /* check if it wasn't normally docked */
1460 value = PLGetDictionaryEntry(info, dForced);
1462 aicon->forced_dock = 0;
1463 if (value) {
1464 if (PLIsString(value)) {
1465 if (strcasecmp(PLGetString(value), "YES")==0)
1466 aicon->forced_dock = 1;
1467 } else {
1468 wwarning(_("bad value in docked icon state info %s"),
1469 PLGetString(dForced));
1473 /* check if we can rely on the stuff in the app */
1474 value = PLGetDictionaryEntry(info, dBuggyApplication);
1476 aicon->buggy_app = 0;
1477 if (value) {
1478 if (PLIsString(value)) {
1479 if (strcasecmp(PLGetString(value), "YES")==0)
1480 aicon->buggy_app = 1;
1481 } else {
1482 wwarning(_("bad value in docked icon state info %s"),
1483 PLGetString(dBuggyApplication));
1487 /* get position in the dock */
1488 value = PLGetDictionaryEntry(info, dPosition);
1489 if (value && PLIsString(value)) {
1490 if (sscanf(PLGetString(value), "%hi,%hi", &aicon->xindex,
1491 &aicon->yindex)!=2)
1492 wwarning(_("bad value in docked icon state info %s"),
1493 PLGetString(dPosition));
1495 /* check position sanity */
1496 /* incomplete section! */
1497 if (type == WM_DOCK) {
1498 aicon->xindex = 0;
1499 if (aicon->yindex < 0)
1500 wwarning(_("bad value in docked icon position %i,%i"),
1501 aicon->xindex, aicon->yindex);
1503 } else {
1504 aicon->yindex = index;
1505 aicon->xindex = 0;
1508 aicon->running = 0;
1509 aicon->docked = 1;
1511 return aicon;
1515 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1518 WAppIcon*
1519 wClipRestoreState(WScreen *scr, proplist_t clip_state)
1521 WAppIcon *icon;
1522 proplist_t value;
1525 icon = mainIconCreate(scr, WM_CLIP);
1527 if (!clip_state)
1528 return icon;
1529 else
1530 PLRetain(clip_state);
1532 /* restore position */
1534 value = PLGetDictionaryEntry(clip_state, dPosition);
1536 if (value) {
1537 if (!PLIsString(value))
1538 COMPLAIN("Position");
1539 else {
1540 if (sscanf(PLGetString(value), "%i,%i", &icon->x_pos,
1541 &icon->y_pos)!=2)
1542 COMPLAIN("Position");
1544 /* check position sanity */
1545 if (icon->y_pos < 0)
1546 icon->y_pos = 0;
1547 else if (icon->y_pos > scr->scr_height-ICON_SIZE)
1548 icon->y_pos = scr->scr_height-ICON_SIZE;
1550 if (icon->x_pos < 0)
1551 icon->x_pos = 0;
1552 else if (icon->x_pos > scr->scr_width-ICON_SIZE)
1553 icon->x_pos = scr->scr_width-ICON_SIZE;
1557 #ifdef OFFIX_DND
1558 value = PLGetDictionaryEntry(clip_state, dDropCommand);
1559 if (value && PLIsString(value))
1560 icon->dnd_command = wstrdup(PLGetString(value));
1561 #endif
1563 PLRelease(clip_state);
1565 return icon;
1569 WDock*
1570 wDockRestoreState(WScreen *scr, proplist_t dock_state, int type)
1572 WDock *dock;
1573 proplist_t apps;
1574 proplist_t value;
1575 WAppIcon *aicon, *old_top;
1576 int count, i;
1579 dock = wDockCreate(scr, type);
1581 if (!dock_state)
1582 return dock;
1584 if (dock_state)
1585 PLRetain(dock_state);
1588 /* restore position */
1590 value = PLGetDictionaryEntry(dock_state, dPosition);
1592 if (value) {
1593 if (!PLIsString(value))
1594 COMPLAIN("Position");
1595 else {
1596 if (sscanf(PLGetString(value), "%i,%i", &dock->x_pos,
1597 &dock->y_pos)!=2)
1598 COMPLAIN("Position");
1600 /* check position sanity */
1601 if (dock->y_pos < 0)
1602 dock->y_pos = 0;
1603 else if (dock->y_pos > scr->scr_height-ICON_SIZE)
1604 dock->y_pos = scr->scr_height-ICON_SIZE;
1606 /* This is no more needed. ??? */
1607 if (type == WM_CLIP) {
1608 if (dock->x_pos < 0)
1609 dock->x_pos = 0;
1610 else if (dock->x_pos > scr->scr_width-ICON_SIZE)
1611 dock->x_pos = scr->scr_width-ICON_SIZE;
1613 else {
1614 if (dock->x_pos >= 0) {
1615 dock->x_pos = DOCK_EXTRA_SPACE;
1616 dock->on_right_side = 0;
1617 } else {
1618 dock->x_pos = scr->scr_width - DOCK_EXTRA_SPACE - ICON_SIZE;
1619 dock->on_right_side = 1;
1625 /* restore lowered/raised state */
1627 dock->lowered = 0;
1629 value = PLGetDictionaryEntry(dock_state, dLowered);
1631 if (value) {
1632 if (!PLIsString(value))
1633 COMPLAIN("Lowered");
1634 else {
1635 if (strcasecmp(PLGetString(value), "YES")==0)
1636 dock->lowered = 1;
1641 /* restore collapsed state */
1643 dock->collapsed = 0;
1645 value = PLGetDictionaryEntry(dock_state, dCollapsed);
1647 if (value) {
1648 if (!PLIsString(value))
1649 COMPLAIN("Collapsed");
1650 else {
1651 if (strcasecmp(PLGetString(value), "YES")==0)
1652 dock->collapsed = 1;
1657 /* restore auto-collapsed state */
1659 value = PLGetDictionaryEntry(dock_state, dAutoCollapse);
1661 if (value) {
1662 if (!PLIsString(value))
1663 COMPLAIN("AutoCollapse");
1664 else {
1665 if (strcasecmp(PLGetString(value), "YES")==0) {
1666 dock->auto_collapse = 1;
1667 dock->collapsed = 1;
1673 /* restore auto-raise/lower state */
1675 value = PLGetDictionaryEntry(dock_state, dAutoRaiseLower);
1677 if (value) {
1678 if (!PLIsString(value))
1679 COMPLAIN("AutoRaiseLower");
1680 else {
1681 if (strcasecmp(PLGetString(value), "YES")==0) {
1682 dock->auto_raise_lower = 1;
1688 /* restore attract icons state */
1690 dock->attract_icons = 0;
1692 value = PLGetDictionaryEntry(dock_state, dAutoAttractIcons);
1694 if (value) {
1695 if (!PLIsString(value))
1696 COMPLAIN("AutoAttractIcons");
1697 else {
1698 if (strcasecmp(PLGetString(value), "YES")==0)
1699 dock->attract_icons = 1;
1704 /* restore keep attracted icons state */
1706 dock->keep_attracted = 0;
1708 value = PLGetDictionaryEntry(dock_state, dKeepAttracted);
1710 if (value) {
1711 if (!PLIsString(value))
1712 COMPLAIN("KeepAttracted");
1713 else {
1714 if (strcasecmp(PLGetString(value), "YES")==0)
1715 dock->keep_attracted = 1;
1720 /* application list */
1722 apps = PLGetDictionaryEntry(dock_state, dApplications);
1724 if (!apps) {
1725 goto finish;
1728 count = PLGetNumberOfElements(apps);
1730 if (count==0)
1731 goto finish;
1733 old_top = dock->icon_array[0];
1735 /* dock->icon_count is set to 1 when dock is created.
1736 * Since Clip is already restored, we want to keep it so for clip,
1737 * but for dock we may change the default top tile, so we set it to 0.
1739 if (type == WM_DOCK)
1740 dock->icon_count = 0;
1742 for (i=0; i<count; i++) {
1743 if (dock->icon_count >= dock->max_icons) {
1744 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1745 break;
1748 value = PLGetArrayElement(apps, i);
1749 aicon = restore_icon_state(scr, value, type, dock->icon_count);
1751 dock->icon_array[dock->icon_count] = aicon;
1753 if (aicon) {
1754 aicon->dock = dock;
1755 aicon->x_pos = dock->x_pos + (aicon->xindex*ICON_SIZE);
1756 aicon->y_pos = dock->y_pos + (aicon->yindex*ICON_SIZE);
1758 if (dock->lowered)
1759 ChangeStackingLevel(aicon->icon->core, WMNormalLevel);
1760 else
1761 ChangeStackingLevel(aicon->icon->core, WMDockLevel);
1763 wCoreConfigure(aicon->icon->core, aicon->x_pos, aicon->y_pos,
1764 0, 0);
1766 if (!dock->collapsed)
1767 XMapWindow(dpy, aicon->icon->core->window);
1768 wRaiseFrame(aicon->icon->core);
1770 dock->icon_count++;
1771 } else if (dock->icon_count==0 && type==WM_DOCK)
1772 dock->icon_count++;
1775 /* if the first icon is not defined, use the default */
1776 if (dock->icon_array[0]==NULL) {
1777 /* update default icon */
1778 old_top->x_pos = dock->x_pos;
1779 old_top->y_pos = dock->y_pos;
1780 if (dock->lowered)
1781 ChangeStackingLevel(old_top->icon->core, WMNormalLevel);
1782 else
1783 ChangeStackingLevel(old_top->icon->core, WMDockLevel);
1784 dock->icon_array[0] = old_top;
1785 XMoveWindow(dpy, old_top->icon->core->window, dock->x_pos, dock->y_pos);
1786 /* we don't need to increment dock->icon_count here because it was
1787 * incremented in the loop above.
1789 } else if (old_top!=dock->icon_array[0]) {
1790 if (old_top == scr->clip_icon)
1791 scr->clip_icon = dock->icon_array[0];
1792 wAppIconDestroy(old_top);
1795 finish:
1796 if (dock_state)
1797 PLRelease(dock_state);
1799 return dock;
1804 void
1805 wDockLaunchWithState(WDock *dock, WAppIcon *btn, WSavedState *state)
1807 if (btn && btn->command && !btn->running && !btn->launching) {
1809 btn->drop_launch = 0;
1811 btn->pid = execCommand(btn, btn->command, state);
1813 if (btn->pid>0) {
1814 if (!btn->forced_dock && !btn->buggy_app) {
1815 btn->launching = 1;
1816 dockIconPaint(btn);
1819 } else {
1820 free(state);
1825 void
1826 wDockDoAutoLaunch(WDock *dock, int workspace)
1828 WAppIcon *btn;
1829 WSavedState *state;
1830 int i;
1832 for (i=0; i < dock->max_icons; i++) {
1833 btn = dock->icon_array[i];
1834 if (!btn || !btn->auto_launch)
1835 continue;
1837 state = wmalloc(sizeof(WSavedState));
1838 memset(state, 0, sizeof(WSavedState));
1839 state->workspace = workspace;
1840 /* TODO: this is klugy and is very difficult to understand
1841 * what's going on. Try to clean up */
1842 wDockLaunchWithState(dock, btn, state);
1846 #ifdef REDUCE_APPICONS
1847 void
1848 wDockSimulateLaunch(WDock *dock, WAppIcon *btn)
1850 if ((btn == NULL) || (dock == NULL))
1851 return;
1853 if (!btn->running) {
1854 if ((btn->icon->owner == NULL) && (btn->applist))
1855 btn->icon->owner = btn->applist->wapp->main_window_desc;
1856 if (!btn->forced_dock)
1857 btn->launching = 1;
1858 dockIconPaint(btn);
1859 wusleep(5000);
1862 #endif
1864 #ifdef OFFIX_DND
1865 static WDock*
1866 findDock(WScreen *scr, XEvent *event, int *icon_pos)
1868 WDock *dock;
1869 int i;
1871 *icon_pos = -1;
1872 if ((dock = scr->dock)!=NULL) {
1873 for (i=0; i<dock->max_icons; i++) {
1874 if (dock->icon_array[i]
1875 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1876 *icon_pos = i;
1877 break;
1881 if (*icon_pos<0 && (dock = scr->workspaces[scr->current_workspace]->clip)!=NULL) {
1882 for (i=0; i<dock->max_icons; i++) {
1883 if (dock->icon_array[i]
1884 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1885 *icon_pos = i;
1886 break;
1890 if(*icon_pos>=0)
1891 return dock;
1892 return NULL;
1897 wDockReceiveDNDDrop(WScreen *scr, XEvent *event)
1899 WDock *dock;
1900 WAppIcon *btn;
1901 int icon_pos;
1903 dock = findDock(scr, event, &icon_pos);
1904 if (!dock)
1905 return False;
1908 * Return True if the drop was on an application icon window.
1909 * In this case, let the ClientMessage handler redirect the
1910 * message to the app.
1912 if (dock->icon_array[icon_pos]->icon->icon_win!=None)
1913 return True;
1915 if (dock->icon_array[icon_pos]->dnd_command!=NULL) {
1916 scr->flags.dnd_data_convertion_status = 0;
1918 btn = dock->icon_array[icon_pos];
1920 if (!btn->forced_dock) {
1921 btn->relaunching = btn->running;
1922 btn->running = 1;
1924 if (btn->wm_instance || btn->wm_class) {
1925 WWindowAttributes attr;
1926 memset(&attr, 0, sizeof(WWindowAttributes));
1927 wDefaultFillAttributes(btn->icon->core->screen_ptr,
1928 btn->wm_instance,
1929 btn->wm_class, &attr, NULL, True);
1931 if (!attr.no_appicon)
1932 btn->launching = 1;
1933 else
1934 btn->running = 0;
1937 btn->drop_launch = 1;
1938 scr->last_dock = dock;
1939 btn->pid = execCommand(btn, btn->dnd_command, NULL);
1940 if (btn->pid>0) {
1941 dockIconPaint(btn);
1942 } else {
1943 btn->launching = 0;
1944 if (!btn->relaunching) {
1945 btn->running = 0;
1949 return False;
1951 #endif /* OFFIX_DND */
1955 Bool
1956 wDockAttachIcon(WDock *dock, WAppIcon *icon, int x, int y)
1958 WWindow *wwin;
1959 char **argv;
1960 int argc;
1961 int index;
1963 wwin = icon->icon->owner;
1964 if (icon->command==NULL) {
1965 icon->editing = 0;
1966 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
1968 icon->command = FlattenStringList(argv, argc);
1969 XFreeStringList(argv);
1970 } else {
1971 char *command=NULL;
1973 /* icon->forced_dock = 1;*/
1974 if (!icon->attracted || dock->type!=WM_CLIP || dock->keep_attracted) {
1975 icon->editing = 1;
1976 if (wInputDialog(dock->screen_ptr, _("Dock Icon"),
1977 _("Type the command used to launch the application"),
1978 &command)) {
1979 if (command && (command[0]==0 ||
1980 (command[0]=='-' && command[1]==0))) {
1981 free(command);
1982 command = NULL;
1984 icon->command = command;
1985 icon->editing = 0;
1986 } else {
1987 icon->editing = 0;
1988 if (command)
1989 free(command);
1990 /* If the target is the dock, reject the icon. If
1991 * the target is the clip, make it an attracted icon
1993 if (dock->type==WM_CLIP) {
1994 icon->attracted = 1;
1995 if (!icon->icon->shadowed) {
1996 icon->icon->shadowed = 1;
1997 icon->icon->force_paint = 1;
1999 } else {
2000 return False;
2005 } else {
2006 icon->editing = 0;
2009 for (index=1; index<dock->max_icons; index++)
2010 if (dock->icon_array[index] == NULL)
2011 break;
2012 /* if (index == dock->max_icons)
2013 return; */
2015 assert(index < dock->max_icons);
2017 dock->icon_array[index] = icon;
2018 icon->yindex = y;
2019 icon->xindex = x;
2021 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2022 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2024 dock->icon_count++;
2026 icon->running = 1;
2027 icon->launching = 0;
2028 icon->docked = 1;
2029 icon->dock = dock;
2030 icon->icon->core->descriptor.handle_mousedown = iconMouseDown;
2031 if (dock->type == WM_CLIP) {
2032 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2033 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2035 icon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
2036 icon->icon->core->descriptor.parent = icon;
2038 MoveInStackListUnder(dock->icon_array[index-1]->icon->core,
2039 icon->icon->core);
2040 wAppIconMove(icon, icon->x_pos, icon->y_pos);
2041 wAppIconPaint(icon);
2043 if (wPreferences.auto_arrange_icons)
2044 wArrangeIcons(dock->screen_ptr, True);
2046 #ifdef OFFIX_DND
2047 if (icon->command && !icon->dnd_command) {
2048 icon->dnd_command = wmalloc(strlen(icon->command)+8);
2049 sprintf(icon->dnd_command, "%s %%d", icon->command);
2051 #endif
2053 return True;
2057 void
2058 reattachIcon(WDock *dock, WAppIcon *icon, int x, int y)
2060 int index;
2062 for(index=1; index<dock->max_icons; index++) {
2063 if(dock->icon_array[index] == icon)
2064 break;
2066 assert(index < dock->max_icons);
2068 icon->yindex = y;
2069 icon->xindex = x;
2071 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2072 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2076 Bool
2077 moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y)
2079 WWindow *wwin;
2080 char **argv;
2081 int argc;
2082 int index;
2084 if (dest == NULL)
2085 return False;
2087 wwin = icon->icon->owner;
2090 * For the moment we can't do this if we move icons in Clip from one
2091 * workspace to other, because if we move two or more icons without
2092 * command, the dialog box will not be able to tell us to which of the
2093 * moved icons it applies. -Dan
2095 if ((dest->type==WM_DOCK /*|| dest->keep_attracted*/) && icon->command==NULL) {
2096 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
2098 icon->command = FlattenStringList(argv, argc);
2099 XFreeStringList(argv);
2100 } else {
2101 char *command=NULL;
2103 icon->editing = 1;
2104 /* icon->forced_dock = 1;*/
2105 if (wInputDialog(src->screen_ptr, _("Dock Icon"),
2106 _("Type the command used to launch the application"),
2107 &command)) {
2108 if (command && (command[0]==0 ||
2109 (command[0]=='-' && command[1]==0))) {
2110 free(command);
2111 command = NULL;
2113 icon->command = command;
2114 } else {
2115 icon->editing = 0;
2116 if (command)
2117 free(command);
2118 return False;
2120 icon->editing = 0;
2124 for(index=1; index<src->max_icons; index++) {
2125 if(src->icon_array[index] == icon)
2126 break;
2128 assert(index < src->max_icons);
2130 src->icon_array[index] = NULL;
2131 src->icon_count--;
2133 for(index=1; index<dest->max_icons; index++) {
2134 if(dest->icon_array[index] == NULL)
2135 break;
2137 /* if (index == dest->max_icons)
2138 return; */
2140 assert(index < dest->max_icons);
2142 dest->icon_array[index] = icon;
2143 icon->dock = dest;
2145 /* deselect the icon */
2146 if (icon->icon->selected)
2147 wIconSelect(icon->icon);
2149 if (dest->type == WM_DOCK) {
2150 icon->icon->core->descriptor.handle_enternotify = NULL;
2151 icon->icon->core->descriptor.handle_leavenotify = NULL;
2152 } else {
2153 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2154 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2157 /* set it to be kept when moving to dock, or to a clip that keep the
2158 * attracted icons.
2159 * Unless the icon does not have a command set
2161 if (icon->command && (dest->type==WM_DOCK || dest->keep_attracted)) {
2162 icon->attracted = 0;
2163 if (icon->icon->shadowed) {
2164 icon->icon->shadowed = 0;
2165 icon->icon->force_paint = 1;
2169 if (src->auto_collapse || src->auto_raise_lower)
2170 clipLeave(src);
2172 icon->yindex = y;
2173 icon->xindex = x;
2175 icon->x_pos = dest->x_pos + x*ICON_SIZE;
2176 icon->y_pos = dest->y_pos + y*ICON_SIZE;
2178 dest->icon_count++;
2180 MoveInStackListUnder(dest->icon_array[index-1]->icon->core,
2181 icon->icon->core);
2182 wAppIconPaint(icon);
2184 return True;
2188 void
2189 wDockDetach(WDock *dock, WAppIcon *icon)
2191 int index;
2193 /* make the settings panel be closed */
2194 if (icon->panel) {
2195 DestroyDockAppSettingsPanel(icon->panel);
2198 icon->docked = 0;
2199 icon->dock = NULL;
2200 icon->attracted = 0;
2201 if (icon->icon->shadowed) {
2202 icon->icon->shadowed = 0;
2203 icon->icon->force_paint = 1;
2206 /* deselect the icon */
2207 if (icon->icon->selected)
2208 wIconSelect(icon->icon);
2210 if (icon->command) {
2211 free(icon->command);
2212 icon->command = NULL;
2214 #ifdef OFFIX_DND
2215 if (icon->dnd_command) {
2216 free(icon->dnd_command);
2217 icon->dnd_command = NULL;
2219 #endif
2221 for (index=1; index<dock->max_icons; index++)
2222 if (dock->icon_array[index] == icon)
2223 break;
2224 assert(index < dock->max_icons);
2225 dock->icon_array[index] = NULL;
2226 icon->yindex = -1;
2227 icon->xindex = -1;
2228 dock->icon_count--;
2230 /* if the dock is not attached to an application or
2231 * the the application did not set the approriate hints yet,
2232 * destroy the icon */
2233 #ifdef REDUCE_APPICONS
2234 if ((icon->num_apps == 0) && (!icon->running || !wApplicationOf(icon->main_window)) )
2235 #else
2236 if (!icon->running || !wApplicationOf(icon->main_window))
2237 #endif
2238 wAppIconDestroy(icon);
2239 else {
2240 icon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
2241 icon->icon->core->descriptor.handle_enternotify = NULL;
2242 icon->icon->core->descriptor.handle_leavenotify = NULL;
2243 icon->icon->core->descriptor.parent_type = WCLASS_APPICON;
2244 icon->icon->core->descriptor.parent = icon;
2246 ChangeStackingLevel(icon->icon->core, NORMAL_ICON_LEVEL);
2248 wAppIconPaint(icon);
2249 if (wPreferences.auto_arrange_icons) {
2250 wArrangeIcons(dock->screen_ptr, True);
2253 if (dock->auto_collapse || dock->auto_raise_lower)
2254 clipLeave(dock);
2259 * returns the closest Dock slot index for the passed
2260 * coordinates.
2262 * Returns False if icon can't be docked.
2264 Bool
2265 wDockSnapIcon(WDock *dock, WAppIcon *icon, int req_x, int req_y,
2266 int *ret_x, int *ret_y, int redocking)
2268 WScreen *scr = dock->screen_ptr;
2269 int dx, dy;
2270 int ex_x, ex_y;
2271 int i, offset = ICON_SIZE/2;
2272 WAppIcon *aicon = NULL;
2273 WAppIcon *nicon = NULL;
2276 if (wPreferences.flags.noupdates)
2277 return False;
2279 dx = dock->x_pos;
2280 dy = dock->y_pos;
2282 /* if the dock is full */
2283 if (!redocking &&
2284 (dock->icon_count >= dock->max_icons)) {
2285 return False;
2288 /* exact position */
2289 if (req_y < dy)
2290 ex_y = (req_y - offset - dy)/ICON_SIZE;
2291 else
2292 ex_y = (req_y + offset - dy)/ICON_SIZE;
2294 if (req_x < dx)
2295 ex_x = (req_x - offset - dx)/ICON_SIZE;
2296 else
2297 ex_x = (req_x + offset - dx)/ICON_SIZE;
2299 /* check if the icon is outside the screen boundaries */
2300 if (dx + ex_x*ICON_SIZE < -ICON_SIZE+2 ||
2301 dx + ex_x*ICON_SIZE > scr->scr_width-1 ||
2302 dy + ex_y*ICON_SIZE < -ICON_SIZE+2 ||
2303 dy + ex_y*ICON_SIZE > scr->scr_height-1)
2304 return False;
2306 if (dock->type == WM_DOCK) {
2307 if (icon->dock != dock && ex_x != 0)
2308 return False;
2310 for (i=0; i<dock->max_icons; i++) {
2311 nicon = dock->icon_array[i];
2312 if (nicon && nicon->yindex == ex_y) {
2313 aicon = nicon;
2314 break;
2318 *ret_x = 0;
2320 if (redocking) {
2321 int sig, done, closest;
2323 /* Possible cases when redocking:
2325 * icon dragged out of range of any slot -> false
2326 * icon dragged to range of free slot
2327 * icon dragged to range of same slot
2328 * icon dragged to range of different icon
2330 if (abs(ex_x) > DOCK_DETTACH_THRESHOLD)
2331 return False;
2333 if (ex_y >=0 && (aicon == icon || !aicon)) {
2335 *ret_y = ex_y;
2337 return True;
2340 /* start looking at the upper slot or lower? */
2341 if (ex_y*ICON_SIZE < (req_y + offset - dy))
2342 sig = 1;
2343 else
2344 sig = -1;
2346 closest = -1;
2347 done = 0;
2348 /* look for closest free slot */
2349 for (i=0; i<(DOCK_DETTACH_THRESHOLD+1)*2 && !done; i++) {
2350 int j;
2352 done = 1;
2353 closest = sig*(i/2) + ex_y;
2354 /* check if this slot is used */
2355 if (closest >= 0) {
2356 for (j = 0; j<dock->max_icons; j++) {
2357 if (dock->icon_array[j]
2358 && dock->icon_array[j]->yindex==closest) {
2359 /* slot is used by someone else */
2360 if (dock->icon_array[j]!=icon)
2361 done = 0;
2362 break;
2366 sig = -sig;
2368 if (done && closest >= 0 &&
2369 ((ex_y >= closest && ex_y - closest < DOCK_DETTACH_THRESHOLD+1)
2371 (ex_y < closest && closest - ex_y <= DOCK_DETTACH_THRESHOLD+1))) {
2373 *ret_y = closest;
2375 return True;
2377 } else { /* !redocking */
2379 /* if slot is free and the icon is close enough, return it */
2380 if (!aicon && ex_x==0 && ex_y>=0) {
2381 *ret_y = ex_y;
2382 return True;
2385 } else { /* CLIP */
2386 int neighbours = 0;
2388 for (i=0; i<dock->max_icons; i++) {
2389 nicon = dock->icon_array[i];
2390 if (nicon && nicon->xindex == ex_x && nicon->yindex == ex_y) {
2391 aicon = nicon;
2392 break;
2396 for (i=0; i<dock->max_icons; i++) {
2397 nicon = dock->icon_array[i];
2398 if (nicon && nicon != icon && /* Icon can't be it's own neighbour */
2399 (abs(nicon->xindex - ex_x) <= CLIP_ATTACH_VICINITY &&
2400 abs(nicon->yindex - ex_y) <= CLIP_ATTACH_VICINITY)) {
2401 neighbours = 1;
2402 break;
2406 if (neighbours && (aicon==NULL || (redocking && aicon == icon))) {
2407 *ret_x = ex_x;
2408 *ret_y = ex_y;
2409 return True;
2412 return False;
2415 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2416 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2418 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2419 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2420 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2424 * returns true if it can find a free slot in the dock,
2425 * in which case it changes x_pos and y_pos accordingly.
2426 * Else returns false.
2428 Bool
2429 wDockFindFreeSlot(WDock *dock, int *x_pos, int *y_pos)
2431 WScreen *scr = dock->screen_ptr;
2432 WAppIcon *btn;
2433 unsigned char *slot_map;
2434 int mwidth;
2435 int r;
2436 int x, y;
2437 int i, done = False;
2438 int corner;
2439 int sx=0, sy=0, ex=scr->scr_width, ey=scr->scr_height;
2442 /* if the dock is full */
2443 if (dock->icon_count >= dock->max_icons) {
2444 return False;
2447 if (!wPreferences.flags.nodock && scr->dock) {
2448 if (scr->dock->on_right_side)
2449 ex -= ICON_SIZE + DOCK_EXTRA_SPACE;
2450 else
2451 sx += ICON_SIZE + DOCK_EXTRA_SPACE;
2454 if (ex < dock->x_pos)
2455 ex = dock->x_pos;
2456 if (sx > dock->x_pos+ICON_SIZE)
2457 sx = dock->x_pos+ICON_SIZE;
2458 #define C_NONE 0
2459 #define C_NW 1
2460 #define C_NE 2
2461 #define C_SW 3
2462 #define C_SE 4
2464 /* check if clip is in a corner */
2465 if (dock->type==WM_CLIP) {
2466 if (dock->x_pos < 1 && dock->y_pos < 1)
2467 corner = C_NE;
2468 else if (dock->x_pos < 1 && dock->y_pos >= (ey-ICON_SIZE))
2469 corner = C_SE;
2470 else if (dock->x_pos >= (ex-ICON_SIZE)&& dock->y_pos >= (ey-ICON_SIZE))
2471 corner = C_SW;
2472 else if (dock->x_pos >= (ex-ICON_SIZE) && dock->y_pos < 1)
2473 corner = C_NW;
2474 else
2475 corner = C_NONE;
2476 } else
2477 corner = C_NONE;
2479 /* If the clip is in the corner, use only slots that are in the border
2480 * of the screen */
2481 if (corner!=C_NONE) {
2482 char *hmap, *vmap;
2483 int hcount, vcount;
2485 hcount = MIN(dock->max_icons, scr->scr_width/ICON_SIZE);
2486 vcount = MIN(dock->max_icons, scr->scr_height/ICON_SIZE);
2487 hmap = wmalloc(hcount+1);
2488 memset(hmap, 0, hcount+1);
2489 vmap = wmalloc(vcount+1);
2490 memset(vmap, 0, vcount+1);
2492 /* mark used positions */
2493 switch (corner) {
2494 case C_NE:
2495 for (i=0; i<dock->max_icons; i++) {
2496 btn = dock->icon_array[i];
2497 if (!btn)
2498 continue;
2500 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2501 vmap[btn->yindex] = 1;
2502 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2503 hmap[btn->xindex] = 1;
2505 case C_NW:
2506 for (i=0; i<dock->max_icons; i++) {
2507 btn = dock->icon_array[i];
2508 if (!btn)
2509 continue;
2511 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2512 vmap[btn->yindex] = 1;
2513 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2514 hmap[-btn->xindex] = 1;
2516 case C_SE:
2517 for (i=0; i<dock->max_icons; i++) {
2518 btn = dock->icon_array[i];
2519 if (!btn)
2520 continue;
2522 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2523 vmap[-btn->yindex] = 1;
2524 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2525 hmap[btn->xindex] = 1;
2527 case C_SW:
2528 default:
2529 for (i=0; i<dock->max_icons; i++) {
2530 btn = dock->icon_array[i];
2531 if (!btn)
2532 continue;
2534 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2535 vmap[-btn->yindex] = 1;
2536 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2537 hmap[-btn->xindex] = 1;
2540 x=0; y=0;
2541 done = 0;
2542 /* search a vacant slot */
2543 for (i=1; i<MAX(vcount, hcount); i++) {
2544 if (i < vcount && vmap[i]==0) {
2545 /* found a slot */
2546 x = 0;
2547 y = i;
2548 done = 1;
2549 break;
2550 } else if (i < hcount && hmap[i]==0) {
2551 /* found a slot */
2552 x = i;
2553 y = 0;
2554 done = 1;
2555 break;
2558 free(vmap);
2559 free(hmap);
2560 /* If found a slot, translate and return */
2561 if (done) {
2562 if (corner==C_NW || corner==C_NE) {
2563 *y_pos = y;
2564 } else {
2565 *y_pos = -y;
2567 if (corner==C_NE || corner==C_SE) {
2568 *x_pos = x;
2569 } else {
2570 *x_pos = -x;
2572 return True;
2574 /* else, try to find a slot somewhere else */
2577 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2578 * placed outside of screen */
2579 mwidth = (int)ceil(sqrt(dock->max_icons));
2581 /* In the worst case (the clip is in the corner of the screen),
2582 * the amount of icons that fit in the clip is smaller.
2583 * Double the map to get a safe value.
2585 mwidth += mwidth;
2587 r = (mwidth-1)/2;
2589 slot_map = wmalloc(mwidth*mwidth);
2590 memset(slot_map, 0, mwidth*mwidth);
2592 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2594 /* mark used slots in the map. If the slot falls outside the map
2595 * (for example, when all icons are placed in line), ignore them. */
2596 for (i=0; i<dock->max_icons; i++) {
2597 btn = dock->icon_array[i];
2598 if (btn)
2599 slot_map[XY2OFS(btn->xindex, btn->yindex)] = 1;
2601 /* Find closest slot from the center that is free by scanning the
2602 * map from the center to outward in circular passes.
2603 * This will not result in a neat layout, but will be optimal
2604 * in the sense that there will not be holes left.
2606 done = 0;
2607 for (i = 1; i <= r && !done; i++) {
2608 int tx, ty;
2610 /* top and bottom parts of the ring */
2611 for (x = -i; x <= i && !done; x++) {
2612 tx = dock->x_pos + x*ICON_SIZE;
2613 y = -i;
2614 ty = dock->y_pos + y*ICON_SIZE;
2615 if (slot_map[XY2OFS(x,y)]==0
2616 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2617 *x_pos = x;
2618 *y_pos = y;
2619 done = 1;
2620 break;
2622 y = i;
2623 ty = dock->y_pos + y*ICON_SIZE;
2624 if (slot_map[XY2OFS(x,y)]==0
2625 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2626 *x_pos = x;
2627 *y_pos = y;
2628 done = 1;
2629 break;
2632 /* left and right parts of the ring */
2633 for (y = -i+1; y <= i-1; y++) {
2634 ty = dock->y_pos + y*ICON_SIZE;
2635 x = -i;
2636 tx = dock->x_pos + x*ICON_SIZE;
2637 if (slot_map[XY2OFS(x,y)]==0
2638 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2639 *x_pos = x;
2640 *y_pos = y;
2641 done = 1;
2642 break;
2644 x = i;
2645 tx = dock->x_pos + x*ICON_SIZE;
2646 if (slot_map[XY2OFS(x,y)]==0
2647 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2648 *x_pos = x;
2649 *y_pos = y;
2650 done = 1;
2651 break;
2655 free(slot_map);
2656 #undef XY2OFS
2657 return done;
2661 static void
2662 moveDock(WDock *dock, int new_x, int new_y)
2664 WAppIcon *btn;
2665 int i;
2667 dock->x_pos = new_x;
2668 dock->y_pos = new_y;
2669 for (i=0; i<dock->max_icons; i++) {
2670 btn = dock->icon_array[i];
2671 if (btn) {
2672 btn->x_pos = new_x + btn->xindex*ICON_SIZE;
2673 btn->y_pos = new_y + btn->yindex*ICON_SIZE;
2674 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2680 static void
2681 swapDock(WDock *dock)
2683 WScreen *scr = dock->screen_ptr;
2684 WAppIcon *btn;
2685 int x, i;
2688 if (dock->on_right_side) {
2689 x = dock->x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
2690 } else {
2691 x = dock->x_pos = DOCK_EXTRA_SPACE;
2694 for (i=0; i<dock->max_icons; i++) {
2695 btn = dock->icon_array[i];
2696 if (btn) {
2697 btn->x_pos = x;
2698 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2702 wScreenUpdateUsableArea(scr);
2706 static pid_t
2707 execCommand(WAppIcon *btn, char *command, WSavedState *state)
2709 WScreen *scr = btn->icon->core->screen_ptr;
2710 pid_t pid;
2711 char **argv;
2712 int argc;
2713 char *cmdline;
2715 cmdline = ExpandOptions(scr, command);
2717 if (scr->flags.dnd_data_convertion_status || !cmdline) {
2718 if (cmdline)
2719 free(cmdline);
2720 if (state)
2721 free(state);
2722 return 0;
2725 ParseCommand(cmdline, &argv, &argc);
2727 if (argv==NULL) {
2728 if (cmdline)
2729 free(cmdline);
2730 if (state)
2731 free(state);
2732 return 0;
2735 if ((pid=fork())==0) {
2736 char **args;
2737 int i;
2739 SetupEnvironment(scr);
2741 #ifdef HAVE_SETPGID
2742 setpgid(0, 0);
2743 #endif
2745 args = malloc(sizeof(char*)*(argc+1));
2746 if (!args)
2747 exit(111);
2748 for (i=0; i<argc; i++) {
2749 args[i] = argv[i];
2751 args[argc] = NULL;
2752 execvp(argv[0], args);
2753 exit(111);
2755 while (argc > 0)
2756 free(argv[--argc]);
2757 free(argv);
2759 if (pid > 0) {
2760 if (!state) {
2761 state = wmalloc(sizeof(WSavedState));
2762 memset(state, 0, sizeof(WSavedState));
2763 state->hidden = -1;
2764 state->miniaturized = -1;
2765 state->shaded = -1;
2766 if (btn->dock == scr->dock)
2767 state->workspace = -1;
2768 else
2769 state->workspace = scr->current_workspace;
2771 wWindowAddSavedState(btn->wm_instance, btn->wm_class, cmdline, pid,
2772 state);
2773 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess,
2774 btn->dock);
2775 } else if (state) {
2776 free(state);
2778 free(cmdline);
2779 return pid;
2783 void
2784 wDockHideIcons(WDock *dock)
2786 int i;
2787 WAppIcon *btn;
2789 if (dock==NULL)
2790 return;
2792 btn = dock->icon_array[0];
2794 for (i=1; i<dock->max_icons; i++) {
2795 if (dock->icon_array[i])
2796 XUnmapWindow(dpy, dock->icon_array[i]->icon->core->window);
2798 dock->mapped = 0;
2800 dockIconPaint(btn);
2804 void
2805 wDockShowIcons(WDock *dock)
2807 int i, newlevel;
2808 WAppIcon *btn;
2810 if (dock==NULL)
2811 return;
2813 btn = dock->icon_array[0];
2814 moveDock(dock, btn->x_pos, btn->y_pos);
2816 newlevel = dock->lowered ? WMNormalLevel : WMDockLevel;
2817 ChangeStackingLevel(btn->icon->core, newlevel);
2819 for (i=1; i<dock->max_icons; i++) {
2820 if (dock->icon_array[i]) {
2821 MoveInStackListAbove(dock->icon_array[i]->icon->core,
2822 btn->icon->core);
2823 break;
2827 if (!dock->collapsed) {
2828 for (i=1; i<dock->max_icons; i++) {
2829 if (dock->icon_array[i]) {
2830 XMapWindow(dpy, dock->icon_array[i]->icon->core->window);
2834 dock->mapped = 1;
2836 dockIconPaint(btn);
2840 void
2841 wDockLower(WDock *dock)
2843 int i;
2845 for (i=0; i<dock->max_icons; i++) {
2846 if (dock->icon_array[i])
2847 wLowerFrame(dock->icon_array[i]->icon->core);
2852 void
2853 wDockRaise(WDock *dock)
2855 int i;
2857 for (i=dock->max_icons-1; i>=0; i--) {
2858 if (dock->icon_array[i])
2859 wRaiseFrame(dock->icon_array[i]->icon->core);
2864 void
2865 wDockRaiseLower(WDock *dock)
2867 if (!dock->icon_array[0]->icon->core->stacking->above
2868 ||(dock->icon_array[0]->icon->core->stacking->window_level
2869 !=dock->icon_array[0]->icon->core->stacking->above->stacking->window_level))
2870 wDockLower(dock);
2871 else
2872 wDockRaise(dock);
2876 void
2877 wDockFinishLaunch(WDock *dock, WAppIcon *icon)
2879 icon->launching = 0;
2880 icon->relaunching = 0;
2881 dockIconPaint(icon);
2885 WAppIcon*
2886 wDockFindIconFor(WDock *dock, Window window)
2888 WAppIcon *icon;
2889 int i;
2891 for (i=0; i<dock->max_icons; i++) {
2892 icon = dock->icon_array[i];
2893 if (icon && icon->main_window == window)
2894 return icon;
2896 return NULL;
2900 void
2901 wDockTrackWindowLaunch(WDock *dock, Window window)
2903 WAppIcon *icon;
2904 #ifdef REDUCE_APPICONS
2905 WAppIconAppList *tapplist;
2906 #endif
2907 char *wm_class, *wm_instance;
2908 int i;
2909 Bool firstPass = True;
2910 Bool found = False;
2911 char *command = NULL;
2914 int argc;
2915 char **argv;
2917 if (XGetCommand(dpy, window, &argv, &argc)) {
2918 if (argc > 0 && argv != NULL)
2919 command = FlattenStringList(argv,argc);
2920 if (argv) {
2921 XFreeStringList(argv);
2926 if (!PropGetWMClass(window, &wm_class, &wm_instance) ||
2927 (!wm_class && !wm_instance))
2928 return;
2930 retry:
2931 for (i=0; i<dock->max_icons; i++) {
2932 icon = dock->icon_array[i];
2933 if (!icon)
2934 continue;
2936 /* app is already attached to icon */
2937 if (icon->main_window == window) {
2938 found = True;
2939 break;
2942 if ((icon->wm_instance || icon->wm_class)
2943 && (icon->launching
2944 || (dock->screen_ptr->flags.startup && !icon->running))) {
2946 if (icon->wm_instance && wm_instance &&
2947 strcmp(icon->wm_instance, wm_instance)!=0) {
2948 continue;
2950 if (icon->wm_class && wm_class &&
2951 strcmp(icon->wm_class, wm_class)!=0) {
2952 continue;
2954 if (firstPass && command && strcmp(icon->command, command)!=0) {
2955 continue;
2958 if (!icon->relaunching) {
2959 WApplication *wapp;
2961 /* Possibly an application that was docked with dockit,
2962 * but the user did not update WMState to indicate that
2963 * it was docked by force */
2964 wapp = wApplicationOf(window);
2965 if (!wapp) {
2966 icon->forced_dock = 1;
2967 icon->running = 0;
2969 if (!icon->forced_dock)
2970 icon->main_window = window;
2972 #ifdef REDUCE_APPICONS
2973 tapplist = wmalloc(sizeof(WAppIconAppList));
2974 memset(tapplist, 0, sizeof(WAppIconAppList));
2975 tapplist->next = icon->applist;
2976 if (icon->applist)
2977 icon->applist->prev = tapplist;
2978 icon->applist = tapplist;
2979 tapplist->wapp = wApplicationOf(window);
2980 icon->num_apps++;
2981 #endif
2983 found = True;
2984 wDockFinishLaunch(dock, icon);
2985 break;
2989 if (firstPass && !found) {
2990 firstPass = False;
2991 goto retry;
2994 if (command)
2995 free(command);
2997 if (wm_class)
2998 XFree(wm_class);
2999 if (wm_instance)
3000 XFree(wm_instance);
3005 void
3006 wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
3008 if (!wPreferences.flags.noclip) {
3009 scr->clip_icon->dock = scr->workspaces[workspace]->clip;
3010 if (scr->current_workspace != workspace) {
3011 WDock *old_clip = scr->workspaces[scr->current_workspace]->clip;
3013 wDockHideIcons(old_clip);
3014 if (old_clip->auto_raise_lower)
3015 wDockLower(old_clip);
3016 if (old_clip->auto_collapse && !old_clip->collapsed)
3017 old_clip->collapsed = 1;
3018 wDockShowIcons(scr->workspaces[workspace]->clip);
3020 if (scr->flags.clip_balloon_mapped)
3021 showClipBalloon(scr->clip_icon->dock, workspace);
3027 static void
3028 trackDeadProcess(pid_t pid, unsigned char status, WDock *dock)
3030 WAppIcon *icon;
3031 int i;
3033 for (i=0; i<dock->max_icons; i++) {
3034 icon = dock->icon_array[i];
3035 if (!icon)
3036 continue;
3038 if (icon->launching && icon->pid == pid) {
3039 if (!icon->relaunching) {
3040 icon->running = 0;
3041 icon->main_window = None;
3043 wDockFinishLaunch(dock, icon);
3044 icon->pid = 0;
3045 if (status==111) {
3046 char msg[PATH_MAX];
3047 #ifdef OFFIX_DND
3048 sprintf(msg, _("Could not execute command \"%s\""),
3049 icon->drop_launch && icon->dnd_command
3050 ? icon->dnd_command : icon->command);
3051 #else
3052 sprintf(msg, _("Could not execute command \"%s\""),
3053 icon->command);
3054 #endif
3055 wMessageDialog(dock->screen_ptr, _("Error"), msg,
3056 _("OK"), NULL, NULL);
3058 break;
3064 static void
3065 toggleLowered(WDock *dock)
3067 WAppIcon *tmp;
3068 int newlevel, i;
3070 /* lower/raise Dock */
3071 if (!dock->lowered) {
3072 newlevel = WMNormalLevel;
3073 dock->lowered = 1;
3074 } else {
3075 newlevel = WMDockLevel;
3076 dock->lowered = 0;
3079 for (i=0; i<dock->max_icons; i++) {
3080 tmp = dock->icon_array[i];
3081 if (!tmp)
3082 continue;
3084 ChangeStackingLevel(tmp->icon->core, newlevel);
3085 if (dock->lowered)
3086 wLowerFrame(tmp->icon->core);
3089 if (dock->type == WM_DOCK)
3090 wScreenUpdateUsableArea(dock->screen_ptr);
3094 static void
3095 toggleCollapsed(WDock *dock)
3097 if (dock->collapsed) {
3098 dock->collapsed = 0;
3099 wDockShowIcons(dock);
3101 else {
3102 dock->collapsed = 1;
3103 wDockHideIcons(dock);
3108 static void
3109 openDockMenu(WDock *dock, WAppIcon *aicon, XEvent *event)
3111 WScreen *scr = dock->screen_ptr;
3112 WObjDescriptor *desc;
3113 WMenuEntry *entry;
3114 int index = 0;
3115 int x_pos;
3116 int appIsRunning = aicon->running && aicon->icon && aicon->icon->owner;
3118 if (dock->type == WM_DOCK) {
3119 /* keep on top */
3120 entry = dock->menu->entries[index];
3121 entry->flags.indicator_on = !dock->lowered;
3122 entry->clientdata = dock;
3123 } else {
3124 /* clip options */
3125 if (scr->clip_options)
3126 updateClipOptionsMenu(scr->clip_options, dock);
3128 /* Rename Workspace */
3129 entry = dock->menu->entries[++index];
3130 entry->clientdata = dock;
3132 /* select icon */
3133 entry = dock->menu->entries[++index];
3134 entry->clientdata = aicon;
3135 wMenuSetEnabled(dock->menu, index, aicon!=scr->clip_icon);
3137 /* (un)select all icons */
3138 entry = dock->menu->entries[++index];
3139 entry->clientdata = aicon;
3140 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3142 /* keep icon(s) */
3143 entry = dock->menu->entries[++index];
3144 entry->clientdata = aicon;
3145 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3147 /* this is the workspace submenu part */
3148 if (scr->clip_submenu)
3149 updateWorkspaceMenu(scr->clip_submenu, aicon);
3150 index++;
3152 /* remove icon(s) */
3153 entry = dock->menu->entries[++index];
3154 entry->clientdata = aicon;
3155 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3157 /* attract icon(s) */
3158 entry = dock->menu->entries[++index];
3159 entry->clientdata = aicon;
3162 /* launch */
3163 entry = dock->menu->entries[++index];
3164 entry->clientdata = aicon;
3165 wMenuSetEnabled(dock->menu, index, aicon->command!=NULL);
3167 /* unhide here */
3168 entry = dock->menu->entries[++index];
3169 entry->clientdata = aicon;
3170 wMenuSetEnabled(dock->menu, index, appIsRunning);
3172 /* hide */
3173 entry = dock->menu->entries[++index];
3174 entry->clientdata = aicon;
3175 wMenuSetEnabled(dock->menu, index, appIsRunning);
3177 /* settings */
3178 entry = dock->menu->entries[++index];
3179 entry->clientdata = aicon;
3180 wMenuSetEnabled(dock->menu, index, !aicon->editing
3181 && !wPreferences.flags.noupdates);
3183 /* kill */
3184 entry = dock->menu->entries[++index];
3185 entry->clientdata = aicon;
3186 wMenuSetEnabled(dock->menu, index, appIsRunning);
3188 if (!dock->menu->flags.realized)
3189 wMenuRealize(dock->menu);
3191 if (dock->type == WM_CLIP) {
3192 x_pos = event->xbutton.x_root+2;
3193 } else {
3194 x_pos = dock->on_right_side ?
3195 scr->scr_width - dock->menu->frame->core->width - 2 : 0;
3198 wMenuMapAt(dock->menu, x_pos, event->xbutton.y_root+2, False);
3200 /* allow drag select */
3201 event->xany.send_event = True;
3202 desc = &dock->menu->menu->descriptor;
3203 (*desc->handle_mousedown)(desc, event);
3207 static void
3208 openClipWorkspaceMenu(WScreen *scr, int x, int y)
3210 if (!scr->clip_ws_menu) {
3211 scr->clip_ws_menu = wWorkspaceMenuMake(scr, False);
3213 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
3214 wMenuMapAt(scr->clip_ws_menu, x, y, False);
3218 /******************************************************************/
3219 static void
3220 iconDblClick(WObjDescriptor *desc, XEvent *event)
3222 WAppIcon *btn = desc->parent;
3223 WDock *dock = btn->dock;
3224 WApplication *wapp = NULL;
3225 int unhideHere = 0;
3227 #ifdef REDUCE_APPICONS
3228 if ((btn->icon->owner && !(event->xbutton.state & ControlMask)) ||
3229 ((btn->icon->owner == NULL) && (btn->applist != NULL))) {
3230 if (btn->icon->owner == NULL)
3231 btn->icon->owner = btn->applist->wapp->main_window_desc;
3232 #ifdef I_HATE_THIS
3234 #endif
3235 #else
3236 if (btn->icon->owner && !(event->xbutton.state & ControlMask)) {
3237 #endif
3238 wapp = wApplicationOf(btn->icon->owner->main_window);
3240 assert(wapp!=NULL);
3242 unhideHere = (event->xbutton.state & ShiftMask);
3244 /* go to the last workspace that the user worked on the app */
3245 if (!unhideHere) {
3246 wWorkspaceChange(dock->screen_ptr, wapp->last_workspace);
3249 wUnhideApplication(wapp, event->xbutton.button==Button2,
3250 unhideHere);
3252 if (event->xbutton.state & MOD_MASK) {
3253 wHideOtherApplications(btn->icon->owner);
3255 } else {
3256 if (event->xbutton.button==Button1) {
3258 if (event->xbutton.state & MOD_MASK) {
3259 /* raise/lower dock */
3260 toggleLowered(dock);
3261 } else if (btn == dock->screen_ptr->clip_icon) {
3262 if (getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE)
3263 toggleCollapsed(dock);
3264 else
3265 handleClipChangeWorkspace(dock->screen_ptr, event);
3266 } else if (btn->command) {
3267 if (!btn->launching &&
3268 (!btn->running || (event->xbutton.state & ControlMask))) {
3269 launchDockedApplication(btn);
3277 static void
3278 handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3280 WScreen *scr = dock->screen_ptr;
3281 int ofs_x=event->xbutton.x, ofs_y=event->xbutton.y;
3282 int x, y;
3283 XEvent ev;
3284 int grabbed = 0, swapped = 0, done;
3285 Pixmap ghost = None;
3286 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3288 #ifdef DEBUG
3289 puts("moving dock");
3290 #endif
3291 if (XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
3292 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3293 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3294 wwarning("pointer grab failed for dock move");
3296 y = 0;
3297 for (x=0; x<dock->max_icons; x++) {
3298 if (dock->icon_array[x]!=NULL &&
3299 dock->icon_array[x]->yindex > y)
3300 y = dock->icon_array[x]->yindex;
3302 y++;
3303 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE*y);
3305 done = 0;
3306 while (!done) {
3307 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3308 |ButtonMotionMask|ExposureMask, &ev);
3309 switch (ev.type) {
3310 case Expose:
3311 WMHandleEvent(&ev);
3312 break;
3314 case MotionNotify:
3315 if (!grabbed) {
3316 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3317 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3318 XChangeActivePointerGrab(dpy, ButtonMotionMask
3319 |ButtonReleaseMask|ButtonPressMask,
3320 wCursor[WCUR_MOVE], CurrentTime);
3321 grabbed=1;
3323 break;
3325 if (dock->type == WM_CLIP) {
3326 if (ev.xmotion.x_root - ofs_x < 0) {
3327 x = 0;
3328 } else if (ev.xmotion.x_root - ofs_x + ICON_SIZE >
3329 scr->scr_width) {
3330 x = scr->scr_width - ICON_SIZE;
3331 } else {
3332 x = ev.xmotion.x_root - ofs_x;
3334 if (ev.xmotion.y_root - ofs_y < 0) {
3335 y = 0;
3336 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3337 scr->scr_height) {
3338 y = scr->scr_height - ICON_SIZE;
3339 } else {
3340 y = ev.xmotion.y_root - ofs_y;
3342 moveDock(dock, x, y);
3344 else {
3345 /* move vertically if pointer is inside the dock*/
3346 if ((dock->on_right_side &&
3347 ev.xmotion.x_root >= dock->x_pos - ICON_SIZE)
3348 || (!dock->on_right_side &&
3349 ev.xmotion.x_root <= dock->x_pos + ICON_SIZE*2)) {
3351 if (ev.xmotion.y_root - ofs_y < 0) {
3352 y = 0;
3353 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3354 scr->scr_height) {
3355 y = scr->scr_height - ICON_SIZE;
3356 } else {
3357 y = ev.xmotion.y_root - ofs_y;
3359 moveDock(dock, dock->x_pos, y);
3361 /* move horizontally to change sides */
3362 x = ev.xmotion.x_root - ofs_x;
3363 if (!dock->on_right_side) {
3365 /* is on left */
3367 if (ev.xmotion.x_root > dock->x_pos + ICON_SIZE*2) {
3368 XMoveWindow(dpy, scr->dock_shadow, scr->scr_width-ICON_SIZE
3369 -DOCK_EXTRA_SPACE, dock->y_pos);
3370 if (superfluous) {
3371 if (ghost==None) {
3372 ghost = MakeGhostDock(dock, dock->x_pos,
3373 scr->scr_width-ICON_SIZE
3374 -DOCK_EXTRA_SPACE,
3375 dock->y_pos);
3376 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3377 ghost);
3378 XClearWindow(dpy, scr->dock_shadow);
3381 XMapRaised(dpy, scr->dock_shadow);
3382 swapped = 1;
3383 } else {
3384 if (superfluous && ghost!=None) {
3385 XFreePixmap(dpy, ghost);
3386 ghost = None;
3388 XUnmapWindow(dpy, scr->dock_shadow);
3389 swapped = 0;
3391 } else {
3392 /* is on right */
3393 if (ev.xmotion.x_root < dock->x_pos - ICON_SIZE) {
3394 XMoveWindow(dpy, scr->dock_shadow,
3395 DOCK_EXTRA_SPACE, dock->y_pos);
3396 if (superfluous) {
3397 if (ghost==None) {
3398 ghost = MakeGhostDock(dock, dock->x_pos,
3399 DOCK_EXTRA_SPACE, dock->y_pos);
3400 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3401 ghost);
3402 XClearWindow(dpy, scr->dock_shadow);
3405 XMapRaised(dpy, scr->dock_shadow);
3406 swapped = -1;
3407 } else {
3408 XUnmapWindow(dpy, scr->dock_shadow);
3409 swapped = 0;
3410 if (superfluous && ghost!=None) {
3411 XFreePixmap(dpy, ghost);
3412 ghost = None;
3417 break;
3419 case ButtonPress:
3420 break;
3422 case ButtonRelease:
3423 if (ev.xbutton.button != event->xbutton.button)
3424 break;
3425 XUngrabPointer(dpy, CurrentTime);
3426 XUnmapWindow(dpy, scr->dock_shadow);
3427 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE);
3428 if (dock->type == WM_DOCK) {
3429 if (swapped!=0) {
3430 if (swapped>0)
3431 dock->on_right_side = 1;
3432 else
3433 dock->on_right_side = 0;
3434 swapDock(dock);
3435 wArrangeIcons(scr, False);
3438 done = 1;
3439 break;
3442 if (superfluous) {
3443 if (ghost!=None)
3444 XFreePixmap(dpy, ghost);
3445 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3447 #ifdef DEBUG
3448 puts("End dock move");
3449 #endif
3454 static void
3455 handleIconMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3457 WScreen *scr = dock->screen_ptr;
3458 Window wins[2];
3459 WIcon *icon = aicon->icon;
3460 WDock *dock2 = NULL, *last_dock = dock, *clip = NULL;
3461 int ondock, grabbed = 0, change_dock = 0, collapsed = 0;
3462 XEvent ev;
3463 int x = aicon->x_pos, y = aicon->y_pos;
3464 int ofs_x = event->xbutton.x, ofs_y = event->xbutton.y;
3465 int shad_x = x, shad_y = y;
3466 int ix = aicon->xindex, iy = aicon->yindex;
3467 int tmp;
3468 Pixmap ghost = None;
3469 Bool docked;
3470 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3472 if (wPreferences.flags.noupdates)
3473 return;
3475 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
3476 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3477 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3478 #ifdef DEBUG0
3479 wwarning("pointer grab failed for icon move");
3480 #endif
3483 wRaiseFrame(icon->core);
3485 if (!wPreferences.flags.noclip)
3486 clip = scr->workspaces[scr->current_workspace]->clip;
3488 if (dock == scr->dock && !wPreferences.flags.noclip)
3489 dock2 = clip;
3490 else if (dock != scr->dock && !wPreferences.flags.nodock)
3491 dock2 = scr->dock;
3493 wins[0] = icon->core->window;
3494 wins[1] = scr->dock_shadow;
3495 XRestackWindows(dpy, wins, 2);
3496 XMoveResizeWindow(dpy, scr->dock_shadow, aicon->x_pos, aicon->y_pos,
3497 ICON_SIZE, ICON_SIZE);
3498 if (superfluous) {
3499 if (icon->pixmap!=None)
3500 ghost = MakeGhostIcon(scr, icon->pixmap);
3501 else
3502 ghost = MakeGhostIcon(scr, icon->core->window);
3504 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow, ghost);
3505 XClearWindow(dpy, scr->dock_shadow);
3507 XMapWindow(dpy, scr->dock_shadow);
3509 ondock = 1;
3512 while(1) {
3513 XMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3514 |ButtonMotionMask|ExposureMask, &ev);
3515 switch (ev.type) {
3516 case Expose:
3517 WMHandleEvent(&ev);
3518 break;
3520 case MotionNotify:
3521 if (!grabbed) {
3522 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3523 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3524 XChangeActivePointerGrab(dpy, ButtonMotionMask
3525 |ButtonReleaseMask|ButtonPressMask,
3526 wCursor[WCUR_MOVE], CurrentTime);
3527 grabbed=1;
3528 } else {
3529 break;
3533 x = ev.xmotion.x_root - ofs_x;
3534 y = ev.xmotion.y_root - ofs_y;
3535 tmp = wDockSnapIcon(dock, aicon, x, y, &ix, &iy, True);
3536 if (tmp && dock2) {
3537 change_dock = 0;
3538 if (last_dock != dock && collapsed) {
3539 last_dock->collapsed = 1;
3540 wDockHideIcons(last_dock);
3541 collapsed = 0;
3543 if (!collapsed && (collapsed = dock->collapsed)) {
3544 dock->collapsed = 0;
3545 wDockShowIcons(dock);
3547 if (dock->auto_raise_lower)
3548 wDockRaise(dock);
3549 last_dock = dock;
3551 else if (dock2) {
3552 tmp = wDockSnapIcon(dock2, aicon, x, y, &ix, &iy, False);
3553 if (tmp) {
3554 change_dock = 1;
3555 if (last_dock != dock2 && collapsed) {
3556 last_dock->collapsed = 1;
3557 wDockHideIcons(last_dock);
3558 collapsed = 0;
3560 if (!collapsed && (collapsed = dock2->collapsed)) {
3561 dock2->collapsed = 0;
3562 wDockShowIcons(dock2);
3564 if (dock2->auto_raise_lower)
3565 wDockRaise(dock2);
3566 last_dock = dock2;
3569 if (aicon->launching
3570 || (aicon->running && !(ev.xmotion.state & MOD_MASK))
3571 || (!aicon->running && tmp)) {
3572 shad_x = last_dock->x_pos + ix*wPreferences.icon_size;
3573 shad_y = last_dock->y_pos + iy*wPreferences.icon_size;
3575 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
3577 if (!ondock) {
3578 XMapWindow(dpy, scr->dock_shadow);
3579 #if 0
3580 if (!collapsed && (collapsed = last_dock->collapsed)) {
3581 last_dock->collapsed = 0;
3582 wDockShowIcons(last_dock);
3584 #endif
3586 ondock = 1;
3587 } else {
3588 if (ondock) {
3589 XUnmapWindow(dpy, scr->dock_shadow);
3590 #if 0
3591 if (last_dock && collapsed &&
3592 aicon->running && (ev.xmotion.state & MOD_MASK)) {
3593 last_dock->collapsed = 1;
3594 wDockHideIcons(last_dock);
3595 collapsed = 0;
3597 #endif
3599 ondock = 0;
3601 XMoveWindow(dpy, icon->core->window, x, y);
3602 break;
3604 case ButtonPress:
3605 break;
3607 case ButtonRelease:
3608 if (ev.xbutton.button != event->xbutton.button)
3609 break;
3610 XUngrabPointer(dpy, CurrentTime);
3611 if (ondock) {
3612 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
3613 XUnmapWindow(dpy, scr->dock_shadow);
3614 if (!change_dock) {
3615 reattachIcon(dock, aicon, ix, iy);
3616 if (clip && dock!=clip && clip->auto_raise_lower)
3617 wDockLower(clip);
3618 } else {
3619 docked = moveIconBetweenDocks(dock, dock2, aicon, ix, iy);
3620 if (!docked) {
3621 /* Slide it back if dock rejected it */
3622 SlideWindow(icon->core->window, x, y, aicon->x_pos,
3623 aicon->y_pos);
3624 reattachIcon(dock, aicon, aicon->xindex,aicon->yindex);
3626 if (last_dock->type==WM_CLIP && last_dock->auto_collapse) {
3627 collapsed = 0;
3630 } else {
3631 aicon->x_pos = x;
3632 aicon->y_pos = y;
3633 if (superfluous) {
3634 if (!aicon->running && !wPreferences.no_animations) {
3635 /* We need to deselect it, even if is deselected in
3636 * wDockDetach(), because else DoKaboom() will fail.
3638 if (aicon->icon->selected)
3639 wIconSelect(aicon->icon);
3640 DoKaboom(scr,aicon->icon->core->window, x, y);
3643 if (clip && clip->auto_raise_lower)
3644 wDockLower(clip);
3645 wDockDetach(dock, aicon);
3647 if (collapsed) {
3648 last_dock->collapsed = 1;
3649 wDockHideIcons(last_dock);
3650 collapsed = 0;
3652 if (superfluous) {
3653 if (ghost!=None)
3654 XFreePixmap(dpy, ghost);
3655 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3657 #ifdef DEBUG
3658 puts("End icon move");
3659 #endif
3660 return;
3666 static int
3667 getClipButton(int px, int py)
3669 int pt = (CLIP_BUTTON_SIZE+2)*ICON_SIZE/64;
3671 if (px < 0 || py < 0 || px >= ICON_SIZE || py >= ICON_SIZE)
3672 return CLIP_IDLE;
3674 if (py <= pt-((int)ICON_SIZE-1-px))
3675 return CLIP_FORWARD;
3676 else if (px <= pt-((int)ICON_SIZE-1-py))
3677 return CLIP_REWIND;
3679 return CLIP_IDLE;
3683 static void
3684 handleClipChangeWorkspace(WScreen *scr, XEvent *event)
3686 XEvent ev;
3687 int done, direction, new_ws;
3688 int new_dir;
3689 WDock *clip = scr->clip_icon->dock;
3691 direction = getClipButton(event->xbutton.x, event->xbutton.y);
3693 clip->lclip_button_pushed = direction==CLIP_REWIND;
3694 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3696 wClipIconPaint(scr->clip_icon);
3697 done = 0;
3698 while(!done) {
3699 WMMaskEvent(dpy, ExposureMask|ButtonMotionMask|ButtonReleaseMask
3700 |ButtonPressMask, &ev);
3701 switch (ev.type) {
3702 case Expose:
3703 WMHandleEvent(&ev);
3704 break;
3706 case MotionNotify:
3707 new_dir = getClipButton(ev.xmotion.x, ev.xmotion.y);
3708 if (new_dir != direction) {
3709 direction = new_dir;
3710 clip->lclip_button_pushed = direction==CLIP_REWIND;
3711 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3712 wClipIconPaint(scr->clip_icon);
3714 break;
3716 case ButtonPress:
3717 break;
3719 case ButtonRelease:
3720 if (ev.xbutton.button == event->xbutton.button)
3721 done = 1;
3725 clip->lclip_button_pushed = 0;
3726 clip->rclip_button_pushed = 0;
3728 new_ws = wPreferences.ws_advance || (event->xbutton.state & ControlMask);
3730 if (direction == CLIP_FORWARD) {
3731 if (scr->current_workspace < scr->workspace_count-1)
3732 wWorkspaceChange(scr, scr->current_workspace+1);
3733 else if (new_ws && scr->current_workspace < MAX_WORKSPACES-1)
3734 wWorkspaceChange(scr, scr->current_workspace+1);
3735 else if (wPreferences.ws_cycle)
3736 wWorkspaceChange(scr, 0);
3738 else if (direction == CLIP_REWIND) {
3739 if (scr->current_workspace > 0)
3740 wWorkspaceChange(scr, scr->current_workspace-1);
3741 else if (scr->current_workspace==0 && wPreferences.ws_cycle)
3742 wWorkspaceChange(scr, scr->workspace_count-1);
3745 wClipIconPaint(scr->clip_icon);
3749 static void
3750 iconMouseDown(WObjDescriptor *desc, XEvent *event)
3752 WAppIcon *aicon = desc->parent;
3753 WDock *dock = aicon->dock;
3754 WScreen *scr = aicon->icon->core->screen_ptr;
3756 if (aicon->editing)
3757 return;
3759 scr->last_dock = dock;
3761 if (dock->menu->flags.mapped)
3762 wMenuUnmap(dock->menu);
3764 if (IsDoubleClick(scr, event)) {
3765 /* double-click was not in the main clip icon */
3766 if (dock->type != WM_CLIP || aicon->xindex!=0 || aicon->yindex!=0
3767 || getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE) {
3768 iconDblClick(desc, event);
3769 return;
3773 if (dock->type == WM_CLIP && scr->flags.clip_balloon_mapped) {
3774 XUnmapWindow(dpy, scr->clip_balloon);
3775 scr->flags.clip_balloon_mapped = 0;
3778 #ifdef DEBUG
3779 puts("handling dock");
3780 #endif
3781 if (event->xbutton.button == Button1) {
3782 if (event->xbutton.state & MOD_MASK)
3783 wDockLower(dock);
3784 else
3785 wDockRaise(dock);
3787 if ((event->xbutton.state & ShiftMask) && aicon!=scr->clip_icon &&
3788 dock->type!=WM_DOCK) {
3789 wIconSelect(aicon->icon);
3790 return;
3793 if (aicon->yindex==0 && aicon->xindex==0) {
3794 if (getClipButton(event->xbutton.x, event->xbutton.y)!=CLIP_IDLE
3795 && dock->type==WM_CLIP)
3796 handleClipChangeWorkspace(scr, event);
3797 else
3798 handleDockMove(dock, aicon, event);
3799 } else
3800 handleIconMove(dock, aicon, event);
3802 } else if (event->xbutton.button==Button2 && dock->type==WM_CLIP &&
3803 aicon->xindex==0 && aicon->yindex==0) {
3804 openClipWorkspaceMenu(scr, event->xbutton.x_root+2,
3805 event->xbutton.y_root+2);
3806 if (scr->clip_ws_menu) {
3807 WMenu *menu;
3808 menu = scr->clip_ws_menu;
3809 desc = &menu->menu->descriptor;
3811 event->xany.send_event = True;
3812 (*desc->handle_mousedown)(desc, event);
3814 } else if (event->xbutton.button == Button3) {
3815 openDockMenu(dock, aicon, event);
3820 static void
3821 showClipBalloon(WDock *dock, int workspace)
3823 int w, h;
3824 int x, y;
3825 WScreen *scr = dock->screen_ptr;
3826 char *text;
3827 Window stack[2];
3829 scr->flags.clip_balloon_mapped = 1;
3830 XMapWindow(dpy, scr->clip_balloon);
3832 text = scr->workspaces[workspace]->name;
3834 w = wTextWidth(scr->clip_title_font->font, text, strlen(text));
3836 h = scr->clip_title_font->height;
3837 XResizeWindow(dpy, scr->clip_balloon, w, h);
3839 x = dock->x_pos + CLIP_BUTTON_SIZE*ICON_SIZE/64;
3840 y = dock->y_pos + ICON_SIZE-scr->clip_title_font->height - 3;
3842 if (x+w > scr->scr_width) {
3843 x = scr->scr_width - w;
3844 if (dock->y_pos + ICON_SIZE + h > scr->scr_height)
3845 y = dock->y_pos - h - 1;
3846 else
3847 y = dock->y_pos + ICON_SIZE;
3848 XRaiseWindow(dpy, scr->clip_balloon);
3849 } else {
3850 stack[0] = scr->clip_icon->icon->core->window;
3851 stack[1] = scr->clip_balloon;
3852 XRestackWindows(dpy, stack, 2);
3854 XMoveWindow(dpy, scr->clip_balloon, x, y);
3855 XSetForeground(dpy, scr->clip_title_gc,
3856 scr->clip_title_pixel[CLIP_NORMAL]);
3857 XClearWindow(dpy, scr->clip_balloon);
3858 wDrawString(scr->clip_balloon, scr->clip_title_font, scr->clip_title_gc,
3859 0, scr->clip_title_font->y, text, strlen(text));
3863 static void
3864 clipEnterNotify(WObjDescriptor *desc, XEvent *event)
3866 WAppIcon *btn = (WAppIcon*)desc->parent;
3867 WDock *dock;
3869 assert(event->type==EnterNotify);
3871 if(desc->parent_type!=WCLASS_DOCK_ICON)
3872 return;
3874 dock = btn->dock;
3875 if (!dock || dock->type!=WM_CLIP)
3876 return;
3878 if (dock->auto_lower_magic) {
3879 WMDeleteTimerHandler(dock->auto_lower_magic);
3880 dock->auto_lower_magic = NULL;
3882 if (dock->auto_raise_lower) {
3883 dock->auto_raise_magic = WMAddTimerHandler(AUTO_RAISE_DELAY,
3884 clipAutoRaise,
3885 (void *)dock);
3888 if (btn->xindex == 0 && btn->yindex == 0)
3889 showClipBalloon(dock, dock->screen_ptr->current_workspace);
3890 else {
3891 if (dock->screen_ptr->flags.clip_balloon_mapped) {
3892 XUnmapWindow(dpy, dock->screen_ptr->clip_balloon);
3893 dock->screen_ptr->flags.clip_balloon_mapped = 0;
3896 if (dock->auto_collapse) {
3897 if (dock->auto_collapse_magic) {
3898 WMDeleteTimerHandler(dock->auto_collapse_magic);
3899 dock->auto_collapse_magic = NULL;
3902 if (dock->collapsed)
3903 toggleCollapsed(dock);
3908 static void
3909 clipLeave(WDock *dock)
3911 if (!dock || dock->type!=WM_CLIP)
3912 return;
3914 if (dock->auto_raise_magic) {
3915 WMDeleteTimerHandler(dock->auto_raise_magic);
3916 dock->auto_raise_magic = NULL;
3918 if (dock->auto_raise_lower) {
3919 dock->auto_lower_magic = WMAddTimerHandler(AUTO_LOWER_DELAY,
3920 clipAutoLower,
3921 (void *)dock);
3924 if (dock->auto_collapse) {
3925 if (dock->auto_collapse_magic) {
3926 WMDeleteTimerHandler(dock->auto_collapse_magic);
3927 dock->auto_collapse_magic = NULL;
3929 if (!dock->collapsed) {
3930 dock->auto_collapse_magic = WMAddTimerHandler(AUTO_COLLAPSE_DELAY,
3931 clipAutoCollapse,
3932 (void *)dock);
3938 static void
3939 clipLeaveNotify(WObjDescriptor *desc, XEvent *event)
3941 WAppIcon *btn = (WAppIcon*)desc->parent;
3943 assert(event->type==LeaveNotify);
3945 if(desc->parent_type!=WCLASS_DOCK_ICON)
3946 return;
3948 clipLeave(btn->dock);
3952 static void
3953 clipAutoCollapse(void *cdata)
3955 WDock *dock = (WDock *)cdata;
3957 if (dock->type!=WM_CLIP || !dock->auto_collapse)
3958 return;
3960 if (!dock->collapsed && dock->auto_collapse_magic!=NULL) {
3961 toggleCollapsed(dock);
3963 dock->auto_collapse_magic = NULL;
3967 static void
3968 clipAutoLower(void *cdata)
3970 WDock *dock = (WDock *)cdata;
3972 if (dock->type!=WM_CLIP)
3973 return;
3975 if (dock->auto_raise_lower)
3976 wDockLower(dock);
3978 dock->auto_lower_magic = NULL;
3982 static void
3983 clipAutoRaise(void *cdata)
3985 WDock *dock = (WDock *)cdata;
3987 if (dock->type!=WM_CLIP)
3988 return;
3990 if (dock->auto_raise_lower)
3991 wDockRaise(dock);
3993 dock->auto_raise_magic = NULL;