Skip to content

Commit 78172bf

Browse files
committed
address some of the comments
Signed-off-by: Michael Pollind <mpollind@gmail.com>
1 parent 21d91f7 commit 78172bf

File tree

9 files changed

+188
-147
lines changed

9 files changed

+188
-147
lines changed

include/nbl/ui/CWindowManagerXCB.h

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,30 @@
1-
#ifndef C_WINDOW_MANAGER_XCB
2-
#define C_WINDOW_MANAGER_XCB
1+
#ifndef _NBL_UI_C__WINDOWMANAGER_XCB_INCLUDED_
2+
#define _NBL_UI_C__WINDOWMANAGER_XCB_INCLUDED_
33

44
#ifdef _NBL_PLATFORM_LINUX_
55
#include "nbl/core/decl/Types.h"
66

77
#include "nbl/system/DefaultFuncPtrLoader.h"
88

99
#include "nbl/ui/IWindow.h"
10-
#include "nbl/ui/IWindowManager.h"
10+
#include "nbl/ui/IWindowManagerXCB.h"
1111

1212
#include <functional>
1313
#include <memory>
1414
#include <string>
1515

16-
#include <xcb/xcb.h>
17-
#include <xcb/xcb_icccm.h>
18-
#include <xcb/xproto.h>
19-
2016
namespace nbl::ui
2117
{
2218

23-
NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(Xcb, system::DefaultFuncPtrLoader,
24-
xcb_destroy_window,
25-
xcb_generate_id,
26-
xcb_create_window,
27-
xcb_connect,
28-
xcb_disconnect,
29-
xcb_map_window,
30-
xcb_get_setup,
31-
xcb_setup_roots_iterator,
32-
xcb_flush,
33-
xcb_intern_atom,
34-
xcb_intern_atom_reply,
35-
xcb_unmap_window,
36-
xcb_get_property,
37-
xcb_get_property_reply,
38-
xcb_get_property_value_length,
39-
xcb_change_property,
40-
xcb_configure_window_checked,
41-
xcb_get_property_value,
42-
xcb_wait_for_event,
43-
xcb_send_event,
44-
xcb_request_check,
45-
xcb_delete_property,
46-
xcb_change_window_attributes,
47-
xcb_warp_pointer,
48-
xcb_query_pointer,
49-
xcb_query_pointer_reply,
50-
xcb_get_selection_owner_reply,
51-
xcb_get_selection_owner
52-
);
53-
54-
NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(XcbIcccm, system::DefaultFuncPtrLoader,
55-
xcb_icccm_set_wm_hints,
56-
xcb_icccm_size_hints_set_size,
57-
xcb_icccm_size_hints_set_min_size,
58-
xcb_icccm_size_hints_set_max_size,
59-
xcb_icccm_set_wm_normal_hints
60-
);
61-
62-
class CWindowManagerXCB : public IWindowManager
19+
class CWindowManagerXCB final : public IWindowManagerXCB
6320
{
6421
public:
65-
66-
virtual bool setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) override;
67-
virtual bool setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) override;
68-
virtual bool setWindowRotation_impl(IWindow* window, bool landscape) override;
69-
virtual bool setWindowVisible_impl(IWindow* window, bool visible) override;
70-
virtual bool setWindowMaximized_impl(IWindow* window, bool maximized) override;
22+
23+
bool setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) override;
24+
bool setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) override;
25+
bool setWindowRotation_impl(IWindow* window, bool landscape) override;
26+
bool setWindowVisible_impl(IWindow* window, bool visible) override;
27+
bool setWindowMaximized_impl(IWindow* window, bool maximized) override;
7128

7229
inline SDisplayInfo getPrimaryDisplayInfo() const override final {
7330
return SDisplayInfo();
@@ -76,9 +33,9 @@ class CWindowManagerXCB : public IWindowManager
7633
CWindowManagerXCB();
7734
~CWindowManagerXCB() override = default;
7835

79-
virtual core::smart_refctd_ptr<IWindow> createWindow(IWindow::SCreationParams&& creationParams) override;
36+
core::smart_refctd_ptr<IWindow> createWindow(IWindow::SCreationParams&& creationParams) override;
8037

81-
virtual void destroyWindow(IWindow* wnd) override final {}
38+
void destroyWindow(IWindow* wnd) override final {}
8239

8340
const Xcb& getXcbFunctionTable() const { return m_xcb; }
8441
const XcbIcccm& getXcbIcccmFunctionTable() const { return m_xcbIcccm; }

include/nbl/ui/CWindowXCB.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __C_WINDOW_XCB_H_INCLUDED__
2-
#define __C_WINDOW_XCB_H_INCLUDED__
1+
#ifndef _NBL_UI_C_WINDOW_XCB_H_INCLUDED_
2+
#define _NBL_UI_C_WINDOW_XCB_H_INCLUDED_
33

44
#include "nbl/core/decl/smart_refctd_ptr.h"
55
#include "nbl/ui/IClipboardManagerXCB.h"
@@ -23,8 +23,13 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
2323
CWindowXCB(core::smart_refctd_ptr<CWindowManagerXCB>&& winManager, SCreationParams&& params);
2424
~CWindowXCB();
2525

26+
27+
const native_handle_t* getNativeHandle() const override {
28+
return &m_handle;
29+
}
30+
2631
// Display* getDisplay() const override { return m_dpy; }
27-
xcb_window_t getXcbWindow() const override { return m_xcbWindow; }
32+
xcb_window_t getXcbWindow() const override { return m_handle.m_window; }
2833
xcb_connection_t* getXcbConnection() const override {
2934
return m_connection->getRawConnection();
3035
}
@@ -52,13 +57,18 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
5257
class CDispatchThread final : public system::IThreadHandler<CDispatchThread>
5358
{
5459
public:
60+
using base_t = system::IThreadHandler<CDispatchThread>;
61+
62+
inline CDispatchThread(CWindowXCB& window) :
63+
base_t(base_t::start_on_construction_t {}),
64+
m_window(window) {
5565

56-
inline CDispatchThread(CWindowXCB& window);
66+
}
5767
inline ~CDispatchThread() {
5868
}
5969

60-
void init();
61-
void exit();
70+
inline void init() {}
71+
inline void exit() {}
6272
void work(lock_t& lock);
6373

6474
inline bool wakeupPredicate() const { return true; }
@@ -67,8 +77,8 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
6777
CWindowXCB& m_window;
6878
friend class CWindowXCB;
6979
} m_dispatcher;
70-
71-
xcb_window_t m_xcbWindow = 0;
80+
81+
native_handle_t m_handle = {{0}};
7282

7383
XCBConnection::XCBAtomToken<core::StringLiteral("WM_DELETE_WINDOW")> m_WM_DELETE_WINDOW;
7484
XCBConnection::XCBAtomToken<core::StringLiteral("WM_PROTOCOLS")> m_WM_PROTOCOLS;

include/nbl/ui/IWindowManagerXCB.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef _NBL_UI_I_WINDOWMANAGER_XCB_INCLUDED_
2+
#define _NBL_UI_I_WINDOWMANAGER_XCB_INCLUDED_
3+
4+
#include "nbl/ui/IWindowManager.h"
5+
6+
#ifdef _NBL_PLATFORM_LINUX_
7+
8+
#include <xcb/xcb.h>
9+
#include <xcb/xcb_icccm.h>
10+
#include <xcb/xproto.h>
11+
12+
namespace nbl::ui {
13+
14+
class IWindowManagerXCB : public IWindowManager
15+
{
16+
public:
17+
NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(Xcb, system::DefaultFuncPtrLoader,
18+
xcb_destroy_window,
19+
xcb_generate_id,
20+
xcb_create_window,
21+
xcb_connect,
22+
xcb_disconnect,
23+
xcb_map_window,
24+
xcb_get_setup,
25+
xcb_setup_roots_iterator,
26+
xcb_flush,
27+
xcb_intern_atom,
28+
xcb_intern_atom_reply,
29+
xcb_unmap_window,
30+
xcb_get_property,
31+
xcb_get_property_reply,
32+
xcb_get_property_value_length,
33+
xcb_change_property,
34+
xcb_configure_window_checked,
35+
xcb_get_property_value,
36+
xcb_wait_for_event,
37+
xcb_send_event,
38+
xcb_request_check,
39+
xcb_delete_property,
40+
xcb_change_window_attributes,
41+
xcb_warp_pointer,
42+
xcb_query_pointer,
43+
xcb_query_pointer_reply,
44+
xcb_get_selection_owner_reply,
45+
xcb_get_selection_owner
46+
);
47+
48+
NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(XcbIcccm, system::DefaultFuncPtrLoader,
49+
xcb_icccm_set_wm_hints,
50+
xcb_icccm_size_hints_set_size,
51+
xcb_icccm_size_hints_set_min_size,
52+
xcb_icccm_size_hints_set_max_size,
53+
xcb_icccm_set_wm_normal_hints
54+
);
55+
56+
NBL_API2 static core::smart_refctd_ptr<IWindowManagerXCB> create();
57+
};
58+
59+
} // namespace nbl::ui
60+
61+
#endif
62+
#endif

include/nbl/ui/IWindowXCB.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ class NBL_API2 IWindowXCB : public IWindow
2222
public:
2323
using IWindow::IWindow;
2424

25-
const void* getNativeHandle() const { return nullptr; }
25+
struct native_handle_t {
26+
xcb_window_t m_window;
27+
xcb_connection_t* m_connection;
28+
};
29+
30+
virtual const native_handle_t* getNativeHandle() const = 0;
31+
2632
virtual xcb_window_t getXcbWindow() const = 0;
2733
virtual xcb_connection_t* getXcbConnection() const = 0;
2834

include/nbl/ui/XCBConnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class XCBConnection : public core::IReferenceCounted {
9191
return m_connection;
9292
}
9393

94-
const Xcb& getXcbFunctionTable() const { return m_windowManager->getXcbFunctionTable(); }
95-
const XcbIcccm& getXcbIcccmFunctionTable() const { return m_windowManager->getXcbIcccmFunctionTable(); }
94+
const CWindowManagerXCB::Xcb& getXcbFunctionTable() const { return m_windowManager->getXcbFunctionTable(); }
95+
const CWindowManagerXCB::XcbIcccm& getXcbIcccmFunctionTable() const { return m_windowManager->getXcbIcccmFunctionTable(); }
9696

9797
const xcb_screen_t* primaryScreen();
9898

src/nbl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ set(NBL_UI_SOURCES
188188
${NBL_ROOT_PATH}/src/nbl/ui/CWindowManagerWin32.cpp
189189
${NBL_ROOT_PATH}/src/nbl/ui/CWindowXcb.cpp
190190
${NBL_ROOT_PATH}/src/nbl/ui/XCBConnection.cpp
191+
${NBL_ROOT_PATH}/src/nbl/ui/CWindowManagerXCB.cpp
191192
${NBL_ROOT_PATH}/src/nbl/ui/CCursorControlWin32.cpp
192193
${NBL_ROOT_PATH}/src/nbl/ui/CClipboardManagerWin32.cpp
193194
${NBL_ROOT_PATH}/src/nbl/ui/CClipboardManagerXCB.cpp

src/nbl/ui/CClipboardManagerXCB.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace nbl::ui
3333

3434
auto TARGETS = m_connection->resolveAtom(m_TARGETS);
3535

36+
const auto& native_handle = window->getNativeHandle();
37+
3638
switch(event->response_type & ~0x80) {
3739
// XCB_ATOM
3840
// Somone is requesting the clipboard data

src/nbl/ui/CWindowManagerXCB.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "nbl/ui/CWindowManagerXCB.h"
2+
3+
#ifdef _NBL_PLATFORM_LINUX_
4+
5+
#include "nbl/ui/CWindowManagerXCB.h"
6+
#include "nbl/ui/CWindowXCB.h"
7+
8+
using namespace nbl;
9+
using namespace nbl::ui;
10+
11+
core::smart_refctd_ptr<IWindowManagerXCB> IWindowManagerXCB::create()
12+
{
13+
return core::make_smart_refctd_ptr<CWindowManagerXCB>();
14+
}
15+
16+
17+
CWindowManagerXCB::CWindowManagerXCB() {
18+
}
19+
20+
core::smart_refctd_ptr<IWindow> CWindowManagerXCB::createWindow(IWindow::SCreationParams&& creationParams)
21+
{
22+
std::string title = std::string(creationParams.windowCaption);
23+
auto window = core::make_smart_refctd_ptr<CWindowXCB>(core::smart_refctd_ptr<CWindowManagerXCB>(this), std::move(creationParams));
24+
window->setCaption(title);
25+
return window;
26+
}
27+
28+
bool CWindowManagerXCB::setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) {
29+
auto wnd = static_cast<IWindowXCB*>(window);
30+
wnd->setWindowSize_impl(width, height);
31+
return true;
32+
}
33+
34+
bool CWindowManagerXCB::setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) {
35+
auto wnd = static_cast<IWindowXCB*>(window);
36+
wnd->setWindowPosition_impl(x, y);
37+
return true;
38+
}
39+
40+
bool CWindowManagerXCB::setWindowRotation_impl(IWindow* window, bool landscape) {
41+
auto wnd = static_cast<IWindowXCB*>(window);
42+
wnd->setWindowRotation_impl(landscape);
43+
return true;
44+
}
45+
46+
bool CWindowManagerXCB::setWindowVisible_impl(IWindow* window, bool visible) {
47+
auto wnd = static_cast<IWindowXCB*>(window);
48+
wnd->setWindowVisible_impl(visible);
49+
return true;
50+
}
51+
52+
bool CWindowManagerXCB::setWindowMaximized_impl(IWindow* window, bool maximized) {
53+
auto wnd = static_cast<IWindowXCB*>(window);
54+
wnd->setWindowMaximized_impl(maximized);
55+
return true;
56+
}
57+
58+
#endif

0 commit comments

Comments
 (0)