Skip to content

Commit 9905d15

Browse files
committed
shuffled around implementation
Signed-off-by: Michael Pollind <mpollind@gmail.com>
1 parent c3639e9 commit 9905d15

15 files changed

+591
-553
lines changed

include/nbl/ui/CClipboardManagerXCB.h

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,33 @@
55

66
#include "nbl/core/decl/Types.h"
77
#include "nbl/ui/IClipboardManagerXCB.h"
8-
#include "nbl/ui/XCBConnection.h"
98
namespace nbl::ui
109
{
1110

1211
class IWindowXCB;
1312
class XCBConnection;
1413

1514
// details on XCB clipboard protocol: https://tronche.com/gui/x/icccm/sec-2.html#s-2
16-
class NBL_API2 CClipboardManagerXCB final : public IClipboardManagerXCB
17-
{
18-
public:
19-
inline CClipboardManagerXCB(core::smart_refctd_ptr<XCBConnection>&& connect):
20-
IClipboardManagerXCB(),
21-
m_connection(std::move(connect)) {}
22-
23-
virtual std::string getClipboardText() override;
24-
virtual bool setClipboardText(const std::string_view& data) override;
25-
26-
void process(const IWindowXCB* window, xcb_generic_event_t* event) override;
27-
private:
28-
core::smart_refctd_ptr<XCBConnection> m_connection;
29-
std::mutex m_clipboardMutex;
30-
std::condition_variable m_clipboardResponseCV;
31-
std::string m_clipboardResponse; // data sent to the clipboard by another application
32-
33-
std::string m_savedClipboard; // data saved to the clipboard for another application to read
34-
35-
XCBConnection::XCBAtomToken<core::StringLiteral("CLIPBOARD")> m_CLIPBOARD;
36-
XCBConnection::XCBAtomToken<core::StringLiteral("TARGETS")> m_TARGETS;
37-
XCBConnection::XCBAtomToken<core::StringLiteral("INCR")> m_INCR;
38-
39-
XCBConnection::XCBAtomToken<core::StringLiteral("UTF8_STRING")> m_formatUTF8_0;
40-
XCBConnection::XCBAtomToken<core::StringLiteral("text/plain;charset=utf-8")> m_formatUTF8_1;
41-
XCBConnection::XCBAtomToken<core::StringLiteral("text/plain;charset=UTF-8")> m_formatUTF8_2;
42-
XCBConnection::XCBAtomToken<core::StringLiteral("GTK_TEXT_BUFFER_CONTENTS")> m_formatGTK;
43-
XCBConnection::XCBAtomToken<core::StringLiteral("STRING")> m_formatString;
44-
XCBConnection::XCBAtomToken<core::StringLiteral("TEXT")> m_formatText;
45-
XCBConnection::XCBAtomToken<core::StringLiteral("text/plain")> m_formatTextPlain;
46-
};
15+
// class NBL_API2 CClipboardManagerXCB final : public IClipboardManagerXCB
16+
// {
17+
// public:
18+
// inline CClipboardManagerXCB(core::smart_refctd_ptr<XCBConnection>&& connect):
19+
// IClipboardManagerXCB(),
20+
// m_connection(std::move(connect)) {}
21+
22+
// virtual std::string getClipboardText() override;
23+
// virtual bool setClipboardText(const std::string_view& data) override;
24+
25+
// void process(const IWindowXCB* window, xcb_generic_event_t* event) override;
26+
// private:
27+
// core::smart_refctd_ptr<XCBConnection> m_connection;
28+
// std::mutex m_clipboardMutex;
29+
// std::condition_variable m_clipboardResponseCV;
30+
// std::string m_clipboardResponse; // data sent to the clipboard by another application
31+
32+
// std::string m_savedClipboard; // data saved to the clipboard for another application to read
33+
34+
// };
4735

4836
}
4937

include/nbl/ui/CCursorControlXCB.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class XCBConnection;
1212
class NBL_API2 CCursorControlXCB final : public ICursorControl
1313
{
1414
public:
15-
inline CCursorControlXCB(
16-
core::smart_refctd_ptr<XCBConnection>&& xcbConnection) :
17-
m_connection(std::move(xcbConnection)) {}
15+
inline CCursorControlXCB() {}
1816

1917
void setVisible(bool visible) override;
2018
bool isVisible() const override;
@@ -25,7 +23,7 @@ class NBL_API2 CCursorControlXCB final : public ICursorControl
2523
SPosition getPosition() override;
2624
SRelativePosition getRelativePosition(IWindow* window) override;
2725
private:
28-
core::smart_refctd_ptr<XCBConnection> m_connection;
26+
// core::smart_refctd_ptr<XCBConnection> m_connection;
2927
};
3028
}
3129

include/nbl/ui/CWindowManagerXCB.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22
#define _NBL_UI_C__WINDOWMANAGER_XCB_INCLUDED_
33

44
#ifdef _NBL_PLATFORM_LINUX_
5-
#include "nbl/core/decl/Types.h"
65

7-
#include "nbl/system/DefaultFuncPtrLoader.h"
6+
#include "nbl/core/decl/Types.h"
87

98
#include "nbl/ui/IWindow.h"
109
#include "nbl/ui/IWindowManagerXCB.h"
1110

12-
#include <functional>
13-
#include <memory>
14-
#include <string>
15-
1611
namespace nbl::ui
1712
{
1813

1914
class CWindowManagerXCB final : public IWindowManagerXCB
2015
{
2116
public:
22-
17+
2318
bool setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) override;
2419
bool setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) override;
2520
bool setWindowRotation_impl(IWindow* window, bool landscape) override;
@@ -32,13 +27,13 @@ class CWindowManagerXCB final : public IWindowManagerXCB
3227

3328
CWindowManagerXCB();
3429
~CWindowManagerXCB() override = default;
35-
30+
3631
core::smart_refctd_ptr<IWindow> createWindow(IWindow::SCreationParams&& creationParams) override;
3732

3833
void destroyWindow(IWindow* wnd) override final {}
3934

40-
const Xcb& getXcbFunctionTable() const { return m_xcb; }
41-
const XcbIcccm& getXcbIcccmFunctionTable() const { return m_xcbIcccm; }
35+
const Xcb& getXcbFunctionTable() const override { return m_xcb; }
36+
const XcbIcccm& getXcbIcccmFunctionTable() const override { return m_xcbIcccm; }
4237

4338
private:
4439
Xcb m_xcb = Xcb("xcb"); // function tables

include/nbl/ui/CWindowXCB.h

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "nbl/core/decl/smart_refctd_ptr.h"
55
#include "nbl/ui/IClipboardManagerXCB.h"
66
#include "nbl/ui/IWindowXCB.h"
7-
#include "nbl/ui/XCBConnection.h"
7+
#include "nbl/ui/XCBHandle.h"
88

99
#include <cstdlib>
1010

@@ -20,7 +20,7 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
2020
{
2121

2222
public:
23-
CWindowXCB(core::smart_refctd_ptr<CWindowManagerXCB>&& winManager, SCreationParams&& params);
23+
CWindowXCB(native_handle_t&& handle, core::smart_refctd_ptr<CWindowManagerXCB>&& winManager, SCreationParams&& params);
2424
~CWindowXCB();
2525

2626
const native_handle_t* getNativeHandle() const override {
@@ -31,19 +31,19 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
3131
virtual ICursorControl* getCursorControl() override;
3232
virtual IWindowManager* getManager() const override;
3333

34-
virtual bool setWindowSize_impl(uint32_t width, uint32_t height) override;
35-
virtual bool setWindowPosition_impl(int32_t x, int32_t y) override;
36-
virtual bool setWindowRotation_impl(bool landscape) override;
37-
virtual bool setWindowVisible_impl(bool visible) override;
38-
virtual bool setWindowMaximized_impl(bool maximized) override;
34+
virtual bool setWindowSize(uint32_t width, uint32_t height) override;
35+
virtual bool setWindowPosition(int32_t x, int32_t y) override;
36+
virtual bool setWindowRotation(bool landscape) override;
37+
virtual bool setWindowVisible(bool visible) override;
38+
virtual bool setWindowMaximized(bool maximized) override;
3939

4040
virtual void setCaption(const std::string_view& caption) override;
4141

4242
private:
4343
CWindowXCB(core::smart_refctd_ptr<system::ISystem>&& sys, uint32_t _w, uint32_t _h, E_CREATE_FLAGS _flags);
4444

45+
native_handle_t m_handle;
4546
core::smart_refctd_ptr<CWindowManagerXCB> m_windowManager;
46-
core::smart_refctd_ptr<XCBConnection> m_connection;
4747
core::smart_refctd_ptr<CCursorControlXCB> m_cursorControl;
4848
core::smart_refctd_ptr<IClipboardManagerXCB> m_clipboardManager;
4949

@@ -70,16 +70,7 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
7070
CWindowXCB& m_window;
7171
friend class CWindowXCB;
7272
} m_dispatcher;
73-
74-
native_handle_t m_handle = {{0}};
7573

76-
XCBConnection::XCBAtomToken<core::StringLiteral("WM_DELETE_WINDOW")> m_WM_DELETE_WINDOW;
77-
XCBConnection::XCBAtomToken<core::StringLiteral("WM_PROTOCOLS")> m_WM_PROTOCOLS;
78-
XCBConnection::XCBAtomToken<core::StringLiteral("_NET_WM_PING")> m_NET_WM_PING;
79-
80-
XCBConnection::XCBAtomToken<core::StringLiteral("_NET_WM_STATE_MAXIMIZED_VERT")> m_NET_WM_STATE_MAXIMIZED_VERT;
81-
XCBConnection::XCBAtomToken<core::StringLiteral("_NET_WM_STATE_MAXIMIZED_HORZ")> m_NET_WM_STATE_MAXIMIZED_HORZ;
82-
XCBConnection::XCBAtomToken<core::StringLiteral("_NET_WM_STATE_FULLSCREEN")> m_NET_WM_STATE_FULLSCREEN;
8374

8475
};
8576

include/nbl/ui/IWindowManagerXCB.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class IWindowManagerXCB : public IWindowManager
5353
xcb_icccm_set_wm_normal_hints
5454
);
5555

56+
5657
NBL_API2 static core::smart_refctd_ptr<IWindowManagerXCB> create();
58+
virtual const Xcb& getXcbFunctionTable() const = 0;
59+
virtual const XcbIcccm& getXcbIcccmFunctionTable() const = 0;
5760
};
5861

5962
} // namespace nbl::ui

include/nbl/ui/IWindowXCB.h

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef __NBL_I_WINDOW_XCB_H_INCLUDED__
22
#define __NBL_I_WINDOW_XCB_H_INCLUDED__
33

4+
#include "nbl/ui/XCBHandle.h"
45
#ifdef _NBL_PLATFORM_LINUX_
56

67
#include "nbl/core/util/bitflag.h"
78

89
#include "nbl/ui/IWindow.h"
9-
#include "nbl/ui/XCBConnection.h"
1010

1111
#include <xcb/xproto.h>
1212

@@ -24,68 +24,18 @@ class NBL_API2 IWindowXCB : public IWindow
2424

2525
struct native_handle_t {
2626
xcb_window_t m_window;
27-
xcb_connection_t* m_connection;
27+
core::smart_refctd_ptr<xcb::XCBHandle> m_connection;
2828
};
2929

3030
virtual const native_handle_t* getNativeHandle() const = 0;
31-
32-
virtual bool setWindowSize_impl(uint32_t width, uint32_t height) = 0;
33-
virtual bool setWindowPosition_impl(int32_t x, int32_t y) = 0;
34-
virtual bool setWindowRotation_impl(bool landscape) = 0;
35-
virtual bool setWindowVisible_impl(bool visible) = 0;
36-
virtual bool setWindowMaximized_impl(bool maximized) = 0;
37-
38-
static XCBConnection::MotifWmHints fetchMotifMWHints(IWindow::E_CREATE_FLAGS flags) {
39-
core::bitflag<XCBConnection::MotifFlags> motifFlags(XCBConnection::MWM_HINTS_NONE);
40-
core::bitflag<XCBConnection::MotifFunctions> motifFunctions(XCBConnection::MWM_FUNC_NONE);
41-
core::bitflag<XCBConnection::MotifDecorations> motifDecorations(XCBConnection::MWM_DECOR_NONE);
42-
motifFlags |= XCBConnection::MWM_HINTS_DECORATIONS;
43-
44-
if (flags & IWindow::ECF_BORDERLESS) {
45-
motifDecorations |= XCBConnection::MWM_DECOR_ALL;
46-
} else {
47-
motifDecorations |= XCBConnection::MWM_DECOR_BORDER;
48-
motifDecorations |= XCBConnection::MWM_DECOR_RESIZEH;
49-
motifDecorations |= XCBConnection::MWM_DECOR_TITLE;
50-
51-
// minimize button
52-
if(flags & IWindow::ECF_MINIMIZED) {
53-
motifDecorations |= XCBConnection::MWM_DECOR_MINIMIZE;
54-
motifFunctions |= XCBConnection::MWM_FUNC_MINIMIZE;
55-
}
56-
57-
// maximize button
58-
if(flags & IWindow::ECF_MAXIMIZED) {
59-
motifDecorations |= XCBConnection::MWM_DECOR_MAXIMIZE;
60-
motifFunctions |= XCBConnection::MWM_FUNC_MAXIMIZE;
61-
}
62-
63-
// close button
64-
motifFunctions |= XCBConnection::MWM_FUNC_CLOSE;
65-
}
66-
67-
if(motifFunctions.value != XCBConnection::MWM_FUNC_NONE) {
68-
motifFlags |= XCBConnection::MWM_HINTS_FUNCTIONS;
69-
motifFunctions |= XCBConnection::MWM_FUNC_RESIZE;
70-
motifFunctions |= XCBConnection::MWM_FUNC_MOVE;
71-
} else {
72-
motifFunctions = XCBConnection::MWM_FUNC_ALL;
73-
}
74-
75-
XCBConnection::MotifWmHints hints;
76-
hints.flags = motifFlags.value;
77-
hints.functions = motifFunctions.value;
78-
hints.decorations = motifDecorations.value;
79-
hints.input_mode = 0;
80-
hints.status = 0;
81-
return hints;
82-
83-
}
84-
31+
virtual bool setWindowSize(uint32_t width, uint32_t height) = 0;
32+
virtual bool setWindowPosition(int32_t x, int32_t y) = 0;
33+
virtual bool setWindowRotation(bool landscape) = 0;
34+
virtual bool setWindowVisible(bool visible) = 0;
35+
virtual bool setWindowMaximized(bool maximized) = 0;
8536
};
8637

8738
}
8839

8940
#endif
90-
9141
#endif

0 commit comments

Comments
 (0)