Now restoring input focus when entering the screen to the window

that had the focus when the screen was left.
This commit is contained in:
crs 2004-05-12 20:28:00 +00:00
parent 455d0210b2
commit 242050d0f2
2 changed files with 16 additions and 0 deletions

View File

@ -114,6 +114,8 @@ CXWindowsScreen::CXWindowsScreen(bool isPrimary) :
m_xCenter(0), m_yCenter(0), m_xCenter(0), m_yCenter(0),
m_xCursor(0), m_yCursor(0), m_xCursor(0), m_yCursor(0),
m_keyState(NULL), m_keyState(NULL),
m_lastFocus(None),
m_lastFocusRevert(RevertToNone),
m_im(NULL), m_im(NULL),
m_ic(NULL), m_ic(NULL),
m_lastKeycode(0), m_lastKeycode(0),
@ -257,6 +259,13 @@ CXWindowsScreen::enter()
// keyboard if they're grabbed. // keyboard if they're grabbed.
XUnmapWindow(m_display, m_window); XUnmapWindow(m_display, m_window);
// set the input focus to what it had been when we took it
if (m_lastFocus != None) {
// the window may not exist anymore so ignore errors
CXWindowsUtil::CErrorLock lock(m_display);
XSetInputFocus(m_display, m_lastFocus, m_lastFocusRevert, CurrentTime);
}
/* maybe call this if entering for the screensaver /* maybe call this if entering for the screensaver
// set keyboard focus to root window. the screensaver should then // set keyboard focus to root window. the screensaver should then
// pick up key events for when the user enters a password to unlock. // pick up key events for when the user enters a password to unlock.
@ -305,6 +314,9 @@ CXWindowsScreen::leave()
return false; return false;
} }
// save current focus
XGetInputFocus(m_display, &m_lastFocus, &m_lastFocusRevert);
// take focus // take focus
XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime); XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime);

View File

@ -156,6 +156,10 @@ private:
// keyboard stuff // keyboard stuff
CXWindowsKeyState* m_keyState; CXWindowsKeyState* m_keyState;
// input focus stuff
Window m_lastFocus;
int m_lastFocusRevert;
// input method stuff // input method stuff
XIM m_im; XIM m_im;
XIC m_ic; XIC m_ic;