com.github.moaxcp.x11client.protocol.screensaver.SetAttributes 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.screensaver;
import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import com.github.moaxcp.x11client.protocol.xproto.BackingStore;
import com.github.moaxcp.x11client.protocol.xproto.Cw;
import com.github.moaxcp.x11client.protocol.xproto.EventMask;
import com.github.moaxcp.x11client.protocol.xproto.Gravity;
import com.github.moaxcp.x11client.protocol.xproto.WindowClass;
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 SetAttributes implements OneWayRequest {
public static final byte OPCODE = 3;
private int drawable;
private short x;
private short y;
private short width;
private short height;
private short borderWidth;
private byte clazz;
private byte depth;
private int visual;
private int valueMask;
private int backgroundPixmap;
private int backgroundPixel;
private int borderPixmap;
private int borderPixel;
private int bitGravity;
private int winGravity;
private int backingStore;
private int backingPlanes;
private int backingPixel;
private int overrideRedirect;
private int saveUnder;
private int eventMask;
private int doNotPropogateMask;
private int colormap;
private int cursor;
public byte getOpCode() {
return OPCODE;
}
public static SetAttributes readSetAttributes(X11Input in) throws IOException {
in.readPad(1);
short length = in.readCard16();
int drawable = in.readCard32();
short x = in.readInt16();
short y = in.readInt16();
short width = in.readCard16();
short height = in.readCard16();
short borderWidth = in.readCard16();
byte clazz = in.readByte();
byte depth = in.readCard8();
int visual = in.readCard32();
int valueMask = in.readCard32();
SetAttributes.SetAttributesBuilder javaBuilder = SetAttributes.builder();
javaBuilder.drawable(drawable);
javaBuilder.x(x);
javaBuilder.y(y);
javaBuilder.width(width);
javaBuilder.height(height);
javaBuilder.borderWidth(borderWidth);
javaBuilder.clazz(clazz);
javaBuilder.depth(depth);
javaBuilder.visual(visual);
javaBuilder.valueMask(valueMask);
if(javaBuilder.isValueMaskEnabled(Cw.BACK_PIXMAP)) {
javaBuilder.backgroundPixmap(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BACK_PIXEL)) {
javaBuilder.backgroundPixel(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BORDER_PIXMAP)) {
javaBuilder.borderPixmap(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BORDER_PIXEL)) {
javaBuilder.borderPixel(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BIT_GRAVITY)) {
javaBuilder.bitGravity(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.WIN_GRAVITY)) {
javaBuilder.winGravity(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BACKING_STORE)) {
javaBuilder.backingStore(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BACKING_PLANES)) {
javaBuilder.backingPlanes(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.BACKING_PIXEL)) {
javaBuilder.backingPixel(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.OVERRIDE_REDIRECT)) {
javaBuilder.overrideRedirect(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.SAVE_UNDER)) {
javaBuilder.saveUnder(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.EVENT_MASK)) {
javaBuilder.eventMask(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.DONT_PROPAGATE)) {
javaBuilder.doNotPropogateMask(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.COLORMAP)) {
javaBuilder.colormap(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Cw.CURSOR)) {
javaBuilder.cursor(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(drawable);
out.writeInt16(x);
out.writeInt16(y);
out.writeCard16(width);
out.writeCard16(height);
out.writeCard16(borderWidth);
out.writeByte(clazz);
out.writeCard8(depth);
out.writeCard32(visual);
out.writeCard32(valueMask);
if(isValueMaskEnabled(Cw.BACK_PIXMAP)) {
out.writeCard32(backgroundPixmap);
}
if(isValueMaskEnabled(Cw.BACK_PIXEL)) {
out.writeCard32(backgroundPixel);
}
if(isValueMaskEnabled(Cw.BORDER_PIXMAP)) {
out.writeCard32(borderPixmap);
}
if(isValueMaskEnabled(Cw.BORDER_PIXEL)) {
out.writeCard32(borderPixel);
}
if(isValueMaskEnabled(Cw.BIT_GRAVITY)) {
out.writeCard32(bitGravity);
}
if(isValueMaskEnabled(Cw.WIN_GRAVITY)) {
out.writeCard32(winGravity);
}
if(isValueMaskEnabled(Cw.BACKING_STORE)) {
out.writeCard32(backingStore);
}
if(isValueMaskEnabled(Cw.BACKING_PLANES)) {
out.writeCard32(backingPlanes);
}
if(isValueMaskEnabled(Cw.BACKING_PIXEL)) {
out.writeCard32(backingPixel);
}
if(isValueMaskEnabled(Cw.OVERRIDE_REDIRECT)) {
out.writeCard32(overrideRedirect);
}
if(isValueMaskEnabled(Cw.SAVE_UNDER)) {
out.writeCard32(saveUnder);
}
if(isValueMaskEnabled(Cw.EVENT_MASK)) {
out.writeCard32(eventMask);
}
if(isValueMaskEnabled(Cw.DONT_PROPAGATE)) {
out.writeCard32(doNotPropogateMask);
}
if(isValueMaskEnabled(Cw.COLORMAP)) {
out.writeCard32(colormap);
}
if(isValueMaskEnabled(Cw.CURSOR)) {
out.writeCard32(cursor);
}
out.writePadAlign(getSize());
}
public boolean isValueMaskEnabled(@NonNull Cw... maskEnums) {
for(Cw m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
public boolean isEventMaskEnabled(@NonNull EventMask... maskEnums) {
for(EventMask m : maskEnums) {
if(!m.isEnabled(eventMask)) {
return false;
}
}
return true;
}
public boolean isDoNotPropogateMaskEnabled(@NonNull EventMask... maskEnums) {
for(EventMask m : maskEnums) {
if(!m.isEnabled(doNotPropogateMask)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 28 + (isValueMaskEnabled(Cw.BACK_PIXMAP) ? 4 : 0) + (isValueMaskEnabled(Cw.BACK_PIXEL) ? 4 : 0) + (isValueMaskEnabled(Cw.BORDER_PIXMAP) ? 4 : 0) + (isValueMaskEnabled(Cw.BORDER_PIXEL) ? 4 : 0) + (isValueMaskEnabled(Cw.BIT_GRAVITY) ? 4 : 0) + (isValueMaskEnabled(Cw.WIN_GRAVITY) ? 4 : 0) + (isValueMaskEnabled(Cw.BACKING_STORE) ? 4 : 0) + (isValueMaskEnabled(Cw.BACKING_PLANES) ? 4 : 0) + (isValueMaskEnabled(Cw.BACKING_PIXEL) ? 4 : 0) + (isValueMaskEnabled(Cw.OVERRIDE_REDIRECT) ? 4 : 0) + (isValueMaskEnabled(Cw.SAVE_UNDER) ? 4 : 0) + (isValueMaskEnabled(Cw.EVENT_MASK) ? 4 : 0) + (isValueMaskEnabled(Cw.DONT_PROPAGATE) ? 4 : 0) + (isValueMaskEnabled(Cw.COLORMAP) ? 4 : 0) + (isValueMaskEnabled(Cw.CURSOR) ? 4 : 0);
}
public static class SetAttributesBuilder {
public SetAttributes.SetAttributesBuilder clazz(WindowClass clazz) {
this.clazz = (byte) clazz.getValue();
return this;
}
public SetAttributes.SetAttributesBuilder clazz(byte clazz) {
this.clazz = clazz;
return this;
}
private SetAttributes.SetAttributesBuilder valueMask(int valueMask) {
this.valueMask = valueMask;
return this;
}
public boolean isValueMaskEnabled(@NonNull Cw... maskEnums) {
for(Cw m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
private SetAttributes.SetAttributesBuilder valueMaskEnable(Cw... maskEnums) {
for(Cw m : maskEnums) {
valueMask((int) m.enableFor(valueMask));
}
return this;
}
private SetAttributes.SetAttributesBuilder valueMaskDisable(Cw... maskEnums) {
for(Cw m : maskEnums) {
valueMask((int) m.disableFor(valueMask));
}
return this;
}
public SetAttributes.SetAttributesBuilder backgroundPixmap(int backgroundPixmap) {
this.backgroundPixmap = backgroundPixmap;
valueMaskEnable(Cw.BACK_PIXMAP);
return this;
}
public SetAttributes.SetAttributesBuilder backgroundPixel(int backgroundPixel) {
this.backgroundPixel = backgroundPixel;
valueMaskEnable(Cw.BACK_PIXEL);
return this;
}
public SetAttributes.SetAttributesBuilder borderPixmap(int borderPixmap) {
this.borderPixmap = borderPixmap;
valueMaskEnable(Cw.BORDER_PIXMAP);
return this;
}
public SetAttributes.SetAttributesBuilder borderPixel(int borderPixel) {
this.borderPixel = borderPixel;
valueMaskEnable(Cw.BORDER_PIXEL);
return this;
}
public SetAttributes.SetAttributesBuilder bitGravity(int bitGravity) {
this.bitGravity = bitGravity;
valueMaskEnable(Cw.BIT_GRAVITY);
return this;
}
public SetAttributes.SetAttributesBuilder bitGravity(Gravity bitGravity) {
this.bitGravity = (int) bitGravity.getValue();
valueMaskEnable(Cw.BIT_GRAVITY);
return this;
}
public SetAttributes.SetAttributesBuilder winGravity(int winGravity) {
this.winGravity = winGravity;
valueMaskEnable(Cw.WIN_GRAVITY);
return this;
}
public SetAttributes.SetAttributesBuilder winGravity(Gravity winGravity) {
this.winGravity = (int) winGravity.getValue();
valueMaskEnable(Cw.WIN_GRAVITY);
return this;
}
public SetAttributes.SetAttributesBuilder backingStore(int backingStore) {
this.backingStore = backingStore;
valueMaskEnable(Cw.BACKING_STORE);
return this;
}
public SetAttributes.SetAttributesBuilder backingStore(BackingStore backingStore) {
this.backingStore = (int) backingStore.getValue();
valueMaskEnable(Cw.BACKING_STORE);
return this;
}
public SetAttributes.SetAttributesBuilder backingPlanes(int backingPlanes) {
this.backingPlanes = backingPlanes;
valueMaskEnable(Cw.BACKING_PLANES);
return this;
}
public SetAttributes.SetAttributesBuilder backingPixel(int backingPixel) {
this.backingPixel = backingPixel;
valueMaskEnable(Cw.BACKING_PIXEL);
return this;
}
public SetAttributes.SetAttributesBuilder overrideRedirect(int overrideRedirect) {
this.overrideRedirect = overrideRedirect;
valueMaskEnable(Cw.OVERRIDE_REDIRECT);
return this;
}
public SetAttributes.SetAttributesBuilder saveUnder(int saveUnder) {
this.saveUnder = saveUnder;
valueMaskEnable(Cw.SAVE_UNDER);
return this;
}
public SetAttributes.SetAttributesBuilder eventMask(int eventMask) {
this.eventMask = eventMask;
valueMaskEnable(Cw.EVENT_MASK);
return this;
}
public boolean isEventMaskEnabled(@NonNull EventMask... maskEnums) {
for(EventMask m : maskEnums) {
if(!m.isEnabled(eventMask)) {
return false;
}
}
return true;
}
public SetAttributes.SetAttributesBuilder eventMaskEnable(EventMask... maskEnums) {
for(EventMask m : maskEnums) {
eventMask((int) m.enableFor(eventMask));
}
return this;
}
public SetAttributes.SetAttributesBuilder eventMaskDisable(EventMask... maskEnums) {
for(EventMask m : maskEnums) {
eventMask((int) m.disableFor(eventMask));
}
return this;
}
public SetAttributes.SetAttributesBuilder doNotPropogateMask(int doNotPropogateMask) {
this.doNotPropogateMask = doNotPropogateMask;
valueMaskEnable(Cw.DONT_PROPAGATE);
return this;
}
public boolean isDoNotPropogateMaskEnabled(@NonNull EventMask... maskEnums) {
for(EventMask m : maskEnums) {
if(!m.isEnabled(doNotPropogateMask)) {
return false;
}
}
return true;
}
public SetAttributes.SetAttributesBuilder doNotPropogateMaskEnable(EventMask... maskEnums) {
for(EventMask m : maskEnums) {
doNotPropogateMask((int) m.enableFor(doNotPropogateMask));
}
return this;
}
public SetAttributes.SetAttributesBuilder doNotPropogateMaskDisable(EventMask... maskEnums) {
for(EventMask m : maskEnums) {
doNotPropogateMask((int) m.disableFor(doNotPropogateMask));
}
return this;
}
public SetAttributes.SetAttributesBuilder colormap(int colormap) {
this.colormap = colormap;
valueMaskEnable(Cw.COLORMAP);
return this;
}
public SetAttributes.SetAttributesBuilder cursor(int cursor) {
this.cursor = cursor;
valueMaskEnable(Cw.CURSOR);
return this;
}
public int getSize() {
return 28 + (isValueMaskEnabled(Cw.BACK_PIXMAP) ? 4 : 0) + (isValueMaskEnabled(Cw.BACK_PIXEL) ? 4 : 0) + (isValueMaskEnabled(Cw.BORDER_PIXMAP) ? 4 : 0) + (isValueMaskEnabled(Cw.BORDER_PIXEL) ? 4 : 0) + (isValueMaskEnabled(Cw.BIT_GRAVITY) ? 4 : 0) + (isValueMaskEnabled(Cw.WIN_GRAVITY) ? 4 : 0) + (isValueMaskEnabled(Cw.BACKING_STORE) ? 4 : 0) + (isValueMaskEnabled(Cw.BACKING_PLANES) ? 4 : 0) + (isValueMaskEnabled(Cw.BACKING_PIXEL) ? 4 : 0) + (isValueMaskEnabled(Cw.OVERRIDE_REDIRECT) ? 4 : 0) + (isValueMaskEnabled(Cw.SAVE_UNDER) ? 4 : 0) + (isValueMaskEnabled(Cw.EVENT_MASK) ? 4 : 0) + (isValueMaskEnabled(Cw.DONT_PROPAGATE) ? 4 : 0) + (isValueMaskEnabled(Cw.COLORMAP) ? 4 : 0) + (isValueMaskEnabled(Cw.CURSOR) ? 4 : 0);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy