From d019667c001679b9c73b63735f2c2fca92c530d6 Mon Sep 17 00:00:00 2001 From: braveyao Date: Tue, 23 May 2017 09:31:14 -0700 Subject: [PATCH] Linux desktopCapture: fix the cursor position issue in Window sharing On Linux, during Windwo sharing, the cursore capture may happen in the parent window of the target. And the parent window may have some decorations added by window manager(Chrome windows don't have those decorations.), so the relative cursor position to the parent window with decorations may differ to its child target window. The offset includes the height of caption bar and the around shadow and border. This problem only happens with Window sharing on Linux. The fix is to translate the coordinates from the parent window to the coordinates space of the target window. BUG=723889 Review-Url: https://codereview.webrtc.org/2889063002 Cr-Commit-Position: refs/heads/master@{#18243} --- .../desktop_capture/mouse_cursor_monitor_x11.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc b/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc index 4870bae7ff..22339d4221 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc +++ b/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc @@ -185,6 +185,21 @@ void MouseCursorMonitorX11::Capture() { (window_ == root_window || child_window != None) ? INSIDE : OUTSIDE; } + // As the comments to GetTopLevelWindow() above indicate, in window capture, + // the cursor position capture happens in |window_|, while the frame catpure + // happens in |child_window|. These two windows are not alwyas same, as + // window manager may add some decorations to the |window_|. So translate + // the coordinate in |window_| to the coordinate space of |child_window|. + if (window_ != root_window && state == INSIDE) { + int translated_x, translated_y; + Window unused; + if (XTranslateCoordinates(display(), window_, child_window, win_x, win_y, + &translated_x, &translated_y, &unused)) { + win_x = translated_x; + win_y = translated_y; + } + } + callback_->OnMouseCursorPosition(state, webrtc::DesktopVector(win_x, win_y)); }