mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
chore: update logic to use unified winproto
This commit is contained in:
@ -857,30 +857,27 @@ pub fn setInitialWindowSize(self: *const Surface, width: u32, height: u32) !void
|
||||
);
|
||||
|
||||
// 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 (!x11.should_use_net_wm_state(gdk_surface)) {
|
||||
const winproto = &(window.winproto orelse return);
|
||||
if (!winproto.shouldSetWMState()) {
|
||||
log.warn("current WM does not support _NET_WM_STATE", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window.window));
|
||||
const workarea = self.getWorkarea(gdk_surface) orelse return;
|
||||
if (height >= workarea.height and width >= workarea.width) {
|
||||
c.gtk_window_maximize(@ptrCast(window.window));
|
||||
}
|
||||
}
|
||||
|
||||
fn getWorkarea(self: *const Surface, gdk_surface: ?*c.GdkSurface) ?c.GdkRectangle {
|
||||
fn getWorkarea(_: *const Surface, gdk_surface: ?*c.GdkSurface) ?c.GdkRectangle {
|
||||
const monitor = c.gdk_display_get_monitor_at_surface(
|
||||
c.gdk_display_get_default(),
|
||||
gdk_surface,
|
||||
);
|
||||
|
||||
var workarea: c.GdkRectangle = std.mem.zeroes(c.GdkRectangle);
|
||||
if (self.app.wayland != null) {
|
||||
c.gdk_monitor_get_geometry(monitor, &workarea);
|
||||
} else {
|
||||
c.gdk_x11_monitor_get_workarea(monitor, &workarea);
|
||||
}
|
||||
c.gdk_x11_monitor_get_workarea(monitor, &workarea);
|
||||
|
||||
return workarea;
|
||||
}
|
||||
|
@ -613,14 +613,16 @@ fn gtkWindowNotifyDecorated(
|
||||
fn gtkWindowNotifyMaximized(
|
||||
window: *c.GtkWindow,
|
||||
_: *c.GParamSpec,
|
||||
_: ?*anyopaque,
|
||||
ud: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window));
|
||||
if (!winproto.x11.should_use_net_wm_state(gdk_surface)) {
|
||||
// If the current WM doesn't support _NET_WM_STATE, we shouldn't try to set it.
|
||||
const self: *winproto.Window = @ptrCast(@alignCast(ud orelse return));
|
||||
if (!self.shouldSetWMState()) {
|
||||
log.warn("current WM does not support _NET_WM_STATE", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window));
|
||||
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
|
||||
|
@ -125,4 +125,10 @@ pub const Window = union(Protocol) {
|
||||
inline else => |*v| try v.syncAppearance(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shouldSetWMState(self: *Window) bool {
|
||||
return switch (self.*) {
|
||||
inline else => |*v| v.shouldSetWMState(),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -53,4 +53,8 @@ pub const Window = struct {
|
||||
pub fn resizeEvent(_: *Window) !void {}
|
||||
|
||||
pub fn syncAppearance(_: *Window) !void {}
|
||||
|
||||
pub fn shouldSetWMState(_: *Window) bool {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -208,4 +208,8 @@ pub const Window = struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shouldSetWMState(_: *Window) bool {
|
||||
return false; // Wayland doesn't use _NET_WM_STATE
|
||||
}
|
||||
};
|
||||
|
@ -283,6 +283,27 @@ pub const Window = struct {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if we should set the _NET_WM_STATE property on the window.
|
||||
///
|
||||
/// To be truthy, we must have a valid X11 surface and the window manager must
|
||||
/// support _NET_WM_STATE.
|
||||
pub fn shouldSetWMState(self: *Window) bool {
|
||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(self.gtk_window)) orelse return false;
|
||||
|
||||
// Check we have a valid X11 surface
|
||||
if (c.g_type_check_instance_is_a(
|
||||
@ptrCast(@alignCast(gdk_surface)),
|
||||
c.gdk_x11_surface_get_type(),
|
||||
) == 0) return false;
|
||||
|
||||
// Check the window manager supports _NET_WM_STATE
|
||||
return c.XInternAtom(
|
||||
c.gdk_x11_display_get_xdisplay(c.gdk_surface_get_display(gdk_surface)),
|
||||
"_NET_WM_STATE",
|
||||
1,
|
||||
) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
const Region = extern struct {
|
||||
|
@ -22,17 +22,6 @@ 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