Skip to content

Commit

Permalink
chore(deps): bump windows crates from 0.48 to 0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Sep 12, 2023
1 parent 0088ca8 commit 4591274
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 deletions.
72 changes: 41 additions & 31 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ members = [
]

[workspace.dependencies]
windows-interface = { version = "0.48" }
windows-implement = { version = "0.48" }
windows-interface = { version = "0.51" }
windows-implement = { version = "0.51" }

[workspace.dependencies.windows]
version = "0.48"
version = "0.51"
features = [
"implement",
"Win32_System_Com",
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Border {
let class_name = PCSTR(name.as_ptr());
let brush = WindowsApi::create_solid_brush(TRANSPARENCY_COLOUR);
let window_class = WNDCLASSA {
hInstance: instance,
hInstance: instance.into(),
lpszClassName: class_name,
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(windows_callbacks::border_window),
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Hidden {
let class_name = PCSTR(name.as_ptr());
let brush = WindowsApi::create_solid_brush(TRANSPARENCY_COLOUR);
let window_class = WNDCLASSA {
hInstance: instance,
hInstance: instance.into(),
lpszClassName: class_name,
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(windows_callbacks::hidden_window),
Expand Down
3 changes: 1 addition & 2 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ impl Window {
let mut ex_style = self.ex_style()?;
ex_style.insert(ExtendedWindowStyle::LAYERED);
self.update_ex_style(&ex_style)?;
WindowsApi::set_transparent(self.hwnd());
Ok(())
WindowsApi::set_transparent(self.hwnd())
}

pub fn opaque(self) -> Result<()> {
Expand Down
27 changes: 11 additions & 16 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ impl WindowsApi {

pub fn enum_windows(callback: WNDENUMPROC, callback_data_address: isize) -> Result<()> {
unsafe { EnumWindows(callback, LPARAM(callback_data_address)) }
.ok()
.process()
}

Expand Down Expand Up @@ -276,7 +275,6 @@ impl WindowsApi {

pub fn allow_set_foreground_window(process_id: u32) -> Result<()> {
unsafe { AllowSetForegroundWindow(process_id) }
.ok()
.process()
}

Expand Down Expand Up @@ -313,7 +311,7 @@ impl WindowsApi {
}

pub fn bring_window_to_top(hwnd: HWND) -> Result<()> {
unsafe { BringWindowToTop(hwnd) }.ok().process()
unsafe { BringWindowToTop(hwnd) }.process()
}

pub fn raise_window(hwnd: HWND) -> Result<()> {
Expand Down Expand Up @@ -353,7 +351,6 @@ impl WindowsApi {
SET_WINDOW_POS_FLAGS(flags),
)
}
.ok()
.process()
}

Expand All @@ -369,7 +366,6 @@ impl WindowsApi {

fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
unsafe { PostMessageW(hwnd, message, wparam, lparam) }
.ok()
.process()
}

Expand Down Expand Up @@ -436,18 +432,18 @@ impl WindowsApi {

pub fn window_rect(hwnd: HWND) -> Result<Rect> {
let mut rect = unsafe { std::mem::zeroed() };
unsafe { GetWindowRect(hwnd, &mut rect) }.ok().process()?;
unsafe { GetWindowRect(hwnd, &mut rect) }.process()?;

Ok(Rect::from(rect))
}

fn set_cursor_pos(x: i32, y: i32) -> Result<()> {
unsafe { SetCursorPos(x, y) }.ok().process()
unsafe { SetCursorPos(x, y) }.process()
}

pub fn cursor_pos() -> Result<POINT> {
let mut cursor_pos = POINT::default();
unsafe { GetCursorPos(&mut cursor_pos) }.ok().process()?;
unsafe { GetCursorPos(&mut cursor_pos) }.process()?;

Ok(cursor_pos)
}
Expand Down Expand Up @@ -489,7 +485,7 @@ impl WindowsApi {
let mut session_id = 0;

unsafe {
if ProcessIdToSessionId(process_id, &mut session_id).as_bool() {
if ProcessIdToSessionId(process_id, &mut session_id).is_ok() {
Ok(session_id)
} else {
Err(anyhow!("could not determine current session id"))
Expand Down Expand Up @@ -565,7 +561,7 @@ impl WindowsApi {
}

pub fn close_process(handle: HANDLE) -> Result<()> {
unsafe { CloseHandle(handle) }.ok().process()
unsafe { CloseHandle(handle) }.process()
}

pub fn process_handle(process_id: u32) -> Result<HANDLE> {
Expand All @@ -580,7 +576,6 @@ impl WindowsApi {
unsafe {
QueryFullProcessImageNameW(handle, PROCESS_NAME_WIN32, PWSTR(text_ptr), &mut len)
}
.ok()
.process()?;

Ok(String::from_utf16(&path[..len as usize])?)
Expand Down Expand Up @@ -673,7 +668,6 @@ impl WindowsApi {

pub fn set_process_dpi_awareness_context() -> Result<()> {
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) }
.ok()
.process()
}

Expand All @@ -685,7 +679,6 @@ impl WindowsApi {
update_flags: SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS,
) -> Result<()> {
unsafe { SystemParametersInfoW(action, ui_param, Option::from(pv_param), update_flags) }
.ok()
.process()
}

Expand Down Expand Up @@ -777,19 +770,21 @@ impl WindowsApi {
None,
);

SetLayeredWindowAttributes(hwnd, COLORREF(TRANSPARENCY_COLOUR), 0, LWA_COLORKEY);
SetLayeredWindowAttributes(hwnd, COLORREF(TRANSPARENCY_COLOUR), 0, LWA_COLORKEY)?;

hwnd
}
.process()
}

pub fn set_transparent(hwnd: HWND) {
pub fn set_transparent(hwnd: HWND) -> Result<()> {
unsafe {
#[allow(clippy::cast_sign_loss)]
// TODO: alpha should be configurable
SetLayeredWindowAttributes(hwnd, COLORREF(-1i32 as u32), 150, LWA_ALPHA);
SetLayeredWindowAttributes(hwnd, COLORREF(-1i32 as u32), 150, LWA_ALPHA)?;
}

Ok(())
}

pub fn create_hidden_window(name: PCSTR, instance: HMODULE) -> Result<isize> {
Expand Down

0 comments on commit 4591274

Please sign in to comment.