author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 439 | 3488710b02f8 |
child 2802 | d05a9dcc8296 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
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 |
* 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; |
|
38 |
import java.util.logging.*; |
|
39 |
||
40 |
||
41 |
||
42 |
class XAWTXSettings extends XSettings implements XMSelectionListener { |
|
43 |
||
44 |
private final XAtom xSettingsPropertyAtom = XAtom.get("_XSETTINGS_SETTINGS"); |
|
45 |
||
46 |
private static Logger log = Logger.getLogger("sun.awt.X11.XAWTXSettings"); |
|
47 |
||
48 |
/* The maximal length of the property data. */ |
|
49 |
public static final long MAX_LENGTH = 1000000; |
|
50 |
||
51 |
XMSelection settings; |
|
52 |
||
53 |
public XAWTXSettings() { |
|
54 |
initXSettings(); |
|
55 |
||
56 |
} |
|
57 |
||
58 |
void initXSettings() { |
|
59 |
if (log.isLoggable(Level.FINE)) log.fine("Initializing XAWT XSettings"); |
|
60 |
settings = new XMSelection("_XSETTINGS"); |
|
61 |
settings.addSelectionListener(this); |
|
62 |
initPerScreenXSettings(); |
|
63 |
} |
|
64 |
||
65 |
void dispose() { |
|
66 |
settings.removeSelectionListener(this); |
|
67 |
} |
|
68 |
||
69 |
public void ownerDeath(int screen, XMSelection sel, long deadOwner) { |
|
70 |
if (log.isLoggable(Level.FINE)) log.fine("Owner " + deadOwner + " died for selection " + sel + " screen "+ screen); |
|
71 |
} |
|
72 |
||
73 |
||
74 |
public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) { |
|
75 |
if (log.isLoggable(Level.FINE)) log.fine("New Owner "+ newOwner + " for selection = " + sel + " screen " +screen ); |
|
76 |
} |
|
77 |
||
78 |
public void selectionChanged(int screen, XMSelection sel, long owner , XPropertyEvent event) { |
|
79 |
log.fine("Selection changed on sel " + sel + " screen = " + screen + " owner = " + owner + " event = " + event); |
|
80 |
updateXSettings(screen,owner); |
|
81 |
} |
|
82 |
||
83 |
void initPerScreenXSettings() { |
|
84 |
if (log.isLoggable(Level.FINE)) log.fine("Updating Per XSettings changes"); |
|
85 |
||
86 |
/* |
|
87 |
* As toolkit cannot yet cope with per-screen desktop properties, |
|
88 |
* only report XSETTINGS changes on the default screen. This |
|
89 |
* should be "good enough" for most cases. |
|
90 |
*/ |
|
91 |
||
92 |
Map updatedSettings = null; |
|
93 |
XToolkit.awtLock(); |
|
94 |
try { |
|
95 |
long display = XToolkit.getDisplay(); |
|
96 |
int screen = (int) XlibWrapper.DefaultScreen(display); |
|
97 |
updatedSettings = getUpdatedSettings(settings.getOwner(screen)); |
|
98 |
} finally { |
|
99 |
XToolkit.awtUnlock(); |
|
100 |
} |
|
101 |
// we must not invoke this under Awt Lock |
|
102 |
((XToolkit)Toolkit.getDefaultToolkit()).parseXSettings(0,updatedSettings); |
|
103 |
} |
|
104 |
||
105 |
private void updateXSettings(int screen, long owner) { |
|
106 |
final Map updatedSettings = getUpdatedSettings(owner); |
|
107 |
// this method is called under awt lock and usually on toolkit thread |
|
108 |
// but parseXSettings() causes public code execution, so we need to transfer |
|
109 |
// this to EDT |
|
110 |
EventQueue.invokeLater( new Runnable() { |
|
111 |
public void run() { |
|
112 |
((XToolkit) Toolkit.getDefaultToolkit()).parseXSettings( 0, updatedSettings); |
|
113 |
} |
|
114 |
}); |
|
115 |
} |
|
116 |
||
117 |
private Map getUpdatedSettings(final long owner) { |
|
118 |
if (log.isLoggable(Level.FINE)) log.fine("owner =" + owner); |
|
119 |
if (0 == owner) { |
|
120 |
return null; |
|
121 |
} |
|
122 |
||
123 |
Map settings = null; |
|
124 |
try { |
|
125 |
WindowPropertyGetter getter = |
|
126 |
new WindowPropertyGetter(owner, xSettingsPropertyAtom, 0, MAX_LENGTH, |
|
127 |
false, xSettingsPropertyAtom.getAtom() ); |
|
128 |
try { |
|
129 |
int status = getter.execute(XToolkit.IgnoreBadWindowHandler); |
|
130 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
131 |
if (status != XConstants.Success || getter.getData() == 0) { |
2 | 132 |
if (log.isLoggable(Level.FINE)) log.fine("OH OH : getter failed status = " + status ); |
133 |
settings = null; |
|
134 |
} |
|
135 |
||
136 |
long ptr = getter.getData(); |
|
137 |
||
138 |
if (log.isLoggable(Level.FINE)) log.fine("noItems = " + getter.getNumberOfItems()); |
|
139 |
byte array[] = Native.toBytes(ptr,getter.getNumberOfItems()); |
|
140 |
if (array != null) { |
|
141 |
settings = update(array); |
|
142 |
} |
|
143 |
} finally { |
|
144 |
getter.dispose(); |
|
145 |
} |
|
146 |
} |
|
147 |
catch (Exception e) { |
|
148 |
e.printStackTrace(); |
|
149 |
} |
|
150 |
return settings; |
|
151 |
} |
|
152 |
||
153 |
||
154 |
||
155 |
} |