Skip to content

Commit

Permalink
add support for scaling coords based on script vs server resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sibson committed Jan 21, 2013
1 parent c845d23 commit 0fc68fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
21 changes: 18 additions & 3 deletions vncdotool/client.py
Expand Up @@ -116,12 +116,15 @@ class VNCDoToolClient(rfb.RFBClient):
x = 0
y = 0
buttons = 0
scale = (1.0, 1.0)

screen = None
deferred = None

cursor = None
cmask = None


def _decodeKey(self, key):
if len(key) == 1:
keys = [key]
Expand Down Expand Up @@ -252,15 +255,22 @@ def _expectCompare(self, image, maxrms):
def mouseMove(self, x, y):
""" Move the mouse pointer to position (x, y)
"""
log.debug('mouseMove', x, y)
self.x, self.y = x, y
self.pointerEvent(x, y, self.buttons)
log.debug('mouseMove %s %s', x, y)
self.x = self.scale[0] * x
self.y = self.scale[1] * y

self.pointerEvent(self.x, self.y, self.buttons)

return self

def mouseDrag(self, x, y, step=1):
""" Move the mouse point to position (x, y) in increments of step
"""
log.debug('mouseDrag', x, y)

x = self.scale[0] * x
y = self.scale[1] * y

if x < self.x:
xsteps = [self.x - i for i in xrange(step, self.x - x + 1, step)]
else:
Expand All @@ -283,6 +293,11 @@ def mouseDrag(self, x, y, step=1):

return self

def scaleFrom(self, width, height):
self.scale = (float(self.width) / width,
float(self.height / height))
return self

#
# base customizations
#
Expand Down
3 changes: 3 additions & 0 deletions vncdotool/command.py
Expand Up @@ -134,6 +134,9 @@ def build_command_list(factory, args, delay=None, warp=1.0):
lex = shlex.shlex(open(cmd), posix=True)
lex.whitespace_split = True
args = list(lex) + args
elif cmd == 'scaleres':
w, h = float(args.pop(0)), float(args.pop(0))
factory.deferred.addCallback(client.scaleFrom, w, h)
else:
print 'unknown cmd "%s"' % cmd

Expand Down
4 changes: 4 additions & 0 deletions vncdotool/loggingproxy.py
Expand Up @@ -130,6 +130,10 @@ class VNCLoggingClient(VNCDoToolClient):
"""
capture_file = None

def vncConnectionMade(self):
VNCDoToolClient.vncConnectionMade(self)
self.recorder('scaleres %d %d\n' % (self.width, self.height))

def commitUpdate(self, rectangles):
if self.capture_file:
self.screen.save(self.capture_file)
Expand Down

0 comments on commit 0fc68fa

Please sign in to comment.