Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
510 changes: 312 additions & 198 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pico-args = "0.3.0"
png = { version = "0.16.6" }
gif = "0.10.3"
chrono = "0.4.19"
glfw = { version = "0.41.0", optional = true }
glfw = { version = "0.45.0", optional = true }
raw-window-handle = { version = "0.3.3", optional = true }
snap = "0.2.5"
log = { version = "0.4.14", features = ["std"] }
Expand Down
1 change: 1 addition & 0 deletions config/init.rx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ map <return> :f/add -- Add a fr
map <backspace> :f/remove -- Remove a frame from the view
map/normal h :f/prev -- Navigate to previous frame
map/normal l :f/next -- Navigate to next frame
map s :fullscreen -- Toggle fullscreen mode

map/visual j :selection/move 0 -1
map/visual k :selection/move 0 1
Expand Down
11 changes: 9 additions & 2 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub enum Command {
Reset,
Map(Box<KeyMapping>),
MapClear,

Fullscreen,
Slice(Option<usize>),
Fill(Option<Rgba8>),

Expand Down Expand Up @@ -165,6 +165,7 @@ impl fmt::Display for Command {
Self::ForceQuitAll => write!(f, "Quit all views without saving"),
Self::Map(_) => write!(f, "Map a key combination to a command"),
Self::MapClear => write!(f, "Clear all key mappings"),
Self::Fullscreen => write!(f, "Toggle fullscreen"),
Self::Mode(Mode::Help) => write!(f, "Toggle help"),
Self::Mode(m) => write!(f, "Switch to {} mode", m),
Self::FrameAdd => write!(f, "Add a blank frame to the view"),
Expand All @@ -177,7 +178,7 @@ impl fmt::Display for Command {
Self::PaletteClear => write!(f, "Clear palette"),
Self::PaletteGradient(cs, ce, n) => write!(
f,
"Create {} colors gradient from {} to {}",
"Create {number} colors gradient from {colorstart} to {colorend}",
number = n,
colorstart = cs,
colorend = ce
Expand Down Expand Up @@ -290,6 +291,7 @@ impl From<Command> for String {
Command::Zoom(Op::Incr) => format!("v/zoom +"),
Command::Zoom(Op::Decr) => format!("v/zoom -"),
Command::Zoom(Op::Set(z)) => format!("v/zoom {}", z),
Command::Fullscreen => format!("fullscreen"),
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -905,6 +907,11 @@ impl Default for Commands {
.command("map/clear!", "Clear all key mappings", |p| {
p.value(Command::MapClear)
})
.command(
"fullscreen",
"Toggle between fullscreen and windowed",
|p| p.value(Command::Fullscreen),
)
.command("p/add", "Add a color to the palette", |p| {
p.then(color()).map(|(_, rgba)| Command::PaletteAdd(rgba))
})
Expand Down
44 changes: 43 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct Options<'a> {
pub exec: ExecutionMode,
pub glyphs: &'a [u8],
pub debug: bool,
pub fullscreen: bool,
}

impl<'a> Default for Options<'a> {
Expand All @@ -92,6 +93,7 @@ impl<'a> Default for Options<'a> {
exec: ExecutionMode::Normal,
glyphs: data::GLYPHS,
debug: false,
fullscreen: false,
}
}
}
Expand All @@ -109,6 +111,7 @@ pub fn init<P: AsRef<Path>>(paths: &[P], options: Options<'_>) -> std::io::Resul
"rx",
options.width,
options.height,
options.fullscreen,
hints,
platform::GraphicsContext::Gl,
)?;
Expand All @@ -126,14 +129,19 @@ pub fn init<P: AsRef<Path>>(paths: &[P], options: Options<'_>) -> std::io::Resul
let base_dirs = dirs::BaseDirs::new()
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "home directory not found"))?;
let cwd = std::env::current_dir()?;
let mut session = Session::new(win_w, win_h, cwd, proj_dirs, base_dirs)
let mut session = Session::new(options.fullscreen, win_w, win_h, cwd, proj_dirs, base_dirs)
.with_blank(
FileStatus::NoFile,
Session::DEFAULT_VIEW_W,
Session::DEFAULT_VIEW_H,
)
.init(options.source.clone())?;

session.prev_pos = win.handle.get_pos();

let (sx, sy) = win.handle.get_size();
session.prev_size = (sx as u32, sy as u32);

if options.debug {
session
.settings
Expand Down Expand Up @@ -170,6 +178,7 @@ pub fn init<P: AsRef<Path>>(paths: &[P], options: Options<'_>) -> std::io::Resul
if let Err(e) = session.edit(paths) {
session.message(format!("Error loading path(s): {}", e), MessageType::Error);
}

// Make sure our session ticks once before anything is rendered.
let effects = session.update(
&mut vec![],
Expand Down Expand Up @@ -297,6 +306,39 @@ pub fn init<P: AsRef<Path>>(paths: &[P], options: Options<'_>) -> std::io::Resul
};
}

if session.fullscreen_requested {
debug!("Toggled fullscreen");
if session.fullscreen {
win.handle.set_monitor(
glfw::WindowMode::Windowed,
session.prev_pos.0,
session.prev_pos.1,
session.prev_size.0,
session.prev_size.1,
None,
)
} else {
events.glfw.with_primary_monitor(|_, m| {
let mon = m.unwrap();
let mode = mon.get_video_mode().unwrap();

session.prev_pos = win.handle.get_pos();
let (sx, sy) = win.handle.get_size();
session.prev_size = (sx as u32, sy as u32);

win.handle.set_monitor(
glfw::WindowMode::FullScreen(mon),
0,
0,
mode.width,
mode.height,
None,
)
})
}
session.set_fullscreen();
}

if resized {
// Instead of responded to each resize event by creating a new framebuffer,
// we respond to the event *once*, here.
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OPTIONS
-v Verbose mode
-u <script> Use the commands in <script> for initialization

--fullscreen Start application in fullscreen mode
--record <dir> Record user input to a directory
--replay <dir> Replay user input from a directory
--width <width> Set the window width
Expand Down Expand Up @@ -53,6 +54,7 @@ fn execute(mut args: pico_args::Arguments) -> Result<(), Box<dyn std::error::Err

let verbose = args.contains("-v");
let debug = args.contains("--debug");
let fullscreen = args.contains("--fullscreen");
let width = args.opt_value_from_str("--width")?;
let height = args.opt_value_from_str("--height")?;
let record_digests = args.contains("--record-digests");
Expand Down Expand Up @@ -120,6 +122,7 @@ fn execute(mut args: pico_args::Arguments) -> Result<(), Box<dyn std::error::Err
exec,
glyphs,
debug,
fullscreen,
};

match args.free() {
Expand Down
32 changes: 28 additions & 4 deletions src/platform/glfw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn init(
title: &str,
w: u32,
h: u32,
fs: bool,
hints: &[WindowHint],
context: GraphicsContext,
) -> io::Result<(Window, Events)> {
Expand Down Expand Up @@ -44,9 +45,32 @@ pub fn init(
glfw.window_hint((*hint).into());
}

let (mut window, events) = glfw
.create_window(w, h, title, glfw::WindowMode::Windowed)
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "glfw: error creating window"))?;
let (mut window, events) = match fs {
true => glfw.with_primary_monitor(|glfw, m| {
let mon = m.ok_or_else(|| {
io::Error::new(
io::ErrorKind::Other,
"glfw: unable to detect primary monitor",
)
})?;
let mode = mon.get_video_mode().ok_or_else(|| {
io::Error::new(
io::ErrorKind::Other,
"glfw: unable to detect monitor video modes",
)
})?;
let w = mode.width;
let h = mode.height;
return glfw
.create_window(w as u32, h as u32, title, glfw::WindowMode::FullScreen(mon))
.ok_or_else(|| {
io::Error::new(io::ErrorKind::Other, "glfw: error creating window")
});
})?,
false => glfw
.create_window(w, h, title, glfw::WindowMode::Windowed)
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "glfw: error creating window"))?,
};

window.make_current();
window.set_all_polling(true);
Expand All @@ -67,7 +91,7 @@ pub fn init(

pub struct Events {
handle: sync::mpsc::Receiver<(f64, glfw::WindowEvent)>,
glfw: glfw::Glfw,
pub glfw: glfw::Glfw,
}

impl Events {
Expand Down
3 changes: 2 additions & 1 deletion src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ pub fn init(
title: &str,
w: u32,
h: u32,
fs: bool,
hints: &[WindowHint],
context: GraphicsContext,
) -> io::Result<(backend::Window, backend::Events)> {
backend::init(title, w, h, hints, context)
backend::init(title, w, h, fs, hints, context)
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
20 changes: 19 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,14 @@ pub struct Session {
/// the command is processed. For example, when displaying a message before
/// an expensive process is kicked off.
queue: Vec<InternalCommand>,

pub fullscreen: bool,

pub fullscreen_requested: bool,

pub prev_size: (u32, u32),

pub prev_pos: (i32, i32),
}

impl Session {
Expand Down Expand Up @@ -707,6 +715,7 @@ impl Session {

/// Create a new un-initialized session.
pub fn new<P: AsRef<Path>>(
fs: bool,
w: u32,
h: u32,
cwd: P,
Expand Down Expand Up @@ -751,6 +760,10 @@ impl Session {
avg_time: time::Duration::from_secs(0),
frame_number: 0,
queue: Vec::new(),
fullscreen: fs,
fullscreen_requested: false,
prev_size: (1280, 720),
prev_pos: (100, 100),
}
}

Expand Down Expand Up @@ -2678,7 +2691,6 @@ impl Session {
}
}
}
#[allow(mutable_borrow_reservation_conflict)]
Command::Toggle(ref k) => match self.settings.get(k) {
Some(Value::Bool(b)) => self.command(Command::Set(k.clone(), Value::Bool(!b))),
Some(_) => {
Expand Down Expand Up @@ -3017,9 +3029,15 @@ impl Session {
v.paint_color(*color, x, y);
}
}
Command::Fullscreen => self.fullscreen_requested = true,
};
}

pub fn set_fullscreen(&mut self) {
self.fullscreen = !self.fullscreen;
self.fullscreen_requested = false;
}

fn cmdline_hide(&mut self) {
self.switch_mode(self.prev_mode.unwrap_or(Mode::Normal));
}
Expand Down
2 changes: 2 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Config {
struct WindowConfig {
width: u32,
height: u32,
fullscreen: bool,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -152,6 +153,7 @@ fn run(name: &str) -> io::Result<()> {
source: Some(path.join(name).with_extension("rx")),
width: cfg.window.width,
height: cfg.window.height,
fullscreen: cfg.window.fullscreen,
exec: ExecutionMode::Replay(path.clone(), DigestMode::Verify),
glyphs,
debug: false,
Expand Down