wacom: don't add points to the log until we have an absolute value

On the Intuos Pro at least we sometimes get events that are all relative at
first and it can take several events for us to have all three values as
absolute. This is likely a parsing error on our side, but meanwhile don't
write the data until we have at least one known value for all three axes.

And because the SVG writer isn't happy with empty strokes, add a seal()
function to the drawing to purge empty strokes.

Fixed #92 or at least works around it
This commit is contained in:
Peter Hutterer 2018-02-14 12:41:34 +10:00
parent 6c156efc01
commit 7796d3c110
2 changed files with 22 additions and 0 deletions

View File

@ -86,6 +86,10 @@ class Drawing(GObject.Object):
self.strokes = [] self.strokes = []
self._current_stroke = -1 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 # The way we're building drawings, we don't need to change the current
# stroke at runtime, so this is read-ony # stroke at runtime, so this is read-ony
@GObject.Property @GObject.Property

View File

@ -618,6 +618,8 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
drawing = Drawing(self.device.name, (self.width, self.height), timestamp) drawing = Drawing(self.device.name, (self.width, self.height), timestamp)
have_abs = 0x00 # bitmask 3-bits: pyx
while offset < len(data): while offset < len(data):
bitmask, opcode, raw_args, args, offset = self.next_pen_data(data, offset) bitmask, opcode, raw_args, args, offset = self.next_pen_data(data, offset)
@ -650,11 +652,27 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
if bitmask & 0b00111100 == 0: if bitmask & 0b00111100 == 0:
continue 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 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) stroke.new_rel((dx, dy), dp)
else: else:
stroke.new_abs((x, y), p) stroke.new_abs((x, y), p)
drawing.seal()
return drawing return drawing
def read_offline_data(self): def read_offline_data(self):