|
@@ -1,20 +1,12 @@
|
|
|
extern crate xcb;
|
|
|
|
|
|
+use wm::atom;
|
|
|
use std::mem;
|
|
|
|
|
|
-const ATOMS: [&'static str; 3] = [
|
|
|
- "_NET_ACTIVE_WINDOW",
|
|
|
- "_NET_WM_NAME",
|
|
|
- "UTF8_STRING"
|
|
|
-];
|
|
|
-
|
|
|
-#[allow(non_snake_case)]
|
|
|
pub struct EWMH<'a> {
|
|
|
pub conn: &'a xcb::Connection,
|
|
|
pub root: xcb::Window,
|
|
|
- pub _NET_ACTIVE_WINDOW: xcb::Atom,
|
|
|
- pub _NET_WM_NAME: xcb::Atom,
|
|
|
- pub UTF8_STRING: xcb::Atom
|
|
|
+ pub atoms: atom::Atoms
|
|
|
}
|
|
|
|
|
|
pub struct WinClass {
|
|
@@ -25,24 +17,16 @@ pub struct WinClass {
|
|
|
pub fn connect<'a>(conn: &'a xcb::Connection, screen_num: i32) -> EWMH {
|
|
|
let setup = conn.get_setup();
|
|
|
let screen = setup.roots().nth(screen_num as usize).unwrap();
|
|
|
- let atoms: Vec<xcb::Atom> = ATOMS
|
|
|
- .iter()
|
|
|
- .map(|name| xcb::intern_atom(&conn, false, name))
|
|
|
- .map(|cookie| cookie.get_reply().unwrap().atom())
|
|
|
- .collect();
|
|
|
-
|
|
|
EWMH {
|
|
|
conn: conn,
|
|
|
root: screen.root(),
|
|
|
- _NET_ACTIVE_WINDOW: atoms[0],
|
|
|
- _NET_WM_NAME: atoms[1],
|
|
|
- UTF8_STRING: atoms[2]
|
|
|
+ atoms: atom::load_atoms(conn)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
impl<'a> EWMH<'a> {
|
|
|
pub fn get_active_window(&self) -> xcb::Window {
|
|
|
- let cookie = xcb::get_property(&self.conn, false, self.root, self._NET_ACTIVE_WINDOW, xcb::ATOM_WINDOW, 0, 4);
|
|
|
+ let cookie = xcb::get_property(&self.conn, false, self.root, self.atoms._NET_ACTIVE_WINDOW, xcb::ATOM_WINDOW, 0, 4);
|
|
|
let reply = cookie.get_reply().unwrap();
|
|
|
if reply.value_len() == 0 {
|
|
|
0
|
|
@@ -54,7 +38,7 @@ impl<'a> EWMH<'a> {
|
|
|
}
|
|
|
|
|
|
pub fn get_window_name(&self, win: xcb::Window) -> String {
|
|
|
- let cookie = xcb::get_property(&self.conn, false, win, self._NET_WM_NAME, self.UTF8_STRING, 0, 100);
|
|
|
+ let cookie = xcb::get_property(&self.conn, false, win, self.atoms._NET_WM_NAME, self.atoms.UTF8_STRING, 0, 100);
|
|
|
let reply = cookie.get_reply();
|
|
|
let value: &str = match reply {
|
|
|
Ok(reply) => unsafe { mem::transmute(reply.value()) },
|