mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
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:
parent
d3125eecd7
commit
800638ed82
@ -67,15 +67,16 @@ namespace priv
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
WindowImplX11::WindowImplX11(WindowHandle handle) :
|
WindowImplX11::WindowImplX11(WindowHandle handle) :
|
||||||
myWindow (0),
|
myWindow (0),
|
||||||
|
myInputMethod (NULL),
|
||||||
|
myInputContext(NULL),
|
||||||
myIsExternal (true),
|
myIsExternal (true),
|
||||||
myAtomClose (0),
|
myAtomClose (0),
|
||||||
myOldVideoMode(-1),
|
myOldVideoMode(-1),
|
||||||
myHiddenCursor(0),
|
myHiddenCursor(0),
|
||||||
myInputContext(NULL),
|
|
||||||
myKeyRepeat (true)
|
myKeyRepeat (true)
|
||||||
{
|
{
|
||||||
// Get the display and screen
|
// Open a connection with the X server
|
||||||
myDisplay = myDisplayRef.GetDisplay();
|
myDisplay = XOpenDisplay(NULL);
|
||||||
myScreen = DefaultScreen(myDisplay);
|
myScreen = DefaultScreen(myDisplay);
|
||||||
|
|
||||||
// Save the window handle
|
// Save the window handle
|
||||||
@ -107,15 +108,16 @@ myKeyRepeat (true)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
WindowImplX11::WindowImplX11(VideoMode mode, const std::string& title, unsigned long style) :
|
WindowImplX11::WindowImplX11(VideoMode mode, const std::string& title, unsigned long style) :
|
||||||
myWindow (0),
|
myWindow (0),
|
||||||
|
myInputMethod (NULL),
|
||||||
|
myInputContext(NULL),
|
||||||
myIsExternal (false),
|
myIsExternal (false),
|
||||||
myAtomClose (0),
|
myAtomClose (0),
|
||||||
myOldVideoMode(-1),
|
myOldVideoMode(-1),
|
||||||
myHiddenCursor(0),
|
myHiddenCursor(0),
|
||||||
myInputContext(NULL),
|
|
||||||
myKeyRepeat (true)
|
myKeyRepeat (true)
|
||||||
{
|
{
|
||||||
// Get the display and screen
|
// Open a connection with the X server
|
||||||
myDisplay = myDisplayRef.GetDisplay();
|
myDisplay = XOpenDisplay(NULL);
|
||||||
myScreen = DefaultScreen(myDisplay);
|
myScreen = DefaultScreen(myDisplay);
|
||||||
|
|
||||||
// Compute position and size
|
// Compute position and size
|
||||||
@ -261,6 +263,13 @@ WindowImplX11::~WindowImplX11()
|
|||||||
XDestroyWindow(myDisplay, myWindow);
|
XDestroyWindow(myDisplay, myWindow);
|
||||||
XFlush(myDisplay);
|
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
|
else
|
||||||
{
|
{
|
||||||
// Failed to get the screen configuration
|
// 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
|
else
|
||||||
@ -531,18 +540,21 @@ void WindowImplX11::Initialize()
|
|||||||
XSetWMProtocols(myDisplay, myWindow, &myAtomClose, 1);
|
XSetWMProtocols(myDisplay, myWindow, &myAtomClose, 1);
|
||||||
|
|
||||||
// Create the input context
|
// Create the input context
|
||||||
XIM inputMethod = myDisplayRef.GetInputMethod();
|
myInputMethod = XOpenIM(myDisplay, NULL, NULL, NULL);
|
||||||
if (inputMethod)
|
if (myInputMethod)
|
||||||
{
|
{
|
||||||
myInputContext = XCreateIC(inputMethod,
|
myInputContext = XCreateIC(myInputMethod,
|
||||||
XNClientWindow, myWindow,
|
XNClientWindow, myWindow,
|
||||||
XNFocusWindow, myWindow,
|
XNFocusWindow, myWindow,
|
||||||
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
||||||
NULL);
|
NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myInputContext = NULL;
|
||||||
|
}
|
||||||
if (!myInputContext)
|
if (!myInputContext)
|
||||||
std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
|
std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
// Show the window
|
// Show the window
|
||||||
XMapWindow(myDisplay, myWindow);
|
XMapWindow(myDisplay, myWindow);
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Event.hpp>
|
||||||
#include <SFML/Window/WindowImpl.hpp>
|
#include <SFML/Window/WindowImpl.hpp>
|
||||||
#include <SFML/Window/Linux/DisplayRef.hpp>
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -183,15 +182,15 @@ private :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
DisplayRef myDisplayRef; ///< Connection to the X server
|
|
||||||
::Window myWindow; ///< X11 structure defining our window
|
::Window myWindow; ///< X11 structure defining our window
|
||||||
::Display* myDisplay; ///< Pointer to the display
|
::Display* myDisplay; ///< Pointer to the display
|
||||||
int myScreen; ///< Screen identifier
|
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
|
bool myIsExternal; ///< Tell whether the window has been created externally or by SFML
|
||||||
Atom myAtomClose; ///< Atom used to identify the close event
|
Atom myAtomClose; ///< Atom used to identify the close event
|
||||||
int myOldVideoMode; ///< Video mode in use before we switch to fullscreen
|
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
|
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 ?
|
bool myKeyRepeat; ///< Is the KeyRepeat feature enabled ?
|
||||||
XEvent myLastKeyReleaseEvent; ///< Last key release event we received (needed for discarding repeated key events)
|
XEvent myLastKeyReleaseEvent; ///< Last key release event we received (needed for discarding repeated key events)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user