- Setup wayland display and window. Window surface is created and appears in hotbar. Window is not visible.
This commit is contained in:
160
source/platform/linux/wayland/window.cpp
Normal file
160
source/platform/linux/wayland/window.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file window.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
|
||||
#include <fennec/platform/linux/wayland/server.h>
|
||||
#include <fennec/platform/linux/wayland/window.h>
|
||||
#include <fennec/platform/linux/wayland/lib/wayland.h>
|
||||
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h>
|
||||
|
||||
using namespace fennec;
|
||||
|
||||
wayland_window::wayland_window(display_server* server, uint32_t id, const config& cfg)
|
||||
: window(server, id, cfg)
|
||||
, surface(nullptr)
|
||||
, xdgsurface(nullptr) {
|
||||
|
||||
}
|
||||
|
||||
wayland_window::~wayland_window() {
|
||||
|
||||
}
|
||||
|
||||
void wayland_window::show() {
|
||||
static constexpr wl_surface_listener surface_listener = {
|
||||
listen_enter, listen_leave, listen_preferred_buffer_scale, listen_preferred_buffer_transform
|
||||
};
|
||||
|
||||
static constexpr xdg_surface_listener xdg_surface_listener = {
|
||||
listen_xdg_surface_configure
|
||||
};
|
||||
|
||||
static constexpr xdg_toplevel_listener xdg_toplevel_listener = {
|
||||
listen_xdg_toplevel_configure, listen_xdg_toplevel_close, listen_xdg_toplevel_configure_bounds,
|
||||
listen_xdg_toplevel_capabilities
|
||||
};
|
||||
|
||||
static constexpr wl_callback_listener frame_callback_listener = {
|
||||
listen_frame_callback
|
||||
};
|
||||
|
||||
if (is_visible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wayland_window* root = this;
|
||||
while (root != nullptr and root->is_popup()) {
|
||||
root = static_cast<wayland_window*>(root->get_parent());
|
||||
}
|
||||
|
||||
assertf(root != nullptr, "Failed to find appropriate top-level window.");
|
||||
|
||||
wayland_server* wl_server = static_cast<wayland_server*>(server);
|
||||
|
||||
surface = wl_compositor_create_surface(wl_server->compositor);
|
||||
wl_surface_add_listener(surface, &surface_listener, this);
|
||||
|
||||
|
||||
xdgsurface = xdg_wm_base_get_xdg_surface(wl_server->xdg, surface);
|
||||
xdg_surface_add_listener(xdgsurface, &xdg_surface_listener, this);
|
||||
|
||||
xdgtoplevel = xdg_surface_get_toplevel(xdgsurface);
|
||||
xdg_toplevel_add_listener(xdgtoplevel, &xdg_toplevel_listener, this);
|
||||
|
||||
|
||||
frame_callback = wl_surface_frame(surface);
|
||||
wl_callback_add_listener(frame_callback, &frame_callback_listener, this);
|
||||
|
||||
|
||||
wl_surface_commit(surface);
|
||||
wl_display_roundtrip(wl_server->display);
|
||||
|
||||
cfg.flags.set(flag_visible);
|
||||
cfg.flags.set(flag_running);
|
||||
}
|
||||
|
||||
void wayland_window::hide() {
|
||||
if (not is_visible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wayland_server* wl_server = static_cast<wayland_server*>(server);
|
||||
|
||||
if (xdgtoplevel) {
|
||||
xdg_toplevel_destroy(xdgtoplevel);
|
||||
xdgtoplevel = nullptr;
|
||||
}
|
||||
|
||||
if (frame_callback) {
|
||||
wl_callback_destroy(frame_callback);
|
||||
frame_callback = nullptr;
|
||||
}
|
||||
|
||||
if (xdgsurface) {
|
||||
xdg_surface_destroy(xdgsurface);
|
||||
xdgsurface = nullptr;
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
wl_surface_destroy(surface);
|
||||
surface = nullptr;
|
||||
}
|
||||
|
||||
wl_display_roundtrip(wl_server->display);
|
||||
|
||||
cfg.flags.clear(flag_visible);
|
||||
cfg.flags.clear(flag_running);
|
||||
}
|
||||
|
||||
void wayland_window::dispatch() {
|
||||
wayland_server* wl_server = static_cast<wayland_server*>(server);
|
||||
wl_display_dispatch(wl_server->display);
|
||||
}
|
||||
|
||||
bool wayland_window::set_flag(uint8_t, bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void wayland_window::listen_enter(void*, wl_surface*, wl_output*) {}
|
||||
void wayland_window::listen_leave(void*, wl_surface*, wl_output*) {}
|
||||
void wayland_window::listen_preferred_buffer_scale(void*, wl_surface*, int32_t) {}
|
||||
void wayland_window::listen_preferred_buffer_transform(void*, wl_surface*, uint32_t) {}
|
||||
|
||||
void wayland_window::listen_frame_callback(void*, wl_callback*, uint32_t) {}
|
||||
|
||||
void wayland_window::listen_xdg_surface_configure(void*, xdg_surface* xdg, uint32_t serial) {
|
||||
xdg_surface_ack_configure(xdg, serial);
|
||||
}
|
||||
|
||||
void wayland_window::listen_xdg_toplevel_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*) {}
|
||||
void wayland_window::listen_xdg_toplevel_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t) {}
|
||||
void wayland_window::listen_xdg_toplevel_close(void*, xdg_toplevel*) {}
|
||||
void wayland_window::listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*) {}
|
||||
Reference in New Issue
Block a user