Wayland: Detect SSD by querying compositor

Much more reliable than checking environment variables. Does
add ~1ms to startup time on Wayland.
This commit is contained in:
Kovid Goyal 2019-06-05 10:37:57 +05:30
parent 98d7fc9f39
commit 303711ab8d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 55 additions and 9 deletions

33
glfw/wl_init.c vendored
View File

@ -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 //////
//////////////////////////////////////////////////////////////////////////

View File

@ -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):