Compare commits
3 commits
e76e2b43a1
...
d5212ea574
Author | SHA1 | Date | |
---|---|---|---|
|
d5212ea574 | ||
|
6e16ab35cd | ||
|
3fa1647fc9 |
4 changed files with 48 additions and 12 deletions
|
@ -1,14 +1,37 @@
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
bool Application::wake() {
|
||||||
|
if (!m_wakeup_pipe_available) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t buf = 0;
|
||||||
|
write(m_wakeup_pipe_write_end, &buf, 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Application::add_window(std::shared_ptr<Window> window) {
|
void Application::add_window(std::shared_ptr<Window> window) {
|
||||||
m_windows.push_back(window);
|
m_windows.push_back(window);
|
||||||
update_fds();
|
update_fds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::update_fds() {
|
void Application::update_fds() {
|
||||||
|
if (m_should_create_wakeup_pipe) {
|
||||||
|
m_should_create_wakeup_pipe = false;
|
||||||
|
int pipe_fds[2];
|
||||||
|
if (pipe(pipe_fds) != 0) {
|
||||||
|
// TODO: handle this?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_wakeup_pipe_read_end = pipe_fds[0];
|
||||||
|
m_wakeup_pipe_write_end = pipe_fds[1];
|
||||||
|
m_wakeup_pipe_available = true;
|
||||||
|
}
|
||||||
for (int i = 0; i < RAVEN_APPLICATION_MAX_WINDOWS; i++) {
|
for (int i = 0; i < RAVEN_APPLICATION_MAX_WINDOWS; i++) {
|
||||||
m_fds[i].fd = -1;
|
m_fds[i].fd = -1;
|
||||||
m_fds[i].events = 0;
|
m_fds[i].events = 0;
|
||||||
|
@ -18,6 +41,12 @@ void Application::update_fds() {
|
||||||
m_fds[i].fd = m_windows[i]->file_descriptor();
|
m_fds[i].fd = m_windows[i]->file_descriptor();
|
||||||
m_fds[i].events = POLL_IN;
|
m_fds[i].events = POLL_IN;
|
||||||
}
|
}
|
||||||
|
if (m_wakeup_pipe_available) {
|
||||||
|
int wakeup_pipe_index = m_windows.size();
|
||||||
|
m_fds[wakeup_pipe_index].fd = m_wakeup_pipe_read_end;
|
||||||
|
m_fds[wakeup_pipe_index].events = POLL_IN;
|
||||||
|
m_fds[wakeup_pipe_index].revents = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::turn() {
|
int Application::turn() {
|
||||||
|
@ -25,11 +54,14 @@ int Application::turn() {
|
||||||
update_fds();
|
update_fds();
|
||||||
m_fds_need_update = false;
|
m_fds_need_update = false;
|
||||||
}
|
}
|
||||||
if (poll(m_fds, m_windows.size(), -1) > 0) {
|
if (poll(m_fds, m_windows.size() + 1, -1) > 0) {
|
||||||
for (size_t i = 0; i < m_windows.size(); i++) {
|
for (size_t i = 0; i < m_windows.size(); i++) {
|
||||||
if (m_fds[i].revents & POLLIN) {
|
m_windows[i]->run(false);
|
||||||
m_windows[i]->run(false);
|
}
|
||||||
}
|
while (!m_microtasks.empty()) {
|
||||||
|
auto callback = m_microtasks.front();
|
||||||
|
callback();
|
||||||
|
m_microtasks.pop();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -12,8 +12,12 @@ namespace Raven {
|
||||||
class Application {
|
class Application {
|
||||||
public:
|
public:
|
||||||
Application() {}
|
Application() {}
|
||||||
|
Application(bool should_create_wakeup_pipe)
|
||||||
|
: m_should_create_wakeup_pipe(should_create_wakeup_pipe) {}
|
||||||
|
|
||||||
void add_window(std::shared_ptr<Window>);
|
void add_window(std::shared_ptr<Window>);
|
||||||
|
bool wake();
|
||||||
|
void queue_microtask(std::function<void()> callback) { m_microtasks.push(callback); }
|
||||||
int turn();
|
int turn();
|
||||||
int run();
|
int run();
|
||||||
|
|
||||||
|
@ -29,6 +33,11 @@ private:
|
||||||
std::vector<std::shared_ptr<Window>> m_windows;
|
std::vector<std::shared_ptr<Window>> m_windows;
|
||||||
struct pollfd m_fds[RAVEN_APPLICATION_MAX_WINDOWS];
|
struct pollfd m_fds[RAVEN_APPLICATION_MAX_WINDOWS];
|
||||||
bool m_fds_need_update { true };
|
bool m_fds_need_update { true };
|
||||||
|
bool m_should_create_wakeup_pipe { false };
|
||||||
|
bool m_wakeup_pipe_available { false };
|
||||||
|
int m_wakeup_pipe_read_end { -1 };
|
||||||
|
int m_wakeup_pipe_write_end { -1 };
|
||||||
|
std::queue<std::function<void()>> m_microtasks;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -94,13 +94,8 @@ bool BoxLayout::run() {
|
||||||
auto child = m_target->children()[i];
|
auto child = m_target->children()[i];
|
||||||
Slot slot = working_slots[i];
|
Slot slot = working_slots[i];
|
||||||
|
|
||||||
std::cout << "SLOT! " << i << std::endl;
|
|
||||||
|
|
||||||
if (slot.type == SlotType::Auto) {
|
if (slot.type == SlotType::Auto) {
|
||||||
std::cout << "auto - setting to " << space_per_unslotted_widget << std::endl;
|
|
||||||
slot.pixel = space_per_unslotted_widget;
|
slot.pixel = space_per_unslotted_widget;
|
||||||
} else {
|
|
||||||
std::cout << "pixel: " << slot.pixel << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure pixel values are aligned to the pixel grid
|
// make sure pixel values are aligned to the pixel grid
|
||||||
|
|
|
@ -252,12 +252,12 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
|
||||||
update_activation_to = true;
|
update_activation_to = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_rect.contains(event.point())) {
|
if (m_rect.contains(event.point())) {
|
||||||
|
on_mouse_button(event);
|
||||||
|
} else {
|
||||||
update_activation_to = false;
|
update_activation_to = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
on_mouse_button(event);
|
|
||||||
|
|
||||||
if (m_is_active != update_activation_to || (update_activation_to && m_window->active_widget() != this)) {
|
if (m_is_active != update_activation_to || (update_activation_to && m_window->active_widget() != this)) {
|
||||||
m_is_active = update_activation_to;
|
m_is_active = update_activation_to;
|
||||||
if (m_is_active && m_window)
|
if (m_is_active && m_window)
|
||||||
|
|
Loading…
Reference in a new issue