Update for 0.51.0
[wmaker-crm.git] / src / dock.c
bloba74e05f79ca7066ecc096f9eb2d36e8e46a690fb
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 - 1;
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;
1614 else {
1615 if (dock->x_pos >= 0) {
1616 dock->x_pos = DOCK_EXTRA_SPACE;
1617 dock->on_right_side = 0;
1618 } else {
1619 dock->x_pos = scr->scr_width - DOCK_EXTRA_SPACE - ICON_SIZE - 1;
1620 dock->on_right_side = 1;
1626 /* restore lowered/raised state */
1628 dock->lowered = 0;
1630 value = PLGetDictionaryEntry(dock_state, dLowered);
1632 if (value) {
1633 if (!PLIsString(value))
1634 COMPLAIN("Lowered");
1635 else {
1636 if (strcasecmp(PLGetString(value), "YES")==0)
1637 dock->lowered = 1;
1642 /* restore collapsed state */
1644 dock->collapsed = 0;
1646 value = PLGetDictionaryEntry(dock_state, dCollapsed);
1648 if (value) {
1649 if (!PLIsString(value))
1650 COMPLAIN("Collapsed");
1651 else {
1652 if (strcasecmp(PLGetString(value), "YES")==0)
1653 dock->collapsed = 1;
1658 /* restore auto-collapsed state */
1660 value = PLGetDictionaryEntry(dock_state, dAutoCollapse);
1662 if (value) {
1663 if (!PLIsString(value))
1664 COMPLAIN("AutoCollapse");
1665 else {
1666 if (strcasecmp(PLGetString(value), "YES")==0) {
1667 dock->auto_collapse = 1;
1668 dock->collapsed = 1;
1674 /* restore auto-raise/lower state */
1676 value = PLGetDictionaryEntry(dock_state, dAutoRaiseLower);
1678 if (value) {
1679 if (!PLIsString(value))
1680 COMPLAIN("AutoRaiseLower");
1681 else {
1682 if (strcasecmp(PLGetString(value), "YES")==0) {
1683 dock->auto_raise_lower = 1;
1689 /* restore attract icons state */
1691 dock->attract_icons = 0;
1693 value = PLGetDictionaryEntry(dock_state, dAutoAttractIcons);
1695 if (value) {
1696 if (!PLIsString(value))
1697 COMPLAIN("AutoAttractIcons");
1698 else {
1699 if (strcasecmp(PLGetString(value), "YES")==0)
1700 dock->attract_icons = 1;
1705 /* restore keep attracted icons state */
1707 dock->keep_attracted = 0;
1709 value = PLGetDictionaryEntry(dock_state, dKeepAttracted);
1711 if (value) {
1712 if (!PLIsString(value))
1713 COMPLAIN("KeepAttracted");
1714 else {
1715 if (strcasecmp(PLGetString(value), "YES")==0)
1716 dock->keep_attracted = 1;
1721 /* application list */
1723 apps = PLGetDictionaryEntry(dock_state, dApplications);
1725 if (!apps) {
1726 goto finish;
1729 count = PLGetNumberOfElements(apps);
1731 if (count==0)
1732 goto finish;
1734 old_top = dock->icon_array[0];
1736 /* dock->icon_count is set to 1 when dock is created.
1737 * Since Clip is already restored, we want to keep it so for clip,
1738 * but for dock we may change the default top tile, so we set it to 0.
1740 if (type == WM_DOCK)
1741 dock->icon_count = 0;
1743 for (i=0; i<count; i++) {
1744 if (dock->icon_count >= dock->max_icons) {
1745 wwarning(_("there are too many icons stored in dock. Ignoring what doesn't fit"));
1746 break;
1749 value = PLGetArrayElement(apps, i);
1750 aicon = restore_icon_state(scr, value, type, dock->icon_count);
1752 dock->icon_array[dock->icon_count] = aicon;
1754 if (aicon) {
1755 aicon->dock = dock;
1756 aicon->x_pos = dock->x_pos + (aicon->xindex*ICON_SIZE);
1757 aicon->y_pos = dock->y_pos + (aicon->yindex*ICON_SIZE);
1759 if (dock->lowered)
1760 ChangeStackingLevel(aicon->icon->core, WMNormalLevel);
1761 else
1762 ChangeStackingLevel(aicon->icon->core, WMDockLevel);
1764 wCoreConfigure(aicon->icon->core, aicon->x_pos, aicon->y_pos,
1765 0, 0);
1767 if (!dock->collapsed)
1768 XMapWindow(dpy, aicon->icon->core->window);
1769 wRaiseFrame(aicon->icon->core);
1771 dock->icon_count++;
1772 } else if (dock->icon_count==0 && type==WM_DOCK)
1773 dock->icon_count++;
1776 /* if the first icon is not defined, use the default */
1777 if (dock->icon_array[0]==NULL) {
1778 /* update default icon */
1779 old_top->x_pos = dock->x_pos;
1780 old_top->y_pos = dock->y_pos;
1781 if (dock->lowered)
1782 ChangeStackingLevel(old_top->icon->core, WMNormalLevel);
1783 else
1784 ChangeStackingLevel(old_top->icon->core, WMDockLevel);
1785 dock->icon_array[0] = old_top;
1786 XMoveWindow(dpy, old_top->icon->core->window, dock->x_pos, dock->y_pos);
1787 /* we don't need to increment dock->icon_count here because it was
1788 * incremented in the loop above.
1790 } else if (old_top!=dock->icon_array[0]) {
1791 if (old_top == scr->clip_icon)
1792 scr->clip_icon = dock->icon_array[0];
1793 wAppIconDestroy(old_top);
1796 finish:
1797 if (dock_state)
1798 PLRelease(dock_state);
1800 return dock;
1805 void
1806 wDockLaunchWithState(WDock *dock, WAppIcon *btn, WSavedState *state)
1808 if (btn && btn->command && !btn->running && !btn->launching) {
1810 btn->drop_launch = 0;
1812 btn->pid = execCommand(btn, btn->command, state);
1814 if (btn->pid>0) {
1815 if (!btn->forced_dock && !btn->buggy_app) {
1816 btn->launching = 1;
1817 dockIconPaint(btn);
1820 } else {
1821 free(state);
1826 void
1827 wDockDoAutoLaunch(WDock *dock, int workspace)
1829 WAppIcon *btn;
1830 WSavedState *state;
1831 int i;
1833 for (i = 0; i < dock->max_icons; i++) {
1834 btn = dock->icon_array[i];
1835 if (!btn || !btn->auto_launch)
1836 continue;
1838 state = wmalloc(sizeof(WSavedState));
1839 memset(state, 0, sizeof(WSavedState));
1840 state->workspace = workspace;
1841 /* TODO: this is klugy and is very difficult to understand
1842 * what's going on. Try to clean up */
1843 wDockLaunchWithState(dock, btn, state);
1847 #ifdef REDUCE_APPICONS
1848 void
1849 wDockSimulateLaunch(WDock *dock, WAppIcon *btn)
1851 if ((btn == NULL) || (dock == NULL))
1852 return;
1854 if (!btn->running) {
1855 if ((btn->icon->owner == NULL) && (btn->applist))
1856 btn->icon->owner = btn->applist->wapp->main_window_desc;
1857 if (!btn->forced_dock)
1858 btn->launching = 1;
1859 dockIconPaint(btn);
1860 wusleep(5000);
1863 #endif
1865 #ifdef OFFIX_DND
1866 static WDock*
1867 findDock(WScreen *scr, XEvent *event, int *icon_pos)
1869 WDock *dock;
1870 int i;
1872 *icon_pos = -1;
1873 if ((dock = scr->dock)!=NULL) {
1874 for (i=0; i<dock->max_icons; i++) {
1875 if (dock->icon_array[i]
1876 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1877 *icon_pos = i;
1878 break;
1882 if (*icon_pos<0 && (dock = scr->workspaces[scr->current_workspace]->clip)!=NULL) {
1883 for (i=0; i<dock->max_icons; i++) {
1884 if (dock->icon_array[i]
1885 && dock->icon_array[i]->icon->core->window==event->xclient.window) {
1886 *icon_pos = i;
1887 break;
1891 if(*icon_pos>=0)
1892 return dock;
1893 return NULL;
1898 wDockReceiveDNDDrop(WScreen *scr, XEvent *event)
1900 WDock *dock;
1901 WAppIcon *btn;
1902 int icon_pos;
1904 dock = findDock(scr, event, &icon_pos);
1905 if (!dock)
1906 return False;
1909 * Return True if the drop was on an application icon window.
1910 * In this case, let the ClientMessage handler redirect the
1911 * message to the app.
1913 if (dock->icon_array[icon_pos]->icon->icon_win!=None)
1914 return True;
1916 if (dock->icon_array[icon_pos]->dnd_command!=NULL) {
1917 scr->flags.dnd_data_convertion_status = 0;
1919 btn = dock->icon_array[icon_pos];
1921 if (!btn->forced_dock) {
1922 btn->relaunching = btn->running;
1923 btn->running = 1;
1925 if (btn->wm_instance || btn->wm_class) {
1926 WWindowAttributes attr;
1927 memset(&attr, 0, sizeof(WWindowAttributes));
1928 wDefaultFillAttributes(btn->icon->core->screen_ptr,
1929 btn->wm_instance,
1930 btn->wm_class, &attr, NULL, True);
1932 if (!attr.no_appicon)
1933 btn->launching = 1;
1934 else
1935 btn->running = 0;
1938 btn->drop_launch = 1;
1939 scr->last_dock = dock;
1940 btn->pid = execCommand(btn, btn->dnd_command, NULL);
1941 if (btn->pid>0) {
1942 dockIconPaint(btn);
1943 } else {
1944 btn->launching = 0;
1945 if (!btn->relaunching) {
1946 btn->running = 0;
1950 return False;
1952 #endif /* OFFIX_DND */
1956 Bool
1957 wDockAttachIcon(WDock *dock, WAppIcon *icon, int x, int y)
1959 WWindow *wwin;
1960 char **argv;
1961 int argc;
1962 int index;
1964 wwin = icon->icon->owner;
1965 if (icon->command==NULL) {
1966 icon->editing = 0;
1967 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
1969 icon->command = FlattenStringList(argv, argc);
1970 XFreeStringList(argv);
1971 } else {
1972 char *command=NULL;
1974 /* icon->forced_dock = 1;*/
1975 if (!icon->attracted || dock->type!=WM_CLIP || dock->keep_attracted) {
1976 icon->editing = 1;
1977 if (wInputDialog(dock->screen_ptr, _("Dock Icon"),
1978 _("Type the command used to launch the application"),
1979 &command)) {
1980 if (command && (command[0]==0 ||
1981 (command[0]=='-' && command[1]==0))) {
1982 free(command);
1983 command = NULL;
1985 icon->command = command;
1986 icon->editing = 0;
1987 } else {
1988 icon->editing = 0;
1989 if (command)
1990 free(command);
1991 /* If the target is the dock, reject the icon. If
1992 * the target is the clip, make it an attracted icon
1994 if (dock->type==WM_CLIP) {
1995 icon->attracted = 1;
1996 if (!icon->icon->shadowed) {
1997 icon->icon->shadowed = 1;
1998 icon->icon->force_paint = 1;
2000 } else {
2001 return False;
2006 } else {
2007 icon->editing = 0;
2010 for (index=1; index<dock->max_icons; index++)
2011 if (dock->icon_array[index] == NULL)
2012 break;
2013 /* if (index == dock->max_icons)
2014 return; */
2016 assert(index < dock->max_icons);
2018 dock->icon_array[index] = icon;
2019 icon->yindex = y;
2020 icon->xindex = x;
2022 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2023 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2025 dock->icon_count++;
2027 icon->running = 1;
2028 icon->launching = 0;
2029 icon->docked = 1;
2030 icon->dock = dock;
2031 icon->icon->core->descriptor.handle_mousedown = iconMouseDown;
2032 if (dock->type == WM_CLIP) {
2033 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2034 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2036 icon->icon->core->descriptor.parent_type = WCLASS_DOCK_ICON;
2037 icon->icon->core->descriptor.parent = icon;
2039 MoveInStackListUnder(dock->icon_array[index-1]->icon->core,
2040 icon->icon->core);
2041 wAppIconMove(icon, icon->x_pos, icon->y_pos);
2042 wAppIconPaint(icon);
2044 if (wPreferences.auto_arrange_icons)
2045 wArrangeIcons(dock->screen_ptr, True);
2047 #ifdef OFFIX_DND
2048 if (icon->command && !icon->dnd_command) {
2049 icon->dnd_command = wmalloc(strlen(icon->command)+8);
2050 sprintf(icon->dnd_command, "%s %%d", icon->command);
2052 #endif
2054 return True;
2058 void
2059 reattachIcon(WDock *dock, WAppIcon *icon, int x, int y)
2061 int index;
2063 for(index=1; index<dock->max_icons; index++) {
2064 if(dock->icon_array[index] == icon)
2065 break;
2067 assert(index < dock->max_icons);
2069 icon->yindex = y;
2070 icon->xindex = x;
2072 icon->x_pos = dock->x_pos + x*ICON_SIZE;
2073 icon->y_pos = dock->y_pos + y*ICON_SIZE;
2077 Bool
2078 moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, int y)
2080 WWindow *wwin;
2081 char **argv;
2082 int argc;
2083 int index;
2085 if (dest == NULL)
2086 return False;
2088 wwin = icon->icon->owner;
2091 * For the moment we can't do this if we move icons in Clip from one
2092 * workspace to other, because if we move two or more icons without
2093 * command, the dialog box will not be able to tell us to which of the
2094 * moved icons it applies. -Dan
2096 if ((dest->type==WM_DOCK /*|| dest->keep_attracted*/) && icon->command==NULL) {
2097 if (XGetCommand(dpy, wwin->client_win, &argv, &argc) && argc>0) {
2099 icon->command = FlattenStringList(argv, argc);
2100 XFreeStringList(argv);
2101 } else {
2102 char *command=NULL;
2104 icon->editing = 1;
2105 /* icon->forced_dock = 1;*/
2106 if (wInputDialog(src->screen_ptr, _("Dock Icon"),
2107 _("Type the command used to launch the application"),
2108 &command)) {
2109 if (command && (command[0]==0 ||
2110 (command[0]=='-' && command[1]==0))) {
2111 free(command);
2112 command = NULL;
2114 icon->command = command;
2115 } else {
2116 icon->editing = 0;
2117 if (command)
2118 free(command);
2119 return False;
2121 icon->editing = 0;
2125 for(index=1; index<src->max_icons; index++) {
2126 if(src->icon_array[index] == icon)
2127 break;
2129 assert(index < src->max_icons);
2131 src->icon_array[index] = NULL;
2132 src->icon_count--;
2134 for(index=1; index<dest->max_icons; index++) {
2135 if(dest->icon_array[index] == NULL)
2136 break;
2138 /* if (index == dest->max_icons)
2139 return; */
2141 assert(index < dest->max_icons);
2143 dest->icon_array[index] = icon;
2144 icon->dock = dest;
2146 /* deselect the icon */
2147 if (icon->icon->selected)
2148 wIconSelect(icon->icon);
2150 if (dest->type == WM_DOCK) {
2151 icon->icon->core->descriptor.handle_enternotify = NULL;
2152 icon->icon->core->descriptor.handle_leavenotify = NULL;
2153 } else {
2154 icon->icon->core->descriptor.handle_enternotify = clipEnterNotify;
2155 icon->icon->core->descriptor.handle_leavenotify = clipLeaveNotify;
2158 /* set it to be kept when moving to dock, or to a clip that keep the
2159 * attracted icons.
2160 * Unless the icon does not have a command set
2162 if (icon->command && (dest->type==WM_DOCK || dest->keep_attracted)) {
2163 icon->attracted = 0;
2164 if (icon->icon->shadowed) {
2165 icon->icon->shadowed = 0;
2166 icon->icon->force_paint = 1;
2170 if (src->auto_collapse || src->auto_raise_lower)
2171 clipLeave(src);
2173 icon->yindex = y;
2174 icon->xindex = x;
2176 icon->x_pos = dest->x_pos + x*ICON_SIZE;
2177 icon->y_pos = dest->y_pos + y*ICON_SIZE;
2179 dest->icon_count++;
2181 MoveInStackListUnder(dest->icon_array[index-1]->icon->core,
2182 icon->icon->core);
2183 wAppIconPaint(icon);
2185 return True;
2189 void
2190 wDockDetach(WDock *dock, WAppIcon *icon)
2192 int index;
2194 /* make the settings panel be closed */
2195 if (icon->panel) {
2196 DestroyDockAppSettingsPanel(icon->panel);
2199 icon->docked = 0;
2200 icon->dock = NULL;
2201 icon->attracted = 0;
2202 if (icon->icon->shadowed) {
2203 icon->icon->shadowed = 0;
2204 icon->icon->force_paint = 1;
2207 /* deselect the icon */
2208 if (icon->icon->selected)
2209 wIconSelect(icon->icon);
2211 if (icon->command) {
2212 free(icon->command);
2213 icon->command = NULL;
2215 #ifdef OFFIX_DND
2216 if (icon->dnd_command) {
2217 free(icon->dnd_command);
2218 icon->dnd_command = NULL;
2220 #endif
2222 for (index=1; index<dock->max_icons; index++)
2223 if (dock->icon_array[index] == icon)
2224 break;
2225 assert(index < dock->max_icons);
2226 dock->icon_array[index] = NULL;
2227 icon->yindex = -1;
2228 icon->xindex = -1;
2229 dock->icon_count--;
2231 /* if the dock is not attached to an application or
2232 * the the application did not set the approriate hints yet,
2233 * destroy the icon */
2234 #ifdef REDUCE_APPICONS
2235 if ((icon->num_apps == 0) && (!icon->running || !wApplicationOf(icon->main_window)) )
2236 #else
2237 if (!icon->running || !wApplicationOf(icon->main_window))
2238 #endif
2239 wAppIconDestroy(icon);
2240 else {
2241 icon->icon->core->descriptor.handle_mousedown = appIconMouseDown;
2242 icon->icon->core->descriptor.handle_enternotify = NULL;
2243 icon->icon->core->descriptor.handle_leavenotify = NULL;
2244 icon->icon->core->descriptor.parent_type = WCLASS_APPICON;
2245 icon->icon->core->descriptor.parent = icon;
2247 ChangeStackingLevel(icon->icon->core, NORMAL_ICON_LEVEL);
2249 wAppIconPaint(icon);
2250 if (wPreferences.auto_arrange_icons) {
2251 wArrangeIcons(dock->screen_ptr, True);
2254 if (dock->auto_collapse || dock->auto_raise_lower)
2255 clipLeave(dock);
2260 * returns the closest Dock slot index for the passed
2261 * coordinates.
2263 * Returns False if icon can't be docked.
2265 Bool
2266 wDockSnapIcon(WDock *dock, WAppIcon *icon, int req_x, int req_y,
2267 int *ret_x, int *ret_y, int redocking)
2269 WScreen *scr = dock->screen_ptr;
2270 int dx, dy;
2271 int ex_x, ex_y;
2272 int i, offset = ICON_SIZE/2;
2273 WAppIcon *aicon = NULL;
2274 WAppIcon *nicon = NULL;
2275 int max_y_icons, max_x_icons;
2277 max_x_icons = scr->scr_width/ICON_SIZE;
2278 max_y_icons = scr->scr_height/ICON_SIZE-1;
2280 if (wPreferences.flags.noupdates)
2281 return False;
2283 dx = dock->x_pos;
2284 dy = dock->y_pos;
2286 /* if the dock is full */
2287 if (!redocking &&
2288 (dock->icon_count >= dock->max_icons)) {
2289 return False;
2292 /* exact position */
2293 if (req_y < dy)
2294 ex_y = (req_y - offset - dy)/ICON_SIZE;
2295 else
2296 ex_y = (req_y + offset - dy)/ICON_SIZE;
2298 if (req_x < dx)
2299 ex_x = (req_x - offset - dx)/ICON_SIZE;
2300 else
2301 ex_x = (req_x + offset - dx)/ICON_SIZE;
2303 /* check if the icon is outside the screen boundaries */
2304 if (dx + ex_x*ICON_SIZE < -ICON_SIZE+2 ||
2305 dx + ex_x*ICON_SIZE >= scr->scr_width-1 ||
2306 dy + ex_y*ICON_SIZE < -ICON_SIZE+2 ||
2307 dy + ex_y*ICON_SIZE >= scr->scr_height-1)
2308 return False;
2310 if (dock->type == WM_DOCK) {
2311 if (icon->dock != dock && ex_x != 0)
2312 return False;
2314 for (i=0; i<dock->max_icons; i++) {
2315 nicon = dock->icon_array[i];
2316 if (nicon && nicon->yindex == ex_y) {
2317 aicon = nicon;
2318 break;
2322 *ret_x = 0;
2324 if (redocking) {
2325 int sig, done, closest;
2327 /* Possible cases when redocking:
2329 * icon dragged out of range of any slot -> false
2330 * icon dragged to range of free slot
2331 * icon dragged to range of same slot
2332 * icon dragged to range of different icon
2334 if (abs(ex_x) > DOCK_DETTACH_THRESHOLD)
2335 return False;
2337 if (ex_y >= 0 && ex_y <= max_y_icons && (aicon == icon || !aicon)) {
2339 *ret_y = ex_y;
2342 return True;
2345 /* start looking at the upper slot or lower? */
2346 if (ex_y*ICON_SIZE < (req_y + offset - dy))
2347 sig = 1;
2348 else
2349 sig = -1;
2351 closest = -1;
2352 done = 0;
2353 /* look for closest free slot */
2354 for (i=0; i<(DOCK_DETTACH_THRESHOLD+1)*2 && !done; i++) {
2355 int j;
2357 done = 1;
2358 closest = sig*(i/2) + ex_y;
2359 /* check if this slot is used */
2360 if (closest >= 0) {
2361 for (j = 0; j<dock->max_icons; j++) {
2362 if (dock->icon_array[j]
2363 && dock->icon_array[j]->yindex==closest) {
2364 /* slot is used by someone else */
2365 if (dock->icon_array[j]!=icon)
2366 done = 0;
2367 break;
2371 sig = -sig;
2373 if (done && closest >= 0 && closest <= max_y_icons &&
2374 ((ex_y >= closest && ex_y - closest < DOCK_DETTACH_THRESHOLD+1)
2376 (ex_y < closest && closest - ex_y <= DOCK_DETTACH_THRESHOLD+1))) {
2378 *ret_y = closest;
2380 return True;
2382 } else { /* !redocking */
2384 /* if slot is free and the icon is close enough, return it */
2385 if (!aicon && ex_x == 0 && ex_y >= 0 && ex_y <= max_y_icons) {
2386 *ret_y = ex_y;
2387 return True;
2390 } else { /* CLIP */
2391 int neighbours = 0;
2393 for (i=0; i<dock->max_icons; i++) {
2394 nicon = dock->icon_array[i];
2395 if (nicon && nicon->xindex == ex_x && nicon->yindex == ex_y) {
2396 aicon = nicon;
2397 break;
2401 for (i=0; i<dock->max_icons; i++) {
2402 nicon = dock->icon_array[i];
2403 if (nicon && nicon != icon && /* Icon can't be it's own neighbour */
2404 (abs(nicon->xindex - ex_x) <= CLIP_ATTACH_VICINITY &&
2405 abs(nicon->yindex - ex_y) <= CLIP_ATTACH_VICINITY)) {
2406 neighbours = 1;
2407 break;
2411 if (neighbours && (aicon==NULL || (redocking && aicon == icon))) {
2412 *ret_x = ex_x;
2413 *ret_y = ex_y;
2414 return True;
2417 return False;
2420 #define MIN(x, y) ((x) > (y) ? (y) : (x))
2421 #define MAX(x, y) ((x) < (y) ? (y) : (x))
2423 #define ON_SCREEN(x, y, sx, ex, sy, ey) \
2424 ((((x)+ICON_SIZE/2) >= (sx)) && (((y)+ICON_SIZE/2) >= (sy)) && \
2425 (((x) + (ICON_SIZE/2)) <= (ex)) && (((y) + (ICON_SIZE/2)) <= ey))
2429 * returns true if it can find a free slot in the dock,
2430 * in which case it changes x_pos and y_pos accordingly.
2431 * Else returns false.
2433 Bool
2434 wDockFindFreeSlot(WDock *dock, int *x_pos, int *y_pos)
2436 WScreen *scr = dock->screen_ptr;
2437 WAppIcon *btn;
2438 unsigned char *slot_map;
2439 int mwidth;
2440 int r;
2441 int x, y;
2442 int i, done = False;
2443 int corner;
2444 int sx=0, sy=0, ex=scr->scr_width, ey=scr->scr_height;
2447 /* if the dock is full */
2448 if (dock->icon_count >= dock->max_icons) {
2449 return False;
2452 if (!wPreferences.flags.nodock && scr->dock) {
2453 if (scr->dock->on_right_side)
2454 ex -= ICON_SIZE + DOCK_EXTRA_SPACE;
2455 else
2456 sx += ICON_SIZE + DOCK_EXTRA_SPACE;
2459 if (ex < dock->x_pos)
2460 ex = dock->x_pos;
2461 if (sx > dock->x_pos+ICON_SIZE)
2462 sx = dock->x_pos+ICON_SIZE;
2463 #define C_NONE 0
2464 #define C_NW 1
2465 #define C_NE 2
2466 #define C_SW 3
2467 #define C_SE 4
2469 /* check if clip is in a corner */
2470 if (dock->type==WM_CLIP) {
2471 if (dock->x_pos < 1 && dock->y_pos < 1)
2472 corner = C_NE;
2473 else if (dock->x_pos < 1 && dock->y_pos >= (ey-ICON_SIZE))
2474 corner = C_SE;
2475 else if (dock->x_pos >= (ex-ICON_SIZE)&& dock->y_pos >= (ey-ICON_SIZE))
2476 corner = C_SW;
2477 else if (dock->x_pos >= (ex-ICON_SIZE) && dock->y_pos < 1)
2478 corner = C_NW;
2479 else
2480 corner = C_NONE;
2481 } else
2482 corner = C_NONE;
2484 /* If the clip is in the corner, use only slots that are in the border
2485 * of the screen */
2486 if (corner!=C_NONE) {
2487 char *hmap, *vmap;
2488 int hcount, vcount;
2490 hcount = MIN(dock->max_icons, scr->scr_width/ICON_SIZE);
2491 vcount = MIN(dock->max_icons, scr->scr_height/ICON_SIZE);
2492 hmap = wmalloc(hcount+1);
2493 memset(hmap, 0, hcount+1);
2494 vmap = wmalloc(vcount+1);
2495 memset(vmap, 0, vcount+1);
2497 /* mark used positions */
2498 switch (corner) {
2499 case C_NE:
2500 for (i=0; i<dock->max_icons; i++) {
2501 btn = dock->icon_array[i];
2502 if (!btn)
2503 continue;
2505 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2506 vmap[btn->yindex] = 1;
2507 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2508 hmap[btn->xindex] = 1;
2510 case C_NW:
2511 for (i=0; i<dock->max_icons; i++) {
2512 btn = dock->icon_array[i];
2513 if (!btn)
2514 continue;
2516 if (btn->xindex==0 && btn->yindex > 0 && btn->yindex < vcount)
2517 vmap[btn->yindex] = 1;
2518 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2519 hmap[-btn->xindex] = 1;
2521 case C_SE:
2522 for (i=0; i<dock->max_icons; i++) {
2523 btn = dock->icon_array[i];
2524 if (!btn)
2525 continue;
2527 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2528 vmap[-btn->yindex] = 1;
2529 else if (btn->yindex==0 && btn->xindex>0 && btn->xindex<hcount)
2530 hmap[btn->xindex] = 1;
2532 case C_SW:
2533 default:
2534 for (i=0; i<dock->max_icons; i++) {
2535 btn = dock->icon_array[i];
2536 if (!btn)
2537 continue;
2539 if (btn->xindex==0 && btn->yindex < 0 && btn->yindex > -vcount)
2540 vmap[-btn->yindex] = 1;
2541 else if (btn->yindex==0 && btn->xindex<0 &&btn->xindex>-hcount)
2542 hmap[-btn->xindex] = 1;
2545 x=0; y=0;
2546 done = 0;
2547 /* search a vacant slot */
2548 for (i=1; i<MAX(vcount, hcount); i++) {
2549 if (i < vcount && vmap[i]==0) {
2550 /* found a slot */
2551 x = 0;
2552 y = i;
2553 done = 1;
2554 break;
2555 } else if (i < hcount && hmap[i]==0) {
2556 /* found a slot */
2557 x = i;
2558 y = 0;
2559 done = 1;
2560 break;
2563 free(vmap);
2564 free(hmap);
2565 /* If found a slot, translate and return */
2566 if (done) {
2567 if (corner==C_NW || corner==C_NE) {
2568 *y_pos = y;
2569 } else {
2570 *y_pos = -y;
2572 if (corner==C_NE || corner==C_SE) {
2573 *x_pos = x;
2574 } else {
2575 *x_pos = -x;
2577 return True;
2579 /* else, try to find a slot somewhere else */
2582 /* a map of mwidth x mwidth would be enough if we allowed icons to be
2583 * placed outside of screen */
2584 mwidth = (int)ceil(sqrt(dock->max_icons));
2586 /* In the worst case (the clip is in the corner of the screen),
2587 * the amount of icons that fit in the clip is smaller.
2588 * Double the map to get a safe value.
2590 mwidth += mwidth;
2592 r = (mwidth-1)/2;
2594 slot_map = wmalloc(mwidth*mwidth);
2595 memset(slot_map, 0, mwidth*mwidth);
2597 #define XY2OFS(x,y) (MAX(abs(x),abs(y)) > r) ? 0 : (((y)+r)*(mwidth)+(x)+r)
2599 /* mark used slots in the map. If the slot falls outside the map
2600 * (for example, when all icons are placed in line), ignore them. */
2601 for (i=0; i<dock->max_icons; i++) {
2602 btn = dock->icon_array[i];
2603 if (btn)
2604 slot_map[XY2OFS(btn->xindex, btn->yindex)] = 1;
2606 /* Find closest slot from the center that is free by scanning the
2607 * map from the center to outward in circular passes.
2608 * This will not result in a neat layout, but will be optimal
2609 * in the sense that there will not be holes left.
2611 done = 0;
2612 for (i = 1; i <= r && !done; i++) {
2613 int tx, ty;
2615 /* top and bottom parts of the ring */
2616 for (x = -i; x <= i && !done; x++) {
2617 tx = dock->x_pos + x*ICON_SIZE;
2618 y = -i;
2619 ty = dock->y_pos + y*ICON_SIZE;
2620 if (slot_map[XY2OFS(x,y)]==0
2621 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2622 *x_pos = x;
2623 *y_pos = y;
2624 done = 1;
2625 break;
2627 y = i;
2628 ty = dock->y_pos + y*ICON_SIZE;
2629 if (slot_map[XY2OFS(x,y)]==0
2630 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2631 *x_pos = x;
2632 *y_pos = y;
2633 done = 1;
2634 break;
2637 /* left and right parts of the ring */
2638 for (y = -i+1; y <= i-1; y++) {
2639 ty = dock->y_pos + y*ICON_SIZE;
2640 x = -i;
2641 tx = dock->x_pos + x*ICON_SIZE;
2642 if (slot_map[XY2OFS(x,y)]==0
2643 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2644 *x_pos = x;
2645 *y_pos = y;
2646 done = 1;
2647 break;
2649 x = i;
2650 tx = dock->x_pos + x*ICON_SIZE;
2651 if (slot_map[XY2OFS(x,y)]==0
2652 && ON_SCREEN(tx, ty, sx, ex, sy, ey)) {
2653 *x_pos = x;
2654 *y_pos = y;
2655 done = 1;
2656 break;
2660 free(slot_map);
2661 #undef XY2OFS
2662 return done;
2666 static void
2667 moveDock(WDock *dock, int new_x, int new_y)
2669 WAppIcon *btn;
2670 int i;
2672 dock->x_pos = new_x;
2673 dock->y_pos = new_y;
2674 for (i=0; i<dock->max_icons; i++) {
2675 btn = dock->icon_array[i];
2676 if (btn) {
2677 btn->x_pos = new_x + btn->xindex*ICON_SIZE;
2678 btn->y_pos = new_y + btn->yindex*ICON_SIZE;
2679 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2685 static void
2686 swapDock(WDock *dock)
2688 WScreen *scr = dock->screen_ptr;
2689 WAppIcon *btn;
2690 int x, i;
2693 if (dock->on_right_side) {
2694 x = dock->x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE - 1;
2695 } else {
2696 x = dock->x_pos = DOCK_EXTRA_SPACE;
2699 for (i=0; i<dock->max_icons; i++) {
2700 btn = dock->icon_array[i];
2701 if (btn) {
2702 btn->x_pos = x;
2703 XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
2707 wScreenUpdateUsableArea(scr);
2711 static pid_t
2712 execCommand(WAppIcon *btn, char *command, WSavedState *state)
2714 WScreen *scr = btn->icon->core->screen_ptr;
2715 pid_t pid;
2716 char **argv;
2717 int argc;
2718 char *cmdline;
2720 cmdline = ExpandOptions(scr, command);
2722 if (scr->flags.dnd_data_convertion_status || !cmdline) {
2723 if (cmdline)
2724 free(cmdline);
2725 if (state)
2726 free(state);
2727 return 0;
2730 ParseCommand(cmdline, &argv, &argc);
2732 if (argv==NULL) {
2733 if (cmdline)
2734 free(cmdline);
2735 if (state)
2736 free(state);
2737 return 0;
2740 if ((pid=fork())==0) {
2741 char **args;
2742 int i;
2744 SetupEnvironment(scr);
2746 #ifdef HAVE_SETPGID
2747 setpgid(0, 0);
2748 #endif
2750 args = malloc(sizeof(char*)*(argc+1));
2751 if (!args)
2752 exit(111);
2753 for (i=0; i<argc; i++) {
2754 args[i] = argv[i];
2756 args[argc] = NULL;
2757 execvp(argv[0], args);
2758 exit(111);
2760 while (argc > 0)
2761 free(argv[--argc]);
2762 free(argv);
2764 if (pid > 0) {
2765 if (!state) {
2766 state = wmalloc(sizeof(WSavedState));
2767 memset(state, 0, sizeof(WSavedState));
2768 state->hidden = -1;
2769 state->miniaturized = -1;
2770 state->shaded = -1;
2771 if (btn->dock == scr->dock)
2772 state->workspace = -1;
2773 else
2774 state->workspace = scr->current_workspace;
2776 wWindowAddSavedState(btn->wm_instance, btn->wm_class, cmdline, pid,
2777 state);
2778 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess,
2779 btn->dock);
2780 } else if (state) {
2781 free(state);
2783 free(cmdline);
2784 return pid;
2788 void
2789 wDockHideIcons(WDock *dock)
2791 int i;
2792 WAppIcon *btn;
2794 if (dock==NULL)
2795 return;
2797 btn = dock->icon_array[0];
2799 for (i=1; i<dock->max_icons; i++) {
2800 if (dock->icon_array[i])
2801 XUnmapWindow(dpy, dock->icon_array[i]->icon->core->window);
2803 dock->mapped = 0;
2805 dockIconPaint(btn);
2809 void
2810 wDockShowIcons(WDock *dock)
2812 int i, newlevel;
2813 WAppIcon *btn;
2815 if (dock==NULL)
2816 return;
2818 btn = dock->icon_array[0];
2819 moveDock(dock, btn->x_pos, btn->y_pos);
2821 newlevel = dock->lowered ? WMNormalLevel : WMDockLevel;
2822 ChangeStackingLevel(btn->icon->core, newlevel);
2824 for (i=1; i<dock->max_icons; i++) {
2825 if (dock->icon_array[i]) {
2826 MoveInStackListAbove(dock->icon_array[i]->icon->core,
2827 btn->icon->core);
2828 break;
2832 if (!dock->collapsed) {
2833 for (i=1; i<dock->max_icons; i++) {
2834 if (dock->icon_array[i]) {
2835 XMapWindow(dpy, dock->icon_array[i]->icon->core->window);
2839 dock->mapped = 1;
2841 dockIconPaint(btn);
2845 void
2846 wDockLower(WDock *dock)
2848 int i;
2850 for (i=0; i<dock->max_icons; i++) {
2851 if (dock->icon_array[i])
2852 wLowerFrame(dock->icon_array[i]->icon->core);
2857 void
2858 wDockRaise(WDock *dock)
2860 int i;
2862 for (i=dock->max_icons-1; i>=0; i--) {
2863 if (dock->icon_array[i])
2864 wRaiseFrame(dock->icon_array[i]->icon->core);
2869 void
2870 wDockRaiseLower(WDock *dock)
2872 if (!dock->icon_array[0]->icon->core->stacking->above
2873 ||(dock->icon_array[0]->icon->core->stacking->window_level
2874 !=dock->icon_array[0]->icon->core->stacking->above->stacking->window_level))
2875 wDockLower(dock);
2876 else
2877 wDockRaise(dock);
2881 void
2882 wDockFinishLaunch(WDock *dock, WAppIcon *icon)
2884 icon->launching = 0;
2885 icon->relaunching = 0;
2886 dockIconPaint(icon);
2890 WAppIcon*
2891 wDockFindIconFor(WDock *dock, Window window)
2893 WAppIcon *icon;
2894 int i;
2896 for (i=0; i<dock->max_icons; i++) {
2897 icon = dock->icon_array[i];
2898 if (icon && icon->main_window == window)
2899 return icon;
2901 return NULL;
2905 void
2906 wDockTrackWindowLaunch(WDock *dock, Window window)
2908 WAppIcon *icon;
2909 #ifdef REDUCE_APPICONS
2910 WAppIconAppList *tapplist;
2911 #endif
2912 char *wm_class, *wm_instance;
2913 int i;
2914 Bool firstPass = True;
2915 Bool found = False;
2916 char *command = NULL;
2919 int argc;
2920 char **argv;
2922 if (XGetCommand(dpy, window, &argv, &argc)) {
2923 if (argc > 0 && argv != NULL)
2924 command = FlattenStringList(argv,argc);
2925 if (argv) {
2926 XFreeStringList(argv);
2931 if (!PropGetWMClass(window, &wm_class, &wm_instance) ||
2932 (!wm_class && !wm_instance))
2933 return;
2935 retry:
2936 for (i=0; i<dock->max_icons; i++) {
2937 icon = dock->icon_array[i];
2938 if (!icon)
2939 continue;
2941 /* app is already attached to icon */
2942 if (icon->main_window == window) {
2943 found = True;
2944 break;
2947 if ((icon->wm_instance || icon->wm_class)
2948 && (icon->launching
2949 || (dock->screen_ptr->flags.startup && !icon->running))) {
2951 if (icon->wm_instance && wm_instance &&
2952 strcmp(icon->wm_instance, wm_instance)!=0) {
2953 continue;
2955 if (icon->wm_class && wm_class &&
2956 strcmp(icon->wm_class, wm_class)!=0) {
2957 continue;
2959 if (firstPass && command && strcmp(icon->command, command)!=0) {
2960 continue;
2963 if (!icon->relaunching) {
2964 WApplication *wapp;
2966 /* Possibly an application that was docked with dockit,
2967 * but the user did not update WMState to indicate that
2968 * it was docked by force */
2969 wapp = wApplicationOf(window);
2970 if (!wapp) {
2971 icon->forced_dock = 1;
2972 icon->running = 0;
2974 if (!icon->forced_dock)
2975 icon->main_window = window;
2977 #ifdef REDUCE_APPICONS
2978 tapplist = wmalloc(sizeof(WAppIconAppList));
2979 memset(tapplist, 0, sizeof(WAppIconAppList));
2980 tapplist->next = icon->applist;
2981 if (icon->applist)
2982 icon->applist->prev = tapplist;
2983 icon->applist = tapplist;
2984 tapplist->wapp = wApplicationOf(window);
2985 icon->num_apps++;
2986 #endif
2988 found = True;
2989 wDockFinishLaunch(dock, icon);
2990 break;
2994 if (firstPass && !found) {
2995 firstPass = False;
2996 goto retry;
2999 if (command)
3000 free(command);
3002 if (wm_class)
3003 XFree(wm_class);
3004 if (wm_instance)
3005 XFree(wm_instance);
3010 void
3011 wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
3013 if (!wPreferences.flags.noclip) {
3014 scr->clip_icon->dock = scr->workspaces[workspace]->clip;
3015 if (scr->current_workspace != workspace) {
3016 WDock *old_clip = scr->workspaces[scr->current_workspace]->clip;
3018 wDockHideIcons(old_clip);
3019 if (old_clip->auto_raise_lower)
3020 wDockLower(old_clip);
3021 if (old_clip->auto_collapse && !old_clip->collapsed)
3022 old_clip->collapsed = 1;
3023 wDockShowIcons(scr->workspaces[workspace]->clip);
3025 if (scr->flags.clip_balloon_mapped)
3026 showClipBalloon(scr->clip_icon->dock, workspace);
3032 static void
3033 trackDeadProcess(pid_t pid, unsigned char status, WDock *dock)
3035 WAppIcon *icon;
3036 int i;
3038 for (i=0; i<dock->max_icons; i++) {
3039 icon = dock->icon_array[i];
3040 if (!icon)
3041 continue;
3043 if (icon->launching && icon->pid == pid) {
3044 if (!icon->relaunching) {
3045 icon->running = 0;
3046 icon->main_window = None;
3048 wDockFinishLaunch(dock, icon);
3049 icon->pid = 0;
3050 if (status==111) {
3051 char msg[PATH_MAX];
3052 #ifdef OFFIX_DND
3053 sprintf(msg, _("Could not execute command \"%s\""),
3054 icon->drop_launch && icon->dnd_command
3055 ? icon->dnd_command : icon->command);
3056 #else
3057 sprintf(msg, _("Could not execute command \"%s\""),
3058 icon->command);
3059 #endif
3060 wMessageDialog(dock->screen_ptr, _("Error"), msg,
3061 _("OK"), NULL, NULL);
3063 break;
3069 static void
3070 toggleLowered(WDock *dock)
3072 WAppIcon *tmp;
3073 int newlevel, i;
3075 /* lower/raise Dock */
3076 if (!dock->lowered) {
3077 newlevel = WMNormalLevel;
3078 dock->lowered = 1;
3079 } else {
3080 newlevel = WMDockLevel;
3081 dock->lowered = 0;
3084 for (i=0; i<dock->max_icons; i++) {
3085 tmp = dock->icon_array[i];
3086 if (!tmp)
3087 continue;
3089 ChangeStackingLevel(tmp->icon->core, newlevel);
3090 if (dock->lowered)
3091 wLowerFrame(tmp->icon->core);
3094 if (dock->type == WM_DOCK)
3095 wScreenUpdateUsableArea(dock->screen_ptr);
3099 static void
3100 toggleCollapsed(WDock *dock)
3102 if (dock->collapsed) {
3103 dock->collapsed = 0;
3104 wDockShowIcons(dock);
3106 else {
3107 dock->collapsed = 1;
3108 wDockHideIcons(dock);
3113 static void
3114 openDockMenu(WDock *dock, WAppIcon *aicon, XEvent *event)
3116 WScreen *scr = dock->screen_ptr;
3117 WObjDescriptor *desc;
3118 WMenuEntry *entry;
3119 WApplication *wapp = NULL;
3120 int index = 0;
3121 int x_pos;
3122 int appIsRunning = aicon->running && aicon->icon && aicon->icon->owner;
3124 if (dock->type == WM_DOCK) {
3125 /* keep on top */
3126 entry = dock->menu->entries[index];
3127 entry->flags.indicator_on = !dock->lowered;
3128 entry->clientdata = dock;
3129 } else {
3130 /* clip options */
3131 if (scr->clip_options)
3132 updateClipOptionsMenu(scr->clip_options, dock);
3134 /* Rename Workspace */
3135 entry = dock->menu->entries[++index];
3136 entry->clientdata = dock;
3138 /* select icon */
3139 entry = dock->menu->entries[++index];
3140 entry->clientdata = aicon;
3141 wMenuSetEnabled(dock->menu, index, aicon!=scr->clip_icon);
3143 /* (un)select all icons */
3144 entry = dock->menu->entries[++index];
3145 entry->clientdata = aicon;
3146 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3148 /* keep icon(s) */
3149 entry = dock->menu->entries[++index];
3150 entry->clientdata = aicon;
3151 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3153 /* this is the workspace submenu part */
3154 if (scr->clip_submenu)
3155 updateWorkspaceMenu(scr->clip_submenu, aicon);
3156 index++;
3158 /* remove icon(s) */
3159 entry = dock->menu->entries[++index];
3160 entry->clientdata = aicon;
3161 wMenuSetEnabled(dock->menu, index, dock->icon_count > 1);
3163 /* attract icon(s) */
3164 entry = dock->menu->entries[++index];
3165 entry->clientdata = aicon;
3168 /* launch */
3169 entry = dock->menu->entries[++index];
3170 entry->clientdata = aicon;
3171 wMenuSetEnabled(dock->menu, index, aicon->command!=NULL);
3173 /* unhide here */
3174 entry = dock->menu->entries[++index];
3175 entry->clientdata = aicon;
3176 wMenuSetEnabled(dock->menu, index, appIsRunning);
3178 /* hide */
3179 entry = dock->menu->entries[++index];
3180 entry->clientdata = aicon;
3181 if (aicon->icon->owner) {
3182 wapp = wApplicationOf(aicon->icon->owner->main_window);
3183 if (wapp && wapp->flags.hidden)
3184 entry->text = _("Unhide");
3185 else
3186 entry->text = _("Hide");
3187 } else {
3188 entry->text = _("Hide");
3190 wMenuSetEnabled(dock->menu, index, appIsRunning);
3192 /* settings */
3193 entry = dock->menu->entries[++index];
3194 entry->clientdata = aicon;
3195 wMenuSetEnabled(dock->menu, index, !aicon->editing
3196 && !wPreferences.flags.noupdates);
3198 /* kill */
3199 entry = dock->menu->entries[++index];
3200 entry->clientdata = aicon;
3201 wMenuSetEnabled(dock->menu, index, appIsRunning);
3203 if (!dock->menu->flags.realized)
3204 wMenuRealize(dock->menu);
3206 if (dock->type == WM_CLIP) {
3207 x_pos = event->xbutton.x_root+2;
3208 } else {
3209 x_pos = dock->on_right_side ?
3210 scr->scr_width - dock->menu->frame->core->width - 2 : 0;
3213 wMenuMapAt(dock->menu, x_pos, event->xbutton.y_root+2, False);
3215 /* allow drag select */
3216 event->xany.send_event = True;
3217 desc = &dock->menu->menu->descriptor;
3218 (*desc->handle_mousedown)(desc, event);
3222 static void
3223 openClipWorkspaceMenu(WScreen *scr, int x, int y)
3225 if (!scr->clip_ws_menu) {
3226 scr->clip_ws_menu = wWorkspaceMenuMake(scr, False);
3228 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
3229 wMenuMapAt(scr->clip_ws_menu, x, y, False);
3233 /******************************************************************/
3234 static void
3235 iconDblClick(WObjDescriptor *desc, XEvent *event)
3237 WAppIcon *btn = desc->parent;
3238 WDock *dock = btn->dock;
3239 WApplication *wapp = NULL;
3240 int unhideHere = 0;
3242 #ifdef REDUCE_APPICONS
3243 if ((btn->icon->owner && !(event->xbutton.state & ControlMask)) ||
3244 ((btn->icon->owner == NULL) && (btn->applist != NULL))) {
3245 if (btn->icon->owner == NULL)
3246 btn->icon->owner = btn->applist->wapp->main_window_desc;
3247 #ifdef I_HATE_THIS
3249 #endif
3250 #else
3251 if (btn->icon->owner && !(event->xbutton.state & ControlMask)) {
3252 #endif
3253 wapp = wApplicationOf(btn->icon->owner->main_window);
3255 assert(wapp!=NULL);
3257 unhideHere = (event->xbutton.state & ShiftMask);
3259 /* go to the last workspace that the user worked on the app */
3260 if (!unhideHere) {
3261 wWorkspaceChange(dock->screen_ptr, wapp->last_workspace);
3264 wUnhideApplication(wapp, event->xbutton.button==Button2,
3265 unhideHere);
3267 if (event->xbutton.state & MOD_MASK) {
3268 wHideOtherApplications(btn->icon->owner);
3270 } else {
3271 if (event->xbutton.button==Button1) {
3273 if (event->xbutton.state & MOD_MASK) {
3274 /* raise/lower dock */
3275 toggleLowered(dock);
3276 } else if (btn == dock->screen_ptr->clip_icon) {
3277 if (getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE)
3278 toggleCollapsed(dock);
3279 else
3280 handleClipChangeWorkspace(dock->screen_ptr, event);
3281 } else if (btn->command) {
3282 if (!btn->launching &&
3283 (!btn->running || (event->xbutton.state & ControlMask))) {
3284 launchDockedApplication(btn);
3292 static void
3293 handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3295 WScreen *scr = dock->screen_ptr;
3296 int ofs_x=event->xbutton.x, ofs_y=event->xbutton.y;
3297 int x, y;
3298 XEvent ev;
3299 int grabbed = 0, swapped = 0, done;
3300 Pixmap ghost = None;
3301 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3303 #ifdef DEBUG
3304 puts("moving dock");
3305 #endif
3306 if (XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
3307 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3308 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3309 wwarning("pointer grab failed for dock move");
3311 y = 0;
3312 for (x=0; x<dock->max_icons; x++) {
3313 if (dock->icon_array[x]!=NULL &&
3314 dock->icon_array[x]->yindex > y)
3315 y = dock->icon_array[x]->yindex;
3317 y++;
3318 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE*y);
3320 done = 0;
3321 while (!done) {
3322 WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3323 |ButtonMotionMask|ExposureMask, &ev);
3324 switch (ev.type) {
3325 case Expose:
3326 WMHandleEvent(&ev);
3327 break;
3329 case MotionNotify:
3330 if (!grabbed) {
3331 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3332 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3333 XChangeActivePointerGrab(dpy, ButtonMotionMask
3334 |ButtonReleaseMask|ButtonPressMask,
3335 wCursor[WCUR_MOVE], CurrentTime);
3336 grabbed=1;
3338 break;
3340 if (dock->type == WM_CLIP) {
3341 if (ev.xmotion.x_root - ofs_x < 0) {
3342 x = 0;
3343 } else if (ev.xmotion.x_root - ofs_x + ICON_SIZE >
3344 scr->scr_width) {
3345 x = scr->scr_width - ICON_SIZE;
3346 } else {
3347 x = ev.xmotion.x_root - ofs_x;
3349 if (ev.xmotion.y_root - ofs_y < 0) {
3350 y = 0;
3351 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3352 scr->scr_height) {
3353 y = scr->scr_height - ICON_SIZE;
3354 } else {
3355 y = ev.xmotion.y_root - ofs_y;
3357 moveDock(dock, x, y);
3359 else {
3360 /* move vertically if pointer is inside the dock*/
3361 if ((dock->on_right_side &&
3362 ev.xmotion.x_root >= dock->x_pos - ICON_SIZE)
3363 || (!dock->on_right_side &&
3364 ev.xmotion.x_root <= dock->x_pos + ICON_SIZE*2)) {
3366 if (ev.xmotion.y_root - ofs_y < 0) {
3367 y = 0;
3368 } else if (ev.xmotion.y_root - ofs_y + ICON_SIZE >
3369 scr->scr_height) {
3370 y = scr->scr_height - ICON_SIZE;
3371 } else {
3372 y = ev.xmotion.y_root - ofs_y;
3374 moveDock(dock, dock->x_pos, y);
3376 /* move horizontally to change sides */
3377 x = ev.xmotion.x_root - ofs_x;
3378 if (!dock->on_right_side) {
3380 /* is on left */
3382 if (ev.xmotion.x_root > dock->x_pos + ICON_SIZE*2) {
3383 XMoveWindow(dpy, scr->dock_shadow, scr->scr_width-ICON_SIZE
3384 -DOCK_EXTRA_SPACE-1, dock->y_pos);
3385 if (superfluous) {
3386 if (ghost==None) {
3387 ghost = MakeGhostDock(dock, dock->x_pos,
3388 scr->scr_width-ICON_SIZE
3389 -DOCK_EXTRA_SPACE-1,
3390 dock->y_pos);
3391 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3392 ghost);
3393 XClearWindow(dpy, scr->dock_shadow);
3396 XMapRaised(dpy, scr->dock_shadow);
3397 swapped = 1;
3398 } else {
3399 if (superfluous && ghost!=None) {
3400 XFreePixmap(dpy, ghost);
3401 ghost = None;
3403 XUnmapWindow(dpy, scr->dock_shadow);
3404 swapped = 0;
3406 } else {
3407 /* is on right */
3408 if (ev.xmotion.x_root < dock->x_pos - ICON_SIZE) {
3409 XMoveWindow(dpy, scr->dock_shadow,
3410 DOCK_EXTRA_SPACE, dock->y_pos);
3411 if (superfluous) {
3412 if (ghost==None) {
3413 ghost = MakeGhostDock(dock, dock->x_pos,
3414 DOCK_EXTRA_SPACE, dock->y_pos);
3415 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
3416 ghost);
3417 XClearWindow(dpy, scr->dock_shadow);
3420 XMapRaised(dpy, scr->dock_shadow);
3421 swapped = -1;
3422 } else {
3423 XUnmapWindow(dpy, scr->dock_shadow);
3424 swapped = 0;
3425 if (superfluous && ghost!=None) {
3426 XFreePixmap(dpy, ghost);
3427 ghost = None;
3432 break;
3434 case ButtonPress:
3435 break;
3437 case ButtonRelease:
3438 if (ev.xbutton.button != event->xbutton.button)
3439 break;
3440 XUngrabPointer(dpy, CurrentTime);
3441 XUnmapWindow(dpy, scr->dock_shadow);
3442 XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE);
3443 if (dock->type == WM_DOCK) {
3444 if (swapped!=0) {
3445 if (swapped>0)
3446 dock->on_right_side = 1;
3447 else
3448 dock->on_right_side = 0;
3449 swapDock(dock);
3450 wArrangeIcons(scr, False);
3453 done = 1;
3454 break;
3457 if (superfluous) {
3458 if (ghost!=None)
3459 XFreePixmap(dpy, ghost);
3460 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3462 #ifdef DEBUG
3463 puts("End dock move");
3464 #endif
3469 static void
3470 handleIconMove(WDock *dock, WAppIcon *aicon, XEvent *event)
3472 WScreen *scr = dock->screen_ptr;
3473 Window wins[2];
3474 WIcon *icon = aicon->icon;
3475 WDock *dock2 = NULL, *last_dock = dock, *clip = NULL;
3476 int ondock, grabbed = 0, change_dock = 0, collapsed = 0;
3477 XEvent ev;
3478 int x = aicon->x_pos, y = aicon->y_pos;
3479 int ofs_x = event->xbutton.x, ofs_y = event->xbutton.y;
3480 int shad_x = x, shad_y = y;
3481 int ix = aicon->xindex, iy = aicon->yindex;
3482 int tmp;
3483 Pixmap ghost = None;
3484 Bool docked;
3485 int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
3487 if (wPreferences.flags.noupdates)
3488 return;
3490 if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
3491 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
3492 GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
3493 #ifdef DEBUG0
3494 wwarning("pointer grab failed for icon move");
3495 #endif
3498 wRaiseFrame(icon->core);
3500 if (!wPreferences.flags.noclip)
3501 clip = scr->workspaces[scr->current_workspace]->clip;
3503 if (dock == scr->dock && !wPreferences.flags.noclip)
3504 dock2 = clip;
3505 else if (dock != scr->dock && !wPreferences.flags.nodock)
3506 dock2 = scr->dock;
3508 wins[0] = icon->core->window;
3509 wins[1] = scr->dock_shadow;
3510 XRestackWindows(dpy, wins, 2);
3511 XMoveResizeWindow(dpy, scr->dock_shadow, aicon->x_pos, aicon->y_pos,
3512 ICON_SIZE, ICON_SIZE);
3513 if (superfluous) {
3514 if (icon->pixmap!=None)
3515 ghost = MakeGhostIcon(scr, icon->pixmap);
3516 else
3517 ghost = MakeGhostIcon(scr, icon->core->window);
3519 XSetWindowBackgroundPixmap(dpy, scr->dock_shadow, ghost);
3520 XClearWindow(dpy, scr->dock_shadow);
3522 XMapWindow(dpy, scr->dock_shadow);
3524 ondock = 1;
3527 while(1) {
3528 XMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
3529 |ButtonMotionMask|ExposureMask, &ev);
3530 switch (ev.type) {
3531 case Expose:
3532 WMHandleEvent(&ev);
3533 break;
3535 case MotionNotify:
3536 if (!grabbed) {
3537 if (abs(ofs_x-ev.xmotion.x)>=MOVE_THRESHOLD
3538 || abs(ofs_y-ev.xmotion.y)>=MOVE_THRESHOLD) {
3539 XChangeActivePointerGrab(dpy, ButtonMotionMask
3540 |ButtonReleaseMask|ButtonPressMask,
3541 wCursor[WCUR_MOVE], CurrentTime);
3542 grabbed=1;
3543 } else {
3544 break;
3548 x = ev.xmotion.x_root - ofs_x;
3549 y = ev.xmotion.y_root - ofs_y;
3550 tmp = wDockSnapIcon(dock, aicon, x, y, &ix, &iy, True);
3551 if (tmp && dock2) {
3552 change_dock = 0;
3553 if (last_dock != dock && collapsed) {
3554 last_dock->collapsed = 1;
3555 wDockHideIcons(last_dock);
3556 collapsed = 0;
3558 if (!collapsed && (collapsed = dock->collapsed)) {
3559 dock->collapsed = 0;
3560 wDockShowIcons(dock);
3562 if (dock->auto_raise_lower)
3563 wDockRaise(dock);
3564 last_dock = dock;
3566 else if (dock2) {
3567 tmp = wDockSnapIcon(dock2, aicon, x, y, &ix, &iy, False);
3568 if (tmp) {
3569 change_dock = 1;
3570 if (last_dock != dock2 && collapsed) {
3571 last_dock->collapsed = 1;
3572 wDockHideIcons(last_dock);
3573 collapsed = 0;
3575 if (!collapsed && (collapsed = dock2->collapsed)) {
3576 dock2->collapsed = 0;
3577 wDockShowIcons(dock2);
3579 if (dock2->auto_raise_lower)
3580 wDockRaise(dock2);
3581 last_dock = dock2;
3584 if (aicon->launching
3585 || (aicon->running && !(ev.xmotion.state & MOD_MASK))
3586 || (!aicon->running && tmp)) {
3587 shad_x = last_dock->x_pos + ix*wPreferences.icon_size;
3588 shad_y = last_dock->y_pos + iy*wPreferences.icon_size;
3590 XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
3592 if (!ondock) {
3593 XMapWindow(dpy, scr->dock_shadow);
3594 #if 0
3595 if (!collapsed && (collapsed = last_dock->collapsed)) {
3596 last_dock->collapsed = 0;
3597 wDockShowIcons(last_dock);
3599 #endif
3601 ondock = 1;
3602 } else {
3603 if (ondock) {
3604 XUnmapWindow(dpy, scr->dock_shadow);
3605 #if 0
3606 if (last_dock && collapsed &&
3607 aicon->running && (ev.xmotion.state & MOD_MASK)) {
3608 last_dock->collapsed = 1;
3609 wDockHideIcons(last_dock);
3610 collapsed = 0;
3612 #endif
3614 ondock = 0;
3616 XMoveWindow(dpy, icon->core->window, x, y);
3617 break;
3619 case ButtonPress:
3620 break;
3622 case ButtonRelease:
3623 if (ev.xbutton.button != event->xbutton.button)
3624 break;
3625 XUngrabPointer(dpy, CurrentTime);
3626 if (ondock) {
3627 SlideWindow(icon->core->window, x, y, shad_x, shad_y);
3628 XUnmapWindow(dpy, scr->dock_shadow);
3629 if (!change_dock) {
3630 reattachIcon(dock, aicon, ix, iy);
3631 if (clip && dock!=clip && clip->auto_raise_lower)
3632 wDockLower(clip);
3633 } else {
3634 docked = moveIconBetweenDocks(dock, dock2, aicon, ix, iy);
3635 if (!docked) {
3636 /* Slide it back if dock rejected it */
3637 SlideWindow(icon->core->window, x, y, aicon->x_pos,
3638 aicon->y_pos);
3639 reattachIcon(dock, aicon, aicon->xindex,aicon->yindex);
3641 if (last_dock->type==WM_CLIP && last_dock->auto_collapse) {
3642 collapsed = 0;
3645 } else {
3646 aicon->x_pos = x;
3647 aicon->y_pos = y;
3648 if (superfluous) {
3649 if (!aicon->running && !wPreferences.no_animations) {
3650 /* We need to deselect it, even if is deselected in
3651 * wDockDetach(), because else DoKaboom() will fail.
3653 if (aicon->icon->selected)
3654 wIconSelect(aicon->icon);
3655 DoKaboom(scr,aicon->icon->core->window, x, y);
3658 if (clip && clip->auto_raise_lower)
3659 wDockLower(clip);
3660 wDockDetach(dock, aicon);
3662 if (collapsed) {
3663 last_dock->collapsed = 1;
3664 wDockHideIcons(last_dock);
3665 collapsed = 0;
3667 if (superfluous) {
3668 if (ghost!=None)
3669 XFreePixmap(dpy, ghost);
3670 XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
3672 #ifdef DEBUG
3673 puts("End icon move");
3674 #endif
3675 return;
3681 static int
3682 getClipButton(int px, int py)
3684 int pt = (CLIP_BUTTON_SIZE+2)*ICON_SIZE/64;
3686 if (px < 0 || py < 0 || px >= ICON_SIZE || py >= ICON_SIZE)
3687 return CLIP_IDLE;
3689 if (py <= pt-((int)ICON_SIZE-1-px))
3690 return CLIP_FORWARD;
3691 else if (px <= pt-((int)ICON_SIZE-1-py))
3692 return CLIP_REWIND;
3694 return CLIP_IDLE;
3698 static void
3699 handleClipChangeWorkspace(WScreen *scr, XEvent *event)
3701 XEvent ev;
3702 int done, direction, new_ws;
3703 int new_dir;
3704 WDock *clip = scr->clip_icon->dock;
3706 direction = getClipButton(event->xbutton.x, event->xbutton.y);
3708 clip->lclip_button_pushed = direction==CLIP_REWIND;
3709 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3711 wClipIconPaint(scr->clip_icon);
3712 done = 0;
3713 while(!done) {
3714 WMMaskEvent(dpy, ExposureMask|ButtonMotionMask|ButtonReleaseMask
3715 |ButtonPressMask, &ev);
3716 switch (ev.type) {
3717 case Expose:
3718 WMHandleEvent(&ev);
3719 break;
3721 case MotionNotify:
3722 new_dir = getClipButton(ev.xmotion.x, ev.xmotion.y);
3723 if (new_dir != direction) {
3724 direction = new_dir;
3725 clip->lclip_button_pushed = direction==CLIP_REWIND;
3726 clip->rclip_button_pushed = direction==CLIP_FORWARD;
3727 wClipIconPaint(scr->clip_icon);
3729 break;
3731 case ButtonPress:
3732 break;
3734 case ButtonRelease:
3735 if (ev.xbutton.button == event->xbutton.button)
3736 done = 1;
3740 clip->lclip_button_pushed = 0;
3741 clip->rclip_button_pushed = 0;
3743 new_ws = wPreferences.ws_advance || (event->xbutton.state & ControlMask);
3745 if (direction == CLIP_FORWARD) {
3746 if (scr->current_workspace < scr->workspace_count-1)
3747 wWorkspaceChange(scr, scr->current_workspace+1);
3748 else if (new_ws && scr->current_workspace < MAX_WORKSPACES-1)
3749 wWorkspaceChange(scr, scr->current_workspace+1);
3750 else if (wPreferences.ws_cycle)
3751 wWorkspaceChange(scr, 0);
3753 else if (direction == CLIP_REWIND) {
3754 if (scr->current_workspace > 0)
3755 wWorkspaceChange(scr, scr->current_workspace-1);
3756 else if (scr->current_workspace==0 && wPreferences.ws_cycle)
3757 wWorkspaceChange(scr, scr->workspace_count-1);
3760 wClipIconPaint(scr->clip_icon);
3764 static void
3765 iconMouseDown(WObjDescriptor *desc, XEvent *event)
3767 WAppIcon *aicon = desc->parent;
3768 WDock *dock = aicon->dock;
3769 WScreen *scr = aicon->icon->core->screen_ptr;
3771 if (aicon->editing)
3772 return;
3774 scr->last_dock = dock;
3776 if (dock->menu->flags.mapped)
3777 wMenuUnmap(dock->menu);
3779 if (IsDoubleClick(scr, event)) {
3780 /* double-click was not in the main clip icon */
3781 if (dock->type != WM_CLIP || aicon->xindex!=0 || aicon->yindex!=0
3782 || getClipButton(event->xbutton.x, event->xbutton.y)==CLIP_IDLE) {
3783 iconDblClick(desc, event);
3784 return;
3788 if (dock->type == WM_CLIP && scr->flags.clip_balloon_mapped) {
3789 XUnmapWindow(dpy, scr->clip_balloon);
3790 scr->flags.clip_balloon_mapped = 0;
3793 #ifdef DEBUG
3794 puts("handling dock");
3795 #endif
3796 if (event->xbutton.button == Button1) {
3797 if (event->xbutton.state & MOD_MASK)
3798 wDockLower(dock);
3799 else
3800 wDockRaise(dock);
3802 if ((event->xbutton.state & ShiftMask) && aicon!=scr->clip_icon &&
3803 dock->type!=WM_DOCK) {
3804 wIconSelect(aicon->icon);
3805 return;
3808 if (aicon->yindex==0 && aicon->xindex==0) {
3809 if (getClipButton(event->xbutton.x, event->xbutton.y)!=CLIP_IDLE
3810 && dock->type==WM_CLIP)
3811 handleClipChangeWorkspace(scr, event);
3812 else
3813 handleDockMove(dock, aicon, event);
3814 } else
3815 handleIconMove(dock, aicon, event);
3817 } else if (event->xbutton.button==Button2 && dock->type==WM_CLIP &&
3818 aicon->xindex==0 && aicon->yindex==0) {
3819 openClipWorkspaceMenu(scr, event->xbutton.x_root+2,
3820 event->xbutton.y_root+2);
3821 if (scr->clip_ws_menu) {
3822 WMenu *menu;
3823 menu = scr->clip_ws_menu;
3824 desc = &menu->menu->descriptor;
3826 event->xany.send_event = True;
3827 (*desc->handle_mousedown)(desc, event);
3829 } else if (event->xbutton.button == Button3) {
3830 openDockMenu(dock, aicon, event);
3835 static void
3836 showClipBalloon(WDock *dock, int workspace)
3838 int w, h;
3839 int x, y;
3840 WScreen *scr = dock->screen_ptr;
3841 char *text;
3842 Window stack[2];
3844 scr->flags.clip_balloon_mapped = 1;
3845 XMapWindow(dpy, scr->clip_balloon);
3847 text = scr->workspaces[workspace]->name;
3849 w = wTextWidth(scr->clip_title_font->font, text, strlen(text));
3851 h = scr->clip_title_font->height;
3852 XResizeWindow(dpy, scr->clip_balloon, w, h);
3854 x = dock->x_pos + CLIP_BUTTON_SIZE*ICON_SIZE/64;
3855 y = dock->y_pos + ICON_SIZE-scr->clip_title_font->height - 3;
3857 if (x+w > scr->scr_width) {
3858 x = scr->scr_width - w;
3859 if (dock->y_pos + ICON_SIZE + h > scr->scr_height)
3860 y = dock->y_pos - h - 1;
3861 else
3862 y = dock->y_pos + ICON_SIZE;
3863 XRaiseWindow(dpy, scr->clip_balloon);
3864 } else {
3865 stack[0] = scr->clip_icon->icon->core->window;
3866 stack[1] = scr->clip_balloon;
3867 XRestackWindows(dpy, stack, 2);
3869 XMoveWindow(dpy, scr->clip_balloon, x, y);
3870 XSetForeground(dpy, scr->clip_title_gc,
3871 scr->clip_title_pixel[CLIP_NORMAL]);
3872 XClearWindow(dpy, scr->clip_balloon);
3873 wDrawString(scr->clip_balloon, scr->clip_title_font, scr->clip_title_gc,
3874 0, scr->clip_title_font->y, text, strlen(text));
3878 static void
3879 clipEnterNotify(WObjDescriptor *desc, XEvent *event)
3881 WAppIcon *btn = (WAppIcon*)desc->parent;
3882 WDock *dock;
3884 assert(event->type==EnterNotify);
3886 if(desc->parent_type!=WCLASS_DOCK_ICON)
3887 return;
3889 dock = btn->dock;
3890 if (!dock || dock->type!=WM_CLIP)
3891 return;
3893 if (dock->auto_lower_magic) {
3894 WMDeleteTimerHandler(dock->auto_lower_magic);
3895 dock->auto_lower_magic = NULL;
3897 if (dock->auto_raise_lower) {
3898 dock->auto_raise_magic = WMAddTimerHandler(AUTO_RAISE_DELAY,
3899 clipAutoRaise,
3900 (void *)dock);
3903 if (btn->xindex == 0 && btn->yindex == 0)
3904 showClipBalloon(dock, dock->screen_ptr->current_workspace);
3905 else {
3906 if (dock->screen_ptr->flags.clip_balloon_mapped) {
3907 XUnmapWindow(dpy, dock->screen_ptr->clip_balloon);
3908 dock->screen_ptr->flags.clip_balloon_mapped = 0;
3911 if (dock->auto_collapse) {
3912 if (dock->auto_collapse_magic) {
3913 WMDeleteTimerHandler(dock->auto_collapse_magic);
3914 dock->auto_collapse_magic = NULL;
3917 if (dock->collapsed)
3918 toggleCollapsed(dock);
3923 static void
3924 clipLeave(WDock *dock)
3926 if (!dock || dock->type!=WM_CLIP)
3927 return;
3929 if (dock->auto_raise_magic) {
3930 WMDeleteTimerHandler(dock->auto_raise_magic);
3931 dock->auto_raise_magic = NULL;
3933 if (dock->auto_raise_lower) {
3934 dock->auto_lower_magic = WMAddTimerHandler(AUTO_LOWER_DELAY,
3935 clipAutoLower,
3936 (void *)dock);
3939 if (dock->auto_collapse) {
3940 if (dock->auto_collapse_magic) {
3941 WMDeleteTimerHandler(dock->auto_collapse_magic);
3942 dock->auto_collapse_magic = NULL;
3944 if (!dock->collapsed) {
3945 dock->auto_collapse_magic = WMAddTimerHandler(AUTO_COLLAPSE_DELAY,
3946 clipAutoCollapse,
3947 (void *)dock);
3953 static void
3954 clipLeaveNotify(WObjDescriptor *desc, XEvent *event)
3956 WAppIcon *btn = (WAppIcon*)desc->parent;
3958 assert(event->type==LeaveNotify);
3960 if(desc->parent_type!=WCLASS_DOCK_ICON)
3961 return;
3963 clipLeave(btn->dock);
3967 static void
3968 clipAutoCollapse(void *cdata)
3970 WDock *dock = (WDock *)cdata;
3972 if (dock->type!=WM_CLIP || !dock->auto_collapse)
3973 return;
3975 if (!dock->collapsed && dock->auto_collapse_magic!=NULL) {
3976 toggleCollapsed(dock);
3978 dock->auto_collapse_magic = NULL;
3982 static void
3983 clipAutoLower(void *cdata)
3985 WDock *dock = (WDock *)cdata;
3987 if (dock->type!=WM_CLIP)
3988 return;
3990 if (dock->auto_raise_lower)
3991 wDockLower(dock);
3993 dock->auto_lower_magic = NULL;
3997 static void
3998 clipAutoRaise(void *cdata)
4000 WDock *dock = (WDock *)cdata;
4002 if (dock->type!=WM_CLIP)
4003 return;
4005 if (dock->auto_raise_lower)
4006 wDockRaise(dock);
4008 if (dock->screen_ptr->flags.clip_balloon_mapped) {
4009 showClipBalloon(dock, dock->screen_ptr->current_workspace);
4012 dock->auto_raise_magic = NULL;