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
;
256 /* Update the icon images */
257 wIconUpdate(wapp
->app_icon
->icon
);
260 wAppIconPaint(wapp
->app_icon
, False
);
261 } else if (wapp
->app_icon
->docked
) {
262 wapp
->app_icon
->running
= 0;
263 wDockDetach(wapp
->app_icon
->dock
, wapp
->app_icon
);
265 wAppIconDestroy(wapp
->app_icon
);
268 wapp
->app_icon
= NULL
;
270 if (wPreferences
.auto_arrange_icons
)
271 wArrangeIcons(wapp
->main_window_desc
->screen_ptr
, True
);
274 static WAppIcon
*wAppIconCreate(WWindow
*leader_win
)
278 aicon
= wmalloc(sizeof(WAppIcon
));
285 if (leader_win
->wm_class
)
286 aicon
->wm_class
= wstrdup(leader_win
->wm_class
);
288 if (leader_win
->wm_instance
)
289 aicon
->wm_instance
= wstrdup(leader_win
->wm_instance
);
291 aicon
->icon
= icon_create_for_wwindow(leader_win
);
293 wXDNDMakeAwareness(aicon
->icon
->core
->window
);
296 /* will be overriden if docked */
297 aicon
->icon
->core
->descriptor
.handle_mousedown
= appIconMouseDown
;
298 aicon
->icon
->core
->descriptor
.handle_expose
= iconExpose
;
299 aicon
->icon
->core
->descriptor
.parent_type
= WCLASS_APPICON
;
300 aicon
->icon
->core
->descriptor
.parent
= aicon
;
301 AddToStackList(aicon
->icon
->core
);
302 aicon
->icon
->show_title
= 0;
307 void wAppIconDestroy(WAppIcon
* aicon
)
309 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
311 RemoveFromStackList(aicon
->icon
->core
);
312 wIconDestroy(aicon
->icon
);
314 wfree(aicon
->command
);
316 if (aicon
->dnd_command
)
317 wfree(aicon
->dnd_command
);
319 if (aicon
->wm_instance
)
320 wfree(aicon
->wm_instance
);
323 wfree(aicon
->wm_class
);
325 remove_from_appicon_list(scr
, aicon
);
327 aicon
->destroyed
= 1;
331 static void drawCorner(WIcon
* icon
)
333 WScreen
*scr
= icon
->core
->screen_ptr
;
342 XFillPolygon(dpy
, icon
->core
->window
, scr
->icon_title_texture
->normal_gc
,
343 points
, 3, Convex
, CoordModeOrigin
);
344 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 0, 12);
345 XDrawLine(dpy
, icon
->core
->window
, scr
->icon_title_texture
->light_gc
, 0, 0, 12, 0);
348 void wAppIconMove(WAppIcon
* aicon
, int x
, int y
)
350 XMoveWindow(dpy
, aicon
->icon
->core
->window
, x
, y
);
356 static void updateDockNumbers(WScreen
* scr
)
360 WAppIcon
*dicon
= scr
->dock
->icon_array
[0];
362 ws_numbers
= wmalloc(20);
363 snprintf(ws_numbers
, 20, "%i [ %i ]", scr
->current_workspace
+ 1, ((scr
->current_workspace
/ 10) + 1));
364 length
= strlen(ws_numbers
);
366 XClearArea(dpy
, dicon
->icon
->core
->window
, 2, 2, 50, WMFontHeight(scr
->icon_title_font
) + 1, False
);
368 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->black
,
369 scr
->icon_title_font
, 4, 3, ws_numbers
, length
);
371 WMDrawString(scr
->wmscreen
, dicon
->icon
->core
->window
, scr
->white
,
372 scr
->icon_title_font
, 3, 2, ws_numbers
, length
);
376 #endif /* WS_INDICATOR */
378 void wAppIconPaint(WAppIcon
*aicon
, Bool update_icon
)
381 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
383 if (aicon
->icon
->owner
)
384 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
389 wIconUpdate(aicon
->icon
);
391 wIconPaint(aicon
->icon
);
394 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
395 updateDockNumbers(scr
);
397 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
398 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
399 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
400 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
401 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
404 if (wapp
&& wapp
->flags
.hidden
) {
405 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
406 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
407 XCopyArea(dpy
, scr
->dock_dots
->image
,
408 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
410 #endif /* HIDDENDOT */
412 if (aicon
->omnipresent
)
413 drawCorner(aicon
->icon
);
415 XSetClipMask(dpy
, scr
->copy_gc
, None
);
416 if (aicon
->launching
)
417 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
418 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
421 /* Save the application icon, if it's a dockapp then use it with dock = True */
422 void save_appicon(WAppIcon
*aicon
, Bool dock
)
429 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
432 path
= wIconStore(aicon
->icon
);
436 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
440 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
442 /* main_window may not have the full command line; try to find one which does */
443 static void relaunchApplication(WApplication
*wapp
)
446 WWindow
*wlist
, *next
;
448 scr
= wapp
->main_window_desc
->screen_ptr
;
449 wlist
= scr
->focused_window
;
459 if (wlist
->main_window
== wapp
->main_window
) {
460 if (RelaunchWindow(wlist
))
468 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
470 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
472 relaunchApplication(wapp
);
475 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
477 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
479 if (wapp
->flags
.hidden
) {
480 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
481 wUnhideApplication(wapp
, False
, False
);
483 wHideApplication(wapp
);
487 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
489 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
491 wUnhideApplication(wapp
, False
, True
);
494 static void setIconCallback(WMenu
*menu
, WMenuEntry
*entry
)
496 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
501 assert(icon
!= NULL
);
507 scr
= icon
->icon
->core
->screen_ptr
;
511 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
513 if (result
&& !icon
->destroyed
) {
514 if (file
&& *file
== 0) {
518 if (!wIconChangeImageFile(icon
->icon
, file
)) {
519 wMessageDialog(scr
, _("Error"),
520 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
522 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
523 /* The image was updated previously at wIconChangeImageFile,
524 * so we don't need update it here again */
525 wAppIconPaint(icon
, False
);
534 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
536 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
537 WFakeGroupLeader
*fPtr
;
540 char *basename(const char *shortname
);
542 if (!WCHECK_STATE(WSTATE_NORMAL
))
545 WCHANGE_STATE(WSTATE_MODAL
);
547 assert(entry
->clientdata
!= NULL
);
549 shortname
= basename(wapp
->app_icon
->wm_instance
);
551 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
552 _(" will be forcibly closed.\n"
553 "Any unsaved changes will be lost.\n" "Please confirm."));
555 fPtr
= wapp
->main_window_desc
->fake_group
;
557 wretain(wapp
->main_window_desc
);
558 if (wPreferences
.dont_confirm_kill
559 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
560 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
562 WWindow
*wwin
, *twin
;
564 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
567 if (wwin
->fake_group
== fPtr
)
571 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
572 wClientKill(wapp
->main_window_desc
);
575 wrelease(wapp
->main_window_desc
);
577 WCHANGE_STATE(WSTATE_NORMAL
);
580 static WMenu
*createApplicationMenu(WScreen
*scr
)
584 menu
= wMenuCreate(scr
, NULL
, False
);
585 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
586 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
587 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
588 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
589 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
594 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
597 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
600 if (!scr
->icon_menu
) {
601 scr
->icon_menu
= createApplicationMenu(scr
);
602 wfree(scr
->icon_menu
->entries
[1]->text
);
605 menu
= scr
->icon_menu
;
607 if (wapp
->flags
.hidden
)
608 menu
->entries
[1]->text
= _("Unhide");
610 menu
->entries
[1]->text
= _("Hide");
612 menu
->flags
.realized
= 0;
615 x
-= menu
->frame
->core
->width
/ 2;
616 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
617 x
= scr
->scr_width
- menu
->frame
->core
->width
;
622 /* set client data */
623 for (i
= 0; i
< menu
->entry_no
; i
++)
624 menu
->entries
[i
]->clientdata
= wapp
;
626 wMenuMapAt(menu
, x
, y
, False
);
629 /******************************************************************/
631 static void iconExpose(WObjDescriptor
*desc
, XEvent
*event
)
633 wAppIconPaint(desc
->parent
, False
);
636 static void iconDblClick(WObjDescriptor
*desc
, XEvent
*event
)
638 WAppIcon
*aicon
= desc
->parent
;
640 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
643 assert(aicon
->icon
->owner
!= NULL
);
645 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
647 if (event
->xbutton
.state
& ControlMask
) {
648 relaunchApplication(wapp
);
652 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
653 /* go to the last workspace that the user worked on the app */
654 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
655 wWorkspaceChange(scr
, wapp
->last_workspace
);
657 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
659 if (event
->xbutton
.state
& MOD_MASK
)
660 wHideOtherApplications(aicon
->icon
->owner
);
663 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
665 WAppIcon
*aicon
= desc
->parent
;
666 WIcon
*icon
= aicon
->icon
;
668 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
669 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
672 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
673 WScreen
*scr
= icon
->core
->screen_ptr
;
674 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
675 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
677 int clickButton
= event
->xbutton
.button
;
680 Bool movingSingle
= False
;
683 Bool hasMoved
= False
;
685 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
688 if (IsDoubleClick(scr
, event
)) {
689 /* Middle or right mouse actions were handled on first click */
690 if (event
->xbutton
.button
== Button1
)
691 iconDblClick(desc
, event
);
695 if (event
->xbutton
.button
== Button2
) {
696 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
699 relaunchApplication(wapp
);
704 if (event
->xbutton
.button
== Button3
) {
705 WObjDescriptor
*desc
;
706 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
711 if (event
->xbutton
.send_event
&&
712 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
713 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
714 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
715 wwarning("pointer grab failed for appicon menu");
719 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
721 /* allow drag select of menu */
722 desc
= &scr
->icon_menu
->menu
->descriptor
;
723 event
->xbutton
.send_event
= True
;
724 (*desc
->handle_mousedown
) (desc
, event
);
728 if (event
->xbutton
.state
& MOD_MASK
)
729 wLowerFrame(icon
->core
);
731 wRaiseFrame(icon
->core
);
733 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
734 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
735 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
736 wwarning("pointer grab failed for appicon move");
738 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
741 dockable
= canBeDocked(icon
->owner
);
743 wins
[0] = icon
->core
->window
;
744 wins
[1] = scr
->dock_shadow
;
745 XRestackWindows(dpy
, wins
, 2);
747 if (icon
->pixmap
!= None
)
748 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
750 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
751 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
752 XClearWindow(dpy
, scr
->dock_shadow
);
756 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
757 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
764 /* It means the cursor moved so fast that it entered
765 * something else (if moving slowly, it would have
766 * stayed in the appIcon that is being moved. Ignore
767 * such "spurious" EnterNotifiy's */
773 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
774 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
775 XChangeActivePointerGrab(dpy
, ButtonMotionMask
776 | ButtonReleaseMask
| ButtonPressMask
,
777 wCursor
[WCUR_MOVE
], CurrentTime
);
783 x
= ev
.xmotion
.x_root
- dx
;
784 y
= ev
.xmotion
.y_root
- dy
;
787 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
789 wAppIconMove(aicon
, x
, y
);
792 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
793 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
794 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
796 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
797 scr
->last_dock
->collapsed
= 1;
798 wDockHideIcons(scr
->last_dock
);
801 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
802 scr
->dock
->collapsed
= 0;
803 wDockShowIcons(scr
->dock
);
806 if (scr
->dock
->auto_raise_lower
)
807 wDockRaise(scr
->dock
);
809 scr
->last_dock
= scr
->dock
;
811 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
813 XMapWindow(dpy
, scr
->dock_shadow
);
816 } else if (workspace
->clip
&&
817 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
818 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
819 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
821 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
822 scr
->last_dock
->collapsed
= 1;
823 wDockHideIcons(scr
->last_dock
);
826 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
827 workspace
->clip
->collapsed
= 0;
828 wDockShowIcons(workspace
->clip
);
831 if (workspace
->clip
->auto_raise_lower
)
832 wDockRaise(workspace
->clip
);
834 scr
->last_dock
= workspace
->clip
;
836 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
838 XMapWindow(dpy
, scr
->dock_shadow
);
841 } else if (docking
) {
842 XUnmapWindow(dpy
, scr
->dock_shadow
);
852 if (ev
.xbutton
.button
!= clickButton
)
854 XUngrabPointer(dpy
, CurrentTime
);
859 /* icon is trying to be docked */
860 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
861 XUnmapWindow(dpy
, scr
->dock_shadow
);
862 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
, False
);
863 if (scr
->last_dock
->auto_collapse
)
866 if (workspace
->clip
&&
867 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
868 wDockLower(workspace
->clip
);
871 /* If icon could not be docked, slide it back to the old
873 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
877 /* move back to its place */
878 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
879 wAppIconMove(aicon
, oldX
, oldY
);
881 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
885 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
886 wDockLower(workspace
->clip
);
889 scr
->last_dock
->collapsed
= 1;
890 wDockHideIcons(scr
->last_dock
);
895 XFreePixmap(dpy
, ghost
);
896 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
899 if (wPreferences
.auto_arrange_icons
)
900 wArrangeIcons(scr
, True
);
902 if (wPreferences
.single_click
&& !hasMoved
)
903 iconDblClick(desc
, event
);
911 /* This function save the application icon and store the path in the Dictionary */
912 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
914 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
915 WMPropList
*adict
, *key
, *iconk
;
919 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
920 key
= WMCreatePLString(tmp
);
923 adict
= WMGetFromPLDictionary(dict
, key
);
924 iconk
= WMCreatePLString("Icon");
927 val
= WMGetFromPLDictionary(adict
, iconk
);
929 /* no dictionary for app, so create one */
930 adict
= WMCreatePLDictionary(NULL
, NULL
);
931 WMPutInPLDictionary(dict
, key
, adict
);
932 WMReleasePropList(adict
);
937 val
= WMCreatePLString(iconPath
);
938 WMPutInPLDictionary(adict
, iconk
, val
);
939 WMReleasePropList(val
);
944 WMReleasePropList(key
);
945 WMReleasePropList(iconk
);
947 if (val
&& !wPreferences
.flags
.noupdates
)
948 UpdateDomainFile(WDWindowAttributes
);
951 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
953 WAppIcon
*aicon
= NULL
;
955 aicon
= wDockFindIconForWindow(dock
, main_window
);
957 wDockTrackWindowLaunch(dock
, main_window
);
958 aicon
= wDockFindIconForWindow(dock
, main_window
);
963 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
965 WScreen
*scr
= wwin
->screen_ptr
;
966 wapp
->app_icon
= NULL
;
969 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
971 /* check main dock if we did not find it in last dock */
972 if (!wapp
->app_icon
&& scr
->dock
)
973 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
975 /* finally check clips */
976 if (!wapp
->app_icon
) {
978 for (i
= 0; i
< scr
->workspace_count
; i
++) {
979 WDock
*dock
= scr
->workspaces
[i
]->clip
;
981 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
987 /* If created, then set some flags */
988 if (wapp
->app_icon
) {
989 WWindow
*mainw
= wapp
->main_window_desc
;
991 wapp
->app_icon
->running
= 1;
992 wapp
->app_icon
->icon
->owner
= mainw
;
993 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
994 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
996 /* Update the icon images */
997 wIconUpdate(wapp
->app_icon
->icon
);
1000 wAppIconPaint(wapp
->app_icon
, False
);
1001 save_appicon(wapp
->app_icon
, True
);
1005 /* Add the appicon to the appiconlist */
1006 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1008 appicon
->prev
= NULL
;
1009 appicon
->next
= scr
->app_icon_list
;
1010 if (scr
->app_icon_list
)
1011 scr
->app_icon_list
->prev
= appicon
;
1013 scr
->app_icon_list
= appicon
;
1016 /* Remove the appicon from the appiconlist */
1017 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1019 if (appicon
== scr
->app_icon_list
) {
1021 appicon
->next
->prev
= NULL
;
1022 scr
->app_icon_list
= appicon
->next
;
1025 appicon
->next
->prev
= appicon
->prev
;
1027 appicon
->prev
->next
= appicon
->next
;
1030 appicon
->prev
= NULL
;
1031 appicon
->next
= NULL
;
1034 /* Return the AppIcon associated with a given (Xlib) Window. */
1035 WAppIcon
*wAppIconFor(Window window
)
1037 WObjDescriptor
*desc
;
1042 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1045 if (desc
->parent_type
== WCLASS_APPICON
|| desc
->parent_type
== WCLASS_DOCK_ICON
)
1046 return desc
->parent
;