com.github.moaxcp.x11client.protocol.xproto.SendEvent 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 java.util.List;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@Value
@Builder
public class SendEvent implements OneWayRequest {
public static final byte OPCODE = 25;
private boolean propagate;
private int destination;
private int eventMask;
@NonNull
private List event;
public byte getOpCode() {
return OPCODE;
}
public static SendEvent readSendEvent(X11Input in) throws IOException {
boolean propagate = in.readBool();
short length = in.readCard16();
int destination = in.readCard32();
int eventMask = in.readCard32();
List event = in.readChar(32);
SendEvent.SendEventBuilder javaBuilder = SendEvent.builder();
javaBuilder.propagate(propagate);
javaBuilder.destination(destination);
javaBuilder.eventMask(eventMask);
javaBuilder.event(event);
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.writeBool(propagate);
out.writeCard16((short) getLength());
out.writeCard32(destination);
out.writeCard32(eventMask);
out.writeChar(event);
out.writePadAlign(getSize());
}
public boolean isEventMaskEnabled(@NonNull EventMask... maskEnums) {
for(EventMask m : maskEnums) {
if(!m.isEnabled(eventMask)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 12 + 1 * event.size();
}
public static class SendEventBuilder {
public boolean isEventMaskEnabled(@NonNull EventMask... maskEnums) {
for(EventMask m : maskEnums) {
if(!m.isEnabled(eventMask)) {
return false;
}
}
return true;
}
public SendEvent.SendEventBuilder eventMaskEnable(EventMask... maskEnums) {
for(EventMask m : maskEnums) {
eventMask((int) m.enableFor(eventMask));
}
return this;
}
public SendEvent.SendEventBuilder eventMaskDisable(EventMask... maskEnums) {
for(EventMask m : maskEnums) {
eventMask((int) m.disableFor(eventMask));
}
return this;
}
public int getSize() {
return 12 + 1 * event.size();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy