Skip to content

Commit

Permalink
remove menu bar in fullscreen and add full screen cli flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Jun 29, 2024
1 parent 289e047 commit 27c032d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
5 changes: 4 additions & 1 deletion simp.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
.SH NAME
simp \- The simple image manipulation program
.SH SYNOPSIS
\fBsimp\fR [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIFILE\fR]
\fBsimp\fR [\fB\-f\fR|\fB\-\-fullscreen\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIFILE\fR]
.SH DESCRIPTION
The simple image manipulation program
.SH OPTIONS
.TP
\fB\-f\fR, \fB\-\-fullscreen\fR
Start simp in fullscreen
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help
.TP
Expand Down
6 changes: 1 addition & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pub struct App {
dialog_manager: DialogManager,
color_type: ColorType,
size: Vector2<f32>,
fullscreen: bool,
top_bar_size: f32,
bottom_bar_size: f32,
proxy: EventLoopProxy<UserEvent>,
Expand Down Expand Up @@ -381,7 +380,7 @@ impl App {

self.main_area(wgpu, ctx);

if !self.fullscreen {
if wgpu.window.fullscreen().is_none() {
self.menu_bar(wgpu, ctx);
self.bottom_bar(ctx);
}
Expand Down Expand Up @@ -572,13 +571,11 @@ impl App {
let fullscreen = wgpu.window.fullscreen();
if fullscreen.is_some() {
wgpu.window.set_fullscreen(None);
self.fullscreen = false;
self.top_bar_size = TOP_BAR_SIZE;
self.bottom_bar_size = BOTTOM_BAR_SIZE;
} else {
wgpu.window
.set_fullscreen(Some(Fullscreen::Borderless(None)));
self.fullscreen = true;
self.top_bar_size = 0.0;
self.bottom_bar_size = 0.0;
}
Expand Down Expand Up @@ -1131,7 +1128,6 @@ impl App {
dialog_manager,
color_type: ColorType::Rgba8,
size: Vector2::from(size),
fullscreen: false,
top_bar_size: TOP_BAR_SIZE,
bottom_bar_size: BOTTOM_BAR_SIZE,
proxy,
Expand Down
7 changes: 7 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ pub fn get_clap_command() -> clap::Command {
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.version(env!("CARGO_PKG_VERSION"))
.arg(
clap::Arg::new("FULLSCREEN")
.short('f')
.long("fullscreen")
.help("Start simp in fullscreen")
.action(clap::ArgAction::SetTrue),
)
.arg(clap::Arg::new("FILE").help("Load this file").index(1))
}
23 changes: 12 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy},
keyboard::{Key, ModifiersState},
window::{Window, WindowBuilder},
window::{Fullscreen, Window, WindowBuilder},
};
mod cli;
mod image_io;
Expand Down Expand Up @@ -60,19 +60,26 @@ pub struct WindowHandler<'a> {
}

impl<'a> WindowHandler<'a> {
pub async fn new() -> Self {
pub async fn new(fullscreen: bool) -> Self {
let mut config: Config = confy::load("simp", None).unwrap_or_default();
config.preferences.clamp();

let event_loop: EventLoop<UserEvent> = EventLoopBuilder::with_user_event().build().unwrap();
let proxy = event_loop.create_proxy();

let fullscreen = if fullscreen {
Some(Fullscreen::Borderless(None))
} else {
None
};

let builder = WindowBuilder::new()
.with_title(String::from("Simp"))
.with_visible(false)
.with_min_inner_size(winit::dpi::LogicalSize::new(640f64, 400f64))
.with_inner_size(winit::dpi::LogicalSize::new(1100f64, 720f64))
.with_maximized(config.maximized)
.with_fullscreen(fullscreen)
.with_window_icon(Some(icon::get_icon()));

#[cfg(all(unix, not(target_os = "macos")))]
Expand Down Expand Up @@ -419,23 +426,17 @@ impl WindowHandler<'_> {

fn main() {
panic::set_hook(Box::new(|panic_info| {
let dirs = directories::UserDirs::new();
let mut path = PathBuf::from("panic.txt");
if let Some(dirs) = dirs {
if let Some(desktop) = dirs.desktop_dir() {
path = desktop.to_path_buf().join("panic.txt");
}
}
eprintln!("{panic_info:?}");
let _ = fs::write(path, format!("{panic_info:?}"));
let _ = fs::write("panic.txt", format!("{panic_info:?}"));
std::process::exit(1);
}));

let matches = cli::get_clap_command().get_matches();

let path: Option<&String> = matches.get_one("FILE");
let fullscreen: bool = matches.get_flag("FULLSCREEN");

let mut window_handler = pollster::block_on(WindowHandler::new());
let mut window_handler = pollster::block_on(WindowHandler::new(fullscreen));

if !io::stdin().is_terminal() {
let proxy = window_handler.proxy.clone();
Expand Down

0 comments on commit 27c032d

Please sign in to comment.