@@ -36,35 +36,6 @@ private bool CanShowToolbar {
3636 }
3737 }
3838
39- private void ShowToolbar ( ) {
40- // this is checked in LowLevelMouseProc because
41- // otherwise plugins such as Viscape which
42- // create their own window can steal the
43- // mouse move event
44- // it cannot happen in PreFilterMessage!
45- // our window may not even get these messages
46- // all that matters is the mouse position, regardless
47- // of if our window is active
48- Point toolBarToolStripMousePosition = toolBarToolStrip . PointToClient ( MousePosition ) ;
49-
50- if ( toolBarToolStrip . Visible ) {
51- if ( ! toolBarToolStrip . ClientRectangle . Contains ( toolBarToolStripMousePosition ) ) {
52- // the standard layout when the mouse is not in the toolbar rectangle
53- // if in fullscreen, ensure toolbar is invisible
54- // if not in fullscreen, ensure toolbar is visible
55- toolBarToolStrip . Visible = ! Fullscreen ;
56- }
57- } else {
58- if ( toolBarToolStripMousePosition . Y == 0
59- && toolBarToolStrip . ClientRectangle . Contains ( toolBarToolStripMousePosition ) ) {
60- // mouse in toolbar rectangle
61- // if in fullscreen, show toolbar if we can
62- // if not in fullscreen, ensure toolbar is visible
63- toolBarToolStrip . Visible = CanShowToolbar || ! Fullscreen ;
64- }
65- }
66- }
67-
6839 private readonly HookProc lowLevelMouseProc ;
6940 private IntPtr mouseHook = IntPtr . Zero ;
7041
@@ -478,6 +449,51 @@ static public void DeactivateMode() {
478449 }
479450 }
480451
452+ private void ShowToolbar ( ) {
453+ // this is checked in LowLevelMouseProc because
454+ // otherwise plugins such as Viscape which
455+ // create their own window can steal the
456+ // mouse move event
457+ // it cannot happen in PreFilterMessage!
458+ // our window may not even get these messages
459+ // all that matters is the mouse position, regardless
460+ // of if our window is active
461+ Point toolBarToolStripMousePosition = toolBarToolStrip . PointToClient ( MousePosition ) ;
462+
463+ if ( toolBarToolStrip . Visible ) {
464+ if ( ! toolBarToolStrip . ClientRectangle . Contains ( toolBarToolStripMousePosition ) ) {
465+ // the standard layout when the mouse is not in the toolbar rectangle
466+ // if in fullscreen, ensure toolbar is invisible
467+ // if not in fullscreen, ensure toolbar is visible
468+ toolBarToolStrip . Visible = ! Fullscreen ;
469+ }
470+ } else {
471+ if ( toolBarToolStripMousePosition . Y == 0
472+ && toolBarToolStrip . ClientRectangle . Contains ( toolBarToolStripMousePosition ) ) {
473+ // mouse in toolbar rectangle
474+ // if in fullscreen, show toolbar if we can
475+ // if not in fullscreen, ensure toolbar is visible
476+ toolBarToolStrip . Visible = CanShowToolbar || ! Fullscreen ;
477+ }
478+ }
479+ }
480+
481+ private bool FindDialog ( ) {
482+ // test if the new window is a dialog that prevents focus to this window
483+ // if there is a window above us in the z-order
484+ IntPtr previousWindow = GetWindow ( Handle , GW . GW_HWNDPREV ) ;
485+
486+ if ( previousWindow == IntPtr . Zero ) {
487+ return false ;
488+ }
489+
490+ // if we own the window above us in the z-order
491+ if ( Handle != GetWindow ( previousWindow , GW . GW_OWNER ) ) {
492+ return false ;
493+ }
494+ return true ;
495+ }
496+
481497 private bool addressToolStripSpringTextBoxEntered = false ;
482498
483499 public void AddressInvalid ( ) {
@@ -751,44 +767,24 @@ private void WebBrowserMode_Deactivate(object sender, EventArgs e) {
751767 return ;
752768 }
753769
754- IntPtr foregroundWindow = GetForegroundWindow ( ) ;
770+ bool foundDialog = FindDialog ( ) ;
755771
756- // we are the active window, because we are only now deactivating
757- // if this process has the foreground window, it'll be the active window
758- if ( Handle == foregroundWindow ) {
772+ if ( foundDialog && ! CanFocus ) {
773+ // the new window is a dialog we own that prevents focus to this window
774+ // in this case, it is important we don't exit fullscreen
775+ // (causes softlock with minimizing)
776+ CanShowToolbar = false ;
777+ return ;
778+ }
779+
780+ if ( foundDialog || Handle == GetForegroundWindow ( ) ) {
781+ // the new window is a dialog we own that does not prevent focus to this window, or
759782 // this process opened a new window
760- if ( ! CanFocus ) {
761- // if there is a window above us in the z-order
762- IntPtr previousWindow = GetWindow ( Handle , GW . GW_HWNDPREV ) ;
763-
764- if ( previousWindow != IntPtr . Zero ) {
765- // if we own the window above us in the z-order
766- if ( Handle == GetWindow ( previousWindow , GW . GW_OWNER ) ) {
767- // the new window is a dialog that prevents focus to this window
768- CanShowToolbar = false ;
769- return ;
770- }
771- }
772- }
773-
774- // the new window is not a dialog that prevents focus to this window
783+ // in this case, we exit fullscreen because we have a relationship with this window
775784 Fullscreen = false ;
776785 return ;
777786 }
778787
779- // another process opened a window
780- if ( foregroundWindow != IntPtr . Zero ) {
781- // if we own the foreground window
782- if ( Handle == GetWindow ( foregroundWindow , GW . GW_OWNER ) ) {
783- // the new window is owned by this window
784- if ( CanFocus ) {
785- // the new window is not a dialog that prevents focus to this window
786- Fullscreen = false ;
787- }
788- return ;
789- }
790- }
791-
792788 // we use SW_SHOWMINNOACTIVE so new windows (e.g. Task Manager) don't lose focus
793789 WINDOWPLACEMENT windowPlacement = WindowPlacement ;
794790 windowPlacement . showCmd = SW . SW_SHOWMINNOACTIVE ;
0 commit comments