2
|
1 |
/*
|
|
2 |
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
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 |
package sun.awt.X11;
|
|
26 |
|
|
27 |
import java.awt.*;
|
|
28 |
|
|
29 |
import java.awt.event.ComponentEvent;
|
|
30 |
import java.awt.event.InvocationEvent;
|
|
31 |
import java.awt.event.WindowEvent;
|
|
32 |
|
|
33 |
import java.util.logging.Level;
|
|
34 |
import java.util.logging.Logger;
|
|
35 |
|
|
36 |
import sun.awt.ComponentAccessor;
|
|
37 |
import sun.awt.SunToolkit;
|
|
38 |
|
|
39 |
class XDecoratedPeer extends XWindowPeer {
|
|
40 |
private static final Logger log = Logger.getLogger("sun.awt.X11.XDecoratedPeer");
|
|
41 |
private static final Logger insLog = Logger.getLogger("sun.awt.X11.insets.XDecoratedPeer");
|
|
42 |
private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XDecoratedPeer");
|
|
43 |
private final static Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XDecoratedPeer");
|
|
44 |
|
|
45 |
private static XAtom resize_request = new XAtom("_SUN_AWT_RESIZE_REQUEST", false);
|
|
46 |
|
|
47 |
// Set to true when we get the first ConfigureNotify after being
|
|
48 |
// reparented - indicates that WM has adopted the top-level.
|
|
49 |
boolean configure_seen;
|
|
50 |
boolean insets_corrected;
|
|
51 |
|
|
52 |
XIconWindow iconWindow;
|
|
53 |
WindowDimensions dimensions;
|
|
54 |
XContentWindow content;
|
|
55 |
Insets currentInsets;
|
|
56 |
XFocusProxyWindow focusProxy;
|
|
57 |
|
|
58 |
XDecoratedPeer(Window target) {
|
|
59 |
super(target);
|
|
60 |
}
|
|
61 |
|
|
62 |
XDecoratedPeer(XCreateWindowParams params) {
|
|
63 |
super(params);
|
|
64 |
}
|
|
65 |
|
|
66 |
public long getShell() {
|
|
67 |
return window;
|
|
68 |
}
|
|
69 |
|
|
70 |
public long getContentWindow() {
|
|
71 |
return (content == null) ? window : content.getWindow();
|
|
72 |
}
|
|
73 |
|
|
74 |
void preInit(XCreateWindowParams params) {
|
|
75 |
super.preInit(params);
|
|
76 |
if (!resize_request.isInterned()) {
|
|
77 |
resize_request.intern(false);
|
|
78 |
}
|
|
79 |
winAttr.initialFocus = true;
|
|
80 |
|
|
81 |
currentInsets = new Insets(0,0,0,0); // replacemenet for wdata->top, left, bottom, right
|
|
82 |
|
|
83 |
applyGuessedInsets();
|
|
84 |
Rectangle bounds = (Rectangle)params.get(BOUNDS);
|
|
85 |
dimensions = new WindowDimensions(bounds, getRealInsets(), false);
|
|
86 |
params.put(BOUNDS, dimensions.getClientRect());
|
|
87 |
insLog.log(Level.FINE, "Initial dimensions {0}", new Object[] { dimensions });
|
|
88 |
|
|
89 |
// Deny default processing of these events on the shell - proxy will take care of
|
|
90 |
// them instead
|
|
91 |
Long eventMask = (Long)params.get(EVENT_MASK);
|
|
92 |
params.add(EVENT_MASK, Long.valueOf(eventMask.longValue() & ~(FocusChangeMask | KeyPressMask | KeyReleaseMask)));
|
|
93 |
}
|
|
94 |
|
|
95 |
void postInit(XCreateWindowParams params) {
|
|
96 |
super.postInit(params);
|
|
97 |
// The lines that follow need to be in a postInit, so they
|
|
98 |
// happen after the X window is created.
|
|
99 |
initResizability();
|
|
100 |
updateSizeHints(dimensions);
|
|
101 |
content = createContent(dimensions);
|
|
102 |
content.initialize();
|
|
103 |
if (warningWindow != null) {
|
|
104 |
warningWindow.toFront();
|
|
105 |
}
|
|
106 |
focusProxy = createFocusProxy();
|
|
107 |
}
|
|
108 |
|
|
109 |
void setIconHints(java.util.List<XIconInfo> icons) {
|
|
110 |
if (!XWM.getWM().setNetWMIcon(this, icons)) {
|
|
111 |
if (icons.size() > 0) {
|
|
112 |
if (iconWindow == null) {
|
|
113 |
iconWindow = new XIconWindow(this);
|
|
114 |
}
|
|
115 |
iconWindow.setIconImages(icons);
|
|
116 |
}
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
public void updateMinimumSize() {
|
|
121 |
super.updateMinimumSize();
|
|
122 |
updateMinSizeHints();
|
|
123 |
}
|
|
124 |
|
|
125 |
|
|
126 |
private void updateMinSizeHints() {
|
|
127 |
if (isResizable()) {
|
|
128 |
Dimension minimumSize = getTargetMinimumSize();
|
|
129 |
if (minimumSize != null) {
|
|
130 |
Insets insets = getRealInsets();
|
|
131 |
int minWidth = minimumSize.width - insets.left - insets.right;
|
|
132 |
int minHeight = minimumSize.height - insets.top - insets.bottom;
|
|
133 |
if (minWidth < 0) minWidth = 0;
|
|
134 |
if (minHeight < 0) minHeight = 0;
|
|
135 |
setSizeHints(XlibWrapper.PMinSize | (isLocationByPlatform()?0:(XlibWrapper.PPosition | XlibWrapper.USPosition)),
|
|
136 |
getX(), getY(), minWidth, minHeight);
|
|
137 |
if (isVisible()) {
|
|
138 |
Rectangle bounds = getShellBounds();
|
|
139 |
int nw = (bounds.width < minWidth) ? minWidth : bounds.width;
|
|
140 |
int nh = (bounds.height < minHeight) ? minHeight : bounds.height;
|
|
141 |
if (nw != bounds.width || nh != bounds.height) {
|
|
142 |
setShellSize(new Rectangle(0, 0, nw, nh));
|
|
143 |
}
|
|
144 |
}
|
|
145 |
} else {
|
|
146 |
boolean isMinSizeSet = isMinSizeSet();
|
|
147 |
XWM.removeSizeHints(this, XlibWrapper.PMinSize);
|
|
148 |
/* Some WMs need remap to redecorate the window */
|
|
149 |
if (isMinSizeSet && isShowing() && XWM.needRemap(this)) {
|
|
150 |
/*
|
|
151 |
* Do the re/mapping at the Xlib level. Since we essentially
|
|
152 |
* work around a WM bug we don't want this hack to be exposed
|
|
153 |
* to Intrinsics (i.e. don't mess with grabs, callbacks etc).
|
|
154 |
*/
|
|
155 |
xSetVisible(false);
|
|
156 |
XToolkit.XSync();
|
|
157 |
xSetVisible(true);
|
|
158 |
}
|
|
159 |
}
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
XContentWindow createContent(WindowDimensions dims) {
|
|
164 |
Rectangle rec = dims.getBounds();
|
|
165 |
// Fix for - set the location of the content window to the (-left inset, -top inset)
|
|
166 |
Insets ins = dims.getInsets();
|
|
167 |
if (ins != null) {
|
|
168 |
rec.x = -ins.left;
|
|
169 |
rec.y = -ins.top;
|
|
170 |
} else {
|
|
171 |
rec.x = 0;
|
|
172 |
rec.y = 0;
|
|
173 |
}
|
|
174 |
return new XContentWindow(this, rec);
|
|
175 |
}
|
|
176 |
|
|
177 |
XFocusProxyWindow createFocusProxy() {
|
|
178 |
return new XFocusProxyWindow(this);
|
|
179 |
}
|
|
180 |
|
|
181 |
protected XAtomList getWMProtocols() {
|
|
182 |
XAtomList protocols = super.getWMProtocols();
|
|
183 |
protocols.add(wm_delete_window);
|
|
184 |
protocols.add(wm_take_focus);
|
|
185 |
return protocols;
|
|
186 |
}
|
|
187 |
|
|
188 |
public Graphics getGraphics() {
|
|
189 |
return getGraphics(content.surfaceData,
|
|
190 |
ComponentAccessor.getForeground(target),
|
|
191 |
ComponentAccessor.getBackground(target),
|
|
192 |
ComponentAccessor.getFont_NoClientCode(target));
|
|
193 |
}
|
|
194 |
|
|
195 |
public void setTitle(String title) {
|
|
196 |
if (log.isLoggable(Level.FINE)) log.fine("Title is " + title);
|
|
197 |
winAttr.title = title;
|
|
198 |
updateWMName();
|
|
199 |
}
|
|
200 |
|
|
201 |
protected String getWMName() {
|
|
202 |
if (winAttr.title == null || winAttr.title.trim().equals("")) {
|
|
203 |
return " ";
|
|
204 |
} else {
|
|
205 |
return winAttr.title;
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
void updateWMName() {
|
|
210 |
super.updateWMName();
|
|
211 |
String name = getWMName();
|
|
212 |
XToolkit.awtLock();
|
|
213 |
try {
|
|
214 |
if (name == null || name.trim().equals("")) {
|
|
215 |
name = "Java";
|
|
216 |
}
|
|
217 |
XAtom iconNameAtom = XAtom.get(XAtom.XA_WM_ICON_NAME);
|
|
218 |
iconNameAtom.setProperty(getWindow(), name);
|
|
219 |
XAtom netIconNameAtom = XAtom.get("_NET_WM_ICON_NAME");
|
|
220 |
netIconNameAtom.setPropertyUTF8(getWindow(), name);
|
|
221 |
} finally {
|
|
222 |
XToolkit.awtUnlock();
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
// NOTE: This method may be called by privileged threads.
|
|
227 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
|
|
228 |
public void handleIconify() {
|
|
229 |
postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED));
|
|
230 |
}
|
|
231 |
|
|
232 |
// NOTE: This method may be called by privileged threads.
|
|
233 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
|
|
234 |
public void handleDeiconify() {
|
|
235 |
postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED));
|
|
236 |
}
|
|
237 |
|
|
238 |
public void handleFocusEvent(XEvent xev) {
|
|
239 |
super.handleFocusEvent(xev);
|
|
240 |
XFocusChangeEvent xfe = xev.get_xfocus();
|
|
241 |
|
|
242 |
// If we somehow received focus events forward it instead to proxy
|
|
243 |
// FIXME: Shouldn't we instead check for inferrior?
|
|
244 |
focusLog.finer("Received focus event on shell: " + xfe);
|
|
245 |
// focusProxy.xRequestFocus();
|
|
246 |
}
|
|
247 |
|
|
248 |
/***************************************************************************************
|
|
249 |
* I N S E T S C O D E
|
|
250 |
**************************************************************************************/
|
|
251 |
|
|
252 |
protected boolean isInitialReshape() {
|
|
253 |
return false;
|
|
254 |
}
|
|
255 |
|
|
256 |
Insets difference(Insets i1, Insets i2) {
|
|
257 |
return new Insets(i1.top-i2.top, i1.left - i2.left, i1.bottom-i2.bottom, i1.right-i2.right);
|
|
258 |
}
|
|
259 |
|
|
260 |
void add(Insets i1, Insets i2) {
|
|
261 |
i1.left += i2.left;
|
|
262 |
i1.top += i2.top;
|
|
263 |
i1.right += i2.right;
|
|
264 |
i1.bottom += i2.bottom;
|
|
265 |
}
|
|
266 |
boolean isNull(Insets i) {
|
|
267 |
return (i == null) || ((i.left | i.top | i.right | i.bottom) == 0);
|
|
268 |
}
|
|
269 |
Insets copy(Insets i) {
|
|
270 |
return new Insets(i.top, i.left, i.bottom, i.right);
|
|
271 |
}
|
|
272 |
|
|
273 |
long reparent_serial = 0;
|
|
274 |
|
|
275 |
public void handleReparentNotifyEvent(XEvent xev) {
|
|
276 |
XReparentEvent xe = xev.get_xreparent();
|
|
277 |
if (insLog.isLoggable(Level.FINE)) insLog.fine(xe.toString());
|
|
278 |
reparent_serial = xe.get_serial();
|
|
279 |
XToolkit.awtLock();
|
|
280 |
try {
|
|
281 |
long root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber());
|
|
282 |
|
|
283 |
if (isEmbedded()) {
|
|
284 |
setReparented(true);
|
|
285 |
insets_corrected = true;
|
|
286 |
return;
|
|
287 |
}
|
|
288 |
Component t = (Component)target;
|
|
289 |
if (getDecorations() == winAttr.AWT_DECOR_NONE) {
|
|
290 |
setReparented(true);
|
|
291 |
insets_corrected = true;
|
|
292 |
reshape(dimensions, SET_SIZE, false);
|
|
293 |
} else if (xe.get_parent() == root) {
|
|
294 |
configure_seen = false;
|
|
295 |
insets_corrected = false;
|
|
296 |
|
|
297 |
/*
|
|
298 |
* We can be repareted to root for two reasons:
|
|
299 |
* . setVisible(false)
|
|
300 |
* . WM exited
|
|
301 |
*/
|
|
302 |
if (isVisible()) { /* WM exited */
|
|
303 |
/* Work around 4775545 */
|
|
304 |
XWM.getWM().unshadeKludge(this);
|
|
305 |
insLog.fine("- WM exited");
|
|
306 |
} else {
|
|
307 |
insLog.fine(" - reparent due to hide");
|
|
308 |
}
|
|
309 |
} else { /* reparented to WM frame, figure out our insets */
|
|
310 |
setReparented(true);
|
|
311 |
insets_corrected = false;
|
|
312 |
|
|
313 |
// Check if we have insets provided by the WM
|
|
314 |
Insets correctWM = getWMSetInsets(null);
|
|
315 |
if (correctWM != null) {
|
|
316 |
insLog.log(Level.FINER, "wm-provided insets {0}", new Object[]{correctWM});
|
|
317 |
// If these insets are equal to our current insets - no actions are necessary
|
|
318 |
Insets dimInsets = dimensions.getInsets();
|
|
319 |
if (correctWM.equals(dimInsets)) {
|
|
320 |
insLog.finer("Insets are the same as estimated - no additional reshapes necessary");
|
|
321 |
no_reparent_artifacts = true;
|
|
322 |
insets_corrected = true;
|
|
323 |
applyGuessedInsets();
|
|
324 |
return;
|
|
325 |
}
|
|
326 |
} else {
|
|
327 |
correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());
|
|
328 |
|
|
329 |
if (correctWM != null) {
|
|
330 |
insLog.log(Level.FINER, "correctWM {0}", new Object[] {correctWM});
|
|
331 |
} else {
|
|
332 |
insLog.log(Level.FINER, "correctWM insets are not available, waiting for configureNotify");
|
|
333 |
}
|
|
334 |
}
|
|
335 |
|
|
336 |
if (correctWM != null) {
|
|
337 |
handleCorrectInsets(correctWM);
|
|
338 |
}
|
|
339 |
}
|
|
340 |
} finally {
|
|
341 |
XToolkit.awtUnlock();
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
protected void handleCorrectInsets(Insets correctWM) {
|
|
346 |
XToolkit.awtLock();
|
|
347 |
try {
|
|
348 |
/*
|
|
349 |
* Ok, now see if we need adjust window size because
|
|
350 |
* initial insets were wrong (most likely they were).
|
|
351 |
*/
|
|
352 |
Insets correction = difference(correctWM, currentInsets);
|
|
353 |
insLog.log(Level.FINEST, "Corrention {0}", new Object[] {correction});
|
|
354 |
if (!isNull(correction)) {
|
|
355 |
/*
|
|
356 |
* Actual insets account for menubar/warning label,
|
|
357 |
* so we can't assign directly but must adjust them.
|
|
358 |
*/
|
|
359 |
add(currentInsets, correction);
|
|
360 |
applyGuessedInsets();
|
|
361 |
|
|
362 |
//Fix for 6318109: PIT: Min Size is not honored properly when a
|
|
363 |
//smaller size is specified in setSize(), XToolkit
|
|
364 |
//update minimum size hints
|
|
365 |
updateMinSizeHints();
|
|
366 |
|
|
367 |
/*
|
|
368 |
* If this window has been sized by a pack() we need
|
|
369 |
* to keep the interior geometry intact. Since pack()
|
|
370 |
* computed width and height with wrong insets, we
|
|
371 |
* must adjust the target dimensions appropriately.
|
|
372 |
*/
|
|
373 |
}
|
|
374 |
if (insLog.isLoggable(Level.FINER)) insLog.finer("Dimensions before reparent: " + dimensions);
|
|
375 |
|
|
376 |
dimensions.setInsets(getRealInsets());
|
|
377 |
insets_corrected = true;
|
|
378 |
|
|
379 |
if (isMaximized()) {
|
|
380 |
return;
|
|
381 |
}
|
|
382 |
|
|
383 |
if ((getHints().get_flags() & (USPosition | PPosition)) != 0) {
|
|
384 |
reshape(dimensions, SET_BOUNDS, false);
|
|
385 |
} else {
|
|
386 |
reshape(dimensions, SET_SIZE, false);
|
|
387 |
}
|
|
388 |
} finally {
|
|
389 |
XToolkit.awtUnlock();
|
|
390 |
}
|
|
391 |
}
|
|
392 |
|
|
393 |
public void handleMoved(WindowDimensions dims) {
|
|
394 |
Point loc = dims.getLocation();
|
|
395 |
ComponentAccessor.setX((Component)target, loc.x);
|
|
396 |
ComponentAccessor.setY((Component)target, loc.y);
|
|
397 |
postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED));
|
|
398 |
}
|
|
399 |
|
|
400 |
|
|
401 |
protected Insets guessInsets() {
|
|
402 |
if (isEmbedded()) {
|
|
403 |
return new Insets(0, 0, 0, 0);
|
|
404 |
} else {
|
|
405 |
if (currentInsets.top > 0) {
|
|
406 |
/* insets were set on wdata by System Properties */
|
|
407 |
return copy(currentInsets);
|
|
408 |
} else {
|
|
409 |
Insets res = getWMSetInsets(null);
|
|
410 |
if (res == null) {
|
|
411 |
res = XWM.getWM().guessInsets(this);
|
|
412 |
}
|
|
413 |
return res;
|
|
414 |
}
|
|
415 |
}
|
|
416 |
}
|
|
417 |
|
|
418 |
private void applyGuessedInsets() {
|
|
419 |
Insets guessed = guessInsets();
|
|
420 |
currentInsets = copy(guessed);
|
|
421 |
insets = copy(currentInsets);
|
|
422 |
}
|
|
423 |
|
|
424 |
public void revalidate() {
|
|
425 |
XToolkit.executeOnEventHandlerThread(target, new Runnable() {
|
|
426 |
public void run() {
|
|
427 |
target.invalidate();
|
|
428 |
target.validate();
|
|
429 |
}
|
|
430 |
});
|
|
431 |
}
|
|
432 |
|
|
433 |
Insets getRealInsets() {
|
|
434 |
if (isNull(insets)) {
|
|
435 |
applyGuessedInsets();
|
|
436 |
}
|
|
437 |
return insets;
|
|
438 |
}
|
|
439 |
|
|
440 |
public Insets getInsets() {
|
|
441 |
Insets in = copy(getRealInsets());
|
|
442 |
in.top += getMenuBarHeight() + getWarningWindowHeight();
|
|
443 |
if (insLog.isLoggable(Level.FINEST)) insLog.log(Level.FINEST, "Get insets returns {0}", new Object[] {in});
|
|
444 |
return in;
|
|
445 |
}
|
|
446 |
|
|
447 |
boolean gravityBug() {
|
|
448 |
return XWM.configureGravityBuggy();
|
|
449 |
}
|
|
450 |
|
|
451 |
// The height of area used to display current active input method
|
|
452 |
int getInputMethodHeight() {
|
|
453 |
return 0;
|
|
454 |
}
|
|
455 |
|
|
456 |
void updateSizeHints(WindowDimensions dims) {
|
|
457 |
Rectangle rec = dims.getClientRect();
|
|
458 |
checkShellRect(rec);
|
|
459 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height);
|
|
460 |
}
|
|
461 |
|
|
462 |
void updateSizeHints() {
|
|
463 |
updateSizeHints(dimensions);
|
|
464 |
}
|
|
465 |
|
|
466 |
// Coordinates are that of the target
|
|
467 |
// Called only on Toolkit thread
|
|
468 |
public void reshape(WindowDimensions newDimensions, int op,
|
|
469 |
boolean userReshape)
|
|
470 |
{
|
|
471 |
if (insLog.isLoggable(Level.FINE)) {
|
|
472 |
insLog.fine("Reshaping " + this + " to " + newDimensions + " op " + op + " user reshape " + userReshape);
|
|
473 |
}
|
|
474 |
XToolkit.awtLock();
|
|
475 |
try {
|
|
476 |
if (!isReparented() || !isVisible()) {
|
|
477 |
insLog.log(Level.FINE, "- not reparented({0}) or not visible({1}), default reshape",
|
|
478 |
new Object[] {Boolean.valueOf(isReparented()), Boolean.valueOf(visible)});
|
|
479 |
|
|
480 |
// Fix for 6323293.
|
|
481 |
// This actually is needed to preserve compatibility with previous releases -
|
|
482 |
// some of licensees are expecting componentMoved event on invisible one while
|
|
483 |
// its location changes.
|
|
484 |
Point oldLocation = getLocation();
|
|
485 |
|
|
486 |
Point newLocation = new Point(ComponentAccessor.getX((Component)target),
|
|
487 |
ComponentAccessor.getY((Component)target));
|
|
488 |
|
|
489 |
if (!newLocation.equals(oldLocation)) {
|
|
490 |
handleMoved(newDimensions);
|
|
491 |
}
|
|
492 |
|
|
493 |
dimensions = new WindowDimensions(newDimensions);
|
|
494 |
updateSizeHints(dimensions);
|
|
495 |
Rectangle client = dimensions.getClientRect();
|
|
496 |
checkShellRect(client);
|
|
497 |
setShellBounds(client);
|
|
498 |
if (content != null &&
|
|
499 |
!content.getSize().equals(newDimensions.getSize()))
|
|
500 |
{
|
|
501 |
reconfigureContentWindow(newDimensions);
|
|
502 |
}
|
|
503 |
return;
|
|
504 |
}
|
|
505 |
|
|
506 |
int wm = XWM.getWMID();
|
|
507 |
updateChildrenSizes();
|
|
508 |
applyGuessedInsets();
|
|
509 |
|
|
510 |
Rectangle shellRect = newDimensions.getClientRect();
|
|
511 |
|
|
512 |
if (gravityBug()) {
|
|
513 |
Insets in = newDimensions.getInsets();
|
|
514 |
shellRect.translate(in.left, in.top);
|
|
515 |
}
|
|
516 |
|
|
517 |
if ((op & NO_EMBEDDED_CHECK) == 0 && isEmbedded()) {
|
|
518 |
shellRect.setLocation(0, 0);
|
|
519 |
}
|
|
520 |
|
|
521 |
checkShellRectSize(shellRect);
|
|
522 |
if (!isEmbedded()) {
|
|
523 |
checkShellRectPos(shellRect);
|
|
524 |
}
|
|
525 |
|
|
526 |
op = op & ~NO_EMBEDDED_CHECK;
|
|
527 |
|
|
528 |
if (op == SET_LOCATION) {
|
|
529 |
setShellPosition(shellRect);
|
|
530 |
} else if (isResizable()) {
|
|
531 |
if (op == SET_BOUNDS) {
|
|
532 |
setShellBounds(shellRect);
|
|
533 |
} else {
|
|
534 |
setShellSize(shellRect);
|
|
535 |
}
|
|
536 |
} else {
|
|
537 |
XWM.setShellNotResizable(this, newDimensions, shellRect, true);
|
|
538 |
if (op == SET_BOUNDS) {
|
|
539 |
setShellPosition(shellRect);
|
|
540 |
}
|
|
541 |
}
|
|
542 |
|
|
543 |
reconfigureContentWindow(newDimensions);
|
|
544 |
} finally {
|
|
545 |
XToolkit.awtUnlock();
|
|
546 |
}
|
|
547 |
}
|
|
548 |
|
|
549 |
/**
|
|
550 |
* @param x, y, width, heith - dimensions of the window with insets
|
|
551 |
*/
|
|
552 |
private void reshape(int x, int y, int width, int height, int operation,
|
|
553 |
boolean userReshape)
|
|
554 |
{
|
|
555 |
Rectangle newRec;
|
|
556 |
boolean setClient = false;
|
|
557 |
WindowDimensions dims = new WindowDimensions(dimensions);
|
|
558 |
switch (operation & (~NO_EMBEDDED_CHECK)) {
|
|
559 |
case SET_LOCATION:
|
|
560 |
// Set location always sets bounds location. However, until the window is mapped we
|
|
561 |
// should use client coordinates
|
|
562 |
dims.setLocation(x, y);
|
|
563 |
break;
|
|
564 |
case SET_SIZE:
|
|
565 |
// Set size sets bounds size. However, until the window is mapped we
|
|
566 |
// should use client coordinates
|
|
567 |
dims.setSize(width, height);
|
|
568 |
break;
|
|
569 |
case SET_CLIENT_SIZE: {
|
|
570 |
// Sets client rect size. Width and height contain insets.
|
|
571 |
Insets in = currentInsets;
|
|
572 |
width -= in.left+in.right;
|
|
573 |
height -= in.top+in.bottom;
|
|
574 |
dims.setClientSize(width, height);
|
|
575 |
break;
|
|
576 |
}
|
|
577 |
case SET_BOUNDS:
|
|
578 |
default:
|
|
579 |
dims.setLocation(x, y);
|
|
580 |
dims.setSize(width, height);
|
|
581 |
break;
|
|
582 |
}
|
|
583 |
if (insLog.isLoggable(Level.FINE)) insLog.log(Level.FINE, "For the operation {0} new dimensions are {1}",
|
|
584 |
new Object[] {operationToString(operation), dims});
|
|
585 |
|
|
586 |
reshape(dims, operation, userReshape);
|
|
587 |
}
|
|
588 |
|
|
589 |
/**
|
|
590 |
* @see java.awt.peer.ComponentPeer#setBounds
|
|
591 |
*/
|
|
592 |
public void setBounds(int x, int y, int width, int height, int op) {
|
|
593 |
// TODO: Rewrite with WindowDimensions
|
|
594 |
reshape(x, y, width, height, op, true);
|
|
595 |
validateSurface();
|
|
596 |
}
|
|
597 |
|
|
598 |
// Coordinates are that of the shell
|
|
599 |
void reconfigureContentWindow(WindowDimensions dims) {
|
|
600 |
if (content == null) {
|
|
601 |
insLog.fine("WARNING: Content window is null");
|
|
602 |
return;
|
|
603 |
}
|
|
604 |
content.setContentBounds(dims);
|
|
605 |
}
|
|
606 |
|
|
607 |
boolean no_reparent_artifacts = false;
|
|
608 |
public void handleConfigureNotifyEvent(XEvent xev) {
|
|
609 |
assert (SunToolkit.isAWTLockHeldByCurrentThread());
|
|
610 |
XConfigureEvent xe = xev.get_xconfigure();
|
|
611 |
insLog.log(Level.FINE, "Configure notify {0}", new Object[] {xe});
|
|
612 |
|
|
613 |
// XXX: should really only consider synthetic events, but
|
|
614 |
if (isReparented()) {
|
|
615 |
configure_seen = true;
|
|
616 |
}
|
|
617 |
|
|
618 |
if (!isMaximized()
|
|
619 |
&& (xe.get_serial() == reparent_serial || xe.get_window() != getShell())
|
|
620 |
&& !no_reparent_artifacts)
|
|
621 |
{
|
|
622 |
insLog.fine("- reparent artifact, skipping");
|
|
623 |
return;
|
|
624 |
}
|
|
625 |
no_reparent_artifacts = false;
|
|
626 |
|
|
627 |
/**
|
|
628 |
* When there is a WM we receive some CN before being visible and after.
|
|
629 |
* We should skip all CN which are before being visible, because we assume
|
|
630 |
* the gravity is in action while it is not yet.
|
|
631 |
*
|
|
632 |
* When there is no WM we receive CN only _before_ being visible.
|
|
633 |
* We should process these CNs.
|
|
634 |
*/
|
|
635 |
if (!isVisible() && XWM.getWMID() != XWM.NO_WM) {
|
|
636 |
insLog.fine(" - not visible, skipping");
|
|
637 |
return;
|
|
638 |
}
|
|
639 |
|
|
640 |
/*
|
|
641 |
* Some window managers configure before we are reparented and
|
|
642 |
* the send event flag is set! ugh... (Enlighetenment for one,
|
|
643 |
* possibly MWM as well). If we haven't been reparented yet
|
|
644 |
* this is just the WM shuffling us into position. Ignore
|
|
645 |
* it!!!! or we wind up in a bogus location.
|
|
646 |
*/
|
|
647 |
int runningWM = XWM.getWMID();
|
|
648 |
if (insLog.isLoggable(Level.FINE)) {
|
|
649 |
insLog.log(Level.FINE, "reparented={0}, visible={1}, WM={2}, decorations={3}",
|
|
650 |
new Object[] {isReparented(), isVisible(), runningWM, getDecorations()});
|
|
651 |
}
|
|
652 |
if (!isReparented() && isVisible() && runningWM != XWM.NO_WM
|
|
653 |
&& !XWM.isNonReparentingWM()
|
|
654 |
&& getDecorations() != winAttr.AWT_DECOR_NONE) {
|
|
655 |
insLog.fine("- visible but not reparented, skipping");
|
|
656 |
return;
|
|
657 |
}
|
|
658 |
//Last chance to correct insets
|
|
659 |
if (!insets_corrected && getDecorations() != winAttr.AWT_DECOR_NONE) {
|
|
660 |
long parent = XlibUtil.getParentWindow(window);
|
|
661 |
Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null;
|
|
662 |
if (insLog.isLoggable(Level.FINER)) {
|
|
663 |
if (correctWM != null) {
|
|
664 |
insLog.finer("Configure notify - insets : " + correctWM);
|
|
665 |
} else {
|
|
666 |
insLog.finer("Configure notify - insets are still not available");
|
|
667 |
}
|
|
668 |
}
|
|
669 |
if (correctWM != null) {
|
|
670 |
handleCorrectInsets(correctWM);
|
|
671 |
} else {
|
|
672 |
//Only one attempt to correct insets is made (to lower risk)
|
|
673 |
//if insets are still not available we simply set the flag
|
|
674 |
insets_corrected = true;
|
|
675 |
}
|
|
676 |
}
|
|
677 |
|
|
678 |
updateChildrenSizes();
|
|
679 |
|
|
680 |
// Bounds of the window
|
|
681 |
Rectangle targetBounds = new Rectangle(ComponentAccessor.getX((Component)target),
|
|
682 |
ComponentAccessor.getY((Component)target),
|
|
683 |
ComponentAccessor.getWidth((Component)target),
|
|
684 |
ComponentAccessor.getHeight((Component)target));
|
|
685 |
|
|
686 |
Point newLocation = targetBounds.getLocation();
|
|
687 |
if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) {
|
|
688 |
// Location, Client size + insets
|
|
689 |
newLocation = new Point(xe.get_x() - currentInsets.left, xe.get_y() - currentInsets.top);
|
|
690 |
} else {
|
|
691 |
// CDE/MWM/Metacity/Sawfish bug: if shell is resized using
|
|
692 |
// top or left border, we don't receive synthetic
|
|
693 |
// ConfigureNotify, only the one from X with zero
|
|
694 |
// coordinates. This is the workaround to get real
|
|
695 |
// location, 6261336
|
|
696 |
switch (XWM.getWMID()) {
|
|
697 |
case XWM.CDE_WM:
|
|
698 |
case XWM.MOTIF_WM:
|
|
699 |
case XWM.METACITY_WM:
|
|
700 |
case XWM.SAWFISH_WM:
|
|
701 |
{
|
|
702 |
Point xlocation = queryXLocation();
|
|
703 |
if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "New X location: {0}", new Object[]{xlocation});
|
|
704 |
if (xlocation != null) {
|
|
705 |
newLocation = xlocation;
|
|
706 |
}
|
|
707 |
break;
|
|
708 |
}
|
|
709 |
default:
|
|
710 |
break;
|
|
711 |
}
|
|
712 |
}
|
|
713 |
|
|
714 |
WindowDimensions newDimensions =
|
|
715 |
new WindowDimensions(newLocation,
|
|
716 |
new Dimension(xe.get_width(), xe.get_height()),
|
|
717 |
copy(currentInsets),
|
|
718 |
true);
|
|
719 |
|
|
720 |
insLog.log(Level.FINER, "Insets are {0}, new dimensions {1}",
|
|
721 |
new Object[] {currentInsets, newDimensions});
|
|
722 |
|
|
723 |
checkIfOnNewScreen(newDimensions.getBounds());
|
|
724 |
|
|
725 |
Point oldLocation = getLocation();
|
|
726 |
dimensions = newDimensions;
|
|
727 |
if (!newLocation.equals(oldLocation)) {
|
|
728 |
handleMoved(newDimensions);
|
|
729 |
}
|
|
730 |
reconfigureContentWindow(newDimensions);
|
|
731 |
updateChildrenSizes();
|
|
732 |
}
|
|
733 |
|
|
734 |
private void checkShellRectSize(Rectangle shellRect) {
|
|
735 |
if (shellRect.width < 0) {
|
|
736 |
shellRect.width = 1;
|
|
737 |
}
|
|
738 |
if (shellRect.height < 0) {
|
|
739 |
shellRect.height = 1;
|
|
740 |
}
|
|
741 |
}
|
|
742 |
|
|
743 |
private void checkShellRectPos(Rectangle shellRect) {
|
|
744 |
int wm = XWM.getWMID();
|
|
745 |
if (wm == XWM.MOTIF_WM || wm == XWM.CDE_WM) {
|
|
746 |
if (shellRect.x == 0 && shellRect.y == 0) {
|
|
747 |
shellRect.x = shellRect.y = 1;
|
|
748 |
}
|
|
749 |
}
|
|
750 |
}
|
|
751 |
|
|
752 |
private void checkShellRect(Rectangle shellRect) {
|
|
753 |
checkShellRectSize(shellRect);
|
|
754 |
checkShellRectPos(shellRect);
|
|
755 |
}
|
|
756 |
|
|
757 |
public void setShellBounds(Rectangle rec) {
|
|
758 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell bounds on " +
|
|
759 |
this + " to " + rec);
|
|
760 |
XToolkit.awtLock();
|
|
761 |
try {
|
|
762 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height);
|
|
763 |
XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height);
|
|
764 |
XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y);
|
|
765 |
}
|
|
766 |
finally {
|
|
767 |
XToolkit.awtUnlock();
|
|
768 |
}
|
|
769 |
}
|
|
770 |
public void setShellSize(Rectangle rec) {
|
|
771 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell size on " +
|
|
772 |
this + " to " + rec);
|
|
773 |
XToolkit.awtLock();
|
|
774 |
try {
|
|
775 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height);
|
|
776 |
XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height);
|
|
777 |
}
|
|
778 |
finally {
|
|
779 |
XToolkit.awtUnlock();
|
|
780 |
}
|
|
781 |
}
|
|
782 |
public void setShellPosition(Rectangle rec) {
|
|
783 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell position on " +
|
|
784 |
this + " to " + rec);
|
|
785 |
XToolkit.awtLock();
|
|
786 |
try {
|
|
787 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height);
|
|
788 |
XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y);
|
|
789 |
}
|
|
790 |
finally {
|
|
791 |
XToolkit.awtUnlock();
|
|
792 |
}
|
|
793 |
}
|
|
794 |
|
|
795 |
void initResizability() {
|
|
796 |
setResizable(winAttr.initialResizability);
|
|
797 |
}
|
|
798 |
public void setResizable(boolean resizable) {
|
|
799 |
int fs = winAttr.functions;
|
|
800 |
if (!isResizable() && resizable) {
|
|
801 |
insets = currentInsets = new Insets(0, 0, 0, 0);
|
|
802 |
resetWMSetInsets();
|
|
803 |
if (!isEmbedded()) {
|
|
804 |
setReparented(false);
|
|
805 |
}
|
|
806 |
winAttr.isResizable = resizable;
|
|
807 |
if ((fs & MWM_FUNC_ALL) != 0) {
|
|
808 |
fs &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE);
|
|
809 |
} else {
|
|
810 |
fs |= (MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE);
|
|
811 |
}
|
|
812 |
winAttr.functions = fs;
|
|
813 |
XWM.setShellResizable(this);
|
|
814 |
} else if (isResizable() && !resizable) {
|
|
815 |
insets = currentInsets = new Insets(0, 0, 0, 0);
|
|
816 |
resetWMSetInsets();
|
|
817 |
if (!isEmbedded()) {
|
|
818 |
setReparented(false);
|
|
819 |
}
|
|
820 |
winAttr.isResizable = resizable;
|
|
821 |
if ((fs & MWM_FUNC_ALL) != 0) {
|
|
822 |
fs |= (MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE);
|
|
823 |
} else {
|
|
824 |
fs &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE);
|
|
825 |
}
|
|
826 |
winAttr.functions = fs;
|
|
827 |
XWM.setShellNotResizable(this, dimensions, dimensions.getScreenBounds(), false);
|
|
828 |
}
|
|
829 |
}
|
|
830 |
|
|
831 |
Rectangle getShellBounds() {
|
|
832 |
return dimensions.getClientRect();
|
|
833 |
}
|
|
834 |
|
|
835 |
public Rectangle getBounds() {
|
|
836 |
return dimensions.getBounds();
|
|
837 |
}
|
|
838 |
|
|
839 |
public Dimension getSize() {
|
|
840 |
return dimensions.getSize();
|
|
841 |
}
|
|
842 |
|
|
843 |
public int getX() {
|
|
844 |
return dimensions.getLocation().x;
|
|
845 |
}
|
|
846 |
|
|
847 |
public int getY() {
|
|
848 |
return dimensions.getLocation().y;
|
|
849 |
}
|
|
850 |
|
|
851 |
public Point getLocation() {
|
|
852 |
return dimensions.getLocation();
|
|
853 |
}
|
|
854 |
|
|
855 |
public int getAbsoluteX() {
|
|
856 |
// NOTE: returning this peer's location which is shell location
|
|
857 |
return dimensions.getScreenBounds().x;
|
|
858 |
}
|
|
859 |
|
|
860 |
public int getAbsoluteY() {
|
|
861 |
// NOTE: returning this peer's location which is shell location
|
|
862 |
return dimensions.getScreenBounds().y;
|
|
863 |
}
|
|
864 |
|
|
865 |
public int getWidth() {
|
|
866 |
return getSize().width;
|
|
867 |
}
|
|
868 |
|
|
869 |
public int getHeight() {
|
|
870 |
return getSize().height;
|
|
871 |
}
|
|
872 |
|
|
873 |
public WindowDimensions getDimensions() {
|
|
874 |
return dimensions;
|
|
875 |
}
|
|
876 |
|
|
877 |
public Point getLocationOnScreen() {
|
|
878 |
XToolkit.awtLock();
|
|
879 |
try {
|
|
880 |
if (configure_seen) {
|
|
881 |
return toGlobal(0,0);
|
|
882 |
} else {
|
|
883 |
Point location = target.getLocation();
|
|
884 |
if (insLog.isLoggable(Level.FINE))
|
|
885 |
insLog.log(Level.FINE, "getLocationOnScreen {0} not reparented: {1} ",
|
|
886 |
new Object[] {this, location});
|
|
887 |
return location;
|
|
888 |
}
|
|
889 |
} finally {
|
|
890 |
XToolkit.awtUnlock();
|
|
891 |
}
|
|
892 |
}
|
|
893 |
|
|
894 |
|
|
895 |
/***************************************************************************************
|
|
896 |
* END OF I N S E T S C O D E
|
|
897 |
**************************************************************************************/
|
|
898 |
|
|
899 |
protected boolean isEventDisabled(XEvent e) {
|
|
900 |
switch (e.get_type()) {
|
|
901 |
// Do not generate MOVED/RESIZED events since we generate them by ourselves
|
|
902 |
case ConfigureNotify:
|
|
903 |
return true;
|
|
904 |
case EnterNotify:
|
|
905 |
case LeaveNotify:
|
|
906 |
// Disable crossing event on outer borders of Frame so
|
|
907 |
// we receive only one set of cross notifications(first set is from content window)
|
|
908 |
return true;
|
|
909 |
default:
|
|
910 |
return super.isEventDisabled(e);
|
|
911 |
}
|
|
912 |
}
|
|
913 |
|
|
914 |
int getDecorations() {
|
|
915 |
return winAttr.decorations;
|
|
916 |
}
|
|
917 |
|
|
918 |
int getFunctions() {
|
|
919 |
return winAttr.functions;
|
|
920 |
}
|
|
921 |
|
|
922 |
public void setVisible(boolean vis) {
|
|
923 |
log.log(Level.FINER, "Setting {0} to visible {1}", new Object[] {this, Boolean.valueOf(vis)});
|
|
924 |
if (vis && !isVisible()) {
|
|
925 |
XWM.setShellDecor(this);
|
|
926 |
super.setVisible(vis);
|
|
927 |
if (winAttr.isResizable) {
|
|
928 |
//Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
|
|
929 |
//We need to update frame's minimum size, not to reset it
|
|
930 |
XWM.removeSizeHints(this, XlibWrapper.PMaxSize);
|
|
931 |
updateMinimumSize();
|
|
932 |
}
|
|
933 |
} else {
|
|
934 |
super.setVisible(vis);
|
|
935 |
}
|
|
936 |
}
|
|
937 |
|
|
938 |
protected void suppressWmTakeFocus(boolean doSuppress) {
|
|
939 |
XAtomList protocols = getWMProtocols();
|
|
940 |
if (doSuppress) {
|
|
941 |
protocols.remove(wm_take_focus);
|
|
942 |
} else {
|
|
943 |
protocols.add(wm_take_focus);
|
|
944 |
}
|
|
945 |
wm_protocols.setAtomListProperty(this, protocols);
|
|
946 |
}
|
|
947 |
|
|
948 |
public void dispose() {
|
|
949 |
if (content != null) {
|
|
950 |
content.destroy();
|
|
951 |
}
|
|
952 |
focusProxy.destroy();
|
|
953 |
|
|
954 |
if (iconWindow != null) {
|
|
955 |
iconWindow.destroy();
|
|
956 |
}
|
|
957 |
|
|
958 |
super.dispose();
|
|
959 |
}
|
|
960 |
|
|
961 |
public void handleClientMessage(XEvent xev) {
|
|
962 |
super.handleClientMessage(xev);
|
|
963 |
XClientMessageEvent cl = xev.get_xclient();
|
|
964 |
if ((wm_protocols != null) && (cl.get_message_type() == wm_protocols.getAtom())) {
|
|
965 |
if (cl.get_data(0) == wm_delete_window.getAtom()) {
|
|
966 |
handleQuit();
|
|
967 |
} else if (cl.get_data(0) == wm_take_focus.getAtom()) {
|
|
968 |
handleWmTakeFocus(cl);
|
|
969 |
}
|
|
970 |
} else if (cl.get_message_type() == resize_request.getAtom()) {
|
|
971 |
reshape((int)cl.get_data(0), (int)cl.get_data(1),
|
|
972 |
(int)cl.get_data(2), (int)cl.get_data(3),
|
|
973 |
(int)cl.get_data(4), true);
|
|
974 |
}
|
|
975 |
}
|
|
976 |
|
|
977 |
private void handleWmTakeFocus(XClientMessageEvent cl) {
|
|
978 |
focusLog.log(Level.FINE, "WM_TAKE_FOCUS on {0}", new Object[]{this});
|
|
979 |
requestWindowFocus(cl.get_data(1), true);
|
|
980 |
}
|
|
981 |
|
|
982 |
/**
|
|
983 |
* Requests focus to this decorated top-level by requesting X input focus
|
|
984 |
* to the shell window.
|
|
985 |
*/
|
|
986 |
protected void requestXFocus(long time, boolean timeProvided) {
|
|
987 |
// We have proxied focus mechanism - instead of shell the focus is held
|
|
988 |
// by "proxy" - invisible mapped window. When we want to set X input focus to
|
|
989 |
// toplevel set it on proxy instead.
|
|
990 |
if (focusProxy == null) {
|
|
991 |
if (focusLog.isLoggable(Level.FINE)) focusLog.warning("Focus proxy is null for " + this);
|
|
992 |
} else {
|
|
993 |
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("Requesting focus to proxy: " + focusProxy);
|
|
994 |
if (timeProvided) {
|
|
995 |
focusProxy.xRequestFocus(time);
|
|
996 |
} else {
|
|
997 |
focusProxy.xRequestFocus();
|
|
998 |
}
|
|
999 |
}
|
|
1000 |
}
|
|
1001 |
|
|
1002 |
XFocusProxyWindow getFocusProxy() {
|
|
1003 |
return focusProxy;
|
|
1004 |
}
|
|
1005 |
|
|
1006 |
public void handleQuit() {
|
|
1007 |
postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING));
|
|
1008 |
}
|
|
1009 |
|
|
1010 |
final void dumpMe() {
|
|
1011 |
System.err.println(">>> Peer: " + x + ", " + y + ", " + width + ", " + height);
|
|
1012 |
}
|
|
1013 |
|
|
1014 |
final void dumpTarget() {
|
|
1015 |
int getWidth = ComponentAccessor.getWidth((Component)target);
|
|
1016 |
int getHeight = ComponentAccessor.getHeight((Component)target);
|
|
1017 |
int getTargetX = ComponentAccessor.getX((Component)target);
|
|
1018 |
int getTargetY = ComponentAccessor.getY((Component)target);
|
|
1019 |
System.err.println(">>> Target: " + getTargetX + ", " + getTargetY + ", " + getWidth + ", " + getHeight);
|
|
1020 |
}
|
|
1021 |
|
|
1022 |
final void dumpShell() {
|
|
1023 |
dumpWindow("Shell", getShell());
|
|
1024 |
}
|
|
1025 |
final void dumpContent() {
|
|
1026 |
dumpWindow("Content", getContentWindow());
|
|
1027 |
}
|
|
1028 |
final void dumpParent() {
|
|
1029 |
long parent = XlibUtil.getParentWindow(getShell());
|
|
1030 |
if (parent != 0)
|
|
1031 |
{
|
|
1032 |
dumpWindow("Parent", parent);
|
|
1033 |
}
|
|
1034 |
else
|
|
1035 |
{
|
|
1036 |
System.err.println(">>> NO PARENT");
|
|
1037 |
}
|
|
1038 |
}
|
|
1039 |
|
|
1040 |
final void dumpWindow(String id, long window) {
|
|
1041 |
XWindowAttributes pattr = new XWindowAttributes();
|
|
1042 |
try {
|
|
1043 |
XToolkit.awtLock();
|
|
1044 |
try {
|
|
1045 |
int status =
|
|
1046 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
|
|
1047 |
window, pattr.pData);
|
|
1048 |
}
|
|
1049 |
finally {
|
|
1050 |
XToolkit.awtUnlock();
|
|
1051 |
}
|
|
1052 |
System.err.println(">>>> " + id + ": " + pattr.get_x()
|
|
1053 |
+ ", " + pattr.get_y() + ", " + pattr.get_width()
|
|
1054 |
+ ", " + pattr.get_height());
|
|
1055 |
} finally {
|
|
1056 |
pattr.dispose();
|
|
1057 |
}
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
final void dumpAll() {
|
|
1061 |
dumpTarget();
|
|
1062 |
dumpMe();
|
|
1063 |
dumpParent();
|
|
1064 |
dumpShell();
|
|
1065 |
dumpContent();
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
boolean isMaximized() {
|
|
1069 |
return false;
|
|
1070 |
}
|
|
1071 |
|
|
1072 |
boolean isOverrideRedirect() {
|
|
1073 |
return false;
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
public boolean requestWindowFocus(long time, boolean timeProvided) {
|
|
1077 |
focusLog.fine("Request for decorated window focus");
|
|
1078 |
// If this is Frame or Dialog we can't assure focus request success - but we still can try
|
|
1079 |
// If this is Window and its owner Frame is active we can be sure request succedded.
|
|
1080 |
Window win = (Window)target;
|
|
1081 |
Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
|
|
1082 |
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
|
|
1083 |
|
|
1084 |
focusLog.log(Level.FINER, "Current window is: active={0}, focused={1}",
|
|
1085 |
new Object[]{ Boolean.valueOf(win == activeWindow),
|
|
1086 |
Boolean.valueOf(win == focusedWindow)});
|
|
1087 |
|
|
1088 |
XWindowPeer toFocus = this;
|
|
1089 |
while (toFocus.nextTransientFor != null) {
|
|
1090 |
toFocus = toFocus.nextTransientFor;
|
|
1091 |
}
|
|
1092 |
|
|
1093 |
if (this == toFocus) {
|
|
1094 |
if (focusAllowedFor()) {
|
|
1095 |
if (win == activeWindow && win != focusedWindow) {
|
|
1096 |
// Happens when focus is on window child
|
|
1097 |
focusLog.fine("Focus is on child window - transfering it back");
|
|
1098 |
handleWindowFocusInSync(-1);
|
|
1099 |
} else {
|
|
1100 |
focusLog.fine("Requesting focus to this window");
|
|
1101 |
if (timeProvided) {
|
|
1102 |
requestXFocus(time);
|
|
1103 |
} else {
|
|
1104 |
requestXFocus();
|
|
1105 |
}
|
|
1106 |
}
|
|
1107 |
return true;
|
|
1108 |
} else {
|
|
1109 |
return false;
|
|
1110 |
}
|
|
1111 |
}
|
|
1112 |
else if (toFocus.focusAllowedFor()) {
|
|
1113 |
focusLog.fine("Requesting focus to " + toFocus);
|
|
1114 |
if (timeProvided) {
|
|
1115 |
toFocus.requestXFocus(time);
|
|
1116 |
} else {
|
|
1117 |
toFocus.requestXFocus();
|
|
1118 |
}
|
|
1119 |
return false;
|
|
1120 |
}
|
|
1121 |
else
|
|
1122 |
{
|
|
1123 |
// This might change when WM will have property to determine focus policy.
|
|
1124 |
// Right now, because policy is unknown we can't be sure we succedded
|
|
1125 |
return false;
|
|
1126 |
}
|
|
1127 |
}
|
|
1128 |
|
|
1129 |
XWindowPeer actualFocusedWindow = null;
|
|
1130 |
void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
|
|
1131 |
synchronized(getStateLock()) {
|
|
1132 |
this.actualFocusedWindow = actualFocusedWindow;
|
|
1133 |
}
|
|
1134 |
}
|
|
1135 |
|
|
1136 |
boolean requestWindowFocus(XWindowPeer actualFocusedWindow,
|
|
1137 |
long time, boolean timeProvided)
|
|
1138 |
{
|
|
1139 |
setActualFocusedWindow(actualFocusedWindow);
|
|
1140 |
return requestWindowFocus(time, timeProvided);
|
|
1141 |
}
|
|
1142 |
public void handleWindowFocusIn(long serial) {
|
|
1143 |
if (null == actualFocusedWindow) {
|
|
1144 |
super.handleWindowFocusIn(serial);
|
|
1145 |
} else {
|
|
1146 |
/*
|
|
1147 |
* Fix for 6314575.
|
|
1148 |
* If this is a result of clicking on one of the Frame's component
|
|
1149 |
* then 'actualFocusedWindow' shouldn't be focused. A decision of focusing
|
|
1150 |
* it or not should be made after the appropriate Java mouse event (if any)
|
|
1151 |
* is handled by the component where 'actualFocusedWindow' value may be reset.
|
|
1152 |
*
|
|
1153 |
* The fix is based on the empiric fact consisting in that the component
|
|
1154 |
* receives native mouse event nearly at the same time the Frame receives
|
|
1155 |
* WM_TAKE_FOCUS (when FocusIn is generated via XSetInputFocus call) but
|
|
1156 |
* definetely before the Frame gets FocusIn event (when this method is called).
|
|
1157 |
*/
|
|
1158 |
postEvent(new InvocationEvent(target, new Runnable() {
|
|
1159 |
public void run() {
|
|
1160 |
XWindowPeer fw = null;
|
|
1161 |
synchronized (getStateLock()) {
|
|
1162 |
fw = actualFocusedWindow;
|
|
1163 |
actualFocusedWindow = null;
|
|
1164 |
if (null == fw || !fw.isVisible() || !fw.isFocusableWindow()) {
|
|
1165 |
fw = XDecoratedPeer.this;
|
|
1166 |
}
|
|
1167 |
}
|
|
1168 |
fw.handleWindowFocusIn_Dispatch();
|
|
1169 |
}
|
|
1170 |
}));
|
|
1171 |
}
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
|
|
1175 |
Window actualFocusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
|
|
1176 |
|
|
1177 |
// If the actual focused window is not this decorated window then retain it.
|
|
1178 |
if (actualFocusedWindow != null && actualFocusedWindow != target) {
|
|
1179 |
Window owner = XWindowPeer.getDecoratedOwner(actualFocusedWindow);
|
|
1180 |
|
|
1181 |
if (owner != null && owner == target) {
|
|
1182 |
setActualFocusedWindow((XWindowPeer) ComponentAccessor.getPeer(actualFocusedWindow));
|
|
1183 |
}
|
|
1184 |
}
|
|
1185 |
super.handleWindowFocusOut(oppositeWindow, serial);
|
|
1186 |
}
|
|
1187 |
|
|
1188 |
private Point queryXLocation()
|
|
1189 |
{
|
|
1190 |
return XlibUtil.translateCoordinates(
|
|
1191 |
getContentWindow(),
|
|
1192 |
XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
|
|
1193 |
new Point(0, 0));
|
|
1194 |
}
|
|
1195 |
}
|