Converted Unix Window implementation from XCB back to Xlib.

This commit is contained in:
binary1248 2016-08-14 02:52:49 +02:00 committed by Lukas Dürrenberger
parent fae3b65f05
commit 9996b7abb6
14 changed files with 831 additions and 1860 deletions

View File

@ -285,10 +285,7 @@ if(SFML_STATIC_LIBRARIES)
# find libraries # find libraries
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD) if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
find_sfml_dependency(X11_LIBRARY "X11" X11) find_sfml_dependency(X11_LIBRARY "X11" X11)
find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb) find_sfml_dependency(XRANDR_LIBRARY "Xrandr" Xrandr)
find_sfml_dependency(X11_XCB_LIBRARY "X11-xcb" X11-xcb libX11-xcb)
find_sfml_dependency(XCB_RANDR_LIBRARY "xcb-randr" xcb-randr libxcb-randr)
find_sfml_dependency(XCB_IMAGE_LIBRARY "xcb-image" xcb-image libxcb-image)
endif() endif()
if(FIND_SFML_OS_LINUX) if(FIND_SFML_OS_LINUX)
@ -299,9 +296,9 @@ if(SFML_STATIC_LIBRARIES)
if(FIND_SFML_OS_WINDOWS) if(FIND_SFML_OS_WINDOWS)
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32") set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32")
elseif(FIND_SFML_OS_LINUX) elseif(FIND_SFML_OS_LINUX)
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} ${UDEV_LIBRARIES}) set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY} ${UDEV_LIBRARIES})
elseif(FIND_SFML_OS_FREEBSD) elseif(FIND_SFML_OS_FREEBSD)
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} "usbhid") set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY} "usbhid")
elseif(FIND_SFML_OS_MACOSX) elseif(FIND_SFML_OS_MACOSX)
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon") set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon")
endif() endif()

View File

@ -1,97 +0,0 @@
# Try to find libxcb
#
#
# Once done this will define:
# LIBXCB_FOUND - True if xcb was found
# LIBXCB_INCLUDE_DIRS - Directories containing the headers
# LIBXCB_LIBRARIES - List of libraries to link to
#
# Also for each requested component:
# LIBXCB_${UPPER_COMPONENT_NAME}_FOUND
# LIBXCB_${UPPER_COMPONENT_NAME}_INCLUDE_DIRS
# LIBXCB_${UPPER_COMPONENT_NAME}_LIBRARIES
include(FindPackageHandleStandardArgs)
IF(NOT WIN32)
IF(LIBXCB_LIBRARIES AND LIBXCB_INCLUDE_DIR)
set(XCB_FIND_QUIETLY TRUE)
ENDIF()
# Find xcb
FIND_PATH(LIBXCB_INCLUDE_DIR xcb/xcb.h)
FIND_LIBRARY(LIBXCB_LIBRARY NAMES xcb libxcb)
# Add xcb info to LIBXCB_LIBRARIES and LIBXCB_INCLUDE_DIRS
SET(LIBXCB_LIBRARIES ${LIBXCB_LIBRARY})
SET(LIBXCB_INCLUDE_DIRS ${LIBXCB_INCLUDE_DIR})
find_package_handle_standard_args(LIBXCB DEFAULT_MSG
LIBXCB_LIBRARY LIBXCB_INCLUDE_DIR)
mark_as_advanced(LIBXCB_LIBRARY LIBXCB_INCLUDE_DIR)
# Check whether we should search for XLIB_XCB
set(FIND_XLIB_XCB FALSE)
FOREACH(XCB_COMPONENT ${XCB_FIND_COMPONENTS})
# Generate upper string of the component name
string(TOUPPER ${XCB_COMPONENT} XCB_COMPONENT_UPPER)
IF(${XCB_COMPONENT_UPPER} MATCHES "XLIB_XCB")
set(FIND_XLIB_XCB TRUE)
ELSE()
# XCB_COMPONENTS is generated to be a copy of XCB_FIND_COMPONENTS
# without XLIB_XCB (for later component search)
set(XCB_COMPONENTS ${XCB_COMPONENTS} ${XCB_COMPONENT})
ENDIF()
ENDFOREACH()
# Find XLIB_XCB if requested
IF(FIND_XLIB_XCB)
FIND_PATH(XLIB_XCB_INCLUDE_DIR X11/Xlib-xcb.h)
FIND_LIBRARY(XLIB_XCB_LIBRARY NAMES X11-xcb libX11-xcb)
SET(XLIB_XCB_LIBRARIES ${XLIB_XCB_LIBRARY})
SET(XLIB_XCB_INCLUDE_DIRS ${XLIB_XCB_INCLUDE_DIR})
find_package_handle_standard_args(XLIB_XCB DEFAULT_MSG
XLIB_XCB_LIBRARY LIBXCB_INCLUDE_DIR)
mark_as_advanced(XLIB_XCB_LIBRARY XLIB_XCB_INCLUDE_DIR)
# Add xlib_xcb info to LIBXCB_LIBRARIES and LIBXCB_INCLUDE_DIRS
set(LIBXCB_LIBRARIES ${LIBXCB_LIBRARIES} ${XLIB_XCB_LIBRARIES})
set(LIBXCB_INCLUDE_DIRS ${LIBXCB_INCLUDE_DIRS} ${XLIB_XCB_INCLUDE_DIR})
if(NOT XLIB_XCB_FOUND)
message(FATAL_ERROR "XlibXcb library not found")
endif()
ELSE()
# Add component name to the component list
set(XCB_COMPONENTS ${XCB_FIND_COMPONENTS})
ENDIF()
# Loop through requested xcb components (does not contain xlib_xcb)
FOREACH(XCB_COMPONENT ${XCB_COMPONENTS})
# Generate lower and upper string of the component name
string(TOLOWER ${XCB_COMPONENT} XCB_COMPONENT_LOWER)
string(TOUPPER ${XCB_COMPONENT} XCB_COMPONENT_UPPER)
# Find the specific component
FIND_LIBRARY(LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY
NAMES libxcb-${XCB_COMPONENT_LOWER} xcb-${XCB_COMPONENT_LOWER})
find_package_handle_standard_args(LIBXCB_${XCB_COMPONENT_UPPER} DEFAULT_MSG
LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY LIBXCB_INCLUDE_DIR)
mark_as_advanced(LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY)
# Append the component's library path to LIBXCB_LIBRARIES
set(LIBXCB_LIBRARIES ${LIBXCB_LIBRARIES} ${LIBXCB_${XCB_COMPONENT_UPPER}_LIBRARY})
if(NOT LIBXCB_${XCB_COMPONENT_UPPER}_FOUND)
message(FATAL_ERROR "xcb-${XCB_COMPONENT_LOWER} not found")
endif()
ENDFOREACH()
endif()

View File

@ -5,7 +5,7 @@
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <SFML/OpenGL.hpp> #include <SFML/OpenGL.hpp>
#include <X11/Xlib-xcb.h> #include <X11/Xlib.h>
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
@ -133,77 +133,46 @@ int main()
if (!display) if (!display)
return EXIT_FAILURE; return EXIT_FAILURE;
// Get the XCB connection for the opened display. // Get the default screen
xcb_connection_t* xcbConnection = XGetXCBConnection(display); int screen = DefaultScreen(display);
if (!xcbConnection) // Let's create the main window
{ XSetWindowAttributes attributes;
sf::err() << "Failed to get the XCB connection for opened display." << std::endl; attributes.background_pixel = BlackPixel(display, screen);
attributes.event_mask = KeyPressMask;
Window window = XCreateWindow(display, RootWindow(display, screen),
0, 0, 650, 330, 0,
DefaultDepth(display, screen),
InputOutput,
DefaultVisual(display, screen),
CWBackPixel | CWEventMask, &attributes);
if (!window)
return EXIT_FAILURE; return EXIT_FAILURE;
}
// Get XCB screen. // Set the window's name
const xcb_setup_t* xcbSetup = xcb_get_setup(xcbConnection); XStoreName(display, window , "SFML Window");
xcb_screen_iterator_t xcbScreenIter = xcb_setup_roots_iterator(xcbSetup);
xcb_screen_t* screen = xcbScreenIter.data;
if (!screen) // Let's create the windows which will serve as containers for our SFML views
{ Window view1 = XCreateWindow(display, window,
sf::err() << "Failed to get the XCB screen." << std::endl; 10, 10, 310, 310, 0,
return EXIT_FAILURE; DefaultDepth(display, screen),
} InputOutput,
DefaultVisual(display, screen),
0, NULL);
Window view2 = XCreateWindow(display, window,
330, 10, 310, 310, 0,
DefaultDepth(display, screen),
InputOutput,
DefaultVisual(display, screen),
0, NULL);
// Generate the XCB window IDs. // Show our windows
xcb_window_t rootWindowId = xcb_generate_id(xcbConnection); XMapWindow(display, window);
xcb_window_t view1WindowId = xcb_generate_id(xcbConnection); XFlush(display);
xcb_window_t view2WindowId = xcb_generate_id(xcbConnection);
// Create the root window with a black background.
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
uint32_t attributes[2] = {screen->black_pixel, XCB_EVENT_MASK_KEY_PRESS};
xcb_create_window(xcbConnection,
XCB_COPY_FROM_PARENT,
rootWindowId,
screen->root,
0, 0, 650, 330,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual,
mask, attributes);
// Create windows for the SFML views.
xcb_create_window(xcbConnection,
XCB_COPY_FROM_PARENT,
view1WindowId,
rootWindowId,
10, 10, 310, 310,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual,
mask, attributes);
xcb_create_window(xcbConnection,
XCB_COPY_FROM_PARENT,
view2WindowId,
rootWindowId,
330, 10, 310, 310,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual,
mask, attributes);
// Map windows to screen.
xcb_map_window(xcbConnection, rootWindowId);
xcb_map_window(xcbConnection, view1WindowId);
xcb_map_window(xcbConnection, view2WindowId);
// Flush commands.
xcb_flush(xcbConnection);
// Create our SFML views // Create our SFML views
sf::Window sfmlView1(view1WindowId); sf::Window sfmlView1(view1);
sf::Window sfmlView2(view2WindowId); sf::Window sfmlView2(view2);
// Create a clock for measuring elapsed time // Create a clock for measuring elapsed time
sf::Clock clock; sf::Clock clock;
@ -214,13 +183,22 @@ int main()
// Start the event loop // Start the event loop
bool running = true; bool running = true;
xcb_generic_event_t* event = NULL;
while (running) while (running)
{ {
while ((event = xcb_poll_for_event(xcbConnection))) while (XPending(display))
{ {
// Get the next pending event
XEvent event;
XNextEvent(display, &event);
// Process it
switch (event.type)
{
// Any key is pressed: quit
case KeyPress:
running = false; running = false;
break;
}
} }
// Draw something into our views // Draw something into our views
@ -232,5 +210,8 @@ int main()
sfmlView2.display(); sfmlView2.display();
} }
// Close the display
XCloseDisplay(display);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -75,8 +75,6 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
${SRCROOT}/Unix/Display.hpp ${SRCROOT}/Unix/Display.hpp
${SRCROOT}/Unix/InputImpl.cpp ${SRCROOT}/Unix/InputImpl.cpp
${SRCROOT}/Unix/InputImpl.hpp ${SRCROOT}/Unix/InputImpl.hpp
${SRCROOT}/Unix/ScopedXcbPtr.hpp
${SRCROOT}/Unix/ScopedXcbPtr.inl
${SRCROOT}/Unix/SensorImpl.cpp ${SRCROOT}/Unix/SensorImpl.cpp
${SRCROOT}/Unix/SensorImpl.hpp ${SRCROOT}/Unix/SensorImpl.hpp
${SRCROOT}/Unix/VideoModeImpl.cpp ${SRCROOT}/Unix/VideoModeImpl.cpp
@ -200,18 +198,14 @@ if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
if(NOT X11_FOUND) if(NOT X11_FOUND)
message(FATAL_ERROR "X11 library not found") message(FATAL_ERROR "X11 library not found")
endif() endif()
if(NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "Xrandr library not found")
endif()
include_directories(${X11_INCLUDE_DIR}) include_directories(${X11_INCLUDE_DIR})
endif() endif()
if(NOT SFML_OPENGL_ES) if(NOT SFML_OPENGL_ES)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR})
if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
find_package(XCB COMPONENTS xlib_xcb image randr REQUIRED)
if(NOT LIBXCB_FOUND)
message(FATAL_ERROR "Xcb library not found")
endif()
include_directories(${LIBXCB_INCLUDE_DIRS})
endif()
endif() endif()
if(SFML_OPENGL_ES AND SFML_OS_LINUX) if(SFML_OPENGL_ES AND SFML_OS_LINUX)
find_package(EGL REQUIRED) find_package(EGL REQUIRED)
@ -231,9 +225,9 @@ endif()
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
list(APPEND WINDOW_EXT_LIBS winmm gdi32) list(APPEND WINDOW_EXT_LIBS winmm gdi32)
elseif(SFML_OS_LINUX) elseif(SFML_OS_LINUX)
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${LIBXCB_LIBRARIES} ${UDEV_LIBRARIES}) list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES})
elseif(SFML_OS_FREEBSD) elseif(SFML_OS_FREEBSD)
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${LIBXCB_LIBRARIES} usbhid) list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} usbhid)
elseif(SFML_OS_MACOSX) elseif(SFML_OS_MACOSX)
list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon") list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon")
elseif(SFML_OS_IOS) elseif(SFML_OS_IOS)

View File

@ -27,9 +27,9 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <SFML/Window/Unix/Display.hpp> #include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <cassert> #include <cassert>
#include <cstdlib>
#include <map> #include <map>
@ -39,7 +39,7 @@ namespace
Display* sharedDisplay = NULL; Display* sharedDisplay = NULL;
unsigned int referenceCount = 0; unsigned int referenceCount = 0;
typedef std::map<std::string, xcb_atom_t> AtomMap; typedef std::map<std::string, Atom> AtomMap;
AtomMap atoms; AtomMap atoms;
} }
@ -68,13 +68,6 @@ Display* OpenDisplay()
} }
////////////////////////////////////////////////////////////
xcb_connection_t* OpenConnection()
{
return XGetXCBConnection(OpenDisplay());
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void CloseDisplay(Display* display) void CloseDisplay(Display* display)
{ {
@ -87,81 +80,22 @@ void CloseDisplay(Display* display)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void CloseConnection(xcb_connection_t* connection) Atom getAtom(const std::string& name, bool onlyIfExists)
{
assert(connection == XGetXCBConnection(sharedDisplay));
return CloseDisplay(sharedDisplay);
}
////////////////////////////////////////////////////////////
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
{
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection));
for (; iter.rem; --screen_nbr, xcb_screen_next (&iter))
{
if (screen_nbr == 0)
return iter.data;
}
return NULL;
}
////////////////////////////////////////////////////////////
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection)
{
assert(connection == XGetXCBConnection(sharedDisplay));
return XCBScreenOfDisplay(connection, XDefaultScreen(sharedDisplay));
}
////////////////////////////////////////////////////////////
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection)
{
assert(connection == XGetXCBConnection(sharedDisplay));
xcb_screen_t* screen = XCBScreenOfDisplay(connection, XDefaultScreen(sharedDisplay));
if (screen)
return screen->root;
return 0;
}
////////////////////////////////////////////////////////////
xcb_atom_t getAtom(const std::string& name, bool onlyIfExists)
{ {
AtomMap::const_iterator iter = atoms.find(name); AtomMap::const_iterator iter = atoms.find(name);
if (iter != atoms.end()) if (iter != atoms.end())
return iter->second; return iter->second;
ScopedXcbPtr<xcb_generic_error_t> error(NULL); Display* display = OpenDisplay();
xcb_connection_t* connection = OpenConnection(); Atom atom = XInternAtom(display, name.c_str(), onlyIfExists ? True : False);
ScopedXcbPtr<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply( CloseDisplay(display);
connection,
xcb_intern_atom(
connection,
onlyIfExists,
name.size(),
name.c_str()
),
&error
));
CloseConnection(connection); atoms[name] = atom;
if (error || !reply) return atom;
{
err() << "Failed to get " << name << " atom." << std::endl;
return XCB_ATOM_NONE;
}
atoms[name] = reply->atom;
return reply->atom;
} }
} // namespace priv } // namespace priv

View File

@ -28,7 +28,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <X11/Xlib-xcb.h> #include <X11/Xlib.h>
#include <string> #include <string>
@ -47,17 +47,6 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Display* OpenDisplay(); Display* OpenDisplay();
////////////////////////////////////////////////////////////
/// \brief Get the xcb connection of the shared Display
///
/// This function increments the reference count of the display,
/// it must be matched with a call to CloseConnection.
///
/// \return Pointer to the shared connection
///
////////////////////////////////////////////////////////////
xcb_connection_t* OpenConnection();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Release a reference to the shared display /// \brief Release a reference to the shared display
/// ///
@ -66,55 +55,16 @@ xcb_connection_t* OpenConnection();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void CloseDisplay(Display* display); void CloseDisplay(Display* display);
////////////////////////////////////////////////////////////
/// \brief Release a reference to the shared display
///
/// \param connection Connection of display to release
///
////////////////////////////////////////////////////////////
void CloseConnection(xcb_connection_t* connection);
////////////////////////////////////////////////////////////
/// \brief Get screen of a display by index (equivalent to XScreenOfDisplay)
///
/// \param connection Connection of display
/// \param screen_nbr The index of the screen
///
/// \return Pointer to the screen
///
////////////////////////////////////////////////////////////
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr);
////////////////////////////////////////////////////////////
/// \brief Get default screen of a display (equivalent to XDefaultScreen)
///
/// \param connection Connection of display
///
/// \return Pointer to the default screen of the display
///
////////////////////////////////////////////////////////////
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection);
////////////////////////////////////////////////////////////
/// \brief Get default root window of a display (equivalent to XDefaultRootWindow)
///
/// \param connection Connection of display
///
/// \return Root window of the display
///
////////////////////////////////////////////////////////////
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the atom with the specified name /// \brief Get the atom with the specified name
/// ///
/// \param name Name of the atom /// \param name Name of the atom
/// \param onlyIfExists Don't try to create the atom if it doesn't already exist /// \param onlyIfExists Don't try to create the atom if it doesn't already exist
/// ///
/// \return Atom if it exists or XCB_ATOM_NONE (0) if it doesn't /// \return Atom if it exists or None (0) if it doesn't
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
xcb_atom_t getAtom(const std::string& name, bool onlyIfExists = false); Atom getAtom(const std::string& name, bool onlyIfExists = false);
} // namespace priv } // namespace priv

View File

@ -194,8 +194,8 @@ GlxContext::~GlxContext()
// Destroy the window if we own it // Destroy the window if we own it
if (m_window && m_ownsWindow) if (m_window && m_ownsWindow)
{ {
xcb_destroy_window(m_connection, m_window); XDestroyWindow(m_display, m_window);
xcb_flush(m_connection); XFlush(m_display);
} }
// Close the connection with the X server // Close the connection with the X server
@ -444,7 +444,6 @@ void GlxContext::updateSettingsFromWindow()
void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel) void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel)
{ {
m_display = OpenDisplay(); m_display = OpenDisplay();
m_connection = XGetXCBConnection(m_display);
// Choose the visual according to the context settings // Choose the visual according to the context settings
XVisualInfo visualInfo = selectBestVisual(m_display, bitsPerPixel, m_settings); XVisualInfo visualInfo = selectBestVisual(m_display, bitsPerPixel, m_settings);
@ -513,28 +512,22 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned
} }
// If pbuffers are not available we use a hidden window as the off-screen surface to draw to // If pbuffers are not available we use a hidden window as the off-screen surface to draw to
xcb_screen_t* screen = XCBScreenOfDisplay(m_connection, DefaultScreen(m_display)); int screen = DefaultScreen(m_display);
// Define the window attributes // Define the window attributes
xcb_colormap_t colormap = xcb_generate_id(m_connection); XSetWindowAttributes attributes;
xcb_create_colormap(m_connection, XCB_COLORMAP_ALLOC_NONE, colormap, screen->root, visualInfo.visualid); attributes.colormap = XCreateColormap(m_display, RootWindow(m_display, screen), visualInfo.visual, AllocNone);
const uint32_t value_list[] = {colormap};
// Create a dummy window (disabled and hidden) m_window = XCreateWindow(m_display,
m_window = xcb_generate_id(m_connection); RootWindow(m_display, screen),
xcb_create_window(
m_connection,
static_cast<uint8_t>(visualInfo.depth),
m_window,
screen->root,
0, 0, 0, 0,
width, height, width, height,
0, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, DefaultDepth(m_display, screen),
visualInfo.visualid, InputOutput,
XCB_CW_COLORMAP, visualInfo.visual,
value_list CWColormap,
); &attributes);
m_ownsWindow = true; m_ownsWindow = true;
@ -546,7 +539,6 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned
void GlxContext::createSurface(::Window window) void GlxContext::createSurface(::Window window)
{ {
m_display = OpenDisplay(); m_display = OpenDisplay();
m_connection = XGetXCBConnection(m_display);
// A window already exists, so just use it // A window already exists, so just use it
m_window = window; m_window = window;

View File

@ -30,7 +30,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/GlContext.hpp> #include <SFML/Window/GlContext.hpp>
#include <SFML/Window/Unix/GlxExtensions.hpp> #include <SFML/Window/Unix/GlxExtensions.hpp>
#include <X11/Xlib-xcb.h> #include <X11/Xlib.h>
namespace sf namespace sf
@ -178,7 +178,6 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
::Display* m_display; ///< Connection to the X server ::Display* m_display; ///< Connection to the X server
::Window m_window; ///< Window to which the context is attached ::Window m_window; ///< Window to which the context is attached
xcb_connection_t* m_connection; ///< Pointer to the xcb connection
GLXContext m_context; ///< OpenGL context GLXContext m_context; ///< OpenGL context
GLXPbuffer m_pbuffer; ///< GLX pbuffer ID if one was created GLXPbuffer m_pbuffer; ///< GLX pbuffer ID if one was created
bool m_ownsWindow; ///< Do we own the window associated to the context? bool m_ownsWindow; ///< Do we own the window associated to the context?

View File

@ -28,9 +28,8 @@
#include <SFML/Window/Window.hpp> // important to be included first (conflict with None) #include <SFML/Window/Window.hpp> // important to be included first (conflict with None)
#include <SFML/Window/Unix/InputImpl.hpp> #include <SFML/Window/Unix/InputImpl.hpp>
#include <SFML/Window/Unix/Display.hpp> #include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <xcb/xcb.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
@ -157,36 +156,26 @@ bool InputImpl::isKeyPressed(Keyboard::Key key)
Display* display = OpenDisplay(); Display* display = OpenDisplay();
// Convert to keycode // Convert to keycode
xcb_keycode_t keycode = XKeysymToKeycode(display, keysym); KeyCode keycode = XKeysymToKeycode(display, keysym);
if (keycode != 0)
CloseDisplay(display); {
ScopedXcbPtr<xcb_generic_error_t> error(NULL);
// Open a connection with the X server
xcb_connection_t* connection = OpenConnection();
// Get the whole keyboard state // Get the whole keyboard state
ScopedXcbPtr<xcb_query_keymap_reply_t> keymap( char keys[32];
xcb_query_keymap_reply( XQueryKeymap(display, keys);
connection,
xcb_query_keymap(connection),
&error
)
);
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
if (error) // Check our keycode
return (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
}
else
{ {
err() << "Failed to query keymap" << std::endl; // Close the connection with the X server
CloseDisplay(display);
return false; return false;
} }
// Check our keycode
return (keymap->keys[keycode / 8] & (1 << (keycode % 8))) != 0;
} }
@ -201,43 +190,30 @@ void InputImpl::setVirtualKeyboardVisible(bool /*visible*/)
bool InputImpl::isMouseButtonPressed(Mouse::Button button) bool InputImpl::isMouseButtonPressed(Mouse::Button button)
{ {
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
ScopedXcbPtr<xcb_generic_error_t> error(NULL); // we don't care about these but they are required
::Window root, child;
int wx, wy;
int gx, gy;
// Get pointer mask unsigned int buttons = 0;
ScopedXcbPtr<xcb_query_pointer_reply_t> pointer( XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &wx, &wy, &buttons);
xcb_query_pointer_reply(
connection,
xcb_query_pointer(
connection,
XCBDefaultRootWindow(connection)
),
&error
)
);
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
if (error)
{
err() << "Failed to query pointer" << std::endl;
return false;
}
uint16_t buttons = pointer->mask;
switch (button) switch (button)
{ {
case Mouse::Left: return buttons & XCB_BUTTON_MASK_1; case Mouse::Left: return buttons & Button1Mask;
case Mouse::Right: return buttons & XCB_BUTTON_MASK_3; case Mouse::Right: return buttons & Button3Mask;
case Mouse::Middle: return buttons & XCB_BUTTON_MASK_2; case Mouse::Middle: return buttons & Button2Mask;
case Mouse::XButton1: return false; // not supported by X case Mouse::XButton1: return false; // not supported by X
case Mouse::XButton2: return false; // not supported by X case Mouse::XButton2: return false; // not supported by X
default: return false; default: return false;
} }
return false;
} }
@ -245,32 +221,21 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button)
Vector2i InputImpl::getMousePosition() Vector2i InputImpl::getMousePosition()
{ {
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
ScopedXcbPtr<xcb_generic_error_t> error(NULL); // we don't care about these but they are required
::Window root, child;
int x, y;
unsigned int buttons;
ScopedXcbPtr<xcb_query_pointer_reply_t> pointer( int gx = 0;
xcb_query_pointer_reply( int gy = 0;
connection, XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &x, &y, &buttons);
xcb_query_pointer(
connection,
XCBDefaultRootWindow(connection)
),
&error
)
);
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
if (error) return Vector2i(gx, gy);
{
err() << "Failed to query pointer" << std::endl;
return Vector2i(0, 0);
}
return Vector2i(pointer->root_x, pointer->root_y);
} }
@ -281,32 +246,21 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo)
if (handle) if (handle)
{ {
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
ScopedXcbPtr<xcb_generic_error_t> error(NULL); // we don't care about these but they are required
::Window root, child;
int gx, gy;
unsigned int buttons;
ScopedXcbPtr<xcb_query_pointer_reply_t> pointer( int x = 0;
xcb_query_pointer_reply( int y = 0;
connection, XQueryPointer(display, handle, &root, &child, &gx, &gy, &x, &y, &buttons);
xcb_query_pointer(
connection,
handle
),
&error
)
);
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
if (error) return Vector2i(x, y);
{
err() << "Failed to query pointer" << std::endl;
return Vector2i(0, 0);
}
return Vector2i(pointer->win_x, pointer->win_y);
} }
else else
{ {
@ -319,27 +273,13 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo)
void InputImpl::setMousePosition(const Vector2i& position) void InputImpl::setMousePosition(const Vector2i& position)
{ {
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
ScopedXcbPtr<xcb_generic_error_t> error(xcb_request_check( XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, position.x, position.y);
connection, XFlush(display);
xcb_warp_pointer(
connection,
None, // Source window
XCBDefaultRootWindow(connection), // Destination window
0, 0, // Source position
0, 0, // Source size
position.x, position.y // Destination position
)
));
if (error)
err() << "Failed to set mouse position" << std::endl;
xcb_flush(connection);
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
} }
@ -347,31 +287,17 @@ void InputImpl::setMousePosition(const Vector2i& position)
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo) void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
{ {
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
WindowHandle handle = relativeTo.getSystemHandle(); WindowHandle handle = relativeTo.getSystemHandle();
if (handle) if (handle)
{ {
ScopedXcbPtr<xcb_generic_error_t> error(xcb_request_check( XWarpPointer(display, None, handle, 0, 0, 0, 0, position.x, position.y);
connection, XFlush(display);
xcb_warp_pointer(
connection,
None, // Source window
handle, // Destination window
0, 0, // Source position
0, 0, // Source size
position.x, position.y // Destination position
)
));
if (error)
err() << "Failed to set mouse position" << std::endl;
xcb_flush(connection);
} }
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
} }

View File

@ -1,102 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SCOPEDXCBPTR_HPP
#define SFML_SCOPEDXCBPTR_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <cstdlib>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// \brief Scoped pointer that frees memory returned in XCB replies
///
////////////////////////////////////////////////////////////
template<typename T>
class ScopedXcbPtr
{
public:
////////////////////////////////////////////////////////////
/// \brief Constructor
///
/// \param pointer Pointer value to store
///
////////////////////////////////////////////////////////////
ScopedXcbPtr(T* pointer);
////////////////////////////////////////////////////////////
/// \brief Destructor, calls std::free() on the stored pointer
///
////////////////////////////////////////////////////////////
~ScopedXcbPtr();
////////////////////////////////////////////////////////////
/// \brief Structure dereference operator
///
/// \return Stored pointer
///
////////////////////////////////////////////////////////////
T* operator ->() const;
////////////////////////////////////////////////////////////
/// \brief Address operator.
///
/// \return Address of the stored pointer
///
////////////////////////////////////////////////////////////
T** operator &();
////////////////////////////////////////////////////////////
/// \brief Check if stored pointer is valid
///
/// \return true if stored pointer is valid
///
////////////////////////////////////////////////////////////
operator bool() const;
////////////////////////////////////////////////////////////
/// \brief Retrieve the stored pointer.
///
/// \return The stored pointer
///
////////////////////////////////////////////////////////////
T* get() const;
private:
T* m_pointer; ///< Stored pointer
};
#include <SFML/Window/Unix/ScopedXcbPtr.inl>
} // namespace priv
} // namespace sf
#endif // SFML_SCOPEDXCBPTR_HPP

View File

@ -1,72 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
template <typename T>
inline ScopedXcbPtr<T>::ScopedXcbPtr(T* pointer) :
m_pointer(pointer)
{
}
////////////////////////////////////////////////////////////
template <typename T>
inline ScopedXcbPtr<T>::~ScopedXcbPtr()
{
std::free(m_pointer);
}
////////////////////////////////////////////////////////////
template <typename T>
inline T* ScopedXcbPtr<T>::operator ->() const
{
return m_pointer;
}
////////////////////////////////////////////////////////////
template <typename T>
inline T** ScopedXcbPtr<T>::operator &()
{
return &m_pointer;
}
////////////////////////////////////////////////////////////
template <typename T>
inline ScopedXcbPtr<T>::operator bool() const
{
return m_pointer != NULL;
}
////////////////////////////////////////////////////////////
template <typename T>
inline T* ScopedXcbPtr<T>::get() const
{
return m_pointer;
}

View File

@ -27,9 +27,9 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/VideoModeImpl.hpp> #include <SFML/Window/VideoModeImpl.hpp>
#include <SFML/Window/Unix/Display.hpp> #include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <xcb/randr.h> #include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <algorithm> #include <algorithm>
@ -43,84 +43,42 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
std::vector<VideoMode> modes; std::vector<VideoMode> modes;
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
if (display)
// Retrieve the default screen
xcb_screen_t* screen = XCBDefaultScreen(connection);
ScopedXcbPtr<xcb_generic_error_t> error(NULL);
const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id);
if (!randrExt || !randrExt->present)
{ {
// Randr extension is not supported: we cannot get the video modes // Retrieve the default screen number
err() << "Failed to use the RandR extension while trying to get the supported video modes" << std::endl; int screen = DefaultScreen(display);
// Close the connection with the X server // Check if the XRandR extension is present
CloseConnection(connection); int version;
if (XQueryExtension(display, "RANDR", &version, &version, &version))
return modes;
}
// Load RandR and check its version
ScopedXcbPtr<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection,
xcb_randr_query_version(
connection,
1,
1
),
&error
));
if (error)
{ {
err() << "Failed to load the RandR extension while trying to get the supported video modes" << std::endl;
// Close the connection with the X server
CloseConnection(connection);
return modes;
}
// Get the current configuration // Get the current configuration
ScopedXcbPtr<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply( XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
connection, if (config)
xcb_randr_get_screen_info(
connection,
screen->root
),
&error
));
if (error)
{ {
// Failed to get the screen configuration
err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl;
// Close the connection with the X server
CloseConnection(connection);
return modes;
}
// Get the available screen sizes // Get the available screen sizes
xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); int nbSizes;
if (sizes && (config->nSizes > 0)) XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
if (sizes && (nbSizes > 0))
{ {
// Get the list of supported depths // Get the list of supported depths
xcb_depth_iterator_t iter = xcb_screen_allowed_depths_iterator(screen); int nbDepths = 0;
// Combine depths and sizes to fill the array of supported modes int* depths = XListDepths(display, screen, &nbDepths);
for (; iter.rem; xcb_depth_next(&iter)) if (depths && (nbDepths > 0))
{ {
for (int j = 0; j < config->nSizes; ++j) // Combine depths and sizes to fill the array of supported modes
for (int i = 0; i < nbDepths; ++i)
{
for (int j = 0; j < nbSizes; ++j)
{ {
// Convert to VideoMode // Convert to VideoMode
VideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth); VideoMode mode(sizes[j].width, sizes[j].height, depths[i]);
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || Rotation currentRotation;
config->rotation == XCB_RANDR_ROTATION_ROTATE_270) XRRConfigRotations(config, &currentRotation);
if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270)
std::swap(mode.width, mode.height); std::swap(mode.width, mode.height);
// Add it only if it is not already in the array // Add it only if it is not already in the array
@ -128,10 +86,35 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
modes.push_back(mode); modes.push_back(mode);
} }
} }
// Free the array of depths
XFree(depths);
}
}
// Free the configuration instance
XRRFreeScreenConfigInfo(config);
}
else
{
// Failed to get the screen configuration
err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl;
}
}
else
{
// XRandr extension is not supported: we cannot get the video modes
err() << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl;
} }
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
}
else
{
// We couldn't connect to the X server
err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl;
}
return modes; return modes;
} }
@ -143,90 +126,61 @@ VideoMode VideoModeImpl::getDesktopMode()
VideoMode desktopMode; VideoMode desktopMode;
// Open a connection with the X server // Open a connection with the X server
xcb_connection_t* connection = OpenConnection(); Display* display = OpenDisplay();
if (display)
// Retrieve the default screen
xcb_screen_t* screen = XCBDefaultScreen(connection);
ScopedXcbPtr<xcb_generic_error_t> error(NULL);
// Check if the RandR extension is present
const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id);
if (!randrExt || !randrExt->present)
{ {
// Randr extension is not supported: we cannot get the video modes // Retrieve the default screen number
err() << "Failed to use the RandR extension while trying to get the desktop video mode" << std::endl; int screen = DefaultScreen(display);
// Close the connection with the X server // Check if the XRandR extension is present
CloseConnection(connection); int version;
if (XQueryExtension(display, "RANDR", &version, &version, &version))
return desktopMode;
}
// Load RandR and check its version
ScopedXcbPtr<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection,
xcb_randr_query_version(
connection,
1,
1
),
&error
));
if (error)
{ {
err() << "Failed to load the RandR extension while trying to get the desktop video mode" << std::endl;
// Close the connection with the X server
CloseConnection(connection);
return desktopMode;
}
// Get the current configuration // Get the current configuration
ScopedXcbPtr<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply( XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
connection, if (config)
xcb_randr_get_screen_info(
connection,
screen->root
),
&error
));
if (error)
{ {
// Failed to get the screen configuration
err() << "Failed to retrieve the screen configuration while trying to get the desktop video mode" << std::endl;
// Close the connection with the X server
CloseConnection(connection);
return desktopMode;
}
// Get the current video mode // Get the current video mode
xcb_randr_mode_t currentMode = config->sizeID; Rotation currentRotation;
int currentMode = XRRConfigCurrentConfiguration(config, &currentRotation);
// Get the available screen sizes // Get the available screen sizes
int nbSizes = xcb_randr_get_screen_info_sizes_length(config.get()); int nbSizes;
xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get()); XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
if (sizes && (nbSizes > 0)) if (sizes && (nbSizes > 0))
{ {
desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, screen->root_depth); desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen));
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 || Rotation currentRotation;
config->rotation == XCB_RANDR_ROTATION_ROTATE_270) XRRConfigRotations(config, &currentRotation);
if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270)
std::swap(desktopMode.width, desktopMode.height); std::swap(desktopMode.width, desktopMode.height);
} }
// Free the configuration instance
XRRFreeScreenConfigInfo(config);
}
else else
{ {
err() << "Failed to retrieve any screen sizes while trying to get the desktop video mode" << std::endl; // Failed to get the screen configuration
err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl;
}
}
else
{
// XRandr extension is not supported: we cannot get the video modes
err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl;
} }
// Close the connection with the X server // Close the connection with the X server
CloseConnection(connection); CloseDisplay(display);
}
else
{
// We couldn't connect to the X server
err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl;
}
return desktopMode; return desktopMode;
} }

File diff suppressed because it is too large Load Diff

View File

@ -31,8 +31,7 @@
#include <SFML/Window/Event.hpp> #include <SFML/Window/Event.hpp>
#include <SFML/Window/WindowImpl.hpp> #include <SFML/Window/WindowImpl.hpp>
#include <SFML/System/String.hpp> #include <SFML/System/String.hpp>
#include <X11/Xlib-xcb.h> #include <X11/Xlib.h>
#include <xcb/randr.h>
#include <deque> #include <deque>
@ -188,33 +187,6 @@ protected:
private: private:
struct WMHints
{
int32_t flags;
uint32_t input;
int32_t initial_state;
xcb_pixmap_t icon_pixmap;
xcb_window_t icon_window;
int32_t icon_x;
int32_t icon_y;
xcb_pixmap_t icon_mask;
xcb_window_t window_group;
};
struct WMSizeHints
{
uint32_t flags;
int32_t x, y;
int32_t width, height;
int32_t min_width, min_height;
int32_t max_width, max_height;
int32_t width_inc, height_inc;
int32_t min_aspect_num, min_aspect_den;
int32_t max_aspect_num, max_aspect_den;
int32_t base_width, base_height;
uint32_t win_gravity;
};
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Request the WM to make the current window active /// \brief Request the WM to make the current window active
/// ///
@ -248,40 +220,12 @@ private:
void setProtocols(); void setProtocols();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set Motif WM hints /// \brief Update the last time we received user input
///
/// \param time Last time we received user input
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void setMotifHints(unsigned long style); void updateLastInputTime(::Time time);
////////////////////////////////////////////////////////////
/// \brief Set WM hints
///
/// \param hints Hints
///
////////////////////////////////////////////////////////////
void setWMHints(const WMHints& hints);
////////////////////////////////////////////////////////////
/// \brief Set WM size hints
///
/// \param hints Size hints
///
////////////////////////////////////////////////////////////
void setWMSizeHints(const WMSizeHints& hints);
////////////////////////////////////////////////////////////
/// \brief Change a XCB window property
///
/// \param property Property to change
/// \param type Type of the property
/// \param format Format of the property
/// \param length Length of the new value
/// \param data The new value of the property
///
/// \return True if successful, false if unsuccessful
///
////////////////////////////////////////////////////////////
bool changeWindowProperty(xcb_atom_t property, xcb_atom_t type, uint8_t format, uint32_t length, const void* data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Do some common initializations after the window has been created /// \brief Do some common initializations after the window has been created
@ -314,14 +258,13 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
xcb_window_t m_window; ///< xcb identifier defining our window ::Window m_window; ///< X identifier defining our window
::Display* m_display; ///< Pointer to the display ::Display* m_display; ///< Pointer to the display
xcb_connection_t* m_connection; ///< Pointer to the xcb connection int m_screen; ///< Screen identifier
xcb_screen_t* m_screen; ///< Screen identifier
XIM m_inputMethod; ///< Input method linked to the X display XIM m_inputMethod; ///< Input method linked to the X display
XIC m_inputContext; ///< Input context used to get unicode input in our window XIC m_inputContext; ///< Input context used to get unicode input in our window
bool m_isExternal; ///< Tell whether the window has been created externally or by SFML bool m_isExternal; ///< Tell whether the window has been created externally or by SFML
xcb_randr_get_screen_info_reply_t m_oldVideoMode; ///< Video mode in use before we switch to fullscreen 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 Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one
bool m_keyRepeat; ///< Is the KeyRepeat feature enabled? 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) Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only)
@ -329,8 +272,9 @@ private:
bool m_fullscreen; ///< Is the window in fullscreen? bool m_fullscreen; ///< Is the window in fullscreen?
bool m_cursorGrabbed; ///< Is the mouse cursor trapped? bool m_cursorGrabbed; ///< Is the mouse cursor trapped?
bool m_windowMapped; ///< Has the window been mapped by the window manager? bool m_windowMapped; ///< Has the window been mapped by the window manager?
xcb_pixmap_t m_iconPixmap; ///< The current icon pixmap if in use Pixmap m_iconPixmap; ///< The current icon pixmap if in use
xcb_pixmap_t m_iconMaskPixmap; ///< The current icon mask pixmap if in use Pixmap m_iconMaskPixmap; ///< The current icon mask pixmap if in use
::Time m_lastInputTime; ///< Last time we received user input
}; };
} // namespace priv } // namespace priv