Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenesvk committed Feb 1, 2025
1 parent 8d9c086 commit 0e51d83
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 33 deletions.
89 changes: 65 additions & 24 deletions examples/topless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ use ::tracing::info;
fn main() -> Result<(), Box<dyn Error>> {
tracing::init();

println!("Topless mode (Windows only):
println!(
"Topless mode (Windows only):
− title bar (WS_CAPTION) via with_titlebar (false)
+ resize border (WS_SIZEBOX) via with_resizable (true ) ≝
− top resize border via with_top_resize_border(false)
├ not a separate WS_ window style, 'manual' removal on NonClientArea events
└ only implemented for windows without a title bar, eg, with a custom title bar handling resizing from the top
└ only implemented for windows without a title bar, eg, with a custom title bar handling \
resizing from the top
——————————————————————————————
Press a key for (un)setting/querying a specific parameter (modifiers are ignored):
on off toggle status
title bar q w e r
resize border a s d f
─ top resize border z x c v
");
"
);

let event_loop = EventLoop::new()?;

Expand Down Expand Up @@ -65,14 +68,13 @@ use winit::platform::windows::WindowExtWindows;
#[cfg(windows_platform)]
impl ApplicationHandler for Application {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
let window_attributes =
WindowAttributes::default().with_title("Topless (unless you see this)!")
.with_decorations (true )// decorations ≝true
.with_titlebar (false)// titlebar ≝true
.with_resizable (true )// resizable ≝true
.with_top_resize_border(false)// top_resize_border ≝true
.with_position(dpi::Position::Logical(dpi::LogicalPosition::new(0.0,0.0)))// position: Option<Position>
;
let window_attributes = WindowAttributes::default()
.with_title("Topless (unless you see this)!")
.with_decorations(true) // decorations ≝true
.with_titlebar(false) // titlebar ≝true
.with_resizable(true) // resizable ≝true
.with_top_resize_border(false) // top_resize_border ≝true
.with_position(dpi::Position::Logical(dpi::LogicalPosition::new(0.0, 0.0)));
self.window = Some(event_loop.create_window(window_attributes).unwrap());
}

Expand All @@ -84,25 +86,64 @@ impl ApplicationHandler for Application {
) {
let win = match self.window.as_ref() {
Some(win) => win,
None => return,
None => return,
};
let _modi = ModifiersState::default();
match event {
WindowEvent::KeyboardInput { event, .. } => {
if event.state == ElementState::Pressed && !event.repeat {
match event.key_without_modifiers().as_ref() {
Key::Character("q") => {win.set_titlebar(true ) ;info!("set_titlebar → true")}
Key::Character("w") => {win.set_titlebar(false) ;info!("set_titlebar → false")}
Key::Character("e") => {let flip = !win.is_titlebar() ; win.set_titlebar (flip) ;info!("set_titlebar → {flip}")}
Key::Character("r") => {let is = win.is_titlebar() ;info!("is_titlebar = {is}")}
Key::Character("a") => {win.set_resizable(true ) ;info!("set_resizable → true")}
Key::Character("s") => {win.set_resizable(false) ;info!("set_resizable → false")}
Key::Character("d") => {let flip = !win.is_resizable() ; win.set_resizable (flip) ;info!("set_resizable → {flip}")}
Key::Character("f") => {let is = win.is_resizable() ;info!("is_resizable = {is}")}
Key::Character("z") => {win.set_top_resize_border(true ) ;info!("set_top_resize_border→ true")}
Key::Character("x") => {win.set_top_resize_border(false) ;info!("set_top_resize_border→ false")}
Key::Character("c") => {let flip = !win.is_top_resize_border(); win.set_top_resize_border(flip) ;info!("set_top_resize_border→ {flip}")}
Key::Character("v") => {let is = win.is_top_resize_border() ;info!("is_top_resize_border = {is}")}
Key::Character("q") => {
win.set_titlebar(true);
info!("set_titlebar → true")
},
Key::Character("w") => {
win.set_titlebar(false);
info!("set_titlebar → false")
},
Key::Character("e") => {
let flip = !win.is_titlebar();
win.set_titlebar(flip);
info!("set_titlebar → {flip}")
},
Key::Character("r") => {
let is = win.is_titlebar();
info!("is_titlebar = {is}")
},
Key::Character("a") => {
win.set_resizable(true);
info!("set_resizable → true")
},
Key::Character("s") => {
win.set_resizable(false);
info!("set_resizable → false")
},
Key::Character("d") => {
let flip = !win.is_resizable();
win.set_resizable(flip);
info!("set_resizable → {flip}")
},
Key::Character("f") => {
let is = win.is_resizable();
info!("is_resizable = {is}")
},
Key::Character("z") => {
win.set_top_resize_border(true);
info!("set_top_resize_border→ true")
},
Key::Character("x") => {
win.set_top_resize_border(false);
info!("set_top_resize_border→ false")
},
Key::Character("c") => {
let flip = !win.is_top_resize_border();
win.set_top_resize_border(flip);
info!("set_top_resize_border→ {flip}")
},
Key::Character("v") => {
let is = win.is_top_resize_border();
info!("is_top_resize_border = {is}")
},
_ => (),
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,12 +1138,15 @@ unsafe fn public_window_callback_inner(
let callback = || match msg {
WM_NCCALCSIZE => {
let window_flags = userdata.window_state_lock().window_flags;
// Remove top resize border from an untitled window t to free up area for, eg, a custom title bar, which should then handle resizing events itself
// Remove top resize border from an untitled window t to free up area for, eg, a custom
// title bar, which should then handle resizing events itself
if wparam != 0
&& !window_flags.contains(WindowFlags::TITLE_BAR)
&& !window_flags.contains(WindowFlags::TOP_RESIZE_BORDER)
&& window_flags.contains(WindowFlags::RESIZABLE)
&& !util::is_maximized(window) { // maximized wins have no borders
&& !window_flags.contains(WindowFlags::TITLE_BAR)
&& !window_flags.contains(WindowFlags::TOP_RESIZE_BORDER)
&& window_flags.contains(WindowFlags::RESIZABLE)
&& !util::is_maximized(window)
{
// maximized wins have no borders
result = ProcResult::DefWindowProc(wparam);
let rect = unsafe { &mut *(lparam as *mut RECT) };
let adj_rect = userdata
Expand Down Expand Up @@ -2282,9 +2285,10 @@ unsafe fn public_window_callback_inner(

WM_NCACTIVATE => {
let window_flags = userdata.window_state_lock().window_flags;
if !window_flags.contains(WindowFlags::TITLE_BAR)
&& !window_flags.contains(WindowFlags::TOP_RESIZE_BORDER)
&& window_flags.contains(WindowFlags::RESIZABLE) {
if !window_flags.contains(WindowFlags::TITLE_BAR)
&& !window_flags.contains(WindowFlags::TOP_RESIZE_BORDER)
&& window_flags.contains(WindowFlags::RESIZABLE)
{
lparam = -1;
}
let is_active = wparam != false.into();
Expand Down
3 changes: 2 additions & 1 deletion src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,8 @@ unsafe fn init(
let mut window_flags = WindowFlags::empty();
window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations);
window_flags.set(WindowFlags::TITLE_BAR, attributes.platform_specific.titlebar);
window_flags.set(WindowFlags::TOP_RESIZE_BORDER, attributes.platform_specific.top_resize_border);
window_flags
.set(WindowFlags::TOP_RESIZE_BORDER, attributes.platform_specific.top_resize_border);
window_flags.set(
WindowFlags::MARKER_UNDECORATED_SHADOW,
attributes.platform_specific.decoration_shadow,
Expand Down

0 comments on commit 0e51d83

Please sign in to comment.