1 /* gnome.c-- support for the GNOME Hints
3 * Window Maker window manager
5 * Copyright (c) 1998, 1999 Alfredo K. Kojima
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,
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.
34 #include <X11/Xutil.h>
35 #include <X11/Xatom.h>
42 #include "WindowMaker.h"
47 #include "workspace.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
;
105 wGNOMEInitStuff(WScreen
*scr
)
107 Atom supportedStuff
[10];
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 */
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
);
189 wGNOMEUpdateClientListHint(WScreen
*scr
)
195 windows
= malloc(sizeof(Window
)*scr
->window_count
);
197 wwarning(_("out of memory while updating GNOME hints"));
202 wwin
= scr
->focused_window
;
204 if (!wwin
->flags
.internal_window
) {
206 windows
[count
++] = wwin
->client_win
;
212 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_CLIENT_LIST
, XA_CARDINAL
, 32,
213 PropModeReplace
, (unsigned char *)windows
, count
);
221 wGNOMEUpdateWorkspaceHints(WScreen
*scr
)
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
);
235 wGNOMEUpdateWorkspaceNamesHint(WScreen
*scr
)
237 char *wsNames
[MAX_WORKSPACES
];
238 XTextProperty textProp
;
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
);
254 wGNOMEUpdateCurrentWorkspaceHint(WScreen
*scr
)
258 val
= scr
->current_workspace
;
260 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_WORKSPACE
, XA_CARDINAL
,
261 32, PropModeReplace
, (unsigned char*)&val
, 1);
266 getWindowLevel(int layer
)
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
)
280 else if (layer
<= WIN_LAYER_ABOVE_DOCK
)
281 level
= WMSubmenuLevel
;
282 else if (layer
<= WIN_LAYER_MENU
)
283 level
= WMMainMenuLevel
;
285 level
= WMOuterSpaceLevel
;
292 wGNOMECheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
296 unsigned long nitems_ret
;
297 unsigned long bytes_after_ret
;
298 long flags
, val
, *data
= 0;
299 Bool hasHints
= False
;
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
,
307 (unsigned char**)&data
)==Success
&& data
) {
312 if (flags
& (WIN_HINTS_SKIP_FOCUS
|WIN_HINTS_SKIP_WINLIST
)) {
313 wwin
->client_flags
.skip_window_list
= 1;
319 if (XGetWindowProperty(dpy
, wwin
->client_win
, _XA_WIN_LAYER
, 0, 1, False
,
320 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
322 (unsigned char**)&data
)==Success
&& data
) {
327 *layer
= getWindowLevel(val
);
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
) {
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
) {
352 area
= malloc(sizeof(WReservedArea
));
354 wwarning(_("out of memory while updating GNOME hints"));
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];
362 area
->window
= wwin
->client_win
;
365 area
->next
= wwin
->screen_ptr
->reservedAreas
;
366 wwin
->screen_ptr
->reservedAreas
= area
;
368 wScreenUpdateUsableArea(wwin
->screen_ptr
);
377 wGNOMECheckInitialClientState(WWindow
*wwin
)
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
,
388 (unsigned char**)&data
)!=Success
|| !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;
415 wGNOMEUpdateClientStateHint(WWindow
*wwin
, Bool changedWorkspace
)
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
;
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);
462 wGNOMEProcessClientMessage(XClientMessageEvent
*event
)
468 scr
= wScreenForWindow(event
->window
);
470 /* generic client messages */
471 if (event
->message_type
== _XA_WIN_WORKSPACE
) {
472 wWorkspaceChange(scr
, event
->data
.l
[0]);
481 /* window specific client messages */
483 wwin
= wWindowFor(event
->window
);
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
) {
495 Bool updateWindowList
= False
;
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
;
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
;
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
;
539 if (mask
& WIN_STATE_SHADED
) {
540 if ((flags
& WIN_STATE_SHADED
) != wwin
->flags
.shaded
) {
541 if (wwin
->flags
.shaded
)
542 wUnshadeWindow(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]);
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
);
577 wGNOMERemoveClient(WWindow
*wwin
)
582 wGNOMEUpdateClientListHint(wwin
->screen_ptr
);
584 area
= wwin
->screen_ptr
->reservedAreas
;
587 if (area
->window
== wwin
->client_win
) {
588 wwin
->screen_ptr
->reservedAreas
= area
->next
;
592 while (area
->next
&& area
->next
->window
!= wwin
->client_win
)
598 next
= area
->next
->next
;
608 wScreenUpdateUsableArea(wwin
->screen_ptr
);
613 #endif /* GNOME_STUFF */