Skip to content

Latest commit

 

History

History
103 lines (87 loc) · 7.63 KB

IMPLEMENTATION.md

File metadata and controls

103 lines (87 loc) · 7.63 KB

Implementation

Details of the implementation of menyoki.

Project Structure

mod.rs is used for the hierarchy of modules. Every directory in src/ is a module and its general methods/types are contained in a mod.rs file.

settings.rs file is commonly used for handling configuration based operations such as conditionally parsing command line arguments to set an option/flag for a particular module. It constructs a struct named XyzSettings where Xyz is generally the name of the module.

  • main.rs -> starts the application (App::new(...).start())
  • app.rs -> App (contains the application methods such as record, capture and edit_image)
  • settings.rs -> AppSettings
  • analyze
  • anim
  • apng
  • args
    • matches.rs -> ArgMatches (clap::ArgMatches wrapper for using configuration file and environment variables)
    • mod.rs -> Args (command line arguments)
    • parser.rs -> ArgParser (helper for parsing arguments)
  • edit
    • mod.rs -> ImageOps (contains image operations related functions such as crop, resize and rotate)
    • settings.rs -> ImageSettings, ColorSettings, EditSettings
  • file
    • format.rs -> FileFormat (enum for file formats)
    • info.rs -> FileInfo (enum for adding information to the file name)
    • mod.rs -> File (path + format)
    • settings.rs -> SaveSettings
  • gif
    • encoder.rs -> Encoder (trait that GIF encoders implement)
    • mod.rs -> GifEncoder (default GIF encoder)
    • ski.rs -> GifskiEncoder (gifski encoder, enabled with --gifski flag)
  • image
  • record
  • util
    • command.rs -> Command (for executing OS commands)
    • keys.rs -> ActionKeys, CancelKeys, KeyType (parser and checker)
    • logger.rs -> Logger (for initializing the logger)
    • mod.rs -> module declarations
    • state.rs -> InputState (checks the pressed keys)
  • view
  • window
    • mod.rs -> Access, Capture (crucial traits)
    • test.rs -> TestWindow (implements Capture trait for testing purposes)
  • ws
    • mod.rs -> WindowSystem (blank implementation of Access trait)
    • window.rs -> Window (blank implementation of Capture trait)
  • x11
    • display.rs -> Display (X11 display wrapper with methods like get_window and select_window)
    • mod.rs -> WindowSystem (implements Access trait for X11)
    • window.rs -> Window (X11 window wrapper with methods like get_geometry and get_name)

Implementing For Other Platforms

There are two crucial traits in src/window/mod.rs that need to be implemented for menyoki to function.

Access trait must be implemented for accessing the window system and getting a Window.

/* Window system functions for accessing a window */
pub trait Access<'a, Window: Capture + Send + Sync + Copy + Debug + 'static> {
	fn init(settings: &'a AppSettings<'a>) -> Option<Self>
	where
		Self: Sized;
	fn get_window(&mut self) -> Option<Window>;
}

As seen in the Access' definition, the Window that get_window provides must also implement Capture + Send + Sync + Copy + Debug with the 'static lifetime for thread safety.

Capture trait contains methods for getting an Image, showing a countdown on the window or the console and, releasing the captured window.

/* Window methods for capturing an image */
pub trait Capture {
	fn get_image(&self) -> Option<Image>;
	fn show_countdown(&self);
	fn release(&self);
}

As a reference: see src/x11/mod.rs (for Access implementation), src/x11/window.rs (for Capture implementation), and src/ws/* (for implementation templates).

The rest of the modules/functions are not platform-dependent (abstracted) so they are expected to work properly.

Contributing

If you're considering to contribute, please see the Contribution Guidelines.