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
);
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
)
381 WScreen
*scr
= aicon
->icon
->core
->screen_ptr
;
383 if (aicon
->icon
->owner
)
384 wapp
= wApplicationOf(aicon
->icon
->owner
->main_window
);
388 wIconPaint(aicon
->icon
);
391 if (aicon
->docked
&& scr
->dock
&& scr
->dock
== aicon
->dock
&& aicon
->yindex
== 0)
392 updateDockNumbers(scr
);
394 if (scr
->dock_dots
&& aicon
->docked
&& !aicon
->running
&& aicon
->command
!= NULL
) {
395 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
396 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
397 XCopyArea(dpy
, scr
->dock_dots
->image
, aicon
->icon
->core
->window
,
398 scr
->copy_gc
, 0, 0, scr
->dock_dots
->width
, scr
->dock_dots
->height
, 0, 0);
401 if (wapp
&& wapp
->flags
.hidden
) {
402 XSetClipMask(dpy
, scr
->copy_gc
, scr
->dock_dots
->mask
);
403 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
404 XCopyArea(dpy
, scr
->dock_dots
->image
,
405 aicon
->icon
->core
->window
, scr
->copy_gc
, 0, 0, 7, scr
->dock_dots
->height
, 0, 0);
407 #endif /* HIDDENDOT */
409 if (aicon
->omnipresent
)
410 drawCorner(aicon
->icon
);
412 XSetClipMask(dpy
, scr
->copy_gc
, None
);
413 if (aicon
->launching
)
414 XFillRectangle(dpy
, aicon
->icon
->core
->window
, scr
->stipple_gc
,
415 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
418 /* Save the application icon, if it's a dockapp then use it with dock = True */
419 void save_appicon(WAppIcon
*aicon
, Bool dock
)
426 if (dock
&& (!aicon
->docked
|| aicon
->attracted
))
429 path
= wIconStore(aicon
->icon
);
433 wApplicationSaveIconPathFor(path
, aicon
->wm_instance
, aicon
->wm_class
);
437 #define canBeDocked(wwin) ((wwin) && ((wwin)->wm_class||(wwin)->wm_instance))
439 /* main_window may not have the full command line; try to find one which does */
440 static void relaunchApplication(WApplication
*wapp
)
443 WWindow
*wlist
, *next
;
445 scr
= wapp
->main_window_desc
->screen_ptr
;
446 wlist
= scr
->focused_window
;
456 if (wlist
->main_window
== wapp
->main_window
) {
457 if (RelaunchWindow(wlist
))
465 static void relaunchCallback(WMenu
* menu
, WMenuEntry
* entry
)
467 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
469 relaunchApplication(wapp
);
472 static void hideCallback(WMenu
* menu
, WMenuEntry
* entry
)
474 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
476 if (wapp
->flags
.hidden
) {
477 wWorkspaceChange(menu
->menu
->screen_ptr
, wapp
->last_workspace
);
478 wUnhideApplication(wapp
, False
, False
);
480 wHideApplication(wapp
);
484 static void unhideHereCallback(WMenu
* menu
, WMenuEntry
* entry
)
486 WApplication
*wapp
= (WApplication
*) entry
->clientdata
;
488 wUnhideApplication(wapp
, False
, True
);
491 static void setIconCallback(WMenu
*menu
, WMenuEntry
*entry
)
493 WAppIcon
*icon
= ((WApplication
*) entry
->clientdata
)->app_icon
;
498 assert(icon
!= NULL
);
504 scr
= icon
->icon
->core
->screen_ptr
;
508 result
= wIconChooserDialog(scr
, &file
, icon
->wm_instance
, icon
->wm_class
);
510 if (result
&& !icon
->destroyed
) {
511 if (file
&& *file
== 0) {
515 if (!wIconChangeImageFile(icon
->icon
, file
)) {
516 wMessageDialog(scr
, _("Error"),
517 _("Could not open specified icon file"), _("OK"), NULL
, NULL
);
519 wDefaultChangeIcon(scr
, icon
->wm_instance
, icon
->wm_class
, file
);
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
);
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 /* Update the icon images */
992 wIconUpdate(wapp
->app_icon
->icon
);
995 wAppIconPaint(wapp
->app_icon
);
996 save_appicon(wapp
->app_icon
, True
);
1000 /* Add the appicon to the appiconlist */
1001 static void add_to_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1003 appicon
->prev
= NULL
;
1004 appicon
->next
= scr
->app_icon_list
;
1005 if (scr
->app_icon_list
)
1006 scr
->app_icon_list
->prev
= appicon
;
1008 scr
->app_icon_list
= appicon
;
1011 /* Remove the appicon from the appiconlist */
1012 static void remove_from_appicon_list(WScreen
*scr
, WAppIcon
*appicon
)
1014 if (appicon
== scr
->app_icon_list
) {
1016 appicon
->next
->prev
= NULL
;
1017 scr
->app_icon_list
= appicon
->next
;
1020 appicon
->next
->prev
= appicon
->prev
;
1022 appicon
->prev
->next
= appicon
->next
;
1025 appicon
->prev
= NULL
;
1026 appicon
->next
= NULL
;
1029 /* Return the AppIcon associated with a given (Xlib) Window. */
1030 WAppIcon
*wAppIconFor(Window window
)
1032 WObjDescriptor
*desc
;
1037 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1040 if (desc
->parent_type
== WCLASS_APPICON
|| desc
->parent_type
== WCLASS_DOCK_ICON
)
1041 return desc
->parent
;