- Setup libdecor, which is used automatically when available.
TODO: - xdg decorations - threading - thread-safe window manager
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user