From 6ee8541db0196536c935cd8c82dca1991240d38e Mon Sep 17 00:00:00 2001 From: aszlig Date: Sat, 13 Feb 2021 04:04:40 +0100 Subject: profiles/workstation: Add Flameshot So far I've almost exclusively used scrot for screenshots, but most of the time I used an image manipulation program to pixelate stuff, add descriptions or draw arrows. Flameshot combines this in a single application, so I expect that from now on I can spam-post screenshots in even a higher rate than before ;-) Signed-off-by: aszlig --- modules/module-list.nix | 1 + .../user/aszlig/profiles/workstation/default.nix | 1 + .../user/aszlig/programs/flameshot/config.patch | 47 +++++++++++++++++++ modules/user/aszlig/programs/flameshot/default.nix | 52 ++++++++++++++++++++++ modules/user/aszlig/services/i3/default.nix | 4 ++ modules/user/aszlig/services/i3/i3.conf | 2 + tests/aszlig/programs/flameshot.nix | 26 +++++++++++ tests/default.nix | 1 + 8 files changed, 134 insertions(+) create mode 100644 modules/user/aszlig/programs/flameshot/config.patch create mode 100644 modules/user/aszlig/programs/flameshot/default.nix create mode 100644 tests/aszlig/programs/flameshot.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 935129a7..b4574594 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -21,6 +21,7 @@ ./user/aszlig/profiles/base.nix ./user/aszlig/profiles/managed.nix ./user/aszlig/profiles/workstation + ./user/aszlig/programs/flameshot ./user/aszlig/programs/git ./user/aszlig/programs/mpv ./user/aszlig/programs/zsh diff --git a/modules/user/aszlig/profiles/workstation/default.nix b/modules/user/aszlig/profiles/workstation/default.nix index 1935173c..e5591eeb 100644 --- a/modules/user/aszlig/profiles/workstation/default.nix +++ b/modules/user/aszlig/profiles/workstation/default.nix @@ -70,6 +70,7 @@ in { vuizvui.user.aszlig.services.vlock.enable = true; vuizvui.user.aszlig.services.vlock.user = "aszlig"; + vuizvui.user.aszlig.programs.flameshot.enable = true; vuizvui.user.aszlig.programs.mpv.enable = true; vuizvui.user.aszlig.programs.git.enable = true; diff --git a/modules/user/aszlig/programs/flameshot/config.patch b/modules/user/aszlig/programs/flameshot/config.patch new file mode 100644 index 00000000..6d01df12 --- /dev/null +++ b/modules/user/aszlig/programs/flameshot/config.patch @@ -0,0 +1,47 @@ +diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp +index ee50acb..8a92e08 100644 +--- a/src/utils/confighandler.cpp ++++ b/src/utils/confighandler.cpp +@@ -22,9 +22,8 @@ + #include + + ConfigHandler::ConfigHandler() +-{ +- m_settings.setDefaultFormat(QSettings::IniFormat); +-} ++ : m_settings("@configFile@", QSettings::IniFormat) ++{} + + QVector ConfigHandler::getButtons() + { +@@ -55,9 +54,7 @@ QVector ConfigHandler::getButtons() + << CaptureToolButton::TYPE_UNDO << CaptureToolButton::TYPE_REDO + << CaptureToolButton::TYPE_COPY << CaptureToolButton::TYPE_SAVE + << CaptureToolButton::TYPE_EXIT +- << CaptureToolButton::TYPE_IMAGEUPLOADER +- << CaptureToolButton::TYPE_OPEN_APP +- << CaptureToolButton::TYPE_PIN << CaptureToolButton::TYPE_TEXT ++ << CaptureToolButton::TYPE_TEXT + << CaptureToolButton::TYPE_CIRCLECOUNT; + } + +@@ -119,7 +116,8 @@ void ConfigHandler::setUserColors(const QVector& l) + + QString ConfigHandler::savePathValue() + { +- return m_settings.value(QStringLiteral("savePath")).toString(); ++ return m_settings.value(QStringLiteral("savePath")).toString() ++ .replace("$HOME", QDir::homePath()); + } + + void ConfigHandler::setSavePath(const QString& savePath) +@@ -390,7 +388,8 @@ void ConfigHandler::setSaveAfterCopy(const bool save) + + QString ConfigHandler::saveAfterCopyPathValue() + { +- return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString(); ++ return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString() ++ .replace("$HOME", QDir::homePath()); + } + + void ConfigHandler::setSaveAfterCopyPath(const QString& path) diff --git a/modules/user/aszlig/programs/flameshot/default.nix b/modules/user/aszlig/programs/flameshot/default.nix new file mode 100644 index 00000000..29bb638d --- /dev/null +++ b/modules/user/aszlig/programs/flameshot/default.nix @@ -0,0 +1,52 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.vuizvui.user.aszlig.programs.flameshot; + + # TODO: Make configurable via module system. + settings = { + closeAfterScreenshot = true; + disabledTrayIcon = true; + drawColor = "#ff0000"; + drawThickness = 2; + saveAfterCopyPath = "$HOME/screenshots"; + savePath = "$HOME/screenshots"; + savePathFixed = true; + }; + +in { + options.vuizvui.user.aszlig.programs.flameshot = { + enable = lib.mkEnableOption "Flameshot"; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.flameshot.overrideAttrs (drv: { + patches = (drv.patches or []) ++ lib.singleton ./config.patch; + configFile = pkgs.writeText "flameshot.ini" (lib.generators.toINI {} { + General = settings; + }); + postPatch = (drv.postPatch or "") + '' + substituteInPlace src/utils/confighandler.cpp --subst-var configFile + ''; + }); + readOnly = true; + internal = true; + description = "The patched Flameshot package."; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = lib.singleton cfg.package; + + services.dbus.packages = lib.singleton (pkgs.writeTextFile { + name = "flameshot-dbus"; + destination = "/share/dbus-1/services/org.flameshot.Flameshot.service"; + text = lib.generators.toINI {} { + "D-BUS Service" = { + Name = "org.flameshot.Flameshot"; + Exec = "${cfg.package}/bin/flameshot"; + }; + }; + }); + }; +} diff --git a/modules/user/aszlig/services/i3/default.nix b/modules/user/aszlig/services/i3/default.nix index 733541ee..d11140dd 100644 --- a/modules/user/aszlig/services/i3/default.nix +++ b/modules/user/aszlig/services/i3/default.nix @@ -117,6 +117,10 @@ in inherit (pkgs.xorg) xsetroot; inherit wsConfig barConfig; + # XXX: Decouple this by making the i3 bindsym directives available to + # the NixOS module system. + flameshot = config.vuizvui.user.aszlig.programs.flameshot.package; + lockall = pkgs.writeScript "lockvt.sh" '' #!${pkgs.stdenv.shell} "${pkgs.socat}/bin/socat" - UNIX-CONNECT:/run/console-lock.sock \ diff --git a/modules/user/aszlig/services/i3/i3.conf b/modules/user/aszlig/services/i3/i3.conf index 6e9307f2..1f5246fe 100644 --- a/modules/user/aszlig/services/i3/i3.conf +++ b/modules/user/aszlig/services/i3/i3.conf @@ -84,6 +84,8 @@ bindsym $mod+Shift+R restart # exit i3 (logs you out of your X session) bindsym $mod+Shift+Q exit +bindsym Print exec @flameshot@/bin/flameshot gui + # resize window (you can also use the mouse for that) mode "resize" { # These bindings trigger as soon as you enter the resize mode diff --git a/tests/aszlig/programs/flameshot.nix b/tests/aszlig/programs/flameshot.nix new file mode 100644 index 00000000..35e1d570 --- /dev/null +++ b/tests/aszlig/programs/flameshot.nix @@ -0,0 +1,26 @@ +{ nixpkgsPath, ... }: + +{ + name = "flameshot"; + + machine = { pkgs, ... }: { + imports = [ + "${nixpkgsPath}/nixos/tests/common/user-account.nix" + "${nixpkgsPath}/nixos/tests/common/x11.nix" + ]; + test-support.displayManager.auto.user = "alice"; + vuizvui.user.aszlig.programs.flameshot.enable = true; + }; + + enableOCR = true; + + testScript = '' + # fmt: off + machine.wait_for_x() + machine.wait_for_file("/home/alice/.Xauthority") + machine.succeed("xauth merge ~alice/.Xauthority") + machine.succeed('su -c "DISPLAY=:0.0 flameshot gui" - alice &') + machine.wait_for_text('(?i)capture the screen') + machine.screenshot('flameshot') + ''; +} diff --git a/tests/default.nix b/tests/default.nix index edc022ad..e47ddd46 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -10,6 +10,7 @@ let in { aszlig.dnyarri.luks2-bcache = callTest ./aszlig/dnyarri/luks2-bcache.nix; + aszlig.programs.flameshot = callTest aszlig/programs/flameshot.nix; aszlig.programs.psi = callTest aszlig/programs/psi.nix; games = { starbound = callTest ./games/starbound.nix; -- cgit 1.4.1