diff --git a/CHANGES.md b/CHANGES.md index 59f3b284d2..9af3bfa356 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -54,6 +54,7 @@ Features * [#649](https://github.com/java-native-access/jna/pull/649): Bugfix msoffice sample and add two samples taken from MSDN and translated from VisualBasic to Java - [@matthiasblaesing](https://github.com/matthiasblaesing). * [#654](https://github.com/java-native-access/jna/pull/654): Support named arguments for `com.sun.jna.platform.win32.COM.util.CallbackProxy` based callbacks - [@matthiasblaesing](https://github.com/matthiasblaesing). * [#659](https://github.com/java-native-access/jna/issues/659): Enable LCID (locale) override for `com.sun.jna.platform.win32.COM.util.ProxyObject`-based COM calls - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#665](https://github.com/java-native-access/jna/pull/665): Added `XSetWMProtocols` and `XGetWMProtocols` to `com.sun.jna.platform.unix.X11` - [@zainab-ali](https://github.com/zainab-ali). Bug Fixes --------- diff --git a/contrib/platform/src/com/sun/jna/platform/unix/X11.java b/contrib/platform/src/com/sun/jna/platform/unix/X11.java index 1b2e3cea1b..43c883f190 100644 --- a/contrib/platform/src/com/sun/jna/platform/unix/X11.java +++ b/contrib/platform/src/com/sun/jna/platform/unix/X11.java @@ -795,6 +795,10 @@ void XSetWMProperties(Display display, Window window, String window_name, String icon_name, String[] argv, int argc, XSizeHints normal_hints, Pointer wm_hints, Pointer class_hints); + + int XSetWMProtocols(Display display, Window window, Atom[] atom, int count); + int XGetWMProtocols(Display display, Window w, PointerByReference protocols_return, IntByReference count_return); + int XFree(Pointer data); Window XCreateSimpleWindow(Display display, Window parent, int x, int y, int width, int height, int border_width, diff --git a/contrib/platform/test/com/sun/jna/platform/unix/X11Test.java b/contrib/platform/test/com/sun/jna/platform/unix/X11Test.java index 30d1dc466e..9b367172c9 100644 --- a/contrib/platform/test/com/sun/jna/platform/unix/X11Test.java +++ b/contrib/platform/test/com/sun/jna/platform/unix/X11Test.java @@ -15,8 +15,10 @@ import java.awt.GraphicsEnvironment; import com.sun.jna.ptr.PointerByReference; +import com.sun.jna.ptr.IntByReference; import junit.framework.TestCase; +import org.junit.Assert; /** * Exercise the {@link X11} class. @@ -76,6 +78,32 @@ public void testXFetchName() { } } + public void testXSetWMProtocols() { + X11.Atom[] atoms = new X11.Atom[]{ X11.INSTANCE.XInternAtom(display, "WM_DELETE_WINDOW", false), X11.INSTANCE.XInternAtom(display, "WM_TAKE_FOCUS", false) }; + int status = X11.INSTANCE.XSetWMProtocols(display, root, atoms, atoms.length); + Assert.assertNotEquals("Bad status for XSetWMProtocols", 0, status); + } + + public void testXGetWMProtocols() { + X11.Atom[] sentAtoms = new X11.Atom[]{ X11.INSTANCE.XInternAtom(display, "WM_DELETE_WINDOW", false), X11.INSTANCE.XInternAtom(display, "WM_TAKE_FOCUS", false) }; + X11.INSTANCE.XSetWMProtocols(display, root, sentAtoms, sentAtoms.length); + + PointerByReference protocols = new PointerByReference(); + IntByReference count = new IntByReference(); + + int status = X11.INSTANCE.XGetWMProtocols(display, root, protocols, count); + + X11.Atom[] receivedAtoms = new X11.Atom[count.getValue()]; + for(int i = count.getValue() - 1; i >= 0; i--) { + receivedAtoms[i] = new X11.Atom(protocols.getValue().getLong(X11.Atom.SIZE * i)); + } + X11.INSTANCE.XFree(protocols.getValue()); + + Assert.assertNotEquals("Bad status for XGetWMProtocols", 0, status); + Assert.assertEquals("Wrong number of protocols returned for XGetWMProtocols", sentAtoms.length, receivedAtoms.length); + Assert.assertArrayEquals("Sent protocols were not equal to returned procols for XGetWMProtocols", sentAtoms, receivedAtoms); + } + public static void main(java.lang.String[] argList) { junit.textui.TestRunner.run(X11Test.class); }