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
, NULL
);
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 (wPreferences
.highlight_active_app
)
247 wIconSetHighlited(wapp
->app_icon
->icon
, False
);
248 if (wapp
->app_icon
->docked
&& !wapp
->app_icon
->attracted
) {
249 wapp
->app_icon
->running
= 0;
250 /* since we keep it, we don't care if it was attracted or not */
251 wapp
->app_icon
->attracted
= 0;
252 wapp
->app_icon
->icon
->shadowed
= 0;
253 wapp
->app_icon
->main_window
= None
;
254 wapp
->app_icon
->pid
= 0;
255 wapp
->app_icon
->icon
->owner
= NULL
;
256 wapp
->app_icon
->icon
->icon_win
= None
;
258 /* Update the icon images */
259 wIconUpdate(wapp
->app_icon
->icon
, NULL
);
262 wAppIconPaint(wapp
->app_icon
);
263 } else if (wapp
->app_icon
->docked
) {
264 wapp
->app_icon
->running
= 0;
265 wDockDetach(wapp
->app_icon
->dock
, wapp
->app_icon
);
267 wAppIconDestroy(wapp
->app_icon
);
270 wapp
->app_icon
= NULL
;
272 if (wPreferences
.auto_arrange_icons
)
273 wArrangeIcons(wapp
->main_window_desc
->screen_ptr
, True
);
276 static WAppIcon
*wAppIconCreate(WWindow
*leader_win
)
280 aicon
= wmalloc(sizeof(WAppIcon
));
287 if (leader_win
->wm_class
)
288 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
290 if (leader_win
->wm_instance
)
291 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
293 aicon
->icon
= icon_create_for_wwindow(leader_win
);
295 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
298 /* will be overriden if docked */
299 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
300 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
301 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
302 aicon
->icon
->core
->descriptor
.parent
= aicon
;
303 AddToStackList(aicon
->icon
->core
);
304 aicon
->icon
->show_title
= 0;
309 void wAppIconDestroy(WAppIcon
* aicon
)
311 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
313 RemoveFromStackList(aicon
->icon
->core
);
314 wIconDestroy(aicon
->icon
);
316 wfree(aicon
->command
);
318 if (aicon
->dnd_command
)
319 wfree(aicon
->dnd_command
);
321 if (aicon
->wm_instance
)
322 wfree(aicon
->wm_instance
);
325 wfree(aicon
->wm_class
);
327 remove_from_appicon_list(scr
, aicon
);
329 aicon
->destroyed
= 1;
333 static void drawCorner(WIcon
* icon
)
335 WScreen
*scr
= icon
->core
->screen_ptr
;
344 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
345 points
, 3, Convex
, CoordModeOrigin
);
346 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
347 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
350 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
352 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
358 static void updateDockNumbers(WScreen
* scr
)
362 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
364 ws_numbers
= wmalloc(20);
365 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
366 length
= strlen(ws_numbers
);
368 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
370 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
371 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
373 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
374 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
378 #endif /* WS_INDICATOR */
380 void wAppIconPaint(WAppIcon
*aicon
)
383 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
385 if (aicon
->icon
->owner
)
386 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
390 wIconPaint(aicon
->icon
);
393 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
394 updateDockNumbers(scr
);
396 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
397 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
398 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
399 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
400 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
403 if (wapp
&& wapp
->flags
.hidden
) {
404 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
405 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
406 XCopyArea(dpy
, scr
->dock_dots
->image
,
407 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
409 #endif /* HIDDENDOT */
411 if (aicon
->omnipresent
)
412 drawCorner(aicon
->icon
);
414 XSetClipMask(dpy
, scr
->copy_gc
, None
);
415 if (aicon
->launching
)
416 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
417 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
420 /* Save the application icon, if it's a dockapp then use it with dock = True */
421 void save_appicon(WAppIcon
*aicon
, Bool dock
)
428 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
431 path
= wIconStore(aicon
->icon
);
435 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
439 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
441 /* main_window may not have the full command line; try to find one which does */
442 static void relaunchApplication(WApplication
*wapp
)
445 WWindow
*wlist
, *next
;
447 scr
= wapp
->main_window_desc
->screen_ptr
;
448 wlist
= scr
->focused_window
;
458 if (wlist
->main_window
== wapp
->main_window
) {
459 if (RelaunchWindow(wlist
))
467 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
469 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
471 relaunchApplication(wapp
);
474 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
476 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
478 if (wapp
->flags
.hidden
) {
479 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
480 wUnhideApplication(wapp
, False
, False
);
482 wHideApplication(wapp
);
486 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
488 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
490 wUnhideApplication(wapp
, False
, True
);
493 static void setIconCallback(WMenu
*menu
, WMenuEntry
*entry
)
495 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
500 assert(icon
!= NULL
);
506 scr
= icon
->icon
->core
->screen_ptr
;
510 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
512 if (result
&& !icon
->destroyed
) {
513 if (file
&& *file
== 0) {
517 if (!wIconChangeImageFile(icon
->icon
, file
)) {
518 wMessageDialog(scr
, _("Error"),
519 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
521 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
531 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
533 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
534 WFakeGroupLeader
*fPtr
;
537 char *basename(const char *shortname
);
539 if (!WCHECK_STATE(WSTATE_NORMAL
))
542 WCHANGE_STATE(WSTATE_MODAL
);
544 assert(entry
->clientdata
!= NULL
);
546 shortname
= basename(wapp
->app_icon
->wm_instance
);
548 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
549 _(" will be forcibly closed.\n"
550 "Any unsaved changes will be lost.\n" "Please confirm."));
552 fPtr
= wapp
->main_window_desc
->fake_group
;
554 wretain(wapp
->main_window_desc
);
555 if (wPreferences
.dont_confirm_kill
556 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
557 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
559 WWindow
*wwin
, *twin
;
561 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
564 if (wwin
->fake_group
== fPtr
)
568 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
569 wClientKill(wapp
->main_window_desc
);
572 wrelease(wapp
->main_window_desc
);
574 WCHANGE_STATE(WSTATE_NORMAL
);
577 static WMenu
*createApplicationMenu(WScreen
*scr
)
581 menu
= wMenuCreate(scr
, NULL
, False
);
582 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
583 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
584 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
585 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
586 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
591 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
594 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
597 if (!scr
->icon_menu
) {
598 scr
->icon_menu
= createApplicationMenu(scr
);
599 wfree(scr
->icon_menu
->entries
[1]->text
);
602 menu
= scr
->icon_menu
;
604 if (wapp
->flags
.hidden
)
605 menu
->entries
[1]->text
= _("Unhide");
607 menu
->entries
[1]->text
= _("Hide");
609 menu
->flags
.realized
= 0;
612 x
-= menu
->frame
->core
->width
/ 2;
613 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
614 x
= scr
->scr_width
- menu
->frame
->core
->width
;
619 /* set client data */
620 for (i
= 0; i
< menu
->entry_no
; i
++)
621 menu
->entries
[i
]->clientdata
= wapp
;
623 wMenuMapAt(menu
, x
, y
, False
);
626 /******************************************************************/
628 static void iconExpose(WObjDescriptor
*desc
, XEvent
*event
)
630 wAppIconPaint(desc
->parent
);
633 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
635 WAppIcon
*aicon
= desc
->parent
;
637 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
640 assert(aicon
->icon
->owner
!= NULL
);
642 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
644 if (event
->xbutton
.state
& ControlMask
) {
645 relaunchApplication(wapp
);
649 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
650 /* go to the last workspace that the user worked on the app */
651 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
652 wWorkspaceChange(scr
, wapp
->last_workspace
);
654 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
656 if (event
->xbutton
.state
& MOD_MASK
)
657 wHideOtherApplications(aicon
->icon
->owner
);
660 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
662 WAppIcon
*aicon
= desc
->parent
;
663 WIcon
*icon
= aicon
->icon
;
665 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
666 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
669 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
670 WScreen
*scr
= icon
->core
->screen_ptr
;
671 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
672 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
674 int clickButton
= event
->xbutton
.button
;
677 Bool movingSingle
= False
;
680 Bool hasMoved
= False
;
682 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
685 if (IsDoubleClick(scr
, event
)) {
686 /* Middle or right mouse actions were handled on first click */
687 if (event
->xbutton
.button
== Button1
)
688 iconDblClick(desc
, event
);
692 if (event
->xbutton
.button
== Button2
) {
693 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
696 relaunchApplication(wapp
);
701 if (event
->xbutton
.button
== Button3
) {
702 WObjDescriptor
*desc
;
703 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
708 if (event
->xbutton
.send_event
&&
709 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
710 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
711 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
712 wwarning("pointer grab failed for appicon menu");
716 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
718 /* allow drag select of menu */
719 desc
= &scr
->icon_menu
->menu
->descriptor
;
720 event
->xbutton
.send_event
= True
;
721 (*desc
->handle_mousedown
) (desc
, event
);
725 if (event
->xbutton
.state
& MOD_MASK
)
726 wLowerFrame(icon
->core
);
728 wRaiseFrame(icon
->core
);
730 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
731 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
732 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
733 wwarning("pointer grab failed for appicon move");
735 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
738 dockable
= canBeDocked(icon
->owner
);
740 wins
[0] = icon
->core
->window
;
741 wins
[1] = scr
->dock_shadow
;
742 XRestackWindows(dpy
, wins
, 2);
744 if (icon
->pixmap
!= None
)
745 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
747 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
748 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
749 XClearWindow(dpy
, scr
->dock_shadow
);
753 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
754 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
761 /* It means the cursor moved so fast that it entered
762 * something else (if moving slowly, it would have
763 * stayed in the appIcon that is being moved. Ignore
764 * such "spurious" EnterNotifiy's */
770 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
771 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
772 XChangeActivePointerGrab(dpy
, ButtonMotionMask
773 | ButtonReleaseMask
| ButtonPressMask
,
774 wCursor
[WCUR_MOVE
], CurrentTime
);
780 x
= ev
.xmotion
.x_root
- dx
;
781 y
= ev
.xmotion
.y_root
- dy
;
784 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
786 wAppIconMove(aicon
, x
, y
);
789 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
790 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
791 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
793 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
794 scr
->last_dock
->collapsed
= 1;
795 wDockHideIcons(scr
->last_dock
);
798 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
799 scr
->dock
->collapsed
= 0;
800 wDockShowIcons(scr
->dock
);
803 if (scr
->dock
->auto_raise_lower
)
804 wDockRaise(scr
->dock
);
806 scr
->last_dock
= scr
->dock
;
808 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
810 XMapWindow(dpy
, scr
->dock_shadow
);
813 } else if (workspace
->clip
&&
814 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
815 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
816 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
818 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
819 scr
->last_dock
->collapsed
= 1;
820 wDockHideIcons(scr
->last_dock
);
823 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
824 workspace
->clip
->collapsed
= 0;
825 wDockShowIcons(workspace
->clip
);
828 if (workspace
->clip
->auto_raise_lower
)
829 wDockRaise(workspace
->clip
);
831 scr
->last_dock
= workspace
->clip
;
833 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
835 XMapWindow(dpy
, scr
->dock_shadow
);
838 } else if (docking
) {
839 XUnmapWindow(dpy
, scr
->dock_shadow
);
849 if (ev
.xbutton
.button
!= clickButton
)
851 XUngrabPointer(dpy
, CurrentTime
);
856 /* icon is trying to be docked */
857 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
858 XUnmapWindow(dpy
, scr
->dock_shadow
);
859 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
, False
);
860 if (scr
->last_dock
->auto_collapse
)
863 if (workspace
->clip
&&
864 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
865 wDockLower(workspace
->clip
);
868 /* If icon could not be docked, slide it back to the old
870 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
874 /* move back to its place */
875 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
876 wAppIconMove(aicon
, oldX
, oldY
);
878 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
882 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
883 wDockLower(workspace
->clip
);
886 scr
->last_dock
->collapsed
= 1;
887 wDockHideIcons(scr
->last_dock
);
892 XFreePixmap(dpy
, ghost
);
893 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
896 if (wPreferences
.auto_arrange_icons
)
897 wArrangeIcons(scr
, True
);
899 if (wPreferences
.single_click
&& !hasMoved
)
900 iconDblClick(desc
, event
);
908 /* This function save the application icon and store the path in the Dictionary */
909 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
911 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
912 WMPropList
*adict
, *key
, *iconk
;
916 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
917 key
= WMCreatePLString(tmp
);
920 adict
= WMGetFromPLDictionary(dict
, key
);
921 iconk
= WMCreatePLString("Icon");
924 val
= WMGetFromPLDictionary(adict
, iconk
);
926 /* no dictionary for app, so create one */
927 adict
= WMCreatePLDictionary(NULL
, NULL
);
928 WMPutInPLDictionary(dict
, key
, adict
);
929 WMReleasePropList(adict
);
934 val
= WMCreatePLString(iconPath
);
935 WMPutInPLDictionary(adict
, iconk
, val
);
936 WMReleasePropList(val
);
941 WMReleasePropList(key
);
942 WMReleasePropList(iconk
);
944 if (val
&& !wPreferences
.flags
.noupdates
)
945 UpdateDomainFile(WDWindowAttributes
);
948 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
950 WAppIcon
*aicon
= NULL
;
952 aicon
= wDockFindIconForWindow(dock
, main_window
);
954 wDockTrackWindowLaunch(dock
, main_window
);
955 aicon
= wDockFindIconForWindow(dock
, main_window
);
960 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
962 WScreen
*scr
= wwin
->screen_ptr
;
963 wapp
->app_icon
= NULL
;
966 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
968 /* check main dock if we did not find it in last dock */
969 if (!wapp
->app_icon
&& scr
->dock
)
970 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
972 /* finally check clips */
973 if (!wapp
->app_icon
) {
975 for (i
= 0; i
< scr
->workspace_count
; i
++) {
976 WDock
*dock
= scr
->workspaces
[i
]->clip
;
978 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
984 /* If created, then set some flags */
985 if (wapp
->app_icon
) {
986 WWindow
*mainw
= wapp
->main_window_desc
;
988 wapp
->app_icon
->running
= 1;
989 wapp
->app_icon
->icon
->owner
= mainw
;
990 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
991 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
993 /* Update the icon images */
994 wIconUpdate(wapp
->app_icon
->icon
, NULL
);
997 wAppIconPaint(wapp
->app_icon
);
998 save_appicon(wapp
->app_icon
, True
);
1002 /* Add the appicon to the appiconlist */
1003 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1005 appicon
->prev
= NULL
;
1006 appicon
->next
= scr
->app_icon_list
;
1007 if (scr
->app_icon_list
)
1008 scr
->app_icon_list
->prev
= appicon
;
1010 scr
->app_icon_list
= appicon
;
1013 /* Remove the appicon from the appiconlist */
1014 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1016 if (appicon
== scr
->app_icon_list
) {
1018 appicon
->next
->prev
= NULL
;
1019 scr
->app_icon_list
= appicon
->next
;
1022 appicon
->next
->prev
= appicon
->prev
;
1024 appicon
->prev
->next
= appicon
->next
;
1027 appicon
->prev
= NULL
;
1028 appicon
->next
= NULL
;
1031 /* Return the AppIcon associated with a given (Xlib) Window. */
1032 WAppIcon
*wAppIconFor(Window window
)
1034 WObjDescriptor
*desc
;
1039 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1042 if (desc
->parent_type
== WCLASS_APPICON
|| desc
->parent_type
== WCLASS_DOCK_ICON
)
1043 return desc
->parent
;