From 800638ed82a9f31d86eeb6c7d23abe4b715cc4e7 Mon Sep 17 00:00:00 2001 From: laurentgom Date: Fri, 24 Jul 2009 14:11:50 +0000 Subject: [PATCH] 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 --- src/SFML/Window/Linux/WindowImplX11.cpp | 40 ++++++++++++++++--------- src/SFML/Window/Linux/WindowImplX11.hpp | 7 ++--- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/SFML/Window/Linux/WindowImplX11.cpp b/src/SFML/Window/Linux/WindowImplX11.cpp index db88f8cd0..a11b15d1a 100644 --- a/src/SFML/Window/Linux/WindowImplX11.cpp +++ b/src/SFML/Window/Linux/WindowImplX11.cpp @@ -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 @@ -260,7 +262,14 @@ 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); - - if (!myInputContext) - std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl; + } + 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); diff --git a/src/SFML/Window/Linux/WindowImplX11.hpp b/src/SFML/Window/Linux/WindowImplX11.hpp index a0463b132..8065349eb 100644 --- a/src/SFML/Window/Linux/WindowImplX11.hpp +++ b/src/SFML/Window/Linux/WindowImplX11.hpp @@ -30,7 +30,6 @@ //////////////////////////////////////////////////////////// #include #include -#include #include #include #include @@ -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 + 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) };