Commit 5c61a66f authored by Guillaume Desmottes's avatar Guillaume Desmottes 🐐

karapulse: move window code

parent 1e89e000
......@@ -11,7 +11,9 @@
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.
use failure::Error;
use gdk::prelude::*;
use glib::{Receiver, Sender};
use gtk::prelude::*;
use serde::Serialize;
use std::cell::{Cell, RefCell};
use std::convert::TryInto;
......@@ -259,7 +261,7 @@ impl ops::Deref for Karapulse {
impl Karapulse {
pub fn new(window: gtk::Window, tx: Sender<Message>, rx: Receiver<Message>, db: DB) -> Self {
let player = player::Player::new(window, tx).unwrap();
let player = player::Player::new(window.clone(), tx).unwrap();
let inner = KarapulseInner::new(player, db);
let inner = Rc::new(inner);
......@@ -288,6 +290,46 @@ impl Karapulse {
glib::Continue(true)
});
// Hide cursor in fullscreen
window.connect_window_state_event(|window, event| {
let change = event.get_changed_mask();
if change.contains(gdk::WindowState::FULLSCREEN) {
let new_state = event.get_new_window_state();
let win = window.get_window().unwrap();
let cursor = if new_state.contains(gdk::WindowState::FULLSCREEN) {
gdk::Cursor::new(gdk::CursorType::BlankCursor)
} else {
gdk::Cursor::new(gdk::CursorType::Arrow)
};
win.set_cursor(Some(&cursor));
}
Inhibit(false)
});
window.connect_key_press_event(move |window, key| {
let keyval = key.get_keyval();
match keyval {
gdk::enums::key::f => {
let win = window.get_window().unwrap();
let state = win.get_state();
if state.contains(gdk::WindowState::FULLSCREEN) {
window.unfullscreen();
} else {
window.fullscreen();
}
}
gdk::enums::key::Escape => window.unfullscreen(),
_ => {}
}
Inhibit(false)
});
window.set_size_request(800, 600);
window.fullscreen();
window.show_all();
Self { inner }
}
}
......
......@@ -13,8 +13,6 @@
use crate::config;
use crate::karapulse::Message;
use failure::Error;
use gdk;
use gdk::prelude::*;
use get_if_addrs::get_if_addrs;
use gettextrs::*;
use glib::Sender;
......@@ -273,46 +271,7 @@ impl Player {
let widget = gtkglsink.get_property("widget")?;
let widget = widget.get::<gtk::Widget>().unwrap().unwrap();
// Hide cursor in fullscreen
window.connect_window_state_event(|window, event| {
let change = event.get_changed_mask();
if change.contains(gdk::WindowState::FULLSCREEN) {
let new_state = event.get_new_window_state();
let win = window.get_window().unwrap();
let cursor = if new_state.contains(gdk::WindowState::FULLSCREEN) {
gdk::Cursor::new(gdk::CursorType::BlankCursor)
} else {
gdk::Cursor::new(gdk::CursorType::Arrow)
};
win.set_cursor(Some(&cursor));
}
Inhibit(false)
});
window.set_size_request(800, 600);
window.fullscreen();
window.add(&widget);
window.show_all();
window.connect_key_press_event(move |window, key| {
let keyval = key.get_keyval();
match keyval {
gdk::enums::key::f => {
let win = window.get_window().unwrap();
let state = win.get_state();
if state.contains(gdk::WindowState::FULLSCREEN) {
window.unfullscreen();
} else {
window.fullscreen();
}
}
gdk::enums::key::Escape => window.unfullscreen(),
_ => {}
}
Inhibit(false)
});
let player = Player {
pipeline: RefCell::new(Box::new(playbin)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment