Focus event

This commit is contained in:
2026-01-26 20:42:30 +01:00
parent 11fc1b5b4b
commit 6d35cfe3a2
2 changed files with 98 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
#+private
package window
import "core:container/queue"
@@ -36,6 +37,13 @@ Backend_Info :: struct {
event_queue := get_event_queue(hwnd)
switch(msg) {
case win.WM_CREATE: return wm_create(hwnd, lparam)
case win.WM_SETFOCUS, win.WM_KILLFOCUS: {
if event_queue != nil {
queue.push_back(event_queue, Event_Focus {
is_focused = msg == win.WM_SETFOCUS
})
}
}
case win.WM_KEYDOWN, win.WM_SYSKEYDOWN: {
input_event: Event_Input = Event_Keyboard {
virtual_key = get_virtual_key_windows(i32(wparam)),
@@ -129,7 +137,7 @@ Backend_Info :: struct {
}
return 0
}
}
WINDOW_CLASS_NAME :: "ENSENN_WINDOW"
@@ -192,6 +200,48 @@ set_title_windows :: proc(window: ^Window) {
win.SetWindowTextW(window.backend.hwnd, win.utf8_to_wstring(window.title))
}
show_cursor_window :: proc(window: ^Window, show: bool) {
assert(window != nil)
if show == cursor_visible_windows(window) {
if show {
fmt.printfln("Tried to show cursor but it's already visible.")
}
else {
fmt.printfln("Tried to hide cursor but it's already not visible.")
}
return
}
for { // Win32 :)))
counter := win.ShowCursor(show ? win.TRUE : win.FALSE)
if (show && counter >= 0) || (!show && counter < 0) {
break
}
}
win.ShowCursor(show ? win.TRUE : win.FALSE)
}
cursor_visible_windows :: proc(window: ^Window) -> bool {
old_count := win.ShowCursor(win.TRUE)
win.ShowCursor(win.FALSE)
return old_count >= 0
}
set_cursor_position_windows :: proc(window: ^Window, pos: [2]u32) {
pt := win.POINT { x = i32(pos.x), y = i32(pos.y) }
rect: win.RECT
win.GetClientRect(window.backend.hwnd, &rect)
ok := win.ClientToScreen(window.backend.hwnd, &pt)
if !ok {
return
}
win.SetCursorPos(pt.x, pt.y)
}
update_windows :: proc(window: ^Window) {
assert(window != nil)