author | itakiguchi |
Tue, 30 Oct 2018 15:51:10 -0700 | |
changeset 52528 | edc729e2ee36 |
parent 52248 | 2e330da7cbf4 |
child 52987 | 468829d1983e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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 |
* code written originally by Valeriy Ushakov |
|
29 |
* Author : Bino George |
|
30 |
*/ |
|
31 |
||
32 |
package sun.awt.X11; |
|
33 |
||
34 |
import java.util.*; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
439
diff
changeset
|
35 |
import sun.util.logging.PlatformLogger; |
2 | 36 |
|
37 |
public class XMSelection { |
|
38 |
||
39 |
/* |
|
40 |
* A method for a subsytem to express its interest in a certain |
|
41 |
* manager selection. |
|
42 |
* |
|
43 |
* If owner changes, the ownerChanged of the XMSelectionListener |
|
44 |
* will be called with the screen |
|
45 |
* number and the new owning window when onwership is established, or |
|
46 |
* None if the owner is gone. |
|
47 |
* |
|
48 |
* Events in extra_mask are selected for on owning windows (exsiting |
|
49 |
* ones and on new owners when established) and otherEvent of the |
|
50 |
* XMWSelectionListener will be called with the screen number and an event. |
|
51 |
* |
|
52 |
* The function returns an array of current owners. The size of the |
|
53 |
* array is ScreenCount(awt_display). The array is "owned" by this |
|
54 |
* module and should be considered by the caller as read-only. |
|
55 |
*/ |
|
56 |
||
57 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
439
diff
changeset
|
58 |
private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMSelection"); |
2 | 59 |
/* Name of the selection */ |
60 |
String selectionName; |
|
61 |
||
62 |
/* list of listeners to be called for events */ |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
63 |
Vector<XMSelectionListener> listeners; |
2 | 64 |
|
65 |
/* X atom array (one per screen) for this selection */ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
66 |
XAtom[] atoms; |
2 | 67 |
|
68 |
/* Window ids of selection owners */ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
69 |
long[] owners; |
2 | 70 |
|
71 |
/* event mask to set */ |
|
72 |
long eventMask; |
|
73 |
||
74 |
static int numScreens; |
|
75 |
||
76 |
static XAtom XA_MANAGER; |
|
77 |
||
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
78 |
static HashMap<Long, XMSelection> selectionMap; |
2 | 79 |
|
80 |
static { |
|
81 |
long display = XToolkit.getDisplay(); |
|
82 |
XToolkit.awtLock(); |
|
83 |
try { |
|
84 |
numScreens = XlibWrapper.ScreenCount(display); |
|
85 |
} finally { |
|
86 |
XToolkit.awtUnlock(); |
|
87 |
} |
|
88 |
XA_MANAGER = XAtom.get("MANAGER"); |
|
89 |
for (int screen = 0; screen < numScreens ; screen ++) { |
|
90 |
initScreen(display,screen); |
|
91 |
} |
|
92 |
||
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
93 |
selectionMap = new HashMap<>(); |
2 | 94 |
} |
95 |
||
96 |
static void initScreen(long display, final int screen) { |
|
97 |
XToolkit.awtLock(); |
|
98 |
try { |
|
99 |
long root = XlibWrapper.RootWindow(display,screen); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
100 |
XlibWrapper.XSelectInput(display, root, XConstants.StructureNotifyMask); |
2 | 101 |
XToolkit.addEventDispatcher(root, |
102 |
new XEventDispatcher() { |
|
103 |
public void dispatchEvent(XEvent ev) { |
|
104 |
processRootEvent(ev, screen); |
|
105 |
} |
|
106 |
}); |
|
107 |
||
108 |
} finally { |
|
109 |
XToolkit.awtUnlock(); |
|
110 |
} |
|
111 |
} |
|
112 |
||
113 |
||
114 |
public int getNumberOfScreens() { |
|
115 |
return numScreens; |
|
116 |
} |
|
117 |
||
118 |
void select(long extra_mask) { |
|
119 |
eventMask = extra_mask; |
|
120 |
for (int screen = 0; screen < numScreens ; screen ++) { |
|
121 |
selectPerScreen(screen,extra_mask); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
void resetOwner(long owner, final int screen) { |
|
126 |
XToolkit.awtLock(); |
|
127 |
try { |
|
128 |
long display = XToolkit.getDisplay(); |
|
129 |
synchronized(this) { |
|
130 |
setOwner(owner, screen); |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
131 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
132 |
log.fine("New Selection Owner for screen " + screen + " = " + owner ); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
133 |
} |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
134 |
XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | eventMask); |
2 | 135 |
XToolkit.addEventDispatcher(owner, |
136 |
new XEventDispatcher() { |
|
137 |
public void dispatchEvent(XEvent ev) { |
|
138 |
dispatchSelectionEvent(ev, screen); |
|
139 |
} |
|
140 |
}); |
|
141 |
||
142 |
} |
|
143 |
} finally { |
|
144 |
XToolkit.awtUnlock(); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
void selectPerScreen(final int screen, long extra_mask) { |
|
149 |
XToolkit.awtLock(); |
|
150 |
try { |
|
151 |
try { |
|
152 |
long display = XToolkit.getDisplay(); |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
153 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
154 |
log.fine("Grabbing XServer"); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
155 |
} |
2 | 156 |
XlibWrapper.XGrabServer(display); |
157 |
||
158 |
synchronized(this) { |
|
159 |
String selection_name = getName()+"_S"+screen; |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
160 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
161 |
log.fine("Screen = " + screen + " selection name = " + selection_name); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
162 |
} |
2 | 163 |
XAtom atom = XAtom.get(selection_name); |
164 |
selectionMap.put(Long.valueOf(atom.getAtom()),this); // add mapping from atom to the instance of XMSelection |
|
165 |
setAtom(atom,screen); |
|
166 |
long owner = XlibWrapper.XGetSelectionOwner(display, atom.getAtom()); |
|
167 |
if (owner != 0) { |
|
168 |
setOwner(owner, screen); |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
169 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
170 |
log.fine("Selection Owner for screen " + screen + " = " + owner ); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
171 |
} |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
172 |
XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | extra_mask); |
2 | 173 |
XToolkit.addEventDispatcher(owner, |
174 |
new XEventDispatcher() { |
|
175 |
public void dispatchEvent(XEvent ev) { |
|
176 |
dispatchSelectionEvent(ev, screen); |
|
177 |
} |
|
178 |
}); |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
catch (Exception e) { |
|
183 |
e.printStackTrace(); |
|
184 |
} |
|
185 |
finally { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
186 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
187 |
log.fine("UnGrabbing XServer"); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
188 |
} |
2 | 189 |
XlibWrapper.XUngrabServer(XToolkit.getDisplay()); |
190 |
} |
|
191 |
} finally { |
|
192 |
XToolkit.awtUnlock(); |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
||
197 |
static boolean processClientMessage(XEvent xev, int screen) { |
|
198 |
XClientMessageEvent xce = xev.get_xclient(); |
|
199 |
if (xce.get_message_type() == XA_MANAGER.getAtom()) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
200 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
201 |
log.fine("client messags = " + xce); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
202 |
} |
52528
edc729e2ee36
8211810: X11 Time stamp data should be unsigned
itakiguchi
parents:
52248
diff
changeset
|
203 |
long timestamp = xce.get_data(0) & 0xFFFFFFFFL; |
2 | 204 |
long atom = xce.get_data(1); |
205 |
long owner = xce.get_data(2); |
|
206 |
long data = xce.get_data(3); |
|
207 |
||
208 |
XMSelection sel = getInstance(atom); |
|
209 |
if (sel != null) { |
|
210 |
sel.resetOwner(owner,screen); |
|
211 |
sel.dispatchOwnerChangedEvent(xev,screen,owner,data, timestamp); |
|
212 |
} |
|
213 |
} |
|
214 |
return false; |
|
215 |
} |
|
216 |
||
217 |
static boolean processRootEvent(XEvent xev, int screen) { |
|
218 |
switch (xev.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
219 |
case XConstants.ClientMessage: { |
2 | 220 |
return processClientMessage(xev, screen); |
221 |
} |
|
222 |
} |
|
223 |
||
224 |
return false; |
|
225 |
||
226 |
} |
|
227 |
||
228 |
||
229 |
static XMSelection getInstance(long selection) { |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
230 |
return selectionMap.get(Long.valueOf(selection)); |
2 | 231 |
} |
232 |
||
233 |
||
234 |
/* |
|
235 |
* Default constructor specifies PropertyChangeMask as well |
|
236 |
*/ |
|
237 |
||
238 |
public XMSelection (String selname) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
239 |
this(selname, XConstants.PropertyChangeMask); |
2 | 240 |
} |
241 |
||
242 |
||
243 |
/* |
|
244 |
* Some users may not need to know about selection changes, |
|
245 |
* just owner ship changes, They would specify a zero extra mask. |
|
246 |
*/ |
|
247 |
||
248 |
public XMSelection (String selname, long extraMask) { |
|
249 |
||
250 |
synchronized (this) { |
|
251 |
selectionName = selname; |
|
252 |
atoms = new XAtom[getNumberOfScreens()]; |
|
253 |
owners = new long[getNumberOfScreens()]; |
|
254 |
} |
|
255 |
select(extraMask); |
|
256 |
} |
|
257 |
||
258 |
||
259 |
||
260 |
public synchronized void addSelectionListener(XMSelectionListener listener) { |
|
261 |
if (listeners == null) { |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
262 |
listeners = new Vector<>(); |
2 | 263 |
} |
264 |
listeners.add(listener); |
|
265 |
} |
|
266 |
||
267 |
public synchronized void removeSelectionListener(XMSelectionListener listener) { |
|
268 |
if (listeners != null) { |
|
269 |
listeners.remove(listener); |
|
270 |
} |
|
271 |
} |
|
272 |
||
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
273 |
synchronized Collection<XMSelectionListener> getListeners() { |
2 | 274 |
return listeners; |
275 |
} |
|
276 |
||
277 |
synchronized XAtom getAtom(int screen) { |
|
278 |
if (atoms != null) { |
|
279 |
return atoms[screen]; |
|
280 |
} |
|
281 |
return null; |
|
282 |
} |
|
283 |
||
284 |
synchronized void setAtom(XAtom a, int screen) { |
|
285 |
if (atoms != null) { |
|
286 |
atoms[screen] = a; |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
synchronized long getOwner(int screen) { |
|
291 |
if (owners != null) { |
|
292 |
return owners[screen]; |
|
293 |
} |
|
294 |
return 0; |
|
295 |
} |
|
296 |
||
297 |
synchronized void setOwner(long owner, int screen) { |
|
298 |
if (owners != null) { |
|
299 |
owners[screen] = owner; |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
synchronized String getName() { |
|
304 |
return selectionName; |
|
305 |
} |
|
306 |
||
307 |
||
308 |
synchronized void dispatchSelectionChanged( XPropertyEvent ev, int screen) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
309 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
310 |
log.fine("Selection Changed : Screen = " + screen + "Event =" + ev); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
311 |
} |
2 | 312 |
if (listeners != null) { |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
313 |
Iterator<XMSelectionListener> iter = listeners.iterator(); |
2 | 314 |
while (iter.hasNext()) { |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
315 |
XMSelectionListener disp = iter.next(); |
2 | 316 |
disp.selectionChanged(screen, this, ev.get_window(), ev); |
317 |
} |
|
318 |
} |
|
319 |
} |
|
320 |
||
321 |
synchronized void dispatchOwnerDeath(XDestroyWindowEvent de, int screen) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
322 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
323 |
log.fine("Owner dead : Screen = " + screen + "Event =" + de); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
324 |
} |
2 | 325 |
if (listeners != null) { |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
326 |
Iterator<XMSelectionListener> iter = listeners.iterator(); |
2 | 327 |
while (iter.hasNext()) { |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
328 |
XMSelectionListener disp = iter.next(); |
2 | 329 |
disp.ownerDeath(screen, this, de.get_window()); |
330 |
||
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
void dispatchSelectionEvent(XEvent xev, int screen) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
336 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
337 |
log.fine("Event =" + xev); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
338 |
} |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
339 |
if (xev.get_type() == XConstants.DestroyNotify) { |
2 | 340 |
XDestroyWindowEvent de = xev.get_xdestroywindow(); |
341 |
dispatchOwnerDeath( de, screen); |
|
342 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
343 |
else if (xev.get_type() == XConstants.PropertyNotify) { |
2 | 344 |
XPropertyEvent xpe = xev.get_xproperty(); |
345 |
dispatchSelectionChanged( xpe, screen); |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
||
350 |
synchronized void dispatchOwnerChangedEvent(XEvent ev, int screen, long owner, long data, long timestamp) { |
|
351 |
if (listeners != null) { |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
352 |
Iterator<XMSelectionListener> iter = listeners.iterator(); |
2 | 353 |
while (iter.hasNext()) { |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23010
diff
changeset
|
354 |
XMSelectionListener disp = iter.next(); |
2 | 355 |
disp.ownerChanged(screen,this, owner, data, timestamp); |
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
||
361 |
} |