Desktop: Hook up native window controls (#3161)
* Implement window controls * Fix drag target size * Maximize with drag area double click
This commit is contained in:
parent
e97d5520e8
commit
944a6eeea2
|
|
@ -164,6 +164,11 @@ impl WinitApp {
|
||||||
window.set_minimized(minimized);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DesktopFrontendMessage::DragWindow => {
|
||||||
|
if let Some(window) = &self.window {
|
||||||
|
let _ = window.drag_window();
|
||||||
|
}
|
||||||
|
}
|
||||||
DesktopFrontendMessage::CloseWindow => {
|
DesktopFrontendMessage::CloseWindow => {
|
||||||
let _ = self.event_loop_proxy.send_event(CustomEvent::CloseWindow);
|
let _ = self.event_loop_proxy.send_event(CustomEvent::CloseWindow);
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +276,9 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
|
||||||
let mut window = Window::default_attributes()
|
let mut window = Window::default_attributes()
|
||||||
.with_title(APP_NAME)
|
.with_title(APP_NAME)
|
||||||
.with_min_inner_size(winit::dpi::LogicalSize::new(400, 300))
|
.with_min_inner_size(winit::dpi::LogicalSize::new(400, 300))
|
||||||
.with_inner_size(winit::dpi::LogicalSize::new(1200, 800));
|
.with_inner_size(winit::dpi::LogicalSize::new(1200, 800))
|
||||||
|
.with_decorations(false)
|
||||||
|
.with_resizable(true);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
|
||||||
// Forward this to update the UI
|
// Forward this to update the UI
|
||||||
return Some(message);
|
return Some(message);
|
||||||
}
|
}
|
||||||
|
FrontendMessage::DragWindow => {
|
||||||
|
dispatcher.respond(DesktopFrontendMessage::DragWindow);
|
||||||
|
}
|
||||||
FrontendMessage::CloseWindow => {
|
FrontendMessage::CloseWindow => {
|
||||||
dispatcher.respond(DesktopFrontendMessage::CloseWindow);
|
dispatcher.respond(DesktopFrontendMessage::CloseWindow);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ pub enum DesktopFrontendMessage {
|
||||||
maximized: bool,
|
maximized: bool,
|
||||||
minimized: bool,
|
minimized: bool,
|
||||||
},
|
},
|
||||||
|
DragWindow,
|
||||||
|
CloseWindow,
|
||||||
PersistenceWriteDocument {
|
PersistenceWriteDocument {
|
||||||
id: DocumentId,
|
id: DocumentId,
|
||||||
document: Document,
|
document: Document,
|
||||||
|
|
@ -55,7 +57,6 @@ pub enum DesktopFrontendMessage {
|
||||||
preferences: Preferences,
|
preferences: Preferences,
|
||||||
},
|
},
|
||||||
PersistenceLoadPreferences,
|
PersistenceLoadPreferences,
|
||||||
CloseWindow,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum DesktopWrapperMessage {
|
pub enum DesktopWrapperMessage {
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,6 @@ pub enum AppWindowMessage {
|
||||||
AppWindowMinimize,
|
AppWindowMinimize,
|
||||||
AppWindowMaximize,
|
AppWindowMaximize,
|
||||||
AppWindowUpdatePlatform { platform: AppWindowPlatform },
|
AppWindowUpdatePlatform { platform: AppWindowPlatform },
|
||||||
|
AppWindowDrag,
|
||||||
AppWindowClose,
|
AppWindowClose,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@ impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler {
|
||||||
self.platform = platform;
|
self.platform = platform;
|
||||||
responses.add(FrontendMessage::UpdatePlatform { platform: self.platform });
|
responses.add(FrontendMessage::UpdatePlatform { platform: self.platform });
|
||||||
}
|
}
|
||||||
|
AppWindowMessage::AppWindowDrag => {
|
||||||
|
responses.add(FrontendMessage::DragWindow);
|
||||||
|
}
|
||||||
AppWindowMessage::AppWindowClose => {
|
AppWindowMessage::AppWindowClose => {
|
||||||
responses.add(FrontendMessage::CloseWindow);
|
responses.add(FrontendMessage::CloseWindow);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -343,6 +343,7 @@ pub enum FrontendMessage {
|
||||||
maximized: bool,
|
maximized: bool,
|
||||||
minimized: bool,
|
minimized: bool,
|
||||||
},
|
},
|
||||||
|
DragWindow,
|
||||||
CloseWindow,
|
CloseWindow,
|
||||||
UpdateViewportHolePunch {
|
UpdateViewportHolePunch {
|
||||||
active: bool,
|
active: bool,
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
on:dragover
|
on:dragover
|
||||||
on:dragstart
|
on:dragstart
|
||||||
on:drop
|
on:drop
|
||||||
|
on:mousedown
|
||||||
on:mouseup
|
on:mouseup
|
||||||
on:pointerdown
|
on:pointerdown
|
||||||
on:pointerenter
|
on:pointerenter
|
||||||
|
|
@ -67,7 +68,6 @@ on:keydown
|
||||||
on:keypress
|
on:keypress
|
||||||
on:keyup
|
on:keyup
|
||||||
on:lostpointercapture
|
on:lostpointercapture
|
||||||
on:mousedown
|
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
on:mousemove
|
on:mousemove
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,15 @@
|
||||||
<TextButton label={entry.label} icon={entry.icon} menuListChildren={entry.children} action={entry.action} flush={true} />
|
<TextButton label={entry.label} icon={entry.icon} menuListChildren={entry.children} action={entry.action} flush={true} />
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
<LayoutRow on:mousedown={() => editor.handle.appWindowDrag()} on:dblclick={() => editor.handle.appWindowMaximize()} />
|
||||||
</LayoutRow>
|
</LayoutRow>
|
||||||
<!-- Document title -->
|
<!-- Document title -->
|
||||||
<LayoutRow class="center">
|
<LayoutRow class="center" on:mousedown={() => editor.handle.appWindowDrag()} on:dblclick={() => editor.handle.appWindowMaximize()}>
|
||||||
<WindowTitle text={windowTitle} />
|
<WindowTitle text={windowTitle} />
|
||||||
</LayoutRow>
|
</LayoutRow>
|
||||||
<!-- Window buttons (except on Mac) -->
|
<!-- Window buttons (except on Mac) -->
|
||||||
<LayoutRow class="right">
|
<LayoutRow class="right">
|
||||||
|
<LayoutRow on:mousedown={() => editor.handle.appWindowDrag()} on:dblclick={() => editor.handle.appWindowMaximize()} />
|
||||||
{#if platform === "Windows"}
|
{#if platform === "Windows"}
|
||||||
<WindowButtonsWindows {maximized} />
|
<WindowButtonsWindows {maximized} />
|
||||||
{:else if platform === "Linux"}
|
{:else if platform === "Linux"}
|
||||||
|
|
|
||||||
|
|
@ -352,6 +352,13 @@ impl EditorHandle {
|
||||||
self.dispatch(message);
|
self.dispatch(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drag the application window
|
||||||
|
#[wasm_bindgen(js_name = appWindowDrag)]
|
||||||
|
pub fn app_window_start_drag(&self) {
|
||||||
|
let message = AppWindowMessage::AppWindowDrag;
|
||||||
|
self.dispatch(message);
|
||||||
|
}
|
||||||
|
|
||||||
/// Displays a dialog with an error message
|
/// Displays a dialog with an error message
|
||||||
#[wasm_bindgen(js_name = errorDialog)]
|
#[wasm_bindgen(js_name = errorDialog)]
|
||||||
pub fn error_dialog(&self, title: String, description: String) {
|
pub fn error_dialog(&self, title: String, description: String) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue