Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding XSetWMProtocols method to X11 #665

Merged
merged 13 commits into from
Jun 13, 2016
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
4 changes: 4 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/unix/X11.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

@matthiasblaesing matthiasblaesing May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice to have: Should the XGetWMProtocols function also directly implemented (looks a bit more symmetrical :-))?

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,
Expand Down
28 changes: 28 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/unix/X11Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down