1 | 1 |
mod window;
|
2 | 2 |
|
3 | |
use std::ptr;
|
4 | |
use std::io::Write;
|
5 | 3 |
use std::os::unix::io::AsRawFd;
|
6 | |
|
7 | 4 |
use pango::LayoutExt;
|
8 | 5 |
|
9 | |
use window::{Event,Window};
|
| 6 |
use window::{Display,Event,Window};
|
10 | 7 |
|
11 | 8 |
fn main() {
|
12 | |
unsafe {
|
13 | |
let mut w = Window::create();
|
14 | |
w.change_property(
|
15 | |
"_NET_WM_WINDOW_TYPE",
|
16 | |
&["_NET_WM_WINDOW_TYPE_DOCK"],
|
17 | |
);
|
| 9 |
let mut d = Display::create();
|
| 10 |
let width = d.get_width();
|
| 11 |
let mut w = Window::create(d, width, 36);
|
| 12 |
w.change_property(
|
| 13 |
"_NET_WM_WINDOW_TYPE",
|
| 14 |
&["_NET_WM_WINDOW_TYPE_DOCK"],
|
| 15 |
);
|
18 | 16 |
|
19 | |
w.change_property(
|
20 | |
"_NET_WM_STRUT_PARTIAL",
|
21 | |
&[
|
22 | |
0, 0, 36, 0,
|
23 | |
0, 0, 0, 0,
|
24 | |
0, 3840, 0, 0i64,
|
25 | |
],
|
26 | |
);
|
27 | |
w.change_property(
|
28 | |
"_NET_WM_STRUT",
|
29 | |
&[0i64, 0, 36, 0],
|
30 | |
);
|
| 17 |
w.change_property(
|
| 18 |
"_NET_WM_STRUT_PARTIAL",
|
| 19 |
&[
|
| 20 |
0, 0, 36, 0,
|
| 21 |
0, 0, 0, 0,
|
| 22 |
0, width as i64, 0, 0,
|
| 23 |
],
|
| 24 |
);
|
| 25 |
w.change_property(
|
| 26 |
"_NET_WM_STRUT",
|
| 27 |
&[0i64, 0, 36, 0],
|
| 28 |
);
|
31 | 29 |
|
32 | |
w.set_title("rbar");
|
| 30 |
w.set_title("rbar");
|
33 | 31 |
|
34 | |
w.set_input_masks();
|
| 32 |
w.set_input_masks();
|
35 | 33 |
|
36 | |
w.set_protocols();
|
37 | |
w.map();
|
| 34 |
w.set_protocols();
|
| 35 |
w.map();
|
38 | 36 |
|
39 | |
let surf = w.get_cairo_surface();
|
40 | |
let ctx = cairo::Context::new(&surf);
|
| 37 |
let surf = w.get_cairo_surface();
|
| 38 |
let ctx = cairo::Context::new(&surf);
|
41 | 39 |
|
42 | |
let window_fd = w.get_fd();
|
| 40 |
let window_fd = w.get_fd();
|
43 | 41 |
|
44 | |
let mut fds = std::mem::uninitialized();
|
45 | |
let mut input = format!("Loading...");
|
46 | |
let stdin_fd = std::io::stdin().as_raw_fd();
|
47 | |
let mut stdin = std::io::BufReader::new(std::io::stdin());
|
48 | |
let mut timer = libc::timeval {
|
49 | |
tv_sec: 5,
|
50 | |
tv_usec: 0,
|
51 | |
};
|
52 | |
let mut log = std::fs::File::create("/home/gdritter/log.txt").unwrap();
|
53 | |
draw(&ctx, "[1]");
|
| 42 |
let mut fds = unsafe { std::mem::uninitialized() };
|
| 43 |
let mut input = format!("Loading...");
|
| 44 |
let stdin_fd = std::io::stdin().as_raw_fd();
|
| 45 |
let mut stdin = std::io::BufReader::new(std::io::stdin());
|
| 46 |
let mut timer = libc::timeval {
|
| 47 |
tv_sec: 5,
|
| 48 |
tv_usec: 0,
|
| 49 |
};
|
| 50 |
draw(&ctx, "[1]", width);
|
54 | 51 |
|
55 | |
loop {
|
56 | |
use std::io::BufRead;
|
| 52 |
loop {
|
| 53 |
use std::io::BufRead;
|
57 | 54 |
|
| 55 |
unsafe {
|
58 | 56 |
libc::FD_ZERO(&mut fds);
|
59 | 57 |
libc::FD_SET(window_fd, &mut fds);
|
60 | 58 |
libc::FD_SET(stdin_fd, &mut fds);
|
61 | 59 |
|
62 | |
libc::select(window_fd + 1, &mut fds, ptr::null_mut(), ptr::null_mut(), &mut timer);
|
| 60 |
libc::select(
|
| 61 |
window_fd + 1,
|
| 62 |
&mut fds,
|
| 63 |
std::ptr::null_mut(),
|
| 64 |
std::ptr::null_mut(),
|
| 65 |
&mut timer,
|
| 66 |
);
|
| 67 |
}
|
63 | 68 |
|
64 | |
if libc::FD_ISSET(stdin_fd, &mut fds) {
|
65 | |
input = String::new();
|
66 | |
stdin.read_line(&mut input).unwrap();
|
67 | |
log.write_fmt(format_args!("got {}", input)).unwrap();
|
68 | |
if input == "" {
|
69 | |
break;
|
70 | |
}
|
71 | |
draw(&ctx, &input);
|
| 69 |
if unsafe { libc::FD_ISSET(stdin_fd, &mut fds) } {
|
| 70 |
input = String::new();
|
| 71 |
stdin.read_line(&mut input).unwrap();
|
| 72 |
if input == "" {
|
| 73 |
break;
|
72 | 74 |
}
|
| 75 |
draw(&ctx, &input, width);
|
| 76 |
}
|
73 | 77 |
|
74 | |
while w.has_events() {
|
75 | |
draw(&ctx, &input);
|
76 | |
match w.handle() {
|
77 | |
Event::QuitEvent => break,
|
78 | |
Event::ShowEvent =>
|
79 | |
draw(&ctx, &input),
|
80 | |
_e => (),
|
81 | |
}
|
| 78 |
while w.has_events() {
|
| 79 |
draw(&ctx, &input, width);
|
| 80 |
match w.handle() {
|
| 81 |
Event::QuitEvent => break,
|
| 82 |
Event::ShowEvent =>
|
| 83 |
draw(&ctx, &input, width),
|
| 84 |
_e => (),
|
82 | 85 |
}
|
| 86 |
}
|
83 | 87 |
|
84 | |
}
|
85 | 88 |
}
|
86 | 89 |
}
|
87 | 90 |
|
88 | 91 |
|
89 | |
fn draw(ctx: &cairo::Context, left: &str) {
|
| 92 |
fn draw(ctx: &cairo::Context, left: &str, width: i32) {
|
90 | 93 |
let now = time::now();
|
91 | 94 |
|
92 | 95 |
ctx.set_source_rgb(0.1, 0.1, 0.1);
|
|
95 | 98 |
|
96 | 99 |
let layout = pangocairo::functions::create_layout(&ctx).unwrap();
|
97 | 100 |
layout.set_alignment(pango::Alignment::Right);
|
98 | |
layout.set_width((3840 - 20) * pango::SCALE);
|
| 101 |
layout.set_width((width - 20) * pango::SCALE);
|
99 | 102 |
let mut font = pango::FontDescription::from_string("Fira Mono 18");
|
100 | 103 |
font.set_weight(pango::Weight::Bold);
|
101 | 104 |
layout.set_font_description(&font);
|