Merge pull request #641 from DJMcNab/fullscreen

Maintain maximised state across restarts
This commit is contained in:
Dongdong Zhou 2022-06-18 19:50:21 +01:00 committed by GitHub
commit d9870b996c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View File

@ -109,6 +109,7 @@ pub fn load(event_sink: ExtEventSink) -> Self {
let info = db.get_last_window_info().unwrap_or_else(|_| WindowInfo {
size: Size::new(800.0, 600.0),
pos: Point::new(0.0, 0.0),
maximised: false,
tabs: TabsInfo {
active_tab: 0,
workspaces: vec![],
@ -208,6 +209,7 @@ pub struct LapceWindowData {
pub watcher: Arc<notify::RecommendedWatcher>,
/// The size of the window.
pub size: Size,
pub maximised: bool,
/// The position of the window.
pub pos: Point,
}
@ -218,6 +220,7 @@ fn same(&self, other: &Self) -> bool {
&& self.tabs.same(&other.tabs)
&& self.size.same(&other.size)
&& self.pos.same(&other.pos)
&& self.maximised.same(&other.maximised)
&& self.keypress.same(&other.keypress)
&& self.plugins.same(&other.plugins)
}
@ -311,6 +314,7 @@ pub fn new(
watcher: Arc::new(watcher),
size: info.size,
pos: info.pos,
maximised: info.maximised,
}
}
@ -331,6 +335,7 @@ pub fn info(&self) -> WindowInfo {
WindowInfo {
size: self.size,
pos: self.pos,
maximised: self.maximised,
tabs: TabsInfo {
active_tab,
workspaces,

View File

@ -222,6 +222,7 @@ pub struct WorkspaceInfo {
pub struct WindowInfo {
pub size: Size,
pub pos: Point,
pub maximised: bool,
pub tabs: TabsInfo,
}

View File

@ -1,6 +1,7 @@
use druid::{
AppDelegate, AppLauncher, Command, Env, Event, LocalizedString, Menu, MenuItem,
Point, Size, SysMods, Widget, WidgetExt, WindowDesc, WindowHandle, WindowId,
WindowState,
};
use lapce_data::{
command::{LapceUICommand, LAPCE_UI_COMMAND},
@ -55,6 +56,7 @@ pub fn launch() {
root,
window_data.size,
window_data.pos,
window_data.maximised,
);
launcher = launcher.with_window(window);
}
@ -68,6 +70,7 @@ fn new_window_desc<W, T: druid::Data>(
root: W,
size: Size,
pos: Point,
maximised: bool,
) -> WindowDesc<T>
where
W: Widget<T> + 'static,
@ -76,6 +79,9 @@ fn new_window_desc<W, T: druid::Data>(
.title(LocalizedString::new("Lapce").with_placeholder("Lapce"))
.window_size(size)
.set_position(pos);
if maximised {
desc = desc.set_window_state(WindowState::Maximized);
}
if let Some(icon) = window_icon() {
desc = desc.with_window_icon(icon);
@ -189,17 +195,19 @@ fn command(
data: &mut LapceData,
_env: &Env,
) -> druid::Handled {
if cmd.is(LAPCE_UI_COMMAND) {
let command = cmd.get_unchecked(LAPCE_UI_COMMAND);
if let Some(command) = cmd.get(LAPCE_UI_COMMAND) {
if let LapceUICommand::NewWindow(from_window_id) = command {
let (size, pos) = data
.windows
.get(from_window_id)
// If maximised, use default dimensions instead
.filter(|win| !win.maximised)
.map(|win| (win.size, win.pos + (50.0, 50.0)))
.unwrap_or((Size::new(800.0, 600.0), Point::new(0.0, 0.0)));
let info = WindowInfo {
size,
pos,
maximised: false,
tabs: TabsInfo {
active_tab: 0,
workspaces: vec![],
@ -214,7 +222,13 @@ fn command(
let root = build_window(&window_data);
let window_id = window_data.window_id;
data.windows.insert(window_id, window_data);
let desc = new_window_desc(window_id, root, info.size, info.pos);
let desc = new_window_desc(
window_id,
root,
info.size,
info.pos,
info.maximised,
);
ctx.new_window(desc);
return druid::Handled::Yes;
}

View File

@ -3,7 +3,7 @@
widget::{LensWrap, WidgetExt},
BoxConstraints, Command, Env, Event, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, Point, RenderContext, Size, Target, Widget, WidgetId,
WidgetPod,
WidgetPod, WindowState,
};
use lapce_data::{
command::{LapceUICommand, LAPCE_UI_COMMAND},
@ -183,6 +183,10 @@ fn event(
Event::WindowSize(size) => {
ctx.set_handled();
data.size = *size;
data.maximised = matches!(
ctx.window().get_window_state(),
WindowState::Maximized
);
}
Event::WindowConnected => {
ctx.submit_command(Command::new(