From 5999d62660c051a9cbe46b0d206f60d0bc808114 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 12 Oct 2017 21:05:39 -0400 Subject: [PATCH] handle window resizes --- src/gui/Window.cc | 18 ++++++++++-------- src/gui/Window.h | 2 +- src/gui/jtk/Jtk_event.cc | 19 +++++++++++++++++++ src/gui/jtk/Jtk_event.h | 8 ++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 3778fc0..9f59172 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -121,7 +121,7 @@ bool Window::create(std::shared_ptr buffer) m_command_buffer_pane->set_command_mode(); m_command_buffer_screen_rows = 1; - resize(); + resize(INITIAL_WIDTH, INITIAL_HEIGHT); m_redraw_requested = true; @@ -177,6 +177,11 @@ void Window::handle_event(Jtk_Event & event) m_redraw_requested = true; break; + case JTK_EVENT_WINDOW_RESIZE: + resize(event.resize.width, event.resize.height); + m_redraw_requested = true; + break; + #if 0 case SDL_WINDOWEVENT: switch (event.window.event) @@ -355,13 +360,10 @@ void Window::handle_keypress(uint32_t keyval) } } -void Window::resize() +void Window::resize(size_t width, size_t height) { - m_width = 800; - m_height = 800; -#if 0 - SDL_GetWindowSize(m_window, &m_width, &m_height); -#endif + m_width = width; + m_height = height; glViewport(0, 0, m_width, m_height); m_gl->resize(m_width, m_height); int command_buffer_height = m_command_buffer_screen_rows * m_font->get_line_height(); @@ -378,7 +380,7 @@ void Window::redraw() m_command_buffer_screen_rows = 1; if (m_command_buffer_screen_rows != last_command_buffer_screen_rows) { - resize(); + resize(m_width, m_height); } last_command_buffer_screen_rows = m_command_buffer_screen_rows; diff --git a/src/gui/Window.h b/src/gui/Window.h index ba7c0f1..5ae05bf 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -41,7 +41,7 @@ public: protected: - void resize(); + void resize(size_t width, size_t height); void redraw(); void handle_event(Jtk_Event & event); void handle_keypress(uint32_t keyval); diff --git a/src/gui/jtk/Jtk_event.cc b/src/gui/jtk/Jtk_event.cc index 1cc9394..ccd4530 100644 --- a/src/gui/jtk/Jtk_event.cc +++ b/src/gui/jtk/Jtk_event.cc @@ -260,6 +260,22 @@ static bool ProcessXKeyReleaseEvent(XEvent * x_event, Jtk_Event * event) return false; } +/** + * Process an X configure event. + * + * @param x_event + * Pointer to the X event. + * @param event + * Pointer to the Jtk event. + */ +static bool ProcessConfigureEvent(XEvent * x_event, Jtk_Event * event) +{ + event->type = JTK_EVENT_WINDOW_RESIZE; + event->resize.width = x_event->xconfigure.width; + event->resize.height = x_event->xconfigure.height; + return true; +} + /** * Process an X event. * @@ -292,6 +308,9 @@ static bool ProcessXEvent(XEvent * x_event, Jtk_Event * event) case Expose: break; + case ConfigureNotify: + return ProcessConfigureEvent(x_event, event); + case MappingNotify: XRefreshKeyboardMapping(&x_event->xmapping); return false; diff --git a/src/gui/jtk/Jtk_event.h b/src/gui/jtk/Jtk_event.h index 27391b4..9091306 100644 --- a/src/gui/jtk/Jtk_event.h +++ b/src/gui/jtk/Jtk_event.h @@ -11,6 +11,7 @@ #define JTK_EVENT_BUTTON_PRESS 5u #define JTK_EVENT_BUTTON_RELEASE 6u #define JTK_EVENT_TIMER 7u +#define JTK_EVENT_WINDOW_RESIZE 8u typedef struct { @@ -33,6 +34,12 @@ typedef struct void * user2; } Jtk_TimerEvent; +typedef struct +{ + size_t width; + size_t height; +} Jtk_WindowResizeEvent; + typedef struct { uint8_t type; @@ -41,6 +48,7 @@ typedef struct Jtk_KeyEvent key; Jtk_ButtonEvent button; Jtk_TimerEvent timer; + Jtk_WindowResizeEvent resize; }; } Jtk_Event;