From 14817b2b3de3e959a60aee52794894ddba07c8a7 Mon Sep 17 00:00:00 2001 From: John Mercier Date: Wed, 3 Jul 2024 22:16:29 -0400 Subject: [PATCH] Fixing several issues that make the projects unusable. * Fixing XAuthority when parsing number * switched back to junixsocket as jdk does not support sockets only SocketChannel * Fixing usage of io.freefair.lombok in protocol projects. The module-path was not being set on the delombok task * fixing delombok by removing lombok from projects using junixsocket. Delombok does not support mutli-release jar files. * Switched back to junixsocket --- .idea/compiler.xml | 13 -- .idea/modules.xml | 8 +- .idea/modules/examples/x11.examples.main.iml | 8 - .../x11-client/x11.x11-client.main.iml | 8 - .../x11-client/x11.x11-client.test.iml | 8 - .../x11-keysym/x11.x11-keysym.main.iml | 8 - ...11.x11-protocol.x11-protocol-core.test.iml | 8 + ....x11-protocol.x11-protocol-xproto.test.iml | 8 + .../x11-toolkit/x11.x11-toolkit.main.iml | 8 - .../xephyr-runner/x11.xephyr-runner.main.iml | 8 - README.md | 12 +- build.gradle | 7 +- .../moaxcp/x11/examples/KeySymMain.java | 9 +- .../moaxcp/x11/examples/QueryVersion.java | 5 +- .../github/moaxcp/x11/examples/Record.java | 10 +- .../github/moaxcp/x11/examples/RecordApi.java | 8 +- .../x11/examples/RecordApiClientTracker.java | 80 +++++---- examples/src/main/java/module-info.java | 2 - x11-client/build.gradle | 1 + .../x11client/ConnectionFailureException.java | 10 +- .../x11/x11client/ResourceIdService.java | 7 +- .../moaxcp/x11/x11client/X11Client.java | 5 +- .../x11/x11client/X11ClientException.java | 10 +- .../moaxcp/x11/x11client/X11Connection.java | 85 ++++----- .../x11/x11client/XProtocolService.java | 58 +++--- .../x11/x11client/api/record/RecordApi.java | 6 +- .../x11/x11client/api/record/RecordData.java | 115 +++++++++++- .../api/record/RecordDataParser.java | 47 ++++- .../x11/x11client/api/record/RecordReply.java | 170 ++++++++++++++++-- .../api/record/ReplySequenceTracker.java | 42 ++++- x11-client/src/main/java/module-info.java | 3 +- .../ResourceIdServiceConstructor.java | 2 +- .../x11/x11client/X11ClientExceptionTest.java | 9 +- .../x11/x11client/X11ConnectionTest.java | 25 +-- x11-protocol/build.gradle | 8 + x11-protocol/x11-protocol-core/build.gradle | 3 + .../src/main/java/module-info.java | 2 + .../moaxcp/x11/protocol/AtomValueTest.java | 0 .../moaxcp/x11/protocol/DisplayNameTest.java | 0 .../moaxcp/x11/protocol/IntValueTest.java | 0 .../x11/protocol/ParametersCheckTest.java | 3 +- .../moaxcp/x11/protocol/PopcountTest.java | 0 .../moaxcp/x11/protocol/UtilitesTest.java | 12 +- .../x11/protocol/X11InputStreamTest.java | 0 .../x11/protocol/X11OutputStreamTest.java | 15 +- .../x11/protocol/XAuthorityFamilyTest.java | 13 +- .../moaxcp/x11/protocol/XAuthorityTest.java | 10 +- x11-protocol/x11-protocol-xproto/build.gradle | 3 + .../protocol/xproto/ChangePropertyTest.java | 3 +- .../xproto/ClientMessageData16Test.java | 0 .../xproto/ClientMessageData32Test.java | 0 .../xproto/ClientMessageData8Test.java | 0 .../x11/protocol/xproto/CreateWindowTest.java | 1 - .../x11/protocol/xproto/EventMaskTest.java | 0 .../xproto/GetKeyboardMappingRequestTest.java | 14 +- .../xproto/QueryExtensionRequestTest.java | 6 +- .../xproto/ReadWriteTestsPrototype.java | 0 x11-toolkit/build.gradle | 2 + .../github/moaxcp/x11/toolkit/Drawable.java | 27 ++- .../moaxcp/x11/toolkit/GraphicsContext.java | 48 +++-- .../github/moaxcp/x11/toolkit/Resource.java | 7 +- .../com/github/moaxcp/x11/toolkit/Window.java | 80 ++++++--- x11-toolkit/src/main/java/module-info.java | 1 - .../moaxcp/x11/xephyr/XephyrRunner.java | 136 +++++++++++--- xephyr-runner/src/main/java/module-info.java | 2 - 65 files changed, 828 insertions(+), 381 deletions(-) delete mode 100644 .idea/modules/examples/x11.examples.main.iml delete mode 100644 .idea/modules/x11-client/x11.x11-client.main.iml delete mode 100644 .idea/modules/x11-client/x11.x11-client.test.iml delete mode 100644 .idea/modules/x11-keysym/x11.x11-keysym.main.iml create mode 100644 .idea/modules/x11-protocol/x11-protocol-core/x11.x11-protocol.x11-protocol-core.test.iml create mode 100644 .idea/modules/x11-protocol/x11-protocol-xproto/x11.x11-protocol.x11-protocol-xproto.test.iml delete mode 100644 .idea/modules/x11-toolkit/x11.x11-toolkit.main.iml delete mode 100644 .idea/modules/xephyr-runner/x11.xephyr-runner.main.iml rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/AtomValueTest.java (100%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/DisplayNameTest.java (100%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/IntValueTest.java (100%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java (99%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/PopcountTest.java (100%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java (82%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/X11InputStreamTest.java (100%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java (90%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java (67%) rename {x11-client => x11-protocol/x11-protocol-core}/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java (95%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java (99%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData16Test.java (100%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData32Test.java (100%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData8Test.java (100%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java (97%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/EventMaskTest.java (100%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java (70%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java (91%) rename {x11-client => x11-protocol/x11-protocol-xproto}/src/test/java/com/github/moaxcp/x11/protocol/xproto/ReadWriteTestsPrototype.java (100%) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index d2471dff..2a401470 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -8,20 +8,16 @@ - - - - @@ -33,7 +29,6 @@ - @@ -51,17 +46,13 @@ - - - - @@ -69,12 +60,9 @@ - - - @@ -82,7 +70,6 @@ - diff --git a/.idea/modules.xml b/.idea/modules.xml index d0bb7e91..921731fa 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,14 +2,11 @@ - - - - + @@ -35,12 +32,11 @@ + - - \ No newline at end of file diff --git a/.idea/modules/examples/x11.examples.main.iml b/.idea/modules/examples/x11.examples.main.iml deleted file mode 100644 index 6ead6de8..00000000 --- a/.idea/modules/examples/x11.examples.main.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/x11-client/x11.x11-client.main.iml b/.idea/modules/x11-client/x11.x11-client.main.iml deleted file mode 100644 index c63ff3fd..00000000 --- a/.idea/modules/x11-client/x11.x11-client.main.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/x11-client/x11.x11-client.test.iml b/.idea/modules/x11-client/x11.x11-client.test.iml deleted file mode 100644 index b2a1ae0d..00000000 --- a/.idea/modules/x11-client/x11.x11-client.test.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/x11-keysym/x11.x11-keysym.main.iml b/.idea/modules/x11-keysym/x11.x11-keysym.main.iml deleted file mode 100644 index 334f8db7..00000000 --- a/.idea/modules/x11-keysym/x11.x11-keysym.main.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/x11-protocol/x11-protocol-core/x11.x11-protocol.x11-protocol-core.test.iml b/.idea/modules/x11-protocol/x11-protocol-core/x11.x11-protocol.x11-protocol-core.test.iml new file mode 100644 index 00000000..088bd045 --- /dev/null +++ b/.idea/modules/x11-protocol/x11-protocol-core/x11.x11-protocol.x11-protocol-core.test.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/x11-protocol/x11-protocol-xproto/x11.x11-protocol.x11-protocol-xproto.test.iml b/.idea/modules/x11-protocol/x11-protocol-xproto/x11.x11-protocol.x11-protocol-xproto.test.iml new file mode 100644 index 00000000..17f28536 --- /dev/null +++ b/.idea/modules/x11-protocol/x11-protocol-xproto/x11.x11-protocol.x11-protocol-xproto.test.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/x11-toolkit/x11.x11-toolkit.main.iml b/.idea/modules/x11-toolkit/x11.x11-toolkit.main.iml deleted file mode 100644 index c4d00f18..00000000 --- a/.idea/modules/x11-toolkit/x11.x11-toolkit.main.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/xephyr-runner/x11.xephyr-runner.main.iml b/.idea/modules/xephyr-runner/x11.xephyr-runner.main.iml deleted file mode 100644 index 5fca8a4d..00000000 --- a/.idea/modules/xephyr-runner/x11.xephyr-runner.main.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 348e5a3e..2c0384dd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The x11-client library can be added to your project using maven or gradle. com.github.moaxcp.x11 x11-client - 0.18.1 + 0.18.2 module ``` @@ -31,7 +31,7 @@ The x11-client library can be added to your project using maven or gradle. ## Gradle ``` -implementation 'com.github.moaxcp.x11:x11-client:0.18.1' +implementation 'com.github.moaxcp.x11:x11-client:0.18.2' ``` # Usage @@ -435,6 +435,14 @@ https://www.x.org/releases/X11R7.6/doc/libXtst/recordlib.html # versions +## 0.18.2 + +* Fixing XAuthority when parsing number +* switched back to junixsocket as jdk does not support sockets only SocketChannel +* Fixing usage of io.freefair.lombok in protocol projects. The module-path was not being set on the delombok task +* fixing delombok by removing lombok from projects using junixsocket. Delombok does not support mutli-release jar files. +* Switched back to junixsocket + ## 0.18.1 * fixing delombok task so javadoc works again and the project can be published to maven central diff --git a/build.gradle b/build.gradle index a980c0fa..f8a672cb 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } allprojects { - version = '0.18.1' + version = '0.18.2' group = 'com.github.moaxcp.x11' repositories { mavenCentral() @@ -18,7 +18,6 @@ allprojects { subprojects { apply plugin: 'java-library' - apply plugin: 'io.freefair.lombok' java { sourceCompatibility = JavaVersion.VERSION_21 @@ -27,10 +26,6 @@ subprojects { withJavadocJar() } - delombok { - modulePath = classpath - } - dependencies { } diff --git a/examples/src/main/java/com/github/moaxcp/x11/examples/KeySymMain.java b/examples/src/main/java/com/github/moaxcp/x11/examples/KeySymMain.java index 348e35ab..d2db15a2 100644 --- a/examples/src/main/java/com/github/moaxcp/x11/examples/KeySymMain.java +++ b/examples/src/main/java/com/github/moaxcp/x11/examples/KeySymMain.java @@ -2,18 +2,19 @@ import com.github.moaxcp.x11.keysym.KeySym; import com.github.moaxcp.x11.x11client.X11Client; -import lombok.extern.java.Log; import java.io.IOException; import java.util.List; +import java.util.logging.Logger; -@Log public class KeySymMain { + private static final Logger log = Logger.getLogger(KeySymMain.class.getName()); + public static void main(String... args) throws IOException { - try(X11Client client = X11Client.connect()) { + try (X11Client client = X11Client.connect()) { List keyCodes = client.keySymToKeyCodes(KeySym.XK_Escape); - for(byte keyCode : keyCodes) { + for (byte keyCode : keyCodes) { KeySym keySym = client.keyCodeToKeySym(keyCode, (short) 0); log.info(keySym.toString()); } diff --git a/examples/src/main/java/com/github/moaxcp/x11/examples/QueryVersion.java b/examples/src/main/java/com/github/moaxcp/x11/examples/QueryVersion.java index 4953cab1..8e6d3e7d 100644 --- a/examples/src/main/java/com/github/moaxcp/x11/examples/QueryVersion.java +++ b/examples/src/main/java/com/github/moaxcp/x11/examples/QueryVersion.java @@ -2,13 +2,14 @@ import com.github.moaxcp.x11.protocol.record.QueryVersionReply; import com.github.moaxcp.x11.x11client.X11Client; -import lombok.extern.java.Log; import java.io.IOException; +import java.util.logging.Logger; -@Log public class QueryVersion { + private static final Logger log = Logger.getLogger(QueryVersion.class.getName()); + public static void main(String... args) throws IOException { try (X11Client client = X11Client.connect()) { com.github.moaxcp.x11.protocol.record.QueryVersion queryVersion = com.github.moaxcp.x11.protocol.record.QueryVersion.builder().majorVersion((short) 1).minorVersion((short) 13).build(); diff --git a/examples/src/main/java/com/github/moaxcp/x11/examples/Record.java b/examples/src/main/java/com/github/moaxcp/x11/examples/Record.java index 23254ffb..68f4af2c 100644 --- a/examples/src/main/java/com/github/moaxcp/x11/examples/Record.java +++ b/examples/src/main/java/com/github/moaxcp/x11/examples/Record.java @@ -6,17 +6,19 @@ import com.github.moaxcp.x11.protocol.xproto.KeyPressEvent; import com.github.moaxcp.x11.protocol.xproto.MotionNotifyEvent; import com.github.moaxcp.x11.x11client.X11Client; -import lombok.extern.java.Log; import java.io.IOException; import java.util.Collections; +import java.util.logging.Logger; import static com.github.moaxcp.x11.protocol.Utilities.toX11Input; -@Log public class Record { + private static final Logger log = Logger.getLogger(Record.class.getName()); + /** * Tests with only standard device events and directly parses the data + * * @throws IOException */ public static void main(String... args) throws IOException { @@ -60,7 +62,7 @@ public static void main(String... args) throws IOException { log.info(String.format("enableContextReply: %s", enableContextReply)); - while(true) { + while (true) { EnableContextReply reply = data.getNextReply(enableContext.getReplyFunction()); log.info(String.format("Next reply: %s", reply)); XEvent replyData = data.readEvent(toX11Input(reply.getData())); @@ -69,7 +71,7 @@ public static void main(String... args) throws IOException { if (replyData instanceof KeyPressEvent) { KeyPressEvent e = (KeyPressEvent) replyData; KeySym keysym = data.keyCodeToKeySym(e); - if(keysym == KeySym.XK_Escape) { + if (keysym == KeySym.XK_Escape) { break; } } diff --git a/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApi.java b/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApi.java index e878b08a..fa81593b 100644 --- a/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApi.java +++ b/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApi.java @@ -7,17 +7,19 @@ import com.github.moaxcp.x11.x11client.X11Client; import com.github.moaxcp.x11.x11client.api.record.RecordData; import com.github.moaxcp.x11.x11client.api.record.RecordReply; -import lombok.extern.java.Log; import java.io.IOException; import java.util.Collections; import java.util.Optional; +import java.util.logging.Logger; -@Log public class RecordApi { + private static final Logger log = Logger.getLogger(RecordApi.class.getName()); + /** * Tests all xproto events including generic events. Also tests errors. + * * @throws IOException */ public static void main(String... args) throws IOException { @@ -65,7 +67,7 @@ public static void main(String... args) throws IOException { .context(rc) .build(); data.send(enableContext); - while(true) { + while (true) { RecordReply recordReply = data.record().readNextRecord(); log.info(String.format("%s", recordReply)); Optional first = recordReply.getData().stream() diff --git a/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApiClientTracker.java b/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApiClientTracker.java index 97fa3e80..d415ce9d 100644 --- a/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApiClientTracker.java +++ b/examples/src/main/java/com/github/moaxcp/x11/examples/RecordApiClientTracker.java @@ -9,18 +9,20 @@ import com.github.moaxcp.x11.x11client.X11Client; import com.github.moaxcp.x11.x11client.api.record.RecordData; import com.github.moaxcp.x11.x11client.api.record.RecordReply; -import lombok.extern.java.Log; import java.io.IOException; import java.util.Collections; import java.util.Optional; +import java.util.logging.Logger; -@Log public class RecordApiClientTracker { + private static final Logger log = Logger.getLogger(RecordApiClientTracker.class.getName()); + /** * Attempts to read requests and replies but fails + * * @throws IOException */ public static void main(String... args) throws IOException { @@ -28,36 +30,36 @@ public static void main(String... args) throws IOException { int rc = control.nextResourceId(); Range8 empty = Range8.builder().build(); ExtRange emptyExtRange = ExtRange.builder() - .major(empty) - .minor(Range16.builder().build()) - .build(); + .major(empty) + .minor(Range16.builder().build()) + .build(); Range range = Range.builder() - .deviceEvents(Range8.builder().first(KeyPressEvent.NUMBER).last(GeGenericEvent.NUMBER).build()) - //.coreRequests(empty) - //requests partially work except there are errors PutImage and a majorOpcode of -1 - .coreRequests(Range8.builder().first(CreateWindow.OPCODE).last(NoOperation.OPCODE).build()) - .coreReplies(empty) - //replies do not work. There is an issue with matching a sequence number with the sequence number of the reply - //.coreReplies(Range8.builder().first(CreateWindow.OPCODE).last(NoOperation.OPCODE).build()) - .extRequests(emptyExtRange) - .extReplies(emptyExtRange) - .deliveredEvents(empty) - //doesn't accept any value? - //.deliveredEvents(Range8.builder().first((byte) 0).last((byte) 1).build()) - .clientStarted(true) - .errors(Range8.builder() - .first((byte) 1) - .last((byte) 17) - .build()) - .clientDied(true) - .build(); + .deviceEvents(Range8.builder().first(KeyPressEvent.NUMBER).last(GeGenericEvent.NUMBER).build()) + //.coreRequests(empty) + //requests partially work except there are errors PutImage and a majorOpcode of -1 + .coreRequests(Range8.builder().first(CreateWindow.OPCODE).last(NoOperation.OPCODE).build()) + .coreReplies(empty) + //replies do not work. There is an issue with matching a sequence number with the sequence number of the reply + //.coreReplies(Range8.builder().first(CreateWindow.OPCODE).last(NoOperation.OPCODE).build()) + .extRequests(emptyExtRange) + .extReplies(emptyExtRange) + .deliveredEvents(empty) + //doesn't accept any value? + //.deliveredEvents(Range8.builder().first((byte) 0).last((byte) 1).build()) + .clientStarted(true) + .errors(Range8.builder() + .first((byte) 1) + .last((byte) 17) + .build()) + .clientDied(true) + .build(); CreateContext createContext = CreateContext.builder() - .context(rc) - .clientSpecs(Collections.singletonList(Cs.ALL_CLIENTS.getValue())) - .elementHeaderEnable(HType.FROM_CLIENT_SEQUENCE) - .ranges(Collections.singletonList(range)) - .build(); + .context(rc) + .clientSpecs(Collections.singletonList(Cs.ALL_CLIENTS.getValue())) + .elementHeaderEnable(HType.FROM_CLIENT_SEQUENCE) + .ranges(Collections.singletonList(range)) + .build(); control.send(createContext); @@ -65,20 +67,20 @@ public static void main(String... args) throws IOException { try (X11Client data = X11Client.connect()) { EnableContext enableContext = EnableContext - .builder() - .context(rc) - .build(); + .builder() + .context(rc) + .build(); data.send(enableContext); - while(true) { + while (true) { RecordReply recordReply = data.record().readNextRecord(); log.info(String.format("%s", recordReply)); Optional first = recordReply.getData().stream() - .map(RecordData::getXObject) - .filter(obj -> obj instanceof KeyPressEvent) - .map(KeyPressEvent.class::cast) - .map(data::keyCodeToKeySym) - .filter(keySym -> keySym == KeySym.XK_Escape) - .findFirst(); + .map(RecordData::getXObject) + .filter(obj -> obj instanceof KeyPressEvent) + .map(KeyPressEvent.class::cast) + .map(data::keyCodeToKeySym) + .filter(keySym -> keySym == KeySym.XK_Escape) + .findFirst(); if (first.isPresent()) { break; } diff --git a/examples/src/main/java/module-info.java b/examples/src/main/java/module-info.java index b6a5c618..dcee59e1 100644 --- a/examples/src/main/java/module-info.java +++ b/examples/src/main/java/module-info.java @@ -7,6 +7,4 @@ requires transitive com.github.moaxcp.x11.toolkit; requires transitive com.github.moaxcp.x11.keysym; requires transitive java.logging; - - requires static lombok; } \ No newline at end of file diff --git a/x11-client/build.gradle b/x11-client/build.gradle index 921b1510..a49d9bba 100644 --- a/x11-client/build.gradle +++ b/x11-client/build.gradle @@ -8,6 +8,7 @@ plugins { description = 'An x11 client implemented in java' dependencies { + api 'com.kohlschutter.junixsocket:junixsocket-core:2.10.0' api project(':x11-keysym') api project(':x11-protocol:x11-protocol-core') api project(':x11-protocol:x11-protocol-bigreq') diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ConnectionFailureException.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ConnectionFailureException.java index 7e586ce8..a3049591 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ConnectionFailureException.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ConnectionFailureException.java @@ -1,8 +1,6 @@ package com.github.moaxcp.x11.x11client; import com.github.moaxcp.x11.protocol.xproto.SetupFailed; -import lombok.Getter; -import lombok.NonNull; /** * An exception thrown when there is a failure response when connecting to the x11 server. @@ -11,15 +9,19 @@ public class ConnectionFailureException extends X11ClientException { /** * The failure info from the x11 server. non-null. */ - @Getter private final SetupFailed failure; /** * Creates a connection failure exception. + * * @param failure non-null failure information */ - ConnectionFailureException(@NonNull SetupFailed failure) { + ConnectionFailureException(SetupFailed failure) { super(failure.toString()); this.failure = failure; } + + public SetupFailed getFailure() { + return this.failure; + } } diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ResourceIdService.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ResourceIdService.java index bdb064aa..6fe1e7ce 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ResourceIdService.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/ResourceIdService.java @@ -2,7 +2,8 @@ import com.github.moaxcp.x11.protocol.xc_misc.GetXIDRange; import com.github.moaxcp.x11.protocol.xc_misc.GetXIDRangeReply; -import lombok.NonNull; + +import static java.util.Objects.requireNonNull; public class ResourceIdService { private int nextResourceId; @@ -15,8 +16,8 @@ public class ResourceIdService { private final XProtocolService protocolService; - public ResourceIdService(@NonNull XProtocolService protocolService, int resourceIdMask, int resourceIdBase) { - this.protocolService = protocolService; + public ResourceIdService(XProtocolService protocolService, int resourceIdMask, int resourceIdBase) { + this.protocolService = requireNonNull(protocolService, "protocolService"); this.resourceIdMask = resourceIdMask; this.resourceIdBase = resourceIdBase; this.nextResourceId = 1; diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Client.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Client.java index 09238196..68ed9d37 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Client.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Client.java @@ -4,7 +4,6 @@ import com.github.moaxcp.x11.protocol.*; import com.github.moaxcp.x11.protocol.xproto.*; import com.github.moaxcp.x11.x11client.api.record.RecordApi; -import lombok.NonNull; import java.io.IOException; import java.nio.ByteBuffer; @@ -50,7 +49,7 @@ public class X11Client implements AutoCloseable { * @return The connected client * @throws X11ClientException If connection to server could not be established */ - public static X11Client connect(@NonNull DisplayName displayName, @NonNull XAuthority xAuthority) { + public static X11Client connect(DisplayName displayName, XAuthority xAuthority) { try { return new X11Client(X11Connection.connect(displayName, xAuthority)); } catch (IOException e) { @@ -78,7 +77,7 @@ public static X11Client connect() { * @return the connected client * @throws X11ClientException If connection to server could not be established */ - public static X11Client connect(@NonNull DisplayName name) { + public static X11Client connect(DisplayName name) { try { return new X11Client(X11Connection.connect(name)); } catch (IOException e) { diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11ClientException.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11ClientException.java index 2a41965e..57ae23b0 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11ClientException.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11ClientException.java @@ -1,6 +1,6 @@ package com.github.moaxcp.x11.x11client; -import lombok.NonNull; +import static java.util.Objects.requireNonNull; /** * Thrown when there is a client exception. This could mean an IOException or unexpected results from the server. It is @@ -11,8 +11,8 @@ public class X11ClientException extends RuntimeException { * Creates an exception. * @param message of exception. non-null */ - X11ClientException(@NonNull String message) { - super(message); + X11ClientException(String message) { + super(requireNonNull(message, "message")); } /** @@ -20,7 +20,7 @@ public class X11ClientException extends RuntimeException { * @param message of exception. non-null * @param cause of exception. non-null */ - X11ClientException(@NonNull String message, @NonNull Throwable cause) { - super(message, cause); + X11ClientException(String message, Throwable cause) { + super(requireNonNull(message, "message"), requireNonNull(cause, "cause")); } } diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Connection.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Connection.java index 6480f7e7..4665d25d 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Connection.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/X11Connection.java @@ -5,26 +5,23 @@ import com.github.moaxcp.x11.protocol.xproto.SetupAuthenticate; import com.github.moaxcp.x11.protocol.xproto.SetupFailed; import com.github.moaxcp.x11.protocol.xproto.SetupRequest; -import lombok.Getter; -import lombok.NonNull; +import org.newsclub.net.unix.AFUNIXSocket; +import org.newsclub.net.unix.AFUNIXSocketAddress; import java.io.BufferedInputStream; +import java.io.File; import java.io.IOException; -import java.net.*; -import java.nio.channels.SocketChannel; +import java.net.InetAddress; +import java.net.Socket; import java.util.List; import java.util.Optional; +import static java.util.Objects.requireNonNull; + public class X11Connection implements AutoCloseable { - @Getter private final DisplayName displayName; - @Getter private final XAuthority xAuthority; - @Getter private final Setup setup; - - private final SocketChannel socketChannel; - private final Socket socket; private final X11InputStream in; private final X11OutputStream out; @@ -32,17 +29,17 @@ public class X11Connection implements AutoCloseable { /** * Creates an X11Connection with displayName and connects to x11 using the provided socket. The socket must match * information in the displayName. + * * @param displayName of x11 server - * @param socket for x11 server represented by displayName - * @throws ConnectionFailureException if server returns failure - * @throws NullPointerException if any parameter is null + * @param socket for x11 server represented by displayName + * @throws ConnectionFailureException if server returns failure + * @throws NullPointerException if any parameter is null * @throws UnsupportedOperationException if the connection code is authenticate or any other result */ - X11Connection(@NonNull DisplayName displayName, @NonNull XAuthority xAuthority, @NonNull SocketChannel socketChannel, @NonNull Socket socket) throws IOException { - this.displayName = displayName; - this.xAuthority = xAuthority; - this.socketChannel = socketChannel; - this.socket = socket; + X11Connection(DisplayName displayName, XAuthority xAuthority, Socket socket) throws IOException { + this.displayName = requireNonNull(displayName, "displayName"); + this.xAuthority = requireNonNull(xAuthority, "xAuthority"); + this.socket = requireNonNull(socket, "socket"); //using BufferedInputStream to support mark/reset in = new X11InputStream(new BufferedInputStream(socket.getInputStream(), 128)); out = new X11OutputStream(socket.getOutputStream()); @@ -50,7 +47,7 @@ public class X11Connection implements AutoCloseable { in.mark(1); byte result = in.readInt8(); in.reset(); - switch(result) { + switch (result) { case 0: //failure SetupFailed failure = SetupFailed.readSetupFailed(getX11Input()); throw new ConnectionFailureException(failure); @@ -65,6 +62,18 @@ public class X11Connection implements AutoCloseable { } } + public DisplayName getDisplayName() { + return this.displayName; + } + + public XAuthority getXAuthority() { + return this.xAuthority; + } + + public Setup getSetup() { + return this.setup; + } + public X11Input getX11Input() { return in; } @@ -91,55 +100,52 @@ public int getPort() { private void sendConnectionSetup() throws IOException { SetupRequest setup = SetupRequest.builder() - .byteOrder((byte) 'B') - .protocolMajorVersion((short) 11) - .protocolMinorVersion((short) 0) - .authorizationProtocolName(xAuthority.getProtocolName()) - .authorizationProtocolData(xAuthority.getProtocolData()) - .build(); + .byteOrder((byte) 'B') + .protocolMajorVersion((short) 11) + .protocolMinorVersion((short) 0) + .authorizationProtocolName(xAuthority.getProtocolName()) + .authorizationProtocolData(xAuthority.getProtocolData()) + .build(); setup.write(out); out.flush(); } /** * Creates an X11Connection with displayName. + * * @param displayName * @return * @throws NullPointerException if displayName is null. */ - public static X11Connection connect(@NonNull DisplayName displayName, @NonNull XAuthority xAuthority) throws IOException { + public static X11Connection connect(DisplayName displayName, XAuthority xAuthority) throws IOException { + requireNonNull(xAuthority, "xAuthority"); Socket socket; - SocketChannel socketChannel; if (displayName.isForUnixSocket()) { - var address = UnixDomainSocketAddress.of(displayName.getSocketFileName()); - socketChannel = SocketChannel.open(StandardProtocolFamily.UNIX); - socketChannel.connect(address); - socket = socketChannel.socket(); + AFUNIXSocketAddress address = AFUNIXSocketAddress.of(new File(displayName.getSocketFileName())); + socket = AFUNIXSocket.connectTo(address); } else { - var address = InetSocketAddress.createUnresolved(displayName.getHostName(), displayName.getPort()); - socketChannel = SocketChannel.open(StandardProtocolFamily.INET); - socketChannel.connect(address); - socket = socketChannel.socket(); + InetAddress address = InetAddress.getByName(displayName.getHostName()); + socket = new Socket(address, displayName.getPort()); } - return new X11Connection(displayName, xAuthority, socketChannel, socket); + return new X11Connection(displayName, xAuthority, socket); } public static X11Connection connect() throws IOException { DisplayName name = DisplayName.standard(); List authorities = XAuthority.getAuthorities(XAuthority.getXAuthorityFile()); Optional authority = XAuthority.getAuthority(authorities, name); - if(!authority.isPresent()) { + if (!authority.isPresent()) { throw new IllegalStateException("could not find authority for environment"); } return connect(name, authority.get()); } - public static X11Connection connect(@NonNull DisplayName name) throws IOException { + public static X11Connection connect(DisplayName name) throws IOException { List authorities = XAuthority.getAuthorities(XAuthority.getXAuthorityFile()); Optional authority = XAuthority.getAuthority(authorities, name); - if(!authority.isPresent()) { + if (!authority.isPresent()) { throw new IllegalStateException("could not find authority for environment"); } return connect(name, authority.get()); @@ -154,7 +160,6 @@ public void close() throws IOException { in.close(); } finally { socket.close(); - socketChannel.close(); } } } diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/XProtocolService.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/XProtocolService.java index abfddf2b..fefe2852 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/XProtocolService.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/XProtocolService.java @@ -4,7 +4,6 @@ import com.github.moaxcp.x11.protocol.bigreq.Enable; import com.github.moaxcp.x11.protocol.xproto.QueryExtension; import com.github.moaxcp.x11.protocol.xproto.Setup; -import lombok.Getter; import java.io.IOException; import java.util.LinkedList; @@ -17,11 +16,8 @@ public class XProtocolService { private final X11Input in; private final X11Output out; - @Getter private final Setup setup; - @Getter private int nextSequenceNumber = 1; - @Getter private long maximumRequestLength; private final Queue requests = new LinkedList<>(); private final Queue events = new LinkedList<>(); @@ -33,25 +29,37 @@ public XProtocolService(Setup setup, X11Input in, X11Output out) { this.setup = setup; maximumRequestLength = setup.getMaximumRequestLength(); pluginService = new ProtocolPluginService(); - for(String name : pluginService.listLoadedPlugins()) { + for (String name : pluginService.listLoadedPlugins()) { activatePlugin(name); } - if(pluginService.activatedPlugin("BIG-REQUESTS")) { + if (pluginService.activatedPlugin("BIG-REQUESTS")) { maximumRequestLength = Integer.toUnsignedLong(send(Enable.builder().build()) - .getMaximumRequestLength()); + .getMaximumRequestLength()); } } + public Setup getSetup() { + return this.setup; + } + + public int getNextSequenceNumber() { + return this.nextSequenceNumber; + } + + public long getMaximumRequestLength() { + return this.maximumRequestLength; + } + public boolean activatePlugin(String name) { return pluginService.loadedPlugin(name) - .flatMap(XProtocolPlugin::getExtensionXName) - .map(xName -> QueryExtension.builder() - .name(Utilities.toByteList(xName)) - .build()) - .map(this::send) - .map(reply -> reply.isPresent() && pluginService.activatePlugin(name, reply.getMajorOpcode(), reply.getFirstEvent(), reply.getFirstError())) - .orElse(false); + .flatMap(XProtocolPlugin::getExtensionXName) + .map(xName -> QueryExtension.builder() + .name(Utilities.toByteList(xName)) + .build()) + .map(this::send) + .map(reply -> reply.isPresent() && pluginService.activatePlugin(name, reply.getMajorOpcode(), reply.getFirstEvent(), reply.getFirstError())) + .orElse(false); } public boolean loadedPlugin(String name) { @@ -75,7 +83,7 @@ public void send(OneWayRequest request) { private void actuallySend(XRequest request) { try { request.write(getMajorOpcode(request), out); - } catch(IOException e) { + } catch (IOException e) { throw new X11ProtocolException("exception writing request \"" + request + "\"", e); } nextSequenceNumber++; @@ -86,7 +94,7 @@ public byte getMajorOpcode(XRequest request) { } public T readReply(XReplyFunction function) { - while(true) { + while (true) { try { byte responseCode = in.readByte(); if (responseCode == 0) { @@ -128,7 +136,7 @@ public T readError(X11Input in) { byte code = in.readCard8(); XProtocolPlugin plugin = pluginService.activePluginForError(code).orElseThrow(() -> new IllegalStateException(XProtocolPlugin.class.getSimpleName() + " not found for error code " + code)); return plugin.readError(code, in); - } catch(IOException e) { + } catch (IOException e) { throw new X11ProtocolException("could not read error", e); } } @@ -140,10 +148,10 @@ private T readEvent(byte responseCode) throws IOException { private T readEvent(X11Input in, byte responseCode) throws IOException { boolean sentEvent = responseCode < 0; byte number = !sentEvent ? responseCode : (byte) (responseCode ^ (byte) 0b10000000); - if(pluginService.genericEventNumber(number)) { + if (pluginService.genericEventNumber(number)) { byte extension = in.readCard8(); Optional pluginExtension = pluginService.activePluginForMajorOpcode(extension); - if(!pluginExtension.isPresent()) { + if (!pluginExtension.isPresent()) { throw new IllegalStateException("Could not find plugin for generic event with major-opcode of " + extension); } XProtocolPlugin plugin = pluginExtension.get(); @@ -154,31 +162,31 @@ private T readEvent(X11Input in, byte responseCode) throws IO return plugin.readGenericEvent(sentEvent, extension, sequenceNumber, length, eventType, in); } XProtocolPlugin plugin = pluginService.activePluginForEvent(number) - .orElseThrow(() -> new IllegalStateException(XProtocolPlugin.class.getSimpleName() + " not found for number " + number)); + .orElseThrow(() -> new IllegalStateException(XProtocolPlugin.class.getSimpleName() + " not found for number " + number)); return plugin.readEvent(number, sentEvent, in); } public T getNextEvent() { - if(!events.isEmpty()) { + if (!events.isEmpty()) { return (T) events.poll(); } flush(); try { byte responseCode = in.readByte(); - if(responseCode == 0) { + if (responseCode == 0) { throw new X11ErrorException(readError()); } - if(responseCode == 1) { + if (responseCode == 1) { throw new X11ProtocolException("reply not expected when reading events"); } return readEvent(responseCode); - } catch(IOException e) { + } catch (IOException e) { throw new X11ProtocolException("exception when reading event", e); } } public void flush() { - while(!requests.isEmpty()) { + while (!requests.isEmpty()) { XRequest request = requests.poll(); actuallySend(request); } diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordApi.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordApi.java index 2e8beeb8..9bd75d0f 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordApi.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordApi.java @@ -2,13 +2,15 @@ import com.github.moaxcp.x11.protocol.record.EnableContextReply; import com.github.moaxcp.x11.x11client.X11Client; -import lombok.AllArgsConstructor; -@AllArgsConstructor public class RecordApi { private final X11Client client; private final ReplySequenceTracker tracker = new ReplySequenceTracker(); + public RecordApi(X11Client client) { + this.client = client; + } + public RecordReply readNextRecord() { EnableContextReply reply = client.getNextReply(EnableContextReply::readEnableContextReply); RecordDataParser parser = new RecordDataParser(client, reply, tracker); diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordData.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordData.java index 437c8c1a..e4debd64 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordData.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordData.java @@ -1,18 +1,25 @@ package com.github.moaxcp.x11.x11client.api.record; import com.github.moaxcp.x11.protocol.XObject; -import lombok.Builder; -import lombok.Value; import java.util.Optional; -@Value -@Builder -public class RecordData { - Integer fromServerTime; - Integer fromClientTime; - Integer fromClientSequence; - XObject xObject; +public final class RecordData { + private final Integer fromServerTime; + private final Integer fromClientTime; + private final Integer fromClientSequence; + private final XObject xObject; + + RecordData(Integer fromServerTime, Integer fromClientTime, Integer fromClientSequence, XObject xObject) { + this.fromServerTime = fromServerTime; + this.fromClientTime = fromClientTime; + this.fromClientSequence = fromClientSequence; + this.xObject = xObject; + } + + public static RecordDataBuilder builder() { + return new RecordDataBuilder(); + } public Optional fromServerTime() { return Optional.ofNullable(fromServerTime); @@ -25,4 +32,94 @@ public Optional fromClientTime() { public Optional getFromClientSequence() { return Optional.ofNullable(fromClientSequence); } + + public Integer getFromServerTime() { + return this.fromServerTime; + } + + public Integer getFromClientTime() { + return this.fromClientTime; + } + + public XObject getXObject() { + return this.xObject; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof RecordData)) return false; + final RecordData other = (RecordData) o; + final Object this$fromServerTime = this.getFromServerTime(); + final Object other$fromServerTime = other.getFromServerTime(); + if (this$fromServerTime == null ? other$fromServerTime != null : !this$fromServerTime.equals(other$fromServerTime)) + return false; + final Object this$fromClientTime = this.getFromClientTime(); + final Object other$fromClientTime = other.getFromClientTime(); + if (this$fromClientTime == null ? other$fromClientTime != null : !this$fromClientTime.equals(other$fromClientTime)) + return false; + final Object this$fromClientSequence = this.getFromClientSequence(); + final Object other$fromClientSequence = other.getFromClientSequence(); + if (this$fromClientSequence == null ? other$fromClientSequence != null : !this$fromClientSequence.equals(other$fromClientSequence)) + return false; + final Object this$xObject = this.getXObject(); + final Object other$xObject = other.getXObject(); + if (this$xObject == null ? other$xObject != null : !this$xObject.equals(other$xObject)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $fromServerTime = this.getFromServerTime(); + result = result * PRIME + ($fromServerTime == null ? 43 : $fromServerTime.hashCode()); + final Object $fromClientTime = this.getFromClientTime(); + result = result * PRIME + ($fromClientTime == null ? 43 : $fromClientTime.hashCode()); + final Object $fromClientSequence = this.getFromClientSequence(); + result = result * PRIME + ($fromClientSequence == null ? 43 : $fromClientSequence.hashCode()); + final Object $xObject = this.getXObject(); + result = result * PRIME + ($xObject == null ? 43 : $xObject.hashCode()); + return result; + } + + public String toString() { + return "RecordData(fromServerTime=" + this.getFromServerTime() + ", fromClientTime=" + this.getFromClientTime() + ", fromClientSequence=" + this.getFromClientSequence() + ", xObject=" + this.getXObject() + ")"; + } + + public static class RecordDataBuilder { + private Integer fromServerTime; + private Integer fromClientTime; + private Integer fromClientSequence; + private XObject xObject; + + RecordDataBuilder() { + } + + public RecordDataBuilder fromServerTime(Integer fromServerTime) { + this.fromServerTime = fromServerTime; + return this; + } + + public RecordDataBuilder fromClientTime(Integer fromClientTime) { + this.fromClientTime = fromClientTime; + return this; + } + + public RecordDataBuilder fromClientSequence(Integer fromClientSequence) { + this.fromClientSequence = fromClientSequence; + return this; + } + + public RecordDataBuilder xObject(XObject xObject) { + this.xObject = xObject; + return this; + } + + public RecordData build() { + return new RecordData(this.fromServerTime, this.fromClientTime, this.fromClientSequence, this.xObject); + } + + public String toString() { + return "RecordData.RecordDataBuilder(fromServerTime=" + this.fromServerTime + ", fromClientTime=" + this.fromClientTime + ", fromClientSequence=" + this.fromClientSequence + ", xObject=" + this.xObject + ")"; + } + } } diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordDataParser.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordDataParser.java index 9109e064..631804df 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordDataParser.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordDataParser.java @@ -7,7 +7,6 @@ import com.github.moaxcp.x11.x11client.X11Client; import com.github.moaxcp.x11.x11client.api.record.RecordData.RecordDataBuilder; import com.github.moaxcp.x11.x11client.api.record.RecordReply.RecordReplyBuilder; -import lombok.Data; import java.io.EOFException; import java.io.IOException; @@ -106,16 +105,60 @@ private List readFromServer(boolean fromServerTime, boolean fromClie data.readByte(); builder.xObject(client.readError(data)); } else if (responseCode == 1) { - @Data class ReplyHeader implements X11InputConsumer { byte data; short sequence; + public ReplyHeader() { + } + @Override public void accept(X11Input in) throws IOException { data = in.readByte(); sequence = in.readCard16(); } + + public byte getData() { + return this.data; + } + + public short getSequence() { + return this.sequence; + } + + public void setData(byte data) { + this.data = data; + } + + public void setSequence(short sequence) { + this.sequence = sequence; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof ReplyHeader)) return false; + final ReplyHeader other = (ReplyHeader) o; + if (!other.canEqual((Object) this)) return false; + if (this.getData() != other.getData()) return false; + if (this.getSequence() != other.getSequence()) return false; + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof ReplyHeader; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.getData(); + result = result * PRIME + this.getSequence(); + return result; + } + + public String toString() { + return "ReplyHeader(data=" + this.getData() + ", sequence=" + this.getSequence() + ")"; + } } ReplyHeader replyHeader = new ReplyHeader(); data.peekWith(replyHeader); diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordReply.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordReply.java index 765ef480..3eab5a79 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordReply.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/RecordReply.java @@ -2,22 +2,33 @@ import com.github.moaxcp.x11.protocol.record.Category; import com.github.moaxcp.x11.protocol.record.HType; -import lombok.Builder; -import lombok.Value; import java.util.List; -@Value -@Builder -public class RecordReply { - Category category; - short sequenceNumber; - byte elementHeader; - boolean clientSwapped; - int xidBase; - int serverTime; - int recSequenceNum; - List data; +public final class RecordReply { + private final Category category; + private final short sequenceNumber; + private final byte elementHeader; + private final boolean clientSwapped; + private final int xidBase; + private final int serverTime; + private final int recSequenceNum; + private final List data; + + RecordReply(Category category, short sequenceNumber, byte elementHeader, boolean clientSwapped, int xidBase, int serverTime, int recSequenceNum, List data) { + this.category = category; + this.sequenceNumber = sequenceNumber; + this.elementHeader = elementHeader; + this.clientSwapped = clientSwapped; + this.xidBase = xidBase; + this.serverTime = serverTime; + this.recSequenceNum = recSequenceNum; + this.data = data; + } + + public static RecordReplyBuilder builder() { + return new RecordReplyBuilder(); + } public boolean getFromServerTime() { return HType.FROM_SERVER_TIME.isEnabled(elementHeader); @@ -30,4 +41,137 @@ public boolean getFromClientTime() { public boolean getFromClientSequence() { return HType.FROM_CLIENT_SEQUENCE.isEnabled(elementHeader); } + + public Category getCategory() { + return this.category; + } + + public short getSequenceNumber() { + return this.sequenceNumber; + } + + public byte getElementHeader() { + return this.elementHeader; + } + + public boolean isClientSwapped() { + return this.clientSwapped; + } + + public int getXidBase() { + return this.xidBase; + } + + public int getServerTime() { + return this.serverTime; + } + + public int getRecSequenceNum() { + return this.recSequenceNum; + } + + public List getData() { + return this.data; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof RecordReply)) return false; + final RecordReply other = (RecordReply) o; + final Object this$category = this.getCategory(); + final Object other$category = other.getCategory(); + if (this$category == null ? other$category != null : !this$category.equals(other$category)) return false; + if (this.getSequenceNumber() != other.getSequenceNumber()) return false; + if (this.getElementHeader() != other.getElementHeader()) return false; + if (this.isClientSwapped() != other.isClientSwapped()) return false; + if (this.getXidBase() != other.getXidBase()) return false; + if (this.getServerTime() != other.getServerTime()) return false; + if (this.getRecSequenceNum() != other.getRecSequenceNum()) return false; + final Object this$data = this.getData(); + final Object other$data = other.getData(); + if (this$data == null ? other$data != null : !this$data.equals(other$data)) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $category = this.getCategory(); + result = result * PRIME + ($category == null ? 43 : $category.hashCode()); + result = result * PRIME + this.getSequenceNumber(); + result = result * PRIME + this.getElementHeader(); + result = result * PRIME + (this.isClientSwapped() ? 79 : 97); + result = result * PRIME + this.getXidBase(); + result = result * PRIME + this.getServerTime(); + result = result * PRIME + this.getRecSequenceNum(); + final Object $data = this.getData(); + result = result * PRIME + ($data == null ? 43 : $data.hashCode()); + return result; + } + + public String toString() { + return "RecordReply(category=" + this.getCategory() + ", sequenceNumber=" + this.getSequenceNumber() + ", elementHeader=" + this.getElementHeader() + ", clientSwapped=" + this.isClientSwapped() + ", xidBase=" + this.getXidBase() + ", serverTime=" + this.getServerTime() + ", recSequenceNum=" + this.getRecSequenceNum() + ", data=" + this.getData() + ")"; + } + + public static class RecordReplyBuilder { + private Category category; + private short sequenceNumber; + private byte elementHeader; + private boolean clientSwapped; + private int xidBase; + private int serverTime; + private int recSequenceNum; + private List data; + + RecordReplyBuilder() { + } + + public RecordReplyBuilder category(Category category) { + this.category = category; + return this; + } + + public RecordReplyBuilder sequenceNumber(short sequenceNumber) { + this.sequenceNumber = sequenceNumber; + return this; + } + + public RecordReplyBuilder elementHeader(byte elementHeader) { + this.elementHeader = elementHeader; + return this; + } + + public RecordReplyBuilder clientSwapped(boolean clientSwapped) { + this.clientSwapped = clientSwapped; + return this; + } + + public RecordReplyBuilder xidBase(int xidBase) { + this.xidBase = xidBase; + return this; + } + + public RecordReplyBuilder serverTime(int serverTime) { + this.serverTime = serverTime; + return this; + } + + public RecordReplyBuilder recSequenceNum(int recSequenceNum) { + this.recSequenceNum = recSequenceNum; + return this; + } + + public RecordReplyBuilder data(List data) { + this.data = data; + return this; + } + + public RecordReply build() { + return new RecordReply(this.category, this.sequenceNumber, this.elementHeader, this.clientSwapped, this.xidBase, this.serverTime, this.recSequenceNum, this.data); + } + + public String toString() { + return "RecordReply.RecordReplyBuilder(category=" + this.category + ", sequenceNumber=" + this.sequenceNumber + ", elementHeader=" + this.elementHeader + ", clientSwapped=" + this.clientSwapped + ", xidBase=" + this.xidBase + ", serverTime=" + this.serverTime + ", recSequenceNum=" + this.recSequenceNum + ", data=" + this.data + ")"; + } + } } diff --git a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/ReplySequenceTracker.java b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/ReplySequenceTracker.java index b0bcd0b1..5e2ea574 100644 --- a/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/ReplySequenceTracker.java +++ b/x11-client/src/main/java/com/github/moaxcp/x11/x11client/api/record/ReplySequenceTracker.java @@ -2,16 +2,48 @@ import com.github.moaxcp.x11.protocol.XReply; import com.github.moaxcp.x11.protocol.XReplyFunction; -import lombok.Value; import java.util.HashMap; import java.util.Map; class ReplySequenceTracker { - @Value - private static class Key { - int xidBase; - short sequence; + private static final class Key { + private final int xidBase; + private final short sequence; + + public Key(int xidBase, short sequence) { + this.xidBase = xidBase; + this.sequence = sequence; + } + + public int getXidBase() { + return this.xidBase; + } + + public short getSequence() { + return this.sequence; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Key)) return false; + final Key other = (Key) o; + if (this.getXidBase() != other.getXidBase()) return false; + if (this.getSequence() != other.getSequence()) return false; + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.getXidBase(); + result = result * PRIME + this.getSequence(); + return result; + } + + public String toString() { + return "ReplySequenceTracker.Key(xidBase=" + this.getXidBase() + ", sequence=" + this.getSequence() + ")"; + } } private final Map> replyFunctions = new HashMap<>(); diff --git a/x11-client/src/main/java/module-info.java b/x11-client/src/main/java/module-info.java index 7ab193cb..df7c305a 100644 --- a/x11-client/src/main/java/module-info.java +++ b/x11-client/src/main/java/module-info.java @@ -9,5 +9,6 @@ requires transitive com.github.moaxcp.x11.protocol.record; requires transitive com.github.moaxcp.x11.protocol.xproto; requires transitive com.github.moaxcp.x11.protocol.xcmisc; - requires static lombok; + requires transitive org.newsclub.net.unix; + requires transitive com.kohlschutter.junixsocket.nativecommon; } \ No newline at end of file diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/x11client/ResourceIdServiceConstructor.java b/x11-client/src/test/java/com/github/moaxcp/x11/x11client/ResourceIdServiceConstructor.java index ca372ccb..d8fbe7f9 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/x11client/ResourceIdServiceConstructor.java +++ b/x11-client/src/test/java/com/github/moaxcp/x11/x11client/ResourceIdServiceConstructor.java @@ -10,7 +10,7 @@ public class ResourceIdServiceConstructor { @Test void constructor_nullService() { NullPointerException exception = assertThrows(NullPointerException.class, () -> new ResourceIdService(null, 0b011, 0b100)); - assertThat(exception).hasMessage("protocolService is marked non-null but is null"); + assertThat(exception).hasMessage("protocolService"); } @Test diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ClientExceptionTest.java b/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ClientExceptionTest.java index 649ece97..1138874d 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ClientExceptionTest.java +++ b/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ClientExceptionTest.java @@ -1,8 +1,9 @@ package com.github.moaxcp.x11.x11client; -import java.io.IOException; import org.junit.jupiter.api.Test; +import java.io.IOException; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -10,7 +11,7 @@ public class X11ClientExceptionTest { @Test void constructor_nullMessage() { NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11ClientException(null)); - assertThat(exception).hasMessage("message is marked non-null but is null"); + assertThat(exception).hasMessage("message"); } @Test @@ -22,13 +23,13 @@ void constructor_message() { @Test void constructor2_nullMessage() { NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11ClientException(null, null)); - assertThat(exception).hasMessage("message is marked non-null but is null"); + assertThat(exception).hasMessage("message"); } @Test void constructor2_nullCause() { NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11ClientException("message", null)); - assertThat(exception).hasMessage("cause is marked non-null but is null"); + assertThat(exception).hasMessage("cause"); } @Test diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ConnectionTest.java b/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ConnectionTest.java index b2ee5409..62b64898 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ConnectionTest.java +++ b/x11-client/src/test/java/com/github/moaxcp/x11/x11client/X11ConnectionTest.java @@ -10,15 +10,12 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.net.Socket; -import java.nio.channels.SocketChannel; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @ExtendWith(MockitoExtension.class) public class X11ConnectionTest { - @Mock - private SocketChannel socketChannel; @Mock private Socket socket; @@ -26,37 +23,31 @@ public class X11ConnectionTest { @Test void constructor_fails_on_null_displayName() { - NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(null, xAuthority, socketChannel, socket)); - assertThat(exception).hasMessage("displayName is marked non-null but is null"); + NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(null, xAuthority, socket)); + assertThat(exception).hasMessage("displayName"); } @Test void constructor_fails_on_null_xAuthority() { - NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(new DisplayName(":0"), null, socketChannel, socket)); - assertThat(exception).hasMessage("xAuthority is marked non-null but is null"); - } - - @Test - void constructor_fails_on_null_socketChannel() { - NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(new DisplayName(":0"), xAuthority, null, socket)); - assertThat(exception).hasMessage("socketChannel is marked non-null but is null"); + NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(new DisplayName(":0"), null, socket)); + assertThat(exception).hasMessage("xAuthority"); } @Test void constructor_fails_on_null_socket() { - NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(new DisplayName(":0"), xAuthority, socketChannel, null)); - assertThat(exception).hasMessage("socket is marked non-null but is null"); + NullPointerException exception = assertThrows(NullPointerException.class, () -> new X11Connection(new DisplayName(":0"), xAuthority, null)); + assertThat(exception).hasMessage("socket"); } @Test void connect_fails_on_null_displayName() { NullPointerException exception = assertThrows(NullPointerException.class, () -> X11Connection.connect(null, xAuthority)); - assertThat(exception).hasMessage("displayName is marked non-null but is null"); + assertThat(exception).hasMessage("Cannot invoke \"com.github.moaxcp.x11.protocol.DisplayName.isForUnixSocket()\" because \"displayName\" is null"); } @Test void connect_fails_on_null_xAuthority() { NullPointerException exception = assertThrows(NullPointerException.class, () -> X11Connection.connect(new DisplayName((":0")), null)); - assertThat(exception).hasMessage("xAuthority is marked non-null but is null"); + assertThat(exception).hasMessage("xAuthority"); } } diff --git a/x11-protocol/build.gradle b/x11-protocol/build.gradle index ac359cad..cb36e9a5 100644 --- a/x11-protocol/build.gradle +++ b/x11-protocol/build.gradle @@ -3,4 +3,12 @@ allprojects { repositories { mavenCentral() } +} + +subprojects { + apply plugin: 'io.freefair.lombok' + + delombok { + modulePath = classpath + } } \ No newline at end of file diff --git a/x11-protocol/x11-protocol-core/build.gradle b/x11-protocol/x11-protocol-core/build.gradle index d988b151..49603b89 100644 --- a/x11-protocol/x11-protocol-core/build.gradle +++ b/x11-protocol/x11-protocol-core/build.gradle @@ -13,6 +13,9 @@ java { } dependencies { + testImplementation 'org.mockito:mockito-core:3.3.3' + testImplementation 'org.mockito:mockito-junit-jupiter:3.3.3' + testImplementation 'org.assertj:assertj-core:3.16.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' } diff --git a/x11-protocol/x11-protocol-core/src/main/java/module-info.java b/x11-protocol/x11-protocol-core/src/main/java/module-info.java index 9cdfa929..bba36285 100644 --- a/x11-protocol/x11-protocol-core/src/main/java/module-info.java +++ b/x11-protocol/x11-protocol-core/src/main/java/module-info.java @@ -2,5 +2,7 @@ module com.github.moaxcp.x11.protocol.core { exports com.github.moaxcp.x11.protocol; + uses com.github.moaxcp.x11.protocol.XProtocolPlugin; + requires static lombok; } \ No newline at end of file diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/AtomValueTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/AtomValueTest.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/AtomValueTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/AtomValueTest.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/DisplayNameTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/DisplayNameTest.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/DisplayNameTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/DisplayNameTest.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/IntValueTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/IntValueTest.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/IntValueTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/IntValueTest.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java similarity index 99% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java index 69e6e794..25c56c7c 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java +++ b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/ParametersCheckTest.java @@ -1,8 +1,9 @@ package com.github.moaxcp.x11.protocol; -import java.util.List; import org.junit.jupiter.api.Test; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/PopcountTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/PopcountTest.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/PopcountTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/PopcountTest.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java similarity index 82% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java index 1ef8cf63..386f0f05 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java +++ b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/UtilitesTest.java @@ -13,7 +13,7 @@ public class UtilitesTest { @Test void toList_byte_fails_on_null() { - assertThatThrownBy(() -> Utilities.toList(null)) + Assertions.assertThatThrownBy(() -> Utilities.toList(null)) .isInstanceOf(NullPointerException.class) .hasMessage("bytes is marked non-null but is null"); } @@ -25,14 +25,14 @@ void toList_byte() { @Test void toString_fails_on_null_byteList() { - assertThatThrownBy(() -> Utilities.toString(null, Charset.defaultCharset())) + Assertions.assertThatThrownBy(() -> Utilities.toString(null, Charset.defaultCharset())) .isInstanceOf(NullPointerException.class) .hasMessage("byteList is marked non-null but is null"); } @Test void toString_fails_on_null_charSet() { - assertThatThrownBy(() -> Utilities.toString(new ArrayList<>(), null)) + Assertions.assertThatThrownBy(() -> Utilities.toString(new ArrayList<>(), null)) .isInstanceOf(NullPointerException.class) .hasMessage("charset is marked non-null but is null"); } @@ -46,12 +46,12 @@ void toString_test() { bytes.add((byte) 'l'); bytes.add((byte) 'o'); String result = Utilities.toString(bytes, Charset.defaultCharset()); - assertThat(result).isEqualTo("hello"); + Assertions.assertThat(result).isEqualTo("hello"); } @Test void toInteger_fails_on_null() { - assertThatThrownBy(() -> Utilities.toIntegers(null)) + Assertions.assertThatThrownBy(() -> Utilities.toIntegers(null)) .isInstanceOf(NullPointerException.class) .hasMessage("bytes is marked non-null but is null"); } @@ -60,7 +60,7 @@ void toInteger_fails_on_null() { void toInteger_fails_on_size() { List input = new ArrayList<>(); input.add((byte) 1); - assertThatThrownBy(() -> Utilities.toIntegers(input)) + Assertions.assertThatThrownBy(() -> Utilities.toIntegers(input)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("bytes must have size divisible by 4 to be converted to integers got: 1"); } diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/X11InputStreamTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/X11InputStreamTest.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/X11InputStreamTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/X11InputStreamTest.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java similarity index 90% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java index 48ae8e41..6d836d75 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java +++ b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/X11OutputStreamTest.java @@ -1,13 +1,14 @@ package com.github.moaxcp.x11.protocol; +import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; +import org.mockito.Mockito; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.mock; public class X11OutputStreamTest { private ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); @@ -94,17 +95,17 @@ void writePadAlign() throws IOException { @Test void flush() throws IOException { - OutputStream origin = mock(OutputStream.class); + OutputStream origin = Mockito.mock(OutputStream.class); X11OutputStream out = new X11OutputStream(origin); out.flush(); - then(origin).should().flush(); + BDDMockito.then(origin).should().flush(); } @Test void close() throws IOException { - OutputStream origin = mock(OutputStream.class); + OutputStream origin = Mockito.mock(OutputStream.class); X11OutputStream out = new X11OutputStream(origin); out.close(); - then(origin).should().close(); + BDDMockito.then(origin).should().close(); } } diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java similarity index 67% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java index 42d2b6a5..1f7c211b 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java +++ b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityFamilyTest.java @@ -1,7 +1,6 @@ package com.github.moaxcp.x11.protocol; import com.github.moaxcp.x11.protocol.XAuthority.Family; -import org.assertj.core.api.AssertionsForClassTypes; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -10,23 +9,23 @@ public class XAuthorityFamilyTest { @Test void internetCode() { - AssertionsForClassTypes.assertThat(Family.INTERNET.getCode()).isEqualTo(0); + assertThat(Family.INTERNET.getCode()).isEqualTo(0); } @Test void localCode() { - AssertionsForClassTypes.assertThat(Family.LOCAL.getCode()).isEqualTo(256); + assertThat(Family.LOCAL.getCode()).isEqualTo(256); } @Test void wildCode() { - AssertionsForClassTypes.assertThat(Family.WILD.getCode()).isEqualTo(65535); + assertThat(Family.WILD.getCode()).isEqualTo(65535); } @Test void krb5principalCode() { - AssertionsForClassTypes.assertThat(Family.KRB5PRINCIPAL.getCode()).isEqualTo(253); + assertThat(Family.KRB5PRINCIPAL.getCode()).isEqualTo(253); } @Test void localhostCode() { - AssertionsForClassTypes.assertThat(Family.LOCALHOST.getCode()).isEqualTo(252); + assertThat(Family.LOCALHOST.getCode()).isEqualTo(252); } @Test @@ -57,6 +56,6 @@ void localhost_getByCode() { @Test void fail_getByCode() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Family.getByCode(-1234)); - AssertionsForClassTypes.assertThat(exception).hasMessage("Unsupported code \"-1234\""); + assertThat(exception).hasMessage("Unsupported code \"-1234\""); } } diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java similarity index 95% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java rename to x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java index 24712ab3..28a12ecd 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java +++ b/x11-protocol/x11-protocol-core/src/test/java/com/github/moaxcp/x11/protocol/XAuthorityTest.java @@ -1,16 +1,16 @@ package com.github.moaxcp.x11.protocol; import com.github.moaxcp.x11.protocol.XAuthority.Family; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + import java.io.DataInput; import java.io.IOException; import java.util.Optional; -import org.junit.jupiter.api.Test; import static com.github.moaxcp.x11.protocol.Utilities.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class XAuthorityTest { @@ -74,9 +74,9 @@ private static void fillBytes(byte[] bytes) { @Test void read_IOException() throws IOException { - DataInput in = mock(DataInput.class); + DataInput in = Mockito.mock(DataInput.class); IOException cause = new IOException("expected cause"); - when(in.readUnsignedShort()).thenThrow(cause); + Mockito.when(in.readUnsignedShort()).thenThrow(cause); Optional read = XAuthority.read(in); assertThat(read).isEmpty(); } diff --git a/x11-protocol/x11-protocol-xproto/build.gradle b/x11-protocol/x11-protocol-xproto/build.gradle index 08a24534..8acfa84d 100644 --- a/x11-protocol/x11-protocol-xproto/build.gradle +++ b/x11-protocol/x11-protocol-xproto/build.gradle @@ -15,6 +15,9 @@ java { dependencies { api project(':x11-protocol:x11-protocol-core') + testImplementation 'org.mockito:mockito-core:3.3.3' + testImplementation 'org.assertj:assertj-core:3.16.0' + testImplementation 'org.mockito:mockito-junit-jupiter:3.3.3' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' } diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java similarity index 99% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java index 5b22c29d..b585d476 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java +++ b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ChangePropertyTest.java @@ -4,10 +4,11 @@ import com.github.moaxcp.x11.protocol.X11InputStream; import com.github.moaxcp.x11.protocol.X11Output; import com.github.moaxcp.x11.protocol.X11OutputStream; +import org.junit.jupiter.api.Test; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData16Test.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData16Test.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData16Test.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData16Test.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData32Test.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData32Test.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData32Test.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData32Test.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData8Test.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData8Test.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData8Test.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ClientMessageData8Test.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java similarity index 97% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java index d4aee0d7..015cecaa 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java +++ b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/CreateWindowTest.java @@ -1,6 +1,5 @@ package com.github.moaxcp.x11.protocol.xproto; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/EventMaskTest.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/EventMaskTest.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/EventMaskTest.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/EventMaskTest.java diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java similarity index 70% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java index 2f36efc0..1726c60c 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java +++ b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/GetKeyboardMappingRequestTest.java @@ -2,11 +2,11 @@ import com.github.moaxcp.x11.protocol.X11Output; import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; public class GetKeyboardMappingRequestTest { @@ -34,11 +34,11 @@ void write() throws IOException { .build(); request.write((byte) 0, out); - then(out).should().writeCard8(GetKeyboardMapping.OPCODE); - then(out).should().writePad(1); - then(out).should().writeCard16((short) 2); - then(out).should().writeCard8((byte) 22); - then(out).should().writeCard8((byte) 44); - then(out).should().writePadAlign(6); + BDDMockito.then(out).should().writeCard8(GetKeyboardMapping.OPCODE); + BDDMockito.then(out).should().writePad(1); + BDDMockito.then(out).should().writeCard16((short) 2); + BDDMockito.then(out).should().writeCard8((byte) 22); + BDDMockito.then(out).should().writeCard8((byte) 44); + BDDMockito.then(out).should().writePadAlign(6); } } diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java similarity index 91% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java index 4b4df09b..57fc6756 100644 --- a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java +++ b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/QueryExtensionRequestTest.java @@ -3,16 +3,16 @@ import com.github.moaxcp.x11.protocol.Utilities; import com.github.moaxcp.x11.protocol.X11Output; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import java.io.IOException; import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.mock; public class QueryExtensionRequestTest { @Test void writeQueryExtensionXCMISC() throws IOException { - X11Output out = mock(X11Output.class); + X11Output out = Mockito.mock(X11Output.class); QueryExtension request = QueryExtension.builder() .name(Utilities.toList("XC-MISC".getBytes())) .build(); @@ -29,7 +29,7 @@ void writeQueryExtensionXCMISC() throws IOException { } @Test void writeQueryExtensionBIGREQUESTS() throws IOException { - X11Output out = mock(X11Output.class); + X11Output out = Mockito.mock(X11Output.class); QueryExtension request = QueryExtension.builder() .name(Utilities.toList("BIG-REQUESTS".getBytes())) .build(); diff --git a/x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ReadWriteTestsPrototype.java b/x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ReadWriteTestsPrototype.java similarity index 100% rename from x11-client/src/test/java/com/github/moaxcp/x11/protocol/xproto/ReadWriteTestsPrototype.java rename to x11-protocol/x11-protocol-xproto/src/test/java/com/github/moaxcp/x11/protocol/xproto/ReadWriteTestsPrototype.java diff --git a/x11-toolkit/build.gradle b/x11-toolkit/build.gradle index 1dc388ec..c3fdbb61 100644 --- a/x11-toolkit/build.gradle +++ b/x11-toolkit/build.gradle @@ -14,6 +14,8 @@ java { dependencies { api project(':x11-client') + implementation 'com.kohlschutter.junixsocket:junixsocket-core:2.9.1' + implementation 'com.kohlschutter.junixsocket:junixsocket-native-common:2.9.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' } diff --git a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Drawable.java b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Drawable.java index b1278bbd..aeac0a84 100644 --- a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Drawable.java +++ b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Drawable.java @@ -1,8 +1,5 @@ package com.github.moaxcp.x11.toolkit; -import lombok.Getter; - -@Getter public abstract class Drawable extends Resource { private int screen; private short x; @@ -21,7 +18,7 @@ public abstract class Drawable extends Resource { } public GraphicsContext getGc() { - if(gc == null) { + if (gc == null) { gc = new GraphicsContext(display, this); } return gc; @@ -29,8 +26,28 @@ public GraphicsContext getGc() { @Override public void close() { - if(gc != null) { + if (gc != null) { gc.close(); } } + + public int getScreen() { + return this.screen; + } + + public short getX() { + return this.x; + } + + public short getY() { + return this.y; + } + + public short getWidth() { + return this.width; + } + + public short getHeight() { + return this.height; + } } diff --git a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/GraphicsContext.java b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/GraphicsContext.java index 9f423b54..b1c01a48 100644 --- a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/GraphicsContext.java +++ b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/GraphicsContext.java @@ -2,11 +2,9 @@ import com.github.moaxcp.x11.protocol.Utilities; import com.github.moaxcp.x11.protocol.xproto.*; -import lombok.Getter; import java.util.Collections; -@Getter public class GraphicsContext extends Resource { private final int drawable; private int background; @@ -18,35 +16,47 @@ public GraphicsContext(Display display, Drawable drawable) { this.background = display.getWhitePixel(drawable.getScreen()); this.foreground = display.getBlackPixel(drawable.getScreen()); display.send(CreateGC.builder() - .cid(getId()) - .drawable(this.drawable) - .background(background) - .foreground(foreground) - .build()); + .cid(getId()) + .drawable(this.drawable) + .background(background) + .foreground(foreground) + .build()); } public void polyFillRectangle(Rectangle rectangle) { display.send(PolyFillRectangle.builder() - .drawable(drawable) - .gc(getId()) - .rectangles(Collections.singletonList(rectangle)) - .build()); + .drawable(drawable) + .gc(getId()) + .rectangles(Collections.singletonList(rectangle)) + .build()); } public void imageText8(short x, short y, String text) { display.send(ImageText8.builder() - .drawable(drawable) - .gc(getId()) - .x(x) - .y(y) - .string(Utilities.toByteList(text)) - .build()); + .drawable(drawable) + .gc(getId()) + .x(x) + .y(y) + .string(Utilities.toByteList(text)) + .build()); } @Override public void close() { display.send(FreeGC.builder() - .gc(getId()) - .build()); + .gc(getId()) + .build()); + } + + public int getDrawable() { + return this.drawable; + } + + public int getBackground() { + return this.background; + } + + public int getForeground() { + return this.foreground; } } diff --git a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Resource.java b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Resource.java index ef326c43..9f27065d 100644 --- a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Resource.java +++ b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Resource.java @@ -1,9 +1,6 @@ package com.github.moaxcp.x11.toolkit; -import lombok.Getter; - public abstract class Resource implements AutoCloseable { - @Getter private int id; protected final Display display; @@ -11,4 +8,8 @@ public abstract class Resource implements AutoCloseable { this.display = display; id = display.nextResourceId(); } + + public int getId() { + return this.id; + } } diff --git a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Window.java b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Window.java index 791fe045..826ac7ad 100644 --- a/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Window.java +++ b/x11-toolkit/src/main/java/com/github/moaxcp/x11/toolkit/Window.java @@ -1,13 +1,11 @@ package com.github.moaxcp.x11.toolkit; import com.github.moaxcp.x11.protocol.xproto.*; -import lombok.Getter; import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; -@Getter public class Window extends Drawable { private byte depth; private int parent; @@ -29,47 +27,47 @@ public class Window extends Drawable { backgroundPixel = display.getWhitePixel(screen); borderPixel = display.getBlackPixel(screen); display.send(CreateWindow.builder() - .depth(depth) - .wid(getId()) - .parent(parent) - .x(x) - .y(y) - .width(width) - .height(height) - .borderWidth(borderWidth) - .clazz(clazz) - .visual(visual) - .backgroundPixel(backgroundPixel) - .borderPixel(borderPixel) - .eventMaskEnable(EventMask.EXPOSURE) - .eventMaskEnable(EventMask.KEY_PRESS) - .build()); + .depth(depth) + .wid(getId()) + .parent(parent) + .x(x) + .y(y) + .width(width) + .height(height) + .borderWidth(borderWidth) + .clazz(clazz) + .visual(visual) + .backgroundPixel(backgroundPixel) + .borderPixel(borderPixel) + .eventMaskEnable(EventMask.EXPOSURE) + .eventMaskEnable(EventMask.KEY_PRESS) + .build()); } public void map() { display.send(MapWindow.builder() - .window(getId()) - .build()); + .window(getId()) + .build()); } @Override public void close() { super.close(); display.send(DestroyWindow.builder() - .window(getId()) - .build()); + .window(getId()) + .build()); keyPressEventConsumers.clear(); exposeEventConsumers.clear(); } void exposeEvent(ExposeEvent event) { - for(BiConsumer consumer : exposeEventConsumers) { + for (BiConsumer consumer : exposeEventConsumers) { consumer.accept(this, event); } } void keyPressEvent(KeyPressEvent event) { - for(BiConsumer consumer : keyPressEventConsumers) { + for (BiConsumer consumer : keyPressEventConsumers) { consumer.accept(this, event); } } @@ -81,4 +79,40 @@ public void exposeEvent(BiConsumer consumer) { public void keyPressEvent(BiConsumer consumer) { keyPressEventConsumers.add(consumer); } + + public byte getDepth() { + return this.depth; + } + + public int getParent() { + return this.parent; + } + + public short getBorderWidth() { + return this.borderWidth; + } + + public WindowClass getClazz() { + return this.clazz; + } + + public int getVisual() { + return this.visual; + } + + public int getBackgroundPixel() { + return this.backgroundPixel; + } + + public int getBorderPixel() { + return this.borderPixel; + } + + public List> getExposeEventConsumers() { + return this.exposeEventConsumers; + } + + public List> getKeyPressEventConsumers() { + return this.keyPressEventConsumers; + } } diff --git a/x11-toolkit/src/main/java/module-info.java b/x11-toolkit/src/main/java/module-info.java index 86630136..49839db6 100644 --- a/x11-toolkit/src/main/java/module-info.java +++ b/x11-toolkit/src/main/java/module-info.java @@ -3,5 +3,4 @@ exports com.github.moaxcp.x11.toolkit; requires transitive com.github.moaxcp.x11.client; - requires static lombok; } \ No newline at end of file diff --git a/xephyr-runner/src/main/java/com/github/moaxcp/x11/xephyr/XephyrRunner.java b/xephyr-runner/src/main/java/com/github/moaxcp/x11/xephyr/XephyrRunner.java index f09362d2..2ce86776 100644 --- a/xephyr-runner/src/main/java/com/github/moaxcp/x11/xephyr/XephyrRunner.java +++ b/xephyr-runner/src/main/java/com/github/moaxcp/x11/xephyr/XephyrRunner.java @@ -1,12 +1,11 @@ package com.github.moaxcp.x11.xephyr; -import lombok.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.TreeSet; +import java.util.concurrent.TimeUnit; -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -@Builder public class XephyrRunner { private static TreeSet usedDisplays = new TreeSet<>(); private final boolean br; @@ -16,15 +15,25 @@ public class XephyrRunner { private final boolean glamor; private final boolean softCursor; private final String screen; - @NonNull - @Singular + private final int withXTerm; + private final List processes = new ArrayList<>(); private final List enableExtensions = new ArrayList<>(); - @Getter - @Builder.Default - private final String display = getOpenDisplay(); + private final String display; + + XephyrRunner(boolean br, boolean ac, boolean noreset, Boolean iglx, boolean glamor, boolean softCursor, String screen, String display, int withXTerm) { + this.br = br; + this.ac = ac; + this.noreset = noreset; + this.iglx = iglx; + this.glamor = glamor; + this.softCursor = softCursor; + this.screen = screen; + this.display = display; + this.withXTerm = withXTerm; + } private static String getOpenDisplay() { - if(usedDisplays.isEmpty()) { + if (usedDisplays.isEmpty()) { usedDisplays.add(1); return ":1"; } @@ -34,41 +43,40 @@ private static String getOpenDisplay() { return ":" + last; } - private final int withXTerm; - @NonNull - @Builder.Default - private List processes = new ArrayList<>(); + public static XephyrRunnerBuilder builder() { + return new XephyrRunnerBuilder(); + } public void start() throws IOException { List command = new ArrayList<>(); command.add("Xephyr"); - if(br) { + if (br) { command.add("-br"); } - if(ac) { + if (ac) { command.add("-ac"); } - if(noreset) { + if (noreset) { command.add("-noreset"); } - if(iglx != null) { - if(iglx) { + if (iglx != null) { + if (iglx) { command.add("+iglx"); } else { command.add("-iglx"); } } - if(glamor) { + if (glamor) { command.add("-glamor"); } - if(softCursor) { + if (softCursor) { command.add("-softCursor"); } - if(screen != null) { + if (screen != null) { command.add("-screen"); command.add(screen); } - for(String extension : enableExtensions) { + for (String extension : enableExtensions) { command.add("+extension"); command.add(extension); } @@ -81,17 +89,91 @@ public void start() throws IOException { } private void startXTerms() throws IOException { - for(int i = 0; i < withXTerm; i++) { + for (int i = 0; i < withXTerm; i++) { processes.add(new ProcessBuilder("xterm", "-display", display).start()); } } public void stop() throws InterruptedException { - for(Process process : processes) { + for (Process process : processes) { process.destroy(); process.waitFor(10000, TimeUnit.SECONDS); process.destroyForcibly(); process.waitFor(); } } + + public String getDisplay() { + return this.display; + } + + public static class XephyrRunnerBuilder { + private boolean br; + private boolean ac; + private boolean noreset; + private Boolean iglx; + private boolean glamor; + private boolean softCursor; + private String screen; + private String display$value; + private boolean display$set; + private int withXTerm; + + XephyrRunnerBuilder() { + } + + public XephyrRunnerBuilder br(boolean br) { + this.br = br; + return this; + } + + public XephyrRunnerBuilder ac(boolean ac) { + this.ac = ac; + return this; + } + + public XephyrRunnerBuilder noreset(boolean noreset) { + this.noreset = noreset; + return this; + } + + public XephyrRunnerBuilder iglx(Boolean iglx) { + this.iglx = iglx; + return this; + } + + public XephyrRunnerBuilder glamor(boolean glamor) { + this.glamor = glamor; + return this; + } + + public XephyrRunnerBuilder softCursor(boolean softCursor) { + this.softCursor = softCursor; + return this; + } + + public XephyrRunnerBuilder screen(String screen) { + this.screen = screen; + return this; + } + + public XephyrRunnerBuilder display(String display) { + this.display$value = display; + this.display$set = true; + return this; + } + + public XephyrRunnerBuilder withXTerm(int withXTerm) { + this.withXTerm = withXTerm; + return this; + } + + public XephyrRunner build() { + String display$value = this.display$value; + if (!this.display$set) { + display$value = getOpenDisplay(); + } + return new XephyrRunner(this.br, this.ac, this.noreset, this.iglx, this.glamor, this.softCursor, this.screen, display$value, this.withXTerm); + } + } } diff --git a/xephyr-runner/src/main/java/module-info.java b/xephyr-runner/src/main/java/module-info.java index af43dafe..81967fdf 100644 --- a/xephyr-runner/src/main/java/module-info.java +++ b/xephyr-runner/src/main/java/module-info.java @@ -1,6 +1,4 @@ @SuppressWarnings("module") module com.github.moaxcp.x11.xephyr { exports com.github.moaxcp.x11.xephyr; - - requires static lombok; } \ No newline at end of file