mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
metal: start setting up background transparency
This commit is contained in:
@ -278,7 +278,7 @@ pub const Surface = struct {
|
|||||||
"ghostty",
|
"ghostty",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Renderer.glfwWindowHints(),
|
Renderer.glfwWindowHints(&app.config),
|
||||||
) orelse return glfw.mustGetErrorCode();
|
) orelse return glfw.mustGetErrorCode();
|
||||||
errdefer win.destroy();
|
errdefer win.destroy();
|
||||||
|
|
||||||
|
@ -65,6 +65,11 @@ pub const Config = struct {
|
|||||||
|
|
||||||
/// The opacity level (opposite of transparency) of the background.
|
/// The opacity level (opposite of transparency) of the background.
|
||||||
/// A value of 1 is fully opaque and a value of 0 is fully transparent.
|
/// A value of 1 is fully opaque and a value of 0 is fully transparent.
|
||||||
|
/// A value less than 0 or greater than 1 will be clamped to the nearest
|
||||||
|
/// valid value.
|
||||||
|
///
|
||||||
|
/// This can be changed at runtime for native macOS and Linux GTK builds.
|
||||||
|
/// This can NOT be changed at runtime for GLFW builds (not common).
|
||||||
@"background-opacity": f64 = 1.0,
|
@"background-opacity": f64 = 1.0,
|
||||||
|
|
||||||
/// The command to run, usually a shell. If this is not an absolute path,
|
/// The command to run, usually a shell. If this is not an absolute path,
|
||||||
|
@ -132,6 +132,7 @@ pub const DerivedConfig = struct {
|
|||||||
font_thicken: bool,
|
font_thicken: bool,
|
||||||
cursor_color: ?terminal.color.RGB,
|
cursor_color: ?terminal.color.RGB,
|
||||||
background: terminal.color.RGB,
|
background: terminal.color.RGB,
|
||||||
|
background_opacity: f64,
|
||||||
foreground: terminal.color.RGB,
|
foreground: terminal.color.RGB,
|
||||||
selection_background: ?terminal.color.RGB,
|
selection_background: ?terminal.color.RGB,
|
||||||
selection_foreground: ?terminal.color.RGB,
|
selection_foreground: ?terminal.color.RGB,
|
||||||
@ -143,6 +144,7 @@ pub const DerivedConfig = struct {
|
|||||||
_ = alloc_gpa;
|
_ = alloc_gpa;
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
||||||
.font_thicken = config.@"font-thicken",
|
.font_thicken = config.@"font-thicken",
|
||||||
|
|
||||||
.cursor_color = if (config.@"cursor-color") |col|
|
.cursor_color = if (config.@"cursor-color") |col|
|
||||||
@ -171,11 +173,10 @@ pub const DerivedConfig = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Returns the hints that we want for this
|
/// Returns the hints that we want for this
|
||||||
pub fn glfwWindowHints() glfw.Window.Hints {
|
pub fn glfwWindowHints(config: *const configpkg.Config) glfw.Window.Hints {
|
||||||
return .{
|
return .{
|
||||||
.client_api = .no_api,
|
.client_api = .no_api,
|
||||||
// .cocoa_graphics_switching = builtin.os.tag == .macos,
|
.transparent_framebuffer = config.@"background-opacity" < 1,
|
||||||
// .cocoa_retina_framebuffer = true,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +197,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
const CAMetalLayer = objc.Class.getClass("CAMetalLayer").?;
|
const CAMetalLayer = objc.Class.getClass("CAMetalLayer").?;
|
||||||
const swapchain = CAMetalLayer.msgSend(objc.Object, objc.sel("layer"), .{});
|
const swapchain = CAMetalLayer.msgSend(objc.Object, objc.sel("layer"), .{});
|
||||||
swapchain.setProperty("device", device.value);
|
swapchain.setProperty("device", device.value);
|
||||||
swapchain.setProperty("opaque", true);
|
swapchain.setProperty("opaque", options.config.background_opacity >= 1);
|
||||||
|
|
||||||
// disable v-sync
|
// disable v-sync
|
||||||
swapchain.setProperty("displaySyncEnabled", false);
|
swapchain.setProperty("displaySyncEnabled", false);
|
||||||
@ -628,7 +629,7 @@ pub fn render(
|
|||||||
.red = @as(f32, @floatFromInt(critical.bg.r)) / 255,
|
.red = @as(f32, @floatFromInt(critical.bg.r)) / 255,
|
||||||
.green = @as(f32, @floatFromInt(critical.bg.g)) / 255,
|
.green = @as(f32, @floatFromInt(critical.bg.g)) / 255,
|
||||||
.blue = @as(f32, @floatFromInt(critical.bg.b)) / 255,
|
.blue = @as(f32, @floatFromInt(critical.bg.b)) / 255,
|
||||||
.alpha = 1.0,
|
.alpha = self.config.background_opacity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user