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 path
= wDefaultGetIconFile(wm_instance
, wm_class
, True
);
131 if (!path
&& command
) {
132 wApplicationExtractDirPackIcon(scr
, command
, wm_instance
, wm_class
);
133 path
= wDefaultGetIconFile(wm_instance
, wm_class
, False
);
137 path
= FindImage(wPreferences
.icon_path
, path
);
139 dicon
->icon
= wIconCreateWithIconFile(scr
, path
, tile
);
143 wXDNDMakeAwareness(dicon
->icon
->core
->window
);
146 /* will be overriden by dock */
147 dicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
148 dicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
149 dicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
150 dicon
->icon
->core
->descriptor
.parent
= dicon
;
151 AddToStackList(dicon
->icon
->core
);
156 void makeAppIconFor(WApplication
* wapp
)
158 /* If app_icon, work is done, return */
162 /* Create the icon */
163 wapp
->app_icon
= wAppIconCreate(wapp
->main_window_desc
);
165 /* Now, paint the icon */
166 if (!WFLAGP(wapp
->main_window_desc
, no_appicon
))
167 paint_app_icon(wapp
);
170 void paint_app_icon(WApplication
*wapp
)
173 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
174 WDock
*clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
177 if (!wapp
|| !wapp
->app_icon
)
180 icon
= wapp
->app_icon
->icon
;
181 wapp
->app_icon
->main_window
= wapp
->main_window
;
183 /* If the icon is docked, don't continue */
184 if (wapp
->app_icon
->docked
)
187 if (clip
&& clip
->attract_icons
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
188 wapp
->app_icon
->attracted
= 1;
189 if (!icon
->shadowed
) {
191 icon
->force_paint
= 1;
193 wDockAttachIcon(clip
, wapp
->app_icon
, x
, y
);
195 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wapp
->main_window_desc
));
196 wAppIconMove(wapp
->app_icon
, x
, y
);
197 wLowerFrame(icon
->core
);
200 if (!clip
|| !wapp
->app_icon
->attracted
|| !clip
->collapsed
)
201 XMapWindow(dpy
, icon
->core
->window
);
203 if (wPreferences
.auto_arrange_icons
&& !wapp
->app_icon
->attracted
)
204 wArrangeIcons(scr
, True
);
207 void removeAppIconFor(WApplication
* wapp
)
212 if (wapp
->app_icon
->docked
&& !wapp
->app_icon
->attracted
) {
213 wapp
->app_icon
->running
= 0;
214 /* since we keep it, we don't care if it was attracted or not */
215 wapp
->app_icon
->attracted
= 0;
216 wapp
->app_icon
->icon
->shadowed
= 0;
217 wapp
->app_icon
->main_window
= None
;
218 wapp
->app_icon
->pid
= 0;
219 wapp
->app_icon
->icon
->owner
= NULL
;
220 wapp
->app_icon
->icon
->icon_win
= None
;
221 wapp
->app_icon
->icon
->force_paint
= 1;
222 wAppIconPaint(wapp
->app_icon
);
223 } else if (wapp
->app_icon
->docked
) {
224 wapp
->app_icon
->running
= 0;
225 wDockDetach(wapp
->app_icon
->dock
, wapp
->app_icon
);
227 wAppIconDestroy(wapp
->app_icon
);
230 wapp
->app_icon
= NULL
;
232 if (wPreferences
.auto_arrange_icons
)
233 wArrangeIcons(wapp
->main_window_desc
->screen_ptr
, True
);
236 static WAppIcon
*wAppIconCreate(WWindow
* leader_win
)
239 WScreen
*scr
= leader_win
->screen_ptr
;
241 aicon
= wmalloc(sizeof(WAppIcon
));
247 /* When no_appicon is set we want to avoid having it on the list
248 * because otherwise there will be a hole when the icons are
249 * arranged with wArrangeIcons() */
250 if (!WFLAGP(leader_win
, no_appicon
))
251 add_to_appicon_list(scr
, aicon
);
253 if (leader_win
->wm_class
)
254 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
256 if (leader_win
->wm_instance
)
257 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
259 aicon
->icon
= wIconCreate(leader_win
);
261 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
264 /* will be overriden if docked */
265 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
266 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
267 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
268 aicon
->icon
->core
->descriptor
.parent
= aicon
;
269 AddToStackList(aicon
->icon
->core
);
270 aicon
->icon
->show_title
= 0;
271 wIconUpdate(aicon
->icon
);
276 void wAppIconDestroy(WAppIcon
* aicon
)
278 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
280 RemoveFromStackList(aicon
->icon
->core
);
281 wIconDestroy(aicon
->icon
);
283 wfree(aicon
->command
);
285 if (aicon
->dnd_command
)
286 wfree(aicon
->dnd_command
);
288 if (aicon
->wm_instance
)
289 wfree(aicon
->wm_instance
);
292 wfree(aicon
->wm_class
);
294 remove_from_appicon_list(scr
, aicon
);
296 aicon
->destroyed
= 1;
300 static void drawCorner(WIcon
* icon
)
302 WScreen
*scr
= icon
->core
->screen_ptr
;
311 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
312 points
, 3, Convex
, CoordModeOrigin
);
313 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
314 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
317 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
319 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
325 static void updateDockNumbers(WScreen
* scr
)
329 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
331 ws_numbers
= wmalloc(20);
332 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
333 length
= strlen(ws_numbers
);
335 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
337 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
338 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
340 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
341 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
345 #endif /* WS_INDICATOR */
347 void wAppIconPaint(WAppIcon
* aicon
)
350 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
352 if (aicon
->icon
->owner
)
353 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
357 wIconPaint(aicon
->icon
);
360 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
361 updateDockNumbers(scr
);
363 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
364 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
365 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
366 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
367 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
370 if (wapp
&& wapp
->flags
.hidden
) {
371 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
372 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
373 XCopyArea(dpy
, scr
->dock_dots
->image
,
374 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
376 #endif /* HIDDENDOT */
378 if (aicon
->omnipresent
)
379 drawCorner(aicon
->icon
);
381 XSetClipMask(dpy
, scr
->copy_gc
, None
);
382 if (aicon
->launching
)
383 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
384 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
387 /* Save the application icon, if it's a dockapp then use it with dock = True */
388 void save_appicon(WAppIcon
*aicon
, Bool dock
)
395 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
398 path
= wIconStore(aicon
->icon
);
402 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
406 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
408 /* main_window may not have the full command line; try to find one which does */
409 static void relaunchApplication(WApplication
*wapp
)
412 WWindow
*wlist
, *next
;
414 scr
= wapp
->main_window_desc
->screen_ptr
;
415 wlist
= scr
->focused_window
;
425 if (wlist
->main_window
== wapp
->main_window
) {
426 if (RelaunchWindow(wlist
))
434 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
436 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
438 relaunchApplication(wapp
);
441 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
443 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
445 if (wapp
->flags
.hidden
) {
446 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
447 wUnhideApplication(wapp
, False
, False
);
449 wHideApplication(wapp
);
453 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
455 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
457 wUnhideApplication(wapp
, False
, True
);
460 static void setIconCallback(WMenu
* menu
, WMenuEntry
* entry
)
462 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
467 assert(icon
!= NULL
);
473 scr
= icon
->icon
->core
->screen_ptr
;
477 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
479 if (result
&& !icon
->destroyed
) {
480 if (file
&& *file
== 0) {
484 if (!wIconChangeImageFile(icon
->icon
, file
)) {
485 wMessageDialog(scr
, _("Error"),
486 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
488 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
498 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
500 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
501 WFakeGroupLeader
*fPtr
;
504 char *basename(const char *shortname
);
506 if (!WCHECK_STATE(WSTATE_NORMAL
))
509 WCHANGE_STATE(WSTATE_MODAL
);
511 assert(entry
->clientdata
!= NULL
);
513 shortname
= basename(wapp
->app_icon
->wm_instance
);
515 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
516 _(" will be forcibly closed.\n"
517 "Any unsaved changes will be lost.\n" "Please confirm."));
519 fPtr
= wapp
->main_window_desc
->fake_group
;
521 wretain(wapp
->main_window_desc
);
522 if (wPreferences
.dont_confirm_kill
523 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
524 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
526 WWindow
*wwin
, *twin
;
528 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
531 if (wwin
->fake_group
== fPtr
)
535 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
536 wClientKill(wapp
->main_window_desc
);
539 wrelease(wapp
->main_window_desc
);
541 WCHANGE_STATE(WSTATE_NORMAL
);
544 static WMenu
*createApplicationMenu(WScreen
* scr
)
548 menu
= wMenuCreate(scr
, NULL
, False
);
549 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
550 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
551 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
552 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
553 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
558 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
561 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
564 if (!scr
->icon_menu
) {
565 scr
->icon_menu
= createApplicationMenu(scr
);
566 wfree(scr
->icon_menu
->entries
[1]->text
);
569 menu
= scr
->icon_menu
;
571 if (wapp
->flags
.hidden
)
572 menu
->entries
[1]->text
= _("Unhide");
574 menu
->entries
[1]->text
= _("Hide");
576 menu
->flags
.realized
= 0;
579 x
-= menu
->frame
->core
->width
/ 2;
580 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
581 x
= scr
->scr_width
- menu
->frame
->core
->width
;
586 /* set client data */
587 for (i
= 0; i
< menu
->entry_no
; i
++)
588 menu
->entries
[i
]->clientdata
= wapp
;
590 wMenuMapAt(menu
, x
, y
, False
);
593 /******************************************************************/
595 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
)
597 wAppIconPaint(desc
->parent
);
600 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
602 WAppIcon
*aicon
= desc
->parent
;
604 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
607 assert(aicon
->icon
->owner
!= NULL
);
609 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
611 if (event
->xbutton
.state
& ControlMask
) {
612 relaunchApplication(wapp
);
616 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
617 /* go to the last workspace that the user worked on the app */
618 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
619 wWorkspaceChange(scr
, wapp
->last_workspace
);
621 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
623 if (event
->xbutton
.state
& MOD_MASK
)
624 wHideOtherApplications(aicon
->icon
->owner
);
627 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
629 WAppIcon
*aicon
= desc
->parent
;
630 WIcon
*icon
= aicon
->icon
;
632 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
633 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
636 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
637 WScreen
*scr
= icon
->core
->screen_ptr
;
638 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
639 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
641 int clickButton
= event
->xbutton
.button
;
644 Bool movingSingle
= False
;
647 Bool hasMoved
= False
;
649 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
652 if (IsDoubleClick(scr
, event
)) {
653 /* Middle or right mouse actions were handled on first click */
654 if (event
->xbutton
.button
== Button1
)
655 iconDblClick(desc
, event
);
659 if (event
->xbutton
.button
== Button2
) {
660 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
663 relaunchApplication(wapp
);
668 if (event
->xbutton
.button
== Button3
) {
669 WObjDescriptor
*desc
;
670 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
675 if (event
->xbutton
.send_event
&&
676 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
677 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
678 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
679 wwarning("pointer grab failed for appicon menu");
683 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
685 /* allow drag select of menu */
686 desc
= &scr
->icon_menu
->menu
->descriptor
;
687 event
->xbutton
.send_event
= True
;
688 (*desc
->handle_mousedown
) (desc
, event
);
692 if (event
->xbutton
.state
& MOD_MASK
)
693 wLowerFrame(icon
->core
);
695 wRaiseFrame(icon
->core
);
697 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
698 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
699 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
700 wwarning("pointer grab failed for appicon move");
702 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
705 dockable
= canBeDocked(icon
->owner
);
707 wins
[0] = icon
->core
->window
;
708 wins
[1] = scr
->dock_shadow
;
709 XRestackWindows(dpy
, wins
, 2);
711 if (icon
->pixmap
!= None
)
712 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
714 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
715 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
716 XClearWindow(dpy
, scr
->dock_shadow
);
720 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
721 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
728 /* It means the cursor moved so fast that it entered
729 * something else (if moving slowly, it would have
730 * stayed in the appIcon that is being moved. Ignore
731 * such "spurious" EnterNotifiy's */
737 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
738 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
739 XChangeActivePointerGrab(dpy
, ButtonMotionMask
740 | ButtonReleaseMask
| ButtonPressMask
,
741 wCursor
[WCUR_MOVE
], CurrentTime
);
747 x
= ev
.xmotion
.x_root
- dx
;
748 y
= ev
.xmotion
.y_root
- dy
;
751 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
753 wAppIconMove(aicon
, x
, y
);
756 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
757 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
758 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
760 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
761 scr
->last_dock
->collapsed
= 1;
762 wDockHideIcons(scr
->last_dock
);
765 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
766 scr
->dock
->collapsed
= 0;
767 wDockShowIcons(scr
->dock
);
770 if (scr
->dock
->auto_raise_lower
)
771 wDockRaise(scr
->dock
);
773 scr
->last_dock
= scr
->dock
;
775 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
777 XMapWindow(dpy
, scr
->dock_shadow
);
780 } else if (workspace
->clip
&&
781 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
782 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
783 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
785 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
786 scr
->last_dock
->collapsed
= 1;
787 wDockHideIcons(scr
->last_dock
);
790 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
791 workspace
->clip
->collapsed
= 0;
792 wDockShowIcons(workspace
->clip
);
795 if (workspace
->clip
->auto_raise_lower
)
796 wDockRaise(workspace
->clip
);
798 scr
->last_dock
= workspace
->clip
;
800 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
802 XMapWindow(dpy
, scr
->dock_shadow
);
805 } else if (docking
) {
806 XUnmapWindow(dpy
, scr
->dock_shadow
);
816 if (ev
.xbutton
.button
!= clickButton
)
818 XUngrabPointer(dpy
, CurrentTime
);
823 /* icon is trying to be docked */
824 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
825 XUnmapWindow(dpy
, scr
->dock_shadow
);
826 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
);
827 if (scr
->last_dock
->auto_collapse
)
830 if (workspace
->clip
&&
831 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
832 wDockLower(workspace
->clip
);
835 /* If icon could not be docked, slide it back to the old
837 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
841 /* move back to its place */
842 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
843 wAppIconMove(aicon
, oldX
, oldY
);
845 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
849 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
850 wDockLower(workspace
->clip
);
853 scr
->last_dock
->collapsed
= 1;
854 wDockHideIcons(scr
->last_dock
);
859 XFreePixmap(dpy
, ghost
);
860 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
863 if (wPreferences
.auto_arrange_icons
)
864 wArrangeIcons(scr
, True
);
866 if (wPreferences
.single_click
&& !hasMoved
)
867 iconDblClick(desc
, event
);
875 /* This function save the application icon and store the path in the Dictionary */
876 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
878 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
879 WMPropList
*adict
, *key
, *iconk
;
883 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
884 key
= WMCreatePLString(tmp
);
887 adict
= WMGetFromPLDictionary(dict
, key
);
888 iconk
= WMCreatePLString("Icon");
891 val
= WMGetFromPLDictionary(adict
, iconk
);
893 /* no dictionary for app, so create one */
894 adict
= WMCreatePLDictionary(NULL
, NULL
);
895 WMPutInPLDictionary(dict
, key
, adict
);
896 WMReleasePropList(adict
);
901 val
= WMCreatePLString(iconPath
);
902 WMPutInPLDictionary(adict
, iconk
, val
);
903 WMReleasePropList(val
);
908 WMReleasePropList(key
);
909 WMReleasePropList(iconk
);
911 if (val
&& !wPreferences
.flags
.noupdates
)
912 UpdateDomainFile(WDWindowAttributes
);
915 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
917 WAppIcon
*aicon
= NULL
;
919 aicon
= wDockFindIconForWindow(dock
, main_window
);
921 wDockTrackWindowLaunch(dock
, main_window
);
922 aicon
= wDockFindIconForWindow(dock
, main_window
);
927 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
929 WScreen
*scr
= wwin
->screen_ptr
;
930 wapp
->app_icon
= NULL
;
933 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
935 /* check main dock if we did not find it in last dock */
936 if (!wapp
->app_icon
&& scr
->dock
)
937 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
939 /* finally check clips */
940 if (!wapp
->app_icon
) {
942 for (i
= 0; i
< scr
->workspace_count
; i
++) {
943 WDock
*dock
= scr
->workspaces
[i
]->clip
;
945 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
951 /* If created, then set some flags */
952 if (wapp
->app_icon
) {
953 WWindow
*mainw
= wapp
->main_window_desc
;
955 wapp
->app_icon
->running
= 1;
956 wapp
->app_icon
->icon
->force_paint
= 1;
957 wapp
->app_icon
->icon
->owner
= mainw
;
958 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
959 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
961 wAppIconPaint(wapp
->app_icon
);
962 save_appicon(wapp
->app_icon
, True
);
966 /* Add the appicon to the appiconlist */
967 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
969 appicon
->prev
= NULL
;
970 appicon
->next
= scr
->app_icon_list
;
971 if (scr
->app_icon_list
)
972 scr
->app_icon_list
->prev
= appicon
;
974 scr
->app_icon_list
= appicon
;
977 /* Remove the appicon from the appiconlist */
978 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
980 if (appicon
== scr
->app_icon_list
) {
982 appicon
->next
->prev
= NULL
;
983 scr
->app_icon_list
= appicon
->next
;
986 appicon
->next
->prev
= appicon
->prev
;
988 appicon
->prev
->next
= appicon
->next
;