com.github.moaxcp.x11client.protocol.xproto.ConfigureWindow 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.protocol.xproto;
import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Override;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@Value
@Builder
public class ConfigureWindow implements OneWayRequest {
public static final byte OPCODE = 12;
private int window;
private short valueMask;
private int x;
private int y;
private int width;
private int height;
private int borderWidth;
private int sibling;
private int stackMode;
public byte getOpCode() {
return OPCODE;
}
public static ConfigureWindow readConfigureWindow(X11Input in) throws IOException {
in.readPad(1);
short length = in.readCard16();
int window = in.readCard32();
short valueMask = in.readCard16();
in.readPad(2);
ConfigureWindow.ConfigureWindowBuilder javaBuilder = ConfigureWindow.builder();
javaBuilder.window(window);
javaBuilder.valueMask(valueMask);
if(javaBuilder.isValueMaskEnabled(ConfigWindow.X)) {
javaBuilder.x(in.readInt32());
}
if(javaBuilder.isValueMaskEnabled(ConfigWindow.Y)) {
javaBuilder.y(in.readInt32());
}
if(javaBuilder.isValueMaskEnabled(ConfigWindow.WIDTH)) {
javaBuilder.width(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(ConfigWindow.HEIGHT)) {
javaBuilder.height(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(ConfigWindow.BORDER_WIDTH)) {
javaBuilder.borderWidth(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(ConfigWindow.SIBLING)) {
javaBuilder.sibling(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(ConfigWindow.STACK_MODE)) {
javaBuilder.stackMode(in.readCard32());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}
@Override
public void write(byte offset, X11Output out) throws IOException {
out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE) + Byte.toUnsignedInt(offset)));
out.writePad(1);
out.writeCard16((short) getLength());
out.writeCard32(window);
out.writeCard16(valueMask);
out.writePad(2);
if(isValueMaskEnabled(ConfigWindow.X)) {
out.writeInt32(x);
}
if(isValueMaskEnabled(ConfigWindow.Y)) {
out.writeInt32(y);
}
if(isValueMaskEnabled(ConfigWindow.WIDTH)) {
out.writeCard32(width);
}
if(isValueMaskEnabled(ConfigWindow.HEIGHT)) {
out.writeCard32(height);
}
if(isValueMaskEnabled(ConfigWindow.BORDER_WIDTH)) {
out.writeCard32(borderWidth);
}
if(isValueMaskEnabled(ConfigWindow.SIBLING)) {
out.writeCard32(sibling);
}
if(isValueMaskEnabled(ConfigWindow.STACK_MODE)) {
out.writeCard32(stackMode);
}
out.writePadAlign(getSize());
}
public boolean isValueMaskEnabled(@NonNull ConfigWindow... maskEnums) {
for(ConfigWindow m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 12 + (isValueMaskEnabled(ConfigWindow.X) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.Y) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.WIDTH) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.HEIGHT) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.BORDER_WIDTH) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.SIBLING) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.STACK_MODE) ? 4 : 0);
}
public static class ConfigureWindowBuilder {
private ConfigureWindow.ConfigureWindowBuilder valueMask(short valueMask) {
this.valueMask = valueMask;
return this;
}
public boolean isValueMaskEnabled(@NonNull ConfigWindow... maskEnums) {
for(ConfigWindow m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
private ConfigureWindow.ConfigureWindowBuilder valueMaskEnable(ConfigWindow... maskEnums) {
for(ConfigWindow m : maskEnums) {
valueMask((short) m.enableFor(valueMask));
}
return this;
}
private ConfigureWindow.ConfigureWindowBuilder valueMaskDisable(ConfigWindow... maskEnums) {
for(ConfigWindow m : maskEnums) {
valueMask((short) m.disableFor(valueMask));
}
return this;
}
public ConfigureWindow.ConfigureWindowBuilder x(int x) {
this.x = x;
valueMaskEnable(ConfigWindow.X);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder y(int y) {
this.y = y;
valueMaskEnable(ConfigWindow.Y);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder width(int width) {
this.width = width;
valueMaskEnable(ConfigWindow.WIDTH);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder height(int height) {
this.height = height;
valueMaskEnable(ConfigWindow.HEIGHT);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder borderWidth(int borderWidth) {
this.borderWidth = borderWidth;
valueMaskEnable(ConfigWindow.BORDER_WIDTH);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder sibling(int sibling) {
this.sibling = sibling;
valueMaskEnable(ConfigWindow.SIBLING);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder stackMode(int stackMode) {
this.stackMode = stackMode;
valueMaskEnable(ConfigWindow.STACK_MODE);
return this;
}
public ConfigureWindow.ConfigureWindowBuilder stackMode(StackMode stackMode) {
this.stackMode = (int) stackMode.getValue();
valueMaskEnable(ConfigWindow.STACK_MODE);
return this;
}
public int getSize() {
return 12 + (isValueMaskEnabled(ConfigWindow.X) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.Y) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.WIDTH) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.HEIGHT) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.BORDER_WIDTH) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.SIBLING) ? 4 : 0) + (isValueMaskEnabled(ConfigWindow.STACK_MODE) ? 4 : 0);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy