Each window now has its own X display, which solves potential multithreading issues (on Linux)

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1192 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-07-24 14:11:50 +00:00
parent d3125eecd7
commit 800638ed82
2 changed files with 29 additions and 18 deletions

View File

@ -67,15 +67,16 @@ namespace priv
////////////////////////////////////////////////////////////
WindowImplX11::WindowImplX11(WindowHandle handle) :
myWindow (0),
myInputMethod (NULL),
myInputContext(NULL),
myIsExternal (true),
myAtomClose (0),
myOldVideoMode(-1),
myHiddenCursor(0),
myInputContext(NULL),
myKeyRepeat (true)
{
// Get the display and screen
myDisplay = myDisplayRef.GetDisplay();
// Open a connection with the X server
myDisplay = XOpenDisplay(NULL);
myScreen = DefaultScreen(myDisplay);
// Save the window handle
@ -107,15 +108,16 @@ myKeyRepeat (true)
////////////////////////////////////////////////////////////
WindowImplX11::WindowImplX11(VideoMode mode, const std::string& title, unsigned long style) :
myWindow (0),
myInputMethod (NULL),
myInputContext(NULL),
myIsExternal (false),
myAtomClose (0),
myOldVideoMode(-1),
myHiddenCursor(0),
myInputContext(NULL),
myKeyRepeat (true)
{
// Get the display and screen
myDisplay = myDisplayRef.GetDisplay();
// Open a connection with the X server
myDisplay = XOpenDisplay(NULL);
myScreen = DefaultScreen(myDisplay);
// Compute position and size
@ -261,6 +263,13 @@ WindowImplX11::~WindowImplX11()
XDestroyWindow(myDisplay, myWindow);
XFlush(myDisplay);
}
// Close the input method
if (myInputMethod)
XCloseIM(myInputMethod);
// Close the connection with the X server
XCloseDisplay(myDisplay);
}
@ -507,7 +516,7 @@ void WindowImplX11::SwitchToFullscreen(const VideoMode& mode)
else
{
// Failed to get the screen configuration
std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to windiw mode" << std::endl;
std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl;
}
}
else
@ -531,18 +540,21 @@ void WindowImplX11::Initialize()
XSetWMProtocols(myDisplay, myWindow, &myAtomClose, 1);
// Create the input context
XIM inputMethod = myDisplayRef.GetInputMethod();
if (inputMethod)
myInputMethod = XOpenIM(myDisplay, NULL, NULL, NULL);
if (myInputMethod)
{
myInputContext = XCreateIC(inputMethod,
myInputContext = XCreateIC(myInputMethod,
XNClientWindow, myWindow,
XNFocusWindow, myWindow,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
NULL);
}
else
{
myInputContext = NULL;
}
if (!myInputContext)
std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
}
// Show the window
XMapWindow(myDisplay, myWindow);

View File

@ -30,7 +30,6 @@
////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <SFML/Window/WindowImpl.hpp>
#include <SFML/Window/Linux/DisplayRef.hpp>
#include <X11/Xlib.h>
#include <set>
#include <string>
@ -183,15 +182,15 @@ private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
DisplayRef myDisplayRef; ///< Connection to the X server
::Window myWindow; ///< X11 structure defining our window
::Display* myDisplay; ///< Pointer to the display
int myScreen; ///< Screen identifier
XIM myInputMethod; ///< Input method linked to the X display
XIC myInputContext; ///< Input context used to get unicode input in our window
bool myIsExternal; ///< Tell whether the window has been created externally or by SFML
Atom myAtomClose; ///< Atom used to identify the close event
int myOldVideoMode; ///< Video mode in use before we switch to fullscreen
Cursor myHiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one
XIC myInputContext; ///< Input context used to get unicode input in our window
bool myKeyRepeat; ///< Is the KeyRepeat feature enabled ?
XEvent myLastKeyReleaseEvent; ///< Last key release event we received (needed for discarding repeated key events)
};