-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for no-sequence-number in KeymapNotifyEvent I suspect t…
…his also fixed the RecordApiExample. Added examples.
- Loading branch information
Showing
42 changed files
with
1,171 additions
and
329 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...om/github/moaxcp/x11/examples/Record.java → ...ub/moaxcp/x11/examples/record/Record.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/ChangeEventsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/CombinedWindow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/Connect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/CreateGCExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/CreateWindow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/DisplayEventsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
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.setWindowName(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 = ""; | ||
var width = WIDTH; | ||
var height = HEIGHT; | ||
while(true) { | ||
XEvent event = client.getNextEvent(); | ||
System.out.println(event); | ||
if(event instanceof ExposeEvent exposeEvent) { | ||
client.fillRectangle(wid, fill, (short) 0, (short) 0, width, height); | ||
client.imageText8(wid, black, (short) 0, (short) 10, eventString); | ||
client.imageText8(wid, black, (short) 0, (short) 30, event.toString()); | ||
} else if(event instanceof ResizeRequestEvent resize) { | ||
var geometry = client.send(GetGeometry.builder() | ||
.drawable(wid) | ||
.build()); | ||
width = geometry.getWidth(); | ||
height = geometry.getHeight(); | ||
}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); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/EventsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
examples/src/main/java/com/github/moaxcp/x11/examples/xproto/ExposeWindow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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.setWindowName(wid, "Expose Window"); | ||
client.setIconName(wid, "Expose Window (Icon)"); | ||
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); | ||
} |
Oops, something went wrong.