1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
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/gtk-primary-selection-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/primary-selection-unstable-v1-client-protocol.h"
21 #include "mozilla/widget/viewporter-client-protocol.h"
22 #include "mozilla/widget/xdg-activation-v1-client-protocol.h"
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 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsWaylandDisplay
)
34 // Create nsWaylandDisplay object on top of native Wayland wl_display
36 explicit nsWaylandDisplay(wl_display
* aDisplay
);
38 bool DispatchEventQueue();
41 void QueueSyncBegin();
43 void WaitForSyncEnd();
45 bool Matches(wl_display
* aDisplay
);
47 wl_display
* GetDisplay() { return mDisplay
; };
48 wl_event_queue
* GetEventQueue() { return mEventQueue
; };
49 wl_compositor
* GetCompositor(void) { return mCompositor
; };
50 wl_subcompositor
* GetSubcompositor(void) { return mSubcompositor
; };
51 wl_data_device_manager
* GetDataDeviceManager(void) {
52 return mDataDeviceManager
;
54 wl_seat
* GetSeat(void);
55 wl_shm
* GetShm(void) { return mShm
; };
56 gtk_primary_selection_device_manager
* GetPrimarySelectionDeviceManagerGtk(
58 return mPrimarySelectionDeviceManagerGtk
;
60 zwp_primary_selection_device_manager_v1
*
61 GetPrimarySelectionDeviceManagerZwpV1(void) {
62 return mPrimarySelectionDeviceManagerZwpV1
;
64 zwp_idle_inhibit_manager_v1
* GetIdleInhibitManager(void) {
65 return mIdleInhibitManager
;
67 wp_viewporter
* GetViewporter(void) { return mViewporter
; };
68 zwp_relative_pointer_manager_v1
* GetRelativePointerManager(void) {
69 return mRelativePointerManager
;
71 zwp_pointer_constraints_v1
* GetPointerConstraints(void) {
72 return mPointerConstraints
;
74 zwp_linux_dmabuf_v1
* GetDmabuf(void) { return mDmabuf
; };
75 xdg_activation_v1
* GetXdgActivation(void) { return mXdgActivation
; };
77 bool IsMainThreadDisplay() { return mEventQueue
== nullptr; }
79 void SetShm(wl_shm
* aShm
);
80 void SetCompositor(wl_compositor
* aCompositor
);
81 void SetSubcompositor(wl_subcompositor
* aSubcompositor
);
82 void SetDataDeviceManager(wl_data_device_manager
* aDataDeviceManager
);
83 void SetPrimarySelectionDeviceManager(
84 gtk_primary_selection_device_manager
* aPrimarySelectionDeviceManager
);
85 void SetPrimarySelectionDeviceManager(
86 zwp_primary_selection_device_manager_v1
* aPrimarySelectionDeviceManager
);
87 void SetIdleInhibitManager(zwp_idle_inhibit_manager_v1
* aIdleInhibitManager
);
88 void SetViewporter(wp_viewporter
* aViewporter
);
89 void SetRelativePointerManager(
90 zwp_relative_pointer_manager_v1
* aRelativePointerManager
);
91 void SetPointerConstraints(zwp_pointer_constraints_v1
* aPointerConstraints
);
92 void SetDmabuf(zwp_linux_dmabuf_v1
* aDmabuf
);
93 void SetXdgActivation(xdg_activation_v1
* aXdgActivation
);
95 bool IsExplicitSyncEnabled() { return mExplicitSync
; }
101 wl_display
* mDisplay
;
102 wl_event_queue
* mEventQueue
;
103 wl_data_device_manager
* mDataDeviceManager
;
104 wl_compositor
* mCompositor
;
105 wl_subcompositor
* mSubcompositor
;
107 wl_callback
* mSyncCallback
;
108 gtk_primary_selection_device_manager
* mPrimarySelectionDeviceManagerGtk
;
109 zwp_primary_selection_device_manager_v1
* mPrimarySelectionDeviceManagerZwpV1
;
110 zwp_idle_inhibit_manager_v1
* mIdleInhibitManager
;
111 zwp_relative_pointer_manager_v1
* mRelativePointerManager
;
112 zwp_pointer_constraints_v1
* mPointerConstraints
;
113 wp_viewporter
* mViewporter
;
114 zwp_linux_dmabuf_v1
* mDmabuf
;
115 xdg_activation_v1
* mXdgActivation
;
119 void WaylandDispatchDisplays();
120 void WaylandDisplayRelease();
122 RefPtr
<nsWaylandDisplay
> WaylandDisplayGet(GdkDisplay
* aGdkDisplay
= nullptr);
123 wl_display
* WaylandDisplayGetWLDisplay(GdkDisplay
* aGdkDisplay
= nullptr);
125 } // namespace widget
126 } // namespace mozilla
129 static inline T
* WaylandRegistryBind(struct wl_registry
* wl_registry
,
131 const struct wl_interface
* interface
,
135 // When libwayland-client does not provide this symbol, it will be
136 // linked to the fallback in libmozwayland, which returns NULL.
137 id
= wl_proxy_marshal_constructor_versioned(
138 (struct wl_proxy
*)wl_registry
, WL_REGISTRY_BIND
, interface
, version
, name
,
139 interface
->name
, version
, nullptr);
142 id
= wl_proxy_marshal_constructor((struct wl_proxy
*)wl_registry
,
143 WL_REGISTRY_BIND
, interface
, name
,
144 interface
->name
, version
, nullptr);
147 return reinterpret_cast<T
*>(id
);
150 #endif // __MOZ_WAYLAND_DISPLAY_H__