2
|
1 |
/*
|
114
|
2 |
* Copyright 2002-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 |
package sun.awt.X11;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* XAtom is a class that allows you to create and modify X Window properties.
|
|
30 |
* An X Atom is an identifier for a property that you can set on any X Window.
|
|
31 |
* Standard X Atom are defined by X11 and these atoms are defined in this class
|
|
32 |
* for convenience. Common X Atoms like <code>XA_WM_NAME</code> are used to communicate with the
|
|
33 |
* Window manager to let it know the Window name. The use and protocol for these
|
|
34 |
* atoms are defined in the Inter client communications converntions manual.
|
|
35 |
* User specified XAtoms are defined by specifying a name that gets Interned
|
|
36 |
* by the XServer and an <code>XAtom</code> object is returned. An <code>XAtom</code> can also be created
|
|
37 |
* by using a pre-exisiting atom like <code>XA_WM_CLASS</code>. A <code>display</code> has to be specified
|
|
38 |
* in order to create an <code>XAtom</code>. <p> <p>
|
|
39 |
*
|
|
40 |
* Once an <code>XAtom</code> instance is created, you can call get and set property methods to
|
|
41 |
* set the values for a particular window. <p> <p>
|
|
42 |
*
|
|
43 |
*
|
|
44 |
* Example usage : To set the window name for a top level: <p>
|
|
45 |
* <code>
|
|
46 |
* XAtom xa = new XAtom(display,XAtom.XA_WM_NAME); <p>
|
|
47 |
* xa.setProperty(window,"Hello World");<p></code>
|
|
48 |
*<p>
|
|
49 |
*<p>
|
|
50 |
* To get the cut buffer :<p>
|
|
51 |
* <p><code>
|
|
52 |
* XAtom xa = new XAtom(display,XAtom.XA_CUT_BUFFER0);<p>
|
|
53 |
* String selection = xa.getProperty(root_window);<p></code>
|
|
54 |
* @author Bino George
|
|
55 |
* @since JDK1.5
|
|
56 |
*/
|
|
57 |
|
|
58 |
import sun.misc.Unsafe;
|
|
59 |
import java.util.HashMap;
|
|
60 |
|
114
|
61 |
public final class XAtom {
|
2
|
62 |
|
|
63 |
// Order of lock: XAWTLock -> XAtom.class
|
|
64 |
|
|
65 |
/* Predefined Atoms - automatically extracted from XAtom.h */
|
|
66 |
private static Unsafe unsafe = XlibWrapper.unsafe;
|
|
67 |
private static XAtom[] emptyList = new XAtom[0];
|
|
68 |
|
|
69 |
public static final long XA_PRIMARY=1;
|
|
70 |
public static final long XA_SECONDARY=2;
|
|
71 |
public static final long XA_ARC=3;
|
|
72 |
public static final long XA_ATOM=4;
|
|
73 |
public static final long XA_BITMAP=5;
|
|
74 |
public static final long XA_CARDINAL=6;
|
|
75 |
public static final long XA_COLORMAP=7;
|
|
76 |
public static final long XA_CURSOR=8;
|
|
77 |
public static final long XA_CUT_BUFFER0=9;
|
|
78 |
public static final long XA_CUT_BUFFER1=10;
|
|
79 |
public static final long XA_CUT_BUFFER2=11;
|
|
80 |
public static final long XA_CUT_BUFFER3=12;
|
|
81 |
public static final long XA_CUT_BUFFER4=13;
|
|
82 |
public static final long XA_CUT_BUFFER5=14;
|
|
83 |
public static final long XA_CUT_BUFFER6=15;
|
|
84 |
public static final long XA_CUT_BUFFER7=16;
|
|
85 |
public static final long XA_DRAWABLE=17;
|
|
86 |
public static final long XA_FONT=18;
|
|
87 |
public static final long XA_INTEGER=19;
|
|
88 |
public static final long XA_PIXMAP=20;
|
|
89 |
public static final long XA_POINT=21;
|
|
90 |
public static final long XA_RECTANGLE=22;
|
|
91 |
public static final long XA_RESOURCE_MANAGER=23;
|
|
92 |
public static final long XA_RGB_COLOR_MAP=24;
|
|
93 |
public static final long XA_RGB_BEST_MAP=25;
|
|
94 |
public static final long XA_RGB_BLUE_MAP=26;
|
|
95 |
public static final long XA_RGB_DEFAULT_MAP=27;
|
|
96 |
public static final long XA_RGB_GRAY_MAP=28;
|
|
97 |
public static final long XA_RGB_GREEN_MAP=29;
|
|
98 |
public static final long XA_RGB_RED_MAP=30;
|
|
99 |
public static final long XA_STRING=31;
|
|
100 |
public static final long XA_VISUALID=32;
|
|
101 |
public static final long XA_WINDOW=33;
|
|
102 |
public static final long XA_WM_COMMAND=34;
|
|
103 |
public static final long XA_WM_HINTS=35;
|
|
104 |
public static final long XA_WM_CLIENT_MACHINE=36;
|
|
105 |
public static final long XA_WM_ICON_NAME=37;
|
|
106 |
public static final long XA_WM_ICON_SIZE=38;
|
|
107 |
public static final long XA_WM_NAME=39;
|
|
108 |
public static final long XA_WM_NORMAL_HINTS=40;
|
|
109 |
public static final long XA_WM_SIZE_HINTS=41;
|
|
110 |
public static final long XA_WM_ZOOM_HINTS=42;
|
|
111 |
public static final long XA_MIN_SPACE=43;
|
|
112 |
public static final long XA_NORM_SPACE=44;
|
|
113 |
public static final long XA_MAX_SPACE=45;
|
|
114 |
public static final long XA_END_SPACE=46;
|
|
115 |
public static final long XA_SUPERSCRIPT_X=47;
|
|
116 |
public static final long XA_SUPERSCRIPT_Y=48;
|
|
117 |
public static final long XA_SUBSCRIPT_X=49;
|
|
118 |
public static final long XA_SUBSCRIPT_Y=50;
|
|
119 |
public static final long XA_UNDERLINE_POSITION=51;
|
|
120 |
public static final long XA_UNDERLINE_THICKNESS=52 ;
|
|
121 |
public static final long XA_STRIKEOUT_ASCENT=53;
|
|
122 |
public static final long XA_STRIKEOUT_DESCENT=54;
|
|
123 |
public static final long XA_ITALIC_ANGLE=55;
|
|
124 |
public static final long XA_X_HEIGHT=56;
|
|
125 |
public static final long XA_QUAD_WIDTH=57;
|
|
126 |
public static final long XA_WEIGHT=58;
|
|
127 |
public static final long XA_POINT_SIZE=59;
|
|
128 |
public static final long XA_RESOLUTION=60;
|
|
129 |
public static final long XA_COPYRIGHT=61;
|
|
130 |
public static final long XA_NOTICE=62;
|
|
131 |
public static final long XA_FONT_NAME=63;
|
|
132 |
public static final long XA_FAMILY_NAME=64;
|
|
133 |
public static final long XA_FULL_NAME=65;
|
|
134 |
public static final long XA_CAP_HEIGHT=66;
|
|
135 |
public static final long XA_WM_CLASS=67;
|
|
136 |
public static final long XA_WM_TRANSIENT_FOR=68;
|
|
137 |
public static final long XA_LAST_PREDEFINED=68;
|
|
138 |
static HashMap<Long, XAtom> atomToAtom = new HashMap<Long, XAtom>();
|
|
139 |
static HashMap<String, XAtom> nameToAtom = new HashMap<String, XAtom>();
|
|
140 |
static void register(XAtom at) {
|
|
141 |
if (at == null) {
|
|
142 |
return;
|
|
143 |
}
|
|
144 |
synchronized (XAtom.class) {
|
|
145 |
if (at.atom != 0) {
|
|
146 |
atomToAtom.put(Long.valueOf(at.atom), at);
|
|
147 |
}
|
|
148 |
if (at.name != null) {
|
|
149 |
nameToAtom.put(at.name, at);
|
|
150 |
}
|
|
151 |
}
|
|
152 |
}
|
|
153 |
static XAtom lookup(long atom) {
|
|
154 |
synchronized (XAtom.class) {
|
|
155 |
return atomToAtom.get(Long.valueOf(atom));
|
|
156 |
}
|
|
157 |
}
|
|
158 |
static XAtom lookup(String name) {
|
|
159 |
synchronized (XAtom.class) {
|
|
160 |
return nameToAtom.get(name);
|
|
161 |
}
|
|
162 |
}
|
|
163 |
/*
|
|
164 |
* [das]Suggestion:
|
|
165 |
* 1.Make XAtom immutable.
|
|
166 |
* 2.Replace public ctors with factory methods (e.g. get() below).
|
|
167 |
*/
|
|
168 |
static XAtom get(long atom) {
|
|
169 |
XAtom xatom = lookup(atom);
|
|
170 |
if (xatom == null) {
|
|
171 |
xatom = new XAtom(XToolkit.getDisplay(), atom);
|
|
172 |
}
|
|
173 |
return xatom;
|
|
174 |
}
|
|
175 |
public static XAtom get(String name) {
|
|
176 |
XAtom xatom = lookup(name);
|
|
177 |
if (xatom == null) {
|
114
|
178 |
xatom = new XAtom(XToolkit.getDisplay(), name);
|
2
|
179 |
}
|
|
180 |
return xatom;
|
|
181 |
}
|
|
182 |
public final String getName() {
|
|
183 |
if (name == null) {
|
|
184 |
XToolkit.awtLock();
|
|
185 |
try {
|
|
186 |
this.name = XlibWrapper.XGetAtomName(display, atom);
|
|
187 |
} finally {
|
|
188 |
XToolkit.awtUnlock();
|
|
189 |
}
|
|
190 |
register();
|
|
191 |
}
|
|
192 |
return name;
|
|
193 |
}
|
|
194 |
static String asString(long atom) {
|
|
195 |
XAtom at = lookup(atom);
|
|
196 |
if (at == null) {
|
|
197 |
return Long.toString(atom);
|
|
198 |
} else {
|
|
199 |
return at.toString();
|
|
200 |
}
|
|
201 |
}
|
|
202 |
void register() {
|
|
203 |
register(this);
|
|
204 |
}
|
|
205 |
public String toString() {
|
|
206 |
if (name != null) {
|
|
207 |
return name + ":" + atom;
|
|
208 |
} else {
|
|
209 |
return Long.toString(atom);
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
/* interned value of Atom */
|
|
214 |
long atom = 0;
|
|
215 |
|
|
216 |
/* name of atom */
|
|
217 |
String name;
|
|
218 |
|
|
219 |
/* display for X connection */
|
|
220 |
long display;
|
|
221 |
|
|
222 |
|
|
223 |
/** This constructor will create and intern a new XAtom that is specified
|
|
224 |
* by the supplied name.
|
|
225 |
*
|
|
226 |
* @param display X display to use
|
|
227 |
* @param name name of the XAtom to create.
|
|
228 |
* @since 1.5
|
|
229 |
*/
|
|
230 |
|
|
231 |
private XAtom(long display, String name) {
|
|
232 |
this(display, name, true);
|
|
233 |
}
|
|
234 |
|
|
235 |
public XAtom(String name, boolean autoIntern) {
|
|
236 |
this(XToolkit.getDisplay(), name, autoIntern);
|
|
237 |
}
|
|
238 |
|
|
239 |
/** This constructor will create an instance of XAtom that is specified
|
|
240 |
* by the predefined XAtom specified by u <code> latom </code>
|
|
241 |
*
|
|
242 |
* @param display X display to use.
|
|
243 |
* @param atom a predefined XAtom.
|
|
244 |
* @since 1.5
|
|
245 |
*/
|
|
246 |
public XAtom(long display, long atom) {
|
|
247 |
this.atom = atom;
|
|
248 |
this.display = display;
|
|
249 |
register();
|
|
250 |
}
|
|
251 |
|
|
252 |
/** This constructor will create the instance,
|
|
253 |
* and if <code>autoIntern</code> is true intern a new XAtom that is specified
|
|
254 |
* by the supplied name.
|
|
255 |
*
|
|
256 |
* @param display X display to use
|
|
257 |
* @param name name of the XAtom to create.
|
|
258 |
* @since 1.5
|
|
259 |
*/
|
|
260 |
|
114
|
261 |
private XAtom(long display, String name, boolean autoIntern) {
|
2
|
262 |
this.name = name;
|
|
263 |
this.display = display;
|
|
264 |
if (autoIntern) {
|
|
265 |
XToolkit.awtLock();
|
|
266 |
try {
|
|
267 |
atom = XlibWrapper.InternAtom(display,name,0);
|
|
268 |
} finally {
|
|
269 |
XToolkit.awtUnlock();
|
|
270 |
}
|
|
271 |
}
|
|
272 |
register();
|
|
273 |
}
|
|
274 |
|
|
275 |
/**
|
|
276 |
* Creates uninitialized instance of
|
|
277 |
*/
|
|
278 |
public XAtom() {
|
|
279 |
}
|
|
280 |
|
|
281 |
/** Sets the window property for the specified window
|
|
282 |
* @param window window id to use
|
|
283 |
* @param str value to set to.
|
|
284 |
* @since 1.5
|
|
285 |
*/
|
|
286 |
public void setProperty(long window, String str) {
|
|
287 |
if (atom == 0) {
|
|
288 |
throw new IllegalStateException("Atom should be initialized");
|
|
289 |
}
|
|
290 |
checkWindow(window);
|
|
291 |
XToolkit.awtLock();
|
|
292 |
try {
|
|
293 |
XlibWrapper.SetProperty(display,window,atom,str);
|
|
294 |
} finally {
|
|
295 |
XToolkit.awtUnlock();
|
|
296 |
}
|
|
297 |
}
|
|
298 |
|
|
299 |
/**
|
|
300 |
* Sets UTF8_STRING type property. Explicitly converts str to UTF-8 byte sequence.
|
|
301 |
*/
|
|
302 |
public void setPropertyUTF8(long window, String str) {
|
|
303 |
XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING"); /* like STRING but encoding is UTF-8 */
|
|
304 |
if (atom == 0) {
|
|
305 |
throw new IllegalStateException("Atom should be initialized");
|
|
306 |
}
|
|
307 |
checkWindow(window);
|
|
308 |
byte[] bdata = null;
|
|
309 |
try {
|
|
310 |
bdata = str.getBytes("UTF-8");
|
|
311 |
} catch (java.io.UnsupportedEncodingException uee) {
|
|
312 |
uee.printStackTrace();
|
|
313 |
}
|
|
314 |
if (bdata != null) {
|
|
315 |
setAtomData(window, XA_UTF8_STRING.atom, bdata);
|
|
316 |
}
|
|
317 |
}
|
|
318 |
|
|
319 |
/**
|
|
320 |
* Sets STRING/8 type property. Explicitly converts str to Latin-1 byte sequence.
|
|
321 |
*/
|
|
322 |
public void setProperty8(long window, String str) {
|
|
323 |
if (atom == 0) {
|
|
324 |
throw new IllegalStateException("Atom should be initialized");
|
|
325 |
}
|
|
326 |
checkWindow(window);
|
|
327 |
byte[] bdata = null;
|
|
328 |
try {
|
|
329 |
bdata = str.getBytes("ISO-8859-1");
|
|
330 |
} catch (java.io.UnsupportedEncodingException uee) {
|
|
331 |
uee.printStackTrace();
|
|
332 |
}
|
|
333 |
if (bdata != null) {
|
|
334 |
setAtomData(window, XA_STRING, bdata);
|
|
335 |
}
|
|
336 |
}
|
|
337 |
|
|
338 |
|
|
339 |
/** Gets the window property for the specified window
|
|
340 |
* @param window window id to use
|
|
341 |
* @param str value to set to.
|
|
342 |
* @return string with the property.
|
|
343 |
* @since 1.5
|
|
344 |
*/
|
|
345 |
public String getProperty(long window) {
|
|
346 |
if (atom == 0) {
|
|
347 |
throw new IllegalStateException("Atom should be initialized");
|
|
348 |
}
|
|
349 |
checkWindow(window);
|
|
350 |
XToolkit.awtLock();
|
|
351 |
try {
|
|
352 |
return XlibWrapper.GetProperty(display,window,atom);
|
|
353 |
} finally {
|
|
354 |
XToolkit.awtUnlock();
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|
|
358 |
|
|
359 |
/*
|
|
360 |
* Auxiliary function that returns the value of 'property' of type
|
|
361 |
* 'property_type' on window 'window'. Format of the property must be 32.
|
|
362 |
*/
|
|
363 |
public long get32Property(long window, long property_type) {
|
|
364 |
if (atom == 0) {
|
|
365 |
throw new IllegalStateException("Atom should be initialized");
|
|
366 |
}
|
|
367 |
checkWindow(window);
|
|
368 |
WindowPropertyGetter getter =
|
|
369 |
new WindowPropertyGetter(window, this, 0, 1,
|
|
370 |
false, property_type);
|
|
371 |
try {
|
|
372 |
int status = getter.execute();
|
|
373 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
374 |
return 0;
|
|
375 |
}
|
|
376 |
if (getter.getActualType() != property_type || getter.getActualFormat() != 32) {
|
|
377 |
return 0;
|
|
378 |
}
|
|
379 |
return Native.getCard32(getter.getData());
|
|
380 |
} finally {
|
|
381 |
getter.dispose();
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
/**
|
|
386 |
* Returns value of property of type CARDINAL/32 of this window
|
|
387 |
*/
|
|
388 |
public long getCard32Property(XBaseWindow window) {
|
|
389 |
return get32Property(window.getWindow(), XA_CARDINAL);
|
|
390 |
}
|
|
391 |
|
|
392 |
/**
|
|
393 |
* Sets property of type CARDINAL on the window
|
|
394 |
*/
|
|
395 |
public void setCard32Property(long window, long value) {
|
|
396 |
if (atom == 0) {
|
|
397 |
throw new IllegalStateException("Atom should be initialized");
|
|
398 |
}
|
|
399 |
checkWindow(window);
|
|
400 |
XToolkit.awtLock();
|
|
401 |
try {
|
|
402 |
Native.putCard32(XlibWrapper.larg1, value);
|
|
403 |
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
|
|
404 |
atom, XA_CARDINAL, 32, XlibWrapper.PropModeReplace,
|
|
405 |
XlibWrapper.larg1, 1);
|
|
406 |
} finally {
|
|
407 |
XToolkit.awtUnlock();
|
|
408 |
}
|
|
409 |
}
|
|
410 |
|
|
411 |
/**
|
|
412 |
* Sets property of type CARDINAL/32 on the window
|
|
413 |
*/
|
|
414 |
public void setCard32Property(XBaseWindow window, long value) {
|
|
415 |
setCard32Property(window.getWindow(), value);
|
|
416 |
}
|
|
417 |
|
|
418 |
/**
|
|
419 |
* Gets uninterpreted set of data from property and stores them in data_ptr.
|
|
420 |
* Property type is the same as current atom, property is current atom.
|
|
421 |
* Property format is 32. Property 'delete' is false.
|
|
422 |
* Returns boolean if requested type, format, length match returned values
|
|
423 |
* and returned data pointer is not null.
|
|
424 |
*/
|
|
425 |
public boolean getAtomData(long window, long data_ptr, int length) {
|
|
426 |
if (atom == 0) {
|
|
427 |
throw new IllegalStateException("Atom should be initialized");
|
|
428 |
}
|
|
429 |
checkWindow(window);
|
|
430 |
WindowPropertyGetter getter =
|
|
431 |
new WindowPropertyGetter(window, this, 0, (long)length,
|
|
432 |
false, this);
|
|
433 |
try {
|
|
434 |
int status = getter.execute();
|
|
435 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
436 |
return false;
|
|
437 |
}
|
|
438 |
if (getter.getActualType() != atom
|
|
439 |
|| getter.getActualFormat() != 32
|
|
440 |
|| getter.getNumberOfItems() != length
|
|
441 |
)
|
|
442 |
{
|
|
443 |
return false;
|
|
444 |
}
|
|
445 |
XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
|
|
446 |
return true;
|
|
447 |
} finally {
|
|
448 |
getter.dispose();
|
|
449 |
}
|
|
450 |
}
|
|
451 |
|
|
452 |
/**
|
|
453 |
* Gets uninterpreted set of data from property and stores them in data_ptr.
|
|
454 |
* Property type is <code>type</code>, property is current atom.
|
|
455 |
* Property format is 32. Property 'delete' is false.
|
|
456 |
* Returns boolean if requested type, format, length match returned values
|
|
457 |
* and returned data pointer is not null.
|
|
458 |
*/
|
|
459 |
public boolean getAtomData(long window, long type, long data_ptr, int length) {
|
|
460 |
if (atom == 0) {
|
|
461 |
throw new IllegalStateException("Atom should be initialized");
|
|
462 |
}
|
|
463 |
checkWindow(window);
|
|
464 |
WindowPropertyGetter getter =
|
|
465 |
new WindowPropertyGetter(window, this, 0, (long)length,
|
|
466 |
false, type);
|
|
467 |
try {
|
|
468 |
int status = getter.execute();
|
|
469 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
470 |
return false;
|
|
471 |
}
|
|
472 |
if (getter.getActualType() != type
|
|
473 |
|| getter.getActualFormat() != 32
|
|
474 |
|| getter.getNumberOfItems() != length
|
|
475 |
)
|
|
476 |
{
|
|
477 |
return false;
|
|
478 |
}
|
|
479 |
XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
|
|
480 |
return true;
|
|
481 |
} finally {
|
|
482 |
getter.dispose();
|
|
483 |
}
|
|
484 |
}
|
|
485 |
|
|
486 |
/**
|
|
487 |
* Sets uninterpreted set of data into property from data_ptr.
|
|
488 |
* Property type is the same as current atom, property is current atom.
|
|
489 |
* Property format is 32. Mode is PropModeReplace. length is a number
|
|
490 |
* of items pointer by data_ptr.
|
|
491 |
*/
|
|
492 |
public void setAtomData(long window, long data_ptr, int length) {
|
|
493 |
if (atom == 0) {
|
|
494 |
throw new IllegalStateException("Atom should be initialized");
|
|
495 |
}
|
|
496 |
checkWindow(window);
|
|
497 |
XToolkit.awtLock();
|
|
498 |
try {
|
|
499 |
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
|
|
500 |
atom, atom, 32, XlibWrapper.PropModeReplace,
|
|
501 |
data_ptr, length);
|
|
502 |
} finally {
|
|
503 |
XToolkit.awtUnlock();
|
|
504 |
}
|
|
505 |
}
|
|
506 |
|
|
507 |
/**
|
|
508 |
* Sets uninterpreted set of data into property from data_ptr.
|
|
509 |
* Property type is <code>type</code>, property is current atom.
|
|
510 |
* Property format is 32. Mode is PropModeReplace. length is a number
|
|
511 |
* of items pointer by data_ptr.
|
|
512 |
*/
|
|
513 |
public void setAtomData(long window, long type, long data_ptr, int length) {
|
|
514 |
if (atom == 0) {
|
|
515 |
throw new IllegalStateException("Atom should be initialized");
|
|
516 |
}
|
|
517 |
checkWindow(window);
|
|
518 |
XToolkit.awtLock();
|
|
519 |
try {
|
|
520 |
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
|
|
521 |
atom, type, 32, XlibWrapper.PropModeReplace,
|
|
522 |
data_ptr, length);
|
|
523 |
} finally {
|
|
524 |
XToolkit.awtUnlock();
|
|
525 |
}
|
|
526 |
}
|
|
527 |
|
|
528 |
/**
|
|
529 |
* Sets uninterpreted set of data into property from data_ptr.
|
|
530 |
* Property type is <code>type</code>, property is current atom.
|
|
531 |
* Property format is 8. Mode is PropModeReplace. length is a number
|
|
532 |
* of bytes pointer by data_ptr.
|
|
533 |
*/
|
|
534 |
public void setAtomData8(long window, long type, long data_ptr, int length) {
|
|
535 |
if (atom == 0) {
|
|
536 |
throw new IllegalStateException("Atom should be initialized");
|
|
537 |
}
|
|
538 |
checkWindow(window);
|
|
539 |
XToolkit.awtLock();
|
|
540 |
try {
|
|
541 |
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
|
|
542 |
atom, type, 8, XlibWrapper.PropModeReplace,
|
|
543 |
data_ptr, length);
|
|
544 |
} finally {
|
|
545 |
XToolkit.awtUnlock();
|
|
546 |
}
|
|
547 |
}
|
|
548 |
|
|
549 |
/**
|
|
550 |
* Deletes property specified by this item on the window.
|
|
551 |
*/
|
|
552 |
public void DeleteProperty(long window) {
|
|
553 |
if (atom == 0) {
|
|
554 |
throw new IllegalStateException("Atom should be initialized");
|
|
555 |
}
|
|
556 |
checkWindow(window);
|
|
557 |
XToolkit.awtLock();
|
|
558 |
try {
|
|
559 |
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window, atom);
|
|
560 |
} finally {
|
|
561 |
XToolkit.awtUnlock();
|
|
562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
/**
|
|
566 |
* Deletes property specified by this item on the window.
|
|
567 |
*/
|
|
568 |
public void DeleteProperty(XBaseWindow window) {
|
|
569 |
if (atom == 0) {
|
|
570 |
throw new IllegalStateException("Atom should be initialized");
|
|
571 |
}
|
|
572 |
checkWindow(window.getWindow());
|
|
573 |
XToolkit.awtLock();
|
|
574 |
try {
|
|
575 |
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
|
|
576 |
window.getWindow(), atom);
|
|
577 |
} finally {
|
|
578 |
XToolkit.awtUnlock();
|
|
579 |
}
|
|
580 |
}
|
|
581 |
|
|
582 |
public void setAtomData(long window, long property_type, byte[] data) {
|
|
583 |
long bdata = Native.toData(data);
|
|
584 |
try {
|
|
585 |
setAtomData8(window, property_type, bdata, data.length);
|
|
586 |
} finally {
|
|
587 |
unsafe.freeMemory(bdata);
|
|
588 |
}
|
|
589 |
}
|
|
590 |
|
|
591 |
/*
|
|
592 |
* Auxiliary function that returns the value of 'property' of type
|
|
593 |
* 'property_type' on window 'window'. Format of the property must be 8.
|
|
594 |
*/
|
|
595 |
public byte[] getByteArrayProperty(long window, long property_type) {
|
|
596 |
if (atom == 0) {
|
|
597 |
throw new IllegalStateException("Atom should be initialized");
|
|
598 |
}
|
|
599 |
checkWindow(window);
|
|
600 |
WindowPropertyGetter getter =
|
|
601 |
new WindowPropertyGetter(window, this, 0, 0xFFFF,
|
|
602 |
false, property_type);
|
|
603 |
try {
|
|
604 |
int status = getter.execute();
|
|
605 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
606 |
return null;
|
|
607 |
}
|
|
608 |
if (getter.getActualType() != property_type || getter.getActualFormat() != 8) {
|
|
609 |
return null;
|
|
610 |
}
|
|
611 |
byte[] res = XlibWrapper.getStringBytes(getter.getData());
|
|
612 |
return res;
|
|
613 |
} finally {
|
|
614 |
getter.dispose();
|
|
615 |
}
|
|
616 |
}
|
|
617 |
|
|
618 |
/**
|
|
619 |
* Interns the XAtom
|
|
620 |
*/
|
|
621 |
public void intern(boolean onlyIfExists) {
|
|
622 |
XToolkit.awtLock();
|
|
623 |
try {
|
|
624 |
atom = XlibWrapper.InternAtom(display,name, onlyIfExists?1:0);
|
|
625 |
} finally {
|
|
626 |
XToolkit.awtUnlock();
|
|
627 |
}
|
|
628 |
register();
|
|
629 |
}
|
|
630 |
|
|
631 |
public boolean isInterned() {
|
|
632 |
if (atom == 0) {
|
|
633 |
XToolkit.awtLock();
|
|
634 |
try {
|
|
635 |
atom = XlibWrapper.InternAtom(display, name, 1);
|
|
636 |
} finally {
|
|
637 |
XToolkit.awtUnlock();
|
|
638 |
}
|
|
639 |
if (atom == 0) {
|
|
640 |
return false;
|
|
641 |
} else {
|
|
642 |
register();
|
|
643 |
return true;
|
|
644 |
}
|
|
645 |
} else {
|
|
646 |
return true;
|
|
647 |
}
|
|
648 |
}
|
|
649 |
|
|
650 |
public void setValues(long display, String name, long atom) {
|
|
651 |
this.display = display;
|
|
652 |
this.atom = atom;
|
|
653 |
this.name = name;
|
|
654 |
register();
|
|
655 |
}
|
|
656 |
|
|
657 |
static int getAtomSize() {
|
|
658 |
return Native.getLongSize();
|
|
659 |
}
|
|
660 |
|
|
661 |
/*
|
|
662 |
* Returns the value of property ATOM[]/32 as array of XAtom objects
|
|
663 |
* @return array of atoms, array of length 0 if the atom list is empty
|
|
664 |
* or has different format
|
|
665 |
*/
|
|
666 |
XAtom[] getAtomListProperty(long window) {
|
|
667 |
if (atom == 0) {
|
|
668 |
throw new IllegalStateException("Atom should be initialized");
|
|
669 |
}
|
|
670 |
checkWindow(window);
|
|
671 |
|
|
672 |
WindowPropertyGetter getter =
|
|
673 |
new WindowPropertyGetter(window, this, 0, 0xFFFF,
|
|
674 |
false, XA_ATOM);
|
|
675 |
try {
|
|
676 |
int status = getter.execute();
|
|
677 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
678 |
return emptyList;
|
|
679 |
}
|
|
680 |
if (getter.getActualType() != XA_ATOM || getter.getActualFormat() != 32) {
|
|
681 |
return emptyList;
|
|
682 |
}
|
|
683 |
|
|
684 |
int count = (int)getter.getNumberOfItems();
|
|
685 |
if (count == 0) {
|
|
686 |
return emptyList;
|
|
687 |
}
|
|
688 |
long list_atoms = getter.getData();
|
|
689 |
XAtom[] res = new XAtom[count];
|
|
690 |
for (int index = 0; index < count; index++) {
|
|
691 |
res[index] = XAtom.get(XAtom.getAtom(list_atoms+index*getAtomSize()));
|
|
692 |
}
|
|
693 |
return res;
|
|
694 |
} finally {
|
|
695 |
getter.dispose();
|
|
696 |
}
|
|
697 |
}
|
|
698 |
|
|
699 |
/*
|
|
700 |
* Returns the value of property of type ATOM[]/32 as XAtomList
|
|
701 |
* @return list of atoms, empty list if the atom list is empty
|
|
702 |
* or has different format
|
|
703 |
*/
|
|
704 |
XAtomList getAtomListPropertyList(long window) {
|
|
705 |
return new XAtomList(getAtomListProperty(window));
|
|
706 |
}
|
|
707 |
XAtomList getAtomListPropertyList(XBaseWindow window) {
|
|
708 |
return getAtomListPropertyList(window.getWindow());
|
|
709 |
}
|
|
710 |
XAtom[] getAtomListProperty(XBaseWindow window) {
|
|
711 |
return getAtomListProperty(window.getWindow());
|
|
712 |
}
|
|
713 |
|
|
714 |
/**
|
|
715 |
* Sets property value of type ATOM list to the list of atoms.
|
|
716 |
*/
|
|
717 |
void setAtomListProperty(long window, XAtom[] atoms) {
|
|
718 |
long data = toData(atoms);
|
|
719 |
setAtomData(window, XAtom.XA_ATOM, data, atoms.length);
|
|
720 |
unsafe.freeMemory(data);
|
|
721 |
}
|
|
722 |
|
|
723 |
/**
|
|
724 |
* Sets property value of type ATOM list to the list of atoms specified by XAtomList
|
|
725 |
*/
|
|
726 |
void setAtomListProperty(long window, XAtomList atoms) {
|
|
727 |
long data = atoms.getAtomsData();
|
|
728 |
setAtomData(window, XAtom.XA_ATOM, data, atoms.size());
|
|
729 |
unsafe.freeMemory(data);
|
|
730 |
}
|
|
731 |
/**
|
|
732 |
* Sets property value of type ATOM list to the list of atoms.
|
|
733 |
*/
|
|
734 |
public void setAtomListProperty(XBaseWindow window, XAtom[] atoms) {
|
|
735 |
setAtomListProperty(window.getWindow(), atoms);
|
|
736 |
}
|
|
737 |
|
|
738 |
/**
|
|
739 |
* Sets property value of type ATOM list to the list of atoms specified by XAtomList
|
|
740 |
*/
|
|
741 |
public void setAtomListProperty(XBaseWindow window, XAtomList atoms) {
|
|
742 |
setAtomListProperty(window.getWindow(), atoms);
|
|
743 |
}
|
|
744 |
|
|
745 |
long getAtom() {
|
|
746 |
return atom;
|
|
747 |
}
|
|
748 |
|
|
749 |
void putAtom(long ptr) {
|
|
750 |
Native.putLong(ptr, atom);
|
|
751 |
}
|
|
752 |
|
|
753 |
static long getAtom(long ptr) {
|
|
754 |
return Native.getLong(ptr);
|
|
755 |
}
|
|
756 |
/**
|
|
757 |
* Allocated memory to hold the list of native atom data and returns unsafe pointer to it
|
|
758 |
* Caller should free the memory by himself.
|
|
759 |
*/
|
|
760 |
static long toData(XAtom[] atoms) {
|
|
761 |
long data = unsafe.allocateMemory(getAtomSize() * atoms.length);
|
|
762 |
for (int i = 0; i < atoms.length; i++ ) {
|
|
763 |
if (atoms[i] != null) {
|
|
764 |
atoms[i].putAtom(data + i * getAtomSize());
|
|
765 |
}
|
|
766 |
}
|
|
767 |
return data;
|
|
768 |
}
|
|
769 |
|
|
770 |
void checkWindow(long window) {
|
|
771 |
if (window == 0) {
|
|
772 |
throw new IllegalArgumentException("Window must not be zero");
|
|
773 |
}
|
|
774 |
}
|
|
775 |
|
|
776 |
public boolean equals(Object o) {
|
|
777 |
if (!(o instanceof XAtom)) {
|
|
778 |
return false;
|
|
779 |
}
|
|
780 |
XAtom ot = (XAtom)o;
|
|
781 |
return (atom == ot.atom && display == ot.display);
|
|
782 |
}
|
|
783 |
public int hashCode() {
|
|
784 |
return (int)((atom ^ display)& 0xFFFFL);
|
|
785 |
}
|
|
786 |
|
|
787 |
/**
|
|
788 |
* Sets property on the <code>window</code> to the value <code>window_value</window>
|
|
789 |
* Property is assumed to be of type WINDOW/32
|
|
790 |
*/
|
|
791 |
public void setWindowProperty(long window, long window_value) {
|
|
792 |
if (atom == 0) {
|
|
793 |
throw new IllegalStateException("Atom should be initialized");
|
|
794 |
}
|
|
795 |
checkWindow(window);
|
|
796 |
XToolkit.awtLock();
|
|
797 |
try {
|
|
798 |
Native.putWindow(XlibWrapper.larg1, window_value);
|
|
799 |
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
|
|
800 |
atom, XA_WINDOW, 32, XlibWrapper.PropModeReplace,
|
|
801 |
XlibWrapper.larg1, 1);
|
|
802 |
} finally {
|
|
803 |
XToolkit.awtUnlock();
|
|
804 |
}
|
|
805 |
}
|
|
806 |
public void setWindowProperty(XBaseWindow window, XBaseWindow window_value) {
|
|
807 |
setWindowProperty(window.getWindow(), window_value.getWindow());
|
|
808 |
}
|
|
809 |
|
|
810 |
/**
|
|
811 |
* Gets property on the <code>window</code>. Property is assumed to be
|
|
812 |
* of type WINDOW/32.
|
|
813 |
*/
|
|
814 |
public long getWindowProperty(long window) {
|
|
815 |
if (atom == 0) {
|
|
816 |
throw new IllegalStateException("Atom should be initialized");
|
|
817 |
}
|
|
818 |
checkWindow(window);
|
|
819 |
WindowPropertyGetter getter =
|
|
820 |
new WindowPropertyGetter(window, this, 0, 1,
|
|
821 |
false, XA_WINDOW);
|
|
822 |
try {
|
|
823 |
int status = getter.execute();
|
|
824 |
if (status != XlibWrapper.Success || getter.getData() == 0) {
|
|
825 |
return 0;
|
|
826 |
}
|
|
827 |
if (getter.getActualType() != XA_WINDOW || getter.getActualFormat() != 32) {
|
|
828 |
return 0;
|
|
829 |
}
|
|
830 |
return Native.getWindow(getter.getData());
|
|
831 |
} finally {
|
|
832 |
getter.dispose();
|
|
833 |
}
|
|
834 |
}
|
|
835 |
}
|