mirror of
https://github.com/2e3s/awatcher.git
synced 2025-07-21 17:40:08 +00:00
Improve x11 error texts
This commit is contained in:
parent
cc50f221a6
commit
56f492438f
@ -19,14 +19,18 @@ const KWIN_SCRIPT: &str = include_str!("kwin_window.js");
|
||||
|
||||
struct KWinScript {
|
||||
dbus_connection: Connection,
|
||||
is_loaded: bool,
|
||||
}
|
||||
|
||||
impl KWinScript {
|
||||
fn new(dbus_connection: Connection) -> Self {
|
||||
KWinScript { dbus_connection }
|
||||
KWinScript {
|
||||
dbus_connection,
|
||||
is_loaded: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn load(&self) -> Result<(), BoxedError> {
|
||||
fn load(&mut self) -> Result<(), BoxedError> {
|
||||
let path = temp_dir().join("kwin_window.js");
|
||||
std::fs::write(&path, KWIN_SCRIPT).unwrap();
|
||||
|
||||
@ -34,6 +38,7 @@ impl KWinScript {
|
||||
.get_registered_number(&path)
|
||||
.and_then(|number| self.start(number));
|
||||
std::fs::remove_file(&path)?;
|
||||
self.is_loaded = true;
|
||||
|
||||
result
|
||||
}
|
||||
@ -99,10 +104,12 @@ impl KWinScript {
|
||||
|
||||
impl Drop for KWinScript {
|
||||
fn drop(&mut self) {
|
||||
debug!("Unloading KWin script");
|
||||
if let Err(e) = self.unload() {
|
||||
error!("Problem during stopping KWin script: {e}");
|
||||
};
|
||||
if self.is_loaded {
|
||||
debug!("Unloading KWin script");
|
||||
if let Err(e) = self.unload() {
|
||||
error!("Problem during stopping KWin script: {e}");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,13 +48,15 @@ impl X11Connection {
|
||||
|
||||
let name = self.get_property(
|
||||
focus,
|
||||
self.intern_atom(b"_NET_WM_NAME")?,
|
||||
self.intern_atom(b"UTF8_STRING")?,
|
||||
self.intern_atom("_NET_WM_NAME")?,
|
||||
"_NET_WM_NAME",
|
||||
self.intern_atom("UTF8_STRING")?,
|
||||
u32::MAX,
|
||||
)?;
|
||||
let class = self.get_property(
|
||||
focus,
|
||||
AtomEnum::WM_CLASS.into(),
|
||||
"WM_CLASS",
|
||||
AtomEnum::STRING.into(),
|
||||
u32::MAX,
|
||||
)?;
|
||||
@ -71,23 +73,37 @@ impl X11Connection {
|
||||
&self,
|
||||
window: Window,
|
||||
property: Atom,
|
||||
property_name: &str,
|
||||
property_type: Atom,
|
||||
long_length: u32,
|
||||
) -> Result<GetPropertyReply, BoxedError> {
|
||||
self.connection
|
||||
.get_property(false, window, property, property_type, 0, long_length)?
|
||||
.get_property(false, window, property, property_type, 0, long_length)
|
||||
.map_err(|e| format!("GetPropertyRequest[{property_name}] failed: {e}"))?
|
||||
.reply()
|
||||
.map_err(std::convert::Into::into)
|
||||
.map_err(|e| format!("GetPropertyReply[{property_name}] failed: {e}").into())
|
||||
}
|
||||
|
||||
fn intern_atom(&self, name: &[u8]) -> Result<Atom, BoxedError> {
|
||||
Ok(self.connection.intern_atom(false, name)?.reply()?.atom)
|
||||
fn intern_atom(&self, name: &str) -> Result<Atom, BoxedError> {
|
||||
Ok(self
|
||||
.connection
|
||||
.intern_atom(false, name.as_bytes())
|
||||
.map_err(|_| format!("InternAtomRequest[{name}] failed"))?
|
||||
.reply()
|
||||
.map_err(|_| format!("InternAtomReply[{name}] failed"))?
|
||||
.atom)
|
||||
}
|
||||
|
||||
fn find_active_window(&self) -> Result<Window, BoxedError> {
|
||||
let window: Atom = AtomEnum::WINDOW.into();
|
||||
let net_active_window = self.intern_atom(b"_NET_ACTIVE_WINDOW")?;
|
||||
let active_window = self.get_property(self.screen_root, net_active_window, window, 1)?;
|
||||
let net_active_window = self.intern_atom("_NET_ACTIVE_WINDOW")?;
|
||||
let active_window = self.get_property(
|
||||
self.screen_root,
|
||||
net_active_window,
|
||||
"_NET_ACTIVE_WINDOW",
|
||||
window,
|
||||
1,
|
||||
)?;
|
||||
|
||||
if active_window.format == 32 && active_window.length == 1 {
|
||||
active_window
|
||||
|
@ -29,8 +29,11 @@ impl WindowWatcher {
|
||||
|
||||
impl Watcher for WindowWatcher {
|
||||
fn new() -> Result<Self, crate::BoxedError> {
|
||||
let connection = X11Connection::new()?;
|
||||
connection.active_window_data()?;
|
||||
|
||||
Ok(WindowWatcher {
|
||||
connection: X11Connection::new()?,
|
||||
connection,
|
||||
last_title: String::new(),
|
||||
last_app_id: String::new(),
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user