Skip to content

Commit

Permalink
Adding examples with fixes and api.
Browse files Browse the repository at this point in the history
Added support for no-sequence-number in KeymapNotifyEvent I suspect this also fixed the RecordApiExample.

Fixed bug where generated code for reading generic events was missing from protocol plugins

Fixed bug in generated code for replies where reading pad align was missing

Added XApi and extended interfaces to act as traits for the X11Client. These interfaces allow the X11Client to have an api beyond the simple response, reply, event, and error api.

Fixed bug where new resource ids are not requested by the client when they run out

Added examples for xproto.
  • Loading branch information
moaxcp committed Dec 28, 2024
1 parent 08bc643 commit 4df130b
Show file tree
Hide file tree
Showing 190 changed files with 259 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,15 @@ https://www.x.org/releases/X11R7.6/doc/libXtst/recordlib.html

# versions

## 0.20.0
## 0.21.0

* Added support for no-sequence-number events which is only used in KeymapNotifyEvent
* This fixed part of the RecordApiExample
* Fixing bug in generating code to read generic events
* Fixed bug where generated code for reading generic events was missing from protocol plugins
* Fixed bug in generated code for replies where reading pad align was missing
* Adding XApi interfaces to cleanup client
* Added examples and api to run examples
* Fixed bug where new resource ids are not requested by the client when they run out

## 0.20.0

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

allprojects {
version = '0.20.0'
version = '0.21.0'
group = 'com.github.moaxcp.x11'
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static void main(String... args) throws IOException, InterruptedException
.y(500)
.build());

client.sync();

System.out.println(client.getNextEvent());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.github.moaxcp.x11.examples;

import com.github.moaxcp.x11.protocol.record.QueryVersionReply;
import com.github.moaxcp.x11.x11client.X11Client;

import java.io.IOException;
import java.util.logging.Logger;

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();
QueryVersionReply reply = client.send(queryVersion);
log.info(reply.toString());
System.out.println(client.send(queryVersion));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException {
.extReplies(emptyExtRange)
.deliveredEvents(empty)
//doesn't accept any value?
//.deliveredEvents(Range8.builder().first((byte) 0).last((byte) 1).build())
.deliveredEvents(Range8.builder().first((byte) 2).last((byte) 22).build())
.clientStarted(true)
.errors(Range8.builder()
.first((byte) 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.moaxcp.x11.examples;
package com.github.moaxcp.x11.examples.xfixes;

import com.github.moaxcp.x11.protocol.xfixes.QueryVersion;
import com.github.moaxcp.x11.protocol.xfixes.SelectSelectionInput;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.moaxcp.x11.examples.xproto;

import com.github.moaxcp.x11.protocol.X11ErrorException;
import com.github.moaxcp.x11.protocol.xproto.CreateColormap;
import com.github.moaxcp.x11.protocol.xproto.GetGeometry;
import com.github.moaxcp.x11.x11client.X11Client;

import java.io.IOException;

public class ErrorsExample {
public static void main(String... args) throws IOException {
valueError();
drawableError();
}

private static void valueError() throws IOException {
try (var client = X11Client.connect()) {
var cmap = client.nextResourceId();
client.send(CreateColormap.builder()
.alloc((byte) 111)
.mid(cmap)
.window(client.getDefaultRoot())
.visual(client.getDefaultScreen().getRootVisual())
.build());
client.sync();
} catch (X11ErrorException e) {
System.out.println(e);
}
}

private static void drawableError() throws IOException {
try (var client = X11Client.connect()) {
var invalidWindow = client.nextResourceId();
var getGeometry = GetGeometry.builder().drawable(invalidWindow).build();
System.out.println(getGeometry);
client.send(getGeometry);
} catch (X11ErrorException e) {
System.out.println(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static void main(String... args) throws IOException {
.build();
var fonts = client.send(listFontsRequest);

fonts.getNames().forEach(str -> System.out.println(Utilities.toString(str.getName()).indent(4)));
fonts.getNames().forEach(str -> System.out.println(" " + Utilities.toString(str.getName())));

client.sync();

System.out.println("Fonts with info:");

Expand All @@ -36,7 +38,7 @@ public static void main(String... args) throws IOException {
var fontsWithInfo = client.send(listFontsWithInfoRequest);

while (!fontsWithInfo.getName().isEmpty()) {
System.out.println("%s %d".formatted(Utilities.toString(fontsWithInfo.getName()), fontsWithInfo.getRepliesHint()).indent(4));
System.out.println(" %s %d".formatted(Utilities.toString(fontsWithInfo.getName()), fontsWithInfo.getRepliesHint()));
fontsWithInfo = client.getNextReply(listFontsWithInfoRequest.getReplyFunction());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.moaxcp.x11.examples.xproto;

import com.github.moaxcp.x11.x11client.X11Client;

import java.io.IOException;

public class ResourceIdsExample {
public static void main(String... args) throws IOException {
try (var client = X11Client.connect()) {
while (true) {
var id = client.nextResourceId();
System.out.println(id);
if (!(((id + 1) & ~client.getSetup().getResourceIdMask()) == 0)) {
System.out.println("requesting more ids");
return;
}
}
}
}
}
1 change: 1 addition & 0 deletions examples/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module com.github.moaxcp.x11.examples {
exports com.github.moaxcp.x11.examples;
exports com.github.moaxcp.x11.examples.record;
exports com.github.moaxcp.x11.examples.xfixes;

requires transitive com.github.moaxcp.x11.client;
requires transitive com.github.moaxcp.x11.xephyr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int nextResourceId() {
if(nextResourceId >= xcmiscStartId && nextResourceId < xcmiscStartId + xcmiscCount) {
return nextResourceId++;
}
if(!protocolService.activatedPlugin("XC-MISC")) {
if(!protocolService.activatedPlugin("xc_misc")) {
throw new IllegalStateException("Core protocol is out of ids and XC-MISC is not activated.");
}
GetXIDRangeReply range = protocolService.send(GetXIDRange.builder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
public interface XprotoApi extends XApi {

/**
* Sends a {@link GetInputFocus} to the server. This is a {@link TwoWayRequest} which causes a {@link #flush()} and
* Sends a {@link GetInputFocus} to the server. This is a {@link TwoWayRequest} which causes a {@link com.github.moaxcp.x11.x11client.X11Client#flush()} and
* all events to be read from the server and added to the event queue.
* See <a href="https://github.com/mirror/libX11/blob/caa71668af7fd3ebdd56353c8f0ab90824773969/src/Sync.c">...</a>
*/
default void sync() {
GetInputFocusReply reply = send(GetInputFocus.builder().build());
send(GetInputFocus.builder().build());
}

int nextResourceId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ void thirdIdIs3() {
void switchToXCMISCNotActivated() {
service = new ResourceIdService(protocolService, 0b01, 0b10);
service.nextResourceId();
given(protocolService.activatedPlugin("XC-MISC")).willReturn(false);
given(protocolService.activatedPlugin("xc_misc")).willReturn(false);
IllegalStateException exception = assertThrows(IllegalStateException.class, () -> service.nextResourceId());
assertThat(exception).hasMessage("Core protocol is out of ids and XC-MISC is not activated.");
then(protocolService).should().activatedPlugin("XC-MISC");
then(protocolService).should().activatedPlugin("xc_misc");
}

@Test
void switchToXCMISC() {
service = new ResourceIdService(protocolService, 0b01, 0b10);
service.nextResourceId();
given(protocolService.activatedPlugin("XC-MISC")).willReturn(true);
given(protocolService.activatedPlugin("xc_misc")).willReturn(true);
given(protocolService.send(any(GetXIDRange.class))).willReturn(GetXIDRangeReply.builder().startId(0b100).count(2).build());
int id = service.nextResourceId();
then(protocolService).should().activatedPlugin("XC-MISC");
then(protocolService).should().activatedPlugin("xc_misc");
assertThat(id).isEqualTo(4);
id = service.nextResourceId();
assertThat(id).isEqualTo(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class JavaReply extends JavaClass {
methodBuilder.beginControlFlow('if(javaBuilder.getSize() < 32)')
methodBuilder.addStatement('in.readPad(32 - javaBuilder.getSize())')
methodBuilder.endControlFlow()
return
}

if(fixedSize && fixedSize.get() % 4 == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static ConnectReply readConnectReply(byte pad1, short sequenceNumber, X11
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static GetBuffersReply readGetBuffersReply(byte pad1, short sequenceNumbe
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static GetBuffersWithFormatReply readGetBuffersWithFormatReply(byte pad1,
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static BuffersFromPixmapReply readBuffersFromPixmapReply(byte nfd, short
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static GetSupportedModifiersReply readGetSupportedModifiersReply(byte pad
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static AreTexturesResidentReply readAreTexturesResidentReply(byte pad1,
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static GenQueriesARBReply readGenQueriesARBReply(byte pad1, short sequenc
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static GenTexturesReply readGenTexturesReply(byte pad1, short sequenceNum
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetBooleanvReply readGetBooleanvReply(byte pad1, short sequenceNum
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static GetClipPlaneReply readGetClipPlaneReply(byte pad1, short sequenceN
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetColorTableParameterfvReply readGetColorTableParameterfvReply(by
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetColorTableParameterivReply readGetColorTableParameterivReply(by
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static GetColorTableReply readGetColorTableReply(byte pad1, short sequenc
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static GetCompressedTexImageARBReply readGetCompressedTexImageARBReply(by
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static GetConvolutionFilterReply readGetConvolutionFilterReply(byte pad1,
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetConvolutionParameterfvReply readGetConvolutionParameterfvReply(
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetConvolutionParameterivReply readGetConvolutionParameterivReply(
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetDoublevReply readGetDoublevReply(byte pad1, short sequenceNumbe
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static GetDrawableAttributesReply readGetDrawableAttributesReply(byte pad
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static GetFBConfigsReply readGetFBConfigsReply(byte pad1, short sequenceN
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetFloatvReply readGetFloatvReply(byte pad1, short sequenceNumber,
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static GetHistogramParameterfvReply readGetHistogramParameterfvReply(byte
if(javaBuilder.getSize() < 32) {
in.readPad(32 - javaBuilder.getSize());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}

Expand Down
Loading

0 comments on commit 4df130b

Please sign in to comment.