From b4859625bf0ff1f06e6a03e0f1fd55ccb7b9c170 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 24 Oct 2022 10:01:38 -0700 Subject: [PATCH] bring back out of focus no blink --- src/Window.zig | 17 ++++++----------- src/renderer/OpenGL.zig | 9 +++++++-- src/renderer/State.zig | 3 +++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index 5bf10b6aa..4067e3822 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -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 { diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index ddb189804..7ae9b8bea 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -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; diff --git a/src/renderer/State.zig b/src/renderer/State.zig index 2c3e6c36c..f03182f27 100644 --- a/src/renderer/State.zig +++ b/src/renderer/State.zig @@ -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,