Fixed Clip's autoraise/lower behavior regarding attched icons with their own
[wmaker-crm.git] / src / dock.c
blob42a9c4847824b2796a686d168f2d7182fe753b9b
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);
83 extern XContext wWinContext;
85 extern Cursor wCursor[WCUR_LAST];
87 extern WPreferences wPreferences;
89 extern XContext wWinContext;
91 #ifdef OFFIX_DND
92 extern Atom _XA_DND_PROTOCOL;
93 #endif
96 #define MOD_MASK wPreferences.modifier_mask
98 extern void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
100 #define ICON_SIZE wPreferences.icon_size
103 /***** Local variables ****/
105 static proplist_t dCommand=NULL;
106 #ifdef OFFIX_DND
107 static proplist_t dDropCommand=NULL;
108 #endif
109 static proplist_t dAutoLaunch, dName, dForced, dBuggyApplication, dYes, dNo;
110 static proplist_t dHost, dDock, dClip;
111 static proplist_t dAutoAttractIcons, dKeepAttracted;
113 static proplist_t dPosition, dApplications, dLowered, dCollapsed, dAutoCollapse;
115 static proplist_t dAutoRaiseLower;
117 static void dockIconPaint(WAppIcon *btn);
119 static void iconMouseDown(WObjDescriptor *desc, XEvent *event);
121 static pid_t execCommand(WAppIcon *btn, char *command, WSavedState *state);
123 static void trackDeadProcess(pid_t pid, unsigned char status, WDock *dock);
125 static int getClipButton(int px, int py);
127 static void toggleLowered(WDock *dock);
129 static void toggleCollapsed(WDock *dock);
131 static void clipIconExpose(WObjDescriptor *desc, XEvent *event);
133 static void clipLeave(WDock *dock);
135 static void handleClipChangeWorkspace(WScreen *scr, XEvent *event);
137 Bool moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y);
139 static void clipEnterNotify(WObjDescriptor *desc, XEvent *event);
140 static void clipLeaveNotify(WObjDescriptor *desc, XEvent *event);
141 static void clipAutoCollapse(void *cdata);
142 static void launchDockedApplication(WAppIcon *btn);
144 static void clipAutoLower(void *cdata);
145 static void clipAutoRaise(void *cdata);
147 static void showClipBalloon(WDock *dock, int workspace);
149 #ifdef OFFIX_DND
151 #define DndNotDnd -1
152 #define DndUnknown 0
153 #define DndRawData 1
154 #define DndFile 2
155 #define DndFiles 3
156 #define DndText 4
157 #define DndDir 5
158 #define DndLink 6
159 #define DndExe 7
161 #define DndEND 8
163 #endif /* OFFIX_DND */
167 static void
168 make_keys()
170 if (dCommand!=NULL)
171 return;
173 dCommand = PLRetain(PLMakeString("Command"));
174 #ifdef OFFIX_DND
175 dDropCommand = PLRetain(PLMakeString("DropCommand"));
176 #endif
177 dAutoLaunch = PLRetain(PLMakeString("AutoLaunch"));
178 dName = PLRetain(PLMakeString("Name"));
179 dForced = PLRetain(PLMakeString("Forced"));
180 dBuggyApplication = PLRetain(PLMakeString("BuggyApplication"));
181 dYes = PLRetain(PLMakeString("Yes"));
182 dNo = PLRetain(PLMakeString("No"));
183 dHost = PLRetain(PLMakeString("Host"));
185 dPosition = PLMakeString("Position");
186 dApplications = PLMakeString("Applications");
187 dLowered = PLMakeString("Lowered");
188 dCollapsed = PLMakeString("Collapsed");
189 dAutoCollapse = PLMakeString("AutoCollapse");
190 dAutoRaiseLower = PLMakeString("AutoRaiseLower");
191 dAutoAttractIcons = PLMakeString("AutoAttractIcons");
192 dKeepAttracted = PLMakeString("KeepAttracted");
194 dDock = PLMakeString("Dock");
195 dClip = PLMakeString("Clip");
200 static void
201 renameCallback(WMenu *menu, WMenuEntry *entry)
203 WDock *dock = entry->clientdata;
204 char buffer[128];
205 int wspace;
206 char *name;
208 assert(entry->clientdata!=NULL);
210 wspace = dock->screen_ptr->current_workspace;
212 name = wstrdup(dock->screen_ptr->workspaces[wspace]->name);
214 sprintf(buffer, _("Type the name for workspace %i:"), wspace+1);
215 if (wInputDialog(dock->screen_ptr, _("Rename Workspace"), buffer,
216 &name)) {
217 wWorkspaceRename(dock->screen_ptr, wspace, name);
219 if (name) {
220 free(name);
225 static void
226 toggleLoweredCallback(WMenu *menu, WMenuEntry *entry)
228 assert(entry->clientdata!=NULL);
230 toggleLowered(entry->clientdata);
232 entry->flags.indicator_on = !((WDock*)entry->clientdata)->lowered;
234 wMenuPaint(menu);
239 static void
240 killCallback(WMenu *menu, WMenuEntry *entry)
242 WAppIcon *icon;
243 #ifdef REDUCE_APPICONS
244 WAppIconAppList *tapplist;
246 extern Atom _XA_WM_DELETE_WINDOW;
247 #else
248 char *buffer;
249 #endif
251 if (!WCHECK_STATE(WSTATE_NORMAL))
252 return;
254 assert(entry->clientdata!=NULL);
256 icon = (WAppIcon*)entry->clientdata;
258 icon->editing = 1;
260 WCHANGE_STATE(WSTATE_MODAL);
262 #ifdef REDUCE_APPICONS
263 /* Send a delete message to the main window of each application
264 * bound to this docked appicon. - cls
266 tapplist = icon->applist;
267 while (tapplist != NULL) {
268 if (tapplist->wapp->main_window_desc != NULL) {
269 if (tapplist->wapp->main_window_desc->protocols.DELETE_WINDOW) {
270 wClientSendProtocol(tapplist->wapp->main_window_desc,
271 _XA_WM_DELETE_WINDOW, CurrentTime);
272 } else {
273 wClientKill(tapplist->wapp->main_window_desc);
276 tapplist = tapplist->next;
278 #else
279 buffer = wstrappend(icon->wm_class,
280 _(" will be forcibly closed.\n"
281 "Any unsaved changes will be lost.\n"
282 "Please confirm."));
284 if (wPreferences.dont_confirm_kill
285 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
286 buffer, _("Yes"), _("No"), NULL)==WAPRDefault) {
287 if (icon->icon && icon->icon->owner) {
288 wClientKill(icon->icon->owner);
291 #endif /* !REDUCE_APPICONS */
293 icon->editing = 0;
295 WCHANGE_STATE(WSTATE_NORMAL);}
298 static LinkedList*
299 getSelected(WDock *dock)
301 LinkedList *ret=NULL;
302 WAppIcon *btn;
303 int i;
305 for (i=1; i<dock->max_icons; i++) {
306 btn = dock->icon_array[i];
307 if (btn && btn->icon->selected) {
308 ret = list_cons(btn, ret);
312 return ret;
316 static void
317 paintClipButtons(WAppIcon *clipIcon, Bool lpushed, Bool rpushed)
319 Window win = clipIcon->icon->core->window;
320 WScreen *scr = clipIcon->icon->core->screen_ptr;
321 XPoint p[4];
322 int pt = CLIP_BUTTON_SIZE*ICON_SIZE/64;
323 int tp = ICON_SIZE - pt;
324 int as = pt - 15; /* 15 = 5+5+5 */
327 if (rpushed) {
328 p[0].x = tp+1;
329 p[0].y = 1;
330 p[1].x = ICON_SIZE-2;
331 p[1].y = 1;
332 p[2].x = ICON_SIZE-2;
333 p[2].y = pt-1;
334 } else if (lpushed) {
335 p[0].x = 1;
336 p[0].y = tp;
337 p[1].x = pt;
338 p[1].y = ICON_SIZE-2;
339 p[2].x = 1;
340 p[2].y = ICON_SIZE-2;
342 if (lpushed || rpushed) {
343 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
344 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
345 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
348 p[0].x = p[3].x = ICON_SIZE-6-as;
349 p[0].y = p[3].y = 5;
350 p[1].x = ICON_SIZE-6;
351 p[1].y = 5;
352 p[2].x = ICON_SIZE-6;
353 p[2].y = 5+as;
354 if (rpushed) {
355 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
356 XDrawLines(dpy, win, scr->draw_gc, p, 4, CoordModeOrigin);
357 } else {
358 XFillPolygon(dpy, win, scr->clip_title_gc, p,3,Convex,CoordModeOrigin);
359 XDrawLines(dpy, win, scr->clip_title_gc, p,4,CoordModeOrigin);
362 p[0].x = p[3].x = 5;
363 p[0].y = p[3].y = ICON_SIZE-6-as;
364 p[1].x = 5;
365 p[1].y = ICON_SIZE-6;
366 p[2].x = 5+as;
367 p[2].y = ICON_SIZE-6;
368 if (lpushed) {
369 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
370 XDrawLines(dpy, win, scr->draw_gc, p, 4, CoordModeOrigin);
371 } else {
372 XFillPolygon(dpy, win, scr->clip_title_gc, p,3,Convex,CoordModeOrigin);
373 XDrawLines(dpy, win, scr->clip_title_gc, p,4,CoordModeOrigin);
378 RImage*
379 wClipMakeTile(WScreen *scr, RImage *normalTile)
381 RImage *tile = RCloneImage(normalTile);
382 RColor black;
383 RColor dark;
384 RColor light;
385 int pt, tp;
387 pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
388 tp = wPreferences.icon_size-1 - pt;
390 black.alpha = 255;
391 black.red = black.green = black.blue = 0;
393 dark.alpha = 0;
394 dark.red = dark.green = dark.blue = 80;
396 light.alpha = 0;
397 light.red = light.green = light.blue = 80;
400 /* top right */
401 ROperateLine(tile, RSubtractOperation, tp, 0, wPreferences.icon_size-2,
402 pt-1, &dark);
403 RDrawLine(tile, tp-1, 0, wPreferences.icon_size-1, pt+1, &black);
404 ROperateLine(tile, RAddOperation, tp, 2, wPreferences.icon_size-3,
405 pt, &light);
408 /* bottom left */
409 ROperateLine(tile, RAddOperation, 2, tp+2, pt-2,
410 wPreferences.icon_size-3, &dark);
411 RDrawLine(tile, 0, tp-1, pt+1, wPreferences.icon_size-1, &black);
412 ROperateLine(tile, RSubtractOperation, 0, tp-2, pt+1,
413 wPreferences.icon_size-2, &light);
415 return tile;
419 static void
420 removeIconsCallback(WMenu *menu, WMenuEntry *entry)
422 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
423 WDock *dock;
424 WAppIcon *aicon;
425 LinkedList *selectedIcons;
426 int keepit;
428 assert(clickedIcon!=NULL);
430 dock = clickedIcon->dock;
432 selectedIcons = getSelected(dock);
434 if (selectedIcons) {
435 if (wMessageDialog(dock->screen_ptr, _("Workspace Clip"),
436 _("All selected icons will be removed!"),
437 _("OK"), _("Cancel"), NULL)!=WAPRDefault) {
438 return;
440 } else {
441 if (clickedIcon->xindex==0 && clickedIcon->yindex==0)
442 return;
443 selectedIcons = list_cons(clickedIcon, NULL);
446 while (selectedIcons) {
447 aicon = selectedIcons->head;
448 keepit = aicon->running && wApplicationOf(aicon->main_window);
449 wDockDetach(dock, aicon);
450 if (keepit) {
451 PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);
452 XMoveWindow(dpy, aicon->icon->core->window,
453 aicon->x_pos, aicon->y_pos);
454 if (!dock->mapped || dock->collapsed)
455 XMapWindow(dpy, aicon->icon->core->window);
457 list_remove_head(&selectedIcons);
460 if (wPreferences.auto_arrange_icons)
461 wArrangeIcons(dock->screen_ptr, True);
465 static void
466 keepIconsCallback(WMenu *menu, WMenuEntry *entry)
468 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
469 WDock *dock;
470 WAppIcon *aicon;
471 LinkedList *selectedIcons;
473 assert(clickedIcon!=NULL);
474 dock = clickedIcon->dock;
476 selectedIcons = getSelected(dock);
478 if (!selectedIcons && clickedIcon!=dock->screen_ptr->clip_icon) {
479 char *command = NULL;
481 if (!clickedIcon->command && !clickedIcon->editing) {
482 clickedIcon->editing = 1;
483 if (wInputDialog(dock->screen_ptr, _("Keep Icon"),
484 _("Type the command used to launch the application"),
485 &command)) {
486 if (command && (command[0]==0 ||
487 (command[0]=='-' && command[1]==0))) {
488 free(command);
489 command = NULL;
491 clickedIcon->command = command;
492 clickedIcon->editing = 0;
493 } else {
494 clickedIcon->editing = 0;
495 if (command)
496 free(command);
497 return;
501 selectedIcons = list_cons(clickedIcon, NULL);
504 while (selectedIcons) {
505 aicon = selectedIcons->head;
506 if (aicon->icon->selected)
507 wIconSelect(aicon->icon);
508 if (aicon && aicon->attracted && aicon->command) {
509 aicon->attracted = 0;
510 if (aicon->icon->shadowed) {
511 aicon->icon->shadowed = 0;
512 aicon->icon->force_paint = 1;
513 wAppIconPaint(aicon);
516 list_remove_head(&selectedIcons);
523 static void
524 toggleAutoAttractCallback(WMenu *menu, WMenuEntry *entry)
526 WDock *dock = (WDock*)entry->clientdata;
528 assert(entry->clientdata!=NULL);
530 dock->attract_icons = !dock->attract_icons;
531 /*if (!dock->attract_icons)
532 dock->keep_attracted = 0;*/
534 entry->flags.indicator_on = dock->attract_icons;
536 wMenuPaint(menu);
540 static void
541 toggleKeepCallback(WMenu *menu, WMenuEntry *entry)
543 WDock *dock = (WDock*)entry->clientdata;
544 WAppIcon *btn;
545 int i;
547 assert(entry->clientdata!=NULL);
549 dock->keep_attracted = !dock->keep_attracted;
551 if (dock->keep_attracted) {
552 for (i=0; i< dock->max_icons; i++) {
553 btn = dock->icon_array[i];
554 if (btn && btn->attracted && btn->command) {
555 btn->attracted = 0;
556 if (btn->icon->shadowed) {
557 btn->icon->shadowed = 0;
558 btn->icon->force_paint = 1;
559 wAppIconPaint(btn);
565 entry->flags.indicator_on = dock->keep_attracted;
567 wMenuPaint(menu);
571 static void
572 selectCallback(WMenu *menu, WMenuEntry *entry)
574 WAppIcon *icon = (WAppIcon*)entry->clientdata;
576 assert(icon!=NULL);
578 wIconSelect(icon->icon);
580 wMenuPaint(menu);
584 static void
585 colectIconsCallback(WMenu *menu, WMenuEntry *entry)
587 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
588 WDock *clip;
589 WAppIcon *aicon;
590 int x, y, x_pos, y_pos;
592 assert(entry->clientdata!=NULL);
593 clip = clickedIcon->dock;
595 aicon = clip->screen_ptr->app_icon_list;
597 while (aicon) {
598 if (!aicon->docked && wDockFindFreeSlot(clip, &x, &y)) {
599 x_pos = clip->x_pos + x*ICON_SIZE;
600 y_pos = clip->y_pos + y*ICON_SIZE;
601 if (aicon->x_pos != x_pos || aicon->y_pos != y_pos) {
602 #ifdef ANIMATIONS
603 if (wPreferences.no_animations) {
604 XMoveWindow(dpy, aicon->icon->core->window, x_pos, y_pos);
605 } else {
606 SlideWindow(aicon->icon->core->window,
607 aicon->x_pos, aicon->y_pos, x_pos, y_pos);
609 #else
610 XMoveWindow(dpy, aicon->icon->core->window, x_pos, y_pos);
611 #endif /* ANIMATIONS */
613 aicon->attracted = 1;
614 if (!clip->keep_attracted && !aicon->icon->shadowed) {
615 aicon->icon->shadowed = 1;
616 aicon->icon->force_paint = 1;
617 /* We don't do an wAppIconPaint() here because it's in
618 * wDockAttachIcon(). -Dan
621 wDockAttachIcon(clip, aicon, x, y);
622 if (clip->collapsed || !clip->mapped)
623 XUnmapWindow(dpy, aicon->icon->core->window);
625 aicon = aicon->next;
630 static void
631 selectIconsCallback(WMenu *menu, WMenuEntry *entry)
633 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
634 WDock *dock;
635 LinkedList *selectedIcons;
636 WAppIcon *btn;
637 int i;
639 assert(clickedIcon!=NULL);
640 dock = clickedIcon->dock;
642 selectedIcons = getSelected(dock);
644 if (!selectedIcons) {
645 for (i=1; i<dock->max_icons; i++) {
646 btn = dock->icon_array[i];
647 if (btn && !btn->icon->selected) {
648 wIconSelect(btn->icon);
651 } else {
652 while(selectedIcons) {
653 btn = selectedIcons->head;
654 wIconSelect(btn->icon);
655 list_remove_head(&selectedIcons);
659 wMenuPaint(menu);
663 static void
664 toggleCollapsedCallback(WMenu *menu, WMenuEntry *entry)
666 assert(entry->clientdata!=NULL);
668 toggleCollapsed(entry->clientdata);
670 entry->flags.indicator_on = ((WDock*)entry->clientdata)->collapsed;
672 wMenuPaint(menu);
676 static void
677 toggleAutoCollapseCallback(WMenu *menu, WMenuEntry *entry)
679 WDock *dock;
680 assert(entry->clientdata!=NULL);
682 dock = (WDock*) entry->clientdata;
684 dock->auto_collapse = !dock->auto_collapse;
685 if (dock->auto_collapse_magic) {
686 WMDeleteTimerHandler(dock->auto_collapse_magic);
687 dock->auto_collapse_magic = NULL;
690 entry->flags.indicator_on = ((WDock*)entry->clientdata)->auto_collapse;
692 wMenuPaint(menu);
696 static void
697 toggleAutoRaiseLowerCallback(WMenu *menu, WMenuEntry *entry)
699 WDock *dock;
700 assert(entry->clientdata!=NULL);
702 dock = (WDock*) entry->clientdata;
704 dock->auto_raise_lower = !dock->auto_raise_lower;
706 entry->flags.indicator_on = ((WDock*)entry->clientdata)->auto_raise_lower;
708 wMenuPaint(menu);
712 static void
713 launchCallback(WMenu *menu, WMenuEntry *entry)
715 WAppIcon *btn = (WAppIcon*)entry->clientdata;
717 launchDockedApplication(btn);
721 static void
722 settingsCallback(WMenu *menu, WMenuEntry *entry)
724 WAppIcon *btn = (WAppIcon*)entry->clientdata;
726 if (btn->editing)
727 return;
728 ShowDockAppSettingsPanel(btn);
732 static void
733 hideCallback(WMenu *menu, WMenuEntry *entry)
735 WApplication *wapp;
736 WAppIcon *btn = (WAppIcon*)entry->clientdata;
738 wapp = wApplicationOf(btn->icon->owner->main_window);
740 if (wapp->flags.hidden) {
741 wWorkspaceChange(btn->icon->core->screen_ptr,wapp->last_workspace);
742 wUnhideApplication(wapp, False, False);
743 } else {
744 wHideApplication(wapp);
749 static void
750 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
752 WApplication *wapp;
753 WAppIcon *btn = (WAppIcon*)entry->clientdata;
755 wapp = wApplicationOf(btn->icon->owner->main_window);
757 wUnhideApplication(wapp, False, True);
761 WAppIcon*
762 mainIconCreate(WScreen *scr, int type)
764 WAppIcon *btn;
765 int x_pos;
767 if (type == WM_CLIP) {
768 if (scr->clip_icon)
769 return scr->clip_icon;
770 btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMClip", TILE_CLIP);
771 btn->icon->core->descriptor.handle_expose = clipIconExpose;
772 btn->icon->core->descriptor.handle_enternotify = clipEnterNotify;
773 btn->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
774 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
775 x_pos = 0;
776 } else {
777 btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMDock", TILE_NORMAL);
778 x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
781 btn->xindex = 0;
782 btn->yindex = 0;
784 btn->icon->core->descriptor.handle_mousedown = iconMouseDown;
785 btn->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
786 btn->icon->core->descriptor.parent = btn;
787 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
788 XMapWindow(dpy, btn->icon->core->window);
789 btn->x_pos = x_pos;
790 btn->y_pos = 0;
791 btn->docked = 1;
792 if (type == WM_CLIP)
793 scr->clip_icon = btn;
795 return btn;
799 static void
800 switchWSCommand(WMenu *menu, WMenuEntry *entry)
802 WAppIcon *btn, *icon = (WAppIcon*) entry->clientdata;
803 WScreen *scr = icon->icon->core->screen_ptr;
804 WDock *src, *dest;
805 LinkedList *selectedIcons;
806 int x, y;
808 if (entry->order == scr->current_workspace)
809 return;
810 src = icon->dock;
811 dest = scr->workspaces[entry->order]->clip;
813 selectedIcons = getSelected(src);
815 if (selectedIcons) {
816 while(selectedIcons) {
817 btn = selectedIcons->head;
818 if (wDockFindFreeSlot(dest, &x, &y)) {
819 moveIconBetweenDocks(src, dest, btn, x, y);
820 XUnmapWindow(dpy, btn->icon->core->window);
822 list_remove_head(&selectedIcons);
824 } else if (icon != scr->clip_icon) {
825 if (wDockFindFreeSlot(dest, &x, &y)) {
826 moveIconBetweenDocks(src, dest, icon, x, y);
827 XUnmapWindow(dpy, icon->icon->core->window);
834 static void
835 launchDockedApplication(WAppIcon *btn)
837 WScreen *scr = btn->icon->core->screen_ptr;
839 if (!btn->launching && btn->command!=NULL) {
840 if (!btn->forced_dock) {
841 btn->relaunching = btn->running;
842 btn->running = 1;
844 if (btn->wm_instance || btn->wm_class) {
845 WWindowAttributes attr;
846 memset(&attr, 0, sizeof(WWindowAttributes));
847 wDefaultFillAttributes(scr, btn->wm_instance, btn->wm_class,
848 &attr, NULL, True);
850 if (!attr.no_appicon && !btn->buggy_app)
851 btn->launching = 1;
852 else
853 btn->running = 0;
855 btn->drop_launch = 0;
856 scr->last_dock = btn->dock;
857 btn->pid = execCommand(btn, btn->command, NULL);
858 if (btn->pid>0) {
859 if (btn->buggy_app) {
860 /* give feedback that the app was launched */
861 btn->launching = 1;
862 dockIconPaint(btn);
863 btn->launching = 0;
864 WMAddTimerHandler(200, (WMCallback*)dockIconPaint, btn);
865 } else {
866 dockIconPaint(btn);
868 } else {
869 wwarning(_("could not launch application %s\n"), btn->command);
870 btn->launching = 0;
871 if (!btn->relaunching)
872 btn->running = 0;
879 static void
880 updateWorkspaceMenu(WMenu *menu, WAppIcon *icon)
882 WScreen *scr = menu->frame->screen_ptr;
883 char title[MAX_WORKSPACENAME_WIDTH+1];
884 int i;
886 if (!menu || !icon)
887 return;
889 for (i=0; i<scr->workspace_count; i++) {
890 if (i < menu->entry_no) {
891 if (strcmp(menu->entries[i]->text,scr->workspaces[i]->name)!=0) {
892 free(menu->entries[i]->text);
893 strcpy(title, scr->workspaces[i]->name);
894 menu->entries[i]->text = wstrdup(title);
895 menu->flags.realized = 0;
897 menu->entries[i]->clientdata = (void*)icon;
898 } else {
899 strcpy(title, scr->workspaces[i]->name);
901 wMenuAddCallback(menu, title, switchWSCommand, (void*)icon);
903 menu->flags.realized = 0;
905 if (i == scr->current_workspace) {
906 wMenuSetEnabled(menu, i, False);
907 } else {
908 wMenuSetEnabled(menu, i, True);
912 if (!menu->flags.realized)
913 wMenuRealize(menu);
917 static WMenu*
918 makeWorkspaceMenu(WScreen *scr)
920 WMenu *menu;
922 menu = wMenuCreate(scr, NULL, False);
923 if (!menu)
924 wwarning(_("could not create workspace submenu for Clip menu"));
926 wMenuAddCallback(menu, "", switchWSCommand, (void*)scr->clip_icon);
928 menu->flags.realized = 0;
929 wMenuRealize(menu);
931 return menu;
935 static void
936 updateClipOptionsMenu(WMenu *menu, WDock *dock)
938 WMenuEntry *entry;
939 int index = 0;
941 if (!menu || !dock)
942 return;
944 /* keep on top */
945 entry = menu->entries[index];
946 entry->flags.indicator_on = !dock->lowered;
947 entry->clientdata = dock;
949 /* collapsed */
950 entry = menu->entries[++index];
951 entry->flags.indicator_on = dock->collapsed;
952 entry->clientdata = dock;
954 /* auto-collapse */
955 entry = menu->entries[++index];
956 entry->flags.indicator_on = dock->auto_collapse;
957 entry->clientdata = dock;
959 /* auto-raise/lower */
960 entry = menu->entries[++index];
961 entry->flags.indicator_on = dock->auto_raise_lower;
962 entry->clientdata = dock;
964 /* attract icons */
965 entry = menu->entries[++index];
966 entry->flags.indicator_on = dock->attract_icons;
967 entry->clientdata = dock;
969 /* keep attracted icons */
970 entry = menu->entries[++index];
971 entry->flags.indicator_on = dock->keep_attracted;
972 entry->clientdata = dock;
974 menu->flags.realized = 0;
975 wMenuRealize(menu);
979 static WMenu*
980 makeClipOptionsMenu(WScreen *scr)
982 WMenu *menu;
983 WMenuEntry *entry;
985 menu = wMenuCreate(scr, NULL, False);
986 if (!menu) {
987 wwarning(_("could not create options submenu for Clip menu"));
988 return NULL;
991 entry = wMenuAddCallback(menu, _("Keep on top"),
992 toggleLoweredCallback, NULL);
993 entry->flags.indicator = 1;
994 entry->flags.indicator_on = 1;
995 entry->flags.indicator_type = MI_CHECK;
997 entry = wMenuAddCallback(menu, _("Collapsed"),
998 toggleCollapsedCallback, NULL);
999 entry->flags.indicator = 1;
1000 entry->flags.indicator_on = 1;
1001 entry->flags.indicator_type = MI_CHECK;
1003 entry = wMenuAddCallback(menu, _("AutoCollapse"),
1004 toggleAutoCollapseCallback, NULL);
1005 entry->flags.indicator = 1;
1006 entry->flags.indicator_on = 1;
1007 entry->flags.indicator_type = MI_CHECK;
1009 entry = wMenuAddCallback(menu, _("AutoRaiseLower"),
1010 toggleAutoRaiseLowerCallback, NULL);
1011 entry->flags.indicator = 1;
1012 entry->flags.indicator_on = 1;
1013 entry->flags.indicator_type = MI_CHECK;
1015 entry = wMenuAddCallback(menu, _("AutoAttract Icons"),
1016 toggleAutoAttractCallback, NULL);
1017 entry->flags.indicator = 1;
1018 entry->flags.indicator_on = 1;
1019 entry->flags.indicator_type = MI_CHECK;
1021 entry = wMenuAddCallback(menu, _("Keep Attracted Icons"),
1022 toggleKeepCallback, NULL);
1023 entry->flags.indicator = 1;
1024 entry->flags.indicator_on = 1;
1025 entry->flags.indicator_type = MI_CHECK;
1027 menu->flags.realized = 0;
1028 wMenuRealize(menu);
1030 return menu;
1034 static WMenu*
1035 dockMenuCreate(WScreen *scr, int type)
1037 WMenu *menu;
1038 WMenuEntry *entry;
1040 if (type == WM_CLIP && scr->clip_menu)
1041 return scr->clip_menu;
1043 menu = wMenuCreate(scr, NULL, False);
1044 if (type != WM_CLIP) {
1045 entry = wMenuAddCallback(menu, _("Keep on top"),
1046 toggleLoweredCallback, NULL);
1047 entry->flags.indicator = 1;
1048 entry->flags.indicator_on = 1;
1049 entry->flags.indicator_type = MI_CHECK;
1050 } else {
1051 entry = wMenuAddCallback(menu, _("Clip Options"), NULL, NULL);
1052 scr->clip_options = makeClipOptionsMenu(scr);
1053 if (scr->clip_options)
1054 wMenuEntrySetCascade(menu, entry, scr->clip_options);
1056 wMenuAddCallback(menu, _("Rename Workspace"), renameCallback, NULL);
1058 wMenuAddCallback(menu, _("(Un)Select Icon"), selectCallback, NULL);
1060 wMenuAddCallback(menu, _("(Un)Select All Icons"), selectIconsCallback,
1061 NULL);
1063 wMenuAddCallback(menu, _("Keep Icon(s)"), keepIconsCallback, NULL);
1065 entry = wMenuAddCallback(menu, _("Move Icon(s) To"), NULL, NULL);
1066 scr->clip_submenu = makeWorkspaceMenu(scr);
1067 if (scr->clip_submenu)
1068 wMenuEntrySetCascade(menu, entry, scr->clip_submenu);
1070 wMenuAddCallback(menu, _("Remove Icon(s)"), removeIconsCallback, NULL);
1072 wMenuAddCallback(menu, _("Attract Icons"), colectIconsCallback, NULL);
1075 wMenuAddCallback(menu, _("Launch"), launchCallback, NULL);
1077 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
1079 entry = wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
1080 free(entry->text);
1081 entry->text = _("Hide");
1083 wMenuAddCallback(menu, _("Settings..."), settingsCallback, NULL);
1085 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
1087 if (type == WM_CLIP)
1088 scr->clip_menu = menu;
1090 return menu;
1094 WDock*
1095 wDockCreate(WScreen *scr, int type)
1097 WDock *dock;
1098 WAppIcon *btn;
1099 int icon_count;
1101 make_keys();
1103 dock = wmalloc(sizeof(WDock));
1104 memset(dock, 0, sizeof(WDock));
1106 if (type == WM_CLIP)
1107 icon_count = CLIP_MAX_ICONS;
1108 else
1109 icon_count = scr->scr_height/wPreferences.icon_size;
1111 dock->icon_array = wmalloc(sizeof(WAppIcon*)*icon_count);
1112 memset(dock->icon_array, 0, sizeof(WAppIcon*)*icon_count);
1114 dock->max_icons = icon_count;
1116 btn = mainIconCreate(scr, type);
1118 btn->dock = dock;
1120 dock->x_pos = btn->x_pos;
1121 dock->y_pos = btn->y_pos;
1122 dock->screen_ptr = scr;
1123 dock->type = type;
1124 dock->icon_count = 1;
1125 dock->on_right_side = 1;
1126 dock->collapsed = 0;
1127 dock->auto_collapse = 0;
1128 dock->auto_collapse_magic = NULL;
1129 dock->auto_raise_lower = 0;
1130 dock->auto_lower_magic = NULL;
1131 dock->auto_raise_magic = NULL;
1132 dock->attract_icons = 0;
1133 dock->keep_attracted = 0;
1134 dock->lowered = 1;
1135 dock->icon_array[0] = btn;
1136 wRaiseFrame(btn->icon->core);
1137 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
1139 /* create dock menu */
1140 dock->menu = dockMenuCreate(scr, type);
1142 return dock;
1146 void
1147 wDockDestroy(WDock *dock)
1149 int i;
1150 WAppIcon *aicon;
1152 for (i=(dock->type == WM_CLIP) ? 1 : 0; i<dock->max_icons; i++) {
1153 aicon = dock->icon_array[i];
1154 if (aicon) {
1155 int keepit = aicon->running && wApplicationOf(aicon->main_window);
1156 wDockDetach(dock, aicon);
1157 if (keepit) {
1158 PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);
1159 XMoveWindow(dpy, aicon->icon->core->window,
1160 aicon->x_pos, aicon->y_pos);
1161 if (!dock->mapped || dock->collapsed)
1162 XMapWindow(dpy, aicon->icon->core->window);
1166 if (wPreferences.auto_arrange_icons)
1167 wArrangeIcons(dock->screen_ptr, True);
1168 free(dock->icon_array);
1169 if (dock->menu && dock->type!=WM_CLIP)
1170 wMenuDestroy(dock->menu, True);
1171 free(dock);
1175 void
1176 wClipIconPaint(WAppIcon *aicon)
1178 WScreen *scr = aicon->icon->core->screen_ptr;
1179 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
1180 GC gc;
1181 Window win = aicon->icon->core->window;
1182 int length, nlength;
1183 char *ws_name, ws_number[10];
1184 int ty, tx;
1186 wIconPaint(aicon->icon);
1188 length = strlen(workspace->name);
1189 ws_name = malloc(length + 1);
1190 sprintf(ws_name, "%s", workspace->name);
1191 sprintf(ws_number, "%i", scr->current_workspace + 1);
1192 nlength = strlen(ws_number);
1194 gc = scr->clip_title_gc;
1196 if (!workspace->clip->collapsed)
1197 XSetForeground(dpy, gc, scr->clip_title_pixel[CLIP_NORMAL]);
1198 else
1199 XSetForeground(dpy, gc, scr->clip_title_pixel[CLIP_COLLAPSED]);
1201 ty = ICON_SIZE - scr->clip_title_font->height - 3;
1203 tx = CLIP_BUTTON_SIZE*ICON_SIZE/64;
1205 wDrawString(win, scr->clip_title_font, gc, tx,
1206 ty + scr->clip_title_font->y, ws_name, length);
1208 tx = (ICON_SIZE/2 - wTextWidth(scr->clip_title_font->font, ws_number, nlength))/2;
1210 wDrawString(win, scr->clip_title_font, gc, tx,
1211 scr->clip_title_font->y + 2, ws_number, nlength);
1213 free(ws_name);
1215 if (aicon->launching) {
1216 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
1217 0, 0, wPreferences.icon_size, wPreferences.icon_size);
1219 paintClipButtons(aicon, aicon->dock->lclip_button_pushed,
1220 aicon->dock->rclip_button_pushed);
1224 static void
1225 clipIconExpose(WObjDescriptor *desc, XEvent *event)
1227 wClipIconPaint(desc->parent);
1231 static void
1232 dockIconPaint(WAppIcon *btn)
1234 if (btn == btn->icon->core->screen_ptr->clip_icon)
1235 wClipIconPaint(btn);
1236 else
1237 wAppIconPaint(btn);
1241 static proplist_t
1242 make_icon_state(WAppIcon *btn)
1244 proplist_t node = NULL;
1245 proplist_t command, autolaunch, name, forced, host, position, buggy;
1246 char *tmp;
1247 char buffer[64];
1249 if (btn) {
1250 if (!btn->command)
1251 command = PLMakeString("-");
1252 else
1253 command = PLMakeString(btn->command);
1255 autolaunch = btn->auto_launch ? dYes : dNo;
1257 tmp = EscapeWM_CLASS(btn->wm_instance, btn->wm_class);
1259 name = PLMakeString(tmp);
1261 free(tmp);
1263 forced = btn->forced_dock ? dYes : dNo;
1265 buggy = btn->buggy_app ? dYes: dNo;
1267 if (btn == btn->icon->core->screen_ptr->clip_icon)
1268 sprintf(buffer, "%i,%i", btn->x_pos, btn->y_pos);
1269 else
1270 sprintf(buffer, "%hi,%hi", btn->xindex, btn->yindex);
1271 position = PLMakeString(buffer);
1273 node = PLMakeDictionaryFromEntries(dCommand, command,
1274 dName, name,
1275 dAutoLaunch, autolaunch,
1276 dForced, forced,
1277 dBuggyApplication, buggy,
1278 dPosition, position,
1279 NULL);
1280 PLRelease(command);
1281 PLRelease(name);
1282 PLRelease(position);
1283 #ifdef OFFIX_DND
1284 if (btn->dnd_command) {
1285 command = PLMakeString(btn->dnd_command);
1286 PLInsertDictionaryEntry(node, dDropCommand, command);
1287 PLRelease(command);
1289 #endif /* OFFIX_DND */
1291 if (btn->client_machine && btn->remote_start) {
1292 host = PLMakeString(btn->client_machine);
1293 PLInsertDictionaryEntry(node, dHost, host);
1294 PLRelease(host);
1298 return node;
1302 static proplist_t
1303 dockSaveState(WDock *dock)
1305 int i;
1306 proplist_t icon_info;
1307 proplist_t list=NULL, dock_state=NULL;
1308 proplist_t value;
1309 char buffer[256];
1311 list = PLMakeArrayFromElements(NULL);
1313 for (i=(dock->type==WM_DOCK ? 0 : 1); i<dock->max_icons; i++) {
1314 WAppIcon *btn = dock->icon_array[i];
1316 if (!btn || (btn->attracted && !dock->keep_attracted))
1317 continue;
1319 if ((icon_info = make_icon_state(dock->icon_array[i]))) {
1320 list = PLAppendArrayElement(list, icon_info);
1321 PLRelease(icon_info);
1325 dock_state = PLMakeDictionaryFromEntries(dApplications, list, NULL);
1327 PLRelease(list);
1329 if (dock->type == WM_DOCK) {
1330 sprintf(buffer, "%i,%i", (dock->on_right_side ? -ICON_SIZE : 0),
1331 dock->y_pos);
1332 value = PLMakeString(buffer);
1333 PLInsertDictionaryEntry(dock_state, dPosition, value);
1334 PLRelease(value);
1337 value = (dock->lowered ? dYes : dNo);
1338 PLInsertDictionaryEntry(dock_state, dLowered, value);
1340 if (dock->type == WM_CLIP) {
1341 value = (dock->collapsed ? dYes : dNo);
1342 PLInsertDictionaryEntry(dock_state, dCollapsed, value);
1344 value = (dock->auto_collapse ? dYes : dNo);
1345 PLInsertDictionaryEntry(dock_state, dAutoCollapse, value);
1347 value = (dock->auto_raise_lower ? dYes : dNo);
1348 PLInsertDictionaryEntry(dock_state, dAutoRaiseLower, value);
1350 value = (dock->attract_icons ? dYes : dNo);
1351 PLInsertDictionaryEntry(dock_state, dAutoAttractIcons, value);
1353 value = (dock->keep_attracted ? dYes : dNo);
1354 PLInsertDictionaryEntry(dock_state, dKeepAttracted, value);
1357 return dock_state;
1361 void
1362 wDockSaveState(WScreen *scr)
1364 proplist_t dock_state;
1366 dock_state = dockSaveState(scr->dock);
1368 PLInsertDictionaryEntry(scr->session_state, dDock, dock_state);
1370 PLRelease(dock_state);
1374 void
1375 wClipSaveState(WScreen *scr)
1377 proplist_t clip_state;
1379 clip_state = make_icon_state(scr->clip_icon);
1381 PLInsertDictionaryEntry(scr->session_state, dClip, clip_state);
1383 PLRelease(clip_state);
1387 proplist_t
1388 wClipSaveWorkspaceState(WScreen *scr, int workspace)
1390 return dockSaveState(scr->workspaces[workspace]->clip);
1394 static WAppIcon*
1395 restore_icon_state(WScreen *scr, proplist_t info, int type, int index)
1397 WAppIcon *aicon;
1398 char *wclass, *winstance;
1399 proplist_t cmd, value;
1400 char *command;
1403 cmd = PLGetDictionaryEntry(info, dCommand);
1404 if (!cmd || !PLIsString(cmd)) {
1405 return NULL;
1408 /* parse window name */
1409 value = PLGetDictionaryEntry(info, dName);
1410 if (!value)
1411 return NULL;
1413 ParseWindowName(value, &winstance, &wclass, "dock");
1415 if (!winstance && !wclass) {
1416 return NULL;
1419 /* get commands */
1421 if (cmd)
1422 command = wstrdup(PLGetString(cmd));
1423 else
1424 command = NULL;
1426 if (!command || strcmp(command, "-")==0) {
1427 if (command)
1428 free(command);
1429 if (wclass)
1430 free(wclass);
1431 if (winstance)
1432 free(winstance);
1434 return NULL;
1437 aicon = wAppIconCreateForDock(scr, command, winstance, wclass,
1438 TILE_NORMAL);
1439 if (wclass)
1440 free(wclass);
1441 if (winstance)
1442 free(winstance);
1444 aicon->icon->core->descriptor.handle_mousedown = iconMouseDown;
1445 if (type == WM_CLIP) {
1446 aicon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
1447 aicon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
1449 aicon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
1450 aicon->icon->core->descriptor.parent = aicon;
1453 #ifdef OFFIX_DND
1454 cmd = PLGetDictionaryEntry(info, dDropCommand);
1455 if (cmd)
1456 aicon->dnd_command = wstrdup(PLGetString(cmd));
1457 #endif
1459 /* check auto launch */
1460 value = PLGetDictionaryEntry(info, dAutoLaunch);
1462 aicon->auto_launch = 0;
1463 if (value) {
1464 if (PLIsString(value)) {
1465 if (strcasecmp(PLGetString(value), "YES")==0)
1466 aicon->auto_launch = 1;
1467 } else {
1468 wwarning(_("bad value in docked icon state info %s"),
1469 PLGetString(dAutoLaunch));
1473 /* check if it wasn't normally docked */
1474 value = PLGetDictionaryEntry(info, dForced);
1476 aicon->forced_dock = 0;
1477 if (value) {
1478 if (PLIsString(value)) {
1479 if (strcasecmp(PLGetString(value), "YES")==0)
1480 aicon->forced_dock = 1;
1481 } else {
1482 wwarning(_("bad value in docked icon state info %s"),
1483 PLGetString(dForced));
1487 /* check if we can rely on the stuff in the app */
1488 value = PLGetDictionaryEntry(info, dBuggyApplication);
1490 aicon->buggy_app = 0;
1491 if (value) {
1492 if (PLIsString(value)) {
1493 if (strcasecmp(PLGetString(value), "YES")==0)
1494 aicon->buggy_app = 1;
1495 } else {
1496 wwarning(_("bad value in docked icon state info %s"),
1497 PLGetString(dBuggyApplication));
1501 /* get position in the dock */
1502 value = PLGetDictionaryEntry(info, dPosition);
1503 if (value && PLIsString(value)) {
1504 if (sscanf(PLGetString(value), "%hi,%hi", &aicon->xindex,
1505 &aicon->yindex)!=2)
1506 wwarning(_("bad value in docked icon state info %s"),
1507 PLGetString(dPosition));
1509 /* check position sanity */
1510 /* incomplete section! */
1511 if (type == WM_DOCK) {
1512 aicon->xindex = 0;
1513 if (aicon->yindex < 0)
1514 wwarning(_("bad value in docked icon position %i,%i"),
1515 aicon->xindex, aicon->yindex);
1517 } else {
1518 aicon->yindex = index;
1519 aicon->xindex = 0;
1522 aicon->running = 0;
1523 aicon->docked = 1;
1525 return aicon;
1529 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1532 WAppIcon*
1533 wClipRestoreState(WScreen *scr, proplist_t clip_state)
1535 WAppIcon *icon;
1536 proplist_t value;
1539 icon = mainIconCreate(scr, WM_CLIP);
1541 if (!clip_state)
1542 return icon;
1543 else
1544 PLRetain(clip_state);
1546 /* restore position */
1548 value = PLGetDictionaryEntry(clip_state, dPosition);
1550 if (value) {
1551 if (!PLIsString(value))
1552 COMPLAIN("Position");
1553 else {
1554 if (sscanf(PLGetString(value), "%i,%i", &icon->x_pos,
1555 &icon->y_pos)!=2)
1556 COMPLAIN("Position");
1558 /* check position sanity */
1559 if (icon->y_pos < 0)
1560 icon->y_pos = 0;
1561 else if (icon->y_pos > scr->scr_height-ICON_SIZE)
1562 icon->y_pos = scr->scr_height-ICON_SIZE;
1564 if (icon->x_pos < 0)
1565 icon->x_pos = 0;
1566 else if (icon->x_pos > scr->scr_width-ICON_SIZE)
1567 icon->x_pos = scr->scr_width-ICON_SIZE;
1571 #ifdef OFFIX_DND
1572 value = PLGetDictionaryEntry(clip_state, dDropCommand);
1573 if (value && PLIsString(value))
1574 icon->dnd_command = wstrdup(PLGetString(value));
1575 #endif
1577 PLRelease(clip_state);
1579 return icon;
1583 WDock*
1584 wDockRestoreState(WScreen *scr, proplist_t dock_state, int type)
1586 WDock *dock;
1587 proplist_t apps;
1588 proplist_t value;
1589 WAppIcon *aicon, *old_top;
1590 int count, i;
1593 dock = wDockCreate(scr, type);
1595 if (!dock_state)
1596 return dock;
1598 if (dock_state)
1599 PLRetain(dock_state);
1602 /* restore position */
1604 value = PLGetDictionaryEntry(dock_state, dPosition);
1606 if (value) {
1607 if (!PLIsString(value))
1608 COMPLAIN("Position");
1609 else {
1610 if (sscanf(PLGetString(value), "%i,%i", &dock->x_pos,
1611 &dock->y_pos)!=2)
1612 COMPLAIN("Position");
1614 /* check position sanity */
1615 if (dock->y_pos < 0)
1616 dock->y_pos = 0;
1617 else if (dock->y_pos > scr->scr_height-ICON_SIZE)
1618 dock->y_pos = scr->scr_height - ICON_SIZE;
1620 /* This is no more needed. ??? */
1621 if (type == WM_CLIP) {
1622 if (dock->x_pos < 0)
1623 dock->x_pos = 0;
1624 else if (dock->x_pos > scr->scr_width-ICON_SIZE)
1625 dock->x_pos = scr->scr_width-ICON_SIZE;
1626 } else {
1627 if (dock->x_pos >= 0) {
1628 dock->x_pos = DOCK_EXTRA_SPACE;
1629 dock->on_right_side = 0;
1630 } else {
1631 dock->x_pos = scr->scr_width - DOCK_EXTRA_SPACE - ICON_SIZE;
1632 dock->on_right_side = 1;
1638 /* restore lowered/raised state */
1640 dock->lowered = 0;
1642 value = PLGetDictionaryEntry(dock_state, dLowered);
1644 if (value) {
1645 if (!PLIsString(value))
1646 COMPLAIN("Lowered");
1647 else {
1648 if (strcasecmp(PLGetString(value), "YES")==0)
1649 dock->lowered = 1;
1654 /* restore collapsed state */
1656 dock->collapsed = 0;
1658 value = PLGetDictionaryEntry(dock_state, dCollapsed);
1660 if (value) {
1661 if (!PLIsString(value))
1662 COMPLAIN("Collapsed");
1663 else {
1664 if (strcasecmp(PLGetString(value), "YES")==0)
1665 dock->collapsed = 1;
1670 /* restore auto-collapsed state */
1672 value = PLGetDictionaryEntry(dock_state, dAutoCollapse);
1674 if (value) {
1675 if (!PLIsString(value))
1676 COMPLAIN("AutoCollapse");
1677 else {
1678 if (strcasecmp(PLGetString(value), "YES")==0) {
1679 dock->auto_collapse = 1;
1680 dock->collapsed = 1;
1686 /* restore auto-raise/lower state */
1688 value = PLGetDictionaryEntry(dock_state, dAutoRaiseLower);
1690 if (value) {
1691 if (!PLIsString(value))
1692 COMPLAIN("AutoRaiseLower");
1693 else {
1694 if (strcasecmp(PLGetString(value), "YES")==0) {
1695 dock->auto_raise_lower = 1;
1701 /* restore attract icons state */
1703 dock->attract_icons = 0;
1705 value = PLGetDictionaryEntry(dock_state, dAutoAttractIcons);
1707 if (value) {
1708 if (!PLIsString(value))
1709 COMPLAIN("AutoAttractIcons");
1710 else {
1711 if (strcasecmp(PLGetString(value), "YES")==0)
1712 dock->attract_icons = 1;
1717 /* restore keep attracted icons state */
1719 dock->keep_attracted = 0;
1721 value = PLGetDictionaryEntry(dock_state, dKeepAttracted);
1723 if (value) {
1724 if (!PLIsString(value))
1725 COMPLAIN("KeepAttracted");
1726 else {
1727 if (strcasecmp(PLGetString(value), "YES")==0)
1728 dock->keep_attracted = 1;
1733 /* application list */
1735 apps = PLGetDictionaryEntry(dock_state, dApplications);
1737 if (!apps) {
1738 goto finish;
1741 count = PLGetNumberOfElements(apps);
1743 if (count==0)
1744 goto finish;
1746 old_top = dock->icon_array[0];
1748 /* dock->icon_count is set to 1 when dock is created.
1749 * Since Clip is already restored, we want to keep it so for clip,
1750 * but for dock we may change the default top tile, so we set it to 0.
1752 if (type == WM_DOCK)
1753 dock->icon_count = 0;
1755 for (i=0; i<count; i++) {
1756 if (dock->icon_count >= dock->max_icons) {
1757 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1758 break;
1761 value = PLGetArrayElement(apps, i);
1762 aicon = restore_icon_state(scr, value, type, dock->icon_count);
1764 dock->icon_array[dock->icon_count] = aicon;
1766 if (aicon) {
1767 aicon->dock = dock;
1768 aicon->x_pos = dock->x_pos + (aicon->xindex*ICON_SIZE);
1769 aicon->y_pos = dock->y_pos + (aicon->yindex*ICON_SIZE);
1771 if (dock->lowered)
1772 ChangeStackingLevel(aicon->icon->core, WMNormalLevel);
1773 else
1774 ChangeStackingLevel(aicon->icon->core, WMDockLevel);
1776 wCoreConfigure(aicon->icon->core, aicon->x_pos, aicon->y_pos,
1777 0, 0);
1779 if (!dock->collapsed)
1780 XMapWindow(dpy, aicon->icon->core->window);
1781 wRaiseFrame(aicon->icon->core);
1783 dock->icon_count++;
1784 } else if (dock->icon_count==0 && type==WM_DOCK)
1785 dock->icon_count++;
1788 /* if the first icon is not defined, use the default */
1789 if (dock->icon_array[0]==NULL) {
1790 /* update default icon */
1791 old_top->x_pos = dock->x_pos;
1792 old_top->y_pos = dock->y_pos;
1793 if (dock->lowered)
1794 ChangeStackingLevel(old_top->icon->core, WMNormalLevel);
1795 else
1796 ChangeStackingLevel(old_top->icon->core, WMDockLevel);
1797 dock->icon_array[0] = old_top;
1798 XMoveWindow(dpy, old_top->icon->core->window, dock->x_pos, dock->y_pos);
1799 /* we don't need to increment dock->icon_count here because it was
1800 * incremented in the loop above.
1802 } else if (old_top!=dock->icon_array[0]) {
1803 if (old_top == scr->clip_icon)
1804 scr->clip_icon = dock->icon_array[0];
1805 wAppIconDestroy(old_top);
1808 finish:
1809 if (dock_state)
1810 PLRelease(dock_state);
1812 return dock;
1817 void
1818 wDockLaunchWithState(WDock *dock, WAppIcon *btn, WSavedState *state)
1820 if (btn && btn->command && !btn->running && !btn->launching) {
1822 btn->drop_launch = 0;
1824 btn->pid = execCommand(btn, btn->command, state);
1826 if (btn->pid>0) {
1827 if (!btn->forced_dock && !btn->buggy_app) {
1828 btn->launching = 1;
1829 dockIconPaint(btn);
1832 } else {
1833 free(state);
1838 void
1839 wDockDoAutoLaunch(WDock *dock, int workspace)
1841 WAppIcon *btn;
1842 WSavedState *state;
1843 int i;
1845 for (i = 0; i < dock->max_icons; i++) {
1846 btn = dock->icon_array[i];
1847 if (!btn || !btn->auto_launch)
1848 continue;
1850 state = wmalloc(sizeof(WSavedState));
1851 memset(state, 0, sizeof(WSavedState));
1852 state->workspace = workspace;
1853 /* TODO: this is klugy and is very difficult to understand
1854 * what's going on. Try to clean up */
1855 wDockLaunchWithState(dock, btn, state);
1859 #ifdef REDUCE_APPICONS
1860 void
1861 wDockSimulateLaunch(WDock *dock, WAppIcon *btn)
1863 if ((btn == NULL) || (dock == NULL))
1864 return;
1866 if (!btn->running) {
1867 if ((btn->icon->owner == NULL) && (btn->applist))
1868 btn->icon->owner = btn->applist->wapp->main_window_desc;
1869 if (!btn->forced_dock)
1870 btn->launching = 1;
1871 dockIconPaint(btn);
1872 wusleep(5000);
1875 #endif
1877 #ifdef OFFIX_DND
1878 static WDock*
1879 findDock(WScreen *scr, XEvent *event, int *icon_pos)
1881 WDock *dock;
1882 int i;
1884 *icon_pos = -1;
1885 if ((dock = scr->dock)!=NULL) {
1886 for (i=0; i<dock->max_icons; i++) {
1887 if (dock->icon_array[i]
1888 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1889 *icon_pos = i;
1890 break;
1894 if (*icon_pos<0 && (dock = scr->workspaces[scr->current_workspace]->clip)!=NULL) {
1895 for (i=0; i<dock->max_icons; i++) {
1896 if (dock->icon_array[i]
1897 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1898 *icon_pos = i;
1899 break;
1903 if(*icon_pos>=0)
1904 return dock;
1905 return NULL;
1910 wDockReceiveDNDDrop(WScreen *scr, XEvent *event)
1912 WDock *dock;
1913 WAppIcon *btn;
1914 int icon_pos;
1916 dock = findDock(scr, event, &icon_pos);
1917 if (!dock)
1918 return False;
1921 * Return True if the drop was on an application icon window.
1922 * In this case, let the ClientMessage handler redirect the
1923 * message to the app.
1925 if (dock->icon_array[icon_pos]->icon->icon_win!=None)
1926 return True;
1928 if (dock->icon_array[icon_pos]->dnd_command!=NULL) {
1929 scr->flags.dnd_data_convertion_status = 0;
1931 btn = dock->icon_array[icon_pos];
1933 if (!btn->forced_dock) {
1934 btn->relaunching = btn->running;
1935 btn->running = 1;
1937 if (btn->wm_instance || btn->wm_class) {
1938 WWindowAttributes attr;
1939 memset(&attr, 0, sizeof(WWindowAttributes));
1940 wDefaultFillAttributes(btn->icon->core->screen_ptr,
1941 btn->wm_instance,
1942 btn->wm_class, &attr, NULL, True);
1944 if (!attr.no_appicon)
1945 btn->launching = 1;
1946 else
1947 btn->running = 0;
1950 btn->drop_launch = 1;
1951 scr->last_dock = dock;
1952 btn->pid = execCommand(btn, btn->dnd_command, NULL);
1953 if (btn->pid>0) {
1954 dockIconPaint(btn);
1955 } else {
1956 btn->launching = 0;
1957 if (!btn->relaunching) {
1958 btn->running = 0;
1962 return False;
1964 #endif /* OFFIX_DND */
1968 Bool
1969 wDockAttachIcon(WDock *dock, WAppIcon *icon, int x, int y)
1971 WWindow *wwin;
1972 char **argv;
1973 int argc;
1974 int index;
1976 wwin = icon->icon->owner;
1977 if (icon->command==NULL) {
1978 icon->editing = 0;
1979 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
1981 icon->command = FlattenStringList(argv, argc);
1982 XFreeStringList(argv);
1983 } else {
1984 char *command=NULL;
1986 /* icon->forced_dock = 1;*/
1987 if (!icon->attracted || dock->type!=WM_CLIP || dock->keep_attracted) {
1988 icon->editing = 1;
1989 if (wInputDialog(dock->screen_ptr, _("Dock Icon"),
1990 _("Type the command used to launch the application"),
1991 &command)) {
1992 if (command && (command[0]==0 ||
1993 (command[0]=='-' && command[1]==0))) {
1994 free(command);
1995 command = NULL;
1997 icon->command = command;
1998 icon->editing = 0;
1999 } else {
2000 icon->editing = 0;
2001 if (command)
2002 free(command);
2003 /* If the target is the dock, reject the icon. If
2004 * the target is the clip, make it an attracted icon
2006 if (dock->type==WM_CLIP) {
2007 icon->attracted = 1;
2008 if (!icon->icon->shadowed) {
2009 icon->icon->shadowed = 1;
2010 icon->icon->force_paint = 1;
2012 } else {
2013 return False;
2018 } else {
2019 icon->editing = 0;
2022 for (index=1; index<dock->max_icons; index++)
2023 if (dock->icon_array[index] == NULL)
2024 break;
2025 /* if (index == dock->max_icons)
2026 return; */
2028 assert(index < dock->max_icons);
2030 dock->icon_array[index] = icon;
2031 icon->yindex = y;
2032 icon->xindex = x;
2034 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2035 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2037 dock->icon_count++;
2039 icon->running = 1;
2040 icon->launching = 0;
2041 icon->docked = 1;
2042 icon->dock = dock;
2043 icon->icon->core->descriptor.handle_mousedown = iconMouseDown;
2044 if (dock->type == WM_CLIP) {
2045 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2046 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2048 icon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
2049 icon->icon->core->descriptor.parent = icon;
2051 MoveInStackListUnder(dock->icon_array[index-1]->icon->core,
2052 icon->icon->core);
2053 wAppIconMove(icon, icon->x_pos, icon->y_pos);
2054 wAppIconPaint(icon);
2056 if (wPreferences.auto_arrange_icons)
2057 wArrangeIcons(dock->screen_ptr, True);
2059 #ifdef OFFIX_DND
2060 if (icon->command && !icon->dnd_command) {
2061 icon->dnd_command = wmalloc(strlen(icon->command)+8);
2062 sprintf(icon->dnd_command, "%s %%d", icon->command);
2064 #endif
2066 return True;
2070 void
2071 reattachIcon(WDock *dock, WAppIcon *icon, int x, int y)
2073 int index;
2075 for(index=1; index<dock->max_icons; index++) {
2076 if(dock->icon_array[index] == icon)
2077 break;
2079 assert(index < dock->max_icons);
2081 icon->yindex = y;
2082 icon->xindex = x;
2084 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2085 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2089 Bool
2090 moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y)
2092 WWindow *wwin;
2093 char **argv;
2094 int argc;
2095 int index;
2097 if (dest == NULL)
2098 return False;
2100 wwin = icon->icon->owner;
2103 * For the moment we can't do this if we move icons in Clip from one
2104 * workspace to other, because if we move two or more icons without
2105 * command, the dialog box will not be able to tell us to which of the
2106 * moved icons it applies. -Dan
2108 if ((dest->type==WM_DOCK /*|| dest->keep_attracted*/) && icon->command==NULL) {
2109 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
2111 icon->command = FlattenStringList(argv, argc);
2112 XFreeStringList(argv);
2113 } else {
2114 char *command=NULL;
2116 icon->editing = 1;
2117 /* icon->forced_dock = 1;*/
2118 if (wInputDialog(src->screen_ptr, _("Dock Icon"),
2119 _("Type the command used to launch the application"),
2120 &command)) {
2121 if (command && (command[0]==0 ||
2122 (command[0]=='-' && command[1]==0))) {
2123 free(command);
2124 command = NULL;
2126 icon->command = command;
2127 } else {
2128 icon->editing = 0;
2129 if (command)
2130 free(command);
2131 return False;
2133 icon->editing = 0;
2137 for(index=1; index<src->max_icons; index++) {
2138 if(src->icon_array[index] == icon)
2139 break;
2141 assert(index < src->max_icons);
2143 src->icon_array[index] = NULL;
2144 src->icon_count--;
2146 for(index=1; index<dest->max_icons; index++) {
2147 if(dest->icon_array[index] == NULL)
2148 break;
2150 /* if (index == dest->max_icons)
2151 return; */
2153 assert(index < dest->max_icons);
2155 dest->icon_array[index] = icon;
2156 icon->dock = dest;
2158 /* deselect the icon */
2159 if (icon->icon->selected)
2160 wIconSelect(icon->icon);
2162 if (dest->type == WM_DOCK) {
2163 icon->icon->core->descriptor.handle_enternotify = NULL;
2164 icon->icon->core->descriptor.handle_leavenotify = NULL;
2165 } else {
2166 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2167 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2170 /* set it to be kept when moving to dock, or to a clip that keep the
2171 * attracted icons.
2172 * Unless the icon does not have a command set
2174 if (icon->command && (dest->type==WM_DOCK || dest->keep_attracted)) {
2175 icon->attracted = 0;
2176 if (icon->icon->shadowed) {
2177 icon->icon->shadowed = 0;
2178 icon->icon->force_paint = 1;
2182 if (src->auto_collapse || src->auto_raise_lower)
2183 clipLeave(src);
2185 icon->yindex = y;
2186 icon->xindex = x;
2188 icon->x_pos = dest->x_pos + x*ICON_SIZE;
2189 icon->y_pos = dest->y_pos + y*ICON_SIZE;
2191 dest->icon_count++;
2193 MoveInStackListUnder(dest->icon_array[index-1]->icon->core,
2194 icon->icon->core);
2195 wAppIconPaint(icon);
2197 return True;
2201 void
2202 wDockDetach(WDock *dock, WAppIcon *icon)
2204 int index;
2206 /* make the settings panel be closed */
2207 if (icon->panel) {
2208 DestroyDockAppSettingsPanel(icon->panel);
2211 icon->docked = 0;
2212 icon->dock = NULL;
2213 icon->attracted = 0;
2214 if (icon->icon->shadowed) {
2215 icon->icon->shadowed = 0;
2216 icon->icon->force_paint = 1;
2219 /* deselect the icon */
2220 if (icon->icon->selected)
2221 wIconSelect(icon->icon);
2223 if (icon->command) {
2224 free(icon->command);
2225 icon->command = NULL;
2227 #ifdef OFFIX_DND
2228 if (icon->dnd_command) {
2229 free(icon->dnd_command);
2230 icon->dnd_command = NULL;
2232 #endif
2234 for (index=1; index<dock->max_icons; index++)
2235 if (dock->icon_array[index] == icon)
2236 break;
2237 assert(index < dock->max_icons);
2238 dock->icon_array[index] = NULL;
2239 icon->yindex = -1;
2240 icon->xindex = -1;
2241 dock->icon_count--;
2243 /* if the dock is not attached to an application or
2244 * the the application did not set the approriate hints yet,
2245 * destroy the icon */
2246 #ifdef REDUCE_APPICONS
2247 if ((icon->num_apps == 0) && (!icon->running || !wApplicationOf(icon->main_window)) )
2248 #else
2249 if (!icon->running || !wApplicationOf(icon->main_window))
2250 #endif
2251 wAppIconDestroy(icon);
2252 else {
2253 icon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
2254 icon->icon->core->descriptor.handle_enternotify = NULL;
2255 icon->icon->core->descriptor.handle_leavenotify = NULL;
2256 icon->icon->core->descriptor.parent_type = WCLASS_APPICON;
2257 icon->icon->core->descriptor.parent = icon;
2259 ChangeStackingLevel(icon->icon->core, NORMAL_ICON_LEVEL);
2261 wAppIconPaint(icon);
2262 if (wPreferences.auto_arrange_icons) {
2263 wArrangeIcons(dock->screen_ptr, True);
2266 if (dock->auto_collapse || dock->auto_raise_lower)
2267 clipLeave(dock);
2272 * returns the closest Dock slot index for the passed
2273 * coordinates.
2275 * Returns False if icon can't be docked.
2277 Bool
2278 wDockSnapIcon(WDock *dock, WAppIcon *icon, int req_x, int req_y,
2279 int *ret_x, int *ret_y, int redocking)
2281 WScreen *scr = dock->screen_ptr;
2282 int dx, dy;
2283 int ex_x, ex_y;
2284 int i, offset = ICON_SIZE/2;
2285 WAppIcon *aicon = NULL;
2286 WAppIcon *nicon = NULL;
2287 int max_y_icons, max_x_icons;
2289 max_x_icons = scr->scr_width/ICON_SIZE;
2290 max_y_icons = scr->scr_height/ICON_SIZE-1;
2292 if (wPreferences.flags.noupdates)
2293 return False;
2295 dx = dock->x_pos;
2296 dy = dock->y_pos;
2298 /* if the dock is full */
2299 if (!redocking &&
2300 (dock->icon_count >= dock->max_icons)) {
2301 return False;
2304 /* exact position */
2305 if (req_y < dy)
2306 ex_y = (req_y - offset - dy)/ICON_SIZE;
2307 else
2308 ex_y = (req_y + offset - dy)/ICON_SIZE;
2310 if (req_x < dx)
2311 ex_x = (req_x - offset - dx)/ICON_SIZE;
2312 else
2313 ex_x = (req_x + offset - dx)/ICON_SIZE;
2315 /* check if the icon is outside the screen boundaries */
2316 if (dx + ex_x*ICON_SIZE < -ICON_SIZE+2 ||
2317 dx + ex_x*ICON_SIZE >= scr->scr_width-1 ||
2318 dy + ex_y*ICON_SIZE < -ICON_SIZE+2 ||
2319 dy + ex_y*ICON_SIZE >= scr->scr_height-1)
2320 return False;
2322 if (dock->type == WM_DOCK) {
2323 if (icon->dock != dock && ex_x != 0)
2324 return False;
2326 for (i=0; i<dock->max_icons; i++) {
2327 nicon = dock->icon_array[i];
2328 if (nicon && nicon->yindex == ex_y) {
2329 aicon = nicon;
2330 break;
2334 *ret_x = 0;
2336 if (redocking) {
2337 int sig, done, closest;
2339 /* Possible cases when redocking:
2341 * icon dragged out of range of any slot -> false
2342 * icon dragged to range of free slot
2343 * icon dragged to range of same slot
2344 * icon dragged to range of different icon
2346 if (abs(ex_x) > DOCK_DETTACH_THRESHOLD)
2347 return False;
2349 if (ex_y >= 0 && ex_y <= max_y_icons && (aicon == icon || !aicon)) {
2351 *ret_y = ex_y;
2354 return True;
2357 /* start looking at the upper slot or lower? */
2358 if (ex_y*ICON_SIZE < (req_y + offset - dy))
2359 sig = 1;
2360 else
2361 sig = -1;
2363 closest = -1;
2364 done = 0;
2365 /* look for closest free slot */
2366 for (i=0; i<(DOCK_DETTACH_THRESHOLD+1)*2 && !done; i++) {
2367 int j;
2369 done = 1;
2370 closest = sig*(i/2) + ex_y;
2371 /* check if this slot is used */
2372 if (closest >= 0) {
2373 for (j = 0; j<dock->max_icons; j++) {
2374 if (dock->icon_array[j]
2375 && dock->icon_array[j]->yindex==closest) {
2376 /* slot is used by someone else */
2377 if (dock->icon_array[j]!=icon)
2378 done = 0;
2379 break;
2383 sig = -sig;
2385 if (done && closest >= 0 && closest <= max_y_icons &&
2386 ((ex_y >= closest && ex_y - closest < DOCK_DETTACH_THRESHOLD+1)
2388 (ex_y < closest && closest - ex_y <= DOCK_DETTACH_THRESHOLD+1))) {
2390 *ret_y = closest;
2392 return True;
2394 } else { /* !redocking */
2396 /* if slot is free and the icon is close enough, return it */
2397 if (!aicon && ex_x == 0 && ex_y >= 0 && ex_y <= max_y_icons) {
2398 *ret_y = ex_y;
2399 return True;
2402 } else { /* CLIP */
2403 int neighbours = 0;
2405 for (i=0; i<dock->max_icons; i++) {
2406 nicon = dock->icon_array[i];
2407 if (nicon && nicon->xindex == ex_x && nicon->yindex == ex_y) {
2408 aicon = nicon;
2409 break;
2413 for (i=0; i<dock->max_icons; i++) {
2414 nicon = dock->icon_array[i];
2415 if (nicon && nicon != icon && /* Icon can't be it's own neighbour */
2416 (abs(nicon->xindex - ex_x) <= CLIP_ATTACH_VICINITY &&
2417 abs(nicon->yindex - ex_y) <= CLIP_ATTACH_VICINITY)) {
2418 neighbours = 1;
2419 break;
2423 if (neighbours && (aicon==NULL || (redocking && aicon == icon))) {
2424 *ret_x = ex_x;
2425 *ret_y = ex_y;
2426 return True;
2429 return False;
2432 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2433 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2435 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2436 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2437 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2441 * returns true if it can find a free slot in the dock,
2442 * in which case it changes x_pos and y_pos accordingly.
2443 * Else returns false.
2445 Bool
2446 wDockFindFreeSlot(WDock *dock, int *x_pos, int *y_pos)
2448 WScreen *scr = dock->screen_ptr;
2449 WAppIcon *btn;
2450 unsigned char *slot_map;
2451 int mwidth;
2452 int r;
2453 int x, y;
2454 int i, done = False;
2455 int corner;
2456 int sx=0, sy=0, ex=scr->scr_width, ey=scr->scr_height;
2459 /* if the dock is full */
2460 if (dock->icon_count >= dock->max_icons) {
2461 return False;
2464 if (!wPreferences.flags.nodock && scr->dock) {
2465 if (scr->dock->on_right_side)
2466 ex -= ICON_SIZE + DOCK_EXTRA_SPACE;
2467 else
2468 sx += ICON_SIZE + DOCK_EXTRA_SPACE;
2471 if (ex < dock->x_pos)
2472 ex = dock->x_pos;
2473 if (sx > dock->x_pos+ICON_SIZE)
2474 sx = dock->x_pos+ICON_SIZE;
2475 #define C_NONE 0
2476 #define C_NW 1
2477 #define C_NE 2
2478 #define C_SW 3
2479 #define C_SE 4
2481 /* check if clip is in a corner */
2482 if (dock->type==WM_CLIP) {
2483 if (dock->x_pos < 1 && dock->y_pos < 1)
2484 corner = C_NE;
2485 else if (dock->x_pos < 1 && dock->y_pos >= (ey-ICON_SIZE))
2486 corner = C_SE;
2487 else if (dock->x_pos >= (ex-ICON_SIZE)&& dock->y_pos >= (ey-ICON_SIZE))
2488 corner = C_SW;
2489 else if (dock->x_pos >= (ex-ICON_SIZE) && dock->y_pos < 1)
2490 corner = C_NW;
2491 else
2492 corner = C_NONE;
2493 } else
2494 corner = C_NONE;
2496 /* If the clip is in the corner, use only slots that are in the border
2497 * of the screen */
2498 if (corner!=C_NONE) {
2499 char *hmap, *vmap;
2500 int hcount, vcount;
2502 hcount = MIN(dock->max_icons, scr->scr_width/ICON_SIZE);
2503 vcount = MIN(dock->max_icons, scr->scr_height/ICON_SIZE);
2504 hmap = wmalloc(hcount+1);
2505 memset(hmap, 0, hcount+1);
2506 vmap = wmalloc(vcount+1);
2507 memset(vmap, 0, vcount+1);
2509 /* mark used positions */
2510 switch (corner) {
2511 case C_NE:
2512 for (i=0; i<dock->max_icons; i++) {
2513 btn = dock->icon_array[i];
2514 if (!btn)
2515 continue;
2517 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2518 vmap[btn->yindex] = 1;
2519 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2520 hmap[btn->xindex] = 1;
2522 case C_NW:
2523 for (i=0; i<dock->max_icons; i++) {
2524 btn = dock->icon_array[i];
2525 if (!btn)
2526 continue;
2528 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2529 vmap[btn->yindex] = 1;
2530 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2531 hmap[-btn->xindex] = 1;
2533 case C_SE:
2534 for (i=0; i<dock->max_icons; i++) {
2535 btn = dock->icon_array[i];
2536 if (!btn)
2537 continue;
2539 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2540 vmap[-btn->yindex] = 1;
2541 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2542 hmap[btn->xindex] = 1;
2544 case C_SW:
2545 default:
2546 for (i=0; i<dock->max_icons; i++) {
2547 btn = dock->icon_array[i];
2548 if (!btn)
2549 continue;
2551 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2552 vmap[-btn->yindex] = 1;
2553 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2554 hmap[-btn->xindex] = 1;
2557 x=0; y=0;
2558 done = 0;
2559 /* search a vacant slot */
2560 for (i=1; i<MAX(vcount, hcount); i++) {
2561 if (i < vcount && vmap[i]==0) {
2562 /* found a slot */
2563 x = 0;
2564 y = i;
2565 done = 1;
2566 break;
2567 } else if (i < hcount && hmap[i]==0) {
2568 /* found a slot */
2569 x = i;
2570 y = 0;
2571 done = 1;
2572 break;
2575 free(vmap);
2576 free(hmap);
2577 /* If found a slot, translate and return */
2578 if (done) {
2579 if (corner==C_NW || corner==C_NE) {
2580 *y_pos = y;
2581 } else {
2582 *y_pos = -y;
2584 if (corner==C_NE || corner==C_SE) {
2585 *x_pos = x;
2586 } else {
2587 *x_pos = -x;
2589 return True;
2591 /* else, try to find a slot somewhere else */
2594 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2595 * placed outside of screen */
2596 mwidth = (int)ceil(sqrt(dock->max_icons));
2598 /* In the worst case (the clip is in the corner of the screen),
2599 * the amount of icons that fit in the clip is smaller.
2600 * Double the map to get a safe value.
2602 mwidth += mwidth;
2604 r = (mwidth-1)/2;
2606 slot_map = wmalloc(mwidth*mwidth);
2607 memset(slot_map, 0, mwidth*mwidth);
2609 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2611 /* mark used slots in the map. If the slot falls outside the map
2612 * (for example, when all icons are placed in line), ignore them. */
2613 for (i=0; i<dock->max_icons; i++) {
2614 btn = dock->icon_array[i];
2615 if (btn)
2616 slot_map[XY2OFS(btn->xindex, btn->yindex)] = 1;
2618 /* Find closest slot from the center that is free by scanning the
2619 * map from the center to outward in circular passes.
2620 * This will not result in a neat layout, but will be optimal
2621 * in the sense that there will not be holes left.
2623 done = 0;
2624 for (i = 1; i <= r && !done; i++) {
2625 int tx, ty;
2627 /* top and bottom parts of the ring */
2628 for (x = -i; x <= i && !done; x++) {
2629 tx = dock->x_pos + x*ICON_SIZE;
2630 y = -i;
2631 ty = dock->y_pos + y*ICON_SIZE;
2632 if (slot_map[XY2OFS(x,y)]==0
2633 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2634 *x_pos = x;
2635 *y_pos = y;
2636 done = 1;
2637 break;
2639 y = i;
2640 ty = dock->y_pos + y*ICON_SIZE;
2641 if (slot_map[XY2OFS(x,y)]==0
2642 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2643 *x_pos = x;
2644 *y_pos = y;
2645 done = 1;
2646 break;
2649 /* left and right parts of the ring */
2650 for (y = -i+1; y <= i-1; y++) {
2651 ty = dock->y_pos + y*ICON_SIZE;
2652 x = -i;
2653 tx = dock->x_pos + x*ICON_SIZE;
2654 if (slot_map[XY2OFS(x,y)]==0
2655 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2656 *x_pos = x;
2657 *y_pos = y;
2658 done = 1;
2659 break;
2661 x = i;
2662 tx = dock->x_pos + x*ICON_SIZE;
2663 if (slot_map[XY2OFS(x,y)]==0
2664 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2665 *x_pos = x;
2666 *y_pos = y;
2667 done = 1;
2668 break;
2672 free(slot_map);
2673 #undef XY2OFS
2674 return done;
2678 static void
2679 moveDock(WDock *dock, int new_x, int new_y)
2681 WAppIcon *btn;
2682 int i;
2684 dock->x_pos = new_x;
2685 dock->y_pos = new_y;
2686 for (i=0; i<dock->max_icons; i++) {
2687 btn = dock->icon_array[i];
2688 if (btn) {
2689 btn->x_pos = new_x + btn->xindex*ICON_SIZE;
2690 btn->y_pos = new_y + btn->yindex*ICON_SIZE;
2691 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2697 static void
2698 swapDock(WDock *dock)
2700 WScreen *scr = dock->screen_ptr;
2701 WAppIcon *btn;
2702 int x, i;
2705 if (dock->on_right_side) {
2706 x = dock->x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
2707 } else {
2708 x = dock->x_pos = DOCK_EXTRA_SPACE;
2711 for (i=0; i<dock->max_icons; i++) {
2712 btn = dock->icon_array[i];
2713 if (btn) {
2714 btn->x_pos = x;
2715 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2719 wScreenUpdateUsableArea(scr);
2723 static pid_t
2724 execCommand(WAppIcon *btn, char *command, WSavedState *state)
2726 WScreen *scr = btn->icon->core->screen_ptr;
2727 pid_t pid;
2728 char **argv;
2729 int argc;
2730 char *cmdline;
2732 cmdline = ExpandOptions(scr, command);
2734 if (scr->flags.dnd_data_convertion_status || !cmdline) {
2735 if (cmdline)
2736 free(cmdline);
2737 if (state)
2738 free(state);
2739 return 0;
2742 ParseCommand(cmdline, &argv, &argc);
2744 if (argv==NULL) {
2745 if (cmdline)
2746 free(cmdline);
2747 if (state)
2748 free(state);
2749 return 0;
2752 if ((pid=fork())==0) {
2753 char **args;
2754 int i;
2756 SetupEnvironment(scr);
2758 #ifdef HAVE_SETPGID
2759 setpgid(0, 0);
2760 #endif
2762 args = malloc(sizeof(char*)*(argc+1));
2763 if (!args)
2764 exit(111);
2765 for (i=0; i<argc; i++) {
2766 args[i] = argv[i];
2768 args[argc] = NULL;
2769 execvp(argv[0], args);
2770 exit(111);
2772 while (argc > 0)
2773 free(argv[--argc]);
2774 free(argv);
2776 if (pid > 0) {
2777 if (!state) {
2778 state = wmalloc(sizeof(WSavedState));
2779 memset(state, 0, sizeof(WSavedState));
2780 state->hidden = -1;
2781 state->miniaturized = -1;
2782 state->shaded = -1;
2783 if (btn->dock == scr->dock)
2784 state->workspace = -1;
2785 else
2786 state->workspace = scr->current_workspace;
2788 wWindowAddSavedState(btn->wm_instance, btn->wm_class, cmdline, pid,
2789 state);
2790 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess,
2791 btn->dock);
2792 } else if (state) {
2793 free(state);
2795 free(cmdline);
2796 return pid;
2800 void
2801 wDockHideIcons(WDock *dock)
2803 int i;
2804 WAppIcon *btn;
2806 if (dock==NULL)
2807 return;
2809 btn = dock->icon_array[0];
2811 for (i=1; i<dock->max_icons; i++) {
2812 if (dock->icon_array[i])
2813 XUnmapWindow(dpy, dock->icon_array[i]->icon->core->window);
2815 dock->mapped = 0;
2817 dockIconPaint(btn);
2821 void
2822 wDockShowIcons(WDock *dock)
2824 int i, newlevel;
2825 WAppIcon *btn;
2827 if (dock==NULL)
2828 return;
2830 btn = dock->icon_array[0];
2831 moveDock(dock, btn->x_pos, btn->y_pos);
2833 newlevel = dock->lowered ? WMNormalLevel : WMDockLevel;
2834 ChangeStackingLevel(btn->icon->core, newlevel);
2836 for (i=1; i<dock->max_icons; i++) {
2837 if (dock->icon_array[i]) {
2838 MoveInStackListAbove(dock->icon_array[i]->icon->core,
2839 btn->icon->core);
2840 break;
2844 if (!dock->collapsed) {
2845 for (i=1; i<dock->max_icons; i++) {
2846 if (dock->icon_array[i]) {
2847 XMapWindow(dpy, dock->icon_array[i]->icon->core->window);
2851 dock->mapped = 1;
2853 dockIconPaint(btn);
2857 void
2858 wDockLower(WDock *dock)
2860 int i;
2862 for (i=0; i<dock->max_icons; i++) {
2863 if (dock->icon_array[i])
2864 wLowerFrame(dock->icon_array[i]->icon->core);
2869 void
2870 wDockRaise(WDock *dock)
2872 int i;
2874 for (i=dock->max_icons-1; i>=0; i--) {
2875 if (dock->icon_array[i])
2876 wRaiseFrame(dock->icon_array[i]->icon->core);
2881 void
2882 wDockRaiseLower(WDock *dock)
2884 if (!dock->icon_array[0]->icon->core->stacking->above
2885 ||(dock->icon_array[0]->icon->core->stacking->window_level
2886 !=dock->icon_array[0]->icon->core->stacking->above->stacking->window_level))
2887 wDockLower(dock);
2888 else
2889 wDockRaise(dock);
2893 void
2894 wDockFinishLaunch(WDock *dock, WAppIcon *icon)
2896 icon->launching = 0;
2897 icon->relaunching = 0;
2898 dockIconPaint(icon);
2902 WAppIcon*
2903 wDockFindIconFor(WDock *dock, Window window)
2905 WAppIcon *icon;
2906 int i;
2908 for (i=0; i<dock->max_icons; i++) {
2909 icon = dock->icon_array[i];
2910 if (icon && icon->main_window == window)
2911 return icon;
2913 return NULL;
2917 void
2918 wDockTrackWindowLaunch(WDock *dock, Window window)
2920 WAppIcon *icon;
2921 #ifdef REDUCE_APPICONS
2922 WAppIconAppList *tapplist;
2923 #endif
2924 char *wm_class, *wm_instance;
2925 int i;
2926 Bool firstPass = True;
2927 Bool found = False;
2928 char *command = NULL;
2931 int argc;
2932 char **argv;
2934 if (XGetCommand(dpy, window, &argv, &argc)) {
2935 if (argc > 0 && argv != NULL)
2936 command = FlattenStringList(argv,argc);
2937 if (argv) {
2938 XFreeStringList(argv);
2943 if (!PropGetWMClass(window, &wm_class, &wm_instance) ||
2944 (!wm_class && !wm_instance))
2945 return;
2947 retry:
2948 for (i=0; i<dock->max_icons; i++) {
2949 icon = dock->icon_array[i];
2950 if (!icon)
2951 continue;
2953 /* app is already attached to icon */
2954 if (icon->main_window == window) {
2955 found = True;
2956 break;
2959 if ((icon->wm_instance || icon->wm_class)
2960 && (icon->launching
2961 || (dock->screen_ptr->flags.startup && !icon->running))) {
2963 if (icon->wm_instance && wm_instance &&
2964 strcmp(icon->wm_instance, wm_instance)!=0) {
2965 continue;
2967 if (icon->wm_class && wm_class &&
2968 strcmp(icon->wm_class, wm_class)!=0) {
2969 continue;
2971 if (firstPass && command && strcmp(icon->command, command)!=0) {
2972 continue;
2975 if (!icon->relaunching) {
2976 WApplication *wapp;
2978 /* Possibly an application that was docked with dockit,
2979 * but the user did not update WMState to indicate that
2980 * it was docked by force */
2981 wapp = wApplicationOf(window);
2982 if (!wapp) {
2983 icon->forced_dock = 1;
2984 icon->running = 0;
2986 if (!icon->forced_dock)
2987 icon->main_window = window;
2989 #ifdef REDUCE_APPICONS
2990 tapplist = wmalloc(sizeof(WAppIconAppList));
2991 memset(tapplist, 0, sizeof(WAppIconAppList));
2992 tapplist->next = icon->applist;
2993 if (icon->applist)
2994 icon->applist->prev = tapplist;
2995 icon->applist = tapplist;
2996 tapplist->wapp = wApplicationOf(window);
2997 icon->num_apps++;
2998 #endif
3000 found = True;
3001 wDockFinishLaunch(dock, icon);
3002 break;
3006 if (firstPass && !found) {
3007 firstPass = False;
3008 goto retry;
3011 if (command)
3012 free(command);
3014 if (wm_class)
3015 XFree(wm_class);
3016 if (wm_instance)
3017 XFree(wm_instance);
3022 void
3023 wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
3025 if (!wPreferences.flags.noclip) {
3026 scr->clip_icon->dock = scr->workspaces[workspace]->clip;
3027 if (scr->current_workspace != workspace) {
3028 WDock *old_clip = scr->workspaces[scr->current_workspace]->clip;
3030 wDockHideIcons(old_clip);
3031 if (old_clip->auto_raise_lower)
3032 wDockLower(old_clip);
3033 if (old_clip->auto_collapse && !old_clip->collapsed)
3034 old_clip->collapsed = 1;
3035 wDockShowIcons(scr->workspaces[workspace]->clip);
3037 if (scr->flags.clip_balloon_mapped)
3038 showClipBalloon(scr->clip_icon->dock, workspace);
3044 static void
3045 trackDeadProcess(pid_t pid, unsigned char status, WDock *dock)
3047 WAppIcon *icon;
3048 int i;
3050 for (i=0; i<dock->max_icons; i++) {
3051 icon = dock->icon_array[i];
3052 if (!icon)
3053 continue;
3055 if (icon->launching && icon->pid == pid) {
3056 if (!icon->relaunching) {
3057 icon->running = 0;
3058 icon->main_window = None;
3060 wDockFinishLaunch(dock, icon);
3061 icon->pid = 0;
3062 if (status==111) {
3063 char msg[PATH_MAX];
3064 #ifdef OFFIX_DND
3065 sprintf(msg, _("Could not execute command \"%s\""),
3066 icon->drop_launch && icon->dnd_command
3067 ? icon->dnd_command : icon->command);
3068 #else
3069 sprintf(msg, _("Could not execute command \"%s\""),
3070 icon->command);
3071 #endif
3072 wMessageDialog(dock->screen_ptr, _("Error"), msg,
3073 _("OK"), NULL, NULL);
3075 break;
3081 static void
3082 toggleLowered(WDock *dock)
3084 WAppIcon *tmp;
3085 int newlevel, i;
3087 /* lower/raise Dock */
3088 if (!dock->lowered) {
3089 newlevel = WMNormalLevel;
3090 dock->lowered = 1;
3091 } else {
3092 newlevel = WMDockLevel;
3093 dock->lowered = 0;
3096 for (i=0; i<dock->max_icons; i++) {
3097 tmp = dock->icon_array[i];
3098 if (!tmp)
3099 continue;
3101 ChangeStackingLevel(tmp->icon->core, newlevel);
3102 if (dock->lowered)
3103 wLowerFrame(tmp->icon->core);
3106 if (dock->type == WM_DOCK)
3107 wScreenUpdateUsableArea(dock->screen_ptr);
3111 static void
3112 toggleCollapsed(WDock *dock)
3114 if (dock->collapsed) {
3115 dock->collapsed = 0;
3116 wDockShowIcons(dock);
3118 else {
3119 dock->collapsed = 1;
3120 wDockHideIcons(dock);
3125 static void
3126 openDockMenu(WDock *dock, WAppIcon *aicon, XEvent *event)
3128 WScreen *scr = dock->screen_ptr;
3129 WObjDescriptor *desc;
3130 WMenuEntry *entry;
3131 WApplication *wapp = NULL;
3132 int index = 0;
3133 int x_pos;
3134 int appIsRunning = aicon->running && aicon->icon && aicon->icon->owner;
3136 if (dock->type == WM_DOCK) {
3137 /* keep on top */
3138 entry = dock->menu->entries[index];
3139 entry->flags.indicator_on = !dock->lowered;
3140 entry->clientdata = dock;
3141 } else {
3142 /* clip options */
3143 if (scr->clip_options)
3144 updateClipOptionsMenu(scr->clip_options, dock);
3146 /* Rename Workspace */
3147 entry = dock->menu->entries[++index];
3148 entry->clientdata = dock;
3150 /* select icon */
3151 entry = dock->menu->entries[++index];
3152 entry->clientdata = aicon;
3153 wMenuSetEnabled(dock->menu, index, aicon!=scr->clip_icon);
3155 /* (un)select all icons */
3156 entry = dock->menu->entries[++index];
3157 entry->clientdata = aicon;
3158 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3160 /* keep icon(s) */
3161 entry = dock->menu->entries[++index];
3162 entry->clientdata = aicon;
3163 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3165 /* this is the workspace submenu part */
3166 if (scr->clip_submenu)
3167 updateWorkspaceMenu(scr->clip_submenu, aicon);
3168 index++;
3170 /* remove icon(s) */
3171 entry = dock->menu->entries[++index];
3172 entry->clientdata = aicon;
3173 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3175 /* attract icon(s) */
3176 entry = dock->menu->entries[++index];
3177 entry->clientdata = aicon;
3180 /* launch */
3181 entry = dock->menu->entries[++index];
3182 entry->clientdata = aicon;
3183 wMenuSetEnabled(dock->menu, index, aicon->command!=NULL);
3185 /* unhide here */
3186 entry = dock->menu->entries[++index];
3187 entry->clientdata = aicon;
3188 wMenuSetEnabled(dock->menu, index, appIsRunning);
3190 /* hide */
3191 entry = dock->menu->entries[++index];
3192 entry->clientdata = aicon;
3193 if (aicon->icon->owner) {
3194 wapp = wApplicationOf(aicon->icon->owner->main_window);
3195 if (wapp && wapp->flags.hidden)
3196 entry->text = _("Unhide");
3197 else
3198 entry->text = _("Hide");
3199 } else {
3200 entry->text = _("Hide");
3202 wMenuSetEnabled(dock->menu, index, appIsRunning);
3204 /* settings */
3205 entry = dock->menu->entries[++index];
3206 entry->clientdata = aicon;
3207 wMenuSetEnabled(dock->menu, index, !aicon->editing
3208 && !wPreferences.flags.noupdates);
3210 /* kill */
3211 entry = dock->menu->entries[++index];
3212 entry->clientdata = aicon;
3213 wMenuSetEnabled(dock->menu, index, appIsRunning);
3215 if (!dock->menu->flags.realized)
3216 wMenuRealize(dock->menu);
3218 if (dock->type == WM_CLIP) {
3219 x_pos = event->xbutton.x_root+2;
3220 } else {
3221 x_pos = dock->on_right_side ?
3222 scr->scr_width - dock->menu->frame->core->width - 2 : 0;
3225 wMenuMapAt(dock->menu, x_pos, event->xbutton.y_root+2, False);
3227 /* allow drag select */
3228 event->xany.send_event = True;
3229 desc = &dock->menu->menu->descriptor;
3230 (*desc->handle_mousedown)(desc, event);
3234 static void
3235 openClipWorkspaceMenu(WScreen *scr, int x, int y)
3237 if (!scr->clip_ws_menu) {
3238 scr->clip_ws_menu = wWorkspaceMenuMake(scr, False);
3240 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
3241 wMenuMapAt(scr->clip_ws_menu, x, y, False);
3245 /******************************************************************/
3246 static void
3247 iconDblClick(WObjDescriptor *desc, XEvent *event)
3249 WAppIcon *btn = desc->parent;
3250 WDock *dock = btn->dock;
3251 WApplication *wapp = NULL;
3252 int unhideHere = 0;
3254 #ifdef REDUCE_APPICONS
3255 if ((btn->icon->owner && !(event->xbutton.state & ControlMask)) ||
3256 ((btn->icon->owner == NULL) && (btn->applist != NULL))) {
3257 if (btn->icon->owner == NULL)
3258 btn->icon->owner = btn->applist->wapp->main_window_desc;
3259 #ifdef I_HATE_THIS
3261 #endif
3262 #else
3263 if (btn->icon->owner && !(event->xbutton.state & ControlMask)) {
3264 #endif
3265 wapp = wApplicationOf(btn->icon->owner->main_window);
3267 assert(wapp!=NULL);
3269 unhideHere = (event->xbutton.state & ShiftMask);
3271 /* go to the last workspace that the user worked on the app */
3272 if (!unhideHere) {
3273 wWorkspaceChange(dock->screen_ptr, wapp->last_workspace);
3276 wUnhideApplication(wapp, event->xbutton.button==Button2,
3277 unhideHere);
3279 if (event->xbutton.state & MOD_MASK) {
3280 wHideOtherApplications(btn->icon->owner);
3282 } else {
3283 if (event->xbutton.button==Button1) {
3285 if (event->xbutton.state & MOD_MASK) {
3286 /* raise/lower dock */
3287 toggleLowered(dock);
3288 } else if (btn == dock->screen_ptr->clip_icon) {
3289 if (getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE)
3290 toggleCollapsed(dock);
3291 else
3292 handleClipChangeWorkspace(dock->screen_ptr, event);
3293 } else if (btn->command) {
3294 if (!btn->launching &&
3295 (!btn->running || (event->xbutton.state & ControlMask))) {
3296 launchDockedApplication(btn);
3304 static void
3305 handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3307 WScreen *scr = dock->screen_ptr;
3308 int ofs_x=event->xbutton.x, ofs_y=event->xbutton.y;
3309 int x, y;
3310 XEvent ev;
3311 int grabbed = 0, swapped = 0, done;
3312 Pixmap ghost = None;
3313 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3315 #ifdef DEBUG
3316 puts("moving dock");
3317 #endif
3318 if (XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
3319 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3320 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3321 wwarning("pointer grab failed for dock move");
3323 y = 0;
3324 for (x=0; x<dock->max_icons; x++) {
3325 if (dock->icon_array[x]!=NULL &&
3326 dock->icon_array[x]->yindex > y)
3327 y = dock->icon_array[x]->yindex;
3329 y++;
3330 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE*y);
3332 done = 0;
3333 while (!done) {
3334 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3335 |ButtonMotionMask|ExposureMask, &ev);
3336 switch (ev.type) {
3337 case Expose:
3338 WMHandleEvent(&ev);
3339 break;
3341 case MotionNotify:
3342 if (!grabbed) {
3343 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3344 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3345 XChangeActivePointerGrab(dpy, ButtonMotionMask
3346 |ButtonReleaseMask|ButtonPressMask,
3347 wCursor[WCUR_MOVE], CurrentTime);
3348 grabbed=1;
3350 break;
3352 if (dock->type == WM_CLIP) {
3353 if (ev.xmotion.x_root - ofs_x < 0) {
3354 x = 0;
3355 } else if (ev.xmotion.x_root - ofs_x + ICON_SIZE >
3356 scr->scr_width) {
3357 x = scr->scr_width - ICON_SIZE;
3358 } else {
3359 x = ev.xmotion.x_root - ofs_x;
3361 if (ev.xmotion.y_root - ofs_y < 0) {
3362 y = 0;
3363 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3364 scr->scr_height) {
3365 y = scr->scr_height - ICON_SIZE;
3366 } else {
3367 y = ev.xmotion.y_root - ofs_y;
3369 moveDock(dock, x, y);
3370 } else {
3371 /* move vertically if pointer is inside the dock*/
3372 if ((dock->on_right_side &&
3373 ev.xmotion.x_root >= dock->x_pos - ICON_SIZE)
3374 || (!dock->on_right_side &&
3375 ev.xmotion.x_root <= dock->x_pos + ICON_SIZE*2)) {
3377 if (ev.xmotion.y_root - ofs_y < 0) {
3378 y = 0;
3379 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3380 scr->scr_height) {
3381 y = scr->scr_height - ICON_SIZE;
3382 } else {
3383 y = ev.xmotion.y_root - ofs_y;
3385 moveDock(dock, dock->x_pos, y);
3387 /* move horizontally to change sides */
3388 x = ev.xmotion.x_root - ofs_x;
3389 if (!dock->on_right_side) {
3391 /* is on left */
3393 if (ev.xmotion.x_root > dock->x_pos + ICON_SIZE*2) {
3394 XMoveWindow(dpy, scr->dock_shadow, scr->scr_width-ICON_SIZE
3395 -DOCK_EXTRA_SPACE-1, dock->y_pos);
3396 if (superfluous) {
3397 if (ghost==None) {
3398 ghost = MakeGhostDock(dock, dock->x_pos,
3399 scr->scr_width-ICON_SIZE
3400 -DOCK_EXTRA_SPACE-1,
3401 dock->y_pos);
3402 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3403 ghost);
3404 XClearWindow(dpy, scr->dock_shadow);
3407 XMapRaised(dpy, scr->dock_shadow);
3408 swapped = 1;
3409 } else {
3410 if (superfluous && ghost!=None) {
3411 XFreePixmap(dpy, ghost);
3412 ghost = None;
3414 XUnmapWindow(dpy, scr->dock_shadow);
3415 swapped = 0;
3417 } else {
3418 /* is on right */
3419 if (ev.xmotion.x_root < dock->x_pos - ICON_SIZE) {
3420 XMoveWindow(dpy, scr->dock_shadow,
3421 DOCK_EXTRA_SPACE, dock->y_pos);
3422 if (superfluous) {
3423 if (ghost==None) {
3424 ghost = MakeGhostDock(dock, dock->x_pos,
3425 DOCK_EXTRA_SPACE, dock->y_pos);
3426 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3427 ghost);
3428 XClearWindow(dpy, scr->dock_shadow);
3431 XMapRaised(dpy, scr->dock_shadow);
3432 swapped = -1;
3433 } else {
3434 XUnmapWindow(dpy, scr->dock_shadow);
3435 swapped = 0;
3436 if (superfluous && ghost!=None) {
3437 XFreePixmap(dpy, ghost);
3438 ghost = None;
3443 break;
3445 case ButtonPress:
3446 break;
3448 case ButtonRelease:
3449 if (ev.xbutton.button != event->xbutton.button)
3450 break;
3451 XUngrabPointer(dpy, CurrentTime);
3452 XUnmapWindow(dpy, scr->dock_shadow);
3453 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE);
3454 if (dock->type == WM_DOCK) {
3455 if (swapped!=0) {
3456 if (swapped>0)
3457 dock->on_right_side = 1;
3458 else
3459 dock->on_right_side = 0;
3460 swapDock(dock);
3461 wArrangeIcons(scr, False);
3464 done = 1;
3465 break;
3468 if (superfluous) {
3469 if (ghost!=None)
3470 XFreePixmap(dpy, ghost);
3471 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3473 #ifdef DEBUG
3474 puts("End dock move");
3475 #endif
3480 static void
3481 handleIconMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3483 WScreen *scr = dock->screen_ptr;
3484 Window wins[2];
3485 WIcon *icon = aicon->icon;
3486 WDock *dock2 = NULL, *last_dock = dock, *clip = NULL;
3487 int ondock, grabbed = 0, change_dock = 0, collapsed = 0;
3488 XEvent ev;
3489 int x = aicon->x_pos, y = aicon->y_pos;
3490 int ofs_x = event->xbutton.x, ofs_y = event->xbutton.y;
3491 int shad_x = x, shad_y = y;
3492 int ix = aicon->xindex, iy = aicon->yindex;
3493 int tmp;
3494 Pixmap ghost = None;
3495 Bool docked;
3496 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3498 if (wPreferences.flags.noupdates)
3499 return;
3501 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
3502 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3503 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3504 #ifdef DEBUG0
3505 wwarning("pointer grab failed for icon move");
3506 #endif
3509 wRaiseFrame(icon->core);
3511 if (!wPreferences.flags.noclip)
3512 clip = scr->workspaces[scr->current_workspace]->clip;
3514 if (dock == scr->dock && !wPreferences.flags.noclip)
3515 dock2 = clip;
3516 else if (dock != scr->dock && !wPreferences.flags.nodock)
3517 dock2 = scr->dock;
3519 wins[0] = icon->core->window;
3520 wins[1] = scr->dock_shadow;
3521 XRestackWindows(dpy, wins, 2);
3522 XMoveResizeWindow(dpy, scr->dock_shadow, aicon->x_pos, aicon->y_pos,
3523 ICON_SIZE, ICON_SIZE);
3524 if (superfluous) {
3525 if (icon->pixmap!=None)
3526 ghost = MakeGhostIcon(scr, icon->pixmap);
3527 else
3528 ghost = MakeGhostIcon(scr, icon->core->window);
3530 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow, ghost);
3531 XClearWindow(dpy, scr->dock_shadow);
3533 XMapWindow(dpy, scr->dock_shadow);
3535 ondock = 1;
3538 while(1) {
3539 XMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3540 |ButtonMotionMask|ExposureMask, &ev);
3541 switch (ev.type) {
3542 case Expose:
3543 WMHandleEvent(&ev);
3544 break;
3546 case MotionNotify:
3547 if (!grabbed) {
3548 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3549 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3550 XChangeActivePointerGrab(dpy, ButtonMotionMask
3551 |ButtonReleaseMask|ButtonPressMask,
3552 wCursor[WCUR_MOVE], CurrentTime);
3553 grabbed=1;
3554 } else {
3555 break;
3559 x = ev.xmotion.x_root - ofs_x;
3560 y = ev.xmotion.y_root - ofs_y;
3561 tmp = wDockSnapIcon(dock, aicon, x, y, &ix, &iy, True);
3562 if (tmp && dock2) {
3563 change_dock = 0;
3564 if (last_dock != dock && collapsed) {
3565 last_dock->collapsed = 1;
3566 wDockHideIcons(last_dock);
3567 collapsed = 0;
3569 if (!collapsed && (collapsed = dock->collapsed)) {
3570 dock->collapsed = 0;
3571 wDockShowIcons(dock);
3573 if (dock->auto_raise_lower)
3574 wDockRaise(dock);
3575 last_dock = dock;
3577 else if (dock2) {
3578 tmp = wDockSnapIcon(dock2, aicon, x, y, &ix, &iy, False);
3579 if (tmp) {
3580 change_dock = 1;
3581 if (last_dock != dock2 && collapsed) {
3582 last_dock->collapsed = 1;
3583 wDockHideIcons(last_dock);
3584 collapsed = 0;
3586 if (!collapsed && (collapsed = dock2->collapsed)) {
3587 dock2->collapsed = 0;
3588 wDockShowIcons(dock2);
3590 if (dock2->auto_raise_lower)
3591 wDockRaise(dock2);
3592 last_dock = dock2;
3595 if (aicon->launching
3596 || (aicon->running && !(ev.xmotion.state & MOD_MASK))
3597 || (!aicon->running && tmp)) {
3598 shad_x = last_dock->x_pos + ix*wPreferences.icon_size;
3599 shad_y = last_dock->y_pos + iy*wPreferences.icon_size;
3601 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
3603 if (!ondock) {
3604 XMapWindow(dpy, scr->dock_shadow);
3605 #if 0
3606 if (!collapsed && (collapsed = last_dock->collapsed)) {
3607 last_dock->collapsed = 0;
3608 wDockShowIcons(last_dock);
3610 #endif
3612 ondock = 1;
3613 } else {
3614 if (ondock) {
3615 XUnmapWindow(dpy, scr->dock_shadow);
3616 #if 0
3617 if (last_dock && collapsed &&
3618 aicon->running && (ev.xmotion.state & MOD_MASK)) {
3619 last_dock->collapsed = 1;
3620 wDockHideIcons(last_dock);
3621 collapsed = 0;
3623 #endif
3625 ondock = 0;
3627 XMoveWindow(dpy, icon->core->window, x, y);
3628 break;
3630 case ButtonPress:
3631 break;
3633 case ButtonRelease:
3634 if (ev.xbutton.button != event->xbutton.button)
3635 break;
3636 XUngrabPointer(dpy, CurrentTime);
3637 if (ondock) {
3638 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
3639 XUnmapWindow(dpy, scr->dock_shadow);
3640 if (!change_dock) {
3641 reattachIcon(dock, aicon, ix, iy);
3642 if (clip && dock!=clip && clip->auto_raise_lower)
3643 wDockLower(clip);
3644 } else {
3645 docked = moveIconBetweenDocks(dock, dock2, aicon, ix, iy);
3646 if (!docked) {
3647 /* Slide it back if dock rejected it */
3648 SlideWindow(icon->core->window, x, y, aicon->x_pos,
3649 aicon->y_pos);
3650 reattachIcon(dock, aicon, aicon->xindex,aicon->yindex);
3652 if (last_dock->type==WM_CLIP && last_dock->auto_collapse) {
3653 collapsed = 0;
3656 } else {
3657 aicon->x_pos = x;
3658 aicon->y_pos = y;
3659 if (superfluous) {
3660 if (!aicon->running && !wPreferences.no_animations) {
3661 /* We need to deselect it, even if is deselected in
3662 * wDockDetach(), because else DoKaboom() will fail.
3664 if (aicon->icon->selected)
3665 wIconSelect(aicon->icon);
3666 DoKaboom(scr,aicon->icon->core->window, x, y);
3669 if (clip && clip->auto_raise_lower)
3670 wDockLower(clip);
3671 wDockDetach(dock, aicon);
3673 if (collapsed) {
3674 last_dock->collapsed = 1;
3675 wDockHideIcons(last_dock);
3676 collapsed = 0;
3678 if (superfluous) {
3679 if (ghost!=None)
3680 XFreePixmap(dpy, ghost);
3681 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3683 #ifdef DEBUG
3684 puts("End icon move");
3685 #endif
3686 return;
3692 static int
3693 getClipButton(int px, int py)
3695 int pt = (CLIP_BUTTON_SIZE+2)*ICON_SIZE/64;
3697 if (px < 0 || py < 0 || px >= ICON_SIZE || py >= ICON_SIZE)
3698 return CLIP_IDLE;
3700 if (py <= pt-((int)ICON_SIZE-1-px))
3701 return CLIP_FORWARD;
3702 else if (px <= pt-((int)ICON_SIZE-1-py))
3703 return CLIP_REWIND;
3705 return CLIP_IDLE;
3709 static void
3710 handleClipChangeWorkspace(WScreen *scr, XEvent *event)
3712 XEvent ev;
3713 int done, direction, new_ws;
3714 int new_dir;
3715 WDock *clip = scr->clip_icon->dock;
3717 direction = getClipButton(event->xbutton.x, event->xbutton.y);
3719 clip->lclip_button_pushed = direction==CLIP_REWIND;
3720 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3722 wClipIconPaint(scr->clip_icon);
3723 done = 0;
3724 while(!done) {
3725 WMMaskEvent(dpy, ExposureMask|ButtonMotionMask|ButtonReleaseMask
3726 |ButtonPressMask, &ev);
3727 switch (ev.type) {
3728 case Expose:
3729 WMHandleEvent(&ev);
3730 break;
3732 case MotionNotify:
3733 new_dir = getClipButton(ev.xmotion.x, ev.xmotion.y);
3734 if (new_dir != direction) {
3735 direction = new_dir;
3736 clip->lclip_button_pushed = direction==CLIP_REWIND;
3737 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3738 wClipIconPaint(scr->clip_icon);
3740 break;
3742 case ButtonPress:
3743 break;
3745 case ButtonRelease:
3746 if (ev.xbutton.button == event->xbutton.button)
3747 done = 1;
3751 clip->lclip_button_pushed = 0;
3752 clip->rclip_button_pushed = 0;
3754 new_ws = wPreferences.ws_advance || (event->xbutton.state & ControlMask);
3756 if (direction == CLIP_FORWARD) {
3757 if (scr->current_workspace < scr->workspace_count-1)
3758 wWorkspaceChange(scr, scr->current_workspace+1);
3759 else if (new_ws && scr->current_workspace < MAX_WORKSPACES-1)
3760 wWorkspaceChange(scr, scr->current_workspace+1);
3761 else if (wPreferences.ws_cycle)
3762 wWorkspaceChange(scr, 0);
3764 else if (direction == CLIP_REWIND) {
3765 if (scr->current_workspace > 0)
3766 wWorkspaceChange(scr, scr->current_workspace-1);
3767 else if (scr->current_workspace==0 && wPreferences.ws_cycle)
3768 wWorkspaceChange(scr, scr->workspace_count-1);
3771 wClipIconPaint(scr->clip_icon);
3775 static void
3776 iconMouseDown(WObjDescriptor *desc, XEvent *event)
3778 WAppIcon *aicon = desc->parent;
3779 WDock *dock = aicon->dock;
3780 WScreen *scr = aicon->icon->core->screen_ptr;
3782 if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
3783 return;
3785 scr->last_dock = dock;
3787 if (dock->menu->flags.mapped)
3788 wMenuUnmap(dock->menu);
3790 if (IsDoubleClick(scr, event)) {
3791 /* double-click was not in the main clip icon */
3792 if (dock->type != WM_CLIP || aicon->xindex!=0 || aicon->yindex!=0
3793 || getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE) {
3794 iconDblClick(desc, event);
3795 return;
3799 if (dock->type == WM_CLIP && scr->flags.clip_balloon_mapped) {
3800 XUnmapWindow(dpy, scr->clip_balloon);
3801 scr->flags.clip_balloon_mapped = 0;
3804 #ifdef DEBUG
3805 puts("handling dock");
3806 #endif
3807 if (event->xbutton.button == Button1) {
3808 if (event->xbutton.state & MOD_MASK)
3809 wDockLower(dock);
3810 else
3811 wDockRaise(dock);
3813 if ((event->xbutton.state & ShiftMask) && aicon!=scr->clip_icon &&
3814 dock->type!=WM_DOCK) {
3815 wIconSelect(aicon->icon);
3816 return;
3819 if (aicon->yindex==0 && aicon->xindex==0) {
3820 if (getClipButton(event->xbutton.x, event->xbutton.y)!=CLIP_IDLE
3821 && dock->type==WM_CLIP)
3822 handleClipChangeWorkspace(scr, event);
3823 else
3824 handleDockMove(dock, aicon, event);
3825 } else
3826 handleIconMove(dock, aicon, event);
3828 } else if (event->xbutton.button==Button2 && dock->type==WM_CLIP &&
3829 aicon->xindex==0 && aicon->yindex==0) {
3830 openClipWorkspaceMenu(scr, event->xbutton.x_root+2,
3831 event->xbutton.y_root+2);
3832 if (scr->clip_ws_menu) {
3833 WMenu *menu;
3834 menu = scr->clip_ws_menu;
3835 desc = &menu->menu->descriptor;
3837 event->xany.send_event = True;
3838 (*desc->handle_mousedown)(desc, event);
3840 } else if (event->xbutton.button == Button3) {
3841 openDockMenu(dock, aicon, event);
3846 static void
3847 showClipBalloon(WDock *dock, int workspace)
3849 int w, h;
3850 int x, y;
3851 WScreen *scr = dock->screen_ptr;
3852 char *text;
3853 Window stack[2];
3855 scr->flags.clip_balloon_mapped = 1;
3856 XMapWindow(dpy, scr->clip_balloon);
3858 text = scr->workspaces[workspace]->name;
3860 w = wTextWidth(scr->clip_title_font->font, text, strlen(text));
3862 h = scr->clip_title_font->height;
3863 XResizeWindow(dpy, scr->clip_balloon, w, h);
3865 x = dock->x_pos + CLIP_BUTTON_SIZE*ICON_SIZE/64;
3866 y = dock->y_pos + ICON_SIZE-scr->clip_title_font->height - 3;
3868 if (x+w > scr->scr_width) {
3869 x = scr->scr_width - w;
3870 if (dock->y_pos + ICON_SIZE + h > scr->scr_height)
3871 y = dock->y_pos - h - 1;
3872 else
3873 y = dock->y_pos + ICON_SIZE;
3874 XRaiseWindow(dpy, scr->clip_balloon);
3875 } else {
3876 stack[0] = scr->clip_icon->icon->core->window;
3877 stack[1] = scr->clip_balloon;
3878 XRestackWindows(dpy, stack, 2);
3880 XMoveWindow(dpy, scr->clip_balloon, x, y);
3881 XSetForeground(dpy, scr->clip_title_gc,
3882 scr->clip_title_pixel[CLIP_NORMAL]);
3883 XClearWindow(dpy, scr->clip_balloon);
3884 wDrawString(scr->clip_balloon, scr->clip_title_font, scr->clip_title_gc,
3885 0, scr->clip_title_font->y, text, strlen(text));
3889 static void
3890 clipEnterNotify(WObjDescriptor *desc, XEvent *event)
3892 WAppIcon *btn = (WAppIcon*)desc->parent;
3893 WDock *dock;
3895 assert(event->type==EnterNotify);
3897 if(desc->parent_type!=WCLASS_DOCK_ICON)
3898 return;
3900 dock = btn->dock;
3901 if (!dock || dock->type!=WM_CLIP)
3902 return;
3904 if (dock->auto_lower_magic) {
3905 WMDeleteTimerHandler(dock->auto_lower_magic);
3906 dock->auto_lower_magic = NULL;
3908 if (dock->auto_raise_lower) {
3909 dock->auto_raise_magic = WMAddTimerHandler(AUTO_RAISE_DELAY,
3910 clipAutoRaise,
3911 (void *)dock);
3914 if (btn->xindex == 0 && btn->yindex == 0)
3915 showClipBalloon(dock, dock->screen_ptr->current_workspace);
3916 else {
3917 if (dock->screen_ptr->flags.clip_balloon_mapped) {
3918 XUnmapWindow(dpy, dock->screen_ptr->clip_balloon);
3919 dock->screen_ptr->flags.clip_balloon_mapped = 0;
3922 if (dock->auto_collapse) {
3923 if (dock->auto_collapse_magic) {
3924 WMDeleteTimerHandler(dock->auto_collapse_magic);
3925 dock->auto_collapse_magic = NULL;
3928 if (dock->collapsed)
3929 toggleCollapsed(dock);
3934 static void
3935 clipLeave(WDock *dock)
3937 XEvent event;
3938 WObjDescriptor *desc = NULL;
3940 if (!dock || dock->type!=WM_CLIP)
3941 return;
3943 if (XCheckTypedEvent(dpy, EnterNotify, &event)!=False) {
3944 if (XFindContext(dpy, event.xcrossing.window, wWinContext,
3945 (XPointer *)&desc)!=XCNOENT
3946 && desc && desc->parent_type==WCLASS_DOCK_ICON
3947 && ((WAppIcon*)desc->parent)->dock
3948 && ((WAppIcon*)desc->parent)->dock->type==WM_CLIP) {
3949 /* We didn't left the Clip yet */
3950 XPutBackEvent(dpy, &event);
3951 return;
3954 XPutBackEvent(dpy, &event);
3955 } else {
3956 /* We entered a withdrawn window, so we're still in Clip */
3957 return;
3960 if (dock->auto_raise_magic) {
3961 WMDeleteTimerHandler(dock->auto_raise_magic);
3962 dock->auto_raise_magic = NULL;
3964 if (dock->auto_raise_lower) {
3965 dock->auto_lower_magic = WMAddTimerHandler(AUTO_LOWER_DELAY,
3966 clipAutoLower,
3967 (void *)dock);
3970 if (dock->auto_collapse) {
3971 if (dock->auto_collapse_magic) {
3972 WMDeleteTimerHandler(dock->auto_collapse_magic);
3973 dock->auto_collapse_magic = NULL;
3975 if (!dock->collapsed) {
3976 dock->auto_collapse_magic = WMAddTimerHandler(AUTO_COLLAPSE_DELAY,
3977 clipAutoCollapse,
3978 (void *)dock);
3984 static void
3985 clipLeaveNotify(WObjDescriptor *desc, XEvent *event)
3987 WAppIcon *btn = (WAppIcon*)desc->parent;
3989 assert(event->type==LeaveNotify);
3991 if(desc->parent_type!=WCLASS_DOCK_ICON)
3992 return;
3994 clipLeave(btn->dock);
3998 static void
3999 clipAutoCollapse(void *cdata)
4001 WDock *dock = (WDock *)cdata;
4003 if (dock->type!=WM_CLIP || !dock->auto_collapse)
4004 return;
4006 if (!dock->collapsed && dock->auto_collapse_magic!=NULL) {
4007 toggleCollapsed(dock);
4009 dock->auto_collapse_magic = NULL;
4013 static void
4014 clipAutoLower(void *cdata)
4016 WDock *dock = (WDock *)cdata;
4018 if (dock->type!=WM_CLIP)
4019 return;
4021 if (dock->auto_raise_lower)
4022 wDockLower(dock);
4024 dock->auto_lower_magic = NULL;
4028 static void
4029 clipAutoRaise(void *cdata)
4031 WDock *dock = (WDock *)cdata;
4033 if (dock->type!=WM_CLIP)
4034 return;
4036 if (dock->auto_raise_lower)
4037 wDockRaise(dock);
4039 if (dock->screen_ptr->flags.clip_balloon_mapped) {
4040 showClipBalloon(dock, dock->screen_ptr->current_workspace);
4043 dock->auto_raise_magic = NULL;