Open teras opened 1 week ago
All good :)
Looking forward to it!
Actually I am not sure I can do this , at least alone. I know that I requested it, but it's not something I feel I can manage there.
Well, you've done 75% of the work already! If you have Discord or Matrix, feel free to join the OpenDeck chats and I can show you which bits of the OpenDeck internals you need to interface with ;)
I might have an old Discord account. We''l find some time that both of us are online.
Awesome
Recapping some info based on previous discussions.
When the focus moved to another application's window then (probably) a new profile should be selected. For example the focus is on FIrefox, now it's on Nemo, now it's on the Desktop (i.e. none).
This is a feature of the app itself, and this is what other applications are doing, and maybe the paradigm should be similar.
StreamController screenshot
StreamDeck screenshot
Demo code in rust
Cargo.toml
```toml [package] name = "focus_listener" version = "0.1.0" edition = "2021" [dependencies] x11rb = "0.13.1" ```
test.rs
```rust use std::error::Error; use x11rb::atom_manager; use x11rb::connection::Connection; use x11rb::protocol::xproto::{AtomEnum, ConnectionExt, EventMask, PropertyNotifyEvent, Window}; use x11rb::rust_connection::RustConnection; atom_manager! { pub Atoms: AtomsCookie { _NET_ACTIVE_WINDOW, WM_CLASS, _NET_WM_NAME, WM_NAME, UTF8_STRING, } } struct X11FocusListener { conn: RustConnection, root: Window, atoms: Atoms, last_active_window: Option,
}
impl X11FocusListener {
fn new() -> Result> {
let (conn, screen_num) = RustConnection::connect(None)?;
let screen = &conn.setup().roots[screen_num];
let root = screen.root;
let atoms = Atoms::new(&conn)?.reply()?;
conn.change_window_attributes(root, &x11rb::protocol::xproto::ChangeWindowAttributesAux::new()
.event_mask(EventMask::PROPERTY_CHANGE | EventMask::SUBSTRUCTURE_NOTIFY))?;
for child in conn.query_tree(root)?.reply()?.children {
conn.change_window_attributes(child, &x11rb::protocol::xproto::ChangeWindowAttributesAux::new()
.event_mask(EventMask::PROPERTY_CHANGE))?;
}
Ok(Self {
conn,
root,
atoms,
last_active_window: None,
})
}
fn get_next_focus_change(&mut self) -> Result<(String, String), Box> {
loop {
let event = self.conn.wait_for_event()?;
if let x11rb::protocol::Event::PropertyNotify(PropertyNotifyEvent { atom, .. }) = event {
if atom == self.atoms._NET_ACTIVE_WINDOW {
if let Ok(reply) = self.conn.get_property(false, self.root, self.atoms._NET_ACTIVE_WINDOW, AtomEnum::WINDOW, 0, 1)?.reply() {
if let Some(window_id) = reply.value32().and_then(|mut v| v.next()) {
if self.last_active_window != Some(window_id) {
self.last_active_window = Some(window_id);
let wm_class = self.get_window_class(window_id)?;
let wm_title = self.get_window_title(window_id)?;
return Ok((wm_title.unwrap_or_default(), wm_class.unwrap_or_default()));
}
}
}
}
}
}
}
fn get_window_class(&self, window: Window) -> Result
Some key notes need discussion