/* * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
package sun.awt.X11;
/** * XAtom is a class that allows you to create and modify X Window properties. * An X Atom is an identifier for a property that you can set on any X Window. * Standard X Atom are defined by X11 and these atoms are defined in this class * for convenience. Common X Atoms like {@code XA_WM_NAME} are used to communicate with the * Window manager to let it know the Window name. The use and protocol for these * atoms are defined in the Inter client communications converntions manual. * User specified XAtoms are defined by specifying a name that gets Interned * by the XServer and an {@code XAtom} object is returned. An {@code XAtom} can also be created * by using a pre-exisiting atom like {@code XA_WM_CLASS}. A {@code display} has to be specified * in order to create an {@code XAtom}. <p> <p> * * Once an {@code XAtom} instance is created, you can call get and set property methods to * set the values for a particular window. <p> <p> * * * Example usage : To set the window name for a top level: <p> * <pre>{@code * XAtom xa = new XAtom(display,XAtom.XA_WM_NAME); * xa.setProperty(window,"Hello World"); * }</pre> * <p> * <p> * To get the cut buffer: * <pre>{@code * XAtom xa = new XAtom(display,XAtom.XA_CUT_BUFFER0); * String selection = xa.getProperty(root_window); * }</pre> * * @author Bino George * @since 1.5
*/
/** This constructor will create and intern a new XAtom that is specified * by the supplied name. * * @param display X display to use * @param name name of the XAtom to create. * @since 1.5
*/
public XAtom(String name, boolean autoIntern) { this(XToolkit.getDisplay(), name, autoIntern);
}
/** This constructor will create an instance of XAtom that is specified * by the predefined XAtom specified by u {@code latom} * * @param display X display to use. * @param atom a predefined XAtom. * @since 1.5
*/ public XAtom(long display, long atom) { this.atom = atom; this.display = display;
register();
}
/** This constructor will create the instance, * and if {@code autoIntern} is true intern a new XAtom that is specified * by the supplied name. * * @param display X display to use * @param name name of the XAtom to create. * @since 1.5
*/
/** * Creates uninitialized instance of
*/ public XAtom() {
}
/** Sets the window property for the specified window * @param window window id to use * @param str value to set to. * @since 1.5
*/ publicvoid setProperty(long window, String str) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try {
XlibWrapper.SetProperty(display,window,atom,str);
} finally {
XToolkit.awtUnlock();
}
}
/** * Sets UTF8_STRING type property. Explicitly converts str to UTF-8 byte sequence.
*/ publicvoid setPropertyUTF8(long window, String str) {
XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING"); /* like STRING but encoding is UTF-8 */ if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window); byte[] bdata = str.getBytes(UTF_8); if (bdata != null) {
setAtomData(window, XA_UTF8_STRING.atom, bdata);
}
}
/** * Sets STRING/8 type property. Explicitly converts str to Latin-1 byte sequence.
*/ publicvoid setProperty8(long window, String str) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window); byte[] bdata = str.getBytes(ISO_8859_1); if (bdata != null) {
setAtomData(window, XA_STRING, bdata);
}
}
/** Gets the window property for the specified window * @param window window id to use * @return string with the property. * @since 1.5
*/ public String getProperty(long window) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try { return XlibWrapper.GetProperty(display,window,atom);
} finally {
XToolkit.awtUnlock();
}
}
/* * Auxiliary function that returns the value of 'property' of type * 'property_type' on window 'window'. Format of the property must be 32.
*/ publiclong get32Property(long window, long property_type) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
WindowPropertyGetter getter = new WindowPropertyGetter(window, this, 0, 1, false, property_type); try { int status = getter.execute(); if (status != XConstants.Success || getter.getData() == 0) { return 0;
} if (getter.getActualType() != property_type || getter.getActualFormat() != 32) { return 0;
} returnNative.getCard32(getter.getData());
} finally {
getter.dispose();
}
}
/** * Returns value of property of type CARDINAL/32 of this window
*/ publiclong getCard32Property(XBaseWindow window) { return get32Property(window.getWindow(), XA_CARDINAL);
}
/** * Sets property of type CARDINAL on the window
*/ publicvoid setCard32Property(long window, long value) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try { Native.putCard32(XlibWrapper.larg1, value);
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
atom, XA_CARDINAL, 32, XConstants.PropModeReplace,
XlibWrapper.larg1, 1);
} finally {
XToolkit.awtUnlock();
}
}
/** * Sets property of type CARDINAL/32 on the window
*/ publicvoid setCard32Property(XBaseWindow window, long value) {
setCard32Property(window.getWindow(), value);
}
/** * Gets uninterpreted set of data from property and stores them in data_ptr. * Property type is the same as current atom, property is current atom. * Property format is 32. Property 'delete' is false. * Returns boolean if requested type, format, length match returned values * and returned data pointer is not null.
*/ publicboolean getAtomData(long window, long data_ptr, int length) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
WindowPropertyGetter getter = new WindowPropertyGetter(window, this, 0, (long)length, false, this); try { int status = getter.execute(); if (status != XConstants.Success || getter.getData() == 0) { returnfalse;
} if (getter.getActualType() != atom
|| getter.getActualFormat() != 32
|| getter.getNumberOfItems() != length
)
{ returnfalse;
}
XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize()); returntrue;
} finally {
getter.dispose();
}
}
/** * Gets uninterpreted set of data from property and stores them in data_ptr. * Property type is {@code type}, property is current atom. * Property format is 32. Property 'delete' is false. * Returns boolean if requested type, format, length match returned values * and returned data pointer is not null.
*/ publicboolean getAtomData(long window, long type, long data_ptr, int length) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
WindowPropertyGetter getter = new WindowPropertyGetter(window, this, 0, (long)length, false, type); try { int status = getter.execute(); if (status != XConstants.Success || getter.getData() == 0) { returnfalse;
} if (getter.getActualType() != type
|| getter.getActualFormat() != 32
|| getter.getNumberOfItems() != length
)
{ returnfalse;
}
XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize()); returntrue;
} finally {
getter.dispose();
}
}
/** * Sets uninterpreted set of data into property from data_ptr. * Property type is the same as current atom, property is current atom. * Property format is 32. Mode is PropModeReplace. length is a number * of items pointer by data_ptr.
*/ publicvoid setAtomData(long window, long data_ptr, int length) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try {
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
atom, atom, 32, XConstants.PropModeReplace,
data_ptr, length);
} finally {
XToolkit.awtUnlock();
}
}
/** * Sets uninterpreted set of data into property from data_ptr. * Property type is {@code type}, property is current atom. * Property format is 32. Mode is PropModeReplace. length is a number * of items pointer by data_ptr.
*/ publicvoid setAtomData(long window, long type, long data_ptr, int length) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try {
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
atom, type, 32, XConstants.PropModeReplace,
data_ptr, length);
} finally {
XToolkit.awtUnlock();
}
}
/** * Sets uninterpreted set of data into property from data_ptr. * Property type is {@code type}, property is current atom. * Property format is 8. Mode is PropModeReplace. length is a number * of bytes pointer by data_ptr.
*/ publicvoid setAtomData8(long window, long type, long data_ptr, int length) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try {
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
atom, type, 8, XConstants.PropModeReplace,
data_ptr, length);
} finally {
XToolkit.awtUnlock();
}
}
/** * Deletes property specified by this item on the window.
*/ publicvoid DeleteProperty(long window) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try {
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window, atom);
} finally {
XToolkit.awtUnlock();
}
}
/** * Deletes property specified by this item on the window.
*/ publicvoid DeleteProperty(XBaseWindow window) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window.getWindow());
XToolkit.awtLock(); try {
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
window.getWindow(), atom);
} finally {
XToolkit.awtUnlock();
}
}
/* * Auxiliary function that returns the value of 'property' of type * 'property_type' on window 'window'. Format of the property must be 8.
*/ publicbyte[] getByteArrayProperty(long window, long property_type) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
WindowPropertyGetter getter = new WindowPropertyGetter(window, this, 0, 0xFFFF, false, property_type); try { int status = getter.execute(); if (status != XConstants.Success || getter.getData() == 0) { returnnull;
} if (getter.getActualType() != property_type || getter.getActualFormat() != 8) { returnnull;
} byte[] res = XlibWrapper.getStringBytes(getter.getData()); return res;
} finally {
getter.dispose();
}
}
/* * Returns the value of property ATOM[]/32 as array of XAtom objects * @return array of atoms, array of length 0 if the atom list is empty * or has different format
*/
XAtom[] getAtomListProperty(long window) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
WindowPropertyGetter getter = new WindowPropertyGetter(window, this, 0, 0xFFFF, false, XA_ATOM); try { int status = getter.execute(); if (status != XConstants.Success || getter.getData() == 0) { return emptyList;
} if (getter.getActualType() != XA_ATOM || getter.getActualFormat() != 32) { return emptyList;
}
int count = getter.getNumberOfItems(); if (count == 0) { return emptyList;
} long list_atoms = getter.getData();
XAtom[] res = new XAtom[count]; for (int index = 0; index < count; index++) {
res[index] = XAtom.get(XAtom.getAtom(list_atoms+index*getAtomSize()));
} return res;
} finally {
getter.dispose();
}
}
/* * Returns the value of property of type ATOM[]/32 as XAtomList * @return list of atoms, empty list if the atom list is empty * or has different format
*/
XAtomList getAtomListPropertyList(long window) { returnnew XAtomList(getAtomListProperty(window));
}
XAtomList getAtomListPropertyList(XBaseWindow window) { return getAtomListPropertyList(window.getWindow());
}
XAtom[] getAtomListProperty(XBaseWindow window) { return getAtomListProperty(window.getWindow());
}
/** * Sets property value of type ATOM list to the list of atoms.
*/ void setAtomListProperty(long window, XAtom[] atoms) { long data = toData(atoms);
setAtomData(window, XAtom.XA_ATOM, data, atoms.length);
unsafe.freeMemory(data);
}
/** * Sets property value of type ATOM list to the list of atoms specified by XAtomList
*/ void setAtomListProperty(long window, XAtomList atoms) { long data = atoms.getAtomsData();
setAtomData(window, XAtom.XA_ATOM, data, atoms.size());
unsafe.freeMemory(data);
} /** * Sets property value of type ATOM list to the list of atoms.
*/ publicvoid setAtomListProperty(XBaseWindow window, XAtom[] atoms) {
setAtomListProperty(window.getWindow(), atoms);
}
/** * Sets property value of type ATOM list to the list of atoms specified by XAtomList
*/ publicvoid setAtomListProperty(XBaseWindow window, XAtomList atoms) {
setAtomListProperty(window.getWindow(), atoms);
}
staticlong getAtom(long ptr) { returnNative.getLong(ptr);
} /** * Allocated memory to hold the list of native atom data and returns unsafe pointer to it * Caller should free the memory by himself.
*/ staticlong toData(XAtom[] atoms) { long data = unsafe.allocateMemory(getAtomSize() * atoms.length); for (int i = 0; i < atoms.length; i++ ) { if (atoms[i] != null) {
atoms[i].putAtom(data + i * getAtomSize());
}
} return data;
}
void checkWindow(long window) { if (window == 0) { thrownew IllegalArgumentException("Window must not be zero");
}
}
/** * Sets property on the {@code window} to the value {@code window_value} * Property is assumed to be of type WINDOW/32
*/ publicvoid setWindowProperty(long window, long window_value) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
XToolkit.awtLock(); try { Native.putWindow(XlibWrapper.larg1, window_value);
XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
atom, XA_WINDOW, 32, XConstants.PropModeReplace,
XlibWrapper.larg1, 1);
} finally {
XToolkit.awtUnlock();
}
} publicvoid setWindowProperty(XBaseWindow window, XBaseWindow window_value) {
setWindowProperty(window.getWindow(), window_value.getWindow());
}
/** * Gets property on the {@code window}. Property is assumed to be * of type WINDOW/32.
*/ publiclong getWindowProperty(long window) { if (atom == 0) { thrownew IllegalStateException("Atom should be initialized");
}
checkWindow(window);
WindowPropertyGetter getter = new WindowPropertyGetter(window, this, 0, 1, false, XA_WINDOW); try { int status = getter.execute(); if (status != XConstants.Success || getter.getData() == 0) { return 0;
} if (getter.getActualType() != XA_WINDOW || getter.getActualFormat() != 32) { return 0;
} returnNative.getWindow(getter.getData());
} finally {
getter.dispose();
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.