when losing focus, show hollow box

This commit is contained in:
Mitchell Hashimoto
2022-04-22 21:58:15 -07:00
parent 7169679654
commit bd7855da46
4 changed files with 89 additions and 3 deletions

View File

@@ -37,6 +37,12 @@ font_atlas: FontAtlas,
/// Whether the cursor is visible or not. This is used to control cursor
/// blinking.
cursor_visible: bool,
cursor_style: CursorStyle,
const CursorStyle = enum(u8) {
box = 3,
box_hollow = 4,
};
/// The raw structure that maps directly to the buffer sent to the vertex shader.
const GPUCell = struct {
@@ -211,6 +217,7 @@ pub fn init(alloc: Allocator) !Grid {
.texture = tex,
.font_atlas = font,
.cursor_visible = true,
.cursor_style = .box,
};
}
@@ -295,7 +302,7 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
// Draw the cursor
if (self.cursor_visible) {
self.cells.appendAssumeCapacity(.{
.mode = 1,
.mode = @enumToInt(self.cursor_style),
.grid_col = @intCast(u16, term.cursor.x),
.grid_row = @intCast(u16, term.cursor.y),
.fg_r = 0,

View File

@@ -221,10 +221,13 @@ fn keyCallback(
fn focusCallback(window: glfw.Window, focused: bool) void {
const win = window.getUserPointer(Window) orelse return;
if (focused) {
win.cursor_timer.start(cursorTimerCallback, 800, 800) catch unreachable;
win.wakeup = true;
} else {
win.cursor_timer.start(cursorTimerCallback, 0, 800) catch unreachable;
win.grid.cursor_style = .box;
win.grid.cursor_visible = false;
} else {
win.grid.cursor_visible = true;
win.grid.cursor_style = .box_hollow;
win.grid.updateCells(win.terminal) catch unreachable;
win.cursor_timer.stop() catch unreachable;
}