Merge branch 'feature/persist-window-geometry' into 'master'
Issue #50: Persist window geometry See merge request alatiera/Hammond!25
This commit is contained in:
commit
1d32018c02
@ -10,6 +10,27 @@
|
|||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
<schema path="/org/gnome/hammond/" id="org.gnome.Hammond">
|
<schema path="/org/gnome/hammond/" id="org.gnome.Hammond">
|
||||||
|
<key name="persist-window-geometry-top" type="i">
|
||||||
|
<default>-1</default>
|
||||||
|
<summary>Top position of the last open main window</summary>
|
||||||
|
</key>
|
||||||
|
<key name="persist-window-geometry-left" type="i">
|
||||||
|
<default>-1</default>
|
||||||
|
<summary>Left position of the last open main window</summary>
|
||||||
|
</key>
|
||||||
|
<key name="persist-window-geometry-height" type="i">
|
||||||
|
<default>640</default>
|
||||||
|
<summary>Height of the last open main window</summary>
|
||||||
|
</key>
|
||||||
|
<key name="persist-window-geometry-width" type="i">
|
||||||
|
<default>860</default>
|
||||||
|
<summary>Width of the last open main window</summary>
|
||||||
|
</key>
|
||||||
|
<key name="persist-window-geometry-maximized" type="b">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>Maximized state of the last open main window</summary>
|
||||||
|
</key>
|
||||||
|
|
||||||
<key name="dark-theme" type="b">
|
<key name="dark-theme" type="b">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
<summary>Enable or disable dark theme</summary>
|
<summary>Enable or disable dark theme</summary>
|
||||||
|
|||||||
@ -13,6 +13,7 @@ use hammond_data::utils::delete_show;
|
|||||||
|
|
||||||
use appnotif::*;
|
use appnotif::*;
|
||||||
use headerbar::Header;
|
use headerbar::Header;
|
||||||
|
use settings::WindowGeometry;
|
||||||
use stacks::Content;
|
use stacks::Content;
|
||||||
use utils;
|
use utils;
|
||||||
use widgets::mark_all_watched;
|
use widgets::mark_all_watched;
|
||||||
@ -57,6 +58,7 @@ pub struct App {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new() -> App {
|
pub fn new() -> App {
|
||||||
|
let settings = Settings::new("org.gnome.Hammond");
|
||||||
let application = gtk::Application::new("org.gnome.Hammond", ApplicationFlags::empty())
|
let application = gtk::Application::new("org.gnome.Hammond", ApplicationFlags::empty())
|
||||||
.expect("Application Initialization failed...");
|
.expect("Application Initialization failed...");
|
||||||
|
|
||||||
@ -66,10 +68,14 @@ impl App {
|
|||||||
|
|
||||||
// Create the main window
|
// Create the main window
|
||||||
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
||||||
window.set_default_size(860, 640);
|
|
||||||
window.set_title("Hammond");
|
window.set_title("Hammond");
|
||||||
|
|
||||||
let app_clone = application.clone();
|
let app_clone = application.clone();
|
||||||
|
let window_clone = window.clone();
|
||||||
|
let settings_clone = settings.clone();
|
||||||
window.connect_delete_event(move |_, _| {
|
window.connect_delete_event(move |_, _| {
|
||||||
|
WindowGeometry::from_window(&window_clone).write(&settings_clone);
|
||||||
app_clone.quit();
|
app_clone.quit();
|
||||||
Inhibit(false)
|
Inhibit(false)
|
||||||
});
|
});
|
||||||
@ -90,8 +96,6 @@ impl App {
|
|||||||
// Add the overlay to the main window
|
// Add the overlay to the main window
|
||||||
window.add(&overlay);
|
window.add(&overlay);
|
||||||
|
|
||||||
let settings = Settings::new("org.gnome.Hammond");
|
|
||||||
|
|
||||||
App {
|
App {
|
||||||
app_instance: application,
|
app_instance: application,
|
||||||
window,
|
window,
|
||||||
@ -149,7 +153,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self) {
|
pub fn run(self) {
|
||||||
|
WindowGeometry::from_settings(&self.settings).apply(&self.window);
|
||||||
|
|
||||||
let window = self.window.clone();
|
let window = self.window.clone();
|
||||||
|
|
||||||
self.app_instance.connect_startup(move |app| {
|
self.app_instance.connect_startup(move |app| {
|
||||||
build_ui(&window, app);
|
build_ui(&window, app);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -67,6 +67,7 @@ pub mod stacks;
|
|||||||
pub mod headerbar;
|
pub mod headerbar;
|
||||||
pub mod app;
|
pub mod app;
|
||||||
|
|
||||||
|
pub mod settings;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod manager;
|
pub mod manager;
|
||||||
pub mod static_resource;
|
pub mod static_resource;
|
||||||
|
|||||||
90
hammond-gtk/src/settings.rs
Normal file
90
hammond-gtk/src/settings.rs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
use gio;
|
||||||
|
use gio::SettingsExt;
|
||||||
|
use gtk;
|
||||||
|
use gtk::GtkWindowExt;
|
||||||
|
|
||||||
|
pub struct WindowGeometry {
|
||||||
|
left: i32,
|
||||||
|
top: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
is_maximized: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WindowGeometry {
|
||||||
|
pub fn from_window(window: >k::Window) -> WindowGeometry {
|
||||||
|
let position = window.get_position();
|
||||||
|
let size = window.get_size();
|
||||||
|
let left = position.0;
|
||||||
|
let top = position.1;
|
||||||
|
let width = size.0;
|
||||||
|
let height = size.1;
|
||||||
|
let is_maximized = window.is_maximized();
|
||||||
|
|
||||||
|
WindowGeometry {
|
||||||
|
left,
|
||||||
|
top,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
is_maximized,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_settings(settings: &gio::Settings) -> WindowGeometry {
|
||||||
|
let top = settings.get_int("persist-window-geometry-top");
|
||||||
|
let left = settings.get_int("persist-window-geometry-left");
|
||||||
|
let width = settings.get_int("persist-window-geometry-width");
|
||||||
|
let height = settings.get_int("persist-window-geometry-height");
|
||||||
|
let is_maximized = settings.get_boolean("persist-window-geometry-maximized");
|
||||||
|
|
||||||
|
WindowGeometry {
|
||||||
|
left,
|
||||||
|
top,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
is_maximized,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply(&self, window: >k::Window) {
|
||||||
|
if self.width > 0 && self.height > 0 {
|
||||||
|
window.resize(self.width, self.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.is_maximized {
|
||||||
|
window.maximize();
|
||||||
|
} else if self.top > 0 && self.left > 0 {
|
||||||
|
window.move_(self.left, self.top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write(&self, settings: &gio::Settings) {
|
||||||
|
settings.set_int("persist-window-geometry-left", self.left);
|
||||||
|
settings.set_int("persist-window-geometry-top", self.top);
|
||||||
|
settings.set_int("persist-window-geometry-width", self.width);
|
||||||
|
settings.set_int("persist-window-geometry-height", self.height);
|
||||||
|
settings.set_boolean("persist-window-geometry-maximized", self.is_maximized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
|
// fn test_apply_window_geometry() {
|
||||||
|
// gtk::init().expect("Error initializing gtk.");
|
||||||
|
|
||||||
|
// let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
||||||
|
// let _geometry = WindowGeometry {
|
||||||
|
// left: 0,
|
||||||
|
// top: 0,
|
||||||
|
// width: 100,
|
||||||
|
// height: 100,
|
||||||
|
// is_maximized: true
|
||||||
|
// };
|
||||||
|
|
||||||
|
// assert!(!window.is_maximized());
|
||||||
|
|
||||||
|
// window.show();
|
||||||
|
// window.activate();
|
||||||
|
// geometry.apply(&window);
|
||||||
|
|
||||||
|
// assert!(window.is_maximized());
|
||||||
|
// }
|
||||||
Loading…
Reference in New Issue
Block a user