-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor_area.rs
89 lines (80 loc) · 2.48 KB
/
monitor_area.rs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use gdk;
use gtk;
use gtk::{WidgetExt, OrientableExt};
use relm_attributes::widget;
use relm::{Widget};
use playout_backend::Monitor;
use playout_backend::feeds::{VideoConfig, Feed};
use std::rc::Rc;
use gtk::Orientation::Vertical;
#[derive(Msg)]
pub enum MonitorAreaMsg {
Realized,
SetLabelAndPath(String, String),
}
pub struct MonitorAreaModel {
label: String,
feed_path: String,
monitor: Option<Rc<Monitor>>
}
extern {
fn gdk_x11_window_get_xid(window: gdk::Window) -> u32;
}
#[widget]
impl Widget for MonitorArea {
fn model(_: ()) -> MonitorAreaModel {
MonitorAreaModel {label: String::new(), feed_path: String::new(), monitor: None}
}
fn update(&mut self, event: MonitorAreaMsg) {
match event {
MonitorAreaMsg::Realized => {
let feed_path = self.model.feed_path.clone();
let monitor = self.create_monitor(&feed_path);
self.model.monitor = monitor;
}
MonitorAreaMsg::SetLabelAndPath(label, path) => {
self.model.label = label;
self.model.feed_path = path.clone();
let monitor = self.create_monitor(&path);
self.model.monitor = monitor;
}
}
}
view! {
gtk::Box {
orientation: Vertical,
#[name="drawing_area"]
gtk::DrawingArea {
property_width_request: 356,
property_height_request: 200,
realize => MonitorAreaMsg::Realized,
},
gtk::Label {
text: &self.model.label
}
}
}
}
impl MonitorArea {
fn set_name_and_path(&mut self, label: &str, feed_path: &str) {
self.model.label = String::from(label);
self.model.feed_path = String::from(feed_path);
}
fn get_xid(&mut self) -> u32 {
let window = self.drawing_area.get_window().unwrap();
unsafe {
gdk_x11_window_get_xid(window)
}
}
fn create_monitor(&mut self, socket_path: &str) -> Option<Rc<Monitor>> {
// todo This config should not be hard-coded.
// Config should come from backend.
let config = VideoConfig{width: 1280,
height: 720,
framerate: "30/1".to_string()};
let mut monitor = Monitor::new(socket_path, &config);
monitor.set_window_xid(self.get_xid());
monitor.play();
Some(Rc::new(monitor))
}
}