Skip to content

Commit

Permalink
Adding XSetWMProtocols and XGetWMProtocols method to X11 (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
zainab-ali authored and matthiasblaesing committed Jun 13, 2016
1 parent f4b6d92 commit 3a803b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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);
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

0 comments on commit 3a803b7

Please sign in to comment.