diff --git a/tuhi/drawing.py b/tuhi/drawing.py index 1a44f0b..0bd4882 100644 --- a/tuhi/drawing.py +++ b/tuhi/drawing.py @@ -86,6 +86,10 @@ class Drawing(GObject.Object): self.strokes = [] self._current_stroke = -1 + def seal(self): + # Drop empty strokes + self.strokes = [s for s in self.strokes if s.points] + # The way we're building drawings, we don't need to change the current # stroke at runtime, so this is read-ony @GObject.Property diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 7ae773c..9dd24d8 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -618,6 +618,8 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): drawing = Drawing(self.device.name, (self.width, self.height), timestamp) + have_abs = 0x00 # bitmask 3-bits: pyx + while offset < len(data): bitmask, opcode, raw_args, args, offset = self.next_pen_data(data, offset) @@ -650,11 +652,27 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): if bitmask & 0b00111100 == 0: continue + + if not xrel: + have_abs |= 0x1 + if not yrel: + have_abs |= 0x2 + if not prel: + have_abs |= 0x4 + if xrel or yrel or prel: + if not stroke.points: + if have_abs == 0x7: + logger.info('Forcing first point to be absolute') + stroke.new_abs((x, y), p) + else: + logger.warning('First point in stroke is relative, skipping') + continue stroke.new_rel((dx, dy), dp) else: stroke.new_abs((x, y), p) + drawing.seal() return drawing def read_offline_data(self):