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"
60 #define WIN_HINTS_SKIP_FOCUS (1<<0) /*"alt-tab" skips this win*/
61 #define WIN_HINTS_SKIP_WINLIST (1<<1) /*do not show in window list*/
62 #define WIN_HINTS_SKIP_TASKBAR (1<<2) /*do not show on taskbar*/
63 #define WIN_HINTS_GROUP_TRANSIENT (1<<3) /*Reserved - definition is unclear*/
64 #define WIN_HINTS_FOCUS_ON_CLICK (1<<4) /*app only accepts focus if clicked*/
65 #define WIN_HINTS_DO_NOT_COVER (1<<5) /* attempt to not cover this window */
68 #define WIN_STATE_STICKY (1<<0) /*everyone knows sticky*/
69 #define WIN_STATE_MINIMIZED (1<<1) /*Reserved - definition is unclear*/
70 #define WIN_STATE_MAXIMIZED_VERT (1<<2) /*window in maximized V state*/
71 #define WIN_STATE_MAXIMIZED_HORIZ (1<<3) /*window in maximized H state*/
72 #define WIN_STATE_HIDDEN (1<<4) /*not on taskbar but window visible*/
73 #define WIN_STATE_SHADED (1<<5) /*shaded (MacOS / Afterstep style)*/
74 /* these are bogus states defined in "the spec" */
75 #define WIN_STATE_HID_WORKSPACE (1<<6) /*not on current desktop*/
76 #define WIN_STATE_HID_TRANSIENT (1<<7) /*owner of transient is hidden*/
77 #define WIN_STATE_FIXED_POSITION (1<<8) /*window is fixed in position even*/
78 #define WIN_STATE_ARRANGE_IGNORE (1<<9) /*ignore for auto arranging*/
81 #define WIN_LAYER_DESKTOP 0
82 #define WIN_LAYER_BELOW 2
83 #define WIN_LAYER_NORMAL 4
84 #define WIN_LAYER_ONTOP 6
85 #define WIN_LAYER_DOCK 8
86 #define WIN_LAYER_ABOVE_DOCK 10
87 #define WIN_LAYER_MENU 12
91 static Atom _XA_WIN_SUPPORTING_WM_CHECK
= 0;
92 static Atom _XA_WIN_PROTOCOLS
;
93 static Atom _XA_WIN_LAYER
;
94 static Atom _XA_WIN_STATE
;
95 static Atom _XA_WIN_HINTS
;
96 static Atom _XA_WIN_APP_STATE
;
97 static Atom _XA_WIN_EXPANDED_SIZE
;
98 static Atom _XA_WIN_ICONS
;
99 static Atom _XA_WIN_WORKSPACE
;
100 static Atom _XA_WIN_WORKSPACE_COUNT
;
101 static Atom _XA_WIN_WORKSPACE_NAMES
;
102 static Atom _XA_WIN_CLIENT_LIST
;
103 static Atom _XA_WIN_DESKTOP_BUTTON_PROXY
;
106 static void observer(void *self
, WMNotification
*notif
);
107 static void wsobserver(void *self
, WMNotification
*notif
);
111 wGNOMEInitStuff(WScreen
*scr
)
113 Atom supportedStuff
[10];
116 if (!_XA_WIN_SUPPORTING_WM_CHECK
) {
118 _XA_WIN_SUPPORTING_WM_CHECK
=
119 XInternAtom(dpy
, "_WIN_SUPPORTING_WM_CHECK", False
);
121 _XA_WIN_PROTOCOLS
= XInternAtom(dpy
, "_WIN_PROTOCOLS", False
);
123 _XA_WIN_LAYER
= XInternAtom(dpy
, "_WIN_LAYER", False
);
125 _XA_WIN_STATE
= XInternAtom(dpy
, "_WIN_STATE", False
);
127 _XA_WIN_HINTS
= XInternAtom(dpy
, "_WIN_HINTS", False
);
129 _XA_WIN_APP_STATE
= XInternAtom(dpy
, "_WIN_APP_STATE", False
);
131 _XA_WIN_EXPANDED_SIZE
= XInternAtom(dpy
, "_WIN_EXPANDED_SIZE", False
);
133 _XA_WIN_ICONS
= XInternAtom(dpy
, "_WIN_ICONS", False
);
135 _XA_WIN_WORKSPACE
= XInternAtom(dpy
, "_WIN_WORKSPACE", False
);
137 _XA_WIN_WORKSPACE_COUNT
=
138 XInternAtom(dpy
, "_WIN_WORKSPACE_COUNT", False
);
140 _XA_WIN_WORKSPACE_NAMES
=
141 XInternAtom(dpy
, "_WIN_WORKSPACE_NAMES", False
);
143 _XA_WIN_CLIENT_LIST
= XInternAtom(dpy
, "_WIN_CLIENT_LIST", False
);
145 _XA_WIN_DESKTOP_BUTTON_PROXY
=
146 XInternAtom(dpy
, "_WIN_DESKTOP_BUTTON_PROXY", False
);
149 /* I'd rather use the ICCCM 2.0 mechanisms, but
150 * since some people prefer to reinvent the wheel instead of
151 * conforming to standards... */
153 /* setup the "We're compliant, you idiot!" hint */
155 /* why XA_CARDINAL instead of XA_WINDOW? */
156 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_SUPPORTING_WM_CHECK
,
157 XA_CARDINAL
, 32, PropModeReplace
,
158 (unsigned char*)&scr
->no_focus_win
, 1);
160 XChangeProperty(dpy
, scr
->no_focus_win
, _XA_WIN_SUPPORTING_WM_CHECK
,
161 XA_CARDINAL
, 32, PropModeReplace
,
162 (unsigned char*)&scr
->no_focus_win
, 1);
165 /* setup the "desktop button proxy" thing */
166 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_DESKTOP_BUTTON_PROXY
,
167 XA_CARDINAL
, 32, PropModeReplace
,
168 (unsigned char*)&scr
->no_focus_win
, 1);
169 XChangeProperty(dpy
, scr
->no_focus_win
, _XA_WIN_DESKTOP_BUTTON_PROXY
,
170 XA_CARDINAL
, 32, PropModeReplace
,
171 (unsigned char*)&scr
->no_focus_win
, 1);
174 /* setup the list of supported protocols */
176 supportedStuff
[count
++] = _XA_WIN_LAYER
;
177 supportedStuff
[count
++] = _XA_WIN_STATE
;
178 supportedStuff
[count
++] = _XA_WIN_HINTS
;
179 supportedStuff
[count
++] = _XA_WIN_APP_STATE
;
180 supportedStuff
[count
++] = _XA_WIN_EXPANDED_SIZE
;
181 supportedStuff
[count
++] = _XA_WIN_ICONS
;
182 supportedStuff
[count
++] = _XA_WIN_WORKSPACE
;
183 supportedStuff
[count
++] = _XA_WIN_WORKSPACE_COUNT
;
184 supportedStuff
[count
++] = _XA_WIN_WORKSPACE_NAMES
;
185 supportedStuff
[count
++] = _XA_WIN_CLIENT_LIST
;
187 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_PROTOCOLS
, XA_ATOM
, 32,
188 PropModeReplace
, (unsigned char*)supportedStuff
, count
);
192 WMAddNotificationObserver(observer
, NULL
, WMNManaged
, NULL
);
193 WMAddNotificationObserver(observer
, NULL
, WMNUnmanaged
, NULL
);
194 WMAddNotificationObserver(observer
, NULL
, WMNChangedWorkspace
, NULL
);
195 WMAddNotificationObserver(observer
, NULL
, WMNChangedState
, NULL
);
196 WMAddNotificationObserver(observer
, NULL
, WMNChangedFocus
, NULL
);
197 WMAddNotificationObserver(observer
, NULL
, WMNChangedStacking
, NULL
);
198 WMAddNotificationObserver(observer
, NULL
, WMNChangedName
, NULL
);
200 WMAddNotificationObserver(wsobserver
, NULL
, WMNWorkspaceChanged
, NULL
);
201 WMAddNotificationObserver(wsobserver
, NULL
, WMNWorkspaceNameChanged
, NULL
);
206 wGNOMEUpdateClientListHint(WScreen
*scr
)
212 windows
= malloc(sizeof(Window
)*scr
->window_count
);
214 wwarning(_("out of memory while updating GNOME hints"));
219 wwin
= scr
->focused_window
;
221 if (!wwin
->flags
.internal_window
&&
222 !wwin
->client_flags
.skip_window_list
) {
224 windows
[count
++] = wwin
->client_win
;
230 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_CLIENT_LIST
, XA_CARDINAL
, 32,
231 PropModeReplace
, (unsigned char *)windows
, count
);
239 wGNOMEUpdateWorkspaceHints(WScreen
*scr
)
243 val
= scr
->workspace_count
;
245 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_WORKSPACE_COUNT
, XA_CARDINAL
,
246 32, PropModeReplace
, (unsigned char*)&val
, 1);
248 wGNOMEUpdateWorkspaceNamesHint(scr
);
253 wGNOMEUpdateWorkspaceNamesHint(WScreen
*scr
)
255 char *wsNames
[MAX_WORKSPACES
];
256 XTextProperty textProp
;
259 for (i
= 0; i
< scr
->workspace_count
; i
++) {
260 wsNames
[i
] = scr
->workspaces
[i
]->name
;
263 if (XStringListToTextProperty(wsNames
, scr
->workspace_count
, &textProp
)) {
264 XSetTextProperty(dpy
, scr
->root_win
, &textProp
,
265 _XA_WIN_WORKSPACE_NAMES
);
266 XFree(textProp
.value
);
272 wGNOMEUpdateCurrentWorkspaceHint(WScreen
*scr
)
276 val
= scr
->current_workspace
;
278 XChangeProperty(dpy
, scr
->root_win
, _XA_WIN_WORKSPACE
, XA_CARDINAL
,
279 32, PropModeReplace
, (unsigned char*)&val
, 1);
284 getWindowLevel(int layer
)
288 if (layer
<= WIN_LAYER_DESKTOP
)
289 level
= WMDesktopLevel
;
290 else if (layer
<= WIN_LAYER_BELOW
)
291 level
= WMSunkenLevel
;
292 else if (layer
<= WIN_LAYER_NORMAL
)
293 level
= WMNormalLevel
;
294 else if (layer
<= WIN_LAYER_ONTOP
)
295 level
= WMFloatingLevel
;
296 else if (layer
<= WIN_LAYER_DOCK
)
298 else if (layer
<= WIN_LAYER_ABOVE_DOCK
)
299 level
= WMSubmenuLevel
;
300 else if (layer
<= WIN_LAYER_MENU
)
301 level
= WMMainMenuLevel
;
303 level
= WMOuterSpaceLevel
;
310 wGNOMECheckClientHints(WWindow
*wwin
, int *layer
, int *workspace
)
314 unsigned long nitems_ret
;
315 unsigned long bytes_after_ret
;
316 long flags
, val
, *data
= 0;
317 Bool hasHints
= False
;
321 if (XGetWindowProperty(dpy
, wwin
->client_win
, _XA_WIN_HINTS
, 0, 1, False
,
322 /* should be XA_INTEGER, but spec is broken */
323 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
325 (unsigned char**)&data
)==Success
&& data
) {
330 if (flags
& (WIN_HINTS_SKIP_FOCUS
|WIN_HINTS_SKIP_WINLIST
331 |WIN_HINTS_SKIP_TASKBAR
)) {
332 wwin
->client_flags
.skip_window_list
= 1;
335 /* client reserved area, for the panel */
336 if (flags
& (WIN_HINTS_DO_NOT_COVER
)) {
339 area
= malloc(sizeof(WReservedArea
));
341 wwarning(_("out of memory while updating GNOME hints"));
343 XWindowAttributes wattribs
;
345 XGetWindowAttributes(dpy
, wwin
->client_win
, &wattribs
);
346 wClientGetNormalHints(wwin
, &wattribs
, False
,
347 &area
->area
.x1
, &area
->area
.y1
,
348 &area
->area
.x2
, &area
->area
.y2
);
349 area
->area
.x2
= area
->area
.x2
+ area
->area
.x1
;
350 area
->area
.y2
= area
->area
.y2
+ area
->area
.y1
;
352 area
->window
= wwin
->client_win
;
354 area
->next
= wwin
->screen_ptr
->reservedAreas
;
355 wwin
->screen_ptr
->reservedAreas
= area
;
357 wScreenUpdateUsableArea(wwin
->screen_ptr
);
364 if (XGetWindowProperty(dpy
, wwin
->client_win
, _XA_WIN_LAYER
, 0, 1, False
,
365 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
367 (unsigned char**)&data
)==Success
&& data
) {
372 *layer
= getWindowLevel(val
);
377 if (XGetWindowProperty(dpy
, wwin
->client_win
, _XA_WIN_WORKSPACE
, 0, 1,
378 False
, XA_CARDINAL
, &type_ret
, &fmt_ret
,
379 &nitems_ret
, &bytes_after_ret
,
380 (unsigned char**)&data
)==Success
&& data
) {
391 if (XGetWindowProperty(dpy
, wwin
->client_win
, _XA_WIN_EXPANDED_SIZE
, 0, 1,
392 False
, XA_CARDINAL
, &type_ret
, &fmt_ret
,
393 &nitems_ret
, &bytes_after_ret
,
394 (unsigned char**)&data
)==Success
&& data
) {
397 area
= malloc(sizeof(WReservedArea
));
399 wwarning(_("out of memory while updating GNOME hints"));
401 area
->area
.x1
= data
[0];
402 area
->area
.y1
= data
[1];
403 area
->area
.x2
= data
[2] - data
[0];
404 area
->area
.y2
= data
[3] - data
[1];
407 area
->window
= wwin
->client_win
;
410 area
->next
= wwin
->screen_ptr
->reservedAreas
;
411 wwin
->screen_ptr
->reservedAreas
= area
;
413 wScreenUpdateUsableArea(wwin
->screen_ptr
);
422 wGNOMECheckInitialClientState(WWindow
*wwin
)
426 unsigned long nitems_ret
;
427 unsigned long bytes_after_ret
;
428 long flags
, *data
= 0;
430 if (XGetWindowProperty(dpy
, wwin
->client_win
, _XA_WIN_STATE
, 0, 1, False
,
431 XA_CARDINAL
, &type_ret
, &fmt_ret
, &nitems_ret
,
433 (unsigned char**)&data
)!=Success
|| !data
)
440 if (flags
& WIN_STATE_STICKY
)
441 wwin
->client_flags
.omnipresent
= 1;
443 if (flags
& (WIN_STATE_MAXIMIZED_VERT
|WIN_STATE_MAXIMIZED_HORIZ
)) {
445 if (flags
& WIN_STATE_MAXIMIZED_VERT
)
446 wwin
->flags
.maximized
|= MAX_VERTICAL
;
448 if (flags
& WIN_STATE_MAXIMIZED_HORIZ
)
449 wwin
->flags
.maximized
|= MAX_HORIZONTAL
;
452 if (flags
& WIN_STATE_SHADED
)
453 wwin
->flags
.shaded
= 1;
460 wGNOMEUpdateClientStateHint(WWindow
*wwin
, Bool changedWorkspace
)
465 if (changedWorkspace
) {
466 val
= wwin
->frame
->workspace
;
468 XChangeProperty(dpy
, wwin
->client_win
, _XA_WIN_WORKSPACE
, XA_CARDINAL
,
469 32, PropModeReplace
, (unsigned char*)&val
, 1);
471 if (val
!= wwin
->screen_ptr
->current_workspace
)
472 flags
|= WIN_STATE_HID_WORKSPACE
;
475 if (IS_OMNIPRESENT(wwin
))
476 flags
|= WIN_STATE_STICKY
;
478 if (wwin
->flags
.miniaturized
)
479 flags
|= WIN_STATE_MINIMIZED
;
481 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
482 flags
|= WIN_STATE_MAXIMIZED_VERT
;
484 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
485 flags
|= WIN_STATE_MAXIMIZED_HORIZ
;
487 if (wwin
->flags
.shaded
)
488 flags
|= WIN_STATE_SHADED
;
490 if (wwin
->transient_for
!= None
) {
491 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
493 if (owner
&& !owner
->flags
.mapped
)
494 flags
|= WIN_STATE_HID_TRANSIENT
;
498 if (wwin
->flags
.hidden
)
499 flags
|= WIN_STATE_HIDDEN
;
501 XChangeProperty(dpy
, wwin
->client_win
, _XA_WIN_STATE
, XA_CARDINAL
,
502 32, PropModeReplace
, (unsigned char*)&flags
, 1);
507 wGNOMEProcessClientMessage(XClientMessageEvent
*event
)
513 scr
= wScreenForWindow(event
->window
);
515 /* generic client messages */
516 if (event
->message_type
== _XA_WIN_WORKSPACE
) {
517 wWorkspaceChange(scr
, event
->data
.l
[0]);
526 /* window specific client messages */
528 wwin
= wWindowFor(event
->window
);
532 if (event
->message_type
== _XA_WIN_LAYER
) {
533 int level
= getWindowLevel(event
->data
.l
[0]);
535 if (WINDOW_LEVEL(wwin
) != level
) {
536 ChangeStackingLevel(wwin
->frame
->core
, level
);
538 } else if (event
->message_type
== _XA_WIN_STATE
) {
542 mask
= event
->data
.l
[0];
543 flags
= event
->data
.l
[1];
545 if (mask
& WIN_STATE_STICKY
) {
546 if ((flags
& WIN_STATE_STICKY
) != WFLAGP(wwin
, omnipresent
)) {
547 wWindowSetOmnipresent(wwin
, (flags
& WIN_STATE_STICKY
)!=0);
551 if (mask
& WIN_STATE_MAXIMIZED_VERT
) {
552 if (flags
& WIN_STATE_MAXIMIZED_VERT
)
553 maximize
= MAX_VERTICAL
;
557 maximize
= wwin
->flags
.maximized
& MAX_VERTICAL
;
560 if (mask
& WIN_STATE_MAXIMIZED_HORIZ
) {
561 if (flags
& WIN_STATE_MAXIMIZED_HORIZ
)
562 maximize
|= MAX_HORIZONTAL
;
566 maximize
|= wwin
->flags
.maximized
& MAX_HORIZONTAL
;
569 if (maximize
!= wwin
->flags
.maximized
) {
570 #define both (MAX_HORIZONTAL|MAX_VERTICAL)
571 if (!(maximize
& both
) && (wwin
->flags
.maximized
& both
)) {
572 wUnmaximizeWindow(wwin
);
574 if ((maximize
& both
) && !(wwin
->flags
.maximized
& both
)) {
575 wMaximizeWindow(wwin
, maximize
);
580 if (mask
& WIN_STATE_SHADED
) {
581 if ((flags
& WIN_STATE_SHADED
) != wwin
->flags
.shaded
) {
582 if (wwin
->flags
.shaded
)
583 wUnshadeWindow(wwin
);
588 } else if (event
->message_type
== _XA_WIN_WORKSPACE
) {
590 if (event
->data
.l
[0] != wwin
->frame
->workspace
) {
591 wWindowChangeWorkspace(wwin
, event
->data
.l
[0]);
602 wGNOMEProxyizeButtonEvent(WScreen
*scr
, XEvent
*event
)
604 if (event
->type
== ButtonPress
)
605 XUngrabPointer(dpy
, CurrentTime
);
606 XSendEvent(dpy
, scr
->no_focus_win
, False
, SubstructureNotifyMask
, event
);
613 wGNOMERemoveClient(WWindow
*wwin
)
618 wGNOMEUpdateClientListHint(wwin
->screen_ptr
);
620 area
= wwin
->screen_ptr
->reservedAreas
;
623 if (area
->window
== wwin
->client_win
) {
624 wwin
->screen_ptr
->reservedAreas
= area
->next
;
628 while (area
->next
&& area
->next
->window
!= wwin
->client_win
)
634 next
= area
->next
->next
;
644 wScreenUpdateUsableArea(wwin
->screen_ptr
);
651 static void observer(void *self
, WMNotification
*notif
)
653 WWindow
*wwin
= (WWindow
*)WMGetNotificationObject(notif
);
654 const char *name
= WMGetNotificationName(notif
);
656 if (strcmp(name
, WMNManaged
) == 0 && wwin
) {
657 wGNOMEUpdateClientStateHint(wwin
, True
);
659 wGNOMEUpdateClientListHint(wwin
->screen_ptr
);
660 } else if (strcmp(name
, WMNUnmanaged
) == 0 && wwin
) {
661 wGNOMERemoveClient(wwin
);
662 } else if (strcmp(name
, WMNChangedWorkspace
) == 0 && wwin
) {
663 wGNOMEUpdateClientStateHint(wwin
, True
);
664 } else if (strcmp(name
, WMNChangedState
) == 0 && wwin
) {
665 wGNOMEUpdateClientStateHint(wwin
, False
);
669 static void wsobserver(void *self
, WMNotification
*notif
)
671 WScreen
*scr
= (WScreen
*)WMGetNotificationObject(notif
);
672 const char *name
= WMGetNotificationName(notif
);
674 if (strcmp(name
, WMNWorkspaceCreated
) == 0) {
675 wGNOMEUpdateWorkspaceHints(scr
);
676 } else if (strcmp(name
, WMNWorkspaceDestroyed
) == 0) {
677 wGNOMEUpdateWorkspaceHints(scr
);
678 } else if (strcmp(name
, WMNWorkspaceNameChanged
) == 0) {
679 wGNOMEUpdateWorkspaceNamesHint(scr
);
680 } else if (strcmp(name
, WMNWorkspaceChanged
) == 0) {
681 wGNOMEUpdateCurrentWorkspaceHint(scr
);
684 } else if (strcmp(name
, WMNResetStacking
) == 0) {
690 #endif /* GNOME_STUFF */