-
Notifications
You must be signed in to change notification settings - Fork 178
/
wl-listener-wrapper.tpp
60 lines (50 loc) · 1.1 KB
/
wl-listener-wrapper.tpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/** Implementation for wf::wl_listener_wrapper */
#include <wayfire/util.hpp>
namespace wf
{
static void handle_wrapped_listener(wl_listener *listener, void *data)
{
wf::wl_listener_wrapper::wrapper *wrap =
wl_container_of(listener, wrap, listener);
wrap->self->emit(data);
}
wl_listener_wrapper::wl_listener_wrapper()
{
_wrap.self = this;
_wrap.listener.notify = handle_wrapped_listener;
wl_list_init(&_wrap.listener.link);
}
wl_listener_wrapper::~wl_listener_wrapper()
{
disconnect();
}
void wl_listener_wrapper::set_callback(callback_t _call)
{
this->call = _call;
}
bool wl_listener_wrapper::connect(wl_signal *signal)
{
if (is_connected())
{
return false;
}
wl_signal_add(signal, &_wrap.listener);
return true;
}
void wl_listener_wrapper::disconnect()
{
wl_list_remove(&_wrap.listener.link);
wl_list_init(&_wrap.listener.link);
}
bool wl_listener_wrapper::is_connected() const
{
return !wl_list_empty(&_wrap.listener.link);
}
void wl_listener_wrapper::emit(void *data)
{
if (this->call)
{
this->call(data);
}
}
}