Project
Loading...
Searching...
No Matches
GPUDisplayFrontendWayland.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUDISPLAYFRONTENDWAYLAND_H
16#define GPUDISPLAYFRONTENDWAYLAND_H
17
18#include "GPUDisplayFrontend.h"
19#include <wayland-client.h>
20#include "xdg-shell-client-protocol.h"
21#include "fractional-scale-client-protocol.h"
22#include <vector>
23#include <string>
24
25struct zxdg_decoration_manager_v1;
26struct wp_viewporter;
27struct wp_viewport;
28struct wp_cursor_shape_manager_v1;
29struct wp_cursor_shape_device_v1;
30struct zxdg_toplevel_decoration_v1;
31struct xkb_context;
32struct xkb_keymap;
33struct xkb_state;
34
35namespace o2::gpu
36{
38{
39 public:
41 ~GPUDisplayFrontendWayland() override = default;
42
43 void SwitchFullscreen(bool set) override;
44 void ToggleMaximized(bool set) override;
45 void SetVSync(bool enable) override;
46 void OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton = true) override;
47 void getSize(int32_t& width, int32_t& height) override;
48 float getDisplayScale() const override { return mScale; }
49 float getRefreshRate() override;
50 int32_t getVulkanSurface(void* instance, void* surface) override;
51 uint32_t getReqVulkanExtensions(const char**& p) override;
52
53 private:
54 int32_t FrontendMain() override;
55 int32_t GetKey(uint32_t key, uint32_t state);
56 void updateScale(); // Scale from wp_fractional_scale_v1, else integer wl_surface.preferred_buffer_scale, or max scale of the outputs the surface is on (older compositors)
57 void updateSize(); // Physical size = logical size * scale, resizes the scene if changed
58 void reportError(const char* where); // Print the Wayland display error (protocol error with interface and object, or errno) after a call returned -1
59 void handleKeyRepeat(); // Call HandleKey for the held key according to wl_keyboard.repeat_info
60 void applyScroll(); // Apply scroll events of one wl_pointer.frame: high-resolution wheel (120 = 1 notch = 100 mMouseWheel units) if available, otherwise continuous axis (touchpad, ~15 units per notch)
61
62 struct OutputInfo {
63 wl_output* output;
64 uint32_t globalName;
65 uint32_t version;
66 int32_t scale = 1;
67 std::string name;
68 int32_t refresh = 0; // mHz, current mode
69 };
70 OutputInfo* findOutput(wl_output* output);
71
72 wl_display* mWayland = nullptr;
73 wl_registry* mRegistry = nullptr;
74
75 wl_compositor* mCompositor = nullptr;
76 wl_seat* mSeat = nullptr;
77 wl_pointer* mPointer = nullptr;
78 wl_keyboard* mKeyboard = nullptr;
79 xdg_wm_base* mXdgBase = nullptr;
80
81 wl_surface* mSurface = nullptr;
82 xdg_surface* mXdgSurface = nullptr;
83 xdg_toplevel* mXdgToplevel = nullptr;
84
85 wl_registry_listener mRegistryListener{};
86 wl_seat_listener mSeatListener{};
87 wl_pointer_listener mPointerListener{};
88 wl_keyboard_listener mKeyboardListener{};
89 wl_output_listener mOutputListener{};
90 wl_surface_listener mSurfaceListener{};
91 xdg_wm_base_listener mXdgWmBaseListener{};
92 xdg_surface_listener mXdgSurfaceListener{};
93 xdg_toplevel_listener mXdgToplevelListener{};
94 wp_fractional_scale_v1_listener mFractionalScaleListener{};
95
96 std::vector<OutputInfo> mOutputs;
97 std::vector<wl_output*> mSurfaceOutputs; // Outputs the surface is on, most recently entered last
98 uint32_t mSeatVersion = 0;
99
100 xkb_context* mXKBcontext = nullptr;
101 xkb_keymap* mXKBkeymap = nullptr;
102 xkb_state* mXKBstate = nullptr;
103
104 zxdg_decoration_manager_v1* mDecManager = nullptr;
105 zxdg_toplevel_decoration_v1* mXdgDecoration = nullptr;
106
107 wp_viewporter* mViewporter = nullptr; // Fractional scaling (if both are available): buffer scale 1, buffer at physical size, viewport destination = logical size
108 wp_fractional_scale_manager_v1* mFractionalScaleManager = nullptr;
109 wp_cursor_shape_manager_v1* mCursorShapeManager = nullptr; // Sets the default cursor on pointer enter, otherwise the cursor image is undefined
110 wp_cursor_shape_device_v1* mCursorShapeDevice = nullptr;
111 wp_viewport* mViewport = nullptr;
112 wp_fractional_scale_v1* mFractionalScale = nullptr;
113
114 int32_t mWidthRequested = 0;
115 int32_t mHeightRequested = 0;
116 int32_t mWidthLogical = INIT_WIDTH;
117 int32_t mHeightLogical = INIT_HEIGHT;
118 int32_t mWidthWindowed = INIT_WIDTH; // Last size when neither maximized nor fullscreen
119 int32_t mHeightWindowed = INIT_HEIGHT;
120 bool mStateFullScreenOrMaximized = false;
121 int32_t mBoundsWidth = 0;
122 int32_t mBoundsHeight = 0;
123 double mScale = 1; // Physical pixels per logical pixel
124 int32_t mPreferredScale = 0; // Integer scale from wl_surface.preferred_buffer_scale, 0 = not sent by compositor
125 uint32_t mFractionalScale120 = 0; // Scale * 120 from wp_fractional_scale_v1, 0 = not sent yet
126 bool mSuspended = false;
127 bool mCanFullscreen = true;
128 bool mCanMaximize = true;
129
130 int32_t mRepeatRate = 0; // Keys per second, 0 = no repeat
131 int32_t mRepeatDelay = 0; // ms before the first repeat
132 int64_t mRepeatKeyCode = -1; // Evdev key code of the held key to repeat, -1 = none
133 int32_t mRepeatSymbol = 0;
134 std::chrono::steady_clock::time_point mRepeatNext;
135
136 double mAxisValue = 0; // Accumulated scroll values of one wl_pointer.frame
137 int32_t mAxisValue120 = 0;
138 bool mHasAxisValue120 = false;
139};
140GPUDisplayFrontend* createGPUDisplayFrontendWayland();
141} // namespace o2::gpu
142
143#endif
SurfaceTrackState state
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
uint32_t version
Definition RawData.h:8
const Acts::Surface * surface
StringRef key
~GPUDisplayFrontendWayland() override=default
int32_t getVulkanSurface(void *instance, void *surface) override
void getSize(int32_t &width, int32_t &height) override
void OpenGLPrint(const char *s, float x, float y, float r, float g, float b, float a, bool fromBotton=true) override
uint32_t getReqVulkanExtensions(const char **&p) override
static constexpr int32_t INIT_WIDTH
static constexpr int32_t INIT_HEIGHT
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint const GLchar * name
Definition glcorearb.h:781
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint GLsizei width
Definition glcorearb.h:270
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLboolean GLboolean g
Definition glcorearb.h:1233
GLboolean enable
Definition glcorearb.h:3991
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GPUDisplayFrontend * createGPUDisplayFrontendWayland()