fix(signals): Use pointer to value
Only pass pointers to emitted signal value since the signal receivers will be called on the same thread as the signal emitter. Refs #302
This commit is contained in:
parent
5f6a1f5ae6
commit
f4406783e2
@ -41,38 +41,18 @@ namespace signals {
|
||||
class value_signal : public base_signal<Derived> {
|
||||
public:
|
||||
using base_type = value_signal<Derived, ValueType>;
|
||||
using value_type = ValueType;
|
||||
|
||||
template <size_t Size = sizeof(ValueType)>
|
||||
explicit value_signal(void* data) : m_data(data), m_size(Size) {}
|
||||
explicit value_signal(void* data) : m_ptr(data) {}
|
||||
explicit value_signal(ValueType&& data) : m_ptr(&data) {}
|
||||
|
||||
template <size_t Size = sizeof(ValueType)>
|
||||
explicit value_signal(ValueType data) : m_size(Size) {
|
||||
m_data = new char[Size];
|
||||
m_alloced = true;
|
||||
memcpy(m_data, static_cast<void*>(&data), Size);
|
||||
}
|
||||
virtual ~value_signal() {}
|
||||
|
||||
virtual ~value_signal() {
|
||||
if (m_alloced) {
|
||||
delete[] static_cast<char*>(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
void* data() const {
|
||||
return m_data;
|
||||
}
|
||||
size_t size() const {
|
||||
return m_size;
|
||||
}
|
||||
inline ValueType cast() const {
|
||||
return *static_cast<ValueType*>(m_data);
|
||||
return *static_cast<ValueType*>(m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
void* m_data;
|
||||
size_t m_size;
|
||||
bool m_alloced{false};
|
||||
void* m_ptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -514,7 +514,7 @@ void bar::handle(const evt::leave_notify&) {
|
||||
if (!m_opts.dimmed) {
|
||||
m_taskqueue->defer_unique("window-dim", 3s, [&](size_t) {
|
||||
m_opts.dimmed = true;
|
||||
m_sig.emit(dim_window{m_opts.dimvalue});
|
||||
m_sig.emit(dim_window{double(m_opts.dimvalue)});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ bool controller::enqueue(string&& input_data) {
|
||||
} else if (chrono::system_clock::now() - m_swallow_input < m_lastinput) {
|
||||
m_log.trace("controller: Swallowing input event (throttled)");
|
||||
} else {
|
||||
m_inputdata = input_data;
|
||||
m_inputdata = forward<string>(input_data);
|
||||
return enqueue(make_input_evt());
|
||||
}
|
||||
return false;
|
||||
|
@ -184,7 +184,7 @@ size_t parser::text(string&& data) {
|
||||
}
|
||||
|
||||
pkt.length = len;
|
||||
m_sig.emit(write_text_string{static_cast<void*>(&pkt)});
|
||||
m_sig.emit(write_text_string{move(pkt)});
|
||||
}
|
||||
|
||||
if (pos > 0) {
|
||||
|
@ -707,7 +707,7 @@ bool renderer::on(const write_text_unicode& evt) {
|
||||
}
|
||||
|
||||
bool renderer::on(const write_text_string& evt) {
|
||||
auto pkt = *static_cast<const parser::packet*>(evt.data());
|
||||
auto pkt = evt.cast();
|
||||
draw_textstring(pkt.data, pkt.length);
|
||||
return true;
|
||||
}
|
||||
|
@ -1097,7 +1097,7 @@ void tray_manager::handle(const evt::map_notify& evt) {
|
||||
if (clientcount > m_opts.configured_slots) {
|
||||
reconfigure();
|
||||
}
|
||||
m_sig.emit(signals::ui_tray::mapped_clients{clientcount});
|
||||
m_sig.emit(signals::ui_tray::mapped_clients{move(clientcount)});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user