Skip to content

Commit 7d85967

Browse files
committed
clipmenud: Allow partial_merge_secs to be configurable
Closes #259.
1 parent 32510bc commit 7d85967

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

man/clipmenu.conf.5

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ When an entry is selected via
5353
it will also be moved up to the newest slot.
5454
Default: 0.
5555
.TP
56+
.B partial_merge_secs
57+
Specifies the time window in seconds during which consecutive clipboard updates
58+
where the previous entry was a substring of the new one are merged together
59+
instead of being stored separately. This is useful for applications that
60+
incrementally update the clipboard (e.g. progressive text selection in
61+
browsers). Set to 0 to disable partial merging entirely. Default: 2.
62+
.TP
5663
.B cm_dir
5764
Overrides the default directory for the clip store. This is by default at a
5865
subdirectory inside XDG_RUNTIME_DIR, TMPDIR, or if both are unset, inside /tmp.

src/clipmenud.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ static void maybe_trim(void) {
289289
}
290290
}
291291

292-
/**
293-
* Clips more than this many seconds apart are not considered for partial merge
294-
*/
295-
#define PARTIAL_MAX_SECS 2
296-
297292
/**
298293
* Store the clipboard text. If the text is a possible partial of the last clip
299294
* and it was received shortly afterwards, replace instead of adding.
@@ -306,8 +301,8 @@ static uint64_t store_clip(struct clip_text *ct) {
306301
time_t current_time = time(NULL);
307302
uint64_t hash;
308303

309-
if (last_text.data &&
310-
difftime(current_time, last_text_time) <= PARTIAL_MAX_SECS &&
304+
if (cfg.partial_merge_secs > 0 && last_text.data &&
305+
difftime(current_time, last_text_time) <= cfg.partial_merge_secs &&
311306
is_possible_partial(last_text.data, ct->data)) {
312307
dbg("Possible partial of last clip, replacing\n");
313308
expect(cs_replace(&cs, CS_ITER_NEWEST_FIRST, 0, ct->data, &hash) == 0);

src/config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ int config_setup_internal(FILE *file, struct config *cfg) {
289289
{"launcher_pass_dmenu_args", "CM_LAUNCHER_PASS_DMENU_ARGS",
290290
&cfg->launcher_pass_dmenu_args, convert_bool, "1", 0},
291291
{"touch_on_select", NULL, &cfg->touch_on_select, convert_bool, "0", 0},
292+
{"partial_merge_secs", NULL, &cfg->partial_merge_secs,
293+
convert_positive_int, "2", 0},
292294
{"cm_dir", "CM_DIR", &cfg->runtime_dir, convert_cm_dir, NULL, 0}};
293295

294296
size_t entries_len = arrlen(entries);

src/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct config {
5252
struct launcher launcher;
5353
bool launcher_pass_dmenu_args;
5454
bool touch_on_select;
55+
int partial_merge_secs;
5556
};
5657
typedef int (*conversion_func_t)(const char *, void *);
5758
struct config_entry {

0 commit comments

Comments
 (0)