wAppIconPaint argument removed
[wmaker-crm.git] / src / application.c
blob7c52fa0d05eba38c405b6454e4f454985b579a7e
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 Dan Pascu
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #include <X11/Xlib.h>
24 #include <string.h>
26 #include "WindowMaker.h"
27 #include "menu.h"
28 #include "window.h"
29 #ifdef USER_MENU
30 #include "usermenu.h"
31 #endif /* USER_MENU */
32 #include "appicon.h"
33 #include "application.h"
34 #include "appmenu.h"
35 #include "properties.h"
36 #include "workspace.h"
37 #include "dock.h"
39 /******** Global variables ********/
41 extern XContext wAppWinContext;
42 extern XContext wWinContext;
44 /******** Local variables ********/
46 static WWindow *makeMainWindow(WScreen * scr, Window window)
48 WWindow *wwin;
49 XWindowAttributes attr;
51 if (!XGetWindowAttributes(dpy, window, &attr))
52 return NULL;
54 wwin = wWindowCreate();
55 wwin->screen_ptr = scr;
56 wwin->client_win = window;
57 wwin->main_window = window;
58 wwin->wm_hints = XGetWMHints(dpy, window);
60 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
62 wDefaultFillAttributes(wwin->wm_instance, wwin->wm_class, &wwin->user_flags,
63 &wwin->defined_user_flags, True);
65 XSelectInput(dpy, window, attr.your_event_mask | PropertyChangeMask | StructureNotifyMask);
66 return wwin;
69 WApplication *wApplicationOf(Window window)
71 WApplication *wapp;
73 if (window == None)
74 return NULL;
75 if (XFindContext(dpy, window, wAppWinContext, (XPointer *) & wapp) != XCSUCCESS)
76 return NULL;
77 return wapp;
80 WApplication *wApplicationCreate(WWindow * wwin)
82 WScreen *scr = wwin->screen_ptr;
83 Window main_window = wwin->main_window;
84 WApplication *wapp;
85 WWindow *leader;
87 if (main_window == None || main_window == scr->root_win)
88 return NULL;
91 Window root;
92 int foo;
93 unsigned int bar;
94 /* check if the window is valid */
95 if (!XGetGeometry(dpy, main_window, &root, &foo, &foo, &bar, &bar, &bar, &bar))
96 return NULL;
99 wapp = wApplicationOf(main_window);
100 if (wapp) {
101 wapp->refcount++;
102 if (wapp->app_icon && wapp->app_icon->docked &&
103 wapp->app_icon->relaunching && wapp->main_window_desc->fake_group)
104 wDockFinishLaunch(wapp->app_icon->dock, wapp->app_icon);
106 return wapp;
109 wapp = wmalloc(sizeof(WApplication));
111 wapp->refcount = 1;
112 wapp->last_focused = NULL;
113 wapp->urgent_bounce_timer = NULL;
115 wapp->last_workspace = 0;
117 wapp->main_window = main_window;
118 wapp->main_window_desc = makeMainWindow(scr, main_window);
119 if (!wapp->main_window_desc) {
120 wfree(wapp);
121 return NULL;
124 wapp->main_window_desc->fake_group = wwin->fake_group;
125 wapp->main_window_desc->net_icon_image = RRetainImage(wwin->net_icon_image);
127 leader = wWindowFor(main_window);
128 if (leader)
129 leader->main_window = main_window;
131 wapp->menu = wAppMenuGet(scr, main_window);
132 #ifdef USER_MENU
133 if (!wapp->menu)
134 wapp->menu = wUserMenuGet(scr, wapp->main_window_desc);
135 #endif
137 /* Set application wide attributes from the leader */
138 wapp->flags.hidden = WFLAGP(wapp->main_window_desc, start_hidden);
139 wapp->flags.emulated = WFLAGP(wapp->main_window_desc, emulate_appicon);
141 /* application descriptor */
142 XSaveContext(dpy, main_window, wAppWinContext, (XPointer) wapp);
144 /* First try to create an icon from the dock or clip */
145 create_appicon_from_dock(wwin, wapp, main_window);
148 * In case it was not found in the dock, make it from scratch.
149 * Note: makeAppIconFor() returns early if wapp->app_icon exists
151 makeAppIconFor(wapp);
153 /* Save the app_icon in a file */
154 save_appicon(wapp->app_icon, False);
156 return wapp;
159 void wApplicationDestroy(WApplication * wapp)
161 WWindow *wwin;
162 WScreen *scr;
164 if (!wapp)
165 return;
167 wapp->refcount--;
168 if (wapp->refcount > 0)
169 return;
171 if (wapp->urgent_bounce_timer) {
172 WMDeleteTimerHandler(wapp->urgent_bounce_timer);
173 wapp->urgent_bounce_timer = NULL;
175 if (wapp->flags.bouncing) {
176 /* event.c:handleDestroyNotify forced this destroy
177 and thereby overlooked the bounce callback */
178 wapp->refcount = 1;
179 return;
182 scr = wapp->main_window_desc->screen_ptr;
184 if (wapp == scr->wapp_list) {
185 if (wapp->next)
186 wapp->next->prev = NULL;
187 scr->wapp_list = wapp->next;
188 } else {
189 if (wapp->next)
190 wapp->next->prev = wapp->prev;
191 if (wapp->prev)
192 wapp->prev->next = wapp->next;
195 XDeleteContext(dpy, wapp->main_window, wAppWinContext);
196 wAppMenuDestroy(wapp->menu);
197 wApplicationDeactivate(wapp);
199 /* Remove application icon */
200 removeAppIconFor(wapp);
202 wwin = wWindowFor(wapp->main_window_desc->client_win);
204 wWindowDestroy(wapp->main_window_desc);
205 if (wwin) {
206 /* undelete client window context that was deleted in
207 * wWindowDestroy */
208 XSaveContext(dpy, wwin->client_win, wWinContext, (XPointer) & wwin->client_descriptor);
210 wfree(wapp);
213 void wApplicationActivate(WApplication *wapp)
215 #ifdef NEWAPPICON
216 if (wapp->app_icon) {
217 wIconSetHighlited(wapp->app_icon->icon, True);
218 wAppIconPaint(wapp->app_icon);
220 #endif
223 void wApplicationDeactivate(WApplication *wapp)
225 #ifdef NEWAPPICON
226 if (wapp->app_icon) {
227 wIconSetHighlited(wapp->app_icon->icon, False);
228 wAppIconPaint(wapp->app_icon);
230 #endif