macos title double click fix
-use std::sync::Arc;
+use std::{sync::Arc, time::Instant};
use crate::svg::get_svg;
use druid::{
piet::{Text, TextLayout, TextLayoutBuilder},
BoxConstraints, Color, Command, Env, Event, EventCtx, FontFamily, LayoutCtx,
LifeCycle, LifeCycleCtx, MouseEvent, PaintCtx, Point, Rect, RenderContext, Size,
- Target, UpdateCtx, Widget,
+ Target, UpdateCtx, Widget, WindowConfig, WindowState,
};
use lapce_data::{
command::{
pub struct Title {
mouse_pos: Point,
commands: Vec<(Rect, Command)>,
+ last_mouse_up: Instant,
}
impl Title {
@@ -30,6 +31,7 @@ pub fn new() -> Self {
Self {
mouse_pos: Point::ZERO,
commands: Vec::new(),
+ last_mouse_up: Instant::now(),
}
}
@@ -62,7 +64,7 @@ fn event(
&mut self,
ctx: &mut EventCtx,
event: &Event,
- _data: &mut LapceWindowData,
+ data: &mut LapceWindowData,
_env: &Env,
) {
match event {
@@ -79,6 +81,22 @@ fn event(
Event::MouseDown(mouse_event) => {
self.mouse_down(ctx, mouse_event);
}
+ Event::MouseUp(_) => {
+ #[cfg(target_os = "macos")]
+ if self.last_mouse_up.elapsed().as_millis() < 500 {
+ let state = match ctx.window().get_window_state() {
+ WindowState::Maximized => WindowState::Restored,
+ WindowState::Restored => WindowState::Maximized,
+ WindowState::Minimized => WindowState::Maximized,
+ };
+ ctx.submit_command(
+ druid::commands::CONFIGURE_WINDOW
+ .with(WindowConfig::default().set_window_state(state))
+ .to(Target::Window(data.window_id)),
+ )
+ }
+ self.last_mouse_up = Instant::now();
+ }
_ => {}
}
}
