about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--modules/module-list.nix1
-rw-r--r--modules/user/aszlig/profiles/workstation/default.nix1
-rw-r--r--modules/user/aszlig/programs/flameshot/config.patch47
-rw-r--r--modules/user/aszlig/programs/flameshot/default.nix52
-rw-r--r--modules/user/aszlig/services/i3/default.nix4
-rw-r--r--modules/user/aszlig/services/i3/i3.conf2
-rw-r--r--tests/aszlig/programs/flameshot.nix26
-rw-r--r--tests/default.nix1
8 files changed, 134 insertions, 0 deletions
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 <algorithm>
+ 
+ ConfigHandler::ConfigHandler()
+-{
+-    m_settings.setDefaultFormat(QSettings::IniFormat);
+-}
++  : m_settings("@configFile@", QSettings::IniFormat)
++{}
+ 
+ QVector<CaptureToolButton::ButtonType> ConfigHandler::getButtons()
+ {
+@@ -55,9 +54,7 @@ QVector<CaptureToolButton::ButtonType> 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<QColor>& 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;