summaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/mossbar/concepts/Bar.java
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-02 23:36:30 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-02 23:36:30 +0200
commit1eae252f41eab7612864fb479263dc93310d8930 (patch)
treeb10172d42668cb8b5199565c0e2eee4ac3e9c5c3 /src/main/java/moe/nea/mossbar/concepts/Bar.java
downloadmossbar-1eae252f41eab7612864fb479263dc93310d8930.tar.gz
mossbar-1eae252f41eab7612864fb479263dc93310d8930.tar.bz2
mossbar-1eae252f41eab7612864fb479263dc93310d8930.zip
init
Diffstat (limited to 'src/main/java/moe/nea/mossbar/concepts/Bar.java')
-rw-r--r--src/main/java/moe/nea/mossbar/concepts/Bar.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/mossbar/concepts/Bar.java b/src/main/java/moe/nea/mossbar/concepts/Bar.java
new file mode 100644
index 0000000..891b28a
--- /dev/null
+++ b/src/main/java/moe/nea/mossbar/concepts/Bar.java
@@ -0,0 +1,103 @@
+package moe.nea.mossbar.concepts;
+
+import org.freedesktop.wayland.client.*;
+import org.freedesktop.wayland.shared.WlOutputTransform;
+import org.freedesktop.wayland.shared.ZwlrLayerShellV1Layer;
+import org.freedesktop.wayland.shared.ZwlrLayerSurfaceV1Anchor;
+import org.freedesktop.wayland.util.EnumUtil;
+
+import java.io.IOException;
+import java.nio.IntBuffer;
+import java.util.EnumSet;
+
+public class Bar extends Scope {
+ private final Display display;
+ private final WlSurfaceProxy surface;
+ private final ZwlrLayerSurfaceV1Proxy layer;
+ private final ShmBufferPool bufferPool;
+ private WlCallbackProxy callbackProxy;
+
+
+ public Bar(Display display, WlOutputProxy output) {
+ this.display = display;
+ this.surface = display.compositorProxy.createSurface(new WlSurfaceEventsV6() {
+ @Override
+ public void enter(WlSurfaceProxy emitter, WlOutputProxy output) {
+ System.out.println("Surface entered");
+ }
+
+ @Override
+ public void leave(WlSurfaceProxy emitter, WlOutputProxy output) {
+ System.out.println("Left surface");
+ }
+
+ @Override
+ public void preferredBufferScale(WlSurfaceProxy emitter, int factor) {
+ System.out.println("Preferred buffer scale ${factor}");
+ }
+
+ @Override
+ public void preferredBufferTransform(WlSurfaceProxy emitter, int transform) {
+ var transforms = EnumUtil.decode(WlOutputTransform.class, transform);
+ System.out.println("Preferred buffer transform ${transforms}");
+ }
+ }).bindTo(this);
+ this.layer = display.layerShell.getLayerSurface(new ZwlrLayerSurfaceV1EventsV4() {
+ @Override
+ public void configure(ZwlrLayerSurfaceV1Proxy emitter, int serial, int width, int height) {
+ System.out.println("Configure layer ${serial} ${width}x${height}");
+ emitter.ackConfigure(serial);
+ }
+
+ @Override
+ public void closed(ZwlrLayerSurfaceV1Proxy emitter) {
+ System.out.println("layer closed");
+ }
+ }, this.surface, output, ZwlrLayerShellV1Layer.OVERLAY.getValue(), "mossbar")
+ .bindTo(this);
+ int width = 1920;
+ int height = 30;
+ layer.setSize(width, height); // TODO??? this should really not be a hardcoded width
+ layer.setAnchor(EnumUtil.encode(EnumSet.of(ZwlrLayerSurfaceV1Anchor.TOP, ZwlrLayerSurfaceV1Anchor.RIGHT, ZwlrLayerSurfaceV1Anchor.LEFT)));
+ surface.commit();
+ try {
+ bufferPool = ShmBufferPool.newARGBPool(display, width, height, 2);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ display.roundtrip();
+ }
+
+ public void renderOnce() {
+ System.out.println("Rendering");
+ var nextBuffer = bufferPool.poll();
+ assert nextBuffer != null;
+ var pixels = nextBuffer.getByteBuffer().asIntBuffer();
+ fill(pixels, 0xFFFF00A0);
+ surface.attach(nextBuffer.getProxy(), 0, 0);
+ surface.damage(0, 0, nextBuffer.width, nextBuffer.height);
+ queueNextFrame();
+ surface.commit();
+ System.out.println("surface committed");
+ }
+
+ private void queueNextFrame() {
+ if (callbackProxy != null)
+ callbackProxy.destroy();
+ callbackProxy = surface.frame((_, _) -> renderOnce());
+ }
+
+ @Override
+ public void closeObject() {
+ callbackProxy.destroy();
+ super.closeObject();
+ }
+
+ private static void fill(IntBuffer buffer, int value) {
+ buffer.clear();
+ buffer.limit(buffer.capacity());
+ while (buffer.hasRemaining()) {
+ buffer.put(value);
+ }
+ }
+}