Skip to content

Commit

Permalink
chore(deps): bump windows-rs from 0.57 to 0.58
Browse files Browse the repository at this point in the history
Not a huge fan of these updates in the windows-rs crate which swap the
isize values which were previously wrapped in various handles with *mut
core::ffi:c_void pointers.

In order to at least keep this codebase sane, all of the wrapper
functions exposed in WindowsApi now take isize wherever they previously
took HWND, HMONITOR, HINSTANCE etc.

Going forward any pub fn in WindowsApi should prefer isize over Windows
handles which wrap c_void pointers.
  • Loading branch information
LGUG2Z committed Sep 26, 2024
1 parent 167ec92 commit ddb600f
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 210 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
paste = "1"
sysinfo = "0.31"
uds_windows = "1"
win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "790d56567bd15b4ba3d49ed1ac9701ede6fab4a3" }
windows-implement = { version = "0.57" }
windows-interface = { version = "0.57" }
windows-core = { version = "0.57" }
win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "dd65e3f22d0521b78fcddde11abc2a3e9dcc32a8" }
windows-implement = { version = "0.58" }
windows-interface = { version = "0.58" }
windows-core = { version = "0.58" }
shadow-rs = "0.35"
which = "6"

[workspace.dependencies.windows]
version = "0.57"
version = "0.58"
features = [
"implement",
"Win32_System_Com",
Expand Down
2 changes: 1 addition & 1 deletion komorebi-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ extern "system" fn enum_window(
lparam: windows::Win32::Foundation::LPARAM,
) -> windows::Win32::Foundation::BOOL {
let windows = unsafe { &mut *(lparam.0 as *mut Vec<Window>) };
let window = Window::from(hwnd.0);
let window = Window::from(hwnd.0 as isize);

if window.is_window()
&& !window.is_miminized()
Expand Down
19 changes: 11 additions & 8 deletions komorebi/src/border_manager/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::border_manager::BORDER_WIDTH;
use crate::border_manager::FOCUS_STATE;
use crate::border_manager::STYLE;
use crate::border_manager::Z_ORDER;
use crate::windows_api;
use crate::WindowsApi;
use crate::WINDOWS_11;

Expand Down Expand Up @@ -46,10 +47,11 @@ use windows::Win32::UI::WindowsAndMessaging::WNDCLASSW;

pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
let hwnds = unsafe { &mut *(lparam.0 as *mut Vec<isize>) };
let hwnd = hwnd.0 as isize;

if let Ok(class) = WindowsApi::real_window_class_w(hwnd) {
if class.starts_with("komoborder") {
hwnds.push(hwnd.0);
hwnds.push(hwnd);
}
}

Expand All @@ -69,7 +71,7 @@ impl From<isize> for Border {

impl Border {
pub const fn hwnd(&self) -> HWND {
HWND(self.hwnd)
HWND(windows_api::as_ptr!(self.hwnd))
}

pub fn create(id: &str) -> color_eyre::Result<Self> {
Expand All @@ -91,8 +93,9 @@ impl Border {

let (hwnd_sender, hwnd_receiver) = mpsc::channel();

let instance = h_module.0 as isize;
std::thread::spawn(move || -> color_eyre::Result<()> {
let hwnd = WindowsApi::create_border_window(PCWSTR(name.as_ptr()), h_module)?;
let hwnd = WindowsApi::create_border_window(PCWSTR(name.as_ptr()), instance)?;
hwnd_sender.send(hwnd)?;

let mut msg: MSG = MSG::default();
Expand Down Expand Up @@ -120,7 +123,7 @@ impl Border {
}

pub fn destroy(&self) -> color_eyre::Result<()> {
WindowsApi::close_window(self.hwnd())
WindowsApi::close_window(self.hwnd)
}

pub fn update(&self, rect: &Rect, mut should_invalidate: bool) -> color_eyre::Result<()> {
Expand All @@ -130,8 +133,8 @@ impl Border {
rect.add_padding(-BORDER_OFFSET.load(Ordering::SeqCst));

// Update the position of the border if required
if !WindowsApi::window_rect(self.hwnd())?.eq(&rect) {
WindowsApi::set_border_pos(self.hwnd(), &rect, HWND((Z_ORDER.load()).into()))?;
if !WindowsApi::window_rect(self.hwnd)?.eq(&rect) {
WindowsApi::set_border_pos(self.hwnd, &rect, Z_ORDER.load().into())?;
should_invalidate = true;
}

Expand Down Expand Up @@ -160,13 +163,13 @@ impl Border {
let hdc = BeginPaint(window, &mut ps);

// With the rect that we set in Self::update
match WindowsApi::window_rect(window) {
match WindowsApi::window_rect(window.0 as isize) {
Ok(rect) => {
// Grab the focus kind for this border
let window_kind = {
FOCUS_STATE
.lock()
.get(&window.0)
.get(&(window.0 as isize))
.copied()
.unwrap_or(WindowKind::Unfocused)
};
Expand Down
32 changes: 15 additions & 17 deletions komorebi/src/border_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ mod border;

use crate::core::BorderImplementation;
use crate::core::BorderStyle;
use crate::core::WindowKind;
use crate::ring::Ring;
use crate::workspace_reconciliator::ALT_TAB_HWND;
use crate::Colour;
use crate::Rgb;
use crate::WindowManager;
use crate::WindowsApi;
use border::border_hwnds;
use border::Border;
use crossbeam_channel::Receiver;
use crossbeam_channel::Sender;
use crossbeam_utils::atomic::AtomicCell;
Expand All @@ -21,17 +30,6 @@ use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::OnceLock;
use windows::Win32::Foundation::HWND;

use crate::core::WindowKind;
use crate::ring::Ring;
use crate::workspace_reconciliator::ALT_TAB_HWND;
use crate::Colour;
use crate::Rgb;
use crate::WindowManager;
use crate::WindowsApi;
use border::border_hwnds;
use border::Border;

pub static BORDER_WIDTH: AtomicI32 = AtomicI32::new(8);
pub static BORDER_OFFSET: AtomicI32 = AtomicI32::new(-1);
Expand Down Expand Up @@ -300,7 +298,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
}

let rect = WindowsApi::window_rect(
monocle.focused_window().copied().unwrap_or_default().hwnd(),
monocle.focused_window().copied().unwrap_or_default().hwnd,
)?;

border.update(&rect, true)?;
Expand All @@ -324,9 +322,9 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
continue 'monitors;
}

let is_maximized = WindowsApi::is_zoomed(HWND(
let is_maximized = WindowsApi::is_zoomed(
WindowsApi::foreground_window().unwrap_or_default(),
));
);

if is_maximized {
let mut to_remove = vec![];
Expand Down Expand Up @@ -374,7 +372,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
Z_ORDER.store(ZOrder::TopMost);

let mut rect = WindowsApi::window_rect(
c.focused_window().copied().unwrap_or_default().hwnd(),
c.focused_window().copied().unwrap_or_default().hwnd,
)?;

while WindowsApi::lbutton_is_pressed() {
Expand All @@ -390,7 +388,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
};

let new_rect = WindowsApi::window_rect(
c.focused_window().copied().unwrap_or_default().hwnd(),
c.focused_window().copied().unwrap_or_default().hwnd,
)?;

if rect != new_rect {
Expand Down Expand Up @@ -438,7 +436,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
}

let rect = WindowsApi::window_rect(
c.focused_window().copied().unwrap_or_default().hwnd(),
c.focused_window().copied().unwrap_or_default().hwnd,
)?;

let should_invalidate = match last_focus_state {
Expand Down
6 changes: 3 additions & 3 deletions komorebi/src/com/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ pub extern "C" fn SetCloak(hwnd: HWND, cloak_type: u32, flags: i32) {
if view_collection.get_view_for_hwnd(hwnd, &mut view).is_err() {
tracing::error!(
"could not get view for hwnd {} due to os error: {}",
hwnd.0,
hwnd.0 as isize,
std::io::Error::last_os_error()
);
}
};

view.map_or_else(
|| {
tracing::error!("no view was found for {}", hwnd.0,);
tracing::error!("no view was found for {}", hwnd.0 as isize);
},
|view| {
unsafe {
if view.set_cloak(cloak_type, flags).is_err() {
tracing::error!(
"could not change the cloaking status for hwnd {} due to os error: {}",
hwnd.0,
hwnd.0 as isize,
std::io::Error::last_os_error()
);
}
Expand Down
6 changes: 4 additions & 2 deletions komorebi/src/monitor_reconciliator/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use windows::Win32::UI::WindowsAndMessaging::WTS_SESSION_LOCK;
use windows::Win32::UI::WindowsAndMessaging::WTS_SESSION_UNLOCK;

use crate::monitor_reconciliator;
use crate::windows_api;
use crate::WindowsApi;

// This is a hidden window specifically spawned to listen to system-wide events related to monitors
Expand All @@ -44,7 +45,7 @@ impl From<isize> for Hidden {

impl Hidden {
pub const fn hwnd(self) -> HWND {
HWND(self.hwnd)
HWND(windows_api::as_ptr!(self.hwnd))
}

pub fn create(name: &str) -> color_eyre::Result<Self> {
Expand All @@ -65,8 +66,9 @@ impl Hidden {

let (hwnd_sender, hwnd_receiver) = mpsc::channel();

let instance = h_module.0 as isize;
std::thread::spawn(move || -> color_eyre::Result<()> {
let hwnd = WindowsApi::create_hidden_window(PCWSTR(name.as_ptr()), h_module)?;
let hwnd = WindowsApi::create_hidden_window(PCWSTR(name.as_ptr()), instance)?;
hwnd_sender.send(hwnd)?;

let mut msg: MSG = MSG::default();
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl WindowManager {
}
SocketMessage::ForceFocus => {
let focused_window = self.focused_window()?;
let focused_window_rect = WindowsApi::window_rect(focused_window.hwnd())?;
let focused_window_rect = WindowsApi::window_rect(focused_window.hwnd)?;
WindowsApi::center_cursor_in_rect(&focused_window_rect)?;
WindowsApi::left_click();
}
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no workspace with this idx"))?
.focused_container_idx();

WindowsApi::bring_window_to_top(window.hwnd())?;
WindowsApi::bring_window_to_top(window.hwnd)?;

self.pending_move_op =
Option::from((monitor_idx, workspace_idx, container_idx));
Expand All @@ -407,7 +407,7 @@ impl WindowManager {

let workspace = self.focused_workspace_mut()?;
let focused_container_idx = workspace.focused_container_idx();
let new_position = WindowsApi::window_rect(window.hwnd())?;
let new_position = WindowsApi::window_rect(window.hwnd)?;
let old_position = *workspace
.latest_layout()
.get(focused_container_idx)
Expand Down
12 changes: 3 additions & 9 deletions komorebi/src/stackbar_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::OnceLock;
use windows::Win32::Foundation::HWND;

pub static STACKBAR_FONT_SIZE: AtomicI32 = AtomicI32::new(0); // 0 will produce the system default
pub static STACKBAR_FOCUSED_TEXT_COLOUR: AtomicU32 = AtomicU32::new(16777215); // white
Expand Down Expand Up @@ -128,9 +127,8 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
continue 'receiver;
}

let is_maximized = WindowsApi::is_zoomed(HWND(
WindowsApi::foreground_window().unwrap_or_default(),
));
let is_maximized =
WindowsApi::is_zoomed(WindowsApi::foreground_window().unwrap_or_default());

// Handle the monocle container separately
if ws.monocle_container().is_some() || is_maximized {
Expand Down Expand Up @@ -207,11 +205,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
stackbars_monitors.insert(container.id().clone(), monitor_idx);

let rect = WindowsApi::window_rect(
container
.focused_window()
.copied()
.unwrap_or_default()
.hwnd(),
container.focused_window().copied().unwrap_or_default().hwnd,
)?;

stackbar.update(container_padding, container, &rect)?;
Expand Down
Loading

0 comments on commit ddb600f

Please sign in to comment.