com.github.moaxcp.x11client.experimental.Window Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x11-client Show documentation
Show all versions of x11-client Show documentation
An x11 client implemented in java
package com.github.moaxcp.x11client.experimental;
import com.github.moaxcp.x11client.protocol.xproto.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import lombok.Getter;
@Getter
public class Window extends Drawable {
private byte depth;
private int parent;
private short borderWidth;
private WindowClass clazz;
private int visual;
private int backgroundPixel;
private int borderPixel;
private List> exposeEventConsumers = new ArrayList<>();
private List> keyPressEventConsumers = new ArrayList<>();
Window(Display display, int screen, short x, short y, short width, short height) {
super(display, screen, x, y, width, height);
depth = display.getDepth(screen);
parent = display.getRoot(screen);
this.borderWidth = 0;
clazz = WindowClass.COPY_FROM_PARENT;
visual = display.getVisualId(screen);
backgroundPixel = display.getWhitePixel(screen);
borderPixel = display.getBlackPixel(screen);
display.send(CreateWindow.builder()
.depth(depth)
.wid(getId())
.parent(parent)
.x(x)
.y(y)
.width(width)
.height(height)
.borderWidth(borderWidth)
.clazz(clazz)
.visual(visual)
.backgroundPixel(backgroundPixel)
.borderPixel(borderPixel)
.eventMaskEnable(EventMask.EXPOSURE)
.eventMaskEnable(EventMask.KEY_PRESS)
.build());
}
public void map() {
display.send(MapWindow.builder()
.window(getId())
.build());
}
@Override
public void close() {
super.close();
display.send(DestroyWindow.builder()
.window(getId())
.build());
keyPressEventConsumers.clear();
exposeEventConsumers.clear();
}
void exposeEvent(ExposeEvent event) {
for(BiConsumer consumer : exposeEventConsumers) {
consumer.accept(this, event);
}
}
void keyPressEvent(KeyPressEvent event) {
for(BiConsumer consumer : keyPressEventConsumers) {
consumer.accept(this, event);
}
}
public void exposeEvent(BiConsumer consumer) {
exposeEventConsumers.add(consumer);
}
public void keyPressEvent(BiConsumer consumer) {
keyPressEventConsumers.add(consumer);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy