2
|
1 |
/*
|
107
|
2 |
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Ported from awt_wm.c, SCCS v1.11, author Valeriy Ushakov
|
|
29 |
* Author: Denis Mikhalkin
|
|
30 |
*/
|
|
31 |
package sun.awt.X11;
|
|
32 |
|
|
33 |
import sun.misc.Unsafe;
|
107
|
34 |
import java.awt.Insets;
|
2
|
35 |
import java.awt.Frame;
|
|
36 |
import java.awt.Rectangle;
|
107
|
37 |
import java.util.Collection;
|
|
38 |
import java.util.HashMap;
|
|
39 |
import java.util.LinkedList;
|
2
|
40 |
import java.util.logging.Level;
|
|
41 |
import java.util.logging.Logger;
|
107
|
42 |
import java.util.regex.Matcher;
|
|
43 |
import java.util.regex.Pattern;
|
2
|
44 |
|
|
45 |
/**
|
|
46 |
* Class incapsulating knowledge about window managers in general
|
|
47 |
* Descendants should provide some information about specific window manager.
|
|
48 |
*/
|
107
|
49 |
final class XWM implements MWMConstants, XUtilConstants
|
|
50 |
{
|
2
|
51 |
|
|
52 |
private final static Logger log = Logger.getLogger("sun.awt.X11.XWM");
|
|
53 |
private final static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWM");
|
|
54 |
private final static Logger stateLog = Logger.getLogger("sun.awt.X11.states.XWM");
|
|
55 |
|
|
56 |
static final XAtom XA_MWM_HINTS = new XAtom();
|
|
57 |
|
|
58 |
private static Unsafe unsafe = XlibWrapper.unsafe;
|
|
59 |
|
|
60 |
|
|
61 |
/* Good old ICCCM */
|
|
62 |
static XAtom XA_WM_STATE = new XAtom();
|
|
63 |
|
|
64 |
|
|
65 |
XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING"); /* like STRING but encoding is UTF-8 */
|
|
66 |
|
|
67 |
/* Currently we only care about max_v and max_h in _NET_WM_STATE */
|
|
68 |
final static int AWT_NET_N_KNOWN_STATES=2;
|
|
69 |
|
|
70 |
/* Enlightenment */
|
|
71 |
final static XAtom XA_E_FRAME_SIZE = new XAtom();
|
|
72 |
|
|
73 |
/* KWin (KDE2) */
|
|
74 |
final static XAtom XA_KDE_NET_WM_FRAME_STRUT = new XAtom();
|
|
75 |
|
|
76 |
/* KWM (KDE 1.x) OBSOLETE??? */
|
|
77 |
final static XAtom XA_KWM_WIN_ICONIFIED = new XAtom();
|
|
78 |
final static XAtom XA_KWM_WIN_MAXIMIZED = new XAtom();
|
|
79 |
|
|
80 |
/* OpenLook */
|
|
81 |
final static XAtom XA_OL_DECOR_DEL = new XAtom();
|
|
82 |
final static XAtom XA_OL_DECOR_HEADER = new XAtom();
|
|
83 |
final static XAtom XA_OL_DECOR_RESIZE = new XAtom();
|
|
84 |
final static XAtom XA_OL_DECOR_PIN = new XAtom();
|
|
85 |
final static XAtom XA_OL_DECOR_CLOSE = new XAtom();
|
|
86 |
|
|
87 |
/* EWMH */
|
|
88 |
final static XAtom XA_NET_FRAME_EXTENTS = new XAtom();
|
|
89 |
final static XAtom XA_NET_REQUEST_FRAME_EXTENTS = new XAtom();
|
|
90 |
|
|
91 |
final static int
|
|
92 |
UNDETERMINED_WM = 1,
|
|
93 |
NO_WM = 2,
|
|
94 |
OTHER_WM = 3,
|
|
95 |
OPENLOOK_WM = 4,
|
|
96 |
MOTIF_WM = 5,
|
|
97 |
CDE_WM = 6,
|
|
98 |
ENLIGHTEN_WM = 7,
|
|
99 |
KDE2_WM = 8,
|
|
100 |
SAWFISH_WM = 9,
|
|
101 |
ICE_WM = 10,
|
|
102 |
METACITY_WM = 11,
|
|
103 |
COMPIZ_WM = 12,
|
|
104 |
LG3D_WM = 13;
|
|
105 |
public String toString() {
|
|
106 |
switch (WMID) {
|
|
107 |
case NO_WM:
|
|
108 |
return "NO WM";
|
|
109 |
case OTHER_WM:
|
|
110 |
return "Other WM";
|
|
111 |
case OPENLOOK_WM:
|
|
112 |
return "OPENLOOK";
|
|
113 |
case MOTIF_WM:
|
|
114 |
return "MWM";
|
|
115 |
case CDE_WM:
|
|
116 |
return "DTWM";
|
|
117 |
case ENLIGHTEN_WM:
|
|
118 |
return "Enlightenment";
|
|
119 |
case KDE2_WM:
|
|
120 |
return "KWM2";
|
|
121 |
case SAWFISH_WM:
|
|
122 |
return "Sawfish";
|
|
123 |
case ICE_WM:
|
|
124 |
return "IceWM";
|
|
125 |
case METACITY_WM:
|
|
126 |
return "Metacity";
|
|
127 |
case COMPIZ_WM:
|
|
128 |
return "Compiz";
|
|
129 |
case LG3D_WM:
|
|
130 |
return "LookingGlass";
|
|
131 |
case UNDETERMINED_WM:
|
|
132 |
default:
|
|
133 |
return "Undetermined WM";
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
|
|
138 |
int WMID;
|
|
139 |
static final Insets zeroInsets = new Insets(0, 0, 0, 0);
|
|
140 |
static final Insets defaultInsets = new Insets(25, 5, 5, 5);
|
|
141 |
|
|
142 |
XWM(int WMID) {
|
|
143 |
this.WMID = WMID;
|
|
144 |
initializeProtocols();
|
|
145 |
if (log.isLoggable(Level.FINE)) log.fine("Window manager: " + toString());
|
|
146 |
}
|
|
147 |
int getID() {
|
|
148 |
return WMID;
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
static Insets normalize(Insets insets) {
|
|
153 |
if (insets.top > 64 || insets.top < 0) {
|
|
154 |
insets.top = 28;
|
|
155 |
}
|
|
156 |
if (insets.left > 32 || insets.left < 0) {
|
|
157 |
insets.left = 6;
|
|
158 |
}
|
|
159 |
if (insets.right > 32 || insets.right < 0) {
|
|
160 |
insets.right = 6;
|
|
161 |
}
|
|
162 |
if (insets.bottom > 32 || insets.bottom < 0) {
|
|
163 |
insets.bottom = 6;
|
|
164 |
}
|
|
165 |
return insets;
|
|
166 |
}
|
|
167 |
|
|
168 |
static XNETProtocol g_net_protocol = null;
|
|
169 |
static XWINProtocol g_win_protocol = null;
|
|
170 |
static boolean isNetWMName(String name) {
|
|
171 |
if (g_net_protocol != null) {
|
|
172 |
return g_net_protocol.isWMName(name);
|
|
173 |
} else {
|
|
174 |
return false;
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
static void initAtoms() {
|
|
179 |
final Object[][] atomInitList ={
|
|
180 |
{ XA_WM_STATE, "WM_STATE" },
|
|
181 |
|
|
182 |
{ XA_KDE_NET_WM_FRAME_STRUT, "_KDE_NET_WM_FRAME_STRUT" },
|
|
183 |
|
|
184 |
{ XA_E_FRAME_SIZE, "_E_FRAME_SIZE" },
|
|
185 |
|
|
186 |
{ XA_KWM_WIN_ICONIFIED, "KWM_WIN_ICONIFIED" },
|
|
187 |
{ XA_KWM_WIN_MAXIMIZED, "KWM_WIN_MAXIMIZED" },
|
|
188 |
|
|
189 |
{ XA_OL_DECOR_DEL, "_OL_DECOR_DEL" },
|
|
190 |
{ XA_OL_DECOR_HEADER, "_OL_DECOR_HEADER" },
|
|
191 |
{ XA_OL_DECOR_RESIZE, "_OL_DECOR_RESIZE" },
|
|
192 |
{ XA_OL_DECOR_PIN, "_OL_DECOR_PIN" },
|
|
193 |
{ XA_OL_DECOR_CLOSE, "_OL_DECOR_CLOSE" },
|
|
194 |
{ XA_MWM_HINTS, "_MOTIF_WM_HINTS" },
|
|
195 |
{ XA_NET_FRAME_EXTENTS, "_NET_FRAME_EXTENTS" },
|
|
196 |
{ XA_NET_REQUEST_FRAME_EXTENTS, "_NET_REQUEST_FRAME_EXTENTS" },
|
|
197 |
};
|
|
198 |
|
|
199 |
String[] names = new String[atomInitList.length];
|
|
200 |
for (int index = 0; index < names.length; index++) {
|
|
201 |
names[index] = (String)atomInitList[index][1];
|
|
202 |
}
|
|
203 |
|
|
204 |
int atomSize = XAtom.getAtomSize();
|
|
205 |
long atoms = unsafe.allocateMemory(names.length*atomSize);
|
|
206 |
XToolkit.awtLock();
|
|
207 |
try {
|
|
208 |
int status = XlibWrapper.XInternAtoms(XToolkit.getDisplay(), names, false, atoms);
|
|
209 |
if (status == 0) {
|
|
210 |
return;
|
|
211 |
}
|
|
212 |
for (int atom = 0, atomPtr = 0; atom < names.length; atom++, atomPtr += atomSize) {
|
|
213 |
((XAtom)(atomInitList[atom][0])).setValues(XToolkit.getDisplay(), names[atom], XAtom.getAtom(atoms + atomPtr));
|
|
214 |
}
|
|
215 |
} finally {
|
|
216 |
XToolkit.awtUnlock();
|
|
217 |
unsafe.freeMemory(atoms);
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
/*
|
|
222 |
* MUST BE CALLED UNDER AWTLOCK.
|
|
223 |
*
|
|
224 |
* If *any* window manager is running?
|
|
225 |
*
|
|
226 |
* According to ICCCM 2.0 section 4.3.
|
|
227 |
* WM will acquire ownership of a selection named WM_Sn, where n is
|
|
228 |
* the screen number.
|
|
229 |
*
|
|
230 |
* No selection owner, but, perhaps it is not ICCCM compliant WM
|
|
231 |
* (e.g. CDE/Sawfish).
|
|
232 |
* Try selecting for SubstructureRedirect, that only one client
|
|
233 |
* can select for, and if the request fails, than some other WM is
|
|
234 |
* already running.
|
|
235 |
*
|
|
236 |
* We also treat eXcursion as NO_WM.
|
|
237 |
*/
|
|
238 |
private static boolean isNoWM() {
|
|
239 |
/*
|
|
240 |
* Quick checks for specific servers.
|
|
241 |
*/
|
|
242 |
String vendor_string = XlibWrapper.ServerVendor(XToolkit.getDisplay());
|
|
243 |
if (vendor_string.indexOf("eXcursion") != -1) {
|
|
244 |
/*
|
|
245 |
* Use NO_WM since in all other aspects eXcursion is like not
|
|
246 |
* having a window manager running. I.e. it does not reparent
|
|
247 |
* top level shells.
|
|
248 |
*/
|
|
249 |
if (insLog.isLoggable(Level.FINE)) {
|
|
250 |
insLog.finer("eXcursion means NO_WM");
|
|
251 |
}
|
|
252 |
return true;
|
|
253 |
}
|
|
254 |
|
|
255 |
XSetWindowAttributes substruct = new XSetWindowAttributes();
|
|
256 |
try {
|
|
257 |
/*
|
|
258 |
* Let's check an owner of WM_Sn selection for the default screen.
|
|
259 |
*/
|
|
260 |
final long default_screen_number =
|
|
261 |
XlibWrapper.DefaultScreen(XToolkit.getDisplay());
|
|
262 |
final String selection_name = "WM_S" + default_screen_number;
|
|
263 |
|
|
264 |
long selection_owner =
|
|
265 |
XlibWrapper.XGetSelectionOwner(XToolkit.getDisplay(),
|
|
266 |
XAtom.get(selection_name).getAtom());
|
|
267 |
if (insLog.isLoggable(Level.FINE)) {
|
|
268 |
insLog.finer("selection owner of " + selection_name
|
|
269 |
+ " is " + selection_owner);
|
|
270 |
}
|
|
271 |
|
|
272 |
if (selection_owner != XConstants.None) {
|
|
273 |
return false;
|
|
274 |
}
|
|
275 |
|
|
276 |
winmgr_running = false;
|
|
277 |
substruct.set_event_mask(XlibWrapper.SubstructureRedirectMask);
|
|
278 |
|
|
279 |
XToolkit.WITH_XERROR_HANDLER(DetectWMHandler);
|
|
280 |
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),
|
|
281 |
XToolkit.getDefaultRootWindow(),
|
|
282 |
XlibWrapper.CWEventMask,
|
|
283 |
substruct.pData);
|
|
284 |
XToolkit.RESTORE_XERROR_HANDLER();
|
|
285 |
|
|
286 |
/*
|
|
287 |
* If no WM is running then our selection for SubstructureRedirect
|
|
288 |
* succeeded and needs to be undone (hey we are *not* a WM ;-).
|
|
289 |
*/
|
|
290 |
if (!winmgr_running) {
|
|
291 |
substruct.set_event_mask(0);
|
|
292 |
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),
|
|
293 |
XToolkit.getDefaultRootWindow(),
|
|
294 |
XlibWrapper.CWEventMask,
|
|
295 |
substruct.pData);
|
|
296 |
if (insLog.isLoggable(Level.FINE)) {
|
|
297 |
insLog.finer("It looks like there is no WM thus NO_WM");
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
return !winmgr_running;
|
|
302 |
} finally {
|
|
303 |
substruct.dispose();
|
|
304 |
}
|
|
305 |
}
|
|
306 |
|
|
307 |
static XAtom XA_ENLIGHTENMENT_COMMS = new XAtom("ENLIGHTENMENT_COMMS", false);
|
|
308 |
/*
|
|
309 |
* Helper function for isEnlightenment().
|
|
310 |
* Enlightenment uses STRING property for its comms window id. Gaaa!
|
|
311 |
* The property is ENLIGHTENMENT_COMMS, STRING/8 and the string format
|
|
312 |
* is "WINID %8x". Gee, I haven't been using scanf for *ages*... :-)
|
|
313 |
*/
|
|
314 |
static long getECommsWindowIDProperty(long window) {
|
|
315 |
|
|
316 |
if (!XA_ENLIGHTENMENT_COMMS.isInterned()) {
|
|
317 |
return 0;
|
|
318 |
}
|
|
319 |
|
|
320 |
WindowPropertyGetter getter =
|
|
321 |
new WindowPropertyGetter(window, XA_ENLIGHTENMENT_COMMS, 0, 14, false,
|
|
322 |
XAtom.XA_STRING);
|
|
323 |
try {
|
|
324 |
int status = getter.execute(XToolkit.IgnoreBadWindowHandler);
|
|
325 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
326 |
return 0;
|
|
327 |
}
|
|
328 |
|
|
329 |
if (getter.getActualType() != XAtom.XA_STRING
|
|
330 |
|| getter.getActualFormat() != 8
|
|
331 |
|| getter.getNumberOfItems() != 14 || getter.getBytesAfter() != 0)
|
|
332 |
{
|
|
333 |
return 0;
|
|
334 |
}
|
|
335 |
|
|
336 |
// Convert data to String, ASCII
|
|
337 |
byte[] bytes = XlibWrapper.getStringBytes(getter.getData());
|
|
338 |
String id = new String(bytes);
|
|
339 |
|
|
340 |
log.finer("ENLIGHTENMENT_COMMS is " + id);
|
|
341 |
|
|
342 |
// Parse WINID
|
|
343 |
Pattern winIdPat = Pattern.compile("WINID\\s+(\\p{XDigit}{0,8})");
|
|
344 |
try {
|
|
345 |
Matcher match = winIdPat.matcher(id);
|
|
346 |
if (match.matches()) {
|
|
347 |
log.finest("Match group count: " + match.groupCount());
|
|
348 |
String longId = match.group(1);
|
|
349 |
log.finest("Match group 1 " + longId);
|
|
350 |
long winid = Long.parseLong(longId, 16);
|
|
351 |
log.finer("Enlightenment communication window " + winid);
|
|
352 |
return winid;
|
|
353 |
} else {
|
|
354 |
log.finer("ENLIGHTENMENT_COMMS has wrong format");
|
|
355 |
return 0;
|
|
356 |
}
|
|
357 |
} catch (Exception e) {
|
|
358 |
if (log.isLoggable(Level.FINER)) {
|
|
359 |
e.printStackTrace();
|
|
360 |
}
|
|
361 |
return 0;
|
|
362 |
}
|
|
363 |
} finally {
|
|
364 |
getter.dispose();
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
/*
|
|
369 |
* Is Enlightenment WM running? Congruent to awt_wm_checkAnchor, but
|
|
370 |
* uses STRING property peculiar to Enlightenment.
|
|
371 |
*/
|
|
372 |
static boolean isEnlightenment() {
|
|
373 |
|
|
374 |
long root_xref = getECommsWindowIDProperty(XToolkit.getDefaultRootWindow());
|
|
375 |
if (root_xref == 0) {
|
|
376 |
return false;
|
|
377 |
}
|
|
378 |
|
|
379 |
long self_xref = getECommsWindowIDProperty(root_xref);
|
|
380 |
if (self_xref != root_xref) {
|
|
381 |
return false;
|
|
382 |
}
|
|
383 |
|
|
384 |
return true;
|
|
385 |
}
|
|
386 |
|
|
387 |
/*
|
|
388 |
* Is CDE running?
|
|
389 |
*
|
|
390 |
* XXX: This is hairy... CDE is MWM as well. It seems we simply test
|
|
391 |
* for default setup and will be bitten if user changes things...
|
|
392 |
*
|
|
393 |
* Check for _DT_SM_WINDOW_INFO(_DT_SM_WINDOW_INFO) on root. Take the
|
|
394 |
* second element of the property and check for presence of
|
|
395 |
* _DT_SM_STATE_INFO(_DT_SM_STATE_INFO) on that window.
|
|
396 |
*
|
|
397 |
* XXX: Any header that defines this structures???
|
|
398 |
*/
|
|
399 |
static final XAtom XA_DT_SM_WINDOW_INFO = new XAtom("_DT_SM_WINDOW_INFO", false);
|
|
400 |
static final XAtom XA_DT_SM_STATE_INFO = new XAtom("_DT_SM_STATE_INFO", false);
|
|
401 |
static boolean isCDE() {
|
|
402 |
|
|
403 |
if (!XA_DT_SM_WINDOW_INFO.isInterned()) {
|
|
404 |
log.log(Level.FINER, "{0} is not interned", new Object[] {XA_DT_SM_WINDOW_INFO});
|
|
405 |
return false;
|
|
406 |
}
|
|
407 |
|
|
408 |
WindowPropertyGetter getter =
|
|
409 |
new WindowPropertyGetter(XToolkit.getDefaultRootWindow(),
|
|
410 |
XA_DT_SM_WINDOW_INFO, 0, 2,
|
|
411 |
false, XA_DT_SM_WINDOW_INFO);
|
|
412 |
try {
|
|
413 |
int status = getter.execute();
|
|
414 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
415 |
log.finer("Getting of _DT_SM_WINDOW_INFO is not successfull");
|
|
416 |
return false;
|
|
417 |
}
|
|
418 |
if (getter.getActualType() != XA_DT_SM_WINDOW_INFO.getAtom()
|
|
419 |
|| getter.getActualFormat() != 32
|
|
420 |
|| getter.getNumberOfItems() != 2 || getter.getBytesAfter() != 0)
|
|
421 |
{
|
|
422 |
log.finer("Wrong format of _DT_SM_WINDOW_INFO");
|
|
423 |
return false;
|
|
424 |
}
|
|
425 |
|
|
426 |
long wmwin = Native.getWindow(getter.getData(), 1); //unsafe.getInt(getter.getData()+4);
|
|
427 |
|
|
428 |
if (wmwin == 0) {
|
|
429 |
log.fine("WARNING: DT_SM_WINDOW_INFO exists but returns zero windows");
|
|
430 |
return false;
|
|
431 |
}
|
|
432 |
|
|
433 |
/* Now check that this window has _DT_SM_STATE_INFO (ignore contents) */
|
|
434 |
if (!XA_DT_SM_STATE_INFO.isInterned()) {
|
|
435 |
log.log(Level.FINER, "{0} is not interned", new Object[] {XA_DT_SM_STATE_INFO});
|
|
436 |
return false;
|
|
437 |
}
|
|
438 |
WindowPropertyGetter getter2 =
|
|
439 |
new WindowPropertyGetter(wmwin, XA_DT_SM_STATE_INFO, 0, 1,
|
|
440 |
false, XA_DT_SM_STATE_INFO);
|
|
441 |
try {
|
|
442 |
status = getter2.execute(XToolkit.IgnoreBadWindowHandler);
|
|
443 |
|
|
444 |
|
|
445 |
if (status != XlibWrapper.Success || getter2.getData() == 0) {
|
|
446 |
log.finer("Getting of _DT_SM_STATE_INFO is not successfull");
|
|
447 |
return false;
|
|
448 |
}
|
|
449 |
if (getter2.getActualType() != XA_DT_SM_STATE_INFO.getAtom()
|
|
450 |
|| getter2.getActualFormat() != 32)
|
|
451 |
{
|
|
452 |
log.finer("Wrong format of _DT_SM_STATE_INFO");
|
|
453 |
return false;
|
|
454 |
}
|
|
455 |
|
|
456 |
return true;
|
|
457 |
} finally {
|
|
458 |
getter2.dispose();
|
|
459 |
}
|
|
460 |
} finally {
|
|
461 |
getter.dispose();
|
|
462 |
}
|
|
463 |
}
|
|
464 |
|
|
465 |
/*
|
|
466 |
* Is MWM running? (Note that CDE will test positive as well).
|
|
467 |
*
|
|
468 |
* Check for _MOTIF_WM_INFO(_MOTIF_WM_INFO) on root. Take the
|
|
469 |
* second element of the property and check for presence of
|
|
470 |
* _DT_SM_STATE_INFO(_DT_SM_STATE_INFO) on that window.
|
|
471 |
*/
|
|
472 |
static final XAtom XA_MOTIF_WM_INFO = new XAtom("_MOTIF_WM_INFO", false);
|
|
473 |
static final XAtom XA_DT_WORKSPACE_CURRENT = new XAtom("_DT_WORKSPACE_CURRENT", false);
|
|
474 |
static boolean isMotif() {
|
|
475 |
|
|
476 |
if (!(XA_MOTIF_WM_INFO.isInterned()/* && XA_DT_WORKSPACE_CURRENT.isInterned()*/) ) {
|
|
477 |
return false;
|
|
478 |
}
|
|
479 |
|
|
480 |
WindowPropertyGetter getter =
|
|
481 |
new WindowPropertyGetter(XToolkit.getDefaultRootWindow(),
|
|
482 |
XA_MOTIF_WM_INFO, 0,
|
|
483 |
PROP_MOTIF_WM_INFO_ELEMENTS,
|
|
484 |
false, XA_MOTIF_WM_INFO);
|
|
485 |
try {
|
|
486 |
int status = getter.execute();
|
|
487 |
|
|
488 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
489 |
return false;
|
|
490 |
}
|
|
491 |
|
|
492 |
if (getter.getActualType() != XA_MOTIF_WM_INFO.getAtom()
|
|
493 |
|| getter.getActualFormat() != 32
|
|
494 |
|| getter.getNumberOfItems() != PROP_MOTIF_WM_INFO_ELEMENTS
|
|
495 |
|| getter.getBytesAfter() != 0)
|
|
496 |
{
|
|
497 |
return false;
|
|
498 |
}
|
|
499 |
|
|
500 |
long wmwin = Native.getLong(getter.getData(), 1);
|
|
501 |
if (wmwin != 0) {
|
|
502 |
if (XA_DT_WORKSPACE_CURRENT.isInterned()) {
|
|
503 |
/* Now check that this window has _DT_WORKSPACE_CURRENT */
|
|
504 |
XAtom[] curws = XA_DT_WORKSPACE_CURRENT.getAtomListProperty(wmwin);
|
|
505 |
if (curws.length == 0) {
|
|
506 |
return false;
|
|
507 |
}
|
|
508 |
return true;
|
|
509 |
} else {
|
|
510 |
// No DT_WORKSPACE, however in our tests MWM sometimes can be without desktop -
|
|
511 |
// and that is still MWM. So simply check for the validity of this window
|
|
512 |
// (through WM_STATE property).
|
|
513 |
WindowPropertyGetter state_getter =
|
|
514 |
new WindowPropertyGetter(wmwin,
|
|
515 |
XA_WM_STATE,
|
|
516 |
0, 1, false,
|
|
517 |
XA_WM_STATE);
|
|
518 |
try {
|
|
519 |
if (state_getter.execute() == XlibWrapper.Success &&
|
|
520 |
state_getter.getData() != 0 &&
|
|
521 |
state_getter.getActualType() == XA_WM_STATE.getAtom())
|
|
522 |
{
|
|
523 |
return true;
|
|
524 |
}
|
|
525 |
} finally {
|
|
526 |
state_getter.dispose();
|
|
527 |
}
|
|
528 |
}
|
|
529 |
}
|
|
530 |
} finally {
|
|
531 |
getter.dispose();
|
|
532 |
}
|
|
533 |
return false;
|
|
534 |
}
|
|
535 |
|
|
536 |
/*
|
|
537 |
* Is Sawfish running?
|
|
538 |
*/
|
|
539 |
static boolean isSawfish() {
|
|
540 |
return isNetWMName("Sawfish");
|
|
541 |
}
|
|
542 |
|
|
543 |
/*
|
|
544 |
* Is KDE2 (KWin) running?
|
|
545 |
*/
|
|
546 |
static boolean isKDE2() {
|
|
547 |
return isNetWMName("KWin");
|
|
548 |
}
|
|
549 |
|
|
550 |
static boolean isCompiz() {
|
|
551 |
return isNetWMName("compiz");
|
|
552 |
}
|
|
553 |
|
|
554 |
static boolean isLookingGlass() {
|
|
555 |
return isNetWMName("LG3D");
|
|
556 |
}
|
|
557 |
|
|
558 |
/*
|
|
559 |
* Is Metacity running?
|
|
560 |
*/
|
|
561 |
static boolean isMetacity() {
|
|
562 |
return isNetWMName("Metacity");
|
|
563 |
// || (
|
|
564 |
// XA_NET_SUPPORTING_WM_CHECK.
|
|
565 |
// getIntProperty(XToolkit.getDefaultRootWindow(), XA_NET_SUPPORTING_WM_CHECK.
|
|
566 |
// getIntProperty(XToolkit.getDefaultRootWindow(), XAtom.XA_CARDINAL)) == 0);
|
|
567 |
}
|
|
568 |
|
|
569 |
static boolean isNonReparentingWM() {
|
|
570 |
return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM);
|
|
571 |
}
|
|
572 |
|
|
573 |
/*
|
|
574 |
* Temporary error handler that ensures that we know if
|
|
575 |
* XChangeProperty succeeded or not.
|
|
576 |
*/
|
|
577 |
static XToolkit.XErrorHandler VerifyChangePropertyHandler = new XToolkit.XErrorHandler() {
|
|
578 |
public int handleError(long display, XErrorEvent err) {
|
|
579 |
XToolkit.XERROR_SAVE(err);
|
|
580 |
if (err.get_request_code() == XlibWrapper.X_ChangeProperty) {
|
|
581 |
return 0;
|
|
582 |
} else {
|
|
583 |
return XToolkit.SAVED_ERROR_HANDLER(display, err);
|
|
584 |
}
|
|
585 |
}
|
|
586 |
};
|
|
587 |
|
|
588 |
/*
|
|
589 |
* Prepare IceWM check.
|
|
590 |
*
|
|
591 |
* The only way to detect IceWM, seems to be by setting
|
|
592 |
* _ICEWM_WINOPTHINT(_ICEWM_WINOPTHINT/8) on root and checking if it
|
|
593 |
* was immediately deleted by IceWM.
|
|
594 |
*
|
|
595 |
* But messing with PropertyNotify here is way too much trouble, so
|
|
596 |
* approximate the check by setting the property in this function and
|
|
597 |
* checking if it still exists later on.
|
|
598 |
*
|
|
599 |
* Gaa, dirty dances...
|
|
600 |
*/
|
|
601 |
static final XAtom XA_ICEWM_WINOPTHINT = new XAtom("_ICEWM_WINOPTHINT", false);
|
|
602 |
static final char opt[] = {
|
|
603 |
'A','W','T','_','I','C','E','W','M','_','T','E','S','T','\0',
|
|
604 |
'a','l','l','W','o','r','k','s','p','a','c','e','s','\0',
|
|
605 |
'0','\0'
|
|
606 |
};
|
|
607 |
static boolean prepareIsIceWM() {
|
|
608 |
/*
|
|
609 |
* Choose something innocuous: "AWT_ICEWM_TEST allWorkspaces 0".
|
|
610 |
* IceWM expects "class\0option\0arg\0" with zero bytes as delimiters.
|
|
611 |
*/
|
|
612 |
|
|
613 |
if (!XA_ICEWM_WINOPTHINT.isInterned()) {
|
|
614 |
log.log(Level.FINER, "{0} is not interned", new Object[] {XA_ICEWM_WINOPTHINT});
|
|
615 |
return false;
|
|
616 |
}
|
|
617 |
|
|
618 |
XToolkit.awtLock();
|
|
619 |
try {
|
|
620 |
XToolkit.WITH_XERROR_HANDLER(VerifyChangePropertyHandler);
|
|
621 |
XlibWrapper.XChangePropertyS(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
|
|
622 |
XA_ICEWM_WINOPTHINT.getAtom(),
|
|
623 |
XA_ICEWM_WINOPTHINT.getAtom(),
|
|
624 |
8, XlibWrapper.PropModeReplace,
|
|
625 |
new String(opt));
|
|
626 |
XToolkit.RESTORE_XERROR_HANDLER();
|
|
627 |
|
|
628 |
if (XToolkit.saved_error != null && XToolkit.saved_error.get_error_code() != XlibWrapper.Success) {
|
|
629 |
log.finer("Erorr getting XA_ICEWM_WINOPTHINT property");
|
|
630 |
return false;
|
|
631 |
}
|
|
632 |
log.finer("Prepared for IceWM detection");
|
|
633 |
return true;
|
|
634 |
} finally {
|
|
635 |
XToolkit.awtUnlock();
|
|
636 |
}
|
|
637 |
}
|
|
638 |
|
|
639 |
/*
|
|
640 |
* Is IceWM running?
|
|
641 |
*
|
|
642 |
* Note well: Only call this if awt_wm_prepareIsIceWM succeeded, or a
|
|
643 |
* false positive will be reported.
|
|
644 |
*/
|
|
645 |
static boolean isIceWM() {
|
|
646 |
if (!XA_ICEWM_WINOPTHINT.isInterned()) {
|
|
647 |
log.log(Level.FINER, "{0} is not interned", new Object[] {XA_ICEWM_WINOPTHINT});
|
|
648 |
return false;
|
|
649 |
}
|
|
650 |
|
|
651 |
WindowPropertyGetter getter =
|
|
652 |
new WindowPropertyGetter(XToolkit.getDefaultRootWindow(),
|
|
653 |
XA_ICEWM_WINOPTHINT, 0, 0xFFFF,
|
|
654 |
true, XA_ICEWM_WINOPTHINT);
|
|
655 |
try {
|
|
656 |
int status = getter.execute();
|
|
657 |
boolean res = (status == XlibWrapper.Success && getter.getActualType() != 0);
|
|
658 |
log.finer("Status getting XA_ICEWM_WINOPTHINT: " + !res);
|
|
659 |
return !res || isNetWMName("IceWM");
|
|
660 |
} finally {
|
|
661 |
getter.dispose();
|
|
662 |
}
|
|
663 |
}
|
|
664 |
|
|
665 |
/*
|
|
666 |
* Is OpenLook WM running?
|
|
667 |
*
|
|
668 |
* This one is pretty lame, but the only property peculiar to OLWM is
|
|
669 |
* _SUN_WM_PROTOCOLS(ATOM[]). Fortunately, olwm deletes it on exit.
|
|
670 |
*/
|
|
671 |
static final XAtom XA_SUN_WM_PROTOCOLS = new XAtom("_SUN_WM_PROTOCOLS", false);
|
|
672 |
static boolean isOpenLook() {
|
|
673 |
if (!XA_SUN_WM_PROTOCOLS.isInterned()) {
|
|
674 |
return false;
|
|
675 |
}
|
|
676 |
|
|
677 |
XAtom[] list = XA_SUN_WM_PROTOCOLS.getAtomListProperty(XToolkit.getDefaultRootWindow());
|
|
678 |
return (list.length != 0);
|
|
679 |
}
|
|
680 |
|
|
681 |
/*
|
|
682 |
* Temporary error handler that checks if selecting for
|
|
683 |
* SubstructureRedirect failed.
|
|
684 |
*/
|
|
685 |
static boolean winmgr_running = false;
|
|
686 |
static XToolkit.XErrorHandler DetectWMHandler = new XToolkit.XErrorHandler() {
|
|
687 |
public int handleError(long display, XErrorEvent err) {
|
|
688 |
XToolkit.XERROR_SAVE(err);
|
|
689 |
if (err.get_request_code() == XlibWrapper.X_ChangeWindowAttributes
|
|
690 |
&& err.get_error_code() == XlibWrapper.BadAccess)
|
|
691 |
{
|
|
692 |
winmgr_running = true;
|
|
693 |
return 0;
|
|
694 |
} else {
|
|
695 |
return XToolkit.SAVED_ERROR_HANDLER(display, err);
|
|
696 |
}
|
|
697 |
}
|
|
698 |
};
|
|
699 |
|
|
700 |
/*
|
|
701 |
* Make an educated guess about running window manager.
|
|
702 |
* XXX: ideally, we should detect wm restart.
|
|
703 |
*/
|
|
704 |
static int awt_wmgr = XWM.UNDETERMINED_WM;
|
|
705 |
static XWM wm;
|
|
706 |
static XWM getWM() {
|
|
707 |
if (wm == null) {
|
|
708 |
wm = new XWM(awt_wmgr = getWMID()/*XWM.OTHER_WM*/);
|
|
709 |
}
|
|
710 |
return wm;
|
|
711 |
}
|
|
712 |
static int getWMID() {
|
|
713 |
if (insLog.isLoggable(Level.FINEST)) {
|
|
714 |
insLog.finest("awt_wmgr = " + awt_wmgr);
|
|
715 |
}
|
|
716 |
/*
|
|
717 |
* Ideally, we should support cases when a different WM is started
|
|
718 |
* during a Java app lifetime.
|
|
719 |
*/
|
|
720 |
|
|
721 |
if (awt_wmgr != XWM.UNDETERMINED_WM) {
|
|
722 |
return awt_wmgr;
|
|
723 |
}
|
|
724 |
|
|
725 |
XSetWindowAttributes substruct = new XSetWindowAttributes();
|
|
726 |
XToolkit.awtLock();
|
|
727 |
try {
|
|
728 |
if (isNoWM()) {
|
|
729 |
awt_wmgr = XWM.NO_WM;
|
|
730 |
return awt_wmgr;
|
|
731 |
}
|
|
732 |
|
|
733 |
// Initialize _NET protocol - used to detect Window Manager.
|
|
734 |
// Later, WM will initialize its own version of protocol
|
|
735 |
XNETProtocol l_net_protocol = g_net_protocol = new XNETProtocol();
|
|
736 |
l_net_protocol.detect();
|
|
737 |
if (log.isLoggable(Level.FINE) && l_net_protocol.active()) {
|
|
738 |
log.fine("_NET_WM_NAME is " + l_net_protocol.getWMName());
|
|
739 |
}
|
|
740 |
XWINProtocol win = g_win_protocol = new XWINProtocol();
|
|
741 |
win.detect();
|
|
742 |
|
|
743 |
/* actual check for IceWM to follow below */
|
|
744 |
boolean doIsIceWM = prepareIsIceWM(); /* and let IceWM to act */
|
|
745 |
|
|
746 |
/*
|
|
747 |
* Ok, some WM is out there. Check which one by testing for
|
|
748 |
* "distinguishing" atoms.
|
|
749 |
*/
|
|
750 |
if (isEnlightenment()) {
|
|
751 |
awt_wmgr = XWM.ENLIGHTEN_WM;
|
|
752 |
} else if (isMetacity()) {
|
|
753 |
awt_wmgr = XWM.METACITY_WM;
|
|
754 |
} else if (isSawfish()) {
|
|
755 |
awt_wmgr = XWM.SAWFISH_WM;
|
|
756 |
} else if (isKDE2()) {
|
|
757 |
awt_wmgr =XWM.KDE2_WM;
|
|
758 |
} else if (isCompiz()) {
|
|
759 |
awt_wmgr = XWM.COMPIZ_WM;
|
|
760 |
} else if (isLookingGlass()) {
|
|
761 |
awt_wmgr = LG3D_WM;
|
|
762 |
} else if (doIsIceWM && isIceWM()) {
|
|
763 |
awt_wmgr = XWM.ICE_WM;
|
|
764 |
}
|
|
765 |
/*
|
|
766 |
* We don't check for legacy WM when we already know that WM
|
|
767 |
* supports WIN or _NET wm spec.
|
|
768 |
*/
|
|
769 |
else if (l_net_protocol.active()) {
|
|
770 |
awt_wmgr = XWM.OTHER_WM;
|
|
771 |
} else if (win.active()) {
|
|
772 |
awt_wmgr = XWM.OTHER_WM;
|
|
773 |
}
|
|
774 |
/*
|
|
775 |
* Check for legacy WMs.
|
|
776 |
*/
|
|
777 |
else if (isCDE()) { /* XXX: must come before isMotif */
|
|
778 |
awt_wmgr = XWM.CDE_WM;
|
|
779 |
} else if (isMotif()) {
|
|
780 |
awt_wmgr = XWM.MOTIF_WM;
|
|
781 |
} else if (isOpenLook()) {
|
|
782 |
awt_wmgr = XWM.OPENLOOK_WM;
|
|
783 |
} else {
|
|
784 |
awt_wmgr = XWM.OTHER_WM;
|
|
785 |
}
|
|
786 |
|
|
787 |
return awt_wmgr;
|
|
788 |
} finally {
|
|
789 |
XToolkit.awtUnlock();
|
|
790 |
substruct.dispose();
|
|
791 |
}
|
|
792 |
}
|
|
793 |
|
|
794 |
|
|
795 |
/*****************************************************************************\
|
|
796 |
*
|
|
797 |
* Size and decoration hints ...
|
|
798 |
*
|
|
799 |
\*****************************************************************************/
|
|
800 |
|
|
801 |
|
|
802 |
/*
|
|
803 |
* Remove size hints specified by the mask.
|
|
804 |
* XXX: Why do we need this in the first place???
|
|
805 |
*/
|
|
806 |
static void removeSizeHints(XDecoratedPeer window, long mask) {
|
|
807 |
mask &= PMaxSize | PMinSize;
|
|
808 |
|
|
809 |
XToolkit.awtLock();
|
|
810 |
try {
|
|
811 |
XSizeHints hints = window.getHints();
|
|
812 |
if ((hints.get_flags() & mask) == 0) {
|
|
813 |
return;
|
|
814 |
}
|
|
815 |
|
|
816 |
hints.set_flags(hints.get_flags() & ~mask);
|
|
817 |
if (insLog.isLoggable(Level.FINER)) insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));
|
|
818 |
XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(),
|
|
819 |
window.getWindow(),
|
|
820 |
hints.pData);
|
|
821 |
} finally {
|
|
822 |
XToolkit.awtUnlock();
|
|
823 |
}
|
|
824 |
}
|
|
825 |
|
|
826 |
/*
|
|
827 |
* If MWM_DECOR_ALL bit is set, then the rest of the bit-mask is taken
|
|
828 |
* to be subtracted from the decorations. Normalize decoration spec
|
|
829 |
* so that we can map motif decor to something else bit-by-bit in the
|
|
830 |
* rest of the code.
|
|
831 |
*/
|
|
832 |
static int normalizeMotifDecor(int decorations) {
|
|
833 |
if ((decorations & MWM_DECOR_ALL) == 0) {
|
|
834 |
return decorations;
|
|
835 |
}
|
|
836 |
int d = MWM_DECOR_BORDER | MWM_DECOR_RESIZEH
|
|
837 |
| MWM_DECOR_TITLE
|
|
838 |
| MWM_DECOR_MENU | MWM_DECOR_MINIMIZE
|
|
839 |
| MWM_DECOR_MAXIMIZE;
|
|
840 |
d &= ~decorations;
|
|
841 |
return d;
|
|
842 |
}
|
|
843 |
|
|
844 |
/*
|
|
845 |
* If MWM_FUNC_ALL bit is set, then the rest of the bit-mask is taken
|
|
846 |
* to be subtracted from the functions. Normalize function spec
|
|
847 |
* so that we can map motif func to something else bit-by-bit in the
|
|
848 |
* rest of the code.
|
|
849 |
*/
|
|
850 |
static int normalizeMotifFunc(int functions) {
|
|
851 |
if ((functions & MWM_FUNC_ALL) == 0) {
|
|
852 |
return functions;
|
|
853 |
}
|
|
854 |
int f = MWM_FUNC_RESIZE |
|
|
855 |
MWM_FUNC_MOVE |
|
|
856 |
MWM_FUNC_MAXIMIZE |
|
|
857 |
MWM_FUNC_MINIMIZE |
|
|
858 |
MWM_FUNC_CLOSE;
|
|
859 |
f &= ~functions;
|
|
860 |
return f;
|
|
861 |
}
|
|
862 |
|
|
863 |
/*
|
|
864 |
* Infer OL properties from MWM decorations.
|
|
865 |
* Use _OL_DECOR_DEL(ATOM[]) to remove unwanted ones.
|
|
866 |
*/
|
|
867 |
static void setOLDecor(XWindow window, boolean resizable, int decorations) {
|
|
868 |
if (window == null) {
|
|
869 |
return;
|
|
870 |
}
|
|
871 |
|
|
872 |
XAtomList decorDel = new XAtomList();
|
|
873 |
decorations = normalizeMotifDecor(decorations);
|
|
874 |
if (insLog.isLoggable(Level.FINER)) insLog.finer("Setting OL_DECOR to " + Integer.toBinaryString(decorations));
|
|
875 |
if ((decorations & MWM_DECOR_TITLE) == 0) {
|
|
876 |
decorDel.add(XA_OL_DECOR_HEADER);
|
|
877 |
}
|
|
878 |
if ((decorations & (MWM_DECOR_RESIZEH | MWM_DECOR_MAXIMIZE)) == 0) {
|
|
879 |
decorDel.add(XA_OL_DECOR_RESIZE);
|
|
880 |
}
|
|
881 |
if ((decorations & (MWM_DECOR_MENU |
|
|
882 |
MWM_DECOR_MAXIMIZE |
|
|
883 |
MWM_DECOR_MINIMIZE)) == 0)
|
|
884 |
{
|
|
885 |
decorDel.add(XA_OL_DECOR_CLOSE);
|
|
886 |
}
|
|
887 |
if (decorDel.size() == 0) {
|
|
888 |
insLog.finer("Deleting OL_DECOR");
|
|
889 |
XA_OL_DECOR_DEL.DeleteProperty(window);
|
|
890 |
} else {
|
|
891 |
if (insLog.isLoggable(Level.FINER)) insLog.finer("Setting OL_DECOR to " + decorDel);
|
|
892 |
XA_OL_DECOR_DEL.setAtomListProperty(window, decorDel);
|
|
893 |
}
|
|
894 |
}
|
|
895 |
|
|
896 |
/*
|
|
897 |
* Set MWM decorations. Set MWM functions depending on resizability.
|
|
898 |
*/
|
|
899 |
static void setMotifDecor(XWindowPeer window, boolean resizable, int decorations, int functions) {
|
|
900 |
/* Apparently some WMs don't implement MWM_*_ALL semantic correctly */
|
|
901 |
if ((decorations & MWM_DECOR_ALL) != 0
|
|
902 |
&& (decorations != MWM_DECOR_ALL))
|
|
903 |
{
|
|
904 |
decorations = normalizeMotifDecor(decorations);
|
|
905 |
}
|
|
906 |
if ((functions & MWM_FUNC_ALL) != 0
|
|
907 |
&& (functions != MWM_FUNC_ALL))
|
|
908 |
{
|
|
909 |
functions = normalizeMotifFunc(functions);
|
|
910 |
}
|
|
911 |
|
|
912 |
PropMwmHints hints = window.getMWMHints();
|
|
913 |
hints.set_flags(hints.get_flags() | MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS);
|
|
914 |
hints.set_functions(functions);
|
|
915 |
hints.set_decorations(decorations);
|
|
916 |
|
|
917 |
if (stateLog.isLoggable(Level.FINER)) stateLog.finer("Setting MWM_HINTS to " + hints);
|
|
918 |
window.setMWMHints(hints);
|
|
919 |
}
|
|
920 |
|
|
921 |
/*
|
|
922 |
* Under some window managers if shell is already mapped, we MUST
|
|
923 |
* unmap and later remap in order to effect the changes we make in the
|
|
924 |
* window manager decorations.
|
|
925 |
*
|
|
926 |
* N.B. This unmapping / remapping of the shell exposes a bug in
|
|
927 |
* X/Motif or the Motif Window Manager. When you attempt to map a
|
|
928 |
* widget which is positioned (partially) off-screen, the window is
|
|
929 |
* relocated to be entirely on screen. Good idea. But if both the x
|
|
930 |
* and the y coordinates are less than the origin (0,0), the first
|
|
931 |
* (re)map will move the window to the origin, and any subsequent
|
|
932 |
* (re)map will relocate the window at some other point on the screen.
|
|
933 |
* I have written a short Motif test program to discover this bug.
|
|
934 |
* This should occur infrequently and it does not cause any real
|
|
935 |
* problem. So for now we'll let it be.
|
|
936 |
*/
|
|
937 |
static boolean needRemap(XDecoratedPeer window) {
|
|
938 |
// Don't remap EmbeddedFrame,
|
|
939 |
// e.g. for TrayIcon it causes problems.
|
|
940 |
return !window.isEmbedded();
|
|
941 |
}
|
|
942 |
|
|
943 |
/*
|
|
944 |
* Set decoration hints on the shell to wdata->decor adjusted
|
|
945 |
* appropriately if not resizable.
|
|
946 |
*/
|
|
947 |
static void setShellDecor(XDecoratedPeer window) {
|
|
948 |
int decorations = window.getDecorations();
|
|
949 |
int functions = window.getFunctions();
|
|
950 |
boolean resizable = window.isResizable();
|
|
951 |
|
|
952 |
if (!resizable) {
|
|
953 |
if ((decorations & MWM_DECOR_ALL) != 0) {
|
|
954 |
decorations |= MWM_DECOR_RESIZEH | MWM_DECOR_MAXIMIZE;
|
|
955 |
} else {
|
|
956 |
decorations &= ~(MWM_DECOR_RESIZEH | MWM_DECOR_MAXIMIZE);
|
|
957 |
}
|
|
958 |
}
|
|
959 |
setMotifDecor(window, resizable, decorations, functions);
|
|
960 |
setOLDecor(window, resizable, decorations);
|
|
961 |
|
|
962 |
/* Some WMs need remap to redecorate the window */
|
|
963 |
if (window.isShowing() && needRemap(window)) {
|
|
964 |
/*
|
|
965 |
* Do the re/mapping at the Xlib level. Since we essentially
|
|
966 |
* work around a WM bug we don't want this hack to be exposed
|
|
967 |
* to Intrinsics (i.e. don't mess with grabs, callbacks etc).
|
|
968 |
*/
|
|
969 |
window.xSetVisible(false);
|
|
970 |
XToolkit.XSync();
|
|
971 |
window.xSetVisible(true);
|
|
972 |
}
|
|
973 |
}
|
|
974 |
|
|
975 |
/*
|
|
976 |
* Make specified shell resizable.
|
|
977 |
*/
|
|
978 |
static void setShellResizable(XDecoratedPeer window) {
|
|
979 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell resizable " + window);
|
|
980 |
XToolkit.awtLock();
|
|
981 |
try {
|
|
982 |
Rectangle shellBounds = window.getShellBounds();
|
|
983 |
shellBounds.translate(-window.currentInsets.left, -window.currentInsets.top);
|
|
984 |
window.updateSizeHints(window.getDimensions());
|
|
985 |
requestWMExtents(window.getWindow());
|
|
986 |
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
|
|
987 |
shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
|
|
988 |
/* REMINDER: will need to revisit when setExtendedStateBounds is added */
|
|
989 |
//Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
|
|
990 |
//We need to update frame's minimum size, not to reset it
|
|
991 |
removeSizeHints(window, PMaxSize);
|
|
992 |
window.updateMinimumSize();
|
|
993 |
|
|
994 |
/* Restore decorations */
|
|
995 |
setShellDecor(window);
|
|
996 |
} finally {
|
|
997 |
XToolkit.awtUnlock();
|
|
998 |
}
|
|
999 |
}
|
|
1000 |
|
|
1001 |
/*
|
|
1002 |
* Make specified shell non-resizable.
|
|
1003 |
* If justChangeSize is false, update decorations as well.
|
|
1004 |
* @param shellBounds bounds of the shell window
|
|
1005 |
*/
|
|
1006 |
static void setShellNotResizable(XDecoratedPeer window, WindowDimensions newDimensions, Rectangle shellBounds,
|
|
1007 |
boolean justChangeSize)
|
|
1008 |
{
|
|
1009 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting non-resizable shell " + window + ", dimensions " + newDimensions +
|
|
1010 |
", shellBounds " + shellBounds +", just change size: " + justChangeSize);
|
|
1011 |
XToolkit.awtLock();
|
|
1012 |
try {
|
|
1013 |
/* Fix min/max size hints at the specified values */
|
|
1014 |
if (!shellBounds.isEmpty()) {
|
|
1015 |
window.updateSizeHints(newDimensions);
|
|
1016 |
requestWMExtents(window.getWindow());
|
|
1017 |
XToolkit.XSync();
|
|
1018 |
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
|
|
1019 |
shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
|
|
1020 |
}
|
|
1021 |
if (!justChangeSize) { /* update decorations */
|
|
1022 |
setShellDecor(window);
|
|
1023 |
}
|
|
1024 |
} finally {
|
|
1025 |
XToolkit.awtUnlock();
|
|
1026 |
}
|
|
1027 |
}
|
|
1028 |
|
|
1029 |
/*****************************************************************************\
|
|
1030 |
* Protocols support
|
|
1031 |
*/
|
107
|
1032 |
private HashMap<Class<?>, Collection<?>> protocolsMap = new HashMap<Class<?>, Collection<?>>();
|
2
|
1033 |
/**
|
|
1034 |
* Returns all protocols supporting given protocol interface
|
|
1035 |
*/
|
107
|
1036 |
<T> Collection<T> getProtocols(Class<T> protocolInterface) {
|
|
1037 |
Collection<T> res = (Collection<T>) protocolsMap.get(protocolInterface);
|
2
|
1038 |
if (res != null) {
|
107
|
1039 |
return res;
|
2
|
1040 |
} else {
|
107
|
1041 |
return new LinkedList<T>();
|
2
|
1042 |
}
|
|
1043 |
}
|
|
1044 |
|
107
|
1045 |
private <T> void addProtocol(Class<T> protocolInterface, T protocol) {
|
|
1046 |
Collection<T> protocols = getProtocols(protocolInterface);
|
2
|
1047 |
protocols.add(protocol);
|
|
1048 |
protocolsMap.put(protocolInterface, protocols);
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
boolean supportsDynamicLayout() {
|
|
1052 |
int wm = getWMID();
|
|
1053 |
switch (wm) {
|
|
1054 |
case XWM.ENLIGHTEN_WM:
|
|
1055 |
case XWM.KDE2_WM:
|
|
1056 |
case XWM.SAWFISH_WM:
|
|
1057 |
case XWM.ICE_WM:
|
|
1058 |
case XWM.METACITY_WM:
|
|
1059 |
return true;
|
|
1060 |
case XWM.OPENLOOK_WM:
|
|
1061 |
case XWM.MOTIF_WM:
|
|
1062 |
case XWM.CDE_WM:
|
|
1063 |
return false;
|
|
1064 |
default:
|
|
1065 |
return false;
|
|
1066 |
}
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
|
|
1070 |
/**
|
|
1071 |
* Check if state is supported.
|
|
1072 |
* Note that a compound state is always reported as not supported.
|
|
1073 |
* Note also that MAXIMIZED_BOTH is considered not a compound state.
|
|
1074 |
* Therefore, a compound state is just ICONIFIED | anything else.
|
|
1075 |
*
|
|
1076 |
*/
|
|
1077 |
boolean supportsExtendedState(int state) {
|
|
1078 |
switch (state) {
|
|
1079 |
case Frame.MAXIMIZED_VERT:
|
|
1080 |
case Frame.MAXIMIZED_HORIZ:
|
|
1081 |
/*
|
|
1082 |
* WMs that talk NET/WIN protocol, but do not support
|
|
1083 |
* unidirectional maximization.
|
|
1084 |
*/
|
|
1085 |
if (getWMID() == METACITY_WM) {
|
|
1086 |
/* "This is a deliberate policy decision." -hp */
|
|
1087 |
return false;
|
|
1088 |
}
|
|
1089 |
/* FALLTROUGH */
|
|
1090 |
case Frame.MAXIMIZED_BOTH:
|
107
|
1091 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
|
2
|
1092 |
if (proto.supportsState(state)) {
|
|
1093 |
return true;
|
|
1094 |
}
|
|
1095 |
}
|
|
1096 |
default:
|
|
1097 |
return false;
|
|
1098 |
}
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
/*****************************************************************************\
|
|
1102 |
*
|
|
1103 |
* Reading state from different protocols
|
|
1104 |
*
|
|
1105 |
\*****************************************************************************/
|
|
1106 |
|
|
1107 |
|
|
1108 |
int getExtendedState(XWindowPeer window) {
|
|
1109 |
int state = 0;
|
107
|
1110 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
|
2
|
1111 |
state |= proto.getState(window);
|
|
1112 |
}
|
|
1113 |
if (state != 0) {
|
|
1114 |
return state;
|
|
1115 |
} else {
|
|
1116 |
return Frame.NORMAL;
|
|
1117 |
}
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
/*****************************************************************************\
|
|
1121 |
*
|
|
1122 |
* Notice window state change when WM changes a property on the window ...
|
|
1123 |
*
|
|
1124 |
\*****************************************************************************/
|
|
1125 |
|
|
1126 |
|
|
1127 |
/*
|
|
1128 |
* Check if property change is a window state protocol message.
|
|
1129 |
*/
|
107
|
1130 |
boolean isStateChange(XDecoratedPeer window, XPropertyEvent e) {
|
2
|
1131 |
if (!window.isShowing()) {
|
|
1132 |
stateLog.finer("Window is not showing");
|
107
|
1133 |
return false;
|
2
|
1134 |
}
|
|
1135 |
|
|
1136 |
int wm_state = window.getWMState();
|
|
1137 |
if (wm_state == XlibWrapper.WithdrawnState) {
|
|
1138 |
stateLog.finer("WithdrawnState");
|
107
|
1139 |
return false;
|
2
|
1140 |
} else {
|
|
1141 |
stateLog.finer("Window WM_STATE is " + wm_state);
|
|
1142 |
}
|
|
1143 |
boolean is_state_change = false;
|
|
1144 |
if (e.get_atom() == XA_WM_STATE.getAtom()) {
|
|
1145 |
is_state_change = true;
|
|
1146 |
}
|
|
1147 |
|
107
|
1148 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
|
2
|
1149 |
is_state_change |= proto.isStateChange(e);
|
107
|
1150 |
stateLog.finest(proto + ": is state changed = " + is_state_change);
|
2
|
1151 |
}
|
107
|
1152 |
return is_state_change;
|
|
1153 |
}
|
2
|
1154 |
|
107
|
1155 |
/*
|
|
1156 |
* Returns current state (including extended) of a given window.
|
|
1157 |
*/
|
|
1158 |
int getState(XDecoratedPeer window) {
|
|
1159 |
int res = 0;
|
|
1160 |
final int wm_state = window.getWMState();
|
|
1161 |
if (wm_state == XlibWrapper.IconicState) {
|
|
1162 |
res = Frame.ICONIFIED;
|
|
1163 |
} else {
|
|
1164 |
res = Frame.NORMAL;
|
2
|
1165 |
}
|
107
|
1166 |
res |= getExtendedState(window);
|
|
1167 |
return res;
|
2
|
1168 |
}
|
|
1169 |
|
|
1170 |
/*****************************************************************************\
|
|
1171 |
*
|
|
1172 |
* Setting/changing window state ...
|
|
1173 |
*
|
|
1174 |
\*****************************************************************************/
|
|
1175 |
|
|
1176 |
/**
|
|
1177 |
* Moves window to the specified layer, layer is one of the constants defined
|
|
1178 |
* in XLayerProtocol
|
|
1179 |
*/
|
|
1180 |
void setLayer(XWindowPeer window, int layer) {
|
107
|
1181 |
for (XLayerProtocol proto : getProtocols(XLayerProtocol.class)) {
|
2
|
1182 |
if (proto.supportsLayer(layer)) {
|
|
1183 |
proto.setLayer(window, layer);
|
|
1184 |
}
|
|
1185 |
}
|
|
1186 |
XToolkit.XSync();
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
void setExtendedState(XWindowPeer window, int state) {
|
107
|
1190 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
|
2
|
1191 |
if (proto.supportsState(state)) {
|
|
1192 |
proto.setState(window, state);
|
|
1193 |
break;
|
|
1194 |
}
|
|
1195 |
}
|
|
1196 |
|
|
1197 |
if (!window.isShowing()) {
|
|
1198 |
/*
|
|
1199 |
* Purge KWM bits.
|
|
1200 |
* Not really tested with KWM, only with WindowMaker.
|
|
1201 |
*/
|
|
1202 |
XToolkit.awtLock();
|
|
1203 |
try {
|
|
1204 |
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
|
|
1205 |
window.getWindow(),
|
|
1206 |
XA_KWM_WIN_ICONIFIED.getAtom());
|
|
1207 |
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
|
|
1208 |
window.getWindow(),
|
|
1209 |
XA_KWM_WIN_MAXIMIZED.getAtom());
|
|
1210 |
}
|
|
1211 |
finally {
|
|
1212 |
XToolkit.awtUnlock();
|
|
1213 |
}
|
|
1214 |
}
|
|
1215 |
XToolkit.XSync();
|
|
1216 |
}
|
|
1217 |
|
|
1218 |
|
|
1219 |
/*
|
|
1220 |
* Work around for 4775545.
|
|
1221 |
*
|
|
1222 |
* If WM exits while the top-level is shaded, the shaded hint remains
|
|
1223 |
* on the top-level properties. When WM restarts and sees the shaded
|
|
1224 |
* window it can reparent it into a "pre-shaded" decoration frame
|
|
1225 |
* (Metacity does), and our insets logic will go crazy, b/c it will
|
|
1226 |
* see a huge nagative bottom inset. There's no clean solution for
|
|
1227 |
* this, so let's just be weasels and drop the shaded hint if we
|
|
1228 |
* detect that WM exited. NB: we are in for a race condition with WM
|
|
1229 |
* restart here. NB2: e.g. WindowMaker saves the state in a private
|
|
1230 |
* property that this code knows nothing about, so this workaround is
|
|
1231 |
* not effective; other WMs might play similar tricks.
|
|
1232 |
*/
|
|
1233 |
void unshadeKludge(XDecoratedPeer window) {
|
|
1234 |
assert(window.isShowing());
|
|
1235 |
|
107
|
1236 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
|
2
|
1237 |
proto.unshadeKludge(window);
|
|
1238 |
}
|
|
1239 |
XToolkit.XSync();
|
|
1240 |
}
|
|
1241 |
|
|
1242 |
static boolean inited = false;
|
|
1243 |
static void init() {
|
|
1244 |
if (inited) {
|
|
1245 |
return;
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
initAtoms();
|
|
1249 |
getWM();
|
|
1250 |
inited = true;
|
|
1251 |
}
|
|
1252 |
|
|
1253 |
void initializeProtocols() {
|
|
1254 |
XNETProtocol net_protocol = g_net_protocol;
|
|
1255 |
if (net_protocol != null) {
|
|
1256 |
if (!net_protocol.active()) {
|
|
1257 |
net_protocol = null;
|
|
1258 |
} else {
|
|
1259 |
if (net_protocol.doStateProtocol()) {
|
|
1260 |
addProtocol(XStateProtocol.class, net_protocol);
|
|
1261 |
}
|
|
1262 |
if (net_protocol.doLayerProtocol()) {
|
|
1263 |
addProtocol(XLayerProtocol.class, net_protocol);
|
|
1264 |
}
|
|
1265 |
}
|
|
1266 |
}
|
|
1267 |
|
|
1268 |
XWINProtocol win = g_win_protocol;
|
|
1269 |
if (win != null) {
|
|
1270 |
if (win.active()) {
|
|
1271 |
if (win.doStateProtocol()) {
|
|
1272 |
addProtocol(XStateProtocol.class, win);
|
|
1273 |
}
|
|
1274 |
if (win.doLayerProtocol()) {
|
|
1275 |
addProtocol(XLayerProtocol.class, win);
|
|
1276 |
}
|
|
1277 |
}
|
|
1278 |
}
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
HashMap storedInsets = new HashMap();
|
|
1282 |
Insets guessInsets(XDecoratedPeer window) {
|
|
1283 |
Insets res = (Insets)storedInsets.get(window.getClass());
|
|
1284 |
if (res == null) {
|
|
1285 |
switch (WMID) {
|
|
1286 |
case ENLIGHTEN_WM:
|
|
1287 |
res = new Insets(19, 4, 4, 4);
|
|
1288 |
break;
|
|
1289 |
case CDE_WM:
|
|
1290 |
res = new Insets(28, 6, 6, 6);
|
|
1291 |
break;
|
|
1292 |
case NO_WM:
|
|
1293 |
case LG3D_WM:
|
|
1294 |
res = zeroInsets;
|
|
1295 |
break;
|
|
1296 |
case MOTIF_WM:
|
|
1297 |
case OPENLOOK_WM:
|
|
1298 |
default:
|
|
1299 |
res = defaultInsets;
|
|
1300 |
}
|
|
1301 |
}
|
|
1302 |
if (insLog.isLoggable(Level.FINEST)) insLog.finest("WM guessed insets: " + res);
|
|
1303 |
return res;
|
|
1304 |
}
|
|
1305 |
/*
|
|
1306 |
* Some buggy WMs ignore window gravity when processing
|
|
1307 |
* ConfigureRequest and position window as if the gravity is Static.
|
|
1308 |
* We work around this in MWindowPeer.pReshape().
|
|
1309 |
*
|
|
1310 |
* Starting with 1.5 we have introduced an Environment variable
|
|
1311 |
* _JAVA_AWT_WM_STATIC_GRAVITY that can be set to indicate to Java
|
|
1312 |
* explicitly that the WM has this behaviour, example is FVWM.
|
|
1313 |
*/
|
|
1314 |
|
|
1315 |
static int awtWMStaticGravity = -1;
|
|
1316 |
static boolean configureGravityBuggy() {
|
|
1317 |
|
|
1318 |
if (awtWMStaticGravity == -1) {
|
|
1319 |
awtWMStaticGravity = (XToolkit.getEnv("_JAVA_AWT_WM_STATIC_GRAVITY") != null) ? 1 : 0;
|
|
1320 |
}
|
|
1321 |
|
|
1322 |
if (awtWMStaticGravity == 1) {
|
|
1323 |
return true;
|
|
1324 |
}
|
|
1325 |
|
|
1326 |
switch(getWMID()) {
|
|
1327 |
case XWM.ICE_WM:
|
|
1328 |
/*
|
|
1329 |
* See bug #228981 at IceWM's SourceForge pages.
|
|
1330 |
* Latest stable version 1.0.8-6 still has this problem.
|
|
1331 |
*/
|
|
1332 |
/**
|
|
1333 |
* Version 1.2.2 doesn't have this problem
|
|
1334 |
*/
|
|
1335 |
// Detect IceWM version
|
|
1336 |
if (g_net_protocol != null) {
|
|
1337 |
String wm_name = g_net_protocol.getWMName();
|
|
1338 |
Pattern pat = Pattern.compile("^IceWM (\\d+)\\.(\\d+)\\.(\\d+).*$");
|
|
1339 |
try {
|
|
1340 |
Matcher match = pat.matcher(wm_name);
|
|
1341 |
if (match.matches()) {
|
|
1342 |
int v1 = Integer.parseInt(match.group(1));
|
|
1343 |
int v2 = Integer.parseInt(match.group(2));
|
|
1344 |
int v3 = Integer.parseInt(match.group(3));
|
|
1345 |
return !(v1 > 1 || (v1 == 1 && (v2 > 2 || (v2 == 2 && v3 >=2))));
|
|
1346 |
}
|
|
1347 |
} catch (Exception e) {
|
|
1348 |
return true;
|
|
1349 |
}
|
|
1350 |
}
|
|
1351 |
return true;
|
|
1352 |
case XWM.ENLIGHTEN_WM:
|
|
1353 |
/* At least E16 is buggy. */
|
|
1354 |
return true;
|
|
1355 |
default:
|
|
1356 |
return false;
|
|
1357 |
}
|
|
1358 |
}
|
|
1359 |
|
|
1360 |
/*
|
|
1361 |
* @return if WM implements the insets property - returns insets with values
|
|
1362 |
* specified in that property, null otherwise.
|
|
1363 |
*/
|
|
1364 |
public static Insets getInsetsFromExtents(long window) {
|
|
1365 |
if (window == XConstants.None) {
|
|
1366 |
return null;
|
|
1367 |
}
|
|
1368 |
XNETProtocol net_protocol = getWM().getNETProtocol();
|
|
1369 |
if (net_protocol != null && net_protocol.active()) {
|
|
1370 |
Insets insets = getInsetsFromProp(window, XA_NET_FRAME_EXTENTS);
|
|
1371 |
insLog.log(Level.FINE, "_NET_FRAME_EXTENTS: {0}", insets);
|
|
1372 |
|
|
1373 |
if (insets != null) {
|
|
1374 |
return insets;
|
|
1375 |
}
|
|
1376 |
}
|
|
1377 |
switch(getWMID()) {
|
|
1378 |
case XWM.KDE2_WM:
|
|
1379 |
return getInsetsFromProp(window, XA_KDE_NET_WM_FRAME_STRUT);
|
|
1380 |
case XWM.ENLIGHTEN_WM:
|
|
1381 |
return getInsetsFromProp(window, XA_E_FRAME_SIZE);
|
|
1382 |
default:
|
|
1383 |
return null;
|
|
1384 |
}
|
|
1385 |
}
|
|
1386 |
|
|
1387 |
/**
|
|
1388 |
* Helper function reads property of type CARDINAL[4] = { left, right, top, bottom }
|
|
1389 |
* and converts it to Insets object.
|
|
1390 |
*/
|
|
1391 |
public static Insets getInsetsFromProp(long window, XAtom atom) {
|
|
1392 |
if (window == XConstants.None) {
|
|
1393 |
return null;
|
|
1394 |
}
|
|
1395 |
|
|
1396 |
WindowPropertyGetter getter =
|
|
1397 |
new WindowPropertyGetter(window, atom,
|
|
1398 |
0, 4, false, XAtom.XA_CARDINAL);
|
|
1399 |
try {
|
|
1400 |
if (getter.execute() != XlibWrapper.Success
|
|
1401 |
|| getter.getData() == 0
|
|
1402 |
|| getter.getActualType() != XAtom.XA_CARDINAL
|
|
1403 |
|| getter.getActualFormat() != 32)
|
|
1404 |
{
|
|
1405 |
return null;
|
|
1406 |
} else {
|
|
1407 |
return new Insets((int)Native.getCard32(getter.getData(), 2), // top
|
|
1408 |
(int)Native.getCard32(getter.getData(), 0), // left
|
|
1409 |
(int)Native.getCard32(getter.getData(), 3), // bottom
|
|
1410 |
(int)Native.getCard32(getter.getData(), 1)); // right
|
|
1411 |
}
|
|
1412 |
} finally {
|
|
1413 |
getter.dispose();
|
|
1414 |
}
|
|
1415 |
}
|
|
1416 |
|
|
1417 |
/**
|
|
1418 |
* Asks WM to fill Frame Extents (insets) for the window.
|
|
1419 |
*/
|
|
1420 |
public static void requestWMExtents(long window) {
|
|
1421 |
if (window == XConstants.None) { // not initialized
|
|
1422 |
return;
|
|
1423 |
}
|
|
1424 |
|
|
1425 |
log.fine("Requesting FRAME_EXTENTS");
|
|
1426 |
|
|
1427 |
XClientMessageEvent msg = new XClientMessageEvent();
|
|
1428 |
msg.zero();
|
|
1429 |
msg.set_type(XlibWrapper.ClientMessage);
|
|
1430 |
msg.set_display(XToolkit.getDisplay());
|
|
1431 |
msg.set_window(window);
|
|
1432 |
msg.set_format(32);
|
|
1433 |
XToolkit.awtLock();
|
|
1434 |
try {
|
|
1435 |
XNETProtocol net_protocol = getWM().getNETProtocol();
|
|
1436 |
if (net_protocol != null && net_protocol.active()) {
|
|
1437 |
msg.set_message_type(XA_NET_REQUEST_FRAME_EXTENTS.getAtom());
|
|
1438 |
XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
|
|
1439 |
false, XlibWrapper.SubstructureRedirectMask | XlibWrapper.SubstructureNotifyMask,
|
|
1440 |
msg.getPData());
|
|
1441 |
}
|
|
1442 |
if (getWMID() == XWM.KDE2_WM) {
|
|
1443 |
msg.set_message_type(XA_KDE_NET_WM_FRAME_STRUT.getAtom());
|
|
1444 |
XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
|
|
1445 |
false, XlibWrapper.SubstructureRedirectMask | XlibWrapper.SubstructureNotifyMask,
|
|
1446 |
msg.getPData());
|
|
1447 |
}
|
|
1448 |
// XXX: should we wait for response? XIfEvent() would be useful here :)
|
|
1449 |
} finally {
|
|
1450 |
XToolkit.awtUnlock();
|
|
1451 |
msg.dispose();
|
|
1452 |
}
|
|
1453 |
}
|
|
1454 |
|
|
1455 |
/* syncTopLEvelPos() is necessary to insure that the window manager has in
|
|
1456 |
* fact moved us to our final position relative to the reParented WM window.
|
|
1457 |
* We have noted a timing window which our shell has not been moved so we
|
|
1458 |
* screw up the insets thinking they are 0,0. Wait (for a limited period of
|
|
1459 |
* time to let the WM hava a chance to move us.
|
|
1460 |
* @param window window ID of the shell, assuming it is the window
|
|
1461 |
* which will NOT have zero coordinates after the complete
|
|
1462 |
* reparenting
|
|
1463 |
*/
|
|
1464 |
boolean syncTopLevelPos(long window, XWindowAttributes attrs) {
|
|
1465 |
int tries = 0;
|
|
1466 |
XToolkit.awtLock();
|
|
1467 |
try {
|
|
1468 |
do {
|
|
1469 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), window, attrs.pData);
|
|
1470 |
if (attrs.get_x() != 0 || attrs.get_y() != 0) {
|
|
1471 |
return true;
|
|
1472 |
}
|
|
1473 |
tries++;
|
|
1474 |
XToolkit.XSync();
|
|
1475 |
} while (tries < 50);
|
|
1476 |
}
|
|
1477 |
finally {
|
|
1478 |
XToolkit.awtUnlock();
|
|
1479 |
}
|
|
1480 |
return false;
|
|
1481 |
}
|
|
1482 |
|
|
1483 |
Insets getInsets(XDecoratedPeer win, long window, long parent) {
|
|
1484 |
/*
|
|
1485 |
* Unfortunately the concept of "insets" borrowed to AWT
|
|
1486 |
* from Win32 is *absolutely*, *unbelievably* foreign to
|
|
1487 |
* X11. Few WMs provide the size of frame decor
|
|
1488 |
* (i.e. insets) in a property they set on the client
|
|
1489 |
* window, so we check if we can get away with just
|
|
1490 |
* peeking at it. [Future versions of wm-spec might add a
|
|
1491 |
* standardized hint for this].
|
|
1492 |
*
|
|
1493 |
* Otherwise we do some special casing. Actually the
|
|
1494 |
* fallback code ("default" case) seems to cover most of
|
|
1495 |
* the existing WMs (modulo Reparent/Configure order
|
|
1496 |
* perhaps?).
|
|
1497 |
*
|
|
1498 |
* Fallback code tries to account for the two most common cases:
|
|
1499 |
*
|
|
1500 |
* . single reparenting
|
|
1501 |
* parent window is the WM frame
|
|
1502 |
* [twm, olwm, sawfish]
|
|
1503 |
*
|
|
1504 |
* . double reparenting
|
|
1505 |
* parent is a lining exactly the size of the client
|
|
1506 |
* grandpa is the WM frame
|
|
1507 |
* [mwm, e!, kwin, fvwm2 ... ]
|
|
1508 |
*/
|
|
1509 |
Insets correctWM = XWM.getInsetsFromExtents(window);
|
|
1510 |
insLog.log(Level.FINER, "Got insets from property: {0}", correctWM);
|
|
1511 |
|
|
1512 |
if (correctWM == null) {
|
|
1513 |
correctWM = new Insets(0,0,0,0);
|
|
1514 |
|
|
1515 |
correctWM.top = -1;
|
|
1516 |
correctWM.left = -1;
|
|
1517 |
|
|
1518 |
XWindowAttributes lwinAttr = new XWindowAttributes();
|
|
1519 |
XWindowAttributes pattr = new XWindowAttributes();
|
|
1520 |
try {
|
|
1521 |
switch (XWM.getWMID()) {
|
|
1522 |
/* should've been done in awt_wm_getInsetsFromProp */
|
|
1523 |
case XWM.ENLIGHTEN_WM: {
|
|
1524 |
/* enlightenment does double reparenting */
|
|
1525 |
syncTopLevelPos(parent, lwinAttr);
|
|
1526 |
correctWM.left = lwinAttr.get_x();
|
|
1527 |
correctWM.top = lwinAttr.get_y();
|
|
1528 |
/*
|
|
1529 |
* Now get the actual dimensions of the parent window
|
|
1530 |
* resolve the difference. We can't rely on the left
|
|
1531 |
* to be equal to right or bottom... Enlightment
|
|
1532 |
* breaks that assumption.
|
|
1533 |
*/
|
|
1534 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
|
|
1535 |
XlibUtil.getParentWindow(parent),
|
|
1536 |
pattr.pData);
|
|
1537 |
correctWM.right = pattr.get_width() -
|
|
1538 |
(lwinAttr.get_width() + correctWM.left);
|
|
1539 |
correctWM.bottom = pattr.get_height() -
|
|
1540 |
(lwinAttr.get_height() + correctWM.top);
|
|
1541 |
|
|
1542 |
break;
|
|
1543 |
}
|
|
1544 |
case XWM.ICE_WM: // for 1.2.2.
|
|
1545 |
case XWM.KDE2_WM: /* should've been done in getInsetsFromProp */
|
|
1546 |
case XWM.CDE_WM:
|
|
1547 |
case XWM.MOTIF_WM: {
|
|
1548 |
/* these are double reparenting too */
|
|
1549 |
if (syncTopLevelPos(parent, lwinAttr)) {
|
|
1550 |
correctWM.top = lwinAttr.get_y();
|
|
1551 |
correctWM.left = lwinAttr.get_x();
|
|
1552 |
correctWM.right = correctWM.left;
|
|
1553 |
correctWM.bottom = correctWM.left;
|
|
1554 |
} else {
|
|
1555 |
return null;
|
|
1556 |
}
|
|
1557 |
break;
|
|
1558 |
}
|
|
1559 |
case XWM.SAWFISH_WM:
|
|
1560 |
case XWM.OPENLOOK_WM: {
|
|
1561 |
/* single reparenting */
|
|
1562 |
syncTopLevelPos(window, lwinAttr);
|
|
1563 |
correctWM.top = lwinAttr.get_y();
|
|
1564 |
correctWM.left = lwinAttr.get_x();
|
|
1565 |
correctWM.right = correctWM.left;
|
|
1566 |
correctWM.bottom = correctWM.left;
|
|
1567 |
break;
|
|
1568 |
}
|
|
1569 |
case XWM.OTHER_WM:
|
|
1570 |
default: { /* this is very similar to the E! case above */
|
|
1571 |
insLog.log(Level.FINEST, "Getting correct insets for OTHER_WM/default, parent: {0}", parent);
|
|
1572 |
syncTopLevelPos(parent, lwinAttr);
|
|
1573 |
int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
|
|
1574 |
window, lwinAttr.pData);
|
|
1575 |
status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
|
|
1576 |
parent, pattr.pData);
|
|
1577 |
if (lwinAttr.get_root() == parent) {
|
|
1578 |
insLog.finest("our parent is root so insets should be zero");
|
|
1579 |
correctWM = new Insets(0, 0, 0, 0);
|
|
1580 |
break;
|
|
1581 |
}
|
|
1582 |
|
|
1583 |
/*
|
|
1584 |
* Check for double-reparenting WM.
|
|
1585 |
*
|
|
1586 |
* If the parent is exactly the same size as the
|
|
1587 |
* top-level assume taht it's the "lining" window and
|
|
1588 |
* that the grandparent is the actual frame (NB: we
|
|
1589 |
* have already handled undecorated windows).
|
|
1590 |
*
|
|
1591 |
* XXX: what about timing issues that syncTopLevelPos
|
|
1592 |
* is supposed to work around?
|
|
1593 |
*/
|
|
1594 |
if (lwinAttr.get_x() == 0 && lwinAttr.get_y() == 0
|
|
1595 |
&& lwinAttr.get_width()+2*lwinAttr.get_border_width() == pattr.get_width()
|
|
1596 |
&& lwinAttr.get_height()+2*lwinAttr.get_border_width() == pattr.get_height())
|
|
1597 |
{
|
|
1598 |
insLog.log(Level.FINEST, "Double reparenting detected, pattr({2})={0}, lwinAttr({3})={1}",
|
|
1599 |
new Object[] {lwinAttr, pattr, parent, window});
|
|
1600 |
lwinAttr.set_x(pattr.get_x());
|
|
1601 |
lwinAttr.set_y(pattr.get_y());
|
|
1602 |
lwinAttr.set_border_width(lwinAttr.get_border_width()+pattr.get_border_width());
|
|
1603 |
|
|
1604 |
final long grand_parent = XlibUtil.getParentWindow(parent);
|
|
1605 |
|
|
1606 |
if (grand_parent == lwinAttr.get_root()) {
|
|
1607 |
// This is not double-reparenting in a
|
|
1608 |
// general sense - we simply don't have
|
|
1609 |
// correct insets - return null to try to
|
|
1610 |
// get insets later
|
|
1611 |
return null;
|
|
1612 |
} else {
|
|
1613 |
parent = grand_parent;
|
|
1614 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
|
|
1615 |
parent,
|
|
1616 |
pattr.pData);
|
|
1617 |
}
|
|
1618 |
}
|
|
1619 |
/*
|
|
1620 |
* XXX: To be absolutely correct, we'd need to take
|
|
1621 |
* parent's border-width into account too, but the
|
|
1622 |
* rest of the code is happily unaware about border
|
|
1623 |
* widths and inner/outer distinction, so for the time
|
|
1624 |
* being, just ignore it.
|
|
1625 |
*/
|
|
1626 |
insLog.log(Level.FINEST, "Attrs before calculation: pattr({2})={0}, lwinAttr({3})={1}",
|
|
1627 |
new Object[] {lwinAttr, pattr, parent, window});
|
|
1628 |
correctWM = new Insets(lwinAttr.get_y() + lwinAttr.get_border_width(),
|
|
1629 |
lwinAttr.get_x() + lwinAttr.get_border_width(),
|
|
1630 |
pattr.get_height() - (lwinAttr.get_y() + lwinAttr.get_height() + 2*lwinAttr.get_border_width()),
|
|
1631 |
pattr.get_width() - (lwinAttr.get_x() + lwinAttr.get_width() + 2*lwinAttr.get_border_width()));
|
|
1632 |
break;
|
|
1633 |
} /* default */
|
|
1634 |
} /* switch (runningWM) */
|
|
1635 |
} finally {
|
|
1636 |
lwinAttr.dispose();
|
|
1637 |
pattr.dispose();
|
|
1638 |
}
|
|
1639 |
}
|
|
1640 |
if (storedInsets.get(win.getClass()) == null) {
|
|
1641 |
storedInsets.put(win.getClass(), correctWM);
|
|
1642 |
}
|
|
1643 |
return correctWM;
|
|
1644 |
}
|
|
1645 |
boolean isDesktopWindow( long w ) {
|
|
1646 |
if (g_net_protocol != null) {
|
|
1647 |
XAtomList wtype = XAtom.get("_NET_WM_WINDOW_TYPE").getAtomListPropertyList( w );
|
|
1648 |
return wtype.contains( XAtom.get("_NET_WM_WINDOW_TYPE_DESKTOP") );
|
|
1649 |
} else {
|
|
1650 |
return false;
|
|
1651 |
}
|
|
1652 |
}
|
|
1653 |
|
|
1654 |
public XNETProtocol getNETProtocol() {
|
|
1655 |
return g_net_protocol;
|
|
1656 |
}
|
|
1657 |
|
|
1658 |
/**
|
|
1659 |
* Sets _NET_WN_ICON property on the window using the arrays of
|
|
1660 |
* raster-data for icons. If icons is null, removes _NET_WM_ICON
|
|
1661 |
* property.
|
|
1662 |
* This method invokes XNETProtocol.setWMIcon() for WMs that
|
|
1663 |
* support NET protocol.
|
|
1664 |
*
|
|
1665 |
* @return true if hint was modified successfully, false otherwise
|
|
1666 |
*/
|
|
1667 |
public boolean setNetWMIcon(XWindowPeer window, java.util.List<XIconInfo> icons) {
|
|
1668 |
if (g_net_protocol != null && g_net_protocol.active()) {
|
|
1669 |
g_net_protocol.setWMIcons(window, icons);
|
|
1670 |
return getWMID() != ICE_WM;
|
|
1671 |
}
|
|
1672 |
return false;
|
|
1673 |
}
|
|
1674 |
}
|