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

com.github.moaxcp.x11client.protocol.randr.GetScreenResourcesCurrentReply 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.XObject;
import com.github.moaxcp.x11client.protocol.XReply;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Integer;
import java.lang.Override;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;

@Value
@Builder
public class GetScreenResourcesCurrentReply implements XReply {
  private short sequenceNumber;

  private int timestamp;

  private int configTimestamp;

  private short numModes;

  @NonNull
  private List crtcs;

  @NonNull
  private List outputs;

  @NonNull
  private List modes;

  @NonNull
  private List names;

  public static GetScreenResourcesCurrentReply readGetScreenResourcesCurrentReply(byte pad,
      short sequenceNumber, X11Input in) throws IOException {
    int length = in.readCard32();
    int timestamp = in.readCard32();
    int configTimestamp = in.readCard32();
    short numCrtcs = in.readCard16();
    short numOutputs = in.readCard16();
    short numModes = in.readCard16();
    short namesLen = in.readCard16();
    in.readPad(8);
    List crtcs = in.readCard32(Short.toUnsignedInt(numCrtcs));
    List outputs = in.readCard32(Short.toUnsignedInt(numOutputs));
    List modes = new ArrayList<>(Short.toUnsignedInt(numModes));
    for(int i = 0; i < Short.toUnsignedInt(numModes); i++) {
      modes.add(ModeInfo.readModeInfo(in));
    }
    List names = in.readByte(Short.toUnsignedInt(namesLen));
    GetScreenResourcesCurrentReply.GetScreenResourcesCurrentReplyBuilder javaBuilder = GetScreenResourcesCurrentReply.builder();
    javaBuilder.sequenceNumber(sequenceNumber);
    javaBuilder.timestamp(timestamp);
    javaBuilder.configTimestamp(configTimestamp);
    javaBuilder.numModes(numModes);
    javaBuilder.crtcs(crtcs);
    javaBuilder.outputs(outputs);
    javaBuilder.modes(modes);
    javaBuilder.names(names);
    if(javaBuilder.getSize() < 32) {
      in.readPad(32 - javaBuilder.getSize());
    }
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard8(getResponseCode());
    out.writePad(1);
    out.writeCard16(sequenceNumber);
    out.writeCard32(getLength());
    out.writeCard32(timestamp);
    out.writeCard32(configTimestamp);
    short numCrtcs = (short) crtcs.size();
    out.writeCard16(numCrtcs);
    short numOutputs = (short) outputs.size();
    out.writeCard16(numOutputs);
    out.writeCard16(numModes);
    short namesLen = (short) names.size();
    out.writeCard16(namesLen);
    out.writePad(8);
    out.writeCard32(crtcs);
    out.writeCard32(outputs);
    for(ModeInfo t : modes) {
      t.write(out);
    }
    out.writeByte(names);
    out.writePadAlign(getSize());
  }

  @Override
  public int getSize() {
    return 32 + 4 * crtcs.size() + 4 * outputs.size() + XObject.sizeOf(modes) + 1 * names.size();
  }

  public static class GetScreenResourcesCurrentReplyBuilder {
    public int getSize() {
      return 32 + 4 * crtcs.size() + 4 * outputs.size() + XObject.sizeOf(modes) + 1 * names.size();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy