Skip to content

Commit be121d1

Browse files
committed
waylandpp
1 parent e48b110 commit be121d1

File tree

7 files changed

+502
-302
lines changed

7 files changed

+502
-302
lines changed

CMakeLists.txt

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.2)
66

77
project(flutter_wayland)
88

9-
set(FLUTTER_ENGINE_SHA b9523318caa1a99ffde8adaf331212eb879cabc9)
9+
set(FLUTTER_ENGINE_SHA af51afceb8886cc11e25047523c4e0c7e1f5d408)
1010

1111
set(FLUTTER_EMBEDDER_ARTIFACTS_ZIP ${CMAKE_BINARY_DIR}/flutter_embedder_${FLUTTER_ENGINE_SHA}.zip)
1212
set(FLUTTER_ARTIFACTS_ZIP ${CMAKE_BINARY_DIR}/flutter_artifact_${FLUTTER_ENGINE_SHA}.zip)
@@ -37,32 +37,46 @@ if(NOT EXISTS ${FLUTTER_ARTIFACTS_ZIP})
3737
)
3838
endif()
3939

40-
find_package(PkgConfig)
41-
pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
42-
pkg_check_modules(WAYLAND_EGL REQUIRED wayland-egl)
43-
pkg_check_modules(EGL REQUIRED egl)
40+
set(CMAKE_CXX_STANDARD 11)
41+
42+
include(FindPkgConfig)
43+
pkg_check_modules(WAYLANDPP_CLIENT REQUIRED "wayland-client++>=0.2.7")
44+
pkg_check_modules(WAYLANDPP_CURSOR REQUIRED "wayland-cursor++>=0.2.7")
45+
pkg_check_modules(WAYLANDPP_EGL REQUIRED "wayland-egl++>=0.2.7")
46+
pkg_check_modules(WAYLANDPP_CLIENT_EXTRA REQUIRED "wayland-client-extra++>=0.2.7")
47+
pkg_check_modules(EGL REQUIRED egl)
4448

4549
# Executable
46-
file(GLOB_RECURSE FLUTTER_WAYLAND_SRC
47-
"src/*.cc"
48-
"src/*.h"
50+
set(FLUTTER_WAYLAND_SRC
51+
src/flutter_application.cc
52+
src/flutter_application.h
53+
src/utils.cc
54+
src/utils.h
55+
src/wayland_display.cc
56+
src/wayland_display.h
57+
src/main.cc
4958
)
5059

5160
link_directories(${CMAKE_BINARY_DIR})
5261

5362
add_executable(flutter_wayland ${FLUTTER_WAYLAND_SRC})
5463

5564
target_link_libraries(flutter_wayland
56-
${WAYLAND_CLIENT_LIBRARIES}
57-
${WAYLAND_EGL_LIBRARIES}
58-
${EGL_LIBRARIES}
65+
${WAYLANDPP_CLIENT_LIBRARIES}
66+
${WAYLANDPP_EGL_LIBRARIES}
67+
${WAYLANDPP_CURSOR_LIBRARIES}
68+
${WAYLANDPP_CLIENT_EXTRA_LIBRARIES}
69+
${EGL_LDFLAGS}
5970
flutter_engine
6071
)
6172

6273
target_include_directories(flutter_wayland
6374
PRIVATE
64-
${WAYLAND_CLIENT_INCLUDE_DIRS}
65-
${WAYLAND_EGL_INCLUDE_DIRS}
66-
${EGL_INCLUDE_DIRS}
75+
${WAYLANDPP_CLIENT_INCLUDE_DIRS}
76+
${WAYLANDPP_CURSOR_INCLUDE_DIRS}
77+
${WAYLANDPP_EGL_INCLUDE_DIRS}
78+
${WAYLANDPP_CLIENT_EXTRA_INCLUDE_DIRS}
6779
${CMAKE_BINARY_DIR}
6880
)
81+
82+
target_compile_options(flutter_wayland PUBLIC ${EGL_CFLAGS})

src/Delegate.h

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
3+
Copyright (C) 2017 by Sergey A Kryukov: derived work
4+
http://www.SAKryukov.org
5+
http://www.codeproject.com/Members/SAKryukov
6+
7+
Based on original work by Sergey Ryazanov:
8+
"The Impossibly Fast C++ Delegates", 18 Jul 2005
9+
https://www.codeproject.com/articles/11015/the-impossibly-fast-c-delegates
10+
11+
MIT license:
12+
http://en.wikipedia.org/wiki/MIT_License
13+
14+
Original publication: https://www.codeproject.com/Articles/1170503/The-Impossibly-Fast-Cplusplus-Delegates-Fixed
15+
16+
*/
17+
18+
#pragma once
19+
#include "DelegateBase.h"
20+
21+
namespace SA {
22+
23+
template <typename T> class delegate;
24+
template <typename T> class multicast_delegate;
25+
26+
template<typename RET, typename ...PARAMS>
27+
class delegate<RET(PARAMS...)> final : private delegate_base<RET(PARAMS...)> {
28+
public:
29+
30+
delegate() = default;
31+
32+
bool isNull() const { return invocation.stub == nullptr; }
33+
bool operator ==(void* ptr) const {
34+
return (ptr == nullptr) && this->isNull();
35+
} //operator ==
36+
bool operator !=(void* ptr) const {
37+
return (ptr != nullptr) || (!this->isNull());
38+
} //operator !=
39+
40+
delegate(const delegate& another) { another.invocation.Clone(invocation); }
41+
42+
template <typename LAMBDA>
43+
delegate(const LAMBDA& lambda) {
44+
assign((void*)(&lambda), lambda_stub<LAMBDA>);
45+
} //delegate
46+
47+
delegate& operator =(const delegate& another) {
48+
another.invocation.Clone(invocation);
49+
return *this;
50+
} //operator =
51+
52+
template <typename LAMBDA> // template instantiation is not needed, will be deduced (inferred):
53+
delegate& operator =(const LAMBDA& instance) {
54+
assign((void*)(&instance), lambda_stub<LAMBDA>);
55+
return *this;
56+
} //operator =
57+
58+
bool operator == (const delegate& another) const { return invocation == another.invocation; }
59+
bool operator != (const delegate& another) const { return invocation != another.invocation; }
60+
61+
bool operator ==(const multicast_delegate<RET(PARAMS...)>& another) const { return another == (*this); }
62+
bool operator !=(const multicast_delegate<RET(PARAMS...)>& another) const { return another != (*this); }
63+
64+
template <class T, RET(T::*TMethod)(PARAMS...)>
65+
static delegate create(T* instance) {
66+
return delegate(instance, method_stub<T, TMethod>);
67+
} //create
68+
69+
template <class T, RET(T::*TMethod)(PARAMS...) const>
70+
static delegate create(T const* instance) {
71+
return delegate(const_cast<T*>(instance), const_method_stub<T, TMethod>);
72+
} //create
73+
74+
template <RET(*TMethod)(PARAMS...)>
75+
static delegate create() {
76+
return delegate(nullptr, function_stub<TMethod>);
77+
} //create
78+
79+
template <typename LAMBDA>
80+
static delegate create(const LAMBDA & instance) {
81+
return delegate((void*)(&instance), lambda_stub<LAMBDA>);
82+
} //create
83+
84+
RET operator()(PARAMS... arg) const {
85+
return (*invocation.stub)(invocation.object, arg...);
86+
} //operator()
87+
88+
private:
89+
90+
delegate(void* anObject, typename delegate_base<RET(PARAMS...)>::stub_type aStub) {
91+
invocation.object = anObject;
92+
invocation.stub = aStub;
93+
} //delegate
94+
95+
void assign(void* anObject, typename delegate_base<RET(PARAMS...)>::stub_type aStub) {
96+
this->invocation.object = anObject;
97+
this->invocation.stub = aStub;
98+
} //assign
99+
100+
template <class T, RET(T::*TMethod)(PARAMS...)>
101+
static RET method_stub(void* this_ptr, PARAMS... params) {
102+
T* p = static_cast<T*>(this_ptr);
103+
return (p->*TMethod)(params...);
104+
} //method_stub
105+
106+
template <class T, RET(T::*TMethod)(PARAMS...) const>
107+
static RET const_method_stub(void* this_ptr, PARAMS... params) {
108+
T* const p = static_cast<T*>(this_ptr);
109+
return (p->*TMethod)(params...);
110+
} //const_method_stub
111+
112+
template <RET(*TMethod)(PARAMS...)>
113+
static RET function_stub(void* this_ptr, PARAMS... params) {
114+
return (TMethod)(params...);
115+
} //function_stub
116+
117+
template <typename LAMBDA>
118+
static RET lambda_stub(void* this_ptr, PARAMS... arg) {
119+
LAMBDA* p = static_cast<LAMBDA*>(this_ptr);
120+
return (p->operator())(arg...);
121+
} //lambda_stub
122+
123+
friend class multicast_delegate<RET(PARAMS...)>;
124+
typename delegate_base<RET(PARAMS...)>::InvocationElement invocation;
125+
126+
}; //class delegate
127+
128+
} /* namespace SA */

src/DelegateBase.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
3+
Copyright (C) 2017 by Sergey A Kryukov: derived work
4+
http://www.SAKryukov.org
5+
http://www.codeproject.com/Members/SAKryukov
6+
7+
Based on original work by Sergey Ryazanov:
8+
"The Impossibly Fast C++ Delegates", 18 Jul 2005
9+
https://www.codeproject.com/articles/11015/the-impossibly-fast-c-delegates
10+
11+
MIT license:
12+
http://en.wikipedia.org/wiki/MIT_License
13+
14+
Original publication: https://www.codeproject.com/Articles/1170503/The-Impossibly-Fast-Cplusplus-Delegates-Fixed
15+
16+
*/
17+
18+
#pragma once
19+
20+
namespace SA {
21+
22+
template<typename T>
23+
class delegate_base;
24+
25+
template<typename RET, typename ...PARAMS>
26+
class delegate_base<RET(PARAMS...)> {
27+
28+
protected:
29+
30+
using stub_type = RET(*)(void* this_ptr, PARAMS...);
31+
32+
struct InvocationElement {
33+
InvocationElement() = default;
34+
InvocationElement(void* this_ptr, stub_type aStub) : object(this_ptr), stub(aStub) {}
35+
void Clone(InvocationElement& target) const {
36+
target.stub = stub;
37+
target.object = object;
38+
} //Clone
39+
bool operator ==(const InvocationElement& another) const {
40+
return another.stub == stub && another.object == object;
41+
} //==
42+
bool operator !=(const InvocationElement& another) const {
43+
return another.stub != stub || another.object != object;
44+
} //!=
45+
void* object = nullptr;
46+
stub_type stub = nullptr;
47+
}; //InvocationElement
48+
49+
}; //class delegate_base
50+
51+
} /* namespace SA */

src/flutter_application.cc

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <vector>
1313

1414
#include "utils.h"
15+
#include "wayland_display.h"
1516

1617
namespace flutter {
1718

@@ -40,8 +41,7 @@ static std::string GetICUDataPath() {
4041
FlutterApplication::FlutterApplication(
4142
std::string bundle_path,
4243
const std::vector<std::string>& command_line_args,
43-
RenderDelegate& render_delegate)
44-
: render_delegate_(render_delegate) {
44+
RenderDelegate& render_delegate) : render_delegate_(render_delegate) {
4545
if (!FlutterAssetBundleIsValid(bundle_path)) {
4646
FLWAY_ERROR << "Flutter asset bundle was not valid." << std::endl;
4747
return;
@@ -94,8 +94,6 @@ FlutterApplication::FlutterApplication(
9494
FlutterProjectArgs args = {
9595
.struct_size = sizeof(FlutterProjectArgs),
9696
.assets_path = bundle_path.c_str(),
97-
.main_path = "",
98-
.packages_path = "",
9997
.icu_data_path = icu_data_path.c_str(),
10098
.command_line_argc = static_cast<int>(command_line_args_c.size()),
10199
.command_line_argv = command_line_args_c.data(),
@@ -110,6 +108,13 @@ FlutterApplication::FlutterApplication(
110108
return;
111109
}
112110

111+
// wire up delegates
112+
OnEnter_ = decltype(WaylandDisplay::OnEnter)::create<FlutterApplication, &FlutterApplication::OnEnter>(this);
113+
OnLeave_ = decltype(WaylandDisplay::OnLeave)::create<FlutterApplication, &FlutterApplication::OnLeave>(this);
114+
OnMotion_ = decltype(WaylandDisplay::OnMotion)::create<FlutterApplication, &FlutterApplication::OnMotion>(this);
115+
OnButton_ = decltype(WaylandDisplay::OnButton)::create<FlutterApplication, &FlutterApplication::OnButton>(this);
116+
OnAxis_ = decltype(WaylandDisplay::OnAxis)::create<FlutterApplication, &FlutterApplication::OnAxis>(this);
117+
113118
valid_ = true;
114119
}
115120

@@ -182,4 +187,29 @@ bool FlutterApplication::SendFlutterPointerEvent(FlutterPointerPhase phase,
182187
return FlutterEngineSendPointerEvent(engine_, &event, 1) == kSuccess;
183188
}
184189

190+
void FlutterApplication::OnEnter(uint32_t serial, wayland::surface_t surface, int32_t surface_x, int32_t surface_y)
191+
{
192+
std::cout << "OnEnter serial: " << serial << " surface: " << surface.interface_name << " x: " << surface_x << " y: " << surface_y << std::endl;
193+
}
194+
195+
void FlutterApplication::OnLeave(uint32_t serial, wayland::surface_t surface)
196+
{
197+
std::cout << "OnLeave serial: " << serial << " surface: " << surface.interface_name << std::endl;
198+
}
199+
200+
void FlutterApplication::OnMotion(uint32_t time, double surface_x, double surface_y)
201+
{
202+
std::cout << "OnMotion time: " << time << " x: " << surface_y << " y: " << surface_y << std::endl;
203+
}
204+
205+
void FlutterApplication::OnButton(uint32_t serial, uint32_t time, uint32_t button, wayland::pointer_button_state state)
206+
{
207+
std::cout << "OnButton serial: " << serial << " time: " << time << " button: " << button << " state: " << static_cast<uint32_t>(state) << std::endl;
208+
}
209+
210+
void FlutterApplication::OnAxis(uint32_t time, wayland::pointer_axis axis, double value)
211+
{
212+
std::cout << "OnAxis time: " << time << " axis: " << static_cast<uint32_t>(axis) << " value: " << value << std::endl;
213+
}
214+
185215
} // namespace flutter

src/flutter_application.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
#include <functional>
1010
#include <vector>
11+
#include <wayland-client.hpp>
1112

1213
#include "macros.h"
14+
#include "Delegate.h"
1315

1416
namespace flutter {
1517

@@ -27,8 +29,8 @@ class FlutterApplication {
2729
};
2830

2931
FlutterApplication(std::string bundle_path,
30-
const std::vector<std::string>& args,
31-
RenderDelegate& render_delegate);
32+
const std::vector<std::string>& args,
33+
RenderDelegate& render_delegate);
3234

3335
~FlutterApplication();
3436

@@ -48,6 +50,18 @@ class FlutterApplication {
4850

4951
bool SendFlutterPointerEvent(FlutterPointerPhase phase, double x, double y);
5052

53+
SA::delegate<void (uint32_t serial, wayland::surface_t, int32_t surface_x, int32_t surface_y)> OnEnter_;
54+
SA::delegate<void (uint32_t serial, wayland::surface_t surface)> OnLeave_;
55+
SA::delegate<void (uint32_t time, double surface_x, double surface_y)> OnMotion_;
56+
SA::delegate<void (uint32_t serial, uint32_t time, uint32_t button, wayland::pointer_button_state state)> OnButton_;
57+
SA::delegate<void (uint32_t time, wayland::pointer_axis axis, double value)> OnAxis_;
58+
59+
void OnEnter(uint32_t serial, wayland::surface_t surface, int32_t surface_x, int32_t surface_y);
60+
void OnLeave(uint32_t serial, wayland::surface_t surface);
61+
void OnMotion(uint32_t time, double surface_x, double surface_y);
62+
void OnButton(uint32_t serial, uint32_t time, uint32_t button, wayland::pointer_button_state state);
63+
void OnAxis(uint32_t time, wayland::pointer_axis axis, double value);
64+
5165
FLWAY_DISALLOW_COPY_AND_ASSIGN(FlutterApplication);
5266
};
5367

0 commit comments

Comments
 (0)