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

com.github.moaxcp.x11client.protocol.randr.NotifyEvent Maven / Gradle / Ivy

There is a newer version: 0.18.2
Show newest version
package com.github.moaxcp.x11client.protocol.randr;

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 NotifyEvent implements XEvent {
  public static final byte NUMBER = 1;

  private boolean sentEvent;

  private byte subCode;

  private short sequenceNumber;

  @NonNull
  private NotifyDataUnion u;

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

  public static NotifyEvent readNotifyEvent(boolean sentEvent, X11Input in) throws IOException {
    byte subCode = in.readCard8();
    short sequenceNumber = in.readCard16();
    NotifyDataUnion u = NotifyDataUnion.readNotifyDataUnion(in, subCode);
    NotifyEvent.NotifyEventBuilder javaBuilder = NotifyEvent.builder();
    javaBuilder.subCode(subCode);
    javaBuilder.sequenceNumber(sequenceNumber);
    javaBuilder.u(u);

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

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard8(sentEvent ? 0b10000000 & NUMBER : NUMBER);
    out.writeCard8(subCode);
    out.writeCard16(sequenceNumber);
    u.write(out);
  }

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

  public static class NotifyEventBuilder {
    public NotifyEvent.NotifyEventBuilder subCode(Notify subCode) {
      this.subCode = (byte) subCode.getValue();
      return this;
    }

    public NotifyEvent.NotifyEventBuilder subCode(byte subCode) {
      this.subCode = subCode;
      return this;
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy