mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Removed XCB dependencies (EWMH, ICCCM, Keysyms, Util), added XCB libraries to FindSFML.cmake, fixed checking for X11 library checking for XRandR instead.
This commit is contained in:
parent
3d0ab05e7b
commit
3ec672afe9
@ -281,22 +281,25 @@ if(SFML_STATIC_LIBRARIES)
|
||||
if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1)
|
||||
|
||||
# find libraries
|
||||
if(FIND_SFML_OS_LINUX)
|
||||
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
||||
find_sfml_dependency(X11_LIBRARY "X11" X11)
|
||||
find_sfml_dependency(XRANDR_LIBRARY "Xrandr" Xrandr)
|
||||
find_sfml_dependency(UDEV_LIBRARIES "UDev" udev)
|
||||
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)
|
||||
endif()
|
||||
|
||||
if(FIND_SFML_OS_LINUX)
|
||||
find_sfml_dependency(UDEV_LIBRARIES "UDev" udev libudev)
|
||||
endif()
|
||||
|
||||
# update the list
|
||||
if(FIND_SFML_OS_WINDOWS)
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32")
|
||||
elseif(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY})
|
||||
if(FIND_SFML_OS_FREEBSD)
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "usbhid")
|
||||
else()
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${UDEV_LIBRARIES})
|
||||
endif()
|
||||
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})
|
||||
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")
|
||||
elseif(FIND_SFML_OS_MACOSX)
|
||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||
endif()
|
||||
|
@ -190,8 +190,8 @@ endif()
|
||||
# find external libraries
|
||||
if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||
find_package(X11 REQUIRED)
|
||||
if(NOT X11_Xrandr_FOUND)
|
||||
message(FATAL_ERROR "Xrandr library not found")
|
||||
if(NOT X11_FOUND)
|
||||
message(FATAL_ERROR "X11 library not found")
|
||||
endif()
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
endif()
|
||||
@ -199,7 +199,7 @@ 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 icccm image randr util ewmh keysyms REQUIRED)
|
||||
find_package(XCB COMPONENTS xlib_xcb image randr REQUIRED)
|
||||
if(NOT LIBXCB_FOUND)
|
||||
message(FATAL_ERROR "Xcb library not found")
|
||||
endif()
|
||||
@ -224,9 +224,9 @@ endif()
|
||||
if(SFML_OS_WINDOWS)
|
||||
list(APPEND WINDOW_EXT_LIBS winmm gdi32)
|
||||
elseif(SFML_OS_LINUX)
|
||||
list(APPEND WINDOW_EXT_LIBS ${LIBXCB_LIBRARIES} ${UDEV_LIBRARIES})
|
||||
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${LIBXCB_LIBRARIES} ${UDEV_LIBRARIES})
|
||||
elseif(SFML_OS_FREEBSD)
|
||||
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${LIBXCB_LIBRARIES} usbhid)
|
||||
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${LIBXCB_LIBRARIES} usbhid)
|
||||
elseif(SFML_OS_MACOSX)
|
||||
list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||
elseif(SFML_OS_IOS)
|
||||
|
@ -27,8 +27,12 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#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 <algorithm>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace
|
||||
@ -36,6 +40,182 @@ namespace
|
||||
// The shared display and its reference counter
|
||||
Display* sharedDisplay = NULL;
|
||||
unsigned int referenceCount = 0;
|
||||
|
||||
typedef std::map<std::string, xcb_atom_t> AtomMap;
|
||||
AtomMap atoms;
|
||||
|
||||
bool mapBuilt = false;
|
||||
xcb_keycode_t firstKeycode = 255;
|
||||
xcb_keycode_t lastKeycode = 0;
|
||||
|
||||
// We use a simple array instead of a map => constant time lookup
|
||||
// xcb_keycode_t can only contain 256 distinct values
|
||||
xcb_keysym_t keysymMap[256];
|
||||
|
||||
xcb_keysym_t keysymToLower(xcb_keysym_t keysym)
|
||||
{
|
||||
switch(keysym >> 8)
|
||||
{
|
||||
// Latin 1
|
||||
case 0:
|
||||
{
|
||||
if ((keysym >= XK_A) && (keysym <= XK_Z))
|
||||
return keysym + (XK_a - XK_A);
|
||||
else if ((keysym >= XK_Agrave) && (keysym <= XK_Odiaeresis))
|
||||
return keysym + (XK_agrave - XK_Agrave);
|
||||
else if ((keysym >= XK_Ooblique) && (keysym <= XK_Thorn))
|
||||
return keysym + (XK_oslash - XK_Ooblique);
|
||||
break;
|
||||
}
|
||||
|
||||
// Latin 2
|
||||
case 1:
|
||||
{
|
||||
if (keysym == XK_Aogonek)
|
||||
return XK_aogonek;
|
||||
else if (keysym >= XK_Lstroke && keysym <= XK_Sacute)
|
||||
return keysym + (XK_lstroke - XK_Lstroke);
|
||||
else if (keysym >= XK_Scaron && keysym <= XK_Zacute)
|
||||
return keysym + (XK_scaron - XK_Scaron);
|
||||
else if (keysym >= XK_Zcaron && keysym <= XK_Zabovedot)
|
||||
return keysym + (XK_zcaron - XK_Zcaron);
|
||||
else if (keysym >= XK_Racute && keysym <= XK_Tcedilla)
|
||||
return keysym + (XK_racute - XK_Racute);
|
||||
break;
|
||||
}
|
||||
|
||||
// Latin 3
|
||||
case 2:
|
||||
{
|
||||
if (keysym >= XK_Hstroke && keysym <= XK_Hcircumflex)
|
||||
return keysym + (XK_hstroke - XK_Hstroke);
|
||||
else if (keysym >= XK_Gbreve && keysym <= XK_Jcircumflex)
|
||||
return keysym + (XK_gbreve - XK_Gbreve);
|
||||
else if (keysym >= XK_Cabovedot && keysym <= XK_Scircumflex)
|
||||
return keysym + (XK_cabovedot - XK_Cabovedot);
|
||||
break;
|
||||
}
|
||||
|
||||
// Latin 4
|
||||
case 3:
|
||||
{
|
||||
if (keysym >= XK_Rcedilla && keysym <= XK_Tslash)
|
||||
return keysym + (XK_rcedilla - XK_Rcedilla);
|
||||
else if (keysym == XK_ENG)
|
||||
return XK_eng;
|
||||
else if (keysym >= XK_Amacron && keysym <= XK_Umacron)
|
||||
return keysym + (XK_amacron - XK_Amacron);
|
||||
break;
|
||||
}
|
||||
|
||||
// Cyrillic
|
||||
case 6:
|
||||
{
|
||||
if (keysym >= XK_Serbian_DJE && keysym <= XK_Serbian_DZE)
|
||||
return keysym - (XK_Serbian_DJE - XK_Serbian_dje);
|
||||
else if (keysym >= XK_Cyrillic_YU && keysym <= XK_Cyrillic_HARDSIGN)
|
||||
return keysym - (XK_Cyrillic_YU - XK_Cyrillic_yu);
|
||||
break;
|
||||
}
|
||||
|
||||
// Greek
|
||||
case 7:
|
||||
{
|
||||
if (keysym >= XK_Greek_ALPHAaccent && keysym <= XK_Greek_OMEGAaccent)
|
||||
return keysym + (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
|
||||
else if (keysym >= XK_Greek_ALPHA && keysym <= XK_Greek_OMEGA)
|
||||
return keysym + (XK_Greek_alpha - XK_Greek_ALPHA);
|
||||
break;
|
||||
}
|
||||
|
||||
// Armenian
|
||||
case 0x14:
|
||||
{
|
||||
if (keysym >= XK_Armenian_AYB && keysym <= XK_Armenian_fe) {
|
||||
return (keysym | 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return keysym;
|
||||
}
|
||||
|
||||
void buildMap()
|
||||
{
|
||||
// Open a connection with the X server
|
||||
xcb_connection_t* connection = sf::priv::OpenConnection();
|
||||
|
||||
firstKeycode = xcb_get_setup(connection)->min_keycode;
|
||||
lastKeycode = xcb_get_setup(connection)->max_keycode;
|
||||
|
||||
sf::priv::ScopedXcbPtr<xcb_generic_error_t> error(NULL);
|
||||
|
||||
sf::priv::ScopedXcbPtr<xcb_get_keyboard_mapping_reply_t> keyboardMapping(xcb_get_keyboard_mapping_reply(
|
||||
connection,
|
||||
xcb_get_keyboard_mapping(
|
||||
connection,
|
||||
firstKeycode,
|
||||
lastKeycode - firstKeycode + 1
|
||||
),
|
||||
&error
|
||||
));
|
||||
|
||||
sf::priv::CloseConnection(connection);
|
||||
|
||||
if (error || !keyboardMapping)
|
||||
{
|
||||
sf::err() << "Failed to get keyboard mapping" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t keysymsPerKeycode = keyboardMapping->keysyms_per_keycode;
|
||||
|
||||
if (!keysymsPerKeycode)
|
||||
{
|
||||
sf::err() << "Error: No keysyms per keycode" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const xcb_keysym_t* keysyms = xcb_get_keyboard_mapping_keysyms(keyboardMapping.get());
|
||||
|
||||
if (!keysyms)
|
||||
{
|
||||
sf::err() << "Failed to get keyboard mapping keysyms" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_keycode_t range = lastKeycode - firstKeycode + 1;
|
||||
|
||||
std::fill(keysymMap, keysymMap + 256, XK_VoidSymbol);
|
||||
|
||||
for (xcb_keycode_t i = firstKeycode; ; ++i)
|
||||
{
|
||||
const xcb_keysym_t* keysym = &keysyms[(i - firstKeycode) * keysymsPerKeycode];
|
||||
|
||||
if ((keysymsPerKeycode == 1) || (keysym[1] == XCB_NO_SYMBOL))
|
||||
{
|
||||
keysymMap[i] = keysymToLower(keysym[0]);
|
||||
|
||||
if (i == lastKeycode)
|
||||
break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
keysymMap[i] = keysym[0];
|
||||
|
||||
if (i == lastKeycode)
|
||||
break;
|
||||
}
|
||||
|
||||
mapBuilt = true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace sf
|
||||
@ -80,6 +260,7 @@ void CloseDisplay(Display* display)
|
||||
XCloseDisplay(display);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void CloseConnection(xcb_connection_t* connection)
|
||||
{
|
||||
@ -87,6 +268,7 @@ void CloseConnection(xcb_connection_t* connection)
|
||||
return CloseDisplay(sharedDisplay);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
|
||||
{
|
||||
@ -101,6 +283,7 @@ xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection)
|
||||
{
|
||||
@ -108,6 +291,7 @@ xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection)
|
||||
return XCBScreenOfDisplay(connection, XDefaultScreen(sharedDisplay));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection)
|
||||
{
|
||||
@ -118,6 +302,53 @@ xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
xcb_atom_t 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);
|
||||
|
||||
xcb_connection_t* connection = OpenConnection();
|
||||
|
||||
ScopedXcbPtr<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(
|
||||
connection,
|
||||
xcb_intern_atom(
|
||||
connection,
|
||||
onlyIfExists,
|
||||
name.size(),
|
||||
name.c_str()
|
||||
),
|
||||
&error
|
||||
));
|
||||
|
||||
CloseConnection(connection);
|
||||
|
||||
if (error || !reply)
|
||||
{
|
||||
err() << "Failed to get " << name << " atom." << std::endl;
|
||||
return XCB_ATOM_NONE;
|
||||
}
|
||||
|
||||
atoms[name] = reply->atom;
|
||||
|
||||
return reply->atom;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const xcb_keysym_t* getKeysymMap()
|
||||
{
|
||||
if (!mapBuilt)
|
||||
buildMap();
|
||||
|
||||
return keysymMap;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
@ -29,6 +29,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -104,6 +105,28 @@ xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection);
|
||||
////////////////////////////////////////////////////////////
|
||||
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
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
xcb_atom_t getAtom(const std::string& name, bool onlyIfExists = false);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the keycode to keysym map
|
||||
///
|
||||
/// Contains 255 values. Use the keycode as the index
|
||||
/// into the array to retrieve its keysym.
|
||||
///
|
||||
/// \return Keycode to keysym map
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const xcb_keysym_t* getKeysymMap();
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
@ -30,8 +30,7 @@
|
||||
#include <SFML/Window/Unix/Display.hpp>
|
||||
#include <SFML/Window/Unix/ScopedXcbPtr.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <cstdlib>
|
||||
|
||||
@ -45,138 +44,125 @@ namespace
|
||||
// We use a simple array instead of a map => constant time lookup
|
||||
xcb_keycode_t keycodeMap[sf::Keyboard::KeyCount];
|
||||
|
||||
xcb_keycode_t getKeycode(xcb_key_symbols_t* keySymbols, xcb_keysym_t keysym)
|
||||
xcb_keycode_t getKeycode(xcb_keysym_t keysym)
|
||||
{
|
||||
// keycodes is actually a vector of keycodes
|
||||
// Since we only care about the unmodified keycode,
|
||||
// we simply return the first one
|
||||
sf::priv::ScopedXcbPtr<xcb_keycode_t> keycodes(xcb_key_symbols_get_keycode(keySymbols, keysym));
|
||||
const xcb_keysym_t* keysymMap = sf::priv::getKeysymMap();
|
||||
|
||||
if (keycodes)
|
||||
return *keycodes.get();
|
||||
for (xcb_keycode_t i = 0; ; ++i)
|
||||
{
|
||||
if (keysymMap[i] == keysym)
|
||||
return i;
|
||||
|
||||
return 0;
|
||||
if (i == 255)
|
||||
break;
|
||||
}
|
||||
|
||||
return 255;
|
||||
}
|
||||
|
||||
void buildMap()
|
||||
{
|
||||
// Open a connection with the X server
|
||||
xcb_connection_t* connection = sf::priv::OpenConnection();
|
||||
|
||||
xcb_key_symbols_t* keySymbols = xcb_key_symbols_alloc(connection);
|
||||
|
||||
if (!keySymbols)
|
||||
{
|
||||
sf::err() << "Failed to allocate key symbols" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
keycodeMap[sf::Keyboard::A] = getKeycode(keySymbols, XK_A);
|
||||
keycodeMap[sf::Keyboard::B] = getKeycode(keySymbols, XK_B);
|
||||
keycodeMap[sf::Keyboard::C] = getKeycode(keySymbols, XK_C);
|
||||
keycodeMap[sf::Keyboard::D] = getKeycode(keySymbols, XK_D);
|
||||
keycodeMap[sf::Keyboard::E] = getKeycode(keySymbols, XK_E);
|
||||
keycodeMap[sf::Keyboard::F] = getKeycode(keySymbols, XK_F);
|
||||
keycodeMap[sf::Keyboard::G] = getKeycode(keySymbols, XK_G);
|
||||
keycodeMap[sf::Keyboard::H] = getKeycode(keySymbols, XK_H);
|
||||
keycodeMap[sf::Keyboard::I] = getKeycode(keySymbols, XK_I);
|
||||
keycodeMap[sf::Keyboard::J] = getKeycode(keySymbols, XK_J);
|
||||
keycodeMap[sf::Keyboard::K] = getKeycode(keySymbols, XK_K);
|
||||
keycodeMap[sf::Keyboard::L] = getKeycode(keySymbols, XK_L);
|
||||
keycodeMap[sf::Keyboard::M] = getKeycode(keySymbols, XK_M);
|
||||
keycodeMap[sf::Keyboard::N] = getKeycode(keySymbols, XK_N);
|
||||
keycodeMap[sf::Keyboard::O] = getKeycode(keySymbols, XK_O);
|
||||
keycodeMap[sf::Keyboard::P] = getKeycode(keySymbols, XK_P);
|
||||
keycodeMap[sf::Keyboard::Q] = getKeycode(keySymbols, XK_Q);
|
||||
keycodeMap[sf::Keyboard::R] = getKeycode(keySymbols, XK_R);
|
||||
keycodeMap[sf::Keyboard::S] = getKeycode(keySymbols, XK_S);
|
||||
keycodeMap[sf::Keyboard::T] = getKeycode(keySymbols, XK_T);
|
||||
keycodeMap[sf::Keyboard::U] = getKeycode(keySymbols, XK_U);
|
||||
keycodeMap[sf::Keyboard::V] = getKeycode(keySymbols, XK_V);
|
||||
keycodeMap[sf::Keyboard::W] = getKeycode(keySymbols, XK_W);
|
||||
keycodeMap[sf::Keyboard::X] = getKeycode(keySymbols, XK_X);
|
||||
keycodeMap[sf::Keyboard::Y] = getKeycode(keySymbols, XK_Y);
|
||||
keycodeMap[sf::Keyboard::Z] = getKeycode(keySymbols, XK_Z);
|
||||
keycodeMap[sf::Keyboard::Num0] = getKeycode(keySymbols, XK_0);
|
||||
keycodeMap[sf::Keyboard::Num1] = getKeycode(keySymbols, XK_1);
|
||||
keycodeMap[sf::Keyboard::Num2] = getKeycode(keySymbols, XK_2);
|
||||
keycodeMap[sf::Keyboard::Num3] = getKeycode(keySymbols, XK_3);
|
||||
keycodeMap[sf::Keyboard::Num4] = getKeycode(keySymbols, XK_4);
|
||||
keycodeMap[sf::Keyboard::Num5] = getKeycode(keySymbols, XK_5);
|
||||
keycodeMap[sf::Keyboard::Num6] = getKeycode(keySymbols, XK_6);
|
||||
keycodeMap[sf::Keyboard::Num7] = getKeycode(keySymbols, XK_7);
|
||||
keycodeMap[sf::Keyboard::Num8] = getKeycode(keySymbols, XK_8);
|
||||
keycodeMap[sf::Keyboard::Num9] = getKeycode(keySymbols, XK_9);
|
||||
keycodeMap[sf::Keyboard::Escape] = getKeycode(keySymbols, XK_Escape);
|
||||
keycodeMap[sf::Keyboard::LControl] = getKeycode(keySymbols, XK_Control_L);
|
||||
keycodeMap[sf::Keyboard::LShift] = getKeycode(keySymbols, XK_Shift_L);
|
||||
keycodeMap[sf::Keyboard::LAlt] = getKeycode(keySymbols, XK_Alt_L);
|
||||
keycodeMap[sf::Keyboard::LSystem] = getKeycode(keySymbols, XK_Super_L);
|
||||
keycodeMap[sf::Keyboard::RControl] = getKeycode(keySymbols, XK_Control_R);
|
||||
keycodeMap[sf::Keyboard::RShift] = getKeycode(keySymbols, XK_Shift_R);
|
||||
keycodeMap[sf::Keyboard::RAlt] = getKeycode(keySymbols, XK_Alt_R);
|
||||
keycodeMap[sf::Keyboard::RSystem] = getKeycode(keySymbols, XK_Super_R);
|
||||
keycodeMap[sf::Keyboard::Menu] = getKeycode(keySymbols, XK_Menu);
|
||||
keycodeMap[sf::Keyboard::LBracket] = getKeycode(keySymbols, XK_bracketleft);
|
||||
keycodeMap[sf::Keyboard::RBracket] = getKeycode(keySymbols, XK_bracketright);
|
||||
keycodeMap[sf::Keyboard::SemiColon] = getKeycode(keySymbols, XK_semicolon);
|
||||
keycodeMap[sf::Keyboard::Comma] = getKeycode(keySymbols, XK_comma);
|
||||
keycodeMap[sf::Keyboard::Period] = getKeycode(keySymbols, XK_period);
|
||||
keycodeMap[sf::Keyboard::Quote] = getKeycode(keySymbols, XK_apostrophe);
|
||||
keycodeMap[sf::Keyboard::Slash] = getKeycode(keySymbols, XK_slash);
|
||||
keycodeMap[sf::Keyboard::BackSlash] = getKeycode(keySymbols, XK_backslash);
|
||||
keycodeMap[sf::Keyboard::Tilde] = getKeycode(keySymbols, XK_grave);
|
||||
keycodeMap[sf::Keyboard::Equal] = getKeycode(keySymbols, XK_equal);
|
||||
keycodeMap[sf::Keyboard::Dash] = getKeycode(keySymbols, XK_minus);
|
||||
keycodeMap[sf::Keyboard::Space] = getKeycode(keySymbols, XK_space);
|
||||
keycodeMap[sf::Keyboard::Return] = getKeycode(keySymbols, XK_Return);
|
||||
keycodeMap[sf::Keyboard::BackSpace] = getKeycode(keySymbols, XK_BackSpace);
|
||||
keycodeMap[sf::Keyboard::Tab] = getKeycode(keySymbols, XK_Tab);
|
||||
keycodeMap[sf::Keyboard::PageUp] = getKeycode(keySymbols, XK_Prior);
|
||||
keycodeMap[sf::Keyboard::PageDown] = getKeycode(keySymbols, XK_Next);
|
||||
keycodeMap[sf::Keyboard::End] = getKeycode(keySymbols, XK_End);
|
||||
keycodeMap[sf::Keyboard::Home] = getKeycode(keySymbols, XK_Home);
|
||||
keycodeMap[sf::Keyboard::Insert] = getKeycode(keySymbols, XK_Insert);
|
||||
keycodeMap[sf::Keyboard::Delete] = getKeycode(keySymbols, XK_Delete);
|
||||
keycodeMap[sf::Keyboard::Add] = getKeycode(keySymbols, XK_KP_Add);
|
||||
keycodeMap[sf::Keyboard::Subtract] = getKeycode(keySymbols, XK_KP_Subtract);
|
||||
keycodeMap[sf::Keyboard::Multiply] = getKeycode(keySymbols, XK_KP_Multiply);
|
||||
keycodeMap[sf::Keyboard::Divide] = getKeycode(keySymbols, XK_KP_Divide);
|
||||
keycodeMap[sf::Keyboard::Left] = getKeycode(keySymbols, XK_Left);
|
||||
keycodeMap[sf::Keyboard::Right] = getKeycode(keySymbols, XK_Right);
|
||||
keycodeMap[sf::Keyboard::Up] = getKeycode(keySymbols, XK_Up);
|
||||
keycodeMap[sf::Keyboard::Down] = getKeycode(keySymbols, XK_Down);
|
||||
keycodeMap[sf::Keyboard::Numpad0] = getKeycode(keySymbols, XK_KP_0);
|
||||
keycodeMap[sf::Keyboard::Numpad1] = getKeycode(keySymbols, XK_KP_1);
|
||||
keycodeMap[sf::Keyboard::Numpad2] = getKeycode(keySymbols, XK_KP_2);
|
||||
keycodeMap[sf::Keyboard::Numpad3] = getKeycode(keySymbols, XK_KP_3);
|
||||
keycodeMap[sf::Keyboard::Numpad4] = getKeycode(keySymbols, XK_KP_4);
|
||||
keycodeMap[sf::Keyboard::Numpad5] = getKeycode(keySymbols, XK_KP_5);
|
||||
keycodeMap[sf::Keyboard::Numpad6] = getKeycode(keySymbols, XK_KP_6);
|
||||
keycodeMap[sf::Keyboard::Numpad7] = getKeycode(keySymbols, XK_KP_7);
|
||||
keycodeMap[sf::Keyboard::Numpad8] = getKeycode(keySymbols, XK_KP_8);
|
||||
keycodeMap[sf::Keyboard::Numpad9] = getKeycode(keySymbols, XK_KP_9);
|
||||
keycodeMap[sf::Keyboard::F1] = getKeycode(keySymbols, XK_F1);
|
||||
keycodeMap[sf::Keyboard::F2] = getKeycode(keySymbols, XK_F2);
|
||||
keycodeMap[sf::Keyboard::F3] = getKeycode(keySymbols, XK_F3);
|
||||
keycodeMap[sf::Keyboard::F4] = getKeycode(keySymbols, XK_F4);
|
||||
keycodeMap[sf::Keyboard::F5] = getKeycode(keySymbols, XK_F5);
|
||||
keycodeMap[sf::Keyboard::F6] = getKeycode(keySymbols, XK_F6);
|
||||
keycodeMap[sf::Keyboard::F7] = getKeycode(keySymbols, XK_F7);
|
||||
keycodeMap[sf::Keyboard::F8] = getKeycode(keySymbols, XK_F8);
|
||||
keycodeMap[sf::Keyboard::F9] = getKeycode(keySymbols, XK_F9);
|
||||
keycodeMap[sf::Keyboard::F10] = getKeycode(keySymbols, XK_F10);
|
||||
keycodeMap[sf::Keyboard::F11] = getKeycode(keySymbols, XK_F11);
|
||||
keycodeMap[sf::Keyboard::F12] = getKeycode(keySymbols, XK_F12);
|
||||
keycodeMap[sf::Keyboard::F13] = getKeycode(keySymbols, XK_F13);
|
||||
keycodeMap[sf::Keyboard::F14] = getKeycode(keySymbols, XK_F14);
|
||||
keycodeMap[sf::Keyboard::F15] = getKeycode(keySymbols, XK_F15);
|
||||
keycodeMap[sf::Keyboard::Pause] = getKeycode(keySymbols, XK_Pause);
|
||||
|
||||
xcb_key_symbols_free(keySymbols);
|
||||
|
||||
// Close the connection with the X server
|
||||
sf::priv::CloseConnection(connection);
|
||||
keycodeMap[sf::Keyboard::A] = getKeycode(XK_a);
|
||||
keycodeMap[sf::Keyboard::B] = getKeycode(XK_b);
|
||||
keycodeMap[sf::Keyboard::C] = getKeycode(XK_c);
|
||||
keycodeMap[sf::Keyboard::D] = getKeycode(XK_d);
|
||||
keycodeMap[sf::Keyboard::E] = getKeycode(XK_e);
|
||||
keycodeMap[sf::Keyboard::F] = getKeycode(XK_f);
|
||||
keycodeMap[sf::Keyboard::G] = getKeycode(XK_g);
|
||||
keycodeMap[sf::Keyboard::H] = getKeycode(XK_h);
|
||||
keycodeMap[sf::Keyboard::I] = getKeycode(XK_i);
|
||||
keycodeMap[sf::Keyboard::J] = getKeycode(XK_j);
|
||||
keycodeMap[sf::Keyboard::K] = getKeycode(XK_k);
|
||||
keycodeMap[sf::Keyboard::L] = getKeycode(XK_l);
|
||||
keycodeMap[sf::Keyboard::M] = getKeycode(XK_m);
|
||||
keycodeMap[sf::Keyboard::N] = getKeycode(XK_n);
|
||||
keycodeMap[sf::Keyboard::O] = getKeycode(XK_o);
|
||||
keycodeMap[sf::Keyboard::P] = getKeycode(XK_p);
|
||||
keycodeMap[sf::Keyboard::Q] = getKeycode(XK_q);
|
||||
keycodeMap[sf::Keyboard::R] = getKeycode(XK_r);
|
||||
keycodeMap[sf::Keyboard::S] = getKeycode(XK_s);
|
||||
keycodeMap[sf::Keyboard::T] = getKeycode(XK_t);
|
||||
keycodeMap[sf::Keyboard::U] = getKeycode(XK_u);
|
||||
keycodeMap[sf::Keyboard::V] = getKeycode(XK_v);
|
||||
keycodeMap[sf::Keyboard::W] = getKeycode(XK_w);
|
||||
keycodeMap[sf::Keyboard::X] = getKeycode(XK_x);
|
||||
keycodeMap[sf::Keyboard::Y] = getKeycode(XK_y);
|
||||
keycodeMap[sf::Keyboard::Z] = getKeycode(XK_z);
|
||||
keycodeMap[sf::Keyboard::Num0] = getKeycode(XK_0);
|
||||
keycodeMap[sf::Keyboard::Num1] = getKeycode(XK_1);
|
||||
keycodeMap[sf::Keyboard::Num2] = getKeycode(XK_2);
|
||||
keycodeMap[sf::Keyboard::Num3] = getKeycode(XK_3);
|
||||
keycodeMap[sf::Keyboard::Num4] = getKeycode(XK_4);
|
||||
keycodeMap[sf::Keyboard::Num5] = getKeycode(XK_5);
|
||||
keycodeMap[sf::Keyboard::Num6] = getKeycode(XK_6);
|
||||
keycodeMap[sf::Keyboard::Num7] = getKeycode(XK_7);
|
||||
keycodeMap[sf::Keyboard::Num8] = getKeycode(XK_8);
|
||||
keycodeMap[sf::Keyboard::Num9] = getKeycode(XK_9);
|
||||
keycodeMap[sf::Keyboard::Escape] = getKeycode(XK_Escape);
|
||||
keycodeMap[sf::Keyboard::LControl] = getKeycode(XK_Control_L);
|
||||
keycodeMap[sf::Keyboard::LShift] = getKeycode(XK_Shift_L);
|
||||
keycodeMap[sf::Keyboard::LAlt] = getKeycode(XK_Alt_L);
|
||||
keycodeMap[sf::Keyboard::LSystem] = getKeycode(XK_Super_L);
|
||||
keycodeMap[sf::Keyboard::RControl] = getKeycode(XK_Control_R);
|
||||
keycodeMap[sf::Keyboard::RShift] = getKeycode(XK_Shift_R);
|
||||
keycodeMap[sf::Keyboard::RAlt] = getKeycode(XK_Alt_R);
|
||||
keycodeMap[sf::Keyboard::RSystem] = getKeycode(XK_Super_R);
|
||||
keycodeMap[sf::Keyboard::Menu] = getKeycode(XK_Menu);
|
||||
keycodeMap[sf::Keyboard::LBracket] = getKeycode(XK_bracketleft);
|
||||
keycodeMap[sf::Keyboard::RBracket] = getKeycode(XK_bracketright);
|
||||
keycodeMap[sf::Keyboard::SemiColon] = getKeycode(XK_semicolon);
|
||||
keycodeMap[sf::Keyboard::Comma] = getKeycode(XK_comma);
|
||||
keycodeMap[sf::Keyboard::Period] = getKeycode(XK_period);
|
||||
keycodeMap[sf::Keyboard::Quote] = getKeycode(XK_apostrophe);
|
||||
keycodeMap[sf::Keyboard::Slash] = getKeycode(XK_slash);
|
||||
keycodeMap[sf::Keyboard::BackSlash] = getKeycode(XK_backslash);
|
||||
keycodeMap[sf::Keyboard::Tilde] = getKeycode(XK_grave);
|
||||
keycodeMap[sf::Keyboard::Equal] = getKeycode(XK_equal);
|
||||
keycodeMap[sf::Keyboard::Dash] = getKeycode(XK_minus);
|
||||
keycodeMap[sf::Keyboard::Space] = getKeycode(XK_space);
|
||||
keycodeMap[sf::Keyboard::Return] = getKeycode(XK_Return);
|
||||
keycodeMap[sf::Keyboard::BackSpace] = getKeycode(XK_BackSpace);
|
||||
keycodeMap[sf::Keyboard::Tab] = getKeycode(XK_Tab);
|
||||
keycodeMap[sf::Keyboard::PageUp] = getKeycode(XK_Prior);
|
||||
keycodeMap[sf::Keyboard::PageDown] = getKeycode(XK_Next);
|
||||
keycodeMap[sf::Keyboard::End] = getKeycode(XK_End);
|
||||
keycodeMap[sf::Keyboard::Home] = getKeycode(XK_Home);
|
||||
keycodeMap[sf::Keyboard::Insert] = getKeycode(XK_Insert);
|
||||
keycodeMap[sf::Keyboard::Delete] = getKeycode(XK_Delete);
|
||||
keycodeMap[sf::Keyboard::Add] = getKeycode(XK_KP_Add);
|
||||
keycodeMap[sf::Keyboard::Subtract] = getKeycode(XK_KP_Subtract);
|
||||
keycodeMap[sf::Keyboard::Multiply] = getKeycode(XK_KP_Multiply);
|
||||
keycodeMap[sf::Keyboard::Divide] = getKeycode(XK_KP_Divide);
|
||||
keycodeMap[sf::Keyboard::Left] = getKeycode(XK_Left);
|
||||
keycodeMap[sf::Keyboard::Right] = getKeycode(XK_Right);
|
||||
keycodeMap[sf::Keyboard::Up] = getKeycode(XK_Up);
|
||||
keycodeMap[sf::Keyboard::Down] = getKeycode(XK_Down);
|
||||
keycodeMap[sf::Keyboard::Numpad0] = getKeycode(XK_KP_0);
|
||||
keycodeMap[sf::Keyboard::Numpad1] = getKeycode(XK_KP_1);
|
||||
keycodeMap[sf::Keyboard::Numpad2] = getKeycode(XK_KP_2);
|
||||
keycodeMap[sf::Keyboard::Numpad3] = getKeycode(XK_KP_3);
|
||||
keycodeMap[sf::Keyboard::Numpad4] = getKeycode(XK_KP_4);
|
||||
keycodeMap[sf::Keyboard::Numpad5] = getKeycode(XK_KP_5);
|
||||
keycodeMap[sf::Keyboard::Numpad6] = getKeycode(XK_KP_6);
|
||||
keycodeMap[sf::Keyboard::Numpad7] = getKeycode(XK_KP_7);
|
||||
keycodeMap[sf::Keyboard::Numpad8] = getKeycode(XK_KP_8);
|
||||
keycodeMap[sf::Keyboard::Numpad9] = getKeycode(XK_KP_9);
|
||||
keycodeMap[sf::Keyboard::F1] = getKeycode(XK_F1);
|
||||
keycodeMap[sf::Keyboard::F2] = getKeycode(XK_F2);
|
||||
keycodeMap[sf::Keyboard::F3] = getKeycode(XK_F3);
|
||||
keycodeMap[sf::Keyboard::F4] = getKeycode(XK_F4);
|
||||
keycodeMap[sf::Keyboard::F5] = getKeycode(XK_F5);
|
||||
keycodeMap[sf::Keyboard::F6] = getKeycode(XK_F6);
|
||||
keycodeMap[sf::Keyboard::F7] = getKeycode(XK_F7);
|
||||
keycodeMap[sf::Keyboard::F8] = getKeycode(XK_F8);
|
||||
keycodeMap[sf::Keyboard::F9] = getKeycode(XK_F9);
|
||||
keycodeMap[sf::Keyboard::F10] = getKeycode(XK_F10);
|
||||
keycodeMap[sf::Keyboard::F11] = getKeycode(XK_F11);
|
||||
keycodeMap[sf::Keyboard::F12] = getKeycode(XK_F12);
|
||||
keycodeMap[sf::Keyboard::F13] = getKeycode(XK_F13);
|
||||
keycodeMap[sf::Keyboard::F14] = getKeycode(XK_F14);
|
||||
keycodeMap[sf::Keyboard::F15] = getKeycode(XK_F15);
|
||||
keycodeMap[sf::Keyboard::Pause] = getKeycode(XK_Pause);
|
||||
|
||||
mapBuilt = true;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -32,8 +32,6 @@
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/xcb_ewmh.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <xcb/randr.h>
|
||||
#include <deque>
|
||||
|
||||
@ -182,6 +180,33 @@ 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
|
||||
///
|
||||
@ -220,6 +245,36 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
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);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Do some common initializations after the window has been created
|
||||
///
|
||||
@ -259,31 +314,17 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
bool passEvent(xcb_generic_event_t* windowEvent, xcb_window_t window);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a X11 keysym to SFML key code
|
||||
///
|
||||
/// \param symbol Key symbol to convert
|
||||
///
|
||||
/// \return Corresponding SFML key code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Key keysymToSF(xcb_keysym_t symbol);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// 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_ewmh_connection_t m_ewmhConnection; ///< xcb EWMH 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
|
||||
xcb_key_symbols_t* m_keySymbols; ///< Symbols used to look up keysyms
|
||||
std::deque<xcb_generic_event_t*> m_xcbEvents; ///< Events that were received in another window's loop
|
||||
bool m_isExternal; ///< Tell whether the window has been created externally or by SFML
|
||||
Atom m_atomWmProtocols; ///< Atom used to identify WM protocol messages
|
||||
Atom m_atomClose; ///< Atom used to identify the close event
|
||||
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?
|
||||
|
Loading…
Reference in New Issue
Block a user