1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef __MOZ_WAYLAND_DISPLAY_H__
9 #define __MOZ_WAYLAND_DISPLAY_H__
11 #include "DMABufLibWrapper.h"
13 #include "mozilla/widget/mozwayland.h"
14 #include "mozilla/widget/gbm.h"
15 #include "mozilla/widget/fractional-scale-v1-client-protocol.h"
16 #include "mozilla/widget/idle-inhibit-unstable-v1-client-protocol.h"
17 #include "mozilla/widget/relative-pointer-unstable-v1-client-protocol.h"
18 #include "mozilla/widget/pointer-constraints-unstable-v1-client-protocol.h"
19 #include "mozilla/widget/linux-dmabuf-unstable-v1-client-protocol.h"
20 #include "mozilla/widget/viewporter-client-protocol.h"
21 #include "mozilla/widget/xdg-activation-v1-client-protocol.h"
22 #include "mozilla/widget/xdg-dbus-annotation-v1-client-protocol.h"
23 #include "mozilla/widget/xdg-output-unstable-v1-client-protocol.h"
25 namespace mozilla::widget
{
27 // Our general connection to Wayland display server,
28 // holds our display connection and runs event loop.
29 // We have a global nsWaylandDisplay object for each thread.
30 class nsWaylandDisplay
{
32 // Create nsWaylandDisplay object on top of native Wayland wl_display
34 explicit nsWaylandDisplay(wl_display
* aDisplay
);
36 wl_display
* GetDisplay() { return mDisplay
; };
37 wl_compositor
* GetCompositor() { return mCompositor
; };
38 wl_subcompositor
* GetSubcompositor() { return mSubcompositor
; };
39 wl_shm
* GetShm() { return mShm
; };
40 zwp_idle_inhibit_manager_v1
* GetIdleInhibitManager() {
41 return mIdleInhibitManager
;
43 wp_viewporter
* GetViewporter() { return mViewporter
; };
44 zwp_relative_pointer_manager_v1
* GetRelativePointerManager() {
45 return mRelativePointerManager
;
47 zwp_pointer_constraints_v1
* GetPointerConstraints() {
48 return mPointerConstraints
;
50 zwp_linux_dmabuf_v1
* GetDmabuf() { return mDmabuf
; };
51 xdg_activation_v1
* GetXdgActivation() { return mXdgActivation
; };
52 xdg_dbus_annotation_manager_v1
* GetXdgDbusAnnotationManager() {
53 return mXdgDbusAnnotationManager
;
55 wp_fractional_scale_manager_v1
* GetFractionalScaleManager() {
56 return mFractionalScaleManager
;
58 bool IsPrimarySelectionEnabled() { return mIsPrimarySelectionEnabled
; }
60 void SetShm(wl_shm
* aShm
);
61 void SetCompositor(wl_compositor
* aCompositor
);
62 void SetSubcompositor(wl_subcompositor
* aSubcompositor
);
63 void SetDataDeviceManager(wl_data_device_manager
* aDataDeviceManager
);
64 void SetIdleInhibitManager(zwp_idle_inhibit_manager_v1
* aIdleInhibitManager
);
65 void SetViewporter(wp_viewporter
* aViewporter
);
66 void SetRelativePointerManager(
67 zwp_relative_pointer_manager_v1
* aRelativePointerManager
);
68 void SetPointerConstraints(zwp_pointer_constraints_v1
* aPointerConstraints
);
69 void SetDmabuf(zwp_linux_dmabuf_v1
* aDmabuf
);
70 void SetXdgActivation(xdg_activation_v1
* aXdgActivation
);
71 void SetXdgDbusAnnotationManager(
72 xdg_dbus_annotation_manager_v1
* aXdgDbusAnnotationManager
);
73 void SetFractionalScaleManager(wp_fractional_scale_manager_v1
* aManager
) {
74 mFractionalScaleManager
= aManager
;
76 void EnablePrimarySelection() { mIsPrimarySelectionEnabled
= true; }
81 PRThread
* mThreadId
= nullptr;
82 wl_registry
* mRegistry
= nullptr;
83 wl_display
* mDisplay
= nullptr;
84 wl_compositor
* mCompositor
= nullptr;
85 wl_subcompositor
* mSubcompositor
= nullptr;
86 wl_shm
* mShm
= nullptr;
87 zwp_idle_inhibit_manager_v1
* mIdleInhibitManager
= nullptr;
88 zwp_relative_pointer_manager_v1
* mRelativePointerManager
= nullptr;
89 zwp_pointer_constraints_v1
* mPointerConstraints
= nullptr;
90 wp_viewporter
* mViewporter
= nullptr;
91 zwp_linux_dmabuf_v1
* mDmabuf
= nullptr;
92 xdg_activation_v1
* mXdgActivation
= nullptr;
93 xdg_dbus_annotation_manager_v1
* mXdgDbusAnnotationManager
= nullptr;
94 wp_fractional_scale_manager_v1
* mFractionalScaleManager
= nullptr;
95 bool mExplicitSync
= false;
96 bool mIsPrimarySelectionEnabled
= false;
99 wl_display
* WaylandDisplayGetWLDisplay();
100 nsWaylandDisplay
* WaylandDisplayGet();
101 void WaylandDisplayRelease();
103 } // namespace mozilla::widget
106 static inline T
* WaylandRegistryBind(struct wl_registry
* wl_registry
,
108 const struct wl_interface
* interface
,
112 // When libwayland-client does not provide this symbol, it will be
113 // linked to the fallback in libmozwayland, which returns NULL.
114 id
= wl_proxy_marshal_constructor_versioned(
115 (struct wl_proxy
*)wl_registry
, WL_REGISTRY_BIND
, interface
, version
, name
,
116 interface
->name
, version
, nullptr);
119 id
= wl_proxy_marshal_constructor((struct wl_proxy
*)wl_registry
,
120 WL_REGISTRY_BIND
, interface
, name
,
121 interface
->name
, version
, nullptr);
124 return reinterpret_cast<T
*>(id
);
127 #endif // __MOZ_WAYLAND_DISPLAY_H__