Skip to content

Commit f9861c0

Browse files
googleson78tek
authored andcommitted
Respect subscribedSelections config option when subscribing to gtk's clipboard
1 parent 7a596cf commit f9861c0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/helic/lib/Helic/Interpreter/GtkClipboard.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import Helic.Effect.GtkClipboard (GtkClipboard)
88
import Helic.Effect.GtkMain (GtkMain)
99
import Helic.Gtk (clipboardText, setClipboardText, subscribeToClipboard)
1010
import Helic.Interpreter.GtkMain (interpretWithGtk)
11+
import Helic.Data.X11Config (X11Config(..))
12+
import Helic.Data.Selection (Selection)
13+
import qualified Data.Set as Set
1114

1215
-- |Specialization of 'scoped_' to 'GtkClipboard' for syntactic sugar.
1316
withGtkClipboard ::
@@ -21,7 +24,7 @@ withGtkClipboard =
2124
-- The effect then needs to be scoped using 'withGtkClipboard'.
2225
-- The default implementation for this purpose is 'interpretWithGtk'.
2326
handleGtkClipboard ::
24-
Members [Log, Embed IO, Final IO] r =>
27+
Members [Reader X11Config, Log, Embed IO, Final IO] r =>
2528
Display ->
2629
GtkClipboard (Sem r0) a ->
2730
Tactical effect (Sem r0) (Stop Text : r) a
@@ -33,12 +36,16 @@ handleGtkClipboard display = \case
3336
GtkClipboard.Events f -> do
3437
let f' s t = void (raise (runTSimple (f s t)))
3538
runReader display do
36-
for_ @[] [minBound..maxBound] (subscribeToClipboard f')
39+
x11Config <- ask @X11Config
40+
let
41+
targetSelections :: Set Selection
42+
targetSelections = fromMaybe (Set.fromList [minBound..maxBound]) x11Config.subscribedSelections
43+
for_ @Set targetSelections (subscribeToClipboard f')
3744
pureT ()
3845

3946
-- |Native interpreter for 'GtkClipboard' that requires the effect to be used within a 'withGtkClipboard' region.
4047
interpretGtkClipboard ::
41-
Members [GtkMain Display, Log, Embed IO, Final IO] r =>
48+
Members [Reader X11Config, GtkMain Display, Log, Embed IO, Final IO] r =>
4249
InterpreterFor (Scoped_ GtkClipboard !! Text) r
4350
interpretGtkClipboard =
4451
interpretWithGtk handleGtkClipboard

0 commit comments

Comments
 (0)