From 762895bc45f852e2c2554ade23e4399496f12f53 Mon Sep 17 00:00:00 2001 From: Josh Engler Date: Fri, 3 Jun 2022 07:40:45 -0400 Subject: [PATCH 1/4] - Added EnumDisplaySettingsW and friends. - Added additional file access/security/sharing attributes --- core/sys/windows/types.odin | 87 ++++++++++++++++++++++++++++++++---- core/sys/windows/user32.odin | 2 + 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index a0649c5f3..2e04ec0f0 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -187,18 +187,33 @@ OPEN_ALWAYS: DWORD : 4 OPEN_EXISTING: DWORD : 3 TRUNCATE_EXISTING: DWORD : 5 +FILE_READ_DATA : DWORD : 0x00000001 +FILE_LIST_DIRECTORY : DWORD : 0x00000001 +FILE_WRITE_DATA : DWORD : 0x00000002 +FILE_ADD_FILE : DWORD : 0x00000002 +FILE_APPEND_DATA : DWORD : 0x00000004 +FILE_ADD_SUBDIRECTORY : DWORD : 0x00000004 +FILE_CREATE_PIPE_INSTANCE : DWORD : 0x00000004 +FILE_READ_EA : DWORD : 0x00000008 +FILE_WRITE_EA : DWORD : 0x00000010 +FILE_EXECUTE : DWORD : 0x00000020 +FILE_TRAVERSE : DWORD : 0x00000020 +FILE_DELETE_CHILD : DWORD : 0x00000040 +FILE_READ_ATTRIBUTES : DWORD : 0x00000080 +FILE_WRITE_ATTRIBUTES : DWORD : 0x00000100 - -FILE_WRITE_DATA: DWORD : 0x00000002 -FILE_APPEND_DATA: DWORD : 0x00000004 -FILE_WRITE_EA: DWORD : 0x00000010 -FILE_WRITE_ATTRIBUTES: DWORD : 0x00000100 -FILE_READ_ATTRIBUTES: DWORD : 0x000000080 READ_CONTROL: DWORD : 0x00020000 SYNCHRONIZE: DWORD : 0x00100000 -GENERIC_READ: DWORD : 0x80000000 -GENERIC_WRITE: DWORD : 0x40000000 -STANDARD_RIGHTS_WRITE: DWORD : READ_CONTROL + +GENERIC_READ : DWORD : 0x80000000 +GENERIC_WRITE : DWORD : 0x40000000 +GENERIC_EXECUTE : DWORD : 0x20000000 +GENERIC_ALL : DWORD : 0x10000000 + +STANDARD_RIGHTS_READ : DWORD : READ_CONTROL +STANDARD_RIGHTS_WRITE : DWORD : READ_CONTROL +STANDARD_RIGHTS_EXECUTE : DWORD : READ_CONTROL + FILE_GENERIC_WRITE: DWORD : STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | @@ -244,6 +259,9 @@ DIAGNOSTIC_REASON_SIMPLE_STRING :: 0x00000001 DIAGNOSTIC_REASON_DETAILED_STRING :: 0x00000002 DIAGNOSTIC_REASON_NOT_SPECIFIED :: 0x80000000 +ENUM_CURRENT_SETTINGS : DWORD : 4294967295 // (DWORD)-1 +ENUM_REGISTRY_SETTINGS : DWORD : 4294967294 // (DWORD)-2 + // Defines for power request APIs POWER_REQUEST_CONTEXT_VERSION :: DIAGNOSTIC_REASON_VERSION @@ -414,6 +432,57 @@ CREATESTRUCTW:: struct { dwExStyle: DWORD, } +DEVMODEW :: struct { + dmDeviceName: [32]wchar_t, + dmSpecVersion: WORD, + dmDriverVersion: WORD, + dmSize: WORD, + dmDriverExtra: WORD, + dmFields: DWORD, + using _: struct #raw_union { + // Printer only fields. + using _: struct { + dmOrientation: c_short, + dmPaperSize: c_short, + dmPaperLength: c_short, + dmPaperWidth: c_short, + dmScale: c_short, + dmCopies: c_short, + dmDefaultSource: c_short, + dmPrintQuality: c_short, + }, + // Display only fields. + using _: struct { + dmPosition: POINT, + dmDisplayOrientation: DWORD, + dmDisplayFixedOutput: DWORD, + }, + }, + dmColor: c_short, + dmDuplex: c_short, + dmYResolution: c_short, + dmTTOption: c_short, + dmCollate: c_short, + dmFormName: [32]wchar_t, + dmLogPixels: WORD, + dmBitsPerPel: DWORD, + dmPelsWidth: DWORD, + dmPelsHeight: DWORD, + using _: struct #raw_union { + dmDisplayFlags: DWORD, + dmNup: DWORD, + }, + dmDisplayFrequency: DWORD, + dmICMMethod: DWORD, + dmICMIntent: DWORD, + dmMediaType: DWORD, + dmDitherType: DWORD, + dmReserved1: DWORD, + dmReserved2: DWORD, + dmPanningWidth: DWORD, + dmPanningHeight: DWORD, +} + // MessageBox() Flags MB_OK :: 0x00000000 MB_OKCANCEL :: 0x00000001 diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 1b6d23ba4..4f31a2585 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -134,6 +134,8 @@ foreign user32 { GetCursorPos :: proc(lpPoint: LPPOINT) -> BOOL --- SetCursorPos :: proc(X: c_int, Y: c_int) -> BOOL --- SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR --- + + EnumDisplaySettingsW :: proc(lpszDeviceName: LPCWSTR, iModeNum: DWORD, lpDevMode: ^DEVMODEW) -> BOOL --- } CreateWindowW :: #force_inline proc "stdcall" ( From 50cbb8a1fce5fb25ee2076d85c43845e1fdfacbc Mon Sep 17 00:00:00 2001 From: Josh Engler Date: Sun, 12 Jun 2022 15:55:38 -0400 Subject: [PATCH 2/4] Fix tab spacing. --- core/sys/windows/types.odin | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 570969a78..ad2ab7b37 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -816,12 +816,12 @@ CREATESTRUCTW:: struct { } DEVMODEW :: struct { - dmDeviceName: [32]wchar_t, - dmSpecVersion: WORD, - dmDriverVersion: WORD, - dmSize: WORD, - dmDriverExtra: WORD, - dmFields: DWORD, + dmDeviceName: [32]wchar_t, + dmSpecVersion: WORD, + dmDriverVersion: WORD, + dmSize: WORD, + dmDriverExtra: WORD, + dmFields: DWORD, using _: struct #raw_union { // Printer only fields. using _: struct { @@ -841,29 +841,29 @@ DEVMODEW :: struct { dmDisplayFixedOutput: DWORD, }, }, - dmColor: c_short, - dmDuplex: c_short, - dmYResolution: c_short, - dmTTOption: c_short, - dmCollate: c_short, - dmFormName: [32]wchar_t, - dmLogPixels: WORD, - dmBitsPerPel: DWORD, - dmPelsWidth: DWORD, - dmPelsHeight: DWORD, + dmColor: c_short, + dmDuplex: c_short, + dmYResolution: c_short, + dmTTOption: c_short, + dmCollate: c_short, + dmFormName: [32]wchar_t, + dmLogPixels: WORD, + dmBitsPerPel: DWORD, + dmPelsWidth: DWORD, + dmPelsHeight: DWORD, using _: struct #raw_union { dmDisplayFlags: DWORD, dmNup: DWORD, }, - dmDisplayFrequency: DWORD, - dmICMMethod: DWORD, - dmICMIntent: DWORD, - dmMediaType: DWORD, - dmDitherType: DWORD, - dmReserved1: DWORD, - dmReserved2: DWORD, - dmPanningWidth: DWORD, - dmPanningHeight: DWORD, + dmDisplayFrequency: DWORD, + dmICMMethod: DWORD, + dmICMIntent: DWORD, + dmMediaType: DWORD, + dmDitherType: DWORD, + dmReserved1: DWORD, + dmReserved2: DWORD, + dmPanningWidth: DWORD, + dmPanningHeight: DWORD, } // MessageBox() Flags From e58f45bef789ab068656827b3b75f8cd817976e5 Mon Sep 17 00:00:00 2001 From: Peter DV Date: Mon, 27 Jun 2022 11:26:34 +1000 Subject: [PATCH 3/4] Correct error reporting --- core/os/file_windows.odin | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/core/os/file_windows.odin b/core/os/file_windows.odin index ca9beff5d..8019b0440 100644 --- a/core/os/file_windows.odin +++ b/core/os/file_windows.odin @@ -384,21 +384,33 @@ set_current_directory :: proc(path: string) -> (err: Errno) { -change_directory :: proc(path: string) -> Errno { +change_directory :: proc(path: string) -> (err: Errno) { wpath := win32.utf8_to_wstring(path, context.temp_allocator) - return Errno(win32.SetCurrentDirectoryW(wpath)) + + if !win32.SetCurrentDirectoryW(wpath) { + err = Errno(win32.GetLastError()) + } + return } -make_directory :: proc(path: string, mode: u32 = 0) -> Errno { +make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) { // Mode is unused on Windows, but is needed on *nix wpath := win32.utf8_to_wstring(path, context.temp_allocator) - return Errno(win32.CreateDirectoryW(wpath, nil)) + + if !win32.CreateDirectoryW(wpath, nil) { + err = Errno(win32.GetLastError()) + } + return } -remove_directory :: proc(path: string) -> Errno { +remove_directory :: proc(path: string) -> (err: Errno) { wpath := win32.utf8_to_wstring(path, context.temp_allocator) - return Errno(win32.RemoveDirectoryW(wpath)) + + if !win32.RemoveDirectoryW(wpath) { + err = Errno(win32.GetLastError()) + } + return } @@ -464,23 +476,31 @@ fix_long_path :: proc(path: string) -> string { } -link :: proc(old_name, new_name: string) -> Errno { +link :: proc(old_name, new_name: string) -> (err: Errno) { n := win32.utf8_to_wstring(fix_long_path(new_name)) o := win32.utf8_to_wstring(fix_long_path(old_name)) return Errno(win32.CreateHardLinkW(n, o, nil)) } -unlink :: proc(path: string) -> Errno { +unlink :: proc(path: string) -> (err: Errno) { wpath := win32.utf8_to_wstring(path, context.temp_allocator) - return Errno(win32.DeleteFileW(wpath)) + + if !win32.DeleteFileW(wpath) { + err = Errno(win32.GetLastError()) + } + return } -rename :: proc(old_path, new_path: string) -> Errno { +rename :: proc(old_path, new_path: string) -> (err: Errno) { from := win32.utf8_to_wstring(old_path, context.temp_allocator) to := win32.utf8_to_wstring(new_path, context.temp_allocator) - return Errno(win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING)) + + if !win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING) { + err = Errno(win32.GetLastError()) + } + return } From b313d09c2cebbe5da02dd9bccca40a5a67f50c3c Mon Sep 17 00:00:00 2001 From: Michael Kutowski Date: Tue, 28 Jun 2022 18:27:52 +0200 Subject: [PATCH 4/4] flux fixed key deletion and generic in `flux_to` --- core/math/ease/ease.odin | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/core/math/ease/ease.odin b/core/math/ease/ease.odin index 5a767b5a9..0bd7c3641 100644 --- a/core/math/ease/ease.odin +++ b/core/math/ease/ease.odin @@ -325,9 +325,9 @@ ease :: proc "contextless" (type: Ease, p: $T) -> T // in case type was invalid return 0 } - Flux_Map :: struct($T: typeid) { values: map[^T]Flux_Tween(T), + keys_to_be_deleted: [dynamic]^T, } Flux_Tween :: struct($T: typeid) { @@ -353,15 +353,17 @@ Flux_Tween :: struct($T: typeid) { } // init flux map to a float type and a wanted cap -flux_init :: proc($T: typeid, cap := 8) -> Flux_Map(T) where intrinsics.type_is_float(T) { +flux_init :: proc($T: typeid, value_capacity := 8) -> Flux_Map(T) where intrinsics.type_is_float(T) { return { - make(map[^T]Flux_Tween(T), cap), + values = make(map[^T]Flux_Tween(T), value_capacity), + keys_to_be_deleted = make([dynamic]^T, 0, value_capacity) } } // delete map content flux_destroy :: proc(flux: Flux_Map($T)) where intrinsics.type_is_float(T) { delete(flux.values) + delete(flux.keys_to_be_deleted) } // clear map content, stops all animations @@ -374,8 +376,8 @@ flux_clear :: proc(flux: ^Flux_Map($T)) where intrinsics.type_is_float(T) { // return value can be used to set callbacks flux_to :: proc( flux: ^Flux_Map($T), - value: ^f32, - goal: f32, + value: ^T, + goal: T, type: Ease = .Quadratic_Out, duration: time.Duration = time.Second, delay: f64 = 0, @@ -413,6 +415,8 @@ flux_tween_init :: proc(tween: ^Flux_Tween($T), duration: time.Duration) where i // calls callbacks in all stages, when they're filled // deletes tween from the map after completion flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float(T) { + clear(&flux.keys_to_be_deleted) + for key, tween in &flux.values { delay_remainder := f64(0) @@ -451,7 +455,8 @@ flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float } if tween.progress >= 1 { - delete_key(&flux.values, key) + // append keys to array that will be deleted after the loop + append(&flux.keys_to_be_deleted, key) if tween.on_complete != nil { tween.on_complete(flux, tween.data) @@ -459,17 +464,24 @@ flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float } } } + + // loop through keys that should be deleted from the map + if len(flux.keys_to_be_deleted) != 0 { + for key in flux.keys_to_be_deleted { + delete_key(&flux.values, key) + } + } } // stop a specific key inside the map // returns true when it successfully removed the key flux_stop :: proc(flux: ^Flux_Map($T), key: ^T) -> bool where intrinsics.type_is_float(T) { - if key in flux.values { - delete_key(&flux.values, key) - return true - } + if key in flux.values { + delete_key(&flux.values, key) + return true + } - return false + return false } // returns the amount of time left for the tween animation, if the key exists in the map