1 /* appicon.c- icon for applications (not mini-window)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
33 #include "WindowMaker.h"
36 #include "application.h"
43 #include "workspace.h"
44 #include "superfluous.h"
55 * icon_file for the dock is got from the preferences file by
56 * using the classname/instancename
59 /**** Global variables ****/
60 extern Cursor wCursor
[WCUR_LAST
];
61 extern WPreferences wPreferences
;
62 extern WDDomain
*WDWindowAttributes
;
64 #define MOD_MASK wPreferences.modifier_mask
66 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
67 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
);
68 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
);
69 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
);
70 static WAppIcon
*wAppIconCreate(WWindow
* leader_win
);
71 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
);
72 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
);
74 /* This function is used if the application is a .app. It checks if it has an icon in it
75 * like for example /usr/local/GNUstep/Applications/WPrefs.app/WPrefs.tiff
77 void wApplicationExtractDirPackIcon(WScreen
* scr
, char *path
, char *wm_instance
, char *wm_class
)
79 char *iconPath
= NULL
;
82 if (strstr(path
, ".app")) {
83 tmp
= wmalloc(strlen(path
) + 16);
85 if (scr
->flags
.supports_tiff
) {
88 if (access(tmp
, R_OK
) == 0)
95 if (access(tmp
, R_OK
) == 0)
103 wApplicationSaveIconPathFor(iconPath
, wm_instance
, wm_class
);
109 WAppIcon
*wAppIconCreateForDock(WScreen
* scr
, char *command
, char *wm_instance
, char *wm_class
, int tile
)
114 dicon
= wmalloc(sizeof(WAppIcon
));
119 add_to_appicon_list(scr
, dicon
);
122 dicon
->command
= wstrdup(command
);
125 dicon
->wm_class
= wstrdup(wm_class
);
128 dicon
->wm_instance
= wstrdup(wm_instance
);
130 /* Search the icon using instance and class, without default icon */
131 path
= wDefaultGetIconFile(wm_instance
, wm_class
, False
);
132 if (!path
&& command
) {
133 wApplicationExtractDirPackIcon(scr
, command
, wm_instance
, wm_class
);
134 /* Search again, now with default icon */
135 path
= wDefaultGetIconFile(wm_instance
, wm_class
, True
);
139 path
= FindImage(wPreferences
.icon_path
, path
);
141 dicon
->icon
= wIconCreateWithIconFile(scr
, path
, tile
);
145 wXDNDMakeAwareness(dicon
->icon
->core
->window
);
148 /* will be overriden by dock */
149 dicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
150 dicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
151 dicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
152 dicon
->icon
->core
->descriptor
.parent
= dicon
;
153 AddToStackList(dicon
->icon
->core
);
158 void makeAppIconFor(WApplication
* wapp
)
160 /* If app_icon, work is done, return */
164 /* Create the icon */
165 wapp
->app_icon
= wAppIconCreate(wapp
->main_window_desc
);
167 /* Now, paint the icon */
168 if (!WFLAGP(wapp
->main_window_desc
, no_appicon
))
169 paint_app_icon(wapp
);
172 void paint_app_icon(WApplication
*wapp
)
175 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
176 WDock
*clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
179 if (!wapp
|| !wapp
->app_icon
)
182 icon
= wapp
->app_icon
->icon
;
183 wapp
->app_icon
->main_window
= wapp
->main_window
;
185 /* If the icon is docked, don't continue */
186 if (wapp
->app_icon
->docked
)
189 if (clip
&& clip
->attract_icons
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
190 wapp
->app_icon
->attracted
= 1;
191 if (!icon
->shadowed
) {
193 icon
->force_paint
= 1;
195 wDockAttachIcon(clip
, wapp
->app_icon
, x
, y
);
197 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wapp
->main_window_desc
));
198 wAppIconMove(wapp
->app_icon
, x
, y
);
199 wLowerFrame(icon
->core
);
202 if (!clip
|| !wapp
->app_icon
->attracted
|| !clip
->collapsed
)
203 XMapWindow(dpy
, icon
->core
->window
);
205 if (wPreferences
.auto_arrange_icons
&& !wapp
->app_icon
->attracted
)
206 wArrangeIcons(scr
, True
);
209 void removeAppIconFor(WApplication
* wapp
)
214 if (wapp
->app_icon
->docked
&& !wapp
->app_icon
->attracted
) {
215 wapp
->app_icon
->running
= 0;
216 /* since we keep it, we don't care if it was attracted or not */
217 wapp
->app_icon
->attracted
= 0;
218 wapp
->app_icon
->icon
->shadowed
= 0;
219 wapp
->app_icon
->main_window
= None
;
220 wapp
->app_icon
->pid
= 0;
221 wapp
->app_icon
->icon
->owner
= NULL
;
222 wapp
->app_icon
->icon
->icon_win
= None
;
223 wapp
->app_icon
->icon
->force_paint
= 1;
224 wAppIconPaint(wapp
->app_icon
);
225 } else if (wapp
->app_icon
->docked
) {
226 wapp
->app_icon
->running
= 0;
227 wDockDetach(wapp
->app_icon
->dock
, wapp
->app_icon
);
229 wAppIconDestroy(wapp
->app_icon
);
232 wapp
->app_icon
= NULL
;
234 if (wPreferences
.auto_arrange_icons
)
235 wArrangeIcons(wapp
->main_window_desc
->screen_ptr
, True
);
238 static WAppIcon
*wAppIconCreate(WWindow
* leader_win
)
241 WScreen
*scr
= leader_win
->screen_ptr
;
243 aicon
= wmalloc(sizeof(WAppIcon
));
249 /* When no_appicon is set we want to avoid having it on the list
250 * because otherwise there will be a hole when the icons are
251 * arranged with wArrangeIcons() */
252 if (!WFLAGP(leader_win
, no_appicon
))
253 add_to_appicon_list(scr
, aicon
);
255 if (leader_win
->wm_class
)
256 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
258 if (leader_win
->wm_instance
)
259 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
261 aicon
->icon
= wIconCreate(leader_win
);
263 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
266 /* will be overriden if docked */
267 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
268 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
269 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
270 aicon
->icon
->core
->descriptor
.parent
= aicon
;
271 AddToStackList(aicon
->icon
->core
);
272 aicon
->icon
->show_title
= 0;
273 wIconUpdate(aicon
->icon
);
278 void wAppIconDestroy(WAppIcon
* aicon
)
280 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
282 RemoveFromStackList(aicon
->icon
->core
);
283 wIconDestroy(aicon
->icon
);
285 wfree(aicon
->command
);
287 if (aicon
->dnd_command
)
288 wfree(aicon
->dnd_command
);
290 if (aicon
->wm_instance
)
291 wfree(aicon
->wm_instance
);
294 wfree(aicon
->wm_class
);
296 remove_from_appicon_list(scr
, aicon
);
298 aicon
->destroyed
= 1;
302 static void drawCorner(WIcon
* icon
)
304 WScreen
*scr
= icon
->core
->screen_ptr
;
313 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
314 points
, 3, Convex
, CoordModeOrigin
);
315 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
316 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
319 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
321 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
327 static void updateDockNumbers(WScreen
* scr
)
331 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
333 ws_numbers
= wmalloc(20);
334 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
335 length
= strlen(ws_numbers
);
337 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
339 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
340 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
342 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
343 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
347 #endif /* WS_INDICATOR */
349 void wAppIconPaint(WAppIcon
* aicon
)
352 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
354 if (aicon
->icon
->owner
)
355 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
359 wIconPaint(aicon
->icon
);
362 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
363 updateDockNumbers(scr
);
365 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
366 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
367 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
368 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
369 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
372 if (wapp
&& wapp
->flags
.hidden
) {
373 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
374 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
375 XCopyArea(dpy
, scr
->dock_dots
->image
,
376 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
378 #endif /* HIDDENDOT */
380 if (aicon
->omnipresent
)
381 drawCorner(aicon
->icon
);
383 XSetClipMask(dpy
, scr
->copy_gc
, None
);
384 if (aicon
->launching
)
385 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
386 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
389 /* Save the application icon, if it's a dockapp then use it with dock = True */
390 void save_appicon(WAppIcon
*aicon
, Bool dock
)
397 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
400 path
= wIconStore(aicon
->icon
);
404 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
408 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
410 /* main_window may not have the full command line; try to find one which does */
411 static void relaunchApplication(WApplication
*wapp
)
414 WWindow
*wlist
, *next
;
416 scr
= wapp
->main_window_desc
->screen_ptr
;
417 wlist
= scr
->focused_window
;
427 if (wlist
->main_window
== wapp
->main_window
) {
428 if (RelaunchWindow(wlist
))
436 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
438 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
440 relaunchApplication(wapp
);
443 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
445 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
447 if (wapp
->flags
.hidden
) {
448 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
449 wUnhideApplication(wapp
, False
, False
);
451 wHideApplication(wapp
);
455 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
457 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
459 wUnhideApplication(wapp
, False
, True
);
462 static void setIconCallback(WMenu
* menu
, WMenuEntry
* entry
)
464 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
469 assert(icon
!= NULL
);
475 scr
= icon
->icon
->core
->screen_ptr
;
479 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
481 if (result
&& !icon
->destroyed
) {
482 if (file
&& *file
== 0) {
486 if (!wIconChangeImageFile(icon
->icon
, file
)) {
487 wMessageDialog(scr
, _("Error"),
488 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
490 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
500 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
502 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
503 WFakeGroupLeader
*fPtr
;
506 char *basename(const char *shortname
);
508 if (!WCHECK_STATE(WSTATE_NORMAL
))
511 WCHANGE_STATE(WSTATE_MODAL
);
513 assert(entry
->clientdata
!= NULL
);
515 shortname
= basename(wapp
->app_icon
->wm_instance
);
517 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
518 _(" will be forcibly closed.\n"
519 "Any unsaved changes will be lost.\n" "Please confirm."));
521 fPtr
= wapp
->main_window_desc
->fake_group
;
523 wretain(wapp
->main_window_desc
);
524 if (wPreferences
.dont_confirm_kill
525 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
526 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
528 WWindow
*wwin
, *twin
;
530 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
533 if (wwin
->fake_group
== fPtr
)
537 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
538 wClientKill(wapp
->main_window_desc
);
541 wrelease(wapp
->main_window_desc
);
543 WCHANGE_STATE(WSTATE_NORMAL
);
546 static WMenu
*createApplicationMenu(WScreen
* scr
)
550 menu
= wMenuCreate(scr
, NULL
, False
);
551 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
552 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
553 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
554 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
555 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
560 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
563 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
566 if (!scr
->icon_menu
) {
567 scr
->icon_menu
= createApplicationMenu(scr
);
568 wfree(scr
->icon_menu
->entries
[1]->text
);
571 menu
= scr
->icon_menu
;
573 if (wapp
->flags
.hidden
)
574 menu
->entries
[1]->text
= _("Unhide");
576 menu
->entries
[1]->text
= _("Hide");
578 menu
->flags
.realized
= 0;
581 x
-= menu
->frame
->core
->width
/ 2;
582 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
583 x
= scr
->scr_width
- menu
->frame
->core
->width
;
588 /* set client data */
589 for (i
= 0; i
< menu
->entry_no
; i
++)
590 menu
->entries
[i
]->clientdata
= wapp
;
592 wMenuMapAt(menu
, x
, y
, False
);
595 /******************************************************************/
597 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
)
599 wAppIconPaint(desc
->parent
);
602 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
604 WAppIcon
*aicon
= desc
->parent
;
606 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
609 assert(aicon
->icon
->owner
!= NULL
);
611 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
613 if (event
->xbutton
.state
& ControlMask
) {
614 relaunchApplication(wapp
);
618 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
619 /* go to the last workspace that the user worked on the app */
620 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
621 wWorkspaceChange(scr
, wapp
->last_workspace
);
623 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
625 if (event
->xbutton
.state
& MOD_MASK
)
626 wHideOtherApplications(aicon
->icon
->owner
);
629 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
631 WAppIcon
*aicon
= desc
->parent
;
632 WIcon
*icon
= aicon
->icon
;
634 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
635 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
638 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
639 WScreen
*scr
= icon
->core
->screen_ptr
;
640 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
641 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
643 int clickButton
= event
->xbutton
.button
;
646 Bool movingSingle
= False
;
649 Bool hasMoved
= False
;
651 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
654 if (IsDoubleClick(scr
, event
)) {
655 /* Middle or right mouse actions were handled on first click */
656 if (event
->xbutton
.button
== Button1
)
657 iconDblClick(desc
, event
);
661 if (event
->xbutton
.button
== Button2
) {
662 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
665 relaunchApplication(wapp
);
670 if (event
->xbutton
.button
== Button3
) {
671 WObjDescriptor
*desc
;
672 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
677 if (event
->xbutton
.send_event
&&
678 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
679 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
680 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
681 wwarning("pointer grab failed for appicon menu");
685 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
687 /* allow drag select of menu */
688 desc
= &scr
->icon_menu
->menu
->descriptor
;
689 event
->xbutton
.send_event
= True
;
690 (*desc
->handle_mousedown
) (desc
, event
);
694 if (event
->xbutton
.state
& MOD_MASK
)
695 wLowerFrame(icon
->core
);
697 wRaiseFrame(icon
->core
);
699 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
700 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
701 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
702 wwarning("pointer grab failed for appicon move");
704 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
707 dockable
= canBeDocked(icon
->owner
);
709 wins
[0] = icon
->core
->window
;
710 wins
[1] = scr
->dock_shadow
;
711 XRestackWindows(dpy
, wins
, 2);
713 if (icon
->pixmap
!= None
)
714 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
716 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
717 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
718 XClearWindow(dpy
, scr
->dock_shadow
);
722 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
723 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
730 /* It means the cursor moved so fast that it entered
731 * something else (if moving slowly, it would have
732 * stayed in the appIcon that is being moved. Ignore
733 * such "spurious" EnterNotifiy's */
739 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
740 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
741 XChangeActivePointerGrab(dpy
, ButtonMotionMask
742 | ButtonReleaseMask
| ButtonPressMask
,
743 wCursor
[WCUR_MOVE
], CurrentTime
);
749 x
= ev
.xmotion
.x_root
- dx
;
750 y
= ev
.xmotion
.y_root
- dy
;
753 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
755 wAppIconMove(aicon
, x
, y
);
758 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
759 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
760 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
762 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
763 scr
->last_dock
->collapsed
= 1;
764 wDockHideIcons(scr
->last_dock
);
767 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
768 scr
->dock
->collapsed
= 0;
769 wDockShowIcons(scr
->dock
);
772 if (scr
->dock
->auto_raise_lower
)
773 wDockRaise(scr
->dock
);
775 scr
->last_dock
= scr
->dock
;
777 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
779 XMapWindow(dpy
, scr
->dock_shadow
);
782 } else if (workspace
->clip
&&
783 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
784 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
785 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
787 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
788 scr
->last_dock
->collapsed
= 1;
789 wDockHideIcons(scr
->last_dock
);
792 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
793 workspace
->clip
->collapsed
= 0;
794 wDockShowIcons(workspace
->clip
);
797 if (workspace
->clip
->auto_raise_lower
)
798 wDockRaise(workspace
->clip
);
800 scr
->last_dock
= workspace
->clip
;
802 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
804 XMapWindow(dpy
, scr
->dock_shadow
);
807 } else if (docking
) {
808 XUnmapWindow(dpy
, scr
->dock_shadow
);
818 if (ev
.xbutton
.button
!= clickButton
)
820 XUngrabPointer(dpy
, CurrentTime
);
825 /* icon is trying to be docked */
826 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
827 XUnmapWindow(dpy
, scr
->dock_shadow
);
828 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
);
829 if (scr
->last_dock
->auto_collapse
)
832 if (workspace
->clip
&&
833 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
834 wDockLower(workspace
->clip
);
837 /* If icon could not be docked, slide it back to the old
839 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
843 /* move back to its place */
844 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
845 wAppIconMove(aicon
, oldX
, oldY
);
847 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
851 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
852 wDockLower(workspace
->clip
);
855 scr
->last_dock
->collapsed
= 1;
856 wDockHideIcons(scr
->last_dock
);
861 XFreePixmap(dpy
, ghost
);
862 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
865 if (wPreferences
.auto_arrange_icons
)
866 wArrangeIcons(scr
, True
);
868 if (wPreferences
.single_click
&& !hasMoved
)
869 iconDblClick(desc
, event
);
877 /* This function save the application icon and store the path in the Dictionary */
878 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
880 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
881 WMPropList
*adict
, *key
, *iconk
;
885 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
886 key
= WMCreatePLString(tmp
);
889 adict
= WMGetFromPLDictionary(dict
, key
);
890 iconk
= WMCreatePLString("Icon");
893 val
= WMGetFromPLDictionary(adict
, iconk
);
895 /* no dictionary for app, so create one */
896 adict
= WMCreatePLDictionary(NULL
, NULL
);
897 WMPutInPLDictionary(dict
, key
, adict
);
898 WMReleasePropList(adict
);
903 val
= WMCreatePLString(iconPath
);
904 WMPutInPLDictionary(adict
, iconk
, val
);
905 WMReleasePropList(val
);
910 WMReleasePropList(key
);
911 WMReleasePropList(iconk
);
913 if (val
&& !wPreferences
.flags
.noupdates
)
914 UpdateDomainFile(WDWindowAttributes
);
917 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
919 WAppIcon
*aicon
= NULL
;
921 aicon
= wDockFindIconForWindow(dock
, main_window
);
923 wDockTrackWindowLaunch(dock
, main_window
);
924 aicon
= wDockFindIconForWindow(dock
, main_window
);
929 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
931 WScreen
*scr
= wwin
->screen_ptr
;
932 wapp
->app_icon
= NULL
;
935 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
937 /* check main dock if we did not find it in last dock */
938 if (!wapp
->app_icon
&& scr
->dock
)
939 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
941 /* finally check clips */
942 if (!wapp
->app_icon
) {
944 for (i
= 0; i
< scr
->workspace_count
; i
++) {
945 WDock
*dock
= scr
->workspaces
[i
]->clip
;
947 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
953 /* If created, then set some flags */
954 if (wapp
->app_icon
) {
955 WWindow
*mainw
= wapp
->main_window_desc
;
957 wapp
->app_icon
->running
= 1;
958 wapp
->app_icon
->icon
->force_paint
= 1;
959 wapp
->app_icon
->icon
->owner
= mainw
;
960 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
961 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
963 wAppIconPaint(wapp
->app_icon
);
964 save_appicon(wapp
->app_icon
, True
);
968 /* Add the appicon to the appiconlist */
969 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
971 appicon
->prev
= NULL
;
972 appicon
->next
= scr
->app_icon_list
;
973 if (scr
->app_icon_list
)
974 scr
->app_icon_list
->prev
= appicon
;
976 scr
->app_icon_list
= appicon
;
979 /* Remove the appicon from the appiconlist */
980 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
982 if (appicon
== scr
->app_icon_list
) {
984 appicon
->next
->prev
= NULL
;
985 scr
->app_icon_list
= appicon
->next
;
988 appicon
->next
->prev
= appicon
->prev
;
990 appicon
->prev
->next
= appicon
->next
;