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

com.github.moaxcp.x11client.protocol.xproto.ConfigureRequestEvent 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.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import com.github.moaxcp.x11client.protocol.XEvent;
import java.io.IOException;
import java.lang.Override;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;

@Value
@Builder
public class ConfigureRequestEvent implements XEvent {
  public static final byte NUMBER = 23;

  private boolean sentEvent;

  private byte stackMode;

  private short sequenceNumber;

  private int parent;

  private int window;

  private int sibling;

  private short x;

  private short y;

  private short width;

  private short height;

  private short borderWidth;

  private short valueMask;

  @Override
  public byte getResponseCode() {
    return NUMBER;
  }

  public static ConfigureRequestEvent readConfigureRequestEvent(boolean sentEvent, X11Input in)
      throws IOException {
    byte stackMode = in.readByte();
    short sequenceNumber = in.readCard16();
    int parent = in.readCard32();
    int window = in.readCard32();
    int sibling = in.readCard32();
    short x = in.readInt16();
    short y = in.readInt16();
    short width = in.readCard16();
    short height = in.readCard16();
    short borderWidth = in.readCard16();
    short valueMask = in.readCard16();
    in.readPad(4);
    ConfigureRequestEvent.ConfigureRequestEventBuilder javaBuilder = ConfigureRequestEvent.builder();
    javaBuilder.stackMode(stackMode);
    javaBuilder.sequenceNumber(sequenceNumber);
    javaBuilder.parent(parent);
    javaBuilder.window(window);
    javaBuilder.sibling(sibling);
    javaBuilder.x(x);
    javaBuilder.y(y);
    javaBuilder.width(width);
    javaBuilder.height(height);
    javaBuilder.borderWidth(borderWidth);
    javaBuilder.valueMask(valueMask);

    javaBuilder.sentEvent(sentEvent);
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard8(sentEvent ? 0b10000000 & NUMBER : NUMBER);
    out.writeByte(stackMode);
    out.writeCard16(sequenceNumber);
    out.writeCard32(parent);
    out.writeCard32(window);
    out.writeCard32(sibling);
    out.writeInt16(x);
    out.writeInt16(y);
    out.writeCard16(width);
    out.writeCard16(height);
    out.writeCard16(borderWidth);
    out.writeCard16(valueMask);
    out.writePad(4);
  }

  public boolean isValueMaskEnabled(@NonNull ConfigWindow... maskEnums) {
    for(ConfigWindow m : maskEnums) {
      if(!m.isEnabled(valueMask)) {
        return false;
      }
    }
    return true;
  }

  @Override
  public int getSize() {
    return 32;
  }

  public static class ConfigureRequestEventBuilder {
    public ConfigureRequestEvent.ConfigureRequestEventBuilder stackMode(StackMode stackMode) {
      this.stackMode = (byte) stackMode.getValue();
      return this;
    }

    public ConfigureRequestEvent.ConfigureRequestEventBuilder stackMode(byte stackMode) {
      this.stackMode = stackMode;
      return this;
    }

    private ConfigureRequestEvent.ConfigureRequestEventBuilder 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 ConfigureRequestEvent.ConfigureRequestEventBuilder valueMaskEnable(
        ConfigWindow... maskEnums) {
      for(ConfigWindow m : maskEnums) {
        valueMask((short) m.enableFor(valueMask));
      }
      return this;
    }

    private ConfigureRequestEvent.ConfigureRequestEventBuilder valueMaskDisable(
        ConfigWindow... maskEnums) {
      for(ConfigWindow m : maskEnums) {
        valueMask((short) m.disableFor(valueMask));
      }
      return this;
    }

    public int getSize() {
      return 32;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy