-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic winit selection implementation
- Loading branch information
1 parent
7b0b050
commit e824241
Showing
15 changed files
with
479 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
use sss_lib::image::{ | ||
error::{ImageFormatHint, UnsupportedError, UnsupportedErrorKind}, | ||
ImageError, ImageFormat, | ||
}; | ||
use sss_lib::{Background, GenerationSettings, Shadow, ToRgba}; | ||
use sss_select::SelectConfig; | ||
|
||
#[derive(Clone, Debug, Parser)] | ||
#[clap(version, author)] | ||
pub struct CliConfig { | ||
#[clap( | ||
long, | ||
default_value = "false", | ||
help = "When you take from a screen or window, capture the one on which the mouse is located." | ||
)] | ||
pub current: bool, | ||
#[clap(long, default_value = "false", help = "Capture a full screen")] | ||
pub screen: bool, | ||
#[clap(long, default_value = "false", help = "Capture a application window")] | ||
pub window: bool, | ||
#[clap(long, default_value = "false", help = "Captures an area of the screen")] | ||
pub area: bool, | ||
// Screenshot Section | ||
#[clap( | ||
long, | ||
short, | ||
default_value = "#323232", | ||
help = "Support: '#RRGGBBAA' 'h;#RRGGBBAA;#RRGGBBAA' 'v;#RRGGBBAA;#RRGGBBAA' or file path" | ||
)] | ||
pub background: String, | ||
#[clap(long, short, default_value = "15")] | ||
pub radius: u32, | ||
// Padding Section | ||
#[clap(long, default_value = "80")] | ||
pub padding_x: u32, | ||
#[clap(long, default_value = "100")] | ||
pub padding_y: u32, | ||
// Shadow Section | ||
#[clap( | ||
long, | ||
default_value = "false", | ||
help = "Generate shadow from inner image" | ||
)] | ||
pub shadow_image: bool, | ||
#[clap( | ||
long, | ||
default_value = "#707070", | ||
help = "Support: '#RRGGBBAA' '#RRGGBBAA;#RRGGBBAA' or file path" | ||
)] | ||
pub shadow_color: String, | ||
#[clap(long, default_value = "50")] | ||
pub shadow_blur: f32, | ||
// Saving options | ||
#[clap(long, short = 'c', help = "Send the result to your clipboard")] | ||
pub just_copy: bool, | ||
#[clap( | ||
long, | ||
default_value = "None", | ||
help = "If it is set then the result will be saved here, otherwise it will not be saved." | ||
)] | ||
pub save_path: Option<PathBuf>, | ||
#[clap( | ||
long, | ||
short = 'f', | ||
default_value = "png", | ||
help = "The format in which the image will be saved", | ||
value_parser = str_to_format | ||
)] | ||
pub save_format: ImageFormat, | ||
} | ||
|
||
pub fn get_config() -> CliConfig { | ||
CliConfig::parse() | ||
} | ||
|
||
impl Into<GenerationSettings> for CliConfig { | ||
fn into(self) -> GenerationSettings { | ||
let background = Background::try_from(self.background.clone()).unwrap(); | ||
GenerationSettings { | ||
background: background.clone(), | ||
padding: (self.padding_x, self.padding_y), | ||
round_corner: Some(self.radius), | ||
shadow: Some(Shadow { | ||
background, | ||
use_inner_image: self.shadow_image, | ||
shadow_color: self.shadow_color.to_rgba().unwrap(), | ||
blur_radius: self.shadow_blur, | ||
}), | ||
} | ||
} | ||
} | ||
|
||
impl Into<SelectConfig> for CliConfig { | ||
fn into(self) -> SelectConfig { | ||
SelectConfig { | ||
current: self.current, | ||
screen: self.screen, | ||
window: self.window, | ||
area: self.area, | ||
} | ||
} | ||
} | ||
|
||
fn str_to_format(s: &str) -> Result<ImageFormat, ImageError> { | ||
ImageFormat::from_extension(s).ok_or(ImageError::Unsupported( | ||
UnsupportedError::from_format_and_kind( | ||
ImageFormatHint::Name(s.to_string()), | ||
UnsupportedErrorKind::Format(ImageFormatHint::Name(s.to_string())), | ||
), | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,30 @@ | ||
use font_kit::error::{FontLoadingError, SelectionError}; | ||
use std::error::Error; | ||
use std::fmt::{self, Display}; | ||
use std::num::ParseIntError; | ||
|
||
#[derive(Debug)] | ||
pub enum ImagenGeneration { | ||
Font(Font), | ||
Color(ParseColor), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Font { | ||
SelectionError(SelectionError), | ||
FontLoadingError(FontLoadingError), | ||
} | ||
|
||
impl Error for Font {} | ||
|
||
impl Display for Font { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
Font::SelectionError(e) => write!(f, "Font error: {}", e), | ||
Font::FontLoadingError(e) => write!(f, "Font error: {}", e), | ||
} | ||
} | ||
} | ||
use thiserror::Error; | ||
|
||
impl From<SelectionError> for Font { | ||
fn from(e: SelectionError) -> Self { | ||
Font::SelectionError(e) | ||
} | ||
#[derive(Debug, Error)] | ||
#[error(transparent)] | ||
pub enum ImagenGeneration { | ||
Color(#[from] ParseColor), | ||
Background(#[from] Background), | ||
} | ||
|
||
impl From<FontLoadingError> for Font { | ||
fn from(e: FontLoadingError) -> Self { | ||
Font::FontLoadingError(e) | ||
} | ||
#[derive(Debug, Error)] | ||
pub enum Background { | ||
#[error("Cannot Parse Background from String")] | ||
CannotParse, | ||
#[error("Invalid format of String")] | ||
InvalidFormat, | ||
#[error("Invalid path of image")] | ||
InvalidPath, | ||
} | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
#[derive(Debug, Error, Eq, PartialEq)] | ||
pub enum ParseColor { | ||
#[error("Invalid length of String")] | ||
InvalidLength, | ||
#[error("Invalid digit")] | ||
InvalidDigit, | ||
} | ||
|
||
impl Error for ParseColor {} | ||
|
||
impl Display for ParseColor { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
ParseColor::InvalidDigit => write!(f, "Invalid digit"), | ||
ParseColor::InvalidLength => write!(f, "Invalid length"), | ||
} | ||
} | ||
} | ||
|
||
impl From<ParseIntError> for ParseColor { | ||
fn from(_e: ParseIntError) -> Self { | ||
ParseColor::InvalidDigit | ||
} | ||
#[error("Error parsing number")] | ||
Parse(#[from] ParseIntError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "sss_select" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
raqote = "0.8.3" | ||
winit = "0.29.8" | ||
softbuffer = { version = "0.4.0", default-features = false, features = ["x11", "wayland"] } |
Oops, something went wrong.