mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-23 00:44:15 +01:00
refactor(kde): the Backend answers with the shared WindowInfo and MonitorInfo
KDE's Backend returned its own WindowInfo/MonitorInfo (plain String and bool fields) and the Shared wrapper rebuilt the shared ones from them, the KDE fake did the reverse. The trait now returns komorebi_backend's types (Option for what a platform may lack); the fake passes the shared fake's values through and KWin converts its table's records with From. The plain KDE structs stay as the view the window manager core reads (Window::info and the monitor loaders convert with From, which fills a missing field with empty/false and a missing 'normal' with true, exactly what KDE always had); the shared wrapper is now a pure pass-through, removed in the next revision. A few test assertions read the Option fields. No behaviour change. Verified: KDE cargo test --workspace --no-fail-fast 881 passed, 0 failed (native, FakeBackend; the one doc test that needed a fix was re-run and passes). Not run: KDE VM suites.
This commit is contained in:
1 parent
c08ee2cfae
commit
68d1e49442
7 files changed
+116
-93
No files matched your search
@@ -38,8 +38,6 @@
|
||||
|
||||
use super::Backend;
|
||||
use super::Look;
|
||||
use super::MonitorInfo;
|
||||
use super::WindowInfo;
|
||||
use crate::core::Rect;
|
||||
use color_eyre::eyre;
|
||||
use komorebi_backend as shared;
|
||||
@@ -130,23 +128,6 @@ fn wid(id: u32) -> WindowId {
|
||||
WindowId::from_u32(id)
|
||||
}
|
||||
|
||||
fn window_info(info: shared::WindowInfo) -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: raw(info.id),
|
||||
pid: info.pid,
|
||||
title: info.title.unwrap_or_default(),
|
||||
class: info.class.unwrap_or_default(),
|
||||
exe: info.exe.unwrap_or_default(),
|
||||
path: info.path.unwrap_or_default(),
|
||||
rect: info.rect,
|
||||
minimized: info.minimized,
|
||||
fullscreen: info.fullscreen.unwrap_or_default(),
|
||||
maximized: info.maximized.unwrap_or_default(),
|
||||
normal: info.normal.unwrap_or(true),
|
||||
alive: info.alive,
|
||||
}
|
||||
}
|
||||
|
||||
fn command(command: SharedCommand<KdeCommand>) -> Option<Command> {
|
||||
Some(match command {
|
||||
SharedCommand::SetRect(id, rect) => Command::SetRect(raw(id), rect),
|
||||
@@ -402,31 +383,20 @@ impl FakeBackend {
|
||||
}
|
||||
|
||||
impl Backend for FakeBackend {
|
||||
fn windows(&self) -> Vec<WindowInfo> {
|
||||
self.inner.windows().into_iter().map(window_info).collect()
|
||||
fn windows(&self) -> Vec<komorebi_backend::WindowInfo> {
|
||||
self.inner.windows()
|
||||
}
|
||||
|
||||
fn window(&self, id: WindowId) -> Option<WindowInfo> {
|
||||
self.inner.window(id).map(window_info)
|
||||
fn window(&self, id: WindowId) -> Option<komorebi_backend::WindowInfo> {
|
||||
self.inner.window(id)
|
||||
}
|
||||
|
||||
fn foreground_window(&self) -> Option<WindowId> {
|
||||
self.inner.foreground_window()
|
||||
}
|
||||
|
||||
fn monitors(&self) -> shared::Result<Vec<MonitorInfo>> {
|
||||
Ok(self
|
||||
.inner
|
||||
.monitors()?
|
||||
.into_iter()
|
||||
.map(|m| MonitorInfo {
|
||||
id: raw_monitor(m.id),
|
||||
name: m.name.unwrap_or_default(),
|
||||
serial_number_id: m.serial_number_id.unwrap_or_default(),
|
||||
size: m.size,
|
||||
work_area: m.work_area,
|
||||
})
|
||||
.collect())
|
||||
fn monitors(&self) -> shared::Result<Vec<shared::MonitorInfo>> {
|
||||
self.inner.monitors()
|
||||
}
|
||||
|
||||
fn cursor_pos(&self) -> Option<(i32, i32)> {
|
||||
@@ -649,8 +619,9 @@ mod tests {
|
||||
fake.window(1.into())
|
||||
.expect("window 1 was opened")
|
||||
.maximized
|
||||
.unwrap_or_default()
|
||||
);
|
||||
assert!(fake.windows()[0].maximized);
|
||||
assert!(fake.windows()[0].maximized.unwrap_or_default());
|
||||
assert_eq!(fake.rect_of(1), Some(tile(0, 1920)));
|
||||
assert!(fake.commands().is_empty());
|
||||
|
||||
@@ -661,6 +632,7 @@ mod tests {
|
||||
.window(1.into())
|
||||
.expect("window 1 was opened")
|
||||
.maximized
|
||||
.unwrap_or_default()
|
||||
);
|
||||
assert_eq!(fake.rect_of(1), Some(tile(100, 200)));
|
||||
}
|
||||
@@ -677,8 +649,9 @@ mod tests {
|
||||
fake.window(1.into())
|
||||
.expect("window 1 was opened")
|
||||
.fullscreen
|
||||
.unwrap_or_default()
|
||||
);
|
||||
assert!(fake.windows()[0].fullscreen);
|
||||
assert!(fake.windows()[0].fullscreen.unwrap_or_default());
|
||||
assert_eq!(
|
||||
fake.rect_of(1),
|
||||
Some(Rect {
|
||||
@@ -698,6 +671,7 @@ mod tests {
|
||||
.window(1.into())
|
||||
.expect("window 1 was opened")
|
||||
.fullscreen
|
||||
.unwrap_or_default()
|
||||
);
|
||||
assert_eq!(fake.rect_of(1), Some(tile(100, 200)));
|
||||
}
|
||||
@@ -779,8 +753,8 @@ mod tests {
|
||||
assert!(fake.commands().is_empty());
|
||||
assert_eq!(fake.rect_of(1), Some(tile(300, 300)));
|
||||
let window = fake.window(1.into()).expect("window 1 was opened");
|
||||
assert_eq!(window.title, "renamed");
|
||||
assert!(!window.normal);
|
||||
assert_eq!(window.title, Some("renamed".to_string()));
|
||||
assert!(window.normal == Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -788,7 +762,11 @@ mod tests {
|
||||
let fake = fake_with(&[3, 1, 2]);
|
||||
fake.close_window_now(2);
|
||||
|
||||
let ids: Vec<_> = fake.windows().iter().map(|w| w.id).collect();
|
||||
let ids: Vec<_> = fake
|
||||
.windows()
|
||||
.iter()
|
||||
.map(|w| w.id.to_u32().unwrap())
|
||||
.collect();
|
||||
|
||||
assert_eq!(ids, [1, 3]);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,46 @@ pub struct WindowInfo {
|
||||
pub alive: bool,
|
||||
}
|
||||
|
||||
impl From<komorebi_backend::WindowInfo> for WindowInfo {
|
||||
/// KDE fills every field of a window, so the optional ones are always there; a backend that has
|
||||
/// not got one gets the empty string or false, and a window is normal unless it says it is not.
|
||||
fn from(info: komorebi_backend::WindowInfo) -> Self {
|
||||
Self {
|
||||
id: info.id.to_u32().unwrap_or(u32::MAX),
|
||||
pid: info.pid,
|
||||
title: info.title.unwrap_or_default(),
|
||||
class: info.class.unwrap_or_default(),
|
||||
exe: info.exe.unwrap_or_default(),
|
||||
path: info.path.unwrap_or_default(),
|
||||
rect: info.rect,
|
||||
minimized: info.minimized,
|
||||
fullscreen: info.fullscreen.unwrap_or_default(),
|
||||
maximized: info.maximized.unwrap_or_default(),
|
||||
normal: info.normal.unwrap_or(true),
|
||||
alive: info.alive,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WindowInfo> for komorebi_backend::WindowInfo {
|
||||
fn from(info: WindowInfo) -> Self {
|
||||
Self {
|
||||
id: WindowId::from_u32(info.id),
|
||||
pid: info.pid,
|
||||
rect: info.rect,
|
||||
minimized: info.minimized,
|
||||
alive: info.alive,
|
||||
title: Some(info.title),
|
||||
class: Some(info.class),
|
||||
exe: Some(info.exe),
|
||||
path: Some(info.path),
|
||||
fullscreen: Some(info.fullscreen),
|
||||
maximized: Some(info.maximized),
|
||||
normal: Some(info.normal),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A connected monitor, in logical pixels.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct MonitorInfo {
|
||||
@@ -108,6 +148,30 @@ pub struct MonitorInfo {
|
||||
pub work_area: Rect,
|
||||
}
|
||||
|
||||
impl From<komorebi_backend::MonitorInfo> for MonitorInfo {
|
||||
fn from(info: komorebi_backend::MonitorInfo) -> Self {
|
||||
Self {
|
||||
id: info.id.to_u32().unwrap_or(u32::MAX),
|
||||
name: info.name.unwrap_or_default(),
|
||||
serial_number_id: info.serial_number_id.unwrap_or_default(),
|
||||
size: info.size,
|
||||
work_area: info.work_area,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MonitorInfo> for komorebi_backend::MonitorInfo {
|
||||
fn from(info: MonitorInfo) -> Self {
|
||||
Self {
|
||||
id: MonitorId::from_u32(info.id),
|
||||
size: info.size,
|
||||
work_area: info.work_area,
|
||||
name: Some(info.name),
|
||||
serial_number_id: Some(info.serial_number_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How the compositor is asked to dress the windows komorebi arranges.
|
||||
///
|
||||
/// komorebi decides what the windows look like and the compositor draws it, so this only
|
||||
@@ -212,16 +276,16 @@ pub struct BorderLook {
|
||||
/// ```rust,compile_fail,E0277
|
||||
/// # use std::rc::Rc;
|
||||
/// # use color_eyre::eyre;
|
||||
/// # use komorebi::backend::{Backend, MonitorInfo, WindowInfo};
|
||||
/// # use komorebi::backend::Backend;
|
||||
/// # use komorebi::core::Rect;
|
||||
/// # use komorebi_backend::{MonitorId, WindowId};
|
||||
/// struct NotShareable(Rc<u8>);
|
||||
///
|
||||
/// # impl Backend for NotShareable {
|
||||
/// # fn windows(&self) -> Vec<WindowInfo> { vec![] }
|
||||
/// # fn window(&self, _: WindowId) -> Option<WindowInfo> { None }
|
||||
/// # fn windows(&self) -> Vec<komorebi_backend::WindowInfo> { vec![] }
|
||||
/// # fn window(&self, _: WindowId) -> Option<komorebi_backend::WindowInfo> { None }
|
||||
/// # fn foreground_window(&self) -> Option<WindowId> { None }
|
||||
/// # fn monitors(&self) -> komorebi_backend::Result<Vec<MonitorInfo>> { Ok(vec![]) }
|
||||
/// # fn monitors(&self) -> komorebi_backend::Result<Vec<komorebi_backend::MonitorInfo>> { Ok(vec![]) }
|
||||
/// # fn cursor_pos(&self) -> Option<(i32, i32)> { None }
|
||||
/// # fn set_rect(&self, _: WindowId, _: &Rect) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
/// # fn focus(&self, _: WindowId, _: bool) -> komorebi_backend::Result<()> { Ok(()) }
|
||||
@@ -243,10 +307,10 @@ pub trait Backend: Send + Sync + 'static {
|
||||
// ---- queries -------------------------------------------------------------------------------
|
||||
|
||||
/// Returns every window on the desktop that is a candidate for management, ordered by id.
|
||||
fn windows(&self) -> Vec<WindowInfo>;
|
||||
fn windows(&self) -> Vec<komorebi_backend::WindowInfo>;
|
||||
|
||||
/// Returns what is known about the window, or `None` if the compositor has never heard of it.
|
||||
fn window(&self, id: WindowId) -> Option<WindowInfo>;
|
||||
fn window(&self, id: WindowId) -> Option<komorebi_backend::WindowInfo>;
|
||||
|
||||
/// Returns the id of the window that has the focus, if any window does.
|
||||
fn foreground_window(&self) -> Option<WindowId>;
|
||||
@@ -256,7 +320,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
/// # Errors
|
||||
///
|
||||
/// When the compositor cannot report its outputs.
|
||||
fn monitors(&self) -> komorebi_backend::Result<Vec<MonitorInfo>>;
|
||||
fn monitors(&self) -> komorebi_backend::Result<Vec<komorebi_backend::MonitorInfo>>;
|
||||
|
||||
/// Returns where the pointer is, if the compositor says.
|
||||
fn cursor_pos(&self) -> Option<(i32, i32)>;
|
||||
@@ -627,7 +691,7 @@ pub trait Backend: Send + Sync + 'static {
|
||||
self.monitors().ok()?.into_iter().find_map(|m| {
|
||||
let (l, t) = (m.size.left, m.size.top);
|
||||
let (r, b) = (l + m.size.right, t + m.size.bottom);
|
||||
(x >= l && x < r && y >= t && y < b).then_some(MonitorId::from_u32(m.id))
|
||||
(x >= l && x < r && y >= t && y < b).then_some(m.id)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -693,7 +757,7 @@ fn test_default() -> Option<Arc<dyn Backend>> {
|
||||
/// fake.open_window(7, "foot", "foot", "a terminal");
|
||||
///
|
||||
/// let titles = with_backend(fake.clone(), || {
|
||||
/// backend().windows().into_iter().map(|w| w.title).collect::<Vec<_>>()
|
||||
/// backend().windows().into_iter().filter_map(|w| w.title).collect::<Vec<_>>()
|
||||
/// });
|
||||
///
|
||||
/// assert_eq!(titles, ["a terminal"]);
|
||||
|
||||
@@ -35,30 +35,13 @@ impl<B: Backend + ?Sized> Shared<B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn window_info(info: super::WindowInfo) -> shared::WindowInfo {
|
||||
shared::WindowInfo {
|
||||
id: WindowId::from_u32(info.id),
|
||||
pid: info.pid,
|
||||
rect: info.rect,
|
||||
minimized: info.minimized,
|
||||
alive: info.alive,
|
||||
title: Some(info.title),
|
||||
class: Some(info.class),
|
||||
exe: Some(info.exe),
|
||||
path: Some(info.path),
|
||||
fullscreen: Some(info.fullscreen),
|
||||
maximized: Some(info.maximized),
|
||||
normal: Some(info.normal),
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend + ?Sized> shared::Backend for Shared<B> {
|
||||
fn windows(&self) -> Vec<shared::WindowInfo> {
|
||||
self.0.windows().into_iter().map(window_info).collect()
|
||||
self.0.windows()
|
||||
}
|
||||
|
||||
fn window(&self, id: WindowId) -> Option<shared::WindowInfo> {
|
||||
self.0.window(id).map(window_info)
|
||||
self.0.window(id)
|
||||
}
|
||||
|
||||
fn foreground_window(&self) -> Option<WindowId> {
|
||||
@@ -66,18 +49,7 @@ impl<B: Backend + ?Sized> shared::Backend for Shared<B> {
|
||||
}
|
||||
|
||||
fn monitors(&self) -> shared::Result<Vec<shared::MonitorInfo>> {
|
||||
Ok(self
|
||||
.0
|
||||
.monitors()?
|
||||
.into_iter()
|
||||
.map(|m| shared::MonitorInfo {
|
||||
id: MonitorId::from_u32(m.id),
|
||||
size: m.size,
|
||||
work_area: m.work_area,
|
||||
name: Some(m.name),
|
||||
serial_number_id: Some(m.serial_number_id),
|
||||
})
|
||||
.collect())
|
||||
self.0.monitors()
|
||||
}
|
||||
|
||||
fn cursor_pos(&self) -> Option<(i32, i32)> {
|
||||
|
||||
@@ -86,6 +86,7 @@ pub fn latest_monitor_information() -> eyre::Result<Vec<Monitor>> {
|
||||
Ok(backend()
|
||||
.monitors()?
|
||||
.into_iter()
|
||||
.map(crate::backend::MonitorInfo::from)
|
||||
.map(|m| Monitor::new(m.id, m.size, m.work_area, &m.name, &m.serial_number_id))
|
||||
.collect())
|
||||
}
|
||||
@@ -351,7 +352,11 @@ pub fn load_workspace_information(wm: &mut WindowManager) -> eyre::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
for info in backend().windows() {
|
||||
for info in backend()
|
||||
.windows()
|
||||
.into_iter()
|
||||
.map(crate::backend::WindowInfo::from)
|
||||
{
|
||||
if info.minimized {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -93,8 +93,6 @@ mod wallpaper;
|
||||
use crate::DATA_DIR;
|
||||
use crate::backend::Backend;
|
||||
use crate::backend::Look;
|
||||
use crate::backend::MonitorInfo;
|
||||
use crate::backend::WindowInfo;
|
||||
use crate::core::Rect;
|
||||
use crate::monitor_reconciliator;
|
||||
use crate::window_manager_event_listener;
|
||||
@@ -825,13 +823,19 @@ impl KWinBackend {
|
||||
}
|
||||
|
||||
impl Backend for KWinBackend {
|
||||
fn windows(&self) -> Vec<WindowInfo> {
|
||||
self.shared.table.lock().windows()
|
||||
fn windows(&self) -> Vec<komorebi_backend::WindowInfo> {
|
||||
self.shared
|
||||
.table
|
||||
.lock()
|
||||
.windows()
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn window(&self, id: WindowId) -> Option<WindowInfo> {
|
||||
fn window(&self, id: WindowId) -> Option<komorebi_backend::WindowInfo> {
|
||||
let id = id.to_u32()?;
|
||||
self.shared.table.lock().window(id)
|
||||
self.shared.table.lock().window(id).map(Into::into)
|
||||
}
|
||||
|
||||
fn foreground_window(&self) -> Option<WindowId> {
|
||||
@@ -852,12 +856,12 @@ impl Backend for KWinBackend {
|
||||
self.shared.table.lock().drag_end(id)
|
||||
}
|
||||
|
||||
fn monitors(&self) -> komorebi_backend::Result<Vec<MonitorInfo>> {
|
||||
fn monitors(&self) -> komorebi_backend::Result<Vec<komorebi_backend::MonitorInfo>> {
|
||||
let monitors = self.shared.table.lock().monitors();
|
||||
if monitors.is_empty() {
|
||||
return Err(platform(eyre::eyre!("KWin reported no outputs")));
|
||||
}
|
||||
Ok(monitors)
|
||||
Ok(monitors.into_iter().map(Into::into).collect())
|
||||
}
|
||||
|
||||
fn cursor_pos(&self) -> Option<(i32, i32)> {
|
||||
|
||||
@@ -460,7 +460,7 @@ impl WindowManager {
|
||||
// an app that remembers it was maximized opens that way
|
||||
if backend()
|
||||
.window(WindowId::from_u32(window_id))
|
||||
.is_some_and(|w| w.maximized)
|
||||
.is_some_and(|w| w.maximized == Some(true))
|
||||
{
|
||||
self.update_known_window_ids();
|
||||
self.adopt_maximize_change(window_id, true)?;
|
||||
|
||||
@@ -192,7 +192,7 @@ impl Window {
|
||||
|
||||
/// What the compositor knows about this window, including for a few moments after it closed
|
||||
pub fn info(self) -> Option<crate::backend::WindowInfo> {
|
||||
backend().window(self.window_id())
|
||||
backend().window(self.window_id()).map(Into::into)
|
||||
}
|
||||
|
||||
/// Whether the window still exists
|
||||
@@ -263,7 +263,7 @@ impl Window {
|
||||
pub fn is_fullscreen(self) -> bool {
|
||||
backend()
|
||||
.window(self.window_id())
|
||||
.is_some_and(|w| w.fullscreen)
|
||||
.is_some_and(|w| w.fullscreen == Some(true))
|
||||
}
|
||||
|
||||
/// Asks the compositor to draw the window with this opacity, 255 being not see-through at all
|
||||
|
||||
Reference in new issue
Block a user