mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 06:11:21 +01:00
refactor(kde): the Backend fails with the shared Error
KDE's Backend trait returned eyre reports and the Shared wrapper turned
them into komorebi_backend::Error (guessing WindowGone from is_window
afterwards). The 16 operations that the shared trait has now return
komorebi_backend::Result themselves: KWinBackend says WindowGone for an
id it has no uuid for and Platform for everything else, and the fake
passes the shared fake's errors through. Window's commands (set_position,
focus, raise, close, minimize, ...) return the shared Result too. KDE-only
methods (look, border colours, wallpaper) keep eyre.
Only the text of a failure changes ("no such window: 9" instead of
"there is no such window" in logs); no control flow does.
Verified: KDE cargo test --workspace --no-fail-fast, 881 passed, 0 failed
(native, FakeBackend). Not run: KDE VM suites.
This commit is contained in:
1 parent
633e7453cd
commit
06ce5adfe8
5 files changed
+130
-139
No files matched your search
@@ -130,10 +130,6 @@ fn wid(id: u32) -> WindowId {
|
||||
WindowId::from_u32(id)
|
||||
}
|
||||
|
||||
fn eyre_of(error: shared::Error) -> eyre::Report {
|
||||
eyre::Report::new(error)
|
||||
}
|
||||
|
||||
fn window_info(info: shared::WindowInfo) -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: raw(info.id),
|
||||
@@ -418,11 +414,10 @@ impl Backend for FakeBackend {
|
||||
self.inner.foreground_window().map(raw)
|
||||
}
|
||||
|
||||
fn monitors(&self) -> eyre::Result<Vec<MonitorInfo>> {
|
||||
fn monitors(&self) -> shared::Result<Vec<MonitorInfo>> {
|
||||
Ok(self
|
||||
.inner
|
||||
.monitors()
|
||||
.map_err(eyre_of)?
|
||||
.monitors()?
|
||||
.into_iter()
|
||||
.map(|m| MonitorInfo {
|
||||
id: raw_monitor(m.id),
|
||||
@@ -442,58 +437,55 @@ impl Backend for FakeBackend {
|
||||
self.kde.lock().drag_ends.get(&id).copied()
|
||||
}
|
||||
|
||||
fn set_rect(&self, id: u32, rect: &Rect) -> eyre::Result<()> {
|
||||
self.inner.set_rect(wid(id), rect).map_err(eyre_of)
|
||||
fn set_rect(&self, id: u32, rect: &Rect) -> shared::Result<()> {
|
||||
self.inner.set_rect(wid(id), rect)
|
||||
}
|
||||
|
||||
fn focus(&self, id: u32, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
fn focus(&self, id: u32, mouse_follows_focus: bool) -> shared::Result<()> {
|
||||
self.inner
|
||||
.focus(wid(id), mouse_follows_focus)
|
||||
.map_err(eyre_of)
|
||||
}
|
||||
|
||||
fn raise(&self, id: u32) -> eyre::Result<()> {
|
||||
self.inner.raise(wid(id)).map_err(eyre_of)
|
||||
fn raise(&self, id: u32) -> shared::Result<()> {
|
||||
self.inner.raise(wid(id))
|
||||
}
|
||||
|
||||
fn hide(&self, id: u32) -> eyre::Result<()> {
|
||||
self.inner.hide(wid(id)).map_err(eyre_of)
|
||||
fn hide(&self, id: u32) -> shared::Result<()> {
|
||||
self.inner.hide(wid(id))
|
||||
}
|
||||
|
||||
fn restore(&self, id: u32) -> eyre::Result<()> {
|
||||
self.inner.restore(wid(id)).map_err(eyre_of)
|
||||
fn restore(&self, id: u32) -> shared::Result<()> {
|
||||
self.inner.restore(wid(id))
|
||||
}
|
||||
|
||||
fn minimize(&self, id: u32) -> eyre::Result<()> {
|
||||
self.inner.minimize(wid(id)).map_err(eyre_of)
|
||||
fn minimize(&self, id: u32) -> shared::Result<()> {
|
||||
self.inner.minimize(wid(id))
|
||||
}
|
||||
|
||||
fn unminimize(&self, id: u32) -> eyre::Result<()> {
|
||||
self.inner.unminimize(wid(id)).map_err(eyre_of)
|
||||
fn unminimize(&self, id: u32) -> shared::Result<()> {
|
||||
self.inner.unminimize(wid(id))
|
||||
}
|
||||
|
||||
fn close(&self, id: u32) -> eyre::Result<()> {
|
||||
self.inner.close(wid(id)).map_err(eyre_of)
|
||||
fn close(&self, id: u32) -> shared::Result<()> {
|
||||
self.inner.close(wid(id))
|
||||
}
|
||||
|
||||
fn center_cursor_in(&self, rect: &Rect) -> eyre::Result<()> {
|
||||
self.inner.center_cursor_in(rect).map_err(eyre_of)
|
||||
fn center_cursor_in(&self, rect: &Rect) -> shared::Result<()> {
|
||||
self.inner.center_cursor_in(rect)
|
||||
}
|
||||
|
||||
fn ensure_workspaces(&self, names: &[String]) -> eyre::Result<()> {
|
||||
self.inner.ensure_workspaces(names).map_err(eyre_of)
|
||||
fn ensure_workspaces(&self, names: &[String]) -> shared::Result<()> {
|
||||
self.inner.ensure_workspaces(names)
|
||||
}
|
||||
|
||||
fn switch_workspace(&self, monitor_id: u32, idx: usize) -> eyre::Result<()> {
|
||||
fn switch_workspace(&self, monitor_id: u32, idx: usize) -> shared::Result<()> {
|
||||
self.inner
|
||||
.switch_workspace(MonitorId::from_u32(monitor_id), idx)
|
||||
.map_err(eyre_of)
|
||||
}
|
||||
|
||||
fn set_window_workspace(&self, id: u32, idx: usize) -> eyre::Result<()> {
|
||||
fn set_window_workspace(&self, id: u32, idx: usize) -> shared::Result<()> {
|
||||
self.inner
|
||||
.set_window_workspace(wid(id), idx)
|
||||
.map_err(eyre_of)
|
||||
}
|
||||
|
||||
fn window_workspace(&self, id: u32) -> Option<usize> {
|
||||
@@ -509,8 +501,8 @@ impl Backend for FakeBackend {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn maximize(&self, id: u32, maximize: bool) -> eyre::Result<()> {
|
||||
self.inner.maximize(wid(id), maximize).map_err(eyre_of)
|
||||
fn maximize(&self, id: u32, maximize: bool) -> shared::Result<()> {
|
||||
self.inner.maximize(wid(id), maximize)
|
||||
}
|
||||
|
||||
fn apply_look(&self, look: &Look) -> eyre::Result<bool> {
|
||||
@@ -523,8 +515,8 @@ impl Backend for FakeBackend {
|
||||
Ok(kde.borders_drawn && look.border.is_some())
|
||||
}
|
||||
|
||||
fn set_focus_follows_mouse(&self, enable: bool) -> eyre::Result<()> {
|
||||
self.inner.set_focus_follows_mouse(enable).map_err(eyre_of)
|
||||
fn set_focus_follows_mouse(&self, enable: bool) -> shared::Result<()> {
|
||||
self.inner.set_focus_follows_mouse(enable)
|
||||
}
|
||||
|
||||
fn set_wallpaper(&self, monitor_id: u32, path: &Path) -> eyre::Result<()> {
|
||||
@@ -537,8 +529,8 @@ impl Backend for FakeBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_opacity(&self, id: u32, alpha: u8) -> eyre::Result<()> {
|
||||
self.inner.set_opacity(wid(id), alpha).map_err(eyre_of)
|
||||
fn set_opacity(&self, id: u32, alpha: u8) -> shared::Result<()> {
|
||||
self.inner.set_opacity(wid(id), alpha)
|
||||
}
|
||||
|
||||
fn set_border_colours(&self, colours: &[(u32, u32)]) -> eyre::Result<bool> {
|
||||
|
||||
@@ -218,20 +218,20 @@ pub struct BorderLook {
|
||||
/// # fn windows(&self) -> Vec<WindowInfo> { vec![] }
|
||||
/// # fn window(&self, _: u32) -> Option<WindowInfo> { None }
|
||||
/// # fn foreground_window(&self) -> Option<u32> { None }
|
||||
/// # fn monitors(&self) -> eyre::Result<Vec<MonitorInfo>> { Ok(vec![]) }
|
||||
/// # fn monitors(&self) -> komorebi_backend::Result<Vec<MonitorInfo>> { Ok(vec![]) }
|
||||
/// # fn cursor_pos(&self) -> Option<(i32, i32)> { None }
|
||||
/// # fn set_rect(&self, _: u32, _: &Rect) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn focus(&self, _: u32, _: bool) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn raise(&self, _: u32) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn hide(&self, _: u32) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn restore(&self, _: u32) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn minimize(&self, _: u32) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn unminimize(&self, _: u32) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn close(&self, _: u32) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn center_cursor_in(&self, _: &Rect) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn ensure_workspaces(&self, _: &[String]) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn switch_workspace(&self, _: u32, _: usize) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn set_window_workspace(&self, _: u32, _: usize) -> eyre::Result<()> { Ok(()) }
|
||||
/// # fn set_rect(&self, _: u32, _: &Rect) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn focus(&self, _: u32, _: bool) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn raise(&self, _: u32) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn hide(&self, _: u32) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn restore(&self, _: u32) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn minimize(&self, _: u32) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn unminimize(&self, _: u32) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn close(&self, _: u32) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn center_cursor_in(&self, _: &Rect) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn ensure_workspaces(&self, _: &[String]) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn switch_workspace(&self, _: u32, _: usize) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn set_window_workspace(&self, _: u32, _: usize) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn window_workspace(&self, _: u32) -> Option<usize> { None }
|
||||
/// # fn current_workspaces(&self) -> Vec<(u32, usize)> { vec![] }
|
||||
/// # }
|
||||
@@ -253,7 +253,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When the compositor cannot report its outputs.
|
||||
fn monitors(&self) -> eyre::Result<Vec<MonitorInfo>>;
|
||||
fn monitors(&self) -> komorebi_backend::Result<Vec<MonitorInfo>>;
|
||||
|
||||
/// Returns where the pointer is, if the compositor says.
|
||||
fn cursor_pos(&self) -> Option<(i32, i32)>;
|
||||
@@ -323,21 +323,21 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn set_rect(&self, id: u32, rect: &Rect) -> eyre::Result<()>;
|
||||
fn set_rect(&self, id: u32, rect: &Rect) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Gives the window the focus, and, if `mouse_follows_focus`, puts the pointer in its middle.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn focus(&self, id: u32, mouse_follows_focus: bool) -> eyre::Result<()>;
|
||||
fn focus(&self, id: u32, mouse_follows_focus: bool) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Raises the window above the others.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn raise(&self, id: u32) -> eyre::Result<()>;
|
||||
fn raise(&self, id: u32) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Takes the window out of sight without closing or minimizing it, which is how the window
|
||||
/// manager keeps the back of a stack out of the way. On KWin it goes to a virtual desktop that
|
||||
@@ -351,7 +351,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
///
|
||||
/// When the window does not exist or is no longer alive, or the compositor cannot make the
|
||||
/// place the window is hidden in.
|
||||
fn hide(&self, id: u32) -> eyre::Result<()>;
|
||||
fn hide(&self, id: u32) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Brings a hidden window back, to the workspace it is on. A window that is not hidden is left
|
||||
/// as it is.
|
||||
@@ -359,35 +359,35 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn restore(&self, id: u32) -> eyre::Result<()>;
|
||||
fn restore(&self, id: u32) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Minimizes the window.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn minimize(&self, id: u32) -> eyre::Result<()>;
|
||||
fn minimize(&self, id: u32) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Brings a minimized window back.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn unminimize(&self, id: u32) -> eyre::Result<()>;
|
||||
fn unminimize(&self, id: u32) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Asks the window to close.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn close(&self, id: u32) -> eyre::Result<()>;
|
||||
fn close(&self, id: u32) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Puts the pointer in the middle of `rect`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the compositor refuses to move the pointer.
|
||||
fn center_cursor_in(&self, rect: &Rect) -> eyre::Result<()>;
|
||||
fn center_cursor_in(&self, rect: &Rect) -> komorebi_backend::Result<()>;
|
||||
|
||||
// ---- workspaces ----------------------------------------------------------------------------
|
||||
//
|
||||
@@ -406,7 +406,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When the compositor refuses to create or rename a desktop.
|
||||
fn ensure_workspaces(&self, names: &[String]) -> eyre::Result<()>;
|
||||
fn ensure_workspaces(&self, names: &[String]) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Shows workspace `idx` on the monitor `monitor_id`, leaving the other monitors as they are.
|
||||
///
|
||||
@@ -416,14 +416,14 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When there is no desktop for `idx` and one cannot be made.
|
||||
fn switch_workspace(&self, monitor_id: u32, idx: usize) -> eyre::Result<()>;
|
||||
fn switch_workspace(&self, monitor_id: u32, idx: usize) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Puts a window on workspace `idx`. It is visible at once to [`Backend::window_workspace`].
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist, or there is no desktop for `idx` and one cannot be made.
|
||||
fn set_window_workspace(&self, id: u32, idx: usize) -> eyre::Result<()>;
|
||||
fn set_window_workspace(&self, id: u32, idx: usize) -> komorebi_backend::Result<()>;
|
||||
|
||||
/// Returns the workspace a window is on, or `None` for a window the compositor does not know or
|
||||
/// that is on every workspace.
|
||||
@@ -527,7 +527,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// assert_eq!(fake.opacity_of(7), 150);
|
||||
/// # Ok::<(), color_eyre::eyre::Report>(())
|
||||
/// ```
|
||||
fn set_opacity(&self, _id: u32, _alpha: u8) -> eyre::Result<()> {
|
||||
fn set_opacity(&self, _id: u32, _alpha: u8) -> komorebi_backend::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -551,7 +551,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// assert_eq!(fake.commands(), [Command::FocusFollowsMouse(true)]);
|
||||
/// # Ok::<(), color_eyre::eyre::Report>(())
|
||||
/// ```
|
||||
fn set_focus_follows_mouse(&self, _enable: bool) -> eyre::Result<()> {
|
||||
fn set_focus_follows_mouse(&self, _enable: bool) -> komorebi_backend::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When the window does not exist or is no longer alive.
|
||||
fn maximize(&self, _id: u32, _maximize: bool) -> eyre::Result<()> {
|
||||
fn maximize(&self, _id: u32, _maximize: bool) -> komorebi_backend::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@
|
||||
//!
|
||||
//! - an id is a [`WindowId`] made from the `u32` ([`WindowId::from_u32`]); an id too wide for a
|
||||
//! `u32` is a window KDE never had;
|
||||
//! - an `eyre` error of a window command becomes [`Error::WindowGone`] if the window is not alive
|
||||
//! any more by the time the command is answered (KDE fails only for an unknown or dead
|
||||
//! window), and [`Error::Platform`] otherwise;
|
||||
//! - errors need no translation: KDE's trait already fails with the shared [`Error`];
|
||||
//! - KDE fills every field of a window, so the optional fields are all `Some`;
|
||||
//! - every [`Capability`] is supported: KDE has workspaces, maximize, opacity and focus follows
|
||||
//! mouse;
|
||||
@@ -37,26 +35,16 @@ impl<B: Backend + ?Sized> Shared<B> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Runs a window command through KDE's trait and says why it failed in the shared terms.
|
||||
/// Runs a window command through KDE's trait; an id too wide for KDE is a window it never had.
|
||||
fn window_command(
|
||||
&self,
|
||||
id: WindowId,
|
||||
command: impl FnOnce(&B, u32) -> color_eyre::eyre::Result<()>,
|
||||
command: impl FnOnce(&B, u32) -> shared::Result<()>,
|
||||
) -> shared::Result<()> {
|
||||
let Some(raw) = id.to_u32() else {
|
||||
return Err(Error::WindowGone(id));
|
||||
};
|
||||
command(&self.0, raw).map_err(|report| {
|
||||
if self.0.is_window(raw) {
|
||||
Error::Platform(report.into())
|
||||
} else {
|
||||
Error::WindowGone(id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn platform(report: color_eyre::eyre::Report) -> Error {
|
||||
Error::Platform(report.into())
|
||||
command(&self.0, raw)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +81,7 @@ impl<B: Backend + ?Sized> shared::Backend for Shared<B> {
|
||||
fn monitors(&self) -> shared::Result<Vec<shared::MonitorInfo>> {
|
||||
Ok(self
|
||||
.0
|
||||
.monitors()
|
||||
.map_err(Self::platform)?
|
||||
.monitors()?
|
||||
.into_iter()
|
||||
.map(|m| shared::MonitorInfo {
|
||||
id: MonitorId::from_u32(m.id),
|
||||
@@ -143,7 +130,7 @@ impl<B: Backend + ?Sized> shared::Backend for Shared<B> {
|
||||
}
|
||||
|
||||
fn center_cursor_in(&self, rect: &Rect) -> shared::Result<()> {
|
||||
self.0.center_cursor_in(rect).map_err(Self::platform)
|
||||
self.0.center_cursor_in(rect)
|
||||
}
|
||||
|
||||
fn supports(&self, _capability: Capability) -> bool {
|
||||
@@ -159,18 +146,16 @@ impl<B: Backend + ?Sized> shared::Backend for Shared<B> {
|
||||
}
|
||||
|
||||
fn set_focus_follows_mouse(&self, enable: bool) -> shared::Result<()> {
|
||||
self.0
|
||||
.set_focus_follows_mouse(enable)
|
||||
.map_err(Self::platform)
|
||||
self.0.set_focus_follows_mouse(enable)
|
||||
}
|
||||
|
||||
fn ensure_workspaces(&self, names: &[String]) -> shared::Result<()> {
|
||||
self.0.ensure_workspaces(names).map_err(Self::platform)
|
||||
self.0.ensure_workspaces(names)
|
||||
}
|
||||
|
||||
fn switch_workspace(&self, monitor: MonitorId, idx: usize) -> shared::Result<()> {
|
||||
let id = monitor.to_u32().unwrap_or(u32::MAX);
|
||||
self.0.switch_workspace(id, idx).map_err(Self::platform)
|
||||
self.0.switch_workspace(id, idx)
|
||||
}
|
||||
|
||||
fn set_window_workspace(&self, id: WindowId, idx: usize) -> shared::Result<()> {
|
||||
|
||||
@@ -783,24 +783,39 @@ async fn move_mouse_to_focus(shared: &Shared) -> eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A failure of the compositor, in the shared terms.
|
||||
fn platform(report: eyre::Report) -> komorebi_backend::Error {
|
||||
komorebi_backend::Error::Platform(report.into())
|
||||
}
|
||||
|
||||
fn command_rect(uuid: &str, rect: &Rect) -> Value {
|
||||
json!({ "op": "geo", "id": uuid, "x": rect.left, "y": rect.top, "w": rect.right, "h": rect.bottom })
|
||||
}
|
||||
|
||||
impl KWinBackend {
|
||||
/// A workspace was asked for that has no desktop: make desktops up to it
|
||||
fn make_desktops(&self, count: usize) -> eyre::Result<()> {
|
||||
fn make_desktops(&self, count: usize) -> komorebi_backend::Result<()> {
|
||||
let names: Vec<String> = (1..=count).map(|n| format!("Workspace {n}")).collect();
|
||||
self.ensure_workspaces(&names)
|
||||
}
|
||||
|
||||
fn command(&self, id: u32, build: impl FnOnce(&str) -> Value) -> eyre::Result<()> {
|
||||
let uuid = self
|
||||
.shared
|
||||
/// The compositor's name for a window, or "that window is gone" for an id it does not know
|
||||
fn uuid_of(&self, id: u32) -> komorebi_backend::Result<String> {
|
||||
self.shared
|
||||
.table
|
||||
.lock()
|
||||
.uuid(id)
|
||||
.ok_or_eyre("there is no such window")?;
|
||||
.ok_or(komorebi_backend::Error::WindowGone(
|
||||
komorebi_backend::WindowId::from_u32(id),
|
||||
))
|
||||
}
|
||||
|
||||
fn command(
|
||||
&self,
|
||||
id: u32,
|
||||
build: impl FnOnce(&str) -> Value,
|
||||
) -> komorebi_backend::Result<()> {
|
||||
let uuid = self.uuid_of(id)?;
|
||||
self.shared.push(build(&uuid));
|
||||
Ok(())
|
||||
}
|
||||
@@ -827,10 +842,10 @@ impl Backend for KWinBackend {
|
||||
self.shared.table.lock().drag_end(id)
|
||||
}
|
||||
|
||||
fn monitors(&self) -> eyre::Result<Vec<MonitorInfo>> {
|
||||
fn monitors(&self) -> komorebi_backend::Result<Vec<MonitorInfo>> {
|
||||
let monitors = self.shared.table.lock().monitors();
|
||||
if monitors.is_empty() {
|
||||
eyre::bail!("KWin reported no outputs");
|
||||
return Err(platform(eyre::eyre!("KWin reported no outputs")));
|
||||
}
|
||||
Ok(monitors)
|
||||
}
|
||||
@@ -849,14 +864,14 @@ impl Backend for KWinBackend {
|
||||
answer.or_else(|| self.shared.table.lock().cursor())
|
||||
}
|
||||
|
||||
fn set_rect(&self, id: u32, rect: &Rect) -> eyre::Result<()> {
|
||||
fn set_rect(&self, id: u32, rect: &Rect) -> komorebi_backend::Result<()> {
|
||||
tracing::debug!("asking for window {id} to be at {rect:?}");
|
||||
self.command(id, |uuid| command_rect(uuid, rect))?;
|
||||
self.shared.table.lock().note_requested_rect(id, *rect);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn focus(&self, id: u32, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
fn focus(&self, id: u32, mouse_follows_focus: bool) -> komorebi_backend::Result<()> {
|
||||
self.command(id, |uuid| json!({ "op": "activate", "id": uuid }))?;
|
||||
|
||||
if mouse_follows_focus {
|
||||
@@ -879,16 +894,12 @@ impl Backend for KWinBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn raise(&self, id: u32) -> eyre::Result<()> {
|
||||
fn raise(&self, id: u32) -> komorebi_backend::Result<()> {
|
||||
self.command(id, |uuid| json!({ "op": "raise", "id": uuid }))
|
||||
}
|
||||
|
||||
fn hide(&self, id: u32) -> eyre::Result<()> {
|
||||
self.shared
|
||||
.table
|
||||
.lock()
|
||||
.uuid(id)
|
||||
.ok_or_eyre("there is no such window")?;
|
||||
fn hide(&self, id: u32) -> komorebi_backend::Result<()> {
|
||||
self.uuid_of(id)?;
|
||||
|
||||
let commands = loop {
|
||||
let attempt = self.shared.table.lock().hide_commands(id);
|
||||
@@ -898,7 +909,9 @@ impl Backend for KWinBackend {
|
||||
let shared = self.shared.clone();
|
||||
let park = self
|
||||
.shared
|
||||
.block_on(async move { create_park_desktop(&shared).await })??;
|
||||
.block_on(async move { create_park_desktop(&shared).await })
|
||||
.map_err(platform)?
|
||||
.map_err(platform)?;
|
||||
self.shared.table.lock().set_park(park);
|
||||
}
|
||||
}
|
||||
@@ -910,12 +923,8 @@ impl Backend for KWinBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn restore(&self, id: u32) -> eyre::Result<()> {
|
||||
self.shared
|
||||
.table
|
||||
.lock()
|
||||
.uuid(id)
|
||||
.ok_or_eyre("there is no such window")?;
|
||||
fn restore(&self, id: u32) -> komorebi_backend::Result<()> {
|
||||
self.uuid_of(id)?;
|
||||
|
||||
let commands = self.shared.table.lock().restore_commands(id);
|
||||
for command in commands {
|
||||
@@ -924,14 +933,16 @@ impl Backend for KWinBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_workspaces(&self, names: &[String]) -> eyre::Result<()> {
|
||||
fn ensure_workspaces(&self, names: &[String]) -> komorebi_backend::Result<()> {
|
||||
let shared = self.shared.clone();
|
||||
let names = names.to_vec();
|
||||
self.shared
|
||||
.block_on(async move { create_workspace_desktops(&shared, &names).await })?
|
||||
.block_on(async move { create_workspace_desktops(&shared, &names).await })
|
||||
.map_err(platform)?
|
||||
.map_err(platform)
|
||||
}
|
||||
|
||||
fn switch_workspace(&self, monitor_id: u32, idx: usize) -> eyre::Result<()> {
|
||||
fn switch_workspace(&self, monitor_id: u32, idx: usize) -> komorebi_backend::Result<()> {
|
||||
let commands = loop {
|
||||
let attempt = self.shared.table.lock().switch_commands(monitor_id, idx);
|
||||
match attempt {
|
||||
@@ -946,7 +957,7 @@ impl Backend for KWinBackend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_window_workspace(&self, id: u32, idx: usize) -> eyre::Result<()> {
|
||||
fn set_window_workspace(&self, id: u32, idx: usize) -> komorebi_backend::Result<()> {
|
||||
let commands = loop {
|
||||
let attempt = self.shared.table.lock().window_workspace_commands(id, idx);
|
||||
match attempt {
|
||||
@@ -969,26 +980,26 @@ impl Backend for KWinBackend {
|
||||
self.shared.table.lock().current_workspaces()
|
||||
}
|
||||
|
||||
fn minimize(&self, id: u32) -> eyre::Result<()> {
|
||||
fn minimize(&self, id: u32) -> komorebi_backend::Result<()> {
|
||||
self.command(id, |uuid| json!({ "op": "min", "id": uuid, "v": true }))
|
||||
}
|
||||
|
||||
fn unminimize(&self, id: u32) -> eyre::Result<()> {
|
||||
fn unminimize(&self, id: u32) -> komorebi_backend::Result<()> {
|
||||
self.command(id, |uuid| json!({ "op": "min", "id": uuid, "v": false }))
|
||||
}
|
||||
|
||||
fn close(&self, id: u32) -> eyre::Result<()> {
|
||||
fn close(&self, id: u32) -> komorebi_backend::Result<()> {
|
||||
self.command(id, |uuid| json!({ "op": "close", "id": uuid }))
|
||||
}
|
||||
|
||||
fn maximize(&self, id: u32, maximize: bool) -> eyre::Result<()> {
|
||||
fn maximize(&self, id: u32, maximize: bool) -> komorebi_backend::Result<()> {
|
||||
self.command(
|
||||
id,
|
||||
|uuid| json!({ "op": "maximize", "id": uuid, "v": maximize }),
|
||||
)
|
||||
}
|
||||
|
||||
fn center_cursor_in(&self, _rect: &Rect) -> eyre::Result<()> {
|
||||
fn center_cursor_in(&self, _rect: &Rect) -> komorebi_backend::Result<()> {
|
||||
// KWin can center the pointer on the active window and nothing else; the WM calls this
|
||||
// right after focusing the window in question
|
||||
let shared = self.shared.clone();
|
||||
@@ -1014,17 +1025,18 @@ impl Backend for KWinBackend {
|
||||
})?
|
||||
}
|
||||
|
||||
fn set_opacity(&self, id: u32, alpha: u8) -> eyre::Result<()> {
|
||||
fn set_opacity(&self, id: u32, alpha: u8) -> komorebi_backend::Result<()> {
|
||||
self.command(
|
||||
id,
|
||||
|uuid| json!({ "op": "opacity", "id": uuid, "v": f64::from(alpha) / 255.0 }),
|
||||
)
|
||||
}
|
||||
|
||||
fn set_focus_follows_mouse(&self, enable: bool) -> eyre::Result<()> {
|
||||
fn set_focus_follows_mouse(&self, enable: bool) -> komorebi_backend::Result<()> {
|
||||
let shared = self.shared.clone();
|
||||
|
||||
self.shared.block_on(async move {
|
||||
self.shared
|
||||
.block_on(async move {
|
||||
let Some(kwinrc) = &shared.kwinrc else {
|
||||
eyre::bail!("there is no configuration directory to find kwinrc in");
|
||||
};
|
||||
@@ -1044,7 +1056,9 @@ impl Backend for KWinBackend {
|
||||
let connection = shared.connection().await?;
|
||||
kwin_reconfigure(&connection).await;
|
||||
Ok(())
|
||||
})?
|
||||
})
|
||||
.map_err(platform)?
|
||||
.map_err(platform)
|
||||
}
|
||||
|
||||
fn set_wallpaper(&self, monitor_id: u32, path: &std::path::Path) -> eyre::Result<()> {
|
||||
|
||||
@@ -227,7 +227,7 @@ impl Window {
|
||||
/// user's until they let go.
|
||||
///
|
||||
/// A fullscreen window is left where it is, and the call succeeds.
|
||||
pub fn set_position(self, rect: &Rect) -> eyre::Result<()> {
|
||||
pub fn set_position(self, rect: &Rect) -> komorebi_backend::Result<()> {
|
||||
// the window the user is dragging an edge of is theirs until they let go
|
||||
if is_live_resized(self.id) {
|
||||
return Ok(());
|
||||
@@ -249,11 +249,11 @@ impl Window {
|
||||
}
|
||||
|
||||
/// Asks the compositor to draw the window with this opacity, 255 being not see-through at all
|
||||
pub fn set_opacity(self, alpha: u8) -> eyre::Result<()> {
|
||||
pub fn set_opacity(self, alpha: u8) -> komorebi_backend::Result<()> {
|
||||
backend().set_opacity(self.id, alpha)
|
||||
}
|
||||
|
||||
pub fn focus(self, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
pub fn focus(self, mouse_follows_focus: bool) -> komorebi_backend::Result<()> {
|
||||
backend().focus(self.id, mouse_follows_focus)
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ impl Window {
|
||||
/// # Errors
|
||||
///
|
||||
/// The backend does not know the window, or refuses to maximize it.
|
||||
pub fn maximize(self) -> eyre::Result<()> {
|
||||
pub fn maximize(self) -> komorebi_backend::Result<()> {
|
||||
backend().maximize(self.id, true)
|
||||
}
|
||||
|
||||
@@ -271,25 +271,25 @@ impl Window {
|
||||
/// # Errors
|
||||
///
|
||||
/// The backend does not know the window, or refuses to restore it.
|
||||
pub fn unmaximize(self) -> eyre::Result<()> {
|
||||
pub fn unmaximize(self) -> komorebi_backend::Result<()> {
|
||||
backend().maximize(self.id, false)
|
||||
}
|
||||
|
||||
pub fn raise(self) -> eyre::Result<()> {
|
||||
pub fn raise(self) -> komorebi_backend::Result<()> {
|
||||
backend().raise(self.id)
|
||||
}
|
||||
|
||||
pub fn close(self) -> eyre::Result<()> {
|
||||
pub fn close(self) -> komorebi_backend::Result<()> {
|
||||
backend().close(self.id)
|
||||
}
|
||||
|
||||
/// Minimizes the window, as the user asking for it would. [`Window::hide`] is what komorebi
|
||||
/// does to keep the back of a stack out of the way.
|
||||
pub fn minimize(self) -> eyre::Result<()> {
|
||||
pub fn minimize(self) -> komorebi_backend::Result<()> {
|
||||
backend().minimize(self.id)
|
||||
}
|
||||
|
||||
pub fn unminimize(self) -> eyre::Result<()> {
|
||||
pub fn unminimize(self) -> komorebi_backend::Result<()> {
|
||||
backend().unminimize(self.id)
|
||||
}
|
||||
|
||||
@@ -338,12 +338,12 @@ impl Window {
|
||||
let x = work_area.left + ((work_area.right - target_width) / 2);
|
||||
let y = work_area.top + ((work_area.bottom - target_height) / 2);
|
||||
|
||||
self.set_position(&Rect {
|
||||
Ok(self.set_position(&Rect {
|
||||
left: x,
|
||||
top: y,
|
||||
right: target_width,
|
||||
bottom: target_height,
|
||||
})
|
||||
})?)
|
||||
}
|
||||
|
||||
/// Moves the window from one work area to another, keeping where it is in the area and how
|
||||
@@ -366,12 +366,12 @@ impl Window {
|
||||
let corrected_width = (current_rect.right as f32 * x_ratio) as i32;
|
||||
let corrected_height = (current_rect.bottom as f32 * y_ratio) as i32;
|
||||
|
||||
self.set_position(&Rect {
|
||||
Ok(self.set_position(&Rect {
|
||||
left,
|
||||
top,
|
||||
right: corrected_width,
|
||||
bottom: corrected_height,
|
||||
})
|
||||
})?)
|
||||
}
|
||||
|
||||
/// Whether the window is one komorebi should tile: a window that is still alive, that the
|
||||
|
||||
Reference in new issue
Block a user