summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 56c8629b83373a4d142af3ed355003442d8781c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use gio::prelude::*;
use gtk::prelude::*;

use glib::clone;

use std::cell::RefCell;
use std::env::args;
use std::rc::Rc;

mod systray;

fn build_ui(application: &gtk::Application) {
    let window = gtk::ApplicationWindow::new(application);

    window.set_title("First GTK+ Program");
    window.set_border_width(10);
    window.set_position(gtk::WindowPosition::Center);
    window.set_default_size(350, 70);

    let disp = gdk::DisplayManager::get()
        .get_default_display()
        .expect("Strange");
    let screen = disp.get_default_screen();

    let vbox = gtk::Box::new(gtk::Orientation::Vertical, 2);
    window.add(&vbox);
    let tray = Rc::new(RefCell::new(systray::Systray::manage_screen(&screen)));
    vbox.add(tray.borrow().get_tray_widget());
    let label = gtk::Label::new(Some("Nothing to see here"));
    vbox.add(&label);
    gtk::timeout_add(
        1000,
        clone!(@weak tray => @default-return glib::Continue(false), move || {
            println!("Notifying potential clients");
            tray.borrow().notify_potential_clients();
            glib::Continue(false)
        }),
    );
    window.connect_destroy(move |_| {
        tray.borrow_mut().unmanage();
    });

    window.show_all();
}

fn main() {
    let application = gtk::Application::new(Some("org.digital-scurf.basic"), Default::default())
        .expect("Initialization failed...");

    application.connect_activate(|app| {
        build_ui(app);
    });

    application.run(&args().collect::<Vec<_>>());
}