|
| 1 | +#include "xdg_surface.hxx" |
| 2 | + |
| 3 | +#include "application.hxx" |
| 4 | + |
| 5 | +xdg_surface_wrapper::xdg_surface_wrapper( |
| 6 | + wayland_surface_wrapper& wayland_surface, // |
| 7 | + xdg_wm_base_wrapper& xdg_wm_base |
| 8 | +) : |
| 9 | + wayland_surface(wayland_surface), |
| 10 | + surface(xdg_wm_base_get_xdg_surface( |
| 11 | + xdg_wm_base.wm_base, // |
| 12 | + wayland_surface.surface |
| 13 | + )) |
| 14 | +{ |
| 15 | + if (!this->surface) { |
| 16 | + throw std::runtime_error("could not create wayland xdg surface"); |
| 17 | + } |
| 18 | + |
| 19 | + utki::log_debug([&](auto& o) { |
| 20 | + auto id = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(this->surface)); |
| 21 | + o << "xgd_surface: CREATED, id = " << id << std::endl; |
| 22 | + }); |
| 23 | + |
| 24 | + xdg_surface_add_listener( |
| 25 | + this->surface, // |
| 26 | + &listener, |
| 27 | + this // user data |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +void xdg_surface_wrapper::xdg_surface_configure( |
| 32 | + void* data, // |
| 33 | + xdg_surface* surface, |
| 34 | + uint32_t serial |
| 35 | +) |
| 36 | +{ |
| 37 | + utki::assert(data, SL); |
| 38 | + auto& self = *static_cast<xdg_surface_wrapper*>(data); |
| 39 | + |
| 40 | + utki::log_debug([&](auto& o) { |
| 41 | + auto id = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(surface)); |
| 42 | + o << "xgd_surface: CONFIGURE for surface id = " << id << std::endl; |
| 43 | + }); |
| 44 | + |
| 45 | + // Wayland protocol requires to acknowledge the configure event |
| 46 | + xdg_surface_ack_configure( |
| 47 | + surface, // |
| 48 | + serial |
| 49 | + ); |
| 50 | + |
| 51 | + auto& glue = get_glue(); |
| 52 | + |
| 53 | + auto window = glue.get_window(self.wayland_surface.surface); |
| 54 | + if (!window) { |
| 55 | + utki::logcat_debug(" could not find window object, perhaps called for shared gl context window", '\n'); |
| 56 | + utki::assert(self.wayland_surface.surface == glue.get_shared_gl_context_window_id(), SL); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + auto& win = *window; |
| 61 | + auto& natwin = win.ruis_native_window.get(); |
| 62 | + |
| 63 | + // swap EGL frame buffers with the window's EGL context made current |
| 64 | + win.gui.context.get().ren().ctx().apply([&]() { |
| 65 | + natwin.swap_frame_buffers(); |
| 66 | + }); |
| 67 | + |
| 68 | + // self.wayland_surface.commit(); |
| 69 | +} |
0 commit comments