diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-07-03 00:07:42 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-07-03 00:07:42 +0200 |
| commit | a6e9cd2aef129e71479800a8dfaec05b3d38d20e (patch) | |
| tree | 57b63239d0c6d6a579d5089eaee9b14e23354f79 | |
| parent | 1eae252f41eab7612864fb479263dc93310d8930 (diff) | |
| download | mossbar-a6e9cd2aef129e71479800a8dfaec05b3d38d20e.tar.gz mossbar-a6e9cd2aef129e71479800a8dfaec05b3d38d20e.tar.bz2 mossbar-a6e9cd2aef129e71479800a8dfaec05b3d38d20e.zip | |
feat: Adjust to screen size
| -rw-r--r-- | src/main/java/moe/nea/mossbar/concepts/Bar.java | 12 | ||||
| -rw-r--r-- | src/main/java/moe/nea/mossbar/concepts/Display.java | 20 | ||||
| -rw-r--r-- | src/main/java/moe/nea/mossbar/concepts/Output.java | 50 |
3 files changed, 61 insertions, 21 deletions
diff --git a/src/main/java/moe/nea/mossbar/concepts/Bar.java b/src/main/java/moe/nea/mossbar/concepts/Bar.java index 891b28a..7ce6591 100644 --- a/src/main/java/moe/nea/mossbar/concepts/Bar.java +++ b/src/main/java/moe/nea/mossbar/concepts/Bar.java @@ -17,8 +17,7 @@ public class Bar extends Scope { private final ShmBufferPool bufferPool; private WlCallbackProxy callbackProxy; - - public Bar(Display display, WlOutputProxy output) { + public Bar(Display display, Output output) { this.display = display; this.surface = display.compositorProxy.createSurface(new WlSurfaceEventsV6() { @Override @@ -53,12 +52,15 @@ public class Bar extends Scope { public void closed(ZwlrLayerSurfaceV1Proxy emitter) { System.out.println("layer closed"); } - }, this.surface, output, ZwlrLayerShellV1Layer.OVERLAY.getValue(), "mossbar") + }, this.surface, output.proxy, ZwlrLayerShellV1Layer.OVERLAY.getValue(), "mossbar") .bindTo(this); - int width = 1920; + if (output.width <= 0) + throw new IllegalStateException("Monitor with 0 sized output"); + int width = output.width; 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))); + layer.setExclusiveZone(height); surface.commit(); try { bufferPool = ShmBufferPool.newARGBPool(display, width, height, 2); @@ -69,7 +71,6 @@ public class Bar extends Scope { } public void renderOnce() { - System.out.println("Rendering"); var nextBuffer = bufferPool.poll(); assert nextBuffer != null; var pixels = nextBuffer.getByteBuffer().asIntBuffer(); @@ -78,7 +79,6 @@ public class Bar extends Scope { surface.damage(0, 0, nextBuffer.width, nextBuffer.height); queueNextFrame(); surface.commit(); - System.out.println("surface committed"); } private void queueNextFrame() { diff --git a/src/main/java/moe/nea/mossbar/concepts/Display.java b/src/main/java/moe/nea/mossbar/concepts/Display.java index 0234739..1166f13 100644 --- a/src/main/java/moe/nea/mossbar/concepts/Display.java +++ b/src/main/java/moe/nea/mossbar/concepts/Display.java @@ -14,12 +14,13 @@ import java.util.Objects; public class Display extends Scope { private final WlDisplayProxy proxy; - private final WlRegistryProxy registry; + @get + final WlRegistryProxy registry; private int shmFormat = 0; private WlCompositorProxy compositorProxy; - private final List<WlOutputProxy> outputs = new ArrayList<>(); + private final List<Output> outputs = new ArrayList<Output>(); - public List<WlOutputProxy> getOutputs() { + public List<Output> getOutputs() { return outputs; } @@ -96,18 +97,7 @@ public class Display extends Scope { case ZwlrLayerShellV1Proxy.INTERFACE_NAME -> Display.this.layerShell = bind(name, ZwlrLayerShellV1Proxy.class, ZwlrLayerShellV1EventsV4.VERSION, new ZwlrLayerShellV1EventsV4() { }); - case WlOutputProxy.INTERFACE_NAME -> - outputs.add(bind(name, WlOutputProxy.class, WlOutputEvents.VERSION, new WlOutputEvents() { - @Override - public void geometry(WlOutputProxy emitter, int x, int y, int physicalWidth, int physicalHeight, int subpixel, String make, String model, int transform) { - - } - - @Override - public void mode(WlOutputProxy emitter, int flags, int width, int height, int refresh) { - - } - })); + case WlOutputProxy.INTERFACE_NAME -> outputs.add(new Output(this, name).bindTo(this)); case WlSeatProxy.INTERFACE_NAME -> Display.this.seatProxy = bind(name, WlSeatProxy.class, WlSeatEventsV3.VERSION, new WlSeatEventsV3() { @Override diff --git a/src/main/java/moe/nea/mossbar/concepts/Output.java b/src/main/java/moe/nea/mossbar/concepts/Output.java new file mode 100644 index 0000000..472dfce --- /dev/null +++ b/src/main/java/moe/nea/mossbar/concepts/Output.java @@ -0,0 +1,50 @@ +package moe.nea.mossbar.concepts; + +import org.freedesktop.wayland.client.WlOutputEvents; +import org.freedesktop.wayland.client.WlOutputProxy; +import org.freedesktop.wayland.shared.WlOutputMode; +import org.freedesktop.wayland.util.EnumUtil; + +import java.util.EnumSet; + +public class Output extends Scope implements WlOutputEvents { + private final WlOutputProxy proxy; + int width = -1, height = -1; + EnumSet<WlOutputMode> flags; + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public EnumSet<WlOutputMode> getFlags() { + return flags; + } + + public Output(Display display, int name) { + proxy = display.registry.bind(name, WlOutputProxy.class, WlOutputEvents.VERSION, this).bindTo(this); + } + + @Override + public void geometry(WlOutputProxy emitter, int x, int y, int physicalWidth, int physicalHeight, int subpixel, String make, String model, int transform) { + System.out.println("${make} ${model} is at $x,$y ${physicalWidth}x${physicalHeight}"); + } + + @Override + public void mode(WlOutputProxy emitter, int flags, int width, int height, int refresh) { + var encodedFlags = EnumUtil.decode(WlOutputMode.class, flags); + if (encodedFlags.contains(WlOutputMode.CURRENT)) { + this.width = width; + this.height = height; + this.flags = encodedFlags; + } + System.out.println("mode ${width}x${height} ${this.flags}"); + } + + public WlOutputProxy getProxy() { + return proxy; + } +} |
