title_bar: Fix move window support for Linux. (#368)
This commit is contained in:
parent
2c979c32c5
commit
2aaf424df9
2 changed files with 107 additions and 21 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -29,7 +29,7 @@ jobs:
|
||||||
target/
|
target/
|
||||||
key: ubuntu-test-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ubuntu-test-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
- name: Install Tools
|
- name: Install Tools
|
||||||
run: cargo install typos-cli
|
run: cargo install typos-cli || echo "typos-cli already installed"
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: |
|
run: |
|
||||||
cargo clippy -- --deny warnings
|
cargo clippy -- --deny warnings
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, px, AnyElement, Hsla, InteractiveElement as _, IntoElement,
|
div, prelude::FluentBuilder as _, px, relative, AnyElement, Element, Hsla,
|
||||||
ParentElement, Pixels, RenderOnce, StatefulInteractiveElement as _, Styled, WindowContext,
|
InteractiveElement as _, IntoElement, ParentElement, Pixels, RenderOnce,
|
||||||
|
StatefulInteractiveElement as _, Style, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// TitleBar used to customize the appearance of the title bar.
|
/// TitleBar used to customize the appearance of the title bar.
|
||||||
|
|
@ -174,34 +175,119 @@ impl RenderOnce for WindowControls {
|
||||||
|
|
||||||
impl RenderOnce for TitleBar {
|
impl RenderOnce for TitleBar {
|
||||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
|
let is_linux = cfg!(target_os = "linux");
|
||||||
let macos_pl = if cfg!(target_os = "macos") {
|
let macos_pl = if cfg!(target_os = "macos") {
|
||||||
Some(px(80.))
|
Some(px(80.))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
h_flex()
|
const HEIGHT: Pixels = px(34.);
|
||||||
.id("title-bar")
|
|
||||||
|
div()
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.items_center()
|
|
||||||
.justify_between()
|
|
||||||
.pl(px(12.))
|
|
||||||
.when(!cx.is_fullscreen(), |this| {
|
|
||||||
// Leave space for the macOS window controls.
|
|
||||||
this.when_some(macos_pl, |this, pl| this.pl(pl))
|
|
||||||
})
|
|
||||||
.border_b_1()
|
|
||||||
.border_color(cx.theme().title_bar_border)
|
|
||||||
.bg(cx.theme().title_bar_background)
|
|
||||||
.on_double_click(|_, cx| cx.zoom_window())
|
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.h(px(34.))
|
.id("title-bar")
|
||||||
|
.items_center()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.flex_shrink_0()
|
.h(HEIGHT)
|
||||||
.flex_1()
|
.pl(px(12.))
|
||||||
.children(self.children),
|
.when(!cx.is_fullscreen(), |this| {
|
||||||
|
// Leave space for the macOS window controls.
|
||||||
|
this.when_some(macos_pl, |this, pl| this.pl(pl))
|
||||||
|
})
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(cx.theme().title_bar_border)
|
||||||
|
.bg(cx.theme().title_bar_background)
|
||||||
|
.on_double_click(|_, cx| cx.zoom_window())
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.h_full()
|
||||||
|
.justify_between()
|
||||||
|
.flex_shrink_0()
|
||||||
|
.flex_1()
|
||||||
|
.children(self.children),
|
||||||
|
)
|
||||||
|
.child(WindowControls {}),
|
||||||
)
|
)
|
||||||
.child(WindowControls {})
|
.when(is_linux, |this| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.top_0()
|
||||||
|
.left_0()
|
||||||
|
.absolute()
|
||||||
|
.size_full()
|
||||||
|
.h_full()
|
||||||
|
.child(TitleBarElement {}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TitleBarElement {}
|
||||||
|
|
||||||
|
impl IntoElement for TitleBarElement {
|
||||||
|
type Element = Self;
|
||||||
|
|
||||||
|
fn into_element(self) -> Self::Element {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Element for TitleBarElement {
|
||||||
|
type RequestLayoutState = ();
|
||||||
|
|
||||||
|
type PrepaintState = ();
|
||||||
|
|
||||||
|
fn id(&self) -> Option<gpui::ElementId> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_layout(
|
||||||
|
&mut self,
|
||||||
|
_: Option<&gpui::GlobalElementId>,
|
||||||
|
cx: &mut WindowContext,
|
||||||
|
) -> (gpui::LayoutId, Self::RequestLayoutState) {
|
||||||
|
let mut style = Style::default();
|
||||||
|
style.flex_grow = 1.0;
|
||||||
|
style.flex_shrink = 1.0;
|
||||||
|
style.size.width = relative(1.).into();
|
||||||
|
style.size.height = relative(1.).into();
|
||||||
|
|
||||||
|
let id = cx.request_layout(style, []);
|
||||||
|
(id, ())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepaint(
|
||||||
|
&mut self,
|
||||||
|
_: Option<&gpui::GlobalElementId>,
|
||||||
|
_: gpui::Bounds<Pixels>,
|
||||||
|
_: &mut Self::RequestLayoutState,
|
||||||
|
_: &mut WindowContext,
|
||||||
|
) -> Self::PrepaintState {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
fn paint(
|
||||||
|
&mut self,
|
||||||
|
_: Option<&gpui::GlobalElementId>,
|
||||||
|
bounds: gpui::Bounds<Pixels>,
|
||||||
|
_: &mut Self::RequestLayoutState,
|
||||||
|
_: &mut Self::PrepaintState,
|
||||||
|
cx: &mut WindowContext,
|
||||||
|
) {
|
||||||
|
use gpui::{MouseButton, MouseMoveEvent, MouseUpEvent};
|
||||||
|
cx.on_mouse_event(move |ev: &MouseMoveEvent, _, cx: &mut WindowContext| {
|
||||||
|
if bounds.contains(&ev.position) && ev.pressed_button == Some(MouseButton::Left) {
|
||||||
|
cx.start_window_move();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.on_mouse_event(move |ev: &MouseUpEvent, _, cx: &mut WindowContext| {
|
||||||
|
if ev.button == MouseButton::Left {
|
||||||
|
cx.show_window_menu(ev.position);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue