CVS: seamlessrdp/ServerExe/HookDll hookdll.c,1.24,1.25

Pierre Ossman <[email protected]> Fri, 17 Mar 2006 05:11:23 -0800
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/seamlessrdp/ServerExe/HookDll
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13568/ServerExe/HookDll

Modified Files:
	hookdll.c 
Log Message:
Encapsulate ZCHANGE and FOCUS requests into safe wrappers to avoid loops.
Setting focus also needed a hack because it killed off menus.


Index: hookdll.c
===================================================================
RCS file: /cvsroot/rdesktop/seamlessrdp/ServerExe/HookDll/hookdll.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** hookdll.c	17 Mar 2006 09:55:35 -0000	1.24
--- hookdll.c	17 Mar 2006 13:11:20 -0000	1.25
***************
*** 47,50 ****
--- 47,52 ----
  // blocks for locally generated events
  RECT g_block_move SHARED = { 0, 0, 0, 0 };
+ HWND g_blocked_zchange[2] SHARED = { NULL, NULL };
+ HWND g_blocked_focus SHARED = NULL;
  
  #pragma data_seg ()
***************
*** 163,170 ****
  				if (!(wp->flags & SWP_NOZORDER))
  				{
! 					vchannel_write("ZCHANGE,0x%p,0x%p,0x%x",
! 						       hwnd,
! 						       wp->flags & SWP_NOACTIVATE ? wp->
! 						       hwndInsertAfter : 0, 0);
  				}
  
--- 165,182 ----
  				if (!(wp->flags & SWP_NOZORDER))
  				{
! 					HWND block_hwnd, block_behind;
! 					WaitForSingleObject(g_mutex, INFINITE);
! 					block_hwnd = g_blocked_zchange[0];
! 					block_behind = g_blocked_zchange[1];
! 					ReleaseMutex(g_mutex);
! 
! 					if ((hwnd != block_hwnd)
! 					    || (wp->hwndInsertAfter != block_behind))
! 					{
! 						vchannel_write("ZCHANGE,0x%p,0x%p,0x%x",
! 							       hwnd,
! 							       wp->flags & SWP_NOACTIVATE ? wp->
! 							       hwndInsertAfter : 0, 0);
! 					}
  				}
  
***************
*** 223,226 ****
--- 235,247 ----
  		goto end;
  
+ 	if (style & WS_POPUP)
+ 	{
+ 		parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
+ 		if (!parent)
+ 			parent = (HWND) - 1;
+ 	}
+ 	else
+ 		parent = NULL;
+ 
  	switch (msg)
  	{
***************
*** 243,247 ****
  
  	if (msg == g_wm_seamless_focus)
! 		SetFocus(hwnd);
  
        end:
--- 264,273 ----
  
  	if (msg == g_wm_seamless_focus)
! 	{
! 		/* FIXME: SetActiveWindow() kills menus. Need to find a clean
! 		   way to solve this. */
! 		if ((GetActiveWindow() != hwnd) && !parent)
! 			SetActiveWindow(hwnd);
! 	}
  
        end:
***************
*** 331,334 ****
--- 357,393 ----
  }
  
+ DLL_EXPORT void
+ SafeZChange(HWND hwnd, HWND behind)
+ {
+ 	if (behind == NULL)
+ 		behind = HWND_TOP;
+ 
+ 	WaitForSingleObject(g_mutex, INFINITE);
+ 	g_blocked_zchange[0] = hwnd;
+ 	g_blocked_zchange[1] = behind;
+ 	ReleaseMutex(g_mutex);
+ 
+ 	SetWindowPos(hwnd, behind, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
+ 
+ 	WaitForSingleObject(g_mutex, INFINITE);
+ 	g_blocked_zchange[0] = NULL;
+ 	g_blocked_zchange[1] = NULL;
+ 	ReleaseMutex(g_mutex);
+ }
+ 
+ DLL_EXPORT void
+ SafeFocus(HWND hwnd)
+ {
+ 	WaitForSingleObject(g_mutex, INFINITE);
+ 	g_blocked_focus = hwnd;
+ 	ReleaseMutex(g_mutex);
+ 
+ 	SendMessage(hwnd, g_wm_seamless_focus, 0, 0);
+ 
+ 	WaitForSingleObject(g_mutex, INFINITE);
+ 	g_blocked_focus = NULL;
+ 	ReleaseMutex(g_mutex);
+ }
+ 
  DLL_EXPORT int
  GetInstanceCount()



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642