diff options
author | fluxgen <fluxgen> | 2002-09-07 20:32:44 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-09-07 20:32:44 (GMT) |
commit | e9cd9e763d85940d4fbf770537fcde64d202c2f6 (patch) | |
tree | 4105fc5c5a8c6e2280a275d24a8ff01719242770 /src/Gnome.cc | |
parent | 5ee0f8d309418fea649ae1d488ea94b3ed8c2d8c (diff) | |
download | fluxbox_pavel-e9cd9e763d85940d4fbf770537fcde64d202c2f6.zip fluxbox_pavel-e9cd9e763d85940d4fbf770537fcde64d202c2f6.tar.bz2 |
first
Diffstat (limited to 'src/Gnome.cc')
-rw-r--r-- | src/Gnome.cc | 321 |
1 files changed, 321 insertions, 0 deletions
diff --git a/src/Gnome.cc b/src/Gnome.cc new file mode 100644 index 0000000..9a5d9cb --- /dev/null +++ b/src/Gnome.cc | |||
@@ -0,0 +1,321 @@ | |||
1 | // Gnome.cc for fluxbox | ||
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen@fluxbox.org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: Gnome.cc,v 1.1 2002/09/07 20:32:44 fluxgen Exp $ | ||
23 | |||
24 | #include "Gnome.hh" | ||
25 | #include "Window.hh" | ||
26 | #include "Screen.hh" | ||
27 | |||
28 | #include <iostream> | ||
29 | using namespace std; | ||
30 | |||
31 | Gnome::Gnome() { | ||
32 | createAtoms(); | ||
33 | } | ||
34 | |||
35 | Gnome::~Gnome() { | ||
36 | // destroy gnome windows | ||
37 | while (!m_gnomewindows.empty()) { | ||
38 | XDestroyWindow(BaseDisplay::getXDisplay(), m_gnomewindows.back()); | ||
39 | m_gnomewindows.pop_back(); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void Gnome::initForScreen(const BScreen &screen) { | ||
44 | Display *disp = BaseDisplay::getXDisplay(); | ||
45 | // create the GNOME window | ||
46 | Window gnome_win = XCreateSimpleWindow(disp, | ||
47 | screen.getRootWindow(), 0, 0, 5, 5, 0, 0, 0); | ||
48 | // supported WM check | ||
49 | XChangeProperty(disp, screen.getRootWindow(), | ||
50 | m_gnome_wm_supporting_wm_check, | ||
51 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &gnome_win, 1); | ||
52 | |||
53 | XChangeProperty(disp, gnome_win, | ||
54 | m_gnome_wm_supporting_wm_check, | ||
55 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &gnome_win, 1); | ||
56 | |||
57 | Atom gnomeatomlist[] = { | ||
58 | m_gnome_wm_supporting_wm_check, | ||
59 | m_gnome_wm_win_workspace_names, | ||
60 | m_gnome_wm_win_client_list, | ||
61 | m_gnome_wm_win_state, | ||
62 | m_gnome_wm_win_hints | ||
63 | // m_gnome_wm_win_layer not supported yet | ||
64 | }; | ||
65 | |||
66 | //list atoms that we support | ||
67 | XChangeProperty(disp, screen.getRootWindow(), | ||
68 | m_gnome_wm_prot, XA_ATOM, 32, PropModeReplace, | ||
69 | (unsigned char *)gnomeatomlist, (sizeof gnomeatomlist)/sizeof gnomeatomlist[0]); | ||
70 | |||
71 | m_gnomewindows.push_back(gnome_win); | ||
72 | |||
73 | updateClientList(screen); | ||
74 | updateWorkspaceNames(screen); | ||
75 | updateWorkspaceCount(screen); | ||
76 | updateCurrentWorkspace(screen); | ||
77 | |||
78 | } | ||
79 | |||
80 | void Gnome::updateClientList(const BScreen &screen) { | ||
81 | size_t num=0; | ||
82 | |||
83 | BScreen::Workspaces::const_iterator workspace_it = screen.getWorkspacesList().begin(); | ||
84 | BScreen::Workspaces::const_iterator workspace_it_end = screen.getWorkspacesList().end(); | ||
85 | for (; workspace_it != workspace_it_end; ++workspace_it) { | ||
86 | num += (*workspace_it)->getWindowList().size(); | ||
87 | } | ||
88 | //int num = getCurrentWorkspace()->getWindowList().size(); | ||
89 | |||
90 | Window *wl = new (nothrow) Window[num]; | ||
91 | if (wl == 0) { | ||
92 | cerr<<"Fatal: Out of memory, can't allocate for gnome client list"<<endl; | ||
93 | return; | ||
94 | } | ||
95 | //start the iterator from begining | ||
96 | workspace_it = screen.getWorkspacesList().begin(); | ||
97 | int win=0; | ||
98 | for (; workspace_it != workspace_it_end; ++workspace_it) { | ||
99 | |||
100 | // Fill in array of window ID's | ||
101 | Workspace::Windows::const_iterator it = (*workspace_it)->getWindowList().begin(); | ||
102 | Workspace::Windows::const_iterator it_end = (*workspace_it)->getWindowList().end(); | ||
103 | for (; it != it_end; ++it) { | ||
104 | // TODO! | ||
105 | //check if the window don't want to be visible in the list | ||
106 | //if (! ( (*it)->getGnomeHints() & WIN_STATE_HIDDEN) ) { | ||
107 | wl[win++] = (*it)->getClientWindow(); | ||
108 | //} | ||
109 | } | ||
110 | } | ||
111 | //number of windows to show in client list | ||
112 | num = win; | ||
113 | XChangeProperty(BaseDisplay::getXDisplay(), | ||
114 | screen.getRootWindow(), | ||
115 | m_gnome_wm_win_client_list, | ||
116 | XA_CARDINAL, 32, | ||
117 | PropModeReplace, (unsigned char *)wl, num); | ||
118 | |||
119 | delete wl; | ||
120 | } | ||
121 | |||
122 | void Gnome::updateWorkspaceNames(const BScreen &screen) { | ||
123 | XTextProperty text; | ||
124 | int number_of_desks = screen.getWorkspaceNames().size(); | ||
125 | |||
126 | char s[1024]; | ||
127 | char *names[number_of_desks]; | ||
128 | |||
129 | for (int i = 0; i < number_of_desks; i++) { | ||
130 | sprintf(s, "Desktop %i", i); | ||
131 | names[i] = new char[strlen(s) + 1]; | ||
132 | strcpy(names[i], s); | ||
133 | } | ||
134 | |||
135 | if (XStringListToTextProperty(names, number_of_desks, &text)) { | ||
136 | XSetTextProperty(BaseDisplay::getXDisplay(), screen.getRootWindow(), | ||
137 | &text, m_gnome_wm_win_workspace_names); | ||
138 | XFree(text.value); | ||
139 | } | ||
140 | |||
141 | for (int i = 0; i < number_of_desks; i++) | ||
142 | delete [] names[i]; | ||
143 | } | ||
144 | |||
145 | void Gnome::updateCurrentWorkspace(const BScreen &screen) { | ||
146 | int workspace = screen.getCurrentWorkspaceID(); | ||
147 | XChangeProperty(BaseDisplay::getXDisplay(), | ||
148 | screen.getRootWindow(), | ||
149 | m_gnome_wm_win_workspace, XA_CARDINAL, 32, PropModeReplace, | ||
150 | (unsigned char *)&workspace, 1); | ||
151 | |||
152 | updateClientList(screen); // make sure the client list is updated too | ||
153 | } | ||
154 | |||
155 | void Gnome::updateWorkspaceCount(const BScreen &screen) { | ||
156 | int numworkspaces = screen.getCount(); | ||
157 | XChangeProperty(BaseDisplay::getXDisplay(), screen.getRootWindow(), | ||
158 | m_gnome_wm_win_workspace_count, XA_CARDINAL, 32, PropModeReplace, | ||
159 | (unsigned char *)&numworkspaces, 1); | ||
160 | } | ||
161 | |||
162 | void Gnome::updateState(FluxboxWindow *win) { | ||
163 | //translate to gnome win state | ||
164 | int state=0; | ||
165 | if (win->isStuck()) | ||
166 | state |= WIN_STATE_STICKY; | ||
167 | if (win->isIconic()) | ||
168 | state |= WIN_STATE_MINIMIZED; | ||
169 | if (win->isShaded()) | ||
170 | state |= WIN_STATE_SHADED; | ||
171 | |||
172 | XChangeProperty(BaseDisplay::getXDisplay(), win->getClientWindow(), | ||
173 | m_gnome_wm_win_state, | ||
174 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&state, 1); | ||
175 | } | ||
176 | |||
177 | void Gnome::updateHints(FluxboxWindow *win) { | ||
178 | //TODO | ||
179 | |||
180 | } | ||
181 | |||
182 | bool Gnome::checkClientMessage(const XClientMessageEvent &ce, BScreen *screen, FluxboxWindow *win) { | ||
183 | if (ce.message_type == m_gnome_wm_win_workspace) { | ||
184 | #ifdef DEBUG | ||
185 | cerr<<__FILE__<<"("<<__LINE__<<"): Got workspace atom="<<ce.data.l[0]<<endl; | ||
186 | #endif//!DEBUG | ||
187 | if ( win !=0 && // the message sent to client window? | ||
188 | win->getScreen() && ce.data.l[0] >= 0 && | ||
189 | ce.data.l[0] < (signed)win->getScreen()->getCount()) { | ||
190 | win->getScreen()->changeWorkspaceID(ce.data.l[0]); | ||
191 | |||
192 | } else if (screen!=0 && //the message sent to root window? | ||
193 | ce.data.l[0] >= 0 && | ||
194 | ce.data.l[0] < (signed)screen->getCount()) | ||
195 | screen->changeWorkspaceID(ce.data.l[0]); | ||
196 | return true; | ||
197 | } else if (win == 0) | ||
198 | return false; | ||
199 | |||
200 | |||
201 | if (ce.message_type == m_gnome_wm_win_state) { | ||
202 | #ifdef DEBUG | ||
203 | cerr<<__FILE__<<"("<<__LINE__<<"): _WIN_STATE"<<endl; | ||
204 | #endif // DEBUG | ||
205 | |||
206 | #ifdef DEBUG | ||
207 | cerr<<__FILE__<<"("<<__LINE__<<"): Mask of members to change:"<< | ||
208 | hex<<ce.data.l[0]<<dec<<endl; // mask_of_members_to_change | ||
209 | cerr<<"New members:"<<ce.data.l[1]<<endl; | ||
210 | #endif // DEBUG | ||
211 | |||
212 | //get new states | ||
213 | int flag = ce.data.l[0] & ce.data.l[1]; | ||
214 | //don't update this when when we set new state | ||
215 | disableUpdate(); | ||
216 | // convert to Fluxbox state | ||
217 | setState(win, flag); | ||
218 | // enable update of atom states | ||
219 | enableUpdate(); | ||
220 | |||
221 | } else if (ce.message_type == m_gnome_wm_win_hints) { | ||
222 | #ifdef DEBUG | ||
223 | cerr<<__FILE__<<"("<<__LINE__<<"): _WIN_HINTS"<<endl; | ||
224 | #endif // DEBUG | ||
225 | |||
226 | } else | ||
227 | return false; //the gnome atom wasn't found or not supported | ||
228 | |||
229 | return true; // we handled the atom | ||
230 | } | ||
231 | |||
232 | void Gnome::setState(FluxboxWindow *win, int state) { | ||
233 | #ifdef DEBUG | ||
234 | cerr<<"Gnome: state=0x"<<hex<<state<<dec<<endl; | ||
235 | #endif // DEBUG | ||
236 | |||
237 | if (state & WIN_STATE_STICKY) { | ||
238 | #ifdef DEBUG | ||
239 | cerr<<"Gnome state: Sticky"<<endl; | ||
240 | #endif // DEBUG | ||
241 | if (!win->isStuck()) | ||
242 | win->stick(); | ||
243 | } else if (win->isStuck()) | ||
244 | win->stick(); | ||
245 | |||
246 | if (state & WIN_STATE_MINIMIZED) { | ||
247 | #ifdef DEBUG | ||
248 | cerr<<"Gnome state: Minimized"<<endl; | ||
249 | #endif // DEBUG | ||
250 | if (win->isIconic()) | ||
251 | win->iconify(); | ||
252 | } else if (win->isIconic()) | ||
253 | win->deiconify(true, true); | ||
254 | |||
255 | if (state & WIN_STATE_SHADED) { | ||
256 | #ifdef DEBUG | ||
257 | cerr<<"Gnome state: Shade"<<endl; | ||
258 | #endif // DEBUG | ||
259 | if (!win->isShaded()) | ||
260 | win->shade(); | ||
261 | } else if (win->isShaded()) | ||
262 | win->shade(); | ||
263 | |||
264 | /* TODO | ||
265 | if (state & WIN_STATE_MAXIMIZED_VERT) | ||
266 | cerr<<"Maximize Vert"<<endl; | ||
267 | if (state & WIN_STATE_MAXIMIZED_HORIZ) | ||
268 | cerr<<"Maximize Horiz"<<endl; | ||
269 | if (state & WIN_STATE_HIDDEN) | ||
270 | cerr<<"Hidden"<<endl; | ||
271 | if (state & WIN_STATE_HID_WORKSPACE) | ||
272 | cerr<<"HID Workspace"<<endl; | ||
273 | if (state & WIN_STATE_HID_TRANSIENT) | ||
274 | cerr<<"HID Transient"<<endl; | ||
275 | if (state & WIN_STATE_FIXED_POSITION) | ||
276 | cerr<<"Fixed Position"<<endl; | ||
277 | if (state & WIN_STATE_ARRANGE_IGNORE) | ||
278 | cerr<<"Arrange Ignore"<<endl; | ||
279 | */ | ||
280 | } | ||
281 | |||
282 | void Gnome::setLayer(GnomeLayer layer) { | ||
283 | FluxboxWindow::WinLayer winlayer; | ||
284 | |||
285 | switch (layer) { | ||
286 | case WIN_LAYER_DESKTOP: | ||
287 | winlayer = FluxboxWindow::LAYER_BOTTOM; | ||
288 | break; | ||
289 | case WIN_LAYER_BELOW: | ||
290 | winlayer = FluxboxWindow::LAYER_BELOW; | ||
291 | break; | ||
292 | case WIN_LAYER_NORMAL: | ||
293 | winlayer = FluxboxWindow::LAYER_NORMAL; | ||
294 | break; | ||
295 | case WIN_LAYER_ONTOP: | ||
296 | case WIN_LAYER_DOCK: | ||
297 | case WIN_LAYER_ABOVE_DOCK: | ||
298 | case WIN_LAYER_MENU: | ||
299 | winlayer = FluxboxWindow::LAYER_TOP; | ||
300 | break; | ||
301 | default: | ||
302 | winlayer = FluxboxWindow::LAYER_NORMAL; | ||
303 | break; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | void Gnome::createAtoms() { | ||
308 | Display *disp = BaseDisplay::getXDisplay(); | ||
309 | m_gnome_wm_win_layer = XInternAtom(disp, "_WIN_LAYER", False); | ||
310 | m_gnome_wm_win_state = XInternAtom(disp, "_WIN_STATE", False); | ||
311 | m_gnome_wm_win_hints = XInternAtom(disp, "_WIN_HINTS", False); | ||
312 | m_gnome_wm_win_app_state = XInternAtom(disp, "_WIN_APP_STATE", False); | ||
313 | m_gnome_wm_win_expanded_size = XInternAtom(disp, "_WIN_EXPANDED_SIZE", False); | ||
314 | m_gnome_wm_win_icons = XInternAtom(disp, "_WIN_ICONS", False); | ||
315 | m_gnome_wm_win_workspace = XInternAtom(disp, "_WIN_WORKSPACE", False); | ||
316 | m_gnome_wm_win_workspace_count = XInternAtom(disp, "_WIN_WORKSPACE_COUNT", False); | ||
317 | m_gnome_wm_win_workspace_names = XInternAtom(disp, "_WIN_WORKSPACE_NAMES", False); | ||
318 | m_gnome_wm_win_client_list = XInternAtom(disp, "_WIN_CLIENT_LIST", False); | ||
319 | m_gnome_wm_prot = XInternAtom(disp, "_WIN_PROTOCOLS", False); | ||
320 | m_gnome_wm_supporting_wm_check = XInternAtom(disp, "_WIN_SUPPORTING_WM_CHECK", False); | ||
321 | } | ||