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 aicon
= wmalloc(sizeof(WAppIcon
));
119 add_to_appicon_list(scr
, aicon
);
122 aicon
->command
= wstrdup(command
);
125 aicon
->wm_class
= wstrdup(wm_class
);
128 aicon
->wm_instance
= wstrdup(wm_instance
);
130 /* Search the icon using instance and class, without default icon */
131 path
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
133 aicon
->icon
= icon_create_for_dock(scr
, path
, tile
);
137 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
140 /* will be overriden by dock */
141 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
142 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
143 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
144 aicon
->icon
->core
->descriptor
.parent
= aicon
;
145 AddToStackList(aicon
->icon
->core
);
150 void makeAppIconFor(WApplication
*wapp
)
152 /* If app_icon, work is done, return */
156 /* Create the icon */
157 wapp
->app_icon
= wAppIconCreate(wapp
->main_window_desc
);
158 wIconUpdate(wapp
->app_icon
->icon
);
160 /* Now, paint the icon */
161 if (!WFLAGP(wapp
->main_window_desc
, no_appicon
))
162 paint_app_icon(wapp
);
165 void paint_app_icon(WApplication
*wapp
)
168 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
169 WDock
*clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
172 if (!wapp
|| !wapp
->app_icon
)
175 icon
= wapp
->app_icon
->icon
;
176 wapp
->app_icon
->main_window
= wapp
->main_window
;
178 /* If the icon is docked, don't continue */
179 if (wapp
->app_icon
->docked
)
182 if (clip
&& clip
->attract_icons
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
183 wapp
->app_icon
->attracted
= 1;
184 if (!icon
->shadowed
) {
186 icon
->force_paint
= 1;
188 wDockAttachIcon(clip
, wapp
->app_icon
, x
, y
);
190 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wapp
->main_window_desc
));
191 wAppIconMove(wapp
->app_icon
, x
, y
);
192 wLowerFrame(icon
->core
);
195 if (!clip
|| !wapp
->app_icon
->attracted
|| !clip
->collapsed
)
196 XMapWindow(dpy
, icon
->core
->window
);
198 if (wPreferences
.auto_arrange_icons
&& !wapp
->app_icon
->attracted
)
199 wArrangeIcons(scr
, True
);
202 void removeAppIconFor(WApplication
* wapp
)
207 if (wapp
->app_icon
->docked
&& !wapp
->app_icon
->attracted
) {
208 wapp
->app_icon
->running
= 0;
209 /* since we keep it, we don't care if it was attracted or not */
210 wapp
->app_icon
->attracted
= 0;
211 wapp
->app_icon
->icon
->shadowed
= 0;
212 wapp
->app_icon
->main_window
= None
;
213 wapp
->app_icon
->pid
= 0;
214 wapp
->app_icon
->icon
->owner
= NULL
;
215 wapp
->app_icon
->icon
->icon_win
= None
;
216 wapp
->app_icon
->icon
->force_paint
= 1;
217 wAppIconPaint(wapp
->app_icon
);
218 } else if (wapp
->app_icon
->docked
) {
219 wapp
->app_icon
->running
= 0;
220 wDockDetach(wapp
->app_icon
->dock
, wapp
->app_icon
);
222 wAppIconDestroy(wapp
->app_icon
);
225 wapp
->app_icon
= NULL
;
227 if (wPreferences
.auto_arrange_icons
)
228 wArrangeIcons(wapp
->main_window_desc
->screen_ptr
, True
);
231 static WAppIcon
*wAppIconCreate(WWindow
*leader_win
)
234 WScreen
*scr
= leader_win
->screen_ptr
;
236 aicon
= wmalloc(sizeof(WAppIcon
));
241 /* When no_appicon is set we want to avoid having it on the list
242 * because otherwise there will be a hole when the icons are
243 * arranged with wArrangeIcons() */
244 if (!WFLAGP(leader_win
, no_appicon
))
245 add_to_appicon_list(scr
, aicon
);
247 if (leader_win
->wm_class
)
248 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
250 if (leader_win
->wm_instance
)
251 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
253 aicon
->icon
= icon_create_for_wwindow(leader_win
);
255 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
258 /* will be overriden if docked */
259 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
260 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
261 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
262 aicon
->icon
->core
->descriptor
.parent
= aicon
;
263 AddToStackList(aicon
->icon
->core
);
264 aicon
->icon
->show_title
= 0;
269 void wAppIconDestroy(WAppIcon
* aicon
)
271 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
273 RemoveFromStackList(aicon
->icon
->core
);
274 wIconDestroy(aicon
->icon
);
276 wfree(aicon
->command
);
278 if (aicon
->dnd_command
)
279 wfree(aicon
->dnd_command
);
281 if (aicon
->wm_instance
)
282 wfree(aicon
->wm_instance
);
285 wfree(aicon
->wm_class
);
287 remove_from_appicon_list(scr
, aicon
);
289 aicon
->destroyed
= 1;
293 static void drawCorner(WIcon
* icon
)
295 WScreen
*scr
= icon
->core
->screen_ptr
;
304 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
305 points
, 3, Convex
, CoordModeOrigin
);
306 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
307 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
310 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
312 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
318 static void updateDockNumbers(WScreen
* scr
)
322 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
324 ws_numbers
= wmalloc(20);
325 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
326 length
= strlen(ws_numbers
);
328 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
330 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
331 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
333 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
334 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
338 #endif /* WS_INDICATOR */
340 void wAppIconPaint(WAppIcon
* aicon
)
343 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
345 if (aicon
->icon
->owner
)
346 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
350 wIconPaint(aicon
->icon
);
353 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
354 updateDockNumbers(scr
);
356 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
357 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
358 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
359 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
360 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
363 if (wapp
&& wapp
->flags
.hidden
) {
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
,
367 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
369 #endif /* HIDDENDOT */
371 if (aicon
->omnipresent
)
372 drawCorner(aicon
->icon
);
374 XSetClipMask(dpy
, scr
->copy_gc
, None
);
375 if (aicon
->launching
)
376 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
377 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
380 /* Save the application icon, if it's a dockapp then use it with dock = True */
381 void save_appicon(WAppIcon
*aicon
, Bool dock
)
388 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
391 path
= wIconStore(aicon
->icon
);
395 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
399 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
401 /* main_window may not have the full command line; try to find one which does */
402 static void relaunchApplication(WApplication
*wapp
)
405 WWindow
*wlist
, *next
;
407 scr
= wapp
->main_window_desc
->screen_ptr
;
408 wlist
= scr
->focused_window
;
418 if (wlist
->main_window
== wapp
->main_window
) {
419 if (RelaunchWindow(wlist
))
427 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
429 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
431 relaunchApplication(wapp
);
434 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
436 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
438 if (wapp
->flags
.hidden
) {
439 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
440 wUnhideApplication(wapp
, False
, False
);
442 wHideApplication(wapp
);
446 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
448 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
450 wUnhideApplication(wapp
, False
, True
);
453 static void setIconCallback(WMenu
* menu
, WMenuEntry
* entry
)
455 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
460 assert(icon
!= NULL
);
466 scr
= icon
->icon
->core
->screen_ptr
;
470 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
472 if (result
&& !icon
->destroyed
) {
473 if (file
&& *file
== 0) {
477 if (!wIconChangeImageFile(icon
->icon
, file
)) {
478 wMessageDialog(scr
, _("Error"),
479 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
481 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
491 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
493 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
494 WFakeGroupLeader
*fPtr
;
497 char *basename(const char *shortname
);
499 if (!WCHECK_STATE(WSTATE_NORMAL
))
502 WCHANGE_STATE(WSTATE_MODAL
);
504 assert(entry
->clientdata
!= NULL
);
506 shortname
= basename(wapp
->app_icon
->wm_instance
);
508 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
509 _(" will be forcibly closed.\n"
510 "Any unsaved changes will be lost.\n" "Please confirm."));
512 fPtr
= wapp
->main_window_desc
->fake_group
;
514 wretain(wapp
->main_window_desc
);
515 if (wPreferences
.dont_confirm_kill
516 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
517 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
519 WWindow
*wwin
, *twin
;
521 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
524 if (wwin
->fake_group
== fPtr
)
528 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
529 wClientKill(wapp
->main_window_desc
);
532 wrelease(wapp
->main_window_desc
);
534 WCHANGE_STATE(WSTATE_NORMAL
);
537 static WMenu
*createApplicationMenu(WScreen
* scr
)
541 menu
= wMenuCreate(scr
, NULL
, False
);
542 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
543 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
544 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
545 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
546 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
551 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
554 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
557 if (!scr
->icon_menu
) {
558 scr
->icon_menu
= createApplicationMenu(scr
);
559 wfree(scr
->icon_menu
->entries
[1]->text
);
562 menu
= scr
->icon_menu
;
564 if (wapp
->flags
.hidden
)
565 menu
->entries
[1]->text
= _("Unhide");
567 menu
->entries
[1]->text
= _("Hide");
569 menu
->flags
.realized
= 0;
572 x
-= menu
->frame
->core
->width
/ 2;
573 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
574 x
= scr
->scr_width
- menu
->frame
->core
->width
;
579 /* set client data */
580 for (i
= 0; i
< menu
->entry_no
; i
++)
581 menu
->entries
[i
]->clientdata
= wapp
;
583 wMenuMapAt(menu
, x
, y
, False
);
586 /******************************************************************/
588 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
)
590 wAppIconPaint(desc
->parent
);
593 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
595 WAppIcon
*aicon
= desc
->parent
;
597 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
600 assert(aicon
->icon
->owner
!= NULL
);
602 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
604 if (event
->xbutton
.state
& ControlMask
) {
605 relaunchApplication(wapp
);
609 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
610 /* go to the last workspace that the user worked on the app */
611 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
612 wWorkspaceChange(scr
, wapp
->last_workspace
);
614 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
616 if (event
->xbutton
.state
& MOD_MASK
)
617 wHideOtherApplications(aicon
->icon
->owner
);
620 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
622 WAppIcon
*aicon
= desc
->parent
;
623 WIcon
*icon
= aicon
->icon
;
625 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
626 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
629 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
630 WScreen
*scr
= icon
->core
->screen_ptr
;
631 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
632 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
634 int clickButton
= event
->xbutton
.button
;
637 Bool movingSingle
= False
;
640 Bool hasMoved
= False
;
642 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
645 if (IsDoubleClick(scr
, event
)) {
646 /* Middle or right mouse actions were handled on first click */
647 if (event
->xbutton
.button
== Button1
)
648 iconDblClick(desc
, event
);
652 if (event
->xbutton
.button
== Button2
) {
653 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
656 relaunchApplication(wapp
);
661 if (event
->xbutton
.button
== Button3
) {
662 WObjDescriptor
*desc
;
663 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
668 if (event
->xbutton
.send_event
&&
669 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
670 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
671 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
672 wwarning("pointer grab failed for appicon menu");
676 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
678 /* allow drag select of menu */
679 desc
= &scr
->icon_menu
->menu
->descriptor
;
680 event
->xbutton
.send_event
= True
;
681 (*desc
->handle_mousedown
) (desc
, event
);
685 if (event
->xbutton
.state
& MOD_MASK
)
686 wLowerFrame(icon
->core
);
688 wRaiseFrame(icon
->core
);
690 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
691 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
692 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
693 wwarning("pointer grab failed for appicon move");
695 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
698 dockable
= canBeDocked(icon
->owner
);
700 wins
[0] = icon
->core
->window
;
701 wins
[1] = scr
->dock_shadow
;
702 XRestackWindows(dpy
, wins
, 2);
704 if (icon
->pixmap
!= None
)
705 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
707 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
708 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
709 XClearWindow(dpy
, scr
->dock_shadow
);
713 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
714 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
721 /* It means the cursor moved so fast that it entered
722 * something else (if moving slowly, it would have
723 * stayed in the appIcon that is being moved. Ignore
724 * such "spurious" EnterNotifiy's */
730 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
731 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
732 XChangeActivePointerGrab(dpy
, ButtonMotionMask
733 | ButtonReleaseMask
| ButtonPressMask
,
734 wCursor
[WCUR_MOVE
], CurrentTime
);
740 x
= ev
.xmotion
.x_root
- dx
;
741 y
= ev
.xmotion
.y_root
- dy
;
744 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
746 wAppIconMove(aicon
, x
, y
);
749 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
750 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
751 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
753 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
754 scr
->last_dock
->collapsed
= 1;
755 wDockHideIcons(scr
->last_dock
);
758 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
759 scr
->dock
->collapsed
= 0;
760 wDockShowIcons(scr
->dock
);
763 if (scr
->dock
->auto_raise_lower
)
764 wDockRaise(scr
->dock
);
766 scr
->last_dock
= scr
->dock
;
768 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
770 XMapWindow(dpy
, scr
->dock_shadow
);
773 } else if (workspace
->clip
&&
774 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
775 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
776 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
778 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
779 scr
->last_dock
->collapsed
= 1;
780 wDockHideIcons(scr
->last_dock
);
783 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
784 workspace
->clip
->collapsed
= 0;
785 wDockShowIcons(workspace
->clip
);
788 if (workspace
->clip
->auto_raise_lower
)
789 wDockRaise(workspace
->clip
);
791 scr
->last_dock
= workspace
->clip
;
793 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
795 XMapWindow(dpy
, scr
->dock_shadow
);
798 } else if (docking
) {
799 XUnmapWindow(dpy
, scr
->dock_shadow
);
809 if (ev
.xbutton
.button
!= clickButton
)
811 XUngrabPointer(dpy
, CurrentTime
);
816 /* icon is trying to be docked */
817 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
818 XUnmapWindow(dpy
, scr
->dock_shadow
);
819 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
);
820 if (scr
->last_dock
->auto_collapse
)
823 if (workspace
->clip
&&
824 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
825 wDockLower(workspace
->clip
);
828 /* If icon could not be docked, slide it back to the old
830 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
834 /* move back to its place */
835 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
836 wAppIconMove(aicon
, oldX
, oldY
);
838 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
842 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
843 wDockLower(workspace
->clip
);
846 scr
->last_dock
->collapsed
= 1;
847 wDockHideIcons(scr
->last_dock
);
852 XFreePixmap(dpy
, ghost
);
853 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
856 if (wPreferences
.auto_arrange_icons
)
857 wArrangeIcons(scr
, True
);
859 if (wPreferences
.single_click
&& !hasMoved
)
860 iconDblClick(desc
, event
);
868 /* This function save the application icon and store the path in the Dictionary */
869 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
871 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
872 WMPropList
*adict
, *key
, *iconk
;
876 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
877 key
= WMCreatePLString(tmp
);
880 adict
= WMGetFromPLDictionary(dict
, key
);
881 iconk
= WMCreatePLString("Icon");
884 val
= WMGetFromPLDictionary(adict
, iconk
);
886 /* no dictionary for app, so create one */
887 adict
= WMCreatePLDictionary(NULL
, NULL
);
888 WMPutInPLDictionary(dict
, key
, adict
);
889 WMReleasePropList(adict
);
894 val
= WMCreatePLString(iconPath
);
895 WMPutInPLDictionary(adict
, iconk
, val
);
896 WMReleasePropList(val
);
901 WMReleasePropList(key
);
902 WMReleasePropList(iconk
);
904 if (val
&& !wPreferences
.flags
.noupdates
)
905 UpdateDomainFile(WDWindowAttributes
);
908 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
910 WAppIcon
*aicon
= NULL
;
912 aicon
= wDockFindIconForWindow(dock
, main_window
);
914 wDockTrackWindowLaunch(dock
, main_window
);
915 aicon
= wDockFindIconForWindow(dock
, main_window
);
920 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
922 WScreen
*scr
= wwin
->screen_ptr
;
923 wapp
->app_icon
= NULL
;
926 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
928 /* check main dock if we did not find it in last dock */
929 if (!wapp
->app_icon
&& scr
->dock
)
930 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
932 /* finally check clips */
933 if (!wapp
->app_icon
) {
935 for (i
= 0; i
< scr
->workspace_count
; i
++) {
936 WDock
*dock
= scr
->workspaces
[i
]->clip
;
938 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
944 /* If created, then set some flags */
945 if (wapp
->app_icon
) {
946 WWindow
*mainw
= wapp
->main_window_desc
;
948 wapp
->app_icon
->running
= 1;
949 wapp
->app_icon
->icon
->force_paint
= 1;
950 wapp
->app_icon
->icon
->owner
= mainw
;
951 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
952 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
954 wAppIconPaint(wapp
->app_icon
);
955 save_appicon(wapp
->app_icon
, True
);
959 /* Add the appicon to the appiconlist */
960 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
962 appicon
->prev
= NULL
;
963 appicon
->next
= scr
->app_icon_list
;
964 if (scr
->app_icon_list
)
965 scr
->app_icon_list
->prev
= appicon
;
967 scr
->app_icon_list
= appicon
;
970 /* Remove the appicon from the appiconlist */
971 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
973 if (appicon
== scr
->app_icon_list
) {
975 appicon
->next
->prev
= NULL
;
976 scr
->app_icon_list
= appicon
->next
;
979 appicon
->next
->prev
= appicon
->prev
;
981 appicon
->prev
->next
= appicon
->next
;