@@ -66,6 +66,12 @@ class LinuxPasteboardService(
66
66
67
67
private fun run (): Job {
68
68
return serviceScope.launch(CoroutineName (" LinuxPasteboardService" )) {
69
+ val firstChange = changeCount == configManager.config.lastPasteboardChangeCount
70
+
71
+ if (firstChange && ! configManager.config.enableSkipPriorPasteboardContent) {
72
+ onChange(this , true )
73
+ }
74
+
69
75
val x11 = X11Api .INSTANCE
70
76
x11.XOpenDisplay (null )?.let { display ->
71
77
try {
@@ -106,29 +112,7 @@ class LinuxPasteboardService(
106
112
if (selectionNotify.selection?.toLong() == clipboardAtom.toLong()) {
107
113
logger.info { " notify change event" }
108
114
changeCount++
109
-
110
- val source =
111
- controlUtils.ensureMinExecutionTime(delayTime = 20 ) {
112
- appWindowManager.getCurrentActiveAppName()
113
- }
114
-
115
- val contents =
116
- controlUtils.exponentialBackoffUntilValid(
117
- initTime = 20L ,
118
- maxTime = 1000L ,
119
- isValidResult = ::isValidContents,
120
- ) {
121
- getPasteboardContentsBySafe()
122
- }
123
- if (contents != ownerTransferable) {
124
- contents?.let {
125
- ownerTransferable = it
126
- launch(CoroutineName (" LinuxPasteboardServiceConsumer" )) {
127
- val pasteTransferable = DesktopReadTransferable (it)
128
- pasteConsumer.consume(pasteTransferable, source, remote = false )
129
- }
130
- }
131
- }
115
+ onChange(this )
132
116
}
133
117
selectionNotify.clear()
134
118
}
@@ -143,6 +127,38 @@ class LinuxPasteboardService(
143
127
}
144
128
}
145
129
130
+ private suspend fun onChange (
131
+ scope : CoroutineScope ,
132
+ firstChange : Boolean = false,
133
+ ) {
134
+ val source =
135
+ if (firstChange) {
136
+ null
137
+ } else {
138
+ controlUtils.ensureMinExecutionTime(delayTime = 20 ) {
139
+ appWindowManager.getCurrentActiveAppName()
140
+ }
141
+ }
142
+
143
+ val contents =
144
+ controlUtils.exponentialBackoffUntilValid(
145
+ initTime = 20L ,
146
+ maxTime = 1000L ,
147
+ isValidResult = ::isValidContents,
148
+ ) {
149
+ getPasteboardContentsBySafe()
150
+ }
151
+ if (contents != ownerTransferable) {
152
+ contents?.let {
153
+ ownerTransferable = it
154
+ scope.launch(CoroutineName (" LinuxPasteboardServiceConsumer" )) {
155
+ val pasteTransferable = DesktopReadTransferable (it)
156
+ pasteConsumer.consume(pasteTransferable, source, remote = false )
157
+ }
158
+ }
159
+ }
160
+ }
161
+
146
162
override fun start () {
147
163
if (configManager.config.enablePasteboardListening) {
148
164
if (job?.isActive != true ) {
0 commit comments