Skip to content

Commit 1ac7295

Browse files
committed
updated window manager
1 parent 57074d8 commit 1ac7295

File tree

5 files changed

+54
-138
lines changed

5 files changed

+54
-138
lines changed

include/nbl/ui/CWindowXCB.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ class NBL_API2 CWindowXCB final : public IWindowXCB
3131
virtual ICursorControl* getCursorControl() override;
3232
virtual IWindowManager* getManager() override;
3333

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;
39-
4034
virtual void setCaption(const std::string_view& caption) override;
4135

4236
private:

include/nbl/ui/IWindowXCB.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class NBL_API2 IWindowXCB : public IWindow
2828
};
2929

3030
virtual const native_handle_t* getNativeHandle() const = 0;
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;
3631
};
3732

3833
}

include/nbl/ui/XCBHandle.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ namespace nbl::ui::xcb
210210
xcb_screen_t *screen = xcb.pxcb_setup_roots_iterator(setup).data;
211211
return screen;
212212
}
213+
214+
inline bool checkCookie(XCBHandle& handle, xcb_void_cookie_t cookie) {
215+
auto& xcb = handle.getXcbFunctionTable();
216+
if (xcb_generic_error_t* error = xcb.pxcb_request_check(handle, cookie))
217+
{
218+
printf("XCB error: %d", error->error_code);
219+
return false;
220+
}
221+
return true;
222+
}
223+
213224
}
214225

215226
#endif

src/nbl/ui/CWindowManagerXCB.cpp

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ CWindowManagerXCB::CWindowManagerXCB() {
1919

2020
core::smart_refctd_ptr<IWindow> CWindowManagerXCB::createWindow(IWindow::SCreationParams&& creationParams)
2121
{
22-
// const auto* primaryScreen = m_connection.primaryScreen();
2322
IWindowXCB::native_handle_t windowHandle = {
2423
0,
2524
core::make_smart_refctd_ptr<xcb::XCBHandle>(core::smart_refctd_ptr<CWindowManagerXCB>(this))
@@ -74,43 +73,69 @@ core::smart_refctd_ptr<IWindow> CWindowManagerXCB::createWindow(IWindow::SCreati
7473

7574
bool CWindowManagerXCB::setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) {
7675
auto wnd = static_cast<IWindowXCB*>(window);
77-
wnd->setWindowSize(width, height);
76+
auto* nativeHandle = wnd->getNativeHandle();
77+
78+
xcb_size_hints_t hints = {0};
79+
m_xcbIcccm.pxcb_icccm_size_hints_set_size(&hints, true, width, height);
80+
m_xcbIcccm.pxcb_icccm_size_hints_set_min_size(&hints, width, height);
81+
m_xcbIcccm.pxcb_icccm_size_hints_set_max_size(&hints, width, height);
82+
m_xcbIcccm.pxcb_icccm_set_wm_normal_hints(*nativeHandle->m_connection, nativeHandle->m_window, &hints);
7883
return true;
7984
}
8085

8186
bool CWindowManagerXCB::setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) {
8287
auto wnd = static_cast<IWindowXCB*>(window);
83-
wnd->setWindowPosition(x, y);
84-
return true;
88+
auto* nativeHandle = wnd->getNativeHandle();
89+
90+
const int32_t values[] = { x, y };
91+
auto cookie = m_xcb.pxcb_configure_window_checked(*nativeHandle->m_connection, nativeHandle->m_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
92+
bool check = xcb::checkCookie(*nativeHandle->m_connection, cookie);
93+
m_xcb.pxcb_flush(*nativeHandle->m_connection);
94+
95+
return check;
8596
}
8697

8798
bool CWindowManagerXCB::setWindowRotation_impl(IWindow* window, bool landscape) {
8899
auto wnd = static_cast<IWindowXCB*>(window);
89-
auto* handle = wnd->getNativeHandle();
100+
auto* nativeHandle = wnd->getNativeHandle();
101+
90102

91103
return true;
92104
}
93105

94106
bool CWindowManagerXCB::setWindowVisible_impl(IWindow* window, bool visible) {
95107
auto wnd = static_cast<IWindowXCB*>(window);
96108
auto* handle = wnd->getNativeHandle();
97-
// auto conn = handle->m_connection->getXcbFunctionTable();
98109

99-
// if(visible) {
100-
// xcb.pxcb_map_window(m_connection->getNativeHandle(), m_handle.m_window);
101-
// xcb.pxcb_flush(m_connection->getNativeHandle());
102-
// } else {
103-
// xcb.pxcb_unmap_window(m_connection->getNativeHandle(), m_handle.m_window);
104-
// xcb.pxcb_flush(m_connection->getNativeHandle());
105-
// }
110+
if(visible) {
111+
m_xcb.pxcb_map_window(*handle->m_connection, handle->m_window);
112+
m_xcb.pxcb_flush(*handle->m_connection);
113+
} else {
114+
m_xcb.pxcb_unmap_window(*handle->m_connection, handle->m_window);
115+
m_xcb.pxcb_flush(*handle->m_connection);
116+
}
106117

107-
wnd->setWindowVisible(visible);
108118
return true;
109119
}
110120

111121
bool CWindowManagerXCB::setWindowMaximized_impl(IWindow* window, bool maximized) {
112122
auto wnd = static_cast<IWindowXCB*>(window);
113-
wnd->setWindowMaximized(maximized);
123+
auto* handle = wnd->getNativeHandle();
124+
const auto* primaryScreen = xcb::primaryScreen(*handle->m_connection);
125+
126+
xcb::setNetMWState(
127+
*handle->m_connection,
128+
primaryScreen->root,
129+
handle->m_window, maximized && !wnd->isBorderless(), handle->m_connection->_NET_WM_STATE_FULLSCREEN);
130+
131+
xcb::setNetMWState(
132+
*handle->m_connection,
133+
primaryScreen->root,
134+
handle->m_window, maximized && wnd->isBorderless(),
135+
handle->m_connection->_NET_WM_STATE_MAXIMIZED_VERT,
136+
handle->m_connection->_NET_WM_STATE_MAXIMIZED_HORZ);
137+
138+
m_xcb.pxcb_flush(*handle->m_connection);
114139
return true;
115140
}
116141

src/nbl/ui/CWindowXCB.cpp

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "nbl/ui/IWindowXCB.h"
99
#include "nbl/ui/CWindowXCB.h"
1010
#include "nbl/ui/CCursorControlXCB.h"
11-
// #include "nbl/ui/CClipboardManagerXCB.h"
1211
#include "nbl/ui/CWindowManagerXCB.h"
1312

1413
#include <cstdint>
@@ -96,59 +95,11 @@ CWindowXCB::CWindowXCB(native_handle_t&& handle, core::smart_refctd_ptr<CWindowM
9695
IWindowXCB(std::move(params)),
9796
m_handle(std::move(handle)),
9897
m_windowManager(std::move(winManager)),
99-
// m_connection(core::make_smart_refctd_ptr<XCBConnection>(core::smart_refctd_ptr<CWindowManagerXCB>(m_windowManager))),
100-
// m_cursorControl(core::make_smart_refctd_ptr<CCursorControlXCB>(core::smart_refctd_ptr<XCBConnection>(m_connection))),
10198
m_dispatcher(*this) {
10299

103100
auto& xcb = m_handle.m_connection->getXcbFunctionTable();
104101
auto& xcbIccm = m_handle.m_connection->getXcbIcccmFunctionTable();
105102

106-
// // m_handle.m_connection = m_connection->getRawConnection();
107-
// // m_handle.m_window = xcb.pxcb_generate_id(m_connection->getNativeHandle());
108-
// // m_handle.m_connection = m_connection->getNativeHandle();
109-
110-
// const auto* primaryScreen = xcb::primaryScreen(m_handle.m_connection);
111-
112-
// uint32_t eventMask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
113-
// uint32_t valueList[] = {
114-
// primaryScreen->black_pixel,
115-
// XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE |
116-
// XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_PROPERTY_CHANGE
117-
// };
118-
119-
// xcb_void_cookie_t xcbCheckResult = xcb.pxcb_create_window(
120-
// m_handle.m_connection, XCB_COPY_FROM_PARENT, m_handle.m_window, primaryScreen->root,
121-
// static_cast<int16_t>(m_x),
122-
// static_cast<int16_t>(m_y),
123-
// static_cast<int16_t>(m_width),
124-
// static_cast<int16_t>(m_height), 4,
125-
// XCB_WINDOW_CLASS_INPUT_OUTPUT, primaryScreen->root_visual, eventMask,
126-
// valueList);
127-
128-
// setWindowSize(m_width, m_height);
129-
130-
// auto WM_DELETE_WINDOW = xcb::resolveAtom(m_handle.m_connection, m_WM_DELETE_WINDOW);
131-
// auto NET_WM_PING = xcb::resolveAtom(m_handle.m_connection, m_NET_WM_PING);
132-
// auto WM_PROTOCOLS = xcb::resolveAtom(m_handle.m_connection, m_WM_PROTOCOLS);
133-
134-
// const std::array atoms {WM_DELETE_WINDOW, NET_WM_PING};
135-
// xcb.pxcb_change_property(
136-
// m_handle.m_connection,
137-
// XCB_PROP_MODE_REPLACE,
138-
// m_handle.m_window,
139-
// WM_PROTOCOLS, XCB_ATOM_ATOM, 32, atoms.size(), atoms.data());
140-
141-
142-
// auto motifHints = XCBConnection::createFlagsToMotifWmHints(getFlags().value);
143-
// xcb::setMotifWmHints(m_handle.m_window, motifHints);
144-
145-
// if(isAlwaysOnTop()) {
146-
// XCBConnection::AtomToken<core::StringLiteral("NET_WM_STATE_ABOVE")> NET_WM_STATE_ABOVE;
147-
// m_connection->setNetMWState(
148-
// primaryScreen->root,
149-
// m_handle.m_window, false, m_connection->resolveAtom(NET_WM_STATE_ABOVE));
150-
// }
151-
152103
xcb.pxcb_map_window(*m_handle.m_connection, m_handle.m_window);
153104
xcb.pxcb_flush(*m_handle.m_connection);
154105

@@ -170,71 +121,11 @@ IWindowManager* CWindowXCB::getManager() {
170121
return m_windowManager.get();
171122
}
172123

173-
bool CWindowXCB::setWindowSize(uint32_t width, uint32_t height) {
174-
auto& xcb = m_windowManager->getXcbFunctionTable();
175-
auto& xcbIccm = m_windowManager->getXcbIcccmFunctionTable();
176-
177-
// xcb_size_hints_t hints = {0};
178-
179-
// xcbIccm.pxcb_icccm_size_hints_set_size(&hints, true, width, height);
180-
// xcbIccm.pxcb_icccm_size_hints_set_min_size(&hints, width, height);
181-
// xcbIccm.pxcb_icccm_size_hints_set_max_size(&hints, width, height);
182-
// xcbIccm.pxcb_icccm_set_wm_normal_hints(m_connection->getNativeHandle(), m_handle.m_window, &hints);
183-
return true;
184-
}
185-
186-
bool CWindowXCB::setWindowPosition(int32_t x, int32_t y) {
187-
auto& xcb = m_windowManager->getXcbFunctionTable();
188-
189-
// const int32_t values[] = { x, y };
190-
// auto cookie = xcb.pxcb_configure_window_checked(m_connection->getNativeHandle(), m_handle.m_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
191-
// bool check = checkXcbCookie(xcb, m_connection->getNativeHandle(), cookie);
192-
// xcb.pxcb_flush(m_connection->getNativeHandle());
193-
return true;
194-
}
195-
196124
void CWindowXCB::setCaption(const std::string_view& caption) {
197-
auto& xcb = m_windowManager->getXcbFunctionTable();
198-
199-
// xcb.pxcb_change_property(m_connection->getNativeHandle(), XCB_PROP_MODE_REPLACE, m_handle.m_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, static_cast<uint32_t>(caption.size()), reinterpret_cast<const void* const>(caption.data()));
200-
// xcb.pxcb_flush(m_connection->getNativeHandle());
201-
}
202-
203-
bool CWindowXCB::setWindowRotation(bool landscape) {
204-
return true;
205-
}
206-
207-
bool CWindowXCB::setWindowVisible( bool visible) {
208-
auto& xcb = m_windowManager->getXcbFunctionTable();
209-
210-
// if(visible) {
211-
// xcb.pxcb_map_window(m_connection->getNativeHandle(), m_handle.m_window);
212-
// xcb.pxcb_flush(m_connection->getNativeHandle());
213-
// } else {
214-
// xcb.pxcb_unmap_window(m_connection->getNativeHandle(), m_handle.m_window);
215-
// xcb.pxcb_flush(m_connection->getNativeHandle());
216-
// }
217-
return true;
218-
}
219-
220-
bool CWindowXCB::setWindowMaximized(bool maximized) {
221-
auto& xcb = m_windowManager->getXcbFunctionTable();
222-
// const auto* primaryScreen = m_connection->primaryScreen();
223-
224-
// m_connection->setNetMWState(
225-
// primaryScreen->root,
226-
// m_handle.m_window, maximized && !isBorderless(), m_connection->resolveAtom(m_NET_WM_STATE_FULLSCREEN));
227-
228-
// m_connection->setNetMWState(
229-
// primaryScreen->root,
230-
// m_handle.m_window, maximized && isBorderless(),
231-
// m_connection->resolveAtom(m_NET_WM_STATE_MAXIMIZED_VERT),
232-
// m_connection->resolveAtom(m_NET_WM_STATE_MAXIMIZED_HORZ));
233-
234-
// xcb.pxcb_flush(m_connection->getNativeHandle());
235-
return true;
125+
auto& xcb = m_handle.m_connection->getXcbFunctionTable();
126+
xcb.pxcb_change_property(*m_handle.m_connection, XCB_PROP_MODE_REPLACE, m_handle.m_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, static_cast<uint32_t>(caption.size()), reinterpret_cast<const void* const>(caption.data()));
127+
xcb.pxcb_flush(*m_handle.m_connection);
236128
}
237-
238129
}
239130

240131
#endif

0 commit comments

Comments
 (0)