mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-02-13 08:47:41 +01:00
Compare commits
2 Commits
feature/ex
...
v0.1.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2b49845ac | ||
|
|
5b923a135c |
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -505,7 +505,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "komorebi"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"bindings",
|
||||
"bitflags",
|
||||
@@ -537,7 +537,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "komorebi-core"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"bindings",
|
||||
"clap",
|
||||
@@ -549,7 +549,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "komorebic"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"bindings",
|
||||
"clap",
|
||||
@@ -1319,9 +1319,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.2.22"
|
||||
version = "0.2.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62af966210b88ad5776ee3ba12d5f35b8d6a2b2a12168f3080cf02b814d7376b"
|
||||
checksum = "56c42e73a9d277d4d2b6a88389a137ccf3c58599660b17e8f5fc39305e490669"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"chrono",
|
||||
@@ -1357,9 +1357,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
fn main() {
|
||||
windows::build!(
|
||||
Windows::Win32::Devices::HumanInterfaceDevice::HID_USAGE_PAGE_GENERIC,
|
||||
Windows::Win32::Devices::HumanInterfaceDevice::HID_USAGE_GENERIC_MOUSE,
|
||||
Windows::Win32::Foundation::RECT,
|
||||
Windows::Win32::Foundation::POINT,
|
||||
Windows::Win32::Foundation::BOOL,
|
||||
@@ -12,7 +10,6 @@ fn main() {
|
||||
Windows::Win32::Graphics::Dwm::*,
|
||||
// error: `Windows.Win32.Graphics.Gdi.MONITOR_DEFAULTTONEAREST` not found in metadata
|
||||
Windows::Win32::Graphics::Gdi::*,
|
||||
Windows::Win32::System::LibraryLoader::GetModuleHandleW,
|
||||
Windows::Win32::System::Threading::PROCESS_ACCESS_RIGHTS,
|
||||
Windows::Win32::System::Threading::PROCESS_NAME_FORMAT,
|
||||
Windows::Win32::System::Threading::OpenProcess,
|
||||
@@ -20,8 +17,7 @@ fn main() {
|
||||
Windows::Win32::System::Threading::GetCurrentThreadId,
|
||||
Windows::Win32::System::Threading::AttachThreadInput,
|
||||
Windows::Win32::System::Threading::GetCurrentProcessId,
|
||||
// error: `Windows.Win32.UI.KeyboardAndMouseInput.RIM_TYPEMOUSE` not found in metadata
|
||||
Windows::Win32::UI::KeyboardAndMouseInput::*,
|
||||
Windows::Win32::UI::KeyboardAndMouseInput::SetFocus,
|
||||
Windows::Win32::UI::Accessibility::SetWinEventHook,
|
||||
Windows::Win32::UI::Accessibility::HWINEVENTHOOK,
|
||||
// error: `Windows.Win32.UI.WindowsAndMessaging.GWL_EXSTYLE` not found in metadata
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi-core"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
authors = ["Jade Iqbal <jadeiqbal@fastmail.com>"]
|
||||
description = "A tiling window manager for Windows"
|
||||
categories = ["tiling-window-manager", "windows"]
|
||||
|
||||
@@ -19,8 +19,9 @@ use crate::workspace::Workspace;
|
||||
pub struct Monitor {
|
||||
#[getset(get_copy = "pub", set = "pub")]
|
||||
id: isize,
|
||||
monitor_size: Rect,
|
||||
#[getset(get = "pub")]
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
size: Rect,
|
||||
#[getset(get = "pub", set = "pub")]
|
||||
work_area_size: Rect,
|
||||
workspaces: Ring<Workspace>,
|
||||
#[serde(skip_serializing)]
|
||||
@@ -30,13 +31,13 @@ pub struct Monitor {
|
||||
|
||||
impl_ring_elements!(Monitor, Workspace);
|
||||
|
||||
pub fn new(id: isize, monitor_size: Rect, work_area_size: Rect) -> Monitor {
|
||||
pub fn new(id: isize, size: Rect, work_area_size: Rect) -> Monitor {
|
||||
let mut workspaces = Ring::default();
|
||||
workspaces.elements_mut().push_back(Workspace::default());
|
||||
|
||||
Monitor {
|
||||
id,
|
||||
monitor_size,
|
||||
size,
|
||||
work_area_size,
|
||||
workspaces,
|
||||
workspace_names: HashMap::default(),
|
||||
|
||||
@@ -51,7 +51,8 @@ impl WindowManager {
|
||||
|
||||
// Make sure we have the most recently focused monitor from any event
|
||||
match event {
|
||||
WindowManagerEvent::FocusChange(_, window)
|
||||
WindowManagerEvent::MonitorPoll(_, window)
|
||||
| WindowManagerEvent::FocusChange(_, window)
|
||||
| WindowManagerEvent::Show(_, window)
|
||||
| WindowManagerEvent::MoveResizeEnd(_, window) => {
|
||||
self.reconcile_monitors()?;
|
||||
@@ -284,7 +285,7 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false)?;
|
||||
}
|
||||
}
|
||||
WindowManagerEvent::MouseCapture(..) => {}
|
||||
WindowManagerEvent::MonitorPoll(..) | WindowManagerEvent::MouseCapture(..) => {}
|
||||
};
|
||||
|
||||
// If we unmanaged a window, it shouldn't be immediately hidden behind managed windows
|
||||
|
||||
@@ -231,6 +231,10 @@ impl Window {
|
||||
|
||||
#[tracing::instrument(fields(exe, title))]
|
||||
pub fn should_manage(self, event: Option<WindowManagerEvent>) -> Result<bool> {
|
||||
if let Some(WindowManagerEvent::MonitorPoll(_, _)) = event {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if self.title().is_err() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -265,6 +265,39 @@ impl WindowManager {
|
||||
// Remove any invalid monitors from our state
|
||||
self.monitors_mut().retain(|m| !invalid.contains(&m.id()));
|
||||
|
||||
let invisible_borders = self.invisible_borders;
|
||||
|
||||
for monitor in self.monitors_mut() {
|
||||
let mut should_update = false;
|
||||
let reference = WindowsApi::monitor(monitor.id())?;
|
||||
// TODO: If this is different, force a redraw
|
||||
|
||||
if reference.work_area_size() != monitor.work_area_size() {
|
||||
monitor.set_work_area_size(Rect {
|
||||
left: reference.work_area_size().left,
|
||||
top: reference.work_area_size().top,
|
||||
right: reference.work_area_size().right,
|
||||
bottom: reference.work_area_size().bottom,
|
||||
});
|
||||
|
||||
should_update = true;
|
||||
}
|
||||
if reference.size() != monitor.size() {
|
||||
monitor.set_size(Rect {
|
||||
left: reference.size().left,
|
||||
top: reference.size().top,
|
||||
right: reference.size().right,
|
||||
bottom: reference.size().bottom,
|
||||
});
|
||||
|
||||
should_update = true;
|
||||
}
|
||||
|
||||
if should_update {
|
||||
monitor.update_focused_workspace(&invisible_borders)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for and add any new monitors that may have been plugged in
|
||||
WindowsApi::load_monitor_information(&mut self.monitors)?;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ pub enum WindowManagerEvent {
|
||||
Manage(Window),
|
||||
Unmanage(Window),
|
||||
Raise(Window),
|
||||
MonitorPoll(WinEvent, Window),
|
||||
}
|
||||
|
||||
impl Display for WindowManagerEvent {
|
||||
@@ -64,6 +65,13 @@ impl Display for WindowManagerEvent {
|
||||
WindowManagerEvent::Raise(window) => {
|
||||
write!(f, "Raise (Window: {})", window)
|
||||
}
|
||||
WindowManagerEvent::MonitorPoll(winevent, window) => {
|
||||
write!(
|
||||
f,
|
||||
"MonitorPoll (WinEvent: {}, Window: {})",
|
||||
winevent, window
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +86,7 @@ impl WindowManagerEvent {
|
||||
| WindowManagerEvent::Show(_, window)
|
||||
| WindowManagerEvent::MoveResizeEnd(_, window)
|
||||
| WindowManagerEvent::MouseCapture(_, window)
|
||||
| WindowManagerEvent::MonitorPoll(_, window)
|
||||
| WindowManagerEvent::Raise(window)
|
||||
| WindowManagerEvent::Manage(window)
|
||||
| WindowManagerEvent::Unmanage(window) => window,
|
||||
@@ -121,6 +130,17 @@ impl WindowManagerEvent {
|
||||
None
|
||||
}
|
||||
}
|
||||
WinEvent::ObjectCreate => {
|
||||
if let Ok(title) = window.title() {
|
||||
// Hidden COM support mechanism window that fires this event on both DPI/scaling
|
||||
// changes and resolution changes, a good candidate for polling
|
||||
if title == "OLEChannelWnd" {
|
||||
return Option::from(Self::MonitorPoll(winevent, window));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,8 @@ use color_eyre::eyre::anyhow;
|
||||
use color_eyre::eyre::Error;
|
||||
use color_eyre::Result;
|
||||
|
||||
use bindings::Windows::Win32::Devices::HumanInterfaceDevice::HID_USAGE_GENERIC_MOUSE;
|
||||
use bindings::Windows::Win32::Devices::HumanInterfaceDevice::HID_USAGE_PAGE_GENERIC;
|
||||
use bindings::Windows::Win32::Foundation::BOOL;
|
||||
use bindings::Windows::Win32::Foundation::HANDLE;
|
||||
use bindings::Windows::Win32::Foundation::HINSTANCE;
|
||||
use bindings::Windows::Win32::Foundation::HWND;
|
||||
use bindings::Windows::Win32::Foundation::LPARAM;
|
||||
use bindings::Windows::Win32::Foundation::POINT;
|
||||
@@ -28,13 +25,11 @@ use bindings::Windows::Win32::Graphics::Gdi::EnumDisplayMonitors;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::GetMonitorInfoW;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::MonitorFromPoint;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::MonitorFromWindow;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::HBRUSH;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::HDC;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::HMONITOR;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::MONITORENUMPROC;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::MONITORINFO;
|
||||
use bindings::Windows::Win32::Graphics::Gdi::MONITOR_DEFAULTTONEAREST;
|
||||
use bindings::Windows::Win32::System::LibraryLoader::GetModuleHandleW;
|
||||
use bindings::Windows::Win32::System::Threading::AttachThreadInput;
|
||||
use bindings::Windows::Win32::System::Threading::GetCurrentProcessId;
|
||||
use bindings::Windows::Win32::System::Threading::GetCurrentThreadId;
|
||||
@@ -43,22 +38,9 @@ use bindings::Windows::Win32::System::Threading::QueryFullProcessImageNameW;
|
||||
use bindings::Windows::Win32::System::Threading::PROCESS_ACCESS_RIGHTS;
|
||||
use bindings::Windows::Win32::System::Threading::PROCESS_NAME_FORMAT;
|
||||
use bindings::Windows::Win32::System::Threading::PROCESS_QUERY_INFORMATION;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::GetRawInputBuffer;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::GetRawInputData;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RegisterRawInputDevices;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::SetFocus;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::HRAWINPUT;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RAWINPUT;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RAWINPUTDEVICE;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RAWINPUTHEADER;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RIDEV_INPUTSINK;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RIDEV_NOLEGACY;
|
||||
use bindings::Windows::Win32::UI::KeyboardAndMouseInput::RID_INPUT;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::AllowSetForegroundWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::CreateWindowExW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::DestroyWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::EnumWindows;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::FindWindowExW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetCursorPos;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetDesktopWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GetForegroundWindow;
|
||||
@@ -72,23 +54,16 @@ use bindings::Windows::Win32::UI::WindowsAndMessaging::IsIconic;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::IsWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::IsWindowVisible;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::RealGetWindowClassW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::RegisterClassExW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SetCursorPos;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SetForegroundWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SetWindowLongPtrW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SetWindowPos;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::ShowWindow;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SystemParametersInfoW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::UnregisterClassW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WindowFromPoint;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::CW_USEDEFAULT;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GWL_EXSTYLE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GWL_STYLE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::GW_HWNDNEXT;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::HCURSOR;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::HICON;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::HMENU;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::HWND_MESSAGE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::HWND_NOTOPMOST;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::HWND_TOPMOST;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SET_WINDOW_POS_FLAGS;
|
||||
@@ -101,13 +76,8 @@ use bindings::Windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SW_RESTORE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_ACTION;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WINDOW_EX_STYLE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WINDOW_LONG_PTR_INDEX;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WINDOW_STYLE;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WNDCLASSEXW;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WNDCLASS_STYLES;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WNDENUMPROC;
|
||||
use bindings::Windows::Win32::UI::WindowsAndMessaging::WNDPROC;
|
||||
use komorebi_core::Rect;
|
||||
|
||||
use crate::container::Container;
|
||||
@@ -117,21 +87,6 @@ use crate::ring::Ring;
|
||||
use crate::set_window_position::SetWindowPosition;
|
||||
use crate::windows_callbacks;
|
||||
|
||||
pub trait IntoPWSTR {
|
||||
fn into_pwstr(self) -> PWSTR;
|
||||
}
|
||||
|
||||
impl IntoPWSTR for &str {
|
||||
fn into_pwstr(self) -> PWSTR {
|
||||
PWSTR(
|
||||
self.encode_utf16()
|
||||
.chain([0_u16])
|
||||
.collect::<Vec<u16>>()
|
||||
.as_mut_ptr(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum WindowsResult<T, E> {
|
||||
Err(E),
|
||||
Ok(T),
|
||||
@@ -147,16 +102,6 @@ impl From<BOOL> for WindowsResult<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HINSTANCE> for WindowsResult<HINSTANCE, Error> {
|
||||
fn from(return_value: HINSTANCE) -> Self {
|
||||
if return_value.is_null() {
|
||||
Self::Err(std::io::Error::last_os_error().into())
|
||||
} else {
|
||||
Self::Ok(return_value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HWND> for WindowsResult<isize, Error> {
|
||||
fn from(return_value: HWND) -> Self {
|
||||
if return_value.is_null() {
|
||||
@@ -192,7 +137,7 @@ macro_rules! impl_from_integer_for_windows_result {
|
||||
};
|
||||
}
|
||||
|
||||
impl_from_integer_for_windows_result!(isize, u16, u32, i32);
|
||||
impl_from_integer_for_windows_result!(isize, u32, i32);
|
||||
|
||||
impl<T, E> From<WindowsResult<T, E>> for Result<T, E> {
|
||||
fn from(result: WindowsResult<T, E>) -> Self {
|
||||
@@ -220,46 +165,6 @@ impl WindowsApi {
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn valid_hwnds() -> Result<Vec<isize>> {
|
||||
let mut hwnds: Vec<isize> = vec![];
|
||||
let hwnds_ref: &mut Vec<isize> = hwnds.as_mut();
|
||||
Self::enum_windows(
|
||||
windows_callbacks::valid_hwnds,
|
||||
hwnds_ref as *mut Vec<isize> as isize,
|
||||
)?;
|
||||
|
||||
Ok(hwnds)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn hwnd_by_class(class: &str) -> Option<isize> {
|
||||
let hwnds = Self::valid_hwnds().ok()?;
|
||||
for hwnd in hwnds {
|
||||
if let Ok(hwnd_class) = Self::real_window_class_w(HWND(hwnd)) {
|
||||
if hwnd_class == class {
|
||||
return Option::from(hwnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn hwnd_by_title(class: &str) -> Option<isize> {
|
||||
let hwnds = Self::valid_hwnds().ok()?;
|
||||
for hwnd in hwnds {
|
||||
if let Ok(hwnd_title) = Self::window_text_w(HWND(hwnd)) {
|
||||
if hwnd_title == class {
|
||||
return Option::from(hwnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn valid_hmonitors() -> Result<Vec<isize>> {
|
||||
let mut monitors: Vec<isize> = vec![];
|
||||
let monitors_ref: &mut Vec<isize> = monitors.as_mut();
|
||||
@@ -655,11 +560,11 @@ impl WindowsApi {
|
||||
Ok(monitor_info)
|
||||
}
|
||||
|
||||
pub fn monitor(hmonitor: HMONITOR) -> Result<Monitor> {
|
||||
let monitor_info = Self::monitor_info_w(hmonitor)?;
|
||||
pub fn monitor(hmonitor: isize) -> Result<Monitor> {
|
||||
let monitor_info = Self::monitor_info_w(HMONITOR(hmonitor))?;
|
||||
|
||||
Ok(monitor::new(
|
||||
hmonitor.0,
|
||||
hmonitor,
|
||||
monitor_info.rcMonitor.into(),
|
||||
monitor_info.rcWork.into(),
|
||||
))
|
||||
@@ -710,192 +615,4 @@ impl WindowsApi {
|
||||
SPIF_SENDCHANGE,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn module_handle_w() -> Result<HINSTANCE> {
|
||||
Result::from(WindowsResult::from(unsafe { GetModuleHandleW(None) }))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn register_class_ex_w(class: &WNDCLASSEXW) -> Result<u16> {
|
||||
Result::from(WindowsResult::from(unsafe { RegisterClassExW(class) }))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments, dead_code)]
|
||||
fn create_window_ex_w(
|
||||
window_ex_style: WINDOW_EX_STYLE,
|
||||
class_name: PWSTR,
|
||||
window_name: PWSTR,
|
||||
window_style: WINDOW_STYLE,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
hwnd_parent: HWND,
|
||||
hmenu: HMENU,
|
||||
hinstance: HINSTANCE,
|
||||
lp_param: *mut c_void,
|
||||
) -> Result<isize> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
CreateWindowExW(
|
||||
window_ex_style,
|
||||
class_name,
|
||||
window_name,
|
||||
window_style,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
hwnd_parent,
|
||||
hmenu,
|
||||
hinstance,
|
||||
lp_param,
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn hidden_message_window(name: &str, wnd_proc: Option<WNDPROC>) -> Result<isize> {
|
||||
let hinstance = Self::module_handle_w()?;
|
||||
|
||||
let window_class = WNDCLASSEXW {
|
||||
cbSize: u32::try_from(std::mem::size_of::<WNDCLASSEXW>())?,
|
||||
cbClsExtra: 0,
|
||||
cbWndExtra: 0,
|
||||
hbrBackground: HBRUSH::NULL,
|
||||
hCursor: HCURSOR::NULL,
|
||||
hIcon: HICON::NULL,
|
||||
hIconSm: HICON::NULL,
|
||||
hInstance: hinstance,
|
||||
lpfnWndProc: wnd_proc,
|
||||
lpszClassName: name.into_pwstr(),
|
||||
lpszMenuName: PWSTR::NULL,
|
||||
style: WNDCLASS_STYLES::from(0),
|
||||
};
|
||||
|
||||
Self::register_class_ex_w(&window_class)?;
|
||||
|
||||
Self::create_window_ex_w(
|
||||
WINDOW_EX_STYLE::from(0),
|
||||
name.into_pwstr(),
|
||||
name.into_pwstr(),
|
||||
WINDOW_STYLE::from(0),
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
HWND_MESSAGE,
|
||||
HMENU::NULL,
|
||||
hinstance,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn destroy_window(hwnd: isize) -> Result<()> {
|
||||
Result::from(WindowsResult::from(unsafe { DestroyWindow(HWND(hwnd)) }))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn unregister_class_w(name: &str) -> Result<()> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
UnregisterClassW(name.into_pwstr(), Self::module_handle_w()?)
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn register_raw_input_devices(devices: &mut [RAWINPUTDEVICE]) -> Result<()> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
RegisterRawInputDevices(
|
||||
devices.as_mut_ptr(),
|
||||
u32::try_from(devices.len())?,
|
||||
u32::try_from(std::mem::size_of::<RAWINPUTDEVICE>())?,
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn register_mice_for_hwnd(hwnd: isize) -> Result<()> {
|
||||
Self::register_raw_input_devices(&mut [RAWINPUTDEVICE {
|
||||
dwFlags: RIDEV_NOLEGACY | RIDEV_INPUTSINK,
|
||||
usUsagePage: HID_USAGE_PAGE_GENERIC,
|
||||
usUsage: HID_USAGE_GENERIC_MOUSE,
|
||||
hwndTarget: HWND(hwnd),
|
||||
}])
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn raw_input_buffer_null(buffer_size: *mut u32, header_size: u32) -> Result<()> {
|
||||
Result::from(unsafe {
|
||||
match GetRawInputBuffer(std::ptr::null_mut(), buffer_size, header_size) {
|
||||
0 => WindowsResult::Ok(()),
|
||||
_ => WindowsResult::Err(std::io::Error::last_os_error().into()),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn raw_input_buffer(
|
||||
raw_input_pointer: *mut RAWINPUT,
|
||||
buffer_size: *mut u32,
|
||||
header_size: u32,
|
||||
) -> Result<u32> {
|
||||
Result::from(unsafe {
|
||||
WindowsResult::Ok(GetRawInputBuffer(
|
||||
raw_input_pointer,
|
||||
buffer_size,
|
||||
header_size,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn raw_input_data_null(raw_input_handle: HRAWINPUT, buffer_size: &mut u32) -> Result<()> {
|
||||
Result::from(unsafe {
|
||||
match GetRawInputData(
|
||||
raw_input_handle,
|
||||
RID_INPUT,
|
||||
std::ptr::null_mut(),
|
||||
buffer_size,
|
||||
u32::try_from(std::mem::size_of::<RAWINPUTHEADER>())?,
|
||||
) {
|
||||
0 => WindowsResult::Ok(()),
|
||||
_ => WindowsResult::Err(std::io::Error::last_os_error().into()),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn raw_input_data(
|
||||
raw_input_handle: HRAWINPUT,
|
||||
buffer: *mut c_void,
|
||||
buffer_size: *mut u32,
|
||||
) -> Result<u32> {
|
||||
Result::from(unsafe {
|
||||
match GetRawInputData(
|
||||
raw_input_handle,
|
||||
RID_INPUT,
|
||||
buffer,
|
||||
buffer_size,
|
||||
u32::try_from(std::mem::size_of::<RAWINPUTHEADER>())?,
|
||||
) {
|
||||
0 => WindowsResult::Err(std::io::Error::last_os_error().into()),
|
||||
n => WindowsResult::Ok(n),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn find_window_ex_w(parent: HWND, class: &str, title: &str) -> Result<isize> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
let hwnd = FindWindowExW(parent, HWND::NULL, class.into_pwstr(), title.into_pwstr());
|
||||
dbg!(hwnd);
|
||||
hwnd
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn find_message_window(class: &str, title: &str) -> Result<isize> {
|
||||
Self::find_window_ex_w(HWND_MESSAGE, class, title)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,20 +42,13 @@ pub extern "system" fn enum_display_monitor(
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(m) = WindowsApi::monitor(hmonitor) {
|
||||
if let Ok(m) = WindowsApi::monitor(hmonitor.0) {
|
||||
monitors.elements_mut().push_back(m);
|
||||
}
|
||||
|
||||
true.into()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub extern "system" fn valid_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
let hwnds = unsafe { &mut *(lparam.0 as *mut Vec<isize>) };
|
||||
hwnds.push(hwnd.0);
|
||||
true.into()
|
||||
}
|
||||
|
||||
pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
let containers = unsafe { &mut *(lparam.0 as *mut VecDeque<Container>) };
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ impl MessageLoop {
|
||||
loop {
|
||||
let mut value: Option<MSG> = None;
|
||||
unsafe {
|
||||
if bool::from(PeekMessageW(&mut msg, HWND(0), 0, 0, PM_REMOVE)) {
|
||||
if !bool::from(!PeekMessageW(&mut msg, HWND(0), 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebic"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
authors = ["Jade Iqbal <jadeiqbal@fastmail.com>"]
|
||||
description = "The command-line interface for Komorebi, a tiling window manager for Windows"
|
||||
categories = ["cli", "tiling-window-manager", "windows"]
|
||||
|
||||
Reference in New Issue
Block a user