com.github.moaxcp.x11.protocol.xinput.HierarchyInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x11-protocol-xinput Show documentation
Show all versions of x11-protocol-xinput Show documentation
An implementation of the x11 xinput protocol in java
package com.github.moaxcp.x11.protocol.xinput;
import com.github.moaxcp.x11.protocol.X11Input;
import com.github.moaxcp.x11.protocol.X11Output;
import com.github.moaxcp.x11.protocol.XStruct;
import java.io.IOException;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@Value
@Builder
public class HierarchyInfo implements XStruct {
public static final String PLUGIN_NAME = "xinput";
private short deviceid;
private short attachment;
private byte type;
private boolean enabled;
private int flags;
public static HierarchyInfo readHierarchyInfo(X11Input in) throws IOException {
HierarchyInfo.HierarchyInfoBuilder javaBuilder = HierarchyInfo.builder();
short deviceid = in.readCard16();
short attachment = in.readCard16();
byte type = in.readCard8();
boolean enabled = in.readBool();
byte[] pad4 = in.readPad(2);
int flags = in.readCard32();
javaBuilder.deviceid(deviceid);
javaBuilder.attachment(attachment);
javaBuilder.type(type);
javaBuilder.enabled(enabled);
javaBuilder.flags(flags);
return javaBuilder.build();
}
@Override
public void write(X11Output out) throws IOException {
out.writeCard16(deviceid);
out.writeCard16(attachment);
out.writeCard8(type);
out.writeBool(enabled);
out.writePad(2);
out.writeCard32(flags);
}
public boolean isFlagsEnabled(@NonNull HierarchyMask... maskEnums) {
for(HierarchyMask m : maskEnums) {
if(!m.isEnabled(flags)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 12;
}
public String getPluginName() {
return PLUGIN_NAME;
}
public static class HierarchyInfoBuilder {
public HierarchyInfo.HierarchyInfoBuilder type(DeviceType type) {
this.type = (byte) type.getValue();
return this;
}
public HierarchyInfo.HierarchyInfoBuilder type(byte type) {
this.type = type;
return this;
}
public boolean isFlagsEnabled(@NonNull HierarchyMask... maskEnums) {
for(HierarchyMask m : maskEnums) {
if(!m.isEnabled(flags)) {
return false;
}
}
return true;
}
public HierarchyInfo.HierarchyInfoBuilder flagsEnable(HierarchyMask... maskEnums) {
for(HierarchyMask m : maskEnums) {
flags((int) m.enableFor(flags));
}
return this;
}
public HierarchyInfo.HierarchyInfoBuilder flagsDisable(HierarchyMask... maskEnums) {
for(HierarchyMask m : maskEnums) {
flags((int) m.disableFor(flags));
}
return this;
}
public int getSize() {
return 12;
}
}
}