Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Askestad authored and Martin Askestad committed May 9, 2024
1 parent 7dc791f commit 58ab8c0
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 42 deletions.
106 changes: 95 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ log = "0.4.19"
serde = { version = "1.0.164", features = ["derive"] }
serde_yaml = "0.9.22"
simple-logging = "2.0.2"
windows = { version = "0.48.0", features = ["Win32_Foundation", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_Globalization", "Win32_Security", "Win32_System_Com", "Win32_System_LibraryLoader", "Win32_System_ProcessStatus", "Win32_System_Threading", "Win32_UI_Accessibility", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_UI_Controls", "Win32_System_Registry"] }
windows = { version = "0.54.0", features = ["Win32_Foundation", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_Globalization", "Win32_Security", "Win32_System_Com", "Win32_System_LibraryLoader", "Win32_System_ProcessStatus", "Win32_System_Threading", "Win32_UI_Accessibility", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_UI_Controls", "Win32_System_Registry"] }

[build-dependencies]
copy_to_output = "2.1.0"
Expand Down
10 changes: 5 additions & 5 deletions src/appwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{

use log::{debug, error, info};
use windows::{
w,
core::w,
Win32::{
Foundation::{HWND, LPARAM, LRESULT, WPARAM},
Foundation::{HINSTANCE, HWND, LPARAM, LRESULT, WPARAM},
Graphics::{
Dwm::{DWMWA_FORCE_ICONIC_REPRESENTATION, DWMWA_HAS_ICONIC_BITMAP},
Gdi::{BITMAPINFO, BITMAPINFOHEADER, COLOR_WINDOW, HBRUSH},
Expand Down Expand Up @@ -51,12 +51,12 @@ pub struct AppWindow {

impl AppWindow {
pub fn new_window(wm: &mut WindowManager) -> Result<Self> {
let instance = get_module_handle()?;
let instance: HINSTANCE = get_module_handle()?.into();
let window_class = w!("grout-wm.window");
let wc = WNDCLASSW {
hInstance: instance,
lpszClassName: window_class,
hIcon: load_icon(instance, w!("appicon"))?,
hIcon: load_icon(instance.into(), w!("appicon"))?,
hbrBackground: HBRUSH((COLOR_WINDOW.0 + 1) as isize),
lpfnWndProc: Some(Self::wnd_proc),
..Default::default()
Expand Down Expand Up @@ -258,7 +258,7 @@ impl AppWindow {
_ => event,
};
if msg >= WM_USER || msg < WM_APP {
win32::post_message(my_hwnd, msg, WPARAM(0), LPARAM(hwnd.0));
let _ = win32::post_message(my_hwnd, msg, WPARAM(0), LPARAM(hwnd.0));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/win32/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Win32Com {
use windows::Win32::System::Com::CoInitialize;
info!("Initialize COM");
unsafe {
CoInitialize(None)?;
let _ = CoInitialize(None);
}
Ok(Win32Com)
}
Expand Down
2 changes: 1 addition & 1 deletion src/win32/dwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn get_window_extended_frame_bounds(hwnd: HWND) -> RECT {
let mut rect: RECT = unsafe { zeroed() };
let mut frame: RECT = unsafe { zeroed() };
unsafe {
GetWindowRect(hwnd, &mut rect);
let _ = GetWindowRect(hwnd, &mut rect);
let _ = DwmGetWindowAttribute(
hwnd,
DWMWA_EXTENDED_FRAME_BOUNDS,
Expand Down
48 changes: 31 additions & 17 deletions src/win32/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use log::{error};
use std::{
ffi::c_void,
mem::{size_of, zeroed},
path::PathBuf,
};

use windows::{
core::PCWSTR,
w,
core::{w, PCWSTR},
Win32::{
Foundation::{
CloseHandle, GetLastError, BOOL, ERROR_ALREADY_EXISTS, FALSE, HANDLE, HMODULE, HWND,
LPARAM, LRESULT, MAX_PATH, POINT, RECT, TRUE, WPARAM,
CloseHandle, GetLastError, ERROR_ALREADY_EXISTS, FALSE, HANDLE, HMODULE, HWND, LPARAM,
LRESULT, MAX_PATH, POINT, RECT, TRUE, WPARAM,
},
Graphics::Gdi::PtInRect,
System::{
Expand Down Expand Up @@ -71,7 +71,10 @@ pub fn defer_window_pos(hdwp: HDWP, hwnd: HWND, rect: RECT) -> Result<HDWP> {
}

pub fn end_defer_window_pos(hdwp: HDWP) {
unsafe { EndDeferWindowPos(hdwp) };
let res = unsafe { EndDeferWindowPos(hdwp) };
if res.is_err() {
error!("EndDeferWindowPos failed: {:?}", res);
}
}

pub fn is_iconic(hwnd: HWND) -> bool {
Expand Down Expand Up @@ -111,7 +114,7 @@ pub fn get_working_area() -> Result<RECT> {
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),
)
};
if res == FALSE {
if res.is_err() {
return Err("".into());
}
Ok(wa)
Expand Down Expand Up @@ -160,7 +163,7 @@ pub fn show_window(hwnd: HWND) -> bool {
}

pub fn enum_windows(cb: WNDENUMPROC, param: LPARAM) -> bool {
unsafe { EnumWindows(cb, param).into() }
unsafe { EnumWindows(cb, param).is_ok() }
}

pub fn get_window_text(hwnd: HWND) -> String {
Expand Down Expand Up @@ -192,7 +195,8 @@ pub fn get_exe_filename(hwnd: HWND) -> Option<String> {
module_handles.as_mut_ptr(),
(module_handles.len() * size_of::<HMODULE>()) as u32,
&mut module_handles_size,
) == FALSE
)
.is_err()
{
return None;
}
Expand All @@ -203,7 +207,8 @@ pub fn get_exe_filename(hwnd: HWND) -> Option<String> {
module_handle,
&mut module_info,
size_of::<MODULEINFO>().try_into().unwrap(),
) == FALSE
)
.is_err()
{
return None;
}
Expand All @@ -213,7 +218,10 @@ pub fn get_exe_filename(hwnd: HWND) -> Option<String> {
if base_name_length == 0 {
return None;
}
CloseHandle(process_handle);
let res = CloseHandle(process_handle);
if res.is_err() {
error!("Failed to close process handle: {}", res.unwrap_err());
}
Some(String::from_utf16_lossy(
&module_base_name[..base_name_length as usize],
))
Expand All @@ -231,8 +239,9 @@ pub fn post_quit_message(msg: i32) {
unsafe { PostQuitMessage(msg) }
}

pub fn post_message(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> BOOL {
unsafe { PostMessageW(hwnd, msg, wparam, lparam) }
pub fn post_message(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
unsafe { PostMessageW(hwnd, msg, wparam, lparam).unwrap() };
Ok(())
}

pub fn get_mutex() -> Result<HANDLE> {
Expand All @@ -246,9 +255,13 @@ pub fn get_mutex() -> Result<HANDLE> {
}

pub fn release_mutex(handle: HANDLE) {
unsafe {
ReleaseMutex(handle);
CloseHandle(handle);
let mutex_res = unsafe { ReleaseMutex(handle) };
if mutex_res.is_err() {
error!("ReleaseMutex failed: {:?}", mutex_res);
}
let handle_res = unsafe { CloseHandle(handle) };
if handle_res.is_err() {
error!("CloseHandle failed: {:?}", handle_res);
}
}

Expand All @@ -271,8 +284,9 @@ pub fn get_local_appdata_path() -> Result<PathBuf> {

pub fn get_cursor_pos() -> POINT {
let mut p: POINT = unsafe { zeroed() };
unsafe {
GetCursorPos(&mut p);
let res = unsafe { GetCursorPos(&mut p) };
if res.is_err() {
error!("GetCursorPos failed: {:?}", res);
}
p
}
Expand Down
2 changes: 1 addition & 1 deletion src/win32/theme.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use windows::{
w,
core::w,
Win32::{
Foundation::{ERROR_FILE_NOT_FOUND, ERROR_SUCCESS},
System::Registry::{RegGetValueW, HKEY_CURRENT_USER, REG_VALUE_TYPE, RRF_RT_REG_DWORD},
Expand Down
11 changes: 6 additions & 5 deletions src/window.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::win32;
use core::fmt;

use log::error;
use windows::Win32::Foundation::HWND;

use crate::win32;

#[derive(Clone, Copy)]
pub struct Window(pub HWND);

Expand Down Expand Up @@ -38,8 +37,10 @@ impl Window {

pub fn position(&self) -> windows::Win32::Foundation::RECT {
let mut rect: windows::Win32::Foundation::RECT = unsafe { std::mem::zeroed() };
unsafe {
windows::Win32::UI::WindowsAndMessaging::GetWindowRect(self.0, &mut rect);
let res =
unsafe { windows::Win32::UI::WindowsAndMessaging::GetWindowRect(self.0, &mut rect) };
if res.is_err() {
error!("GetWindowRect failed: {:?}", res);
}
rect
}
Expand Down

0 comments on commit 58ab8c0

Please sign in to comment.