summaryrefslogtreecommitdiff
path: root/modules/window/c++/xcb.hpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-01-23 13:12:11 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-01-23 13:12:11 +0100
commit8dad985328e2183b224300aa992951131956fdb3 (patch)
treeceda3d9805335f36f571fb36585444ebdb421a02 /modules/window/c++/xcb.hpp
parenta9d2025030d0a7641f4b0701bd4aff7d2db5aeb4 (diff)
core,codec-json,codec-minecraft,codec-netcdf,codec,io-tls,io,io_codec,window,window-opengl:
Renamed file endings and changed includes
Diffstat (limited to 'modules/window/c++/xcb.hpp')
-rw-r--r--modules/window/c++/xcb.hpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/modules/window/c++/xcb.hpp b/modules/window/c++/xcb.hpp
new file mode 100644
index 0000000..4c7b9fa
--- /dev/null
+++ b/modules/window/c++/xcb.hpp
@@ -0,0 +1,105 @@
+#pragma once
+
+#ifndef SAW_UNIX_XCB
+#error "XCB is not supported"
+#endif
+
+#include "backends.hpp
+#include "device.hpp
+#include "window.hpp
+
+#include <map>
+
+#include <X11/Xlib-xcb.h>
+#include <X11/Xlib.h>
+
+namespace saw {
+namespace gfx {
+template<typename T>
+class window;
+
+template<typename T>
+class device;
+
+template<>
+class device<backend::linux_xcb> final {
+private:
+ ::Display *display_;
+ int screen_;
+
+ xcb_connection_t *xcb_connection_;
+ xcb_screen_t *xcb_screen_;
+
+ own<input_stream> async_notifier_;
+ conveyor_sink async_conveyor_;
+
+ std::map<xcb_window_t, window<backend::linux_xcb> *> windows_;
+
+ std::vector<xcb_generic_event_t *> pending_events_;
+
+ friend class window<backend::linux_xcb>;
+public:
+ own<window<backend::linux_xcb>> create_xcb_window(const video_mode& vid_mod, std::string_view title_view, int visual_id);
+ void xcb_window_was_destroyed(xcb_window_t window_id);
+public:
+ device(::Display *display, int screen, xcb_connection_t *xcb_connection,
+ xcb_screen_t *xcb_screen, own<input_stream> && an);
+
+ ~device();
+
+ void handle_events();
+
+ own<window<backend::linux_xcb>> create_window(const video_mode& vid_mod, std::string_view title_view);
+
+ void flush();
+
+ // XCB specific info for other classes
+ ::Display* get_xcb_display() {
+ return display_;
+ }
+
+ int get_xcb_screen() const {
+ return screen_;
+ }
+};
+
+error_or<own<device<backend::linux_xcb>>> create_xcb_device(io_provider& provider);
+
+template<>
+class window<backend::linux_xcb> final {
+private:
+ device<backend::linux_xcb> *device_;
+
+ xcb_window_t xcb_window_;
+ xcb_colormap_t xcb_colormap_;
+
+ video_mode video_mode_;
+ std::string window_title_;
+
+ 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_);
+
+ ~window();
+
+ void show();
+ void hide();
+
+ const video_mode& get_video_mode() const;
+
+ const std::string_view get_title() const;
+
+ void resize(uint64_t width, uint64_t height);
+
+ conveyor<data<schema::WindowEvents>> on_event();
+
+ void resize_event(uint64_t x, uint64_t y, uint64_t width, uint64_t height);
+ void mouse_event(int16_t x, int16_t y, uint16_t state, bool pressed);
+ void mouse_move_event(int16_t x, int16_t y);
+ void keyboard_event(int16_t x, int16_t y, uint32_t keycode, bool pressed, bool repeat);
+
+ // XCB specific things
+ xcb_window_t get_xcb_window_handle() const;
+};
+}
+}