com.github.moaxcp.x11client.protocol.xproto.ChangeKeyboardControl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x11-client Show documentation
Show all versions of x11-client Show documentation
An x11 client implemented in java
package com.github.moaxcp.x11client.protocol.xproto;
import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Override;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@Value
@Builder
public class ChangeKeyboardControl implements OneWayRequest {
public static final byte OPCODE = 102;
private int valueMask;
private int keyClickPercent;
private int bellPercent;
private int bellPitch;
private int bellDuration;
private int led;
private int ledMode;
private int key;
private int autoRepeatMode;
public byte getOpCode() {
return OPCODE;
}
public static ChangeKeyboardControl readChangeKeyboardControl(X11Input in) throws IOException {
in.readPad(1);
short length = in.readCard16();
int valueMask = in.readCard32();
ChangeKeyboardControl.ChangeKeyboardControlBuilder javaBuilder = ChangeKeyboardControl.builder();
javaBuilder.valueMask(valueMask);
if(javaBuilder.isValueMaskEnabled(Kb.KEY_CLICK_PERCENT)) {
javaBuilder.keyClickPercent(in.readInt32());
}
if(javaBuilder.isValueMaskEnabled(Kb.BELL_PERCENT)) {
javaBuilder.bellPercent(in.readInt32());
}
if(javaBuilder.isValueMaskEnabled(Kb.BELL_PITCH)) {
javaBuilder.bellPitch(in.readInt32());
}
if(javaBuilder.isValueMaskEnabled(Kb.BELL_DURATION)) {
javaBuilder.bellDuration(in.readInt32());
}
if(javaBuilder.isValueMaskEnabled(Kb.LED)) {
javaBuilder.led(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Kb.LED_MODE)) {
javaBuilder.ledMode(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Kb.KEY)) {
javaBuilder.key(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Kb.AUTO_REPEAT_MODE)) {
javaBuilder.autoRepeatMode(in.readCard32());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}
@Override
public void write(byte offset, X11Output out) throws IOException {
out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE) + Byte.toUnsignedInt(offset)));
out.writePad(1);
out.writeCard16((short) getLength());
out.writeCard32(valueMask);
if(isValueMaskEnabled(Kb.KEY_CLICK_PERCENT)) {
out.writeInt32(keyClickPercent);
}
if(isValueMaskEnabled(Kb.BELL_PERCENT)) {
out.writeInt32(bellPercent);
}
if(isValueMaskEnabled(Kb.BELL_PITCH)) {
out.writeInt32(bellPitch);
}
if(isValueMaskEnabled(Kb.BELL_DURATION)) {
out.writeInt32(bellDuration);
}
if(isValueMaskEnabled(Kb.LED)) {
out.writeCard32(led);
}
if(isValueMaskEnabled(Kb.LED_MODE)) {
out.writeCard32(ledMode);
}
if(isValueMaskEnabled(Kb.KEY)) {
out.writeCard32(key);
}
if(isValueMaskEnabled(Kb.AUTO_REPEAT_MODE)) {
out.writeCard32(autoRepeatMode);
}
out.writePadAlign(getSize());
}
public boolean isValueMaskEnabled(@NonNull Kb... maskEnums) {
for(Kb m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 8 + (isValueMaskEnabled(Kb.KEY_CLICK_PERCENT) ? 4 : 0) + (isValueMaskEnabled(Kb.BELL_PERCENT) ? 4 : 0) + (isValueMaskEnabled(Kb.BELL_PITCH) ? 4 : 0) + (isValueMaskEnabled(Kb.BELL_DURATION) ? 4 : 0) + (isValueMaskEnabled(Kb.LED) ? 4 : 0) + (isValueMaskEnabled(Kb.LED_MODE) ? 4 : 0) + (isValueMaskEnabled(Kb.KEY) ? 4 : 0) + (isValueMaskEnabled(Kb.AUTO_REPEAT_MODE) ? 4 : 0);
}
public static class ChangeKeyboardControlBuilder {
private ChangeKeyboardControl.ChangeKeyboardControlBuilder valueMask(int valueMask) {
this.valueMask = valueMask;
return this;
}
public boolean isValueMaskEnabled(@NonNull Kb... maskEnums) {
for(Kb m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
private ChangeKeyboardControl.ChangeKeyboardControlBuilder valueMaskEnable(Kb... maskEnums) {
for(Kb m : maskEnums) {
valueMask((int) m.enableFor(valueMask));
}
return this;
}
private ChangeKeyboardControl.ChangeKeyboardControlBuilder valueMaskDisable(Kb... maskEnums) {
for(Kb m : maskEnums) {
valueMask((int) m.disableFor(valueMask));
}
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder keyClickPercent(int keyClickPercent) {
this.keyClickPercent = keyClickPercent;
valueMaskEnable(Kb.KEY_CLICK_PERCENT);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder bellPercent(int bellPercent) {
this.bellPercent = bellPercent;
valueMaskEnable(Kb.BELL_PERCENT);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder bellPitch(int bellPitch) {
this.bellPitch = bellPitch;
valueMaskEnable(Kb.BELL_PITCH);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder bellDuration(int bellDuration) {
this.bellDuration = bellDuration;
valueMaskEnable(Kb.BELL_DURATION);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder led(int led) {
this.led = led;
valueMaskEnable(Kb.LED);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder ledMode(int ledMode) {
this.ledMode = ledMode;
valueMaskEnable(Kb.LED_MODE);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder ledMode(LedMode ledMode) {
this.ledMode = (int) ledMode.getValue();
valueMaskEnable(Kb.LED_MODE);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder key(int key) {
this.key = key;
valueMaskEnable(Kb.KEY);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder autoRepeatMode(int autoRepeatMode) {
this.autoRepeatMode = autoRepeatMode;
valueMaskEnable(Kb.AUTO_REPEAT_MODE);
return this;
}
public ChangeKeyboardControl.ChangeKeyboardControlBuilder autoRepeatMode(
AutoRepeatMode autoRepeatMode) {
this.autoRepeatMode = (int) autoRepeatMode.getValue();
valueMaskEnable(Kb.AUTO_REPEAT_MODE);
return this;
}
public int getSize() {
return 8 + (isValueMaskEnabled(Kb.KEY_CLICK_PERCENT) ? 4 : 0) + (isValueMaskEnabled(Kb.BELL_PERCENT) ? 4 : 0) + (isValueMaskEnabled(Kb.BELL_PITCH) ? 4 : 0) + (isValueMaskEnabled(Kb.BELL_DURATION) ? 4 : 0) + (isValueMaskEnabled(Kb.LED) ? 4 : 0) + (isValueMaskEnabled(Kb.LED_MODE) ? 4 : 0) + (isValueMaskEnabled(Kb.KEY) ? 4 : 0) + (isValueMaskEnabled(Kb.AUTO_REPEAT_MODE) ? 4 : 0);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy