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
;
63 extern XContext wWinContext
;
65 #define MOD_MASK wPreferences.modifier_mask
67 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
68 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
);
69 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
);
70 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
);
71 static WAppIcon
*wAppIconCreate(WWindow
* leader_win
);
72 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
);
73 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
);
75 /* This function is used if the application is a .app. It checks if it has an icon in it
76 * like for example /usr/local/GNUstep/Applications/WPrefs.app/WPrefs.tiff
78 void wApplicationExtractDirPackIcon(WScreen
* scr
, char *path
, char *wm_instance
, char *wm_class
)
80 char *iconPath
= NULL
;
83 if (strstr(path
, ".app")) {
84 tmp
= wmalloc(strlen(path
) + 16);
86 if (scr
->flags
.supports_tiff
) {
89 if (access(tmp
, R_OK
) == 0)
96 if (access(tmp
, R_OK
) == 0)
104 wApplicationSaveIconPathFor(iconPath
, wm_instance
, wm_class
);
110 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 aicon
->icon
= icon_create_for_dock(scr
, command
, wm_instance
, wm_class
, tile
);
133 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
136 /* will be overriden by dock */
137 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
138 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
139 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
140 aicon
->icon
->core
->descriptor
.parent
= aicon
;
141 AddToStackList(aicon
->icon
->core
);
146 void makeAppIconFor(WApplication
*wapp
)
148 /* If app_icon, work is done, return */
152 /* Create the icon */
153 wapp
->app_icon
= wAppIconCreate(wapp
->main_window_desc
);
154 wIconUpdate(wapp
->app_icon
->icon
);
156 /* Now, paint the icon */
157 if (!WFLAGP(wapp
->main_window_desc
, no_appicon
))
158 paint_app_icon(wapp
);
161 void unpaint_app_icon(WApplication
*wapp
)
167 if (!wapp
|| !wapp
->app_icon
)
170 aicon
= wapp
->app_icon
;
172 /* If the icon is docked, don't continue */
176 scr
= wapp
->main_window_desc
->screen_ptr
;
177 clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
179 if (!clip
|| !aicon
->attracted
|| !clip
->collapsed
)
180 XUnmapWindow(dpy
, aicon
->icon
->core
->window
);
182 /* We want to avoid having it on the list because otherwise
183 * there will be a hole when the icons are arranged with
185 remove_from_appicon_list(scr
, aicon
);
187 if (wPreferences
.auto_arrange_icons
&& !aicon
->attracted
)
188 wArrangeIcons(scr
, True
);
191 void paint_app_icon(WApplication
*wapp
)
194 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
195 WDock
*clip
= scr
->workspaces
[scr
->current_workspace
]->clip
;
197 Bool update_icon
= False
;
199 if (!wapp
|| !wapp
->app_icon
)
202 icon
= wapp
->app_icon
->icon
;
203 wapp
->app_icon
->main_window
= wapp
->main_window
;
205 /* If the icon is docked, don't continue */
206 if (wapp
->app_icon
->docked
)
209 if (clip
&& clip
->attract_icons
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
210 wapp
->app_icon
->attracted
= 1;
211 if (!icon
->shadowed
) {
215 wDockAttachIcon(clip
, wapp
->app_icon
, x
, y
, update_icon
);
217 /* We must know if the icon is painted in the screen,
218 * because if painted, then PlaceIcon will return the next
219 * space on the screen, and the icon will move */
220 if (wapp
->app_icon
->next
== NULL
&& wapp
->app_icon
->prev
== NULL
) {
221 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wapp
->main_window_desc
));
222 wAppIconMove(wapp
->app_icon
, x
, y
);
223 wLowerFrame(icon
->core
);
227 /* If we want appicon (no_appicon is not set) and the icon is not
228 * in the appicon_list, we must add it. Else, we want to avoid
229 * having it on the list */
230 if (!WFLAGP(wapp
->main_window_desc
, no_appicon
) &&
231 wapp
->app_icon
->next
== NULL
&& wapp
->app_icon
->prev
== NULL
)
232 add_to_appicon_list(scr
, wapp
->app_icon
);
234 if (!clip
|| !wapp
->app_icon
->attracted
|| !clip
->collapsed
)
235 XMapWindow(dpy
, icon
->core
->window
);
237 if (wPreferences
.auto_arrange_icons
&& !wapp
->app_icon
->attracted
)
238 wArrangeIcons(scr
, True
);
241 void removeAppIconFor(WApplication
*wapp
)
246 if (wapp
->app_icon
->docked
&& !wapp
->app_icon
->attracted
) {
247 wapp
->app_icon
->running
= 0;
248 /* since we keep it, we don't care if it was attracted or not */
249 wapp
->app_icon
->attracted
= 0;
250 wapp
->app_icon
->icon
->shadowed
= 0;
251 wapp
->app_icon
->main_window
= None
;
252 wapp
->app_icon
->pid
= 0;
253 wapp
->app_icon
->icon
->owner
= NULL
;
254 wapp
->app_icon
->icon
->icon_win
= None
;
255 wAppIconPaint(wapp
->app_icon
, True
);
256 } else if (wapp
->app_icon
->docked
) {
257 wapp
->app_icon
->running
= 0;
258 wDockDetach(wapp
->app_icon
->dock
, wapp
->app_icon
);
260 wAppIconDestroy(wapp
->app_icon
);
263 wapp
->app_icon
= NULL
;
265 if (wPreferences
.auto_arrange_icons
)
266 wArrangeIcons(wapp
->main_window_desc
->screen_ptr
, True
);
269 static WAppIcon
*wAppIconCreate(WWindow
*leader_win
)
273 aicon
= wmalloc(sizeof(WAppIcon
));
280 if (leader_win
->wm_class
)
281 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
283 if (leader_win
->wm_instance
)
284 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
286 aicon
->icon
= icon_create_for_wwindow(leader_win
);
288 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
291 /* will be overriden if docked */
292 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
293 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
294 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
295 aicon
->icon
->core
->descriptor
.parent
= aicon
;
296 AddToStackList(aicon
->icon
->core
);
297 aicon
->icon
->show_title
= 0;
302 void wAppIconDestroy(WAppIcon
* aicon
)
304 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
306 RemoveFromStackList(aicon
->icon
->core
);
307 wIconDestroy(aicon
->icon
);
309 wfree(aicon
->command
);
311 if (aicon
->dnd_command
)
312 wfree(aicon
->dnd_command
);
314 if (aicon
->wm_instance
)
315 wfree(aicon
->wm_instance
);
318 wfree(aicon
->wm_class
);
320 remove_from_appicon_list(scr
, aicon
);
322 aicon
->destroyed
= 1;
326 static void drawCorner(WIcon
* icon
)
328 WScreen
*scr
= icon
->core
->screen_ptr
;
337 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
338 points
, 3, Convex
, CoordModeOrigin
);
339 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
340 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
343 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
345 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
351 static void updateDockNumbers(WScreen
* scr
)
355 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
357 ws_numbers
= wmalloc(20);
358 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
359 length
= strlen(ws_numbers
);
361 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
363 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
364 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
366 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
367 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
371 #endif /* WS_INDICATOR */
373 void wAppIconPaint(WAppIcon
*aicon
, Bool update_icon
)
376 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
378 if (aicon
->icon
->owner
)
379 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
384 wIconUpdate(aicon
->icon
);
386 wIconPaint(aicon
->icon
);
389 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
390 updateDockNumbers(scr
);
392 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
393 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
394 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
395 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
396 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
399 if (wapp
&& wapp
->flags
.hidden
) {
400 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
401 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
402 XCopyArea(dpy
, scr
->dock_dots
->image
,
403 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
405 #endif /* HIDDENDOT */
407 if (aicon
->omnipresent
)
408 drawCorner(aicon
->icon
);
410 XSetClipMask(dpy
, scr
->copy_gc
, None
);
411 if (aicon
->launching
)
412 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
413 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
416 /* Save the application icon, if it's a dockapp then use it with dock = True */
417 void save_appicon(WAppIcon
*aicon
, Bool dock
)
424 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
427 path
= wIconStore(aicon
->icon
);
431 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
435 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
437 /* main_window may not have the full command line; try to find one which does */
438 static void relaunchApplication(WApplication
*wapp
)
441 WWindow
*wlist
, *next
;
443 scr
= wapp
->main_window_desc
->screen_ptr
;
444 wlist
= scr
->focused_window
;
454 if (wlist
->main_window
== wapp
->main_window
) {
455 if (RelaunchWindow(wlist
))
463 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
465 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
467 relaunchApplication(wapp
);
470 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
472 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
474 if (wapp
->flags
.hidden
) {
475 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
476 wUnhideApplication(wapp
, False
, False
);
478 wHideApplication(wapp
);
482 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
484 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
486 wUnhideApplication(wapp
, False
, True
);
489 static void setIconCallback(WMenu
*menu
, WMenuEntry
*entry
)
491 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
496 assert(icon
!= NULL
);
502 scr
= icon
->icon
->core
->screen_ptr
;
506 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
508 if (result
&& !icon
->destroyed
) {
509 if (file
&& *file
== 0) {
513 if (!wIconChangeImageFile(icon
->icon
, file
)) {
514 wMessageDialog(scr
, _("Error"),
515 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
517 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
518 /* The image was updated previously at wIconChangeImageFile,
519 * so we don't need update it here again */
520 wAppIconPaint(icon
, False
);
529 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
531 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
532 WFakeGroupLeader
*fPtr
;
535 char *basename(const char *shortname
);
537 if (!WCHECK_STATE(WSTATE_NORMAL
))
540 WCHANGE_STATE(WSTATE_MODAL
);
542 assert(entry
->clientdata
!= NULL
);
544 shortname
= basename(wapp
->app_icon
->wm_instance
);
546 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
547 _(" will be forcibly closed.\n"
548 "Any unsaved changes will be lost.\n" "Please confirm."));
550 fPtr
= wapp
->main_window_desc
->fake_group
;
552 wretain(wapp
->main_window_desc
);
553 if (wPreferences
.dont_confirm_kill
554 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
555 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
557 WWindow
*wwin
, *twin
;
559 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
562 if (wwin
->fake_group
== fPtr
)
566 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
567 wClientKill(wapp
->main_window_desc
);
570 wrelease(wapp
->main_window_desc
);
572 WCHANGE_STATE(WSTATE_NORMAL
);
575 static WMenu
*createApplicationMenu(WScreen
*scr
)
579 menu
= wMenuCreate(scr
, NULL
, False
);
580 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
581 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
582 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
583 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
584 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
589 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
592 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
595 if (!scr
->icon_menu
) {
596 scr
->icon_menu
= createApplicationMenu(scr
);
597 wfree(scr
->icon_menu
->entries
[1]->text
);
600 menu
= scr
->icon_menu
;
602 if (wapp
->flags
.hidden
)
603 menu
->entries
[1]->text
= _("Unhide");
605 menu
->entries
[1]->text
= _("Hide");
607 menu
->flags
.realized
= 0;
610 x
-= menu
->frame
->core
->width
/ 2;
611 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
612 x
= scr
->scr_width
- menu
->frame
->core
->width
;
617 /* set client data */
618 for (i
= 0; i
< menu
->entry_no
; i
++)
619 menu
->entries
[i
]->clientdata
= wapp
;
621 wMenuMapAt(menu
, x
, y
, False
);
624 /******************************************************************/
626 static void iconExpose(WObjDescriptor
*desc
, XEvent
*event
)
628 wAppIconPaint(desc
->parent
, False
);
631 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
633 WAppIcon
*aicon
= desc
->parent
;
635 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
638 assert(aicon
->icon
->owner
!= NULL
);
640 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
642 if (event
->xbutton
.state
& ControlMask
) {
643 relaunchApplication(wapp
);
647 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
648 /* go to the last workspace that the user worked on the app */
649 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
650 wWorkspaceChange(scr
, wapp
->last_workspace
);
652 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
654 if (event
->xbutton
.state
& MOD_MASK
)
655 wHideOtherApplications(aicon
->icon
->owner
);
658 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
660 WAppIcon
*aicon
= desc
->parent
;
661 WIcon
*icon
= aicon
->icon
;
663 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
664 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
667 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
668 WScreen
*scr
= icon
->core
->screen_ptr
;
669 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
670 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
672 int clickButton
= event
->xbutton
.button
;
675 Bool movingSingle
= False
;
678 Bool hasMoved
= False
;
680 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
683 if (IsDoubleClick(scr
, event
)) {
684 /* Middle or right mouse actions were handled on first click */
685 if (event
->xbutton
.button
== Button1
)
686 iconDblClick(desc
, event
);
690 if (event
->xbutton
.button
== Button2
) {
691 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
694 relaunchApplication(wapp
);
699 if (event
->xbutton
.button
== Button3
) {
700 WObjDescriptor
*desc
;
701 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
706 if (event
->xbutton
.send_event
&&
707 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
708 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
709 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
710 wwarning("pointer grab failed for appicon menu");
714 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
716 /* allow drag select of menu */
717 desc
= &scr
->icon_menu
->menu
->descriptor
;
718 event
->xbutton
.send_event
= True
;
719 (*desc
->handle_mousedown
) (desc
, event
);
723 if (event
->xbutton
.state
& MOD_MASK
)
724 wLowerFrame(icon
->core
);
726 wRaiseFrame(icon
->core
);
728 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
729 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
730 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
731 wwarning("pointer grab failed for appicon move");
733 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
736 dockable
= canBeDocked(icon
->owner
);
738 wins
[0] = icon
->core
->window
;
739 wins
[1] = scr
->dock_shadow
;
740 XRestackWindows(dpy
, wins
, 2);
742 if (icon
->pixmap
!= None
)
743 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
745 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
746 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
747 XClearWindow(dpy
, scr
->dock_shadow
);
751 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
752 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
759 /* It means the cursor moved so fast that it entered
760 * something else (if moving slowly, it would have
761 * stayed in the appIcon that is being moved. Ignore
762 * such "spurious" EnterNotifiy's */
768 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
769 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
770 XChangeActivePointerGrab(dpy
, ButtonMotionMask
771 | ButtonReleaseMask
| ButtonPressMask
,
772 wCursor
[WCUR_MOVE
], CurrentTime
);
778 x
= ev
.xmotion
.x_root
- dx
;
779 y
= ev
.xmotion
.y_root
- dy
;
782 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
784 wAppIconMove(aicon
, x
, y
);
787 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
788 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
789 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
791 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
792 scr
->last_dock
->collapsed
= 1;
793 wDockHideIcons(scr
->last_dock
);
796 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
797 scr
->dock
->collapsed
= 0;
798 wDockShowIcons(scr
->dock
);
801 if (scr
->dock
->auto_raise_lower
)
802 wDockRaise(scr
->dock
);
804 scr
->last_dock
= scr
->dock
;
806 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
808 XMapWindow(dpy
, scr
->dock_shadow
);
811 } else if (workspace
->clip
&&
812 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
813 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
814 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
816 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
817 scr
->last_dock
->collapsed
= 1;
818 wDockHideIcons(scr
->last_dock
);
821 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
822 workspace
->clip
->collapsed
= 0;
823 wDockShowIcons(workspace
->clip
);
826 if (workspace
->clip
->auto_raise_lower
)
827 wDockRaise(workspace
->clip
);
829 scr
->last_dock
= workspace
->clip
;
831 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
833 XMapWindow(dpy
, scr
->dock_shadow
);
836 } else if (docking
) {
837 XUnmapWindow(dpy
, scr
->dock_shadow
);
847 if (ev
.xbutton
.button
!= clickButton
)
849 XUngrabPointer(dpy
, CurrentTime
);
854 /* icon is trying to be docked */
855 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
856 XUnmapWindow(dpy
, scr
->dock_shadow
);
857 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
, False
);
858 if (scr
->last_dock
->auto_collapse
)
861 if (workspace
->clip
&&
862 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
863 wDockLower(workspace
->clip
);
866 /* If icon could not be docked, slide it back to the old
868 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
872 /* move back to its place */
873 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
874 wAppIconMove(aicon
, oldX
, oldY
);
876 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
880 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
881 wDockLower(workspace
->clip
);
884 scr
->last_dock
->collapsed
= 1;
885 wDockHideIcons(scr
->last_dock
);
890 XFreePixmap(dpy
, ghost
);
891 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
894 if (wPreferences
.auto_arrange_icons
)
895 wArrangeIcons(scr
, True
);
897 if (wPreferences
.single_click
&& !hasMoved
)
898 iconDblClick(desc
, event
);
906 /* This function save the application icon and store the path in the Dictionary */
907 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
909 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
910 WMPropList
*adict
, *key
, *iconk
;
914 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
915 key
= WMCreatePLString(tmp
);
918 adict
= WMGetFromPLDictionary(dict
, key
);
919 iconk
= WMCreatePLString("Icon");
922 val
= WMGetFromPLDictionary(adict
, iconk
);
924 /* no dictionary for app, so create one */
925 adict
= WMCreatePLDictionary(NULL
, NULL
);
926 WMPutInPLDictionary(dict
, key
, adict
);
927 WMReleasePropList(adict
);
932 val
= WMCreatePLString(iconPath
);
933 WMPutInPLDictionary(adict
, iconk
, val
);
934 WMReleasePropList(val
);
939 WMReleasePropList(key
);
940 WMReleasePropList(iconk
);
942 if (val
&& !wPreferences
.flags
.noupdates
)
943 UpdateDomainFile(WDWindowAttributes
);
946 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
948 WAppIcon
*aicon
= NULL
;
950 aicon
= wDockFindIconForWindow(dock
, main_window
);
952 wDockTrackWindowLaunch(dock
, main_window
);
953 aicon
= wDockFindIconForWindow(dock
, main_window
);
958 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
960 WScreen
*scr
= wwin
->screen_ptr
;
961 wapp
->app_icon
= NULL
;
964 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
966 /* check main dock if we did not find it in last dock */
967 if (!wapp
->app_icon
&& scr
->dock
)
968 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
970 /* finally check clips */
971 if (!wapp
->app_icon
) {
973 for (i
= 0; i
< scr
->workspace_count
; i
++) {
974 WDock
*dock
= scr
->workspaces
[i
]->clip
;
976 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
982 /* If created, then set some flags */
983 if (wapp
->app_icon
) {
984 WWindow
*mainw
= wapp
->main_window_desc
;
986 wapp
->app_icon
->running
= 1;
987 wapp
->app_icon
->icon
->owner
= mainw
;
988 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
989 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
991 wAppIconPaint(wapp
->app_icon
, True
);
992 save_appicon(wapp
->app_icon
, True
);
996 /* Add the appicon to the appiconlist */
997 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
999 appicon
->prev
= NULL
;
1000 appicon
->next
= scr
->app_icon_list
;
1001 if (scr
->app_icon_list
)
1002 scr
->app_icon_list
->prev
= appicon
;
1004 scr
->app_icon_list
= appicon
;
1007 /* Remove the appicon from the appiconlist */
1008 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1010 if (appicon
== scr
->app_icon_list
) {
1012 appicon
->next
->prev
= NULL
;
1013 scr
->app_icon_list
= appicon
->next
;
1016 appicon
->next
->prev
= appicon
->prev
;
1018 appicon
->prev
->next
= appicon
->next
;
1021 appicon
->prev
= NULL
;
1022 appicon
->next
= NULL
;
1025 /* Return the AppIcon associated with a given (Xlib) Window. */
1026 WAppIcon
*wAppIconFor(Window window
)
1028 WObjDescriptor
*desc
;
1033 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1036 if (desc
->parent_type
== WCLASS_APPICON
|| desc
->parent_type
== WCLASS_DOCK_ICON
)
1037 return desc
->parent
;