Fixed RandR not resetting the original screen configuration in some situations.

This commit is contained in:
binary1248 2015-03-27 18:31:41 +01:00 committed by Lukas Dürrenberger
parent 39cdebfe71
commit 5aaf9a6115
2 changed files with 39 additions and 47 deletions

View File

@ -311,7 +311,6 @@ m_inputContext (NULL),
m_isExternal (true),
m_atomWmProtocols(0),
m_atomClose (0),
m_oldVideoMode (-1),
m_hiddenCursor (0),
m_keyRepeat (true),
m_previousSize (-1, -1),
@ -322,6 +321,8 @@ m_fullscreen (false)
m_display = OpenDisplay();
m_connection = XGetXCBConnection(m_display);
std::memset(&m_oldVideoMode, 0, sizeof(m_oldVideoMode));
if (!m_connection)
{
err() << "Failed cast Display object to an XCB connection object" << std::endl;
@ -381,7 +382,6 @@ m_inputContext (NULL),
m_isExternal (false),
m_atomWmProtocols(0),
m_atomClose (0),
m_oldVideoMode (-1),
m_hiddenCursor (0),
m_keyRepeat (true),
m_previousSize (-1, -1),
@ -392,6 +392,8 @@ m_fullscreen ((style & Style::Fullscreen) != 0)
m_display = OpenDisplay();
m_connection = XGetXCBConnection(m_display);
std::memset(&m_oldVideoMode, 0, sizeof(m_oldVideoMode));
if (!m_connection)
{
err() << "Failed cast Display object to an XCB connection object" << std::endl;
@ -1252,7 +1254,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
&error
));
if (error)
if (error || !config)
{
// Failed to get the screen configuration
err() << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl;
@ -1260,7 +1262,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
}
// Save the current video mode before we switch to fullscreen
m_oldVideoMode = config->sizeID;
m_oldVideoMode = *config.get();
// Get the available screen sizes
xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get());
@ -1286,12 +1288,12 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
m_connection,
xcb_randr_set_screen_config(
m_connection,
m_screen->root,
config->root,
XCB_CURRENT_TIME,
config->config_timestamp,
i,
config->rotation,
0//config->rate
config->rate
),
&error
));
@ -1316,35 +1318,24 @@ void WindowImplX11::resetVideoMode()
{
// Get current screen info
ScopedXcbPtr<xcb_generic_error_t> error(NULL);
ScopedXcbPtr<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply(
// Reset the video mode
ScopedXcbPtr<xcb_randr_set_screen_config_reply_t> setScreenConfig(xcb_randr_set_screen_config_reply(
m_connection,
xcb_randr_get_screen_info(
m_connection,
m_screen->root
xcb_randr_set_screen_config(
m_connection,
m_oldVideoMode.root,
XCB_CURRENT_TIME,
m_oldVideoMode.config_timestamp,
m_oldVideoMode.sizeID,
m_oldVideoMode.rotation,
m_oldVideoMode.rate
),
&error
));
if (!error)
{
// Reset the video mode
ScopedXcbPtr<xcb_randr_set_screen_config_reply_t> setScreenConfig(xcb_randr_set_screen_config_reply(
m_connection,
xcb_randr_set_screen_config(
m_connection,
m_screen->root,
CurrentTime,
config->config_timestamp,
m_oldVideoMode,
config->rotation,
config->rate
),
&error
));
if (error)
err() << "Failed to reset old screen configuration" << std::endl;
}
if (error)
err() << "Failed to reset old screen configuration" << std::endl;
// Reset the fullscreen window
fullscreenWindow = NULL;

View File

@ -33,6 +33,7 @@
#include <SFML/System/String.hpp>
#include <X11/Xlib-xcb.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/randr.h>
#include <deque>
@ -270,23 +271,23 @@ private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
xcb_window_t m_window; ///< xcb identifier defining our window
::Display* m_display; ///< Pointer to the display
xcb_connection_t* m_connection; ///< Pointer to the xcb connection
xcb_ewmh_connection_t m_ewmhConnection; ///< xcb EWMH connection
xcb_screen_t* m_screen; ///< Screen identifier
XIM m_inputMethod; ///< Input method linked to the X display
XIC m_inputContext; ///< Input context used to get unicode input in our window
std::deque<xcb_generic_event_t*> m_xcbEvents; ///< Events that were received in another window's loop
bool m_isExternal; ///< Tell whether the window has been created externally or by SFML
Atom m_atomWmProtocols; ///< Atom used to identify WM protocol messages
Atom m_atomClose; ///< Atom used to identify the close event
int m_oldVideoMode; ///< Video mode in use before we switch to fullscreen
Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one
bool m_keyRepeat; ///< Is the KeyRepeat feature enabled?
Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only)
bool m_useSizeHints; ///< Is the size of the window fixed with size hints?
bool m_fullscreen; ///< Is window in fullscreen?
xcb_window_t m_window; ///< xcb identifier defining our window
::Display* m_display; ///< Pointer to the display
xcb_connection_t* m_connection; ///< Pointer to the xcb connection
xcb_ewmh_connection_t m_ewmhConnection; ///< xcb EWMH connection
xcb_screen_t* m_screen; ///< Screen identifier
XIM m_inputMethod; ///< Input method linked to the X display
XIC m_inputContext; ///< Input context used to get unicode input in our window
std::deque<xcb_generic_event_t*> m_xcbEvents; ///< Events that were received in another window's loop
bool m_isExternal; ///< Tell whether the window has been created externally or by SFML
Atom m_atomWmProtocols; ///< Atom used to identify WM protocol messages
Atom m_atomClose; ///< Atom used to identify the close event
xcb_randr_get_screen_info_reply_t m_oldVideoMode; ///< Video mode in use before we switch to fullscreen
Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one
bool m_keyRepeat; ///< Is the KeyRepeat feature enabled?
Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only)
bool m_useSizeHints; ///< Is the size of the window fixed with size hints?
bool m_fullscreen; ///< Is window in fullscreen?
};
} // namespace priv