Merge branch 'ghostty-org:main' into feat/add-keybind-action-for-copy_url_to_clipboard

This commit is contained in:
Alexandre Antonio Juca
2025-01-06 17:03:49 +01:00
committed by GitHub
5 changed files with 49 additions and 24 deletions

View File

@ -145,7 +145,6 @@ pub fn build(b: *std.Build) !void {
if (std.mem.indexOf(u8, stdout.items, "wayland")) |_| wayland = true; if (std.mem.indexOf(u8, stdout.items, "wayland")) |_| wayland = true;
} else { } else {
std.log.warn("pkg-config: {s} with code {d}", .{ @tagName(term), code }); std.log.warn("pkg-config: {s} with code {d}", .{ @tagName(term), code });
return error.Unexpected;
} }
}, },
inline else => |code| { inline else => |code| {

View File

@ -424,35 +424,42 @@ class AppDelegate: NSObject,
// If we have a main window then we don't process any of the keys // If we have a main window then we don't process any of the keys
// because we let it capture and propagate. // because we let it capture and propagate.
guard NSApp.mainWindow == nil else { return event } guard NSApp.mainWindow == nil else { return event }
// If this event as-is would result in a key binding then we send it. // If this event as-is would result in a key binding then we send it.
if let app = ghostty.app, if let app = ghostty.app,
ghostty_app_key_is_binding( ghostty_app_key_is_binding(
app, app,
event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS)) { event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS)) {
ghostty_app_key(app, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS)) // If the key was handled by Ghostty we stop the event chain. If
return nil // the key wasn't handled then we let it fall through and continue
// processing. This is important because some bindings may have no
// affect at this scope.
if (ghostty_app_key(
app,
event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))) {
return nil
}
} }
// If this event would be handled by our menu then we do nothing. // If this event would be handled by our menu then we do nothing.
if let mainMenu = NSApp.mainMenu, if let mainMenu = NSApp.mainMenu,
mainMenu.performKeyEquivalent(with: event) { mainMenu.performKeyEquivalent(with: event) {
return nil return nil
} }
// If we reach this point then we try to process the key event // If we reach this point then we try to process the key event
// through the Ghostty key mechanism. // through the Ghostty key mechanism.
// Ghostty must be loaded // Ghostty must be loaded
guard let ghostty = self.ghostty.app else { return event } guard let ghostty = self.ghostty.app else { return event }
// Build our event input and call ghostty // Build our event input and call ghostty
if (ghostty_app_key(ghostty, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))) { if (ghostty_app_key(ghostty, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))) {
// The key was used so we want to stop it from going to our Mac app // The key was used so we want to stop it from going to our Mac app
Ghostty.logger.debug("local key event handled event=\(event)") Ghostty.logger.debug("local key event handled event=\(event)")
return nil return nil
} }
return event return event
} }

View File

@ -667,12 +667,16 @@ fileprivate class WindowDragView: NSView {
// A view that matches the color of selected and unselected tabs in the adjacent tab bar. // A view that matches the color of selected and unselected tabs in the adjacent tab bar.
fileprivate class WindowButtonsBackdropView: NSView { fileprivate class WindowButtonsBackdropView: NSView {
private let terminalWindow: TerminalWindow // This must be weak because the window has this view. Otherwise
// a retain cycle occurs.
private weak var terminalWindow: TerminalWindow?
private let isLightTheme: Bool private let isLightTheme: Bool
private let overlayLayer = VibrantLayer() private let overlayLayer = VibrantLayer()
var isHighlighted: Bool = true { var isHighlighted: Bool = true {
didSet { didSet {
guard let terminalWindow else { return }
if isLightTheme { if isLightTheme {
overlayLayer.isHidden = isHighlighted overlayLayer.isHidden = isHighlighted
layer?.backgroundColor = .clear layer?.backgroundColor = .clear

View File

@ -209,20 +209,31 @@ pub const GPUState = struct {
} }
fn chooseDevice() error{NoMetalDevice}!objc.Object { fn chooseDevice() error{NoMetalDevice}!objc.Object {
const devices = objc.Object.fromId(mtl.MTLCopyAllDevices());
defer devices.release();
var chosen_device: ?objc.Object = null; var chosen_device: ?objc.Object = null;
var iter = devices.iterate();
while (iter.next()) |device| { switch (comptime builtin.os.tag) {
// We want a GPU thats connected to a display. .macos => {
if (device.getProperty(bool, "isHeadless")) continue; const devices = objc.Object.fromId(mtl.MTLCopyAllDevices());
chosen_device = device; defer devices.release();
// If the user has an eGPU plugged in, they probably want
// to use it. Otherwise, integrated GPUs are better for var iter = devices.iterate();
// battery life and thermals. while (iter.next()) |device| {
if (device.getProperty(bool, "isRemovable") or // We want a GPU thats connected to a display.
device.getProperty(bool, "isLowPower")) break; if (device.getProperty(bool, "isHeadless")) continue;
chosen_device = device;
// If the user has an eGPU plugged in, they probably want
// to use it. Otherwise, integrated GPUs are better for
// battery life and thermals.
if (device.getProperty(bool, "isRemovable") or
device.getProperty(bool, "isLowPower")) break;
}
},
.ios => {
chosen_device = objc.Object.fromId(mtl.MTLCreateSystemDefaultDevice());
},
else => @compileError("unsupported target for Metal"),
} }
const device = chosen_device orelse return error.NoMetalDevice; const device = chosen_device orelse return error.NoMetalDevice;
return device.retain(); return device.retain();
} }

View File

@ -175,4 +175,8 @@ pub const MTLSize = extern struct {
depth: c_ulong, depth: c_ulong,
}; };
/// https://developer.apple.com/documentation/metal/1433367-mtlcopyalldevices
pub extern "c" fn MTLCopyAllDevices() ?*anyopaque; pub extern "c" fn MTLCopyAllDevices() ?*anyopaque;
/// https://developer.apple.com/documentation/metal/1433401-mtlcreatesystemdefaultdevice
pub extern "c" fn MTLCreateSystemDefaultDevice() ?*anyopaque;