From 5f2ca9a01d2e493e222bead7222613e050871928 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Tue, 23 May 2023 01:38:07 +0200 Subject: c++: Changing approach to a more exposed variant --- src/window/xcb.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/window/xcb.h (limited to 'src/window/xcb.h') diff --git a/src/window/xcb.h b/src/window/xcb.h new file mode 100644 index 0000000..61ed509 --- /dev/null +++ b/src/window/xcb.h @@ -0,0 +1,69 @@ +#pragma once + +#ifndef SAW_UNIX_XCB +#error "XCB is not supported" +#endif + +namespace saw { +class window; +class device { +private: + ::Display *display; + int screen; + + xcb_connection_t *xcb_connection; + xcb_screen_t *xcb_screen; + + own async_notifier; + conveyor_sink async_conveyor; + + std::map windows; + + std::vector pending_events; +public: + device(::Display *display, int screen, xcb_connection_t *xcb_connection, + xcb_screen_t *xcb_screen, own && an); + + ~device(); + + void xcb_window_was_destroyed(xcb_window_t window_id); + void handle_events(); + + own create_window(const video_mode& vid_mod, std::string_view title_view); + + void flush(); +}; + +class window { +private: + device *device_; + + xcb_window_t xcb_window_; + xcb_colormap_t xcb_colormap_; + + video_mode video_mode_; + std::string window_title_; + + own>> event_feeder = nullptr; +public: + window(device& dev_, xcb_window_t xcb_win, xcb_colormap_t xcb_colormap_, const video_mode& vid_mode_, 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 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); +}; +} -- cgit v1.2.3