mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-19 11:31:19 +00:00
gtk: implement quick-terminal-size (#6629)
Fixes #2384 on GTK I'm not exactly sure how to deal with centered quick terminals so I opted to make them similar to either top/bottom or left/right quick terminals based on the monitor's orientation (portrait/landscape). This may not be the right approach, so I'd like to hear more thoughts about this.
This commit is contained in:
@@ -82,6 +82,7 @@ pub const DerivedConfig = struct {
|
||||
gtk_toolbar_style: configpkg.Config.GtkToolbarStyle,
|
||||
|
||||
quick_terminal_position: configpkg.Config.QuickTerminalPosition,
|
||||
quick_terminal_size: configpkg.Config.QuickTerminalSize,
|
||||
quick_terminal_autohide: bool,
|
||||
|
||||
maximize: bool,
|
||||
@@ -100,6 +101,7 @@ pub const DerivedConfig = struct {
|
||||
.gtk_toolbar_style = config.@"gtk-toolbar-style",
|
||||
|
||||
.quick_terminal_position = config.@"quick-terminal-position",
|
||||
.quick_terminal_size = config.@"quick-terminal-size",
|
||||
.quick_terminal_autohide = config.@"quick-terminal-autohide",
|
||||
|
||||
.maximize = config.maximize,
|
||||
|
||||
@@ -6,6 +6,7 @@ const build_options = @import("build_options");
|
||||
const wayland = @import("wayland");
|
||||
const gtk = @import("gtk");
|
||||
const gtk4_layer_shell = @import("gtk4-layer-shell");
|
||||
const gdk = @import("gdk");
|
||||
|
||||
const c = @import("../c.zig").c;
|
||||
const Config = @import("../../../config.zig").Config;
|
||||
@@ -249,6 +250,11 @@ pub const Window = struct {
|
||||
break :deco deco;
|
||||
};
|
||||
|
||||
if (apprt_window.isQuickTerminal()) {
|
||||
const surface: *gdk.Surface = @ptrCast(gdk_surface);
|
||||
_ = gdk.Surface.signals.enter_monitor.connect(surface, *ApprtWindow, enteredMonitor, apprt_window, .{});
|
||||
}
|
||||
|
||||
return .{
|
||||
.apprt_window = apprt_window,
|
||||
.surface = wl_surface,
|
||||
@@ -365,11 +371,6 @@ pub const Window = struct {
|
||||
gtk4_layer_shell.setAnchor(window, edge, false);
|
||||
}
|
||||
|
||||
switch (position) {
|
||||
.top, .bottom, .center => window.setDefaultSize(800, 400),
|
||||
.left, .right => window.setDefaultSize(400, 800),
|
||||
}
|
||||
|
||||
if (self.apprt_window.isQuickTerminal()) {
|
||||
if (self.slide) |slide| slide.release();
|
||||
|
||||
@@ -394,4 +395,25 @@ pub const Window = struct {
|
||||
} else null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the size of the quick terminal based on monitor dimensions.
|
||||
fn enteredMonitor(
|
||||
_: *gdk.Surface,
|
||||
monitor: *gdk.Monitor,
|
||||
apprt_window: *ApprtWindow,
|
||||
) callconv(.C) void {
|
||||
const window: *gtk.Window = @ptrCast(apprt_window.window);
|
||||
const size = apprt_window.config.quick_terminal_size;
|
||||
const position = apprt_window.config.quick_terminal_position;
|
||||
|
||||
var monitor_size: gdk.Rectangle = undefined;
|
||||
monitor.getGeometry(&monitor_size);
|
||||
|
||||
const dims = size.calculate(position, .{
|
||||
.width = @intCast(monitor_size.f_width),
|
||||
.height = @intCast(monitor_size.f_height),
|
||||
});
|
||||
|
||||
window.setDefaultSize(@intCast(dims.width), @intCast(dims.height));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user