From: Brian P. Hinz Date: Mon, 27 Feb 2017 21:38:30 +0000 (-0500) Subject: Java client support for X Cursor X-Git-Tag: v1.7.90~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=038dc6e2313e03775f214b7bffb247ada0d226fa;p=tigervnc.git Java client support for X Cursor --- diff --git a/java/com/tigervnc/rfb/CMsgReader.java b/java/com/tigervnc/rfb/CMsgReader.java index 12862c14..a5cc267f 100644 --- a/java/com/tigervnc/rfb/CMsgReader.java +++ b/java/com/tigervnc/rfb/CMsgReader.java @@ -95,6 +95,9 @@ public class CMsgReader { case Encodings.pseudoEncodingLastRect: nUpdateRectsLeft = 1; // this rectangle is the last one break; + case Encodings.pseudoEncodingXCursor: + readSetXCursor(w, h, new Point(x,y)); + break; case Encodings.pseudoEncodingCursor: readSetCursor(w, h, new Point(x,y)); break; @@ -206,6 +209,62 @@ public class CMsgReader { handler.dataRect(r, encoding); } + protected void readSetXCursor(int width, int height, Point hotspot) + { + byte pr, pg, pb; + byte sr, sg, sb; + int data_len = ((width+7)/8) * height; + int mask_len = ((width+7)/8) * height; + ByteBuffer data = ByteBuffer.allocate(data_len); + ByteBuffer mask = ByteBuffer.allocate(mask_len); + + int x, y; + byte[] buf = new byte[width*height*4]; + ByteBuffer out; + + if (width * height == 0) + return; + + pr = (byte)is.readU8(); + pg = (byte)is.readU8(); + pb = (byte)is.readU8(); + + sr = (byte)is.readU8(); + sg = (byte)is.readU8(); + sb = (byte)is.readU8(); + + is.readBytes(data, data_len); + is.readBytes(mask, mask_len); + + int maskBytesPerRow = (width+7)/8; + out = ByteBuffer.wrap(buf); + for (y = 0;y < height;y++) { + for (x = 0;x < width;x++) { + int byte_ = y * maskBytesPerRow + x / 8; + int bit = 7 - x % 8; + + if ((data.get(byte_) & (1 << bit)) > 0) { + out.put(out.position() + 1, pr); + out.put(out.position() + 2, pg); + out.put(out.position() + 3, pb); + } else { + out.put(out.position() + 1, sr); + out.put(out.position() + 2, sg); + out.put(out.position() + 3, sb); + } + + if ((mask.get(byte_) & (1 << bit)) > 0) + out.put(out.position() + 0, (byte)255); + else + out.put(out.position() + 0, (byte)0); + + out.position(out.position() + 4); + } + } + + handler.setCursor(width, height, hotspot, buf); + } + protected void readSetCursor(int width, int height, Point hotspot) { int data_len = width * height * (handler.cp.pf().bpp/8); diff --git a/java/com/tigervnc/rfb/CMsgWriter.java b/java/com/tigervnc/rfb/CMsgWriter.java index 701f2d3d..7838da34 100644 --- a/java/com/tigervnc/rfb/CMsgWriter.java +++ b/java/com/tigervnc/rfb/CMsgWriter.java @@ -65,6 +65,7 @@ public class CMsgWriter { int[] encodings = new int[Encodings.encodingMax+3]; if (cp.supportsLocalCursor) { + encodings[nEncodings++] = Encodings.pseudoEncodingXCursor; encodings[nEncodings++] = Encodings.pseudoEncodingCursor; encodings[nEncodings++] = Encodings.pseudoEncodingCursorWithAlpha; }