0.51.1 pre snapshot. Be careful, it may be buggy. It fixes some bugs though.
[wmaker-crm.git] / src / dock.c
blob25b6d80ccb525280e6c8b16dec98412e3fb3f815
1 /* dock.c- built-in Dock module for WindowMaker
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <limits.h>
34 #ifndef PATH_MAX
35 #define PATH_MAX DEFAULT_PATH_MAX
36 #endif
38 #include "WindowMaker.h"
39 #include "wcore.h"
40 #include "window.h"
41 #include "icon.h"
42 #include "appicon.h"
43 #include "actions.h"
44 #include "stacking.h"
45 #include "dock.h"
46 #include "dialog.h"
47 #include "funcs.h"
48 #include "properties.h"
49 #include "menu.h"
50 #include "client.h"
51 #include "defaults.h"
52 #include "workspace.h"
53 #include "framewin.h"
54 #include "superfluous.h"
56 #include "list.h"
58 #ifdef WMSOUND
59 #include "wmsound.h"
60 #endif
62 #include <proplist.h>
67 /**** Local variables ****/
68 #define CLIP_REWIND 1
69 #define CLIP_IDLE 0
70 #define CLIP_FORWARD 2
72 #define CLIP_BUTTON_SIZE 23
75 /**** Global variables ****/
77 /* in dockedapp.c */
78 extern void DestroyDockAppSettingsPanel();
80 extern void ShowDockAppSettingsPanel(WAppIcon *aicon);
84 extern Cursor wCursor[WCUR_LAST];
86 extern WPreferences wPreferences;
88 extern XContext wWinContext;
90 #ifdef OFFIX_DND
91 extern Atom _XA_DND_PROTOCOL;
92 #endif
95 #define MOD_MASK wPreferences.modifier_mask
97 extern void appIconMouseDown(WObjDescriptor *desc, XEvent *event);
99 #define ICON_SIZE wPreferences.icon_size
102 /***** Local variables ****/
104 static proplist_t dCommand=NULL;
105 #ifdef OFFIX_DND
106 static proplist_t dDropCommand=NULL;
107 #endif
108 static proplist_t dAutoLaunch, dName, dForced, dBuggyApplication, dYes, dNo;
109 static proplist_t dHost, dDock, dClip;
110 static proplist_t dAutoAttractIcons, dKeepAttracted;
112 static proplist_t dPosition, dApplications, dLowered, dCollapsed, dAutoCollapse;
114 static proplist_t dAutoRaiseLower;
116 static void dockIconPaint(WAppIcon *btn);
118 static void iconMouseDown(WObjDescriptor *desc, XEvent *event);
120 static pid_t execCommand(WAppIcon *btn, char *command, WSavedState *state);
122 static void trackDeadProcess(pid_t pid, unsigned char status, WDock *dock);
124 static int getClipButton(int px, int py);
126 static void toggleLowered(WDock *dock);
128 static void toggleCollapsed(WDock *dock);
130 static void clipIconExpose(WObjDescriptor *desc, XEvent *event);
132 static void clipLeave(WDock *dock);
134 static void handleClipChangeWorkspace(WScreen *scr, XEvent *event);
136 Bool moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y);
138 static void clipEnterNotify(WObjDescriptor *desc, XEvent *event);
139 static void clipLeaveNotify(WObjDescriptor *desc, XEvent *event);
140 static void clipAutoCollapse(void *cdata);
141 static void launchDockedApplication(WAppIcon *btn);
143 static void clipAutoLower(void *cdata);
144 static void clipAutoRaise(void *cdata);
146 static void showClipBalloon(WDock *dock, int workspace);
148 #ifdef OFFIX_DND
150 #define DndNotDnd -1
151 #define DndUnknown 0
152 #define DndRawData 1
153 #define DndFile 2
154 #define DndFiles 3
155 #define DndText 4
156 #define DndDir 5
157 #define DndLink 6
158 #define DndExe 7
160 #define DndEND 8
162 #endif /* OFFIX_DND */
166 static void
167 make_keys()
169 if (dCommand!=NULL)
170 return;
172 dCommand = PLRetain(PLMakeString("Command"));
173 #ifdef OFFIX_DND
174 dDropCommand = PLRetain(PLMakeString("DropCommand"));
175 #endif
176 dAutoLaunch = PLRetain(PLMakeString("AutoLaunch"));
177 dName = PLRetain(PLMakeString("Name"));
178 dForced = PLRetain(PLMakeString("Forced"));
179 dBuggyApplication = PLRetain(PLMakeString("BuggyApplication"));
180 dYes = PLRetain(PLMakeString("Yes"));
181 dNo = PLRetain(PLMakeString("No"));
182 dHost = PLRetain(PLMakeString("Host"));
184 dPosition = PLMakeString("Position");
185 dApplications = PLMakeString("Applications");
186 dLowered = PLMakeString("Lowered");
187 dCollapsed = PLMakeString("Collapsed");
188 dAutoCollapse = PLMakeString("AutoCollapse");
189 dAutoRaiseLower = PLMakeString("AutoRaiseLower");
190 dAutoAttractIcons = PLMakeString("AutoAttractIcons");
191 dKeepAttracted = PLMakeString("KeepAttracted");
193 dDock = PLMakeString("Dock");
194 dClip = PLMakeString("Clip");
199 static void
200 renameCallback(WMenu *menu, WMenuEntry *entry)
202 WDock *dock = entry->clientdata;
203 char buffer[128];
204 int wspace;
205 char *name;
207 assert(entry->clientdata!=NULL);
209 wspace = dock->screen_ptr->current_workspace;
211 name = wstrdup(dock->screen_ptr->workspaces[wspace]->name);
213 sprintf(buffer, _("Type the name for workspace %i:"), wspace+1);
214 if (wInputDialog(dock->screen_ptr, _("Rename Workspace"), buffer,
215 &name)) {
216 wWorkspaceRename(dock->screen_ptr, wspace, name);
218 if (name) {
219 free(name);
224 static void
225 toggleLoweredCallback(WMenu *menu, WMenuEntry *entry)
227 assert(entry->clientdata!=NULL);
229 toggleLowered(entry->clientdata);
231 entry->flags.indicator_on = !((WDock*)entry->clientdata)->lowered;
233 wMenuPaint(menu);
238 static void
239 killCallback(WMenu *menu, WMenuEntry *entry)
241 WAppIcon *icon;
242 #ifdef REDUCE_APPICONS
243 WAppIconAppList *tapplist;
245 extern Atom _XA_WM_DELETE_WINDOW;
246 #endif
248 assert(entry->clientdata!=NULL);
250 icon = (WAppIcon*)entry->clientdata;
252 icon->editing = 1;
254 #ifdef REDUCE_APPICONS
255 /* Send a delete message to the main window of each application
256 * bound to this docked appicon. - cls
258 tapplist = icon->applist;
259 while (tapplist != NULL) {
260 if (tapplist->wapp->main_window_desc != NULL) {
261 if (tapplist->wapp->main_window_desc->protocols.DELETE_WINDOW) {
262 wClientSendProtocol(tapplist->wapp->main_window_desc,
263 _XA_WM_DELETE_WINDOW, CurrentTime);
264 } else {
265 wClientKill(tapplist->wapp->main_window_desc);
268 tapplist = tapplist->next;
270 #else
271 if (wPreferences.dont_confirm_kill
272 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
273 _("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
274 _("Yes"), _("No"), NULL)==WAPRDefault) {
275 if (icon->icon && icon->icon->owner) {
276 wClientKill(icon->icon->owner);
279 #endif /* !REDUCE_APPICONS */
281 icon->editing = 0;
285 static LinkedList*
286 getSelected(WDock *dock)
288 LinkedList *ret=NULL;
289 WAppIcon *btn;
290 int i;
292 for (i=1; i<dock->max_icons; i++) {
293 btn = dock->icon_array[i];
294 if (btn && btn->icon->selected) {
295 ret = list_cons(btn, ret);
299 return ret;
303 static void
304 paintClipButtons(WAppIcon *clipIcon, Bool lpushed, Bool rpushed)
306 Window win = clipIcon->icon->core->window;
307 WScreen *scr = clipIcon->icon->core->screen_ptr;
308 XPoint p[4];
309 int pt = CLIP_BUTTON_SIZE*ICON_SIZE/64;
310 int tp = ICON_SIZE - pt;
311 int as = pt - 15; /* 15 = 5+5+5 */
314 if (rpushed) {
315 p[0].x = tp+1;
316 p[0].y = 1;
317 p[1].x = ICON_SIZE-2;
318 p[1].y = 1;
319 p[2].x = ICON_SIZE-2;
320 p[2].y = pt-1;
321 } else if (lpushed) {
322 p[0].x = 1;
323 p[0].y = tp;
324 p[1].x = pt;
325 p[1].y = ICON_SIZE-2;
326 p[2].x = 1;
327 p[2].y = ICON_SIZE-2;
329 if (lpushed || rpushed) {
330 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
331 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
332 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
335 p[0].x = p[3].x = ICON_SIZE-6-as;
336 p[0].y = p[3].y = 5;
337 p[1].x = ICON_SIZE-6;
338 p[1].y = 5;
339 p[2].x = ICON_SIZE-6;
340 p[2].y = 5+as;
341 if (rpushed) {
342 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
343 XDrawLines(dpy, win, scr->draw_gc, p, 4, CoordModeOrigin);
344 } else {
345 XFillPolygon(dpy, win, scr->clip_title_gc, p,3,Convex,CoordModeOrigin);
346 XDrawLines(dpy, win, scr->clip_title_gc, p,4,CoordModeOrigin);
349 p[0].x = p[3].x = 5;
350 p[0].y = p[3].y = ICON_SIZE-6-as;
351 p[1].x = 5;
352 p[1].y = ICON_SIZE-6;
353 p[2].x = 5+as;
354 p[2].y = ICON_SIZE-6;
355 if (lpushed) {
356 XFillPolygon(dpy, win, scr->draw_gc, p, 3, Convex, CoordModeOrigin);
357 XDrawLines(dpy, win, scr->draw_gc, p, 4, CoordModeOrigin);
358 } else {
359 XFillPolygon(dpy, win, scr->clip_title_gc, p,3,Convex,CoordModeOrigin);
360 XDrawLines(dpy, win, scr->clip_title_gc, p,4,CoordModeOrigin);
365 RImage*
366 wClipMakeTile(WScreen *scr, RImage *normalTile)
368 RImage *tile = RCloneImage(normalTile);
369 RColor black;
370 RColor dark;
371 RColor light;
372 int pt, tp;
374 pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
375 tp = wPreferences.icon_size-1 - pt;
377 black.alpha = 255;
378 black.red = black.green = black.blue = 0;
380 dark.alpha = 0;
381 dark.red = dark.green = dark.blue = 80;
383 light.alpha = 0;
384 light.red = light.green = light.blue = 80;
387 /* top right */
388 ROperateLine(tile, RSubtractOperation, tp, 0, wPreferences.icon_size-2,
389 pt-1, &dark);
390 RDrawLine(tile, tp-1, 0, wPreferences.icon_size-1, pt+1, &black);
391 ROperateLine(tile, RAddOperation, tp, 2, wPreferences.icon_size-3,
392 pt, &light);
395 /* bottom left */
396 ROperateLine(tile, RAddOperation, 2, tp+2, pt-2,
397 wPreferences.icon_size-3, &dark);
398 RDrawLine(tile, 0, tp-1, pt+1, wPreferences.icon_size-1, &black);
399 ROperateLine(tile, RSubtractOperation, 0, tp-2, pt+1,
400 wPreferences.icon_size-2, &light);
402 return tile;
406 static void
407 removeIconsCallback(WMenu *menu, WMenuEntry *entry)
409 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
410 WDock *dock;
411 WAppIcon *aicon;
412 LinkedList *selectedIcons;
413 int keepit;
415 assert(clickedIcon!=NULL);
417 dock = clickedIcon->dock;
419 selectedIcons = getSelected(dock);
421 if (selectedIcons) {
422 if (wMessageDialog(dock->screen_ptr, _("Workspace Clip"),
423 _("All selected icons will be removed!"),
424 _("OK"), _("Cancel"), NULL)!=WAPRDefault) {
425 return;
427 } else {
428 if (clickedIcon->xindex==0 && clickedIcon->yindex==0)
429 return;
430 selectedIcons = list_cons(clickedIcon, NULL);
433 while (selectedIcons) {
434 aicon = selectedIcons->head;
435 keepit = aicon->running && wApplicationOf(aicon->main_window);
436 wDockDetach(dock, aicon);
437 if (keepit) {
438 PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);
439 XMoveWindow(dpy, aicon->icon->core->window,
440 aicon->x_pos, aicon->y_pos);
441 if (!dock->mapped || dock->collapsed)
442 XMapWindow(dpy, aicon->icon->core->window);
444 list_remove_head(&selectedIcons);
447 if (wPreferences.auto_arrange_icons)
448 wArrangeIcons(dock->screen_ptr, True);
452 static void
453 keepIconsCallback(WMenu *menu, WMenuEntry *entry)
455 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
456 WDock *dock;
457 WAppIcon *aicon;
458 LinkedList *selectedIcons;
460 assert(clickedIcon!=NULL);
461 dock = clickedIcon->dock;
463 selectedIcons = getSelected(dock);
465 if (!selectedIcons && clickedIcon!=dock->screen_ptr->clip_icon) {
466 char *command = NULL;
468 if (!clickedIcon->command && !clickedIcon->editing) {
469 clickedIcon->editing = 1;
470 if (wInputDialog(dock->screen_ptr, _("Keep Icon"),
471 _("Type the command used to launch the application"),
472 &command)) {
473 if (command && (command[0]==0 ||
474 (command[0]=='-' && command[1]==0))) {
475 free(command);
476 command = NULL;
478 clickedIcon->command = command;
479 clickedIcon->editing = 0;
480 } else {
481 clickedIcon->editing = 0;
482 if (command)
483 free(command);
484 return;
488 selectedIcons = list_cons(clickedIcon, NULL);
491 while (selectedIcons) {
492 aicon = selectedIcons->head;
493 if (aicon->icon->selected)
494 wIconSelect(aicon->icon);
495 if (aicon && aicon->attracted && aicon->command) {
496 aicon->attracted = 0;
497 if (aicon->icon->shadowed) {
498 aicon->icon->shadowed = 0;
499 aicon->icon->force_paint = 1;
500 wAppIconPaint(aicon);
503 list_remove_head(&selectedIcons);
510 static void
511 toggleAutoAttractCallback(WMenu *menu, WMenuEntry *entry)
513 WDock *dock = (WDock*)entry->clientdata;
515 assert(entry->clientdata!=NULL);
517 dock->attract_icons = !dock->attract_icons;
518 /*if (!dock->attract_icons)
519 dock->keep_attracted = 0;*/
521 entry->flags.indicator_on = dock->attract_icons;
523 wMenuPaint(menu);
527 static void
528 toggleKeepCallback(WMenu *menu, WMenuEntry *entry)
530 WDock *dock = (WDock*)entry->clientdata;
531 WAppIcon *btn;
532 int i;
534 assert(entry->clientdata!=NULL);
536 dock->keep_attracted = !dock->keep_attracted;
538 if (dock->keep_attracted) {
539 for (i=0; i< dock->max_icons; i++) {
540 btn = dock->icon_array[i];
541 if (btn && btn->attracted && btn->command) {
542 btn->attracted = 0;
543 if (btn->icon->shadowed) {
544 btn->icon->shadowed = 0;
545 btn->icon->force_paint = 1;
546 wAppIconPaint(btn);
552 entry->flags.indicator_on = dock->keep_attracted;
554 wMenuPaint(menu);
558 static void
559 selectCallback(WMenu *menu, WMenuEntry *entry)
561 WAppIcon *icon = (WAppIcon*)entry->clientdata;
563 assert(icon!=NULL);
565 wIconSelect(icon->icon);
567 wMenuPaint(menu);
571 static void
572 colectIconsCallback(WMenu *menu, WMenuEntry *entry)
574 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
575 WDock *clip;
576 WAppIcon *aicon;
577 int x, y, x_pos, y_pos;
579 assert(entry->clientdata!=NULL);
580 clip = clickedIcon->dock;
582 aicon = clip->screen_ptr->app_icon_list;
584 while (aicon) {
585 if (!aicon->docked && wDockFindFreeSlot(clip, &x, &y)) {
586 x_pos = clip->x_pos + x*ICON_SIZE;
587 y_pos = clip->y_pos + y*ICON_SIZE;
588 if (aicon->x_pos != x_pos || aicon->y_pos != y_pos) {
589 #ifdef ANIMATIONS
590 if (wPreferences.no_animations) {
591 XMoveWindow(dpy, aicon->icon->core->window, x_pos, y_pos);
592 } else {
593 SlideWindow(aicon->icon->core->window,
594 aicon->x_pos, aicon->y_pos, x_pos, y_pos);
596 #else
597 XMoveWindow(dpy, aicon->icon->core->window, x_pos, y_pos);
598 #endif /* ANIMATIONS */
600 aicon->attracted = 1;
601 if (!clip->keep_attracted && !aicon->icon->shadowed) {
602 aicon->icon->shadowed = 1;
603 aicon->icon->force_paint = 1;
604 /* We don't do an wAppIconPaint() here because it's in
605 * wDockAttachIcon(). -Dan
608 wDockAttachIcon(clip, aicon, x, y);
609 if (clip->collapsed || !clip->mapped)
610 XUnmapWindow(dpy, aicon->icon->core->window);
612 aicon = aicon->next;
617 static void
618 selectIconsCallback(WMenu *menu, WMenuEntry *entry)
620 WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
621 WDock *dock;
622 LinkedList *selectedIcons;
623 WAppIcon *btn;
624 int i;
626 assert(clickedIcon!=NULL);
627 dock = clickedIcon->dock;
629 selectedIcons = getSelected(dock);
631 if (!selectedIcons) {
632 for (i=1; i<dock->max_icons; i++) {
633 btn = dock->icon_array[i];
634 if (btn && !btn->icon->selected) {
635 wIconSelect(btn->icon);
638 } else {
639 while(selectedIcons) {
640 btn = selectedIcons->head;
641 wIconSelect(btn->icon);
642 list_remove_head(&selectedIcons);
646 wMenuPaint(menu);
650 static void
651 toggleCollapsedCallback(WMenu *menu, WMenuEntry *entry)
653 assert(entry->clientdata!=NULL);
655 toggleCollapsed(entry->clientdata);
657 entry->flags.indicator_on = ((WDock*)entry->clientdata)->collapsed;
659 wMenuPaint(menu);
663 static void
664 toggleAutoCollapseCallback(WMenu *menu, WMenuEntry *entry)
666 WDock *dock;
667 assert(entry->clientdata!=NULL);
669 dock = (WDock*) entry->clientdata;
671 dock->auto_collapse = !dock->auto_collapse;
672 if (dock->auto_collapse_magic) {
673 WMDeleteTimerHandler(dock->auto_collapse_magic);
674 dock->auto_collapse_magic = NULL;
677 entry->flags.indicator_on = ((WDock*)entry->clientdata)->auto_collapse;
679 wMenuPaint(menu);
683 static void
684 toggleAutoRaiseLowerCallback(WMenu *menu, WMenuEntry *entry)
686 WDock *dock;
687 assert(entry->clientdata!=NULL);
689 dock = (WDock*) entry->clientdata;
691 dock->auto_raise_lower = !dock->auto_raise_lower;
693 entry->flags.indicator_on = ((WDock*)entry->clientdata)->auto_raise_lower;
695 wMenuPaint(menu);
699 static void
700 launchCallback(WMenu *menu, WMenuEntry *entry)
702 WAppIcon *btn = (WAppIcon*)entry->clientdata;
704 launchDockedApplication(btn);
708 static void
709 settingsCallback(WMenu *menu, WMenuEntry *entry)
711 WAppIcon *btn = (WAppIcon*)entry->clientdata;
713 if (btn->editing)
714 return;
715 ShowDockAppSettingsPanel(btn);
719 static void
720 hideCallback(WMenu *menu, WMenuEntry *entry)
722 WApplication *wapp;
723 WAppIcon *btn = (WAppIcon*)entry->clientdata;
725 wapp = wApplicationOf(btn->icon->owner->main_window);
727 if (wapp->flags.hidden) {
728 wWorkspaceChange(btn->icon->core->screen_ptr,wapp->last_workspace);
729 wUnhideApplication(wapp, False, False);
730 } else {
731 wHideApplication(wapp);
736 static void
737 unhideHereCallback(WMenu *menu, WMenuEntry *entry)
739 WApplication *wapp;
740 WAppIcon *btn = (WAppIcon*)entry->clientdata;
742 wapp = wApplicationOf(btn->icon->owner->main_window);
744 wUnhideApplication(wapp, False, True);
748 WAppIcon*
749 mainIconCreate(WScreen *scr, int type)
751 WAppIcon *btn;
752 int x_pos;
754 if (type == WM_CLIP) {
755 if (scr->clip_icon)
756 return scr->clip_icon;
757 btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMClip", TILE_CLIP);
758 btn->icon->core->descriptor.handle_expose = clipIconExpose;
759 btn->icon->core->descriptor.handle_enternotify = clipEnterNotify;
760 btn->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
761 /*x_pos = scr->scr_width - ICON_SIZE*2 - DOCK_EXTRA_SPACE;*/
762 x_pos = 0;
763 } else {
764 btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMDock", TILE_NORMAL);
765 x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
768 btn->xindex = 0;
769 btn->yindex = 0;
771 btn->icon->core->descriptor.handle_mousedown = iconMouseDown;
772 btn->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
773 btn->icon->core->descriptor.parent = btn;
774 /*ChangeStackingLevel(btn->icon->core, WMDockLevel);*/
775 XMapWindow(dpy, btn->icon->core->window);
776 btn->x_pos = x_pos;
777 btn->y_pos = 0;
778 btn->docked = 1;
779 if (type == WM_CLIP)
780 scr->clip_icon = btn;
782 return btn;
786 static void
787 switchWSCommand(WMenu *menu, WMenuEntry *entry)
789 WAppIcon *btn, *icon = (WAppIcon*) entry->clientdata;
790 WScreen *scr = icon->icon->core->screen_ptr;
791 WDock *src, *dest;
792 LinkedList *selectedIcons;
793 int x, y;
795 if (entry->order == scr->current_workspace)
796 return;
797 src = icon->dock;
798 dest = scr->workspaces[entry->order]->clip;
800 selectedIcons = getSelected(src);
802 if (selectedIcons) {
803 while(selectedIcons) {
804 btn = selectedIcons->head;
805 if (wDockFindFreeSlot(dest, &x, &y)) {
806 moveIconBetweenDocks(src, dest, btn, x, y);
807 XUnmapWindow(dpy, btn->icon->core->window);
809 list_remove_head(&selectedIcons);
811 } else if (icon != scr->clip_icon) {
812 if (wDockFindFreeSlot(dest, &x, &y)) {
813 moveIconBetweenDocks(src, dest, icon, x, y);
814 XUnmapWindow(dpy, icon->icon->core->window);
821 static void
822 launchDockedApplication(WAppIcon *btn)
824 WScreen *scr = btn->icon->core->screen_ptr;
826 if (!btn->launching && btn->command!=NULL) {
827 if (!btn->forced_dock) {
828 btn->relaunching = btn->running;
829 btn->running = 1;
831 if (btn->wm_instance || btn->wm_class) {
832 WWindowAttributes attr;
833 memset(&attr, 0, sizeof(WWindowAttributes));
834 wDefaultFillAttributes(scr, btn->wm_instance, btn->wm_class,
835 &attr, NULL, True);
837 if (!attr.no_appicon && !btn->buggy_app)
838 btn->launching = 1;
839 else
840 btn->running = 0;
842 btn->drop_launch = 0;
843 scr->last_dock = btn->dock;
844 btn->pid = execCommand(btn, btn->command, NULL);
845 if (btn->pid>0) {
846 if (btn->buggy_app) {
847 /* give feedback that the app was launched */
848 btn->launching = 1;
849 dockIconPaint(btn);
850 btn->launching = 0;
851 WMAddTimerHandler(200, (WMCallback*)dockIconPaint, btn);
852 } else {
853 dockIconPaint(btn);
855 } else {
856 wwarning(_("could not launch application %s\n"), btn->command);
857 btn->launching = 0;
858 if (!btn->relaunching)
859 btn->running = 0;
866 static void
867 updateWorkspaceMenu(WMenu *menu, WAppIcon *icon)
869 WScreen *scr = menu->frame->screen_ptr;
870 char title[MAX_WORKSPACENAME_WIDTH+1];
871 int i;
873 if (!menu || !icon)
874 return;
876 for (i=0; i<scr->workspace_count; i++) {
877 if (i < menu->entry_no) {
878 if (strcmp(menu->entries[i]->text,scr->workspaces[i]->name)!=0) {
879 free(menu->entries[i]->text);
880 strcpy(title, scr->workspaces[i]->name);
881 menu->entries[i]->text = wstrdup(title);
882 menu->flags.realized = 0;
884 menu->entries[i]->clientdata = (void*)icon;
885 } else {
886 strcpy(title, scr->workspaces[i]->name);
888 wMenuAddCallback(menu, title, switchWSCommand, (void*)icon);
890 menu->flags.realized = 0;
892 if (i == scr->current_workspace) {
893 wMenuSetEnabled(menu, i, False);
894 } else {
895 wMenuSetEnabled(menu, i, True);
899 if (!menu->flags.realized)
900 wMenuRealize(menu);
904 static WMenu*
905 makeWorkspaceMenu(WScreen *scr)
907 WMenu *menu;
909 menu = wMenuCreate(scr, NULL, False);
910 if (!menu)
911 wwarning(_("could not create workspace submenu for Clip menu"));
913 wMenuAddCallback(menu, "", switchWSCommand, (void*)scr->clip_icon);
915 menu->flags.realized = 0;
916 wMenuRealize(menu);
918 return menu;
922 static void
923 updateClipOptionsMenu(WMenu *menu, WDock *dock)
925 WMenuEntry *entry;
926 int index = 0;
928 if (!menu || !dock)
929 return;
931 /* keep on top */
932 entry = menu->entries[index];
933 entry->flags.indicator_on = !dock->lowered;
934 entry->clientdata = dock;
936 /* collapsed */
937 entry = menu->entries[++index];
938 entry->flags.indicator_on = dock->collapsed;
939 entry->clientdata = dock;
941 /* auto-collapse */
942 entry = menu->entries[++index];
943 entry->flags.indicator_on = dock->auto_collapse;
944 entry->clientdata = dock;
946 /* auto-raise/lower */
947 entry = menu->entries[++index];
948 entry->flags.indicator_on = dock->auto_raise_lower;
949 entry->clientdata = dock;
951 /* attract icons */
952 entry = menu->entries[++index];
953 entry->flags.indicator_on = dock->attract_icons;
954 entry->clientdata = dock;
956 /* keep attracted icons */
957 entry = menu->entries[++index];
958 entry->flags.indicator_on = dock->keep_attracted;
959 entry->clientdata = dock;
961 menu->flags.realized = 0;
962 wMenuRealize(menu);
966 static WMenu*
967 makeClipOptionsMenu(WScreen *scr)
969 WMenu *menu;
970 WMenuEntry *entry;
972 menu = wMenuCreate(scr, NULL, False);
973 if (!menu) {
974 wwarning(_("could not create options submenu for Clip menu"));
975 return NULL;
978 entry = wMenuAddCallback(menu, _("Keep on top"),
979 toggleLoweredCallback, NULL);
980 entry->flags.indicator = 1;
981 entry->flags.indicator_on = 1;
982 entry->flags.indicator_type = MI_CHECK;
984 entry = wMenuAddCallback(menu, _("Collapsed"),
985 toggleCollapsedCallback, NULL);
986 entry->flags.indicator = 1;
987 entry->flags.indicator_on = 1;
988 entry->flags.indicator_type = MI_CHECK;
990 entry = wMenuAddCallback(menu, _("AutoCollapse"),
991 toggleAutoCollapseCallback, NULL);
992 entry->flags.indicator = 1;
993 entry->flags.indicator_on = 1;
994 entry->flags.indicator_type = MI_CHECK;
996 entry = wMenuAddCallback(menu, _("AutoRaiseLower"),
997 toggleAutoRaiseLowerCallback, NULL);
998 entry->flags.indicator = 1;
999 entry->flags.indicator_on = 1;
1000 entry->flags.indicator_type = MI_CHECK;
1002 entry = wMenuAddCallback(menu, _("AutoAttract Icons"),
1003 toggleAutoAttractCallback, NULL);
1004 entry->flags.indicator = 1;
1005 entry->flags.indicator_on = 1;
1006 entry->flags.indicator_type = MI_CHECK;
1008 entry = wMenuAddCallback(menu, _("Keep Attracted Icons"),
1009 toggleKeepCallback, NULL);
1010 entry->flags.indicator = 1;
1011 entry->flags.indicator_on = 1;
1012 entry->flags.indicator_type = MI_CHECK;
1014 menu->flags.realized = 0;
1015 wMenuRealize(menu);
1017 return menu;
1021 static WMenu*
1022 dockMenuCreate(WScreen *scr, int type)
1024 WMenu *menu;
1025 WMenuEntry *entry;
1027 if (type == WM_CLIP && scr->clip_menu)
1028 return scr->clip_menu;
1030 menu = wMenuCreate(scr, NULL, False);
1031 if (type != WM_CLIP) {
1032 entry = wMenuAddCallback(menu, _("Keep on top"),
1033 toggleLoweredCallback, NULL);
1034 entry->flags.indicator = 1;
1035 entry->flags.indicator_on = 1;
1036 entry->flags.indicator_type = MI_CHECK;
1037 } else {
1038 entry = wMenuAddCallback(menu, _("Clip Options"), NULL, NULL);
1039 scr->clip_options = makeClipOptionsMenu(scr);
1040 if (scr->clip_options)
1041 wMenuEntrySetCascade(menu, entry, scr->clip_options);
1043 wMenuAddCallback(menu, _("Rename Workspace"), renameCallback, NULL);
1045 wMenuAddCallback(menu, _("(Un)Select Icon"), selectCallback, NULL);
1047 wMenuAddCallback(menu, _("(Un)Select All Icons"), selectIconsCallback,
1048 NULL);
1050 wMenuAddCallback(menu, _("Keep Icon(s)"), keepIconsCallback, NULL);
1052 entry = wMenuAddCallback(menu, _("Move Icon(s) To"), NULL, NULL);
1053 scr->clip_submenu = makeWorkspaceMenu(scr);
1054 if (scr->clip_submenu)
1055 wMenuEntrySetCascade(menu, entry, scr->clip_submenu);
1057 wMenuAddCallback(menu, _("Remove Icon(s)"), removeIconsCallback, NULL);
1059 wMenuAddCallback(menu, _("Attract Icons"), colectIconsCallback, NULL);
1062 wMenuAddCallback(menu, _("Launch"), launchCallback, NULL);
1064 wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
1066 entry = wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
1067 free(entry->text);
1068 entry->text = _("Hide");
1070 wMenuAddCallback(menu, _("Settings..."), settingsCallback, NULL);
1072 wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
1074 if (type == WM_CLIP)
1075 scr->clip_menu = menu;
1077 return menu;
1081 WDock*
1082 wDockCreate(WScreen *scr, int type)
1084 WDock *dock;
1085 WAppIcon *btn;
1086 int icon_count;
1088 make_keys();
1090 dock = wmalloc(sizeof(WDock));
1091 memset(dock, 0, sizeof(WDock));
1093 if (type == WM_CLIP)
1094 icon_count = CLIP_MAX_ICONS;
1095 else
1096 icon_count = scr->scr_height/wPreferences.icon_size;
1098 dock->icon_array = wmalloc(sizeof(WAppIcon*)*icon_count);
1099 memset(dock->icon_array, 0, sizeof(WAppIcon*)*icon_count);
1101 dock->max_icons = icon_count;
1103 btn = mainIconCreate(scr, type);
1105 btn->dock = dock;
1107 dock->x_pos = btn->x_pos;
1108 dock->y_pos = btn->y_pos;
1109 dock->screen_ptr = scr;
1110 dock->type = type;
1111 dock->icon_count = 1;
1112 dock->on_right_side = 1;
1113 dock->collapsed = 0;
1114 dock->auto_collapse = 0;
1115 dock->auto_collapse_magic = NULL;
1116 dock->auto_raise_lower = 0;
1117 dock->auto_lower_magic = NULL;
1118 dock->auto_raise_magic = NULL;
1119 dock->attract_icons = 0;
1120 dock->keep_attracted = 0;
1121 dock->lowered = 1;
1122 dock->icon_array[0] = btn;
1123 wRaiseFrame(btn->icon->core);
1124 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
1126 /* create dock menu */
1127 dock->menu = dockMenuCreate(scr, type);
1129 return dock;
1133 void
1134 wDockDestroy(WDock *dock)
1136 int i;
1137 WAppIcon *aicon;
1139 for (i=(dock->type == WM_CLIP) ? 1 : 0; i<dock->max_icons; i++) {
1140 aicon = dock->icon_array[i];
1141 if (aicon) {
1142 int keepit = aicon->running && wApplicationOf(aicon->main_window);
1143 wDockDetach(dock, aicon);
1144 if (keepit) {
1145 PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);
1146 XMoveWindow(dpy, aicon->icon->core->window,
1147 aicon->x_pos, aicon->y_pos);
1148 if (!dock->mapped || dock->collapsed)
1149 XMapWindow(dpy, aicon->icon->core->window);
1153 if (wPreferences.auto_arrange_icons)
1154 wArrangeIcons(dock->screen_ptr, True);
1155 free(dock->icon_array);
1156 if (dock->menu && dock->type!=WM_CLIP)
1157 wMenuDestroy(dock->menu, True);
1158 free(dock);
1162 void
1163 wClipIconPaint(WAppIcon *aicon)
1165 WScreen *scr = aicon->icon->core->screen_ptr;
1166 WWorkspace *workspace = scr->workspaces[scr->current_workspace];
1167 GC gc;
1168 Window win = aicon->icon->core->window;
1169 int length, nlength;
1170 char *ws_name, ws_number[10];
1171 int ty, tx;
1173 wIconPaint(aicon->icon);
1175 length = strlen(workspace->name);
1176 ws_name = malloc(length + 1);
1177 sprintf(ws_name, "%s", workspace->name);
1178 sprintf(ws_number, "%i", scr->current_workspace + 1);
1179 nlength = strlen(ws_number);
1181 gc = scr->clip_title_gc;
1183 if (!workspace->clip->collapsed)
1184 XSetForeground(dpy, gc, scr->clip_title_pixel[CLIP_NORMAL]);
1185 else
1186 XSetForeground(dpy, gc, scr->clip_title_pixel[CLIP_COLLAPSED]);
1188 ty = ICON_SIZE - scr->clip_title_font->height - 3;
1190 tx = CLIP_BUTTON_SIZE*ICON_SIZE/64;
1192 wDrawString(win, scr->clip_title_font, gc, tx,
1193 ty + scr->clip_title_font->y, ws_name, length);
1195 tx = (ICON_SIZE/2 - wTextWidth(scr->clip_title_font->font, ws_number, nlength))/2;
1197 wDrawString(win, scr->clip_title_font, gc, tx,
1198 scr->clip_title_font->y + 2, ws_number, nlength);
1200 free(ws_name);
1202 if (aicon->launching) {
1203 XFillRectangle(dpy, aicon->icon->core->window, scr->stipple_gc,
1204 0, 0, wPreferences.icon_size, wPreferences.icon_size);
1206 paintClipButtons(aicon, aicon->dock->lclip_button_pushed,
1207 aicon->dock->rclip_button_pushed);
1211 static void
1212 clipIconExpose(WObjDescriptor *desc, XEvent *event)
1214 wClipIconPaint(desc->parent);
1218 static void
1219 dockIconPaint(WAppIcon *btn)
1221 if (btn == btn->icon->core->screen_ptr->clip_icon)
1222 wClipIconPaint(btn);
1223 else
1224 wAppIconPaint(btn);
1228 static proplist_t
1229 make_icon_state(WAppIcon *btn)
1231 proplist_t node = NULL;
1232 proplist_t command, autolaunch, name, forced, host, position, buggy;
1233 char *tmp;
1234 char buffer[64];
1236 if (btn) {
1237 if (!btn->command)
1238 command = PLMakeString("-");
1239 else
1240 command = PLMakeString(btn->command);
1242 autolaunch = btn->auto_launch ? dYes : dNo;
1244 tmp = EscapeWM_CLASS(btn->wm_instance, btn->wm_class);
1246 name = PLMakeString(tmp);
1248 free(tmp);
1250 forced = btn->forced_dock ? dYes : dNo;
1252 buggy = btn->buggy_app ? dYes: dNo;
1254 if (btn == btn->icon->core->screen_ptr->clip_icon)
1255 sprintf(buffer, "%i,%i", btn->x_pos, btn->y_pos);
1256 else
1257 sprintf(buffer, "%hi,%hi", btn->xindex, btn->yindex);
1258 position = PLMakeString(buffer);
1260 node = PLMakeDictionaryFromEntries(dCommand, command,
1261 dName, name,
1262 dAutoLaunch, autolaunch,
1263 dForced, forced,
1264 dBuggyApplication, buggy,
1265 dPosition, position,
1266 NULL);
1267 PLRelease(command);
1268 PLRelease(name);
1269 PLRelease(position);
1270 #ifdef OFFIX_DND
1271 if (btn->dnd_command) {
1272 command = PLMakeString(btn->dnd_command);
1273 PLInsertDictionaryEntry(node, dDropCommand, command);
1274 PLRelease(command);
1276 #endif /* OFFIX_DND */
1278 if (btn->client_machine && btn->remote_start) {
1279 host = PLMakeString(btn->client_machine);
1280 PLInsertDictionaryEntry(node, dHost, host);
1281 PLRelease(host);
1285 return node;
1289 static proplist_t
1290 dockSaveState(WDock *dock)
1292 int i;
1293 proplist_t icon_info;
1294 proplist_t list=NULL, dock_state=NULL;
1295 proplist_t value;
1296 char buffer[256];
1298 list = PLMakeArrayFromElements(NULL);
1300 for (i=(dock->type==WM_DOCK ? 0 : 1); i<dock->max_icons; i++) {
1301 WAppIcon *btn = dock->icon_array[i];
1303 if (!btn || (btn->attracted && !dock->keep_attracted))
1304 continue;
1306 if ((icon_info = make_icon_state(dock->icon_array[i]))) {
1307 list = PLAppendArrayElement(list, icon_info);
1308 PLRelease(icon_info);
1312 dock_state = PLMakeDictionaryFromEntries(dApplications, list, NULL);
1314 PLRelease(list);
1316 if (dock->type == WM_DOCK) {
1317 sprintf(buffer, "%i,%i", (dock->on_right_side ? -ICON_SIZE : 0),
1318 dock->y_pos);
1319 value = PLMakeString(buffer);
1320 PLInsertDictionaryEntry(dock_state, dPosition, value);
1321 PLRelease(value);
1324 value = (dock->lowered ? dYes : dNo);
1325 PLInsertDictionaryEntry(dock_state, dLowered, value);
1327 if (dock->type == WM_CLIP) {
1328 value = (dock->collapsed ? dYes : dNo);
1329 PLInsertDictionaryEntry(dock_state, dCollapsed, value);
1331 value = (dock->auto_collapse ? dYes : dNo);
1332 PLInsertDictionaryEntry(dock_state, dAutoCollapse, value);
1334 value = (dock->auto_raise_lower ? dYes : dNo);
1335 PLInsertDictionaryEntry(dock_state, dAutoRaiseLower, value);
1337 value = (dock->attract_icons ? dYes : dNo);
1338 PLInsertDictionaryEntry(dock_state, dAutoAttractIcons, value);
1340 value = (dock->keep_attracted ? dYes : dNo);
1341 PLInsertDictionaryEntry(dock_state, dKeepAttracted, value);
1344 return dock_state;
1348 void
1349 wDockSaveState(WScreen *scr)
1351 proplist_t dock_state;
1353 dock_state = dockSaveState(scr->dock);
1355 PLInsertDictionaryEntry(scr->session_state, dDock, dock_state);
1357 PLRelease(dock_state);
1361 void
1362 wClipSaveState(WScreen *scr)
1364 proplist_t clip_state;
1366 clip_state = make_icon_state(scr->clip_icon);
1368 PLInsertDictionaryEntry(scr->session_state, dClip, clip_state);
1370 PLRelease(clip_state);
1374 proplist_t
1375 wClipSaveWorkspaceState(WScreen *scr, int workspace)
1377 return dockSaveState(scr->workspaces[workspace]->clip);
1381 static WAppIcon*
1382 restore_icon_state(WScreen *scr, proplist_t info, int type, int index)
1384 WAppIcon *aicon;
1385 char *wclass, *winstance;
1386 proplist_t cmd, value;
1387 char *command;
1390 cmd = PLGetDictionaryEntry(info, dCommand);
1391 if (!cmd || !PLIsString(cmd)) {
1392 return NULL;
1395 /* parse window name */
1396 value = PLGetDictionaryEntry(info, dName);
1397 if (!value)
1398 return NULL;
1400 ParseWindowName(value, &winstance, &wclass, "dock");
1402 if (!winstance && !wclass) {
1403 return NULL;
1406 /* get commands */
1408 if (cmd)
1409 command = wstrdup(PLGetString(cmd));
1410 else
1411 command = NULL;
1413 if (!command || strcmp(command, "-")==0) {
1414 if (command)
1415 free(command);
1416 if (wclass)
1417 free(wclass);
1418 if (winstance)
1419 free(winstance);
1421 return NULL;
1424 aicon = wAppIconCreateForDock(scr, command, winstance, wclass,
1425 TILE_NORMAL);
1426 if (wclass)
1427 free(wclass);
1428 if (winstance)
1429 free(winstance);
1431 aicon->icon->core->descriptor.handle_mousedown = iconMouseDown;
1432 if (type == WM_CLIP) {
1433 aicon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
1434 aicon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
1436 aicon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
1437 aicon->icon->core->descriptor.parent = aicon;
1440 #ifdef OFFIX_DND
1441 cmd = PLGetDictionaryEntry(info, dDropCommand);
1442 if (cmd)
1443 aicon->dnd_command = wstrdup(PLGetString(cmd));
1444 #endif
1446 /* check auto launch */
1447 value = PLGetDictionaryEntry(info, dAutoLaunch);
1449 aicon->auto_launch = 0;
1450 if (value) {
1451 if (PLIsString(value)) {
1452 if (strcasecmp(PLGetString(value), "YES")==0)
1453 aicon->auto_launch = 1;
1454 } else {
1455 wwarning(_("bad value in docked icon state info %s"),
1456 PLGetString(dAutoLaunch));
1460 /* check if it wasn't normally docked */
1461 value = PLGetDictionaryEntry(info, dForced);
1463 aicon->forced_dock = 0;
1464 if (value) {
1465 if (PLIsString(value)) {
1466 if (strcasecmp(PLGetString(value), "YES")==0)
1467 aicon->forced_dock = 1;
1468 } else {
1469 wwarning(_("bad value in docked icon state info %s"),
1470 PLGetString(dForced));
1474 /* check if we can rely on the stuff in the app */
1475 value = PLGetDictionaryEntry(info, dBuggyApplication);
1477 aicon->buggy_app = 0;
1478 if (value) {
1479 if (PLIsString(value)) {
1480 if (strcasecmp(PLGetString(value), "YES")==0)
1481 aicon->buggy_app = 1;
1482 } else {
1483 wwarning(_("bad value in docked icon state info %s"),
1484 PLGetString(dBuggyApplication));
1488 /* get position in the dock */
1489 value = PLGetDictionaryEntry(info, dPosition);
1490 if (value && PLIsString(value)) {
1491 if (sscanf(PLGetString(value), "%hi,%hi", &aicon->xindex,
1492 &aicon->yindex)!=2)
1493 wwarning(_("bad value in docked icon state info %s"),
1494 PLGetString(dPosition));
1496 /* check position sanity */
1497 /* incomplete section! */
1498 if (type == WM_DOCK) {
1499 aicon->xindex = 0;
1500 if (aicon->yindex < 0)
1501 wwarning(_("bad value in docked icon position %i,%i"),
1502 aicon->xindex, aicon->yindex);
1504 } else {
1505 aicon->yindex = index;
1506 aicon->xindex = 0;
1509 aicon->running = 0;
1510 aicon->docked = 1;
1512 return aicon;
1516 #define COMPLAIN(key) wwarning(_("bad value in dock state info:%s"), key)
1519 WAppIcon*
1520 wClipRestoreState(WScreen *scr, proplist_t clip_state)
1522 WAppIcon *icon;
1523 proplist_t value;
1526 icon = mainIconCreate(scr, WM_CLIP);
1528 if (!clip_state)
1529 return icon;
1530 else
1531 PLRetain(clip_state);
1533 /* restore position */
1535 value = PLGetDictionaryEntry(clip_state, dPosition);
1537 if (value) {
1538 if (!PLIsString(value))
1539 COMPLAIN("Position");
1540 else {
1541 if (sscanf(PLGetString(value), "%i,%i", &icon->x_pos,
1542 &icon->y_pos)!=2)
1543 COMPLAIN("Position");
1545 /* check position sanity */
1546 if (icon->y_pos < 0)
1547 icon->y_pos = 0;
1548 else if (icon->y_pos > scr->scr_height-ICON_SIZE)
1549 icon->y_pos = scr->scr_height-ICON_SIZE;
1551 if (icon->x_pos < 0)
1552 icon->x_pos = 0;
1553 else if (icon->x_pos > scr->scr_width-ICON_SIZE)
1554 icon->x_pos = scr->scr_width-ICON_SIZE;
1558 #ifdef OFFIX_DND
1559 value = PLGetDictionaryEntry(clip_state, dDropCommand);
1560 if (value && PLIsString(value))
1561 icon->dnd_command = wstrdup(PLGetString(value));
1562 #endif
1564 PLRelease(clip_state);
1566 return icon;
1570 WDock*
1571 wDockRestoreState(WScreen *scr, proplist_t dock_state, int type)
1573 WDock *dock;
1574 proplist_t apps;
1575 proplist_t value;
1576 WAppIcon *aicon, *old_top;
1577 int count, i;
1580 dock = wDockCreate(scr, type);
1582 if (!dock_state)
1583 return dock;
1585 if (dock_state)
1586 PLRetain(dock_state);
1589 /* restore position */
1591 value = PLGetDictionaryEntry(dock_state, dPosition);
1593 if (value) {
1594 if (!PLIsString(value))
1595 COMPLAIN("Position");
1596 else {
1597 if (sscanf(PLGetString(value), "%i,%i", &dock->x_pos,
1598 &dock->y_pos)!=2)
1599 COMPLAIN("Position");
1601 /* check position sanity */
1602 if (dock->y_pos < 0)
1603 dock->y_pos = 0;
1604 else if (dock->y_pos > scr->scr_height-ICON_SIZE)
1605 dock->y_pos = scr->scr_height - ICON_SIZE;
1607 /* This is no more needed. ??? */
1608 if (type == WM_CLIP) {
1609 if (dock->x_pos < 0)
1610 dock->x_pos = 0;
1611 else if (dock->x_pos > scr->scr_width-ICON_SIZE)
1612 dock->x_pos = scr->scr_width-ICON_SIZE;
1613 } else {
1614 if (dock->x_pos >= 0) {
1615 dock->x_pos = DOCK_EXTRA_SPACE;
1616 dock->on_right_side = 0;
1617 } else {
1618 dock->x_pos = scr->scr_width - DOCK_EXTRA_SPACE - ICON_SIZE;
1619 dock->on_right_side = 1;
1625 /* restore lowered/raised state */
1627 dock->lowered = 0;
1629 value = PLGetDictionaryEntry(dock_state, dLowered);
1631 if (value) {
1632 if (!PLIsString(value))
1633 COMPLAIN("Lowered");
1634 else {
1635 if (strcasecmp(PLGetString(value), "YES")==0)
1636 dock->lowered = 1;
1641 /* restore collapsed state */
1643 dock->collapsed = 0;
1645 value = PLGetDictionaryEntry(dock_state, dCollapsed);
1647 if (value) {
1648 if (!PLIsString(value))
1649 COMPLAIN("Collapsed");
1650 else {
1651 if (strcasecmp(PLGetString(value), "YES")==0)
1652 dock->collapsed = 1;
1657 /* restore auto-collapsed state */
1659 value = PLGetDictionaryEntry(dock_state, dAutoCollapse);
1661 if (value) {
1662 if (!PLIsString(value))
1663 COMPLAIN("AutoCollapse");
1664 else {
1665 if (strcasecmp(PLGetString(value), "YES")==0) {
1666 dock->auto_collapse = 1;
1667 dock->collapsed = 1;
1673 /* restore auto-raise/lower state */
1675 value = PLGetDictionaryEntry(dock_state, dAutoRaiseLower);
1677 if (value) {
1678 if (!PLIsString(value))
1679 COMPLAIN("AutoRaiseLower");
1680 else {
1681 if (strcasecmp(PLGetString(value), "YES")==0) {
1682 dock->auto_raise_lower = 1;
1688 /* restore attract icons state */
1690 dock->attract_icons = 0;
1692 value = PLGetDictionaryEntry(dock_state, dAutoAttractIcons);
1694 if (value) {
1695 if (!PLIsString(value))
1696 COMPLAIN("AutoAttractIcons");
1697 else {
1698 if (strcasecmp(PLGetString(value), "YES")==0)
1699 dock->attract_icons = 1;
1704 /* restore keep attracted icons state */
1706 dock->keep_attracted = 0;
1708 value = PLGetDictionaryEntry(dock_state, dKeepAttracted);
1710 if (value) {
1711 if (!PLIsString(value))
1712 COMPLAIN("KeepAttracted");
1713 else {
1714 if (strcasecmp(PLGetString(value), "YES")==0)
1715 dock->keep_attracted = 1;
1720 /* application list */
1722 apps = PLGetDictionaryEntry(dock_state, dApplications);
1724 if (!apps) {
1725 goto finish;
1728 count = PLGetNumberOfElements(apps);
1730 if (count==0)
1731 goto finish;
1733 old_top = dock->icon_array[0];
1735 /* dock->icon_count is set to 1 when dock is created.
1736 * Since Clip is already restored, we want to keep it so for clip,
1737 * but for dock we may change the default top tile, so we set it to 0.
1739 if (type == WM_DOCK)
1740 dock->icon_count = 0;
1742 for (i=0; i<count; i++) {
1743 if (dock->icon_count >= dock->max_icons) {
1744 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1745 break;
1748 value = PLGetArrayElement(apps, i);
1749 aicon = restore_icon_state(scr, value, type, dock->icon_count);
1751 dock->icon_array[dock->icon_count] = aicon;
1753 if (aicon) {
1754 aicon->dock = dock;
1755 aicon->x_pos = dock->x_pos + (aicon->xindex*ICON_SIZE);
1756 aicon->y_pos = dock->y_pos + (aicon->yindex*ICON_SIZE);
1758 if (dock->lowered)
1759 ChangeStackingLevel(aicon->icon->core, WMNormalLevel);
1760 else
1761 ChangeStackingLevel(aicon->icon->core, WMDockLevel);
1763 wCoreConfigure(aicon->icon->core, aicon->x_pos, aicon->y_pos,
1764 0, 0);
1766 if (!dock->collapsed)
1767 XMapWindow(dpy, aicon->icon->core->window);
1768 wRaiseFrame(aicon->icon->core);
1770 dock->icon_count++;
1771 } else if (dock->icon_count==0 && type==WM_DOCK)
1772 dock->icon_count++;
1775 /* if the first icon is not defined, use the default */
1776 if (dock->icon_array[0]==NULL) {
1777 /* update default icon */
1778 old_top->x_pos = dock->x_pos;
1779 old_top->y_pos = dock->y_pos;
1780 if (dock->lowered)
1781 ChangeStackingLevel(old_top->icon->core, WMNormalLevel);
1782 else
1783 ChangeStackingLevel(old_top->icon->core, WMDockLevel);
1784 dock->icon_array[0] = old_top;
1785 XMoveWindow(dpy, old_top->icon->core->window, dock->x_pos, dock->y_pos);
1786 /* we don't need to increment dock->icon_count here because it was
1787 * incremented in the loop above.
1789 } else if (old_top!=dock->icon_array[0]) {
1790 if (old_top == scr->clip_icon)
1791 scr->clip_icon = dock->icon_array[0];
1792 wAppIconDestroy(old_top);
1795 finish:
1796 if (dock_state)
1797 PLRelease(dock_state);
1799 return dock;
1804 void
1805 wDockLaunchWithState(WDock *dock, WAppIcon *btn, WSavedState *state)
1807 if (btn && btn->command && !btn->running && !btn->launching) {
1809 btn->drop_launch = 0;
1811 btn->pid = execCommand(btn, btn->command, state);
1813 if (btn->pid>0) {
1814 if (!btn->forced_dock && !btn->buggy_app) {
1815 btn->launching = 1;
1816 dockIconPaint(btn);
1819 } else {
1820 free(state);
1825 void
1826 wDockDoAutoLaunch(WDock *dock, int workspace)
1828 WAppIcon *btn;
1829 WSavedState *state;
1830 int i;
1832 for (i = 0; i < dock->max_icons; i++) {
1833 btn = dock->icon_array[i];
1834 if (!btn || !btn->auto_launch)
1835 continue;
1837 state = wmalloc(sizeof(WSavedState));
1838 memset(state, 0, sizeof(WSavedState));
1839 state->workspace = workspace;
1840 /* TODO: this is klugy and is very difficult to understand
1841 * what's going on. Try to clean up */
1842 wDockLaunchWithState(dock, btn, state);
1846 #ifdef REDUCE_APPICONS
1847 void
1848 wDockSimulateLaunch(WDock *dock, WAppIcon *btn)
1850 if ((btn == NULL) || (dock == NULL))
1851 return;
1853 if (!btn->running) {
1854 if ((btn->icon->owner == NULL) && (btn->applist))
1855 btn->icon->owner = btn->applist->wapp->main_window_desc;
1856 if (!btn->forced_dock)
1857 btn->launching = 1;
1858 dockIconPaint(btn);
1859 wusleep(5000);
1862 #endif
1864 #ifdef OFFIX_DND
1865 static WDock*
1866 findDock(WScreen *scr, XEvent *event, int *icon_pos)
1868 WDock *dock;
1869 int i;
1871 *icon_pos = -1;
1872 if ((dock = scr->dock)!=NULL) {
1873 for (i=0; i<dock->max_icons; i++) {
1874 if (dock->icon_array[i]
1875 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1876 *icon_pos = i;
1877 break;
1881 if (*icon_pos<0 && (dock = scr->workspaces[scr->current_workspace]->clip)!=NULL) {
1882 for (i=0; i<dock->max_icons; i++) {
1883 if (dock->icon_array[i]
1884 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1885 *icon_pos = i;
1886 break;
1890 if(*icon_pos>=0)
1891 return dock;
1892 return NULL;
1897 wDockReceiveDNDDrop(WScreen *scr, XEvent *event)
1899 WDock *dock;
1900 WAppIcon *btn;
1901 int icon_pos;
1903 dock = findDock(scr, event, &icon_pos);
1904 if (!dock)
1905 return False;
1908 * Return True if the drop was on an application icon window.
1909 * In this case, let the ClientMessage handler redirect the
1910 * message to the app.
1912 if (dock->icon_array[icon_pos]->icon->icon_win!=None)
1913 return True;
1915 if (dock->icon_array[icon_pos]->dnd_command!=NULL) {
1916 scr->flags.dnd_data_convertion_status = 0;
1918 btn = dock->icon_array[icon_pos];
1920 if (!btn->forced_dock) {
1921 btn->relaunching = btn->running;
1922 btn->running = 1;
1924 if (btn->wm_instance || btn->wm_class) {
1925 WWindowAttributes attr;
1926 memset(&attr, 0, sizeof(WWindowAttributes));
1927 wDefaultFillAttributes(btn->icon->core->screen_ptr,
1928 btn->wm_instance,
1929 btn->wm_class, &attr, NULL, True);
1931 if (!attr.no_appicon)
1932 btn->launching = 1;
1933 else
1934 btn->running = 0;
1937 btn->drop_launch = 1;
1938 scr->last_dock = dock;
1939 btn->pid = execCommand(btn, btn->dnd_command, NULL);
1940 if (btn->pid>0) {
1941 dockIconPaint(btn);
1942 } else {
1943 btn->launching = 0;
1944 if (!btn->relaunching) {
1945 btn->running = 0;
1949 return False;
1951 #endif /* OFFIX_DND */
1955 Bool
1956 wDockAttachIcon(WDock *dock, WAppIcon *icon, int x, int y)
1958 WWindow *wwin;
1959 char **argv;
1960 int argc;
1961 int index;
1963 wwin = icon->icon->owner;
1964 if (icon->command==NULL) {
1965 icon->editing = 0;
1966 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
1968 icon->command = FlattenStringList(argv, argc);
1969 XFreeStringList(argv);
1970 } else {
1971 char *command=NULL;
1973 /* icon->forced_dock = 1;*/
1974 if (!icon->attracted || dock->type!=WM_CLIP || dock->keep_attracted) {
1975 icon->editing = 1;
1976 if (wInputDialog(dock->screen_ptr, _("Dock Icon"),
1977 _("Type the command used to launch the application"),
1978 &command)) {
1979 if (command && (command[0]==0 ||
1980 (command[0]=='-' && command[1]==0))) {
1981 free(command);
1982 command = NULL;
1984 icon->command = command;
1985 icon->editing = 0;
1986 } else {
1987 icon->editing = 0;
1988 if (command)
1989 free(command);
1990 /* If the target is the dock, reject the icon. If
1991 * the target is the clip, make it an attracted icon
1993 if (dock->type==WM_CLIP) {
1994 icon->attracted = 1;
1995 if (!icon->icon->shadowed) {
1996 icon->icon->shadowed = 1;
1997 icon->icon->force_paint = 1;
1999 } else {
2000 return False;
2005 } else {
2006 icon->editing = 0;
2009 for (index=1; index<dock->max_icons; index++)
2010 if (dock->icon_array[index] == NULL)
2011 break;
2012 /* if (index == dock->max_icons)
2013 return; */
2015 assert(index < dock->max_icons);
2017 dock->icon_array[index] = icon;
2018 icon->yindex = y;
2019 icon->xindex = x;
2021 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2022 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2024 dock->icon_count++;
2026 icon->running = 1;
2027 icon->launching = 0;
2028 icon->docked = 1;
2029 icon->dock = dock;
2030 icon->icon->core->descriptor.handle_mousedown = iconMouseDown;
2031 if (dock->type == WM_CLIP) {
2032 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2033 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2035 icon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
2036 icon->icon->core->descriptor.parent = icon;
2038 MoveInStackListUnder(dock->icon_array[index-1]->icon->core,
2039 icon->icon->core);
2040 wAppIconMove(icon, icon->x_pos, icon->y_pos);
2041 wAppIconPaint(icon);
2043 if (wPreferences.auto_arrange_icons)
2044 wArrangeIcons(dock->screen_ptr, True);
2046 #ifdef OFFIX_DND
2047 if (icon->command && !icon->dnd_command) {
2048 icon->dnd_command = wmalloc(strlen(icon->command)+8);
2049 sprintf(icon->dnd_command, "%s %%d", icon->command);
2051 #endif
2053 return True;
2057 void
2058 reattachIcon(WDock *dock, WAppIcon *icon, int x, int y)
2060 int index;
2062 for(index=1; index<dock->max_icons; index++) {
2063 if(dock->icon_array[index] == icon)
2064 break;
2066 assert(index < dock->max_icons);
2068 icon->yindex = y;
2069 icon->xindex = x;
2071 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2072 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2076 Bool
2077 moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y)
2079 WWindow *wwin;
2080 char **argv;
2081 int argc;
2082 int index;
2084 if (dest == NULL)
2085 return False;
2087 wwin = icon->icon->owner;
2090 * For the moment we can't do this if we move icons in Clip from one
2091 * workspace to other, because if we move two or more icons without
2092 * command, the dialog box will not be able to tell us to which of the
2093 * moved icons it applies. -Dan
2095 if ((dest->type==WM_DOCK /*|| dest->keep_attracted*/) && icon->command==NULL) {
2096 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
2098 icon->command = FlattenStringList(argv, argc);
2099 XFreeStringList(argv);
2100 } else {
2101 char *command=NULL;
2103 icon->editing = 1;
2104 /* icon->forced_dock = 1;*/
2105 if (wInputDialog(src->screen_ptr, _("Dock Icon"),
2106 _("Type the command used to launch the application"),
2107 &command)) {
2108 if (command && (command[0]==0 ||
2109 (command[0]=='-' && command[1]==0))) {
2110 free(command);
2111 command = NULL;
2113 icon->command = command;
2114 } else {
2115 icon->editing = 0;
2116 if (command)
2117 free(command);
2118 return False;
2120 icon->editing = 0;
2124 for(index=1; index<src->max_icons; index++) {
2125 if(src->icon_array[index] == icon)
2126 break;
2128 assert(index < src->max_icons);
2130 src->icon_array[index] = NULL;
2131 src->icon_count--;
2133 for(index=1; index<dest->max_icons; index++) {
2134 if(dest->icon_array[index] == NULL)
2135 break;
2137 /* if (index == dest->max_icons)
2138 return; */
2140 assert(index < dest->max_icons);
2142 dest->icon_array[index] = icon;
2143 icon->dock = dest;
2145 /* deselect the icon */
2146 if (icon->icon->selected)
2147 wIconSelect(icon->icon);
2149 if (dest->type == WM_DOCK) {
2150 icon->icon->core->descriptor.handle_enternotify = NULL;
2151 icon->icon->core->descriptor.handle_leavenotify = NULL;
2152 } else {
2153 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2154 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2157 /* set it to be kept when moving to dock, or to a clip that keep the
2158 * attracted icons.
2159 * Unless the icon does not have a command set
2161 if (icon->command && (dest->type==WM_DOCK || dest->keep_attracted)) {
2162 icon->attracted = 0;
2163 if (icon->icon->shadowed) {
2164 icon->icon->shadowed = 0;
2165 icon->icon->force_paint = 1;
2169 if (src->auto_collapse || src->auto_raise_lower)
2170 clipLeave(src);
2172 icon->yindex = y;
2173 icon->xindex = x;
2175 icon->x_pos = dest->x_pos + x*ICON_SIZE;
2176 icon->y_pos = dest->y_pos + y*ICON_SIZE;
2178 dest->icon_count++;
2180 MoveInStackListUnder(dest->icon_array[index-1]->icon->core,
2181 icon->icon->core);
2182 wAppIconPaint(icon);
2184 return True;
2188 void
2189 wDockDetach(WDock *dock, WAppIcon *icon)
2191 int index;
2193 /* make the settings panel be closed */
2194 if (icon->panel) {
2195 DestroyDockAppSettingsPanel(icon->panel);
2198 icon->docked = 0;
2199 icon->dock = NULL;
2200 icon->attracted = 0;
2201 if (icon->icon->shadowed) {
2202 icon->icon->shadowed = 0;
2203 icon->icon->force_paint = 1;
2206 /* deselect the icon */
2207 if (icon->icon->selected)
2208 wIconSelect(icon->icon);
2210 if (icon->command) {
2211 free(icon->command);
2212 icon->command = NULL;
2214 #ifdef OFFIX_DND
2215 if (icon->dnd_command) {
2216 free(icon->dnd_command);
2217 icon->dnd_command = NULL;
2219 #endif
2221 for (index=1; index<dock->max_icons; index++)
2222 if (dock->icon_array[index] == icon)
2223 break;
2224 assert(index < dock->max_icons);
2225 dock->icon_array[index] = NULL;
2226 icon->yindex = -1;
2227 icon->xindex = -1;
2228 dock->icon_count--;
2230 /* if the dock is not attached to an application or
2231 * the the application did not set the approriate hints yet,
2232 * destroy the icon */
2233 #ifdef REDUCE_APPICONS
2234 if ((icon->num_apps == 0) && (!icon->running || !wApplicationOf(icon->main_window)) )
2235 #else
2236 if (!icon->running || !wApplicationOf(icon->main_window))
2237 #endif
2238 wAppIconDestroy(icon);
2239 else {
2240 icon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
2241 icon->icon->core->descriptor.handle_enternotify = NULL;
2242 icon->icon->core->descriptor.handle_leavenotify = NULL;
2243 icon->icon->core->descriptor.parent_type = WCLASS_APPICON;
2244 icon->icon->core->descriptor.parent = icon;
2246 ChangeStackingLevel(icon->icon->core, NORMAL_ICON_LEVEL);
2248 wAppIconPaint(icon);
2249 if (wPreferences.auto_arrange_icons) {
2250 wArrangeIcons(dock->screen_ptr, True);
2253 if (dock->auto_collapse || dock->auto_raise_lower)
2254 clipLeave(dock);
2259 * returns the closest Dock slot index for the passed
2260 * coordinates.
2262 * Returns False if icon can't be docked.
2264 Bool
2265 wDockSnapIcon(WDock *dock, WAppIcon *icon, int req_x, int req_y,
2266 int *ret_x, int *ret_y, int redocking)
2268 WScreen *scr = dock->screen_ptr;
2269 int dx, dy;
2270 int ex_x, ex_y;
2271 int i, offset = ICON_SIZE/2;
2272 WAppIcon *aicon = NULL;
2273 WAppIcon *nicon = NULL;
2274 int max_y_icons, max_x_icons;
2276 max_x_icons = scr->scr_width/ICON_SIZE;
2277 max_y_icons = scr->scr_height/ICON_SIZE-1;
2279 if (wPreferences.flags.noupdates)
2280 return False;
2282 dx = dock->x_pos;
2283 dy = dock->y_pos;
2285 /* if the dock is full */
2286 if (!redocking &&
2287 (dock->icon_count >= dock->max_icons)) {
2288 return False;
2291 /* exact position */
2292 if (req_y < dy)
2293 ex_y = (req_y - offset - dy)/ICON_SIZE;
2294 else
2295 ex_y = (req_y + offset - dy)/ICON_SIZE;
2297 if (req_x < dx)
2298 ex_x = (req_x - offset - dx)/ICON_SIZE;
2299 else
2300 ex_x = (req_x + offset - dx)/ICON_SIZE;
2302 /* check if the icon is outside the screen boundaries */
2303 if (dx + ex_x*ICON_SIZE < -ICON_SIZE+2 ||
2304 dx + ex_x*ICON_SIZE >= scr->scr_width-1 ||
2305 dy + ex_y*ICON_SIZE < -ICON_SIZE+2 ||
2306 dy + ex_y*ICON_SIZE >= scr->scr_height-1)
2307 return False;
2309 if (dock->type == WM_DOCK) {
2310 if (icon->dock != dock && ex_x != 0)
2311 return False;
2313 for (i=0; i<dock->max_icons; i++) {
2314 nicon = dock->icon_array[i];
2315 if (nicon && nicon->yindex == ex_y) {
2316 aicon = nicon;
2317 break;
2321 *ret_x = 0;
2323 if (redocking) {
2324 int sig, done, closest;
2326 /* Possible cases when redocking:
2328 * icon dragged out of range of any slot -> false
2329 * icon dragged to range of free slot
2330 * icon dragged to range of same slot
2331 * icon dragged to range of different icon
2333 if (abs(ex_x) > DOCK_DETTACH_THRESHOLD)
2334 return False;
2336 if (ex_y >= 0 && ex_y <= max_y_icons && (aicon == icon || !aicon)) {
2338 *ret_y = ex_y;
2341 return True;
2344 /* start looking at the upper slot or lower? */
2345 if (ex_y*ICON_SIZE < (req_y + offset - dy))
2346 sig = 1;
2347 else
2348 sig = -1;
2350 closest = -1;
2351 done = 0;
2352 /* look for closest free slot */
2353 for (i=0; i<(DOCK_DETTACH_THRESHOLD+1)*2 && !done; i++) {
2354 int j;
2356 done = 1;
2357 closest = sig*(i/2) + ex_y;
2358 /* check if this slot is used */
2359 if (closest >= 0) {
2360 for (j = 0; j<dock->max_icons; j++) {
2361 if (dock->icon_array[j]
2362 && dock->icon_array[j]->yindex==closest) {
2363 /* slot is used by someone else */
2364 if (dock->icon_array[j]!=icon)
2365 done = 0;
2366 break;
2370 sig = -sig;
2372 if (done && closest >= 0 && closest <= max_y_icons &&
2373 ((ex_y >= closest && ex_y - closest < DOCK_DETTACH_THRESHOLD+1)
2375 (ex_y < closest && closest - ex_y <= DOCK_DETTACH_THRESHOLD+1))) {
2377 *ret_y = closest;
2379 return True;
2381 } else { /* !redocking */
2383 /* if slot is free and the icon is close enough, return it */
2384 if (!aicon && ex_x == 0 && ex_y >= 0 && ex_y <= max_y_icons) {
2385 *ret_y = ex_y;
2386 return True;
2389 } else { /* CLIP */
2390 int neighbours = 0;
2392 for (i=0; i<dock->max_icons; i++) {
2393 nicon = dock->icon_array[i];
2394 if (nicon && nicon->xindex == ex_x && nicon->yindex == ex_y) {
2395 aicon = nicon;
2396 break;
2400 for (i=0; i<dock->max_icons; i++) {
2401 nicon = dock->icon_array[i];
2402 if (nicon && nicon != icon && /* Icon can't be it's own neighbour */
2403 (abs(nicon->xindex - ex_x) <= CLIP_ATTACH_VICINITY &&
2404 abs(nicon->yindex - ex_y) <= CLIP_ATTACH_VICINITY)) {
2405 neighbours = 1;
2406 break;
2410 if (neighbours && (aicon==NULL || (redocking && aicon == icon))) {
2411 *ret_x = ex_x;
2412 *ret_y = ex_y;
2413 return True;
2416 return False;
2419 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2420 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2422 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2423 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2424 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2428 * returns true if it can find a free slot in the dock,
2429 * in which case it changes x_pos and y_pos accordingly.
2430 * Else returns false.
2432 Bool
2433 wDockFindFreeSlot(WDock *dock, int *x_pos, int *y_pos)
2435 WScreen *scr = dock->screen_ptr;
2436 WAppIcon *btn;
2437 unsigned char *slot_map;
2438 int mwidth;
2439 int r;
2440 int x, y;
2441 int i, done = False;
2442 int corner;
2443 int sx=0, sy=0, ex=scr->scr_width, ey=scr->scr_height;
2446 /* if the dock is full */
2447 if (dock->icon_count >= dock->max_icons) {
2448 return False;
2451 if (!wPreferences.flags.nodock && scr->dock) {
2452 if (scr->dock->on_right_side)
2453 ex -= ICON_SIZE + DOCK_EXTRA_SPACE;
2454 else
2455 sx += ICON_SIZE + DOCK_EXTRA_SPACE;
2458 if (ex < dock->x_pos)
2459 ex = dock->x_pos;
2460 if (sx > dock->x_pos+ICON_SIZE)
2461 sx = dock->x_pos+ICON_SIZE;
2462 #define C_NONE 0
2463 #define C_NW 1
2464 #define C_NE 2
2465 #define C_SW 3
2466 #define C_SE 4
2468 /* check if clip is in a corner */
2469 if (dock->type==WM_CLIP) {
2470 if (dock->x_pos < 1 && dock->y_pos < 1)
2471 corner = C_NE;
2472 else if (dock->x_pos < 1 && dock->y_pos >= (ey-ICON_SIZE))
2473 corner = C_SE;
2474 else if (dock->x_pos >= (ex-ICON_SIZE)&& dock->y_pos >= (ey-ICON_SIZE))
2475 corner = C_SW;
2476 else if (dock->x_pos >= (ex-ICON_SIZE) && dock->y_pos < 1)
2477 corner = C_NW;
2478 else
2479 corner = C_NONE;
2480 } else
2481 corner = C_NONE;
2483 /* If the clip is in the corner, use only slots that are in the border
2484 * of the screen */
2485 if (corner!=C_NONE) {
2486 char *hmap, *vmap;
2487 int hcount, vcount;
2489 hcount = MIN(dock->max_icons, scr->scr_width/ICON_SIZE);
2490 vcount = MIN(dock->max_icons, scr->scr_height/ICON_SIZE);
2491 hmap = wmalloc(hcount+1);
2492 memset(hmap, 0, hcount+1);
2493 vmap = wmalloc(vcount+1);
2494 memset(vmap, 0, vcount+1);
2496 /* mark used positions */
2497 switch (corner) {
2498 case C_NE:
2499 for (i=0; i<dock->max_icons; i++) {
2500 btn = dock->icon_array[i];
2501 if (!btn)
2502 continue;
2504 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2505 vmap[btn->yindex] = 1;
2506 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2507 hmap[btn->xindex] = 1;
2509 case C_NW:
2510 for (i=0; i<dock->max_icons; i++) {
2511 btn = dock->icon_array[i];
2512 if (!btn)
2513 continue;
2515 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2516 vmap[btn->yindex] = 1;
2517 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2518 hmap[-btn->xindex] = 1;
2520 case C_SE:
2521 for (i=0; i<dock->max_icons; i++) {
2522 btn = dock->icon_array[i];
2523 if (!btn)
2524 continue;
2526 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2527 vmap[-btn->yindex] = 1;
2528 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2529 hmap[btn->xindex] = 1;
2531 case C_SW:
2532 default:
2533 for (i=0; i<dock->max_icons; i++) {
2534 btn = dock->icon_array[i];
2535 if (!btn)
2536 continue;
2538 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2539 vmap[-btn->yindex] = 1;
2540 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2541 hmap[-btn->xindex] = 1;
2544 x=0; y=0;
2545 done = 0;
2546 /* search a vacant slot */
2547 for (i=1; i<MAX(vcount, hcount); i++) {
2548 if (i < vcount && vmap[i]==0) {
2549 /* found a slot */
2550 x = 0;
2551 y = i;
2552 done = 1;
2553 break;
2554 } else if (i < hcount && hmap[i]==0) {
2555 /* found a slot */
2556 x = i;
2557 y = 0;
2558 done = 1;
2559 break;
2562 free(vmap);
2563 free(hmap);
2564 /* If found a slot, translate and return */
2565 if (done) {
2566 if (corner==C_NW || corner==C_NE) {
2567 *y_pos = y;
2568 } else {
2569 *y_pos = -y;
2571 if (corner==C_NE || corner==C_SE) {
2572 *x_pos = x;
2573 } else {
2574 *x_pos = -x;
2576 return True;
2578 /* else, try to find a slot somewhere else */
2581 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2582 * placed outside of screen */
2583 mwidth = (int)ceil(sqrt(dock->max_icons));
2585 /* In the worst case (the clip is in the corner of the screen),
2586 * the amount of icons that fit in the clip is smaller.
2587 * Double the map to get a safe value.
2589 mwidth += mwidth;
2591 r = (mwidth-1)/2;
2593 slot_map = wmalloc(mwidth*mwidth);
2594 memset(slot_map, 0, mwidth*mwidth);
2596 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2598 /* mark used slots in the map. If the slot falls outside the map
2599 * (for example, when all icons are placed in line), ignore them. */
2600 for (i=0; i<dock->max_icons; i++) {
2601 btn = dock->icon_array[i];
2602 if (btn)
2603 slot_map[XY2OFS(btn->xindex, btn->yindex)] = 1;
2605 /* Find closest slot from the center that is free by scanning the
2606 * map from the center to outward in circular passes.
2607 * This will not result in a neat layout, but will be optimal
2608 * in the sense that there will not be holes left.
2610 done = 0;
2611 for (i = 1; i <= r && !done; i++) {
2612 int tx, ty;
2614 /* top and bottom parts of the ring */
2615 for (x = -i; x <= i && !done; x++) {
2616 tx = dock->x_pos + x*ICON_SIZE;
2617 y = -i;
2618 ty = dock->y_pos + y*ICON_SIZE;
2619 if (slot_map[XY2OFS(x,y)]==0
2620 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2621 *x_pos = x;
2622 *y_pos = y;
2623 done = 1;
2624 break;
2626 y = i;
2627 ty = dock->y_pos + y*ICON_SIZE;
2628 if (slot_map[XY2OFS(x,y)]==0
2629 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2630 *x_pos = x;
2631 *y_pos = y;
2632 done = 1;
2633 break;
2636 /* left and right parts of the ring */
2637 for (y = -i+1; y <= i-1; y++) {
2638 ty = dock->y_pos + y*ICON_SIZE;
2639 x = -i;
2640 tx = dock->x_pos + x*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;
2648 x = i;
2649 tx = dock->x_pos + x*ICON_SIZE;
2650 if (slot_map[XY2OFS(x,y)]==0
2651 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2652 *x_pos = x;
2653 *y_pos = y;
2654 done = 1;
2655 break;
2659 free(slot_map);
2660 #undef XY2OFS
2661 return done;
2665 static void
2666 moveDock(WDock *dock, int new_x, int new_y)
2668 WAppIcon *btn;
2669 int i;
2671 dock->x_pos = new_x;
2672 dock->y_pos = new_y;
2673 for (i=0; i<dock->max_icons; i++) {
2674 btn = dock->icon_array[i];
2675 if (btn) {
2676 btn->x_pos = new_x + btn->xindex*ICON_SIZE;
2677 btn->y_pos = new_y + btn->yindex*ICON_SIZE;
2678 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2684 static void
2685 swapDock(WDock *dock)
2687 WScreen *scr = dock->screen_ptr;
2688 WAppIcon *btn;
2689 int x, i;
2692 if (dock->on_right_side) {
2693 x = dock->x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
2694 } else {
2695 x = dock->x_pos = DOCK_EXTRA_SPACE;
2698 for (i=0; i<dock->max_icons; i++) {
2699 btn = dock->icon_array[i];
2700 if (btn) {
2701 btn->x_pos = x;
2702 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2706 wScreenUpdateUsableArea(scr);
2710 static pid_t
2711 execCommand(WAppIcon *btn, char *command, WSavedState *state)
2713 WScreen *scr = btn->icon->core->screen_ptr;
2714 pid_t pid;
2715 char **argv;
2716 int argc;
2717 char *cmdline;
2719 cmdline = ExpandOptions(scr, command);
2721 if (scr->flags.dnd_data_convertion_status || !cmdline) {
2722 if (cmdline)
2723 free(cmdline);
2724 if (state)
2725 free(state);
2726 return 0;
2729 ParseCommand(cmdline, &argv, &argc);
2731 if (argv==NULL) {
2732 if (cmdline)
2733 free(cmdline);
2734 if (state)
2735 free(state);
2736 return 0;
2739 if ((pid=fork())==0) {
2740 char **args;
2741 int i;
2743 SetupEnvironment(scr);
2745 #ifdef HAVE_SETPGID
2746 setpgid(0, 0);
2747 #endif
2749 args = malloc(sizeof(char*)*(argc+1));
2750 if (!args)
2751 exit(111);
2752 for (i=0; i<argc; i++) {
2753 args[i] = argv[i];
2755 args[argc] = NULL;
2756 execvp(argv[0], args);
2757 exit(111);
2759 while (argc > 0)
2760 free(argv[--argc]);
2761 free(argv);
2763 if (pid > 0) {
2764 if (!state) {
2765 state = wmalloc(sizeof(WSavedState));
2766 memset(state, 0, sizeof(WSavedState));
2767 state->hidden = -1;
2768 state->miniaturized = -1;
2769 state->shaded = -1;
2770 if (btn->dock == scr->dock)
2771 state->workspace = -1;
2772 else
2773 state->workspace = scr->current_workspace;
2775 wWindowAddSavedState(btn->wm_instance, btn->wm_class, cmdline, pid,
2776 state);
2777 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess,
2778 btn->dock);
2779 } else if (state) {
2780 free(state);
2782 free(cmdline);
2783 return pid;
2787 void
2788 wDockHideIcons(WDock *dock)
2790 int i;
2791 WAppIcon *btn;
2793 if (dock==NULL)
2794 return;
2796 btn = dock->icon_array[0];
2798 for (i=1; i<dock->max_icons; i++) {
2799 if (dock->icon_array[i])
2800 XUnmapWindow(dpy, dock->icon_array[i]->icon->core->window);
2802 dock->mapped = 0;
2804 dockIconPaint(btn);
2808 void
2809 wDockShowIcons(WDock *dock)
2811 int i, newlevel;
2812 WAppIcon *btn;
2814 if (dock==NULL)
2815 return;
2817 btn = dock->icon_array[0];
2818 moveDock(dock, btn->x_pos, btn->y_pos);
2820 newlevel = dock->lowered ? WMNormalLevel : WMDockLevel;
2821 ChangeStackingLevel(btn->icon->core, newlevel);
2823 for (i=1; i<dock->max_icons; i++) {
2824 if (dock->icon_array[i]) {
2825 MoveInStackListAbove(dock->icon_array[i]->icon->core,
2826 btn->icon->core);
2827 break;
2831 if (!dock->collapsed) {
2832 for (i=1; i<dock->max_icons; i++) {
2833 if (dock->icon_array[i]) {
2834 XMapWindow(dpy, dock->icon_array[i]->icon->core->window);
2838 dock->mapped = 1;
2840 dockIconPaint(btn);
2844 void
2845 wDockLower(WDock *dock)
2847 int i;
2849 for (i=0; i<dock->max_icons; i++) {
2850 if (dock->icon_array[i])
2851 wLowerFrame(dock->icon_array[i]->icon->core);
2856 void
2857 wDockRaise(WDock *dock)
2859 int i;
2861 for (i=dock->max_icons-1; i>=0; i--) {
2862 if (dock->icon_array[i])
2863 wRaiseFrame(dock->icon_array[i]->icon->core);
2868 void
2869 wDockRaiseLower(WDock *dock)
2871 if (!dock->icon_array[0]->icon->core->stacking->above
2872 ||(dock->icon_array[0]->icon->core->stacking->window_level
2873 !=dock->icon_array[0]->icon->core->stacking->above->stacking->window_level))
2874 wDockLower(dock);
2875 else
2876 wDockRaise(dock);
2880 void
2881 wDockFinishLaunch(WDock *dock, WAppIcon *icon)
2883 icon->launching = 0;
2884 icon->relaunching = 0;
2885 dockIconPaint(icon);
2889 WAppIcon*
2890 wDockFindIconFor(WDock *dock, Window window)
2892 WAppIcon *icon;
2893 int i;
2895 for (i=0; i<dock->max_icons; i++) {
2896 icon = dock->icon_array[i];
2897 if (icon && icon->main_window == window)
2898 return icon;
2900 return NULL;
2904 void
2905 wDockTrackWindowLaunch(WDock *dock, Window window)
2907 WAppIcon *icon;
2908 #ifdef REDUCE_APPICONS
2909 WAppIconAppList *tapplist;
2910 #endif
2911 char *wm_class, *wm_instance;
2912 int i;
2913 Bool firstPass = True;
2914 Bool found = False;
2915 char *command = NULL;
2918 int argc;
2919 char **argv;
2921 if (XGetCommand(dpy, window, &argv, &argc)) {
2922 if (argc > 0 && argv != NULL)
2923 command = FlattenStringList(argv,argc);
2924 if (argv) {
2925 XFreeStringList(argv);
2930 if (!PropGetWMClass(window, &wm_class, &wm_instance) ||
2931 (!wm_class && !wm_instance))
2932 return;
2934 retry:
2935 for (i=0; i<dock->max_icons; i++) {
2936 icon = dock->icon_array[i];
2937 if (!icon)
2938 continue;
2940 /* app is already attached to icon */
2941 if (icon->main_window == window) {
2942 found = True;
2943 break;
2946 if ((icon->wm_instance || icon->wm_class)
2947 && (icon->launching
2948 || (dock->screen_ptr->flags.startup && !icon->running))) {
2950 if (icon->wm_instance && wm_instance &&
2951 strcmp(icon->wm_instance, wm_instance)!=0) {
2952 continue;
2954 if (icon->wm_class && wm_class &&
2955 strcmp(icon->wm_class, wm_class)!=0) {
2956 continue;
2958 if (firstPass && command && strcmp(icon->command, command)!=0) {
2959 continue;
2962 if (!icon->relaunching) {
2963 WApplication *wapp;
2965 /* Possibly an application that was docked with dockit,
2966 * but the user did not update WMState to indicate that
2967 * it was docked by force */
2968 wapp = wApplicationOf(window);
2969 if (!wapp) {
2970 icon->forced_dock = 1;
2971 icon->running = 0;
2973 if (!icon->forced_dock)
2974 icon->main_window = window;
2976 #ifdef REDUCE_APPICONS
2977 tapplist = wmalloc(sizeof(WAppIconAppList));
2978 memset(tapplist, 0, sizeof(WAppIconAppList));
2979 tapplist->next = icon->applist;
2980 if (icon->applist)
2981 icon->applist->prev = tapplist;
2982 icon->applist = tapplist;
2983 tapplist->wapp = wApplicationOf(window);
2984 icon->num_apps++;
2985 #endif
2987 found = True;
2988 wDockFinishLaunch(dock, icon);
2989 break;
2993 if (firstPass && !found) {
2994 firstPass = False;
2995 goto retry;
2998 if (command)
2999 free(command);
3001 if (wm_class)
3002 XFree(wm_class);
3003 if (wm_instance)
3004 XFree(wm_instance);
3009 void
3010 wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
3012 if (!wPreferences.flags.noclip) {
3013 scr->clip_icon->dock = scr->workspaces[workspace]->clip;
3014 if (scr->current_workspace != workspace) {
3015 WDock *old_clip = scr->workspaces[scr->current_workspace]->clip;
3017 wDockHideIcons(old_clip);
3018 if (old_clip->auto_raise_lower)
3019 wDockLower(old_clip);
3020 if (old_clip->auto_collapse && !old_clip->collapsed)
3021 old_clip->collapsed = 1;
3022 wDockShowIcons(scr->workspaces[workspace]->clip);
3024 if (scr->flags.clip_balloon_mapped)
3025 showClipBalloon(scr->clip_icon->dock, workspace);
3031 static void
3032 trackDeadProcess(pid_t pid, unsigned char status, WDock *dock)
3034 WAppIcon *icon;
3035 int i;
3037 for (i=0; i<dock->max_icons; i++) {
3038 icon = dock->icon_array[i];
3039 if (!icon)
3040 continue;
3042 if (icon->launching && icon->pid == pid) {
3043 if (!icon->relaunching) {
3044 icon->running = 0;
3045 icon->main_window = None;
3047 wDockFinishLaunch(dock, icon);
3048 icon->pid = 0;
3049 if (status==111) {
3050 char msg[PATH_MAX];
3051 #ifdef OFFIX_DND
3052 sprintf(msg, _("Could not execute command \"%s\""),
3053 icon->drop_launch && icon->dnd_command
3054 ? icon->dnd_command : icon->command);
3055 #else
3056 sprintf(msg, _("Could not execute command \"%s\""),
3057 icon->command);
3058 #endif
3059 wMessageDialog(dock->screen_ptr, _("Error"), msg,
3060 _("OK"), NULL, NULL);
3062 break;
3068 static void
3069 toggleLowered(WDock *dock)
3071 WAppIcon *tmp;
3072 int newlevel, i;
3074 /* lower/raise Dock */
3075 if (!dock->lowered) {
3076 newlevel = WMNormalLevel;
3077 dock->lowered = 1;
3078 } else {
3079 newlevel = WMDockLevel;
3080 dock->lowered = 0;
3083 for (i=0; i<dock->max_icons; i++) {
3084 tmp = dock->icon_array[i];
3085 if (!tmp)
3086 continue;
3088 ChangeStackingLevel(tmp->icon->core, newlevel);
3089 if (dock->lowered)
3090 wLowerFrame(tmp->icon->core);
3093 if (dock->type == WM_DOCK)
3094 wScreenUpdateUsableArea(dock->screen_ptr);
3098 static void
3099 toggleCollapsed(WDock *dock)
3101 if (dock->collapsed) {
3102 dock->collapsed = 0;
3103 wDockShowIcons(dock);
3105 else {
3106 dock->collapsed = 1;
3107 wDockHideIcons(dock);
3112 static void
3113 openDockMenu(WDock *dock, WAppIcon *aicon, XEvent *event)
3115 WScreen *scr = dock->screen_ptr;
3116 WObjDescriptor *desc;
3117 WMenuEntry *entry;
3118 WApplication *wapp = NULL;
3119 int index = 0;
3120 int x_pos;
3121 int appIsRunning = aicon->running && aicon->icon && aicon->icon->owner;
3123 if (dock->type == WM_DOCK) {
3124 /* keep on top */
3125 entry = dock->menu->entries[index];
3126 entry->flags.indicator_on = !dock->lowered;
3127 entry->clientdata = dock;
3128 } else {
3129 /* clip options */
3130 if (scr->clip_options)
3131 updateClipOptionsMenu(scr->clip_options, dock);
3133 /* Rename Workspace */
3134 entry = dock->menu->entries[++index];
3135 entry->clientdata = dock;
3137 /* select icon */
3138 entry = dock->menu->entries[++index];
3139 entry->clientdata = aicon;
3140 wMenuSetEnabled(dock->menu, index, aicon!=scr->clip_icon);
3142 /* (un)select all icons */
3143 entry = dock->menu->entries[++index];
3144 entry->clientdata = aicon;
3145 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3147 /* keep icon(s) */
3148 entry = dock->menu->entries[++index];
3149 entry->clientdata = aicon;
3150 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3152 /* this is the workspace submenu part */
3153 if (scr->clip_submenu)
3154 updateWorkspaceMenu(scr->clip_submenu, aicon);
3155 index++;
3157 /* remove icon(s) */
3158 entry = dock->menu->entries[++index];
3159 entry->clientdata = aicon;
3160 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3162 /* attract icon(s) */
3163 entry = dock->menu->entries[++index];
3164 entry->clientdata = aicon;
3167 /* launch */
3168 entry = dock->menu->entries[++index];
3169 entry->clientdata = aicon;
3170 wMenuSetEnabled(dock->menu, index, aicon->command!=NULL);
3172 /* unhide here */
3173 entry = dock->menu->entries[++index];
3174 entry->clientdata = aicon;
3175 wMenuSetEnabled(dock->menu, index, appIsRunning);
3177 /* hide */
3178 entry = dock->menu->entries[++index];
3179 entry->clientdata = aicon;
3180 if (aicon->icon->owner) {
3181 wapp = wApplicationOf(aicon->icon->owner->main_window);
3182 if (wapp && wapp->flags.hidden)
3183 entry->text = _("Unhide");
3184 else
3185 entry->text = _("Hide");
3186 } else {
3187 entry->text = _("Hide");
3189 wMenuSetEnabled(dock->menu, index, appIsRunning);
3191 /* settings */
3192 entry = dock->menu->entries[++index];
3193 entry->clientdata = aicon;
3194 wMenuSetEnabled(dock->menu, index, !aicon->editing
3195 && !wPreferences.flags.noupdates);
3197 /* kill */
3198 entry = dock->menu->entries[++index];
3199 entry->clientdata = aicon;
3200 wMenuSetEnabled(dock->menu, index, appIsRunning);
3202 if (!dock->menu->flags.realized)
3203 wMenuRealize(dock->menu);
3205 if (dock->type == WM_CLIP) {
3206 x_pos = event->xbutton.x_root+2;
3207 } else {
3208 x_pos = dock->on_right_side ?
3209 scr->scr_width - dock->menu->frame->core->width - 2 : 0;
3212 wMenuMapAt(dock->menu, x_pos, event->xbutton.y_root+2, False);
3214 /* allow drag select */
3215 event->xany.send_event = True;
3216 desc = &dock->menu->menu->descriptor;
3217 (*desc->handle_mousedown)(desc, event);
3221 static void
3222 openClipWorkspaceMenu(WScreen *scr, int x, int y)
3224 if (!scr->clip_ws_menu) {
3225 scr->clip_ws_menu = wWorkspaceMenuMake(scr, False);
3227 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
3228 wMenuMapAt(scr->clip_ws_menu, x, y, False);
3232 /******************************************************************/
3233 static void
3234 iconDblClick(WObjDescriptor *desc, XEvent *event)
3236 WAppIcon *btn = desc->parent;
3237 WDock *dock = btn->dock;
3238 WApplication *wapp = NULL;
3239 int unhideHere = 0;
3241 #ifdef REDUCE_APPICONS
3242 if ((btn->icon->owner && !(event->xbutton.state & ControlMask)) ||
3243 ((btn->icon->owner == NULL) && (btn->applist != NULL))) {
3244 if (btn->icon->owner == NULL)
3245 btn->icon->owner = btn->applist->wapp->main_window_desc;
3246 #ifdef I_HATE_THIS
3248 #endif
3249 #else
3250 if (btn->icon->owner && !(event->xbutton.state & ControlMask)) {
3251 #endif
3252 wapp = wApplicationOf(btn->icon->owner->main_window);
3254 assert(wapp!=NULL);
3256 unhideHere = (event->xbutton.state & ShiftMask);
3258 /* go to the last workspace that the user worked on the app */
3259 if (!unhideHere) {
3260 wWorkspaceChange(dock->screen_ptr, wapp->last_workspace);
3263 wUnhideApplication(wapp, event->xbutton.button==Button2,
3264 unhideHere);
3266 if (event->xbutton.state & MOD_MASK) {
3267 wHideOtherApplications(btn->icon->owner);
3269 } else {
3270 if (event->xbutton.button==Button1) {
3272 if (event->xbutton.state & MOD_MASK) {
3273 /* raise/lower dock */
3274 toggleLowered(dock);
3275 } else if (btn == dock->screen_ptr->clip_icon) {
3276 if (getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE)
3277 toggleCollapsed(dock);
3278 else
3279 handleClipChangeWorkspace(dock->screen_ptr, event);
3280 } else if (btn->command) {
3281 if (!btn->launching &&
3282 (!btn->running || (event->xbutton.state & ControlMask))) {
3283 launchDockedApplication(btn);
3291 static void
3292 handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3294 WScreen *scr = dock->screen_ptr;
3295 int ofs_x=event->xbutton.x, ofs_y=event->xbutton.y;
3296 int x, y;
3297 XEvent ev;
3298 int grabbed = 0, swapped = 0, done;
3299 Pixmap ghost = None;
3300 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3302 #ifdef DEBUG
3303 puts("moving dock");
3304 #endif
3305 if (XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
3306 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3307 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3308 wwarning("pointer grab failed for dock move");
3310 y = 0;
3311 for (x=0; x<dock->max_icons; x++) {
3312 if (dock->icon_array[x]!=NULL &&
3313 dock->icon_array[x]->yindex > y)
3314 y = dock->icon_array[x]->yindex;
3316 y++;
3317 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE*y);
3319 done = 0;
3320 while (!done) {
3321 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3322 |ButtonMotionMask|ExposureMask, &ev);
3323 switch (ev.type) {
3324 case Expose:
3325 WMHandleEvent(&ev);
3326 break;
3328 case MotionNotify:
3329 if (!grabbed) {
3330 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3331 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3332 XChangeActivePointerGrab(dpy, ButtonMotionMask
3333 |ButtonReleaseMask|ButtonPressMask,
3334 wCursor[WCUR_MOVE], CurrentTime);
3335 grabbed=1;
3337 break;
3339 if (dock->type == WM_CLIP) {
3340 if (ev.xmotion.x_root - ofs_x < 0) {
3341 x = 0;
3342 } else if (ev.xmotion.x_root - ofs_x + ICON_SIZE >
3343 scr->scr_width) {
3344 x = scr->scr_width - ICON_SIZE;
3345 } else {
3346 x = ev.xmotion.x_root - ofs_x;
3348 if (ev.xmotion.y_root - ofs_y < 0) {
3349 y = 0;
3350 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3351 scr->scr_height) {
3352 y = scr->scr_height - ICON_SIZE;
3353 } else {
3354 y = ev.xmotion.y_root - ofs_y;
3356 moveDock(dock, x, y);
3357 } else {
3358 /* move vertically if pointer is inside the dock*/
3359 if ((dock->on_right_side &&
3360 ev.xmotion.x_root >= dock->x_pos - ICON_SIZE)
3361 || (!dock->on_right_side &&
3362 ev.xmotion.x_root <= dock->x_pos + ICON_SIZE*2)) {
3364 if (ev.xmotion.y_root - ofs_y < 0) {
3365 y = 0;
3366 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3367 scr->scr_height) {
3368 y = scr->scr_height - ICON_SIZE;
3369 } else {
3370 y = ev.xmotion.y_root - ofs_y;
3372 moveDock(dock, dock->x_pos, y);
3374 /* move horizontally to change sides */
3375 x = ev.xmotion.x_root - ofs_x;
3376 if (!dock->on_right_side) {
3378 /* is on left */
3380 if (ev.xmotion.x_root > dock->x_pos + ICON_SIZE*2) {
3381 XMoveWindow(dpy, scr->dock_shadow, scr->scr_width-ICON_SIZE
3382 -DOCK_EXTRA_SPACE-1, dock->y_pos);
3383 if (superfluous) {
3384 if (ghost==None) {
3385 ghost = MakeGhostDock(dock, dock->x_pos,
3386 scr->scr_width-ICON_SIZE
3387 -DOCK_EXTRA_SPACE-1,
3388 dock->y_pos);
3389 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3390 ghost);
3391 XClearWindow(dpy, scr->dock_shadow);
3394 XMapRaised(dpy, scr->dock_shadow);
3395 swapped = 1;
3396 } else {
3397 if (superfluous && ghost!=None) {
3398 XFreePixmap(dpy, ghost);
3399 ghost = None;
3401 XUnmapWindow(dpy, scr->dock_shadow);
3402 swapped = 0;
3404 } else {
3405 /* is on right */
3406 if (ev.xmotion.x_root < dock->x_pos - ICON_SIZE) {
3407 XMoveWindow(dpy, scr->dock_shadow,
3408 DOCK_EXTRA_SPACE, dock->y_pos);
3409 if (superfluous) {
3410 if (ghost==None) {
3411 ghost = MakeGhostDock(dock, dock->x_pos,
3412 DOCK_EXTRA_SPACE, dock->y_pos);
3413 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3414 ghost);
3415 XClearWindow(dpy, scr->dock_shadow);
3418 XMapRaised(dpy, scr->dock_shadow);
3419 swapped = -1;
3420 } else {
3421 XUnmapWindow(dpy, scr->dock_shadow);
3422 swapped = 0;
3423 if (superfluous && ghost!=None) {
3424 XFreePixmap(dpy, ghost);
3425 ghost = None;
3430 break;
3432 case ButtonPress:
3433 break;
3435 case ButtonRelease:
3436 if (ev.xbutton.button != event->xbutton.button)
3437 break;
3438 XUngrabPointer(dpy, CurrentTime);
3439 XUnmapWindow(dpy, scr->dock_shadow);
3440 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE);
3441 if (dock->type == WM_DOCK) {
3442 if (swapped!=0) {
3443 if (swapped>0)
3444 dock->on_right_side = 1;
3445 else
3446 dock->on_right_side = 0;
3447 swapDock(dock);
3448 wArrangeIcons(scr, False);
3451 done = 1;
3452 break;
3455 if (superfluous) {
3456 if (ghost!=None)
3457 XFreePixmap(dpy, ghost);
3458 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3460 #ifdef DEBUG
3461 puts("End dock move");
3462 #endif
3467 static void
3468 handleIconMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3470 WScreen *scr = dock->screen_ptr;
3471 Window wins[2];
3472 WIcon *icon = aicon->icon;
3473 WDock *dock2 = NULL, *last_dock = dock, *clip = NULL;
3474 int ondock, grabbed = 0, change_dock = 0, collapsed = 0;
3475 XEvent ev;
3476 int x = aicon->x_pos, y = aicon->y_pos;
3477 int ofs_x = event->xbutton.x, ofs_y = event->xbutton.y;
3478 int shad_x = x, shad_y = y;
3479 int ix = aicon->xindex, iy = aicon->yindex;
3480 int tmp;
3481 Pixmap ghost = None;
3482 Bool docked;
3483 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3485 if (wPreferences.flags.noupdates)
3486 return;
3488 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
3489 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3490 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3491 #ifdef DEBUG0
3492 wwarning("pointer grab failed for icon move");
3493 #endif
3496 wRaiseFrame(icon->core);
3498 if (!wPreferences.flags.noclip)
3499 clip = scr->workspaces[scr->current_workspace]->clip;
3501 if (dock == scr->dock && !wPreferences.flags.noclip)
3502 dock2 = clip;
3503 else if (dock != scr->dock && !wPreferences.flags.nodock)
3504 dock2 = scr->dock;
3506 wins[0] = icon->core->window;
3507 wins[1] = scr->dock_shadow;
3508 XRestackWindows(dpy, wins, 2);
3509 XMoveResizeWindow(dpy, scr->dock_shadow, aicon->x_pos, aicon->y_pos,
3510 ICON_SIZE, ICON_SIZE);
3511 if (superfluous) {
3512 if (icon->pixmap!=None)
3513 ghost = MakeGhostIcon(scr, icon->pixmap);
3514 else
3515 ghost = MakeGhostIcon(scr, icon->core->window);
3517 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow, ghost);
3518 XClearWindow(dpy, scr->dock_shadow);
3520 XMapWindow(dpy, scr->dock_shadow);
3522 ondock = 1;
3525 while(1) {
3526 XMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3527 |ButtonMotionMask|ExposureMask, &ev);
3528 switch (ev.type) {
3529 case Expose:
3530 WMHandleEvent(&ev);
3531 break;
3533 case MotionNotify:
3534 if (!grabbed) {
3535 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3536 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3537 XChangeActivePointerGrab(dpy, ButtonMotionMask
3538 |ButtonReleaseMask|ButtonPressMask,
3539 wCursor[WCUR_MOVE], CurrentTime);
3540 grabbed=1;
3541 } else {
3542 break;
3546 x = ev.xmotion.x_root - ofs_x;
3547 y = ev.xmotion.y_root - ofs_y;
3548 tmp = wDockSnapIcon(dock, aicon, x, y, &ix, &iy, True);
3549 if (tmp && dock2) {
3550 change_dock = 0;
3551 if (last_dock != dock && collapsed) {
3552 last_dock->collapsed = 1;
3553 wDockHideIcons(last_dock);
3554 collapsed = 0;
3556 if (!collapsed && (collapsed = dock->collapsed)) {
3557 dock->collapsed = 0;
3558 wDockShowIcons(dock);
3560 if (dock->auto_raise_lower)
3561 wDockRaise(dock);
3562 last_dock = dock;
3564 else if (dock2) {
3565 tmp = wDockSnapIcon(dock2, aicon, x, y, &ix, &iy, False);
3566 if (tmp) {
3567 change_dock = 1;
3568 if (last_dock != dock2 && collapsed) {
3569 last_dock->collapsed = 1;
3570 wDockHideIcons(last_dock);
3571 collapsed = 0;
3573 if (!collapsed && (collapsed = dock2->collapsed)) {
3574 dock2->collapsed = 0;
3575 wDockShowIcons(dock2);
3577 if (dock2->auto_raise_lower)
3578 wDockRaise(dock2);
3579 last_dock = dock2;
3582 if (aicon->launching
3583 || (aicon->running && !(ev.xmotion.state & MOD_MASK))
3584 || (!aicon->running && tmp)) {
3585 shad_x = last_dock->x_pos + ix*wPreferences.icon_size;
3586 shad_y = last_dock->y_pos + iy*wPreferences.icon_size;
3588 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
3590 if (!ondock) {
3591 XMapWindow(dpy, scr->dock_shadow);
3592 #if 0
3593 if (!collapsed && (collapsed = last_dock->collapsed)) {
3594 last_dock->collapsed = 0;
3595 wDockShowIcons(last_dock);
3597 #endif
3599 ondock = 1;
3600 } else {
3601 if (ondock) {
3602 XUnmapWindow(dpy, scr->dock_shadow);
3603 #if 0
3604 if (last_dock && collapsed &&
3605 aicon->running && (ev.xmotion.state & MOD_MASK)) {
3606 last_dock->collapsed = 1;
3607 wDockHideIcons(last_dock);
3608 collapsed = 0;
3610 #endif
3612 ondock = 0;
3614 XMoveWindow(dpy, icon->core->window, x, y);
3615 break;
3617 case ButtonPress:
3618 break;
3620 case ButtonRelease:
3621 if (ev.xbutton.button != event->xbutton.button)
3622 break;
3623 XUngrabPointer(dpy, CurrentTime);
3624 if (ondock) {
3625 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
3626 XUnmapWindow(dpy, scr->dock_shadow);
3627 if (!change_dock) {
3628 reattachIcon(dock, aicon, ix, iy);
3629 if (clip && dock!=clip && clip->auto_raise_lower)
3630 wDockLower(clip);
3631 } else {
3632 docked = moveIconBetweenDocks(dock, dock2, aicon, ix, iy);
3633 if (!docked) {
3634 /* Slide it back if dock rejected it */
3635 SlideWindow(icon->core->window, x, y, aicon->x_pos,
3636 aicon->y_pos);
3637 reattachIcon(dock, aicon, aicon->xindex,aicon->yindex);
3639 if (last_dock->type==WM_CLIP && last_dock->auto_collapse) {
3640 collapsed = 0;
3643 } else {
3644 aicon->x_pos = x;
3645 aicon->y_pos = y;
3646 if (superfluous) {
3647 if (!aicon->running && !wPreferences.no_animations) {
3648 /* We need to deselect it, even if is deselected in
3649 * wDockDetach(), because else DoKaboom() will fail.
3651 if (aicon->icon->selected)
3652 wIconSelect(aicon->icon);
3653 DoKaboom(scr,aicon->icon->core->window, x, y);
3656 if (clip && clip->auto_raise_lower)
3657 wDockLower(clip);
3658 wDockDetach(dock, aicon);
3660 if (collapsed) {
3661 last_dock->collapsed = 1;
3662 wDockHideIcons(last_dock);
3663 collapsed = 0;
3665 if (superfluous) {
3666 if (ghost!=None)
3667 XFreePixmap(dpy, ghost);
3668 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3670 #ifdef DEBUG
3671 puts("End icon move");
3672 #endif
3673 return;
3679 static int
3680 getClipButton(int px, int py)
3682 int pt = (CLIP_BUTTON_SIZE+2)*ICON_SIZE/64;
3684 if (px < 0 || py < 0 || px >= ICON_SIZE || py >= ICON_SIZE)
3685 return CLIP_IDLE;
3687 if (py <= pt-((int)ICON_SIZE-1-px))
3688 return CLIP_FORWARD;
3689 else if (px <= pt-((int)ICON_SIZE-1-py))
3690 return CLIP_REWIND;
3692 return CLIP_IDLE;
3696 static void
3697 handleClipChangeWorkspace(WScreen *scr, XEvent *event)
3699 XEvent ev;
3700 int done, direction, new_ws;
3701 int new_dir;
3702 WDock *clip = scr->clip_icon->dock;
3704 direction = getClipButton(event->xbutton.x, event->xbutton.y);
3706 clip->lclip_button_pushed = direction==CLIP_REWIND;
3707 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3709 wClipIconPaint(scr->clip_icon);
3710 done = 0;
3711 while(!done) {
3712 WMMaskEvent(dpy, ExposureMask|ButtonMotionMask|ButtonReleaseMask
3713 |ButtonPressMask, &ev);
3714 switch (ev.type) {
3715 case Expose:
3716 WMHandleEvent(&ev);
3717 break;
3719 case MotionNotify:
3720 new_dir = getClipButton(ev.xmotion.x, ev.xmotion.y);
3721 if (new_dir != direction) {
3722 direction = new_dir;
3723 clip->lclip_button_pushed = direction==CLIP_REWIND;
3724 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3725 wClipIconPaint(scr->clip_icon);
3727 break;
3729 case ButtonPress:
3730 break;
3732 case ButtonRelease:
3733 if (ev.xbutton.button == event->xbutton.button)
3734 done = 1;
3738 clip->lclip_button_pushed = 0;
3739 clip->rclip_button_pushed = 0;
3741 new_ws = wPreferences.ws_advance || (event->xbutton.state & ControlMask);
3743 if (direction == CLIP_FORWARD) {
3744 if (scr->current_workspace < scr->workspace_count-1)
3745 wWorkspaceChange(scr, scr->current_workspace+1);
3746 else if (new_ws && scr->current_workspace < MAX_WORKSPACES-1)
3747 wWorkspaceChange(scr, scr->current_workspace+1);
3748 else if (wPreferences.ws_cycle)
3749 wWorkspaceChange(scr, 0);
3751 else if (direction == CLIP_REWIND) {
3752 if (scr->current_workspace > 0)
3753 wWorkspaceChange(scr, scr->current_workspace-1);
3754 else if (scr->current_workspace==0 && wPreferences.ws_cycle)
3755 wWorkspaceChange(scr, scr->workspace_count-1);
3758 wClipIconPaint(scr->clip_icon);
3762 static void
3763 iconMouseDown(WObjDescriptor *desc, XEvent *event)
3765 WAppIcon *aicon = desc->parent;
3766 WDock *dock = aicon->dock;
3767 WScreen *scr = aicon->icon->core->screen_ptr;
3769 if (aicon->editing)
3770 return;
3772 scr->last_dock = dock;
3774 if (dock->menu->flags.mapped)
3775 wMenuUnmap(dock->menu);
3777 if (IsDoubleClick(scr, event)) {
3778 /* double-click was not in the main clip icon */
3779 if (dock->type != WM_CLIP || aicon->xindex!=0 || aicon->yindex!=0
3780 || getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE) {
3781 iconDblClick(desc, event);
3782 return;
3786 if (dock->type == WM_CLIP && scr->flags.clip_balloon_mapped) {
3787 XUnmapWindow(dpy, scr->clip_balloon);
3788 scr->flags.clip_balloon_mapped = 0;
3791 #ifdef DEBUG
3792 puts("handling dock");
3793 #endif
3794 if (event->xbutton.button == Button1) {
3795 if (event->xbutton.state & MOD_MASK)
3796 wDockLower(dock);
3797 else
3798 wDockRaise(dock);
3800 if ((event->xbutton.state & ShiftMask) && aicon!=scr->clip_icon &&
3801 dock->type!=WM_DOCK) {
3802 wIconSelect(aicon->icon);
3803 return;
3806 if (aicon->yindex==0 && aicon->xindex==0) {
3807 if (getClipButton(event->xbutton.x, event->xbutton.y)!=CLIP_IDLE
3808 && dock->type==WM_CLIP)
3809 handleClipChangeWorkspace(scr, event);
3810 else
3811 handleDockMove(dock, aicon, event);
3812 } else
3813 handleIconMove(dock, aicon, event);
3815 } else if (event->xbutton.button==Button2 && dock->type==WM_CLIP &&
3816 aicon->xindex==0 && aicon->yindex==0) {
3817 openClipWorkspaceMenu(scr, event->xbutton.x_root+2,
3818 event->xbutton.y_root+2);
3819 if (scr->clip_ws_menu) {
3820 WMenu *menu;
3821 menu = scr->clip_ws_menu;
3822 desc = &menu->menu->descriptor;
3824 event->xany.send_event = True;
3825 (*desc->handle_mousedown)(desc, event);
3827 } else if (event->xbutton.button == Button3) {
3828 openDockMenu(dock, aicon, event);
3833 static void
3834 showClipBalloon(WDock *dock, int workspace)
3836 int w, h;
3837 int x, y;
3838 WScreen *scr = dock->screen_ptr;
3839 char *text;
3840 Window stack[2];
3842 scr->flags.clip_balloon_mapped = 1;
3843 XMapWindow(dpy, scr->clip_balloon);
3845 text = scr->workspaces[workspace]->name;
3847 w = wTextWidth(scr->clip_title_font->font, text, strlen(text));
3849 h = scr->clip_title_font->height;
3850 XResizeWindow(dpy, scr->clip_balloon, w, h);
3852 x = dock->x_pos + CLIP_BUTTON_SIZE*ICON_SIZE/64;
3853 y = dock->y_pos + ICON_SIZE-scr->clip_title_font->height - 3;
3855 if (x+w > scr->scr_width) {
3856 x = scr->scr_width - w;
3857 if (dock->y_pos + ICON_SIZE + h > scr->scr_height)
3858 y = dock->y_pos - h - 1;
3859 else
3860 y = dock->y_pos + ICON_SIZE;
3861 XRaiseWindow(dpy, scr->clip_balloon);
3862 } else {
3863 stack[0] = scr->clip_icon->icon->core->window;
3864 stack[1] = scr->clip_balloon;
3865 XRestackWindows(dpy, stack, 2);
3867 XMoveWindow(dpy, scr->clip_balloon, x, y);
3868 XSetForeground(dpy, scr->clip_title_gc,
3869 scr->clip_title_pixel[CLIP_NORMAL]);
3870 XClearWindow(dpy, scr->clip_balloon);
3871 wDrawString(scr->clip_balloon, scr->clip_title_font, scr->clip_title_gc,
3872 0, scr->clip_title_font->y, text, strlen(text));
3876 static void
3877 clipEnterNotify(WObjDescriptor *desc, XEvent *event)
3879 WAppIcon *btn = (WAppIcon*)desc->parent;
3880 WDock *dock;
3882 assert(event->type==EnterNotify);
3884 if(desc->parent_type!=WCLASS_DOCK_ICON)
3885 return;
3887 dock = btn->dock;
3888 if (!dock || dock->type!=WM_CLIP)
3889 return;
3891 if (dock->auto_lower_magic) {
3892 WMDeleteTimerHandler(dock->auto_lower_magic);
3893 dock->auto_lower_magic = NULL;
3895 if (dock->auto_raise_lower) {
3896 dock->auto_raise_magic = WMAddTimerHandler(AUTO_RAISE_DELAY,
3897 clipAutoRaise,
3898 (void *)dock);
3901 if (btn->xindex == 0 && btn->yindex == 0)
3902 showClipBalloon(dock, dock->screen_ptr->current_workspace);
3903 else {
3904 if (dock->screen_ptr->flags.clip_balloon_mapped) {
3905 XUnmapWindow(dpy, dock->screen_ptr->clip_balloon);
3906 dock->screen_ptr->flags.clip_balloon_mapped = 0;
3909 if (dock->auto_collapse) {
3910 if (dock->auto_collapse_magic) {
3911 WMDeleteTimerHandler(dock->auto_collapse_magic);
3912 dock->auto_collapse_magic = NULL;
3915 if (dock->collapsed)
3916 toggleCollapsed(dock);
3921 static void
3922 clipLeave(WDock *dock)
3924 if (!dock || dock->type!=WM_CLIP)
3925 return;
3927 if (dock->auto_raise_magic) {
3928 WMDeleteTimerHandler(dock->auto_raise_magic);
3929 dock->auto_raise_magic = NULL;
3931 if (dock->auto_raise_lower) {
3932 dock->auto_lower_magic = WMAddTimerHandler(AUTO_LOWER_DELAY,
3933 clipAutoLower,
3934 (void *)dock);
3937 if (dock->auto_collapse) {
3938 if (dock->auto_collapse_magic) {
3939 WMDeleteTimerHandler(dock->auto_collapse_magic);
3940 dock->auto_collapse_magic = NULL;
3942 if (!dock->collapsed) {
3943 dock->auto_collapse_magic = WMAddTimerHandler(AUTO_COLLAPSE_DELAY,
3944 clipAutoCollapse,
3945 (void *)dock);
3951 static void
3952 clipLeaveNotify(WObjDescriptor *desc, XEvent *event)
3954 WAppIcon *btn = (WAppIcon*)desc->parent;
3956 assert(event->type==LeaveNotify);
3958 if(desc->parent_type!=WCLASS_DOCK_ICON)
3959 return;
3961 clipLeave(btn->dock);
3965 static void
3966 clipAutoCollapse(void *cdata)
3968 WDock *dock = (WDock *)cdata;
3970 if (dock->type!=WM_CLIP || !dock->auto_collapse)
3971 return;
3973 if (!dock->collapsed && dock->auto_collapse_magic!=NULL) {
3974 toggleCollapsed(dock);
3976 dock->auto_collapse_magic = NULL;
3980 static void
3981 clipAutoLower(void *cdata)
3983 WDock *dock = (WDock *)cdata;
3985 if (dock->type!=WM_CLIP)
3986 return;
3988 if (dock->auto_raise_lower)
3989 wDockLower(dock);
3991 dock->auto_lower_magic = NULL;
3995 static void
3996 clipAutoRaise(void *cdata)
3998 WDock *dock = (WDock *)cdata;
4000 if (dock->type!=WM_CLIP)
4001 return;
4003 if (dock->auto_raise_lower)
4004 wDockRaise(dock);
4006 if (dock->screen_ptr->flags.clip_balloon_mapped) {
4007 showClipBalloon(dock, dock->screen_ptr->current_workspace);
4010 dock->auto_raise_magic = NULL;