moving towards rename refactor

dev
Claudius Holeksa 2023-02-25 20:51:56 +01:00
parent fdbe79c882
commit 96e3e9a817
8 changed files with 73 additions and 73 deletions

View File

@ -5,27 +5,27 @@
#include "window_xcb.h"
namespace saw {
XcbDevice::XcbDevice(::Display *display, int screen,
xcb_device::xcb_device(::Display *display, int screen,
xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen,
Own<InputStream> &&an)
own<input_stream> &&an)
: display{display}, screen{screen}, xcb_connection{xcb_connection},
xcb_screen{xcb_screen}, async_notifier{std::move(an)},
async_conveyor{async_notifier->readReady()
.then([this]() { handleEvents(); })
.sink()} {}
XcbDevice::~XcbDevice() {
xcb_device::~xcb_device() {
if (display) {
xcb_flush(xcb_connection);
::XCloseDisplay(display);
}
}
void XcbDevice::windowDestroyed(xcb_window_t window_id) {
void xcb_device::windowDestroyed(xcb_window_t window_id) {
windows.erase(window_id);
}
void XcbDevice::handleEvents() {
void xcb_device::handleEvents() {
while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection)) {
pending_events.push_back(event);
}
@ -128,7 +128,7 @@ void XcbDevice::handleEvents() {
pending_events.clear();
}
Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode &video_mode,
own<xcb_window> xcb_device::create_xcb_window(const video_mode &video_mode,
std::string_view title_view,
int visual_id) {
assert(xcb_screen);
@ -158,25 +158,25 @@ Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode &video_mode,
title_view.data());
xcb_flush(xcb_connection);
auto window = heap<XcbWindow>(*this, xcb_window, xcb_colormap, video_mode,
auto window = heap<xcb_window>(*this, xcb_window, xcb_colormap, video_mode,
title_view);
windows[xcb_window] = window.get();
return window;
}
Own<Window> XcbDevice::createWindow(const VideoMode &video_mode,
own<Window> xcb_device::createWindow(const video_mode &video_mode,
std::string_view title_view) {
assert(xcb_screen);
return createXcbWindow(video_mode, title_view, xcb_screen->root_visual);
return create_xcb_window(video_mode, title_view, xcb_screen->root_visual);
}
void XcbDevice::flush() {
void xcb_device::flush() {
assert(xcb_connection);
xcb_flush(xcb_connection);
}
Own<XcbDevice> createXcbDevice(IoProvider &provider) {
own<xcb_device> create_xcb_device(io_provider &provider) {
::Display *display = ::XOpenDisplay(nullptr);
if (!display) {
/// @todo log errors
@ -194,7 +194,7 @@ Own<XcbDevice> createXcbDevice(IoProvider &provider) {
int fd = xcb_get_file_descriptor(xcb_connection);
Own<InputStream> fd_wrapped = provider.wrapInputFd(fd);
own<input_stream> fd_wrapped = provider.wrapInputFd(fd);
if (!fd_wrapped) {
::XCloseDisplay(display);
return nullptr;
@ -210,11 +210,11 @@ Own<XcbDevice> createXcbDevice(IoProvider &provider) {
xcb_screen_t *xcb_screen = screen_iter.data;
return heap<XcbDevice>(display, screen, xcb_connection, xcb_screen,
return heap<xcb_device>(display, screen, xcb_connection, xcb_screen,
std::move(fd_wrapped));
}
Own<Device> createDevice(IoProvider &provider) {
return createXcbDevice(provider);
own<device> createdevice(io_provider &provider) {
return create_xcb_device(provider);
}
} // namespace saw

View File

@ -64,7 +64,7 @@ int translateDrawableTypeSetting(GlSettings::DrawableType cmp) {
} // namespace
XcbGlContext::XcbGlContext(const GlxLibraryExtensions &ext_lib,
Own<XcbDevice> &&dev, int visual_id,
own<xcb_device> &&dev, int visual_id,
GLXContext context, GLXFBConfig fb_config)
: ext_lib{ext_lib}, device{std::move(dev)}, visual_id{visual_id},
context{context}, fb_config{fb_config} {}
@ -79,14 +79,14 @@ XcbGlContext::~XcbGlContext() {
device->flush();
}
Own<GlWindow> XcbGlContext::createWindow(const VideoMode &video_mode,
own<GlWindow> XcbGlContext::createWindow(const video_mode &video_mode,
std::string_view title_view) {
assert(device);
if (!device) {
return nullptr;
}
Own<XcbWindow> window =
device->createXcbWindow(video_mode, title_view, visual_id);
own<xcb_window> window =
device->create_xcb_window(video_mode, title_view, visual_id);
if (!window) {
return nullptr;
}
@ -104,9 +104,9 @@ void XcbGlContext::flush() {
}
}
Own<GlContext> createGlContext(IoProvider &provider,
own<GlContext> createGlContext(io_provider &provider,
const GlSettings &settings) {
Own<XcbDevice> device = createXcbDevice(provider);
own<xcb_device> device = create_xcb_device(provider);
if (!device) {
return nullptr;
}

View File

@ -16,21 +16,21 @@ public:
Bool, const int *) = nullptr;
};
class XcbDevice;
class xcb_device;
class XcbGlContext final : public GlContext {
public:
GlxLibraryExtensions ext_lib;
Own<XcbDevice> device;
own<xcb_device> device;
int visual_id;
GLXContext context;
GLXFBConfig fb_config;
public:
XcbGlContext(const GlxLibraryExtensions &, Own<XcbDevice> &&, int,
XcbGlContext(const GlxLibraryExtensions &, own<xcb_device> &&, int,
GLXContext, GLXFBConfig);
~XcbGlContext();
Own<GlWindow> createWindow(const VideoMode &, std::string_view) override;
own<GlWindow> createWindow(const video_mode &, std::string_view) override;
void flush() override;
};

View File

@ -8,7 +8,7 @@
#include <cassert>
namespace saw {
XcbGlWindow::XcbGlWindow(Own<XcbWindow> &&win, XcbGlContext &ctx,
XcbGlWindow::XcbGlWindow(own<xcb_window> &&win, XcbGlContext &ctx,
::GLXWindow glx_win)
: window{std::move(win)}, context{ctx}, glx_window{glx_win} {}
@ -51,7 +51,7 @@ void XcbGlWindow::swap() {
}
}
const VideoMode &XcbGlWindow::videoMode() const {
const video_mode &XcbGlWindow::videoMode() const {
assert(window);
return window->videoMode();
}

View File

@ -6,17 +6,17 @@
#include "forstio/window/gl/gl_window.h"
namespace saw {
class XcbWindow;
class xcb_window;
class XcbGlContext;
class XcbGlWindow final : public GlWindow {
public:
Own<XcbWindow> window;
own<xcb_window> window;
XcbGlContext &context;
::GLXWindow glx_window;
public:
XcbGlWindow(Own<XcbWindow> &&, XcbGlContext &, ::GLXWindow);
XcbGlWindow(own<xcb_window> &&, XcbGlContext &, ::GLXWindow);
~XcbGlWindow();
void bind() override;
@ -24,7 +24,7 @@ public:
void show() override;
void hide() override;
const VideoMode &videoMode() const override;
const video_mode &videoMode() const override;
const std::string_view title() const override;
void resize(size_t height, size_t width) override;

View File

@ -5,55 +5,55 @@
#include "device_xcb.h"
namespace saw {
XcbWindow::XcbWindow(XcbDevice &device, xcb_window_t xcb_window,
xcb_colormap_t xcb_colormap, const VideoMode &video_mode,
std::string_view title_view)
: device{device}, xcb_window{xcb_window}, xcb_colormap{xcb_colormap},
video_mode{video_mode}, window_title{title_view} {}
xcb_window::xcb_window(xcb_device &dev, xcb_window_t xcb_win,
xcb_colormap_t xcb_colmap, const video_mode &vid_mode,
std::string_view title_view_)
: device_{dev}, xcb_window_{xcb_win}, xcb_colormap_{xcb_colmap},
video_mode_{vid_mode}, window_title_{title_view_} {}
XcbWindow::~XcbWindow() {
device.windowDestroyed(xcb_window);
xcb_destroy_window(device.xcb_connection, xcb_window);
device.flush();
xcb_window::~xcb_window() {
device_.windowDestroyed(xcb_window_);
xcb_destroy_window(device_.xcb_connection, xcb_window_);
device_.flush();
}
void XcbWindow::show() {
assert(device.xcb_connection);
xcb_map_window(device.xcb_connection, xcb_window);
void xcb_window::show() {
assert(device_.xcb_connection);
xcb_map_window(device_.xcb_connection, xcb_window_);
}
void XcbWindow::hide() {
assert(device.xcb_connection);
xcb_unmap_window(device.xcb_connection, xcb_window);
void xcb_window::hide() {
assert(device_.xcb_connection);
xcb_unmap_window(device_.xcb_connection, xcb_window_);
}
const VideoMode &XcbWindow::videoMode() const { return video_mode; }
const video_mode &xcb_window::videoMode() const { return video_mode_; }
const std::string_view XcbWindow::title() const { return window_title; }
const std::string_view xcb_window::title() const { return window_title_; }
void XcbWindow::resize(size_t width, size_t height) {
void xcb_window::resize(size_t width, size_t height) {
const uint32_t values[2] = {static_cast<uint32_t>(width),
static_cast<uint32_t>(height)};
xcb_configure_window(device.xcb_connection, xcb_window,
xcb_configure_window(device_.xcb_connection, xcb_window_,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values);
video_mode.width = width;
video_mode.height = height;
video_mode_.width = width;
video_mode_.height = height;
}
Conveyor<Window::VariantEvent> XcbWindow::onEvent() {
Conveyor<Window::VariantEvent> xcb_window::onEvent() {
auto caf = newConveyorAndFeeder<Window::VariantEvent>();
event_feeder = std::move(caf.feeder);
return std::move(caf.conveyor);
}
void XcbWindow::resizeEvent(size_t x, size_t y, size_t width, size_t height) {
void xcb_window::resizeEvent(size_t x, size_t y, size_t width, size_t height) {
(void)x;
(void)y;
/// @todo maybe include x and y?
video_mode.width = width;
video_mode.height = height;
video_mode_.width = width;
video_mode_.height = height;
if (event_feeder) {
event_feeder->feed(
@ -61,13 +61,13 @@ void XcbWindow::resizeEvent(size_t x, size_t y, size_t width, size_t height) {
}
}
void XcbWindow::mouseEvent(int16_t x, int16_t y, uint16_t state, bool pressed) {
void xcb_window::mouseEvent(int16_t x, int16_t y, uint16_t state, bool pressed) {
if (x < 0 || y < 0) {
return;
}
uint32_t ux = static_cast<uint32_t>(x);
uint32_t uy = static_cast<uint32_t>(y);
if (ux >= video_mode.width || uy >= video_mode.height) {
if (ux >= video_mode_.width || uy >= video_mode_.height) {
return;
}
if (event_feeder) {
@ -76,13 +76,13 @@ void XcbWindow::mouseEvent(int16_t x, int16_t y, uint16_t state, bool pressed) {
}
}
void XcbWindow::mouseMoveEvent(int16_t x, int16_t y) {
void xcb_window::mouseMoveEvent(int16_t x, int16_t y) {
if (x < 0 || y < 0) {
return;
}
uint32_t ux = static_cast<uint32_t>(x);
uint32_t uy = static_cast<uint32_t>(y);
if (ux >= video_mode.width || uy >= video_mode.height) {
if (ux >= video_mode_.width || uy >= video_mode_.height) {
return;
}
if (event_feeder) {
@ -91,14 +91,14 @@ void XcbWindow::mouseMoveEvent(int16_t x, int16_t y) {
}
}
void XcbWindow::keyboardEvent(int16_t x, int16_t y, uint32_t keycode,
void xcb_window::keyboardEvent(int16_t x, int16_t y, uint32_t keycode,
bool pressed, bool repeat) {
if (x < 0 || y < 0) {
return;
}
uint32_t ux = static_cast<uint32_t>(x);
uint32_t uy = static_cast<uint32_t>(y);
if (ux >= video_mode.width || uy >= video_mode.height) {
if (ux >= video_mode_.width || uy >= video_mode_.height) {
return;
}
if (event_feeder) {

View File

@ -12,20 +12,20 @@ namespace saw {
class xcb_device;
class xcb_window final : public window {
public:
xcb_device &device;
xcb_device &device_;
xcb_window_t xcb_window;
xcb_colormap_t xcb_colormap;
xcb_window_t xcb_window_;
xcb_colormap_t xcb_colormap_;
video_mode video_mode;
std::string window_title;
video_mode video_mode_;
std::string window_title_;
own<conveyor_feeder<window::variant_event>> event_feeder = nullptr;
public:
xcb_window(xcb_device &device, xcb_window_t xcb_window,
xcb_colormap_t xcb_colormap, const video_mode &video_mode,
std::string_view title_view);
xcb_window(xcb_device &dev, xcb_window_t xcb_win,
xcb_colormap_t xcb_colormap_, const video_mode &video_mode_,
std::string_view title_view_);
~xcb_window();
void show() override;

View File

@ -51,11 +51,11 @@ class GlContext {
public:
virtual ~GlContext() = default;
virtual Own<GlWindow> createWindow(const VideoMode &, std::string_view) = 0;
virtual own<GlWindow> createWindow(const video_mode &, std::string_view) = 0;
virtual void flush() = 0;
};
class IoProvider;
Own<GlContext> createGlContext(IoProvider &, const GlSettings &);
class io_provider;
own<GlContext> createGlContext(io_provider &, const GlSettings &);
} // namespace saw