mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Converted Unix Window implementation from XCB back to Xlib.
This commit is contained in:
parent
fae3b65f05
commit
9996b7abb6
@ -285,10 +285,7 @@ if(SFML_STATIC_LIBRARIES)
|
||||
# find libraries
|
||||
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
||||
find_sfml_dependency(X11_LIBRARY "X11" X11)
|
||||
find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb)
|
||||
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)
|
||||
find_sfml_dependency(XRANDR_LIBRARY "Xrandr" Xrandr)
|
||||
endif()
|
||||
|
||||
if(FIND_SFML_OS_LINUX)
|
||||
@ -299,9 +296,9 @@ if(SFML_STATIC_LIBRARIES)
|
||||
if(FIND_SFML_OS_WINDOWS)
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32")
|
||||
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)
|
||||
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)
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||
endif()
|
||||
|
@ -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()
|
@ -5,7 +5,7 @@
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
@ -133,77 +133,46 @@ int main()
|
||||
if (!display)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Get the XCB connection for the opened display.
|
||||
xcb_connection_t* xcbConnection = XGetXCBConnection(display);
|
||||
// Get the default screen
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
if (!xcbConnection)
|
||||
{
|
||||
sf::err() << "Failed to get the XCB connection for opened display." << std::endl;
|
||||
// Let's create the main window
|
||||
XSetWindowAttributes attributes;
|
||||
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;
|
||||
}
|
||||
|
||||
// Get XCB screen.
|
||||
const xcb_setup_t* xcbSetup = xcb_get_setup(xcbConnection);
|
||||
xcb_screen_iterator_t xcbScreenIter = xcb_setup_roots_iterator(xcbSetup);
|
||||
xcb_screen_t* screen = xcbScreenIter.data;
|
||||
// Set the window's name
|
||||
XStoreName(display, window , "SFML Window");
|
||||
|
||||
if (!screen)
|
||||
{
|
||||
sf::err() << "Failed to get the XCB screen." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Let's create the windows which will serve as containers for our SFML views
|
||||
Window view1 = XCreateWindow(display, window,
|
||||
10, 10, 310, 310, 0,
|
||||
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.
|
||||
xcb_window_t rootWindowId = xcb_generate_id(xcbConnection);
|
||||
xcb_window_t view1WindowId = xcb_generate_id(xcbConnection);
|
||||
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);
|
||||
// Show our windows
|
||||
XMapWindow(display, window);
|
||||
XFlush(display);
|
||||
|
||||
// Create our SFML views
|
||||
sf::Window sfmlView1(view1WindowId);
|
||||
sf::Window sfmlView2(view2WindowId);
|
||||
sf::Window sfmlView1(view1);
|
||||
sf::Window sfmlView2(view2);
|
||||
|
||||
// Create a clock for measuring elapsed time
|
||||
sf::Clock clock;
|
||||
@ -214,13 +183,22 @@ int main()
|
||||
|
||||
// Start the event loop
|
||||
bool running = true;
|
||||
xcb_generic_event_t* event = NULL;
|
||||
|
||||
while (running)
|
||||
{
|
||||
while ((event = xcb_poll_for_event(xcbConnection)))
|
||||
while (XPending(display))
|
||||
{
|
||||
running = false;
|
||||
// Get the next pending event
|
||||
XEvent event;
|
||||
XNextEvent(display, &event);
|
||||
|
||||
// Process it
|
||||
switch (event.type)
|
||||
{
|
||||
// Any key is pressed: quit
|
||||
case KeyPress:
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw something into our views
|
||||
@ -232,5 +210,8 @@ int main()
|
||||
sfmlView2.display();
|
||||
}
|
||||
|
||||
// Close the display
|
||||
XCloseDisplay(display);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -75,8 +75,6 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||
${SRCROOT}/Unix/Display.hpp
|
||||
${SRCROOT}/Unix/InputImpl.cpp
|
||||
${SRCROOT}/Unix/InputImpl.hpp
|
||||
${SRCROOT}/Unix/ScopedXcbPtr.hpp
|
||||
${SRCROOT}/Unix/ScopedXcbPtr.inl
|
||||
${SRCROOT}/Unix/SensorImpl.cpp
|
||||
${SRCROOT}/Unix/SensorImpl.hpp
|
||||
${SRCROOT}/Unix/VideoModeImpl.cpp
|
||||
@ -200,18 +198,14 @@ if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||
if(NOT X11_FOUND)
|
||||
message(FATAL_ERROR "X11 library not found")
|
||||
endif()
|
||||
if(NOT X11_Xrandr_FOUND)
|
||||
message(FATAL_ERROR "Xrandr library not found")
|
||||
endif()
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
endif()
|
||||
if(NOT SFML_OPENGL_ES)
|
||||
find_package(OpenGL REQUIRED)
|
||||
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()
|
||||
if(SFML_OPENGL_ES AND SFML_OS_LINUX)
|
||||
find_package(EGL REQUIRED)
|
||||
@ -231,9 +225,9 @@ endif()
|
||||
if(SFML_OS_WINDOWS)
|
||||
list(APPEND WINDOW_EXT_LIBS winmm gdi32)
|
||||
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)
|
||||
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)
|
||||
list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||
elseif(SFML_OS_IOS)
|
||||
|
@ -27,9 +27,9 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <SFML/Window/Unix/Display.hpp>
|
||||
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
|
||||
#include <X11/keysym.h>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ namespace
|
||||
Display* sharedDisplay = NULL;
|
||||
unsigned int referenceCount = 0;
|
||||
|
||||
typedef std::map<std::string, xcb_atom_t> AtomMap;
|
||||
typedef std::map<std::string, Atom> AtomMap;
|
||||
AtomMap atoms;
|
||||
}
|
||||
|
||||
@ -68,13 +68,6 @@ Display* OpenDisplay()
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
xcb_connection_t* OpenConnection()
|
||||
{
|
||||
return XGetXCBConnection(OpenDisplay());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void CloseDisplay(Display* display)
|
||||
{
|
||||
@ -87,81 +80,22 @@ void CloseDisplay(Display* display)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void CloseConnection(xcb_connection_t* connection)
|
||||
{
|
||||
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)
|
||||
Atom getAtom(const std::string& name, bool onlyIfExists)
|
||||
{
|
||||
AtomMap::const_iterator iter = atoms.find(name);
|
||||
|
||||
if (iter != atoms.end())
|
||||
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(
|
||||
connection,
|
||||
xcb_intern_atom(
|
||||
connection,
|
||||
onlyIfExists,
|
||||
name.size(),
|
||||
name.c_str()
|
||||
),
|
||||
&error
|
||||
));
|
||||
CloseDisplay(display);
|
||||
|
||||
CloseConnection(connection);
|
||||
atoms[name] = atom;
|
||||
|
||||
if (error || !reply)
|
||||
{
|
||||
err() << "Failed to get " << name << " atom." << std::endl;
|
||||
return XCB_ATOM_NONE;
|
||||
}
|
||||
|
||||
atoms[name] = reply->atom;
|
||||
|
||||
return reply->atom;
|
||||
return atom;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
@ -28,7 +28,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
@ -47,17 +47,6 @@ namespace priv
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
@ -66,55 +55,16 @@ xcb_connection_t* OpenConnection();
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
/// \param name Name of the atom
|
||||
/// \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
|
||||
|
||||
|
@ -194,8 +194,8 @@ GlxContext::~GlxContext()
|
||||
// Destroy the window if we own it
|
||||
if (m_window && m_ownsWindow)
|
||||
{
|
||||
xcb_destroy_window(m_connection, m_window);
|
||||
xcb_flush(m_connection);
|
||||
XDestroyWindow(m_display, m_window);
|
||||
XFlush(m_display);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
m_display = OpenDisplay();
|
||||
m_connection = XGetXCBConnection(m_display);
|
||||
|
||||
// Choose the visual according to the context 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
|
||||
xcb_screen_t* screen = XCBScreenOfDisplay(m_connection, DefaultScreen(m_display));
|
||||
int screen = DefaultScreen(m_display);
|
||||
|
||||
// Define the window attributes
|
||||
xcb_colormap_t colormap = xcb_generate_id(m_connection);
|
||||
xcb_create_colormap(m_connection, XCB_COLORMAP_ALLOC_NONE, colormap, screen->root, visualInfo.visualid);
|
||||
const uint32_t value_list[] = {colormap};
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.colormap = XCreateColormap(m_display, RootWindow(m_display, screen), visualInfo.visual, AllocNone);
|
||||
|
||||
// Create a dummy window (disabled and hidden)
|
||||
m_window = xcb_generate_id(m_connection);
|
||||
xcb_create_window(
|
||||
m_connection,
|
||||
static_cast<uint8_t>(visualInfo.depth),
|
||||
m_window,
|
||||
screen->root,
|
||||
0, 0,
|
||||
width, height,
|
||||
0,
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
||||
visualInfo.visualid,
|
||||
XCB_CW_COLORMAP,
|
||||
value_list
|
||||
);
|
||||
m_window = XCreateWindow(m_display,
|
||||
RootWindow(m_display, screen),
|
||||
0, 0,
|
||||
width, height,
|
||||
0,
|
||||
DefaultDepth(m_display, screen),
|
||||
InputOutput,
|
||||
visualInfo.visual,
|
||||
CWColormap,
|
||||
&attributes);
|
||||
|
||||
m_ownsWindow = true;
|
||||
|
||||
@ -546,7 +539,6 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned
|
||||
void GlxContext::createSurface(::Window window)
|
||||
{
|
||||
m_display = OpenDisplay();
|
||||
m_connection = XGetXCBConnection(m_display);
|
||||
|
||||
// A window already exists, so just use it
|
||||
m_window = window;
|
||||
|
@ -30,7 +30,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/GlContext.hpp>
|
||||
#include <SFML/Window/Unix/GlxExtensions.hpp>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -178,7 +178,6 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
::Display* m_display; ///< Connection to the X server
|
||||
::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
|
||||
GLXPbuffer m_pbuffer; ///< GLX pbuffer ID if one was created
|
||||
bool m_ownsWindow; ///< Do we own the window associated to the context?
|
||||
|
@ -28,9 +28,8 @@
|
||||
#include <SFML/Window/Window.hpp> // important to be included first (conflict with None)
|
||||
#include <SFML/Window/Unix/InputImpl.hpp>
|
||||
#include <SFML/Window/Unix/Display.hpp>
|
||||
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <xcb/xcb.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
|
||||
@ -157,36 +156,26 @@ bool InputImpl::isKeyPressed(Keyboard::Key key)
|
||||
Display* display = OpenDisplay();
|
||||
|
||||
// Convert to keycode
|
||||
xcb_keycode_t keycode = XKeysymToKeycode(display, keysym);
|
||||
|
||||
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
|
||||
ScopedXcbPtr<xcb_query_keymap_reply_t> keymap(
|
||||
xcb_query_keymap_reply(
|
||||
connection,
|
||||
xcb_query_keymap(connection),
|
||||
&error
|
||||
)
|
||||
);
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
|
||||
if (error)
|
||||
KeyCode keycode = XKeysymToKeycode(display, keysym);
|
||||
if (keycode != 0)
|
||||
{
|
||||
err() << "Failed to query keymap" << std::endl;
|
||||
// Get the whole keyboard state
|
||||
char keys[32];
|
||||
XQueryKeymap(display, keys);
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseDisplay(display);
|
||||
|
||||
// Check our keycode
|
||||
return (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Close the connection with the X server
|
||||
CloseDisplay(display);
|
||||
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
ScopedXcbPtr<xcb_query_pointer_reply_t> pointer(
|
||||
xcb_query_pointer_reply(
|
||||
connection,
|
||||
xcb_query_pointer(
|
||||
connection,
|
||||
XCBDefaultRootWindow(connection)
|
||||
),
|
||||
&error
|
||||
)
|
||||
);
|
||||
unsigned int buttons = 0;
|
||||
XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &wx, &wy, &buttons);
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
|
||||
if (error)
|
||||
{
|
||||
err() << "Failed to query pointer" << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t buttons = pointer->mask;
|
||||
CloseDisplay(display);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case Mouse::Left: return buttons & XCB_BUTTON_MASK_1;
|
||||
case Mouse::Right: return buttons & XCB_BUTTON_MASK_3;
|
||||
case Mouse::Middle: return buttons & XCB_BUTTON_MASK_2;
|
||||
case Mouse::Left: return buttons & Button1Mask;
|
||||
case Mouse::Right: return buttons & Button3Mask;
|
||||
case Mouse::Middle: return buttons & Button2Mask;
|
||||
case Mouse::XButton1: return false; // not supported by X
|
||||
case Mouse::XButton2: return false; // not supported by X
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -245,32 +221,21 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button)
|
||||
Vector2i InputImpl::getMousePosition()
|
||||
{
|
||||
// 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(
|
||||
xcb_query_pointer_reply(
|
||||
connection,
|
||||
xcb_query_pointer(
|
||||
connection,
|
||||
XCBDefaultRootWindow(connection)
|
||||
),
|
||||
&error
|
||||
)
|
||||
);
|
||||
int gx = 0;
|
||||
int gy = 0;
|
||||
XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
CloseDisplay(display);
|
||||
|
||||
if (error)
|
||||
{
|
||||
err() << "Failed to query pointer" << std::endl;
|
||||
|
||||
return Vector2i(0, 0);
|
||||
}
|
||||
|
||||
return Vector2i(pointer->root_x, pointer->root_y);
|
||||
return Vector2i(gx, gy);
|
||||
}
|
||||
|
||||
|
||||
@ -281,32 +246,21 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
if (handle)
|
||||
{
|
||||
// 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(
|
||||
xcb_query_pointer_reply(
|
||||
connection,
|
||||
xcb_query_pointer(
|
||||
connection,
|
||||
handle
|
||||
),
|
||||
&error
|
||||
)
|
||||
);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
XQueryPointer(display, handle, &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
CloseDisplay(display);
|
||||
|
||||
if (error)
|
||||
{
|
||||
err() << "Failed to query pointer" << std::endl;
|
||||
|
||||
return Vector2i(0, 0);
|
||||
}
|
||||
|
||||
return Vector2i(pointer->win_x, pointer->win_y);
|
||||
return Vector2i(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -319,27 +273,13 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
void InputImpl::setMousePosition(const Vector2i& position)
|
||||
{
|
||||
// Open a connection with the X server
|
||||
xcb_connection_t* connection = OpenConnection();
|
||||
Display* display = OpenDisplay();
|
||||
|
||||
ScopedXcbPtr<xcb_generic_error_t> error(xcb_request_check(
|
||||
connection,
|
||||
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);
|
||||
XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, position.x, position.y);
|
||||
XFlush(display);
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Open a connection with the X server
|
||||
xcb_connection_t* connection = OpenConnection();
|
||||
Display* display = OpenDisplay();
|
||||
|
||||
WindowHandle handle = relativeTo.getSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
ScopedXcbPtr<xcb_generic_error_t> error(xcb_request_check(
|
||||
connection,
|
||||
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);
|
||||
XWarpPointer(display, None, handle, 0, 0, 0, 0, position.x, position.y);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
CloseDisplay(display);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
@ -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;
|
||||
}
|
@ -27,9 +27,9 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoModeImpl.hpp>
|
||||
#include <SFML/Window/Unix/Display.hpp>
|
||||
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <xcb/randr.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
@ -43,95 +43,78 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
|
||||
std::vector<VideoMode> modes;
|
||||
|
||||
// Open a connection with the X server
|
||||
xcb_connection_t* connection = OpenConnection();
|
||||
|
||||
// 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)
|
||||
Display* display = OpenDisplay();
|
||||
if (display)
|
||||
{
|
||||
// Randr extension is not supported: we cannot get the video modes
|
||||
err() << "Failed to use the RandR extension while trying to get the supported video modes" << std::endl;
|
||||
// Retrieve the default screen number
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
|
||||
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
|
||||
ScopedXcbPtr<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply(
|
||||
connection,
|
||||
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
|
||||
xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get());
|
||||
if (sizes && (config->nSizes > 0))
|
||||
{
|
||||
// Get the list of supported depths
|
||||
xcb_depth_iterator_t iter = xcb_screen_allowed_depths_iterator(screen);
|
||||
// Combine depths and sizes to fill the array of supported modes
|
||||
for (; iter.rem; xcb_depth_next(&iter))
|
||||
// Check if the XRandR extension is present
|
||||
int version;
|
||||
if (XQueryExtension(display, "RANDR", &version, &version, &version))
|
||||
{
|
||||
for (int j = 0; j < config->nSizes; ++j)
|
||||
// Get the current configuration
|
||||
XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
|
||||
if (config)
|
||||
{
|
||||
// Convert to VideoMode
|
||||
VideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth);
|
||||
// Get the available screen sizes
|
||||
int nbSizes;
|
||||
XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
|
||||
if (sizes && (nbSizes > 0))
|
||||
{
|
||||
// Get the list of supported depths
|
||||
int nbDepths = 0;
|
||||
int* depths = XListDepths(display, screen, &nbDepths);
|
||||
if (depths && (nbDepths > 0))
|
||||
{
|
||||
// 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
|
||||
VideoMode mode(sizes[j].width, sizes[j].height, depths[i]);
|
||||
|
||||
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 ||
|
||||
config->rotation == XCB_RANDR_ROTATION_ROTATE_270)
|
||||
std::swap(mode.width, mode.height);
|
||||
Rotation currentRotation;
|
||||
XRRConfigRotations(config, ¤tRotation);
|
||||
|
||||
// Add it only if it is not already in the array
|
||||
if (std::find(modes.begin(), modes.end(), mode) == modes.end())
|
||||
modes.push_back(mode);
|
||||
if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270)
|
||||
std::swap(mode.width, mode.height);
|
||||
|
||||
// Add it only if it is not already in the array
|
||||
if (std::find(modes.begin(), modes.end(), mode) == modes.end())
|
||||
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
|
||||
CloseConnection(connection);
|
||||
// Close the connection with the X server
|
||||
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;
|
||||
}
|
||||
@ -143,91 +126,62 @@ VideoMode VideoModeImpl::getDesktopMode()
|
||||
VideoMode desktopMode;
|
||||
|
||||
// Open a connection with the X server
|
||||
xcb_connection_t* connection = OpenConnection();
|
||||
|
||||
// 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)
|
||||
Display* display = OpenDisplay();
|
||||
if (display)
|
||||
{
|
||||
// Randr extension is not supported: we cannot get the video modes
|
||||
err() << "Failed to use the RandR extension while trying to get the desktop video mode" << std::endl;
|
||||
// Retrieve the default screen number
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
// Check if the XRandR extension is present
|
||||
int version;
|
||||
if (XQueryExtension(display, "RANDR", &version, &version, &version))
|
||||
{
|
||||
// Get the current configuration
|
||||
XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
|
||||
if (config)
|
||||
{
|
||||
// Get the current video mode
|
||||
Rotation currentRotation;
|
||||
int currentMode = XRRConfigCurrentConfiguration(config, ¤tRotation);
|
||||
|
||||
// Get the available screen sizes
|
||||
int nbSizes;
|
||||
XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
|
||||
if (sizes && (nbSizes > 0))
|
||||
{
|
||||
desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen));
|
||||
|
||||
Rotation currentRotation;
|
||||
XRRConfigRotations(config, ¤tRotation);
|
||||
|
||||
if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270)
|
||||
std::swap(desktopMode.width, desktopMode.height);
|
||||
}
|
||||
|
||||
// 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 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
|
||||
CloseConnection(connection);
|
||||
|
||||
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
|
||||
ScopedXcbPtr<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply(
|
||||
connection,
|
||||
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
|
||||
xcb_randr_mode_t currentMode = config->sizeID;
|
||||
|
||||
// Get the available screen sizes
|
||||
int nbSizes = xcb_randr_get_screen_info_sizes_length(config.get());
|
||||
xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(config.get());
|
||||
if (sizes && (nbSizes > 0))
|
||||
{
|
||||
desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, screen->root_depth);
|
||||
|
||||
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 ||
|
||||
config->rotation == XCB_RANDR_ROTATION_ROTATE_270)
|
||||
std::swap(desktopMode.width, desktopMode.height);
|
||||
CloseDisplay(display);
|
||||
}
|
||||
else
|
||||
{
|
||||
err() << "Failed to retrieve any screen sizes while trying to get the desktop video mode" << std::endl;
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseConnection(connection);
|
||||
|
||||
return desktopMode;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,8 +31,7 @@
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/randr.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <deque>
|
||||
|
||||
|
||||
@ -188,33 +187,6 @@ protected:
|
||||
|
||||
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
|
||||
///
|
||||
@ -248,40 +220,12 @@ private:
|
||||
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);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \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);
|
||||
void updateLastInputTime(::Time time);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Do some common initializations after the window has been created
|
||||
@ -314,23 +258,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_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
|
||||
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
|
||||
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 the window in fullscreen?
|
||||
bool m_cursorGrabbed; ///< Is the mouse cursor trapped?
|
||||
bool m_windowMapped; ///< Has the window been mapped by the window manager?
|
||||
xcb_pixmap_t m_iconPixmap; ///< The current icon pixmap if in use
|
||||
xcb_pixmap_t m_iconMaskPixmap; ///< The current icon mask pixmap if in use
|
||||
::Window m_window; ///< X identifier defining our window
|
||||
::Display* m_display; ///< Pointer to the display
|
||||
int 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
|
||||
bool m_isExternal; ///< Tell whether the window has been created externally or by SFML
|
||||
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 the window in fullscreen?
|
||||
bool m_cursorGrabbed; ///< Is the mouse cursor trapped?
|
||||
bool m_windowMapped; ///< Has the window been mapped by the window manager?
|
||||
Pixmap m_iconPixmap; ///< The current icon 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
|
||||
|
Loading…
Reference in New Issue
Block a user