mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
gtk-ng: add debug warning banner
This commit is contained in:
@ -41,6 +41,8 @@ pub const blueprints: []const Blueprint = &.{
|
||||
.{ .major = 1, .minor = 2, .name = "surface" },
|
||||
.{ .major = 1, .minor = 3, .name = "surface-child-exited" },
|
||||
.{ .major = 1, .minor = 5, .name = "window" },
|
||||
.{ .major = 1, .minor = 2, .name = "debug-warning" },
|
||||
.{ .major = 1, .minor = 3, .name = "debug-warning" },
|
||||
};
|
||||
|
||||
/// CSS files in css_path
|
||||
|
80
src/apprt/gtk-ng/class/debug_warning.zig
Normal file
80
src/apprt/gtk-ng/class/debug_warning.zig
Normal file
@ -0,0 +1,80 @@
|
||||
const std = @import("std");
|
||||
const adw = @import("adw");
|
||||
const gobject = @import("gobject");
|
||||
const gtk = @import("gtk");
|
||||
|
||||
const build_config = @import("../../../build_config.zig");
|
||||
const adw_version = @import("../adw_version.zig");
|
||||
const gresource = @import("../build/gresource.zig");
|
||||
const Common = @import("../class.zig").Common;
|
||||
|
||||
/// Debug warning banner. It will be based on adw.Banner if we're using Adwaita
|
||||
/// 1.3 or newer. Otherwise it will use a gtk.Label.
|
||||
pub const DebugWarning = extern struct {
|
||||
const Self = @This();
|
||||
parent_instance: Parent,
|
||||
pub const Parent = if (adw_version.supportsBanner()) adw.Bin else gtk.Box;
|
||||
pub const getGObjectType = gobject.ext.defineClass(Self, .{
|
||||
.name = "GhosttyDebugWarning",
|
||||
.instanceInit = &init,
|
||||
.classInit = &Class.init,
|
||||
.parent_class = &Class.parent,
|
||||
});
|
||||
|
||||
pub const properties = struct {
|
||||
pub const debug = struct {
|
||||
pub const name = "debug";
|
||||
const impl = gobject.ext.defineProperty(
|
||||
name,
|
||||
Self,
|
||||
bool,
|
||||
.{
|
||||
.nick = "Debug",
|
||||
.blurb = "True if runtime safety checks are enabled.",
|
||||
.default = build_config.is_debug,
|
||||
.accessor = gobject.ext.typedAccessor(Self, bool, .{
|
||||
.getter = struct {
|
||||
pub fn getter(_: *DebugWarning) bool {
|
||||
return build_config.is_debug;
|
||||
}
|
||||
}.getter,
|
||||
}),
|
||||
},
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
fn init(self: *Self, _: *Class) callconv(.c) void {
|
||||
gtk.Widget.initTemplate(self.as(gtk.Widget));
|
||||
}
|
||||
|
||||
const C = Common(Self, null);
|
||||
pub const as = C.as;
|
||||
pub const ref = C.ref;
|
||||
pub const unref = C.unref;
|
||||
const private = C.private;
|
||||
|
||||
pub const Class = extern struct {
|
||||
parent_class: Parent.Class,
|
||||
var parent: *Parent.Class = undefined;
|
||||
pub const Instance = Self;
|
||||
|
||||
fn init(class: *Class) callconv(.c) void {
|
||||
gtk.Widget.Class.setTemplateFromResource(
|
||||
class.as(gtk.Widget.Class),
|
||||
comptime gresource.blueprint(.{
|
||||
.major = 1,
|
||||
.minor = if (adw_version.supportsBanner()) 3 else 2,
|
||||
.name = "debug-warning",
|
||||
}),
|
||||
);
|
||||
|
||||
// Properties
|
||||
gobject.ext.registerProperties(class, &.{
|
||||
properties.debug.impl,
|
||||
});
|
||||
}
|
||||
|
||||
pub const as = C.Class.as;
|
||||
};
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const build_config = @import("../../../build_config.zig");
|
||||
const assert = std.debug.assert;
|
||||
const adw = @import("adw");
|
||||
const gobject = @import("gobject");
|
||||
@ -9,6 +10,7 @@ const gresource = @import("../build/gresource.zig");
|
||||
const Common = @import("../class.zig").Common;
|
||||
const Application = @import("application.zig").Application;
|
||||
const Surface = @import("surface.zig").Surface;
|
||||
const DebugWarning = @import("debug_warning.zig").DebugWarning;
|
||||
|
||||
const log = std.log.scoped(.gtk_ghostty_window);
|
||||
|
||||
@ -46,6 +48,9 @@ pub const Window = extern struct {
|
||||
|
||||
fn init(self: *Self, _: *Class) callconv(.C) void {
|
||||
gtk.Widget.initTemplate(self.as(gtk.Widget));
|
||||
|
||||
if (comptime build_config.is_debug)
|
||||
self.as(gtk.Widget).addCssClass("devel");
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
@ -91,6 +96,7 @@ pub const Window = extern struct {
|
||||
|
||||
fn init(class: *Class) callconv(.C) void {
|
||||
gobject.ext.ensureType(Surface);
|
||||
gobject.ext.ensureType(DebugWarning);
|
||||
gtk.Widget.Class.setTemplateFromResource(
|
||||
class.as(gtk.Widget.Class),
|
||||
comptime gresource.blueprint(.{
|
||||
|
12
src/apprt/gtk-ng/ui/1.2/debug-warning.blp
Normal file
12
src/apprt/gtk-ng/ui/1.2/debug-warning.blp
Normal file
@ -0,0 +1,12 @@
|
||||
using Gtk 4.0;
|
||||
|
||||
template $GhosttyDebugWarning: Gtk.Box {
|
||||
orientation: vertical;
|
||||
|
||||
Gtk.Label {
|
||||
label: _("⚠️ You're running a debug build of Ghostty! Performance will be degraded.");
|
||||
visible: bind template.debug;
|
||||
margin-top: 10;
|
||||
margin-bottom: 10;
|
||||
}
|
||||
}
|
9
src/apprt/gtk-ng/ui/1.3/debug-warning.blp
Normal file
9
src/apprt/gtk-ng/ui/1.3/debug-warning.blp
Normal file
@ -0,0 +1,9 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $GhosttyDebugWarning: Adw.Bin {
|
||||
Adw.Banner {
|
||||
title: _("⚠️ You're running a debug build of Ghostty! Performance will be degraded.");
|
||||
revealed: bind template.debug;
|
||||
}
|
||||
}
|
@ -2,10 +2,21 @@ using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $GhosttyWindow: Adw.ApplicationWindow {
|
||||
styles [
|
||||
"window",
|
||||
]
|
||||
|
||||
default-width: 800;
|
||||
default-height: 600;
|
||||
|
||||
content: $GhosttySurface surface {
|
||||
close-request => $surface_close_request();
|
||||
content: Gtk.Box {
|
||||
orientation: vertical;
|
||||
spacing: 0;
|
||||
|
||||
$GhosttyDebugWarning {}
|
||||
|
||||
$GhosttySurface surface {
|
||||
close-request => $surface_close_request();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -96,3 +96,9 @@ pub const Artifact = enum {
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// True if runtime safety checks are enabled.
|
||||
pub const is_debug = switch (builtin.mode) {
|
||||
.Debug, .ReleaseSafe => true,
|
||||
.ReleaseFast, .ReleaseSmall => false,
|
||||
};
|
||||
|
Reference in New Issue
Block a user