Browse Source

win-capture: Fix bug calculating cursor position

Cursor position calculation was not taking in to account the window
client coordinates relative to the screen.
jp9000 11 years ago
parent
commit
8ab1bc8e7b
1 changed files with 11 additions and 6 deletions
  1. 11 6
      plugins/win-capture/dc-capture.c

+ 11 - 6
plugins/win-capture/dc-capture.c

@@ -86,11 +86,12 @@ void dc_capture_free(struct dc_capture *capture)
 	memset(capture, 0, sizeof(struct dc_capture));
 }
 
-static void draw_cursor(struct dc_capture *capture, HDC hdc)
+static void draw_cursor(struct dc_capture *capture, HDC hdc, HWND window)
 {
-	HICON icon;
-	ICONINFO ii;
+	HICON      icon;
+	ICONINFO   ii;
 	CURSORINFO *ci = &capture->ci;
+	POINT      win_pos = {capture->x, capture->y};
 
 	if (!(capture->ci.flags & CURSOR_SHOWING))
 		return;
@@ -101,8 +102,12 @@ static void draw_cursor(struct dc_capture *capture, HDC hdc)
 
 	if (GetIconInfo(icon, &ii)) {
 		POINT pos;
-		pos.x = ci->ptScreenPos.x - (int)ii.xHotspot - capture->x;
-		pos.y = ci->ptScreenPos.y - (int)ii.yHotspot - capture->y;
+
+		if (window)
+			ClientToScreen(window, &win_pos);
+
+		pos.x = ci->ptScreenPos.x - (int)ii.xHotspot - win_pos.x;
+		pos.y = ci->ptScreenPos.y - (int)ii.yHotspot - win_pos.y;
 
 		DrawIcon(hdc, pos.x, pos.y, icon);
 
@@ -163,7 +168,7 @@ void dc_capture_capture(struct dc_capture *capture, HWND window)
 	ReleaseDC(NULL, hdc_target);
 
 	if (capture->cursor_captured)
-		draw_cursor(capture, hdc);
+		draw_cursor(capture, hdc, window);
 
 	dc_capture_release_dc(capture);