mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-17 06:19:45 +02:00
refactor(rust): use eyre::Result uniformly
Matching the emerging style in komorebi for Mac
This commit is contained in:
@@ -22,6 +22,7 @@ use crate::widgets::komorebi::Komorebi;
|
||||
use crate::widgets::komorebi::MonitorInfo;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::widgets::widget::WidgetConfig;
|
||||
use color_eyre::eyre;
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::TryRecvError;
|
||||
use eframe::egui::Align;
|
||||
@@ -61,7 +62,6 @@ use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Result;
|
||||
use std::io::Write;
|
||||
use std::os::windows::process::CommandExt;
|
||||
use std::path::PathBuf;
|
||||
@@ -78,7 +78,7 @@ lazy_static! {
|
||||
static ref SESSION_STDIN: Mutex<Option<ChildStdin>> = Mutex::new(None);
|
||||
}
|
||||
|
||||
fn start_powershell() -> Result<()> {
|
||||
fn start_powershell() -> eyre::Result<()> {
|
||||
// found running session, do nothing
|
||||
if SESSION_STDIN.lock().as_mut().is_some() {
|
||||
tracing::debug!("PowerShell session already started");
|
||||
@@ -102,17 +102,17 @@ fn start_powershell() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn stop_powershell() -> Result<()> {
|
||||
fn stop_powershell() -> eyre::Result<()> {
|
||||
tracing::debug!("Stopping PowerShell session");
|
||||
|
||||
if let Some(mut session_stdin) = SESSION_STDIN.lock().take() {
|
||||
if let Err(e) = session_stdin.write_all(b"exit\n") {
|
||||
tracing::error!(error = %e, "failed to write exit command to PowerShell stdin");
|
||||
return Err(e);
|
||||
return Err(e.into());
|
||||
}
|
||||
if let Err(e) = session_stdin.flush() {
|
||||
tracing::error!(error = %e, "failed to flush PowerShell stdin");
|
||||
return Err(e);
|
||||
return Err(e.into());
|
||||
}
|
||||
|
||||
tracing::debug!("PowerShell session stopped");
|
||||
@@ -123,25 +123,22 @@ fn stop_powershell() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn exec_powershell(cmd: &str) -> Result<()> {
|
||||
pub fn exec_powershell(cmd: &str) -> eyre::Result<()> {
|
||||
if let Some(session_stdin) = SESSION_STDIN.lock().as_mut() {
|
||||
if let Err(e) = writeln!(session_stdin, "{cmd}") {
|
||||
tracing::error!(error = %e, cmd = cmd, "failed to write command to PowerShell stdin");
|
||||
return Err(e);
|
||||
return Err(e.into());
|
||||
}
|
||||
|
||||
if let Err(e) = session_stdin.flush() {
|
||||
tracing::error!(error = %e, "failed to flush PowerShell stdin");
|
||||
return Err(e);
|
||||
return Err(e.into());
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(Error::new(
|
||||
ErrorKind::NotFound,
|
||||
"PowerShell session not started",
|
||||
))
|
||||
Err(Error::new(ErrorKind::NotFound, "PowerShell session not started").into())
|
||||
}
|
||||
|
||||
pub struct Komobar {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use color_eyre::eyre;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::Label;
|
||||
@@ -80,7 +81,7 @@ pub struct Keyboard {
|
||||
/// - `Ok(String)`: The name of the active keyboard layout as a valid UTF-8 string.
|
||||
/// - `Err(())`: Indicates that the function failed to retrieve the locale name or encountered
|
||||
/// invalid UTF-16 characters during conversion.
|
||||
fn get_active_keyboard_layout() -> Result<String, ()> {
|
||||
fn get_active_keyboard_layout() -> eyre::Result<String, ()> {
|
||||
let foreground_window_tid = unsafe { GetWindowThreadProcessId(GetForegroundWindow(), None) };
|
||||
let lcid = unsafe { GetKeyboardLayout(foreground_window_tid) };
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::config::DisplayFormat;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::komorebi::KomorebiLayoutConfig;
|
||||
use color_eyre::eyre;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::CornerRadius;
|
||||
use eframe::egui::FontId;
|
||||
@@ -34,7 +35,7 @@ pub enum KomorebiLayout {
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for KomorebiLayout {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> eyre::Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -57,7 +57,7 @@ impl AnimationEngine {
|
||||
pub fn animate(
|
||||
render_dispatcher: impl RenderDispatcher + Send + 'static,
|
||||
duration: Duration,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
std::thread::spawn(move || {
|
||||
let animation_key = render_dispatcher.get_animation_key();
|
||||
if ANIMATION_MANAGER.lock().in_progress(animation_key.as_str()) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
|
||||
pub trait RenderDispatcher {
|
||||
fn get_animation_key(&self) -> String;
|
||||
fn pre_render(&self) -> Result<()>;
|
||||
fn render(&self, delta: f64) -> Result<()>;
|
||||
fn post_render(&self) -> Result<()>;
|
||||
fn pre_render(&self) -> eyre::Result<()>;
|
||||
fn render(&self, delta: f64) -> eyre::Result<()>;
|
||||
fn post_render(&self) -> eyre::Result<()>;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::config_generation::ApplicationConfiguration;
|
||||
use crate::config_generation::ApplicationOptions;
|
||||
use crate::config_generation::MatchingRule;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -36,12 +36,12 @@ impl DerefMut for ApplicationSpecificConfiguration {
|
||||
}
|
||||
|
||||
impl ApplicationSpecificConfiguration {
|
||||
pub fn load(pathbuf: &PathBuf) -> Result<Self> {
|
||||
pub fn load(pathbuf: &PathBuf) -> eyre::Result<Self> {
|
||||
let content = std::fs::read_to_string(pathbuf)?;
|
||||
Ok(serde_json::from_str(&content)?)
|
||||
}
|
||||
|
||||
pub fn format(pathbuf: &PathBuf) -> Result<String> {
|
||||
pub fn format(pathbuf: &PathBuf) -> eyre::Result<String> {
|
||||
Ok(serde_json::to_string_pretty(&Self::load(pathbuf)?)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use clap::ValueEnum;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use strum::Display;
|
||||
@@ -142,11 +142,11 @@ impl ApplicationConfiguration {
|
||||
pub struct ApplicationConfigurationGenerator;
|
||||
|
||||
impl ApplicationConfigurationGenerator {
|
||||
pub fn load(content: &str) -> Result<Vec<ApplicationConfiguration>> {
|
||||
pub fn load(content: &str) -> eyre::Result<Vec<ApplicationConfiguration>> {
|
||||
Ok(serde_yaml::from_str(content)?)
|
||||
}
|
||||
|
||||
pub fn format(content: &str) -> Result<String> {
|
||||
pub fn format(content: &str) -> eyre::Result<String> {
|
||||
let mut cfgen = Self::load(content)?;
|
||||
for cfg in &mut cfgen {
|
||||
cfg.populate_default_matching_strategies();
|
||||
@@ -156,7 +156,10 @@ impl ApplicationConfigurationGenerator {
|
||||
Ok(serde_yaml::to_string(&cfgen)?)
|
||||
}
|
||||
|
||||
fn merge(base_content: &str, override_content: &str) -> Result<Vec<ApplicationConfiguration>> {
|
||||
fn merge(
|
||||
base_content: &str,
|
||||
override_content: &str,
|
||||
) -> eyre::Result<Vec<ApplicationConfiguration>> {
|
||||
let base_cfgen = Self::load(base_content)?;
|
||||
let override_cfgen = Self::load(override_content)?;
|
||||
|
||||
@@ -182,7 +185,7 @@ impl ApplicationConfigurationGenerator {
|
||||
pub fn generate_pwsh(
|
||||
base_content: &str,
|
||||
override_content: Option<&str>,
|
||||
) -> Result<Vec<String>> {
|
||||
) -> eyre::Result<Vec<String>> {
|
||||
let mut cfgen = if let Some(override_content) = override_content {
|
||||
Self::merge(base_content, override_content)?
|
||||
} else {
|
||||
@@ -233,7 +236,10 @@ impl ApplicationConfigurationGenerator {
|
||||
Ok(lines)
|
||||
}
|
||||
|
||||
pub fn generate_ahk(base_content: &str, override_content: Option<&str>) -> Result<Vec<String>> {
|
||||
pub fn generate_ahk(
|
||||
base_content: &str,
|
||||
override_content: Option<&str>,
|
||||
) -> eyre::Result<Vec<String>> {
|
||||
let mut cfgen = if let Some(override_content) = override_content {
|
||||
Self::merge(base_content, override_content)?
|
||||
} else {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::bail;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
@@ -5,11 +9,6 @@ use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::path::Path;
|
||||
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre::bail;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::Rect;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
@@ -31,7 +30,7 @@ impl DerefMut for CustomLayout {
|
||||
}
|
||||
|
||||
impl CustomLayout {
|
||||
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||
pub fn from_path<P: AsRef<Path>>(path: P) -> eyre::Result<Self> {
|
||||
let path = path.as_ref();
|
||||
let layout: Self = match path.extension() {
|
||||
Some(extension) if extension == "yaml" || extension == "yml" => {
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use clap::ValueEnum;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use strum::Display;
|
||||
@@ -248,7 +248,7 @@ pub enum SocketMessage {
|
||||
}
|
||||
|
||||
impl SocketMessage {
|
||||
pub fn as_bytes(&self) -> Result<Vec<u8>> {
|
||||
pub fn as_bytes(&self) -> eyre::Result<Vec<u8>> {
|
||||
Ok(serde_json::to_string(self)?.as_bytes().to_vec())
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,7 @@ impl SocketMessage {
|
||||
impl FromStr for SocketMessage {
|
||||
type Err = serde_json::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
fn from_str(s: &str) -> eyre::Result<Self, Self::Err> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ use crate::core::config_generation::IdWithIdentifier;
|
||||
use crate::core::config_generation::MatchingRule;
|
||||
use crate::core::config_generation::MatchingStrategy;
|
||||
use crate::core::config_generation::WorkspaceMatchingRule;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use os_info::Version;
|
||||
use parking_lot::Mutex;
|
||||
@@ -329,7 +329,10 @@ pub struct Notification {
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
pub fn notify_subscribers(notification: Notification, state_has_been_modified: bool) -> Result<()> {
|
||||
pub fn notify_subscribers(
|
||||
notification: Notification,
|
||||
state_has_been_modified: bool,
|
||||
) -> eyre::Result<()> {
|
||||
let is_override_event = matches!(
|
||||
notification.event,
|
||||
NotificationEvent::Socket(SocketMessage::AddSubscriberSocket(_))
|
||||
@@ -410,7 +413,7 @@ pub fn notify_subscribers(notification: Notification, state_has_been_modified: b
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_configuration() -> Result<()> {
|
||||
pub fn load_configuration() -> eyre::Result<()> {
|
||||
let config_pwsh = HOME_DIR.join("komorebi.ps1");
|
||||
let config_ahk = HOME_DIR.join("komorebi.ahk");
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::time::Duration;
|
||||
|
||||
use clap::Parser;
|
||||
use clap::ValueEnum;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::bail;
|
||||
use crossbeam_utils::Backoff;
|
||||
use komorebi::animation::ANIMATION_ENABLED_GLOBAL;
|
||||
@@ -58,7 +58,7 @@ use komorebi::window_manager::WindowManager;
|
||||
use komorebi::windows_api::WindowsApi;
|
||||
use komorebi::winevent_listener;
|
||||
|
||||
fn setup(log_level: LogLevel) -> Result<(WorkerGuard, WorkerGuard)> {
|
||||
fn setup(log_level: LogLevel) -> eyre::Result<(WorkerGuard, WorkerGuard)> {
|
||||
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LIB_BACKTRACE", "1");
|
||||
@@ -196,7 +196,7 @@ struct Opts {
|
||||
|
||||
#[tracing::instrument]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn main() -> Result<()> {
|
||||
fn main() -> eyre::Result<()> {
|
||||
let opts: Opts = Opts::parse();
|
||||
CUSTOM_FFM.store(opts.focus_follows_mouse, Ordering::SeqCst);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use color_eyre::eyre::bail;
|
||||
use serde::Deserialize;
|
||||
@@ -167,7 +167,7 @@ impl Monitor {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> Result<()> {
|
||||
pub fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_workspace_idx();
|
||||
let hmonitor = self.id;
|
||||
let monitor_wp = self.wallpaper.clone();
|
||||
@@ -264,7 +264,7 @@ impl Monitor {
|
||||
&mut self,
|
||||
container: Container,
|
||||
workspace_idx: Option<usize>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = if let Some(idx) = workspace_idx {
|
||||
self.workspaces_mut()
|
||||
.get_mut(idx)
|
||||
@@ -288,7 +288,7 @@ impl Monitor {
|
||||
container: Container,
|
||||
workspace_idx: Option<usize>,
|
||||
direction: OperationDirection,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = if let Some(idx) = workspace_idx {
|
||||
self.workspaces_mut()
|
||||
.get_mut(idx)
|
||||
@@ -390,7 +390,7 @@ impl Monitor {
|
||||
target_workspace_idx: usize,
|
||||
follow: bool,
|
||||
direction: Option<OperationDirection>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = self
|
||||
.focused_workspace_mut()
|
||||
.ok_or_eyre("there is no workspace")?;
|
||||
@@ -469,7 +469,7 @@ impl Monitor {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_workspace(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
tracing::info!("focusing workspace");
|
||||
|
||||
{
|
||||
@@ -500,7 +500,7 @@ impl Monitor {
|
||||
self.workspaces().len()
|
||||
}
|
||||
|
||||
pub fn update_focused_workspace(&mut self, offset: Option<Rect>) -> Result<()> {
|
||||
pub fn update_focused_workspace(&mut self, offset: Option<Rect>) -> eyre::Result<()> {
|
||||
let offset = if self.work_area_offset.is_some() {
|
||||
self.work_area_offset
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use color_eyre::eyre::WrapErr;
|
||||
use komorebi_themes::colour::Rgb;
|
||||
@@ -194,7 +194,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
message: SocketMessage,
|
||||
mut reply: impl std::io::Write,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
if let Some(virtual_desktop_id) = &self.virtual_desktop_id
|
||||
&& let Some(id) = current_virtual_desktop()
|
||||
&& id != *virtual_desktop_id
|
||||
@@ -2283,7 +2283,10 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_commands_uds(wm: &Arc<Mutex<WindowManager>>, mut stream: UnixStream) -> Result<()> {
|
||||
pub fn read_commands_uds(
|
||||
wm: &Arc<Mutex<WindowManager>>,
|
||||
mut stream: UnixStream,
|
||||
) -> eyre::Result<()> {
|
||||
let reader = BufReader::new(stream.try_clone()?);
|
||||
// TODO(raggi): while this processes more than one command, if there are
|
||||
// replies there is no clearly defined protocol for framing yet - it's
|
||||
@@ -2324,7 +2327,7 @@ pub fn read_commands_tcp(
|
||||
wm: &Arc<Mutex<WindowManager>>,
|
||||
stream: &mut TcpStream,
|
||||
addr: &str,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let mut reader = BufReader::new(stream.try_clone()?);
|
||||
|
||||
loop {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use crossbeam_utils::atomic::AtomicConsume;
|
||||
use parking_lot::Mutex;
|
||||
@@ -65,7 +65,7 @@ pub fn listen_for_events(wm: Arc<Mutex<WindowManager>>) {
|
||||
impl WindowManager {
|
||||
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
|
||||
#[tracing::instrument(skip(self, event), fields(event = event.title(), winevent = event.winevent(), hwnd = event.hwnd()))]
|
||||
pub fn process_event(&mut self, event: WindowManagerEvent) -> Result<()> {
|
||||
pub fn process_event(&mut self, event: WindowManagerEvent) -> eyre::Result<()> {
|
||||
if self.is_paused {
|
||||
tracing::trace!("ignoring while paused");
|
||||
return Ok(());
|
||||
|
||||
@@ -87,7 +87,7 @@ use crate::window_manager::WindowManager;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use crate::workspace::Workspace;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use crossbeam_channel::Receiver;
|
||||
use hotwatch::EventKind;
|
||||
use hotwatch::Hotwatch;
|
||||
@@ -952,7 +952,7 @@ impl From<&WindowManager> for StaticConfig {
|
||||
|
||||
impl StaticConfig {
|
||||
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
|
||||
fn apply_globals(&mut self) -> Result<()> {
|
||||
fn apply_globals(&mut self) -> eyre::Result<()> {
|
||||
*FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock() = self
|
||||
.floating_window_aspect_ratio
|
||||
.unwrap_or(AspectRatio::Predefined(PredefinedAspectRatio::Standard));
|
||||
@@ -1240,11 +1240,11 @@ impl StaticConfig {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_raw(raw: &str) -> Result<Self> {
|
||||
pub fn read_raw(raw: &str) -> eyre::Result<Self> {
|
||||
Ok(serde_json::from_str(raw)?)
|
||||
}
|
||||
|
||||
pub fn read(path: &PathBuf) -> Result<Self> {
|
||||
pub fn read(path: &PathBuf) -> eyre::Result<Self> {
|
||||
let content = std::fs::read_to_string(path)?;
|
||||
serde_json::from_str(&content).map_err(Into::into)
|
||||
}
|
||||
@@ -1254,7 +1254,7 @@ impl StaticConfig {
|
||||
path: &PathBuf,
|
||||
incoming: Receiver<WindowManagerEvent>,
|
||||
unix_listener: Option<UnixListener>,
|
||||
) -> Result<WindowManager> {
|
||||
) -> eyre::Result<WindowManager> {
|
||||
let mut value = Self::read(path)?;
|
||||
value.apply_globals()?;
|
||||
|
||||
@@ -1349,7 +1349,7 @@ impl StaticConfig {
|
||||
Ok(wm)
|
||||
}
|
||||
|
||||
pub fn postload(path: &PathBuf, wm: &Arc<Mutex<WindowManager>>) -> Result<()> {
|
||||
pub fn postload(path: &PathBuf, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()> {
|
||||
let mut value = Self::read(path)?;
|
||||
let mut wm = wm.lock();
|
||||
|
||||
@@ -1521,7 +1521,7 @@ impl StaticConfig {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reload(path: &PathBuf, wm: &mut WindowManager) -> Result<()> {
|
||||
pub fn reload(path: &PathBuf, wm: &mut WindowManager) -> eyre::Result<()> {
|
||||
let mut value = Self::read(path)?;
|
||||
|
||||
value.apply_globals()?;
|
||||
@@ -1728,7 +1728,7 @@ fn populate_option(
|
||||
entry: &mut ApplicationConfiguration,
|
||||
identifiers: &mut Vec<MatchingRule>,
|
||||
regex_identifiers: &mut HashMap<String, Regex>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
if entry.identifier.matching_strategy.is_none() {
|
||||
entry.identifier.matching_strategy = Option::from(MatchingStrategy::Legacy);
|
||||
}
|
||||
@@ -1754,7 +1754,7 @@ fn populate_rules(
|
||||
matching_rules: &mut Vec<MatchingRule>,
|
||||
identifiers: &mut Vec<MatchingRule>,
|
||||
regex_identifiers: &mut HashMap<String, Regex>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
for matching_rule in matching_rules {
|
||||
if !identifiers.contains(matching_rule) {
|
||||
match matching_rule {
|
||||
@@ -1800,7 +1800,7 @@ fn handle_asc_file(
|
||||
transparency_blacklist: &mut Vec<MatchingRule>,
|
||||
slow_application_identifiers: &mut Vec<MatchingRule>,
|
||||
regex_identifiers: &mut HashMap<String, Regex>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
match path.extension() {
|
||||
None => {}
|
||||
Some(ext) => match ext.to_string_lossy().to_string().as_str() {
|
||||
|
||||
@@ -40,7 +40,6 @@ use crate::transparency_manager;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::windows_api;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use crossbeam_utils::atomic::AtomicConsume;
|
||||
use regex::Regex;
|
||||
@@ -128,7 +127,7 @@ impl Display for Window {
|
||||
}
|
||||
|
||||
impl Serialize for Window {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> eyre::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
@@ -193,14 +192,14 @@ impl RenderDispatcher for MovementRenderDispatcher {
|
||||
new_animation_key(MovementRenderDispatcher::PREFIX, self.hwnd.to_string())
|
||||
}
|
||||
|
||||
fn pre_render(&self) -> Result<()> {
|
||||
fn pre_render(&self) -> eyre::Result<()> {
|
||||
stackbar_manager::STACKBAR_TEMPORARILY_DISABLED.store(true, Ordering::SeqCst);
|
||||
stackbar_manager::send_notification();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render(&self, progress: f64) -> Result<()> {
|
||||
fn render(&self, progress: f64) -> eyre::Result<()> {
|
||||
let new_rect = self.start_rect.lerp(self.target_rect, progress, self.style);
|
||||
|
||||
// we don't check WINDOW_HANDLING_BEHAVIOUR here because animations
|
||||
@@ -211,7 +210,7 @@ impl RenderDispatcher for MovementRenderDispatcher {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn post_render(&self) -> Result<()> {
|
||||
fn post_render(&self) -> eyre::Result<()> {
|
||||
// we don't add the async_window_pos flag here because animations
|
||||
// are always run on a separate thread
|
||||
WindowsApi::position_window(self.hwnd, &self.target_rect, self.top, false)?;
|
||||
@@ -267,7 +266,7 @@ impl RenderDispatcher for TransparencyRenderDispatcher {
|
||||
new_animation_key(TransparencyRenderDispatcher::PREFIX, self.hwnd.to_string())
|
||||
}
|
||||
|
||||
fn pre_render(&self) -> Result<()> {
|
||||
fn pre_render(&self) -> eyre::Result<()> {
|
||||
//transparent
|
||||
if !self.is_opaque {
|
||||
let window = Window::from(self.hwnd);
|
||||
@@ -279,7 +278,7 @@ impl RenderDispatcher for TransparencyRenderDispatcher {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render(&self, progress: f64) -> Result<()> {
|
||||
fn render(&self, progress: f64) -> eyre::Result<()> {
|
||||
WindowsApi::set_transparent(
|
||||
self.hwnd,
|
||||
self.start_opacity
|
||||
@@ -287,7 +286,7 @@ impl RenderDispatcher for TransparencyRenderDispatcher {
|
||||
)
|
||||
}
|
||||
|
||||
fn post_render(&self) -> Result<()> {
|
||||
fn post_render(&self) -> eyre::Result<()> {
|
||||
//opaque
|
||||
if self.is_opaque {
|
||||
let window = Window::from(self.hwnd);
|
||||
@@ -346,7 +345,7 @@ impl Window {
|
||||
HWND(windows_api::as_ptr!(self.hwnd))
|
||||
}
|
||||
|
||||
pub fn move_to_area(&mut self, current_area: &Rect, target_area: &Rect) -> Result<()> {
|
||||
pub fn move_to_area(&mut self, current_area: &Rect, target_area: &Rect) -> eyre::Result<()> {
|
||||
let current_rect = WindowsApi::window_rect(self.hwnd)?;
|
||||
let x_diff = target_area.left - current_area.left;
|
||||
let y_diff = target_area.top - current_area.top;
|
||||
@@ -413,7 +412,7 @@ impl Window {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn center(&mut self, work_area: &Rect, resize: bool) -> Result<()> {
|
||||
pub fn center(&mut self, work_area: &Rect, resize: bool) -> eyre::Result<()> {
|
||||
let (target_width, target_height) = if resize {
|
||||
let (aspect_ratio_width, aspect_ratio_height) = FLOATING_WINDOW_TOGGLE_ASPECT_RATIO
|
||||
.lock()
|
||||
@@ -440,7 +439,7 @@ impl Window {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_position(&self, layout: &Rect, top: bool) -> Result<()> {
|
||||
pub fn set_position(&self, layout: &Rect, top: bool) -> eyre::Result<()> {
|
||||
let window_rect = WindowsApi::window_rect(self.hwnd)?;
|
||||
|
||||
if window_rect.eq(layout) {
|
||||
@@ -538,7 +537,7 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(self) -> Result<()> {
|
||||
pub fn close(self) -> eyre::Result<()> {
|
||||
WindowsApi::close_window(self.hwnd)
|
||||
}
|
||||
|
||||
@@ -566,7 +565,7 @@ impl Window {
|
||||
WindowsApi::unmaximize_window(self.hwnd);
|
||||
}
|
||||
|
||||
pub fn focus(self, mouse_follows_focus: bool) -> Result<()> {
|
||||
pub fn focus(self, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
// If the target window is already focused, do nothing.
|
||||
if let Ok(ihwnd) = WindowsApi::foreground_window()
|
||||
&& ihwnd == self.hwnd
|
||||
@@ -593,7 +592,7 @@ impl Window {
|
||||
WindowsApi::foreground_window().unwrap_or_default() == self.hwnd
|
||||
}
|
||||
|
||||
pub fn transparent(self) -> Result<()> {
|
||||
pub fn transparent(self) -> eyre::Result<()> {
|
||||
let animation_enabled = ANIMATION_ENABLED_PER_ANIMATION.lock();
|
||||
let transparent_enabled = animation_enabled.get(&TransparencyRenderDispatcher::PREFIX);
|
||||
|
||||
@@ -631,7 +630,7 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opaque(self) -> Result<()> {
|
||||
pub fn opaque(self) -> eyre::Result<()> {
|
||||
let animation_enabled = ANIMATION_ENABLED_PER_ANIMATION.lock();
|
||||
let transparent_enabled = animation_enabled.get(&TransparencyRenderDispatcher::PREFIX);
|
||||
|
||||
@@ -666,49 +665,49 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_accent(self, colour: u32) -> Result<()> {
|
||||
pub fn set_accent(self, colour: u32) -> eyre::Result<()> {
|
||||
WindowsApi::set_window_accent(self.hwnd, Some(colour))
|
||||
}
|
||||
|
||||
pub fn remove_accent(self) -> Result<()> {
|
||||
pub fn remove_accent(self) -> eyre::Result<()> {
|
||||
WindowsApi::set_window_accent(self.hwnd, None)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn update_style(self, style: &WindowStyle) -> Result<()> {
|
||||
pub fn update_style(self, style: &WindowStyle) -> eyre::Result<()> {
|
||||
WindowsApi::update_style(self.hwnd, isize::try_from(style.bits())?)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn update_style(self, style: &WindowStyle) -> Result<()> {
|
||||
pub fn update_style(self, style: &WindowStyle) -> eyre::Result<()> {
|
||||
WindowsApi::update_style(self.hwnd, i32::try_from(style.bits())?)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn update_ex_style(self, style: &ExtendedWindowStyle) -> Result<()> {
|
||||
pub fn update_ex_style(self, style: &ExtendedWindowStyle) -> eyre::Result<()> {
|
||||
WindowsApi::update_ex_style(self.hwnd, isize::try_from(style.bits())?)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn update_ex_style(self, style: &ExtendedWindowStyle) -> Result<()> {
|
||||
pub fn update_ex_style(self, style: &ExtendedWindowStyle) -> eyre::Result<()> {
|
||||
WindowsApi::update_ex_style(self.hwnd, i32::try_from(style.bits())?)
|
||||
}
|
||||
|
||||
pub fn style(self) -> Result<WindowStyle> {
|
||||
pub fn style(self) -> eyre::Result<WindowStyle> {
|
||||
let bits = u32::try_from(WindowsApi::gwl_style(self.hwnd)?)?;
|
||||
Ok(WindowStyle::from_bits_truncate(bits))
|
||||
}
|
||||
|
||||
pub fn ex_style(self) -> Result<ExtendedWindowStyle> {
|
||||
pub fn ex_style(self) -> eyre::Result<ExtendedWindowStyle> {
|
||||
let bits = u32::try_from(WindowsApi::gwl_ex_style(self.hwnd)?)?;
|
||||
Ok(ExtendedWindowStyle::from_bits_truncate(bits))
|
||||
}
|
||||
|
||||
pub fn title(self) -> Result<String> {
|
||||
pub fn title(self) -> eyre::Result<String> {
|
||||
WindowsApi::window_text_w(self.hwnd)
|
||||
}
|
||||
|
||||
pub fn path(self) -> Result<String> {
|
||||
pub fn path(self) -> eyre::Result<String> {
|
||||
let (process_id, _) = WindowsApi::window_thread_process_id(self.hwnd);
|
||||
let handle = WindowsApi::process_handle(process_id)?;
|
||||
let path = WindowsApi::exe_path(handle);
|
||||
@@ -716,7 +715,7 @@ impl Window {
|
||||
path
|
||||
}
|
||||
|
||||
pub fn exe(self) -> Result<String> {
|
||||
pub fn exe(self) -> eyre::Result<String> {
|
||||
let (process_id, _) = WindowsApi::window_thread_process_id(self.hwnd);
|
||||
let handle = WindowsApi::process_handle(process_id)?;
|
||||
let exe = WindowsApi::exe(handle);
|
||||
@@ -729,11 +728,11 @@ impl Window {
|
||||
process_id
|
||||
}
|
||||
|
||||
pub fn class(self) -> Result<String> {
|
||||
pub fn class(self) -> eyre::Result<String> {
|
||||
WindowsApi::real_window_class_w(self.hwnd)
|
||||
}
|
||||
|
||||
pub fn is_cloaked(self) -> Result<bool> {
|
||||
pub fn is_cloaked(self) -> eyre::Result<bool> {
|
||||
WindowsApi::is_window_cloaked(self.hwnd)
|
||||
}
|
||||
|
||||
@@ -741,14 +740,14 @@ impl Window {
|
||||
WindowsApi::is_window(self.hwnd)
|
||||
}
|
||||
|
||||
pub fn remove_title_bar(self) -> Result<()> {
|
||||
pub fn remove_title_bar(self) -> eyre::Result<()> {
|
||||
let mut style = self.style()?;
|
||||
style.remove(WindowStyle::CAPTION);
|
||||
style.remove(WindowStyle::THICKFRAME);
|
||||
self.update_style(&style)
|
||||
}
|
||||
|
||||
pub fn add_title_bar(self) -> Result<()> {
|
||||
pub fn add_title_bar(self) -> eyre::Result<()> {
|
||||
let mut style = self.style()?;
|
||||
style.insert(WindowStyle::CAPTION);
|
||||
style.insert(WindowStyle::THICKFRAME);
|
||||
@@ -759,7 +758,7 @@ impl Window {
|
||||
/// it. Use raise_and_focus_window to activate and focus a window.
|
||||
/// It also checks if there is a border attached to this window and if it is
|
||||
/// it raises it as well.
|
||||
pub fn raise(self) -> Result<()> {
|
||||
pub fn raise(self) -> eyre::Result<()> {
|
||||
WindowsApi::raise_window(self.hwnd)?;
|
||||
if let Some(border_info) = crate::border_manager::window_border(self.hwnd) {
|
||||
WindowsApi::raise_window(border_info.border_hwnd)?;
|
||||
@@ -771,7 +770,7 @@ impl Window {
|
||||
/// it.
|
||||
/// It also checks if there is a border attached to this window and if it is
|
||||
/// it lowers it as well.
|
||||
pub fn lower(self) -> Result<()> {
|
||||
pub fn lower(self) -> eyre::Result<()> {
|
||||
WindowsApi::lower_window(self.hwnd)?;
|
||||
if let Some(border_info) = crate::border_manager::window_border(self.hwnd) {
|
||||
WindowsApi::lower_window(border_info.border_hwnd)?;
|
||||
@@ -784,7 +783,7 @@ impl Window {
|
||||
self,
|
||||
event: Option<WindowManagerEvent>,
|
||||
debug: &mut RuleDebug,
|
||||
) -> Result<bool> {
|
||||
) -> eyre::Result<bool> {
|
||||
if !self.is_window() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use color_eyre::eyre::bail;
|
||||
use crossbeam_channel::Receiver;
|
||||
@@ -413,7 +413,7 @@ impl WindowManager {
|
||||
pub fn new(
|
||||
incoming: Receiver<WindowManagerEvent>,
|
||||
custom_socket_path: Option<PathBuf>,
|
||||
) -> Result<Self> {
|
||||
) -> eyre::Result<Self> {
|
||||
let socket = custom_socket_path.unwrap_or_else(|| DATA_DIR.join("komorebi.sock"));
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
@@ -454,7 +454,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn init(&mut self) -> Result<()> {
|
||||
pub fn init(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("initialising");
|
||||
WindowsApi::load_monitor_information(self)?;
|
||||
WindowsApi::load_workspace_information(&mut self.monitors)
|
||||
@@ -611,7 +611,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn reload_static_configuration(&mut self, pathbuf: &PathBuf) -> Result<()> {
|
||||
pub fn reload_static_configuration(&mut self, pathbuf: &PathBuf) -> eyre::Result<()> {
|
||||
tracing::info!("reloading static configuration");
|
||||
StaticConfig::reload(pathbuf, self)
|
||||
}
|
||||
@@ -691,7 +691,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn watch_configuration(&mut self, enable: bool) -> Result<()> {
|
||||
pub fn watch_configuration(&mut self, enable: bool) -> eyre::Result<()> {
|
||||
let config_pwsh = HOME_DIR.join("komorebi.ps1");
|
||||
let config_ahk = HOME_DIR.join("komorebi.ahk");
|
||||
|
||||
@@ -704,7 +704,7 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure_watcher(&mut self, enable: bool, config: PathBuf) -> Result<()> {
|
||||
fn configure_watcher(&mut self, enable: bool, config: PathBuf) -> eyre::Result<()> {
|
||||
if enable {
|
||||
tracing::info!("watching configuration for changes: {}", config.display());
|
||||
// Always make absolutely sure that there isn't an already existing watch, because
|
||||
@@ -834,7 +834,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub fn enforce_workspace_rules(&mut self) -> Result<()> {
|
||||
pub fn enforce_workspace_rules(&mut self) -> eyre::Result<()> {
|
||||
let mut to_move = vec![];
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
@@ -1017,7 +1017,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn retile_all(&mut self, preserve_resize_dimensions: bool) -> Result<()> {
|
||||
pub fn retile_all(&mut self, preserve_resize_dimensions: bool) -> eyre::Result<()> {
|
||||
let offset = self.work_area_offset;
|
||||
|
||||
for monitor in self.monitors_mut() {
|
||||
@@ -1056,21 +1056,21 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn manage_focused_window(&mut self) -> Result<()> {
|
||||
pub fn manage_focused_window(&mut self) -> eyre::Result<()> {
|
||||
let hwnd = WindowsApi::foreground_window()?;
|
||||
let event = WindowManagerEvent::Manage(Window::from(hwnd));
|
||||
Ok(winevent_listener::event_tx().send(event)?)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn unmanage_focused_window(&mut self) -> Result<()> {
|
||||
pub fn unmanage_focused_window(&mut self) -> eyre::Result<()> {
|
||||
let hwnd = WindowsApi::foreground_window()?;
|
||||
let event = WindowManagerEvent::Unmanage(Window::from(hwnd));
|
||||
Ok(winevent_listener::event_tx().send(event)?)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn raise_window_at_cursor_pos(&mut self) -> Result<()> {
|
||||
pub fn raise_window_at_cursor_pos(&mut self) -> eyre::Result<()> {
|
||||
let mut hwnd = None;
|
||||
|
||||
let workspace = self.focused_workspace()?;
|
||||
@@ -1138,7 +1138,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
origin: (usize, usize, isize),
|
||||
target: (usize, usize, usize),
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let (origin_monitor_idx, origin_workspace_idx, w_hwnd) = origin;
|
||||
let (target_monitor_idx, target_workspace_idx, target_container_idx) = target;
|
||||
|
||||
@@ -1265,7 +1265,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
origin: (usize, usize, usize),
|
||||
target: (usize, usize, usize),
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let (origin_monitor_idx, origin_workspace_idx, origin_container_idx) = origin;
|
||||
let (target_monitor_idx, target_workspace_idx, target_container_idx) = target;
|
||||
|
||||
@@ -1301,7 +1301,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
origin: (usize, usize, usize),
|
||||
target: (usize, usize, usize),
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let (origin_monitor_idx, origin_workspace_idx, origin_container_idx) = origin;
|
||||
let (target_monitor_idx, target_workspace_idx, target_container_idx) = target;
|
||||
|
||||
@@ -1376,7 +1376,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
follow_focus: bool,
|
||||
trigger_focus: bool,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("updating");
|
||||
|
||||
let offset = self.work_area_offset;
|
||||
@@ -1453,7 +1453,7 @@ impl WindowManager {
|
||||
sizing: Sizing,
|
||||
delta: i32,
|
||||
update: bool,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let mut focused_monitor_work_area = self.focused_monitor_work_area()?;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -1627,7 +1627,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn stop(&mut self, ignore_restore: bool) -> Result<()> {
|
||||
pub fn stop(&mut self, ignore_restore: bool) -> eyre::Result<()> {
|
||||
tracing::info!(
|
||||
"received stop command, restoring all hidden windows and terminating process"
|
||||
);
|
||||
@@ -1661,7 +1661,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn restore_all_windows(&mut self, ignore_restore: bool) -> Result<()> {
|
||||
pub fn restore_all_windows(&mut self, ignore_restore: bool) -> eyre::Result<()> {
|
||||
tracing::info!("restoring all hidden windows");
|
||||
|
||||
let no_titlebar = NO_TITLEBAR.lock();
|
||||
@@ -1715,7 +1715,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn remove_all_accents(&mut self) -> Result<()> {
|
||||
pub fn remove_all_accents(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("removing all window accents");
|
||||
|
||||
for monitor in self.monitors() {
|
||||
@@ -1738,7 +1738,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn handle_unmanaged_window_behaviour(&self) -> Result<()> {
|
||||
fn handle_unmanaged_window_behaviour(&self) -> eyre::Result<()> {
|
||||
if matches!(
|
||||
self.unmanaged_window_operation_behaviour,
|
||||
OperationBehaviour::NoOp
|
||||
@@ -1760,7 +1760,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
@@ -1777,7 +1777,7 @@ impl WindowManager {
|
||||
workspace.apply_wallpaper(hmonitor, &monitor_wp)
|
||||
}
|
||||
|
||||
pub fn update_focused_workspace_by_monitor_idx(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn update_focused_workspace_by_monitor_idx(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
let offset = self.work_area_offset;
|
||||
|
||||
self.monitors_mut()
|
||||
@@ -1787,7 +1787,11 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn swap_monitor_workspaces(&mut self, first_idx: usize, second_idx: usize) -> Result<()> {
|
||||
pub fn swap_monitor_workspaces(
|
||||
&mut self,
|
||||
first_idx: usize,
|
||||
second_idx: usize,
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("swaping monitors");
|
||||
if first_idx == second_idx {
|
||||
return Ok(());
|
||||
@@ -1854,7 +1858,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn swap_focused_monitor(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn swap_focused_monitor(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
tracing::info!("swapping focused monitor");
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
@@ -1872,7 +1876,7 @@ impl WindowManager {
|
||||
workspace_idx: Option<usize>,
|
||||
follow: bool,
|
||||
move_direction: Option<OperationDirection>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("moving container");
|
||||
@@ -2006,7 +2010,7 @@ impl WindowManager {
|
||||
idx: usize,
|
||||
follow: bool,
|
||||
direction: Option<OperationDirection>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("moving container");
|
||||
@@ -2039,7 +2043,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_workspace_to_monitor(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn move_workspace_to_monitor(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
tracing::info!("moving workspace");
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let offset = self.work_area_offset;
|
||||
@@ -2067,7 +2071,7 @@ impl WindowManager {
|
||||
pub fn focus_floating_window_in_direction(
|
||||
&mut self,
|
||||
direction: OperationDirection,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let focused_workspace = self.focused_workspace_mut()?;
|
||||
|
||||
@@ -2320,7 +2324,10 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
pub fn focus_container_in_direction(
|
||||
&mut self,
|
||||
direction: OperationDirection,
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace()?;
|
||||
@@ -2486,7 +2493,7 @@ impl WindowManager {
|
||||
pub fn move_floating_window_in_direction(
|
||||
&mut self,
|
||||
direction: OperationDirection,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
let mut focused_monitor_work_area = self.focused_monitor_work_area()?;
|
||||
@@ -2560,7 +2567,10 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_in_direction(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
pub fn move_container_in_direction(
|
||||
&mut self,
|
||||
direction: OperationDirection,
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace()?;
|
||||
@@ -2737,7 +2747,7 @@ impl WindowManager {
|
||||
pub fn focus_floating_window_in_cycle_direction(
|
||||
&mut self,
|
||||
direction: CycleDirection,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
|
||||
@@ -2782,7 +2792,10 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container_in_cycle_direction(&mut self, direction: CycleDirection) -> Result<()> {
|
||||
pub fn focus_container_in_cycle_direction(
|
||||
&mut self,
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("focusing container");
|
||||
@@ -2819,7 +2832,10 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn move_container_in_cycle_direction(&mut self, direction: CycleDirection) -> Result<()> {
|
||||
pub fn move_container_in_cycle_direction(
|
||||
&mut self,
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -2840,7 +2856,10 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn cycle_container_window_in_direction(&mut self, direction: CycleDirection) -> Result<()> {
|
||||
pub fn cycle_container_window_in_direction(
|
||||
&mut self,
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("cycling container windows");
|
||||
@@ -2876,7 +2895,7 @@ impl WindowManager {
|
||||
pub fn cycle_container_window_index_in_direction(
|
||||
&mut self,
|
||||
direction: CycleDirection,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("cycling container window index");
|
||||
@@ -2909,7 +2928,7 @@ impl WindowManager {
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_container_window(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn focus_container_window(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("focusing container window at index {idx}");
|
||||
@@ -2943,7 +2962,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn stack_all(&mut self) -> Result<()> {
|
||||
pub fn stack_all(&mut self) -> eyre::Result<()> {
|
||||
self.unstack_all(false)?;
|
||||
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
@@ -2972,7 +2991,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn unstack_all(&mut self, update_workspace: bool) -> Result<()> {
|
||||
pub fn unstack_all(&mut self, update_workspace: bool) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
tracing::info!("unstacking all windows in container");
|
||||
|
||||
@@ -3010,7 +3029,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn add_window_to_container(&mut self, direction: OperationDirection) -> Result<()> {
|
||||
pub fn add_window_to_container(&mut self, direction: OperationDirection) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("adding window to container");
|
||||
@@ -3081,7 +3100,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_container_to_front(&mut self) -> Result<()> {
|
||||
pub fn promote_container_to_front(&mut self) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3098,7 +3117,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_focus_to_front(&mut self) -> Result<()> {
|
||||
pub fn promote_focus_to_front(&mut self) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3121,7 +3140,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn remove_window_from_container(&mut self) -> Result<()> {
|
||||
pub fn remove_window_from_container(&mut self) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
tracing::info!("removing window");
|
||||
@@ -3137,14 +3156,14 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_tiling(&mut self) -> Result<()> {
|
||||
pub fn toggle_tiling(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.tile = !workspace.tile;
|
||||
self.update_focused_workspace(false, false)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_float(&mut self, force_float: bool) -> Result<()> {
|
||||
pub fn toggle_float(&mut self, force_float: bool) -> eyre::Result<()> {
|
||||
let hwnd = WindowsApi::foreground_window()?;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
if workspace.monocle_container.is_some() {
|
||||
@@ -3172,7 +3191,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_lock(&mut self) -> Result<()> {
|
||||
pub fn toggle_lock(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
if let Some(container) = workspace.focused_container_mut() {
|
||||
// Toggle the locked flag
|
||||
@@ -3182,7 +3201,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn float_window(&mut self) -> Result<()> {
|
||||
pub fn float_window(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("floating window");
|
||||
|
||||
let work_area = self.focused_monitor_work_area()?;
|
||||
@@ -3206,7 +3225,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn unfloat_window(&mut self) -> Result<()> {
|
||||
pub fn unfloat_window(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("unfloating window");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3214,7 +3233,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_monocle(&mut self) -> Result<()> {
|
||||
pub fn toggle_monocle(&mut self) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace()?;
|
||||
@@ -3229,7 +3248,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn monocle_on(&mut self) -> Result<()> {
|
||||
pub fn monocle_on(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("enabling monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3247,7 +3266,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn monocle_off(&mut self) -> Result<()> {
|
||||
pub fn monocle_off(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("disabling monocle");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3264,7 +3283,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_maximize(&mut self) -> Result<()> {
|
||||
pub fn toggle_maximize(&mut self) -> eyre::Result<()> {
|
||||
self.handle_unmanaged_window_behaviour()?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3278,7 +3297,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn maximize_window(&mut self) -> Result<()> {
|
||||
pub fn maximize_window(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("maximizing windowj");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3286,7 +3305,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn unmaximize_window(&mut self) -> Result<()> {
|
||||
pub fn unmaximize_window(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("unmaximizing window");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3294,7 +3313,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn flip_layout(&mut self, layout_flip: Axis) -> Result<()> {
|
||||
pub fn flip_layout(&mut self, layout_flip: Axis) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
tracing::info!("flipping layout");
|
||||
@@ -3337,7 +3356,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn change_workspace_layout_default(&mut self, layout: DefaultLayout) -> Result<()> {
|
||||
pub fn change_workspace_layout_default(&mut self, layout: DefaultLayout) -> eyre::Result<()> {
|
||||
tracing::info!("changing layout");
|
||||
|
||||
let monitor_count = self.monitors().len();
|
||||
@@ -3371,7 +3390,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn cycle_layout(&mut self, direction: CycleDirection) -> Result<()> {
|
||||
pub fn cycle_layout(&mut self, direction: CycleDirection) -> eyre::Result<()> {
|
||||
tracing::info!("cycling layout");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3394,7 +3413,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn change_workspace_custom_layout<P>(&mut self, path: P) -> Result<()>
|
||||
pub fn change_workspace_custom_layout<P>(&mut self, path: P) -> eyre::Result<()>
|
||||
where
|
||||
P: AsRef<Path> + std::fmt::Debug,
|
||||
{
|
||||
@@ -3425,7 +3444,11 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn adjust_workspace_padding(&mut self, sizing: Sizing, adjustment: i32) -> Result<()> {
|
||||
pub fn adjust_workspace_padding(
|
||||
&mut self,
|
||||
sizing: Sizing,
|
||||
adjustment: i32,
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("adjusting workspace padding");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3440,7 +3463,11 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn adjust_container_padding(&mut self, sizing: Sizing, adjustment: i32) -> Result<()> {
|
||||
pub fn adjust_container_padding(
|
||||
&mut self,
|
||||
sizing: Sizing,
|
||||
adjustment: i32,
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("adjusting container padding");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -3460,7 +3487,7 @@ impl WindowManager {
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
tile: bool,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
@@ -3483,7 +3510,7 @@ impl WindowManager {
|
||||
workspace_idx: usize,
|
||||
at_container_count: usize,
|
||||
layout: DefaultLayout,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("setting workspace layout");
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
@@ -3521,7 +3548,7 @@ impl WindowManager {
|
||||
workspace_idx: usize,
|
||||
at_container_count: usize,
|
||||
path: P,
|
||||
) -> Result<()>
|
||||
) -> eyre::Result<()>
|
||||
where
|
||||
P: AsRef<Path> + std::fmt::Debug,
|
||||
{
|
||||
@@ -3562,7 +3589,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("setting workspace layout");
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
@@ -3597,7 +3624,7 @@ impl WindowManager {
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
layout: DefaultLayout,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("setting workspace layout");
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
@@ -3631,7 +3658,7 @@ impl WindowManager {
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
path: P,
|
||||
) -> Result<()>
|
||||
) -> eyre::Result<()>
|
||||
where
|
||||
P: AsRef<Path> + std::fmt::Debug,
|
||||
{
|
||||
@@ -3668,7 +3695,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
workspace_count: usize,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("ensuring workspace count");
|
||||
|
||||
let monitor = self
|
||||
@@ -3686,7 +3713,7 @@ impl WindowManager {
|
||||
&mut self,
|
||||
monitor_idx: usize,
|
||||
names: &Vec<String>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("ensuring workspace count");
|
||||
|
||||
let monitor = self
|
||||
@@ -3711,7 +3738,7 @@ impl WindowManager {
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
size: i32,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("setting workspace padding");
|
||||
|
||||
let monitor = self
|
||||
@@ -3735,7 +3762,7 @@ impl WindowManager {
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
name: String,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("setting workspace name");
|
||||
|
||||
let monitor = self
|
||||
@@ -3760,7 +3787,7 @@ impl WindowManager {
|
||||
monitor_idx: usize,
|
||||
workspace_idx: usize,
|
||||
size: i32,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
tracing::info!("setting container padding");
|
||||
|
||||
let monitor = self
|
||||
@@ -3778,14 +3805,14 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false, false)
|
||||
}
|
||||
|
||||
pub fn focused_monitor_size(&self) -> Result<Rect> {
|
||||
pub fn focused_monitor_size(&self) -> eyre::Result<Rect> {
|
||||
Ok(self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.size)
|
||||
}
|
||||
|
||||
pub fn focused_monitor_work_area(&self) -> Result<Rect> {
|
||||
pub fn focused_monitor_work_area(&self) -> eyre::Result<Rect> {
|
||||
Ok(self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
@@ -3793,7 +3820,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_monitor(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn focus_monitor(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
tracing::info!("focusing monitor");
|
||||
|
||||
if self.monitors().get(idx).is_some() {
|
||||
@@ -3851,28 +3878,28 @@ impl WindowManager {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn focused_workspace_idx(&self) -> Result<usize> {
|
||||
pub fn focused_workspace_idx(&self) -> eyre::Result<usize> {
|
||||
Ok(self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_idx())
|
||||
}
|
||||
|
||||
pub fn focused_workspace(&self) -> Result<&Workspace> {
|
||||
pub fn focused_workspace(&self) -> eyre::Result<&Workspace> {
|
||||
self.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace()
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_workspace_mut(&mut self) -> Result<&mut Workspace> {
|
||||
pub fn focused_workspace_mut(&mut self) -> eyre::Result<&mut Workspace> {
|
||||
self.focused_monitor_mut()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_mut()
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_workspace_idx_for_monitor_idx(&self, idx: usize) -> Result<usize> {
|
||||
pub fn focused_workspace_idx_for_monitor_idx(&self, idx: usize) -> eyre::Result<usize> {
|
||||
Ok(self
|
||||
.monitors()
|
||||
.get(idx)
|
||||
@@ -3880,7 +3907,7 @@ impl WindowManager {
|
||||
.focused_workspace_idx())
|
||||
}
|
||||
|
||||
pub fn focused_workspace_for_monitor_idx(&self, idx: usize) -> Result<&Workspace> {
|
||||
pub fn focused_workspace_for_monitor_idx(&self, idx: usize) -> eyre::Result<&Workspace> {
|
||||
self.monitors()
|
||||
.get(idx)
|
||||
.ok_or_eyre("there is no monitor at this index")?
|
||||
@@ -3888,7 +3915,10 @@ impl WindowManager {
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_workspace_for_monitor_idx_mut(&mut self, idx: usize) -> Result<&mut Workspace> {
|
||||
pub fn focused_workspace_for_monitor_idx_mut(
|
||||
&mut self,
|
||||
idx: usize,
|
||||
) -> eyre::Result<&mut Workspace> {
|
||||
self.monitors_mut()
|
||||
.get_mut(idx)
|
||||
.ok_or_eyre("there is no monitor at this index")?
|
||||
@@ -3897,7 +3927,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn focus_workspace(&mut self, idx: usize) -> Result<()> {
|
||||
pub fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
tracing::info!("focusing workspace");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
@@ -3929,7 +3959,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn new_workspace(&mut self) -> Result<()> {
|
||||
pub fn new_workspace(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("adding new workspace");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
@@ -3943,29 +3973,29 @@ impl WindowManager {
|
||||
self.update_focused_workspace(self.mouse_follows_focus, false)
|
||||
}
|
||||
|
||||
pub fn focused_container(&self) -> Result<&Container> {
|
||||
pub fn focused_container(&self) -> eyre::Result<&Container> {
|
||||
self.focused_workspace()?
|
||||
.focused_container()
|
||||
.ok_or_eyre("there is no container")
|
||||
}
|
||||
|
||||
pub fn focused_container_idx(&self) -> Result<usize> {
|
||||
pub fn focused_container_idx(&self) -> eyre::Result<usize> {
|
||||
Ok(self.focused_workspace()?.focused_container_idx())
|
||||
}
|
||||
|
||||
pub fn focused_container_mut(&mut self) -> Result<&mut Container> {
|
||||
pub fn focused_container_mut(&mut self) -> eyre::Result<&mut Container> {
|
||||
self.focused_workspace_mut()?
|
||||
.focused_container_mut()
|
||||
.ok_or_eyre("there is no container")
|
||||
}
|
||||
|
||||
pub fn focused_window(&self) -> Result<&Window> {
|
||||
pub fn focused_window(&self) -> eyre::Result<&Window> {
|
||||
self.focused_container()?
|
||||
.focused_window()
|
||||
.ok_or_eyre("there is no window")
|
||||
}
|
||||
|
||||
fn focused_window_mut(&mut self) -> Result<&mut Window> {
|
||||
fn focused_window_mut(&mut self) -> eyre::Result<&mut Window> {
|
||||
self.focused_container_mut()?
|
||||
.focused_window_mut()
|
||||
.ok_or_eyre("there is no window")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::Error;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use color_eyre::eyre::bail;
|
||||
@@ -207,7 +207,7 @@ impl<T, E> From<WindowsResult<T, E>> for Result<T, E> {
|
||||
}
|
||||
|
||||
pub trait ProcessWindowsCrateResult<T> {
|
||||
fn process(self) -> Result<T>;
|
||||
fn process(self) -> eyre::Result<T>;
|
||||
}
|
||||
|
||||
macro_rules! impl_process_windows_crate_integer_wrapper_result {
|
||||
@@ -215,7 +215,7 @@ macro_rules! impl_process_windows_crate_integer_wrapper_result {
|
||||
paste::paste! {
|
||||
$(
|
||||
impl ProcessWindowsCrateResult<$deref> for $input {
|
||||
fn process(self) -> Result<$deref> {
|
||||
fn process(self) -> eyre::Result<$deref> {
|
||||
if self == $input(std::ptr::null_mut()) {
|
||||
Err(std::io::Error::last_os_error().into())
|
||||
} else {
|
||||
@@ -233,7 +233,7 @@ impl_process_windows_crate_integer_wrapper_result!(
|
||||
);
|
||||
|
||||
impl<T> ProcessWindowsCrateResult<T> for WindowsCrateResult<T> {
|
||||
fn process(self) -> Result<T> {
|
||||
fn process(self) -> eyre::Result<T> {
|
||||
match self {
|
||||
Ok(value) => Ok(value),
|
||||
Err(error) => Err(error.into()),
|
||||
@@ -247,13 +247,13 @@ impl WindowsApi {
|
||||
pub fn enum_display_monitors(
|
||||
callback: MONITORENUMPROC,
|
||||
callback_data_address: isize,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
unsafe { EnumDisplayMonitors(None, None, callback, LPARAM(callback_data_address)) }
|
||||
.ok()
|
||||
.process()
|
||||
}
|
||||
|
||||
pub fn valid_hmonitors() -> Result<Vec<(String, isize)>> {
|
||||
pub fn valid_hmonitors() -> eyre::Result<Vec<(String, isize)>> {
|
||||
Ok(win32_display_data::connected_displays_all()
|
||||
.flatten()
|
||||
.map(|d| {
|
||||
@@ -265,7 +265,7 @@ impl WindowsApi {
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
pub fn load_monitor_information(wm: &mut WindowManager) -> Result<()> {
|
||||
pub fn load_monitor_information(wm: &mut WindowManager) -> eyre::Result<()> {
|
||||
let monitors = &mut wm.monitors;
|
||||
let monitor_usr_idx_map = &mut wm.monitor_usr_idx_map;
|
||||
|
||||
@@ -406,11 +406,11 @@ impl WindowsApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enum_windows(callback: WNDENUMPROC, callback_data_address: isize) -> Result<()> {
|
||||
pub fn enum_windows(callback: WNDENUMPROC, callback_data_address: isize) -> eyre::Result<()> {
|
||||
unsafe { EnumWindows(callback, LPARAM(callback_data_address)) }.process()
|
||||
}
|
||||
|
||||
pub fn load_workspace_information(monitors: &mut Ring<Monitor>) -> Result<()> {
|
||||
pub fn load_workspace_information(monitors: &mut Ring<Monitor>) -> eyre::Result<()> {
|
||||
for monitor in monitors.elements_mut() {
|
||||
let monitor_name = monitor.name.clone();
|
||||
if let Some(workspace) = monitor.workspaces_mut().front_mut() {
|
||||
@@ -445,7 +445,7 @@ impl WindowsApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn allow_set_foreground_window(process_id: u32) -> Result<()> {
|
||||
pub fn allow_set_foreground_window(process_id: u32) -> eyre::Result<()> {
|
||||
unsafe { AllowSetForegroundWindow(process_id) }.process()
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ impl WindowsApi {
|
||||
unsafe { MonitorFromWindow(HWND(as_ptr!(hwnd)), MONITOR_DEFAULTTONEAREST) }.0 as isize
|
||||
}
|
||||
|
||||
pub fn monitor_name_from_window(hwnd: isize) -> Result<String> {
|
||||
pub fn monitor_name_from_window(hwnd: isize) -> eyre::Result<String> {
|
||||
// MONITOR_DEFAULTTONEAREST ensures that the return value will never be NULL
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-monitorfromwindow
|
||||
Ok(Self::monitor(
|
||||
@@ -479,7 +479,7 @@ impl WindowsApi {
|
||||
layout: &Rect,
|
||||
top: bool,
|
||||
with_async_window_pos: bool,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
let hwnd = HWND(as_ptr!(hwnd));
|
||||
|
||||
let mut flags = SetWindowPosition::NO_ACTIVATE
|
||||
@@ -530,13 +530,13 @@ impl WindowsApi {
|
||||
Self::set_window_pos(hwnd, &rect, HWND_TOP, flags.bits())
|
||||
}
|
||||
|
||||
pub fn bring_window_to_top(hwnd: isize) -> Result<()> {
|
||||
pub fn bring_window_to_top(hwnd: isize) -> eyre::Result<()> {
|
||||
unsafe { BringWindowToTop(HWND(as_ptr!(hwnd))) }.process()
|
||||
}
|
||||
|
||||
/// Raise the window to the top of the Z order, but do not activate or focus
|
||||
/// it. Use raise_and_focus_window to activate and focus a window.
|
||||
pub fn raise_window(hwnd: isize) -> Result<()> {
|
||||
pub fn raise_window(hwnd: isize) -> eyre::Result<()> {
|
||||
let mut flags = SetWindowPosition::NO_MOVE
|
||||
| SetWindowPosition::NO_SIZE
|
||||
| SetWindowPosition::NO_ACTIVATE
|
||||
@@ -560,7 +560,7 @@ impl WindowsApi {
|
||||
|
||||
/// Lower the window to the bottom of the Z order, but do not activate or focus
|
||||
/// it.
|
||||
pub fn lower_window(hwnd: isize) -> Result<()> {
|
||||
pub fn lower_window(hwnd: isize) -> eyre::Result<()> {
|
||||
let mut flags = SetWindowPosition::NO_MOVE
|
||||
| SetWindowPosition::NO_SIZE
|
||||
| SetWindowPosition::NO_ACTIVATE
|
||||
@@ -582,7 +582,7 @@ impl WindowsApi {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_border_pos(hwnd: isize, layout: &Rect, position: isize) -> Result<()> {
|
||||
pub fn set_border_pos(hwnd: isize, layout: &Rect, position: isize) -> eyre::Result<()> {
|
||||
let mut flags = SetWindowPosition::NO_SEND_CHANGING
|
||||
| SetWindowPosition::NO_ACTIVATE
|
||||
| SetWindowPosition::NO_REDRAW
|
||||
@@ -604,7 +604,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
/// set_window_pos calls SetWindowPos without any accounting for Window decorations.
|
||||
fn set_window_pos(hwnd: HWND, layout: &Rect, position: HWND, flags: u32) -> Result<()> {
|
||||
fn set_window_pos(hwnd: HWND, layout: &Rect, position: HWND, flags: u32) -> eyre::Result<()> {
|
||||
unsafe {
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
@@ -620,7 +620,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
/// move_windows calls MoveWindow, but cannot be called with async window pos, so it might hang
|
||||
pub fn move_window(hwnd: isize, layout: &Rect, repaint: bool) -> Result<()> {
|
||||
pub fn move_window(hwnd: isize, layout: &Rect, repaint: bool) -> eyre::Result<()> {
|
||||
let hwnd = HWND(as_ptr!(hwnd));
|
||||
|
||||
let shadow_rect = Self::shadow_rect(hwnd).unwrap_or_default();
|
||||
@@ -655,11 +655,11 @@ impl WindowsApi {
|
||||
Self::show_window(hwnd, SW_MINIMIZE);
|
||||
}
|
||||
|
||||
fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
|
||||
fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> eyre::Result<()> {
|
||||
unsafe { PostMessageW(Option::from(hwnd), message, wparam, lparam) }.process()
|
||||
}
|
||||
|
||||
pub fn close_window(hwnd: isize) -> Result<()> {
|
||||
pub fn close_window(hwnd: isize) -> eyre::Result<()> {
|
||||
if Self::post_message(HWND(as_ptr!(hwnd)), WM_CLOSE, WPARAM(0), LPARAM(0)).is_err() {
|
||||
bail!("could not close window");
|
||||
}
|
||||
@@ -683,11 +683,11 @@ impl WindowsApi {
|
||||
Self::show_window(hwnd, SW_MAXIMIZE);
|
||||
}
|
||||
|
||||
pub fn foreground_window() -> Result<isize> {
|
||||
pub fn foreground_window() -> eyre::Result<isize> {
|
||||
unsafe { GetForegroundWindow() }.process()
|
||||
}
|
||||
|
||||
pub fn raise_and_focus_window(hwnd: isize) -> Result<()> {
|
||||
pub fn raise_and_focus_window(hwnd: isize) -> eyre::Result<()> {
|
||||
let event = [INPUT {
|
||||
r#type: INPUT_MOUSE,
|
||||
..Default::default()
|
||||
@@ -715,20 +715,20 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn top_window() -> Result<isize> {
|
||||
pub fn top_window() -> eyre::Result<isize> {
|
||||
unsafe { GetTopWindow(None)? }.process()
|
||||
}
|
||||
|
||||
pub fn desktop_window() -> Result<isize> {
|
||||
pub fn desktop_window() -> eyre::Result<isize> {
|
||||
unsafe { GetDesktopWindow() }.process()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn next_window(hwnd: isize) -> Result<isize> {
|
||||
pub fn next_window(hwnd: isize) -> eyre::Result<isize> {
|
||||
unsafe { GetWindow(HWND(as_ptr!(hwnd)), GW_HWNDNEXT)? }.process()
|
||||
}
|
||||
|
||||
pub fn alt_tab_windows() -> Result<Vec<Window>> {
|
||||
pub fn alt_tab_windows() -> eyre::Result<Vec<Window>> {
|
||||
let mut hwnds = vec![];
|
||||
Self::enum_windows(
|
||||
Some(windows_callbacks::alt_tab_windows),
|
||||
@@ -739,7 +739,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn top_visible_window() -> Result<isize> {
|
||||
pub fn top_visible_window() -> eyre::Result<isize> {
|
||||
let hwnd = Self::top_window()?;
|
||||
let mut next_hwnd = hwnd;
|
||||
|
||||
@@ -754,7 +754,7 @@ impl WindowsApi {
|
||||
bail!("could not find next window")
|
||||
}
|
||||
|
||||
pub fn window_rect(hwnd: isize) -> Result<Rect> {
|
||||
pub fn window_rect(hwnd: isize) -> eyre::Result<Rect> {
|
||||
let mut rect = unsafe { std::mem::zeroed() };
|
||||
|
||||
if Self::dwm_get_window_attribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &mut rect).is_ok() {
|
||||
@@ -773,7 +773,7 @@ impl WindowsApi {
|
||||
/// the window painted region. The four values in the returned Rect can be
|
||||
/// added to a position rect to compute a size for set_window_pos that will
|
||||
/// fill the target area, ignoring shadows.
|
||||
fn shadow_rect(hwnd: HWND) -> Result<Rect> {
|
||||
fn shadow_rect(hwnd: HWND) -> eyre::Result<Rect> {
|
||||
let window_rect = Self::window_rect(hwnd.0 as isize)?;
|
||||
|
||||
let mut srect = Default::default();
|
||||
@@ -808,26 +808,26 @@ impl WindowsApi {
|
||||
let _ = Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
}
|
||||
fn set_cursor_pos(x: i32, y: i32) -> Result<()> {
|
||||
fn set_cursor_pos(x: i32, y: i32) -> eyre::Result<()> {
|
||||
unsafe { SetCursorPos(x, y) }.process()
|
||||
}
|
||||
|
||||
pub fn cursor_pos() -> Result<POINT> {
|
||||
pub fn cursor_pos() -> eyre::Result<POINT> {
|
||||
let mut cursor_pos = POINT::default();
|
||||
unsafe { GetCursorPos(&mut cursor_pos) }.process()?;
|
||||
|
||||
Ok(cursor_pos)
|
||||
}
|
||||
|
||||
pub fn window_from_point(point: POINT) -> Result<isize> {
|
||||
pub fn window_from_point(point: POINT) -> eyre::Result<isize> {
|
||||
unsafe { WindowFromPoint(point) }.process()
|
||||
}
|
||||
|
||||
pub fn window_at_cursor_pos() -> Result<isize> {
|
||||
pub fn window_at_cursor_pos() -> eyre::Result<isize> {
|
||||
Self::window_from_point(Self::cursor_pos()?)
|
||||
}
|
||||
|
||||
pub fn center_cursor_in_rect(rect: &Rect) -> Result<()> {
|
||||
pub fn center_cursor_in_rect(rect: &Rect) -> eyre::Result<()> {
|
||||
Self::set_cursor_pos(rect.left + (rect.right / 2), rect.top + (rect.bottom / 2))
|
||||
}
|
||||
|
||||
@@ -850,7 +850,7 @@ impl WindowsApi {
|
||||
unsafe { GetCurrentProcessId() }
|
||||
}
|
||||
|
||||
pub fn process_id_to_session_id() -> Result<u32> {
|
||||
pub fn process_id_to_session_id() -> eyre::Result<u32> {
|
||||
let process_id = Self::current_process_id();
|
||||
let mut session_id = 0;
|
||||
|
||||
@@ -868,7 +868,7 @@ impl WindowsApi {
|
||||
hwnd: HWND,
|
||||
index: WINDOW_LONG_PTR_INDEX,
|
||||
new_value: isize,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
SetWindowLongPtrW(hwnd, index, new_value)
|
||||
}))
|
||||
@@ -880,7 +880,7 @@ impl WindowsApi {
|
||||
hwnd: HWND,
|
||||
index: WINDOW_LONG_PTR_INDEX,
|
||||
new_value: i32,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
SetWindowLongPtrW(hwnd, index, new_value)
|
||||
}))
|
||||
@@ -888,27 +888,27 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn gwl_style(hwnd: isize) -> Result<isize> {
|
||||
pub fn gwl_style(hwnd: isize) -> eyre::Result<isize> {
|
||||
Self::window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_STYLE)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn gwl_style(hwnd: isize) -> Result<i32> {
|
||||
pub fn gwl_style(hwnd: isize) -> eyre::Result<i32> {
|
||||
Self::window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_STYLE)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn gwl_ex_style(hwnd: isize) -> Result<isize> {
|
||||
pub fn gwl_ex_style(hwnd: isize) -> eyre::Result<isize> {
|
||||
Self::window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_EXSTYLE)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn gwl_ex_style(hwnd: isize) -> Result<i32> {
|
||||
pub fn gwl_ex_style(hwnd: isize) -> eyre::Result<i32> {
|
||||
Self::window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_EXSTYLE)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
fn window_long_ptr_w(hwnd: HWND, index: WINDOW_LONG_PTR_INDEX) -> Result<isize> {
|
||||
fn window_long_ptr_w(hwnd: HWND, index: WINDOW_LONG_PTR_INDEX) -> eyre::Result<isize> {
|
||||
// Can return 0, which does not always mean that an error has occurred
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptrw
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
@@ -917,7 +917,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
fn window_long_ptr_w(hwnd: HWND, index: WINDOW_LONG_PTR_INDEX) -> Result<i32> {
|
||||
fn window_long_ptr_w(hwnd: HWND, index: WINDOW_LONG_PTR_INDEX) -> eyre::Result<i32> {
|
||||
// Can return 0, which does not always mean that an error has occurred
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptrw
|
||||
Result::from(WindowsResult::from(unsafe {
|
||||
@@ -926,26 +926,26 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn update_style(hwnd: isize, new_value: isize) -> Result<()> {
|
||||
pub fn update_style(hwnd: isize, new_value: isize) -> eyre::Result<()> {
|
||||
Self::set_window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_STYLE, new_value)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn update_style(hwnd: isize, new_value: i32) -> Result<()> {
|
||||
pub fn update_style(hwnd: isize, new_value: i32) -> eyre::Result<()> {
|
||||
Self::set_window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_STYLE, new_value)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn update_ex_style(hwnd: isize, new_value: isize) -> Result<()> {
|
||||
pub fn update_ex_style(hwnd: isize, new_value: isize) -> eyre::Result<()> {
|
||||
Self::set_window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_EXSTYLE, new_value)
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn update_ex_style(hwnd: isize, new_value: i32) -> Result<()> {
|
||||
pub fn update_ex_style(hwnd: isize, new_value: i32) -> eyre::Result<()> {
|
||||
Self::set_window_long_ptr_w(HWND(as_ptr!(hwnd)), GWL_EXSTYLE, new_value)
|
||||
}
|
||||
|
||||
pub fn window_text_w(hwnd: isize) -> Result<String> {
|
||||
pub fn window_text_w(hwnd: isize) -> eyre::Result<String> {
|
||||
let mut text: [u16; 512] = [0; 512];
|
||||
match WindowsResult::from(unsafe { GetWindowTextW(HWND(as_ptr!(hwnd)), &mut text) }) {
|
||||
WindowsResult::Ok(len) => {
|
||||
@@ -960,19 +960,19 @@ impl WindowsApi {
|
||||
access_rights: PROCESS_ACCESS_RIGHTS,
|
||||
inherit_handle: bool,
|
||||
process_id: u32,
|
||||
) -> Result<HANDLE> {
|
||||
) -> eyre::Result<HANDLE> {
|
||||
unsafe { OpenProcess(access_rights, inherit_handle, process_id) }.process()
|
||||
}
|
||||
|
||||
pub fn close_process(handle: HANDLE) -> Result<()> {
|
||||
pub fn close_process(handle: HANDLE) -> eyre::Result<()> {
|
||||
unsafe { CloseHandle(handle) }.process()
|
||||
}
|
||||
|
||||
pub fn process_handle(process_id: u32) -> Result<HANDLE> {
|
||||
pub fn process_handle(process_id: u32) -> eyre::Result<HANDLE> {
|
||||
Self::open_process(PROCESS_QUERY_INFORMATION, false, process_id)
|
||||
}
|
||||
|
||||
pub fn exe_path(handle: HANDLE) -> Result<String> {
|
||||
pub fn exe_path(handle: HANDLE) -> eyre::Result<String> {
|
||||
let mut len = 260_u32;
|
||||
let mut path: Vec<u16> = vec![0; len as usize];
|
||||
let text_ptr = path.as_mut_ptr();
|
||||
@@ -985,7 +985,7 @@ impl WindowsApi {
|
||||
Ok(String::from_utf16(&path[..len as usize])?)
|
||||
}
|
||||
|
||||
pub fn exe(handle: HANDLE) -> Result<String> {
|
||||
pub fn exe(handle: HANDLE) -> eyre::Result<String> {
|
||||
Ok(Self::exe_path(handle)?
|
||||
.split('\\')
|
||||
.next_back()
|
||||
@@ -993,7 +993,7 @@ impl WindowsApi {
|
||||
.to_string())
|
||||
}
|
||||
|
||||
pub fn real_window_class_w(hwnd: isize) -> Result<String> {
|
||||
pub fn real_window_class_w(hwnd: isize) -> eyre::Result<String> {
|
||||
const BUF_SIZE: usize = 512;
|
||||
let mut class: [u16; BUF_SIZE] = [0; BUF_SIZE];
|
||||
|
||||
@@ -1008,7 +1008,7 @@ impl WindowsApi {
|
||||
hwnd: isize,
|
||||
attribute: DWMWINDOWATTRIBUTE,
|
||||
value: &mut T,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
unsafe {
|
||||
DwmGetWindowAttribute(
|
||||
HWND(as_ptr!(hwnd)),
|
||||
@@ -1021,7 +1021,7 @@ impl WindowsApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_window_cloaked(hwnd: isize) -> Result<bool> {
|
||||
pub fn is_window_cloaked(hwnd: isize) -> eyre::Result<bool> {
|
||||
let mut cloaked: u32 = 0;
|
||||
Self::dwm_get_window_attribute(hwnd, DWMWA_CLOAKED, &mut cloaked)?;
|
||||
|
||||
@@ -1047,7 +1047,7 @@ impl WindowsApi {
|
||||
unsafe { IsZoomed(HWND(as_ptr!(hwnd))) }.into()
|
||||
}
|
||||
|
||||
pub fn monitor_info_w(hmonitor: HMONITOR) -> Result<MONITORINFOEXW> {
|
||||
pub fn monitor_info_w(hmonitor: HMONITOR) -> eyre::Result<MONITORINFOEXW> {
|
||||
let mut ex_info = MONITORINFOEXW::default();
|
||||
ex_info.monitorInfo.cbSize = u32::try_from(std::mem::size_of::<MONITORINFOEXW>())?;
|
||||
unsafe { GetMonitorInfoW(hmonitor, &mut ex_info.monitorInfo) }
|
||||
@@ -1067,7 +1067,7 @@ impl WindowsApi {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn monitor(hmonitor: isize) -> Result<Monitor> {
|
||||
pub fn monitor(hmonitor: isize) -> eyre::Result<Monitor> {
|
||||
for mut display in win32_display_data::connected_displays_all().flatten() {
|
||||
if display.hmonitor == hmonitor {
|
||||
let path = display.device_path;
|
||||
@@ -1110,7 +1110,7 @@ impl WindowsApi {
|
||||
bail!("could not find device_id for hmonitor: {hmonitor}");
|
||||
}
|
||||
|
||||
pub fn set_process_dpi_awareness_context() -> Result<()> {
|
||||
pub fn set_process_dpi_awareness_context() -> eyre::Result<()> {
|
||||
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) }
|
||||
.process()
|
||||
}
|
||||
@@ -1121,13 +1121,13 @@ impl WindowsApi {
|
||||
ui_param: u32,
|
||||
pv_param: *mut c_void,
|
||||
update_flags: SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
unsafe { SystemParametersInfoW(action, ui_param, Option::from(pv_param), update_flags) }
|
||||
.process()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn foreground_lock_timeout() -> Result<()> {
|
||||
pub fn foreground_lock_timeout() -> eyre::Result<()> {
|
||||
let mut value: u32 = 0;
|
||||
|
||||
Self::system_parameters_info_w(
|
||||
@@ -1165,7 +1165,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn focus_follows_mouse() -> Result<bool> {
|
||||
pub fn focus_follows_mouse() -> eyre::Result<bool> {
|
||||
let mut is_enabled: BOOL = unsafe { std::mem::zeroed() };
|
||||
|
||||
Self::system_parameters_info_w(
|
||||
@@ -1179,7 +1179,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn enable_focus_follows_mouse() -> Result<()> {
|
||||
pub fn enable_focus_follows_mouse() -> eyre::Result<()> {
|
||||
#[allow(clippy::manual_dangling_ptr)]
|
||||
Self::system_parameters_info_w(
|
||||
SPI_SETACTIVEWINDOWTRACKING,
|
||||
@@ -1190,7 +1190,7 @@ impl WindowsApi {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn disable_focus_follows_mouse() -> Result<()> {
|
||||
pub fn disable_focus_follows_mouse() -> eyre::Result<()> {
|
||||
Self::system_parameters_info_w(
|
||||
SPI_SETACTIVEWINDOWTRACKING,
|
||||
0,
|
||||
@@ -1199,7 +1199,7 @@ impl WindowsApi {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn module_handle_w() -> Result<HMODULE> {
|
||||
pub fn module_handle_w() -> eyre::Result<HMODULE> {
|
||||
unsafe { GetModuleHandleW(None) }.process()
|
||||
}
|
||||
|
||||
@@ -1207,11 +1207,11 @@ impl WindowsApi {
|
||||
unsafe { CreateSolidBrush(COLORREF(colour)) }
|
||||
}
|
||||
|
||||
pub fn register_class_w(window_class: &WNDCLASSW) -> Result<u16> {
|
||||
pub fn register_class_w(window_class: &WNDCLASSW) -> eyre::Result<u16> {
|
||||
Result::from(WindowsResult::from(unsafe { RegisterClassW(window_class) }))
|
||||
}
|
||||
|
||||
pub fn dpi_for_monitor(hmonitor: isize) -> Result<f32> {
|
||||
pub fn dpi_for_monitor(hmonitor: isize) -> eyre::Result<f32> {
|
||||
let mut dpi_x = u32::default();
|
||||
let mut dpi_y = u32::default();
|
||||
|
||||
@@ -1229,14 +1229,14 @@ impl WindowsApi {
|
||||
Ok(dpi_y as f32 / 96.0)
|
||||
}
|
||||
|
||||
pub fn monitors_have_same_dpi(hmonitor_a: isize, hmonitor_b: isize) -> Result<bool> {
|
||||
pub fn monitors_have_same_dpi(hmonitor_a: isize, hmonitor_b: isize) -> eyre::Result<bool> {
|
||||
let dpi_a = Self::dpi_for_monitor(hmonitor_a)?;
|
||||
let dpi_b = Self::dpi_for_monitor(hmonitor_b)?;
|
||||
|
||||
Ok((dpi_a - dpi_b).abs() < f32::EPSILON)
|
||||
}
|
||||
|
||||
pub fn round_corners(hwnd: isize) -> Result<()> {
|
||||
pub fn round_corners(hwnd: isize) -> eyre::Result<()> {
|
||||
let round = DWMWCP_ROUND;
|
||||
|
||||
unsafe {
|
||||
@@ -1250,7 +1250,7 @@ impl WindowsApi {
|
||||
.process()
|
||||
}
|
||||
|
||||
pub fn set_window_accent(hwnd: isize, color: Option<u32>) -> Result<()> {
|
||||
pub fn set_window_accent(hwnd: isize, color: Option<u32>) -> eyre::Result<()> {
|
||||
let col_ref = COLORREF(color.unwrap_or(DWMWA_COLOR_NONE));
|
||||
unsafe {
|
||||
DwmSetWindowAttribute(
|
||||
@@ -1267,7 +1267,7 @@ impl WindowsApi {
|
||||
name: PCWSTR,
|
||||
instance: isize,
|
||||
border: *mut Border,
|
||||
) -> Result<isize> {
|
||||
) -> eyre::Result<isize> {
|
||||
unsafe {
|
||||
CreateWindowExW(
|
||||
WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE,
|
||||
@@ -1287,7 +1287,7 @@ impl WindowsApi {
|
||||
.process()
|
||||
}
|
||||
|
||||
pub fn set_transparent(hwnd: isize, alpha: u8) -> Result<()> {
|
||||
pub fn set_transparent(hwnd: isize, alpha: u8) -> eyre::Result<()> {
|
||||
unsafe {
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
SetLayeredWindowAttributes(
|
||||
@@ -1301,7 +1301,7 @@ impl WindowsApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_transparent(hwnd: isize) -> Result<u8> {
|
||||
pub fn get_transparent(hwnd: isize) -> eyre::Result<u8> {
|
||||
unsafe {
|
||||
let mut alpha: u8 = u8::default();
|
||||
let mut color_ref = COLORREF(-1i32 as u32);
|
||||
@@ -1316,7 +1316,7 @@ impl WindowsApi {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_hidden_window(name: PCWSTR, instance: isize) -> Result<isize> {
|
||||
pub fn create_hidden_window(name: PCWSTR, instance: isize) -> eyre::Result<isize> {
|
||||
unsafe {
|
||||
CreateWindowExW(
|
||||
WS_EX_NOACTIVATE,
|
||||
@@ -1410,11 +1410,11 @@ impl WindowsApi {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wts_register_session_notification(hwnd: isize) -> Result<()> {
|
||||
pub fn wts_register_session_notification(hwnd: isize) -> eyre::Result<()> {
|
||||
unsafe { WTSRegisterSessionNotification(HWND(as_ptr!(hwnd)), 1) }.process()
|
||||
}
|
||||
|
||||
pub fn set_wallpaper(path: &Path, hmonitor: isize) -> Result<()> {
|
||||
pub fn set_wallpaper(path: &Path, hmonitor: isize) -> eyre::Result<()> {
|
||||
let path = path.canonicalize()?;
|
||||
|
||||
let wallpaper: IDesktopWallpaper =
|
||||
@@ -1438,7 +1438,7 @@ impl WindowsApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_wallpaper(hmonitor: isize) -> Result<String> {
|
||||
pub fn get_wallpaper(hmonitor: isize) -> eyre::Result<String> {
|
||||
let wallpaper: IDesktopWallpaper =
|
||||
unsafe { CoCreateInstance(&DesktopWallpaper, None, CLSCTX_ALL)? };
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ use crate::static_config::WorkspaceConfig;
|
||||
use crate::window::Window;
|
||||
use crate::window::WindowDetails;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use komorebi_themes::Base16ColourPalette;
|
||||
use serde::Deserialize;
|
||||
@@ -157,7 +157,7 @@ pub struct WorkspaceGlobals {
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
pub fn load_static_config(&mut self, config: &WorkspaceConfig) -> Result<()> {
|
||||
pub fn load_static_config(&mut self, config: &WorkspaceConfig) -> eyre::Result<()> {
|
||||
self.name = Option::from(config.name.clone());
|
||||
|
||||
self.container_padding = config.container_padding;
|
||||
@@ -263,7 +263,11 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_wallpaper(&self, hmonitor: isize, monitor_wp: &Option<Wallpaper>) -> Result<()> {
|
||||
pub fn apply_wallpaper(
|
||||
&self,
|
||||
hmonitor: isize,
|
||||
monitor_wp: &Option<Wallpaper>,
|
||||
) -> eyre::Result<()> {
|
||||
if let Some(wallpaper) = self.wallpaper.as_ref().or(monitor_wp.as_ref()) {
|
||||
if let Err(error) = WindowsApi::set_wallpaper(&wallpaper.path, hmonitor) {
|
||||
tracing::error!("failed to set wallpaper: {error}");
|
||||
@@ -384,7 +388,7 @@ impl Workspace {
|
||||
mouse_follows_focus: bool,
|
||||
hmonitor: isize,
|
||||
monitor_wp: &Option<Wallpaper>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
if let Some(container) = &self.monocle_container
|
||||
&& let Some(window) = container.focused_window()
|
||||
{
|
||||
@@ -436,7 +440,7 @@ impl Workspace {
|
||||
self.apply_wallpaper(hmonitor, monitor_wp)
|
||||
}
|
||||
|
||||
pub fn update(&mut self) -> Result<()> {
|
||||
pub fn update(&mut self) -> eyre::Result<()> {
|
||||
if !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -627,7 +631,7 @@ impl Workspace {
|
||||
/// If there is a container which holds the window with `hwnd` it will focus that container.
|
||||
/// This function will only emit a focus on the window if it isn't the focused window of that
|
||||
/// container already.
|
||||
pub fn focus_container_by_window(&mut self, hwnd: isize) -> Result<()> {
|
||||
pub fn focus_container_by_window(&mut self, hwnd: isize) -> eyre::Result<()> {
|
||||
let container_idx = self
|
||||
.container_idx_for_window(hwnd)
|
||||
.ok_or_eyre("there is no container/window")?;
|
||||
@@ -761,7 +765,7 @@ impl Workspace {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn is_focused_window_monocle_or_maximized(&self) -> Result<bool> {
|
||||
pub fn is_focused_window_monocle_or_maximized(&self) -> eyre::Result<bool> {
|
||||
let hwnd = WindowsApi::foreground_window()?;
|
||||
if let Some(window) = self.maximized_window
|
||||
&& hwnd == window.hwnd
|
||||
@@ -813,7 +817,7 @@ impl Workspace {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn promote_container(&mut self) -> Result<()> {
|
||||
pub fn promote_container(&mut self) -> eyre::Result<()> {
|
||||
let resize = self.resize_dimensions.remove(0);
|
||||
let container = self
|
||||
.remove_focused_container()
|
||||
@@ -886,7 +890,7 @@ impl Workspace {
|
||||
idx
|
||||
}
|
||||
|
||||
pub fn remove_window(&mut self, hwnd: isize) -> Result<()> {
|
||||
pub fn remove_window(&mut self, hwnd: isize) -> eyre::Result<()> {
|
||||
border_manager::delete_border(hwnd);
|
||||
|
||||
if self.floating_windows().iter().any(|w| w.hwnd == hwnd) {
|
||||
@@ -991,7 +995,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
// this is what we use for stacking
|
||||
pub fn move_window_to_container(&mut self, target_container_idx: usize) -> Result<()> {
|
||||
pub fn move_window_to_container(&mut self, target_container_idx: usize) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
|
||||
let container = self
|
||||
@@ -1031,7 +1035,7 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_container_for_focused_window(&mut self) -> Result<()> {
|
||||
pub fn new_container_for_focused_window(&mut self) -> eyre::Result<()> {
|
||||
let focused_container_idx = self.focused_container_idx();
|
||||
|
||||
let container = self
|
||||
@@ -1055,7 +1059,7 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_container_for_floating_window(&mut self) -> Result<()> {
|
||||
pub fn new_container_for_floating_window(&mut self) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
let window = self
|
||||
.remove_focused_floating_window()
|
||||
@@ -1082,7 +1086,7 @@ impl Workspace {
|
||||
self.insert_container_at_idx(next_idx, container);
|
||||
}
|
||||
|
||||
pub fn new_floating_window(&mut self) -> Result<()> {
|
||||
pub fn new_floating_window(&mut self) -> eyre::Result<()> {
|
||||
let window = if let Some(maximized_window) = self.maximized_window {
|
||||
let window = maximized_window;
|
||||
self.maximized_window = None;
|
||||
@@ -1408,7 +1412,7 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_monocle_container(&mut self) -> Result<()> {
|
||||
pub fn new_monocle_container(&mut self) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
|
||||
// we shouldn't use remove_container_by_idx here because it doesn't make sense for
|
||||
@@ -1435,7 +1439,7 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reintegrate_monocle_container(&mut self) -> Result<()> {
|
||||
pub fn reintegrate_monocle_container(&mut self) -> eyre::Result<()> {
|
||||
let restore_idx = self
|
||||
.monocle_container_restore_idx
|
||||
.ok_or_eyre("there is no monocle restore index")?;
|
||||
@@ -1466,7 +1470,7 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_maximized_window(&mut self) -> Result<()> {
|
||||
pub fn new_maximized_window(&mut self) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
|
||||
if matches!(self.layer, WorkspaceLayer::Floating) {
|
||||
@@ -1535,7 +1539,7 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reintegrate_maximized_window(&mut self) -> Result<()> {
|
||||
pub fn reintegrate_maximized_window(&mut self) -> eyre::Result<()> {
|
||||
let restore_idx = self
|
||||
.maximized_window_restore_idx
|
||||
.ok_or_eyre("there is no monocle restore index")?;
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::time::Duration;
|
||||
use clap::CommandFactory;
|
||||
use clap::Parser;
|
||||
use clap::ValueEnum;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use color_eyre::eyre::bail;
|
||||
use dirs::data_local_dir;
|
||||
@@ -1527,7 +1527,7 @@ fn print_query(message: &SocketMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
fn startup_dir() -> Result<PathBuf> {
|
||||
fn startup_dir() -> eyre::Result<PathBuf> {
|
||||
let startup = dirs::home_dir()
|
||||
.expect("unable to obtain user's home folder")
|
||||
.join("AppData")
|
||||
@@ -1546,7 +1546,7 @@ fn startup_dir() -> Result<PathBuf> {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
|
||||
fn main() -> Result<()> {
|
||||
fn main() -> eyre::Result<()> {
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
match opts.subcmd {
|
||||
@@ -1585,7 +1585,7 @@ fn main() -> Result<()> {
|
||||
path: &PathBuf,
|
||||
content: &str,
|
||||
created_files: &mut Vec<String>,
|
||||
) -> Result<()> {
|
||||
) -> eyre::Result<()> {
|
||||
if path.exists() {
|
||||
print!(
|
||||
"{} will be overwritten, do you want to continue? (y/N): ",
|
||||
|
||||
Reference in New Issue
Block a user