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
;
198 if (!wapp
|| !wapp
->app_icon
)
201 icon
= wapp
->app_icon
->icon
;
202 wapp
->app_icon
->main_window
= wapp
->main_window
;
204 /* If the icon is docked, don't continue */
205 if (wapp
->app_icon
->docked
)
208 if (clip
&& clip
->attract_icons
&& wDockFindFreeSlot(clip
, &x
, &y
)) {
209 wapp
->app_icon
->attracted
= 1;
210 if (!icon
->shadowed
) {
212 icon
->force_paint
= 1;
214 wDockAttachIcon(clip
, wapp
->app_icon
, x
, y
);
216 /* We must know if the icon is painted in the screen,
217 * because if painted, then PlaceIcon will return the next
218 * space on the screen, and the icon will move */
219 if (wapp
->app_icon
->next
== NULL
&& wapp
->app_icon
->prev
== NULL
) {
220 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wapp
->main_window_desc
));
221 wAppIconMove(wapp
->app_icon
, x
, y
);
222 wLowerFrame(icon
->core
);
226 /* If we want appicon (no_appicon is not set) and the icon is not
227 * in the appicon_list, we must add it. Else, we want to avoid
228 * having it on the list */
229 if (!WFLAGP(wapp
->main_window_desc
, no_appicon
) &&
230 wapp
->app_icon
->next
== NULL
&& wapp
->app_icon
->prev
== NULL
)
231 add_to_appicon_list(scr
, wapp
->app_icon
);
233 if (!clip
|| !wapp
->app_icon
->attracted
|| !clip
->collapsed
)
234 XMapWindow(dpy
, icon
->core
->window
);
236 if (wPreferences
.auto_arrange_icons
&& !wapp
->app_icon
->attracted
)
237 wArrangeIcons(scr
, True
);
240 void removeAppIconFor(WApplication
* wapp
)
245 if (wapp
->app_icon
->docked
&& !wapp
->app_icon
->attracted
) {
246 wapp
->app_icon
->running
= 0;
247 /* since we keep it, we don't care if it was attracted or not */
248 wapp
->app_icon
->attracted
= 0;
249 wapp
->app_icon
->icon
->shadowed
= 0;
250 wapp
->app_icon
->main_window
= None
;
251 wapp
->app_icon
->pid
= 0;
252 wapp
->app_icon
->icon
->owner
= NULL
;
253 wapp
->app_icon
->icon
->icon_win
= None
;
254 wapp
->app_icon
->icon
->force_paint
= 1;
255 wAppIconPaint(wapp
->app_icon
);
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
)
376 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
378 if (aicon
->icon
->owner
)
379 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
383 wIconPaint(aicon
->icon
);
386 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
387 updateDockNumbers(scr
);
389 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
390 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
391 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
392 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
393 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
396 if (wapp
&& wapp
->flags
.hidden
) {
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
,
400 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
402 #endif /* HIDDENDOT */
404 if (aicon
->omnipresent
)
405 drawCorner(aicon
->icon
);
407 XSetClipMask(dpy
, scr
->copy_gc
, None
);
408 if (aicon
->launching
)
409 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
410 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
413 /* Save the application icon, if it's a dockapp then use it with dock = True */
414 void save_appicon(WAppIcon
*aicon
, Bool dock
)
421 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
424 path
= wIconStore(aicon
->icon
);
428 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
432 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
434 /* main_window may not have the full command line; try to find one which does */
435 static void relaunchApplication(WApplication
*wapp
)
438 WWindow
*wlist
, *next
;
440 scr
= wapp
->main_window_desc
->screen_ptr
;
441 wlist
= scr
->focused_window
;
451 if (wlist
->main_window
== wapp
->main_window
) {
452 if (RelaunchWindow(wlist
))
460 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
462 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
464 relaunchApplication(wapp
);
467 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
469 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
471 if (wapp
->flags
.hidden
) {
472 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
473 wUnhideApplication(wapp
, False
, False
);
475 wHideApplication(wapp
);
479 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
481 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
483 wUnhideApplication(wapp
, False
, True
);
486 static void setIconCallback(WMenu
* menu
, WMenuEntry
* entry
)
488 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
493 assert(icon
!= NULL
);
499 scr
= icon
->icon
->core
->screen_ptr
;
503 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
505 if (result
&& !icon
->destroyed
) {
506 if (file
&& *file
== 0) {
510 if (!wIconChangeImageFile(icon
->icon
, file
)) {
511 wMessageDialog(scr
, _("Error"),
512 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
514 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
524 static void killCallback(WMenu
* menu
, WMenuEntry
* entry
)
526 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
527 WFakeGroupLeader
*fPtr
;
530 char *basename(const char *shortname
);
532 if (!WCHECK_STATE(WSTATE_NORMAL
))
535 WCHANGE_STATE(WSTATE_MODAL
);
537 assert(entry
->clientdata
!= NULL
);
539 shortname
= basename(wapp
->app_icon
->wm_instance
);
541 buffer
= wstrconcat(wapp
->app_icon
? shortname
: NULL
,
542 _(" will be forcibly closed.\n"
543 "Any unsaved changes will be lost.\n" "Please confirm."));
545 fPtr
= wapp
->main_window_desc
->fake_group
;
547 wretain(wapp
->main_window_desc
);
548 if (wPreferences
.dont_confirm_kill
549 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
550 buffer
, _("Yes"), _("No"), NULL
) == WAPRDefault
) {
552 WWindow
*wwin
, *twin
;
554 wwin
= wapp
->main_window_desc
->screen_ptr
->focused_window
;
557 if (wwin
->fake_group
== fPtr
)
561 } else if (!wapp
->main_window_desc
->flags
.destroyed
) {
562 wClientKill(wapp
->main_window_desc
);
565 wrelease(wapp
->main_window_desc
);
567 WCHANGE_STATE(WSTATE_NORMAL
);
570 static WMenu
*createApplicationMenu(WScreen
* scr
)
574 menu
= wMenuCreate(scr
, NULL
, False
);
575 wMenuAddCallback(menu
, _("Launch"), relaunchCallback
, NULL
);
576 wMenuAddCallback(menu
, _("Unhide Here"), unhideHereCallback
, NULL
);
577 wMenuAddCallback(menu
, _("Hide"), hideCallback
, NULL
);
578 wMenuAddCallback(menu
, _("Set Icon..."), setIconCallback
, NULL
);
579 wMenuAddCallback(menu
, _("Kill"), killCallback
, NULL
);
584 static void openApplicationMenu(WApplication
* wapp
, int x
, int y
)
587 WScreen
*scr
= wapp
->main_window_desc
->screen_ptr
;
590 if (!scr
->icon_menu
) {
591 scr
->icon_menu
= createApplicationMenu(scr
);
592 wfree(scr
->icon_menu
->entries
[1]->text
);
595 menu
= scr
->icon_menu
;
597 if (wapp
->flags
.hidden
)
598 menu
->entries
[1]->text
= _("Unhide");
600 menu
->entries
[1]->text
= _("Hide");
602 menu
->flags
.realized
= 0;
605 x
-= menu
->frame
->core
->width
/ 2;
606 if (x
+ menu
->frame
->core
->width
> scr
->scr_width
)
607 x
= scr
->scr_width
- menu
->frame
->core
->width
;
612 /* set client data */
613 for (i
= 0; i
< menu
->entry_no
; i
++)
614 menu
->entries
[i
]->clientdata
= wapp
;
616 wMenuMapAt(menu
, x
, y
, False
);
619 /******************************************************************/
621 static void iconExpose(WObjDescriptor
* desc
, XEvent
* event
)
623 wAppIconPaint(desc
->parent
);
626 static void iconDblClick(WObjDescriptor
* desc
, XEvent
* event
)
628 WAppIcon
*aicon
= desc
->parent
;
630 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
633 assert(aicon
->icon
->owner
!= NULL
);
635 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
637 if (event
->xbutton
.state
& ControlMask
) {
638 relaunchApplication(wapp
);
642 unhideHere
= (event
->xbutton
.state
& ShiftMask
);
643 /* go to the last workspace that the user worked on the app */
644 if (!unhideHere
&& wapp
->last_workspace
!= scr
->current_workspace
)
645 wWorkspaceChange(scr
, wapp
->last_workspace
);
647 wUnhideApplication(wapp
, event
->xbutton
.button
== Button2
, unhideHere
);
649 if (event
->xbutton
.state
& MOD_MASK
)
650 wHideOtherApplications(aicon
->icon
->owner
);
653 void appIconMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
655 WAppIcon
*aicon
= desc
->parent
;
656 WIcon
*icon
= aicon
->icon
;
658 int x
= aicon
->x_pos
, y
= aicon
->y_pos
;
659 int dx
= event
->xbutton
.x
, dy
= event
->xbutton
.y
;
662 int superfluous
= wPreferences
.superfluous
; /* we catch it to avoid problems */
663 WScreen
*scr
= icon
->core
->screen_ptr
;
664 WWorkspace
*workspace
= scr
->workspaces
[scr
->current_workspace
];
665 int shad_x
= 0, shad_y
= 0, docking
= 0, dockable
, collapsed
= 0;
667 int clickButton
= event
->xbutton
.button
;
670 Bool movingSingle
= False
;
673 Bool hasMoved
= False
;
675 if (aicon
->editing
|| WCHECK_STATE(WSTATE_MODAL
))
678 if (IsDoubleClick(scr
, event
)) {
679 /* Middle or right mouse actions were handled on first click */
680 if (event
->xbutton
.button
== Button1
)
681 iconDblClick(desc
, event
);
685 if (event
->xbutton
.button
== Button2
) {
686 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
689 relaunchApplication(wapp
);
694 if (event
->xbutton
.button
== Button3
) {
695 WObjDescriptor
*desc
;
696 WApplication
*wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
701 if (event
->xbutton
.send_event
&&
702 XGrabPointer(dpy
, aicon
->icon
->core
->window
, True
, ButtonMotionMask
703 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
704 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
705 wwarning("pointer grab failed for appicon menu");
709 openApplicationMenu(wapp
, event
->xbutton
.x_root
, event
->xbutton
.y_root
);
711 /* allow drag select of menu */
712 desc
= &scr
->icon_menu
->menu
->descriptor
;
713 event
->xbutton
.send_event
= True
;
714 (*desc
->handle_mousedown
) (desc
, event
);
718 if (event
->xbutton
.state
& MOD_MASK
)
719 wLowerFrame(icon
->core
);
721 wRaiseFrame(icon
->core
);
723 if (XGrabPointer(dpy
, icon
->core
->window
, True
, ButtonMotionMask
724 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
725 GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
726 wwarning("pointer grab failed for appicon move");
728 if (wPreferences
.flags
.nodock
&& wPreferences
.flags
.noclip
)
731 dockable
= canBeDocked(icon
->owner
);
733 wins
[0] = icon
->core
->window
;
734 wins
[1] = scr
->dock_shadow
;
735 XRestackWindows(dpy
, wins
, 2);
737 if (icon
->pixmap
!= None
)
738 ghost
= MakeGhostIcon(scr
, icon
->pixmap
);
740 ghost
= MakeGhostIcon(scr
, icon
->core
->window
);
741 XSetWindowBackgroundPixmap(dpy
, scr
->dock_shadow
, ghost
);
742 XClearWindow(dpy
, scr
->dock_shadow
);
746 WMMaskEvent(dpy
, PointerMotionMask
| ButtonReleaseMask
| ButtonPressMask
747 | ButtonMotionMask
| ExposureMask
| EnterWindowMask
, &ev
);
754 /* It means the cursor moved so fast that it entered
755 * something else (if moving slowly, it would have
756 * stayed in the appIcon that is being moved. Ignore
757 * such "spurious" EnterNotifiy's */
763 if (abs(dx
- ev
.xmotion
.x
) >= MOVE_THRESHOLD
764 || abs(dy
- ev
.xmotion
.y
) >= MOVE_THRESHOLD
) {
765 XChangeActivePointerGrab(dpy
, ButtonMotionMask
766 | ButtonReleaseMask
| ButtonPressMask
,
767 wCursor
[WCUR_MOVE
], CurrentTime
);
773 x
= ev
.xmotion
.x_root
- dx
;
774 y
= ev
.xmotion
.y_root
- dy
;
777 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
779 wAppIconMove(aicon
, x
, y
);
782 if (scr
->dock
&& wDockSnapIcon(scr
->dock
, aicon
, x
, y
, &ix
, &iy
, False
)) {
783 shad_x
= scr
->dock
->x_pos
+ ix
* wPreferences
.icon_size
;
784 shad_y
= scr
->dock
->y_pos
+ iy
* wPreferences
.icon_size
;
786 if (scr
->last_dock
!= scr
->dock
&& collapsed
) {
787 scr
->last_dock
->collapsed
= 1;
788 wDockHideIcons(scr
->last_dock
);
791 if (!collapsed
&& (collapsed
= scr
->dock
->collapsed
)) {
792 scr
->dock
->collapsed
= 0;
793 wDockShowIcons(scr
->dock
);
796 if (scr
->dock
->auto_raise_lower
)
797 wDockRaise(scr
->dock
);
799 scr
->last_dock
= scr
->dock
;
801 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
803 XMapWindow(dpy
, scr
->dock_shadow
);
806 } else if (workspace
->clip
&&
807 wDockSnapIcon(workspace
->clip
, aicon
, x
, y
, &ix
, &iy
, False
)) {
808 shad_x
= workspace
->clip
->x_pos
+ ix
* wPreferences
.icon_size
;
809 shad_y
= workspace
->clip
->y_pos
+ iy
* wPreferences
.icon_size
;
811 if (scr
->last_dock
!= workspace
->clip
&& collapsed
) {
812 scr
->last_dock
->collapsed
= 1;
813 wDockHideIcons(scr
->last_dock
);
816 if (!collapsed
&& (collapsed
= workspace
->clip
->collapsed
)) {
817 workspace
->clip
->collapsed
= 0;
818 wDockShowIcons(workspace
->clip
);
821 if (workspace
->clip
->auto_raise_lower
)
822 wDockRaise(workspace
->clip
);
824 scr
->last_dock
= workspace
->clip
;
826 XMoveWindow(dpy
, scr
->dock_shadow
, shad_x
, shad_y
);
828 XMapWindow(dpy
, scr
->dock_shadow
);
831 } else if (docking
) {
832 XUnmapWindow(dpy
, scr
->dock_shadow
);
842 if (ev
.xbutton
.button
!= clickButton
)
844 XUngrabPointer(dpy
, CurrentTime
);
849 /* icon is trying to be docked */
850 SlideWindow(icon
->core
->window
, x
, y
, shad_x
, shad_y
);
851 XUnmapWindow(dpy
, scr
->dock_shadow
);
852 docked
= wDockAttachIcon(scr
->last_dock
, aicon
, ix
, iy
);
853 if (scr
->last_dock
->auto_collapse
)
856 if (workspace
->clip
&&
857 workspace
->clip
!= scr
->last_dock
&& workspace
->clip
->auto_raise_lower
)
858 wDockLower(workspace
->clip
);
861 /* If icon could not be docked, slide it back to the old
863 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
867 /* move back to its place */
868 SlideWindow(icon
->core
->window
, x
, y
, oldX
, oldY
);
869 wAppIconMove(aicon
, oldX
, oldY
);
871 XMoveWindow(dpy
, icon
->core
->window
, x
, y
);
875 if (workspace
->clip
&& workspace
->clip
->auto_raise_lower
)
876 wDockLower(workspace
->clip
);
879 scr
->last_dock
->collapsed
= 1;
880 wDockHideIcons(scr
->last_dock
);
885 XFreePixmap(dpy
, ghost
);
886 XSetWindowBackground(dpy
, scr
->dock_shadow
, scr
->white_pixel
);
889 if (wPreferences
.auto_arrange_icons
)
890 wArrangeIcons(scr
, True
);
892 if (wPreferences
.single_click
&& !hasMoved
)
893 iconDblClick(desc
, event
);
901 /* This function save the application icon and store the path in the Dictionary */
902 static void wApplicationSaveIconPathFor(char *iconPath
, char *wm_instance
, char *wm_class
)
904 WMPropList
*dict
= WDWindowAttributes
->dictionary
;
905 WMPropList
*adict
, *key
, *iconk
;
909 tmp
= get_name_for_instance_class(wm_instance
, wm_class
);
910 key
= WMCreatePLString(tmp
);
913 adict
= WMGetFromPLDictionary(dict
, key
);
914 iconk
= WMCreatePLString("Icon");
917 val
= WMGetFromPLDictionary(adict
, iconk
);
919 /* no dictionary for app, so create one */
920 adict
= WMCreatePLDictionary(NULL
, NULL
);
921 WMPutInPLDictionary(dict
, key
, adict
);
922 WMReleasePropList(adict
);
927 val
= WMCreatePLString(iconPath
);
928 WMPutInPLDictionary(adict
, iconk
, val
);
929 WMReleasePropList(val
);
934 WMReleasePropList(key
);
935 WMReleasePropList(iconk
);
937 if (val
&& !wPreferences
.flags
.noupdates
)
938 UpdateDomainFile(WDWindowAttributes
);
941 static WAppIcon
*findDockIconFor(WDock
*dock
, Window main_window
)
943 WAppIcon
*aicon
= NULL
;
945 aicon
= wDockFindIconForWindow(dock
, main_window
);
947 wDockTrackWindowLaunch(dock
, main_window
);
948 aicon
= wDockFindIconForWindow(dock
, main_window
);
953 void create_appicon_from_dock(WWindow
*wwin
, WApplication
*wapp
, Window main_window
)
955 WScreen
*scr
= wwin
->screen_ptr
;
956 wapp
->app_icon
= NULL
;
959 wapp
->app_icon
= findDockIconFor(scr
->last_dock
, main_window
);
961 /* check main dock if we did not find it in last dock */
962 if (!wapp
->app_icon
&& scr
->dock
)
963 wapp
->app_icon
= findDockIconFor(scr
->dock
, main_window
);
965 /* finally check clips */
966 if (!wapp
->app_icon
) {
968 for (i
= 0; i
< scr
->workspace_count
; i
++) {
969 WDock
*dock
= scr
->workspaces
[i
]->clip
;
971 wapp
->app_icon
= findDockIconFor(dock
, main_window
);
977 /* If created, then set some flags */
978 if (wapp
->app_icon
) {
979 WWindow
*mainw
= wapp
->main_window_desc
;
981 wapp
->app_icon
->running
= 1;
982 wapp
->app_icon
->icon
->force_paint
= 1;
983 wapp
->app_icon
->icon
->owner
= mainw
;
984 if (mainw
->wm_hints
&& (mainw
->wm_hints
->flags
& IconWindowHint
))
985 wapp
->app_icon
->icon
->icon_win
= mainw
->wm_hints
->icon_window
;
987 wAppIconPaint(wapp
->app_icon
);
988 save_appicon(wapp
->app_icon
, True
);
992 /* Add the appicon to the appiconlist */
993 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
995 appicon
->prev
= NULL
;
996 appicon
->next
= scr
->app_icon_list
;
997 if (scr
->app_icon_list
)
998 scr
->app_icon_list
->prev
= appicon
;
1000 scr
->app_icon_list
= appicon
;
1003 /* Remove the appicon from the appiconlist */
1004 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1006 if (appicon
== scr
->app_icon_list
) {
1008 appicon
->next
->prev
= NULL
;
1009 scr
->app_icon_list
= appicon
->next
;
1012 appicon
->next
->prev
= appicon
->prev
;
1014 appicon
->prev
->next
= appicon
->next
;
1017 appicon
->prev
= NULL
;
1018 appicon
->next
= NULL
;
1021 /* Return the AppIcon associated with a given (Xlib) Window. */
1022 WAppIcon
*wAppIconFor(Window window
)
1024 WObjDescriptor
*desc
;
1029 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1032 if (desc
->parent_type
== WCLASS_APPICON
|| desc
->parent_type
== WCLASS_DOCK_ICON
)
1033 return desc
->parent
;