1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FWS.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
40 #include <X11/Xutil.h>
41 #include <X11/Xatom.h>
44 static Atom fwsIconAtom
;
46 static Atom FWS_CLIENT
;
47 static Atom FWS_COMM_WINDOW
;
48 static Atom FWS_PROTOCOLS
;
49 static Atom FWS_STACK_UNDER
;
50 static Atom FWS_PARK_ICONS
;
51 static Atom FWS_PASS_ALL_INPUT
;
52 static Atom FWS_PASSES_INPUT
;
53 static Atom FWS_HANDLES_FOCUS
;
55 static Atom FWS_REGISTER_WINDOW
;
56 static Atom FWS_STATE_CHANGE
;
57 static Atom FWS_UNSEEN_STATE
;
58 static Atom FWS_NORMAL_STATE
;
59 static Atom WM_PROTOCOLS
;
60 static Atom WM_CHANGE_STATE
;
62 static Bool fwsStackUnder
;
63 static Bool fwsParkIcons
;
64 static Bool fwsPassesInput
;
65 static Bool fwsHandlesFocus
;
67 static Window fwsCommWindow
;
69 /*************************************<->***********************************
73 * Initialize our atoms and determine if the current window manager is
74 * providing FWS extension support.
76 *************************************<->***********************************/
79 WMSupportsFWS (Display
*display
, int screen
)
85 unsigned long propItems
;
86 unsigned long propBytesAfter
;
87 unsigned char *propData
;
90 FWS_CLIENT
= XInternAtom(display
, "_SUN_FWS_CLIENT", False
);
91 FWS_COMM_WINDOW
= XInternAtom(display
, "_SUN_FWS_COMM_WINDOW", False
);
92 FWS_PROTOCOLS
= XInternAtom(display
, "_SUN_FWS_PROTOCOLS", False
);
93 FWS_STACK_UNDER
= XInternAtom(display
, "_SUN_FWS_STACK_UNDER", False
);
94 FWS_PARK_ICONS
= XInternAtom(display
, "_SUN_FWS_PARK_ICONS", False
);
95 FWS_PASS_ALL_INPUT
= XInternAtom(display
, "_SUN_FWS_PASS_ALL_INPUT", False
);
96 FWS_PASSES_INPUT
= XInternAtom(display
, "_SUN_FWS_PASSES_INPUT", False
);
97 FWS_HANDLES_FOCUS
= XInternAtom(display
, "_SUN_FWS_HANDLES_FOCUS", False
);
98 FWS_REGISTER_WINDOW
= XInternAtom(display
, "_SUN_FWS_REGISTER_WINDOW",False
);
99 FWS_STATE_CHANGE
= XInternAtom(display
, "_SUN_FWS_STATE_CHANGE", False
);
100 FWS_UNSEEN_STATE
= XInternAtom(display
, "_SUN_FWS_UNSEEN_STATE", False
);
101 FWS_NORMAL_STATE
= XInternAtom(display
, "_SUN_FWS_NORMAL_STATE", False
);
102 WM_PROTOCOLS
= XInternAtom(display
, "WM_PROTOCOLS", False
);
103 WM_CHANGE_STATE
= XInternAtom(display
, "WM_CHANGE_STATE", False
);
105 snprintf (propName
, sizeof(propName
), "_SUN_FWS_NEXT_ICON_%d", screen
);
106 fwsIconAtom
= XInternAtom(display
, propName
, False
);
108 if (XGetWindowProperty (display
, DefaultRootWindow (display
),
109 FWS_COMM_WINDOW
, 0, 1,
110 False
, AnyPropertyType
, &propType
,
111 &propFormat
, &propItems
,
112 &propBytesAfter
, &propData
) != Success
)
115 if (propFormat
!= 32 ||
119 #if OSL_DEBUG_LEVEL > 1
120 fprintf (stderr
, "Bad FWS_COMM_WINDOW property on root window.\n");
126 fwsCommWindow
= *(Window
*) propData
;
127 #if OSL_DEBUG_LEVEL > 1
128 fprintf (stderr
, "Using fwsCommWindow = 0x%lx.\n", fwsCommWindow
);
133 if (XGetWindowProperty (display
, DefaultRootWindow (display
),
134 FWS_PROTOCOLS
, 0, 10,
135 False
, AnyPropertyType
, &propType
,
136 &propFormat
, &propItems
,
137 &propBytesAfter
, &propData
) != Success
)
142 if (propFormat
!= 32 ||
145 #if OSL_DEBUG_LEVEL > 1
146 fprintf (stderr
, "Bad FWS_PROTOCOLS property on root window.\n");
152 for (i
= 0; i
< propItems
; ++i
)
154 protocol
= ((Atom
*) propData
)[i
];
155 if (protocol
== FWS_STACK_UNDER
)
157 fwsStackUnder
= True
;
158 #if OSL_DEBUG_LEVEL > 1
159 fprintf (stderr
, "Using fwsStackUnder.\n");
163 if (protocol
== FWS_PARK_ICONS
)
166 #if OSL_DEBUG_LEVEL > 1
167 fprintf (stderr
, "Using fwsParkIcons.\n");
171 if (protocol
== FWS_PASSES_INPUT
)
173 fwsPassesInput
= True
;
174 #if OSL_DEBUG_LEVEL > 1
175 fprintf (stderr
, "Using fwsPassesInput.\n");
179 if (protocol
== FWS_HANDLES_FOCUS
)
181 fwsHandlesFocus
= True
;
182 #if OSL_DEBUG_LEVEL > 1
183 fprintf (stderr
, "Using fwsHandlesFocus.\n");
192 /*************************************<->***********************************
196 * Handle X errors (temporarily) to record the occurance of BadWindow
197 * errors without crashing. Used to detect the FWS_COMM_WINDOW root window
198 * property containing an old or obsolete window id.
200 *************************************<->***********************************/
204 static Bool badWindowFound
;
205 static int (* oldHandler
) (Display
*, XErrorEvent
*);
208 newHandler (Display
*display
, XErrorEvent
*xerror
)
210 if (xerror
->error_code
!= BadWindow
)
211 (*oldHandler
)(display
, xerror
);
213 badWindowFound
= True
;
220 /*************************************<->***********************************
222 * RegisterFwsWindow() -
224 * Send a client message to the FWS_COMM_WINDOW indicating the existance
225 * of a new FWS client window. Be careful to avoid BadWindow errors on
226 * the XSendEvent in case the FWS_COMM_WINDOW root window property had
227 * old/obsolete junk in it.
229 *************************************<->***********************************/
232 RegisterFwsWindow (Display
*display
, Window window
)
234 XClientMessageEvent msg
;
236 msg
.type
= ClientMessage
;
237 msg
.window
= fwsCommWindow
;
238 msg
.message_type
= FWS_REGISTER_WINDOW
;
240 msg
.data
.l
[0] = window
;
242 XSync (display
, False
);
243 badWindowFound
= False
;
244 oldHandler
= XSetErrorHandler (newHandler
);
246 XSendEvent (display
, fwsCommWindow
, False
, NoEventMask
,
248 XSync (display
, False
);
250 XSetErrorHandler (oldHandler
);
251 #if OSL_DEBUG_LEVEL > 1
253 fprintf (stderr
, "No FWS client window to register with.\n");
256 return !badWindowFound
;
259 /*************************************<->***********************************
263 * Add the FWS protocol atoms to the WMProtocols property for the window.
265 *************************************<->***********************************/
268 AddFwsProtocols (Display
*display
, Window window
)
270 #define MAX_FWS_PROTOS 10
272 Atom fwsProtocols
[ MAX_FWS_PROTOS
];
275 fwsProtocols
[ nProtos
++ ] = FWS_CLIENT
;
276 fwsProtocols
[ nProtos
++ ] = FWS_STACK_UNDER
;
277 fwsProtocols
[ nProtos
++ ] = FWS_STATE_CHANGE
;
278 fwsProtocols
[ nProtos
++ ] = FWS_PASS_ALL_INPUT
;
279 XChangeProperty (display
, window
, WM_PROTOCOLS
,
280 XA_ATOM
, 32, PropModeAppend
,
281 (unsigned char *) fwsProtocols
, nProtos
);