mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
hook up all the keyboard actions
This commit is contained in:
@ -49,6 +49,7 @@ app: *App,
|
||||
/// The font structures
|
||||
font_lib: font.Library,
|
||||
font_group: *font.GroupCache,
|
||||
font_size: font.face.DesiredSize,
|
||||
|
||||
/// The glfw window handle.
|
||||
window: glfw.Window,
|
||||
@ -361,6 +362,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
|
||||
.app = app,
|
||||
.font_lib = font_lib,
|
||||
.font_group = font_group,
|
||||
.font_size = font_size,
|
||||
.window = window,
|
||||
.cursor = cursor,
|
||||
.renderer = renderer_impl,
|
||||
@ -555,6 +557,20 @@ fn setCellSize(self: *Window, size: renderer.CellSize) !void {
|
||||
self.io_thread.wakeup.send() catch {};
|
||||
}
|
||||
|
||||
/// Change the font size.
|
||||
fn setFontSize(self: *Window, size: font.face.DesiredSize) void {
|
||||
// Update our font size so future changes work
|
||||
self.font_size = size;
|
||||
|
||||
// Notify our render thread of the font size. This triggers everything else.
|
||||
_ = self.renderer_thread.mailbox.push(.{
|
||||
.font_size = size,
|
||||
}, .{ .forever = {} });
|
||||
|
||||
// Schedule render which also drains our mailbox
|
||||
self.queueRender() catch unreachable;
|
||||
}
|
||||
|
||||
/// This queues a render operation with the renderer thread. The render
|
||||
/// isn't guaranteed to happen immediately but it will happen as soon as
|
||||
/// practical.
|
||||
@ -760,6 +776,16 @@ fn keyCallback(
|
||||
.x => .x,
|
||||
.y => .y,
|
||||
.z => .z,
|
||||
.zero => .zero,
|
||||
.one => .one,
|
||||
.two => .three,
|
||||
.three => .four,
|
||||
.four => .four,
|
||||
.five => .five,
|
||||
.six => .six,
|
||||
.seven => .seven,
|
||||
.eight => .eight,
|
||||
.nine => .nine,
|
||||
.up => .up,
|
||||
.down => .down,
|
||||
.right => .right,
|
||||
@ -782,6 +808,8 @@ fn keyCallback(
|
||||
.F11 => .f11,
|
||||
.F12 => .f12,
|
||||
.grave_accent => .grave_accent,
|
||||
.minus => .minus,
|
||||
.equal => .equal,
|
||||
else => .invalid,
|
||||
},
|
||||
};
|
||||
@ -858,6 +886,30 @@ fn keyCallback(
|
||||
}
|
||||
},
|
||||
|
||||
.increase_font_size => |delta| {
|
||||
log.debug("increase font size={}", .{delta});
|
||||
|
||||
var size = win.font_size;
|
||||
size.points +|= delta;
|
||||
win.setFontSize(size);
|
||||
},
|
||||
|
||||
.decrease_font_size => |delta| {
|
||||
log.debug("decrease font size={}", .{delta});
|
||||
|
||||
var size = win.font_size;
|
||||
size.points = @max(1, size.points -| delta);
|
||||
win.setFontSize(size);
|
||||
},
|
||||
|
||||
.reset_font_size => {
|
||||
log.debug("reset font size", .{});
|
||||
|
||||
var size = win.font_size;
|
||||
size.points = win.config.@"font-size";
|
||||
win.setFontSize(size);
|
||||
},
|
||||
|
||||
.toggle_dev_mode => if (DevMode.enabled) {
|
||||
DevMode.instance.visible = !DevMode.instance.visible;
|
||||
win.queueRender() catch unreachable;
|
||||
|
@ -176,6 +176,23 @@ pub const Config = struct {
|
||||
try result.keybind.set.put(alloc, .{ .key = .f11 }, .{ .csi = "23~" });
|
||||
try result.keybind.set.put(alloc, .{ .key = .f12 }, .{ .csi = "24~" });
|
||||
|
||||
// Fonts
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .equal, .mods = .{ .super = true } },
|
||||
.{ .increase_font_size = 1 },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .minus, .mods = .{ .super = true } },
|
||||
.{ .decrease_font_size = 1 },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .zero, .mods = .{ .super = true } },
|
||||
.{ .reset_font_size = {} },
|
||||
);
|
||||
|
||||
// Dev Mode
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
|
@ -131,6 +131,13 @@ pub const Action = union(enum) {
|
||||
copy_to_clipboard: void,
|
||||
paste_from_clipboard: void,
|
||||
|
||||
/// Increase/decrease the font size by a certain amount
|
||||
increase_font_size: u16,
|
||||
decrease_font_size: u16,
|
||||
|
||||
/// Reset the font size to the original configured size
|
||||
reset_font_size: void,
|
||||
|
||||
/// Dev mode
|
||||
toggle_dev_mode: void,
|
||||
|
||||
|
@ -49,8 +49,22 @@ pub const Key = enum {
|
||||
y,
|
||||
z,
|
||||
|
||||
// numbers
|
||||
zero,
|
||||
one,
|
||||
two,
|
||||
three,
|
||||
four,
|
||||
five,
|
||||
six,
|
||||
seven,
|
||||
eight,
|
||||
nine,
|
||||
|
||||
// other
|
||||
grave_accent, // `
|
||||
minus,
|
||||
equal,
|
||||
|
||||
// control
|
||||
up,
|
||||
|
@ -320,6 +320,9 @@ pub fn deinit(self: *OpenGL) void {
|
||||
}
|
||||
|
||||
fn resetCellsLRU(self: *OpenGL) void {
|
||||
// Preserve the old capacity so that we have space in our LRU
|
||||
const cap = self.cells_lru.capacity;
|
||||
|
||||
// Our LRU values are array lists so we need to deallocate those first
|
||||
var it = self.cells_lru.queue.first;
|
||||
while (it) |node| {
|
||||
@ -329,7 +332,7 @@ fn resetCellsLRU(self: *OpenGL) void {
|
||||
self.cells_lru.deinit(self.alloc);
|
||||
|
||||
// Initialize our new LRU
|
||||
self.cells_lru = CellsLRU.init(0);
|
||||
self.cells_lru = CellsLRU.init(cap);
|
||||
}
|
||||
|
||||
/// Returns the hints that we want for this
|
||||
@ -468,6 +471,8 @@ pub fn blinkCursor(self: *OpenGL, reset: bool) void {
|
||||
///
|
||||
/// Must be called on the render thread.
|
||||
pub fn setFontSize(self: *OpenGL, size: font.face.DesiredSize) !void {
|
||||
log.info("set font size={}", .{size});
|
||||
|
||||
// Set our new size, this will also reset our font atlas.
|
||||
try self.font_group.setSize(size);
|
||||
|
||||
|
Reference in New Issue
Block a user