event handlings here
parent
d8b87ca1e7
commit
4b6f06a532
|
@ -27,7 +27,19 @@ void XcbDevice::windowDestroyed(xcb_window_t window_id) {
|
|||
|
||||
void XcbDevice::handleEvents() {
|
||||
while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection)) {
|
||||
|
||||
switch (event->response_type & ~0x80) {
|
||||
case XCB_EXPOSE: {
|
||||
xcb_expose_event_t *expose =
|
||||
reinterpret_cast<xcb_expose_event_t *>(event);
|
||||
auto find = windows.find(expose->window);
|
||||
if (find != windows.end()) {
|
||||
assert(find->second);
|
||||
find->second->resizeEvent(static_cast<size_t>(expose->x),static_cast<size_t>(expose->y), static_cast<size_t>(expose->width), static_cast<size_t>(expose->height));
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
free(event);
|
||||
}
|
||||
}
|
||||
|
@ -58,9 +70,11 @@ Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode &video_mode,
|
|||
title_view.data());
|
||||
|
||||
xcb_flush(xcb_connection);
|
||||
|
||||
return heap<XcbWindow>(*this, xcb_window, xcb_colormap, video_mode,
|
||||
auto window = heap<XcbWindow>(*this, xcb_window, xcb_colormap, video_mode,
|
||||
title_view);
|
||||
windows[xcb_window] = window.get();
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
Own<Window> XcbDevice::createWindow(const VideoMode &video_mode,
|
||||
|
|
|
@ -53,13 +53,7 @@ void XcbGlWindow::swap() {
|
|||
|
||||
const VideoMode &XcbGlWindow::videoMode() const {
|
||||
assert(window);
|
||||
if (window) {
|
||||
return window->videoMode();
|
||||
}
|
||||
{
|
||||
static VideoMode mode_which_should_never_exist;
|
||||
return mode_which_should_never_exist;
|
||||
}
|
||||
return window->videoMode();
|
||||
}
|
||||
|
||||
const std::string_view XcbGlWindow::title() const {
|
||||
|
@ -76,4 +70,9 @@ void XcbGlWindow::resize(size_t height, size_t width) {
|
|||
window->resize(height, width);
|
||||
}
|
||||
}
|
||||
|
||||
Conveyor<Window::VariantEvent> XcbGlWindow::onEvent() {
|
||||
assert(window);
|
||||
return window->onEvent();
|
||||
}
|
||||
} // namespace gin
|
|
@ -28,5 +28,7 @@ public:
|
|||
const std::string_view title() const override;
|
||||
|
||||
void resize(size_t height, size_t width) override;
|
||||
|
||||
Conveyor<Window::VariantEvent> onEvent() override;
|
||||
};
|
||||
} // namespace gin
|
|
@ -47,4 +47,13 @@ Conveyor<Window::VariantEvent> XcbWindow::onEvent() {
|
|||
event_feeder = std::move(caf.feeder);
|
||||
return std::move(caf.conveyor);
|
||||
}
|
||||
|
||||
void XcbWindow::resizeEvent(size_t x, size_t y, size_t width, size_t height){
|
||||
(void)x;
|
||||
(void)y;
|
||||
/// @todo maybe include x and y?
|
||||
if(event_feeder){
|
||||
event_feeder->feed(Window::VariantEvent{Window::Event::Resize{width, height}});
|
||||
}
|
||||
}
|
||||
} // namespace gin
|
||||
|
|
|
@ -37,5 +37,7 @@ public:
|
|||
void resize(size_t width, size_t height) override;
|
||||
|
||||
Conveyor<Window::VariantEvent> onEvent() override;
|
||||
|
||||
void resizeEvent(size_t x, size_t y, size_t width, size_t height);
|
||||
};
|
||||
} // namespace gin
|
|
@ -1,7 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "../window.h"
|
||||
#include "../video_mode.h"
|
||||
|
||||
#include <kelgin/async.h>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace gin {
|
||||
|
@ -22,5 +25,7 @@ public:
|
|||
virtual const std::string_view title() const = 0;
|
||||
|
||||
virtual void resize(size_t height, size_t width) = 0;
|
||||
|
||||
virtual Conveyor<Window::VariantEvent> onEvent() = 0;
|
||||
};
|
||||
} // namespace gin
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
namespace gin {
|
||||
class VideoMode {
|
||||
public:
|
||||
size_t height = 128;
|
||||
size_t width = 128;
|
||||
size_t height = 128;
|
||||
};
|
||||
} // namespace gin
|
||||
|
|
Loading…
Reference in New Issue