- Setup libdecor, which is used automatically when available.
TODO: - xdg decorations - threading - thread-safe window manager
This commit is contained in:
@@ -29,7 +29,7 @@ platform::platform() {
|
||||
}
|
||||
|
||||
void platform::initialize() {
|
||||
logger::log(fennec::format("Initializing platform {}", get_type().name()));
|
||||
logger::log(format("Initializing platform {}", get_type().name()));
|
||||
|
||||
display_server::entrylist_t display_servers = display_server::get_type_list();
|
||||
while (not display_servers.empty()) {
|
||||
@@ -39,6 +39,7 @@ void platform::initialize() {
|
||||
unique_ptr<display_server> server = unique_ptr(it.ctor(this));
|
||||
server->connect();
|
||||
if (server->connected()) {
|
||||
logger::log(format("Selected {} for the display server.", server->get_type().name()));
|
||||
display = move(server);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace fennec
|
||||
{
|
||||
|
||||
wayland_eglsurface::wayland_eglsurface(wayland_window* win, eglcontext* ctx)
|
||||
: eglsurface(win, ctx,
|
||||
reinterpret_cast<EGLNativeWindowType>(
|
||||
wl_egl_window_create(
|
||||
static_cast<wl_surface*>(win->get_native_handle()), win->get_size().x, win->get_size().y
|
||||
)
|
||||
: eglsurface(
|
||||
win, ctx,
|
||||
wl_egl_window_create(
|
||||
static_cast<wl_surface*>(win->get_native_handle()),
|
||||
win->get_config().rect.size.x, win->get_config().rect.size.y
|
||||
)
|
||||
) {
|
||||
|
||||
|
||||
@@ -114,18 +114,18 @@ void wayland_server::connect() {
|
||||
auto contexts = ctx_registry::get_type_list();
|
||||
while (not contexts.empty()) {
|
||||
const auto& ctx = contexts.front();
|
||||
gfx_context = ctx.ctor(this);
|
||||
gfx_context = unique_ptr(ctx.ctor(this));
|
||||
|
||||
if (gfx_context->is_valid()) {
|
||||
break;
|
||||
} else {
|
||||
delete gfx_context;
|
||||
gfx_context.reset();
|
||||
gfx_context = nullptr;
|
||||
contexts.pop();
|
||||
}
|
||||
}
|
||||
|
||||
assertf(gfx_context != nullptr, "Failed to create graphics context.");
|
||||
assertf(not gfx_context.empty(), "Failed to create graphics context.");
|
||||
}
|
||||
|
||||
void wayland_server::disconnect() {
|
||||
@@ -136,7 +136,7 @@ void wayland_server::disconnect() {
|
||||
}
|
||||
|
||||
// delete the gfx context
|
||||
delete gfx_context;
|
||||
gfx_context.reset();
|
||||
|
||||
|
||||
// check compositor
|
||||
@@ -167,7 +167,14 @@ bool wayland_server::connected() const {
|
||||
}
|
||||
|
||||
void wayland_server::dispatch() {
|
||||
wl_display_dispatch_pending(display);
|
||||
#if FENNEC_HAS_LIBDECOR
|
||||
if (libdecor) {
|
||||
libdecor_dispatch(libdecor, 0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
wl_display_dispatch_pending(display);
|
||||
}
|
||||
}
|
||||
|
||||
window* wayland_server::create_window(const window::config& conf) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/core/logger.h>
|
||||
#include <fennec/math/relational.h>
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
|
||||
#include <fennec/renderers/interface/gfxcontext.h>
|
||||
@@ -24,6 +26,8 @@
|
||||
#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>
|
||||
#include <fennec/platform/linux/wayland/libdecor/libdecor.h>
|
||||
#include <fennec/renderers/interface/gfxsurface.h>
|
||||
|
||||
#if FENNEC_HAS_LIBDECOR
|
||||
#include <fennec/platform/linux/wayland/libdecor/libdecor.h>
|
||||
@@ -42,7 +46,7 @@ wayland_window::~wayland_window() {
|
||||
|
||||
}
|
||||
|
||||
void wayland_window::show() {
|
||||
void wayland_window::initialize() {
|
||||
static constexpr wl_surface_listener surface_listener = {
|
||||
.enter = _wl_surface_listen_enter,
|
||||
.leave = _wl_surface_listen_leave,
|
||||
@@ -106,14 +110,17 @@ void wayland_window::show() {
|
||||
.reserved9 = nullptr,
|
||||
};
|
||||
|
||||
gfx_surface = wl_server->get_gfx_context()->create_surface(this);
|
||||
|
||||
if (wl_server->has_libdecor) {
|
||||
|
||||
libdecorframe = libdecor_decorate(wl_server->libdecor, surface, &libdecor_frame_listener, this);
|
||||
libdecor_frame_set_app_id(libdecorframe, cfg.title.cstr());
|
||||
libdecor_frame_set_title(libdecorframe, cfg.title.cstr());
|
||||
libdecor_frame_map(libdecorframe);
|
||||
|
||||
xdgsurface = libdecor_frame_get_xdg_surface(libdecorframe);
|
||||
xdgtoplevel = libdecor_frame_get_xdg_toplevel(libdecorframe);
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -123,23 +130,21 @@ void wayland_window::show() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
wl_display_roundtrip(wl_server->display);
|
||||
|
||||
cfg.flags.set(flag_visible);
|
||||
cfg.flags.set(flag_running);
|
||||
|
||||
gfx_surface = wl_server->get_gfx_context()->create_surface(this);
|
||||
state.flags.set(state_visible);
|
||||
state.flags.set(state_running);
|
||||
}
|
||||
|
||||
void wayland_window::hide() {
|
||||
void wayland_window::shutdown() {
|
||||
if (not is_running()) {
|
||||
return;
|
||||
}
|
||||
@@ -176,18 +181,99 @@ void wayland_window::hide() {
|
||||
|
||||
wl_display_roundtrip(wl_server->display);
|
||||
|
||||
cfg.flags.clear(flag_visible);
|
||||
cfg.flags.clear(flag_running);
|
||||
state.flags.clear(state_visible);
|
||||
state.flags.clear(state_running);
|
||||
}
|
||||
|
||||
void* wayland_window::get_native_handle() {
|
||||
return surface;
|
||||
}
|
||||
|
||||
bool wayland_window::set_flag(uint8_t, bool) {
|
||||
return false;
|
||||
bool wayland_window::set_flag(uint8_t flag, bool value) {
|
||||
|
||||
// Do nothing if already set
|
||||
if (cfg.flags.test(flag) == value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (not is_running()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (flag) {
|
||||
case flag_always_on_top:
|
||||
break;
|
||||
|
||||
case flag_borderless:
|
||||
#if FENNEC_HAS_LIBDECOR
|
||||
if (libdecorframe) {
|
||||
bool vis = libdecor_frame_is_visible(libdecorframe);
|
||||
bool tgt = not value;
|
||||
|
||||
if (vis != tgt) {
|
||||
libdecor_frame_set_visibility(libdecorframe, tgt);
|
||||
}
|
||||
} else
|
||||
#endif // FENNEC_HAS_LIBDECOR
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case flag_modal:
|
||||
break;
|
||||
|
||||
case flag_pass_mouse:
|
||||
break;
|
||||
|
||||
case flag_popup:
|
||||
break;
|
||||
|
||||
case flag_resizable:
|
||||
break;
|
||||
|
||||
case flag_transparent:
|
||||
break;
|
||||
|
||||
case flag_no_focus:
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
logger::log("Invalid flag passed to window::set_flag.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Store the value
|
||||
cfg.flags.store(flag, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Helpers =============================================================================================================
|
||||
|
||||
void wayland_window::_update_size(const ivec2& size) {
|
||||
//bool size_changed = any(notEqual(size, state.rect.size));
|
||||
|
||||
state.rect.size = size;
|
||||
|
||||
if (gfx_surface) {
|
||||
gfx_surface->resize(size);
|
||||
}
|
||||
|
||||
#if FENNEC_HAS_LIBDECOR
|
||||
if (libdecorframe) {
|
||||
libdecor_state* state = libdecor_state_new(size.x, size.y);
|
||||
libdecor_frame_commit(libdecorframe, state, libdecorcfg);
|
||||
libdecor_state_free(state);
|
||||
libdecorcfg = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Listeners ===========================================================================================================
|
||||
|
||||
// Surface Listeners
|
||||
|
||||
void wayland_window::_wl_surface_listen_enter(void*, wl_surface*, wl_output*) {}
|
||||
@@ -212,7 +298,7 @@ void wayland_window::_xdg_toplevel_listen_configure_bounds(void*, xdg_toplevel*,
|
||||
|
||||
void wayland_window::_xdg_toplevel_listen_close(void* data, xdg_toplevel*) {
|
||||
wayland_window* window = static_cast<wayland_window*>(data);
|
||||
window->hide();
|
||||
window->shutdown();
|
||||
|
||||
}
|
||||
|
||||
@@ -223,14 +309,52 @@ void wayland_window::_xdg_toplevel_listen_wm_capabilities(void*, xdg_toplevel*,
|
||||
|
||||
#if FENNEC_HAS_LIBDECOR
|
||||
|
||||
void wayland_window::_libdecor_frame_listen_configure(libdecor_frame*, libdecor_configuration*, void*) {}
|
||||
void wayland_window::_libdecor_frame_listen_configure(libdecor_frame* frame, libdecor_configuration* cfg, void* data) {
|
||||
wayland_window* window = static_cast<wayland_window*>(data);
|
||||
|
||||
ivec2 size = window->state.rect.size;
|
||||
libdecor_configuration_get_content_size(cfg, frame, &size.x, &size.y);
|
||||
size.x = size.x == 0 ? window->state.rect.size.x : size.x;
|
||||
size.y = size.y == 0 ? window->state.rect.size.y : size.y;
|
||||
|
||||
size.x = size.x == 0 ? window->cfg.rect.size.x : size.x;
|
||||
size.y = size.y == 0 ? window->cfg.rect.size.y : size.y;
|
||||
|
||||
assertf(size.x != 0 or size.y != 0, "Invalid window size!");
|
||||
|
||||
libdecor_window_state state = LIBDECOR_WINDOW_STATE_NONE;
|
||||
|
||||
window->state.mode = mode_windowed;
|
||||
window->state.flags.clear(state_suspended);
|
||||
window->libdecorcfg = cfg;
|
||||
|
||||
if (libdecor_configuration_get_window_state(cfg, &state)) {
|
||||
if (state & LIBDECOR_WINDOW_STATE_MAXIMIZED) {
|
||||
window->state.mode = mode_maximized;
|
||||
}
|
||||
|
||||
if (state & LIBDECOR_WINDOW_STATE_FULLSCREEN) {
|
||||
window->state.mode = mode_fullscreen;
|
||||
}
|
||||
|
||||
if (state & LIBDECOR_WINDOW_STATE_SUSPENDED) {
|
||||
window->state.flags.set(state_suspended);
|
||||
}
|
||||
}
|
||||
|
||||
window->_update_size(size);
|
||||
}
|
||||
|
||||
void wayland_window::_libdecor_frame_listen_close(libdecor_frame*, void* data) {
|
||||
wayland_window* window = static_cast<wayland_window*>(data);
|
||||
window->hide();
|
||||
window->shutdown();
|
||||
}
|
||||
|
||||
void wayland_window::_libdecor_frame_listen_commit(libdecor_frame*, void* data) {
|
||||
wayland_window* window = static_cast<wayland_window*>(data);
|
||||
window->gfx_surface->swap();
|
||||
}
|
||||
|
||||
void wayland_window::_libdecor_frame_listen_commit(libdecor_frame*, void*) {}
|
||||
void wayland_window::_libdecor_frame_listen_dismiss_popup(libdecor_frame*, const char*, void*) {}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,7 +38,13 @@ static const cstring& egl_translate_type(EGLint type) {
|
||||
}
|
||||
|
||||
eglcontext::eglcontext(display_server* display)
|
||||
: glcontext(display) {
|
||||
: glcontext(display)
|
||||
, _egldisplay(nullptr)
|
||||
, _eglcontext(nullptr)
|
||||
, _eglconfig(nullptr)
|
||||
, _eglvmajor(0)
|
||||
, _eglvminor(0)
|
||||
, _eglctype(0){
|
||||
|
||||
EGLint config_attrs[] = {
|
||||
EGL_SURFACE_TYPE,
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/core/logger.h>
|
||||
#include <fennec/platform/opengl/egl/context.h>
|
||||
#include <fennec/platform/opengl/egl/surface.h>
|
||||
|
||||
namespace fennec {
|
||||
|
||||
eglsurface::eglsurface(fennec::window* win, eglcontext* ctx, EGLNativeWindowType eglwindow)
|
||||
eglsurface::eglsurface(fennec::window* win, eglcontext* ctx, void* eglwindow)
|
||||
: gfxsurface(win, ctx)
|
||||
, _eglwindow(eglwindow)
|
||||
, _eglsurface(nullptr) {
|
||||
@@ -31,25 +32,32 @@ eglsurface::eglsurface(fennec::window* win, eglcontext* ctx, EGLNativeWindowType
|
||||
_eglsurface = eglCreateWindowSurface(
|
||||
ctx->_egldisplay,
|
||||
ctx->_eglconfig,
|
||||
_eglwindow,
|
||||
reinterpret_cast<EGLNativeWindowType>(_eglwindow),
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (not _eglsurface) {
|
||||
int32_t err = eglGetError();
|
||||
logger::log(format("EGL error: {}", eglErrorString(err)));
|
||||
}
|
||||
assertf(_eglsurface, "Failed to create EGL surface!");
|
||||
|
||||
eglsurface::make_current();
|
||||
}
|
||||
|
||||
eglsurface::~eglsurface() {
|
||||
eglcontext* ctx = static_cast<eglcontext*>(context);
|
||||
eglDestroySurface(ctx->_egldisplay, _eglsurface);
|
||||
assertf(eglDestroySurface(ctx->_egldisplay, _eglsurface), "Error destroying EGL surface!");
|
||||
}
|
||||
|
||||
void eglsurface::make_current() {
|
||||
eglcontext* ctx = static_cast<eglcontext*>(context);
|
||||
eglMakeCurrent(ctx->_egldisplay, _eglsurface, _eglsurface, ctx->_eglcontext);
|
||||
assertf(eglMakeCurrent(ctx->_egldisplay, _eglsurface, _eglsurface, ctx->_eglcontext), "Error setting the current surface!");
|
||||
}
|
||||
|
||||
void eglsurface::swap() {
|
||||
eglcontext* ctx = static_cast<eglcontext*>(context);
|
||||
eglSwapBuffers(ctx->_egldisplay, _eglsurface);
|
||||
assertf(eglSwapBuffers(ctx->_egldisplay, _eglsurface), "Error swapping surface buffers!");
|
||||
}
|
||||
|
||||
} // fennec
|
||||
Reference in New Issue
Block a user