Line data Source code
1 : /** 2 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #ifndef XENOLITH_BACKEND_VKGUI_PLATFORM_LINUX_XLVKGUIVIEWIMPL_H_ 24 : #define XENOLITH_BACKEND_VKGUI_PLATFORM_LINUX_XLVKGUIVIEWIMPL_H_ 25 : 26 : #include "XLVkView.h" 27 : #include "linux/XLPlatformLinuxView.h" 28 : 29 : #if LINUX 30 : 31 : namespace STAPPLER_VERSIONIZED stappler::xenolith::vk::platform { 32 : 33 : enum class SurfaceType : uint32_t { 34 : None, 35 : XCB = 1 << 0, 36 : Wayland = 1 << 1, 37 : }; 38 : 39 : SP_DEFINE_ENUM_AS_MASK(SurfaceType) 40 : 41 : class ViewImpl : public vk::View { 42 : public: 43 : ViewImpl(); 44 : virtual ~ViewImpl(); 45 : 46 : virtual bool init(Application &loop, const core::Device &dev, ViewInfo &&); 47 : 48 : virtual void threadInit() override; 49 : virtual void threadDispose() override; 50 : virtual bool worker() override; 51 : 52 : virtual void wakeup(std::unique_lock<Mutex> &) override; 53 : 54 : virtual void updateTextCursor(uint32_t pos, uint32_t len) override; 55 : virtual void updateTextInput(WideStringView str, uint32_t pos, uint32_t len, TextInputType) override; 56 : virtual void runTextInput(WideStringView str, uint32_t pos, uint32_t len, TextInputType) override; 57 : virtual void cancelTextInput() override; 58 : 59 : virtual void presentWithQueue(vk::DeviceQueue &, Rc<ImageStorage> &&) override; 60 : 61 0 : virtual bool isInputEnabled() const override { return _inputEnabled; } 62 : xenolith::platform::LinuxViewInterface *getView() const { return _view; } 63 : 64 : vk::Device *getDevice() const { return _device; } 65 : 66 : // minimal poll interval 67 9260 : virtual uint64_t getUpdateInterval() const override { return 250; } 68 : 69 : virtual void mapWindow() override; 70 : 71 0 : virtual void linkWithNativeWindow(void *) override { } 72 0 : virtual void stopNativeWindow() override { } 73 : 74 : virtual void readFromClipboard(Function<void(BytesView, StringView)> &&, Ref *) override; 75 : virtual void writeToClipboard(BytesView, StringView contentType = StringView()) override; 76 : 77 : protected: 78 : virtual bool pollInput(bool frameReady) override; 79 : 80 : virtual core::SurfaceInfo getSurfaceOptions() const override; 81 : 82 : virtual void finalize() override; 83 : 84 : Rc<xenolith::platform::LinuxViewInterface> _view; 85 : int _eventFd = -1; 86 : bool _inputEnabled = false; 87 : }; 88 : 89 : } 90 : 91 : #endif 92 : 93 : #endif /* XENOLITH_BACKEND_VKGUI_PLATFORM_LINUX_XLVKGUIVIEWIMPL_H_ */