mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
hook up all the keyboard actions
This commit is contained in:
@ -49,6 +49,7 @@ app: *App,
|
|||||||
/// The font structures
|
/// The font structures
|
||||||
font_lib: font.Library,
|
font_lib: font.Library,
|
||||||
font_group: *font.GroupCache,
|
font_group: *font.GroupCache,
|
||||||
|
font_size: font.face.DesiredSize,
|
||||||
|
|
||||||
/// The glfw window handle.
|
/// The glfw window handle.
|
||||||
window: glfw.Window,
|
window: glfw.Window,
|
||||||
@ -361,6 +362,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
|
|||||||
.app = app,
|
.app = app,
|
||||||
.font_lib = font_lib,
|
.font_lib = font_lib,
|
||||||
.font_group = font_group,
|
.font_group = font_group,
|
||||||
|
.font_size = font_size,
|
||||||
.window = window,
|
.window = window,
|
||||||
.cursor = cursor,
|
.cursor = cursor,
|
||||||
.renderer = renderer_impl,
|
.renderer = renderer_impl,
|
||||||
@ -555,6 +557,20 @@ fn setCellSize(self: *Window, size: renderer.CellSize) !void {
|
|||||||
self.io_thread.wakeup.send() catch {};
|
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
|
/// This queues a render operation with the renderer thread. The render
|
||||||
/// isn't guaranteed to happen immediately but it will happen as soon as
|
/// isn't guaranteed to happen immediately but it will happen as soon as
|
||||||
/// practical.
|
/// practical.
|
||||||
@ -760,6 +776,16 @@ fn keyCallback(
|
|||||||
.x => .x,
|
.x => .x,
|
||||||
.y => .y,
|
.y => .y,
|
||||||
.z => .z,
|
.z => .z,
|
||||||
|
.zero => .zero,
|
||||||
|
.one => .one,
|
||||||
|
.two => .three,
|
||||||
|
.three => .four,
|
||||||
|
.four => .four,
|
||||||
|
.five => .five,
|
||||||
|
.six => .six,
|
||||||
|
.seven => .seven,
|
||||||
|
.eight => .eight,
|
||||||
|
.nine => .nine,
|
||||||
.up => .up,
|
.up => .up,
|
||||||
.down => .down,
|
.down => .down,
|
||||||
.right => .right,
|
.right => .right,
|
||||||
@ -782,6 +808,8 @@ fn keyCallback(
|
|||||||
.F11 => .f11,
|
.F11 => .f11,
|
||||||
.F12 => .f12,
|
.F12 => .f12,
|
||||||
.grave_accent => .grave_accent,
|
.grave_accent => .grave_accent,
|
||||||
|
.minus => .minus,
|
||||||
|
.equal => .equal,
|
||||||
else => .invalid,
|
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) {
|
.toggle_dev_mode => if (DevMode.enabled) {
|
||||||
DevMode.instance.visible = !DevMode.instance.visible;
|
DevMode.instance.visible = !DevMode.instance.visible;
|
||||||
win.queueRender() catch unreachable;
|
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 = .f11 }, .{ .csi = "23~" });
|
||||||
try result.keybind.set.put(alloc, .{ .key = .f12 }, .{ .csi = "24~" });
|
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
|
// Dev Mode
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
|
@ -131,6 +131,13 @@ pub const Action = union(enum) {
|
|||||||
copy_to_clipboard: void,
|
copy_to_clipboard: void,
|
||||||
paste_from_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
|
/// Dev mode
|
||||||
toggle_dev_mode: void,
|
toggle_dev_mode: void,
|
||||||
|
|
||||||
|
@ -49,8 +49,22 @@ pub const Key = enum {
|
|||||||
y,
|
y,
|
||||||
z,
|
z,
|
||||||
|
|
||||||
|
// numbers
|
||||||
|
zero,
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
three,
|
||||||
|
four,
|
||||||
|
five,
|
||||||
|
six,
|
||||||
|
seven,
|
||||||
|
eight,
|
||||||
|
nine,
|
||||||
|
|
||||||
// other
|
// other
|
||||||
grave_accent, // `
|
grave_accent, // `
|
||||||
|
minus,
|
||||||
|
equal,
|
||||||
|
|
||||||
// control
|
// control
|
||||||
up,
|
up,
|
||||||
|
@ -320,6 +320,9 @@ pub fn deinit(self: *OpenGL) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn resetCellsLRU(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
|
// Our LRU values are array lists so we need to deallocate those first
|
||||||
var it = self.cells_lru.queue.first;
|
var it = self.cells_lru.queue.first;
|
||||||
while (it) |node| {
|
while (it) |node| {
|
||||||
@ -329,7 +332,7 @@ fn resetCellsLRU(self: *OpenGL) void {
|
|||||||
self.cells_lru.deinit(self.alloc);
|
self.cells_lru.deinit(self.alloc);
|
||||||
|
|
||||||
// Initialize our new LRU
|
// Initialize our new LRU
|
||||||
self.cells_lru = CellsLRU.init(0);
|
self.cells_lru = CellsLRU.init(cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the hints that we want for this
|
/// 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.
|
/// Must be called on the render thread.
|
||||||
pub fn setFontSize(self: *OpenGL, size: font.face.DesiredSize) !void {
|
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.
|
// Set our new size, this will also reset our font atlas.
|
||||||
try self.font_group.setSize(size);
|
try self.font_group.setSize(size);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user