diff --git a/glfw/wl_init.c b/glfw/wl_init.c index fdac7c3c6..27ef32d75 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -634,6 +634,39 @@ static const struct wl_registry_listener registryListener = { }; + +static void registry_handle_global(void* data, + struct wl_registry* registry, + uint32_t name, + const char* interface, + uint32_t version) { + if (strcmp(interface, "zxdg_decoration_manager_v1") == 0) { + bool *has_ssd = (bool*)data; + if (has_ssd) *has_ssd = true; + } +} + +static void registry_handle_global_remove(void *data, + struct wl_registry *registry, + uint32_t name) {} +GLFWAPI const char* +glfwWaylandCheckForServerSideDecorations(void) { + struct wl_display *display = wl_display_connect(NULL); + if (!display) return "ERR: Failed to connect to Wayland display"; + static const struct wl_registry_listener rl = { + registry_handle_global, registry_handle_global_remove + }; + struct wl_registry *registry = wl_display_get_registry(display); + bool has_ssd = false; + wl_registry_add_listener(registry, &rl, &has_ssd); + wl_display_roundtrip(display); + + wl_registry_destroy(registry); + wl_display_flush(display); + wl_display_flush(display); + return has_ssd ? "YES" : "NO"; +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/kitty/constants.py b/kitty/constants.py index 7ba74b910..eedead535 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -137,16 +137,29 @@ def detect_if_wayland_ok(): return False if 'KITTY_DISABLE_WAYLAND' in os.environ: return False - if not os.path.exists(glfw_path('wayland')): + wayland = glfw_path('wayland') + if not os.path.exists(wayland): return False - cd = os.environ.get('XDG_CURRENT_DESKTOP') - if cd: - cd = frozenset(cd.split(':')) - if 'GNOME' in cd: - # GNOME does not support xdg-decorations - # https://gitlab.gnome.org/GNOME/mutter/issues/217 - return False - return True + # GNOME does not support xdg-decorations + # https://gitlab.gnome.org/GNOME/mutter/issues/217 + import ctypes + lib = ctypes.CDLL(wayland) + check = lib.glfwWaylandCheckForServerSideDecorations + check.restype = ctypes.c_char_p + check.argtypes = () + try: + ans = bytes(check()) + except Exception: + return False + if ans == b'NO': + print( + 'Your Wayland compositor does not support server side window decorations,' + ' disabling Wayland. You can force Wayland support using the' + ' linux_display_server option in kitty.conf' + ' See https://drewdevault.com/2018/01/27/Sway-and-client-side-decorations.html' + ' for more information.', + file=sys.stderr) + return ans == b'YES' def is_wayland(opts=None):