author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 439 | 3488710b02f8 |
child 2472 | b7aba00cabb6 |
permissions | -rw-r--r-- |
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 |
*/ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
49 |
final class XWM |
107 | 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; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
277 |
substruct.set_event_mask(XConstants.SubstructureRedirectMask); |
2 | 278 |
|
279 |
XToolkit.WITH_XERROR_HANDLER(DetectWMHandler); |
|
280 |
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(), |
|
281 |
XToolkit.getDefaultRootWindow(), |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
282 |
XConstants.CWEventMask, |
2 | 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(), |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
294 |
XConstants.CWEventMask, |
2 | 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); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
325 |
if (status != XConstants.Success || getter.getData() == 0) { |
2 | 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(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
414 |
if (status != XConstants.Success || getter.getData() == 0) { |
2 | 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 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
445 |
if (status != XConstants.Success || getter2.getData() == 0) { |
2 | 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, |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
483 |
MWMConstants.PROP_MOTIF_WM_INFO_ELEMENTS, |
2 | 484 |
false, XA_MOTIF_WM_INFO); |
485 |
try { |
|
486 |
int status = getter.execute(); |
|
487 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
488 |
if (status != XConstants.Success || getter.getData() == 0) { |
2 | 489 |
return false; |
490 |
} |
|
491 |
||
492 |
if (getter.getActualType() != XA_MOTIF_WM_INFO.getAtom() |
|
493 |
|| getter.getActualFormat() != 32 |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
494 |
|| getter.getNumberOfItems() != MWMConstants.PROP_MOTIF_WM_INFO_ELEMENTS |
2 | 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 { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
519 |
if (state_getter.execute() == XConstants.Success && |
2 | 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); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
580 |
if (err.get_request_code() == XProtocolConstants.X_ChangeProperty) { |
2 | 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(), |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
624 |
8, XConstants.PropModeReplace, |
2 | 625 |
new String(opt)); |
626 |
XToolkit.RESTORE_XERROR_HANDLER(); |
|
627 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
628 |
if (XToolkit.saved_error != null && XToolkit.saved_error.get_error_code() != XConstants.Success) { |
2 | 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(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
657 |
boolean res = (status == XConstants.Success && getter.getActualType() != 0); |
2 | 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); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
689 |
if (err.get_request_code() == XProtocolConstants.X_ChangeWindowAttributes |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
690 |
&& err.get_error_code() == XConstants.BadAccess) |
2 | 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) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
807 |
mask &= XUtilConstants.PMaxSize | XUtilConstants.PMinSize; |
2 | 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) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
833 |
if ((decorations & MWMConstants.MWM_DECOR_ALL) == 0) { |
2 | 834 |
return decorations; |
835 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
836 |
int d = MWMConstants.MWM_DECOR_BORDER | MWMConstants.MWM_DECOR_RESIZEH |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
837 |
| MWMConstants.MWM_DECOR_TITLE |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
838 |
| MWMConstants.MWM_DECOR_MENU | MWMConstants.MWM_DECOR_MINIMIZE |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
839 |
| MWMConstants.MWM_DECOR_MAXIMIZE; |
2 | 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) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
851 |
if ((functions & MWMConstants.MWM_FUNC_ALL) == 0) { |
2 | 852 |
return functions; |
853 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
854 |
int f = MWMConstants.MWM_FUNC_RESIZE | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
855 |
MWMConstants.MWM_FUNC_MOVE | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
856 |
MWMConstants.MWM_FUNC_MAXIMIZE | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
857 |
MWMConstants.MWM_FUNC_MINIMIZE | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
858 |
MWMConstants.MWM_FUNC_CLOSE; |
2 | 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)); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
875 |
if ((decorations & MWMConstants.MWM_DECOR_TITLE) == 0) { |
2 | 876 |
decorDel.add(XA_OL_DECOR_HEADER); |
877 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
878 |
if ((decorations & (MWMConstants.MWM_DECOR_RESIZEH | MWMConstants.MWM_DECOR_MAXIMIZE)) == 0) { |
2 | 879 |
decorDel.add(XA_OL_DECOR_RESIZE); |
880 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
881 |
if ((decorations & (MWMConstants.MWM_DECOR_MENU | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
882 |
MWMConstants.MWM_DECOR_MAXIMIZE | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
883 |
MWMConstants.MWM_DECOR_MINIMIZE)) == 0) |
2 | 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 */ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
901 |
if ((decorations & MWMConstants.MWM_DECOR_ALL) != 0 |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
902 |
&& (decorations != MWMConstants.MWM_DECOR_ALL)) |
2 | 903 |
{ |
904 |
decorations = normalizeMotifDecor(decorations); |
|
905 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
906 |
if ((functions & MWMConstants.MWM_FUNC_ALL) != 0 |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
907 |
&& (functions != MWMConstants.MWM_FUNC_ALL)) |
2 | 908 |
{ |
909 |
functions = normalizeMotifFunc(functions); |
|
910 |
} |
|
911 |
||
912 |
PropMwmHints hints = window.getMWMHints(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
913 |
hints.set_flags(hints.get_flags() | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
914 |
MWMConstants.MWM_HINTS_FUNCTIONS | |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
915 |
MWMConstants.MWM_HINTS_DECORATIONS); |
2 | 916 |
hints.set_functions(functions); |
917 |
hints.set_decorations(decorations); |
|
918 |
||
919 |
if (stateLog.isLoggable(Level.FINER)) stateLog.finer("Setting MWM_HINTS to " + hints); |
|
920 |
window.setMWMHints(hints); |
|
921 |
} |
|
922 |
||
923 |
/* |
|
924 |
* Under some window managers if shell is already mapped, we MUST |
|
925 |
* unmap and later remap in order to effect the changes we make in the |
|
926 |
* window manager decorations. |
|
927 |
* |
|
928 |
* N.B. This unmapping / remapping of the shell exposes a bug in |
|
929 |
* X/Motif or the Motif Window Manager. When you attempt to map a |
|
930 |
* widget which is positioned (partially) off-screen, the window is |
|
931 |
* relocated to be entirely on screen. Good idea. But if both the x |
|
932 |
* and the y coordinates are less than the origin (0,0), the first |
|
933 |
* (re)map will move the window to the origin, and any subsequent |
|
934 |
* (re)map will relocate the window at some other point on the screen. |
|
935 |
* I have written a short Motif test program to discover this bug. |
|
936 |
* This should occur infrequently and it does not cause any real |
|
937 |
* problem. So for now we'll let it be. |
|
938 |
*/ |
|
939 |
static boolean needRemap(XDecoratedPeer window) { |
|
940 |
// Don't remap EmbeddedFrame, |
|
941 |
// e.g. for TrayIcon it causes problems. |
|
942 |
return !window.isEmbedded(); |
|
943 |
} |
|
944 |
||
945 |
/* |
|
946 |
* Set decoration hints on the shell to wdata->decor adjusted |
|
947 |
* appropriately if not resizable. |
|
948 |
*/ |
|
949 |
static void setShellDecor(XDecoratedPeer window) { |
|
950 |
int decorations = window.getDecorations(); |
|
951 |
int functions = window.getFunctions(); |
|
952 |
boolean resizable = window.isResizable(); |
|
953 |
||
954 |
if (!resizable) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
955 |
if ((decorations & MWMConstants.MWM_DECOR_ALL) != 0) { |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
956 |
decorations |= MWMConstants.MWM_DECOR_RESIZEH | MWMConstants.MWM_DECOR_MAXIMIZE; |
2 | 957 |
} else { |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
958 |
decorations &= ~(MWMConstants.MWM_DECOR_RESIZEH | MWMConstants.MWM_DECOR_MAXIMIZE); |
2 | 959 |
} |
960 |
} |
|
961 |
setMotifDecor(window, resizable, decorations, functions); |
|
962 |
setOLDecor(window, resizable, decorations); |
|
963 |
||
964 |
/* Some WMs need remap to redecorate the window */ |
|
965 |
if (window.isShowing() && needRemap(window)) { |
|
966 |
/* |
|
967 |
* Do the re/mapping at the Xlib level. Since we essentially |
|
968 |
* work around a WM bug we don't want this hack to be exposed |
|
969 |
* to Intrinsics (i.e. don't mess with grabs, callbacks etc). |
|
970 |
*/ |
|
971 |
window.xSetVisible(false); |
|
972 |
XToolkit.XSync(); |
|
973 |
window.xSetVisible(true); |
|
974 |
} |
|
975 |
} |
|
976 |
||
977 |
/* |
|
978 |
* Make specified shell resizable. |
|
979 |
*/ |
|
980 |
static void setShellResizable(XDecoratedPeer window) { |
|
981 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell resizable " + window); |
|
982 |
XToolkit.awtLock(); |
|
983 |
try { |
|
984 |
Rectangle shellBounds = window.getShellBounds(); |
|
985 |
shellBounds.translate(-window.currentInsets.left, -window.currentInsets.top); |
|
986 |
window.updateSizeHints(window.getDimensions()); |
|
987 |
requestWMExtents(window.getWindow()); |
|
988 |
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(), |
|
989 |
shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height); |
|
990 |
/* REMINDER: will need to revisit when setExtendedStateBounds is added */ |
|
991 |
//Fix for 4320050: Minimum size for java.awt.Frame is not being enforced. |
|
992 |
//We need to update frame's minimum size, not to reset it |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
993 |
removeSizeHints(window, XUtilConstants.PMaxSize); |
2 | 994 |
window.updateMinimumSize(); |
995 |
||
996 |
/* Restore decorations */ |
|
997 |
setShellDecor(window); |
|
998 |
} finally { |
|
999 |
XToolkit.awtUnlock(); |
|
1000 |
} |
|
1001 |
} |
|
1002 |
||
1003 |
/* |
|
1004 |
* Make specified shell non-resizable. |
|
1005 |
* If justChangeSize is false, update decorations as well. |
|
1006 |
* @param shellBounds bounds of the shell window |
|
1007 |
*/ |
|
1008 |
static void setShellNotResizable(XDecoratedPeer window, WindowDimensions newDimensions, Rectangle shellBounds, |
|
1009 |
boolean justChangeSize) |
|
1010 |
{ |
|
1011 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting non-resizable shell " + window + ", dimensions " + newDimensions + |
|
1012 |
", shellBounds " + shellBounds +", just change size: " + justChangeSize); |
|
1013 |
XToolkit.awtLock(); |
|
1014 |
try { |
|
1015 |
/* Fix min/max size hints at the specified values */ |
|
1016 |
if (!shellBounds.isEmpty()) { |
|
1017 |
window.updateSizeHints(newDimensions); |
|
1018 |
requestWMExtents(window.getWindow()); |
|
1019 |
XToolkit.XSync(); |
|
1020 |
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(), |
|
1021 |
shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height); |
|
1022 |
} |
|
1023 |
if (!justChangeSize) { /* update decorations */ |
|
1024 |
setShellDecor(window); |
|
1025 |
} |
|
1026 |
} finally { |
|
1027 |
XToolkit.awtUnlock(); |
|
1028 |
} |
|
1029 |
} |
|
1030 |
||
1031 |
/*****************************************************************************\ |
|
1032 |
* Protocols support |
|
1033 |
*/ |
|
107 | 1034 |
private HashMap<Class<?>, Collection<?>> protocolsMap = new HashMap<Class<?>, Collection<?>>(); |
2 | 1035 |
/** |
1036 |
* Returns all protocols supporting given protocol interface |
|
1037 |
*/ |
|
107 | 1038 |
<T> Collection<T> getProtocols(Class<T> protocolInterface) { |
1039 |
Collection<T> res = (Collection<T>) protocolsMap.get(protocolInterface); |
|
2 | 1040 |
if (res != null) { |
107 | 1041 |
return res; |
2 | 1042 |
} else { |
107 | 1043 |
return new LinkedList<T>(); |
2 | 1044 |
} |
1045 |
} |
|
1046 |
||
107 | 1047 |
private <T> void addProtocol(Class<T> protocolInterface, T protocol) { |
1048 |
Collection<T> protocols = getProtocols(protocolInterface); |
|
2 | 1049 |
protocols.add(protocol); |
1050 |
protocolsMap.put(protocolInterface, protocols); |
|
1051 |
} |
|
1052 |
||
1053 |
boolean supportsDynamicLayout() { |
|
1054 |
int wm = getWMID(); |
|
1055 |
switch (wm) { |
|
1056 |
case XWM.ENLIGHTEN_WM: |
|
1057 |
case XWM.KDE2_WM: |
|
1058 |
case XWM.SAWFISH_WM: |
|
1059 |
case XWM.ICE_WM: |
|
1060 |
case XWM.METACITY_WM: |
|
1061 |
return true; |
|
1062 |
case XWM.OPENLOOK_WM: |
|
1063 |
case XWM.MOTIF_WM: |
|
1064 |
case XWM.CDE_WM: |
|
1065 |
return false; |
|
1066 |
default: |
|
1067 |
return false; |
|
1068 |
} |
|
1069 |
} |
|
1070 |
||
1071 |
||
1072 |
/** |
|
1073 |
* Check if state is supported. |
|
1074 |
* Note that a compound state is always reported as not supported. |
|
1075 |
* Note also that MAXIMIZED_BOTH is considered not a compound state. |
|
1076 |
* Therefore, a compound state is just ICONIFIED | anything else. |
|
1077 |
* |
|
1078 |
*/ |
|
1079 |
boolean supportsExtendedState(int state) { |
|
1080 |
switch (state) { |
|
1081 |
case Frame.MAXIMIZED_VERT: |
|
1082 |
case Frame.MAXIMIZED_HORIZ: |
|
1083 |
/* |
|
1084 |
* WMs that talk NET/WIN protocol, but do not support |
|
1085 |
* unidirectional maximization. |
|
1086 |
*/ |
|
1087 |
if (getWMID() == METACITY_WM) { |
|
1088 |
/* "This is a deliberate policy decision." -hp */ |
|
1089 |
return false; |
|
1090 |
} |
|
1091 |
/* FALLTROUGH */ |
|
1092 |
case Frame.MAXIMIZED_BOTH: |
|
107 | 1093 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) { |
2 | 1094 |
if (proto.supportsState(state)) { |
1095 |
return true; |
|
1096 |
} |
|
1097 |
} |
|
1098 |
default: |
|
1099 |
return false; |
|
1100 |
} |
|
1101 |
} |
|
1102 |
||
1103 |
/*****************************************************************************\ |
|
1104 |
* |
|
1105 |
* Reading state from different protocols |
|
1106 |
* |
|
1107 |
\*****************************************************************************/ |
|
1108 |
||
1109 |
||
1110 |
int getExtendedState(XWindowPeer window) { |
|
1111 |
int state = 0; |
|
107 | 1112 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) { |
2 | 1113 |
state |= proto.getState(window); |
1114 |
} |
|
1115 |
if (state != 0) { |
|
1116 |
return state; |
|
1117 |
} else { |
|
1118 |
return Frame.NORMAL; |
|
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
/*****************************************************************************\ |
|
1123 |
* |
|
1124 |
* Notice window state change when WM changes a property on the window ... |
|
1125 |
* |
|
1126 |
\*****************************************************************************/ |
|
1127 |
||
1128 |
||
1129 |
/* |
|
1130 |
* Check if property change is a window state protocol message. |
|
1131 |
*/ |
|
107 | 1132 |
boolean isStateChange(XDecoratedPeer window, XPropertyEvent e) { |
2 | 1133 |
if (!window.isShowing()) { |
1134 |
stateLog.finer("Window is not showing"); |
|
107 | 1135 |
return false; |
2 | 1136 |
} |
1137 |
||
1138 |
int wm_state = window.getWMState(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1139 |
if (wm_state == XUtilConstants.WithdrawnState) { |
2 | 1140 |
stateLog.finer("WithdrawnState"); |
107 | 1141 |
return false; |
2 | 1142 |
} else { |
1143 |
stateLog.finer("Window WM_STATE is " + wm_state); |
|
1144 |
} |
|
1145 |
boolean is_state_change = false; |
|
1146 |
if (e.get_atom() == XA_WM_STATE.getAtom()) { |
|
1147 |
is_state_change = true; |
|
1148 |
} |
|
1149 |
||
107 | 1150 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) { |
2 | 1151 |
is_state_change |= proto.isStateChange(e); |
107 | 1152 |
stateLog.finest(proto + ": is state changed = " + is_state_change); |
2 | 1153 |
} |
107 | 1154 |
return is_state_change; |
1155 |
} |
|
2 | 1156 |
|
107 | 1157 |
/* |
1158 |
* Returns current state (including extended) of a given window. |
|
1159 |
*/ |
|
1160 |
int getState(XDecoratedPeer window) { |
|
1161 |
int res = 0; |
|
1162 |
final int wm_state = window.getWMState(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1163 |
if (wm_state == XUtilConstants.IconicState) { |
107 | 1164 |
res = Frame.ICONIFIED; |
1165 |
} else { |
|
1166 |
res = Frame.NORMAL; |
|
2 | 1167 |
} |
107 | 1168 |
res |= getExtendedState(window); |
1169 |
return res; |
|
2 | 1170 |
} |
1171 |
||
1172 |
/*****************************************************************************\ |
|
1173 |
* |
|
1174 |
* Setting/changing window state ... |
|
1175 |
* |
|
1176 |
\*****************************************************************************/ |
|
1177 |
||
1178 |
/** |
|
1179 |
* Moves window to the specified layer, layer is one of the constants defined |
|
1180 |
* in XLayerProtocol |
|
1181 |
*/ |
|
1182 |
void setLayer(XWindowPeer window, int layer) { |
|
107 | 1183 |
for (XLayerProtocol proto : getProtocols(XLayerProtocol.class)) { |
2 | 1184 |
if (proto.supportsLayer(layer)) { |
1185 |
proto.setLayer(window, layer); |
|
1186 |
} |
|
1187 |
} |
|
1188 |
XToolkit.XSync(); |
|
1189 |
} |
|
1190 |
||
1191 |
void setExtendedState(XWindowPeer window, int state) { |
|
107 | 1192 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) { |
2 | 1193 |
if (proto.supportsState(state)) { |
1194 |
proto.setState(window, state); |
|
1195 |
break; |
|
1196 |
} |
|
1197 |
} |
|
1198 |
||
1199 |
if (!window.isShowing()) { |
|
1200 |
/* |
|
1201 |
* Purge KWM bits. |
|
1202 |
* Not really tested with KWM, only with WindowMaker. |
|
1203 |
*/ |
|
1204 |
XToolkit.awtLock(); |
|
1205 |
try { |
|
1206 |
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), |
|
1207 |
window.getWindow(), |
|
1208 |
XA_KWM_WIN_ICONIFIED.getAtom()); |
|
1209 |
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), |
|
1210 |
window.getWindow(), |
|
1211 |
XA_KWM_WIN_MAXIMIZED.getAtom()); |
|
1212 |
} |
|
1213 |
finally { |
|
1214 |
XToolkit.awtUnlock(); |
|
1215 |
} |
|
1216 |
} |
|
1217 |
XToolkit.XSync(); |
|
1218 |
} |
|
1219 |
||
1220 |
||
1221 |
/* |
|
1222 |
* Work around for 4775545. |
|
1223 |
* |
|
1224 |
* If WM exits while the top-level is shaded, the shaded hint remains |
|
1225 |
* on the top-level properties. When WM restarts and sees the shaded |
|
1226 |
* window it can reparent it into a "pre-shaded" decoration frame |
|
1227 |
* (Metacity does), and our insets logic will go crazy, b/c it will |
|
1228 |
* see a huge nagative bottom inset. There's no clean solution for |
|
1229 |
* this, so let's just be weasels and drop the shaded hint if we |
|
1230 |
* detect that WM exited. NB: we are in for a race condition with WM |
|
1231 |
* restart here. NB2: e.g. WindowMaker saves the state in a private |
|
1232 |
* property that this code knows nothing about, so this workaround is |
|
1233 |
* not effective; other WMs might play similar tricks. |
|
1234 |
*/ |
|
1235 |
void unshadeKludge(XDecoratedPeer window) { |
|
1236 |
assert(window.isShowing()); |
|
1237 |
||
107 | 1238 |
for (XStateProtocol proto : getProtocols(XStateProtocol.class)) { |
2 | 1239 |
proto.unshadeKludge(window); |
1240 |
} |
|
1241 |
XToolkit.XSync(); |
|
1242 |
} |
|
1243 |
||
1244 |
static boolean inited = false; |
|
1245 |
static void init() { |
|
1246 |
if (inited) { |
|
1247 |
return; |
|
1248 |
} |
|
1249 |
||
1250 |
initAtoms(); |
|
1251 |
getWM(); |
|
1252 |
inited = true; |
|
1253 |
} |
|
1254 |
||
1255 |
void initializeProtocols() { |
|
1256 |
XNETProtocol net_protocol = g_net_protocol; |
|
1257 |
if (net_protocol != null) { |
|
1258 |
if (!net_protocol.active()) { |
|
1259 |
net_protocol = null; |
|
1260 |
} else { |
|
1261 |
if (net_protocol.doStateProtocol()) { |
|
1262 |
addProtocol(XStateProtocol.class, net_protocol); |
|
1263 |
} |
|
1264 |
if (net_protocol.doLayerProtocol()) { |
|
1265 |
addProtocol(XLayerProtocol.class, net_protocol); |
|
1266 |
} |
|
1267 |
} |
|
1268 |
} |
|
1269 |
||
1270 |
XWINProtocol win = g_win_protocol; |
|
1271 |
if (win != null) { |
|
1272 |
if (win.active()) { |
|
1273 |
if (win.doStateProtocol()) { |
|
1274 |
addProtocol(XStateProtocol.class, win); |
|
1275 |
} |
|
1276 |
if (win.doLayerProtocol()) { |
|
1277 |
addProtocol(XLayerProtocol.class, win); |
|
1278 |
} |
|
1279 |
} |
|
1280 |
} |
|
1281 |
} |
|
1282 |
||
1283 |
HashMap storedInsets = new HashMap(); |
|
1284 |
Insets guessInsets(XDecoratedPeer window) { |
|
1285 |
Insets res = (Insets)storedInsets.get(window.getClass()); |
|
1286 |
if (res == null) { |
|
1287 |
switch (WMID) { |
|
1288 |
case ENLIGHTEN_WM: |
|
1289 |
res = new Insets(19, 4, 4, 4); |
|
1290 |
break; |
|
1291 |
case CDE_WM: |
|
1292 |
res = new Insets(28, 6, 6, 6); |
|
1293 |
break; |
|
1294 |
case NO_WM: |
|
1295 |
case LG3D_WM: |
|
1296 |
res = zeroInsets; |
|
1297 |
break; |
|
1298 |
case MOTIF_WM: |
|
1299 |
case OPENLOOK_WM: |
|
1300 |
default: |
|
1301 |
res = defaultInsets; |
|
1302 |
} |
|
1303 |
} |
|
1304 |
if (insLog.isLoggable(Level.FINEST)) insLog.finest("WM guessed insets: " + res); |
|
1305 |
return res; |
|
1306 |
} |
|
1307 |
/* |
|
1308 |
* Some buggy WMs ignore window gravity when processing |
|
1309 |
* ConfigureRequest and position window as if the gravity is Static. |
|
1310 |
* We work around this in MWindowPeer.pReshape(). |
|
1311 |
* |
|
1312 |
* Starting with 1.5 we have introduced an Environment variable |
|
1313 |
* _JAVA_AWT_WM_STATIC_GRAVITY that can be set to indicate to Java |
|
1314 |
* explicitly that the WM has this behaviour, example is FVWM. |
|
1315 |
*/ |
|
1316 |
||
1317 |
static int awtWMStaticGravity = -1; |
|
1318 |
static boolean configureGravityBuggy() { |
|
1319 |
||
1320 |
if (awtWMStaticGravity == -1) { |
|
1321 |
awtWMStaticGravity = (XToolkit.getEnv("_JAVA_AWT_WM_STATIC_GRAVITY") != null) ? 1 : 0; |
|
1322 |
} |
|
1323 |
||
1324 |
if (awtWMStaticGravity == 1) { |
|
1325 |
return true; |
|
1326 |
} |
|
1327 |
||
1328 |
switch(getWMID()) { |
|
1329 |
case XWM.ICE_WM: |
|
1330 |
/* |
|
1331 |
* See bug #228981 at IceWM's SourceForge pages. |
|
1332 |
* Latest stable version 1.0.8-6 still has this problem. |
|
1333 |
*/ |
|
1334 |
/** |
|
1335 |
* Version 1.2.2 doesn't have this problem |
|
1336 |
*/ |
|
1337 |
// Detect IceWM version |
|
1338 |
if (g_net_protocol != null) { |
|
1339 |
String wm_name = g_net_protocol.getWMName(); |
|
1340 |
Pattern pat = Pattern.compile("^IceWM (\\d+)\\.(\\d+)\\.(\\d+).*$"); |
|
1341 |
try { |
|
1342 |
Matcher match = pat.matcher(wm_name); |
|
1343 |
if (match.matches()) { |
|
1344 |
int v1 = Integer.parseInt(match.group(1)); |
|
1345 |
int v2 = Integer.parseInt(match.group(2)); |
|
1346 |
int v3 = Integer.parseInt(match.group(3)); |
|
1347 |
return !(v1 > 1 || (v1 == 1 && (v2 > 2 || (v2 == 2 && v3 >=2)))); |
|
1348 |
} |
|
1349 |
} catch (Exception e) { |
|
1350 |
return true; |
|
1351 |
} |
|
1352 |
} |
|
1353 |
return true; |
|
1354 |
case XWM.ENLIGHTEN_WM: |
|
1355 |
/* At least E16 is buggy. */ |
|
1356 |
return true; |
|
1357 |
default: |
|
1358 |
return false; |
|
1359 |
} |
|
1360 |
} |
|
1361 |
||
1362 |
/* |
|
1363 |
* @return if WM implements the insets property - returns insets with values |
|
1364 |
* specified in that property, null otherwise. |
|
1365 |
*/ |
|
1366 |
public static Insets getInsetsFromExtents(long window) { |
|
1367 |
if (window == XConstants.None) { |
|
1368 |
return null; |
|
1369 |
} |
|
1370 |
XNETProtocol net_protocol = getWM().getNETProtocol(); |
|
1371 |
if (net_protocol != null && net_protocol.active()) { |
|
1372 |
Insets insets = getInsetsFromProp(window, XA_NET_FRAME_EXTENTS); |
|
1373 |
insLog.log(Level.FINE, "_NET_FRAME_EXTENTS: {0}", insets); |
|
1374 |
||
1375 |
if (insets != null) { |
|
1376 |
return insets; |
|
1377 |
} |
|
1378 |
} |
|
1379 |
switch(getWMID()) { |
|
1380 |
case XWM.KDE2_WM: |
|
1381 |
return getInsetsFromProp(window, XA_KDE_NET_WM_FRAME_STRUT); |
|
1382 |
case XWM.ENLIGHTEN_WM: |
|
1383 |
return getInsetsFromProp(window, XA_E_FRAME_SIZE); |
|
1384 |
default: |
|
1385 |
return null; |
|
1386 |
} |
|
1387 |
} |
|
1388 |
||
1389 |
/** |
|
1390 |
* Helper function reads property of type CARDINAL[4] = { left, right, top, bottom } |
|
1391 |
* and converts it to Insets object. |
|
1392 |
*/ |
|
1393 |
public static Insets getInsetsFromProp(long window, XAtom atom) { |
|
1394 |
if (window == XConstants.None) { |
|
1395 |
return null; |
|
1396 |
} |
|
1397 |
||
1398 |
WindowPropertyGetter getter = |
|
1399 |
new WindowPropertyGetter(window, atom, |
|
1400 |
0, 4, false, XAtom.XA_CARDINAL); |
|
1401 |
try { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1402 |
if (getter.execute() != XConstants.Success |
2 | 1403 |
|| getter.getData() == 0 |
1404 |
|| getter.getActualType() != XAtom.XA_CARDINAL |
|
1405 |
|| getter.getActualFormat() != 32) |
|
1406 |
{ |
|
1407 |
return null; |
|
1408 |
} else { |
|
1409 |
return new Insets((int)Native.getCard32(getter.getData(), 2), // top |
|
1410 |
(int)Native.getCard32(getter.getData(), 0), // left |
|
1411 |
(int)Native.getCard32(getter.getData(), 3), // bottom |
|
1412 |
(int)Native.getCard32(getter.getData(), 1)); // right |
|
1413 |
} |
|
1414 |
} finally { |
|
1415 |
getter.dispose(); |
|
1416 |
} |
|
1417 |
} |
|
1418 |
||
1419 |
/** |
|
1420 |
* Asks WM to fill Frame Extents (insets) for the window. |
|
1421 |
*/ |
|
1422 |
public static void requestWMExtents(long window) { |
|
1423 |
if (window == XConstants.None) { // not initialized |
|
1424 |
return; |
|
1425 |
} |
|
1426 |
||
1427 |
log.fine("Requesting FRAME_EXTENTS"); |
|
1428 |
||
1429 |
XClientMessageEvent msg = new XClientMessageEvent(); |
|
1430 |
msg.zero(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1431 |
msg.set_type(XConstants.ClientMessage); |
2 | 1432 |
msg.set_display(XToolkit.getDisplay()); |
1433 |
msg.set_window(window); |
|
1434 |
msg.set_format(32); |
|
1435 |
XToolkit.awtLock(); |
|
1436 |
try { |
|
1437 |
XNETProtocol net_protocol = getWM().getNETProtocol(); |
|
1438 |
if (net_protocol != null && net_protocol.active()) { |
|
1439 |
msg.set_message_type(XA_NET_REQUEST_FRAME_EXTENTS.getAtom()); |
|
1440 |
XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1441 |
false, |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1442 |
XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask, |
2 | 1443 |
msg.getPData()); |
1444 |
} |
|
1445 |
if (getWMID() == XWM.KDE2_WM) { |
|
1446 |
msg.set_message_type(XA_KDE_NET_WM_FRAME_STRUT.getAtom()); |
|
1447 |
XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1448 |
false, |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
107
diff
changeset
|
1449 |
XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask, |
2 | 1450 |
msg.getPData()); |
1451 |
} |
|
1452 |
// XXX: should we wait for response? XIfEvent() would be useful here :) |
|
1453 |
} finally { |
|
1454 |
XToolkit.awtUnlock(); |
|
1455 |
msg.dispose(); |
|
1456 |
} |
|
1457 |
} |
|
1458 |
||
1459 |
/* syncTopLEvelPos() is necessary to insure that the window manager has in |
|
1460 |
* fact moved us to our final position relative to the reParented WM window. |
|
1461 |
* We have noted a timing window which our shell has not been moved so we |
|
1462 |
* screw up the insets thinking they are 0,0. Wait (for a limited period of |
|
1463 |
* time to let the WM hava a chance to move us. |
|
1464 |
* @param window window ID of the shell, assuming it is the window |
|
1465 |
* which will NOT have zero coordinates after the complete |
|
1466 |
* reparenting |
|
1467 |
*/ |
|
1468 |
boolean syncTopLevelPos(long window, XWindowAttributes attrs) { |
|
1469 |
int tries = 0; |
|
1470 |
XToolkit.awtLock(); |
|
1471 |
try { |
|
1472 |
do { |
|
1473 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), window, attrs.pData); |
|
1474 |
if (attrs.get_x() != 0 || attrs.get_y() != 0) { |
|
1475 |
return true; |
|
1476 |
} |
|
1477 |
tries++; |
|
1478 |
XToolkit.XSync(); |
|
1479 |
} while (tries < 50); |
|
1480 |
} |
|
1481 |
finally { |
|
1482 |
XToolkit.awtUnlock(); |
|
1483 |
} |
|
1484 |
return false; |
|
1485 |
} |
|
1486 |
||
1487 |
Insets getInsets(XDecoratedPeer win, long window, long parent) { |
|
1488 |
/* |
|
1489 |
* Unfortunately the concept of "insets" borrowed to AWT |
|
1490 |
* from Win32 is *absolutely*, *unbelievably* foreign to |
|
1491 |
* X11. Few WMs provide the size of frame decor |
|
1492 |
* (i.e. insets) in a property they set on the client |
|
1493 |
* window, so we check if we can get away with just |
|
1494 |
* peeking at it. [Future versions of wm-spec might add a |
|
1495 |
* standardized hint for this]. |
|
1496 |
* |
|
1497 |
* Otherwise we do some special casing. Actually the |
|
1498 |
* fallback code ("default" case) seems to cover most of |
|
1499 |
* the existing WMs (modulo Reparent/Configure order |
|
1500 |
* perhaps?). |
|
1501 |
* |
|
1502 |
* Fallback code tries to account for the two most common cases: |
|
1503 |
* |
|
1504 |
* . single reparenting |
|
1505 |
* parent window is the WM frame |
|
1506 |
* [twm, olwm, sawfish] |
|
1507 |
* |
|
1508 |
* . double reparenting |
|
1509 |
* parent is a lining exactly the size of the client |
|
1510 |
* grandpa is the WM frame |
|
1511 |
* [mwm, e!, kwin, fvwm2 ... ] |
|
1512 |
*/ |
|
1513 |
Insets correctWM = XWM.getInsetsFromExtents(window); |
|
1514 |
insLog.log(Level.FINER, "Got insets from property: {0}", correctWM); |
|
1515 |
||
1516 |
if (correctWM == null) { |
|
1517 |
correctWM = new Insets(0,0,0,0); |
|
1518 |
||
1519 |
correctWM.top = -1; |
|
1520 |
correctWM.left = -1; |
|
1521 |
||
1522 |
XWindowAttributes lwinAttr = new XWindowAttributes(); |
|
1523 |
XWindowAttributes pattr = new XWindowAttributes(); |
|
1524 |
try { |
|
1525 |
switch (XWM.getWMID()) { |
|
1526 |
/* should've been done in awt_wm_getInsetsFromProp */ |
|
1527 |
case XWM.ENLIGHTEN_WM: { |
|
1528 |
/* enlightenment does double reparenting */ |
|
1529 |
syncTopLevelPos(parent, lwinAttr); |
|
1530 |
correctWM.left = lwinAttr.get_x(); |
|
1531 |
correctWM.top = lwinAttr.get_y(); |
|
1532 |
/* |
|
1533 |
* Now get the actual dimensions of the parent window |
|
1534 |
* resolve the difference. We can't rely on the left |
|
1535 |
* to be equal to right or bottom... Enlightment |
|
1536 |
* breaks that assumption. |
|
1537 |
*/ |
|
1538 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
1539 |
XlibUtil.getParentWindow(parent), |
|
1540 |
pattr.pData); |
|
1541 |
correctWM.right = pattr.get_width() - |
|
1542 |
(lwinAttr.get_width() + correctWM.left); |
|
1543 |
correctWM.bottom = pattr.get_height() - |
|
1544 |
(lwinAttr.get_height() + correctWM.top); |
|
1545 |
||
1546 |
break; |
|
1547 |
} |
|
1548 |
case XWM.ICE_WM: // for 1.2.2. |
|
1549 |
case XWM.KDE2_WM: /* should've been done in getInsetsFromProp */ |
|
1550 |
case XWM.CDE_WM: |
|
1551 |
case XWM.MOTIF_WM: { |
|
1552 |
/* these are double reparenting too */ |
|
1553 |
if (syncTopLevelPos(parent, lwinAttr)) { |
|
1554 |
correctWM.top = lwinAttr.get_y(); |
|
1555 |
correctWM.left = lwinAttr.get_x(); |
|
1556 |
correctWM.right = correctWM.left; |
|
1557 |
correctWM.bottom = correctWM.left; |
|
1558 |
} else { |
|
1559 |
return null; |
|
1560 |
} |
|
1561 |
break; |
|
1562 |
} |
|
1563 |
case XWM.SAWFISH_WM: |
|
1564 |
case XWM.OPENLOOK_WM: { |
|
1565 |
/* single reparenting */ |
|
1566 |
syncTopLevelPos(window, lwinAttr); |
|
1567 |
correctWM.top = lwinAttr.get_y(); |
|
1568 |
correctWM.left = lwinAttr.get_x(); |
|
1569 |
correctWM.right = correctWM.left; |
|
1570 |
correctWM.bottom = correctWM.left; |
|
1571 |
break; |
|
1572 |
} |
|
1573 |
case XWM.OTHER_WM: |
|
1574 |
default: { /* this is very similar to the E! case above */ |
|
1575 |
insLog.log(Level.FINEST, "Getting correct insets for OTHER_WM/default, parent: {0}", parent); |
|
1576 |
syncTopLevelPos(parent, lwinAttr); |
|
1577 |
int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
1578 |
window, lwinAttr.pData); |
|
1579 |
status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
1580 |
parent, pattr.pData); |
|
1581 |
if (lwinAttr.get_root() == parent) { |
|
1582 |
insLog.finest("our parent is root so insets should be zero"); |
|
1583 |
correctWM = new Insets(0, 0, 0, 0); |
|
1584 |
break; |
|
1585 |
} |
|
1586 |
||
1587 |
/* |
|
1588 |
* Check for double-reparenting WM. |
|
1589 |
* |
|
1590 |
* If the parent is exactly the same size as the |
|
1591 |
* top-level assume taht it's the "lining" window and |
|
1592 |
* that the grandparent is the actual frame (NB: we |
|
1593 |
* have already handled undecorated windows). |
|
1594 |
* |
|
1595 |
* XXX: what about timing issues that syncTopLevelPos |
|
1596 |
* is supposed to work around? |
|
1597 |
*/ |
|
1598 |
if (lwinAttr.get_x() == 0 && lwinAttr.get_y() == 0 |
|
1599 |
&& lwinAttr.get_width()+2*lwinAttr.get_border_width() == pattr.get_width() |
|
1600 |
&& lwinAttr.get_height()+2*lwinAttr.get_border_width() == pattr.get_height()) |
|
1601 |
{ |
|
1602 |
insLog.log(Level.FINEST, "Double reparenting detected, pattr({2})={0}, lwinAttr({3})={1}", |
|
1603 |
new Object[] {lwinAttr, pattr, parent, window}); |
|
1604 |
lwinAttr.set_x(pattr.get_x()); |
|
1605 |
lwinAttr.set_y(pattr.get_y()); |
|
1606 |
lwinAttr.set_border_width(lwinAttr.get_border_width()+pattr.get_border_width()); |
|
1607 |
||
1608 |
final long grand_parent = XlibUtil.getParentWindow(parent); |
|
1609 |
||
1610 |
if (grand_parent == lwinAttr.get_root()) { |
|
1611 |
// This is not double-reparenting in a |
|
1612 |
// general sense - we simply don't have |
|
1613 |
// correct insets - return null to try to |
|
1614 |
// get insets later |
|
1615 |
return null; |
|
1616 |
} else { |
|
1617 |
parent = grand_parent; |
|
1618 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
1619 |
parent, |
|
1620 |
pattr.pData); |
|
1621 |
} |
|
1622 |
} |
|
1623 |
/* |
|
1624 |
* XXX: To be absolutely correct, we'd need to take |
|
1625 |
* parent's border-width into account too, but the |
|
1626 |
* rest of the code is happily unaware about border |
|
1627 |
* widths and inner/outer distinction, so for the time |
|
1628 |
* being, just ignore it. |
|
1629 |
*/ |
|
1630 |
insLog.log(Level.FINEST, "Attrs before calculation: pattr({2})={0}, lwinAttr({3})={1}", |
|
1631 |
new Object[] {lwinAttr, pattr, parent, window}); |
|
1632 |
correctWM = new Insets(lwinAttr.get_y() + lwinAttr.get_border_width(), |
|
1633 |
lwinAttr.get_x() + lwinAttr.get_border_width(), |
|
1634 |
pattr.get_height() - (lwinAttr.get_y() + lwinAttr.get_height() + 2*lwinAttr.get_border_width()), |
|
1635 |
pattr.get_width() - (lwinAttr.get_x() + lwinAttr.get_width() + 2*lwinAttr.get_border_width())); |
|
1636 |
break; |
|
1637 |
} /* default */ |
|
1638 |
} /* switch (runningWM) */ |
|
1639 |
} finally { |
|
1640 |
lwinAttr.dispose(); |
|
1641 |
pattr.dispose(); |
|
1642 |
} |
|
1643 |
} |
|
1644 |
if (storedInsets.get(win.getClass()) == null) { |
|
1645 |
storedInsets.put(win.getClass(), correctWM); |
|
1646 |
} |
|
1647 |
return correctWM; |
|
1648 |
} |
|
1649 |
boolean isDesktopWindow( long w ) { |
|
1650 |
if (g_net_protocol != null) { |
|
1651 |
XAtomList wtype = XAtom.get("_NET_WM_WINDOW_TYPE").getAtomListPropertyList( w ); |
|
1652 |
return wtype.contains( XAtom.get("_NET_WM_WINDOW_TYPE_DESKTOP") ); |
|
1653 |
} else { |
|
1654 |
return false; |
|
1655 |
} |
|
1656 |
} |
|
1657 |
||
1658 |
public XNETProtocol getNETProtocol() { |
|
1659 |
return g_net_protocol; |
|
1660 |
} |
|
1661 |
||
1662 |
/** |
|
1663 |
* Sets _NET_WN_ICON property on the window using the arrays of |
|
1664 |
* raster-data for icons. If icons is null, removes _NET_WM_ICON |
|
1665 |
* property. |
|
1666 |
* This method invokes XNETProtocol.setWMIcon() for WMs that |
|
1667 |
* support NET protocol. |
|
1668 |
* |
|
1669 |
* @return true if hint was modified successfully, false otherwise |
|
1670 |
*/ |
|
1671 |
public boolean setNetWMIcon(XWindowPeer window, java.util.List<XIconInfo> icons) { |
|
1672 |
if (g_net_protocol != null && g_net_protocol.active()) { |
|
1673 |
g_net_protocol.setWMIcons(window, icons); |
|
1674 |
return getWMID() != ICE_WM; |
|
1675 |
} |
|
1676 |
return false; |
|
1677 |
} |
|
1678 |
} |