mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
refactor: move x11 surface and _NET_WM_STATE support check to common file
This commit is contained in:
@ -857,12 +857,9 @@ pub fn setInitialWindowSize(self: *const Surface, width: u32, height: u32) !void
|
||||
@intCast(height),
|
||||
);
|
||||
|
||||
// TODO: move this check somewhere else so we can reuse it
|
||||
// If the current WM doesn't support _NET_WM_STATE, we shouldn't try to set it.
|
||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window.window));
|
||||
if (c.g_type_check_instance_is_a(@ptrCast(@alignCast(gdk_surface)), c.gdk_x11_surface_get_type()) == 0) return; // X11 only, sorry Wayland
|
||||
|
||||
if (c.XInternAtom(c.gdk_x11_display_get_xdisplay(c.gdk_surface_get_display(gdk_surface)), "_NET_WM_STATE", 1) == 0) {
|
||||
if (!x11.should_use_net_wm_state(gdk_surface)) {
|
||||
log.warn("current WM does not support _NET_WM_STATE", .{});
|
||||
return;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ const Notebook = @import("notebook.zig").Notebook;
|
||||
const HeaderBar = @import("headerbar.zig").HeaderBar;
|
||||
const version = @import("version.zig");
|
||||
const wayland = @import("wayland.zig");
|
||||
const x11 = @import("x11.zig");
|
||||
|
||||
const log = std.log.scoped(.gtk);
|
||||
|
||||
@ -623,16 +624,13 @@ fn gtkWindowNotifyMaximized(
|
||||
_: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window));
|
||||
if (c.g_type_check_instance_is_a(@ptrCast(@alignCast(gdk_surface)), c.gdk_x11_surface_get_type()) == 0) return; // X11 only, sorry Wayland
|
||||
|
||||
const xdisplay = c.gdk_x11_display_get_xdisplay(c.gdk_surface_get_display(gdk_surface)) orelse return;
|
||||
|
||||
// If the WM doesn't support _NET_WM_STATE, no need to continue.
|
||||
if (c.XInternAtom(xdisplay, "_NET_WM_STATE", 1) == 0) {
|
||||
if (!x11.should_use_net_wm_state(gdk_surface)) {
|
||||
log.warn("current WM does not support _NET_WM_STATE", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
const xdisplay = c.gdk_x11_display_get_xdisplay(c.gdk_surface_get_display(gdk_surface)) orelse return;
|
||||
|
||||
// https://tronche.com/gui/x/xlib/events/client-communication/client-message.html#XClientMessageEvent
|
||||
var client_message_event: c.XClientMessageEvent = std.mem.zeroes(c.XClientMessageEvent);
|
||||
client_message_event.type = c.ClientMessage;
|
||||
|
@ -22,6 +22,17 @@ pub fn is_current_display_server() bool {
|
||||
return is_display(display);
|
||||
}
|
||||
|
||||
/// Returns true if we have a valid X11 surface and the current WM supports _NET_WM_STATE.
|
||||
pub fn should_use_net_wm_state(surface: ?*c.GdkSurface) bool {
|
||||
if (comptime !build_options.x11) return false;
|
||||
if (c.g_type_check_instance_is_a(
|
||||
@ptrCast(@alignCast(surface)),
|
||||
c.gdk_x11_surface_get_type(),
|
||||
) == 0) return false;
|
||||
|
||||
return c.XInternAtom(c.gdk_x11_display_get_xdisplay(c.gdk_surface_get_display(surface)), "_NET_WM_STATE", 1) != 0;
|
||||
}
|
||||
|
||||
pub const Xkb = struct {
|
||||
base_event_code: c_int,
|
||||
|
||||
|
Reference in New Issue
Block a user