Skip to content

Commit

Permalink
fix: home manager module
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Jan 29, 2024
1 parent 67c554f commit 2c64716
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 100 deletions.
1 change: 1 addition & 0 deletions crates/sss_lib/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct GenerationSettingsArgs {
#[clap(flatten)]
pub colors: ColorsArgs,
#[clap(flatten)]
#[serde(rename = "window-controls")]
pub window_controls: WindowControlsArgs,
}

Expand Down
16 changes: 10 additions & 6 deletions crates/sss_lib/src/img.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use arboard::SetExtLinux;
use image::imageops::{horizontal_gradient, resize, vertical_gradient, FilterType};
use image::{Rgba, RgbaImage};

Expand Down Expand Up @@ -121,12 +122,15 @@ pub fn generate_image(settings: GenerationSettings, content: impl DynImageConten
if settings.copy {
let mut c = arboard::Clipboard::new().unwrap();

c.set_image(arboard::ImageData {
width: img.width() as usize,
height: img.height() as usize,
bytes: std::borrow::Cow::Owned(img.to_vec()),
})
.unwrap();
c.set()
.clipboard(arboard::LinuxClipboardKind::Clipboard)
.wait()
.image(arboard::ImageData {
width: img.width() as usize,
height: img.height() as usize,
bytes: img.to_vec().into(),
})
.unwrap();
} else {
img.save_with_format(
&settings.output,
Expand Down
105 changes: 61 additions & 44 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,90 @@ with lib; let
system = pkgs.system;
};
cfgSSS = config.programs.sss;
cfgCode = config.programs.sssCode;
tomlFormat = pkgs.formats.toml {};
configDir =
if pkgs.stdenv.isDarwin
then "Library/Application Support"
else config.xdg.configHome;
sharedConfig = import ./sharedConfig.nix {inherit lib;};
# Temp config
haveEnable = cfgSSS.enable || cfgCode.enable;
sssPackage = lists.optional cfgSSS.enable sss.packages.default;
codePackage = lists.optional cfgCode.enable sss.packages.code;
codePackage = lists.optional cfgSSS.code.enable sss.packages.code;
filterConfig = cfg: filterAttrs (n: v: ((builtins.typeOf v) != "null") && n != "enable") cfg;
in {
options.programs = {
sss =
{
current = mkEnableOption "Capture current screens";
screen = mkEnableOption "Capture all screens";
screen-id = mkOption {
type = types.str;
default = "";
description = "ID or Name of screen to capture";
enable = mkEnableOption "cli to take screenshots";
cli = mkOption {
description = "";
default = {};
type = types.submodule {
config = {};
options = {
current = mkEnableOption "Capture current screens";
screen = mkEnableOption "Capture all screens";
screen-id = mkOption {
type = types.str;
default = "";
description = "ID or Name of screen to capture";
};
};
};
};
}
// sharedConfig;
sssCode =
{
# Code Configs
line-numbers = mkEnableOption "Show Line numbers";
theme = mkOption {
type = types.str;
default = "base16-ocean.dark";
example = "base16-ocean.dark";
description = "Theme file to use. May be a path, or an embedded theme. Embedded themes will take precendence.";
};
vim-theme = mkOption {
type = types.str;
default = "";
example = "";
description = "[Not recommended for manual use] Set theme from vim highlights, format: group,bg,fg,style;group,bg,fg,style;";
};
extra-syntaxes = mkOption {
type = types.str;
default = "";
example = "~/.config/extra-syntaxes";
description = "Additional folder to search for .sublime-syntax files in";
code = mkOption {
description = "";
default = {};
type = types.submodule {
config = {};
options = {
enable = mkEnableOption "cli to take screenshots code";
# Code Configs
line-numbers = mkEnableOption "Show Line numbers";
theme = mkOption {
type = types.str;
default = "base16-ocean.dark";
example = "base16-ocean.dark";
description = "Theme file to use. May be a path, or an embedded theme. Embedded themes will take precendence.";
};
vim-theme = mkOption {
type = types.str;
default = "";
example = "";
description = "[Not recommended for manual use] Set theme from vim highlights, format: group,bg,fg,style;group,bg,fg,style;";
};
extra-syntaxes = mkOption {
type = types.str;
default = "";
example = "~/.config/extra-syntaxes";
description = "Additional folder to search for .sublime-syntax files in";
};
tab-width = mkOption {
type = types.int;
default = 4;
example = "4";
description = "Tab width";
};
};
};
};
tab-width = mkOption {
type = types.int;
default = 4;
example = "4";
description = "Tab width";
general = mkOption {
description = "";
default = {};
type = types.submodule {
config = {};
options = sharedConfig;
};
};
}
// sharedConfig;
};
};

config = mkIf haveEnable {
config = mkIf cfgSSS.enable {
home.packages = sssPackage ++ codePackage;

home.file."${configDir}/sss/config.toml" = mkIf cfgSSS.enable {
source =
tomlFormat.generate "config.toml" (filterConfig cfgSSS);
};
home.file."${configDir}/sss_code/config.toml" = mkIf cfgCode.enable {
source =
tomlFormat.generate "config.toml" (filterConfig cfgCode);
};
};
}
107 changes: 57 additions & 50 deletions nix/sharedConfig.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ lib, ... }:
with lib; {
enable = mkEnableOption "cli to take screenshots";
copy = mkEnableOption "Copy screenshot to clipboard";
shadow = mkEnableOption "Enable shadows";
shadow-image = mkEnableOption "Enable shadows from captured image";
Expand All @@ -16,13 +15,13 @@ with lib; {
description = "Radius for the screenshot corners";
};
author = mkOption {
type = lib.types.nullOr types.str;
default = null;
type = types.str;
default = "";
description = "Author Name of screenshot";
};
window-title = mkOption {
type = lib.types.nullOr types.str;
default = null;
type = types.str;
default = "";
description = "Window title";
};
padding-x = mkOption {
Expand All @@ -36,8 +35,8 @@ with lib; {
description = "Padding Y of inner screenshot";
};
shadow-blur = mkOption {
type = types.int;
default = 50;
type = types.float;
default = 50.0;
description = "Blur of shadow";
};
save-format = mkOption {
Expand All @@ -47,53 +46,61 @@ with lib; {
};

colors = mkOption {
type = types.attrsOf (types.submodule {
background = mkOption {
type = types.str;
default = "#323232";
description = "Background of image generated. Support: '#RRGGBBAA' 'h;#RRGGBBAA;#RRGGBBAA' 'v;#RRGGBBAA;#RRGGBBAA' or file path";
};
author = mkOption {
type = types.str;
default = "#FFFFFF";
description = "Title bar text color";
};
window-background = mkOption {
type = types.str;
default = "#4287f5";
description = "Window title bar background";
default = { };
type = types.submodule {
config = { };
options = {
background = mkOption {
type = types.str;
default = "#323232";
description = "Background of image generated. Support: '#RRGGBBAA' 'h;#RRGGBBAA;#RRGGBBAA' 'v;#RRGGBBAA;#RRGGBBAA' or file path";
};
author = mkOption {
type = types.str;
default = "#FFFFFF";
description = "Title bar text color";
};
window-background = mkOption {
type = types.str;
default = "#4287f5";
description = "Window title bar background";
};
shadow = mkOption {
type = types.str;
default = "#707070";
description = "Shadow of screenshot. Support: '#RRGGBBAA' 'h;#RRGGBBAA;#RRGGBBAA' 'v;#RRGGBBAA;#RRGGBBAA' or file path";
};
title = mkOption {
type = types.str;
default = "#FFFFFF";
description = "Title bar text color";
};
};
shadow = mkOption {
type = types.str;
default = "#707070";
description = "Shadow of screenshot. Support: '#RRGGBBAA' 'h;#RRGGBBAA;#RRGGBBAA' 'v;#RRGGBBAA;#RRGGBBAA' or file path";
};
title = mkOption {
type = types.str;
default = "#FFFFFF";
description = "Title bar text color";
};
});
};
};

window-controls = mkOption {
type = types.attrsOf (types.submodule {
enable = mkEnableOption "cli to take screenshots";
width = mkOption {
type = types.int;
default = 120;
description = "Width of window controls";
};
height = mkOption {
type = types.int;
default = 40;
description = "Height of window title/controls bar";
};
titlebar-padding = mkOption {
type = types.int;
default = 10;
description = "Padding of title on window bar";
default = { };
type = types.submodule {
config = { };
options = {
enable = mkEnableOption "cli to take screenshots";
width = mkOption {
type = types.int;
default = 120;
description = "Width of window controls";
};
height = mkOption {
type = types.int;
default = 40;
description = "Height of window title/controls bar";
};
titlebar-padding = mkOption {
type = types.int;
default = 10;
description = "Padding of title on window bar";
};
};
});
};
};
}

0 comments on commit 2c64716

Please sign in to comment.