author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5506 | 202f599c92aa |
child 16839 | d0f2e97b7359 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* This code is ported to XAWT from MAWT based on awt_mgrsel.c |
|
28 |
* and XSettings.java code written originally by Valeriy Ushakov |
|
29 |
* Author : Bino George |
|
30 |
*/ |
|
31 |
||
32 |
||
33 |
package sun.awt.X11; |
|
34 |
||
35 |
import java.util.*; |
|
36 |
import java.awt.*; |
|
37 |
import sun.awt.XSettings; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
38 |
import sun.util.logging.PlatformLogger; |
2 | 39 |
|
40 |
||
41 |
class XAWTXSettings extends XSettings implements XMSelectionListener { |
|
42 |
||
43 |
private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS"); |
|
44 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
45 |
private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XAWTXSettings"); |
2 | 46 |
|
47 |
/* The maximal length of the property data. */ |
|
48 |
public static final long MAX_LENGTH = 1000000; |
|
49 |
||
50 |
XMSelection settings; |
|
51 |
||
52 |
public XAWTXSettings() { |
|
53 |
initXSettings(); |
|
54 |
||
55 |
} |
|
56 |
||
57 |
void initXSettings() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
58 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("Initializing XAWT XSettings"); |
2 | 59 |
settings = new XMSelection("_XSETTINGS"); |
60 |
settings.addSelectionListener(this); |
|
61 |
initPerScreenXSettings(); |
|
62 |
} |
|
63 |
||
64 |
void dispose() { |
|
65 |
settings.removeSelectionListener(this); |
|
66 |
} |
|
67 |
||
68 |
public void ownerDeath(int screen, XMSelection sel, long deadOwner) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
69 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen); |
2 | 70 |
} |
71 |
||
72 |
||
73 |
public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
74 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen ); |
2 | 75 |
} |
76 |
||
77 |
public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) { |
|
78 |
log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event); |
|
79 |
updateXSettings(screen,owner); |
|
80 |
} |
|
81 |
||
82 |
void initPerScreenXSettings() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
83 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("Updating Per XSettings changes"); |
2 | 84 |
|
85 |
/* |
|
86 |
* As toolkit cannot yet cope with per-screen desktop properties, |
|
87 |
* only report XSETTINGS changes on the default screen. This |
|
88 |
* should be "good enough" for most cases. |
|
89 |
*/ |
|
90 |
||
91 |
Map updatedSettings = null; |
|
92 |
XToolkit.awtLock(); |
|
93 |
try { |
|
94 |
long display = XToolkit.getDisplay(); |
|
95 |
int screen = (int) XlibWrapper.DefaultScreen(display); |
|
96 |
updatedSettings = getUpdatedSettings(settings.getOwner(screen)); |
|
97 |
} finally { |
|
98 |
XToolkit.awtUnlock(); |
|
99 |
} |
|
100 |
// we must not invoke this under Awt Lock |
|
101 |
((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings); |
|
102 |
} |
|
103 |
||
104 |
private void updateXSettings(int screen, long owner) { |
|
105 |
final Map updatedSettings = getUpdatedSettings(owner); |
|
106 |
// this method is called under awt lock and usually on toolkit thread |
|
107 |
// but parseXSettings() causes public code execution, so we need to transfer |
|
108 |
// this to EDT |
|
109 |
EventQueue.invokeLater( new Runnable() { |
|
110 |
public void run() { |
|
111 |
((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings); |
|
112 |
} |
|
113 |
}); |
|
114 |
} |
|
115 |
||
116 |
private Map getUpdatedSettings(final long owner) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
117 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("owner =" + owner); |
2 | 118 |
if (0 == owner) { |
119 |
return null; |
|
120 |
} |
|
121 |
||
122 |
Map settings = null; |
|
123 |
try { |
|
124 |
WindowPropertyGetter getter = |
|
125 |
new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH, |
|
126 |
false, xSettingsPropertyAtom.getAtom() ); |
|
127 |
try { |
|
2802
d05a9dcc8296
6678385: Random java.lang.StackOverflowError from various JDKs
art
parents:
439
diff
changeset
|
128 |
int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance()); |
2 | 129 |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
130 |
if (status != XConstants.Success || getter.getData() == 0) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
131 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("OH OH : getter failed status = " + status ); |
2 | 132 |
settings = null; |
133 |
} |
|
134 |
||
135 |
long ptr = getter.getData(); |
|
136 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2802
diff
changeset
|
137 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("noItems = " + getter.getNumberOfItems()); |
2 | 138 |
byte array[] = Native.toBytes(ptr,getter.getNumberOfItems()); |
139 |
if (array != null) { |
|
140 |
settings = update(array); |
|
141 |
} |
|
142 |
} finally { |
|
143 |
getter.dispose(); |
|
144 |
} |
|
145 |
} |
|
146 |
catch (Exception e) { |
|
147 |
e.printStackTrace(); |
|
148 |
} |
|
149 |
return settings; |
|
150 |
} |
|
151 |
||
152 |
||
153 |
||
154 |
} |