mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-21 03:27:55 +03:00
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:
parent
98d7fc9f39
commit
303711ab8d
33
glfw/wl_init.c
vendored
33
glfw/wl_init.c
vendored
@ -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 //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user