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.
|
// 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));
|
const winproto = &(window.winproto orelse return);
|
||||||
if (!x11.should_use_net_wm_state(gdk_surface)) {
|
if (!winproto.shouldSetWMState()) {
|
||||||
log.warn("current WM does not support _NET_WM_STATE", .{});
|
log.warn("current WM does not support _NET_WM_STATE", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window.window));
|
||||||
const workarea = self.getWorkarea(gdk_surface) orelse return;
|
const workarea = self.getWorkarea(gdk_surface) orelse return;
|
||||||
if (height >= workarea.height and width >= workarea.width) {
|
if (height >= workarea.height and width >= workarea.width) {
|
||||||
c.gtk_window_maximize(@ptrCast(window.window));
|
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(
|
const monitor = c.gdk_display_get_monitor_at_surface(
|
||||||
c.gdk_display_get_default(),
|
c.gdk_display_get_default(),
|
||||||
gdk_surface,
|
gdk_surface,
|
||||||
);
|
);
|
||||||
|
|
||||||
var workarea: c.GdkRectangle = std.mem.zeroes(c.GdkRectangle);
|
var workarea: c.GdkRectangle = std.mem.zeroes(c.GdkRectangle);
|
||||||
if (self.app.wayland != null) {
|
c.gdk_x11_monitor_get_workarea(monitor, &workarea);
|
||||||
c.gdk_monitor_get_geometry(monitor, &workarea);
|
|
||||||
} else {
|
|
||||||
c.gdk_x11_monitor_get_workarea(monitor, &workarea);
|
|
||||||
}
|
|
||||||
|
|
||||||
return workarea;
|
return workarea;
|
||||||
}
|
}
|
||||||
|
@ -613,14 +613,16 @@ fn gtkWindowNotifyDecorated(
|
|||||||
fn gtkWindowNotifyMaximized(
|
fn gtkWindowNotifyMaximized(
|
||||||
window: *c.GtkWindow,
|
window: *c.GtkWindow,
|
||||||
_: *c.GParamSpec,
|
_: *c.GParamSpec,
|
||||||
_: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const gdk_surface = c.gtk_native_get_surface(@ptrCast(window));
|
// If the current WM doesn't support _NET_WM_STATE, we shouldn't try to set it.
|
||||||
if (!winproto.x11.should_use_net_wm_state(gdk_surface)) {
|
const self: *winproto.Window = @ptrCast(@alignCast(ud orelse return));
|
||||||
|
if (!self.shouldSetWMState()) {
|
||||||
log.warn("current WM does not support _NET_WM_STATE", .{});
|
log.warn("current WM does not support _NET_WM_STATE", .{});
|
||||||
return;
|
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;
|
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
|
// 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(),
|
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 resizeEvent(_: *Window) !void {}
|
||||||
|
|
||||||
pub fn syncAppearance(_: *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 {
|
const Region = extern struct {
|
||||||
|
@ -22,17 +22,6 @@ pub fn is_current_display_server() bool {
|
|||||||
return is_display(display);
|
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 {
|
pub const Xkb = struct {
|
||||||
base_event_code: c_int,
|
base_event_code: c_int,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user