|
@@ -4,6 +4,7 @@ extern crate chan_signal;
|
|
extern crate xcb;
|
|
extern crate xcb;
|
|
|
|
|
|
mod atom;
|
|
mod atom;
|
|
|
|
+mod tray;
|
|
|
|
|
|
use std::thread;
|
|
use std::thread;
|
|
use std::sync::Arc;
|
|
use std::sync::Arc;
|
|
@@ -15,41 +16,30 @@ fn main() {
|
|
let conn = Arc::new(conn);
|
|
let conn = Arc::new(conn);
|
|
let atoms = atom::Atoms::new(&conn);
|
|
let atoms = atom::Atoms::new(&conn);
|
|
|
|
|
|
- let setup = conn.get_setup();
|
|
|
|
- let screen = setup.roots().nth(preferred as usize).unwrap();
|
|
|
|
-
|
|
|
|
- let owner = xcb::get_selection_owner(&conn, atoms.get(&atom::_NET_SYSTEM_TRAY_S0)).get_reply().unwrap().owner();
|
|
|
|
|
|
+ let owner = xcb::get_selection_owner(&conn, atoms.get(atom::_NET_SYSTEM_TRAY_S0)).get_reply().unwrap().owner();
|
|
if owner != xcb::NONE {
|
|
if owner != xcb::NONE {
|
|
println!("Another system tray is already running");
|
|
println!("Another system tray is already running");
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- let window = conn.generate_id();
|
|
|
|
- xcb::create_window(
|
|
|
|
- &conn,
|
|
|
|
- xcb::COPY_FROM_PARENT as u8,
|
|
|
|
- window,
|
|
|
|
- screen.root(),
|
|
|
|
- 0, 0,
|
|
|
|
- 20, 20,
|
|
|
|
- 0,
|
|
|
|
- xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
|
|
|
|
- screen.root_visual(),
|
|
|
|
- &[
|
|
|
|
- (xcb::CW_BACK_PIXEL, screen.black_pixel()),
|
|
|
|
- (xcb::CW_EVENT_MASK, xcb::EVENT_MASK_EXPOSURE)
|
|
|
|
- ]
|
|
|
|
- );
|
|
|
|
- xcb::map_window(&conn, window);
|
|
|
|
- conn.flush();
|
|
|
|
|
|
+ let tray = tray::Tray::new(&conn, &atoms, preferred as usize);
|
|
|
|
+ tray.create();
|
|
|
|
+ if !tray.take_selection() {
|
|
|
|
+ println!("Could not take ownership of tray selection. Maybe another tray is also running?");
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
{
|
|
{
|
|
let conn = conn.clone();
|
|
let conn = conn.clone();
|
|
|
|
+ const CLIENT_MESSAGE: u8 = xcb::CLIENT_MESSAGE | 0x80;
|
|
thread::spawn(move || {
|
|
thread::spawn(move || {
|
|
loop {
|
|
loop {
|
|
match conn.wait_for_event() {
|
|
match conn.wait_for_event() {
|
|
Some(event) => match event.response_type() {
|
|
Some(event) => match event.response_type() {
|
|
xcb::EXPOSE => { println!("expose") },
|
|
xcb::EXPOSE => { println!("expose") },
|
|
|
|
+ CLIENT_MESSAGE => {
|
|
|
|
+ println!("client message");
|
|
|
|
+ },
|
|
_ => {}
|
|
_ => {}
|
|
},
|
|
},
|
|
None => { break; }
|
|
None => { break; }
|
|
@@ -67,8 +57,6 @@ fn main() {
|
|
}
|
|
}
|
|
|
|
|
|
// cleanup code
|
|
// cleanup code
|
|
- xcb::destroy_window(&conn, window);
|
|
|
|
- conn.flush();
|
|
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
println!("Could not connect to X server!");
|
|
println!("Could not connect to X server!");
|