All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.moaxcp.x11client.protocol.xproto.CreateWindow Maven / Gradle / Ivy

There is a newer version: 0.18.2
Show newest version
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 CreateWindow implements OneWayRequest {
  public static final byte OPCODE = 1;

  private byte depth;

  private int wid;

  private int parent;

  private short x;

  private short y;

  private short width;

  private short height;

  private short borderWidth;

  private short clazz;

  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 CreateWindow readCreateWindow(X11Input in) throws IOException {
    byte depth = in.readCard8();
    short length = in.readCard16();
    int wid = in.readCard32();
    int parent = in.readCard32();
    short x = in.readInt16();
    short y = in.readInt16();
    short width = in.readCard16();
    short height = in.readCard16();
    short borderWidth = in.readCard16();
    short clazz = in.readCard16();
    int visual = in.readCard32();
    int valueMask = in.readCard32();
    CreateWindow.CreateWindowBuilder javaBuilder = CreateWindow.builder();
    javaBuilder.depth(depth);
    javaBuilder.wid(wid);
    javaBuilder.parent(parent);
    javaBuilder.x(x);
    javaBuilder.y(y);
    javaBuilder.width(width);
    javaBuilder.height(height);
    javaBuilder.borderWidth(borderWidth);
    javaBuilder.clazz(clazz);
    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.writeCard8(depth);
    out.writeCard16((short) getLength());
    out.writeCard32(wid);
    out.writeCard32(parent);
    out.writeInt16(x);
    out.writeInt16(y);
    out.writeCard16(width);
    out.writeCard16(height);
    out.writeCard16(borderWidth);
    out.writeCard16(clazz);
    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 32 + (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 CreateWindowBuilder {
    public CreateWindow.CreateWindowBuilder clazz(WindowClass clazz) {
      this.clazz = (short) clazz.getValue();
      return this;
    }

    public CreateWindow.CreateWindowBuilder clazz(short clazz) {
      this.clazz = clazz;
      return this;
    }

    private CreateWindow.CreateWindowBuilder 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 CreateWindow.CreateWindowBuilder valueMaskEnable(Cw... maskEnums) {
      for(Cw m : maskEnums) {
        valueMask((int) m.enableFor(valueMask));
      }
      return this;
    }

    private CreateWindow.CreateWindowBuilder valueMaskDisable(Cw... maskEnums) {
      for(Cw m : maskEnums) {
        valueMask((int) m.disableFor(valueMask));
      }
      return this;
    }

    public CreateWindow.CreateWindowBuilder backgroundPixmap(int backgroundPixmap) {
      this.backgroundPixmap = backgroundPixmap;
      valueMaskEnable(Cw.BACK_PIXMAP);
      return this;
    }

    public CreateWindow.CreateWindowBuilder backgroundPixel(int backgroundPixel) {
      this.backgroundPixel = backgroundPixel;
      valueMaskEnable(Cw.BACK_PIXEL);
      return this;
    }

    public CreateWindow.CreateWindowBuilder borderPixmap(int borderPixmap) {
      this.borderPixmap = borderPixmap;
      valueMaskEnable(Cw.BORDER_PIXMAP);
      return this;
    }

    public CreateWindow.CreateWindowBuilder borderPixel(int borderPixel) {
      this.borderPixel = borderPixel;
      valueMaskEnable(Cw.BORDER_PIXEL);
      return this;
    }

    public CreateWindow.CreateWindowBuilder bitGravity(int bitGravity) {
      this.bitGravity = bitGravity;
      valueMaskEnable(Cw.BIT_GRAVITY);
      return this;
    }

    public CreateWindow.CreateWindowBuilder bitGravity(Gravity bitGravity) {
      this.bitGravity = (int) bitGravity.getValue();
      valueMaskEnable(Cw.BIT_GRAVITY);
      return this;
    }

    public CreateWindow.CreateWindowBuilder winGravity(int winGravity) {
      this.winGravity = winGravity;
      valueMaskEnable(Cw.WIN_GRAVITY);
      return this;
    }

    public CreateWindow.CreateWindowBuilder winGravity(Gravity winGravity) {
      this.winGravity = (int) winGravity.getValue();
      valueMaskEnable(Cw.WIN_GRAVITY);
      return this;
    }

    public CreateWindow.CreateWindowBuilder backingStore(int backingStore) {
      this.backingStore = backingStore;
      valueMaskEnable(Cw.BACKING_STORE);
      return this;
    }

    public CreateWindow.CreateWindowBuilder backingStore(BackingStore backingStore) {
      this.backingStore = (int) backingStore.getValue();
      valueMaskEnable(Cw.BACKING_STORE);
      return this;
    }

    public CreateWindow.CreateWindowBuilder backingPlanes(int backingPlanes) {
      this.backingPlanes = backingPlanes;
      valueMaskEnable(Cw.BACKING_PLANES);
      return this;
    }

    public CreateWindow.CreateWindowBuilder backingPixel(int backingPixel) {
      this.backingPixel = backingPixel;
      valueMaskEnable(Cw.BACKING_PIXEL);
      return this;
    }

    public CreateWindow.CreateWindowBuilder overrideRedirect(int overrideRedirect) {
      this.overrideRedirect = overrideRedirect;
      valueMaskEnable(Cw.OVERRIDE_REDIRECT);
      return this;
    }

    public CreateWindow.CreateWindowBuilder saveUnder(int saveUnder) {
      this.saveUnder = saveUnder;
      valueMaskEnable(Cw.SAVE_UNDER);
      return this;
    }

    public CreateWindow.CreateWindowBuilder 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 CreateWindow.CreateWindowBuilder eventMaskEnable(EventMask... maskEnums) {
      for(EventMask m : maskEnums) {
        eventMask((int) m.enableFor(eventMask));
      }
      return this;
    }

    public CreateWindow.CreateWindowBuilder eventMaskDisable(EventMask... maskEnums) {
      for(EventMask m : maskEnums) {
        eventMask((int) m.disableFor(eventMask));
      }
      return this;
    }

    public CreateWindow.CreateWindowBuilder 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 CreateWindow.CreateWindowBuilder doNotPropogateMaskEnable(EventMask... maskEnums) {
      for(EventMask m : maskEnums) {
        doNotPropogateMask((int) m.enableFor(doNotPropogateMask));
      }
      return this;
    }

    public CreateWindow.CreateWindowBuilder doNotPropogateMaskDisable(EventMask... maskEnums) {
      for(EventMask m : maskEnums) {
        doNotPropogateMask((int) m.disableFor(doNotPropogateMask));
      }
      return this;
    }

    public CreateWindow.CreateWindowBuilder colormap(int colormap) {
      this.colormap = colormap;
      valueMaskEnable(Cw.COLORMAP);
      return this;
    }

    public CreateWindow.CreateWindowBuilder cursor(int cursor) {
      this.cursor = cursor;
      valueMaskEnable(Cw.CURSOR);
      return this;
    }

    public int getSize() {
      return 32 + (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