Skip to content

Commit

Permalink
Added support for no-sequence-number in KeymapNotifyEvent I suspect t…
Browse files Browse the repository at this point in the history
…his also fixed the RecordApiExample.

Added examples.
  • Loading branch information
moaxcp committed Dec 20, 2024
1 parent b12d18e commit 1b17fbe
Show file tree
Hide file tree
Showing 36 changed files with 1,053 additions and 325 deletions.
8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ https://www.x.org/releases/X11R7.6/doc/libXtst/recordlib.html

# versions

## 0.20.0

* Added support for no-sequence-number events which is only used in KeymapNotifyEvent
* Adding XApi interfaces to cleanup client
* Added examples and api to run examples

## 0.19.0

* Added support for little-endian and made it default to match the server default.
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.record;

import com.github.moaxcp.x11.keysym.KeySym;
import com.github.moaxcp.x11.protocol.XEvent;
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.record;

import com.github.moaxcp.x11.keysym.KeySym;
import com.github.moaxcp.x11.protocol.record.*;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static void main(String... args) throws IOException {
.build();
data.send(enableContext);
while (true) {
RecordReply recordReply = data.record().readNextRecord();
RecordReply recordReply = data.readNextRecord();
log.info(String.format("%s", recordReply));
Optional<KeySym> first = recordReply.getData().stream()
.map(RecordData::getXObject)
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.record;

import com.github.moaxcp.x11.keysym.KeySym;
import com.github.moaxcp.x11.protocol.record.*;
Expand All @@ -13,9 +13,9 @@
import java.util.Optional;
import java.util.logging.Logger;

public class RecordApi {
public class RecordApiExample {

private static final Logger log = Logger.getLogger(RecordApi.class.getName());
private static final Logger log = Logger.getLogger(RecordApiExample.class.getName());

/**
* Tests all xproto events including generic events. Also tests errors.
Expand Down Expand Up @@ -68,7 +68,7 @@ public static void main(String... args) throws IOException {
.build();
data.send(enableContext);
while (true) {
RecordReply recordReply = data.record().readNextRecord();
RecordReply recordReply = data.readNextRecord();
log.info(String.format("%s", recordReply));
Optional<KeySym> first = recordReply.getData().stream()
.map(RecordData::getXObject)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.moaxcp.x11.examples.xproto;

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

import java.io.IOException;

import static com.github.moaxcp.x11.protocol.xproto.EventMask.BUTTON_PRESS;
import static com.github.moaxcp.x11.protocol.xproto.EventMask.EXPOSURE;

public class ChangeEventsExample {
public static void main(String... args) throws IOException {
try (var client = X11Client.connect()) {
var wid = client.createSimpleWindow(0, 0, 150, 150);
client.changeWindowEvents(wid, EXPOSURE, BUTTON_PRESS);
client.sync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.moaxcp.x11.examples.xproto;

import com.github.moaxcp.x11.protocol.xproto.*;

import java.util.List;

public class CombinedWindow {
public static void main(String... args) {
var points = List.of(Point.builder().x((short) 10).y((short) 10).build(),
Point.builder().x((short) 10).y((short) 20).build(),
Point.builder().x((short) 20).y((short) 10).build(),
Point.builder().x((short) 20).y((short) 20).build());

var polyLine = List.of(Point.builder().x((short) 50).y((short) 10).build(),
Point.builder().x((short) 5).y((short) 20).build(), // Rest of points are relative
Point.builder().x((short) 25).y((short) -20).build(),
Point.builder().x((short) 10).y((short) 10).build());

var segments = List.of(Segment.builder().x1((short) 100).y1((short) 10).x2((short) 140).y2((short) 30).build(),
Segment.builder().x1((short) 110).x1((short) 25).x2((short) 130).y2((short) 60).build());

var rectangles = List.of(Rectangle.builder().x((short) 10).y((short) 50).width((short) 40).height((short) 20).build(),
Rectangle.builder().x((short) 80).y((short) 50).width((short) 10).height((short) 40).build());

var arcs = List.of(Arc.builder().x((short) 10).y((short) 100).width((short) 60).height((short) 40).angle1((short) 0).angle2((short) (90 << 6)).build(),
Arc.builder().x((short) 90).y((short) 100).width((short) 55).height((short) 40).angle1((short) 0).angle2((short) (270 << 6)).build());

ExposeWindow main = (client, wid, lineGc, fillGc) -> {
client.polyPoint(wid, fillGc, CoordMode.ORIGIN, points);
client.polyLine(wid, lineGc, CoordMode.PREVIOUS, polyLine);
client.polySegment(wid, lineGc, segments);
client.polyRectangle(wid, lineGc, rectangles);
client.polyArc(wid, lineGc, arcs);
};
main.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.moaxcp.x11.examples.xproto;

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

import java.io.IOException;

public class Connect {
public static void main(String... args) throws IOException {
try (var client = X11Client.connect()) {
client.sync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.moaxcp.x11.examples.xproto;

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

import java.io.IOException;

public class CreateGCExample {
public static void main(String... args) throws IOException, InterruptedException {
try (var client = X11Client.connect()) {
var wid = client.createSimpleWindow(0, 0, 150, 150);
var gc = client.createGC(client.getDefaultScreenNumber(), wid);
client.sync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.moaxcp.x11.examples.xproto;

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

import java.io.IOException;

import static java.lang.Thread.sleep;

public class CreateWindow {
public static void main(String... args) throws IOException, InterruptedException {
try (var client = X11Client.connect()) {
var wid = client.createSimpleWindow(0, 0, 150, 150);
client.mapWindow(wid);
client.sync();
sleep(10_000);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.github.moaxcp.x11.examples.xproto;


import com.github.moaxcp.x11.protocol.XEvent;
import com.github.moaxcp.x11.protocol.xproto.*;
import com.github.moaxcp.x11.x11client.X11Client;

import java.awt.*;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Random;

import static com.github.moaxcp.x11.protocol.xproto.EventMask.*;

public class DisplayEventsExample {

public static short WIDTH = (short) 1200;
public static short HEIGHT = (short) 1000;

public static void main(String... args) {
var random = new Random();
try(X11Client client = X11Client.connect()) {
int wid = client.createSimpleWindow((short) 10, (short) 10, WIDTH, HEIGHT,
EXPOSURE, NO_EVENT, KEY_PRESS, KEY_RELEASE, BUTTON_PRESS, BUTTON_RELEASE,ENTER_WINDOW, LEAVE_WINDOW,
POINTER_MOTION, POINTER_MOTION_HINT, BUTTON1_MOTION, BUTTON2_MOTION, BUTTON3_MOTION, BUTTON4_MOTION,
BUTTON5_MOTION, BUTTON_MOTION, KEYMAP_STATE, VISIBILITY_CHANGE, STRUCTURE_NOTIFY, RESIZE_REDIRECT,
SUBSTRUCTURE_NOTIFY, SUBSTRUCTURE_REDIRECT, FOCUS_CHANGE, PROPERTY_CHANGE, COLOR_MAP_CHANGE, OWNER_GRAB_BUTTON);
client.storeName(wid, "Expose Window");
int deleteAtom = client.getAtom("WM_DELETE_WINDOW").getId();
client.setWMProtocols(wid, deleteAtom);
client.mapWindow(wid);
int black = client.nextResourceId();
client.send(CreateGC.builder()
.cid(black)
.drawable(wid)
.fillStyle(FillStyle.TILED)
.lineStyle(LineStyle.SOLID)
.lineWidth(1)
.capStyle(CapStyle.BUTT)
.joinStyle(JoinStyle.MITER)
.background(new Color(random.nextInt(128, 255), random.nextInt(120, 255), random.nextInt(128, 255)).getRGB())
.foreground(client.getBlackPixel(0))
.build());
int fill = client.nextResourceId();
client.send(CreateGC.builder()
.cid(fill)
.drawable(wid)
.fillStyle(FillStyle.TILED)
.lineStyle(LineStyle.SOLID)
.lineWidth(10)
.capStyle(CapStyle.BUTT)
.joinStyle(JoinStyle.MITER)
.foreground(new Color(random.nextInt(128, 255), random.nextInt(120, 255), random.nextInt(128, 255)).getRGB())
.background(client.getBlackPixel(0))
.build());
var eventString = "";
while(true) {
XEvent event = client.getNextEvent();
System.out.println(event);
if(event instanceof ExposeEvent exposeEvent) {
client.fillRectangle(wid, fill, (short) 0, (short) 0, exposeEvent.getWidth(), exposeEvent.getHeight());
client.imageText8(wid, black, (short) 0, (short) 10, eventString);
client.imageText8(wid, black, (short) 0, (short) 30, event.toString());
} else if(event instanceof ClientMessageEvent) {
eventString = event.toString();
client.exposeWindow(wid);
ClientMessageEvent clientMessage = (ClientMessageEvent) event;
if(clientMessage.getFormat() == 32) {
ClientMessageData32 data = (ClientMessageData32) clientMessage.getData();
if(data.getData32().get(0) == deleteAtom) {
break;
}
}
} else {
eventString = event.toString();
client.exposeWindow(wid);
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.moaxcp.x11.examples.xproto;

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

import java.io.IOException;

import static com.github.moaxcp.x11.protocol.xproto.EventMask.BUTTON_PRESS;
import static com.github.moaxcp.x11.protocol.xproto.EventMask.EXPOSURE;

public class EventsExample {
public static void main(String... args) throws IOException {
try (var client = X11Client.connect()) {
var wid = client.createSimpleWindow(0, 0, 150, 150, EXPOSURE, BUTTON_PRESS);
client.sync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.github.moaxcp.x11.examples.xproto;


import com.github.moaxcp.x11.protocol.XEvent;
import com.github.moaxcp.x11.protocol.xproto.*;
import com.github.moaxcp.x11.x11client.X11Client;

import java.awt.*;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Random;

public interface ExposeWindow {

short WIDTH = (short) 1200;
short HEIGHT = (short) 1000;

default void start() {
var random = new Random();
try(X11Client client = X11Client.connect()) {
int wid = client.createSimpleWindow((short) 10, (short) 10, WIDTH, HEIGHT, EventMask.EXPOSURE);
client.storeName(wid, "Expose Window");
int deleteAtom = client.getAtom("WM_DELETE_WINDOW").getId();
client.setWMProtocols(wid, deleteAtom);
client.mapWindow(wid);
int lineGc = client.nextResourceId();
client.send(CreateGC.builder()
.cid(lineGc)
.drawable(wid)
.fillStyle(FillStyle.TILED)
.lineStyle(LineStyle.SOLID)
.lineWidth(1)
.capStyle(CapStyle.BUTT)
.joinStyle(JoinStyle.MITER)
.background(new Color(random.nextInt(128, 255), random.nextInt(120, 255), random.nextInt(128, 255)).getRGB())
.foreground(client.getBlackPixel(0))
.build());
int fillGc = client.nextResourceId();
client.send(CreateGC.builder()
.cid(fillGc)
.drawable(wid)
.fillStyle(FillStyle.TILED)
.lineStyle(LineStyle.SOLID)
.lineWidth(10)
.capStyle(CapStyle.BUTT)
.joinStyle(JoinStyle.MITER)
.foreground(new Color(random.nextInt(128, 255), random.nextInt(120, 255), random.nextInt(128, 255)).getRGB())
.background(client.getBlackPixel(0))
.build());
while(true) {
XEvent event = client.getNextEvent();
if(event instanceof ExposeEvent) {
expose(client, wid, lineGc, fillGc);
} else if(event instanceof KeyPressEvent) {
break;
} else if(event instanceof ClientMessageEvent) {
ClientMessageEvent clientMessage = (ClientMessageEvent) event;
if(clientMessage.getFormat() == 32) {
ClientMessageData32 data = (ClientMessageData32) clientMessage.getData();
if(data.getData32().get(0) == deleteAtom) {
break;
}
}
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

void expose(X11Client client, int wid, int lineGc, int fillGc);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.moaxcp.x11.examples.xproto;

import com.github.moaxcp.x11.protocol.xproto.CoordMode;
import com.github.moaxcp.x11.protocol.xproto.Point;
import com.github.moaxcp.x11.protocol.xproto.PolyShape;

import java.util.ArrayList;
import java.util.Random;

import static com.github.moaxcp.x11.examples.xproto.ExposeWindow.HEIGHT;
import static com.github.moaxcp.x11.examples.xproto.ExposeWindow.WIDTH;

public class FillPolyWindow {
public static void main(String... args) {
var points = new ArrayList<Point>();
var random = new Random();
points.add(Point.builder().x((short) random.nextInt(10, WIDTH / 2)).y((short) random.nextInt(10, HEIGHT / 2)).build());
points.add(Point.builder().x((short) random.nextInt(WIDTH / 2, WIDTH - 10)).y((short) random.nextInt(10, HEIGHT / 2)).build());
points.add(Point.builder().x((short) random.nextInt(WIDTH / 2, WIDTH - 10)).y((short) random.nextInt(HEIGHT / 2, HEIGHT -10)).build());
points.add(Point.builder().x((short) random.nextInt(10, WIDTH / 2)).y((short) random.nextInt(HEIGHT / 2, HEIGHT - 10)).build());
points.add(points.get(0));
ExposeWindow main = (client, wid, lineGc, fillGc) -> {
client.fillPoly(wid, fillGc, PolyShape.CONVEX, CoordMode.ORIGIN, points);
client.polyLine(wid, lineGc, CoordMode.ORIGIN, points);
};
main.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.moaxcp.x11.examples.xproto;

public class ImageText16Window {
public static void main(String... args) {
ExposeWindow main = (client, wid, lineGc, fillGc) -> client.imageText16(wid, lineGc, (short) 0, (short) 10, "Hello World!");
main.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.moaxcp.x11.examples.xproto;

public class ImageText8Window {
public static void main(String... args) {
ExposeWindow main = (client, wid, lineGc, fillGc) -> client.imageText8(wid, lineGc, (short) 0, (short) 10, "Hello World!");
main.start();
}
}
Loading

0 comments on commit 1b17fbe

Please sign in to comment.