mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Initialize GL without drawing anything
This commit is contained in:
@ -68,6 +68,10 @@ clipboard_confirmation_window: ?*ClipboardConfirmationWindow = null,
|
|||||||
/// This is set to false when the main loop should exit.
|
/// This is set to false when the main loop should exit.
|
||||||
running: bool = true,
|
running: bool = true,
|
||||||
|
|
||||||
|
/// We use this variable to initialize the GL
|
||||||
|
/// context without actually creating a window
|
||||||
|
hide_window: bool = false,
|
||||||
|
|
||||||
/// Xkb state (X11 only). Will be null on Wayland.
|
/// Xkb state (X11 only). Will be null on Wayland.
|
||||||
x11_xkb: ?x11.Xkb = null,
|
x11_xkb: ?x11.Xkb = null,
|
||||||
|
|
||||||
@ -369,12 +373,9 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// This just calls the `activate` signal but its part of the normal startup
|
// This just calls the `activate` signal but its part of the normal startup
|
||||||
// routine so we just call it, but only if the config allows it (this allows
|
// routine so we just call it
|
||||||
// for launching Ghostty in the "background" without immediately opening
|
|
||||||
// a window)
|
|
||||||
//
|
//
|
||||||
// https://gitlab.gnome.org/GNOME/glib/-/blob/bd2ccc2f69ecfd78ca3f34ab59e42e2b462bad65/gio/gapplication.c#L2302
|
// https://gitlab.gnome.org/GNOME/glib/-/blob/bd2ccc2f69ecfd78ca3f34ab59e42e2b462bad65/gio/gapplication.c#L2302
|
||||||
if (config.@"initial-window")
|
|
||||||
c.g_application_activate(gapp);
|
c.g_application_activate(gapp);
|
||||||
|
|
||||||
// Register for dbus events
|
// Register for dbus events
|
||||||
@ -421,6 +422,9 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
|
|||||||
// our "activate" call above will open a window.
|
// our "activate" call above will open a window.
|
||||||
.running = c.g_application_get_is_remote(gapp) == 0,
|
.running = c.g_application_get_is_remote(gapp) == 0,
|
||||||
.css_provider = css_provider,
|
.css_provider = css_provider,
|
||||||
|
// this allows for launching Ghostty in the "background"
|
||||||
|
// without immediately opening a window
|
||||||
|
.hide_window = !config.@"initial-window",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,10 +452,13 @@ pub fn performAction(
|
|||||||
value: apprt.Action.Value(action),
|
value: apprt.Action.Value(action),
|
||||||
) !void {
|
) !void {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
.new_window => _ = try self.newWindow(switch (target) {
|
.new_window => _ = {
|
||||||
|
try self.newWindow(switch (target) {
|
||||||
.app => null,
|
.app => null,
|
||||||
.surface => |v| v,
|
.surface => |v| v,
|
||||||
}),
|
}, self.hide_window);
|
||||||
|
self.hide_window = false;
|
||||||
|
},
|
||||||
.toggle_fullscreen => self.toggleFullscreen(target, value),
|
.toggle_fullscreen => self.toggleFullscreen(target, value),
|
||||||
|
|
||||||
.new_tab => try self.newTab(target),
|
.new_tab => try self.newTab(target),
|
||||||
@ -1144,7 +1151,7 @@ pub fn redrawInspector(self: *App, surface: *Surface) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Called by CoreApp to create a new window with a new surface.
|
/// Called by CoreApp to create a new window with a new surface.
|
||||||
fn newWindow(self: *App, parent_: ?*CoreSurface) !void {
|
fn newWindow(self: *App, parent_: ?*CoreSurface, hidden: bool) !void {
|
||||||
const alloc = self.core_app.alloc;
|
const alloc = self.core_app.alloc;
|
||||||
|
|
||||||
// Allocate a fixed pointer for our window. We try to minimize
|
// Allocate a fixed pointer for our window. We try to minimize
|
||||||
@ -1154,11 +1161,13 @@ fn newWindow(self: *App, parent_: ?*CoreSurface) !void {
|
|||||||
//
|
//
|
||||||
// The allocation is owned by the GtkWindow created. It will be
|
// The allocation is owned by the GtkWindow created. It will be
|
||||||
// freed when the window is closed.
|
// freed when the window is closed.
|
||||||
var window = try Window.create(alloc, self);
|
var window = try Window.create(alloc, self, hidden);
|
||||||
|
|
||||||
|
if (!hidden) {
|
||||||
// Add our initial tab
|
// Add our initial tab
|
||||||
try window.newTab(parent_);
|
try window.newTab(parent_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn quit(self: *App) void {
|
fn quit(self: *App) void {
|
||||||
// If we have no toplevel windows, then we're done.
|
// If we have no toplevel windows, then we're done.
|
||||||
|
@ -54,7 +54,7 @@ toast_overlay: ?*c.GtkWidget,
|
|||||||
/// See adwTabOverviewOpen for why we have this.
|
/// See adwTabOverviewOpen for why we have this.
|
||||||
adw_tab_overview_focus_timer: ?c.guint = null,
|
adw_tab_overview_focus_timer: ?c.guint = null,
|
||||||
|
|
||||||
pub fn create(alloc: Allocator, app: *App) !*Window {
|
pub fn create(alloc: Allocator, app: *App, hidden: bool) !*Window {
|
||||||
// Allocate a fixed pointer for our window. We try to minimize
|
// Allocate a fixed pointer for our window. We try to minimize
|
||||||
// allocations but windows and other GUI requirements are so minimal
|
// allocations but windows and other GUI requirements are so minimal
|
||||||
// compared to the steady-state terminal operation so we use heap
|
// compared to the steady-state terminal operation so we use heap
|
||||||
@ -64,11 +64,11 @@ pub fn create(alloc: Allocator, app: *App) !*Window {
|
|||||||
// freed when the window is closed.
|
// freed when the window is closed.
|
||||||
var window = try alloc.create(Window);
|
var window = try alloc.create(Window);
|
||||||
errdefer alloc.destroy(window);
|
errdefer alloc.destroy(window);
|
||||||
try window.init(app);
|
try window.init(app, hidden);
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(self: *Window, app: *App) !void {
|
pub fn init(self: *Window, app: *App, hidden: bool) !void {
|
||||||
// Set up our own state
|
// Set up our own state
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.app = app,
|
.app = app,
|
||||||
@ -361,6 +361,10 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
|
|
||||||
// Show the window
|
// Show the window
|
||||||
c.gtk_widget_show(window);
|
c.gtk_widget_show(window);
|
||||||
|
if (hidden) {
|
||||||
|
c.gtk_widget_hide(window);
|
||||||
|
c.gtk_window_destroy(gtk_window);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets up the GTK actions for the window scope. Actions are how GTK handles
|
/// Sets up the GTK actions for the window scope. Actions are how GTK handles
|
||||||
|
@ -490,5 +490,5 @@ fn createWindow(currentWindow: *Window) !*Window {
|
|||||||
const app = currentWindow.app;
|
const app = currentWindow.app;
|
||||||
|
|
||||||
// Create a new window
|
// Create a new window
|
||||||
return Window.create(alloc, app);
|
return Window.create(alloc, app, false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user