Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: implement xdg-shell #698

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ target_link_libraries(gfxrecon_application

common_build_directives(gfxrecon_application)


if (${RUN_TESTS})
add_executable(gfxrecon_application_test "")
target_sources(gfxrecon_application_test PRIVATE
Expand Down
7 changes: 5 additions & 2 deletions framework/application/wayland_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct wl_keyboard_listener WaylandContext::keyboard_listener_;
struct wl_seat_listener WaylandContext::seat_listener_;
struct wl_registry_listener WaylandContext::registry_listener_;
struct wl_output_listener WaylandContext::output_listener_;
struct xdg_wm_base_listener WaylandContext::shell_listener_;

WaylandContext::WaylandContext(Application* application) : WsiContext(application)
{
Expand Down Expand Up @@ -205,9 +206,11 @@ void WaylandContext::HandleRegistryGlobal(
wayland_context->compositor_ = reinterpret_cast<wl_compositor*>(
wl.registry_bind(registry, id, wl.compositor_interface, WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION));
}
else if (util::platform::StringCompare(interface, "wl_shell") == 0)
else if (util::platform::StringCompare(interface, "xdg_wm_base") == 0)
{
wayland_context->shell_ = reinterpret_cast<wl_shell*>(wl.registry_bind(registry, id, wl.shell_interface, 1));
wayland_context->shell_ = reinterpret_cast<xdg_wm_base*>(wl.registry_bind(registry, id, wl.shell_base_interface, 1));
//wl.xdg_wm_base_add_listener(wayland_context->shell_, &shell_listener_, wayland_context); // TODO FIXME

}
else if (util::platform::StringCompare(interface, "wl_seat") == 0)
{
Expand Down
5 changes: 3 additions & 2 deletions framework/application/wayland_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class WaylandContext : public WsiContext

struct wl_display* GetDisplay() const { return display_; }

struct wl_shell* GetShell() const { return shell_; }
struct xdg_wm_base* GetShell() const { return shell_; }

struct wl_compositor* GetCompositor() const { return compositor_; }

Expand Down Expand Up @@ -137,8 +137,9 @@ class WaylandContext : public WsiContext
static struct wl_seat_listener seat_listener_;
static struct wl_registry_listener registry_listener_;
static struct wl_output_listener output_listener_;
static struct xdg_wm_base_listener shell_listener_;
struct wl_display* display_{};
struct wl_shell* shell_{};
struct xdg_wm_base* shell_{};
struct wl_compositor* compositor_{};
struct wl_registry* registry_{};
struct wl_seat* seat_{};
Expand Down
45 changes: 23 additions & 22 deletions framework/application/wayland_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(application)

struct wl_surface_listener WaylandWindow::surface_listener_;
struct wl_shell_surface_listener WaylandWindow::shell_surface_listener_;
struct xdg_toplevel_listener WaylandWindow::xdg_toplevel_listener_;

WaylandWindow::WaylandWindow(WaylandContext* wayland_context) :
wayland_context_(wayland_context), surface_(nullptr), shell_surface_(nullptr), width_(0), height_(0), scale_(1),
wayland_context_(wayland_context), surface_(nullptr), xdg_toplevel_(nullptr), width_(0), height_(0), scale_(1),
output_(nullptr)
{
assert(wayland_context_ != nullptr);
Expand All @@ -44,19 +44,20 @@ WaylandWindow::WaylandWindow(WaylandContext* wayland_context) :
surface_listener_.enter = HandleSurfaceEnter;
surface_listener_.leave = HandleSurfaceLeave;

shell_surface_listener_.ping = HandlePing;
shell_surface_listener_.configure = HandleConfigure;
shell_surface_listener_.popup_done = HandlePopupDone;
//xdg_toplevel_listener_.configure = HandleConfigure;
// MOVE FIXME
//xdg_toplevel_listener_.ping = HandlePing;
//xdg_toplevel_listener_.popup_done = HandlePopupDone;
}

WaylandWindow::~WaylandWindow()
{
auto& wl = wayland_context_->GetWaylandFunctionTable();
if (surface_)
{
if (shell_surface_)
if (xdg_toplevel_)
{
wl.shell_surface_destroy(shell_surface_);
wl.shell_surface_destroy(xdg_toplevel_);
}

wl.surface_destroy(surface_);
Expand All @@ -78,8 +79,8 @@ bool WaylandWindow::Create(
return false;
}

shell_surface_ = wl.shell_get_shell_surface(wayland_context_->GetShell(), surface_);
if (!shell_surface_)
xdg_toplevel_ = wl.shell_get_shell_surface(wayland_context_->GetShell(), surface_);
if (!xdg_toplevel_)
{
GFXRECON_LOG_ERROR("Failed to create Wayland shell surface");
return false;
Expand All @@ -88,8 +89,8 @@ bool WaylandWindow::Create(
wayland_context_->RegisterWaylandWindow(this);

wl.surface_add_listener(surface_, &WaylandWindow::surface_listener_, this);
wl.shell_surface_add_listener(shell_surface_, &WaylandWindow::shell_surface_listener_, this);
wl.shell_surface_set_title(shell_surface_, title.c_str());
wl.xdg_toplevel_add_listener(xdg_toplevel_, &WaylandWindow::xdg_toplevel_listener_, this);
wl.shell_surface_set_title(xdg_toplevel_, title.c_str());

width_ = width;
height_ = height;
Expand All @@ -103,10 +104,10 @@ bool WaylandWindow::Destroy()
if (surface_)
{
auto& wl = wayland_context_->GetWaylandFunctionTable();
if (shell_surface_)
if (xdg_toplevel_)
{
wl.shell_surface_destroy(shell_surface_);
shell_surface_ = nullptr;
wl.shell_surface_destroy(xdg_toplevel_);
xdg_toplevel_ = nullptr;
}

wl.surface_destroy(surface_);
Expand All @@ -121,7 +122,7 @@ bool WaylandWindow::Destroy()
void WaylandWindow::SetTitle(const std::string& title)
{
auto& wl = wayland_context_->GetWaylandFunctionTable();
wl.shell_surface_set_title(shell_surface_, title.c_str());
wl.shell_surface_set_title(xdg_toplevel_, title.c_str());
}

void WaylandWindow::SetPosition(const int32_t x, const int32_t y)
Expand Down Expand Up @@ -215,16 +216,16 @@ void WaylandWindow::UpdateWindowSize()

if (output_info.width == width_ && output_info.height == height_)
{
wl.shell_surface_set_fullscreen(shell_surface_, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, output_);
wl.shell_surface_set_fullscreen(xdg_toplevel_, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, output_);
}
else
{
wl.shell_surface_set_toplevel(shell_surface_);
wl.shell_surface_set_toplevel(xdg_toplevel_);
}
}
else
{
wl.shell_surface_set_toplevel(shell_surface_);
wl.shell_surface_set_toplevel(xdg_toplevel_);
}
}

Expand All @@ -238,17 +239,17 @@ void WaylandWindow::HandleSurfaceEnter(void* data, struct wl_surface* surface, s

void WaylandWindow::HandleSurfaceLeave(void* data, struct wl_surface* surface, struct wl_output* output) {}

void WaylandWindow::HandlePing(void* data, wl_shell_surface* shell_surface, uint32_t serial)
void WaylandWindow::HandlePing(void* data, xdg_wm_base* xdg_wm_base, uint32_t serial)
{
auto& wl = reinterpret_cast<WaylandWindow*>(data)->wayland_context_->GetWaylandFunctionTable();
wl.shell_surface_pong(shell_surface, serial);
wl.xdg_wm_base_pong(xdg_wm_base, serial);
}

void WaylandWindow::HandleConfigure(
void* data, wl_shell_surface* shell_surface, uint32_t edges, int32_t width, int32_t height)
void* data, xdg_toplevel* shell_surface, uint32_t edges, int32_t width, int32_t height)
{}

void WaylandWindow::HandlePopupDone(void* data, wl_shell_surface* shell_surface) {}
void WaylandWindow::HandlePopupDone(void* data, xdg_toplevel* shell_surface) {}

WaylandWindowFactory::WaylandWindowFactory(WaylandContext* wayland_context) : wayland_context_(wayland_context)
{
Expand Down
15 changes: 8 additions & 7 deletions framework/application/wayland_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "util/defines.h"

#include <wayland-client.h>
#include "util/xdg-shell-client-protocol.h"

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(application)
Expand All @@ -42,7 +43,7 @@ class WaylandWindow : public decode::Window

struct wl_surface* GetSurface() const { return surface_; }

struct wl_shell_surface* GetShellSurface() const { return shell_surface_; }
struct xdg_toplevel* GetShellSurface() const { return xdg_toplevel_; }

virtual bool Create(const std::string& title,
const int32_t x,
Expand Down Expand Up @@ -80,21 +81,21 @@ class WaylandWindow : public decode::Window
static void HandleSurfaceEnter(void* data, struct wl_surface* surface, struct wl_output* output);
static void HandleSurfaceLeave(void* data, struct wl_surface* surface, struct wl_output* output);

static void HandlePing(void* data, wl_shell_surface* shell_surface, uint32_t serial);
static void HandlePing(void* data, xdg_wm_base* xdg_wm_base, uint32_t serial);

static void
HandleConfigure(void* data, wl_shell_surface* shell_surface, uint32_t edges, int32_t width, int32_t height);
HandleConfigure(void* data, xdg_toplevel* xdg_toplevel, uint32_t edges, int32_t width, int32_t height);

static void HandlePopupDone(void* data, wl_shell_surface* shell_surface);
static void HandlePopupDone(void* data, xdg_toplevel* xdg_toplevel);

void UpdateWindowSize();

private:
static struct wl_surface_listener surface_listener_;
static struct wl_shell_surface_listener shell_surface_listener_;
static struct xdg_toplevel_listener xdg_toplevel_listener_;
WaylandContext* wayland_context_;
struct wl_surface* surface_;
struct wl_shell_surface* shell_surface_;
struct xdg_toplevel* xdg_toplevel_;
uint32_t width_;
uint32_t height_;
int32_t scale_;
Expand Down Expand Up @@ -124,4 +125,4 @@ class WaylandWindowFactory : public decode::WindowFactory
GFXRECON_END_NAMESPACE(util)
GFXRECON_END_NAMESPACE(gfxrecon)

#endif // GFXRECON_APPLICATION_WAYLAND_WINDOW_H
#endif // GFXRECON_APPLICATION_WAYLAND_WINDOW_H
2 changes: 2 additions & 0 deletions framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ target_sources(gfxrecon_util
$<$<BOOL:${X11_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/xlib_loader.cpp>
$<$<BOOL:${WAYLAND_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/wayland_loader.h>
$<$<BOOL:${WAYLAND_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/wayland_loader.cpp>
$<$<BOOL:${WAYLAND_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/xdg-shell-client-protocol.h>
$<$<BOOL:${WAYLAND_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/xdg-shell-protocol.c>
)

target_include_directories(gfxrecon_util
Expand Down
8 changes: 4 additions & 4 deletions framework/util/wayland_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ bool WaylandLoader::Initialize()
util::platform::GetProcAddress(libwayland_, "wl_display_roundtrip"));
function_table_.compositor_interface = reinterpret_cast<decltype(wl_compositor_interface)*>(
util::platform::GetProcAddress(libwayland_, "wl_compositor_interface"));
function_table_.shell_interface = reinterpret_cast<decltype(wl_shell_interface)*>(
util::platform::GetProcAddress(libwayland_, "wl_shell_interface"));
function_table_.seat_interface = reinterpret_cast<decltype(wl_seat_interface)*>(
util::platform::GetProcAddress(libwayland_, "wl_seat_interface"));

Expand All @@ -89,6 +87,10 @@ bool WaylandLoader::Initialize()
function_table_.proxy_marshal_constructor_versioned =
reinterpret_cast<decltype(wl_proxy_marshal_constructor_versioned)*>(
util::platform::GetProcAddress(libwayland_, "wl_proxy_marshal_constructor_versioned"));
function_table_.proxy_marshal_flags = reinterpret_cast<decltype(wl_proxy_marshal_flags)*>(
util::platform::GetProcAddress(libwayland_, "wl_proxy_marshal_flags"));
function_table_.proxy_marshal_array_flags = reinterpret_cast<decltype(wl_proxy_marshal_array_flags)*>(
util::platform::GetProcAddress(libwayland_, "wl_proxy_marshal_array_flags"));

// Interfaces
function_table_.registry_interface = reinterpret_cast<decltype(wl_registry_interface)*>(
Expand All @@ -99,8 +101,6 @@ bool WaylandLoader::Initialize()
util::platform::GetProcAddress(libwayland_, "wl_output_interface"));
function_table_.pointer_interface = reinterpret_cast<decltype(wl_pointer_interface)*>(
util::platform::GetProcAddress(libwayland_, "wl_pointer_interface"));
function_table_.shell_surface_interface = reinterpret_cast<decltype(wl_shell_surface_interface)*>(
util::platform::GetProcAddress(libwayland_, "wl_shell_surface_interface"));
function_table_.surface_interface = reinterpret_cast<decltype(wl_surface_interface)*>(
util::platform::GetProcAddress(libwayland_, "wl_surface_interface"));
}
Expand Down
50 changes: 27 additions & 23 deletions framework/util/wayland_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "util/platform.h"

#include <wayland-client.h>
#include "xdg-shell-client-protocol.h"

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(util)
Expand All @@ -46,7 +47,7 @@ class WaylandLoader
decltype(wl_display_flush)* display_flush;
decltype(wl_display_roundtrip)* display_roundtrip;
decltype(wl_compositor_interface)* compositor_interface;
decltype(wl_shell_interface)* shell_interface;
decltype(xdg_wm_base_interface)* shell_base_interface;
decltype(wl_seat_interface)* seat_interface;

// proxy functions
Expand All @@ -55,13 +56,16 @@ class WaylandLoader
decltype(wl_proxy_marshal)* proxy_marshal;
decltype(wl_proxy_marshal_constructor)* proxy_marshal_constructor;
decltype(wl_proxy_marshal_constructor_versioned)* proxy_marshal_constructor_versioned;
decltype(wl_proxy_marshal_flags)* proxy_marshal_flags;
decltype(wl_proxy_marshal_array_flags)* proxy_marshal_array_flags;


// interfaces
decltype(wl_registry_interface)* registry_interface;
decltype(wl_keyboard_interface)* keyboard_interface;
decltype(wl_output_interface)* output_interface;
decltype(wl_pointer_interface)* pointer_interface;
decltype(wl_shell_surface_interface)* shell_surface_interface;
decltype(xdg_toplevel_interface)* shell_surface_interface;
decltype(wl_surface_interface)* surface_interface;

// inline functions, adapted from wayland-client-protocol.h
Expand Down Expand Up @@ -185,66 +189,66 @@ class WaylandLoader
return reinterpret_cast<struct wl_pointer*>(id);
}

void shell_destroy(struct wl_shell* wl_shell) const
void shell_destroy(struct xdg_wm_base* xdg_wm_base) const
{
this->proxy_destroy(reinterpret_cast<struct wl_proxy*>(wl_shell));
this->proxy_destroy(reinterpret_cast<struct wl_proxy*>(xdg_wm_base));
}

struct wl_shell_surface* shell_get_shell_surface(struct wl_shell* wl_shell, struct wl_surface* surface) const
struct xdg_toplevel* shell_get_shell_surface(struct xdg_wm_base* xdg_wm_base, struct wl_surface* surface) const
{
struct wl_proxy* id;

id = this->proxy_marshal_constructor(reinterpret_cast<struct wl_proxy*>(wl_shell),
id = this->proxy_marshal_constructor(reinterpret_cast<struct wl_proxy*>(xdg_wm_base),
WL_SHELL_GET_SHELL_SURFACE,
this->shell_surface_interface,
NULL,
surface);

return reinterpret_cast<struct wl_shell_surface*>(id);
return reinterpret_cast<struct xdg_toplevel*>(id);
}

int shell_surface_add_listener(struct wl_shell_surface* wl_shell_surface,
struct wl_shell_surface_listener* listener,
void* data) const
int xdg_toplevel_add_listener(struct xdg_toplevel* xdg_toplevel,
struct xdg_toplevel_listener* listener,
void* data) const
{
return this->proxy_add_listener(reinterpret_cast<struct wl_proxy*>(wl_shell_surface),
return this->proxy_add_listener(reinterpret_cast<struct wl_proxy*>(xdg_toplevel),
reinterpret_cast<void (**)(void)>(listener),
data);
}

void shell_surface_destroy(struct wl_shell_surface* wl_shell_surface) const
void shell_surface_destroy(struct xdg_toplevel* xdg_toplevel) const
{
this->proxy_destroy(reinterpret_cast<struct wl_proxy*>(wl_shell_surface));
this->proxy_destroy(reinterpret_cast<struct wl_proxy*>(xdg_toplevel));
}

void shell_surface_move(struct wl_shell_surface* wl_shell_surface, struct wl_seat* seat, uint32_t serial) const
void shell_surface_move(struct xdg_toplevel* xdg_toplevel, struct wl_seat* seat, uint32_t serial) const
{
this->proxy_marshal(
reinterpret_cast<struct wl_proxy*>(wl_shell_surface), WL_SHELL_SURFACE_MOVE, seat, serial);
reinterpret_cast<struct wl_proxy*>(xdg_toplevel), WL_SHELL_SURFACE_MOVE, seat, serial);
}

void shell_surface_pong(struct wl_shell_surface* wl_shell_surface, uint32_t serial) const
void xdg_wm_base_pong(struct xdg_wm_base* xdg_wm_base, uint32_t serial) const
{
this->proxy_marshal(reinterpret_cast<struct wl_proxy*>(wl_shell_surface), WL_SHELL_SURFACE_PONG, serial);
this->proxy_marshal(reinterpret_cast<struct wl_proxy*>(xdg_wm_base), WL_SHELL_SURFACE_PONG, serial);
}

void shell_surface_set_fullscreen(struct wl_shell_surface* wl_shell_surface,
void shell_surface_set_fullscreen(struct xdg_toplevel* xdg_toplevel,
uint32_t method,
uint32_t framerate,
struct wl_output* output) const
{
this->proxy_marshal(reinterpret_cast<struct wl_proxy*>(wl_shell_surface), WL_SHELL_SURFACE_SET_FULLSCREEN);
this->proxy_marshal(reinterpret_cast<struct wl_proxy*>(xdg_toplevel), WL_SHELL_SURFACE_SET_FULLSCREEN);
}

void shell_surface_set_title(struct wl_shell_surface* wl_shell_surface, const char* title) const
void shell_surface_set_title(struct xdg_toplevel* xdg_toplevel, const char* title) const
{
this->proxy_marshal(
reinterpret_cast<struct wl_proxy*>(wl_shell_surface), WL_SHELL_SURFACE_SET_TITLE, title);
reinterpret_cast<struct wl_proxy*>(xdg_toplevel), WL_SHELL_SURFACE_SET_TITLE, title);
}

void shell_surface_set_toplevel(struct wl_shell_surface* wl_shell_surface) const
void shell_surface_set_toplevel(struct xdg_toplevel* xdg_toplevel) const
{
this->proxy_marshal(reinterpret_cast<struct wl_proxy*>(wl_shell_surface), WL_SHELL_SURFACE_SET_TOPLEVEL);
this->proxy_marshal(reinterpret_cast<struct wl_proxy*>(xdg_toplevel), WL_SHELL_SURFACE_SET_TOPLEVEL);
}

int surface_add_listener(struct wl_surface* wl_surface, struct wl_surface_listener* listener, void* data) const
Expand Down
Loading