vsg  1.1.0
VulkanSceneGraph library
Xcb_Window.h
1 /* <editor-fold desc="MIT License">
2 
3 Copyright(c) 2018 Robert Osfield
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 
7 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 
9 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 
11 </editor-fold> */
12 
13 #pragma once
14 
15 #include <vsg/app/Window.h>
16 #include <vsg/ui/KeyEvent.h>
17 
18 #include <xcb/xcb.h>
19 
20 #include <vulkan/vulkan_xcb.h>
21 
22 namespace vsgXcb
23 {
24 
26  class KeyboardMap : public vsg::Object
27  {
28  public:
29  KeyboardMap();
30 
31  using KeycodeModifier = std::pair<uint16_t, uint16_t>;
32  using KeycodeMap = std::map<KeycodeModifier, vsg::KeySymbol>;
33 
34  void add(uint16_t keycode, uint16_t modifier, vsg::KeySymbol key);
35 
36  void add(uint16_t keycode, std::initializer_list<std::pair<uint16_t, vsg::KeySymbol>> combinations);
37 
38  vsg::KeySymbol getKeySymbol(uint16_t keycode, uint16_t modifier);
39  vsg::KeyModifier getKeyModifier(vsg::KeySymbol keySym, uint16_t modifier, bool pressed);
40 
41  protected:
42  KeycodeMap _keycodeMap;
43  uint16_t _modifierMask;
44  };
45 
47  class Xcb_Surface : public vsg::Surface
48  {
49  public:
50  Xcb_Surface(vsg::Instance* instance, xcb_connection_t* connection, xcb_window_t window);
51  };
52 
54  class Xcb_Window : public vsg::Inherit<vsg::Window, Xcb_Window>
55  {
56  public:
58  Xcb_Window() = delete;
59  Xcb_Window(const Xcb_Window&) = delete;
60  Xcb_Window& operator=(const Xcb_Window&) = delete;
61 
62  const char* instanceExtensionSurfaceName() const override { return VK_KHR_XCB_SURFACE_EXTENSION_NAME; }
63 
64  bool valid() const override;
65 
66  bool visible() const override;
67 
68  void releaseWindow() override;
69  void releaseConnection() override;
70 
71  bool pollEvents(vsg::UIEvents& events) override;
72 
73  void resize() override;
74 
75  protected:
76  ~Xcb_Window();
77 
78  void _initSurface() override;
79 
80  xcb_connection_t* _connection = nullptr;
81  xcb_screen_t* _screen = nullptr;
82  xcb_window_t _window{};
83  xcb_atom_t _wmProtocols{};
84  xcb_atom_t _wmDeleteWindow{};
85 
86  bool _windowMapped = false;
87 
88  xcb_timestamp_t _first_xcb_timestamp = 0;
89  vsg::clock::time_point _first_xcb_time_point;
90 
91  vsg::ref_ptr<KeyboardMap> _keyboard;
92  };
93 
94 } // namespace vsgXcb
95 
96 EVSG_type_name(vsgXcb::Xcb_Window);
KeyboardMap maps Xcb keyboard events to vsg::KeySymbol.
Definition: Xcb_Window.h:27
Xcb_Surface implements XcbSurface creation.
Definition: Xcb_Window.h:48
Xcb_Window implements Xcb specific window creation, event handling and vulkan Surface setup.
Definition: Xcb_Window.h:55
bool pollEvents(vsg::UIEvents &events) override
get the list of events since the last pollEvents() call by splicing bufferEvents with polled windowin...
void releaseWindow() override
void releaseConnection() override
Definition: Inherit.h:28
Instance encapsulates the VkInstance.
Definition: Instance.h:43
Definition: Object.h:42
Surface encapsulates VkSurfaceKHR.
Definition: Surface.h:22