Skip to content

Commit

Permalink
Add initial Wayland support
Browse files Browse the repository at this point in the history
The window lacks the expected decoration in GNOME since we use glfw
3.3.6 and libdecor support was added 3.3.9.

This does not work well with high-DPI monitors. The window is made
larger than the framebuffer.
  • Loading branch information
footballhead committed Mar 10, 2024
1 parent 9427c6e commit 877ceb3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ if (NOT PPX_ANDROID)
set(GLFW_BUILD_TESTS FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS FALSE CACHE BOOL "" FORCE)
set(GLFW_VULKAN_STATIC FALSE CACHE BOOL "" FORCE)
if (PPX_LINUX_WAYLAND)
set(GLFW_USE_WAYLAND TRUE CACHE BOOL "" FORCE)
endif()
add_subdirectory(${PPX_THIRD_PARTY_DIR}/glfw)
endif()

Expand Down
8 changes: 8 additions & 0 deletions docs/building_and_running.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Install the following prerequisite packages before building:
sudo apt install libxrandr-dev libxinerama-dev libx11-dev libxcursor-dev libxi-dev libx11-xcb-dev clang mesa-vulkan-drivers cmake ninja-build
```

If building for Wayland, also install:

```
sudo apt install libwayland-dev wayland-protocols libxkbcommon-dev extra-cmake-modules
```

## Linux
```
git clone --recursive https://github.com/google/bigwheels
Expand All @@ -49,6 +55,8 @@ ninja -C build

Built binaries are written to `build/bin/`.

If building for Wayland, run CMake with `-DPPX_LINUX_WAYLAND=1`.

## Windows

- Make sure the "Graphics Tools" feature is enabled (Settings > System > "Optional features" > "Add a feature" > "Graphics Tools". This is required to have DX12 debug layers.
Expand Down
2 changes: 1 addition & 1 deletion src/ppx/grfx/vk/vk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Result Instance::ConfigureLayersAndExtensions(const grfx::InstanceCreateInfo* pC
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
mExtensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
#elif defined(PPX_MSW)
mExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
#endif
Expand Down
10 changes: 9 additions & 1 deletion src/ppx/grfx/vk/vk_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ Result Surface::CreateApiObjects(const grfx::SurfaceCreateInfo* pCreateInfo)
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
VkWaylandSurfaceCreateInfoKHR vkci = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
vkci.display = pCreateInfo->display;
vkci.surface = pCreateInfo->surface;

vkres = vkCreateWaylandSurfaceKHR(
ToApi(GetInstance())->GetVkInstance(),
&vkci,
nullptr,
&mSurface);
#elif defined(PPX_MSW)
VkWin32SurfaceCreateInfoKHR vkci = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
vkci.hinstance = pCreateInfo->hinstance;
Expand Down
9 changes: 6 additions & 3 deletions src/ppx/window_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
#include <wayland-client.h>
#endif

#include <GLFW/glfw3.h>
// clang-format off
#if defined(PPX_LINUX)
#if defined(PPX_LINUX_XCB)
# define GLFW_EXPOSE_NATIVE_X11
#elif defined(PPX_MSW)
# define GLFW_EXPOSE_NATIVE_WIN32
#elif defined(PPX_LINUX_WAYLAND)
# define GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#include <GLFW/glfw3native.h>
// clang-format on
Expand Down Expand Up @@ -484,7 +486,8 @@ void WindowImplGLFW::FillSurfaceInfo(grfx::SurfaceCreateInfo* pCreateInfo) const
#elif defined(PPX_LINUX_XLIB)
#error "Xlib not implemented"
#elif defined(PPX_LINUX_WAYLAND)
#error "Wayland not implemented"
pCreateInfo->display = glfwGetWaylandDisplay();
pCreateInfo->surface = glfwGetWaylandWindow(mNative);
#elif defined(PPX_MSW)
pCreateInfo->hinstance = ::GetModuleHandle(nullptr);
pCreateInfo->hwnd = glfwGetWin32Window(mNative);
Expand Down

0 comments on commit 877ceb3

Please sign in to comment.