Rewrite of fullscreen toggling in linux. This goes back to using the EWMH specifications. I wasn't using it right before, but now it should work on all EWMH compliant window managers (like KDE, Metacity, Compiz, etc). Since this doesn't need an override redirect Alt-Tab works even in fullscreen mode. This also allows for some other nice things to be done.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5199 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice
2010-03-15 23:25:11 +00:00
parent c5d4c2c1b1
commit 2015d252f0
12 changed files with 387 additions and 300 deletions

View File

@ -523,7 +523,7 @@ void CFrame::OnQuit(wxCommandEvent& WXUNUSED (event))
}
#if defined HAVE_X11 && HAVE_X11
void X11_SendEvent(const char *message)
void CFrame::X11_SendClientEvent(const char *message)
{
XEvent event;
Display *dpy = (Display *)Core::GetWindowHandle();
@ -536,9 +536,24 @@ void X11_SendEvent(const char *message)
// Send the event
if (!XSendEvent(dpy, win, False, False, &event))
{
ERROR_LOG(VIDEO, "Failed to send message %s to the emulator window.\n", message);
}
}
void X11_SendKeyEvent(int key)
{
XEvent event;
Display *dpy = (Display *)Core::GetWindowHandle();
Window win = *(Window *)Core::GetXWindow();
// Init X event structure for key press event
event.xkey.type = KeyPress;
// WARNING: This works for '3' to '7'. If in the future other keys are needed
// convert with InputCommon::wxCharCodeWXToX from X11InputBase.cpp.
event.xkey.keycode = XKeysymToKeycode(dpy, key);
// Send the event
if (!XSendEvent(dpy, win, False, False, &event))
ERROR_LOG(VIDEO, "Failed to send key press event to the emulator window.\n");
}
#endif
@ -547,8 +562,13 @@ void X11_SendEvent(const char *message)
void CFrame::OnActive(wxActivateEvent& event)
{
#if defined(HAVE_X11) && HAVE_X11 && defined(HAVE_GTK2) && HAVE_GTK2 && defined(wxGTK)
if (event.GetActive() && (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE))
X11_SendEvent("WINDOW_REFOCUS");
if (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
{
if (event.GetActive())
X11_SendClientEvent("FOCUSIN");
else
X11_SendClientEvent("FOCUSOUT");
}
#endif
event.Skip();
}
@ -618,7 +638,7 @@ void CFrame::OnResizeAll(wxSizeEvent& event)
event.Skip();
#if defined(HAVE_X11) && HAVE_X11 && defined(HAVE_GTK2) && HAVE_GTK2 && defined(wxGTK)
if (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
X11_SendEvent("MAIN_RESIZED");
X11_SendClientEvent("RESIZE");
#endif
//wxWindow * Win = (wxWindow*)event.GetEventObject();
//NOTICE_LOG(CONSOLE, "OnResizeAll: %i", (HWND)Win->GetHWND());
@ -675,11 +695,17 @@ void CFrame::OnHostMessage(wxCommandEvent& event)
}
break;
#if defined(HAVE_X11) && HAVE_X11
case WM_USER_CREATE:
bRenderToMain = true;
break;
case TOGGLE_FULLSCREEN:
DoFullscreen(!IsFullScreen());
break;
case WM_USER_STOP:
main_frame->DoStop();
DoStop();
break;
case WM_USER_PAUSE:
main_frame->DoPause();
DoPause();
break;
#endif
}
@ -787,8 +813,14 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
{
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
}
#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_GTK2) && HAVE_GTK2 && defined(wxGTK)
if (event.GetKeyCode() >= '3' && event.GetKeyCode() <= '7') // Send this to the video plugin
{
X11_SendKeyEvent(event.GetKeyCode());
}
#endif
// Send the keyboard status to the Input plugin
if(Core::GetState() != Core::CORE_UNINITIALIZED)
CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 1); // 1 = Down
@ -938,44 +970,46 @@ wxAuiNotebook* CFrame::CreateEmptyNotebook()
void CFrame::DoFullscreen(bool bF)
{
#if defined HAVE_X11 && HAVE_X11
if ((Core::GetState() == Core::CORE_RUN))
X11_SendEvent("TOGGLE_FULLSCREEN");
#endif
// Only switch this to fullscreen if we're rendering to main AND if we're running a game
// plus if a modal dialog is open, this will still process the keyboard events, and may cause
// the main window to become unresponsive, so we have to avoid that.
if ((bRenderToMain && Core::GetState() == Core::CORE_RUN))
if ((Core::GetState() == Core::CORE_RUN) || (Core::GetState() == Core::CORE_PAUSE))
{
ShowFullScreen(bF);
if (bRenderToMain)
{
ShowFullScreen(bF);
if (bF)
{
// Save the current mode before going to fullscreen
AuiCurrent = m_Mgr->SavePerspective();
m_Mgr->LoadPerspective(AuiFullscreen, true);
}
else
{
// Restore saved perspective
m_Mgr->LoadPerspective(AuiCurrent, true);
}
if (bF)
{
// Save the current mode before going to fullscreen
AuiCurrent = m_Mgr->SavePerspective();
m_Mgr->LoadPerspective(AuiFullscreen, true);
}
else
{
// Restore saved perspective
m_Mgr->LoadPerspective(AuiCurrent, true);
}
// Show the cursor again, in case it was hidden
if (IsFullScreen())
{
#ifdef _WIN32
MSWSetCursor(true);
#endif
}
}
#ifdef _WIN32
else // Post the message to the separate rendering window which will then handle it.
{
BringWindowToTop((HWND)Core::GetWindowHandle());
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, TOGGLE_FULLSCREEN, 0);
}
// Show the cursor again, in case it was hidden
if (IsFullScreen())
{
MSWSetCursor(true);
}
#endif
}
#ifdef _WIN32
else // Post the message to the separate rendering window which will then handle it.
{
BringWindowToTop((HWND)Core::GetWindowHandle());
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, TOGGLE_FULLSCREEN, 0);
}
#elif defined HAVE_X11 && HAVE_X11
else // Send the event to the separate rendering window which will then handle it.
X11_SendClientEvent("TOGGLE_FULLSCREEN");
#endif
}
}
// Debugging, show loose windows