Skip to content

Commit

Permalink
Fix #3, but need to update cursor image to match one in use
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Rule committed Jul 23, 2014
1 parent bf62b58 commit 5cd0a78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Binary file modified assets/cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 13 additions & 9 deletions selfspy/sniff_cocoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ def screenshot(self, path, region = None):
try:
# record how long it takes to take screenshot
start = time.time()
scale = 1.0

# Set to capture entire screen, including multiple monitors
if region is None:
Expand All @@ -559,14 +558,14 @@ def screenshot(self, path, region = None):
scaleFactor = height/self.screenSize[1]

mouseLoc = NSEvent.mouseLocation()
x = int(mouseLoc.x *scale)
y = int(mouseLoc.y *scale)
x = int(mouseLoc.x)
y = int(mouseLoc.y)
# w = int(width *scale)
# h = int(height *scale)
w = 20
w = 16
h = 24
org_x = int(x * scaleFactor)
org_y = int((y-h) * scaleFactor)
org_x = int((x) * scaleFactor)
org_y = int((y-h+5) * scaleFactor)

# print "cursor :", x, y, w, h

Expand All @@ -575,20 +574,25 @@ def screenshot(self, path, region = None):

bitmapContext = Quartz.CGBitmapContextCreate(
imageData, # image data we just allocated...
width*scale,
height*scale,
width,
height,
8, # 8 bits per component
4 * width, # bytes per pixel times number of pixels wide
Quartz.CGImageGetColorSpace(image), # use the same colorspace as the original image
Quartz.kCGImageAlphaPremultipliedFirst # use premultiplied alpha
)

#Draw image on context at new scale
rect = CG.CGRectMake(0.0,0.0,width*scale,height*scale)
rect = CG.CGRectMake(0.0,0.0,width,height)
Quartz.CGContextDrawImage(bitmapContext, rect, image)

# Adding Mouse cursor to the screenshot
# https://stackoverflow.com/questions/8008630/not-displaying-mouse-cursor
# cursor = NSCursor.currentSystemCursor().image()
# rect2 = CG.CGRectMake(org_x, org_y, w*scaleFactor, h*scaleFactor)
# image2 = cursor.CGImageForProposedRect_context_hints_(rect2, bitmapContext, None)
# print image2
# Quartz.CGContextDrawImage(bitmapContext, rect2, image2)
# NSImage *overlay = [[[NSCursor arrowCursor] image] copy]
# # arrowCursor grabs the arrow cursor
# # currentSystemCursor grabs the image of the current cursor,
Expand Down

0 comments on commit 5cd0a78

Please sign in to comment.