com.github.moaxcp.x11.protocol.xproto.GrabKey Maven / Gradle / Ivy
package com.github.moaxcp.x11.protocol.xproto;
import com.github.moaxcp.x11.protocol.OneWayRequest;
import com.github.moaxcp.x11.protocol.X11Input;
import com.github.moaxcp.x11.protocol.X11Output;
import java.io.IOException;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@Value
@Builder
public class GrabKey implements OneWayRequest {
public static final String PLUGIN_NAME = "xproto";
public static final byte OPCODE = 33;
private boolean ownerEvents;
private int grabWindow;
private short modifiers;
private byte key;
private byte pointerMode;
private byte keyboardMode;
public byte getOpCode() {
return OPCODE;
}
public static GrabKey readGrabKey(X11Input in) throws IOException {
GrabKey.GrabKeyBuilder javaBuilder = GrabKey.builder();
boolean ownerEvents = in.readBool();
short length = in.readCard16();
int grabWindow = in.readCard32();
short modifiers = in.readCard16();
byte key = in.readCard8();
byte pointerMode = in.readCard8();
byte keyboardMode = in.readCard8();
byte[] pad8 = in.readPad(3);
javaBuilder.ownerEvents(ownerEvents);
javaBuilder.grabWindow(grabWindow);
javaBuilder.modifiers(modifiers);
javaBuilder.key(key);
javaBuilder.pointerMode(pointerMode);
javaBuilder.keyboardMode(keyboardMode);
return javaBuilder.build();
}
@Override
public void write(byte majorOpcode, X11Output out) throws IOException {
out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE)));
out.writeBool(ownerEvents);
out.writeCard16((short) getLength());
out.writeCard32(grabWindow);
out.writeCard16(modifiers);
out.writeCard8(key);
out.writeCard8(pointerMode);
out.writeCard8(keyboardMode);
out.writePad(3);
}
public boolean isModifiersEnabled(@NonNull ModMask... maskEnums) {
for(ModMask m : maskEnums) {
if(!m.isEnabled(modifiers)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 16;
}
public String getPluginName() {
return PLUGIN_NAME;
}
public static class GrabKeyBuilder {
public boolean isModifiersEnabled(@NonNull ModMask... maskEnums) {
for(ModMask m : maskEnums) {
if(!m.isEnabled(modifiers)) {
return false;
}
}
return true;
}
public GrabKey.GrabKeyBuilder modifiersEnable(ModMask... maskEnums) {
for(ModMask m : maskEnums) {
modifiers((short) m.enableFor(modifiers));
}
return this;
}
public GrabKey.GrabKeyBuilder modifiersDisable(ModMask... maskEnums) {
for(ModMask m : maskEnums) {
modifiers((short) m.disableFor(modifiers));
}
return this;
}
public GrabKey.GrabKeyBuilder pointerMode(GrabMode pointerMode) {
this.pointerMode = (byte) pointerMode.getValue();
return this;
}
public GrabKey.GrabKeyBuilder pointerMode(byte pointerMode) {
this.pointerMode = pointerMode;
return this;
}
public GrabKey.GrabKeyBuilder keyboardMode(GrabMode keyboardMode) {
this.keyboardMode = (byte) keyboardMode.getValue();
return this;
}
public GrabKey.GrabKeyBuilder keyboardMode(byte keyboardMode) {
this.keyboardMode = keyboardMode;
return this;
}
public int getSize() {
return 16;
}
}
}