[vlc-commits] common/win32_fullscreen: fixed handling mouse events when vout window thread has changed ( usially after "stop")

Sergey Radionov git at videolan.org
Wed Dec 21 12:54:17 CET 2011


npapi-vlc | branch: master | Sergey Radionov <RSATom at gmail.com> | Wed Dec  7 17:28:05 2011 +0700| [6c1c36cfa6b463f3151dbf1827c0a2f15699181a] | committer: Jean-Baptiste Kempf

common/win32_fullscreen: fixed handling mouse events when vout window thread has changed (usially after "stop")

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=6c1c36cfa6b463f3151dbf1827c0a2f15699181a
---

 common/win32_fullscreen.cpp |   20 +++++++++++++++-----
 common/win32_fullscreen.h   |    3 ++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/common/win32_fullscreen.cpp b/common/win32_fullscreen.cpp
index ea818d9..be07da0 100644
--- a/common/win32_fullscreen.cpp
+++ b/common/win32_fullscreen.cpp
@@ -181,16 +181,24 @@ LRESULT CALLBACK VLCHolderWnd::MouseHookProc(int nCode, WPARAM wParam, LPARAM lP
 void VLCHolderWnd::MouseHook(bool SetHook)
 {
     if(SetHook){
-        HWND hChildWnd = GetWindow(getHWND(), GW_CHILD);
-        if(!_hMouseHook && hChildWnd){
+        const HWND hChildWnd = GetWindow(getHWND(), GW_CHILD);
+        const DWORD WndThreadID = (hChildWnd) ? GetWindowThreadProcessId(hChildWnd, NULL) : 0;
+        if( _hMouseHook &&( !hChildWnd || WndThreadID != _MouseHookThreadId) ){
+            //unhook if something changed
+            MouseHook(false);
+        }
+
+        if(!_hMouseHook && hChildWnd && WndThreadID){
+            _MouseHookThreadId = WndThreadID;
             _hMouseHook =
                 SetWindowsHookEx(WH_MOUSE, VLCHolderWnd::MouseHookProc,
-                                 NULL, GetWindowThreadProcessId(hChildWnd, NULL));
+                                 NULL, WndThreadID);
         }
     }
     else{
         if(_hMouseHook){
             UnhookWindowsHookEx(_hMouseHook);
+            _MouseHookThreadId=0;
             _hMouseHook = 0;
         }
     }
@@ -205,14 +213,16 @@ void VLCHolderWnd::OnLibVlcEvent(const libvlc_event_t* event)
     //So we try catch events,
     //(suppose wnd will be ever created),
     //and then try set mouse hook.
-    if(!_hMouseHook){
+    const HWND hChildWnd = GetWindow(getHWND(), GW_CHILD);
+    const DWORD WndThreadID = (hChildWnd) ? GetWindowThreadProcessId(hChildWnd, NULL) : 0;
+    //if no hook, or window thread has changed
+    if(!_hMouseHook || (hChildWnd && WndThreadID != _MouseHookThreadId)){
         //libvlc events arrives from separate thread,
         //so we need post message to main thread, to notify it.
         PostMessage(getHWND(), WM_TRY_SET_MOUSE_HOOK, 0, 0);
     }
 }
 
-
 void VLCHolderWnd::LibVlcAttach()
 {
     libvlc_media_player_set_hwnd(getMD(), getHWND());
diff --git a/common/win32_fullscreen.h b/common/win32_fullscreen.h
index 8f1de8d..2ceb58e 100644
--- a/common/win32_fullscreen.h
+++ b/common/win32_fullscreen.h
@@ -50,6 +50,7 @@ private:
     static LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam);
 
     HHOOK _hMouseHook;
+    DWORD _MouseHookThreadId;
     void MouseHook(bool SetHook);
 
     libvlc_media_player_t* getMD() const;
@@ -60,7 +61,7 @@ private:
 
 private:
     VLCHolderWnd(HWND hWnd, VLCWindowsManager* WM)
-        : _hMouseHook(NULL), _hWnd(hWnd)
+        : _hMouseHook(NULL), _MouseHookThreadId(0), _hWnd(hWnd)
          , _WindowsManager(WM){};
 
 public:



More information about the vlc-commits mailing list