Skip to content

Commit 7a596cf

Browse files
googleson78tek
authored andcommitted
Allow specifying a set of subscribed selections as a config option
1 parent 404cd40 commit 7a596cf

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

ops/module.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ self: { config, lib, pkgs, ... }:
22
with lib;
33
let
44
cfg = config.services.helic;
5+
nixStringListToJsonArray = xs: "[${concatMapStringsSep ", " (h: "'${h}'") xs}]";
56
in {
67
options.services.helic = {
78
enable = mkEnableOption "Clipboard Manager";
@@ -67,6 +68,12 @@ in {
6768
default = ":0";
6869
description = "The X11 display to connect to if there is no active display in the environment.";
6970
};
71+
subscribedSelections = mkOption {
72+
type = types.listOf types.str;
73+
default = ["Clipboard" "Primary" "Selection"];
74+
description = "A list of unique X11 selections from which to listen to events for.";
75+
example = literalExpression ["Clipboard"];
76+
};
7077
};
7178
};
7279
config = mkIf cfg.enable {
@@ -81,11 +88,12 @@ in {
8188
net:
8289
enable: ${if cfg.net.enable then "true" else "false"}
8390
port: ${toString cfg.net.port}
84-
hosts: [${concatMapStringsSep ", " (h: "'${h}'") cfg.net.hosts}]
91+
hosts: ${nixStringListToJsonArray cfg.net.hosts}
8592
${if cfg.net.timeout == null then "" else "timeout: ${toString cfg.net.timeout}"}
8693
x11:
8794
enable: ${if cfg.x11.enable then "true" else "false"}
8895
display: ${cfg.x11.display}
96+
subscribedSelections: ${nixStringListToJsonArray cfg.x11.subscribedSelections}
8997
'';
9098
systemd.user.services.helic = {
9199
description = "Clipboard Manager";

packages/helic/lib/Helic/Data/Selection.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ data Selection =
1414
Secondary
1515
deriving stock (Eq, Show, Ord, Enum, Bounded)
1616

17+
json ''Selection
18+
1719
-- |Convert a 'Selection' into the string that X11 uses to identify it.
1820
toXString :: Selection -> Text
1921
toXString = \case

packages/helic/lib/Helic/Data/X11Config.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
-- |X11Config Data Type, Internal
44
module Helic.Data.X11Config where
5+
import Helic.Data.Selection (Selection)
56

67
newtype DisplayId =
78
DisplayId { unDisplayId :: Text }
@@ -13,7 +14,9 @@ json ''DisplayId
1314
data X11Config =
1415
X11Config {
1516
enable :: Maybe Bool,
16-
display :: Maybe DisplayId
17+
display :: Maybe DisplayId,
18+
subscribedSelections :: Maybe (Set Selection)
19+
-- ^ if not specified, we default to subscribing to all selections
1720
}
1821
deriving stock (Eq, Show, Generic)
1922
deriving anyclass (Default)

packages/helic/test/Helic/Test/ConfigFileTest.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Helic.Data.Config (Config (Config))
1010
import Helic.Data.NetConfig (NetConfig (NetConfig))
1111
import Helic.Data.TmuxConfig (TmuxConfig (TmuxConfig))
1212
import Helic.Data.X11Config (X11Config (X11Config))
13+
import qualified Helic.Data.Selection as Selection
14+
import qualified Data.Set as Set
1315

1416
target :: Config
1517
target =
@@ -20,7 +22,7 @@ target =
2022
net =
2123
NetConfig (Just True) (Just 10001) (Just 5) (Just ["remote:1000"])
2224
x =
23-
X11Config (Just True) (Just ":1")
25+
X11Config (Just True) (Just ":1") (Just (Set.fromList [Selection.Clipboard, Selection.Primary, Selection.Secondary]))
2426

2527
test_readConfigFile :: UnitTest
2628
test_readConfigFile = do

packages/helic/test/fixtures/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ net:
1313
x11:
1414
enable: true
1515
display: ":1"
16+
subscribedSelections: ['Clipboard', 'Primary', 'Secondary']

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Selections are used when text is selected with the mouse, while the clipboard is
99
When some text is copied or selected in *X11*, the daemon receives an event that it proceeds to broadcast to the
1010
configured targets.
1111
If the source was a selection, the *X11* clipboard is updated as well.
12+
The choice of which *X11* selections to listen to is configurable via `subscribedSelections`.
1213

1314
The CLI program `hel` can be used to manually send text to the daemon, for example from *tmux* or *Neovim*.
1415
If remote hosts are configured, each yank event is sent over the network to update their clipboards.
@@ -170,6 +171,8 @@ For *NixOS*, the file `/etc/helic.yaml` is generated from module options:
170171
x11 = {
171172
enable = true;
172173
display = ":0";
174+
subscribedSelections = ["Clipboard" "Primary" "Selection"];
175+
173176
};
174177
};
175178
}
@@ -193,6 +196,7 @@ The meaning of these options is:
193196
|`tmux.exe`|`tmux`|Only for YAML file: The path to the *tmux* executable|
194197
|`x11.enable`|`true`|Whether to synchronize the X11 clipboard.|
195198
|`x11.display`|`:0`|The display identifier used when connecting to the default display via GTK fails.|
199+
|`x11.subscribedSelections`|`["Clipboard" "Primary" "Selection"]`|Which X11 selections to listen to.|
196200

197201
# Neovim
198202

0 commit comments

Comments
 (0)