mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-24 09:05:48 -04:00
osc52: use first source that actually *has* data
This commit is contained in:
parent
776b831d89
commit
419bd87098
1 changed files with 32 additions and 20 deletions
52
osc.c
52
osc.c
|
|
@ -162,20 +162,6 @@ from_clipboard_done(void *user)
|
||||||
static void
|
static void
|
||||||
osc_from_clipboard(struct terminal *term, const char *source)
|
osc_from_clipboard(struct terminal *term, const char *source)
|
||||||
{
|
{
|
||||||
/* Use clipboard if no source has been specified */
|
|
||||||
char src = source[0] == '\0' ? 'c' : 0;
|
|
||||||
|
|
||||||
for (const char *s = source; *s != '\0'; s++) {
|
|
||||||
if (*s == 'c' || *s == 'p' || *s == 's') {
|
|
||||||
src = *s;
|
|
||||||
break;
|
|
||||||
} else
|
|
||||||
LOG_WARN("unimplemented: clipboard source '%c'", *s);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Find a seat in which the terminal has focus */
|
/* Find a seat in which the terminal has focus */
|
||||||
struct seat *seat = NULL;
|
struct seat *seat = NULL;
|
||||||
tll_foreach(term->wl->seats, it) {
|
tll_foreach(term->wl->seats, it) {
|
||||||
|
|
@ -190,6 +176,35 @@ osc_from_clipboard(struct terminal *term, const char *source)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use clipboard if no source has been specified */
|
||||||
|
char src = source[0] == '\0' ? 'c' : 0;
|
||||||
|
bool from_clipboard = src == 'c';
|
||||||
|
bool from_primary = false;
|
||||||
|
|
||||||
|
for (const char *s = source;
|
||||||
|
*s != '\0' && !from_clipboard && !from_primary;
|
||||||
|
s++)
|
||||||
|
{
|
||||||
|
if (*s == 'c' || *s == 'p' || *s == 's') {
|
||||||
|
src = *s;
|
||||||
|
|
||||||
|
switch (src) {
|
||||||
|
case 'c':
|
||||||
|
from_clipboard = selection_clipboard_has_data(seat);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
case 'p':
|
||||||
|
from_primary = selection_primary_has_data(seat);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
LOG_WARN("unimplemented: clipboard source '%c'", *s);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!from_clipboard && !from_primary)
|
||||||
|
return;
|
||||||
|
|
||||||
term_to_slave(term, "\033]52;", 5);
|
term_to_slave(term, "\033]52;", 5);
|
||||||
term_to_slave(term, &src, 1);
|
term_to_slave(term, &src, 1);
|
||||||
term_to_slave(term, ";", 1);
|
term_to_slave(term, ";", 1);
|
||||||
|
|
@ -197,17 +212,14 @@ osc_from_clipboard(struct terminal *term, const char *source)
|
||||||
struct clip_context *ctx = xmalloc(sizeof(*ctx));
|
struct clip_context *ctx = xmalloc(sizeof(*ctx));
|
||||||
*ctx = (struct clip_context) {.seat = seat, .term = term};
|
*ctx = (struct clip_context) {.seat = seat, .term = term};
|
||||||
|
|
||||||
switch (src) {
|
if (from_clipboard) {
|
||||||
case 'c':
|
|
||||||
text_from_clipboard(
|
text_from_clipboard(
|
||||||
seat, term, &from_clipboard_cb, &from_clipboard_done, ctx);
|
seat, term, &from_clipboard_cb, &from_clipboard_done, ctx);
|
||||||
break;
|
}
|
||||||
|
|
||||||
case 's':
|
if (from_primary) {
|
||||||
case 'p':
|
|
||||||
text_from_primary(
|
text_from_primary(
|
||||||
seat, term, &from_clipboard_cb, &from_clipboard_done, ctx);
|
seat, term, &from_clipboard_cb, &from_clipboard_done, ctx);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue