Switch from Nz prefix to namespace Nz for linux

Former-commit-id: 64eeaf3c633254b04910ebd4576fd9e910002be0
This commit is contained in:
Youri Hubaut
2015-09-27 15:58:49 +02:00
parent 752518ef14
commit 37586e7283
49 changed files with 3918 additions and 3732 deletions

View File

@@ -10,22 +10,22 @@
void* operator new(std::size_t size)
{
return NzMemoryManager::Allocate(size, false);
return Nz::MemoryManager::Allocate(size, false);
}
void* operator new[](std::size_t size)
{
return NzMemoryManager::Allocate(size, true);
return Nz::MemoryManager::Allocate(size, true);
}
void operator delete(void* pointer) noexcept
{
NzMemoryManager::Free(pointer, false);
Nz::MemoryManager::Free(pointer, false);
}
void operator delete[](void* pointer) noexcept
{
NzMemoryManager::Free(pointer, true);
Nz::MemoryManager::Free(pointer, true);
}
#endif // NAZARA_UTILITY_MANAGE_MEMORY

View File

@@ -12,150 +12,153 @@
#include <xcb/xcb_renderutil.h>
#include <Nazara/Utility/Debug.hpp>
bool NzCursorImpl::Create(const NzImage& cursor, int hotSpotX, int hotSpotY)
namespace Nz
{
NzImage cursorImage(cursor); // Vive le COW
if (!cursorImage.Convert(nzPixelFormat_BGRA8))
bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY)
{
NazaraError("Failed to convert cursor to BGRA8");
return false;
}
Image cursorImage(cursor); // Vive le COW
if (!cursorImage.Convert(Nz::PixelFormatType_BGRA8))
{
NazaraError("Failed to convert cursor to BGRA8");
return false;
}
auto width = cursorImage.GetWidth();
auto height = cursorImage.GetHeight();
auto width = cursorImage.GetWidth();
auto height = cursorImage.GetHeight();
NzScopedXCBConnection connection;
ScopedXCBConnection connection;
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
NzScopedXCB<xcb_generic_error_t> error(nullptr);
NzScopedXCB<xcb_render_query_pict_formats_reply_t> formatsReply = xcb_render_query_pict_formats_reply(
connection,
xcb_render_query_pict_formats(connection),
&error);
if (!formatsReply || error)
{
NazaraError("Failed to get pict formats");
return false;
}
xcb_render_pictforminfo_t* fmt = xcb_render_util_find_standard_format(
formatsReply.get(),
XCB_PICT_STANDARD_ARGB_32);
if (!fmt)
{
NazaraError("Failed to find format PICT_STANDARD_ARGB_32");
return false;
}
xcb_image_t* xi = xcb_image_create(
width, height,
XCB_IMAGE_FORMAT_Z_PIXMAP,
32, 32, 32, 32,
XCB_IMAGE_ORDER_LSB_FIRST,
XCB_IMAGE_ORDER_MSB_FIRST,
0, 0, 0);
if (!xi)
{
NazaraError("Failed to create image for cursor");
return false;
}
std::unique_ptr<uint8_t[]> data(new uint8_t[xi->stride * height]);
if (!data)
{
xcb_image_destroy(xi);
NazaraError("Failed to allocate memory for cursor image");
return false;
}
xi->data = data.get();
std::copy(cursorImage.GetConstPixels(), cursorImage.GetConstPixels() + cursorImage.GetBytesPerPixel() * width * height, xi->data);
xcb_render_picture_t pic = XCB_NONE;
NzCallOnExit onExit([&](){
xcb_image_destroy(xi);
if (pic != XCB_NONE)
xcb_render_free_picture(connection, pic);
});
NzXCBPixmap pix(connection);
if (!pix.Create(32, screen->root, width, height))
{
NazaraError("Failed to create pixmap for cursor");
return false;
}
pic = xcb_generate_id(connection);
if (!X11::CheckCookie(
connection,
xcb_render_create_picture(
ScopedXCB<xcb_generic_error_t> error(nullptr);
ScopedXCB<xcb_render_query_pict_formats_reply_t> formatsReply = xcb_render_query_pict_formats_reply(
connection,
pic,
pix,
fmt->id,
0,
nullptr
)))
{
NazaraError("Failed to create render picture for cursor");
return false;
}
xcb_render_query_pict_formats(connection),
&error);
NzXCBGContext gc(connection);
if (!gc.Create(pix, 0, nullptr))
{
NazaraError("Failed to create gcontext for cursor");
return false;
}
if (!formatsReply || error)
{
NazaraError("Failed to get pict formats");
return false;
}
if (!X11::CheckCookie(
connection,
xcb_image_put(
xcb_render_pictforminfo_t* fmt = xcb_render_util_find_standard_format(
formatsReply.get(),
XCB_PICT_STANDARD_ARGB_32);
if (!fmt)
{
NazaraError("Failed to find format PICT_STANDARD_ARGB_32");
return false;
}
xcb_image_t* xi = xcb_image_create(
width, height,
XCB_IMAGE_FORMAT_Z_PIXMAP,
32, 32, 32, 32,
XCB_IMAGE_ORDER_LSB_FIRST,
XCB_IMAGE_ORDER_MSB_FIRST,
0, 0, 0);
if (!xi)
{
NazaraError("Failed to create image for cursor");
return false;
}
std::unique_ptr<uint8_t[]> data(new uint8_t[xi->stride * height]);
if (!data)
{
xcb_image_destroy(xi);
NazaraError("Failed to allocate memory for cursor image");
return false;
}
xi->data = data.get();
std::copy(cursorImage.GetConstPixels(), cursorImage.GetConstPixels() + cursorImage.GetBytesPerPixel() * width * height, xi->data);
xcb_render_picture_t pic = XCB_NONE;
CallOnExit onExit([&](){
xcb_image_destroy(xi);
if (pic != XCB_NONE)
xcb_render_free_picture(connection, pic);
});
XCBPixmap pix(connection);
if (!pix.Create(32, screen->root, width, height))
{
NazaraError("Failed to create pixmap for cursor");
return false;
}
pic = xcb_generate_id(connection);
if (!X11::CheckCookie(
connection,
pix,
gc,
xi,
0, 0,
0
)))
{
NazaraError("Failed to put image for cursor");
return false;
}
xcb_render_create_picture(
connection,
pic,
pix,
fmt->id,
0,
nullptr
)))
{
NazaraError("Failed to create render picture for cursor");
return false;
}
m_cursor = xcb_generate_id(connection);
if (!X11::CheckCookie(
connection,
xcb_render_create_cursor(
XCBGContext gc(connection);
if (!gc.Create(pix, 0, nullptr))
{
NazaraError("Failed to create gcontext for cursor");
return false;
}
if (!X11::CheckCookie(
connection,
m_cursor,
pic,
hotSpotX, hotSpotY
)))
{
NazaraError("Failed to create cursor");
return false;
xcb_image_put(
connection,
pix,
gc,
xi,
0, 0,
0
)))
{
NazaraError("Failed to put image for cursor");
return false;
}
m_cursor = xcb_generate_id(connection);
if (!X11::CheckCookie(
connection,
xcb_render_create_cursor(
connection,
m_cursor,
pic,
hotSpotX, hotSpotY
)))
{
NazaraError("Failed to create cursor");
return false;
}
return true;
}
return true;
}
void CursorImpl::Destroy()
{
ScopedXCBConnection connection;
void NzCursorImpl::Destroy()
{
NzScopedXCBConnection connection;
xcb_free_cursor(connection, m_cursor);
m_cursor = 0;
}
xcb_free_cursor(connection, m_cursor);
m_cursor = 0;
}
xcb_cursor_t NzCursorImpl::GetCursor()
{
return m_cursor;
xcb_cursor_t CursorImpl::GetCursor()
{
return m_cursor;
}
}

View File

@@ -7,20 +7,24 @@
#ifndef NAZARA_CURSORIMPL_HPP
#define NAZARA_CURSORIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <xcb/xcb_cursor.h>
class NzImage;
class NzCursorImpl
namespace Nz
{
public:
bool Create(const NzImage& image, int hotSpotX, int hotSpotY);
void Destroy();
class Image;
xcb_cursor_t GetCursor();
class CursorImpl
{
public:
bool Create(const Image& image, int hotSpotX, int hotSpotY);
void Destroy();
private:
xcb_cursor_t m_cursor;
};
xcb_cursor_t GetCursor();
private:
xcb_cursor_t m_cursor;
};
}
#endif // NAZARA_CURSORIMPL_HPP

View File

@@ -4,32 +4,34 @@
#include <Nazara/Utility/X11/Display.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/String.hpp>
#include <xcb/xcb_keysyms.h>
#include <map>
#include <Nazara/Utility/Debug.hpp>
namespace
namespace Nz
{
// The shared display and its reference counter
xcb_connection_t* sharedConnection = nullptr;
int screen_nbr = 0;
unsigned int referenceCountConnection = 0;
xcb_key_symbols_t* sharedkeySymbol;
unsigned int referenceCountKeySymbol = 0;
xcb_ewmh_connection_t* sharedEwmhConnection;
unsigned int referenceCountEwmhConnection = 0;
using AtomMap = std::map<std::string, xcb_atom_t>;
AtomMap atoms;
}
namespace X11
{
bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie)
namespace
{
NzScopedXCB<xcb_generic_error_t> error(xcb_request_check(
// The shared display and its reference counter
xcb_connection_t* sharedConnection = nullptr;
int screen_nbr = 0;
unsigned int referenceCountConnection = 0;
xcb_key_symbols_t* sharedkeySymbol = nullptr;
unsigned int referenceCountKeySymbol = 0;
xcb_ewmh_connection_t* sharedEwmhConnection = nullptr;
unsigned int referenceCountEwmhConnection = 0;
using AtomMap = std::map<String, xcb_atom_t>;
AtomMap atoms;
}
bool X11::CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie)
{
ScopedXCB<xcb_generic_error_t> error(xcb_request_check(
connection,
cookie
));
@@ -40,36 +42,36 @@ namespace X11
return true;
}
void CloseConnection(xcb_connection_t* connection)
void X11::CloseConnection(xcb_connection_t* connection)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
--referenceCountConnection;
}
void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection)
void X11::CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection)
{
NazaraAssert(ewmh_connection == sharedEwmhConnection, "The model is meant for one connection to X11 server");
--referenceCountEwmhConnection;
}
xcb_atom_t GetAtom(const std::string& name, bool onlyIfExists)
xcb_atom_t X11::GetAtom(const String& name, bool onlyIfExists)
{
AtomMap::const_iterator iter = atoms.find(name);
if (iter != atoms.end())
return iter->second;
NzScopedXCB<xcb_generic_error_t> error(nullptr);
ScopedXCB<xcb_generic_error_t> error(nullptr);
xcb_connection_t* connection = OpenConnection();
NzScopedXCB<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(
ScopedXCB<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(
connection,
xcb_intern_atom(
connection,
onlyIfExists,
name.size(),
name.c_str()
name.GetSize(),
name.GetConstBuffer()
),
&error
));
@@ -87,8 +89,16 @@ namespace X11
return reply->atom;
}
void Initialize()
bool X11::Initialize()
{
if (IsInitialized())
{
s_moduleReferenceCounter++;
return true; // Déjà initialisé
}
s_moduleReferenceCounter++;
NazaraAssert(referenceCountConnection == 0, "Initialize should be called before anything");
NazaraAssert(referenceCountKeySymbol == 0, "Initialize should be called before anything");
NazaraAssert(referenceCountEwmhConnection == 0, "Initialize should be called before anything");
@@ -125,9 +135,17 @@ namespace X11
OpenEWMHConnection(sharedConnection);
}
NazaraNotice("Initialized: Utility module");
return true;
}
xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection)
bool X11::IsInitialized()
{
return s_moduleReferenceCounter != 0;
}
xcb_key_symbols_t* X11::XCBKeySymbolsAlloc(xcb_connection_t* connection)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
@@ -135,20 +153,20 @@ namespace X11
return sharedkeySymbol;
}
void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols)
void X11::XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols)
{
NazaraAssert(keySymbols == sharedkeySymbol, "The model is meant for one connection to X11 server");
--referenceCountKeySymbol;
}
xcb_connection_t* OpenConnection()
xcb_connection_t* X11::OpenConnection()
{
++referenceCountConnection;
return sharedConnection;
}
xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection)
xcb_ewmh_connection_t* X11::OpenEWMHConnection(xcb_connection_t* connection)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
@@ -156,8 +174,19 @@ namespace X11
return sharedEwmhConnection;
}
void Uninitialize()
void X11::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Le module est soit encore utilisé, soit pas initialisé
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
s_moduleReferenceCounter = 0;
{
NazaraAssert(referenceCountEwmhConnection == 1, "Uninitialize should be called after anything or a close is missing");
CloseEWMHConnection(sharedEwmhConnection);
@@ -179,9 +208,11 @@ namespace X11
xcb_disconnect(sharedConnection);
}
NazaraNotice("Uninitialized: Display module");
}
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection)
xcb_window_t X11::XCBDefaultRootWindow(xcb_connection_t* connection)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
xcb_screen_t* screen = XCBDefaultScreen(connection);
@@ -190,19 +221,19 @@ namespace X11
return XCB_NONE;
}
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection)
xcb_screen_t* X11::XCBDefaultScreen(xcb_connection_t* connection)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
return XCBScreenOfDisplay(connection, screen_nbr);
}
int XCBScreen(xcb_connection_t* connection)
int X11::XCBScreen(xcb_connection_t* connection)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
return screen_nbr;
}
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
{
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection));
@@ -215,4 +246,6 @@ namespace X11
return nullptr;
}
unsigned int X11::s_moduleReferenceCounter = 0;
}

View File

@@ -7,35 +7,47 @@
#ifndef NAZARA_X11DISPLAY_HPP
#define NAZARA_X11DISPLAY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/WindowHandle.hpp>
#include <Nazara/Utility/X11/ScopedXCB.hpp>
#include <xcb/xcb_ewmh.h>
#include <string>
typedef struct _XCBKeySymbols xcb_key_symbols_t;
namespace X11
namespace Nz
{
bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie);
void CloseConnection(xcb_connection_t* connection);
void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection);
class String;
xcb_atom_t GetAtom(const std::string& name, bool onlyIfExists = false);
class X11
{
public:
X11() = delete;
~X11() = delete;
void Initialize();
static bool CheckCookie(xcb_connection_t* connection, xcb_void_cookie_t cookie);
static void CloseConnection(xcb_connection_t* connection);
static void CloseEWMHConnection(xcb_ewmh_connection_t* ewmh_connection);
xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection);
void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols);
static xcb_atom_t GetAtom(const String& name, bool onlyIfExists = false);
xcb_connection_t* OpenConnection();
xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection);
static bool Initialize();
static bool IsInitialized();
void Uninitialize();
static xcb_key_symbols_t* XCBKeySymbolsAlloc(xcb_connection_t* connection);
static void XCBKeySymbolsFree(xcb_key_symbols_t* keySymbols);
xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection);
xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection);
int XCBScreen(xcb_connection_t* connection);
xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr);
static xcb_connection_t* OpenConnection();
static xcb_ewmh_connection_t* OpenEWMHConnection(xcb_connection_t* connection);
static void Uninitialize();
static xcb_screen_t* XCBDefaultScreen(xcb_connection_t* connection);
static xcb_window_t XCBDefaultRootWindow(xcb_connection_t* connection);
static int XCBScreen(xcb_connection_t* connection);
static xcb_screen_t* XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr);
private:
static unsigned int s_moduleReferenceCounter;
};
}
#endif // NAZARA_X11DISPLAY_HPP

View File

@@ -10,125 +10,128 @@
#include <Nazara/Utility/X11/Display.hpp>
#include <Nazara/Utility/Debug.hpp>
NzIconImpl::NzIconImpl()
namespace Nz
{
NzScopedXCBConnection connection;
m_iconPixmap.Connect(connection);
m_maskPixmap.Connect(connection);
}
bool NzIconImpl::Create(const NzImage& icon)
{
NzImage iconImage(icon); // Vive le COW
if (!iconImage.Convert(nzPixelFormat_BGRA8))
IconImpl::IconImpl()
{
NazaraError("Failed to convert icon to BGRA8");
return false;
ScopedXCBConnection connection;
m_iconPixmap.Connect(connection);
m_maskPixmap.Connect(connection);
}
auto width = iconImage.GetWidth();
auto height = iconImage.GetHeight();
NzScopedXCBConnection connection;
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
if (!m_iconPixmap.Create(
screen->root_depth,
screen->root,
width,
height))
bool IconImpl::Create(const Image& icon)
{
NazaraError("Failed to create icon pixmap");
return false;
}
NzCallOnExit onExit([this](){
Destroy();
});
NzXCBGContext iconGC(connection);
if (!iconGC.Create(
m_iconPixmap,
0,
nullptr))
{
NazaraError("Failed to create icon gc");
return false;
}
if (!X11::CheckCookie(
connection,
xcb_put_image(
connection,
XCB_IMAGE_FORMAT_Z_PIXMAP,
m_iconPixmap,
iconGC,
width,
height,
0,
0,
0,
screen->root_depth,
width * height * 4,
iconImage.GetConstPixels()
)))
{
NazaraError("Failed to put image for icon");
return false;
}
// Create the mask pixmap (must have 1 bit depth)
std::size_t pitch = (width + 7) / 8;
static std::vector<nzUInt8> maskPixels(pitch * height, 0);
for (std::size_t j = 0; j < height; ++j)
{
for (std::size_t i = 0; i < pitch; ++i)
Image iconImage(icon); // Vive le COW
if (!iconImage.Convert(Nz::PixelFormatType_BGRA8))
{
for (std::size_t k = 0; k < 8; ++k)
NazaraError("Failed to convert icon to BGRA8");
return false;
}
auto width = iconImage.GetWidth();
auto height = iconImage.GetHeight();
ScopedXCBConnection connection;
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
if (!m_iconPixmap.Create(
screen->root_depth,
screen->root,
width,
height))
{
NazaraError("Failed to create icon pixmap");
return false;
}
CallOnExit onExit([this](){
Destroy();
});
XCBGContext iconGC(connection);
if (!iconGC.Create(
m_iconPixmap,
0,
nullptr))
{
NazaraError("Failed to create icon gc");
return false;
}
if (!X11::CheckCookie(
connection,
xcb_put_image(
connection,
XCB_IMAGE_FORMAT_Z_PIXMAP,
m_iconPixmap,
iconGC,
width,
height,
0,
0,
0,
screen->root_depth,
width * height * 4,
iconImage.GetConstPixels()
)))
{
NazaraError("Failed to put image for icon");
return false;
}
// Create the mask pixmap (must have 1 bit depth)
std::size_t pitch = (width + 7) / 8;
static std::vector<UInt8> maskPixels(pitch * height, 0);
for (std::size_t j = 0; j < height; ++j)
{
for (std::size_t i = 0; i < pitch; ++i)
{
if (i * 8 + k < width)
for (std::size_t k = 0; k < 8; ++k)
{
nzUInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0;
maskPixels[i + j * pitch] |= (opacity << k);
if (i * 8 + k < width)
{
UInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0;
maskPixels[i + j * pitch] |= (opacity << k);
}
}
}
}
if (!m_maskPixmap.CreatePixmapFromBitmapData(
X11::XCBDefaultRootWindow(connection),
reinterpret_cast<uint8_t*>(&maskPixels[0]),
width,
height,
1,
0,
1,
nullptr))
{
NazaraError("Failed to create mask pixmap for icon");
return false;
}
onExit.Reset();
return true;
}
if (!m_maskPixmap.CreatePixmapFromBitmapData(
X11::XCBDefaultRootWindow(connection),
reinterpret_cast<uint8_t*>(&maskPixels[0]),
width,
height,
1,
0,
1,
nullptr))
void IconImpl::Destroy()
{
NazaraError("Failed to create mask pixmap for icon");
return false;
m_iconPixmap.Destroy();
m_maskPixmap.Destroy();
}
onExit.Reset();
xcb_pixmap_t IconImpl::GetIcon()
{
return m_iconPixmap;
}
return true;
}
void NzIconImpl::Destroy()
{
m_iconPixmap.Destroy();
m_maskPixmap.Destroy();
}
xcb_pixmap_t NzIconImpl::GetIcon()
{
return m_iconPixmap;
}
xcb_pixmap_t NzIconImpl::GetMask()
{
return m_maskPixmap;
xcb_pixmap_t IconImpl::GetMask()
{
return m_maskPixmap;
}
}

View File

@@ -7,24 +7,28 @@
#ifndef NAZARA_ICONIMPL_HPP
#define NAZARA_ICONIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/X11/ScopedXCB.hpp>
class NzImage;
class NzIconImpl
namespace Nz
{
public:
NzIconImpl();
class Image;
bool Create(const NzImage& image);
void Destroy();
class IconImpl
{
public:
IconImpl();
xcb_pixmap_t GetIcon();
xcb_pixmap_t GetMask();
bool Create(const Image& image);
void Destroy();
private:
NzXCBPixmap m_iconPixmap;
NzXCBPixmap m_maskPixmap;
};
xcb_pixmap_t GetIcon();
xcb_pixmap_t GetMask();
private:
XCBPixmap m_iconPixmap;
XCBPixmap m_maskPixmap;
};
}
#endif // NAZARA_ICONIMPL_HPP

View File

@@ -12,215 +12,186 @@
#include <xcb/xcb_keysyms.h>
#include <Nazara/Utility/Debug.hpp>
namespace
namespace Nz
{
KeySym GetKeySym(NzKeyboard::Key key)
namespace
{
// X11 keysym correspondant
KeySym keysym = 0;
switch (key)
KeySym GetKeySym(Keyboard::Key key)
{
// Lettres
case NzKeyboard::A: keysym = XK_A; break;
case NzKeyboard::B: keysym = XK_B; break;
case NzKeyboard::C: keysym = XK_C; break;
case NzKeyboard::D: keysym = XK_D; break;
case NzKeyboard::E: keysym = XK_E; break;
case NzKeyboard::F: keysym = XK_F; break;
case NzKeyboard::G: keysym = XK_G; break;
case NzKeyboard::H: keysym = XK_H; break;
case NzKeyboard::I: keysym = XK_I; break;
case NzKeyboard::J: keysym = XK_J; break;
case NzKeyboard::K: keysym = XK_K; break;
case NzKeyboard::L: keysym = XK_L; break;
case NzKeyboard::M: keysym = XK_M; break;
case NzKeyboard::N: keysym = XK_N; break;
case NzKeyboard::O: keysym = XK_O; break;
case NzKeyboard::P: keysym = XK_P; break;
case NzKeyboard::Q: keysym = XK_Q; break;
case NzKeyboard::R: keysym = XK_R; break;
case NzKeyboard::S: keysym = XK_S; break;
case NzKeyboard::T: keysym = XK_T; break;
case NzKeyboard::U: keysym = XK_U; break;
case NzKeyboard::V: keysym = XK_V; break;
case NzKeyboard::W: keysym = XK_W; break;
case NzKeyboard::X: keysym = XK_X; break;
case NzKeyboard::Y: keysym = XK_Y; break;
case NzKeyboard::Z: keysym = XK_Z; break;
// X11 keysym correspondant
KeySym keysym = 0;
switch (key)
{
// Lettres
case Keyboard::A: keysym = XK_A; break;
case Keyboard::B: keysym = XK_B; break;
case Keyboard::C: keysym = XK_C; break;
case Keyboard::D: keysym = XK_D; break;
case Keyboard::E: keysym = XK_E; break;
case Keyboard::F: keysym = XK_F; break;
case Keyboard::G: keysym = XK_G; break;
case Keyboard::H: keysym = XK_H; break;
case Keyboard::I: keysym = XK_I; break;
case Keyboard::J: keysym = XK_J; break;
case Keyboard::K: keysym = XK_K; break;
case Keyboard::L: keysym = XK_L; break;
case Keyboard::M: keysym = XK_M; break;
case Keyboard::N: keysym = XK_N; break;
case Keyboard::O: keysym = XK_O; break;
case Keyboard::P: keysym = XK_P; break;
case Keyboard::Q: keysym = XK_Q; break;
case Keyboard::R: keysym = XK_R; break;
case Keyboard::S: keysym = XK_S; break;
case Keyboard::T: keysym = XK_T; break;
case Keyboard::U: keysym = XK_U; break;
case Keyboard::V: keysym = XK_V; break;
case Keyboard::W: keysym = XK_W; break;
case Keyboard::X: keysym = XK_X; break;
case Keyboard::Y: keysym = XK_Y; break;
case Keyboard::Z: keysym = XK_Z; break;
// Touches de fonction
case NzKeyboard::F1: keysym = XK_F1; break;
case NzKeyboard::F2: keysym = XK_F2; break;
case NzKeyboard::F3: keysym = XK_F3; break;
case NzKeyboard::F4: keysym = XK_F4; break;
case NzKeyboard::F5: keysym = XK_F5; break;
case NzKeyboard::F6: keysym = XK_F6; break;
case NzKeyboard::F7: keysym = XK_F7; break;
case NzKeyboard::F8: keysym = XK_F8; break;
case NzKeyboard::F9: keysym = XK_F9; break;
case NzKeyboard::F10: keysym = XK_F10; break;
case NzKeyboard::F11: keysym = XK_F11; break;
case NzKeyboard::F12: keysym = XK_F12; break;
case NzKeyboard::F13: keysym = XK_F13; break;
case NzKeyboard::F14: keysym = XK_F14; break;
case NzKeyboard::F15: keysym = XK_F15; break;
// Touches de fonction
case Keyboard::F1: keysym = XK_F1; break;
case Keyboard::F2: keysym = XK_F2; break;
case Keyboard::F3: keysym = XK_F3; break;
case Keyboard::F4: keysym = XK_F4; break;
case Keyboard::F5: keysym = XK_F5; break;
case Keyboard::F6: keysym = XK_F6; break;
case Keyboard::F7: keysym = XK_F7; break;
case Keyboard::F8: keysym = XK_F8; break;
case Keyboard::F9: keysym = XK_F9; break;
case Keyboard::F10: keysym = XK_F10; break;
case Keyboard::F11: keysym = XK_F11; break;
case Keyboard::F12: keysym = XK_F12; break;
case Keyboard::F13: keysym = XK_F13; break;
case Keyboard::F14: keysym = XK_F14; break;
case Keyboard::F15: keysym = XK_F15; break;
// Flèches directionnelles
case NzKeyboard::Down: keysym = XK_Down; break;
case NzKeyboard::Left: keysym = XK_Left; break;
case NzKeyboard::Right: keysym = XK_Right; break;
case NzKeyboard::Up: keysym = XK_Up; break;
// Flèches directionnelles
case Keyboard::Down: keysym = XK_Down; break;
case Keyboard::Left: keysym = XK_Left; break;
case Keyboard::Right: keysym = XK_Right; break;
case Keyboard::Up: keysym = XK_Up; break;
// Pavé numérique
case NzKeyboard::Add: keysym = XK_KP_Add; break;
case NzKeyboard::Decimal: keysym = XK_KP_Decimal; break;
case NzKeyboard::Divide: keysym = XK_KP_Divide; break;
case NzKeyboard::Multiply: keysym = XK_KP_Multiply; break;
case NzKeyboard::Numpad0: keysym = XK_KP_0; break;
case NzKeyboard::Numpad1: keysym = XK_KP_1; break;
case NzKeyboard::Numpad2: keysym = XK_KP_2; break;
case NzKeyboard::Numpad3: keysym = XK_KP_3; break;
case NzKeyboard::Numpad4: keysym = XK_KP_4; break;
case NzKeyboard::Numpad5: keysym = XK_KP_5; break;
case NzKeyboard::Numpad6: keysym = XK_KP_6; break;
case NzKeyboard::Numpad7: keysym = XK_KP_7; break;
case NzKeyboard::Numpad8: keysym = XK_KP_8; break;
case NzKeyboard::Numpad9: keysym = XK_KP_9; break;
case NzKeyboard::Subtract: keysym = XK_KP_Subtract; break;
// Pavé numérique
case Keyboard::Add: keysym = XK_KP_Add; break;
case Keyboard::Decimal: keysym = XK_KP_Decimal; break;
case Keyboard::Divide: keysym = XK_KP_Divide; break;
case Keyboard::Multiply: keysym = XK_KP_Multiply; break;
case Keyboard::Numpad0: keysym = XK_KP_0; break;
case Keyboard::Numpad1: keysym = XK_KP_1; break;
case Keyboard::Numpad2: keysym = XK_KP_2; break;
case Keyboard::Numpad3: keysym = XK_KP_3; break;
case Keyboard::Numpad4: keysym = XK_KP_4; break;
case Keyboard::Numpad5: keysym = XK_KP_5; break;
case Keyboard::Numpad6: keysym = XK_KP_6; break;
case Keyboard::Numpad7: keysym = XK_KP_7; break;
case Keyboard::Numpad8: keysym = XK_KP_8; break;
case Keyboard::Numpad9: keysym = XK_KP_9; break;
case Keyboard::Subtract: keysym = XK_KP_Subtract; break;
// Divers
case NzKeyboard::Backslash: keysym = XK_backslash; break;
case NzKeyboard::Backspace: keysym = XK_BackSpace; break;
case NzKeyboard::Clear: keysym = XK_Clear; break;
case NzKeyboard::Comma: keysym = XK_comma; break;
case NzKeyboard::Dash: keysym = XK_minus; break;
case NzKeyboard::Delete: keysym = XK_Delete; break;
case NzKeyboard::End: keysym = XK_End; break;
case NzKeyboard::Equal: keysym = XK_equal; break;
case NzKeyboard::Escape: keysym = XK_Escape; break;
case NzKeyboard::Home: keysym = XK_Home; break;
case NzKeyboard::Insert: keysym = XK_Insert; break;
case NzKeyboard::LAlt: keysym = XK_Alt_L; break;
case NzKeyboard::LBracket: keysym = XK_bracketleft; break;
case NzKeyboard::LControl: keysym = XK_Control_L; break;
case NzKeyboard::LShift: keysym = XK_Shift_L; break;
case NzKeyboard::LSystem: keysym = XK_Super_L; break;
case NzKeyboard::Num0: keysym = XK_0; break;
case NzKeyboard::Num1: keysym = XK_1; break;
case NzKeyboard::Num2: keysym = XK_2; break;
case NzKeyboard::Num3: keysym = XK_3; break;
case NzKeyboard::Num4: keysym = XK_4; break;
case NzKeyboard::Num5: keysym = XK_5; break;
case NzKeyboard::Num6: keysym = XK_6; break;
case NzKeyboard::Num7: keysym = XK_7; break;
case NzKeyboard::Num8: keysym = XK_8; break;
case NzKeyboard::Num9: keysym = XK_9; break;
case NzKeyboard::PageDown: keysym = XK_Page_Down; break;
case NzKeyboard::PageUp: keysym = XK_Page_Up; break;
case NzKeyboard::Pause: keysym = XK_Pause; break;
case NzKeyboard::Period: keysym = XK_period; break;
case NzKeyboard::Print: keysym = XK_Print; break;
case NzKeyboard::PrintScreen: keysym = XK_Sys_Req; break;
case NzKeyboard::Quote: keysym = XK_quotedbl; break;
case NzKeyboard::RAlt: keysym = XK_Alt_R; break;
case NzKeyboard::RBracket: keysym = XK_bracketright; break;
case NzKeyboard::RControl: keysym = XK_Control_R; break;
case NzKeyboard::Return: keysym = XK_Return; break;
case NzKeyboard::RShift: keysym = XK_Shift_R; break;
case NzKeyboard::RSystem: keysym = XK_Super_R; break;
case NzKeyboard::Semicolon: keysym = XK_semicolon; break;
case NzKeyboard::Slash: keysym = XK_slash; break;
case NzKeyboard::Space: keysym = XK_space; break;
case NzKeyboard::Tab: keysym = XK_Tab; break;
case NzKeyboard::Tilde: keysym = XK_grave; break;
// Divers
case Keyboard::Backslash: keysym = XK_backslash; break;
case Keyboard::Backspace: keysym = XK_BackSpace; break;
case Keyboard::Clear: keysym = XK_Clear; break;
case Keyboard::Comma: keysym = XK_comma; break;
case Keyboard::Dash: keysym = XK_minus; break;
case Keyboard::Delete: keysym = XK_Delete; break;
case Keyboard::End: keysym = XK_End; break;
case Keyboard::Equal: keysym = XK_equal; break;
case Keyboard::Escape: keysym = XK_Escape; break;
case Keyboard::Home: keysym = XK_Home; break;
case Keyboard::Insert: keysym = XK_Insert; break;
case Keyboard::LAlt: keysym = XK_Alt_L; break;
case Keyboard::LBracket: keysym = XK_bracketleft; break;
case Keyboard::LControl: keysym = XK_Control_L; break;
case Keyboard::LShift: keysym = XK_Shift_L; break;
case Keyboard::LSystem: keysym = XK_Super_L; break;
case Keyboard::Num0: keysym = XK_0; break;
case Keyboard::Num1: keysym = XK_1; break;
case Keyboard::Num2: keysym = XK_2; break;
case Keyboard::Num3: keysym = XK_3; break;
case Keyboard::Num4: keysym = XK_4; break;
case Keyboard::Num5: keysym = XK_5; break;
case Keyboard::Num6: keysym = XK_6; break;
case Keyboard::Num7: keysym = XK_7; break;
case Keyboard::Num8: keysym = XK_8; break;
case Keyboard::Num9: keysym = XK_9; break;
case Keyboard::PageDown: keysym = XK_Page_Down; break;
case Keyboard::PageUp: keysym = XK_Page_Up; break;
case Keyboard::Pause: keysym = XK_Pause; break;
case Keyboard::Period: keysym = XK_period; break;
case Keyboard::Print: keysym = XK_Print; break;
case Keyboard::PrintScreen: keysym = XK_Sys_Req; break;
case Keyboard::Quote: keysym = XK_quotedbl; break;
case Keyboard::RAlt: keysym = XK_Alt_R; break;
case Keyboard::RBracket: keysym = XK_bracketright; break;
case Keyboard::RControl: keysym = XK_Control_R; break;
case Keyboard::Return: keysym = XK_Return; break;
case Keyboard::RShift: keysym = XK_Shift_R; break;
case Keyboard::RSystem: keysym = XK_Super_R; break;
case Keyboard::Semicolon: keysym = XK_semicolon; break;
case Keyboard::Slash: keysym = XK_slash; break;
case Keyboard::Space: keysym = XK_space; break;
case Keyboard::Tab: keysym = XK_Tab; break;
case Keyboard::Tilde: keysym = XK_grave; break;
// Touches navigateur
case NzKeyboard::Browser_Back: keysym = XF86XK_Back; break;
case NzKeyboard::Browser_Favorites: keysym = XF86XK_Favorites; break;
case NzKeyboard::Browser_Forward: keysym = XF86XK_Forward; break;
case NzKeyboard::Browser_Home: keysym = XF86XK_HomePage; break;
case NzKeyboard::Browser_Refresh: keysym = XF86XK_Refresh; break;
case NzKeyboard::Browser_Search: keysym = XF86XK_Search; break;
case NzKeyboard::Browser_Stop: keysym = XF86XK_Stop; break;
// Touches navigateur
case Keyboard::Browser_Back: keysym = XF86XK_Back; break;
case Keyboard::Browser_Favorites: keysym = XF86XK_Favorites; break;
case Keyboard::Browser_Forward: keysym = XF86XK_Forward; break;
case Keyboard::Browser_Home: keysym = XF86XK_HomePage; break;
case Keyboard::Browser_Refresh: keysym = XF86XK_Refresh; break;
case Keyboard::Browser_Search: keysym = XF86XK_Search; break;
case Keyboard::Browser_Stop: keysym = XF86XK_Stop; break;
// Touches de contrôle
case NzKeyboard::Media_Next: keysym = XF86XK_AudioNext; break;
case NzKeyboard::Media_Play: keysym = XF86XK_AudioPlay; break;
case NzKeyboard::Media_Previous: keysym = XF86XK_AudioPrev; break;
case NzKeyboard::Media_Stop: keysym = XF86XK_AudioStop; break;
// Touches de contrôle
case Keyboard::Media_Next: keysym = XF86XK_AudioNext; break;
case Keyboard::Media_Play: keysym = XF86XK_AudioPlay; break;
case Keyboard::Media_Previous: keysym = XF86XK_AudioPrev; break;
case Keyboard::Media_Stop: keysym = XF86XK_AudioStop; break;
// Touches de contrôle du volume
case NzKeyboard::Volume_Down: keysym = XF86XK_AudioLowerVolume; break;
case NzKeyboard::Volume_Mute: keysym = XF86XK_AudioMute; break;
case NzKeyboard::Volume_Up: keysym = XF86XK_AudioRaiseVolume; break;
// Touches de contrôle du volume
case Keyboard::Volume_Down: keysym = XF86XK_AudioLowerVolume; break;
case Keyboard::Volume_Mute: keysym = XF86XK_AudioMute; break;
case Keyboard::Volume_Up: keysym = XF86XK_AudioRaiseVolume; break;
// Touches à verrouillage
case NzKeyboard::CapsLock: keysym = XK_Caps_Lock; break;
case NzKeyboard::NumLock: keysym = XK_Num_Lock; break;
case NzKeyboard::ScrollLock: keysym = XK_Scroll_Lock; break;
// Touches à verrouillage
case Keyboard::CapsLock: keysym = XK_Caps_Lock; break;
case Keyboard::NumLock: keysym = XK_Num_Lock; break;
case Keyboard::ScrollLock: keysym = XK_Scroll_Lock; break;
default: break;
default: break;
}
// Sanity checks
if (key < 0 || key >= Keyboard::Count || keysym == 0)
NazaraWarning("Key " + String::Number(key) + " is not handled in Keyboard");
return keysym;
}
// Sanity checks
if (key < 0 || key >= NzKeyboard::Count || keysym == 0)
NazaraWarning("Key " + NzString::Number(key) + " is not handled in NzKeyboard");
return keysym;
}
}
NzString NzEventImpl::GetKeyName(NzKeyboard::Key key)
{
KeySym keySym = GetKeySym(key);
// XKeysymToString returns a static area.
return XKeysymToString(keySym);
}
NzVector2i NzEventImpl::GetMousePosition()
{
NzScopedXCBConnection connection;
NzScopedXCB<xcb_generic_error_t> error(nullptr);
NzScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply(
connection,
xcb_query_pointer(
connection,
X11::XCBDefaultRootWindow(connection)
),
&error
)
);
if (error)
{
NazaraError("Failed to query pointer");
return NzVector2i(-1, -1);
}
return NzVector2i(pointer->root_x, pointer->root_y);
}
NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo)
{
NzWindowHandle handle = relativeTo.GetHandle();
if (handle)
String EventImpl::GetKeyName(Keyboard::Key key)
{
// Open a connection with the X server
NzScopedXCBConnection connection;
KeySym keySym = GetKeySym(key);
NzScopedXCB<xcb_generic_error_t> error(nullptr);
// XKeysymToString returns a static area.
return XKeysymToString(keySym);
}
NzScopedXCB<xcb_query_pointer_reply_t> pointer(
Vector2i EventImpl::GetMousePosition()
{
ScopedXCBConnection connection;
ScopedXCB<xcb_generic_error_t> error(nullptr);
ScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply(
connection,
xcb_query_pointer(
connection,
handle
X11::XCBDefaultRootWindow(connection)
),
&error
)
@@ -229,143 +200,174 @@ NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo)
if (error)
{
NazaraError("Failed to query pointer");
return NzVector2i(-1, -1);
return Vector2i(-1, -1);
}
return NzVector2i(pointer->win_x, pointer->win_y);
return Vector2i(pointer->root_x, pointer->root_y);
}
else
Vector2i EventImpl::GetMousePosition(const Window& relativeTo)
{
NazaraError("No window handle");
return NzVector2i(-1, -1);
WindowHandle handle = relativeTo.GetHandle();
if (handle)
{
// Open a connection with the X server
ScopedXCBConnection connection;
ScopedXCB<xcb_generic_error_t> error(nullptr);
ScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply(
connection,
xcb_query_pointer(
connection,
handle
),
&error
)
);
if (error)
{
NazaraError("Failed to query pointer");
return Vector2i(-1, -1);
}
return Vector2i(pointer->win_x, pointer->win_y);
}
else
{
NazaraError("No window handle");
return Vector2i(-1, -1);
}
}
}
bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key)
{
NzScopedXCBConnection connection;
xcb_keysym_t keySym = GetKeySym(key);
xcb_key_symbols_t* keySymbols = X11::XCBKeySymbolsAlloc(connection);
if (!keySymbols)
bool EventImpl::IsKeyPressed(Keyboard::Key key)
{
NazaraError("Failed to alloc key symbols");
return false;
}
ScopedXCBConnection connection;
NzScopedXCB<xcb_keycode_t> keyCode = xcb_key_symbols_get_keycode(keySymbols, keySym);
if (!keyCode)
{
NazaraError("Failed to get key code");
return false;
}
X11::XCBKeySymbolsFree(keySymbols);
xcb_keysym_t keySym = GetKeySym(key);
NzScopedXCB<xcb_generic_error_t> error(nullptr);
xcb_key_symbols_t* keySymbols = X11::XCBKeySymbolsAlloc(connection);
if (!keySymbols)
{
NazaraError("Failed to alloc key symbols");
return false;
}
// Get the whole keyboard state
NzScopedXCB<xcb_query_keymap_reply_t> keymap(
xcb_query_keymap_reply(
connection,
xcb_query_keymap(connection),
&error
)
);
ScopedXCB<xcb_keycode_t> keyCode = xcb_key_symbols_get_keycode(keySymbols, keySym);
if (!keyCode)
{
NazaraError("Failed to get key code");
return false;
}
X11::XCBKeySymbolsFree(keySymbols);
if (error)
{
NazaraError("Failed to query keymap");
return false;
}
ScopedXCB<xcb_generic_error_t> error(nullptr);
// Check our keycode
return (keymap->keys[*keyCode.get() / 8] & (1 << (*keyCode.get() % 8))) != 0;
}
bool NzEventImpl::IsMouseButtonPressed(NzMouse::Button button)
{
NzScopedXCBConnection connection;
NzScopedXCB<xcb_generic_error_t> error(nullptr);
// Get pointer mask
NzScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply(
connection,
xcb_query_pointer(
// Get the whole keyboard state
ScopedXCB<xcb_query_keymap_reply_t> keymap(
xcb_query_keymap_reply(
connection,
X11::XCBDefaultRootWindow(connection)
),
&error
)
);
xcb_query_keymap(connection),
&error
)
);
if (error)
if (error)
{
NazaraError("Failed to query keymap");
return false;
}
// Check our keycode
return (keymap->keys[*keyCode.get() / 8] & (1 << (*keyCode.get() % 8))) != 0;
}
bool EventImpl::IsMouseButtonPressed(Mouse::Button button)
{
NazaraError("Failed to query pointer");
ScopedXCBConnection connection;
ScopedXCB<xcb_generic_error_t> error(nullptr);
// Get pointer mask
ScopedXCB<xcb_query_pointer_reply_t> pointer(
xcb_query_pointer_reply(
connection,
xcb_query_pointer(
connection,
X11::XCBDefaultRootWindow(connection)
),
&error
)
);
if (error)
{
NazaraError("Failed to query pointer");
return false;
}
uint16_t buttons = pointer->mask;
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::XButton1: return false; // not supported by X
case Mouse::XButton2: return false; // not supported by X
}
NazaraError("Mouse button not supported.");
return false;
}
uint16_t buttons = pointer->mask;
switch (button)
void EventImpl::SetMousePosition(int x, int y)
{
case NzMouse::Left: return buttons & XCB_BUTTON_MASK_1;
case NzMouse::Right: return buttons & XCB_BUTTON_MASK_3;
case NzMouse::Middle: return buttons & XCB_BUTTON_MASK_2;
case NzMouse::XButton1: return false; // not supported by X
case NzMouse::XButton2: return false; // not supported by X
}
ScopedXCBConnection connection;
NazaraError("Mouse button not supported.");
return false;
}
xcb_window_t root = X11::XCBDefaultRootWindow(connection);
void NzEventImpl::SetMousePosition(int x, int y)
{
NzScopedXCBConnection connection;
xcb_window_t root = X11::XCBDefaultRootWindow(connection);
if (!X11::CheckCookie(
connection,
xcb_warp_pointer(
connection,
None, // Source window
root, // Destination window
0, 0, // Source position
0, 0, // Source size
x, y // Destination position
))
)
NazaraError("Failed to set mouse position");
xcb_flush(connection);
}
void NzEventImpl::SetMousePosition(int x, int y, const NzWindow& relativeTo)
{
NzScopedXCBConnection connection;
NzWindowHandle handle = relativeTo.GetHandle();
if (handle)
{
if (!X11::CheckCookie(
connection,
xcb_warp_pointer(
connection,
None, // Source window
handle, // Destination window
0, 0, // Source position
0, 0, // Source size
x, y // Destination position
None, // Source window
root, // Destination window
0, 0, // Source position
0, 0, // Source size
x, y // Destination position
))
)
NazaraError("Failed to set mouse position relative to window");
NazaraError("Failed to set mouse position");
xcb_flush(connection);
}
else
NazaraError("No window handle");
void EventImpl::SetMousePosition(int x, int y, const Window& relativeTo)
{
ScopedXCBConnection connection;
WindowHandle handle = relativeTo.GetHandle();
if (handle)
{
if (!X11::CheckCookie(
connection,
xcb_warp_pointer(
connection,
None, // Source window
handle, // Destination window
0, 0, // Source position
0, 0, // Source size
x, y // Destination position
))
)
NazaraError("Failed to set mouse position relative to window");
xcb_flush(connection);
}
else
NazaraError("No window handle");
}
}

View File

@@ -7,21 +7,25 @@
#ifndef NAZARA_INPUTIMPL_HPP
#define NAZARA_INPUTIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/Mouse.hpp>
class NzEventImpl
namespace Nz
{
public:
static NzString GetKeyName(NzKeyboard::Key key);
static NzVector2i GetMousePosition();
static NzVector2i GetMousePosition(const NzWindow& relativeTo);
static bool IsKeyPressed(NzKeyboard::Key key);
static bool IsMouseButtonPressed(NzMouse::Button button);
static void SetMousePosition(int x, int y);
static void SetMousePosition(int x, int y, const NzWindow& relativeTo);
};
class EventImpl
{
public:
static String GetKeyName(Keyboard::Key key);
static Vector2i GetMousePosition();
static Vector2i GetMousePosition(const Window& relativeTo);
static bool IsKeyPressed(Keyboard::Key key);
static bool IsMouseButtonPressed(Mouse::Button button);
static void SetMousePosition(int x, int y);
static void SetMousePosition(int x, int y, const Window& relativeTo);
};
}
#endif // NAZARA_INPUTIMPL_HPP

View File

@@ -8,189 +8,192 @@
#include <xcb/xcb_image.h>
#include <Nazara/Utility/Debug.hpp>
/***********************************************
NzScopedXCBConnection
***********************************************/
NzScopedXCBConnection::NzScopedXCBConnection() :
m_connection(nullptr)
namespace Nz
{
m_connection = X11::OpenConnection();
}
/***********************************************
ScopedXCBConnection
***********************************************/
NzScopedXCBConnection::~NzScopedXCBConnection()
{
X11::CloseConnection(m_connection);
}
ScopedXCBConnection::ScopedXCBConnection() :
m_connection(nullptr)
{
m_connection = X11::OpenConnection();
}
NzScopedXCBConnection::operator xcb_connection_t*() const
{
return m_connection;
}
ScopedXCBConnection::~ScopedXCBConnection()
{
X11::CloseConnection(m_connection);
}
/***********************************************
NzScopedXCBEWMHConnection
***********************************************/
ScopedXCBConnection::operator xcb_connection_t*() const
{
return m_connection;
}
NzScopedXCBEWMHConnection::NzScopedXCBEWMHConnection(xcb_connection_t* connection) :
m_ewmhConnection(nullptr)
{
m_ewmhConnection = X11::OpenEWMHConnection(connection);
}
/***********************************************
ScopedXCBEWMHConnection
***********************************************/
NzScopedXCBEWMHConnection::~NzScopedXCBEWMHConnection()
{
X11::CloseEWMHConnection(m_ewmhConnection);
}
ScopedXCBEWMHConnection::ScopedXCBEWMHConnection(xcb_connection_t* connection) :
m_ewmhConnection(nullptr)
{
m_ewmhConnection = X11::OpenEWMHConnection(connection);
}
xcb_ewmh_connection_t* NzScopedXCBEWMHConnection::operator ->() const
{
return m_ewmhConnection;
}
ScopedXCBEWMHConnection::~ScopedXCBEWMHConnection()
{
X11::CloseEWMHConnection(m_ewmhConnection);
}
NzScopedXCBEWMHConnection::operator xcb_ewmh_connection_t*() const
{
return m_ewmhConnection;
}
xcb_ewmh_connection_t* ScopedXCBEWMHConnection::operator ->() const
{
return m_ewmhConnection;
}
/***********************************************
NzXCBGContext
***********************************************/
ScopedXCBEWMHConnection::operator xcb_ewmh_connection_t*() const
{
return m_ewmhConnection;
}
NzXCBGContext::NzXCBGContext(xcb_connection_t* connection) :
m_connection(connection),
m_gcontext(XCB_NONE)
{
NazaraAssert(connection, "Connection must have been established");
}
/***********************************************
XCBGContext
***********************************************/
NzXCBGContext::~NzXCBGContext()
{
Destroy();
}
XCBGContext::XCBGContext(xcb_connection_t* connection) :
m_connection(connection),
m_gcontext(XCB_NONE)
{
NazaraAssert(connection, "Connection must have been established");
}
bool NzXCBGContext::Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list)
{
NazaraAssert(m_gcontext == XCB_NONE, "Context must have been destroyed before or just created");
XCBGContext::~XCBGContext()
{
Destroy();
}
m_gcontext = xcb_generate_id(m_connection);
bool XCBGContext::Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list)
{
NazaraAssert(m_gcontext == XCB_NONE, "Context must have been destroyed before or just created");
return X11::CheckCookie(
m_connection,
xcb_create_gc(
m_gcontext = xcb_generate_id(m_connection);
return X11::CheckCookie(
m_connection,
xcb_create_gc(
m_connection,
m_gcontext,
drawable,
value_mask,
value_list
));
}
void XCBGContext::Destroy()
{
if (m_gcontext == XCB_NONE)
return;
if (!X11::CheckCookie(
m_connection,
xcb_free_gc(
m_connection,
m_gcontext
))
)
NazaraError("Failed to free gcontext");
m_gcontext = XCB_NONE;
}
XCBGContext::operator xcb_gcontext_t() const
{
return m_gcontext;
}
/***********************************************
XCBPixmap
***********************************************/
XCBPixmap::XCBPixmap() :
m_connection(nullptr),
m_pixmap(XCB_NONE)
{
}
XCBPixmap::XCBPixmap(xcb_connection_t* connection) :
m_connection(connection),
m_pixmap(XCB_NONE)
{
}
XCBPixmap::~XCBPixmap()
{
Destroy();
}
void XCBPixmap::Connect(xcb_connection_t* connection)
{
NazaraAssert(connection && !m_connection, "Connection must be established");
m_connection = connection;
}
bool XCBPixmap::Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height)
{
NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created");
m_pixmap = xcb_generate_id(m_connection);
return X11::CheckCookie(
m_connection,
xcb_create_pixmap(
m_connection,
depth,
m_pixmap,
drawable,
width,
height
));
}
bool XCBPixmap::CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* data, uint32_t width, uint32_t height, uint32_t depth, uint32_t fg, uint32_t bg, xcb_gcontext_t* gcp)
{
NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created");
m_pixmap = xcb_create_pixmap_from_bitmap_data(
m_connection,
m_gcontext,
drawable,
value_mask,
value_list
));
}
void NzXCBGContext::Destroy()
{
if (m_gcontext == XCB_NONE)
return;
if (!X11::CheckCookie(
m_connection,
xcb_free_gc(
m_connection,
m_gcontext
))
)
NazaraError("Failed to free gcontext");
m_gcontext = XCB_NONE;
}
NzXCBGContext::operator xcb_gcontext_t() const
{
return m_gcontext;
}
/***********************************************
NzXCBPixmap
***********************************************/
NzXCBPixmap::NzXCBPixmap() :
m_connection(nullptr),
m_pixmap(XCB_NONE)
{
}
NzXCBPixmap::NzXCBPixmap(xcb_connection_t* connection) :
m_connection(connection),
m_pixmap(XCB_NONE)
{
}
NzXCBPixmap::~NzXCBPixmap()
{
Destroy();
}
void NzXCBPixmap::Connect(xcb_connection_t* connection)
{
NazaraAssert(connection && !m_connection, "Connection must be established");
m_connection = connection;
}
bool NzXCBPixmap::Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height)
{
NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created");
m_pixmap = xcb_generate_id(m_connection);
return X11::CheckCookie(
m_connection,
xcb_create_pixmap(
m_connection,
depth,
m_pixmap,
drawable,
data,
width,
height
));
}
height,
depth,
fg,
bg,
gcp
);
bool NzXCBPixmap::CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* data, uint32_t width, uint32_t height, uint32_t depth, uint32_t fg, uint32_t bg, xcb_gcontext_t* gcp)
{
NazaraAssert(m_pixmap == XCB_NONE, "Pixmap must have been destroyed before or just created");
return m_pixmap != XCB_NONE;
}
m_pixmap = xcb_create_pixmap_from_bitmap_data(
m_connection,
drawable,
data,
width,
height,
depth,
fg,
bg,
gcp
);
void XCBPixmap::Destroy()
{
if (m_pixmap == XCB_NONE)
return;
return m_pixmap != XCB_NONE;
}
void NzXCBPixmap::Destroy()
{
if (m_pixmap == XCB_NONE)
return;
if (!X11::CheckCookie(
m_connection,
xcb_free_pixmap(
if (!X11::CheckCookie(
m_connection,
m_pixmap
))
)
NazaraError("Failed to free pixmap");
xcb_free_pixmap(
m_connection,
m_pixmap
))
)
NazaraError("Failed to free pixmap");
m_pixmap = XCB_NONE;
}
m_pixmap = XCB_NONE;
}
NzXCBPixmap::operator xcb_pixmap_t() const
{
return m_pixmap;
XCBPixmap::operator xcb_pixmap_t() const
{
return m_pixmap;
}
}

View File

@@ -7,88 +7,93 @@
#ifndef NAZARA_SCOPEDXCB_HPP
#define NAZARA_SCOPEDXCB_HPP
#include <Nazara/Prerequesites.hpp>
#include <xcb/xcb.h>
#include <xcb/xcb_ewmh.h>
class NzScopedXCBConnection
namespace Nz
{
public:
NzScopedXCBConnection();
~NzScopedXCBConnection();
class ScopedXCBConnection
{
public:
ScopedXCBConnection();
~ScopedXCBConnection();
operator xcb_connection_t*() const;
operator xcb_connection_t*() const;
private:
xcb_connection_t* m_connection;
};
private:
xcb_connection_t* m_connection;
};
class NzScopedXCBEWMHConnection
{
public:
NzScopedXCBEWMHConnection(xcb_connection_t* connection);
~NzScopedXCBEWMHConnection();
class ScopedXCBEWMHConnection
{
public:
ScopedXCBEWMHConnection(xcb_connection_t* connection);
~ScopedXCBEWMHConnection();
xcb_ewmh_connection_t* operator ->() const;
xcb_ewmh_connection_t* operator ->() const;
operator xcb_ewmh_connection_t*() const;
operator xcb_ewmh_connection_t*() const;
private:
xcb_ewmh_connection_t* m_ewmhConnection;
};
private:
xcb_ewmh_connection_t* m_ewmhConnection;
};
template <typename T>
class NzScopedXCB
{
public:
NzScopedXCB(T* pointer);
~NzScopedXCB();
template <typename T>
class ScopedXCB
{
public:
ScopedXCB(T* pointer);
~ScopedXCB();
T* operator ->() const;
T** operator &();
T* operator ->() const;
T** operator &();
operator bool() const;
operator bool() const;
T* get() const;
T* get() const;
private:
T* m_pointer;
};
private:
T* m_pointer;
};
class NzXCBGContext
{
public:
NzXCBGContext(xcb_connection_t* connection);
~NzXCBGContext();
class XCBGContext
{
public:
XCBGContext(xcb_connection_t* connection);
~XCBGContext();
bool Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list);
bool Create(xcb_drawable_t drawable, uint32_t value_mask, const uint32_t* value_list);
void Destroy();
void Destroy();
operator xcb_gcontext_t() const;
operator xcb_gcontext_t() const;
private:
xcb_connection_t* m_connection;
xcb_gcontext_t m_gcontext;
};
private:
xcb_connection_t* m_connection;
xcb_gcontext_t m_gcontext;
};
class NzXCBPixmap
{
public:
NzXCBPixmap();
NzXCBPixmap(xcb_connection_t* connection);
~NzXCBPixmap();
class XCBPixmap
{
public:
XCBPixmap();
XCBPixmap(xcb_connection_t* connection);
~XCBPixmap();
void Connect(xcb_connection_t* connection);
bool Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height);
bool CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* data, uint32_t width, uint32_t height, uint32_t depth, uint32_t fg, uint32_t bg, xcb_gcontext_t* gcp);
void Connect(xcb_connection_t* connection);
bool Create(uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height);
bool CreatePixmapFromBitmapData(xcb_drawable_t drawable, uint8_t* data, uint32_t width, uint32_t height, uint32_t depth, uint32_t fg, uint32_t bg, xcb_gcontext_t* gcp);
void Destroy();
void Destroy();
operator xcb_pixmap_t() const;
operator xcb_pixmap_t() const;
private:
xcb_connection_t* m_connection;
xcb_pixmap_t m_pixmap;
};
private:
xcb_connection_t* m_connection;
xcb_pixmap_t m_pixmap;
};
}
#include <Nazara/Utility/X11/ScopedXCB.inl>

View File

@@ -10,156 +10,159 @@
#include <algorithm>
#include <Nazara/Utility/Debug.hpp>
NzVideoMode NzVideoModeImpl::GetDesktopMode()
namespace Nz
{
NzVideoMode desktopMode;
NzScopedXCBConnection connection;
// Retrieve the default screen
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
NzScopedXCB<xcb_generic_error_t> error(nullptr);
// 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)
VideoMode VideoModeImpl::GetDesktopMode()
{
// Randr extension is not supported: we cannot get the video modes
NazaraError("Failed to use the RandR extension while trying to get the desktop video mode");
return desktopMode;
}
VideoMode desktopMode;
// Load RandR and check its version
NzScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection,
xcb_randr_query_version(
connection,
1,
1
),
&error
));
ScopedXCBConnection connection;
if (error)
{
NazaraError("Failed to load the RandR extension while trying to get the desktop video mode");
return desktopMode;
}
// Retrieve the default screen
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
// Get the current configuration
NzScopedXCB<xcb_randr_get_screen_info_reply_t> config(xcb_randr_get_screen_info_reply(
connection,
xcb_randr_get_screen_info(
connection,
screen->root
),
&error
));
ScopedXCB<xcb_generic_error_t> error(nullptr);
if (error)
{
// Failed to get the screen configuration
NazaraError("Failed to retrieve the screen configuration while trying to get the desktop video mode");
return desktopMode;
}
// Check if the RandR extension is present
const xcb_query_extension_reply_t* randrExt = xcb_get_extension_data(connection, &xcb_randr_id);
// 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 = NzVideoMode(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);
}
else
{
NazaraError("Failed to retrieve any screen sizes while trying to get the desktop video mode");
}
return desktopMode;
}
void NzVideoModeImpl::GetFullscreenModes(std::vector<NzVideoMode>& modes)
{
NzScopedXCBConnection connection;
// Retrieve the default screen
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
NzScopedXCB<xcb_generic_error_t> error(nullptr);
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
NazaraError("Failed to use the RandR extension while trying to get the supported video modes");
return;
}
// Load RandR and check its version
NzScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection,
xcb_randr_query_version(
connection,
1,
1
),
&error
));
if (error)
{
NazaraError("Failed to load the RandR extension while trying to get the supported video modes");
return;
}
// Get the current configuration
NzScopedXCB<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
NazaraError("Failed to retrieve the screen configuration while trying to get the supported video modes");
return;
}
// 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))
if (!randrExt || !randrExt->present)
{
for (int j = 0; j < config->nSizes; ++j)
// Randr extension is not supported: we cannot get the video modes
NazaraError("Failed to use the RandR extension while trying to get the desktop video mode");
return desktopMode;
}
// Load RandR and check its version
ScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection,
xcb_randr_query_version(
connection,
1,
1
),
&error
));
if (error)
{
NazaraError("Failed to load the RandR extension while trying to get the desktop video mode");
return desktopMode;
}
// Get the current configuration
ScopedXCB<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
NazaraError("Failed to retrieve the screen configuration while trying to get the desktop video mode");
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);
}
else
{
NazaraError("Failed to retrieve any screen sizes while trying to get the desktop video mode");
}
return desktopMode;
}
void VideoModeImpl::GetFullscreenModes(std::vector<VideoMode>& modes)
{
ScopedXCBConnection connection;
// Retrieve the default screen
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
ScopedXCB<xcb_generic_error_t> error(nullptr);
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
NazaraError("Failed to use the RandR extension while trying to get the supported video modes");
return;
}
// Load RandR and check its version
ScopedXCB<xcb_randr_query_version_reply_t> randrVersion(xcb_randr_query_version_reply(
connection,
xcb_randr_query_version(
connection,
1,
1
),
&error
));
if (error)
{
NazaraError("Failed to load the RandR extension while trying to get the supported video modes");
return;
}
// Get the current configuration
ScopedXCB<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
NazaraError("Failed to retrieve the screen configuration while trying to get the supported video modes");
return;
}
// 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))
{
// Convert to VideoMode
NzVideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth);
for (int j = 0; j < config->nSizes; ++j)
{
// Convert to VideoMode
VideoMode mode(sizes[j].width, sizes[j].height, iter.data->depth);
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 ||
config->rotation == XCB_RANDR_ROTATION_ROTATE_270)
std::swap(mode.width, mode.height);
if (config->rotation == XCB_RANDR_ROTATION_ROTATE_90 ||
config->rotation == XCB_RANDR_ROTATION_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);
// 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);
}
}
}
}

View File

@@ -7,13 +7,17 @@
#ifndef NAZARA_VIDEOMODEIMPL_HPP
#define NAZARA_VIDEOMODEIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/VideoMode.hpp>
class NzVideoModeImpl
namespace Nz
{
public:
static NzVideoMode GetDesktopMode();
static void GetFullscreenModes(std::vector<NzVideoMode>& modes);
};
class VideoModeImpl
{
public:
static VideoMode GetDesktopMode();
static void GetFullscreenModes(std::vector<VideoMode>& modes);
};
}
#endif // NNAZARA_VIDEOMODEIMPL_HPP

File diff suppressed because it is too large Load Diff

View File

@@ -9,118 +9,127 @@
#ifndef NAZARA_WINDOWIMPL_HPP
#define NAZARA_WINDOWIMPL_HPP
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/X11/Display.hpp>
#include <xcb/randr.h>
#include <xcb/xcb_icccm.h>
#include <Nazara/Utility/X11/Display.hpp>
#if NAZARA_UTILITY_THREADED_WINDOW
class NzConditionVariable;
class NzMutex;
#endif
class NzCursor;
class NzIcon;
class NzVideoMode;
class NzWindow;
class NzWindowImpl : NzNonCopyable
namespace Nz
{
public:
NzWindowImpl(NzWindow* parent);
~NzWindowImpl();
#if NAZARA_UTILITY_THREADED_WINDOW
class ConditionVariable;
class Mutex;
#endif
class Cursor;
class Icon;
class VideoMode;
class Window;
bool Create(const NzVideoMode& mode, const NzString& title, nzUInt32 style);
bool Create(NzWindowHandle handle);
class WindowImpl
{
public:
WindowImpl(Window* parent);
WindowImpl(const WindowImpl&) = delete;
WindowImpl(WindowImpl&&) = delete; ///TODO?
~WindowImpl();
void Destroy();
bool Create(const VideoMode& mode, const String& title, UInt32 style);
bool Create(WindowHandle handle);
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
void Destroy();
NzWindowHandle GetHandle() const;
unsigned int GetHeight() const;
NzVector2i GetPosition() const;
NzVector2ui GetSize() const;
nzUInt32 GetStyle() const;
NzString GetTitle() const;
unsigned int GetWidth() const;
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
bool HasFocus() const;
WindowHandle GetHandle() const;
unsigned int GetHeight() const;
Vector2i GetPosition() const;
Vector2ui GetSize() const;
UInt32 GetStyle() const;
String GetTitle() const;
unsigned int GetWidth() const;
void IgnoreNextMouseEvent(int mouseX, int mouseY);
bool HasFocus() const;
bool IsMinimized() const;
bool IsVisible() const;
void IgnoreNextMouseEvent(int mouseX, int mouseY);
void ProcessEvents(bool block);
bool IsMinimized() const;
bool IsVisible() const;
void SetCursor(nzWindowCursor cursor);
void SetCursor(const NzCursor& cursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(const NzIcon& icon);
void SetMaximumSize(int width, int height);
void SetMinimumSize(int width, int height);
void SetPosition(int x, int y);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const NzString& title);
void SetVisible(bool visible);
void ProcessEvents(bool block);
static bool Initialize();
static void Uninitialize();
void SetCursor(WindowCursor cursor);
void SetCursor(const Cursor& cursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(const Icon& icon);
void SetMaximumSize(int width, int height);
void SetMinimumSize(int width, int height);
void SetPosition(int x, int y);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const String& title);
void SetVisible(bool visible);
private:
WindowImpl& operator=(const WindowImpl&) = delete;
WindowImpl& operator=(WindowImpl&&) = delete; ///TODO?
void CleanUp();
xcb_keysym_t ConvertKeyCodeToKeySym(xcb_keycode_t keycode, uint16_t state);
NzKeyboard::Key ConvertVirtualKey(xcb_keysym_t symbol);
const char* ConvertWindowCursorToXName(nzWindowCursor cursor);
void CommonInitialize();
static bool Initialize();
static void Uninitialize();
void ProcessEvent(xcb_generic_event_t* windowEvent);
private:
void ResetVideoMode();
void CleanUp();
xcb_keysym_t ConvertKeyCodeToKeySym(xcb_keycode_t keycode, uint16_t state);
Keyboard::Key ConvertVirtualKey(xcb_keysym_t symbol);
const char* ConvertWindowCursorToXName(WindowCursor cursor);
void CommonInitialize();
void SetCursor(xcb_cursor_t cursor);
void SetMotifHints();
void SetVideoMode(const NzVideoMode& mode);
void SwitchToFullscreen();
void ProcessEvent(xcb_generic_event_t* windowEvent);
bool UpdateNormalHints();
void UpdateEventQueue(xcb_generic_event_t* event);
void ResetVideoMode();
#if NAZARA_UTILITY_THREADED_WINDOW
static void WindowThread(NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition);
#endif
void SetCursor(xcb_cursor_t cursor);
void SetMotifHints();
void SetVideoMode(const VideoMode& mode);
void SwitchToFullscreen();
xcb_window_t m_window;
xcb_screen_t* m_screen;
xcb_randr_get_screen_info_reply_t m_oldVideoMode;
xcb_size_hints_t m_size_hints;
nzUInt32 m_style;
#if NAZARA_UTILITY_THREADED_WINDOW
NzThread m_thread;
#endif
NzWindow* m_parent;
bool m_eventListener;
bool m_ownsWindow;
bool m_smoothScrolling;
#if NAZARA_UTILITY_THREADED_WINDOW
bool m_threadActive;
#endif
short m_scrolling;
NzVector2i m_mousePos;
bool m_keyRepeat;
bool UpdateNormalHints();
void UpdateEventQueue(xcb_generic_event_t* event);
#if NAZARA_UTILITY_THREADED_WINDOW
static void WindowThread(WindowImpl* window, Mutex* mutex, ConditionVariable* condition);
#endif
xcb_window_t m_window;
xcb_screen_t* m_screen;
xcb_randr_get_screen_info_reply_t m_oldVideoMode;
xcb_size_hints_t m_size_hints;
UInt32 m_style;
#if NAZARA_UTILITY_THREADED_WINDOW
Thread m_thread;
#endif
Window* m_parent;
bool m_eventListener;
bool m_ownsWindow;
bool m_smoothScrolling;
#if NAZARA_UTILITY_THREADED_WINDOW
bool m_threadActive;
#endif
short m_scrolling;
Vector2i m_mousePos;
bool m_keyRepeat;
struct
{
xcb_generic_event_t* curr = nullptr;
xcb_generic_event_t* next = nullptr;
} m_eventQueue;
};
}
struct
{
xcb_generic_event_t* curr = nullptr;
xcb_generic_event_t* next = nullptr;
} m_eventQueue;
};
#endif // NAZARA_WINDOWIMPL_HPP