mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
apprt/gtk: the comptimeEnabled check is redundant
This commit is contained in:
@ -149,7 +149,7 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
|
||||
});
|
||||
|
||||
// If not libadwaita, create a standard GTK application.
|
||||
if ((comptime adwaita.comptimeEnabled()) and
|
||||
if ((comptime adwaita.versionAtLeast(0, 0, 0)) and
|
||||
!adwaita.enabled(&config))
|
||||
{
|
||||
break :app @as(?*c.GtkApplication, @ptrCast(c.gtk_application_new(
|
||||
|
@ -60,10 +60,10 @@ pub fn init(self: *Window, app: *App) !void {
|
||||
};
|
||||
|
||||
// Create the window
|
||||
const adw_window = (comptime adwaita.comptimeEnabled()) and
|
||||
const adw_window =
|
||||
(comptime adwaita.versionAtLeast(1, 4, 0)) and
|
||||
adwaita.enabled(&app.config) and
|
||||
app.config.@"gtk-titlebar" and
|
||||
(comptime adwaita.versionAtLeast(1, 4, 0)) and
|
||||
adwaita.versionAtLeast(1, 4, 0);
|
||||
const window: *c.GtkWidget = if (adw_window)
|
||||
c.adw_application_window_new(app.app)
|
||||
@ -127,8 +127,7 @@ pub fn init(self: *Window, app: *App) !void {
|
||||
// This is a really common issue where people build from source in debug and performance is really bad.
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
const warning_text = "⚠️ You're running a debug build of Ghostty! Performance will be degraded.";
|
||||
if ((comptime adwaita.comptimeEnabled()) and
|
||||
(comptime adwaita.versionAtLeast(1, 3, 0)) and
|
||||
if ((comptime adwaita.versionAtLeast(1, 3, 0)) and
|
||||
adwaita.enabled(&app.config) and
|
||||
adwaita.versionAtLeast(1, 3, 0))
|
||||
{
|
||||
@ -161,8 +160,7 @@ pub fn init(self: *Window, app: *App) !void {
|
||||
// Our actions for the menu
|
||||
initActions(self);
|
||||
|
||||
if ((comptime adwaita.comptimeEnabled()) and
|
||||
(comptime adwaita.versionAtLeast(1, 4, 0)) and
|
||||
if ((comptime adwaita.versionAtLeast(1, 4, 0)) and
|
||||
adwaita.enabled(&app.config) and
|
||||
adwaita.versionAtLeast(1, 4, 0) and
|
||||
app.config.@"gtk-titlebar" and
|
||||
|
@ -3,13 +3,11 @@ const c = @import("c.zig").c;
|
||||
const build_options = @import("build_options");
|
||||
const Config = @import("../../config.zig").Config;
|
||||
|
||||
/// Returns true if Ghostty is configured to build with libadwaita.
|
||||
pub fn comptimeEnabled() bool {
|
||||
return build_options.libadwaita;
|
||||
}
|
||||
|
||||
/// Returns true if Ghostty is configured to build with libadwaita and
|
||||
/// the configuration has enabled adwaita.
|
||||
///
|
||||
/// For a comptime version of this function, use `versionAtLeast` in
|
||||
/// a comptime context with all the version numbers set to 0.
|
||||
pub fn enabled(config: *const Config) bool {
|
||||
return build_options.libadwaita and
|
||||
config.@"gtk-adwaita";
|
||||
|
@ -8,7 +8,7 @@ const adwaita = @import("adwaita.zig");
|
||||
|
||||
const log = std.log.scoped(.gtk);
|
||||
|
||||
const AdwTabView = if (adwaita.comptimeEnabled()) c.AdwTabView else anyopaque;
|
||||
const AdwTabView = if (adwaita.versionAtLeast(0, 0, 0)) c.AdwTabView else anyopaque;
|
||||
|
||||
/// An abstraction over the GTK notebook and Adwaita tab view to manage
|
||||
/// all the terminal tabs in a window.
|
||||
@ -94,7 +94,7 @@ pub const Notebook = union(enum) {
|
||||
pub fn nPages(self: Notebook) c_int {
|
||||
return switch (self) {
|
||||
.gtk_notebook => |notebook| c.gtk_notebook_get_n_pages(notebook),
|
||||
.adw_tab_view => |tab_view| if (comptime adwaita.comptimeEnabled())
|
||||
.adw_tab_view => |tab_view| if (comptime adwaita.versionAtLeast(0, 0, 0))
|
||||
c.adw_tab_view_get_n_pages(tab_view)
|
||||
else
|
||||
unreachable,
|
||||
@ -104,7 +104,7 @@ pub const Notebook = union(enum) {
|
||||
pub fn currentPage(self: Notebook) c_int {
|
||||
switch (self) {
|
||||
.adw_tab_view => |tab_view| {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
const page = c.adw_tab_view_get_selected_page(tab_view);
|
||||
return c.adw_tab_view_get_page_position(tab_view, page);
|
||||
},
|
||||
@ -116,7 +116,7 @@ pub const Notebook = union(enum) {
|
||||
pub fn currentTab(self: Notebook) ?*Tab {
|
||||
const child = switch (self) {
|
||||
.adw_tab_view => |tab_view| child: {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
const page = c.adw_tab_view_get_selected_page(tab_view) orelse return null;
|
||||
const child = c.adw_tab_page_get_child(page);
|
||||
break :child child;
|
||||
@ -136,7 +136,7 @@ pub const Notebook = union(enum) {
|
||||
pub fn gotoNthTab(self: Notebook, position: c_int) void {
|
||||
switch (self) {
|
||||
.adw_tab_view => |tab_view| {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
const page_to_select = c.adw_tab_view_get_nth_page(tab_view, position);
|
||||
c.adw_tab_view_set_selected_page(tab_view, page_to_select);
|
||||
},
|
||||
@ -147,7 +147,7 @@ pub const Notebook = union(enum) {
|
||||
pub fn getTabPosition(self: Notebook, tab: *Tab) ?c_int {
|
||||
return switch (self) {
|
||||
.adw_tab_view => |tab_view| page_idx: {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
const page = c.adw_tab_view_get_page(tab_view, @ptrCast(tab.box)) orelse return null;
|
||||
break :page_idx c.adw_tab_view_get_page_position(tab_view, page);
|
||||
},
|
||||
@ -186,7 +186,7 @@ pub const Notebook = union(enum) {
|
||||
pub fn setTabLabel(self: Notebook, tab: *Tab, title: [:0]const u8) void {
|
||||
switch (self) {
|
||||
.adw_tab_view => |tab_view| {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
const page = c.adw_tab_view_get_page(tab_view, @ptrCast(tab.box));
|
||||
c.adw_tab_page_set_title(page, title.ptr);
|
||||
},
|
||||
@ -198,7 +198,7 @@ pub const Notebook = union(enum) {
|
||||
const box_widget: *c.GtkWidget = @ptrCast(tab.box);
|
||||
switch (self) {
|
||||
.adw_tab_view => |tab_view| {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
|
||||
const page = c.adw_tab_view_append(tab_view, box_widget);
|
||||
c.adw_tab_page_set_title(page, title.ptr);
|
||||
@ -269,7 +269,7 @@ pub const Notebook = union(enum) {
|
||||
const window = tab.window;
|
||||
switch (self) {
|
||||
.adw_tab_view => |tab_view| {
|
||||
if (comptime !adwaita.comptimeEnabled()) unreachable;
|
||||
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
|
||||
|
||||
const page = c.adw_tab_view_get_page(tab_view, @ptrCast(tab.box)) orelse return;
|
||||
c.adw_tab_view_close_page(tab_view, page);
|
||||
|
Reference in New Issue
Block a user