diff options
author | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-08-06 16:13:50 +0200 |
---|---|---|
committer | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-08-06 16:13:50 +0200 |
commit | 6a5d5b204569fc6abe6cb5a8ac338350eb5e923d (patch) | |
tree | 04339a65d987c0bed58c9e1eeb0a3742e7c95705 | |
parent | e42c3750013e634bbe1834e3e684367e42814b97 (diff) |
Fixed xcb windows
-rw-r--r-- | modules/window/SConstruct | 5 | ||||
-rw-r--r-- | modules/window/c++/xcb.cpp | 56 | ||||
-rw-r--r-- | modules/window/c++/xcb.hpp | 6 | ||||
-rw-r--r-- | modules/window/examples/window_create.cpp | 50 |
4 files changed, 107 insertions, 10 deletions
diff --git a/modules/window/SConstruct b/modules/window/SConstruct index 3017baf..23a5195 100644 --- a/modules/window/SConstruct +++ b/modules/window/SConstruct @@ -46,7 +46,7 @@ env_vars.Add('prefix', env_vars.Add( BoolVariable('build_examples', help='Build examples', - default=False + default=True ) ); @@ -59,6 +59,9 @@ env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], ,'forstio-io' ,'forstio-async' ,'forstio-codec' + ,'libX11' + ,'libxcb' + ,'libX11-xcb' ] ); diff --git a/modules/window/c++/xcb.cpp b/modules/window/c++/xcb.cpp index e90fa5a..9d4ae58 100644 --- a/modules/window/c++/xcb.cpp +++ b/modules/window/c++/xcb.cpp @@ -261,25 +261,69 @@ void window<backend::linux_xcb>::resize(uint64_t w, uint64_t h){ conveyor<data<schema::WindowEvents>> window<backend::linux_xcb>::on_event() { auto caf = new_conveyor_and_feeder<data<schema::WindowEvents>>(); - event_feeder = std::move(caf.feeder); + event_feeder_ = std::move(caf.feeder); return std::move(caf.conveyor); } void window<backend::linux_xcb>::resize_event(uint64_t x, uint64_t y, uint64_t width, uint64_t height){ - /// @todo implement - assert(false); + video_mode_.width = width; + video_mode_.height = height; + + if(event_feeder_) { + /// @TODO implement + assert(false); + } } void window<backend::linux_xcb>::mouse_event(int16_t x, int16_t y, uint16_t state, bool pressed){ - /// @todo implement + 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){ + return; + } + + if(event_feeder_){ + /// @TODO implement assert(false); + } } + void window<backend::linux_xcb>::mouse_move_event(int16_t x, int16_t y){ - /// @todo implement + 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){ + return; + } + + if(event_feeder_){ + /// @TODO implement assert(false); + } } + void window<backend::linux_xcb>::keyboard_event(int16_t x, int16_t y, uint32_t keycode, bool pressed, bool repeat){ - /// @todo implement + 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){ + return; + } + + if(event_feeder_){ + /// @TODO implement assert(false); + } } xcb_window_t window<backend::linux_xcb>::get_xcb_window_handle() const{ diff --git a/modules/window/c++/xcb.hpp b/modules/window/c++/xcb.hpp index 1694923..2f84133 100644 --- a/modules/window/c++/xcb.hpp +++ b/modules/window/c++/xcb.hpp @@ -10,8 +10,8 @@ #include <map> -#include <X11/Xlib-xcb.hpp> -#include <X11/Xlib.hpp> +#include <X11/Xlib-xcb.h> +#include <X11/Xlib.h> namespace saw { namespace gfx { @@ -76,7 +76,7 @@ private: video_mode video_mode_; std::string window_title_; - own<conveyor_feeder<data<schema::WindowEvents>>> event_feeder = nullptr; + own<conveyor_feeder<data<schema::WindowEvents>>> event_feeder_ = nullptr; public: window(device<backend::linux_xcb>& dev_, xcb_window_t xcb_win, xcb_colormap_t xcb_colormap_, const video_mode& vid_mode_, const std::string_view& title_view_); diff --git a/modules/window/examples/window_create.cpp b/modules/window/examples/window_create.cpp index dde8295..3517dae 100644 --- a/modules/window/examples/window_create.cpp +++ b/modules/window/examples/window_create.cpp @@ -1,4 +1,54 @@ +#include "../c++/window.hpp" + +#include <iostream> + int main(){ + auto eo_aio = saw::setup_async_io(); + if(eo_aio.is_error()){ + auto& err = eo_aio.get_error(); + std::cerr<<"Error: "<<err.get_category(); + + auto err_msg = err.get_message(); + if(err_msg.size() > 0u){ + std::cerr<<" - "<<err_msg; + } + + std::cerr<<std::endl; + return err.get_id(); + } + auto& aio = eo_aio.get_value(); + saw::wait_scope wait{aio.event_loop}; + + auto eo_device = saw::gfx::create_xcb_device(*aio.io); + if(eo_device.is_error()){ + auto& err = eo_device.get_error(); + std::cerr<<"Error: "<<err.get_category(); + + auto err_msg = err.get_message(); + if(err_msg.size() > 0u){ + std::cerr<<" - "<<err_msg; + } + + std::cerr<<std::endl; + return err.get_id(); + } + auto& device = eo_device.get_value(); + + auto window = device->create_window({}, "foo"); + if(!window){ + return 42; + } + window->show(); + + bool running = true; + + aio.event_port.on_signal(saw::Signal::Terminate).then([&running](){ + running = false; + }).detach(); + while(running){ + device->flush(); + wait.wait(std::chrono::seconds{1u}); + } return 0; } |