Compare commits

...

24 Commits

Author SHA1 Message Date
Claudius Holeksa 0a0f06c925 c++: Moved to new lib dep structure 2023-04-02 20:19:26 +02:00
Claudius Holeksa 7f5b37f3ef executed clang-format 2023-03-04 17:40:57 +01:00
Claudius Holeksa e73e31e876 applying more refactor changes 2023-02-26 19:37:34 +01:00
Claudius Holeksa 80e8f7f0fd binary file 2023-02-26 12:57:58 +01:00
Claudius Holeksa 0605ea1e3d tidy file and cdb target 2023-02-25 22:45:52 +01:00
Claudius Holeksa 882c694510 refactor rename 2023-02-25 22:28:10 +01:00
Claudius Holeksa 96e3e9a817 moving towards rename refactor 2023-02-25 20:51:56 +01:00
Claudius Holeksa fdbe79c882 moving to snake_case 2023-02-23 13:09:15 +01:00
Claudius Holeksa 898b6afbaa changing gl_window 2023-02-19 17:50:45 +01:00
Claudius Holeksa b6ffb77922 changed names in window 2023-02-19 17:48:38 +01:00
Claudius Holeksa 0d25c3c74b gitignore 2023-02-19 17:46:49 +01:00
Claudius Holeksa a48919b95d first changes 2023-02-16 15:28:11 +01:00
Claudius Holeksa 2281b46406 maybe release.nix is fixed now? 2023-02-02 18:08:54 +01:00
Claudius Holeksa fcd4b50cb1 maybe release.nix is fixed now? 2023-02-02 18:06:40 +01:00
Claudius Holeksa 1637cbbb5b maybe release.nix is fixed now? 2023-02-02 18:05:29 +01:00
Claudius Holeksa 833ac97341 maybe release.nix is fixed now? 2023-02-02 18:04:18 +01:00
Claudius Holeksa 001216410d maybe release.nix is fixed now? 2023-02-02 18:03:47 +01:00
Claudius Holeksa cc7c7e37f5 maybe release.nix is fixed now? 2023-02-02 18:02:56 +01:00
Claudius Holeksa b04614af59 maybe release.nix is fixed now? 2023-02-02 18:01:43 +01:00
Claudius Holeksa aabb089f90 maybe release.nix is fixed now? 2023-02-02 17:58:52 +01:00
Claudius Holeksa e4f0828e33 maybe release.nix is fixed now? 2023-02-02 17:55:25 +01:00
Claudius Holeksa 73b68d4907 maybe release.nix is fixed now? 2023-02-02 17:54:41 +01:00
Claudius Holeksa 87376572a7 added nix files 2023-02-02 17:46:44 +01:00
Claudius Holeksa 05cc0f2c97 added nix files 2023-02-02 17:40:41 +01:00
19 changed files with 252 additions and 196 deletions

9
.clang-tidy Normal file
View File

@ -0,0 +1,9 @@
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.PrivateMemberSuffix, value: "_" }
- { key: readability-identifier-naming.AggressiveDependentMemberLookup, value: true }
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: "_" }
- { key: readability-identifier-naming.ClassCase, value: "lower_case" }
- { key: readability-identifier-naming.StructCase, value: "lower_case" }
- { key: readability-identifier-naming.FunctionCase, value: "lower_case" }
- { key: readability-identifier-naming.MethodCase, value: "lower_case" }

2
.gitignore vendored
View File

@ -59,6 +59,7 @@ dkms.conf
# binary files
bin/
result
# test files
assets/
# custom build tracking
@ -70,3 +71,4 @@ thoughts
*.swp
vgcore.*
*.pdf

View File

@ -7,7 +7,9 @@
, clang_12
, clang-tools
, gnutls
, keldu
, forstio
, xorg
, libGL
}:
stdenvNoCC.mkDerivation {
@ -21,7 +23,12 @@ stdenvNoCC.mkDerivation {
];
buildInputs = [
keldu.forstio
forstio.core
forstio.async
forstio.io
xorg.libxcb
xorg.libX11
libGL
];
src = ./..;

View File

@ -1,9 +1,16 @@
{ ... }:
{ nixpkgs ? <nixpkgs>
, forstio ? { outPath = ./.; }
, ...
}:
let
pkgs = (import <nixpkgs>{});
pkgs = import nixpkgs {};
forstioJobset = import "${forstio}/.nix/release.nix" {};
in
{
keldu = {
forstio-window = pkgs.callPackage ./derivation.nix {};
forstio-window = pkgs.callPackage ./derivation.nix {
forstio = forstioJobset.forstio;
};
};
}

View File

@ -42,12 +42,14 @@ env_vars.Add('prefix',
validator=isAbsolutePath
)
env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=['#source','#','#driver'],
env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=['#source','#driver'],
CXX='clang++',
CPPDEFINES=['SAW_UNIX_XCB'],
CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
LIBS=['forstio','xcb','X11','X11-xcb'])
LIBS=['forstio-core','forstio-async','forstio-io','xcb','X11','X11-xcb'])
env.__class__.add_source_files = add_kel_source_files
env.Tool('compilation_db');
env.cdb = env.CompilationDatabase('compile_commands.json');
env.sources = []
env.headers = []
@ -96,6 +98,7 @@ format_iter(env,env.sources + env.headers + env.gl_sources + env.gl_headers)
env.Alias('format', env.format_actions)
env.Alias('cdb', env.cdb);
env.Alias('all', ['format', 'library_shared', 'library_static'])
env.Install('$prefix/lib/', [env.library_shared, env.library_static])

View File

@ -1,3 +1,25 @@
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {}
}:
pkgs.callPackage ./.nix/derivation.nix {}
let
forstio = {
core =
import ((builtins.fetchGit {
url = "gitea@git.keldu.de:forstio/forstio-core.git";
ref = "master";
}).outPath + "/default.nix") {};
async =
import ((builtins.fetchGit {
url = "gitea@git.keldu.de:forstio/forstio-async.git";
ref = "master";
}).outPath + "/default.nix") {};
io =
import ((builtins.fetchGit {
url = "gitea@git.keldu.de:forstio/forstio-io.git";
ref = "master";
}).outPath + "/default.nix") {};
};
in
pkgs.callPackage ./.nix/derivation.nix {
inherit forstio;
}

View File

@ -5,27 +5,27 @@
#include "window_xcb.h"
namespace saw {
XcbDevice::XcbDevice(::Display *display, int screen,
xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen,
Own<InputStream> &&an)
xcb_device::xcb_device(::Display *display, int screen,
xcb_connection_t *xcb_connection,
xcb_screen_t *xcb_screen, 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(); })
async_conveyor{async_notifier->read_ready()
.then([this]() { handle_events(); })
.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::window_destroyed(xcb_window_t window_id) {
windows.erase(window_id);
}
void XcbDevice::handleEvents() {
void xcb_device::handle_events() {
while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection)) {
pending_events.push_back(event);
}
@ -38,7 +38,8 @@ void XcbDevice::handleEvents() {
auto find = windows.find(motion->event);
if (find != windows.end()) {
assert(find->second);
find->second->mouseMoveEvent(motion->event_x, motion->event_y);
find->second->mouse_move_event(motion->event_x,
motion->event_y);
}
} break;
case XCB_EXPOSE: {
@ -47,7 +48,7 @@ void XcbDevice::handleEvents() {
auto find = windows.find(expose->window);
if (find != windows.end()) {
assert(find->second);
find->second->resizeEvent(static_cast<size_t>(expose->x),
find->second->resizeevent(static_cast<size_t>(expose->x),
static_cast<size_t>(expose->y),
static_cast<size_t>(expose->width),
static_cast<size_t>(expose->height));
@ -59,7 +60,7 @@ void XcbDevice::handleEvents() {
auto find = windows.find(button->event);
if (find != windows.end()) {
assert(find->second);
find->second->mouseEvent(button->event_x, button->event_y,
find->second->mouseevent(button->event_x, button->event_y,
button->detail, false);
}
} break;
@ -69,7 +70,7 @@ void XcbDevice::handleEvents() {
auto find = windows.find(button->event);
if (find != windows.end()) {
assert(find->second);
find->second->mouseEvent(button->event_x, button->event_y,
find->second->mouseevent(button->event_x, button->event_y,
button->detail, true);
}
} break;
@ -103,7 +104,7 @@ void XcbDevice::handleEvents() {
auto find = windows.find(key->event);
if (find != windows.end()) {
assert(find->second);
find->second->keyboardEvent(key->event_x, key->event_y,
find->second->keyboardevent(key->event_x, key->event_y,
key->detail, repeat, repeat);
}
} break;
@ -113,7 +114,7 @@ void XcbDevice::handleEvents() {
auto find = windows.find(key->event);
if (find != windows.end()) {
assert(find->second);
find->second->keyboardEvent(key->event_x, key->event_y,
find->second->keyboardevent(key->event_x, key->event_y,
key->detail, true, false);
}
} break;
@ -128,9 +129,9 @@ void XcbDevice::handleEvents() {
pending_events.clear();
}
Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode &video_mode,
std::string_view title_view,
int visual_id) {
own<xcb_window> xcb_device::create_xcb_window(const video_mode &video_mode,
std::string_view title_view,
int visual_id) {
assert(xcb_screen);
assert(xcb_connection);
@ -158,25 +159,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,
title_view);
auto window = heap<class 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,
std::string_view title_view) {
own<window> xcb_device::create_window(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 +195,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.wrap_input_fd(fd);
if (!fd_wrapped) {
::XCloseDisplay(display);
return nullptr;
@ -210,11 +211,11 @@ Own<XcbDevice> createXcbDevice(IoProvider &provider) {
xcb_screen_t *xcb_screen = screen_iter.data;
return heap<XcbDevice>(display, screen, xcb_connection, xcb_screen,
std::move(fd_wrapped));
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

@ -2,7 +2,7 @@
#include <X11/Xlib-xcb.h>
#include <X11/Xlib.h>
#include <forstio/io.h>
#include <forstio/io/io.h>
#include <xcb/xcb.h>
#include <map>
@ -12,7 +12,7 @@
#include "window_xcb.h"
namespace saw {
class XcbDevice final : public Device {
class xcb_device final : public device {
public:
::Display *display;
int screen;
@ -20,28 +20,29 @@ public:
xcb_connection_t *xcb_connection;
xcb_screen_t *xcb_screen;
Own<InputStream> async_notifier;
SinkConveyor async_conveyor;
own<input_stream> async_notifier;
conveyor_sink async_conveyor;
std::map<xcb_window_t, XcbWindow *> windows;
std::map<xcb_window_t, xcb_window *> windows;
std::vector<xcb_generic_event_t *> pending_events;
public:
XcbDevice(::Display *display, int screen, xcb_connection_t *xcb_connection,
xcb_screen_t *xcb_screen, Own<InputStream> &&an);
~XcbDevice();
xcb_device(::Display *display, int screen, xcb_connection_t *xcb_connection,
xcb_screen_t *xcb_screen, own<input_stream> &&an);
~xcb_device();
void windowDestroyed(xcb_window_t window_id);
void handleEvents();
void window_destroyed(xcb_window_t window_id);
void handle_events();
Own<XcbWindow> createXcbWindow(const VideoMode &mode,
std::string_view title_view, int visual_id);
Own<Window> createWindow(const VideoMode &video_mode,
std::string_view title_view) override;
own<xcb_window> create_xcb_window(const video_mode &mode,
std::string_view title_view,
int visual_id);
own<window> create_window(const video_mode &video_mode,
std::string_view title_view) override;
void flush() override;
};
Own<XcbDevice> createXcbDevice(IoProvider &provider);
own<xcb_device> create_xcb_device(io_provider &provider);
} // namespace saw

View File

@ -12,7 +12,8 @@
namespace saw {
namespace {
GlxLibraryExtensions glxLibraryExtensions(const char *extension_string) {
glx_library_extensions
load_glx_library_extensions(const char *extension_string) {
std::string_view extensions_view{extension_string};
std::set<std::string_view> extensions;
while (1) {
@ -37,7 +38,7 @@ GlxLibraryExtensions glxLibraryExtensions(const char *extension_string) {
}
return {extensions_view, glXCreateContextAttribsARB};
}
int translateRenderTypeSetting(GlSettings::RenderType cmp) {
int translate_render_type_setting(GlSettings::RenderType cmp) {
switch (cmp) {
case GlSettings::RenderType::RGBA:
return GLX_RGBA_BIT;
@ -45,10 +46,10 @@ int translateRenderTypeSetting(GlSettings::RenderType cmp) {
}
return 0;
}
int translateDrawableTypeSetting(GlSettings::DrawableType cmp) {
int translate_drawable_type_setting(GlSettings::DrawableType cmp) {
int i = 0;
if (static_cast<int32_t>(cmp) &
static_cast<int32_t>(GlSettings::DrawableType::WindowBit)) {
static_cast<int32_t>(GlSettings::DrawableType::windowBit)) {
i |= static_cast<int32_t>(GLX_WINDOW_BIT);
}
if (static_cast<int32_t>(cmp) &
@ -63,13 +64,13 @@ int translateDrawableTypeSetting(GlSettings::DrawableType cmp) {
}
} // namespace
XcbGlContext::XcbGlContext(const GlxLibraryExtensions &ext_lib,
Own<XcbDevice> &&dev, int visual_id,
GLXContext context, GLXFBConfig fb_config)
xcb_gl_context::xcb_gl_context(const glx_library_extensions &ext_lib,
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} {}
XcbGlContext::~XcbGlContext() {
xcb_gl_context::~xcb_gl_context() {
assert(device);
assert(device->display);
if (context) {
@ -79,34 +80,34 @@ XcbGlContext::~XcbGlContext() {
device->flush();
}
Own<GlWindow> XcbGlContext::createWindow(const VideoMode &video_mode,
std::string_view title_view) {
own<gl_window> xcb_gl_context::create_window(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;
}
::GLXWindow glx_window = glXCreateWindow(device->display, fb_config,
window->xcb_window, nullptr);
window->xcb_window_, nullptr);
return heap<XcbGlWindow>(std::move(window), *this, glx_window);
return heap<xcb_gl_window>(std::move(window), *this, glx_window);
}
void XcbGlContext::flush() {
void xcb_gl_context::flush() {
assert(device);
if (device) {
device->flush();
}
}
Own<GlContext> createGlContext(IoProvider &provider,
const GlSettings &settings) {
Own<XcbDevice> device = createXcbDevice(provider);
own<gl_context> creategl_context(io_provider &provider,
const GlSettings &settings) {
own<xcb_device> device = create_xcb_device(provider);
if (!device) {
return nullptr;
}
@ -121,7 +122,7 @@ Own<GlContext> createGlContext(IoProvider &provider,
attributes.push_back(settings.renderable ? True : False);
attributes.push_back(GLX_RENDER_TYPE);
attributes.push_back(translateRenderTypeSetting(settings.render_type));
attributes.push_back(translate_render_type_setting(settings.render_type));
attributes.push_back(GLX_RED_SIZE);
attributes.push_back(settings.red_bits);
@ -145,7 +146,8 @@ Own<GlContext> createGlContext(IoProvider &provider,
attributes.push_back(settings.double_buffer ? True : False);
attributes.push_back(GLX_DRAWABLE_TYPE);
attributes.push_back(translateDrawableTypeSetting(settings.drawable_type));
attributes.push_back(
translate_drawable_type_setting(settings.drawable_type));
attributes.push_back(GLX_X_VISUAL_TYPE);
attributes.push_back(GLX_TRUE_COLOR);
@ -154,7 +156,7 @@ Own<GlContext> createGlContext(IoProvider &provider,
int num_fb_configs = 0;
GlxLibraryExtensions lib_ext = glxLibraryExtensions(
glx_library_extensions lib_ext = load_glx_library_extensions(
glXQueryExtensionsString(device->display, device->screen));
GLXFBConfig *fb_configs = glXChooseFBConfig(
@ -192,8 +194,8 @@ Own<GlContext> createGlContext(IoProvider &provider,
int visual_id = 0;
glXGetFBConfigAttrib(device->display, fb_config, GLX_VISUAL_ID,
&visual_id);
return heap<XcbGlContext>(lib_ext, std::move(device), visual_id,
context, fb_config);
return heap<xcb_gl_context>(lib_ext, std::move(device), visual_id,
context, fb_config);
}
return nullptr;

View File

@ -8,7 +8,7 @@
#include "forstio/window/gl/gl_context.h"
namespace saw {
struct GlxLibraryExtensions {
struct glx_library_extensions {
public:
std::string_view raw_extension_string;
@ -16,21 +16,21 @@ public:
Bool, const int *) = nullptr;
};
class XcbDevice;
class XcbGlContext final : public GlContext {
class xcb_device;
class xcb_gl_context final : public gl_context {
public:
GlxLibraryExtensions ext_lib;
Own<XcbDevice> device;
glx_library_extensions ext_lib;
own<xcb_device> device;
int visual_id;
GLXContext context;
GLXFBConfig fb_config;
public:
XcbGlContext(const GlxLibraryExtensions &, Own<XcbDevice> &&, int,
GLXContext, GLXFBConfig);
~XcbGlContext();
xcb_gl_context(const glx_library_extensions &, own<xcb_device> &&, int,
GLXContext, GLXFBConfig);
~xcb_gl_context();
Own<GlWindow> createWindow(const VideoMode &, std::string_view) override;
own<gl_window> create_window(const video_mode &, std::string_view) override;
void flush() override;
};

View File

@ -8,18 +8,18 @@
#include <cassert>
namespace saw {
XcbGlWindow::XcbGlWindow(Own<XcbWindow> &&win, XcbGlContext &ctx,
::GLXWindow glx_win)
xcb_gl_window::xcb_gl_window(own<xcb_window> &&win, xcb_gl_context &ctx,
::GLXWindow glx_win)
: window{std::move(win)}, context{ctx}, glx_window{glx_win} {}
XcbGlWindow::~XcbGlWindow() {
xcb_gl_window::~xcb_gl_window() {
assert(context.device);
if (context.device) {
::glXDestroyWindow(context.device->display, glx_window);
}
}
void XcbGlWindow::bind() {
void xcb_gl_window::bind() {
assert(window && context.device && context.device->display);
if (window) {
if (context.device && context.device->display) {
@ -29,21 +29,21 @@ void XcbGlWindow::bind() {
}
}
void XcbGlWindow::show() {
void xcb_gl_window::show() {
assert(window);
if (window) {
window->show();
}
}
void XcbGlWindow::hide() {
void xcb_gl_window::hide() {
assert(window);
if (window) {
window->hide();
}
}
void XcbGlWindow::swap() {
void xcb_gl_window::swap() {
assert(context.device);
assert(context.device->display);
if (context.device && context.device->display) {
@ -51,28 +51,28 @@ void XcbGlWindow::swap() {
}
}
const VideoMode &XcbGlWindow::videoMode() const {
const video_mode &xcb_gl_window::videoMode() const {
assert(window);
return window->videoMode();
}
const std::string_view XcbGlWindow::title() const {
const std::string_view xcb_gl_window::title() const {
assert(window);
if (window) {
return window->title();
}
return "Bad Window";
return "Bad window";
}
void XcbGlWindow::resize(size_t height, size_t width) {
void xcb_gl_window::resize(size_t height, size_t width) {
assert(window);
if (window) {
window->resize(height, width);
}
}
Conveyor<Window::VariantEvent> XcbGlWindow::onEvent() {
conveyor<window::variant_event> xcb_gl_window::onevent() {
assert(window);
return window->onEvent();
return window->onevent();
}
} // namespace saw

View File

@ -6,29 +6,29 @@
#include "forstio/window/gl/gl_window.h"
namespace saw {
class XcbWindow;
class XcbGlContext;
class XcbGlWindow final : public GlWindow {
class xcb_window;
class xcb_gl_context;
class xcb_gl_window final : public gl_window {
public:
Own<XcbWindow> window;
XcbGlContext &context;
own<xcb_window> window;
xcb_gl_context &context;
::GLXWindow glx_window;
public:
XcbGlWindow(Own<XcbWindow> &&, XcbGlContext &, ::GLXWindow);
~XcbGlWindow();
xcb_gl_window(own<xcb_window> &&, xcb_gl_context &, ::GLXWindow);
~xcb_gl_window();
void bind() override;
void swap() override;
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;
Conveyor<Window::VariantEvent> onEvent() override;
conveyor<window::variant_event> onevent() override;
};
} // namespace saw

View File

@ -5,105 +5,106 @@
#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_.window_destroyed(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() {
auto caf = newConveyorAndFeeder<Window::VariantEvent>();
conveyor<window::variant_event> xcb_window::onevent() {
auto caf = new_conveyor_and_feeder<window::variant_event>();
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(
Window::VariantEvent{Window::Event::Resize{width, height}});
window::variant_event{window::event::resize{width, 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) {
event_feeder->feed(
Window::VariantEvent{Window::Event::Mouse{state, pressed, ux, uy}});
event_feeder->feed(window::variant_event{
window::event::mouse{state, pressed, ux, uy}});
}
}
void XcbWindow::mouseMoveEvent(int16_t x, int16_t y) {
void xcb_window::mouse_move_event(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) {
event_feeder->feed(
Window::VariantEvent{Window::Event::MouseMove{ux, uy}});
window::variant_event{window::event::mouse_move{ux, uy}});
}
}
void XcbWindow::keyboardEvent(int16_t x, int16_t y, uint32_t keycode,
bool pressed, bool repeat) {
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) {
event_feeder->feed(Window::VariantEvent{
Window::Event::Keyboard{keycode, keycode, pressed, repeat}});
event_feeder->feed(window::variant_event{
window::event::keyboard{keycode, keycode, pressed, repeat}});
}
}

View File

@ -9,39 +9,39 @@
#include "forstio/window/window.h"
namespace saw {
class XcbDevice;
class XcbWindow final : public Window {
class xcb_device;
class xcb_window final : public window {
public:
XcbDevice &device;
xcb_device &device_;
xcb_window_t xcb_window;
xcb_colormap_t xcb_colormap;
xcb_window_t xcb_window_;
xcb_colormap_t xcb_colormap_;
VideoMode video_mode;
std::string window_title;
video_mode video_mode_;
std::string window_title_;
Own<ConveyorFeeder<Window::VariantEvent>> event_feeder = nullptr;
own<conveyor_feeder<window::variant_event>> event_feeder = nullptr;
public:
XcbWindow(XcbDevice &device, xcb_window_t xcb_window,
xcb_colormap_t xcb_colormap, const VideoMode &video_mode,
std::string_view title_view);
~XcbWindow();
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;
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 width, size_t height) override;
Conveyor<Window::VariantEvent> onEvent() override;
conveyor<window::variant_event> onevent() override;
void resizeEvent(size_t x, size_t y, size_t width, size_t height);
void mouseEvent(int16_t x, int16_t y, uint16_t state, bool pressed);
void mouseMoveEvent(int16_t x, int16_t y);
void keyboardEvent(int16_t x, int16_t y, uint32_t keycode, bool pressed,
void resizeevent(size_t x, size_t y, size_t width, size_t height);
void mouseevent(int16_t x, int16_t y, uint16_t state, bool pressed);
void mouse_move_event(int16_t x, int16_t y);
void keyboardevent(int16_t x, int16_t y, uint32_t keycode, bool pressed,
bool repeat);
};
} // namespace saw

View File

@ -1,6 +1,6 @@
#pragma once
#include <forstio/async.h>
#include <forstio/async/async.h>
#include <forstio/common.h>
#include <string_view>
@ -9,15 +9,15 @@
#include "window.h"
namespace saw {
class Device {
class device {
public:
virtual ~Device() = default;
virtual ~device() = default;
virtual Own<Window> createWindow(const VideoMode &mode,
std::string_view title_view) = 0;
virtual own<window> create_window(const video_mode &mode,
std::string_view title_view) = 0;
virtual void flush() = 0;
};
class IoProvider;
Own<Device> createDevice(IoProvider &provider);
class io_provider;
own<device> create_device(io_provider &provider);
} // namespace saw

View File

@ -27,11 +27,11 @@ public:
/// glcontext-xcb.cpp and other occurences
/// Alternatively implement bitwise operations & and |
enum class DrawableType : int32_t {
WindowBit = 0x01,
windowBit = 0x01,
PixMapBit = 0x02,
PBufferBit = 0x04
};
DrawableType drawable_type = DrawableType::WindowBit;
DrawableType drawable_type = DrawableType::windowBit;
bool double_buffer = true;
@ -47,15 +47,16 @@ public:
bool core_profile = true;
};
class GlContext {
class gl_context {
public:
virtual ~GlContext() = default;
virtual ~gl_context() = default;
virtual Own<GlWindow> createWindow(const VideoMode &, std::string_view) = 0;
virtual own<gl_window> create_window(const video_mode &,
std::string_view) = 0;
virtual void flush() = 0;
};
class IoProvider;
Own<GlContext> createGlContext(IoProvider &, const GlSettings &);
class io_provider;
own<gl_context> creategl_context(io_provider &, const GlSettings &);
} // namespace saw

View File

@ -3,14 +3,14 @@
#include "../video_mode.h"
#include "../window.h"
#include <forstio/async.h>
#include <forstio/async/async.h>
#include <string_view>
namespace saw {
class GlWindow {
class gl_window {
public:
virtual ~GlWindow() = default;
virtual ~gl_window() = default;
/*
* Bind the current window as the default framebuffer target (id 0)
@ -21,11 +21,11 @@ public:
virtual void hide() = 0;
virtual void swap() = 0;
virtual const VideoMode &videoMode() const = 0;
virtual const video_mode &videoMode() const = 0;
virtual const std::string_view title() const = 0;
virtual void resize(size_t height, size_t width) = 0;
virtual Conveyor<Window::VariantEvent> onEvent() = 0;
virtual conveyor<window::variant_event> onevent() = 0;
};
} // namespace saw

View File

@ -3,7 +3,7 @@
#include <cstddef>
namespace saw {
class VideoMode {
class video_mode {
public:
size_t width = 128;
size_t height = 128;

View File

@ -1,6 +1,6 @@
#pragma once
#include <forstio/async.h>
#include <forstio/async/async.h>
#include <forstio/common.h>
#include <string_view>
@ -10,48 +10,48 @@
namespace saw {
class Window {
class window {
public:
class Event {
class event {
public:
struct Resize {
struct resize {
size_t width;
size_t height;
};
struct Keyboard {
struct keyboard {
uint32_t key;
uint32_t scan;
bool pressed;
bool repeat;
};
struct Mouse {
struct mouse {
uint16_t button_mask;
bool pressed;
uint32_t x;
uint32_t y;
};
struct MouseMove {
struct mouse_move {
uint32_t x;
uint32_t y;
};
};
using VariantEvent = std::variant<Event::Resize, Event::Keyboard,
Event::Mouse, Event::MouseMove>;
using variant_event = std::variant<event::resize, event::keyboard,
event::mouse, event::mouse_move>;
virtual ~Window() = default;
virtual ~window() = default;
virtual void show() = 0;
virtual void hide() = 0;
virtual const VideoMode &videoMode() const = 0;
virtual const video_mode &videoMode() const = 0;
virtual const std::string_view title() const = 0;
virtual void resize(size_t width, size_t height) = 0;
virtual Conveyor<VariantEvent> onEvent() = 0;
virtual conveyor<variant_event> onevent() = 0;
};
} // namespace saw