Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: implement xcb for windowing #462

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ set(VOLK_PULL_IN_VULKAN OFF CACHE INTERNAL "" FORCE) # Needed to make sure vulka

if (WIN32)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
elseif(UNIX AND NOT ANDROID AND NOT APPLE)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_XCB_KHR)
endif()
add_subdirectory(volk volk EXCLUDE_FROM_ALL)

Expand Down
5 changes: 5 additions & 0 deletions include/nbl/core/string/StringLiteral.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ struct StringLiteral
std::copy_n(str, N, value);
}

// the size includes the null terminator
constexpr size_t size() const {
return N;
}

char value[N];
};

Expand Down
40 changes: 40 additions & 0 deletions include/nbl/ui/CClipboardManagerXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef _NBL_UI_C_CLIPBOARD_MANAGER_XCB_INCLUDED_
#define _NBL_UI_C_CLIPBOARD_MANAGER_XCB_INCLUDED_

#ifdef _NBL_PLATFORM_LINUX_

#include "nbl/core/decl/Types.h"
#include "nbl/ui/IClipboardManagerXCB.h"
namespace nbl::ui
{

class IWindowXCB;
class XCBConnection;

// details on XCB clipboard protocol: https://tronche.com/gui/x/icccm/sec-2.html#s-2
// class NBL_API2 CClipboardManagerXCB final : public IClipboardManagerXCB
// {
// public:
// inline CClipboardManagerXCB(core::smart_refctd_ptr<XCBConnection>&& connect):
// IClipboardManagerXCB(),
// m_connection(std::move(connect)) {}

// virtual std::string getClipboardText() override;
// virtual bool setClipboardText(const std::string_view& data) override;

// void process(const IWindowXCB* window, xcb_generic_event_t* event) override;
// private:
// core::smart_refctd_ptr<XCBConnection> m_connection;
// std::mutex m_clipboardMutex;
// std::condition_variable m_clipboardResponseCV;
// std::string m_clipboardResponse; // data sent to the clipboard by another application

// std::string m_savedClipboard; // data saved to the clipboard for another application to read

// };

}

#endif

#endif
32 changes: 32 additions & 0 deletions include/nbl/ui/CCursorControlXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef __NBL_SYSTEM_C_CURSOR_CONTROL_XCB_H_INCLUDED__
#define __NBL_SYSTEM_C_CURSOR_CONTROL_XCB_H_INCLUDED__
Comment on lines +1 to +2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong namespace, also one too many _ on the beginning and end


#ifdef _NBL_PLATFORM_LINUX_

#include "nbl/ui/ICursorControl.h"

namespace nbl::ui
{

class XCBConnection;
class NBL_API2 CCursorControlXCB final : public ICursorControl
{
public:
inline CCursorControlXCB() {}

void setVisible(bool visible) override;
bool isVisible() const override;

void setPosition(SPosition pos) override;
void setRelativePosition(IWindow* window, SRelativePosition pos) override;

SPosition getPosition() override;
SRelativePosition getRelativePosition(IWindow* window) override;
private:
// core::smart_refctd_ptr<XCBConnection> m_connection;
};
}

#endif

#endif
46 changes: 46 additions & 0 deletions include/nbl/ui/CWindowManagerXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef _NBL_UI_C__WINDOWMANAGER_XCB_INCLUDED_
#define _NBL_UI_C__WINDOWMANAGER_XCB_INCLUDED_

#ifdef _NBL_PLATFORM_LINUX_

#include "nbl/core/decl/Types.h"

#include "nbl/ui/IWindow.h"
#include "nbl/ui/IWindowManagerXCB.h"

namespace nbl::ui
{

class CWindowManagerXCB final : public IWindowManagerXCB
{
public:

bool setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) override;
bool setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) override;
bool setWindowRotation_impl(IWindow* window, bool landscape) override;
bool setWindowVisible_impl(IWindow* window, bool visible) override;
bool setWindowMaximized_impl(IWindow* window, bool maximized) override;

inline SDisplayInfo getPrimaryDisplayInfo() const override final {
return SDisplayInfo();
}
Comment on lines +24 to +26

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO


CWindowManagerXCB();
~CWindowManagerXCB() override = default;

core::smart_refctd_ptr<IWindow> createWindow(IWindow::SCreationParams&& creationParams) override;

void destroyWindow(IWindow* wnd) override final {}

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

private:
Xcb m_xcb = Xcb("xcb"); // function tables
XcbIcccm m_xcbIcccm = XcbIcccm("xcb-icccm");
};


}
#endif
#endif
71 changes: 71 additions & 0 deletions include/nbl/ui/CWindowXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef _NBL_UI_C_WINDOW_XCB_H_INCLUDED_
#define _NBL_UI_C_WINDOW_XCB_H_INCLUDED_

#include "nbl/core/decl/smart_refctd_ptr.h"
#include "nbl/ui/IClipboardManagerXCB.h"
#include "nbl/ui/IWindowXCB.h"
#include "nbl/ui/XCBHandle.h"

#include <cstdlib>

namespace nbl::ui
{

class CWindowManagerXCB;
class XCBConnection;
class CCursorControlXCB;
class IClipboardManagerXCB;

class NBL_API2 CWindowXCB final : public IWindowXCB
{

public:
CWindowXCB(native_handle_t&& handle, core::smart_refctd_ptr<CWindowManagerXCB>&& winManager, SCreationParams&& params);
~CWindowXCB();

const native_handle_t* getNativeHandle() const override {
return &m_handle;
}

virtual IClipboardManager* getClipboardManager() override;
virtual ICursorControl* getCursorControl() override;
virtual IWindowManager* getManager() const override;

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

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

native_handle_t m_handle;
core::smart_refctd_ptr<CWindowManagerXCB> m_windowManager;
core::smart_refctd_ptr<CCursorControlXCB> m_cursorControl;
core::smart_refctd_ptr<IClipboardManagerXCB> m_clipboardManager;

class CDispatchThread final : public system::IThreadHandler<CDispatchThread>
{
public:
using base_t = system::IThreadHandler<CDispatchThread>;

inline CDispatchThread(CWindowXCB& window) :
base_t(base_t::start_on_construction_t {}),
m_window(window) {

}
inline ~CDispatchThread() {
}

inline void init() {}
inline void exit() {}
void work(lock_t& lock);

inline bool wakeupPredicate() const { return true; }
inline bool continuePredicate() const { return true; }
private:
CWindowXCB& m_window;
friend class CWindowXCB;
} m_dispatcher;
};

}

#endif
28 changes: 28 additions & 0 deletions include/nbl/ui/IClipboardManagerXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _NBL_UI_I_CLIPBOARD_MANAGER_XCB_INCLUDED_
#define _NBL_UI_I_CLIPBOARD_MANAGER_XCB_INCLUDED_

#ifdef _NBL_PLATFORM_LINUX_

#include "nbl/ui/IClipboardManager.h"

namespace nbl::ui
{
class XCBConnection;

// details on XCB clipboard protocol: https://tronche.com/gui/x/icccm/sec-2.html#s-2
class NBL_API2 IClipboardManagerXCB : public IClipboardManager
{
public:
IClipboardManagerXCB() : IClipboardManager() {}
virtual ~IClipboardManagerXCB() = default;

virtual std::string getClipboardText() = 0;
virtual bool setClipboardText(const std::string_view& data) = 0;
virtual void process(const IWindowXCB* window, xcb_generic_event_t* event) = 0;
};

}

#endif

#endif
Comment on lines +1 to +28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably don't need an IClip in header dir and CClip in source, see if you can go with CClip in source dir right away

65 changes: 65 additions & 0 deletions include/nbl/ui/IWindowManagerXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef _NBL_UI_I_WINDOWMANAGER_XCB_INCLUDED_
#define _NBL_UI_I_WINDOWMANAGER_XCB_INCLUDED_

#include "nbl/ui/IWindowManager.h"

#ifdef _NBL_PLATFORM_LINUX_

#include <xcb/xcb.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xproto.h>

namespace nbl::ui {

class IWindowManagerXCB : public IWindowManager
{
public:
NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(Xcb, system::DefaultFuncPtrLoader,
xcb_destroy_window,
xcb_generate_id,
xcb_create_window,
xcb_connect,
xcb_disconnect,
xcb_map_window,
xcb_get_setup,
xcb_setup_roots_iterator,
xcb_flush,
xcb_intern_atom,
xcb_intern_atom_reply,
xcb_unmap_window,
xcb_get_property,
xcb_get_property_reply,
xcb_get_property_value_length,
xcb_change_property,
xcb_configure_window_checked,
xcb_get_property_value,
xcb_wait_for_event,
xcb_send_event,
xcb_request_check,
xcb_delete_property,
xcb_change_window_attributes,
xcb_warp_pointer,
xcb_query_pointer,
xcb_query_pointer_reply,
xcb_get_selection_owner_reply,
xcb_get_selection_owner
);

NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(XcbIcccm, system::DefaultFuncPtrLoader,
xcb_icccm_set_wm_hints,
xcb_icccm_size_hints_set_size,
xcb_icccm_size_hints_set_min_size,
xcb_icccm_size_hints_set_max_size,
xcb_icccm_set_wm_normal_hints
);


NBL_API2 static core::smart_refctd_ptr<IWindowManagerXCB> create();
virtual const Xcb& getXcbFunctionTable() const = 0;
virtual const XcbIcccm& getXcbIcccmFunctionTable() const = 0;
};

} // namespace nbl::ui

#endif
#endif
36 changes: 36 additions & 0 deletions include/nbl/ui/IWindowXCB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef __NBL_I_WINDOW_XCB_H_INCLUDED__
#define __NBL_I_WINDOW_XCB_H_INCLUDED__

#include "nbl/ui/XCBHandle.h"
#ifdef _NBL_PLATFORM_LINUX_

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

#include "nbl/ui/IWindow.h"

#include <xcb/xproto.h>

namespace nbl::ui
{

class NBL_API2 IWindowXCB : public IWindow
{
protected:
virtual ~IWindowXCB() = default;
inline IWindowXCB(SCreationParams&& params) : IWindow(std::move(params)) {}

public:
using IWindow::IWindow;

struct native_handle_t {
xcb_window_t m_window;
core::smart_refctd_ptr<xcb::XCBHandle> m_connection;
};

virtual const native_handle_t* getNativeHandle() const = 0;
};

}

#endif
#endif
Loading