- Setup wayland display and window. Window surface is created and appears in hotbar. Window is not visible.
This commit is contained in:
@@ -35,11 +35,12 @@
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
#include <fennec/platform/interface/window.h>
|
||||
#include <fennec/rtti/enable.h>
|
||||
#include <fennec/rtti/type_registry.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class display_server {
|
||||
class display_server : public type_registry<display_server, platform*> {
|
||||
// Typedefs/Constants/Enums ============================================================================================
|
||||
public:
|
||||
|
||||
@@ -90,19 +91,29 @@ enum feature_ : uint32_t {
|
||||
: platform(p) {
|
||||
}
|
||||
|
||||
virtual ~display_server() = default;
|
||||
virtual ~display_server() {
|
||||
}
|
||||
|
||||
|
||||
bool has_feature(uint32_t feature) const {
|
||||
return _features.test(feature);
|
||||
return features.test(feature);
|
||||
}
|
||||
|
||||
|
||||
virtual window* create_window(const window::config& conf) = 0;
|
||||
|
||||
window* get_window(size_t id) {
|
||||
return id == window::nullid ? nullptr : windows[id];
|
||||
}
|
||||
|
||||
private:
|
||||
featureset_t _features;
|
||||
virtual void connect() = 0;
|
||||
virtual void disconnect() = 0;
|
||||
virtual bool connected() const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
featureset_t features;
|
||||
object_pool<window*> windows;
|
||||
|
||||
FENNEC_RTTI_CLASS_ENABLE() {
|
||||
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
#ifndef FENNEC_PLATFORM_INTERFACE_PLATFORM_H
|
||||
#define FENNEC_PLATFORM_INTERFACE_PLATFORM_H
|
||||
|
||||
#include <fennec/containers/list.h>
|
||||
#include <fennec/containers/sequence.h>
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
#include <fennec/string/cstring.h>
|
||||
#include <fennec/string/string.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
#include <fennec/platform/interface/window.h>
|
||||
|
||||
#include <fennec/rtti/enable.h>
|
||||
#include <fennec/rtti/singleton.h>
|
||||
#include <fennec/rtti/detail/_this_t.h>
|
||||
@@ -63,7 +60,7 @@
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class platform : singleton<platform*> {
|
||||
class platform : public singleton<platform*> {
|
||||
public:
|
||||
using shared_object = struct shared_object;
|
||||
using symbol = void*;
|
||||
@@ -78,10 +75,14 @@ public:
|
||||
virtual symbol find_symbol(shared_object* obj, const cstring& name) = 0;
|
||||
|
||||
virtual void initialize(); // Initialize Drivers and Contexts
|
||||
virtual void shutdown(); // Close Drivers and Contexts
|
||||
virtual void shutdown(); // Close Drivers and Contexts
|
||||
|
||||
display_server* get_display_server() { return display.get(); }
|
||||
|
||||
protected:
|
||||
unique_ptr<display_server> display;
|
||||
|
||||
FENNEC_RTTI_CLASS_ENABLE() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
#ifndef FENNEC_PLATFORM_INTERFACE_WINDOW_H
|
||||
#define FENNEC_PLATFORM_INTERFACE_WINDOW_H
|
||||
|
||||
#include <fennec/lang/types.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
#include <fennec/math/vector.h>
|
||||
#include <fennec/string/string.h>
|
||||
#include <fennec/containers/bitfield.h>
|
||||
#include <fennec/renderers/interface/gfxcontext.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
@@ -42,7 +42,23 @@ namespace fennec
|
||||
class window {
|
||||
// Structures & Typedefs ===============================================================================================
|
||||
public:
|
||||
enum flag_ {
|
||||
static constexpr size_t nullid = -1;
|
||||
|
||||
enum mode_ : uint8_t {
|
||||
mode_windowed = 0,
|
||||
mode_minimized,
|
||||
mode_maximized,
|
||||
mode_fullscreen,
|
||||
mode_exclusive_fullscreen,
|
||||
};
|
||||
|
||||
enum vsync_ : uint8_t {
|
||||
vsync_disabled = 0,
|
||||
vsync_enabled,
|
||||
vsync_adaptive
|
||||
};
|
||||
|
||||
enum flag_ : uint8_t {
|
||||
flag_always_on_top = 0, // Window always appears on top level
|
||||
flag_borderless, // Window has no border decorations
|
||||
flag_child, // Window is a child window, and closes when the parent does
|
||||
@@ -53,6 +69,7 @@ public:
|
||||
flag_resizable, // Window can be resized through functions defined by Desktop Environment
|
||||
flag_transparent, // Window has an alpha value
|
||||
flag_visible, // Window is visible
|
||||
flag_running, // Window is running
|
||||
flag_no_focus, // Window can be focused
|
||||
|
||||
flag_count
|
||||
@@ -67,12 +84,64 @@ public:
|
||||
struct config {
|
||||
string title;
|
||||
flags_t flags;
|
||||
uint8_t mode;
|
||||
|
||||
size_t parent;
|
||||
ivec2 size;
|
||||
|
||||
accessibility accessibility;
|
||||
};
|
||||
|
||||
window(display_server* server, size_t id, const config& conf)
|
||||
: server(server), id(id)
|
||||
, cfg(conf), root(nullptr) {
|
||||
cfg.flags.clear(flag_visible);
|
||||
}
|
||||
|
||||
virtual ~window() = default;
|
||||
|
||||
size_t get_id() const { return id; }
|
||||
size_t get_parent_id() const { return cfg.parent; }
|
||||
|
||||
window* get_parent() const;
|
||||
|
||||
bool get_flag(uint8_t flag) const { return cfg.flags.test(flag); }
|
||||
|
||||
bool is_always_on_top() const { return get_flag(flag_always_on_top); }
|
||||
bool is_borderless() const { return get_flag(flag_borderless); }
|
||||
bool is_child() const { return get_flag(flag_child); }
|
||||
bool has_decorations() const { return get_flag(flag_decorations); }
|
||||
bool is_modal() const { return get_flag(flag_modal); }
|
||||
bool is_passing_mouse() const { return get_flag(flag_pass_mouse); }
|
||||
bool is_popup() const { return get_flag(flag_popup); }
|
||||
bool is_resizable() const { return get_flag(flag_resizable); }
|
||||
bool is_transparent() const { return get_flag(flag_transparent); }
|
||||
bool is_visible() const { return get_flag(flag_visible); }
|
||||
bool is_running() const { return get_flag(flag_running); }
|
||||
bool is_no_focus() const { return get_flag(flag_no_focus); }
|
||||
|
||||
virtual bool set_flag(uint8_t flag, bool val) = 0;
|
||||
|
||||
bool set_always_on_top(bool val) { return set_flag(flag_always_on_top, val); }
|
||||
bool set_borderless(bool val) { return set_flag(flag_borderless, val); }
|
||||
bool set_decorations(bool val) { return set_flag(flag_decorations, val); }
|
||||
bool set_modal(bool val) { return set_flag(flag_modal, val); }
|
||||
bool set_passing_mouse(bool val) { return set_flag(flag_pass_mouse, val); }
|
||||
bool set_popup(bool val) { return set_flag(flag_popup, val); }
|
||||
bool set_resizable(bool val) { return set_flag(flag_resizable, val); }
|
||||
bool set_transparent(bool val) { return set_flag(flag_transparent, val); }
|
||||
bool set_no_focus(bool val) { return set_flag(flag_no_focus, val); }
|
||||
|
||||
virtual void show() = 0;
|
||||
virtual void hide() = 0;
|
||||
|
||||
virtual void dispatch() = 0;
|
||||
|
||||
protected:
|
||||
display_server* const server;
|
||||
const size_t id;
|
||||
config cfg;
|
||||
window* root;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file display_server.h
|
||||
/// \file wayland_server.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
@@ -28,25 +28,59 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
|
||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
|
||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_SERVER_H
|
||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_SERVER_H
|
||||
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
|
||||
// forward defs to avoid flooding global namespace
|
||||
struct wl_display;
|
||||
struct wl_shm;
|
||||
struct wl_compositor;
|
||||
struct wl_registry;
|
||||
struct wl_seat;
|
||||
|
||||
struct wp_viewporter;
|
||||
struct xdg_wm_base;
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class wayland_server : display_server {
|
||||
class wayland_server : public display_server {
|
||||
public:
|
||||
explicit wayland_server(fennec::platform* p)
|
||||
: display_server(p) {
|
||||
}
|
||||
explicit wayland_server(fennec::platform* p);
|
||||
~wayland_server() override;
|
||||
|
||||
void connect() override;
|
||||
void disconnect() override;
|
||||
bool connected() const override;
|
||||
|
||||
window* create_window(const window::config& conf) override;
|
||||
|
||||
private:
|
||||
FENNEC_RTTI_CLASS_ENABLE(display_server) {
|
||||
wl_display* display;
|
||||
wl_registry* registry;
|
||||
|
||||
wl_compositor* compositor;
|
||||
xdg_wm_base* xdg;
|
||||
wl_seat* seat;
|
||||
bool fifo;
|
||||
|
||||
static void listen_global(void*, wl_registry*, uint32_t, const char*, uint32_t);
|
||||
static void listen_global_remove(void*, wl_registry*, uint32_t);
|
||||
|
||||
static void listen_seat_capabilities(void*, wl_seat*, uint32_t);
|
||||
static void listen_seat_name(void*, wl_seat*, const char*);
|
||||
|
||||
static void listen_xdg_ping(void*, xdg_wm_base*, uint32_t);
|
||||
|
||||
FENNEC_RTTI_CLASS_ENABLE(display_server) {
|
||||
display_server::register_type<wayland_server>(1);
|
||||
}
|
||||
|
||||
friend class wayland_window;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
|
||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_SERVER_H
|
||||
82
include/fennec/platform/linux/wayland/window.h
Normal file
82
include/fennec/platform/linux/wayland/window.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// =====================================================================================================================
|
||||
// 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 wayland_window.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
||||
|
||||
#include <fennec/platform/interface/window.h>
|
||||
|
||||
struct wl_array;
|
||||
struct wl_callback;
|
||||
struct wl_output;
|
||||
struct wl_surface;
|
||||
|
||||
struct xdg_surface;
|
||||
struct xdg_toplevel;
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class wayland_window : public window {
|
||||
public:
|
||||
wayland_window(display_server* server, uint32_t id, const config& cfg);
|
||||
~wayland_window();
|
||||
|
||||
void show() override;
|
||||
void hide() override;
|
||||
|
||||
void dispatch() override;
|
||||
|
||||
bool set_flag(uint8_t flag, bool val) override;
|
||||
|
||||
private:
|
||||
wl_surface* surface;
|
||||
xdg_surface* xdgsurface;
|
||||
xdg_toplevel* xdgtoplevel;
|
||||
wl_callback* frame_callback;
|
||||
|
||||
static void listen_enter(void*, wl_surface*, wl_output*);
|
||||
static void listen_leave(void*, wl_surface*, wl_output*);
|
||||
static void listen_preferred_buffer_scale(void*, wl_surface*, int32_t);
|
||||
static void listen_preferred_buffer_transform(void*, wl_surface*, uint32_t);
|
||||
|
||||
static void listen_frame_callback(void*, wl_callback*, uint32_t);
|
||||
|
||||
static void listen_xdg_surface_configure(void*, xdg_surface*, uint32_t);
|
||||
|
||||
static void listen_xdg_toplevel_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*);
|
||||
static void listen_xdg_toplevel_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t);
|
||||
static void listen_xdg_toplevel_close(void*, xdg_toplevel*);
|
||||
static void listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
||||
Reference in New Issue
Block a user