moaxcp / x11 Goto Github PK
View Code? Open in Web Editor NEWAn x11 protocol implementation and client for the jvm
License: MIT License
An x11 protocol implementation and client for the jvm
License: MIT License
my code
package x11;
import com.github.moaxcp.x11client.X11Client;
import com.github.moaxcp.x11client.protocol.record.*;
import java.io.IOException;
import java.util.List;
public class X11Test {
public static void main(String[] args) {
try (X11Client client = X11Client.connect()) {
int rc = client.nextResourceId();
Range8 empty = Range8.builder().build();
ExtRange emptyExtRange = ExtRange.builder()
.major(empty)
.minor(Range16.builder().build())
.build();
Range range = Range.builder()
.deviceEvents(Range8.builder().first((byte) 2).last((byte) 6).build())
.coreRequests(empty)
.coreReplies(empty)
.extRequests(emptyExtRange)
.extReplies(emptyExtRange)
.deliveredEvents(empty)
.clientStarted(false)
.errors(empty)
.clientDied(false)
.build();
CreateContext createContext = CreateContext.builder()
.context(rc)
.clientSpecs(List.of(Cs.ALL_CLIENTS.getValue()))
.elementHeader((byte) 0)
.ranges(List.of(range))
.build();
client.send(createContext);
EnableContext enableContext = EnableContext
.builder()
.context(rc)
.build();
EnableContextReply enableContextReply = client.send(enableContext);
if (enableContextReply.getCategory() == 0) {
for (Byte datum : enableContextReply.getData()) {
System.out.println(datum);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
the code can't work, got this exception
Exception in thread "main" com.github.moaxcp.x11client.X11ErrorException: WindowError(firstErrorOffset=0, sequenceNumber=2, badValue=230686721, minorOpcode=0, majorOpcode=2)
at com.github.moaxcp.x11client.XProtocolService.readReply(XProtocolService.java:87)
at com.github.moaxcp.x11client.XProtocolService.send(XProtocolService.java:66)
at com.github.moaxcp.x11client.X11Client.send(X11Client.java:238)
at x11.X11Test.main(X11Test.java:51)
is somewhere wrongοΌ
each XResult should generate a reader class for events, errors, and replies.
Optional values are defined in a switch element with bit cases in the protocol. These are added to each pojo and used in the read and write methods. It is possible for x11 extensions to add fields to one of these switch elements dynamically. To support this in java a new list of Integers can be added for each of these fields.
Each field in a bitcase is 32 bits
The field is only sent if the bit for the field is set in the value mask.
Hello world
Tinywm
And example from each extension.
All XObjects support reading and writing. The objects could be used in a client and a server. The ProtocolService can also be changed to read and write all objects. The protocol service should be moved the the protocol package.
To make exceptions more generic X11ClientException should only be used at the client level. A new X11ProtocolException should be used for all classes under the protocol package.
When a primatives field has an mask methods are added to mask the value with an enum parameter. The same should be done with an altmask.
Add builder methods to primatives fields that support altenum.
Generated XObjects should be immutable and have a builder. This requires that List
s are used instead of arrays for lists in the protocol.
instead of using arrays in XObjects List
should be used. This will require changes in the generator.
Events need to have the extension offset in order to write correctly. This is needed in order for the send event requests to function.
Switch to java 11 and implement modularity
import java.io.IOException;
import com.github.moaxcp.x11client.X11Client;
import com.github.moaxcp.x11client.protocol.DisplayName;
import com.github.moaxcp.x11client.protocol.xproto.CreateWindow;
import com.github.moaxcp.x11client.protocol.xproto.EventMask;
public class WMTest {
public static void main(final String[] args) throws InterruptedException, IOException {
try (var x11Client = X11Client.connect(DisplayName.displayName(":1"))) {
final var EXPOSURE = EventMask.EXPOSURE;
final var KEY_PRESS = EventMask.KEY_PRESS;
final var window = CreateWindow.builder().depth(x11Client.getDepth(0)).wid(x11Client.nextResourceId())
.parent(x11Client.getRoot(0)).x((short) 10).y((short) 10).width((short) 600).height((short) 480)
.borderWidth((short) 5)
// .clazz(COPY_FROM_PARENT)
.visual(x11Client.getVisualId(0)).backgroundPixel(x11Client.getWhitePixel(0))
.borderPixel(x11Client.getBlackPixel(0)).eventMaskEnable(EXPOSURE, KEY_PRESS).build();
Thread.sleep(100000);
}
}
}
Exception in thread "main" com.github.moaxcp.x11client.X11ClientException: Could not connect with :1.0
at com.github.moaxcp.x11client.X11Client.connect(X11Client.java:80)
at WMTest.main(WMTest.java:12)
Caused by: java.net.SocketException: Cannot find method "setCreated" or field "created" in java.net.Socket. Unsupported JVM?
at org.newsclub.net.unix.NativeUnixSocket.setCreated(Native Method)
at org.newsclub.net.unix.AFUNIXSocket.setIsCreated(AFUNIXSocket.java:56)
at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:50)
at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:79)
at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:74)
at org.newsclub.net.unix.AFUNIXSocket.connectTo(AFUNIXSocket.java:108)
at com.github.moaxcp.x11client.X11Connection.connect(X11Connection.java:116)
at com.github.moaxcp.x11client.X11Connection.connect(X11Connection.java:141)
at com.github.moaxcp.x11client.X11Client.connect(X11Client.java:78)
... 1 more
java:
/usr/lib/jvm/java-21-openjdk/bin/java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment (build 21+35)
OpenJDK 64-Bit Server VM (build 21+35, mixed mode, sharing)
maven deps:
[INFO] com.kohlschutter.junixsocket:junixsocket-core:jar:2.3.2:runtime
[INFO] com.kohlschutter.junixsocket:junixsocket-common:jar:2.3.2:runtime
[INFO] com.kohlschutter.junixsocket:junixsocket-native-common:jar:2.3.2:runtime
[INFO] net.java.dev.jna:jna:jar:5.13.0:compile
[INFO] org.projectlombok:lombok:jar:1.18.30:provided
[INFO] com.github.moaxcp.x11:x11-client:jar:0.11.0:compile
Add xkb extension. This is hard to do.
Value lists are an optional part of x11 objects. When they are set a bit in a value mask is set. There are default values but they are not in the protocol xmls.
Add switch fields
Add custom setter which als sets the bit in the value mask
Add support in read and write methods
At a glance I couldn't find any evidence that XGrabKeyboard
is supported. Did I miss something? What would it take to add it?
Request objects are used to send requests to the x11 server. These objects are generated from the xcb xmls.
Make sure to check requests against the xproto.pdf.
The raw XErrror only contains a few codes to get the correct error message.
WindowError(sequenceNumber=36, badValue=0, minorOpcode=0, majorOpcode=1)
It is up to the client to use those codes to generate an error message. This story is to discuss and implement error messages.
X11lib uses ErrDec to generate the messages. It uses some methods which read an errordb file.
Every extension should add a class implementing XProtocolPlugin. This enables the client to support the extension.
Also generate the service loader properties file.
reply objects are optional parts of request objects in the x11 protocol.
Generate objects and compare with xproto.pdf
List sizes should be determined by the list object not a member variable.
The protocol sends enums as a primative type (byte, short). The java classes currently have members for the java enum rather than this protocol type. This makes it impossible to set values that are not defined in the enum. This is a good general practice in java but not in this case.
One proble is supporting altenums for the field. The other issie is when an X11 extension adds new possible values for an enum field.
Remove the use of enum member fields and replace them with their primative type.
Add builder methods for setting the member based on an enum or alt enum.
This is used in present.xml and input.xml
Class names like SetupStruct
should only be used in cases where there is a duplicate name. For instance
WindowEvent
WindowError
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.