bring back out of focus no blink

This commit is contained in:
Mitchell Hashimoto
2022-10-24 10:01:38 -07:00
parent dc908cb73d
commit b4859625bf
3 changed files with 16 additions and 13 deletions

View File

@ -50,9 +50,6 @@ cursor: glfw.Cursor,
/// Imgui context
imgui_ctx: if (DevMode.enabled) *imgui.Context else void,
/// Whether the window is currently focused
focused: bool,
/// The renderer for this window.
renderer: renderer.OpenGL,
@ -481,11 +478,11 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
.font_group = font_group,
.window = window,
.cursor = cursor,
.focused = false,
.renderer = renderer_impl,
.renderer_thread = render_thread,
.renderer_state = .{
.mutex = mutex,
.focused = false,
.resize_screen = screen_size,
.cursor = .{
.style = .blinking_block,
@ -1004,22 +1001,20 @@ fn focusCallback(window: glfw.Window, focused: bool) void {
const win = window.getUserPointer(Window) orelse return;
// If we aren't changing focus state, do nothing. I don't think this
// can happen but it costs very little to check.
if (win.focused == focused) return;
// We have to schedule a render because no matter what we're changing
// the cursor. If we're focused its reappearing, if we're not then
// its changing to hollow and not blinking.
win.render_timer.schedule() catch unreachable;
// Set our focused state on the window.
win.focused = focused;
if (focused)
win.terminal_cursor.startTimer() catch unreachable
else
win.terminal_cursor.stopTimer() catch unreachable;
// We are modifying renderer state from here on out
win.renderer_state.mutex.lock();
defer win.renderer_state.mutex.unlock();
win.renderer_state.focused = focused;
}
fn refreshCallback(window: glfw.Window) void {

View File

@ -378,8 +378,13 @@ pub fn render(
defer state.resize_screen = null;
// Setup our cursor state
self.cursor_visible = state.cursor.visible and !state.cursor.blink;
self.cursor_style = CursorStyle.fromTerminal(state.cursor.style) orelse .box;
if (state.focused) {
self.cursor_visible = state.cursor.visible and !state.cursor.blink;
self.cursor_style = CursorStyle.fromTerminal(state.cursor.style) orelse .box;
} else {
self.cursor_visible = true;
self.cursor_style = .box_hollow;
}
// Swap bg/fg if the terminal is reversed
const bg = self.background;

View File

@ -11,6 +11,9 @@ const renderer = @import("../renderer.zig");
/// state (i.e. the terminal, devmode, etc. values).
mutex: *std.Thread.Mutex,
/// True if the window is focused
focused: bool,
/// A new screen size if the screen was resized.
resize_screen: ?renderer.ScreenSize,