Compare commits

..

No commits in common. "d5212ea57472721eaf1f3020252e8f9b86561a93" and "e76e2b43a1c8f2749bb549073303f9650c750ff9" have entirely different histories.

4 changed files with 12 additions and 48 deletions

View file

@ -1,37 +1,14 @@
#include "Application.hpp"
#include <poll.h>
#include <unistd.h>
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) {
m_windows.push_back(window);
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++) {
m_fds[i].fd = -1;
m_fds[i].events = 0;
@ -41,12 +18,6 @@ void Application::update_fds() {
m_fds[i].fd = m_windows[i]->file_descriptor();
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() {
@ -54,14 +25,11 @@ int Application::turn() {
update_fds();
m_fds_need_update = false;
}
if (poll(m_fds, m_windows.size() + 1, -1) > 0) {
if (poll(m_fds, m_windows.size(), -1) > 0) {
for (size_t i = 0; i < m_windows.size(); i++) {
m_windows[i]->run(false);
}
while (!m_microtasks.empty()) {
auto callback = m_microtasks.front();
callback();
m_microtasks.pop();
if (m_fds[i].revents & POLLIN) {
m_windows[i]->run(false);
}
}
} else {
return 1;

View file

@ -12,12 +12,8 @@ namespace Raven {
class Application {
public:
Application() {}
Application(bool should_create_wakeup_pipe)
: m_should_create_wakeup_pipe(should_create_wakeup_pipe) {}
void add_window(std::shared_ptr<Window>);
bool wake();
void queue_microtask(std::function<void()> callback) { m_microtasks.push(callback); }
int turn();
int run();
@ -33,11 +29,6 @@ private:
std::vector<std::shared_ptr<Window>> m_windows;
struct pollfd m_fds[RAVEN_APPLICATION_MAX_WINDOWS];
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;
};
}

View file

@ -94,8 +94,13 @@ bool BoxLayout::run() {
auto child = m_target->children()[i];
Slot slot = working_slots[i];
std::cout << "SLOT! " << i << std::endl;
if (slot.type == SlotType::Auto) {
std::cout << "auto - setting to " << space_per_unslotted_widget << std::endl;
slot.pixel = space_per_unslotted_widget;
} else {
std::cout << "pixel: " << slot.pixel << std::endl;
}
// make sure pixel values are aligned to the pixel grid

View file

@ -252,12 +252,12 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
update_activation_to = true;
}
if (m_rect.contains(event.point())) {
on_mouse_button(event);
} else {
if (!m_rect.contains(event.point())) {
update_activation_to = false;
}
on_mouse_button(event);
if (m_is_active != update_activation_to || (update_activation_to && m_window->active_widget() != this)) {
m_is_active = update_activation_to;
if (m_is_active && m_window)