add microtask system and temporary logging system
This commit is contained in:
parent
9f52cad7e9
commit
cc1d49c435
4 changed files with 36 additions and 1 deletions
|
@ -5,6 +5,8 @@ project(
|
|||
)
|
||||
project_description = 'The Raven user interface library'
|
||||
|
||||
add_project_arguments('-g3', language : 'cpp')
|
||||
|
||||
cairomm_dep = dependency('cairomm-1.0')
|
||||
pangocairo_dep = dependency('pangocairo')
|
||||
xlib_dep = dependency('x11')
|
||||
|
|
5
src/Logging.hpp
Normal file
5
src/Logging.hpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define ERROR std::clog << "[ERROR] (" << __FILE__ << ":" << __LINE__ << "): "
|
||||
#define INFO std::clog << "[INFO] (" << __FILE__ << ":" << __LINE__ << "): "
|
||||
#define WARN std::clog << "[WARN] (" << __FILE__ << ":" << __LINE__ << "): "
|
|
@ -10,6 +10,7 @@
|
|||
#include "Window.hpp"
|
||||
#include "Events.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "Logging.hpp"
|
||||
|
||||
namespace Raven {
|
||||
|
||||
|
@ -65,7 +66,10 @@ bool Window::dispatch_to_main_widget(Event &event) {
|
|||
if (!m_main_widget)
|
||||
return false;
|
||||
|
||||
//std::cout << "Dispatched " << event.name() << " to main widget" << std::endl;
|
||||
// MouseMove events tend to spam the output
|
||||
if (event.type() != EventType::MouseMove) {
|
||||
INFO << "Dispatched event '" << event.name() << "' to main widget" << std::endl;
|
||||
}
|
||||
|
||||
m_main_widget->dispatch_event(event);
|
||||
return true;
|
||||
|
@ -112,6 +116,7 @@ void Window::reflow() {
|
|||
}
|
||||
|
||||
void Window::start_batch() {
|
||||
//INFO << "New batch started. Current count: " << m_batches << std::endl;
|
||||
m_batches++;
|
||||
}
|
||||
|
||||
|
@ -122,6 +127,7 @@ void Window::end_batch() {
|
|||
// we are only interested in performing batch operations for the last batch
|
||||
if (m_batches > 1) {
|
||||
m_batches--;
|
||||
//INFO << "Consumed batch. Current count: " << m_batches << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -135,6 +141,7 @@ void Window::end_batch() {
|
|||
|
||||
m_did_relayout_during_batch = false;
|
||||
m_did_repaint_during_batch = false;
|
||||
INFO << "Performed all batch actions." << std::endl;
|
||||
}
|
||||
|
||||
void Window::run(bool block) {
|
||||
|
@ -148,10 +155,12 @@ void Window::run(bool block) {
|
|||
|
||||
switch (e.type) {
|
||||
case MapNotify: {
|
||||
INFO << "[X11 EVENT] MapNotify" << std::endl;
|
||||
end_batch();
|
||||
break;
|
||||
}
|
||||
case ConfigureNotify: {
|
||||
INFO << "[X11 EVENT] ConfigureNotify" << std::endl;
|
||||
if (e.xconfigure.width != m_rect.width() || e.xconfigure.height != m_rect.height()) {
|
||||
m_xlib_surface->set_size(e.xconfigure.width, e.xconfigure.height);
|
||||
m_rect.set_width(e.xconfigure.width);
|
||||
|
@ -169,24 +178,29 @@ void Window::run(bool block) {
|
|||
break;
|
||||
}
|
||||
case Expose: {
|
||||
INFO << "[X11 EVENT] Expose" << std::endl;
|
||||
if (e.xexpose.count == 0) {
|
||||
reflow();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ButtonRelease: {
|
||||
INFO << "[X11 EVENT] ButtonRelease" << std::endl;
|
||||
auto point = Point(e.xbutton.x, e.xbutton.y);
|
||||
auto event = MouseButtonEvent(false, false, false, false, point);
|
||||
dispatch_to_main_widget(event);
|
||||
break;
|
||||
}
|
||||
case ButtonPress: {
|
||||
INFO << "[X11 EVENT] ButtonPress" << std::endl;
|
||||
auto point = Point(e.xbutton.x, e.xbutton.y);
|
||||
auto event = MouseButtonEvent(e.xbutton.button == Button1, e.xbutton.button == Button2, e.xbutton.button == Button4, e.xbutton.button == Button5, point);
|
||||
dispatch_to_main_widget(event);
|
||||
break;
|
||||
}
|
||||
case MotionNotify: {
|
||||
// spammy
|
||||
//INFO << "[X11 EVENT] MotionNotify" << std::endl;
|
||||
auto point = Point(e.xmotion.x, e.xmotion.y);
|
||||
auto event = MouseMoveEvent(point);
|
||||
dispatch_to_main_widget(event);
|
||||
|
@ -195,6 +209,16 @@ void Window::run(bool block) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (XPending(m_x_display) == 0 && !m_microtasks.empty()) {
|
||||
start_batch();
|
||||
while (!m_microtasks.empty()) {
|
||||
auto callback = m_microtasks.front();
|
||||
callback();
|
||||
m_microtasks.pop();
|
||||
}
|
||||
end_batch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <cairomm/xlib_surface.h>
|
||||
#include <functional>
|
||||
#include <queue>
|
||||
|
||||
namespace Raven {
|
||||
|
||||
|
@ -41,6 +42,8 @@ public:
|
|||
void relayout();
|
||||
void reflow();
|
||||
|
||||
void queue_microtask(std::function<void()> callback) { m_microtasks.push(callback); }
|
||||
|
||||
Box &rect() { return m_rect; }
|
||||
|
||||
template<typename T, class... Args>
|
||||
|
@ -59,6 +62,7 @@ private:
|
|||
int m_batches { 1 };
|
||||
bool m_did_repaint_during_batch { false };
|
||||
bool m_did_relayout_during_batch { false };
|
||||
std::queue<std::function<void()>> m_microtasks;
|
||||
|
||||
Display *m_x_display { nullptr };
|
||||
|
||||
|
|
Loading…
Reference in a new issue