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
= get_default_icon_filename(scr
, wm_instance
, wm_class
, command
, False
);
133 dicon
->icon
= wIconCreateWithIconFile(scr
, path
, tile
);
137 wXDNDMakeAwareness(dicon
->icon
->core
->window
);
140 /* will be overriden by dock */
141 dicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
142 dicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
143 dicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
144 dicon
->icon
->core
->descriptor
.parent
= dicon
;
145 AddToStackList(dicon
->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
));
242 /* When no_appicon is set we want to avoid having it on the list
243 * because otherwise there will be a hole when the icons are
244 * arranged with wArrangeIcons() */
245 if (!WFLAGP(leader_win
, no_appicon
))
246 add_to_appicon_list(scr
, aicon
);
248 if (leader_win
->wm_class
)
249 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
251 if (leader_win
->wm_instance
)
252 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
254 aicon
->icon
= wIconCreate(leader_win
);
256 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
259 /* will be overriden if docked */
260 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
261 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
262 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
263 aicon
->icon
->core
->descriptor
.parent
= aicon
;
264 AddToStackList(aicon
->icon
->core
);
265 aicon
->icon
->show_title
= 0;
270 void wAppIconDestroy(WAppIcon
* aicon
)
272 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
274 RemoveFromStackList(aicon
->icon
->core
);
275 wIconDestroy(aicon
->icon
);
277 wfree(aicon
->command
);
279 if (aicon
->dnd_command
)
280 wfree(aicon
->dnd_command
);
282 if (aicon
->wm_instance
)
283 wfree(aicon
->wm_instance
);
286 wfree(aicon
->wm_class
);
288 remove_from_appicon_list(scr
, aicon
);
290 aicon
->destroyed
= 1;
294 static void drawCorner(WIcon
* icon
)
296 WScreen
*scr
= icon
->core
->screen_ptr
;
305 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
306 points
, 3, Convex
, CoordModeOrigin
);
307 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
308 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
311 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
313 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
319 static void updateDockNumbers(WScreen
* scr
)
323 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
325 ws_numbers
= wmalloc(20);
326 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
327 length
= strlen(ws_numbers
);
329 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
331 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
332 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
334 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
335 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
339 #endif /* WS_INDICATOR */
341 void wAppIconPaint(WAppIcon
* aicon
)
344 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
346 if (aicon
->icon
->owner
)
347 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
351 wIconPaint(aicon
->icon
);
354 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
355 updateDockNumbers(scr
);
357 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
358 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
359 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
360 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
361 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
364 if (wapp
&& wapp
->flags
.hidden
) {
365 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
366 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
367 XCopyArea(dpy
, scr
->dock_dots
->image
,
368 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
370 #endif /* HIDDENDOT */
372 if (aicon
->omnipresent
)
373 drawCorner(aicon
->icon
);
375 XSetClipMask(dpy
, scr
->copy_gc
, None
);
376 if (aicon
->launching
)
377 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
378 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
381 /* Save the application icon, if it's a dockapp then use it with dock = True */
382 void save_appicon(WAppIcon
*aicon
, Bool dock
)
389 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
392 path
= wIconStore(aicon
->icon
);
396 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
400 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
402 /* main_window may not have the full command line; try to find one which does */
403 static void relaunchApplication(WApplication
*wapp
)
406 WWindow
*wlist
, *next
;
408 scr
= wapp
->main_window_desc
->screen_ptr
;
409 wlist
= scr
->focused_window
;
419 if (wlist
->main_window
== wapp
->main_window
) {
420 if (RelaunchWindow(wlist
))
428 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
430 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
432 relaunchApplication(wapp
);
435 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
437 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
439 if (wapp
->flags
.hidden
) {
440 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
441 wUnhideApplication(wapp
, False
, False
);
443 wHideApplication(wapp
);
447 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
449 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
451 wUnhideApplication(wapp
, False
, True
);
454 static void setIconCallback(WMenu
* menu
, WMenuEntry
* entry
)
456 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
461 assert(icon
!= NULL
);
467 scr
= icon
->icon
->core
->screen_ptr
;
471 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
473 if (result
&& !icon
->destroyed
) {
474 if (file
&& *file
== 0) {
478 if (!wIconChangeImageFile(icon
->icon
, file
)) {
479 wMessageDialog(scr
, _("Error"),
480 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
482 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
492 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
494 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
495 WFakeGroupLeader
*fPtr
;
498 char *basename(const char *shortname
);
500 if (!WCHECK_STATE(WSTATE_NORMAL
))
503 WCHANGE_STATE(WSTATE_MODAL
);
505 assert(entry
->clientdata
!= NULL
);
507 shortname
= basename(wapp
->app_icon
->wm_instance
);
509 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
510 _(" will be forcibly closed.\n"
511 "Any unsaved changes will be lost.\n" "Please confirm."));
513 fPtr
= wapp
->main_window_desc
->fake_group
;
515 wretain(wapp
->main_window_desc
);
516 if (wPreferences
.dont_confirm_kill
517 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
518 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
520 WWindow
*wwin
, *twin
;
522 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
525 if (wwin
->fake_group
== fPtr
)
529 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
530 wClientKill(wapp
->main_window_desc
);
533 wrelease(wapp
->main_window_desc
);
535 WCHANGE_STATE(WSTATE_NORMAL
);
538 static WMenu
*createApplicationMenu(WScreen
* scr
)
542 menu
= wMenuCreate(scr
, NULL
, False
);
543 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
544 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
545 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
546 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
547 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
552 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
555 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
558 if (!scr
->icon_menu
) {
559 scr
->icon_menu
= createApplicationMenu(scr
);
560 wfree(scr
->icon_menu
->entries
[1]->text
);
563 menu
= scr
->icon_menu
;
565 if (wapp
->flags
.hidden
)
566 menu
->entries
[1]->text
= _("Unhide");
568 menu
->entries
[1]->text
= _("Hide");
570 menu
->flags
.realized
= 0;
573 x
-= menu
->frame
->core
->width
/ 2;
574 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
575 x
= scr
->scr_width
- menu
->frame
->core
->width
;
580 /* set client data */
581 for (i
= 0; i
< menu
->entry_no
; i
++)
582 menu
->entries
[i
]->clientdata
= wapp
;
584 wMenuMapAt(menu
, x
, y
, False
);
587 /******************************************************************/
589 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
)
591 wAppIconPaint(desc
->parent
);
594 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
596 WAppIcon
*aicon
= desc
->parent
;
598 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
601 assert(aicon
->icon
->owner
!= NULL
);
603 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
605 if (event
->xbutton
.state
& ControlMask
) {
606 relaunchApplication(wapp
);
610 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
611 /* go to the last workspace that the user worked on the app */
612 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
613 wWorkspaceChange(scr
, wapp
->last_workspace
);
615 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
617 if (event
->xbutton
.state
& MOD_MASK
)
618 wHideOtherApplications(aicon
->icon
->owner
);
621 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
623 WAppIcon
*aicon
= desc
->parent
;
624 WIcon
*icon
= aicon
->icon
;
626 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
627 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
630 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
631 WScreen
*scr
= icon
->core
->screen_ptr
;
632 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
633 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
635 int clickButton
= event
->xbutton
.button
;
638 Bool movingSingle
= False
;
641 Bool hasMoved
= False
;
643 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
646 if (IsDoubleClick(scr
, event
)) {
647 /* Middle or right mouse actions were handled on first click */
648 if (event
->xbutton
.button
== Button1
)
649 iconDblClick(desc
, event
);
653 if (event
->xbutton
.button
== Button2
) {
654 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
657 relaunchApplication(wapp
);
662 if (event
->xbutton
.button
== Button3
) {
663 WObjDescriptor
*desc
;
664 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
669 if (event
->xbutton
.send_event
&&
670 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
671 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
672 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
673 wwarning("pointer grab failed for appicon menu");
677 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
679 /* allow drag select of menu */
680 desc
= &scr
->icon_menu
->menu
->descriptor
;
681 event
->xbutton
.send_event
= True
;
682 (*desc
->handle_mousedown
) (desc
, event
);
686 if (event
->xbutton
.state
& MOD_MASK
)
687 wLowerFrame(icon
->core
);
689 wRaiseFrame(icon
->core
);
691 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
692 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
693 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
694 wwarning("pointer grab failed for appicon move");
696 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
699 dockable
= canBeDocked(icon
->owner
);
701 wins
[0] = icon
->core
->window
;
702 wins
[1] = scr
->dock_shadow
;
703 XRestackWindows(dpy
, wins
, 2);
705 if (icon
->pixmap
!= None
)
706 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
708 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
709 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
710 XClearWindow(dpy
, scr
->dock_shadow
);
714 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
715 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
722 /* It means the cursor moved so fast that it entered
723 * something else (if moving slowly, it would have
724 * stayed in the appIcon that is being moved. Ignore
725 * such "spurious" EnterNotifiy's */
731 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
732 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
733 XChangeActivePointerGrab(dpy
, ButtonMotionMask
734 | ButtonReleaseMask
| ButtonPressMask
,
735 wCursor
[WCUR_MOVE
], CurrentTime
);
741 x
= ev
.xmotion
.x_root
- dx
;
742 y
= ev
.xmotion
.y_root
- dy
;
745 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
747 wAppIconMove(aicon
, x
, y
);
750 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
751 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
752 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
754 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
755 scr
->last_dock
->collapsed
= 1;
756 wDockHideIcons(scr
->last_dock
);
759 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
760 scr
->dock
->collapsed
= 0;
761 wDockShowIcons(scr
->dock
);
764 if (scr
->dock
->auto_raise_lower
)
765 wDockRaise(scr
->dock
);
767 scr
->last_dock
= scr
->dock
;
769 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
771 XMapWindow(dpy
, scr
->dock_shadow
);
774 } else if (workspace
->clip
&&
775 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
776 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
777 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
779 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
780 scr
->last_dock
->collapsed
= 1;
781 wDockHideIcons(scr
->last_dock
);
784 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
785 workspace
->clip
->collapsed
= 0;
786 wDockShowIcons(workspace
->clip
);
789 if (workspace
->clip
->auto_raise_lower
)
790 wDockRaise(workspace
->clip
);
792 scr
->last_dock
= workspace
->clip
;
794 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
796 XMapWindow(dpy
, scr
->dock_shadow
);
799 } else if (docking
) {
800 XUnmapWindow(dpy
, scr
->dock_shadow
);
810 if (ev
.xbutton
.button
!= clickButton
)
812 XUngrabPointer(dpy
, CurrentTime
);
817 /* icon is trying to be docked */
818 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
819 XUnmapWindow(dpy
, scr
->dock_shadow
);
820 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
);
821 if (scr
->last_dock
->auto_collapse
)
824 if (workspace
->clip
&&
825 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
826 wDockLower(workspace
->clip
);
829 /* If icon could not be docked, slide it back to the old
831 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
835 /* move back to its place */
836 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
837 wAppIconMove(aicon
, oldX
, oldY
);
839 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
843 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
844 wDockLower(workspace
->clip
);
847 scr
->last_dock
->collapsed
= 1;
848 wDockHideIcons(scr
->last_dock
);
853 XFreePixmap(dpy
, ghost
);
854 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
857 if (wPreferences
.auto_arrange_icons
)
858 wArrangeIcons(scr
, True
);
860 if (wPreferences
.single_click
&& !hasMoved
)
861 iconDblClick(desc
, event
);
869 /* This function save the application icon and store the path in the Dictionary */
870 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
872 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
873 WMPropList
*adict
, *key
, *iconk
;
877 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
878 key
= WMCreatePLString(tmp
);
881 adict
= WMGetFromPLDictionary(dict
, key
);
882 iconk
= WMCreatePLString("Icon");
885 val
= WMGetFromPLDictionary(adict
, iconk
);
887 /* no dictionary for app, so create one */
888 adict
= WMCreatePLDictionary(NULL
, NULL
);
889 WMPutInPLDictionary(dict
, key
, adict
);
890 WMReleasePropList(adict
);
895 val
= WMCreatePLString(iconPath
);
896 WMPutInPLDictionary(adict
, iconk
, val
);
897 WMReleasePropList(val
);
902 WMReleasePropList(key
);
903 WMReleasePropList(iconk
);
905 if (val
&& !wPreferences
.flags
.noupdates
)
906 UpdateDomainFile(WDWindowAttributes
);
909 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
911 WAppIcon
*aicon
= NULL
;
913 aicon
= wDockFindIconForWindow(dock
, main_window
);
915 wDockTrackWindowLaunch(dock
, main_window
);
916 aicon
= wDockFindIconForWindow(dock
, main_window
);
921 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
923 WScreen
*scr
= wwin
->screen_ptr
;
924 wapp
->app_icon
= NULL
;
927 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
929 /* check main dock if we did not find it in last dock */
930 if (!wapp
->app_icon
&& scr
->dock
)
931 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
933 /* finally check clips */
934 if (!wapp
->app_icon
) {
936 for (i
= 0; i
< scr
->workspace_count
; i
++) {
937 WDock
*dock
= scr
->workspaces
[i
]->clip
;
939 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
945 /* If created, then set some flags */
946 if (wapp
->app_icon
) {
947 WWindow
*mainw
= wapp
->main_window_desc
;
949 wapp
->app_icon
->running
= 1;
950 wapp
->app_icon
->icon
->force_paint
= 1;
951 wapp
->app_icon
->icon
->owner
= mainw
;
952 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
953 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
955 wAppIconPaint(wapp
->app_icon
);
956 save_appicon(wapp
->app_icon
, True
);
960 /* Add the appicon to the appiconlist */
961 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
963 appicon
->prev
= NULL
;
964 appicon
->next
= scr
->app_icon_list
;
965 if (scr
->app_icon_list
)
966 scr
->app_icon_list
->prev
= appicon
;
968 scr
->app_icon_list
= appicon
;
971 /* Remove the appicon from the appiconlist */
972 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
974 if (appicon
== scr
->app_icon_list
) {
976 appicon
->next
->prev
= NULL
;
977 scr
->app_icon_list
= appicon
->next
;
980 appicon
->next
->prev
= appicon
->prev
;
982 appicon
->prev
->next
= appicon
->next
;