*** empty log message ***
[wmaker-crm.git] / src / gnome.c
blob4825204a05cd6e9ac8845306b1b070da5afe9739
1 /* gnome.c-- support for the GNOME Hints
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1998, 1999 Alfredo K. Kojima
6 *
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 * According to the author of this thing, it should not be taken seriously.
25 * IMHO, there are lot's of weirdnesses and it's quite unelegant. I'd
26 * rather not support it, but here it goes anyway.
29 #include "wconfig.h"
31 #ifdef GNOME_STUFF
33 #include <X11/Xlib.h>
34 #include <X11/Xutil.h>
35 #include <X11/Xatom.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
42 #include "WindowMaker.h"
43 #include "screen.h"
44 #include "wcore.h"
45 #include "framewin.h"
46 #include "window.h"
47 #include "workspace.h"
48 #include "funcs.h"
49 #include "actions.h"
50 #include "stacking.h"
52 #include "gnome.h"
59 #define WIN_HINTS_SKIP_FOCUS (1<<0) /*"alt-tab" skips this win*/
60 #define WIN_HINTS_SKIP_WINLIST (1<<1) /*do not show in window list*/
61 #define WIN_HINTS_SKIP_TASKBAR (1<<2) /*do not show on taskbar*/
62 #define WIN_HINTS_GROUP_TRANSIENT (1<<3) /*Reserved - definition is unclear*/
63 #define WIN_HINTS_FOCUS_ON_CLICK (1<<4) /*app only accepts focus if clicked*/
66 #define WIN_STATE_STICKY (1<<0) /*everyone knows sticky*/
67 #define WIN_STATE_MINIMIZED (1<<1) /*Reserved - definition is unclear*/
68 #define WIN_STATE_MAXIMIZED_VERT (1<<2) /*window in maximized V state*/
69 #define WIN_STATE_MAXIMIZED_HORIZ (1<<3) /*window in maximized H state*/
70 #define WIN_STATE_HIDDEN (1<<4) /*not on taskbar but window visible*/
71 #define WIN_STATE_SHADED (1<<5) /*shaded (MacOS / Afterstep style)*/
72 /* these are bogus states defined in "the spec" */
73 #define WIN_STATE_HID_WORKSPACE (1<<6) /*not on current desktop*/
74 #define WIN_STATE_HID_TRANSIENT (1<<7) /*owner of transient is hidden*/
75 #define WIN_STATE_FIXED_POSITION (1<<8) /*window is fixed in position even*/
76 #define WIN_STATE_ARRANGE_IGNORE (1<<9) /*ignore for auto arranging*/
79 #define WIN_LAYER_DESKTOP 0
80 #define WIN_LAYER_BELOW 2
81 #define WIN_LAYER_NORMAL 4
82 #define WIN_LAYER_ONTOP 6
83 #define WIN_LAYER_DOCK 8
84 #define WIN_LAYER_ABOVE_DOCK 10
85 #define WIN_LAYER_MENU 12
89 static Atom _XA_WIN_SUPPORTING_WM_CHECK = 0;
90 static Atom _XA_WIN_PROTOCOLS;
91 static Atom _XA_WIN_LAYER;
92 static Atom _XA_WIN_STATE;
93 static Atom _XA_WIN_HINTS;
94 static Atom _XA_WIN_APP_STATE;
95 static Atom _XA_WIN_EXPANDED_SIZE;
96 static Atom _XA_WIN_ICONS;
97 static Atom _XA_WIN_WORKSPACE;
98 static Atom _XA_WIN_WORKSPACE_COUNT;
99 static Atom _XA_WIN_WORKSPACE_NAMES;
100 static Atom _XA_WIN_CLIENT_LIST;
101 static Atom _XA_WIN_DESKTOP_BUTTON_PROXY;
104 void
105 wGNOMEInitStuff(WScreen *scr)
107 Atom supportedStuff[10];
108 int count;
110 if (!_XA_WIN_SUPPORTING_WM_CHECK) {
112 _XA_WIN_SUPPORTING_WM_CHECK =
113 XInternAtom(dpy, "_WIN_SUPPORTING_WM_CHECK", False);
115 _XA_WIN_PROTOCOLS = XInternAtom(dpy, "_WIN_PROTOCOLS", False);
117 _XA_WIN_LAYER = XInternAtom(dpy, "_WIN_LAYER", False);
119 _XA_WIN_STATE = XInternAtom(dpy, "_WIN_STATE", False);
121 _XA_WIN_HINTS = XInternAtom(dpy, "_WIN_HINTS", False);
123 _XA_WIN_APP_STATE = XInternAtom(dpy, "_WIN_APP_STATE", False);
125 _XA_WIN_EXPANDED_SIZE = XInternAtom(dpy, "_WIN_EXPANDED_SIZE", False);
127 _XA_WIN_ICONS = XInternAtom(dpy, "_WIN_ICONS", False);
129 _XA_WIN_WORKSPACE = XInternAtom(dpy, "_WIN_WORKSPACE", False);
131 _XA_WIN_WORKSPACE_COUNT =
132 XInternAtom(dpy, "_WIN_WORKSPACE_COUNT", False);
134 _XA_WIN_WORKSPACE_NAMES =
135 XInternAtom(dpy, "_WIN_WORKSPACE_NAMES", False);
137 _XA_WIN_CLIENT_LIST = XInternAtom(dpy, "_WIN_CLIENT_LIST", False);
139 _XA_WIN_DESKTOP_BUTTON_PROXY =
140 XInternAtom(dpy, "_WIN_DESKTOP_BUTTON_PROXY", False);
143 /* I'd rather use the ICCCM 2.0 mechanisms, but
144 * since some people prefer to reinvent the wheel instead of
145 * conforming to standards... */
147 /* setup the "We're compliant, you idiot!" hint */
149 /* why XA_CARDINAL instead of XA_WINDOW? */
150 XChangeProperty(dpy, scr->root_win, _XA_WIN_SUPPORTING_WM_CHECK,
151 XA_CARDINAL, 32, PropModeReplace,
152 (unsigned char*)&scr->no_focus_win, 1);
154 XChangeProperty(dpy, scr->no_focus_win, _XA_WIN_SUPPORTING_WM_CHECK,
155 XA_CARDINAL, 32, PropModeReplace,
156 (unsigned char*)&scr->no_focus_win, 1);
159 /* setup the "desktop button proxy" thing */
160 XChangeProperty(dpy, scr->root_win, _XA_WIN_DESKTOP_BUTTON_PROXY,
161 XA_CARDINAL, 32, PropModeReplace,
162 (unsigned char*)&scr->no_focus_win, 1);
163 XChangeProperty(dpy, scr->no_focus_win, _XA_WIN_DESKTOP_BUTTON_PROXY,
164 XA_CARDINAL, 32, PropModeReplace,
165 (unsigned char*)&scr->no_focus_win, 1);
168 /* setup the list of supported protocols */
169 count = 0;
170 supportedStuff[count++] = _XA_WIN_LAYER;
171 supportedStuff[count++] = _XA_WIN_STATE;
172 supportedStuff[count++] = _XA_WIN_HINTS;
173 supportedStuff[count++] = _XA_WIN_APP_STATE;
174 supportedStuff[count++] = _XA_WIN_EXPANDED_SIZE;
175 supportedStuff[count++] = _XA_WIN_ICONS;
176 supportedStuff[count++] = _XA_WIN_WORKSPACE;
177 supportedStuff[count++] = _XA_WIN_WORKSPACE_COUNT;
178 supportedStuff[count++] = _XA_WIN_WORKSPACE_NAMES;
179 supportedStuff[count++] = _XA_WIN_CLIENT_LIST;
181 XChangeProperty(dpy, scr->root_win, _XA_WIN_PROTOCOLS, XA_ATOM, 32,
182 PropModeReplace, (unsigned char*)supportedStuff, count);
184 XFlush(dpy);
188 void
189 wGNOMEUpdateClientListHint(WScreen *scr)
191 WWindow *wwin;
192 Window *windows;
193 int count;
195 windows = malloc(sizeof(Window)*scr->window_count);
196 if (!windows) {
197 wwarning(_("out of memory while updating GNOME hints"));
198 return;
201 count = 0;
202 wwin = scr->focused_window;
203 while (wwin) {
204 if (!wwin->flags.internal_window) {
206 windows[count++] = wwin->client_win;
209 wwin = wwin->prev;
212 XChangeProperty(dpy, scr->root_win, _XA_WIN_CLIENT_LIST, XA_CARDINAL, 32,
213 PropModeReplace, (unsigned char *)windows, count);
215 free(windows);
216 XFlush(dpy);
220 void
221 wGNOMEUpdateWorkspaceHints(WScreen *scr)
223 long val;
225 val = scr->workspace_count;
227 XChangeProperty(dpy, scr->root_win, _XA_WIN_WORKSPACE_COUNT, XA_CARDINAL,
228 32, PropModeReplace, (unsigned char*)&val, 1);
230 wGNOMEUpdateWorkspaceNamesHint(scr);
234 void
235 wGNOMEUpdateWorkspaceNamesHint(WScreen *scr)
237 char *wsNames[MAX_WORKSPACES];
238 XTextProperty textProp;
239 int i;
241 for (i = 0; i < scr->workspace_count; i++) {
242 wsNames[i] = scr->workspaces[i]->name;
245 if (XStringListToTextProperty(wsNames, scr->workspace_count, &textProp)) {
246 XSetTextProperty(dpy, scr->root_win, &textProp,
247 _XA_WIN_WORKSPACE_NAMES);
248 XFree(textProp.value);
253 void
254 wGNOMEUpdateCurrentWorkspaceHint(WScreen *scr)
256 long val;
258 val = scr->current_workspace;
260 XChangeProperty(dpy, scr->root_win, _XA_WIN_WORKSPACE, XA_CARDINAL,
261 32, PropModeReplace, (unsigned char*)&val, 1);
265 static int
266 getWindowLevel(int layer)
268 int level;
270 if (layer <= WIN_LAYER_DESKTOP)
271 level = WMDesktopLevel;
272 else if (layer <= WIN_LAYER_BELOW)
273 level = WMSunkenLevel;
274 else if (layer <= WIN_LAYER_NORMAL)
275 level = WMNormalLevel;
276 else if (layer <= WIN_LAYER_ONTOP)
277 level = WMFloatingLevel;
278 else if (layer <= WIN_LAYER_DOCK)
279 level = WMDockLevel;
280 else if (layer <= WIN_LAYER_ABOVE_DOCK)
281 level = WMSubmenuLevel;
282 else if (layer <= WIN_LAYER_MENU)
283 level = WMMainMenuLevel;
284 else
285 level = WMOuterSpaceLevel;
287 return level;
291 Bool
292 wGNOMECheckClientHints(WWindow *wwin, int *layer, int *workspace)
294 Atom type_ret;
295 int fmt_ret;
296 unsigned long nitems_ret;
297 unsigned long bytes_after_ret;
298 long flags, val, *data = 0;
299 Bool hasHints = False;
301 /* hints */
303 if (XGetWindowProperty(dpy, wwin->client_win, _XA_WIN_HINTS, 0, 1, False,
304 /* should be XA_INTEGER, but spec is broken */
305 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
306 &bytes_after_ret,
307 (unsigned char**)&data)==Success && data) {
308 flags = *data;
310 XFree(data);
312 if (flags & (WIN_HINTS_SKIP_FOCUS|WIN_HINTS_SKIP_WINLIST)) {
313 wwin->client_flags.skip_window_list = 1;
315 hasHints = True;
318 /* layer */
319 if (XGetWindowProperty(dpy, wwin->client_win, _XA_WIN_LAYER, 0, 1, False,
320 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
321 &bytes_after_ret,
322 (unsigned char**)&data)==Success && data) {
323 val = *data;
325 XFree(data);
327 *layer = getWindowLevel(val);
328 hasHints = True;
331 /* workspace */
332 if (XGetWindowProperty(dpy, wwin->client_win, _XA_WIN_WORKSPACE, 0, 1,
333 False, XA_CARDINAL, &type_ret, &fmt_ret,
334 &nitems_ret, &bytes_after_ret,
335 (unsigned char**)&data)==Success && data) {
336 val = *data;
338 XFree(data);
340 if (val > 0)
341 *workspace = val;
342 hasHints = True;
345 /* reserved area */
346 if (XGetWindowProperty(dpy, wwin->client_win, _XA_WIN_EXPANDED_SIZE, 0, 1,
347 False, XA_CARDINAL, &type_ret, &fmt_ret,
348 &nitems_ret, &bytes_after_ret,
349 (unsigned char**)&data)==Success && data) {
350 WReservedArea *area;
352 area = malloc(sizeof(WReservedArea));
353 if (!area) {
354 wwarning(_("out of memory while updating GNOME hints"));
355 } else {
356 area->area.x1 = data[0];
357 area->area.y1 = data[1];
358 area->area.x2 = data[2] - data[0];
359 area->area.y2 = data[3] - data[1];
360 XFree(data);
362 area->window = wwin->client_win;
365 area->next = wwin->screen_ptr->reservedAreas;
366 wwin->screen_ptr->reservedAreas = area;
368 wScreenUpdateUsableArea(wwin->screen_ptr);
369 hasHints = True;
372 return hasHints;
376 Bool
377 wGNOMECheckInitialClientState(WWindow *wwin)
379 Atom type_ret;
380 int fmt_ret;
381 unsigned long nitems_ret;
382 unsigned long bytes_after_ret;
383 long flags, *data = 0;
385 if (XGetWindowProperty(dpy, wwin->client_win, _XA_WIN_STATE, 0, 1, False,
386 XA_CARDINAL, &type_ret, &fmt_ret, &nitems_ret,
387 &bytes_after_ret,
388 (unsigned char**)&data)!=Success || !data)
389 return False;
391 flags = *data;
393 XFree(data);
395 if (flags & WIN_STATE_STICKY)
396 wwin->client_flags.omnipresent = 1;
398 if (flags & (WIN_STATE_MAXIMIZED_VERT|WIN_STATE_MAXIMIZED_HORIZ)) {
400 if (flags & WIN_STATE_MAXIMIZED_VERT)
401 wwin->flags.maximized |= MAX_VERTICAL;
403 if (flags & WIN_STATE_MAXIMIZED_HORIZ)
404 wwin->flags.maximized |= MAX_HORIZONTAL;
407 if (flags & WIN_STATE_SHADED)
408 wwin->flags.shaded = 1;
410 return True;
414 void
415 wGNOMEUpdateClientStateHint(WWindow *wwin, Bool changedWorkspace)
417 long val;
418 long flags = 0;
420 if (changedWorkspace) {
421 val = wwin->frame->workspace;
423 XChangeProperty(dpy, wwin->client_win, _XA_WIN_WORKSPACE, XA_CARDINAL,
424 32, PropModeReplace, (unsigned char*)&val, 1);
426 if (val != wwin->screen_ptr->current_workspace)
427 flags |= WIN_STATE_HID_WORKSPACE;
430 if (IS_OMNIPRESENT(wwin))
431 flags |= WIN_STATE_STICKY;
433 if (wwin->flags.miniaturized)
434 flags |= WIN_STATE_MINIMIZED;
436 if (wwin->flags.maximized & MAX_VERTICAL)
437 flags |= WIN_STATE_MAXIMIZED_VERT;
439 if (wwin->flags.maximized & MAX_HORIZONTAL)
440 flags |= WIN_STATE_MAXIMIZED_HORIZ;
442 if (wwin->flags.shaded)
443 flags |= WIN_STATE_SHADED;
445 if (wwin->transient_for != None) {
446 WWindow *owner = wWindowFor(wwin->transient_for);
448 if (owner && !owner->flags.mapped)
449 flags |= WIN_STATE_HID_TRANSIENT;
452 /* ? */
453 if (wwin->flags.hidden)
454 flags |= WIN_STATE_HIDDEN;
456 XChangeProperty(dpy, wwin->client_win, _XA_WIN_STATE, XA_CARDINAL,
457 32, PropModeReplace, (unsigned char*)&flags, 1);
461 Bool
462 wGNOMEProcessClientMessage(XClientMessageEvent *event)
464 WScreen *scr;
465 WWindow *wwin;
466 Bool done = True;
468 scr = wScreenForWindow(event->window);
469 if (scr) {
470 /* generic client messages */
471 if (event->message_type == _XA_WIN_WORKSPACE) {
472 wWorkspaceChange(scr, event->data.l[0]);
473 } else {
474 done = False;
477 if (done)
478 return True;
481 /* window specific client messages */
483 wwin = wWindowFor(event->window);
484 if (!wwin)
485 return False;
487 if (event->message_type == _XA_WIN_LAYER) {
488 int level = getWindowLevel(event->data.l[0]);
490 if (WINDOW_LEVEL(wwin) != level) {
491 ChangeStackingLevel(wwin->frame->core, level);
493 } else if (event->message_type == _XA_WIN_STATE) {
494 int flags, mask;
495 Bool updateWindowList = False;
496 int maximize = 0;
498 mask = event->data.l[0];
499 flags = event->data.l[1];
501 if (mask & WIN_STATE_STICKY) {
502 if ((flags & WIN_STATE_STICKY) != WFLAGP(wwin, omnipresent)) {
503 wwin->client_flags.omnipresent = (flags & WIN_STATE_STICKY)!=0;
504 wGNOMEUpdateClientStateHint(wwin, False);
505 updateWindowList = True;
509 if (mask & WIN_STATE_MAXIMIZED_VERT) {
510 if (flags & WIN_STATE_MAXIMIZED_VERT)
511 maximize = MAX_VERTICAL;
512 else
513 maximize = 0;
514 } else {
515 maximize = wwin->flags.maximized & MAX_VERTICAL;
518 if (mask & WIN_STATE_MAXIMIZED_HORIZ) {
519 if (flags & WIN_STATE_MAXIMIZED_HORIZ)
520 maximize |= MAX_HORIZONTAL;
521 else
522 maximize |= 0;
523 } else {
524 maximize |= wwin->flags.maximized & MAX_HORIZONTAL;
527 if (maximize != wwin->flags.maximized) {
528 #define both (MAX_HORIZONTAL|MAX_VERTICAL)
529 if (!(maximize & both) && (wwin->flags.maximized & both)) {
530 wUnmaximizeWindow(wwin);
532 if ((maximize & both) && !(wwin->flags.maximized & both)) {
533 wMaximizeWindow(wwin, maximize);
535 updateWindowList = False;
536 #undef both
539 if (mask & WIN_STATE_SHADED) {
540 if ((flags & WIN_STATE_SHADED) != wwin->flags.shaded) {
541 if (wwin->flags.shaded)
542 wUnshadeWindow(wwin);
543 else
544 wShadeWindow(wwin);
545 updateWindowList = False;
549 if (updateWindowList) {
550 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
552 } else if (event->message_type == _XA_WIN_WORKSPACE) {
554 if (event->data.l[0] != wwin->frame->workspace) {
555 wWindowChangeWorkspace(wwin, event->data.l[0]);
557 } else {
558 done = False;
561 return done;
565 Bool
566 wGNOMEProxyizeButtonEvent(WScreen *scr, XEvent *event)
568 if (event->type == ButtonPress)
569 XUngrabPointer(dpy, CurrentTime);
570 XSendEvent(dpy, scr->no_focus_win, False, SubstructureNotifyMask, event);
572 return True;
576 void
577 wGNOMERemoveClient(WWindow *wwin)
579 int flag = 0;
580 WReservedArea *area;
582 wGNOMEUpdateClientListHint(wwin->screen_ptr);
584 area = wwin->screen_ptr->reservedAreas;
586 if (area) {
587 if (area->window == wwin->client_win) {
588 wwin->screen_ptr->reservedAreas = area->next;
589 free(area);
590 flag = 1;
591 } else {
592 while (area->next && area->next->window != wwin->client_win)
593 area = area->next;
595 if (area->next) {
596 WReservedArea *next;
598 next = area->next->next;
599 free(area->next);
600 area->next = next;
602 flag = 1;
607 if (flag) {
608 wScreenUpdateUsableArea(wwin->screen_ptr);
613 #endif /* GNOME_STUFF */