more events
parent
19240182f6
commit
74f472a8b3
|
@ -40,6 +40,26 @@ void XcbDevice::handleEvents() {
|
|||
static_cast<size_t>(expose->height));
|
||||
}
|
||||
} break;
|
||||
case XCB_BUTTON_RELEASE: {
|
||||
xcb_button_release_event_t *button =
|
||||
reinterpret_cast<xcb_button_release_event_t *>(event);
|
||||
auto find = windows.find(button->event);
|
||||
if (find != windows.end()) {
|
||||
assert(find->second);
|
||||
find->second->mouseEvent(button->event_x, button->event_y,
|
||||
button->state, false);
|
||||
}
|
||||
} break;
|
||||
case XCB_BUTTON_PRESS: {
|
||||
xcb_button_press_event_t *button =
|
||||
reinterpret_cast<xcb_button_press_event_t *>(event);
|
||||
auto find = windows.find(button->event);
|
||||
if (find != windows.end()) {
|
||||
assert(find->second);
|
||||
find->second->mouseEvent(button->event_x, button->event_y,
|
||||
button->state, true);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -132,4 +152,4 @@ Own<XcbDevice> createXcbDevice(AsyncIoProvider &provider) {
|
|||
Own<Device> createDevice(AsyncIoProvider &provider) {
|
||||
return createXcbDevice(provider);
|
||||
}
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -52,9 +52,60 @@ 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?
|
||||
video_mode.width = width;
|
||||
video_mode.height = height;
|
||||
|
||||
if (event_feeder) {
|
||||
event_feeder->feed(
|
||||
Window::VariantEvent{Window::Event::Resize{width, height}});
|
||||
}
|
||||
}
|
||||
|
||||
void XcbWindow::mouseEvent(int16_t x, int16_t y, uint16_t state, bool pressed) {
|
||||
if (x < 0 || y < 0) {
|
||||
return;
|
||||
}
|
||||
uint32_t ux = static_cast<uint32_t>(x);
|
||||
uint32_t uy = static_cast<uint32_t>(y);
|
||||
if (ux >= video_mode.width || uy >= video_mode.height) {
|
||||
return;
|
||||
}
|
||||
if (event_feeder) {
|
||||
event_feeder->feed(
|
||||
Window::VariantEvent{Window::Event::Mouse{state, pressed, ux, uy}});
|
||||
}
|
||||
}
|
||||
|
||||
void XcbWindow::mouseMoveEvent(int16_t x, int16_t y, uint16_t state,
|
||||
uint8_t move_type) {
|
||||
if (x < 0 || y < 0) {
|
||||
return;
|
||||
}
|
||||
uint32_t ux = static_cast<uint32_t>(x);
|
||||
uint32_t uy = static_cast<uint32_t>(y);
|
||||
if (ux >= video_mode.width || uy >= video_mode.height) {
|
||||
return;
|
||||
}
|
||||
if (event_feeder) {
|
||||
event_feeder->feed(Window::VariantEvent{
|
||||
Window::Event::Mouse{state, move_type, ux, uy}});
|
||||
}
|
||||
}
|
||||
|
||||
void XcbWindow::keyboardEvent(int16_t x, int16_t y, uint32_t keycode,
|
||||
bool pressed) {
|
||||
if (x < 0 || y < 0) {
|
||||
return;
|
||||
}
|
||||
uint32_t ux = static_cast<uint32_t>(x);
|
||||
uint32_t uy = static_cast<uint32_t>(y);
|
||||
if (ux >= video_mode.width || uy >= video_mode.height) {
|
||||
return;
|
||||
}
|
||||
if (event_feeder) {
|
||||
event_feeder->feed(Window::VariantEvent{
|
||||
Window::Event::Keyboard{keycode, keycode, pressed, false}});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gin
|
||||
|
|
|
@ -39,5 +39,9 @@ public:
|
|||
Conveyor<Window::VariantEvent> onEvent() override;
|
||||
|
||||
void resizeEvent(size_t x, size_t y, size_t width, size_t height);
|
||||
void mouseEvent(int16_t x, int16_t y, uint16_t state, bool pressed);
|
||||
void mouseMoveEvent(int16_t x, int16_t y, uint16_t state,
|
||||
uint8_t move_type);
|
||||
void keyboardEvent(int16_t x, int16_t y, uint32_t keycode, bool pressed);
|
||||
};
|
||||
} // namespace gin
|
|
@ -18,9 +18,31 @@ public:
|
|||
size_t width;
|
||||
size_t height;
|
||||
};
|
||||
|
||||
struct Keyboard {
|
||||
uint32_t key;
|
||||
uint32_t scan;
|
||||
bool pressed;
|
||||
bool repeat;
|
||||
};
|
||||
|
||||
struct Mouse {
|
||||
uint16_t button_mask;
|
||||
bool pressed;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
};
|
||||
|
||||
struct MouseMove {
|
||||
uint16_t button_mask;
|
||||
uint8_t type;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
};
|
||||
};
|
||||
|
||||
using VariantEvent = std::variant<Event::Resize>;
|
||||
using VariantEvent = std::variant<Event::Resize, Event::Keyboard,
|
||||
Event::Mouse, Event::MouseMove>;
|
||||
|
||||
virtual ~Window() = default;
|
||||
|
||||
|
|
Loading…
Reference in New Issue