2019-06-29 21:03:28 +02:00
|
|
|
|
#include "terminal.h"
|
|
|
|
|
|
|
2021-01-19 15:05:22 +00:00
|
|
|
|
#if defined(__GLIBC__)
|
2019-11-03 12:48:18 +01:00
|
|
|
|
#include <malloc.h>
|
2021-01-19 15:05:22 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
#include <signal.h>
|
2019-06-29 21:03:28 +02:00
|
|
|
|
#include <string.h>
|
2019-07-05 14:24:51 +02:00
|
|
|
|
#include <unistd.h>
|
2019-10-28 18:25:19 +01:00
|
|
|
|
#include <errno.h>
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <sys/wait.h>
|
2020-06-02 19:59:28 +02:00
|
|
|
|
#include <sys/ioctl.h>
|
2019-10-28 18:35:16 +01:00
|
|
|
|
#include <sys/epoll.h>
|
2019-10-30 20:03:11 +01:00
|
|
|
|
#include <sys/eventfd.h>
|
2019-07-30 22:06:02 +02:00
|
|
|
|
#include <sys/timerfd.h>
|
2019-10-28 18:25:19 +01:00
|
|
|
|
#include <fcntl.h>
|
2019-07-09 09:17:24 +02:00
|
|
|
|
#include <linux/input-event-codes.h>
|
2020-03-26 19:39:12 +01:00
|
|
|
|
#include <xdg-shell.h>
|
2019-07-09 09:17:24 +02:00
|
|
|
|
|
2019-06-29 21:03:28 +02:00
|
|
|
|
#define LOG_MODULE "terminal"
|
2019-07-03 20:21:03 +02:00
|
|
|
|
#define LOG_ENABLE_DBG 0
|
2019-06-29 21:03:28 +02:00
|
|
|
|
#include "log.h"
|
2019-11-04 13:46:04 +01:00
|
|
|
|
|
|
|
|
|
|
#include "async.h"
|
2020-02-22 00:23:19 +01:00
|
|
|
|
#include "config.h"
|
2021-01-15 20:39:45 +00:00
|
|
|
|
#include "debug.h"
|
2020-07-15 11:33:37 +02:00
|
|
|
|
#include "extract.h"
|
2019-07-01 12:23:38 +02:00
|
|
|
|
#include "grid.h"
|
2020-12-04 18:39:11 +01:00
|
|
|
|
#include "ime.h"
|
2020-12-10 18:22:48 +01:00
|
|
|
|
#include "notify.h"
|
2020-03-01 13:09:25 +01:00
|
|
|
|
#include "quirks.h"
|
2020-05-21 20:17:29 +02:00
|
|
|
|
#include "reaper.h"
|
2019-07-21 17:35:53 +02:00
|
|
|
|
#include "render.h"
|
2019-08-01 20:51:11 +02:00
|
|
|
|
#include "selection.h"
|
2020-02-22 00:23:19 +01:00
|
|
|
|
#include "sixel.h"
|
2019-10-28 18:25:19 +01:00
|
|
|
|
#include "slave.h"
|
2020-07-15 12:39:10 +02:00
|
|
|
|
#include "spawn.h"
|
2021-01-31 11:12:07 +01:00
|
|
|
|
#include "url-mode.h"
|
2020-05-01 11:46:24 +02:00
|
|
|
|
#include "util.h"
|
2020-02-22 00:23:19 +01:00
|
|
|
|
#include "vt.h"
|
2020-08-08 20:34:30 +01:00
|
|
|
|
#include "xmalloc.h"
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
delayed rendering: ignore frame callback if delayed rendering is active
Before, we applied delayed rendering (that is, we gave the client a
chance to do more writes before we scheduled a render refresh) only
when the renderer were idle.
However, with e.g. a high keyboard repeat rate, it is very much
possible to start the render loop and then never break out of it while
receiving keyboard input.
This causes screen flickering, as we're no longer even trying to
detect the clients transaction boundaries.
So, let's rewrite how this is done.
First, we give the user the ability to disable delayed rendering
altogether, by setting either the lower or upper timeout to 0.
Second, when delayed rendering is enabled, we ignore the frame
callback. That is, when receiving input, we *always* reschedule the
lower timeout timer, regardless of whether the render is idle or not.
The render's frame callback handler will *not* render the grid if the
delayed render timers are armed.
This means for longer client data bursts, we may now skip frames. That
is, we're trading screen flicker for the occasional frame hickup.
For short client data bursts we should behave roughly as before.
This greatly improves the behavior of fullscreen, or near fullscreen,
updates of large grids (example, scrolling in emacs in fullscreen,
with a vertical buffer split).
2020-03-23 19:21:41 +01:00
|
|
|
|
#define PTMX_TIMING 0
|
|
|
|
|
|
|
2020-07-31 17:09:06 +02:00
|
|
|
|
const char *const XCURSOR_HIDDEN = "hidden";
|
2020-07-09 09:52:11 +02:00
|
|
|
|
const char *const XCURSOR_LEFT_PTR = "left_ptr";
|
|
|
|
|
|
const char *const XCURSOR_TEXT = "text";
|
|
|
|
|
|
//const char *const XCURSOR_HAND2 = "hand2";
|
|
|
|
|
|
const char *const XCURSOR_TOP_LEFT_CORNER = "top_left_corner";
|
|
|
|
|
|
const char *const XCURSOR_TOP_RIGHT_CORNER = "top_right_corner";
|
|
|
|
|
|
const char *const XCURSOR_BOTTOM_LEFT_CORNER = "bottom_left_corner";
|
|
|
|
|
|
const char *const XCURSOR_BOTTOM_RIGHT_CORNER = "bottom_right_corner";
|
|
|
|
|
|
const char *const XCURSOR_LEFT_SIDE = "left_side";
|
|
|
|
|
|
const char *const XCURSOR_RIGHT_SIDE = "right_side";
|
|
|
|
|
|
const char *const XCURSOR_TOP_SIDE = "top_side";
|
|
|
|
|
|
const char *const XCURSOR_BOTTOM_SIDE = "bottom_side";
|
2019-11-30 12:43:06 +01:00
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
static void
|
|
|
|
|
|
enqueue_data_for_slave(const void *data, size_t len, size_t offset,
|
|
|
|
|
|
ptmx_buffer_list_t *buffer_list)
|
2019-11-03 01:25:41 +01:00
|
|
|
|
{
|
2020-08-22 09:25:25 +02:00
|
|
|
|
void *copy = xmalloc(len);
|
|
|
|
|
|
memcpy(copy, data, len);
|
2020-02-03 19:58:32 +01:00
|
|
|
|
|
2020-08-22 09:25:25 +02:00
|
|
|
|
struct ptmx_buffer queued = {
|
|
|
|
|
|
.data = copy,
|
|
|
|
|
|
.len = len,
|
|
|
|
|
|
.idx = offset,
|
|
|
|
|
|
};
|
|
|
|
|
|
tll_push_back(*buffer_list, queued);
|
2020-08-22 09:14:18 +02:00
|
|
|
|
}
|
2019-11-03 01:25:41 +01:00
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
static bool
|
|
|
|
|
|
data_to_slave(struct terminal *term, const void *data, size_t len,
|
|
|
|
|
|
ptmx_buffer_list_t *buffer_list)
|
|
|
|
|
|
{
|
2019-11-03 12:13:51 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* Try a synchronous write first. If we fail to write everything,
|
|
|
|
|
|
* switch to asynchronous.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
size_t async_idx = 0;
|
|
|
|
|
|
switch (async_write(term->ptmx, data, len, &async_idx)) {
|
2019-11-04 13:46:04 +01:00
|
|
|
|
case ASYNC_WRITE_REMAIN:
|
2020-01-10 19:51:16 +01:00
|
|
|
|
/* Switch to asynchronous mode; let FDM write the remaining data */
|
|
|
|
|
|
if (!fdm_event_add(term->fdm, term->ptmx, EPOLLOUT))
|
|
|
|
|
|
return false;
|
2020-08-22 09:14:18 +02:00
|
|
|
|
enqueue_data_for_slave(data, len, async_idx, buffer_list);
|
|
|
|
|
|
return true;
|
2019-11-03 01:25:41 +01:00
|
|
|
|
|
2019-11-04 13:46:04 +01:00
|
|
|
|
case ASYNC_WRITE_DONE:
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
case ASYNC_WRITE_ERR:
|
|
|
|
|
|
LOG_ERRNO("failed to synchronously write %zu bytes to slave", len);
|
|
|
|
|
|
return false;
|
2019-11-03 01:25:41 +01:00
|
|
|
|
}
|
2019-11-03 01:03:52 +01:00
|
|
|
|
|
2021-02-09 13:52:33 +00:00
|
|
|
|
BUG("Unexpected async_write() return value");
|
2019-11-03 12:13:51 +01:00
|
|
|
|
return false;
|
2020-08-22 09:14:18 +02:00
|
|
|
|
}
|
2019-11-03 12:13:51 +01:00
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
bool
|
|
|
|
|
|
term_paste_data_to_slave(struct terminal *term, const void *data, size_t len)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->is_sending_paste_data);
|
2019-11-03 01:03:52 +01:00
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
if (term->ptmx < 0) {
|
|
|
|
|
|
/* We're probably in "hold" */
|
|
|
|
|
|
return false;
|
2019-11-03 01:03:52 +01:00
|
|
|
|
}
|
2020-08-22 09:14:18 +02:00
|
|
|
|
|
|
|
|
|
|
if (tll_length(term->ptmx_paste_buffers) > 0) {
|
|
|
|
|
|
/* Don't even try to send data *now* if there's queued up
|
|
|
|
|
|
* data, since that would result in events arriving out of
|
|
|
|
|
|
* order. */
|
|
|
|
|
|
enqueue_data_for_slave(data, len, 0, &term->ptmx_paste_buffers);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return data_to_slave(term, data, len, &term->ptmx_paste_buffers);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
term_to_slave(struct terminal *term, const void *data, size_t len)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->ptmx < 0) {
|
|
|
|
|
|
/* We're probably in "hold" */
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tll_length(term->ptmx_buffers) > 0 || term->is_sending_paste_data) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Don't even try to send data *now* if there's queued up
|
|
|
|
|
|
* data, since that would result in events arriving out of
|
|
|
|
|
|
* order.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Furthermore, if we're currently sending paste data to the
|
|
|
|
|
|
* client, do *not* mix that stream with other events
|
|
|
|
|
|
* (https://codeberg.org/dnkl/foot/issues/101).
|
|
|
|
|
|
*/
|
|
|
|
|
|
enqueue_data_for_slave(data, len, 0, &term->ptmx_buffers);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return data_to_slave(term, data, len, &term->ptmx_buffers);
|
2019-11-03 01:03:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
fdm_ptmx_out(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct terminal *term = data;
|
2019-11-04 12:36:43 +01:00
|
|
|
|
|
2020-01-10 19:51:16 +01:00
|
|
|
|
/* If there is no queued data, then we shouldn't be in asynchronous mode */
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(tll_length(term->ptmx_buffers) > 0 ||
|
2020-08-22 09:14:18 +02:00
|
|
|
|
tll_length(term->ptmx_paste_buffers) > 0);
|
|
|
|
|
|
|
|
|
|
|
|
/* Writes a single buffer, returns if not all of it could be written */
|
|
|
|
|
|
#define write_one_buffer(buffer_list) \
|
|
|
|
|
|
{ \
|
|
|
|
|
|
switch (async_write(term->ptmx, it->item.data, it->item.len, &it->item.idx)) { \
|
|
|
|
|
|
case ASYNC_WRITE_DONE: \
|
|
|
|
|
|
free(it->item.data); \
|
|
|
|
|
|
tll_remove(buffer_list, it); \
|
|
|
|
|
|
break; \
|
|
|
|
|
|
case ASYNC_WRITE_REMAIN: \
|
|
|
|
|
|
/* to_slave() updated it->item.idx */ \
|
|
|
|
|
|
return true; \
|
|
|
|
|
|
case ASYNC_WRITE_ERR: \
|
|
|
|
|
|
LOG_ERRNO("failed to asynchronously write %zu bytes to slave", \
|
|
|
|
|
|
it->item.len - it->item.idx); \
|
|
|
|
|
|
return false; \
|
|
|
|
|
|
} \
|
|
|
|
|
|
}
|
2019-11-03 01:25:41 +01:00
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
tll_foreach(term->ptmx_paste_buffers, it)
|
|
|
|
|
|
write_one_buffer(term->ptmx_paste_buffers);
|
2019-11-04 13:46:04 +01:00
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
/* If we get here, *all* paste data buffers were successfully
|
|
|
|
|
|
* flushed */
|
|
|
|
|
|
|
|
|
|
|
|
if (!term->is_sending_paste_data) {
|
|
|
|
|
|
tll_foreach(term->ptmx_buffers, it)
|
|
|
|
|
|
write_one_buffer(term->ptmx_buffers);
|
2019-11-03 01:03:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-22 09:14:18 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* If we get here, *all* buffers were successfully flushed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Or, we're still sending paste data, in which case we do *not*
|
|
|
|
|
|
* want to send the "normal" queued up data
|
|
|
|
|
|
*
|
|
|
|
|
|
* In both cases, we want to *disable* the FDM callback since
|
|
|
|
|
|
* otherwise we'd just be called right away again, with nothing to
|
|
|
|
|
|
* write.
|
|
|
|
|
|
*/
|
2020-01-10 19:51:16 +01:00
|
|
|
|
fdm_event_del(term->fdm, term->ptmx, EPOLLOUT);
|
2019-11-03 01:03:52 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-31 20:37:43 +01:00
|
|
|
|
#if PTMX_TIMING
|
2020-08-23 07:42:20 +02:00
|
|
|
|
static struct timespec last = {0};
|
2019-12-31 20:26:30 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-11-26 18:08:28 +01:00
|
|
|
|
static bool cursor_blink_rearm_timer(struct terminal *term);
|
|
|
|
|
|
|
2020-11-21 13:25:56 +01:00
|
|
|
|
/* Externally visible, but not declared in terminal.h, to enable pgo
|
|
|
|
|
|
* to call this function directly */
|
|
|
|
|
|
bool
|
2019-10-28 18:35:16 +01:00
|
|
|
|
fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
|
2020-02-03 19:58:32 +01:00
|
|
|
|
const bool pollin = events & EPOLLIN;
|
|
|
|
|
|
const bool pollout = events & EPOLLOUT;
|
|
|
|
|
|
const bool hup = events & EPOLLHUP;
|
2019-11-05 09:23:13 +01:00
|
|
|
|
|
|
|
|
|
|
if (pollout) {
|
2019-11-03 01:03:52 +01:00
|
|
|
|
if (!fdm_ptmx_out(fdm, fd, events, data))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-05 19:50:49 +01:00
|
|
|
|
/* Prevent blinking while typing */
|
2020-11-26 18:08:28 +01:00
|
|
|
|
if (term->cursor_blink.fd >= 0) {
|
|
|
|
|
|
term->cursor_blink.state = CURSOR_BLINK_ON;
|
|
|
|
|
|
cursor_blink_rearm_timer(term);
|
|
|
|
|
|
}
|
2020-02-05 19:50:49 +01:00
|
|
|
|
|
2020-01-10 19:51:16 +01:00
|
|
|
|
uint8_t buf[24 * 1024];
|
2020-02-05 19:50:49 +01:00
|
|
|
|
ssize_t count = sizeof(buf);
|
2020-01-10 19:24:45 +01:00
|
|
|
|
|
2021-04-07 19:09:31 +02:00
|
|
|
|
const size_t max_iterations = !hup ? 10 : (size_t)-1ll;
|
2019-10-28 18:35:16 +01:00
|
|
|
|
|
2021-04-07 19:09:31 +02:00
|
|
|
|
for (size_t i = 0; i < max_iterations && pollin; i++) {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(pollin);
|
2020-02-05 19:50:49 +01:00
|
|
|
|
count = read(term->ptmx, buf, sizeof(buf));
|
2020-01-10 19:51:16 +01:00
|
|
|
|
|
2020-02-05 19:50:49 +01:00
|
|
|
|
if (count < 0) {
|
2021-04-07 19:09:31 +02:00
|
|
|
|
if (errno == EAGAIN || errno == EIO) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* EAGAIN: no more to read - FDM will trigger us again
|
|
|
|
|
|
* EIO: assume PTY was closed - we already have, or will get, a EPOLLHUP
|
|
|
|
|
|
*/
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-06-19 11:33:03 +02:00
|
|
|
|
|
2020-02-05 19:50:49 +01:00
|
|
|
|
LOG_ERRNO("failed to read from pseudo terminal");
|
|
|
|
|
|
return false;
|
2021-04-18 13:56:56 +03:00
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Reached end-of-file
|
|
|
|
|
|
*/
|
|
|
|
|
|
break;
|
2020-02-05 19:50:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vt_from_slave(term, buf, count);
|
|
|
|
|
|
}
|
2019-12-19 07:23:58 +01:00
|
|
|
|
|
2020-12-14 19:05:03 +01:00
|
|
|
|
if (!term->render.app_sync_updates.enabled) {
|
2020-03-17 16:32:57 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* We likely need to re-render. But, we don't want to do it
|
|
|
|
|
|
* immediately. Often, a single client update is done through
|
|
|
|
|
|
* multiple writes. This could lead to us rendering one frame with
|
|
|
|
|
|
* "intermediate" state.
|
|
|
|
|
|
*
|
|
|
|
|
|
* For example, we might end up rendering a frame
|
|
|
|
|
|
* where the client just erased a line, while in the
|
|
|
|
|
|
* next frame, the client wrote to the same line. This
|
|
|
|
|
|
* causes screen "flickering".
|
|
|
|
|
|
*
|
|
|
|
|
|
* Mitigate by always incuring a small delay before
|
|
|
|
|
|
* rendering the next frame. This gives the client
|
|
|
|
|
|
* some time to finish the operation (and thus gives
|
|
|
|
|
|
* us time to receive the last writes before doing any
|
|
|
|
|
|
* actual rendering).
|
|
|
|
|
|
*
|
|
|
|
|
|
* We incur this delay *every* time we receive
|
|
|
|
|
|
* input. To ensure we don't delay rendering
|
|
|
|
|
|
* indefinitely, we start a second timer that is only
|
|
|
|
|
|
* reset when we render.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note that when the client is producing data at a
|
|
|
|
|
|
* very high pace, we're rate limited by the wayland
|
|
|
|
|
|
* compositor anyway. The delay we introduce here only
|
|
|
|
|
|
* has any effect when the renderer is idle.
|
|
|
|
|
|
*/
|
delayed rendering: ignore frame callback if delayed rendering is active
Before, we applied delayed rendering (that is, we gave the client a
chance to do more writes before we scheduled a render refresh) only
when the renderer were idle.
However, with e.g. a high keyboard repeat rate, it is very much
possible to start the render loop and then never break out of it while
receiving keyboard input.
This causes screen flickering, as we're no longer even trying to
detect the clients transaction boundaries.
So, let's rewrite how this is done.
First, we give the user the ability to disable delayed rendering
altogether, by setting either the lower or upper timeout to 0.
Second, when delayed rendering is enabled, we ignore the frame
callback. That is, when receiving input, we *always* reschedule the
lower timeout timer, regardless of whether the render is idle or not.
The render's frame callback handler will *not* render the grid if the
delayed render timers are armed.
This means for longer client data bursts, we may now skip frames. That
is, we're trading screen flicker for the occasional frame hickup.
For short client data bursts we should behave roughly as before.
This greatly improves the behavior of fullscreen, or near fullscreen,
updates of large grids (example, scrolling in emacs in fullscreen,
with a vertical buffer split).
2020-03-23 19:21:41 +01:00
|
|
|
|
uint64_t lower_ns = term->conf->tweak.delayed_render_lower_ns;
|
|
|
|
|
|
uint64_t upper_ns = term->conf->tweak.delayed_render_upper_ns;
|
2019-12-31 20:26:30 +01:00
|
|
|
|
|
delayed rendering: ignore frame callback if delayed rendering is active
Before, we applied delayed rendering (that is, we gave the client a
chance to do more writes before we scheduled a render refresh) only
when the renderer were idle.
However, with e.g. a high keyboard repeat rate, it is very much
possible to start the render loop and then never break out of it while
receiving keyboard input.
This causes screen flickering, as we're no longer even trying to
detect the clients transaction boundaries.
So, let's rewrite how this is done.
First, we give the user the ability to disable delayed rendering
altogether, by setting either the lower or upper timeout to 0.
Second, when delayed rendering is enabled, we ignore the frame
callback. That is, when receiving input, we *always* reschedule the
lower timeout timer, regardless of whether the render is idle or not.
The render's frame callback handler will *not* render the grid if the
delayed render timers are armed.
This means for longer client data bursts, we may now skip frames. That
is, we're trading screen flicker for the occasional frame hickup.
For short client data bursts we should behave roughly as before.
This greatly improves the behavior of fullscreen, or near fullscreen,
updates of large grids (example, scrolling in emacs in fullscreen,
with a vertical buffer split).
2020-03-23 19:21:41 +01:00
|
|
|
|
if (lower_ns > 0 && upper_ns > 0) {
|
2020-01-12 12:23:29 +01:00
|
|
|
|
#if PTMX_TIMING
|
|
|
|
|
|
struct timespec now;
|
|
|
|
|
|
|
|
|
|
|
|
clock_gettime(1, &now);
|
|
|
|
|
|
if (last.tv_sec > 0 || last.tv_nsec > 0) {
|
|
|
|
|
|
struct timeval diff;
|
|
|
|
|
|
struct timeval l = {last.tv_sec, last.tv_nsec / 1000};
|
|
|
|
|
|
struct timeval n = {now.tv_sec, now.tv_nsec / 1000};
|
|
|
|
|
|
|
|
|
|
|
|
timersub(&n, &l, &diff);
|
|
|
|
|
|
LOG_INFO("waited %lu µs for more input", diff.tv_usec);
|
|
|
|
|
|
}
|
|
|
|
|
|
last = now;
|
2019-12-31 20:26:30 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(lower_ns < 1000000000);
|
|
|
|
|
|
xassert(upper_ns < 1000000000);
|
|
|
|
|
|
xassert(upper_ns > lower_ns);
|
2020-03-17 16:46:54 +01:00
|
|
|
|
|
2019-10-28 18:35:16 +01:00
|
|
|
|
timerfd_settime(
|
2020-01-12 12:23:29 +01:00
|
|
|
|
term->delayed_render_timer.lower_fd, 0,
|
2020-03-17 16:46:54 +01:00
|
|
|
|
&(struct itimerspec){.it_value = {.tv_nsec = lower_ns}},
|
2019-10-28 18:35:16 +01:00
|
|
|
|
NULL);
|
2020-01-12 12:23:29 +01:00
|
|
|
|
|
|
|
|
|
|
/* Second timeout - only reset when we render. Set to one
|
|
|
|
|
|
* frame (assuming 60Hz) */
|
|
|
|
|
|
if (!term->delayed_render_timer.is_armed) {
|
|
|
|
|
|
timerfd_settime(
|
|
|
|
|
|
term->delayed_render_timer.upper_fd, 0,
|
2020-03-17 16:46:54 +01:00
|
|
|
|
&(struct itimerspec){.it_value = {.tv_nsec = upper_ns}},
|
2020-01-12 12:23:29 +01:00
|
|
|
|
NULL);
|
|
|
|
|
|
term->delayed_render_timer.is_armed = true;
|
|
|
|
|
|
}
|
2020-03-17 16:32:57 +01:00
|
|
|
|
} else
|
delayed rendering: ignore frame callback if delayed rendering is active
Before, we applied delayed rendering (that is, we gave the client a
chance to do more writes before we scheduled a render refresh) only
when the renderer were idle.
However, with e.g. a high keyboard repeat rate, it is very much
possible to start the render loop and then never break out of it while
receiving keyboard input.
This causes screen flickering, as we're no longer even trying to
detect the clients transaction boundaries.
So, let's rewrite how this is done.
First, we give the user the ability to disable delayed rendering
altogether, by setting either the lower or upper timeout to 0.
Second, when delayed rendering is enabled, we ignore the frame
callback. That is, when receiving input, we *always* reschedule the
lower timeout timer, regardless of whether the render is idle or not.
The render's frame callback handler will *not* render the grid if the
delayed render timers are armed.
This means for longer client data bursts, we may now skip frames. That
is, we're trading screen flicker for the occasional frame hickup.
For short client data bursts we should behave roughly as before.
This greatly improves the behavior of fullscreen, or near fullscreen,
updates of large grids (example, scrolling in emacs in fullscreen,
with a vertical buffer split).
2020-03-23 19:21:41 +01:00
|
|
|
|
render_refresh(term);
|
2020-03-17 16:32:57 +01:00
|
|
|
|
}
|
2019-10-28 18:35:16 +01:00
|
|
|
|
|
2020-02-03 19:58:32 +01:00
|
|
|
|
if (hup) {
|
2020-12-26 01:29:40 +01:00
|
|
|
|
fdm_del(fdm, fd);
|
|
|
|
|
|
term->ptmx = -1;
|
2020-02-03 19:58:32 +01:00
|
|
|
|
}
|
2020-12-14 19:05:03 +01:00
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
return true;
|
2019-10-28 18:35:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
fdm_flash(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (events & EPOLLHUP)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
uint64_t expiration_count;
|
|
|
|
|
|
ssize_t ret = read(
|
|
|
|
|
|
term->flash.fd, &expiration_count, sizeof(expiration_count));
|
|
|
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2019-11-02 01:44:01 +01:00
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2019-10-28 18:35:16 +01:00
|
|
|
|
LOG_ERRNO("failed to read flash timer");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("flash timer expired %llu times",
|
|
|
|
|
|
(unsigned long long)expiration_count);
|
|
|
|
|
|
|
|
|
|
|
|
term->flash.active = false;
|
|
|
|
|
|
term_damage_view(term);
|
|
|
|
|
|
render_refresh(term);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
fdm_blink(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (events & EPOLLHUP)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
uint64_t expiration_count;
|
|
|
|
|
|
ssize_t ret = read(
|
|
|
|
|
|
term->blink.fd, &expiration_count, sizeof(expiration_count));
|
|
|
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2019-11-02 01:44:01 +01:00
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2019-10-28 18:35:16 +01:00
|
|
|
|
LOG_ERRNO("failed to read blink timer");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("blink timer expired %llu times",
|
|
|
|
|
|
(unsigned long long)expiration_count);
|
|
|
|
|
|
|
2019-11-04 13:11:15 +01:00
|
|
|
|
/* Invert blink state */
|
2019-10-28 18:35:16 +01:00
|
|
|
|
term->blink.state = term->blink.state == BLINK_ON
|
|
|
|
|
|
? BLINK_OFF : BLINK_ON;
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan all visible cells and mark rows with blinking cells dirty */
|
2019-12-17 19:11:27 +01:00
|
|
|
|
bool no_blinking_cells = true;
|
2019-10-28 18:35:16 +01:00
|
|
|
|
for (int r = 0; r < term->rows; r++) {
|
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, r);
|
|
|
|
|
|
for (int col = 0; col < term->cols; col++) {
|
|
|
|
|
|
struct cell *cell = &row->cells[col];
|
|
|
|
|
|
|
|
|
|
|
|
if (cell->attrs.blink) {
|
|
|
|
|
|
cell->attrs.clean = 0;
|
|
|
|
|
|
row->dirty = true;
|
2019-12-17 19:11:27 +01:00
|
|
|
|
no_blinking_cells = false;
|
2019-10-28 18:35:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 19:11:27 +01:00
|
|
|
|
if (no_blinking_cells) {
|
|
|
|
|
|
LOG_DBG("disarming blink timer");
|
|
|
|
|
|
|
|
|
|
|
|
term->blink.state = BLINK_ON;
|
2020-10-13 18:40:20 +02:00
|
|
|
|
fdm_del(term->fdm, term->blink.fd);
|
|
|
|
|
|
term->blink.fd = -1;
|
2019-12-17 19:11:27 +01:00
|
|
|
|
} else
|
|
|
|
|
|
render_refresh(term);
|
2019-10-28 18:35:16 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 19:11:27 +01:00
|
|
|
|
void
|
|
|
|
|
|
term_arm_blink_timer(struct terminal *term)
|
|
|
|
|
|
{
|
2020-10-13 18:40:20 +02:00
|
|
|
|
if (term->blink.fd >= 0)
|
2019-12-17 19:11:27 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("arming blink timer");
|
2020-10-13 18:40:20 +02:00
|
|
|
|
|
|
|
|
|
|
int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
|
LOG_ERRNO("failed to create blink timer FD");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_blink, term)) {
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-17 19:11:27 +01:00
|
|
|
|
struct itimerspec alarm = {
|
|
|
|
|
|
.it_value = {.tv_sec = 0, .tv_nsec = 500 * 1000000},
|
|
|
|
|
|
.it_interval = {.tv_sec = 0, .tv_nsec = 500 * 1000000},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-10-13 18:40:20 +02:00
|
|
|
|
if (timerfd_settime(fd, 0, &alarm, NULL) < 0) {
|
2019-12-17 19:11:27 +01:00
|
|
|
|
LOG_ERRNO("failed to arm blink timer");
|
2020-10-13 18:40:20 +02:00
|
|
|
|
fdm_del(term->fdm, fd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
term->blink.fd = fd;
|
2019-12-17 19:11:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-16 21:31:40 +01:00
|
|
|
|
static void
|
|
|
|
|
|
cursor_refresh(struct terminal *term)
|
|
|
|
|
|
{
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cur_row->cells[term->grid->cursor.point.col].attrs.clean = 0;
|
2019-12-16 21:31:40 +01:00
|
|
|
|
term->grid->cur_row->dirty = true;
|
|
|
|
|
|
render_refresh(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-15 15:07:56 +01:00
|
|
|
|
static bool
|
|
|
|
|
|
fdm_cursor_blink(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (events & EPOLLHUP)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
uint64_t expiration_count;
|
|
|
|
|
|
ssize_t ret = read(
|
|
|
|
|
|
term->cursor_blink.fd, &expiration_count, sizeof(expiration_count));
|
|
|
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
LOG_ERRNO("failed to read cursor blink timer");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("cursor blink timer expired %llu times",
|
|
|
|
|
|
(unsigned long long)expiration_count);
|
|
|
|
|
|
|
|
|
|
|
|
/* Invert blink state */
|
|
|
|
|
|
term->cursor_blink.state = term->cursor_blink.state == CURSOR_BLINK_ON
|
|
|
|
|
|
? CURSOR_BLINK_OFF : CURSOR_BLINK_ON;
|
|
|
|
|
|
|
2019-12-16 21:31:40 +01:00
|
|
|
|
cursor_refresh(term);
|
2019-12-15 15:07:56 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 18:35:16 +01:00
|
|
|
|
static bool
|
|
|
|
|
|
fdm_delayed_render(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (events & EPOLLHUP)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t unused;
|
|
|
|
|
|
ssize_t ret1 = 0;
|
|
|
|
|
|
ssize_t ret2 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (fd == term->delayed_render_timer.lower_fd)
|
|
|
|
|
|
ret1 = read(term->delayed_render_timer.lower_fd, &unused, sizeof(unused));
|
|
|
|
|
|
if (fd == term->delayed_render_timer.upper_fd)
|
|
|
|
|
|
ret2 = read(term->delayed_render_timer.upper_fd, &unused, sizeof(unused));
|
|
|
|
|
|
|
2019-11-01 20:27:45 +01:00
|
|
|
|
if ((ret1 < 0 || ret2 < 0)) {
|
2019-11-02 01:44:01 +01:00
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2019-10-28 18:35:16 +01:00
|
|
|
|
LOG_ERRNO("failed to read timeout timer");
|
2019-11-01 20:27:45 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-31 15:39:40 +01:00
|
|
|
|
if (ret1 > 0)
|
|
|
|
|
|
LOG_DBG("lower delay timer expired");
|
|
|
|
|
|
else if (ret2 > 0)
|
|
|
|
|
|
LOG_DBG("upper delay timer expired");
|
|
|
|
|
|
|
2020-03-24 17:41:33 +01:00
|
|
|
|
if (ret1 == 0 && ret2 == 0)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2019-12-31 20:37:43 +01:00
|
|
|
|
#if PTMX_TIMING
|
2020-08-23 07:42:20 +02:00
|
|
|
|
last = (struct timespec){0};
|
2019-12-31 20:26:30 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2019-11-01 20:27:45 +01:00
|
|
|
|
/* Reset timers */
|
2020-08-23 07:42:20 +02:00
|
|
|
|
struct itimerspec reset = {{0}};
|
2019-11-01 20:27:45 +01:00
|
|
|
|
timerfd_settime(term->delayed_render_timer.lower_fd, 0, &reset, NULL);
|
|
|
|
|
|
timerfd_settime(term->delayed_render_timer.upper_fd, 0, &reset, NULL);
|
2020-03-24 17:41:33 +01:00
|
|
|
|
term->delayed_render_timer.is_armed = false;
|
2020-03-23 19:16:53 +01:00
|
|
|
|
|
2020-03-24 17:41:33 +01:00
|
|
|
|
render_refresh(term);
|
2019-10-28 18:35:16 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-12 12:40:42 +01:00
|
|
|
|
static bool
|
2020-01-12 12:55:19 +01:00
|
|
|
|
fdm_app_sync_updates_timeout(
|
2020-01-12 12:40:42 +01:00
|
|
|
|
struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (events & EPOLLHUP)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
uint64_t unused;
|
2020-01-12 12:55:19 +01:00
|
|
|
|
ssize_t ret = read(term->render.app_sync_updates.timer_fd,
|
2020-01-12 12:40:42 +01:00
|
|
|
|
&unused, sizeof(unused));
|
|
|
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
LOG_ERRNO("failed to read application synchronized updates timeout timer");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term_disable_app_sync_updates(term);
|
2020-01-12 12:40:42 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 17:45:59 +01:00
|
|
|
|
static bool
|
|
|
|
|
|
initialize_render_workers(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_INFO("using %zu rendering threads", term->render.workers.count);
|
|
|
|
|
|
|
2020-05-04 20:11:45 +02:00
|
|
|
|
if (sem_init(&term->render.workers.start, 0, 0) < 0 ||
|
|
|
|
|
|
sem_init(&term->render.workers.done, 0, 0) < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_ERRNO("failed to instantiate render worker semaphores");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
|
if ((err = mtx_init(&term->render.workers.lock, mtx_plain)) != thrd_success) {
|
|
|
|
|
|
LOG_ERR("failed to instantiate render worker mutex: %s (%d)",
|
|
|
|
|
|
thrd_err_as_string(err), err);
|
|
|
|
|
|
goto err_sem_destroy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-08 20:34:30 +01:00
|
|
|
|
term->render.workers.threads = xcalloc(
|
2019-10-30 17:45:59 +01:00
|
|
|
|
term->render.workers.count, sizeof(term->render.workers.threads[0]));
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++) {
|
2020-08-08 20:34:30 +01:00
|
|
|
|
struct render_worker_context *ctx = xmalloc(sizeof(*ctx));
|
2019-10-30 17:45:59 +01:00
|
|
|
|
*ctx = (struct render_worker_context) {
|
|
|
|
|
|
.term = term,
|
|
|
|
|
|
.my_id = 1 + i,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int ret = thrd_create(
|
|
|
|
|
|
&term->render.workers.threads[i], &render_worker_thread, ctx);
|
2020-05-03 14:17:54 +02:00
|
|
|
|
if (ret != thrd_success) {
|
2020-05-03 12:25:04 +02:00
|
|
|
|
|
|
|
|
|
|
LOG_ERR("failed to create render worker thread: %s (%d)",
|
|
|
|
|
|
thrd_err_as_string(ret), ret);
|
2019-10-30 17:45:59 +01:00
|
|
|
|
term->render.workers.threads[i] = 0;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-05-04 20:11:45 +02:00
|
|
|
|
|
|
|
|
|
|
err_sem_destroy:
|
|
|
|
|
|
sem_destroy(&term->render.workers.start);
|
|
|
|
|
|
sem_destroy(&term->render.workers.done);
|
|
|
|
|
|
return false;
|
2019-10-30 17:45:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-07 17:17:17 +01:00
|
|
|
|
static int
|
|
|
|
|
|
pt_or_px_as_pixels(const struct terminal *term,
|
2021-01-11 19:37:05 +01:00
|
|
|
|
const struct pt_or_px *pt_or_px)
|
2021-01-07 17:17:17 +01:00
|
|
|
|
{
|
|
|
|
|
|
return pt_or_px->px == 0
|
|
|
|
|
|
? pt_or_px->pt * term->font_dpi / 72
|
|
|
|
|
|
: pt_or_px->px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 17:50:12 +01:00
|
|
|
|
static bool
|
2020-04-21 19:29:36 +02:00
|
|
|
|
term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
{
|
|
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(fonts[i] != NULL);
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
|
2020-04-21 19:29:36 +02:00
|
|
|
|
fcft_destroy(term->fonts[i]);
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
term->fonts[i] = fonts[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-26 16:44:11 +01:00
|
|
|
|
for (size_t i = 0; i < ALEN(term->box_drawing); i++) {
|
|
|
|
|
|
if (term->box_drawing[i] != NULL) {
|
|
|
|
|
|
pixman_image_unref(term->box_drawing[i]->pix);
|
|
|
|
|
|
free(term->box_drawing[i]);
|
|
|
|
|
|
term->box_drawing[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-04 13:10:56 +02:00
|
|
|
|
const int old_cell_width = term->cell_width;
|
|
|
|
|
|
const int old_cell_height = term->cell_height;
|
|
|
|
|
|
|
2021-01-07 17:00:58 +01:00
|
|
|
|
const struct config *conf = term->conf;
|
|
|
|
|
|
|
|
|
|
|
|
term->cell_width =
|
|
|
|
|
|
(term->fonts[0]->space_advance.x > 0
|
|
|
|
|
|
? term->fonts[0]->space_advance.x
|
|
|
|
|
|
: term->fonts[0]->max_advance.x)
|
2021-01-07 17:19:34 +01:00
|
|
|
|
+ pt_or_px_as_pixels(term, &conf->letter_spacing);
|
2021-01-07 17:00:58 +01:00
|
|
|
|
|
2021-03-20 15:32:31 +01:00
|
|
|
|
term->cell_height = term->font_line_height.px >= 0
|
|
|
|
|
|
? pt_or_px_as_pixels(term, &term->font_line_height)
|
2021-01-07 11:17:23 +01:00
|
|
|
|
: max(term->fonts[0]->height,
|
|
|
|
|
|
term->fonts[0]->ascent + term->fonts[0]->descent);
|
2021-01-07 17:00:58 +01:00
|
|
|
|
|
2021-01-07 17:19:34 +01:00
|
|
|
|
term->font_x_ofs = pt_or_px_as_pixels(term, &conf->horizontal_letter_offset);
|
|
|
|
|
|
term->font_y_ofs = pt_or_px_as_pixels(term, &conf->vertical_letter_offset);
|
2021-01-07 17:00:58 +01:00
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
|
|
|
|
|
|
|
2020-10-04 13:10:56 +02:00
|
|
|
|
if (term->cell_width < old_cell_width ||
|
|
|
|
|
|
term->cell_height < old_cell_height)
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
* The cell size has decreased.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This means sixels, which we cannot resize, no longer fit
|
|
|
|
|
|
* into their "allocated" grid space.
|
|
|
|
|
|
*
|
|
|
|
|
|
* To be able to fit them, we would have to change the grid
|
|
|
|
|
|
* content. Inserting empty lines _might_ seem acceptable, but
|
|
|
|
|
|
* we'd also need to insert empty columns, which would break
|
|
|
|
|
|
* existing layout completely.
|
|
|
|
|
|
*
|
|
|
|
|
|
* So we delete them.
|
|
|
|
|
|
*/
|
|
|
|
|
|
sixel_destroy_all(term);
|
|
|
|
|
|
} else if (term->cell_width != old_cell_width ||
|
|
|
|
|
|
term->cell_height != old_cell_height)
|
|
|
|
|
|
{
|
|
|
|
|
|
sixel_cell_size_changed(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-13 15:01:09 +02:00
|
|
|
|
/* Use force, since cell-width/height may have changed */
|
2020-03-10 18:07:12 +01:00
|
|
|
|
render_resize_force(term, term->width / term->scale, term->height / term->scale);
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 07:45:03 +02:00
|
|
|
|
static float
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
get_font_dpi(const struct terminal *term)
|
|
|
|
|
|
{
|
2020-03-11 16:10:55 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* Use output's DPI to scale font. This is to ensure the font has
|
|
|
|
|
|
* the same physical height (if measured by a ruler) regardless of
|
|
|
|
|
|
* monitor.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Conceptually, we use the physical monitor specs to calculate
|
|
|
|
|
|
* the DPI, and we ignore the output's scaling factor.
|
|
|
|
|
|
*
|
|
|
|
|
|
* However, to deal with fractional scaling, where we're told to
|
|
|
|
|
|
* render at e.g. 2x, but are then downscaled by the compositor to
|
|
|
|
|
|
* e.g. 1.25, we use the scaled DPI value multiplied by the scale
|
|
|
|
|
|
* factor instead.
|
|
|
|
|
|
*
|
|
|
|
|
|
* For integral scaling factors the resulting DPI is the same as
|
|
|
|
|
|
* if we had used the physical DPI.
|
|
|
|
|
|
*
|
|
|
|
|
|
* For fractional scaling factors we'll get a DPI *larger* than
|
|
|
|
|
|
* the physical DPI, that ends up being right when later
|
|
|
|
|
|
* downscaled by the compositor.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
/* Use highest DPI from outputs we're mapped on */
|
2020-07-26 07:45:03 +02:00
|
|
|
|
double dpi = 0.0;
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window != NULL);
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
tll_foreach(term->window->on_outputs, it) {
|
2020-07-26 07:45:55 +02:00
|
|
|
|
if (it->item->dpi > dpi)
|
|
|
|
|
|
dpi = it->item->dpi;
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If we're not mapped, use DPI from first monitor. Hopefully this is where we'll get mapped later... */
|
2020-07-26 07:45:03 +02:00
|
|
|
|
if (dpi == 0.) {
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
tll_foreach(term->wl->monitors, it) {
|
2020-07-26 07:45:55 +02:00
|
|
|
|
dpi = it->item.dpi;
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dpi == 0) {
|
|
|
|
|
|
/* No monitors? */
|
2020-07-26 07:45:03 +02:00
|
|
|
|
dpi = 96.;
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return dpi;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-17 17:59:31 +01:00
|
|
|
|
static int
|
|
|
|
|
|
get_font_scale(const struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Same as get_font_dpi(), but returns output scale factor instead */
|
|
|
|
|
|
int scale = 0;
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window != NULL);
|
2020-11-17 17:59:31 +01:00
|
|
|
|
tll_foreach(term->window->on_outputs, it) {
|
|
|
|
|
|
if (it->item->scale > scale)
|
|
|
|
|
|
scale = it->item->scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scale == 0) {
|
|
|
|
|
|
tll_foreach(term->wl->monitors, it) {
|
|
|
|
|
|
scale = it->item.scale;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scale == 0)
|
|
|
|
|
|
scale = 1;
|
|
|
|
|
|
|
|
|
|
|
|
return scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-21 19:29:36 +02:00
|
|
|
|
static enum fcft_subpixel
|
2020-04-20 18:37:59 +02:00
|
|
|
|
get_font_subpixel(const struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->colors.alpha != 0xffff) {
|
|
|
|
|
|
/* Can't do subpixel rendering on transparent background */
|
2020-04-21 19:29:36 +02:00
|
|
|
|
return FCFT_SUBPIXEL_NONE;
|
2020-04-20 18:37:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum wl_output_subpixel wl_subpixel;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Wayland doesn't tell us *which* part of the surface that goes
|
|
|
|
|
|
* on a specific output, only whether the surface is mapped to an
|
|
|
|
|
|
* output or not.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Thus, when determining which subpixel mode to use, we can't do
|
|
|
|
|
|
* much but select *an* output. So, we pick the first one.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If we're not mapped at all, we pick the first available
|
|
|
|
|
|
* monitor, and hope that's where we'll eventually get mapped.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If there aren't any monitors we use the "default" subpixel
|
|
|
|
|
|
* mode.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (tll_length(term->window->on_outputs) > 0)
|
|
|
|
|
|
wl_subpixel = tll_front(term->window->on_outputs)->subpixel;
|
|
|
|
|
|
else if (tll_length(term->wl->monitors) > 0)
|
|
|
|
|
|
wl_subpixel = tll_front(term->wl->monitors).subpixel;
|
|
|
|
|
|
else
|
|
|
|
|
|
wl_subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
|
|
switch (wl_subpixel) {
|
2020-04-21 19:29:36 +02:00
|
|
|
|
case WL_OUTPUT_SUBPIXEL_UNKNOWN: return FCFT_SUBPIXEL_DEFAULT;
|
|
|
|
|
|
case WL_OUTPUT_SUBPIXEL_NONE: return FCFT_SUBPIXEL_NONE;
|
|
|
|
|
|
case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: return FCFT_SUBPIXEL_HORIZONTAL_RGB;
|
|
|
|
|
|
case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: return FCFT_SUBPIXEL_HORIZONTAL_BGR;
|
|
|
|
|
|
case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: return FCFT_SUBPIXEL_VERTICAL_RGB;
|
|
|
|
|
|
case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: return FCFT_SUBPIXEL_VERTICAL_BGR;
|
2020-04-20 18:37:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-21 19:29:36 +02:00
|
|
|
|
return FCFT_SUBPIXEL_DEFAULT;
|
2020-04-20 18:37:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-17 12:05:22 +01:00
|
|
|
|
static bool
|
|
|
|
|
|
font_should_size_by_dpi(const struct terminal *term, int new_scale)
|
|
|
|
|
|
{
|
|
|
|
|
|
return term->conf->dpi_aware == DPI_AWARE_YES ||
|
|
|
|
|
|
(term->conf->dpi_aware == DPI_AWARE_AUTO && new_scale <= 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
font_size_by_dpi(const struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
return font_should_size_by_dpi(term, term->font_scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
font_size_by_scale(const struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
return !font_size_by_dpi(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-28 22:07:02 +02:00
|
|
|
|
struct font_load_data {
|
|
|
|
|
|
size_t count;
|
|
|
|
|
|
const char **names;
|
|
|
|
|
|
const char *attrs;
|
|
|
|
|
|
|
|
|
|
|
|
struct fcft_font **font;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
|
font_loader_thread(void *_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct font_load_data *data = _data;
|
|
|
|
|
|
*data->font = fcft_from_name(data->count, data->names, data->attrs);
|
|
|
|
|
|
return *data->font != NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
static bool
|
2020-07-07 10:44:55 +02:00
|
|
|
|
reload_fonts(struct terminal *term)
|
2019-10-30 17:50:12 +01:00
|
|
|
|
{
|
2020-10-20 21:04:47 +02:00
|
|
|
|
const size_t counts[4] = {
|
|
|
|
|
|
tll_length(term->conf->fonts[0]),
|
|
|
|
|
|
tll_length(term->conf->fonts[1]),
|
|
|
|
|
|
tll_length(term->conf->fonts[2]),
|
|
|
|
|
|
tll_length(term->conf->fonts[3]),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Configure size (which may have been changed run-time) */
|
|
|
|
|
|
char **names[4];
|
|
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
|
|
names[i] = xmalloc(counts[i] * sizeof(names[i][0]));
|
2019-10-30 17:50:12 +01:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
tll_foreach(term->conf->fonts[i], it) {
|
|
|
|
|
|
bool use_px_size = term->font_sizes[i][j].px_size > 0;
|
|
|
|
|
|
char size[64];
|
2019-10-30 17:50:12 +01:00
|
|
|
|
|
2020-12-17 12:05:22 +01:00
|
|
|
|
const int scale = font_size_by_scale(term) ? term->scale : 1;
|
2020-11-17 17:59:31 +01:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
if (use_px_size)
|
2020-11-17 17:59:31 +01:00
|
|
|
|
snprintf(size, sizeof(size), ":pixelsize=%d",
|
|
|
|
|
|
term->font_sizes[i][j].px_size * scale);
|
2020-10-20 21:04:47 +02:00
|
|
|
|
else
|
2020-11-17 17:59:31 +01:00
|
|
|
|
snprintf(size, sizeof(size), ":size=%.2f",
|
|
|
|
|
|
term->font_sizes[i][j].pt_size * (double)scale);
|
2020-07-07 10:44:55 +02:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
size_t len = strlen(it->item.pattern) + strlen(size) + 1;
|
|
|
|
|
|
names[i][j] = xmalloc(len);
|
2020-07-07 10:44:55 +02:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
strcpy(names[i][j], it->item.pattern);
|
|
|
|
|
|
strcat(names[i][j], size);
|
|
|
|
|
|
j++;
|
|
|
|
|
|
}
|
2020-07-07 10:44:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
/* Did user configure custom bold/italic fonts?
|
|
|
|
|
|
* Or should we use the regular font, with weight/slant attributes? */
|
|
|
|
|
|
const bool custom_bold = counts[1] > 0;
|
|
|
|
|
|
const bool custom_italic = counts[2] > 0;
|
|
|
|
|
|
const bool custom_bold_italic = counts[3] > 0;
|
|
|
|
|
|
|
|
|
|
|
|
const size_t count_regular = counts[0];
|
|
|
|
|
|
const char **names_regular = (const char **)names[0];
|
|
|
|
|
|
|
|
|
|
|
|
const size_t count_bold = custom_bold ? counts[1] : counts[0];
|
|
|
|
|
|
const char **names_bold = (const char **)(custom_bold ? names[1] : names[0]);
|
|
|
|
|
|
|
|
|
|
|
|
const size_t count_italic = custom_italic ? counts[2] : counts[0];
|
2020-12-17 12:05:22 +01:00
|
|
|
|
const char **names_italic = (const char **)(custom_italic ? names[2] : names[0]);
|
2020-10-20 21:04:47 +02:00
|
|
|
|
|
|
|
|
|
|
const size_t count_bold_italic = custom_bold_italic ? counts[3] : counts[0];
|
|
|
|
|
|
const char **names_bold_italic = (const char **)(custom_bold_italic ? names[3] : names[0]);
|
|
|
|
|
|
|
2020-12-17 12:05:22 +01:00
|
|
|
|
const bool use_dpi = font_size_by_dpi(term);
|
2020-11-17 17:59:31 +01:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
char *attrs[4] = {NULL};
|
|
|
|
|
|
int attr_len[4] = {-1, -1, -1, -1}; /* -1, so that +1 (below) results in 0 */
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 2; i++) {
|
2020-11-17 17:59:31 +01:00
|
|
|
|
attr_len[0] = snprintf(
|
|
|
|
|
|
attrs[0], attr_len[0] + 1, "dpi=%.2f",
|
2020-11-17 18:43:55 +01:00
|
|
|
|
use_dpi ? term->font_dpi : 96);
|
2020-11-17 17:59:31 +01:00
|
|
|
|
attr_len[1] = snprintf(
|
|
|
|
|
|
attrs[1], attr_len[1] + 1, "dpi=%.2f:%s",
|
2020-11-17 18:43:55 +01:00
|
|
|
|
use_dpi ? term->font_dpi : 96, !custom_bold ? "weight=bold" : "");
|
2020-11-17 17:59:31 +01:00
|
|
|
|
attr_len[2] = snprintf(
|
|
|
|
|
|
attrs[2], attr_len[2] + 1, "dpi=%.2f:%s",
|
2020-11-17 18:43:55 +01:00
|
|
|
|
use_dpi ? term->font_dpi : 96, !custom_italic ? "slant=italic" : "");
|
2020-11-17 17:59:31 +01:00
|
|
|
|
attr_len[3] = snprintf(
|
|
|
|
|
|
attrs[3], attr_len[3] + 1, "dpi=%.2f:%s",
|
2020-11-17 18:43:55 +01:00
|
|
|
|
use_dpi ? term->font_dpi : 96, !custom_bold_italic ? "weight=bold:slant=italic" : "");
|
2020-10-20 21:04:47 +02:00
|
|
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 4; i++)
|
|
|
|
|
|
attrs[i] = xmalloc(attr_len[i] + 1);
|
|
|
|
|
|
}
|
2019-12-04 22:02:02 +01:00
|
|
|
|
|
2020-07-07 10:44:55 +02:00
|
|
|
|
struct fcft_font *fonts[4];
|
2020-04-28 22:07:02 +02:00
|
|
|
|
struct font_load_data data[4] = {
|
2020-10-20 21:04:47 +02:00
|
|
|
|
{count_regular, names_regular, attrs[0], &fonts[0]},
|
|
|
|
|
|
{count_bold, names_bold, attrs[1], &fonts[1]},
|
|
|
|
|
|
{count_italic, names_italic, attrs[2], &fonts[2]},
|
|
|
|
|
|
{count_bold_italic, names_bold_italic, attrs[3], &fonts[3]},
|
2020-04-28 22:07:02 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-08-23 07:42:20 +02:00
|
|
|
|
thrd_t tids[4] = {0};
|
2020-05-03 12:25:04 +02:00
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
|
|
int ret = thrd_create(&tids[i], &font_loader_thread, &data[i]);
|
2020-05-03 14:17:54 +02:00
|
|
|
|
if (ret != thrd_success) {
|
2020-05-03 12:25:04 +02:00
|
|
|
|
LOG_ERR("failed to create font loader thread: %s (%d)",
|
|
|
|
|
|
thrd_err_as_string(ret), ret);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-28 22:07:02 +02:00
|
|
|
|
|
|
|
|
|
|
bool success = true;
|
|
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
2020-05-03 12:25:04 +02:00
|
|
|
|
if (tids[i] != 0) {
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
thrd_join(tids[i], &ret);
|
|
|
|
|
|
success = success && ret;
|
|
|
|
|
|
} else
|
|
|
|
|
|
success = false;
|
2020-04-28 22:07:02 +02:00
|
|
|
|
}
|
2020-02-08 17:57:50 +01:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
|
|
for (size_t j = 0; j < counts[i]; j++)
|
|
|
|
|
|
free(names[i][j]);
|
|
|
|
|
|
free(names[i]);
|
|
|
|
|
|
free(attrs[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-28 22:07:02 +02:00
|
|
|
|
if (!success) {
|
2020-02-09 16:56:59 +01:00
|
|
|
|
LOG_ERR("failed to load primary fonts");
|
2020-02-08 17:57:50 +01:00
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
2020-04-21 19:29:36 +02:00
|
|
|
|
fcft_destroy(fonts[i]);
|
2020-02-08 17:57:50 +01:00
|
|
|
|
fonts[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-07 10:44:55 +02:00
|
|
|
|
return success ? term_set_fonts(term, fonts) : success;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
load_fonts_from_conf(struct terminal *term)
|
|
|
|
|
|
{
|
2020-10-20 21:04:47 +02:00
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
tll_foreach(term->conf->fonts[i], it) {
|
|
|
|
|
|
term->font_sizes[i][j++] = (struct config_font){
|
|
|
|
|
|
.pt_size = it->item.pt_size, .px_size = it->item.px_size};
|
|
|
|
|
|
}
|
2020-07-07 10:44:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-20 15:32:31 +01:00
|
|
|
|
term->font_line_height = term->conf->line_height;
|
2020-07-07 10:44:55 +02:00
|
|
|
|
return reload_fonts(term);
|
2019-10-30 17:50:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
static void
|
|
|
|
|
|
slave_died(struct reaper *reaper, pid_t pid, int status, void *data)
|
2020-12-26 01:29:40 +01:00
|
|
|
|
{
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
LOG_DBG("slave (PID=%u) died", pid);
|
|
|
|
|
|
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
term->slave_has_been_reaped = true;
|
|
|
|
|
|
term->exit_status = status;
|
|
|
|
|
|
|
2021-03-12 22:06:50 +01:00
|
|
|
|
if (!term->conf->hold_at_exit)
|
|
|
|
|
|
term_shutdown(term);
|
2020-12-26 01:29:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
struct terminal *
|
2020-05-21 20:17:29 +02:00
|
|
|
|
term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|
|
|
|
|
struct wayland *wayl, const char *foot_exe, const char *cwd,
|
|
|
|
|
|
int argc, char *const *argv,
|
2019-11-01 20:34:32 +01:00
|
|
|
|
void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data)
|
2019-10-28 18:25:19 +01:00
|
|
|
|
{
|
2019-10-28 18:46:03 +01:00
|
|
|
|
int ptmx = -1;
|
|
|
|
|
|
int flash_fd = -1;
|
|
|
|
|
|
int delay_lower_fd = -1;
|
|
|
|
|
|
int delay_upper_fd = -1;
|
2020-01-12 12:55:19 +01:00
|
|
|
|
int app_sync_updates_fd = -1;
|
2019-10-28 18:46:03 +01:00
|
|
|
|
|
2019-10-30 20:22:01 +01:00
|
|
|
|
struct terminal *term = malloc(sizeof(*term));
|
2020-08-08 20:34:30 +01:00
|
|
|
|
if (unlikely(term == NULL)) {
|
|
|
|
|
|
LOG_ERRNO("malloc() failed");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2019-10-28 18:46:03 +01:00
|
|
|
|
|
|
|
|
|
|
if ((ptmx = posix_openpt(O_RDWR | O_NOCTTY)) == -1) {
|
|
|
|
|
|
LOG_ERRNO("failed to open PTY");
|
|
|
|
|
|
goto close_fds;
|
|
|
|
|
|
}
|
2020-01-10 21:33:40 +01:00
|
|
|
|
if ((flash_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK)) == -1) {
|
2019-10-28 18:46:03 +01:00
|
|
|
|
LOG_ERRNO("failed to create flash timer FD");
|
|
|
|
|
|
goto close_fds;
|
|
|
|
|
|
}
|
2020-01-10 21:33:40 +01:00
|
|
|
|
if ((delay_lower_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK)) == -1 ||
|
|
|
|
|
|
(delay_upper_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK)) == -1)
|
2019-10-28 18:46:03 +01:00
|
|
|
|
{
|
|
|
|
|
|
LOG_ERRNO("failed to create delayed rendering timer FDs");
|
|
|
|
|
|
goto close_fds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-12 12:55:19 +01:00
|
|
|
|
if ((app_sync_updates_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK)) == -1)
|
2020-01-12 12:40:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
LOG_ERRNO("failed to create application synchronized updates timer FD");
|
|
|
|
|
|
goto close_fds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-29 18:06:04 +01:00
|
|
|
|
if (ioctl(ptmx, (unsigned int)TIOCSWINSZ,
|
2020-06-02 19:59:28 +02:00
|
|
|
|
&(struct winsize){.ws_row = 24, .ws_col = 80}) < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_ERRNO("failed to set initial TIOCSWINSZ");
|
|
|
|
|
|
goto close_fds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-03 01:03:52 +01:00
|
|
|
|
int ptmx_flags;
|
|
|
|
|
|
if ((ptmx_flags = fcntl(ptmx, F_GETFL)) < 0 ||
|
|
|
|
|
|
fcntl(ptmx, F_SETFL, ptmx_flags | O_NONBLOCK) < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_ERRNO("failed to configure ptmx as non-blocking");
|
|
|
|
|
|
goto err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-30 17:22:57 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Enable all FDM callbackes *except* ptmx - we can't do that
|
|
|
|
|
|
* until the window has been 'configured' since we don't have a
|
|
|
|
|
|
* size (and thus no grid) before then.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (!fdm_add(fdm, flash_fd, EPOLLIN, &fdm_flash, term) ||
|
2019-11-03 00:25:17 +01:00
|
|
|
|
!fdm_add(fdm, delay_lower_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
2020-01-12 12:40:42 +01:00
|
|
|
|
!fdm_add(fdm, delay_upper_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
2020-01-12 12:55:19 +01:00
|
|
|
|
!fdm_add(fdm, app_sync_updates_fd, EPOLLIN, &fdm_app_sync_updates_timeout, term))
|
2019-10-30 20:22:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
goto err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 18:05:03 +01:00
|
|
|
|
/* Initialize configure-based terminal attributes */
|
2019-10-28 18:25:19 +01:00
|
|
|
|
*term = (struct terminal) {
|
|
|
|
|
|
.fdm = fdm,
|
2020-05-21 20:17:29 +02:00
|
|
|
|
.reaper = reaper,
|
2020-02-08 14:09:06 +01:00
|
|
|
|
.conf = conf,
|
2019-10-28 18:46:03 +01:00
|
|
|
|
.ptmx = ptmx,
|
2020-08-22 09:14:18 +02:00
|
|
|
|
.ptmx_buffers = tll_init(),
|
|
|
|
|
|
.ptmx_paste_buffers = tll_init(),
|
2020-10-20 21:04:47 +02:00
|
|
|
|
.font_sizes = {
|
|
|
|
|
|
xmalloc(sizeof(term->font_sizes[0][0]) * tll_length(conf->fonts[0])),
|
|
|
|
|
|
xmalloc(sizeof(term->font_sizes[1][0]) * tll_length(conf->fonts[1])),
|
|
|
|
|
|
xmalloc(sizeof(term->font_sizes[2][0]) * tll_length(conf->fonts[2])),
|
|
|
|
|
|
xmalloc(sizeof(term->font_sizes[3][0]) * tll_length(conf->fonts[3])),
|
|
|
|
|
|
},
|
2020-07-26 07:45:03 +02:00
|
|
|
|
.font_dpi = 0.,
|
2020-11-17 17:59:31 +01:00
|
|
|
|
.font_scale = 0,
|
2020-04-20 18:37:59 +02:00
|
|
|
|
.font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */
|
2020-04-21 19:29:36 +02:00
|
|
|
|
? FCFT_SUBPIXEL_DEFAULT
|
|
|
|
|
|
: FCFT_SUBPIXEL_NONE),
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.cursor_keys_mode = CURSOR_KEYS_NORMAL,
|
|
|
|
|
|
.keypad_keys_mode = KEYPAD_NUMERICAL,
|
2020-10-06 18:42:26 +02:00
|
|
|
|
.reverse_wrap = true,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.auto_margin = true,
|
|
|
|
|
|
.window_title_stack = tll_init(),
|
|
|
|
|
|
.scale = 1,
|
2019-10-28 18:46:03 +01:00
|
|
|
|
.flash = {.fd = flash_fd},
|
2020-10-13 18:40:20 +02:00
|
|
|
|
.blink = {.fd = -1},
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.vt = {
|
2020-01-20 18:35:13 +01:00
|
|
|
|
.state = 0, /* STATE_GROUND */
|
2021-02-13 12:34:11 +01:00
|
|
|
|
.osc8 = {
|
|
|
|
|
|
.begin = {-1, -1},
|
|
|
|
|
|
},
|
2019-10-28 18:25:19 +01:00
|
|
|
|
},
|
|
|
|
|
|
.colors = {
|
2019-10-30 17:40:09 +01:00
|
|
|
|
.fg = conf->colors.fg,
|
|
|
|
|
|
.bg = conf->colors.bg,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.alpha = conf->colors.alpha,
|
2021-04-07 08:09:40 +02:00
|
|
|
|
.selection_fg = conf->colors.selection_fg,
|
|
|
|
|
|
.selection_bg = conf->colors.selection_bg,
|
|
|
|
|
|
.use_custom_selection = conf->colors.use_custom.selection,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
},
|
2019-11-05 13:27:37 +01:00
|
|
|
|
.origin = ORIGIN_ABSOLUTE,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.cursor_style = conf->cursor.style,
|
2019-12-15 15:07:56 +01:00
|
|
|
|
.cursor_blink = {
|
2020-11-26 18:08:28 +01:00
|
|
|
|
.decset = false,
|
|
|
|
|
|
.deccsusr = conf->cursor.blink,
|
2019-12-15 15:07:56 +01:00
|
|
|
|
.state = CURSOR_BLINK_ON,
|
2020-10-13 19:23:04 +02:00
|
|
|
|
.fd = -1,
|
2019-12-15 15:07:56 +01:00
|
|
|
|
},
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.cursor_color = {
|
|
|
|
|
|
.text = conf->cursor.color.text,
|
|
|
|
|
|
.cursor = conf->cursor.color.cursor,
|
|
|
|
|
|
},
|
|
|
|
|
|
.selection = {
|
|
|
|
|
|
.start = {-1, -1},
|
|
|
|
|
|
.end = {-1, -1},
|
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.
On each timer timeout, we scroll one line, and update the
selection. Thus, the shorter the interval, the faster we scroll.
The timer is canceled as soon as the mouse enters the grid again, or
the selection is either canceled or finalized.
The timer FD is created and destroyed on-demand.
Most of the logic is now in selection.c. The exception is the
calculation of the timer interval, which depends on the mouse’s
position. Thus, this is done in input.c.
The scroll+selection update logic needs to know a) which direction
we’re scrolling in, and b) which *column* the selection should be
updated with.
If the mouse is outside the grid’s left or right margins, the stored
mouse column will be -1. I.e. we don’t know whether the mouse is on
the left or right side of the grid. This is why the caller, that
starts the timer, must provide this value.
The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
|
|
|
|
.auto_scroll = {
|
|
|
|
|
|
.fd = -1,
|
|
|
|
|
|
},
|
2019-10-28 18:25:19 +01:00
|
|
|
|
},
|
2020-08-04 18:07:22 +02:00
|
|
|
|
.normal = {.scroll_damage = tll_init(), .sixel_images = tll_init()},
|
|
|
|
|
|
.alt = {.scroll_damage = tll_init(), .sixel_images = tll_init()},
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.grid = &term->normal,
|
unicode-combining: store seen combining chains "globally" in the term struct
Instead of storing combining data per cell, realize that most
combinations are re-occurring and that there's lots of available space
left in the unicode range, and store seen base+combining combinations
chains in a per-terminal array.
When we encounter a combining character, we first try to pre-compose,
like before. If that fails, we then search for the current
base+combining combo in the list of previously seen combinations. If
not found there either, we allocate a new combo and add it to the
list. Regardless, the result is an index into this array. We store
this index, offsetted by COMB_CHARS_LO=0x40000000ul in the cell.
When rendering, we need to check if the cell character is a plain
character, or if it's a composed character (identified by checking if
the cell character is >= COMB_CHARS_LO).
Then we render the grapheme pretty much like before.
2020-05-03 11:03:22 +02:00
|
|
|
|
.composed_count = 0,
|
|
|
|
|
|
.composed = NULL,
|
2020-09-15 19:09:00 +02:00
|
|
|
|
.alt_scrolling = conf->mouse.alternate_scroll_mode,
|
2020-01-20 18:38:50 +01:00
|
|
|
|
.meta = {
|
|
|
|
|
|
.esc_prefix = true,
|
|
|
|
|
|
.eight_bit = true,
|
|
|
|
|
|
},
|
2020-11-11 18:26:47 +01:00
|
|
|
|
.num_lock_modifier = true,
|
2020-12-10 18:22:48 +01:00
|
|
|
|
.bell_action_enabled = true,
|
2019-11-16 10:54:21 +01:00
|
|
|
|
.tab_stops = tll_init(),
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.wl = wayl,
|
|
|
|
|
|
.render = {
|
2020-07-25 14:31:45 +02:00
|
|
|
|
.scrollback_lines = conf->scrollback.lines,
|
2020-01-12 12:55:19 +01:00
|
|
|
|
.app_sync_updates.timer_fd = app_sync_updates_fd,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
.workers = {
|
|
|
|
|
|
.count = conf->render_worker_count,
|
|
|
|
|
|
.queue = tll_init(),
|
|
|
|
|
|
},
|
2019-12-31 15:39:40 +01:00
|
|
|
|
.presentation_timings = conf->presentation_timings,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
},
|
|
|
|
|
|
.delayed_render_timer = {
|
|
|
|
|
|
.is_armed = false,
|
2019-10-28 18:46:03 +01:00
|
|
|
|
.lower_fd = delay_lower_fd,
|
|
|
|
|
|
.upper_fd = delay_upper_fd,
|
2019-10-28 18:25:19 +01:00
|
|
|
|
},
|
2020-02-22 14:02:00 +01:00
|
|
|
|
.sixel = {
|
sixel: implement private mode 80 - sixel scrolling
When enabled (the default), sixels behave much like normal output; the
start where the cursor is, and the cursor moves with the
sixel. I.e. after emitting a sixel the cursor is left after the image;
either to the right, if private mode 8452 is enabled, or otherwise on
the next line. Terminal content is scrolled up if the sixel is larger
than the screen.
When disabled, sixels *always* start at (0,0), the cursor never moves,
and the terminal content never scrolls.
In other words, the ‘disabled’ mode is a much simpler mode.
All we need to do to support both modes is re-write the sixel-emitting
loop to:
* break early if we’re “out of rows”, i.e. we’ve reached the bottom of
the screen.
* not linefeed, or move the cursor when scrolling is disabled
This patch also fixes a bug in the (new) implementation of private
mode 8452.
When emitting a sixel, we may break it up into smaller pieces, to
ensure a single sixel (as tracked internally) does not cross the
scrollback wrap-around.
The code that checked if we should do a linefeed or not, would skip
the linefeed on the last row of *each* such sixel piece. The correct
thing to do is to skip it only on the last row of the *last* piece.
I chose not to fix this bug in a separate patch since doing so would
have meant re-writing it again when implementing private mode 80.
2021-02-26 09:28:03 +01:00
|
|
|
|
.scrolling = true,
|
2021-02-16 19:37:49 +01:00
|
|
|
|
.use_private_palette = true,
|
2020-02-22 14:02:00 +01:00
|
|
|
|
.palette_size = SIXEL_MAX_COLORS,
|
2020-11-23 20:10:55 +01:00
|
|
|
|
.max_width = SIXEL_MAX_WIDTH,
|
|
|
|
|
|
.max_height = SIXEL_MAX_HEIGHT,
|
2020-02-22 14:02:00 +01:00
|
|
|
|
},
|
2019-11-01 20:34:32 +01:00
|
|
|
|
.shutdown_cb = shutdown_cb,
|
|
|
|
|
|
.shutdown_data = shutdown_data,
|
2020-08-08 20:34:30 +01:00
|
|
|
|
.foot_exe = xstrdup(foot_exe),
|
|
|
|
|
|
.cwd = xstrdup(cwd),
|
2020-12-04 18:39:11 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
.ime_enabled = true,
|
2020-12-04 18:39:11 +01:00
|
|
|
|
#endif
|
2019-10-28 18:25:19 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-03-14 19:19:10 +01:00
|
|
|
|
term_update_ascii_printer(term);
|
|
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
tll_foreach(conf->fonts[i], it) {
|
|
|
|
|
|
term->font_sizes[i][j++] = (struct config_font){
|
2020-07-07 10:44:55 +02:00
|
|
|
|
.pt_size = it->item.pt_size, .px_size = it->item.px_size};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-20 15:32:31 +01:00
|
|
|
|
term->font_line_height = conf->line_height;
|
2020-07-07 10:44:55 +02:00
|
|
|
|
|
2020-04-30 11:39:41 +02:00
|
|
|
|
/* Start the slave/client */
|
|
|
|
|
|
if ((term->slave = slave_spawn(
|
|
|
|
|
|
term->ptmx, argc, term->cwd, argv,
|
2020-07-29 19:42:12 +02:00
|
|
|
|
conf->term, conf->shell, conf->login_shell,
|
2020-07-30 18:57:21 +02:00
|
|
|
|
&conf->notifications)) == -1)
|
2020-04-30 11:39:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
goto err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-26 01:29:40 +01:00
|
|
|
|
reaper_add(term->reaper, term->slave, &slave_died, term);
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
/* Guess scale; we're not mapped yet, so we don't know on which
|
|
|
|
|
|
* output we'll be. Pick highest scale we find for now */
|
|
|
|
|
|
tll_foreach(term->wl->monitors, it) {
|
|
|
|
|
|
if (it->item.scale > term->scale)
|
|
|
|
|
|
term->scale = it->item.scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-07 08:07:43 +02:00
|
|
|
|
memcpy(term->colors.table, term->conf->colors.table,
|
|
|
|
|
|
sizeof(term->colors.table));
|
2020-04-30 11:39:41 +02:00
|
|
|
|
|
2020-01-03 11:15:35 +01:00
|
|
|
|
/* Initialize the Wayland window backend */
|
2020-01-03 13:37:03 +01:00
|
|
|
|
if ((term->window = wayl_win_init(term)) == NULL)
|
2019-10-28 18:46:03 +01:00
|
|
|
|
goto err;
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
/* Load fonts */
|
2020-02-28 18:35:05 +01:00
|
|
|
|
if (!term_font_dpi_changed(term))
|
|
|
|
|
|
goto err;
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
|
2020-04-22 19:38:38 +02:00
|
|
|
|
term->font_subpixel = get_font_subpixel(term);
|
|
|
|
|
|
|
2020-04-01 19:59:47 +02:00
|
|
|
|
term_set_window_title(term, conf->title);
|
2020-03-09 18:46:50 +01:00
|
|
|
|
|
|
|
|
|
|
/* Let the Wayland backend know we exist */
|
|
|
|
|
|
tll_push_back(wayl->terms, term);
|
|
|
|
|
|
|
2020-03-26 19:39:12 +01:00
|
|
|
|
switch (conf->startup_mode) {
|
|
|
|
|
|
case STARTUP_WINDOWED:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case STARTUP_MAXIMIZED:
|
|
|
|
|
|
xdg_toplevel_set_maximized(term->window->xdg_toplevel);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case STARTUP_FULLSCREEN:
|
|
|
|
|
|
xdg_toplevel_set_fullscreen(term->window->xdg_toplevel, NULL);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-29 20:07:21 +02:00
|
|
|
|
if (!initialize_render_workers(term))
|
|
|
|
|
|
goto err;
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
|
|
|
|
|
return term;
|
|
|
|
|
|
|
2019-10-28 18:46:03 +01:00
|
|
|
|
err:
|
2020-05-04 20:46:27 +02:00
|
|
|
|
term->is_shutting_down = true;
|
2019-10-28 18:25:19 +01:00
|
|
|
|
term_destroy(term);
|
|
|
|
|
|
return NULL;
|
2019-10-28 18:46:03 +01:00
|
|
|
|
|
|
|
|
|
|
close_fds:
|
2020-04-30 17:22:57 +02:00
|
|
|
|
close(ptmx);
|
2019-11-01 20:29:16 +01:00
|
|
|
|
fdm_del(fdm, flash_fd);
|
|
|
|
|
|
fdm_del(fdm, delay_lower_fd);
|
|
|
|
|
|
fdm_del(fdm, delay_upper_fd);
|
2020-01-12 12:55:19 +01:00
|
|
|
|
fdm_del(fdm, app_sync_updates_fd);
|
2019-11-01 20:29:16 +01:00
|
|
|
|
|
2019-10-30 20:22:01 +01:00
|
|
|
|
free(term);
|
2019-10-28 18:46:03 +01:00
|
|
|
|
return NULL;
|
2019-10-28 18:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-30 17:22:57 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_window_configured(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Enable ptmx FDM callback */
|
2020-05-04 20:49:28 +02:00
|
|
|
|
if (!term->is_shutting_down) {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->is_configured);
|
2020-05-04 20:49:28 +02:00
|
|
|
|
fdm_add(term->fdm, term->ptmx, EPOLLIN, &fdm_ptmx, term);
|
|
|
|
|
|
}
|
2020-04-30 17:22:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
static bool
|
|
|
|
|
|
fdm_shutdown(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_DBG("FDM shutdown");
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
|
2019-11-01 20:30:58 +01:00
|
|
|
|
/* Kill the event FD */
|
2019-10-30 20:03:11 +01:00
|
|
|
|
fdm_del(term->fdm, fd);
|
|
|
|
|
|
|
2019-11-01 20:30:58 +01:00
|
|
|
|
wayl_win_destroy(term->window);
|
|
|
|
|
|
term->window = NULL;
|
2019-10-30 20:03:11 +01:00
|
|
|
|
|
2020-08-07 20:42:34 +01:00
|
|
|
|
struct wayland *wayl = term->wl;
|
2019-11-21 18:18:35 +01:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Normally we'd get unmapped when we destroy the Wayland
|
|
|
|
|
|
* above.
|
|
|
|
|
|
*
|
|
|
|
|
|
* However, it appears that under certain conditions, those events
|
|
|
|
|
|
* are deferred (for example, when a screen locker is active), and
|
|
|
|
|
|
* thus we can get here without having been unmapped.
|
|
|
|
|
|
*/
|
2020-07-08 16:45:26 +02:00
|
|
|
|
tll_foreach(wayl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term)
|
|
|
|
|
|
it->item.kbd_focus = NULL;
|
|
|
|
|
|
if (it->item.mouse_focus == term)
|
|
|
|
|
|
it->item.mouse_focus = NULL;
|
|
|
|
|
|
}
|
2019-10-30 20:03:11 +01:00
|
|
|
|
|
2019-11-01 20:34:32 +01:00
|
|
|
|
void (*cb)(void *, int) = term->shutdown_cb;
|
|
|
|
|
|
void *cb_data = term->shutdown_data;
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
2019-11-01 20:30:58 +01:00
|
|
|
|
int exit_code = term_destroy(term);
|
2019-11-01 20:34:32 +01:00
|
|
|
|
if (cb != NULL)
|
|
|
|
|
|
cb(cb_data, exit_code);
|
2019-11-01 20:30:58 +01:00
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
term_shutdown(struct terminal *term)
|
|
|
|
|
|
{
|
2019-11-01 20:30:58 +01:00
|
|
|
|
if (term->is_shutting_down)
|
|
|
|
|
|
return true;
|
2019-10-30 20:03:11 +01:00
|
|
|
|
|
2019-11-01 20:30:58 +01:00
|
|
|
|
term->is_shutting_down = true;
|
2019-10-30 20:03:11 +01:00
|
|
|
|
|
|
|
|
|
|
/*
|
2019-11-01 20:30:58 +01:00
|
|
|
|
* Close FDs then postpone self-destruction to the next poll
|
|
|
|
|
|
* iteration, by creating an event FD that we trigger immediately.
|
2019-10-30 20:03:11 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2020-11-26 18:08:28 +01:00
|
|
|
|
term_cursor_blink_update(term);
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->cursor_blink.fd < 0);
|
2019-12-16 21:32:57 +01:00
|
|
|
|
|
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.
On each timer timeout, we scroll one line, and update the
selection. Thus, the shorter the interval, the faster we scroll.
The timer is canceled as soon as the mouse enters the grid again, or
the selection is either canceled or finalized.
The timer FD is created and destroyed on-demand.
Most of the logic is now in selection.c. The exception is the
calculation of the timer interval, which depends on the mouse’s
position. Thus, this is done in input.c.
The scroll+selection update logic needs to know a) which direction
we’re scrolling in, and b) which *column* the selection should be
updated with.
If the mouse is outside the grid’s left or right margins, the stored
mouse column will be -1. I.e. we don’t know whether the mouse is on
the left or right side of the grid. This is why the caller, that
starts the timer, must provide this value.
The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
|
|
|
|
fdm_del(term->fdm, term->selection.auto_scroll.fd);
|
2020-01-12 12:55:19 +01:00
|
|
|
|
fdm_del(term->fdm, term->render.app_sync_updates.timer_fd);
|
2019-11-01 20:30:58 +01:00
|
|
|
|
fdm_del(term->fdm, term->delayed_render_timer.lower_fd);
|
|
|
|
|
|
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
|
|
|
|
|
|
fdm_del(term->fdm, term->blink.fd);
|
|
|
|
|
|
fdm_del(term->fdm, term->flash.fd);
|
2020-04-30 17:22:57 +02:00
|
|
|
|
|
2021-01-12 09:21:01 +01:00
|
|
|
|
/* We’ll deal with this explicitly */
|
|
|
|
|
|
reaper_del(term->reaper, term->slave);
|
|
|
|
|
|
|
2020-04-30 17:22:57 +02:00
|
|
|
|
if (term->window != NULL && term->window->is_configured)
|
|
|
|
|
|
fdm_del(term->fdm, term->ptmx);
|
|
|
|
|
|
else
|
|
|
|
|
|
close(term->ptmx);
|
2019-11-01 20:30:58 +01:00
|
|
|
|
|
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.
On each timer timeout, we scroll one line, and update the
selection. Thus, the shorter the interval, the faster we scroll.
The timer is canceled as soon as the mouse enters the grid again, or
the selection is either canceled or finalized.
The timer FD is created and destroyed on-demand.
Most of the logic is now in selection.c. The exception is the
calculation of the timer interval, which depends on the mouse’s
position. Thus, this is done in input.c.
The scroll+selection update logic needs to know a) which direction
we’re scrolling in, and b) which *column* the selection should be
updated with.
If the mouse is outside the grid’s left or right margins, the stored
mouse column will be -1. I.e. we don’t know whether the mouse is on
the left or right side of the grid. This is why the caller, that
starts the timer, must provide this value.
The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
|
|
|
|
term->selection.auto_scroll.fd = -1;
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term->render.app_sync_updates.timer_fd = -1;
|
2019-11-01 20:30:58 +01:00
|
|
|
|
term->delayed_render_timer.lower_fd = -1;
|
|
|
|
|
|
term->delayed_render_timer.upper_fd = -1;
|
|
|
|
|
|
term->blink.fd = -1;
|
|
|
|
|
|
term->flash.fd = -1;
|
|
|
|
|
|
term->ptmx = -1;
|
|
|
|
|
|
|
2020-01-10 19:25:56 +01:00
|
|
|
|
int event_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
2019-10-30 20:03:11 +01:00
|
|
|
|
if (event_fd == -1) {
|
|
|
|
|
|
LOG_ERRNO("failed to create terminal shutdown event FD");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
if (!fdm_add(term->fdm, event_fd, EPOLLIN, &fdm_shutdown, term)) {
|
|
|
|
|
|
close(event_fd);
|
|
|
|
|
|
return false;
|
2019-10-28 18:35:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
if (write(event_fd, &(uint64_t){1}, sizeof(uint64_t)) != sizeof(uint64_t)) {
|
|
|
|
|
|
LOG_ERRNO("failed to send terminal shutdown event");
|
|
|
|
|
|
fdm_del(term->fdm, event_fd);
|
|
|
|
|
|
return false;
|
2019-10-28 18:35:16 +01:00
|
|
|
|
}
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-02 12:02:11 +01:00
|
|
|
|
static volatile sig_atomic_t alarm_raised;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
sig_alarm(int signo)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_DBG("SIGALRM");
|
|
|
|
|
|
alarm_raised = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 20:03:11 +01:00
|
|
|
|
int
|
|
|
|
|
|
term_destroy(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term == NULL)
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
2019-11-01 20:30:58 +01:00
|
|
|
|
tll_foreach(term->wl->terms, it) {
|
|
|
|
|
|
if (it->item == term) {
|
|
|
|
|
|
tll_remove(term->wl->terms, it);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.
On each timer timeout, we scroll one line, and update the
selection. Thus, the shorter the interval, the faster we scroll.
The timer is canceled as soon as the mouse enters the grid again, or
the selection is either canceled or finalized.
The timer FD is created and destroyed on-demand.
Most of the logic is now in selection.c. The exception is the
calculation of the timer interval, which depends on the mouse’s
position. Thus, this is done in input.c.
The scroll+selection update logic needs to know a) which direction
we’re scrolling in, and b) which *column* the selection should be
updated with.
If the mouse is outside the grid’s left or right margins, the stored
mouse column will be -1. I.e. we don’t know whether the mouse is on
the left or right side of the grid. This is why the caller, that
starts the timer, must provide this value.
The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
|
|
|
|
fdm_del(term->fdm, term->selection.auto_scroll.fd);
|
2020-01-12 12:55:19 +01:00
|
|
|
|
fdm_del(term->fdm, term->render.app_sync_updates.timer_fd);
|
2019-11-01 20:30:58 +01:00
|
|
|
|
fdm_del(term->fdm, term->delayed_render_timer.lower_fd);
|
|
|
|
|
|
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
|
2019-12-15 15:07:56 +01:00
|
|
|
|
fdm_del(term->fdm, term->cursor_blink.fd);
|
2019-11-01 20:30:58 +01:00
|
|
|
|
fdm_del(term->fdm, term->blink.fd);
|
|
|
|
|
|
fdm_del(term->fdm, term->flash.fd);
|
|
|
|
|
|
fdm_del(term->fdm, term->ptmx);
|
2019-10-30 20:03:11 +01:00
|
|
|
|
|
2021-01-31 11:53:12 +01:00
|
|
|
|
if (term->window != NULL) {
|
2019-10-30 20:03:11 +01:00
|
|
|
|
wayl_win_destroy(term->window);
|
2021-01-31 11:53:12 +01:00
|
|
|
|
term->window = NULL;
|
|
|
|
|
|
}
|
2019-10-30 20:03:11 +01:00
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
mtx_lock(&term->render.workers.lock);
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(tll_length(term->render.workers.queue) == 0);
|
2019-10-30 17:45:59 +01:00
|
|
|
|
|
|
|
|
|
|
/* Count livinig threads - we may get here when only some of the
|
|
|
|
|
|
* threads have been successfully started */
|
|
|
|
|
|
size_t worker_count = 0;
|
2020-04-29 20:08:19 +02:00
|
|
|
|
if (term->render.workers.threads != NULL) {
|
|
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++, worker_count++) {
|
|
|
|
|
|
if (term->render.workers.threads[i] == 0)
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-10-30 17:45:59 +01:00
|
|
|
|
|
2020-04-29 20:08:19 +02:00
|
|
|
|
for (size_t i = 0; i < worker_count; i++) {
|
|
|
|
|
|
sem_post(&term->render.workers.start);
|
|
|
|
|
|
tll_push_back(term->render.workers.queue, -2);
|
|
|
|
|
|
}
|
2019-10-28 18:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
mtx_unlock(&term->render.workers.lock);
|
2019-10-30 17:45:59 +01:00
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
free(term->vt.osc.data);
|
2021-03-28 21:01:22 +02:00
|
|
|
|
free(term->vt.osc8.uri);
|
2021-02-22 10:20:52 +01:00
|
|
|
|
grid_free(&term->normal);
|
|
|
|
|
|
grid_free(&term->alt);
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
unicode-combining: store seen combining chains "globally" in the term struct
Instead of storing combining data per cell, realize that most
combinations are re-occurring and that there's lots of available space
left in the unicode range, and store seen base+combining combinations
chains in a per-terminal array.
When we encounter a combining character, we first try to pre-compose,
like before. If that fails, we then search for the current
base+combining combo in the list of previously seen combinations. If
not found there either, we allocate a new combo and add it to the
list. Regardless, the result is an index into this array. We store
this index, offsetted by COMB_CHARS_LO=0x40000000ul in the cell.
When rendering, we need to check if the cell character is a plain
character, or if it's a composed character (identified by checking if
the cell character is >= COMB_CHARS_LO).
Then we render the grapheme pretty much like before.
2020-05-03 11:03:22 +02:00
|
|
|
|
free(term->composed);
|
|
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
free(term->window_title);
|
|
|
|
|
|
tll_free_and_free(term->window_title_stack, free);
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(term->fonts) / sizeof(term->fonts[0]); i++)
|
2020-04-21 19:29:36 +02:00
|
|
|
|
fcft_destroy(term->fonts[i]);
|
2020-10-20 21:04:47 +02:00
|
|
|
|
for (size_t i = 0; i < 4; i++)
|
|
|
|
|
|
free(term->font_sizes[i]);
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
2020-12-26 16:24:16 +01:00
|
|
|
|
for (size_t i = 0; i < ALEN(term->box_drawing); i++) {
|
|
|
|
|
|
if (term->box_drawing[i] != NULL) {
|
|
|
|
|
|
pixman_image_unref(term->box_drawing[i]->pix);
|
|
|
|
|
|
free(term->box_drawing[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
free(term->search.buf);
|
|
|
|
|
|
|
2020-04-29 20:08:19 +02:00
|
|
|
|
if (term->render.workers.threads != NULL) {
|
|
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++) {
|
|
|
|
|
|
if (term->render.workers.threads[i] != 0)
|
|
|
|
|
|
thrd_join(term->render.workers.threads[i], NULL);
|
|
|
|
|
|
}
|
2019-10-30 17:45:59 +01:00
|
|
|
|
}
|
2019-10-28 18:25:19 +01:00
|
|
|
|
free(term->render.workers.threads);
|
|
|
|
|
|
mtx_destroy(&term->render.workers.lock);
|
|
|
|
|
|
sem_destroy(&term->render.workers.start);
|
|
|
|
|
|
sem_destroy(&term->render.workers.done);
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(tll_length(term->render.workers.queue) == 0);
|
2019-10-28 18:25:19 +01:00
|
|
|
|
tll_free(term->render.workers.queue);
|
|
|
|
|
|
|
2021-02-07 14:52:04 +01:00
|
|
|
|
tll_free(term->tab_stops);
|
|
|
|
|
|
|
|
|
|
|
|
tll_foreach(term->ptmx_buffers, it) {
|
2020-08-22 09:14:18 +02:00
|
|
|
|
free(it->item.data);
|
2021-02-07 14:52:04 +01:00
|
|
|
|
tll_remove(term->ptmx_buffers, it);
|
|
|
|
|
|
}
|
|
|
|
|
|
tll_foreach(term->ptmx_paste_buffers, it) {
|
2019-11-03 01:03:52 +01:00
|
|
|
|
free(it->item.data);
|
2021-02-07 14:52:04 +01:00
|
|
|
|
tll_remove(term->ptmx_paste_buffers, it);
|
|
|
|
|
|
}
|
2019-12-21 15:35:54 +01:00
|
|
|
|
|
2020-06-10 18:36:54 +02:00
|
|
|
|
sixel_fini(term);
|
2020-02-21 23:40:35 +01:00
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
urls_reset(term);
|
2020-12-04 18:39:11 +01:00
|
|
|
|
term_ime_reset(term);
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
2019-12-21 15:27:17 +01:00
|
|
|
|
free(term->foot_exe);
|
2019-12-21 15:35:54 +01:00
|
|
|
|
free(term->cwd);
|
2019-11-03 01:03:52 +01:00
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
int ret = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->slave > 0) {
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
int exit_status;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->slave_has_been_reaped)
|
|
|
|
|
|
exit_status = term->exit_status;
|
|
|
|
|
|
else {
|
|
|
|
|
|
LOG_DBG("waiting for slave (PID=%u) to die", term->slave);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Note: we've closed ptmx, so the slave *should* exit...
|
|
|
|
|
|
*
|
|
|
|
|
|
* But, since it is possible to write clients that ignore
|
|
|
|
|
|
* this, we need to handle it in *some* way.
|
|
|
|
|
|
*
|
|
|
|
|
|
* So, what we do is register a SIGALRM handler, and configure
|
|
|
|
|
|
* a 2 second alarm. If the slave hasn't died after this time,
|
|
|
|
|
|
* we send it a SIGTERM, then wait another 2 seconds (using
|
|
|
|
|
|
* the same alarm mechanism). If it still hasn't died, we send
|
|
|
|
|
|
* it a SIGKILL.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note that this solution is *not* asynchronous, and any
|
|
|
|
|
|
* other events etc will be ignored during this time. This of
|
|
|
|
|
|
* course only applies to a 'foot --server' instance, where
|
|
|
|
|
|
* there might be other terminals running.
|
|
|
|
|
|
*/
|
|
|
|
|
|
sigaction(SIGALRM, &(const struct sigaction){.sa_handler = &sig_alarm}, NULL);
|
|
|
|
|
|
alarm(2);
|
|
|
|
|
|
|
|
|
|
|
|
int kill_signal = SIGTERM;
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
int r = waitpid(term->slave, &exit_status, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (r == term->slave)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
if (r == -1) {
|
|
|
|
|
|
xassert(errno == EINTR);
|
|
|
|
|
|
|
|
|
|
|
|
if (alarm_raised) {
|
|
|
|
|
|
LOG_DBG("slave hasn't died yet, sending: %s (%d)",
|
|
|
|
|
|
kill_signal == SIGTERM ? "SIGTERM" : "SIGKILL",
|
|
|
|
|
|
kill_signal);
|
|
|
|
|
|
|
|
|
|
|
|
kill(term->slave, kill_signal);
|
|
|
|
|
|
|
|
|
|
|
|
alarm_raised = 0;
|
|
|
|
|
|
if (kill_signal != SIGKILL)
|
|
|
|
|
|
alarm(2);
|
|
|
|
|
|
|
|
|
|
|
|
kill_signal = SIGKILL;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-11-02 12:02:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
/* Cancel alarm */
|
|
|
|
|
|
alarm(0);
|
|
|
|
|
|
sigaction(SIGALRM, &(const struct sigaction){.sa_handler = SIG_DFL}, NULL);
|
|
|
|
|
|
}
|
2019-10-28 18:25:19 +01:00
|
|
|
|
|
2019-11-02 11:30:32 +01:00
|
|
|
|
ret = EXIT_FAILURE;
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
if (WIFEXITED(exit_status)) {
|
|
|
|
|
|
ret = WEXITSTATUS(exit_status);
|
2019-11-02 12:02:11 +01:00
|
|
|
|
LOG_DBG("slave exited with code %d", ret);
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
} else if (WIFSIGNALED(exit_status)) {
|
|
|
|
|
|
ret = WTERMSIG(exit_status);
|
2019-11-02 12:02:11 +01:00
|
|
|
|
LOG_WARN("slave exited with signal %d (%s)", ret, strsignal(ret));
|
2019-10-28 18:25:19 +01:00
|
|
|
|
} else {
|
reaper: monitor SIGCHLD using the FDM instead of via a signalfd
In addition to letting the FDM do the low-level signal watching, this
patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a
signal, or via a signalfd, can be coalesced, like all signals.
This means we need to loop on waitpid() with WNOHANG until there are
no more processes to reap.
This in turn requires a small change to the way reaper callbacks are
implemented.
Previously, the callback was allowed to do the wait(). This was
signalled back to the reaper through the callback’s return value.
Now, since we’ve already wait():ed, the process’ exit status is passed
as an argument to the reaper callback.
The callback for the client application has been updated accordingly;
it sets a flag in the terminal struct, telling term_destroy() that the
process has already been wait():ed on, and also stores the exit
status.
2021-02-10 16:22:51 +01:00
|
|
|
|
LOG_WARN("slave exited for unknown reason (status = 0x%08x)",
|
|
|
|
|
|
exit_status);
|
2019-10-28 18:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(term);
|
2019-11-03 12:57:47 +01:00
|
|
|
|
|
|
|
|
|
|
#if defined(__GLIBC__)
|
2019-11-03 12:48:18 +01:00
|
|
|
|
if (!malloc_trim(0))
|
|
|
|
|
|
LOG_WARN("failed to trim memory");
|
2019-11-03 12:57:47 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2019-10-28 18:25:19 +01:00
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-13 11:42:10 +02:00
|
|
|
|
static inline void
|
|
|
|
|
|
erase_cell_range(struct terminal *term, struct row *row, int start, int end)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(start < term->cols);
|
|
|
|
|
|
xassert(end < term->cols);
|
2020-04-13 11:42:10 +02:00
|
|
|
|
|
2020-05-17 16:29:09 +02:00
|
|
|
|
row->dirty = true;
|
|
|
|
|
|
|
2020-04-13 11:42:10 +02:00
|
|
|
|
if (unlikely(term->vt.attrs.have_bg)) {
|
|
|
|
|
|
for (int col = start; col <= end; col++) {
|
|
|
|
|
|
struct cell *c = &row->cells[col];
|
|
|
|
|
|
c->wc = 0;
|
|
|
|
|
|
c->attrs = (struct attributes){.have_bg = 1, .bg = term->vt.attrs.bg};
|
|
|
|
|
|
}
|
|
|
|
|
|
} else
|
|
|
|
|
|
memset(&row->cells[start], 0, (end - start + 1) * sizeof(row->cells[0]));
|
2021-02-23 15:10:40 +01:00
|
|
|
|
|
|
|
|
|
|
if (likely(row->extra == NULL))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
/* Split up, or remove, URI ranges affected by the erase */
|
|
|
|
|
|
tll_foreach(row->extra->uri_ranges, it) {
|
|
|
|
|
|
if (it->item.start < start && it->item.end >= start) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* URI crosses the erase *start* point.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Create a new range for the URI part *before* the erased
|
|
|
|
|
|
* cells.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Also modify this URI range’s start point so that we can
|
|
|
|
|
|
* remove it below.
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct row_uri_range range_before = {
|
|
|
|
|
|
.start = it->item.start,
|
|
|
|
|
|
.end = start - 1,
|
|
|
|
|
|
.id = it->item.id,
|
|
|
|
|
|
.uri = xstrdup(it->item.uri),
|
|
|
|
|
|
};
|
|
|
|
|
|
tll_insert_before(row->extra->uri_ranges, it, range_before);
|
|
|
|
|
|
it->item.start = start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (it->item.start <= end && it->item.end > end) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* URI crosses the erase *end* point.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Create a new range for the URI part *after* the erased
|
|
|
|
|
|
* cells.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Also modify the URI range’s end point so that we can
|
|
|
|
|
|
* remove it below.
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct row_uri_range range_after = {
|
|
|
|
|
|
.start = end + 1,
|
|
|
|
|
|
.end = it->item.end,
|
|
|
|
|
|
.id = it->item.id,
|
|
|
|
|
|
.uri = xstrdup(it->item.uri),
|
|
|
|
|
|
};
|
|
|
|
|
|
tll_insert_before(row->extra->uri_ranges, it, range_after);
|
|
|
|
|
|
it->item.end = end;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (it->item.start >= start && it->item.end <= end) {
|
|
|
|
|
|
/* URI range completey covered by the erase - remove it */
|
|
|
|
|
|
free(it->item.uri);
|
|
|
|
|
|
tll_remove(row->extra->uri_ranges, it);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-13 11:42:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
|
erase_line(struct terminal *term, struct row *row)
|
|
|
|
|
|
{
|
|
|
|
|
|
erase_cell_range(term, row, 0, term->cols - 1);
|
|
|
|
|
|
row->linebreak = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-01 20:51:11 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_reset(struct terminal *term, bool hard)
|
|
|
|
|
|
{
|
|
|
|
|
|
term->cursor_keys_mode = CURSOR_KEYS_NORMAL;
|
|
|
|
|
|
term->keypad_keys_mode = KEYPAD_NUMERICAL;
|
|
|
|
|
|
term->reverse = false;
|
|
|
|
|
|
term->hide_cursor = false;
|
2020-10-06 18:42:26 +02:00
|
|
|
|
term->reverse_wrap = true;
|
2019-08-01 20:51:11 +02:00
|
|
|
|
term->auto_margin = true;
|
|
|
|
|
|
term->insert_mode = false;
|
|
|
|
|
|
term->bracketed_paste = false;
|
|
|
|
|
|
term->focus_events = false;
|
2020-11-29 04:04:57 +00:00
|
|
|
|
term->modify_escape_key = false;
|
2020-12-10 18:22:48 +01:00
|
|
|
|
term->num_lock_modifier = true;
|
|
|
|
|
|
term->bell_action_enabled = true;
|
2019-08-01 20:51:11 +02:00
|
|
|
|
term->mouse_tracking = MOUSE_NONE;
|
|
|
|
|
|
term->mouse_reporting = MOUSE_NORMAL;
|
2019-11-17 09:59:12 +01:00
|
|
|
|
term->charsets.selected = 0;
|
|
|
|
|
|
term->charsets.set[0] = CHARSET_ASCII;
|
|
|
|
|
|
term->charsets.set[1] = CHARSET_ASCII;
|
|
|
|
|
|
term->charsets.set[2] = CHARSET_ASCII;
|
|
|
|
|
|
term->charsets.set[3] = CHARSET_ASCII;
|
2019-11-17 10:02:46 +01:00
|
|
|
|
term->saved_charsets = term->charsets;
|
2019-08-01 20:51:11 +02:00
|
|
|
|
tll_free_and_free(term->window_title_stack, free);
|
2020-06-22 14:33:16 +02:00
|
|
|
|
term_set_window_title(term, term->conf->title);
|
2019-08-01 20:51:11 +02:00
|
|
|
|
|
|
|
|
|
|
term->scroll_region.start = 0;
|
|
|
|
|
|
term->scroll_region.end = term->rows;
|
|
|
|
|
|
|
|
|
|
|
|
free(term->vt.osc.data);
|
|
|
|
|
|
memset(&term->vt, 0, sizeof(term->vt));
|
2020-01-20 18:35:13 +01:00
|
|
|
|
term->vt.state = 0; /* GROUND */
|
2021-03-28 21:01:22 +02:00
|
|
|
|
|
2021-02-13 12:34:11 +01:00
|
|
|
|
term->vt.osc8.begin = (struct coord){-1, -1};
|
|
|
|
|
|
free(term->vt.osc8.uri);
|
|
|
|
|
|
term->vt.osc8.uri = NULL;
|
2019-08-01 20:51:11 +02:00
|
|
|
|
|
|
|
|
|
|
if (term->grid == &term->alt) {
|
|
|
|
|
|
term->grid = &term->normal;
|
|
|
|
|
|
selection_cancel(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-20 18:38:50 +01:00
|
|
|
|
term->meta.esc_prefix = true;
|
|
|
|
|
|
term->meta.eight_bit = true;
|
|
|
|
|
|
|
2021-02-07 14:52:04 +01:00
|
|
|
|
tll_foreach(term->normal.sixel_images, it) {
|
2020-03-13 18:44:23 +01:00
|
|
|
|
sixel_destroy(&it->item);
|
2021-02-07 14:52:04 +01:00
|
|
|
|
tll_remove(term->normal.sixel_images, it);
|
|
|
|
|
|
}
|
|
|
|
|
|
tll_foreach(term->alt.sixel_images, it) {
|
2020-02-22 10:47:16 +01:00
|
|
|
|
sixel_destroy(&it->item);
|
2021-02-07 14:52:04 +01:00
|
|
|
|
tll_remove(term->alt.sixel_images, it);
|
|
|
|
|
|
}
|
2020-02-22 10:47:16 +01:00
|
|
|
|
|
2020-12-04 18:39:11 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
|
|
|
|
|
term_ime_enable(term);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-03-14 19:19:10 +01:00
|
|
|
|
term_update_ascii_printer(term);
|
|
|
|
|
|
|
2019-08-01 20:51:11 +02:00
|
|
|
|
if (!hard)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
term->flash.active = false;
|
|
|
|
|
|
term->blink.state = BLINK_ON;
|
2020-10-13 19:28:42 +02:00
|
|
|
|
fdm_del(term->fdm, term->blink.fd); term->blink.fd = -1;
|
2021-04-07 08:07:43 +02:00
|
|
|
|
term->colors.fg = term->conf->colors.fg;
|
|
|
|
|
|
term->colors.bg = term->conf->colors.bg;
|
2021-04-07 19:04:25 +02:00
|
|
|
|
term->colors.alpha = term->conf->colors.alpha;
|
2021-04-07 08:09:40 +02:00
|
|
|
|
term->colors.selection_fg = term->conf->colors.selection_fg;
|
|
|
|
|
|
term->colors.selection_bg = term->conf->colors.selection_bg;
|
|
|
|
|
|
term->colors.use_custom_selection = term->conf->colors.use_custom.selection;
|
2021-04-07 08:07:43 +02:00
|
|
|
|
memcpy(term->colors.table, term->conf->colors.table,
|
|
|
|
|
|
sizeof(term->colors.table));
|
2019-11-30 00:32:06 +01:00
|
|
|
|
term->origin = ORIGIN_ABSOLUTE;
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->normal.cursor.lcf = false;
|
|
|
|
|
|
term->alt.cursor.lcf = false;
|
|
|
|
|
|
term->normal.cursor = (struct cursor){.point = {0, 0}};
|
|
|
|
|
|
term->normal.saved_cursor = (struct cursor){.point = {0, 0}};
|
|
|
|
|
|
term->alt.cursor = (struct cursor){.point = {0, 0}};
|
|
|
|
|
|
term->alt.saved_cursor = (struct cursor){.point = {0, 0}};
|
2020-11-26 18:08:28 +01:00
|
|
|
|
term->cursor_style = term->conf->cursor.style;
|
|
|
|
|
|
term->cursor_blink.decset = false;
|
|
|
|
|
|
term->cursor_blink.deccsusr = term->conf->cursor.blink;
|
|
|
|
|
|
term_cursor_blink_update(term);
|
|
|
|
|
|
term->cursor_color.text = term->conf->cursor.color.text;
|
|
|
|
|
|
term->cursor_color.cursor = term->conf->cursor.color.cursor;
|
2019-08-01 20:51:11 +02:00
|
|
|
|
selection_cancel(term);
|
|
|
|
|
|
term->normal.offset = term->normal.view = 0;
|
|
|
|
|
|
term->alt.offset = term->alt.view = 0;
|
|
|
|
|
|
for (size_t i = 0; i < term->rows; i++) {
|
2020-04-13 11:42:10 +02:00
|
|
|
|
struct row *r = grid_row_and_alloc(&term->normal, i);
|
|
|
|
|
|
erase_line(term, r);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (size_t i = 0; i < term->rows; i++) {
|
|
|
|
|
|
struct row *r = grid_row_and_alloc(&term->alt, i);
|
|
|
|
|
|
erase_line(term, r);
|
2019-08-01 20:51:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
for (size_t i = term->rows; i < term->normal.num_rows; i++) {
|
|
|
|
|
|
grid_row_free(term->normal.rows[i]);
|
|
|
|
|
|
term->normal.rows[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (size_t i = term->rows; i < term->alt.num_rows; i++) {
|
|
|
|
|
|
grid_row_free(term->alt.rows[i]);
|
|
|
|
|
|
term->alt.rows[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
term->normal.cur_row = term->normal.rows[0];
|
|
|
|
|
|
term->alt.cur_row = term->alt.rows[0];
|
|
|
|
|
|
tll_free(term->normal.scroll_damage);
|
|
|
|
|
|
tll_free(term->alt.scroll_damage);
|
2020-05-01 11:56:13 +02:00
|
|
|
|
term->render.last_cursor.row = NULL;
|
2019-08-01 20:51:11 +02:00
|
|
|
|
term->render.was_flashing = false;
|
|
|
|
|
|
term_damage_all(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
static bool
|
2020-02-08 14:09:06 +01:00
|
|
|
|
term_font_size_adjust(struct terminal *term, double amount)
|
|
|
|
|
|
{
|
2020-10-20 21:04:47 +02:00
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
|
|
for (size_t j = 0; j < tll_length(term->conf->fonts[i]); j++) {
|
|
|
|
|
|
double old_pt_size = term->font_sizes[i][j].pt_size;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* To ensure primary and user-configured fallback fonts are
|
|
|
|
|
|
* resizes by the same amount, convert pixel sizes to point
|
|
|
|
|
|
* sizes, and to the adjustment on point sizes only.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (term->font_sizes[i][j].px_size > 0) {
|
|
|
|
|
|
double dpi = term->font_dpi;
|
|
|
|
|
|
old_pt_size = term->font_sizes[i][j].px_size * 72. / dpi;
|
|
|
|
|
|
}
|
2020-04-29 20:09:21 +02:00
|
|
|
|
|
2020-10-20 21:04:47 +02:00
|
|
|
|
term->font_sizes[i][j].pt_size = fmax(old_pt_size + amount, 0);
|
|
|
|
|
|
term->font_sizes[i][j].px_size = -1;
|
2020-07-07 10:44:55 +02:00
|
|
|
|
}
|
2020-02-08 14:09:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-20 15:32:31 +01:00
|
|
|
|
if (term->font_line_height.px >= 0) {
|
|
|
|
|
|
double old_pt_size = term->font_line_height.px > 0
|
|
|
|
|
|
? term->font_line_height.px * 72. / term->font_dpi
|
|
|
|
|
|
: term->font_line_height.pt;
|
|
|
|
|
|
|
|
|
|
|
|
term->font_line_height.px = 0;
|
|
|
|
|
|
term->font_line_height.pt = fmax(old_pt_size + amount, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-04 13:10:56 +02:00
|
|
|
|
return reload_fonts(term);
|
2020-02-08 14:09:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
bool
|
2020-02-08 14:09:06 +01:00
|
|
|
|
term_font_size_increase(struct terminal *term)
|
|
|
|
|
|
{
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
if (!term_font_size_adjust(term, 0.5))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-02-08 14:09:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
bool
|
2020-02-08 14:09:06 +01:00
|
|
|
|
term_font_size_decrease(struct terminal *term)
|
|
|
|
|
|
{
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
if (!term_font_size_adjust(term, -0.5))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-02-08 14:09:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
bool
|
2020-02-08 17:57:50 +01:00
|
|
|
|
term_font_size_reset(struct terminal *term)
|
|
|
|
|
|
{
|
2020-07-07 10:44:55 +02:00
|
|
|
|
return load_fonts_from_conf(term);
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
term_font_dpi_changed(struct terminal *term)
|
|
|
|
|
|
{
|
2020-12-17 12:05:22 +01:00
|
|
|
|
float dpi = get_font_dpi(term);
|
|
|
|
|
|
int scale = get_font_scale(term);
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
|
2020-12-17 12:05:22 +01:00
|
|
|
|
bool was_scaled_using_dpi = font_size_by_dpi(term);
|
|
|
|
|
|
bool will_scale_using_dpi = font_should_size_by_dpi(term, scale);
|
2020-11-17 17:59:31 +01:00
|
|
|
|
|
2020-12-17 12:05:22 +01:00
|
|
|
|
bool need_font_reload =
|
|
|
|
|
|
was_scaled_using_dpi != will_scale_using_dpi ||
|
|
|
|
|
|
(will_scale_using_dpi
|
|
|
|
|
|
? term->font_dpi != dpi
|
|
|
|
|
|
: term->font_scale != scale);
|
|
|
|
|
|
|
|
|
|
|
|
if (need_font_reload) {
|
|
|
|
|
|
LOG_DBG("DPI/scale change: DPI-awareness=%s, "
|
|
|
|
|
|
"DPI: %.2f -> %.2f, scale: %d -> %d, "
|
|
|
|
|
|
"sizing font based on monitor's %s",
|
|
|
|
|
|
term->conf->dpi_aware == DPI_AWARE_AUTO ? "auto" :
|
2020-12-18 17:32:54 +01:00
|
|
|
|
term->conf->dpi_aware == DPI_AWARE_YES ? "yes" : "no",
|
2020-12-17 12:05:22 +01:00
|
|
|
|
term->font_dpi, dpi, term->font_scale, scale,
|
|
|
|
|
|
will_scale_using_dpi ? "DPI" : "scaling factor");
|
2020-11-17 17:59:31 +01:00
|
|
|
|
}
|
term: implement term_font_dpi_changed()
This function reloads the font *if* the DPI has changed. To handle
user run-time adjusted font sizes, we record the number of adjustments
made.
Then, when re-loading the font, we first load the font as specified in
the configuration. Then, we re-apply the size adjustment using
font_size_adjust().
Note that this means we end up loading the fonts twice; first using
the default size (but with adjusted DPI), and then again with the
adjusted size. This can probably be improved upon.
The existing font code has been refactored to avoid code
duplication. For example, term_init() now calls
term_font_dpi_changed() to load the initial fonts, instead of directly
instantiating them.
Finally, the way we calculate the DPI to use has changed: instead of
using the highest DPI of all available outputs, we use the highest DPI
of the output's we're actually mapped on. If we're not mapped at all,
we use the globally highest DPI.
Doing it this way means we usually only have to load the fonts
once. Otherwise, we'd end up using the default DPI of 96 when the
terminal is first instantiated (since it's not mapped at that time).
On a single monitor system, we'll use the globally highest DPI at
first, before being mapped. Then when we get mapped, we re-load the
fonts using the highest mapped DPI. But since they'll be the same,
we can skip actually reloading the fonts.
2020-02-15 19:08:14 +01:00
|
|
|
|
|
2020-12-17 12:05:22 +01:00
|
|
|
|
term->font_dpi = dpi;
|
|
|
|
|
|
term->font_scale = scale;
|
|
|
|
|
|
|
|
|
|
|
|
if (!need_font_reload)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2020-07-07 10:44:55 +02:00
|
|
|
|
return reload_fonts(term);
|
2020-02-08 17:57:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-20 18:37:59 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_font_subpixel_changed(struct terminal *term)
|
|
|
|
|
|
{
|
2020-04-21 19:29:36 +02:00
|
|
|
|
enum fcft_subpixel subpixel = get_font_subpixel(term);
|
2020-04-20 18:37:59 +02:00
|
|
|
|
|
|
|
|
|
|
if (term->font_subpixel == subpixel)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
|
|
|
|
|
static const char *const str[] = {
|
2020-10-13 18:39:36 +02:00
|
|
|
|
[FCFT_SUBPIXEL_DEFAULT] = "default",
|
|
|
|
|
|
[FCFT_SUBPIXEL_NONE] = "disabled",
|
|
|
|
|
|
[FCFT_SUBPIXEL_HORIZONTAL_RGB] = "RGB",
|
|
|
|
|
|
[FCFT_SUBPIXEL_HORIZONTAL_BGR] = "BGR",
|
|
|
|
|
|
[FCFT_SUBPIXEL_VERTICAL_RGB] = "V-RGB",
|
|
|
|
|
|
[FCFT_SUBPIXEL_VERTICAL_BGR] = "V-BGR",
|
2020-04-20 18:37:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("subpixel mode changed: %s -> %s", str[term->font_subpixel], str[subpixel]);
|
|
|
|
|
|
term->font_subpixel = subpixel;
|
|
|
|
|
|
term_damage_view(term);
|
|
|
|
|
|
render_refresh(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-11 09:51:51 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_damage_rows(struct terminal *term, int start, int end)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(start <= end);
|
2019-07-30 18:03:03 +02:00
|
|
|
|
for (int r = start; r <= end; r++) {
|
|
|
|
|
|
struct row *row = grid_row(term->grid, r);
|
|
|
|
|
|
row->dirty = true;
|
|
|
|
|
|
for (int c = 0; c < term->grid->num_cols; c++)
|
|
|
|
|
|
row->cells[c].attrs.clean = 0;
|
|
|
|
|
|
}
|
2019-07-11 09:51:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_damage_rows_in_view(struct terminal *term, int start, int end)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(start <= end);
|
2019-07-30 18:03:03 +02:00
|
|
|
|
for (int r = start; r <= end; r++) {
|
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, r);
|
|
|
|
|
|
row->dirty = true;
|
|
|
|
|
|
for (int c = 0; c < term->grid->num_cols; c++)
|
|
|
|
|
|
row->cells[c].attrs.clean = 0;
|
|
|
|
|
|
}
|
2019-07-11 09:51:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-29 21:03:28 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_damage_all(struct terminal *term)
|
|
|
|
|
|
{
|
2019-07-30 18:03:03 +02:00
|
|
|
|
term_damage_rows(term, 0, term->rows - 1);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-10 14:32:40 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_damage_view(struct terminal *term)
|
|
|
|
|
|
{
|
2019-07-30 18:03:03 +02:00
|
|
|
|
term_damage_rows_in_view(term, 0, term->rows - 1);
|
2019-07-10 14:32:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-29 10:03:00 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_damage_cursor(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
term->grid->cur_row->cells[term->grid->cursor.point.col].attrs.clean = 0;
|
|
|
|
|
|
term->grid->cur_row->dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_damage_margins(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
term->render.margins = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-29 21:03:28 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_damage_scroll(struct terminal *term, enum damage_type damage_type,
|
|
|
|
|
|
struct scroll_region region, int lines)
|
|
|
|
|
|
{
|
2019-06-29 21:23:36 +02:00
|
|
|
|
if (tll_length(term->grid->scroll_damage) > 0) {
|
|
|
|
|
|
struct damage *dmg = &tll_back(term->grid->scroll_damage);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
|
|
|
|
|
if (dmg->type == damage_type &&
|
2020-04-26 12:47:19 +02:00
|
|
|
|
dmg->region.start == region.start &&
|
|
|
|
|
|
dmg->region.end == region.end)
|
2019-06-29 21:03:28 +02:00
|
|
|
|
{
|
2020-04-26 12:47:19 +02:00
|
|
|
|
dmg->lines += lines;
|
2019-06-29 21:03:28 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
struct damage dmg = {
|
|
|
|
|
|
.type = damage_type,
|
2020-04-26 12:47:19 +02:00
|
|
|
|
.region = region,
|
|
|
|
|
|
.lines = lines,
|
2019-06-29 21:03:28 +02:00
|
|
|
|
};
|
2019-06-29 21:23:36 +02:00
|
|
|
|
tll_push_back(term->grid->scroll_damage, dmg);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_erase(struct terminal *term, const struct coord *start, const struct coord *end)
|
2019-06-29 21:03:28 +02:00
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(start->row <= end->row);
|
|
|
|
|
|
xassert(start->col <= end->col || start->row < end->row);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
|
|
if (start->row == end->row) {
|
|
|
|
|
|
struct row *row = grid_row(term->grid, start->row);
|
|
|
|
|
|
erase_cell_range(term, row, start->col, end->col);
|
2020-06-27 15:29:47 +02:00
|
|
|
|
sixel_overwrite_by_row(term, start->row, start->col, end->col - start->col + 1);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(end->row > start->row);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
|
|
erase_cell_range(
|
|
|
|
|
|
term, grid_row(term->grid, start->row), start->col, term->cols - 1);
|
2020-06-27 15:29:47 +02:00
|
|
|
|
sixel_overwrite_by_row(term, start->row, start->col, term->cols - start->col);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
|
|
for (int r = start->row + 1; r < end->row; r++)
|
|
|
|
|
|
erase_line(term, grid_row(term->grid, r));
|
2020-06-27 15:29:47 +02:00
|
|
|
|
sixel_overwrite_by_rectangle(
|
|
|
|
|
|
term, start->row + 1, 0, end->row - start->row, term->cols);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
|
|
erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col);
|
2020-06-27 15:29:47 +02:00
|
|
|
|
sixel_overwrite_by_row(term, end->row, 0, end->col + 1);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-17 18:52:27 +01:00
|
|
|
|
int
|
|
|
|
|
|
term_row_rel_to_abs(const struct terminal *term, int row)
|
2019-11-05 13:27:37 +01:00
|
|
|
|
{
|
|
|
|
|
|
switch (term->origin) {
|
|
|
|
|
|
case ORIGIN_ABSOLUTE:
|
2019-11-17 18:52:27 +01:00
|
|
|
|
return min(row, term->rows - 1);
|
2019-11-05 13:27:37 +01:00
|
|
|
|
|
2019-11-17 18:52:27 +01:00
|
|
|
|
case ORIGIN_RELATIVE:
|
|
|
|
|
|
return min(row + term->scroll_region.start, term->scroll_region.end - 1);
|
2019-11-05 13:27:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-09 13:52:33 +00:00
|
|
|
|
BUG("Invalid cursor_origin value");
|
2019-11-17 18:52:27 +01:00
|
|
|
|
return -1;
|
2019-11-05 13:27:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-29 21:03:28 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_cursor_to(struct terminal *term, int row, int col)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(row < term->rows);
|
|
|
|
|
|
xassert(col < term->cols);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cursor.lcf = false;
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cursor.point.col = col;
|
|
|
|
|
|
term->grid->cursor.point.row = row;
|
2019-07-02 22:18:25 +02:00
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
|
term->grid->cur_row = grid_row(term->grid, row);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-05 13:27:37 +01:00
|
|
|
|
void
|
|
|
|
|
|
term_cursor_home(struct terminal *term)
|
|
|
|
|
|
{
|
2019-11-17 18:52:27 +01:00
|
|
|
|
term_cursor_to(term, term_row_rel_to_abs(term, 0), 0);
|
2019-11-05 13:27:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-29 21:03:28 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_cursor_left(struct terminal *term, int count)
|
|
|
|
|
|
{
|
2021-04-08 12:58:47 +02:00
|
|
|
|
int move_amount = min(term->grid->cursor.point.col, count);
|
|
|
|
|
|
term->grid->cursor.point.col -= move_amount;
|
|
|
|
|
|
xassert(term->grid->cursor.point.col >= 0);
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cursor.lcf = false;
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_cursor_right(struct terminal *term, int count)
|
|
|
|
|
|
{
|
2020-04-16 18:51:14 +02:00
|
|
|
|
int move_amount = min(term->cols - term->grid->cursor.point.col - 1, count);
|
|
|
|
|
|
term->grid->cursor.point.col += move_amount;
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->grid->cursor.point.col < term->cols);
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cursor.lcf = false;
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_cursor_up(struct terminal *term, int count)
|
|
|
|
|
|
{
|
2019-11-16 12:14:58 +01:00
|
|
|
|
int top = term->origin == ORIGIN_ABSOLUTE ? 0 : term->scroll_region.start;
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->grid->cursor.point.row >= top);
|
2019-11-16 12:14:58 +01:00
|
|
|
|
|
2020-04-16 18:51:14 +02:00
|
|
|
|
int move_amount = min(term->grid->cursor.point.row - top, count);
|
|
|
|
|
|
term_cursor_to(term, term->grid->cursor.point.row - move_amount, term->grid->cursor.point.col);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_cursor_down(struct terminal *term, int count)
|
|
|
|
|
|
{
|
2019-11-16 12:14:58 +01:00
|
|
|
|
int bottom = term->origin == ORIGIN_ABSOLUTE ? term->rows : term->scroll_region.end;
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(bottom >= term->grid->cursor.point.row);
|
2019-11-16 12:14:58 +01:00
|
|
|
|
|
2020-04-16 18:51:14 +02:00
|
|
|
|
int move_amount = min(bottom - term->grid->cursor.point.row - 1, count);
|
|
|
|
|
|
term_cursor_to(term, term->grid->cursor.point.row + move_amount, term->grid->cursor.point.col);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-16 21:31:40 +01:00
|
|
|
|
static bool
|
2020-11-26 18:08:28 +01:00
|
|
|
|
cursor_blink_rearm_timer(struct terminal *term)
|
2019-12-15 15:07:56 +01:00
|
|
|
|
{
|
2020-10-13 19:23:04 +02:00
|
|
|
|
if (term->cursor_blink.fd < 0) {
|
|
|
|
|
|
int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
|
LOG_ERRNO("failed to create cursor blink timer FD");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_cursor_blink, term)) {
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
term->cursor_blink.fd = fd;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-15 15:07:56 +01:00
|
|
|
|
static const struct itimerspec timer = {
|
|
|
|
|
|
.it_value = {.tv_sec = 0, .tv_nsec = 500000000},
|
|
|
|
|
|
.it_interval = {.tv_sec = 0, .tv_nsec = 500000000},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-12-16 21:31:40 +01:00
|
|
|
|
if (timerfd_settime(term->cursor_blink.fd, 0, &timer, NULL) < 0) {
|
2019-12-15 15:07:56 +01:00
|
|
|
|
LOG_ERRNO("failed to arm cursor blink timer");
|
2020-10-13 19:23:04 +02:00
|
|
|
|
fdm_del(term->fdm, term->cursor_blink.fd);
|
|
|
|
|
|
term->cursor_blink.fd = -1;
|
2019-12-16 21:31:40 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-12-15 15:07:56 +01:00
|
|
|
|
|
2019-12-16 21:31:40 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2020-11-26 18:08:28 +01:00
|
|
|
|
cursor_blink_disarm_timer(struct terminal *term)
|
2019-12-16 21:31:40 +01:00
|
|
|
|
{
|
2020-10-13 19:23:04 +02:00
|
|
|
|
fdm_del(term->fdm, term->cursor_blink.fd);
|
|
|
|
|
|
term->cursor_blink.fd = -1;
|
|
|
|
|
|
return true;
|
2019-12-16 21:31:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-11-26 18:08:28 +01:00
|
|
|
|
term_cursor_blink_update(struct terminal *term)
|
2019-12-16 21:31:40 +01:00
|
|
|
|
{
|
2020-11-26 18:08:28 +01:00
|
|
|
|
bool enable = term->cursor_blink.decset || term->cursor_blink.deccsusr;
|
|
|
|
|
|
bool activate = !term->is_shutting_down && enable && term->kbd_focus;
|
2019-12-15 15:07:56 +01:00
|
|
|
|
|
2020-11-26 18:08:28 +01:00
|
|
|
|
LOG_DBG("decset=%d, deccsrusr=%d, focus=%d, shutting-down=%d, enable=%d, activate=%d",
|
|
|
|
|
|
term->cursor_blink.decset, term->cursor_blink.deccsusr,
|
|
|
|
|
|
term->kbd_focus, term->is_shutting_down,
|
|
|
|
|
|
enable, activate);
|
2019-12-16 21:31:40 +01:00
|
|
|
|
|
2020-11-26 18:08:28 +01:00
|
|
|
|
if (activate && term->cursor_blink.fd < 0) {
|
2019-12-19 07:27:41 +01:00
|
|
|
|
term->cursor_blink.state = CURSOR_BLINK_ON;
|
2020-11-26 18:08:28 +01:00
|
|
|
|
cursor_blink_rearm_timer(term);
|
|
|
|
|
|
} else if (!activate && term->cursor_blink.fd >= 0)
|
|
|
|
|
|
cursor_blink_disarm_timer(term);
|
2019-12-15 15:07:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
term: scrolling: hopefully fix all selection/scrolling related crashes
When scrolling, there are a couple of cases where an existing
selection must be canceled because we cannot meaningfully represent it
after scrolling.
These are when the selection is (partly) inside:
* The top scrolling region
* The bottom scrolling region
* The new lines scrolled in. I.e. re-used lines
For the scrolling regions, the real problem is when the selection
crosses the scrolling region boundary; a selection that is completely
inside a scrolling regions _might_ be possible to keep, but we would
need to translate the selection coordinates to the new scrolling
region lines.
For simplicity, we cancel the selection if it touches the scrolling
region. Period.
The last item, newly scrolled in lines is when the selection covers
very old lines and we're now wrapping around the scrollback history.
Then there's a fourth problem case: when the user has started a
selection, but hasn't yet moved the cursor. In this case, we have no
end point.
What's more problematic is that when the user (after scrolling) moves
the cursor, we try to create a huge selection that covers mostly
empty (NULL) rows, causing us to crash.
This can happen e.g. when reverse scrolling in such a way that we wrap
around the scrollback history.
The actual viewport in this case is something like `-n - m`. But the
selection we'll end up trying to create will be `m - (rows - n)`. This
range may very well contain NULL rows.
To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
|
|
|
|
static bool
|
|
|
|
|
|
selection_on_top_region(const struct terminal *term,
|
|
|
|
|
|
struct scroll_region region)
|
|
|
|
|
|
{
|
|
|
|
|
|
return region.start > 0 &&
|
|
|
|
|
|
selection_on_rows(term, 0, region.start - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
selection_on_bottom_region(const struct terminal *term,
|
|
|
|
|
|
struct scroll_region region)
|
|
|
|
|
|
{
|
|
|
|
|
|
return region.end < term->rows &&
|
|
|
|
|
|
selection_on_rows(term, region.end, term->rows - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-29 21:03:28 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_scroll_partial(struct terminal *term, struct scroll_region region, int rows)
|
|
|
|
|
|
{
|
2019-07-10 19:18:36 +02:00
|
|
|
|
LOG_DBG("scroll: rows=%d, region.start=%d, region.end=%d",
|
|
|
|
|
|
rows, region.start, region.end);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
2020-05-19 18:47:38 +02:00
|
|
|
|
/* Verify scroll amount has been clamped */
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(rows <= region.end - region.start);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
term: scrolling: hopefully fix all selection/scrolling related crashes
When scrolling, there are a couple of cases where an existing
selection must be canceled because we cannot meaningfully represent it
after scrolling.
These are when the selection is (partly) inside:
* The top scrolling region
* The bottom scrolling region
* The new lines scrolled in. I.e. re-used lines
For the scrolling regions, the real problem is when the selection
crosses the scrolling region boundary; a selection that is completely
inside a scrolling regions _might_ be possible to keep, but we would
need to translate the selection coordinates to the new scrolling
region lines.
For simplicity, we cancel the selection if it touches the scrolling
region. Period.
The last item, newly scrolled in lines is when the selection covers
very old lines and we're now wrapping around the scrollback history.
Then there's a fourth problem case: when the user has started a
selection, but hasn't yet moved the cursor. In this case, we have no
end point.
What's more problematic is that when the user (after scrolling) moves
the cursor, we try to create a huge selection that covers mostly
empty (NULL) rows, causing us to crash.
This can happen e.g. when reverse scrolling in such a way that we wrap
around the scrollback history.
The actual viewport in this case is something like `-n - m`. But the
selection we'll end up trying to create will be `m - (rows - n)`. This
range may very well contain NULL rows.
To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
|
|
|
|
/* Cancel selections that cannot be scrolled */
|
2020-05-19 18:49:42 +02:00
|
|
|
|
if (unlikely(term->selection.end.row >= 0)) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Selection is (partly) inside either the top or bottom
|
|
|
|
|
|
* scrolling regions, or on (at least one) of the lines
|
|
|
|
|
|
* scrolled in (i.e. re-used lines).
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (selection_on_top_region(term, region) ||
|
|
|
|
|
|
selection_on_bottom_region(term, region) ||
|
|
|
|
|
|
selection_on_rows(term, region.end - rows, region.end - 1))
|
|
|
|
|
|
{
|
term: scrolling: hopefully fix all selection/scrolling related crashes
When scrolling, there are a couple of cases where an existing
selection must be canceled because we cannot meaningfully represent it
after scrolling.
These are when the selection is (partly) inside:
* The top scrolling region
* The bottom scrolling region
* The new lines scrolled in. I.e. re-used lines
For the scrolling regions, the real problem is when the selection
crosses the scrolling region boundary; a selection that is completely
inside a scrolling regions _might_ be possible to keep, but we would
need to translate the selection coordinates to the new scrolling
region lines.
For simplicity, we cancel the selection if it touches the scrolling
region. Period.
The last item, newly scrolled in lines is when the selection covers
very old lines and we're now wrapping around the scrollback history.
Then there's a fourth problem case: when the user has started a
selection, but hasn't yet moved the cursor. In this case, we have no
end point.
What's more problematic is that when the user (after scrolling) moves
the cursor, we try to create a huge selection that covers mostly
empty (NULL) rows, causing us to crash.
This can happen e.g. when reverse scrolling in such a way that we wrap
around the scrollback history.
The actual viewport in this case is something like `-n - m`. But the
selection we'll end up trying to create will be `m - (rows - n)`. This
range may very well contain NULL rows.
To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
|
|
|
|
selection_cancel(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-16 21:27:56 +02:00
|
|
|
|
|
2020-06-29 22:01:02 +02:00
|
|
|
|
sixel_scroll_up(term, rows);
|
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
|
bool view_follows = term->grid->view == term->grid->offset;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
term->grid->offset += rows;
|
2019-08-22 17:33:23 +02:00
|
|
|
|
term->grid->offset &= term->grid->num_rows - 1;
|
2019-07-01 19:20:21 +02:00
|
|
|
|
|
2020-05-19 18:49:42 +02:00
|
|
|
|
if (view_follows) {
|
|
|
|
|
|
selection_view_down(term, term->grid->offset);
|
2019-07-09 16:26:36 +02:00
|
|
|
|
term->grid->view = term->grid->offset;
|
2020-05-19 18:49:42 +02:00
|
|
|
|
}
|
2019-07-09 16:26:36 +02:00
|
|
|
|
|
2019-07-10 19:18:53 +02:00
|
|
|
|
/* Top non-scrolling region. */
|
|
|
|
|
|
for (int i = region.start - 1; i >= 0; i--)
|
2020-05-16 23:43:05 +02:00
|
|
|
|
grid_swap_row(term->grid, i - rows, i);
|
2019-07-10 19:18:53 +02:00
|
|
|
|
|
|
|
|
|
|
/* Bottom non-scrolling region */
|
|
|
|
|
|
for (int i = term->rows - 1; i >= region.end; i--)
|
2020-05-16 23:43:05 +02:00
|
|
|
|
grid_swap_row(term->grid, i - rows, i);
|
2019-07-10 19:18:53 +02:00
|
|
|
|
|
|
|
|
|
|
/* Erase scrolled in lines */
|
2021-02-13 12:31:55 +01:00
|
|
|
|
for (int r = region.end - rows; r < region.end; r++) {
|
|
|
|
|
|
struct row *row = grid_row_and_alloc(term->grid, r);
|
|
|
|
|
|
erase_line(term, row);
|
|
|
|
|
|
}
|
2020-05-16 16:28:32 +02:00
|
|
|
|
|
2019-07-01 12:23:38 +02:00
|
|
|
|
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cur_row = grid_row(term->grid, term->grid->cursor.point.row);
|
2020-05-16 23:53:23 +02:00
|
|
|
|
|
|
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
|
|
for (int r = 0; r < term->rows; r++)
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(grid_row(term->grid, r) != NULL);
|
2020-05-16 23:53:23 +02:00
|
|
|
|
#endif
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_scroll(struct terminal *term, int rows)
|
|
|
|
|
|
{
|
2019-06-29 21:08:08 +02:00
|
|
|
|
term_scroll_partial(term, term->scroll_region, rows);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_scroll_reverse_partial(struct terminal *term,
|
|
|
|
|
|
struct scroll_region region, int rows)
|
|
|
|
|
|
{
|
2019-07-10 19:18:36 +02:00
|
|
|
|
LOG_DBG("scroll reverse: rows=%d, region.start=%d, region.end=%d",
|
|
|
|
|
|
rows, region.start, region.end);
|
|
|
|
|
|
|
2020-05-19 18:47:38 +02:00
|
|
|
|
/* Verify scroll amount has been clamped */
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(rows <= region.end - region.start);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
term: scrolling: hopefully fix all selection/scrolling related crashes
When scrolling, there are a couple of cases where an existing
selection must be canceled because we cannot meaningfully represent it
after scrolling.
These are when the selection is (partly) inside:
* The top scrolling region
* The bottom scrolling region
* The new lines scrolled in. I.e. re-used lines
For the scrolling regions, the real problem is when the selection
crosses the scrolling region boundary; a selection that is completely
inside a scrolling regions _might_ be possible to keep, but we would
need to translate the selection coordinates to the new scrolling
region lines.
For simplicity, we cancel the selection if it touches the scrolling
region. Period.
The last item, newly scrolled in lines is when the selection covers
very old lines and we're now wrapping around the scrollback history.
Then there's a fourth problem case: when the user has started a
selection, but hasn't yet moved the cursor. In this case, we have no
end point.
What's more problematic is that when the user (after scrolling) moves
the cursor, we try to create a huge selection that covers mostly
empty (NULL) rows, causing us to crash.
This can happen e.g. when reverse scrolling in such a way that we wrap
around the scrollback history.
The actual viewport in this case is something like `-n - m`. But the
selection we'll end up trying to create will be `m - (rows - n)`. This
range may very well contain NULL rows.
To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
|
|
|
|
/* Cancel selections that cannot be scrolled */
|
2020-05-19 18:49:42 +02:00
|
|
|
|
if (unlikely(term->selection.end.row >= 0)) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Selection is (partly) inside either the top or bottom
|
|
|
|
|
|
* scrolling regions, or on (at least one) of the lines
|
|
|
|
|
|
* scrolled in (i.e. re-used lines).
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (selection_on_top_region(term, region) ||
|
|
|
|
|
|
selection_on_bottom_region(term, region) ||
|
|
|
|
|
|
selection_on_rows(term, region.start, region.start + rows - 1))
|
|
|
|
|
|
{
|
term: scrolling: hopefully fix all selection/scrolling related crashes
When scrolling, there are a couple of cases where an existing
selection must be canceled because we cannot meaningfully represent it
after scrolling.
These are when the selection is (partly) inside:
* The top scrolling region
* The bottom scrolling region
* The new lines scrolled in. I.e. re-used lines
For the scrolling regions, the real problem is when the selection
crosses the scrolling region boundary; a selection that is completely
inside a scrolling regions _might_ be possible to keep, but we would
need to translate the selection coordinates to the new scrolling
region lines.
For simplicity, we cancel the selection if it touches the scrolling
region. Period.
The last item, newly scrolled in lines is when the selection covers
very old lines and we're now wrapping around the scrollback history.
Then there's a fourth problem case: when the user has started a
selection, but hasn't yet moved the cursor. In this case, we have no
end point.
What's more problematic is that when the user (after scrolling) moves
the cursor, we try to create a huge selection that covers mostly
empty (NULL) rows, causing us to crash.
This can happen e.g. when reverse scrolling in such a way that we wrap
around the scrollback history.
The actual viewport in this case is something like `-n - m`. But the
selection we'll end up trying to create will be `m - (rows - n)`. This
range may very well contain NULL rows.
To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
|
|
|
|
selection_cancel(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-16 21:27:56 +02:00
|
|
|
|
|
2020-06-29 22:01:02 +02:00
|
|
|
|
sixel_scroll_down(term, rows);
|
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
|
bool view_follows = term->grid->view == term->grid->offset;
|
2019-08-22 17:33:23 +02:00
|
|
|
|
term->grid->offset -= rows;
|
|
|
|
|
|
while (term->grid->offset < 0)
|
|
|
|
|
|
term->grid->offset += term->grid->num_rows;
|
|
|
|
|
|
term->grid->offset &= term->grid->num_rows - 1;
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->grid->offset >= 0);
|
|
|
|
|
|
xassert(term->grid->offset < term->grid->num_rows);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
2020-05-19 18:49:42 +02:00
|
|
|
|
if (view_follows) {
|
|
|
|
|
|
selection_view_up(term, term->grid->offset);
|
2019-07-09 16:26:36 +02:00
|
|
|
|
term->grid->view = term->grid->offset;
|
2020-05-19 18:49:42 +02:00
|
|
|
|
}
|
2019-07-09 16:26:36 +02:00
|
|
|
|
|
2019-07-09 09:17:24 +02:00
|
|
|
|
/* Bottom non-scrolling region */
|
2019-07-08 13:57:31 +02:00
|
|
|
|
for (int i = region.end + rows; i < term->rows + rows; i++)
|
2020-05-16 23:43:05 +02:00
|
|
|
|
grid_swap_row(term->grid, i, i - rows);
|
2019-07-09 09:17:24 +02:00
|
|
|
|
|
|
|
|
|
|
/* Top non-scrolling region */
|
2019-07-08 13:57:31 +02:00
|
|
|
|
for (int i = 0 + rows; i < region.start + rows; i++)
|
2020-05-16 23:43:05 +02:00
|
|
|
|
grid_swap_row(term->grid, i, i - rows);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
|
2019-07-10 19:18:53 +02:00
|
|
|
|
/* Erase scrolled in lines */
|
2021-02-13 12:31:55 +01:00
|
|
|
|
for (int r = region.start; r < region.start + rows; r++) {
|
|
|
|
|
|
struct row *row = grid_row_and_alloc(term->grid, r);
|
|
|
|
|
|
erase_line(term, row);
|
|
|
|
|
|
}
|
2020-05-16 16:28:32 +02:00
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
|
term_damage_scroll(term, DAMAGE_SCROLL_REVERSE, region, rows);
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cur_row = grid_row(term->grid, term->grid->cursor.point.row);
|
2020-05-16 23:53:23 +02:00
|
|
|
|
|
|
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
|
|
for (int r = 0; r < term->rows; r++)
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(grid_row(term->grid, r) != NULL);
|
2020-05-16 23:53:23 +02:00
|
|
|
|
#endif
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_scroll_reverse(struct terminal *term, int rows)
|
|
|
|
|
|
{
|
2019-06-29 21:08:08 +02:00
|
|
|
|
term_scroll_reverse_partial(term, term->scroll_region, rows);
|
2019-06-29 21:03:28 +02:00
|
|
|
|
}
|
2019-07-05 14:24:51 +02:00
|
|
|
|
|
2020-02-10 21:52:14 +01:00
|
|
|
|
void
|
2020-07-14 09:29:10 +02:00
|
|
|
|
term_carriage_return(struct terminal *term)
|
2020-02-10 21:52:14 +01:00
|
|
|
|
{
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term_cursor_left(term, term->grid->cursor.point.col);
|
2020-02-10 21:52:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-10 16:02:03 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_linefeed(struct terminal *term)
|
|
|
|
|
|
{
|
2020-02-14 22:39:26 +01:00
|
|
|
|
term->grid->cur_row->linebreak = true;
|
2020-07-14 10:49:44 +02:00
|
|
|
|
term->grid->cursor.lcf = false;
|
|
|
|
|
|
|
2020-04-16 18:51:14 +02:00
|
|
|
|
if (term->grid->cursor.point.row == term->scroll_region.end - 1)
|
2019-07-10 16:02:03 +02:00
|
|
|
|
term_scroll(term, 1);
|
|
|
|
|
|
else
|
|
|
|
|
|
term_cursor_down(term, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_reverse_index(struct terminal *term)
|
|
|
|
|
|
{
|
2020-04-16 18:51:14 +02:00
|
|
|
|
if (term->grid->cursor.point.row == term->scroll_region.start)
|
2019-07-10 16:02:03 +02:00
|
|
|
|
term_scroll_reverse(term, 1);
|
|
|
|
|
|
else
|
|
|
|
|
|
term_cursor_up(term, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-28 17:25:42 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_reset_view(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
term->grid->view = term->grid->offset;
|
|
|
|
|
|
term_damage_view(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-15 17:08:30 +01:00
|
|
|
|
void
|
|
|
|
|
|
term_save_cursor(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
term->grid->saved_cursor = term->grid->cursor;
|
|
|
|
|
|
term->vt.saved_attrs = term->vt.attrs;
|
|
|
|
|
|
term->saved_charsets = term->charsets;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-23 17:57:07 +02:00
|
|
|
|
void
|
2020-03-16 12:00:25 +01:00
|
|
|
|
term_restore_cursor(struct terminal *term, const struct cursor *cursor)
|
2019-07-23 17:57:07 +02:00
|
|
|
|
{
|
2020-03-16 12:00:25 +01:00
|
|
|
|
int row = min(cursor->point.row, term->rows - 1);
|
|
|
|
|
|
int col = min(cursor->point.col, term->cols - 1);
|
2021-01-15 17:08:30 +01:00
|
|
|
|
|
2019-07-23 17:57:07 +02:00
|
|
|
|
term_cursor_to(term, row, col);
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cursor.lcf = cursor->lcf;
|
2021-01-15 17:08:30 +01:00
|
|
|
|
|
|
|
|
|
|
term->vt.attrs = term->vt.saved_attrs;
|
|
|
|
|
|
term->charsets = term->saved_charsets;
|
2021-03-14 19:19:10 +01:00
|
|
|
|
term_update_ascii_printer(term);
|
2019-07-23 17:57:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-16 10:34:08 +02:00
|
|
|
|
void
|
2020-01-02 19:35:32 +01:00
|
|
|
|
term_visual_focus_in(struct terminal *term)
|
2019-07-16 10:34:08 +02:00
|
|
|
|
{
|
2020-01-03 11:19:56 +01:00
|
|
|
|
if (term->visual_focus)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-01-02 19:35:32 +01:00
|
|
|
|
term->visual_focus = true;
|
2020-11-26 18:08:28 +01:00
|
|
|
|
term_cursor_blink_update(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
|
render_refresh_csd(term);
|
2019-07-16 10:34:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-01-02 19:35:32 +01:00
|
|
|
|
term_visual_focus_out(struct terminal *term)
|
2019-07-16 10:34:08 +02:00
|
|
|
|
{
|
2020-01-03 11:19:56 +01:00
|
|
|
|
if (!term->visual_focus)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-01-02 19:35:32 +01:00
|
|
|
|
term->visual_focus = false;
|
2020-11-26 18:08:28 +01:00
|
|
|
|
term_cursor_blink_update(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
|
render_refresh_csd(term);
|
2020-01-02 19:35:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_kbd_focus_in(struct terminal *term)
|
|
|
|
|
|
{
|
2020-07-11 09:04:46 +02:00
|
|
|
|
if (term->kbd_focus)
|
2020-07-09 09:16:54 +02:00
|
|
|
|
return;
|
2020-07-09 08:46:25 +02:00
|
|
|
|
|
2020-07-11 09:04:46 +02:00
|
|
|
|
term->kbd_focus = true;
|
2020-10-08 19:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
if (term->render.urgency) {
|
|
|
|
|
|
term->render.urgency = false;
|
|
|
|
|
|
term_damage_margins(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-11 11:14:32 +02:00
|
|
|
|
cursor_refresh(term);
|
2020-07-11 09:04:46 +02:00
|
|
|
|
|
2019-12-16 21:33:22 +01:00
|
|
|
|
if (term->focus_events)
|
2020-01-02 19:35:32 +01:00
|
|
|
|
term_to_slave(term, "\033[I", 3);
|
|
|
|
|
|
}
|
2019-12-16 21:33:22 +01:00
|
|
|
|
|
2020-01-02 19:35:32 +01:00
|
|
|
|
void
|
|
|
|
|
|
term_kbd_focus_out(struct terminal *term)
|
|
|
|
|
|
{
|
2020-07-11 09:04:46 +02:00
|
|
|
|
if (!term->kbd_focus)
|
2020-07-09 09:16:54 +02:00
|
|
|
|
return;
|
2020-07-09 08:46:25 +02:00
|
|
|
|
|
2020-07-11 09:04:46 +02:00
|
|
|
|
tll_foreach(term->wl->seats, it)
|
|
|
|
|
|
if (it->item.kbd_focus == term)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-12-03 18:36:56 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (term_ime_reset(term))
|
2020-12-02 18:52:50 +01:00
|
|
|
|
render_refresh(term);
|
2020-12-03 18:36:56 +01:00
|
|
|
|
#endif
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
2020-07-11 09:04:46 +02:00
|
|
|
|
term->kbd_focus = false;
|
2020-07-11 11:14:32 +02:00
|
|
|
|
cursor_refresh(term);
|
2020-07-11 09:04:46 +02:00
|
|
|
|
|
2020-01-02 19:35:32 +01:00
|
|
|
|
if (term->focus_events)
|
|
|
|
|
|
term_to_slave(term, "\033[O", 3);
|
2019-07-16 10:34:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 14:24:51 +02:00
|
|
|
|
static int
|
|
|
|
|
|
linux_mouse_button_to_x(int button)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (button) {
|
|
|
|
|
|
case BTN_LEFT: return 1;
|
|
|
|
|
|
case BTN_MIDDLE: return 2;
|
2019-08-05 18:59:12 +02:00
|
|
|
|
case BTN_RIGHT: return 3;
|
2019-08-05 18:32:35 +02:00
|
|
|
|
case BTN_BACK: return 4;
|
|
|
|
|
|
case BTN_FORWARD: return 5;
|
2019-08-05 18:59:12 +02:00
|
|
|
|
case BTN_SIDE: return 8;
|
|
|
|
|
|
case BTN_EXTRA: return 9;
|
2019-07-05 14:24:51 +02:00
|
|
|
|
case BTN_TASK: return -1; /* TODO: ??? */
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
LOG_WARN("unrecognized mouse button: %d (0x%x)", button, button);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-08 18:16:43 +02:00
|
|
|
|
|
2019-07-05 14:24:51 +02:00
|
|
|
|
static int
|
|
|
|
|
|
encode_xbutton(int xbutton)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (xbutton) {
|
|
|
|
|
|
case 1: case 2: case 3:
|
|
|
|
|
|
return xbutton - 1;
|
|
|
|
|
|
|
2021-01-22 17:03:43 +01:00
|
|
|
|
case 4: case 5: case 6: case 7:
|
2019-07-05 14:24:51 +02:00
|
|
|
|
/* Like button 1 and 2, but with 64 added */
|
|
|
|
|
|
return xbutton - 4 + 64;
|
|
|
|
|
|
|
|
|
|
|
|
case 8: case 9: case 10: case 11:
|
|
|
|
|
|
/* Similar to 4 and 5, but adding 128 instead of 64 */
|
|
|
|
|
|
return xbutton - 8 + 128;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
LOG_ERR("cannot encode X mouse button: %d", xbutton);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-08 18:16:43 +02:00
|
|
|
|
|
2019-07-05 14:24:51 +02:00
|
|
|
|
static void
|
2019-07-05 15:13:06 +02:00
|
|
|
|
report_mouse_click(struct terminal *term, int encoded_button, int row, int col,
|
|
|
|
|
|
bool release)
|
|
|
|
|
|
{
|
2019-07-05 19:40:52 +02:00
|
|
|
|
char response[128];
|
|
|
|
|
|
|
2019-07-05 15:29:16 +02:00
|
|
|
|
switch (term->mouse_reporting) {
|
2019-11-18 11:31:21 +01:00
|
|
|
|
case MOUSE_NORMAL: {
|
|
|
|
|
|
int encoded_col = 32 + col + 1;
|
|
|
|
|
|
int encoded_row = 32 + row + 1;
|
|
|
|
|
|
if (encoded_col > 255 || encoded_row > 255)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2019-07-05 15:29:16 +02:00
|
|
|
|
snprintf(response, sizeof(response), "\033[M%c%c%c",
|
2019-11-18 11:31:21 +01:00
|
|
|
|
32 + (release ? 3 : encoded_button), encoded_col, encoded_row);
|
2019-07-05 15:29:16 +02:00
|
|
|
|
break;
|
2019-11-18 11:31:21 +01:00
|
|
|
|
}
|
2019-07-05 15:29:16 +02:00
|
|
|
|
|
2019-07-05 19:40:52 +02:00
|
|
|
|
case MOUSE_SGR:
|
2019-07-05 15:29:16 +02:00
|
|
|
|
snprintf(response, sizeof(response), "\033[<%d;%d;%d%c",
|
|
|
|
|
|
encoded_button, col + 1, row + 1, release ? 'm' : 'M');
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MOUSE_URXVT:
|
2019-07-05 19:40:52 +02:00
|
|
|
|
snprintf(response, sizeof(response), "\033[%d;%d;%dM",
|
|
|
|
|
|
32 + (release ? 3 : encoded_button), col + 1, row + 1);
|
2019-07-05 15:29:16 +02:00
|
|
|
|
break;
|
2019-07-05 19:40:52 +02:00
|
|
|
|
|
|
|
|
|
|
case MOUSE_UTF8:
|
|
|
|
|
|
/* Unimplemented */
|
|
|
|
|
|
return;
|
2019-07-05 15:29:16 +02:00
|
|
|
|
}
|
2019-07-05 19:40:52 +02:00
|
|
|
|
|
2019-11-03 00:27:39 +01:00
|
|
|
|
term_to_slave(term, response, strlen(response));
|
2019-07-05 15:13:06 +02:00
|
|
|
|
}
|
2020-07-08 18:16:43 +02:00
|
|
|
|
|
2019-07-05 15:13:06 +02:00
|
|
|
|
static void
|
|
|
|
|
|
report_mouse_motion(struct terminal *term, int encoded_button, int row, int col)
|
|
|
|
|
|
{
|
|
|
|
|
|
report_mouse_click(term, encoded_button, row, col, false);
|
|
|
|
|
|
}
|
2020-07-08 18:16:43 +02:00
|
|
|
|
|
2019-11-30 17:06:15 +01:00
|
|
|
|
bool
|
2020-07-09 09:52:11 +02:00
|
|
|
|
term_mouse_grabbed(const struct terminal *term, struct seat *seat)
|
2019-11-30 17:06:15 +01:00
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Mouse is grabbed by us, regardless of whether mouse tracking has been enabled or not.
|
|
|
|
|
|
*/
|
2021-02-02 09:51:22 +01:00
|
|
|
|
return term->mouse_tracking == MOUSE_NONE ||
|
|
|
|
|
|
(seat->kbd_focus == term &&
|
|
|
|
|
|
seat->kbd.shift &&
|
|
|
|
|
|
!seat->kbd.alt && /*!seat->kbd.ctrl &&*/ !seat->kbd.meta);
|
2019-11-30 17:06:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 15:13:06 +02:00
|
|
|
|
void
|
2020-07-08 18:16:43 +02:00
|
|
|
|
term_mouse_down(struct terminal *term, int button, int row, int col,
|
|
|
|
|
|
bool _shift, bool _alt, bool _ctrl)
|
2019-07-05 14:24:51 +02:00
|
|
|
|
{
|
|
|
|
|
|
/* Map libevent button event code to X button number */
|
|
|
|
|
|
int xbutton = linux_mouse_button_to_x(button);
|
|
|
|
|
|
if (xbutton == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2019-07-05 15:13:06 +02:00
|
|
|
|
int encoded = encode_xbutton(xbutton);
|
2019-07-05 14:24:51 +02:00
|
|
|
|
if (encoded == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2019-11-30 17:11:00 +01:00
|
|
|
|
|
2020-07-11 09:06:20 +02:00
|
|
|
|
bool has_focus = term->kbd_focus;
|
2020-07-08 18:16:43 +02:00
|
|
|
|
bool shift = has_focus ? _shift : false;
|
|
|
|
|
|
bool alt = has_focus ? _alt : false;
|
|
|
|
|
|
bool ctrl = has_focus ? _ctrl : false;
|
2019-11-30 17:11:00 +01:00
|
|
|
|
|
2019-07-05 14:24:51 +02:00
|
|
|
|
encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
|
|
|
|
|
|
|
|
|
|
|
|
switch (term->mouse_tracking) {
|
|
|
|
|
|
case MOUSE_NONE:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MOUSE_CLICK:
|
|
|
|
|
|
case MOUSE_DRAG:
|
|
|
|
|
|
case MOUSE_MOTION:
|
2019-07-05 15:13:06 +02:00
|
|
|
|
report_mouse_click(term, encoded, row, col, false);
|
2019-07-05 14:24:51 +02:00
|
|
|
|
break;
|
2019-11-18 11:18:48 +01:00
|
|
|
|
|
|
|
|
|
|
case MOUSE_X10:
|
|
|
|
|
|
/* Never enabled */
|
2021-02-09 13:52:33 +00:00
|
|
|
|
BUG("X10 mouse mode not implemented");
|
2019-11-18 11:18:48 +01:00
|
|
|
|
break;
|
2019-07-05 14:24:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-07-08 18:16:43 +02:00
|
|
|
|
term_mouse_up(struct terminal *term, int button, int row, int col,
|
|
|
|
|
|
bool _shift, bool _alt, bool _ctrl)
|
2019-07-05 14:24:51 +02:00
|
|
|
|
{
|
2019-07-05 15:13:06 +02:00
|
|
|
|
/* Map libevent button event code to X button number */
|
|
|
|
|
|
int xbutton = linux_mouse_button_to_x(button);
|
|
|
|
|
|
if (xbutton == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (xbutton == 4 || xbutton == 5) {
|
|
|
|
|
|
/* No release events for scroll buttons */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 15:29:16 +02:00
|
|
|
|
int encoded = encode_xbutton(xbutton);
|
|
|
|
|
|
if (encoded == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-07-11 09:06:20 +02:00
|
|
|
|
bool has_focus = term->kbd_focus;
|
2020-07-08 18:16:43 +02:00
|
|
|
|
bool shift = has_focus ? _shift : false;
|
|
|
|
|
|
bool alt = has_focus ? _alt : false;
|
|
|
|
|
|
bool ctrl = has_focus ? _ctrl : false;
|
2019-11-30 17:11:00 +01:00
|
|
|
|
|
2019-07-05 15:13:06 +02:00
|
|
|
|
encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
|
|
|
|
|
|
|
2019-07-05 14:24:51 +02:00
|
|
|
|
switch (term->mouse_tracking) {
|
|
|
|
|
|
case MOUSE_NONE:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MOUSE_CLICK:
|
|
|
|
|
|
case MOUSE_DRAG:
|
|
|
|
|
|
case MOUSE_MOTION:
|
2019-07-05 15:13:06 +02:00
|
|
|
|
report_mouse_click(term, encoded, row, col, true);
|
|
|
|
|
|
break;
|
2019-11-18 11:18:48 +01:00
|
|
|
|
|
|
|
|
|
|
case MOUSE_X10:
|
|
|
|
|
|
/* Never enabled */
|
2021-02-09 13:52:33 +00:00
|
|
|
|
BUG("X10 mouse mode not implemented");
|
2019-11-18 11:18:48 +01:00
|
|
|
|
break;
|
2019-07-05 15:13:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-07-08 18:16:43 +02:00
|
|
|
|
term_mouse_motion(struct terminal *term, int button, int row, int col,
|
|
|
|
|
|
bool _shift, bool _alt, bool _ctrl)
|
2019-07-05 15:13:06 +02:00
|
|
|
|
{
|
|
|
|
|
|
int encoded = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (button != 0) {
|
|
|
|
|
|
/* Map libevent button event code to X button number */
|
|
|
|
|
|
int xbutton = linux_mouse_button_to_x(button);
|
|
|
|
|
|
if (xbutton == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
encoded = encode_xbutton(xbutton);
|
|
|
|
|
|
if (encoded == -1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else
|
|
|
|
|
|
encoded = 3; /* "released" */
|
|
|
|
|
|
|
2020-07-11 09:06:20 +02:00
|
|
|
|
bool has_focus = term->kbd_focus;
|
2020-07-08 18:16:43 +02:00
|
|
|
|
bool shift = has_focus ? _shift : false;
|
|
|
|
|
|
bool alt = has_focus ? _alt : false;
|
|
|
|
|
|
bool ctrl = has_focus ? _ctrl : false;
|
2019-11-30 17:11:00 +01:00
|
|
|
|
|
2019-07-05 15:13:06 +02:00
|
|
|
|
encoded += 32; /* Motion event */
|
|
|
|
|
|
encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
|
|
|
|
|
|
|
|
|
|
|
|
switch (term->mouse_tracking) {
|
|
|
|
|
|
case MOUSE_NONE:
|
|
|
|
|
|
case MOUSE_CLICK:
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
case MOUSE_DRAG:
|
|
|
|
|
|
if (button == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
|
|
|
|
case MOUSE_MOTION:
|
|
|
|
|
|
report_mouse_motion(term, encoded, row, col);
|
2019-07-05 14:24:51 +02:00
|
|
|
|
break;
|
2019-11-18 11:18:48 +01:00
|
|
|
|
|
|
|
|
|
|
case MOUSE_X10:
|
|
|
|
|
|
/* Never enabled */
|
2021-02-09 13:52:33 +00:00
|
|
|
|
BUG("X10 mouse mode not implemented");
|
2019-11-18 11:18:48 +01:00
|
|
|
|
break;
|
2019-07-05 14:24:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-07-21 17:35:53 +02:00
|
|
|
|
|
2019-11-28 19:35:47 +01:00
|
|
|
|
void
|
2020-07-31 17:09:06 +02:00
|
|
|
|
term_xcursor_update_for_seat(struct terminal *term, struct seat *seat)
|
2019-11-28 19:35:47 +01:00
|
|
|
|
{
|
2020-07-31 17:09:06 +02:00
|
|
|
|
const char *xcursor
|
|
|
|
|
|
= seat->pointer.hidden ? XCURSOR_HIDDEN
|
|
|
|
|
|
: term->is_searching ? XCURSOR_LEFT_PTR
|
2021-02-02 09:52:22 +01:00
|
|
|
|
: (seat->mouse.col >= 0 &&
|
|
|
|
|
|
seat->mouse.row >= 0 &&
|
|
|
|
|
|
term_mouse_grabbed(term, seat)) ? XCURSOR_TEXT
|
|
|
|
|
|
: term->is_searching ? XCURSOR_TEXT
|
2020-07-31 17:09:06 +02:00
|
|
|
|
: XCURSOR_LEFT_PTR;
|
2019-11-28 19:35:47 +01:00
|
|
|
|
|
2020-07-31 17:09:06 +02:00
|
|
|
|
render_xcursor_set(seat, term, xcursor);
|
|
|
|
|
|
}
|
2020-07-09 09:52:11 +02:00
|
|
|
|
|
2020-07-31 17:09:06 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_xcursor_update(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
tll_foreach(term->wl->seats, it)
|
|
|
|
|
|
term_xcursor_update_for_seat(term, &it->item);
|
2019-11-28 19:35:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-21 17:35:53 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_set_window_title(struct terminal *term, const char *title)
|
|
|
|
|
|
{
|
|
|
|
|
|
free(term->window_title);
|
2020-08-08 20:34:30 +01:00
|
|
|
|
term->window_title = xstrdup(title);
|
2020-03-25 18:23:55 +01:00
|
|
|
|
render_refresh_title(term);
|
2019-07-21 17:35:53 +02:00
|
|
|
|
}
|
2019-07-30 22:06:02 +02:00
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_flash(struct terminal *term, unsigned duration_ms)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_DBG("FLASH for %ums", duration_ms);
|
|
|
|
|
|
|
|
|
|
|
|
struct itimerspec alarm = {
|
|
|
|
|
|
.it_value = {.tv_sec = 0, .tv_nsec = duration_ms * 1000000},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (timerfd_settime(term->flash.fd, 0, &alarm, NULL) < 0)
|
|
|
|
|
|
LOG_ERRNO("failed to arm flash timer");
|
|
|
|
|
|
else {
|
|
|
|
|
|
term->flash.active = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-12-21 15:27:17 +01:00
|
|
|
|
|
2020-10-08 19:55:32 +02:00
|
|
|
|
void
|
|
|
|
|
|
term_bell(struct terminal *term)
|
|
|
|
|
|
{
|
2020-12-10 18:22:48 +01:00
|
|
|
|
if (term->kbd_focus || !term->bell_action_enabled)
|
2020-10-08 19:55:32 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-12-10 18:22:48 +01:00
|
|
|
|
switch (term->conf->bell_action) {
|
|
|
|
|
|
case BELL_ACTION_NONE:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BELL_ACTION_URGENT:
|
|
|
|
|
|
/* There's no 'urgency' hint in Wayland - we just paint the
|
|
|
|
|
|
* margins red */
|
|
|
|
|
|
term->render.urgency = true;
|
|
|
|
|
|
term_damage_margins(term);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BELL_ACTION_NOTIFY:
|
|
|
|
|
|
notify_notify(term, "Bell", "Bell in terminal");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-10-08 19:55:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-21 15:27:17 +01:00
|
|
|
|
bool
|
|
|
|
|
|
term_spawn_new(const struct terminal *term)
|
|
|
|
|
|
{
|
2020-07-15 12:39:10 +02:00
|
|
|
|
return spawn(
|
2020-07-15 13:33:56 +02:00
|
|
|
|
term->reaper, term->cwd, (char *const []){term->foot_exe, NULL},
|
|
|
|
|
|
-1, -1, -1);
|
2019-12-21 15:27:17 +01:00
|
|
|
|
}
|
2020-01-12 12:43:28 +01:00
|
|
|
|
|
|
|
|
|
|
void
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term_enable_app_sync_updates(struct terminal *term)
|
2020-01-12 12:43:28 +01:00
|
|
|
|
{
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term->render.app_sync_updates.enabled = true;
|
2020-01-12 12:43:28 +01:00
|
|
|
|
|
|
|
|
|
|
if (timerfd_settime(
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term->render.app_sync_updates.timer_fd, 0,
|
2020-01-12 12:43:28 +01:00
|
|
|
|
&(struct itimerspec){.it_value = {.tv_sec = 1}}, NULL) < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_ERR("failed to arm timer for application synchronized updates");
|
|
|
|
|
|
}
|
2020-01-12 12:45:34 +01:00
|
|
|
|
|
2020-12-14 19:05:03 +01:00
|
|
|
|
/* Disable pending refresh *iff* the grid is the *only* thing
|
|
|
|
|
|
* scheduled to be re-rendered */
|
|
|
|
|
|
if (!term->render.refresh.csd && !term->render.refresh.search &&
|
|
|
|
|
|
!term->render.refresh.title &&
|
|
|
|
|
|
!term->render.pending.csd && !term->render.pending.search &&
|
|
|
|
|
|
!term->render.pending.title)
|
|
|
|
|
|
{
|
|
|
|
|
|
term->render.refresh.grid = false;
|
|
|
|
|
|
term->render.pending.grid = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-12 12:45:34 +01:00
|
|
|
|
/* Disarm delayed rendering timers */
|
|
|
|
|
|
timerfd_settime(
|
|
|
|
|
|
term->delayed_render_timer.lower_fd, 0,
|
2020-08-23 07:42:20 +02:00
|
|
|
|
&(struct itimerspec){{0}}, NULL);
|
2020-01-12 12:45:34 +01:00
|
|
|
|
timerfd_settime(
|
|
|
|
|
|
term->delayed_render_timer.upper_fd, 0,
|
2020-08-23 07:42:20 +02:00
|
|
|
|
&(struct itimerspec){{0}}, NULL);
|
2020-03-25 18:24:58 +01:00
|
|
|
|
term->delayed_render_timer.is_armed = false;
|
2020-01-12 12:43:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term_disable_app_sync_updates(struct terminal *term)
|
2020-01-12 12:43:28 +01:00
|
|
|
|
{
|
2020-01-12 12:55:19 +01:00
|
|
|
|
if (!term->render.app_sync_updates.enabled)
|
2020-01-12 12:43:28 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term->render.app_sync_updates.enabled = false;
|
2020-03-16 17:05:44 +01:00
|
|
|
|
render_refresh(term);
|
2020-01-12 12:43:28 +01:00
|
|
|
|
|
|
|
|
|
|
/* Reset timers */
|
|
|
|
|
|
timerfd_settime(
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term->render.app_sync_updates.timer_fd, 0,
|
2020-08-23 07:42:20 +02:00
|
|
|
|
&(struct itimerspec){{0}}, NULL);
|
2020-01-12 12:43:28 +01:00
|
|
|
|
}
|
2020-01-20 18:34:32 +01:00
|
|
|
|
|
|
|
|
|
|
static inline void
|
2020-05-09 12:04:55 +02:00
|
|
|
|
print_linewrap(struct terminal *term)
|
2020-01-20 18:34:32 +01:00
|
|
|
|
{
|
2020-05-09 12:04:55 +02:00
|
|
|
|
if (likely(!term->grid->cursor.lcf)) {
|
2020-01-20 18:34:32 +01:00
|
|
|
|
/* Not and end of line */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!term->auto_margin)) {
|
|
|
|
|
|
/* Auto-wrap disabled */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-14 11:25:06 +02:00
|
|
|
|
term->grid->cursor.lcf = false;
|
2020-07-16 08:47:37 +02:00
|
|
|
|
|
|
|
|
|
|
const int row = term->grid->cursor.point.row;
|
|
|
|
|
|
|
|
|
|
|
|
if (row == term->scroll_region.end - 1)
|
2020-01-20 18:34:32 +01:00
|
|
|
|
term_scroll(term, 1);
|
2020-07-14 11:25:06 +02:00
|
|
|
|
else {
|
2020-07-16 08:47:37 +02:00
|
|
|
|
const int new_row = min(row + 1, term->rows - 1);
|
|
|
|
|
|
term->grid->cursor.point.row = new_row;
|
|
|
|
|
|
term->grid->cur_row = grid_row(term->grid, new_row);
|
2020-07-14 11:25:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
term->grid->cursor.point.col = 0;
|
2020-01-20 18:34:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
|
print_insert(struct terminal *term, int width)
|
|
|
|
|
|
{
|
2020-06-09 17:31:28 +02:00
|
|
|
|
if (likely(!term->insert_mode))
|
|
|
|
|
|
return;
|
2020-01-20 18:34:32 +01:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(width > 0);
|
2020-07-14 10:50:38 +02:00
|
|
|
|
|
2020-06-09 17:31:28 +02:00
|
|
|
|
struct row *row = term->grid->cur_row;
|
|
|
|
|
|
const size_t move_count = max(0, term->cols - term->grid->cursor.point.col - width);
|
2020-01-20 18:34:32 +01:00
|
|
|
|
|
2020-06-09 17:31:28 +02:00
|
|
|
|
memmove(
|
|
|
|
|
|
&row->cells[term->grid->cursor.point.col + width],
|
|
|
|
|
|
&row->cells[term->grid->cursor.point.col],
|
|
|
|
|
|
move_count * sizeof(struct cell));
|
|
|
|
|
|
|
|
|
|
|
|
/* Mark moved cells as dirty */
|
|
|
|
|
|
for (size_t i = term->grid->cursor.point.col + width; i < term->cols; i++)
|
|
|
|
|
|
row->cells[i].attrs.clean = 0;
|
2020-01-20 18:34:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-14 20:24:52 +02:00
|
|
|
|
static void
|
|
|
|
|
|
print_spacer(struct terminal *term, int col)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct row *row = term->grid->cur_row;
|
|
|
|
|
|
struct cell *cell = &row->cells[col];
|
|
|
|
|
|
|
|
|
|
|
|
cell->wc = CELL_MULT_COL_SPACER;
|
|
|
|
|
|
cell->attrs = term->vt.attrs;
|
|
|
|
|
|
cell->attrs.clean = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-20 18:34:32 +01:00
|
|
|
|
void
|
|
|
|
|
|
term_print(struct terminal *term, wchar_t wc, int width)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(width > 0);
|
2020-01-20 18:34:32 +01:00
|
|
|
|
|
2021-03-14 19:19:10 +01:00
|
|
|
|
if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) &&
|
|
|
|
|
|
wc >= 0x60 && wc <= 0x7e)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* 0x60 - 0x7e */
|
|
|
|
|
|
static const wchar_t vt100_0[] = {
|
|
|
|
|
|
L'◆', L'▒', L'␉', L'␌', L'␍', L'␊', L'°', L'±', /* ` - g */
|
|
|
|
|
|
L'', L'␋', L'┘', L'┐', L'┌', L'└', L'┼', L'⎺', /* h - o */
|
|
|
|
|
|
L'⎻', L'─', L'⎼', L'⎽', L'├', L'┤', L'┴', L'┬', /* p - w */
|
|
|
|
|
|
L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
xassert(width == 1);
|
|
|
|
|
|
wc = vt100_0[wc - 0x60];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-14 17:03:20 +02:00
|
|
|
|
print_linewrap(term);
|
|
|
|
|
|
print_insert(term, width);
|
|
|
|
|
|
|
2020-07-15 08:04:51 +02:00
|
|
|
|
if (unlikely(width > 1) && likely(term->auto_margin) &&
|
2020-07-14 11:26:14 +02:00
|
|
|
|
term->grid->cursor.point.col + width > term->cols)
|
|
|
|
|
|
{
|
2020-07-14 10:58:57 +02:00
|
|
|
|
/* Multi-column character that doesn't fit on current line -
|
2020-07-14 16:49:11 +02:00
|
|
|
|
* pad with spacers */
|
2020-07-14 20:24:52 +02:00
|
|
|
|
for (size_t i = term->grid->cursor.point.col; i < term->cols; i++)
|
|
|
|
|
|
print_spacer(term, i);
|
2020-07-14 13:17:50 +02:00
|
|
|
|
|
2020-07-14 16:49:11 +02:00
|
|
|
|
/* And force a line-wrap */
|
|
|
|
|
|
term->grid->cursor.lcf = 1;
|
2020-07-14 17:03:20 +02:00
|
|
|
|
print_linewrap(term);
|
2020-07-14 10:58:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-28 11:01:19 +02:00
|
|
|
|
sixel_overwrite_at_cursor(term, width);
|
2020-02-22 21:35:45 +01:00
|
|
|
|
|
2020-01-22 18:22:15 +01:00
|
|
|
|
/* *Must* get current cell *after* linewrap+insert */
|
|
|
|
|
|
struct row *row = term->grid->cur_row;
|
2020-04-16 18:51:14 +02:00
|
|
|
|
struct cell *cell = &row->cells[term->grid->cursor.point.col];
|
2020-01-22 18:22:15 +01:00
|
|
|
|
|
2020-01-20 18:34:32 +01:00
|
|
|
|
cell->wc = term->vt.last_printed = wc;
|
|
|
|
|
|
cell->attrs = term->vt.attrs;
|
|
|
|
|
|
|
|
|
|
|
|
row->dirty = true;
|
term: term_print(): clear line break flag
The line break flag is used by the text reflow and text
extraction (i.e. copy-paste) logic, to determine whether or not to
insert a newline between two lines.
There’s some amount of heuristics involved in this. For example, the
client application could emit a newline, move the cursor back up, and
print text. What does that mean for us?
Foot’s behavior up until now has been this:
The line break flag is set on the row, when the application emits an
explicit linefeed. The flag is cleared when the line is erased. But
otherwise not.
This meant that emitting a linefeed and then moving the cursor back up
and printing text, did not clear the line break flag. This in turn
meant that text copied always had newlines inserted, even though that
was not the client applications intention.
By clearing the line break flag whenever _anything_ is printed to a
row, the new behavior is, in practice, that the line break flag is
only set on a row if a linefeed was that *last* thing printed to that
row.
Closes #410
2021-03-23 11:02:51 +01:00
|
|
|
|
row->linebreak = false;
|
2020-01-20 18:34:32 +01:00
|
|
|
|
cell->attrs.clean = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Advance cursor the 'additional' columns while dirty:ing the cells */
|
2020-04-16 18:51:14 +02:00
|
|
|
|
for (int i = 1; i < width && term->grid->cursor.point.col < term->cols - 1; i++) {
|
2020-07-14 10:51:22 +02:00
|
|
|
|
term->grid->cursor.point.col++;
|
2020-07-14 20:24:52 +02:00
|
|
|
|
print_spacer(term, term->grid->cursor.point.col);
|
2020-01-20 18:34:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Advance cursor */
|
term: term_print(): assume we’re *not* at the right margin
That is, assume we can, and should, increment the cursor column.
This changes the emitted assembly from:
518fb: 8b 8b f8 05 00 00 mov 0x5f8(%rbx),%ecx
51901: ff c9 dec %ecx
51903: 39 d1 cmp %edx,%ecx
51905: 7e 11 jle 51918 <term_print.constprop.0+0x78>
51907: ff c2 inc %edx
51909: 89 50 10 mov %edx,0x10(%rax)
5190c: 5b pop %rbx
5190d: 5d pop %rbp
5190e: 41 5c pop %r12
51910: c3 ret
51911: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
51918: c6 40 18 01 movb $0x1,0x18(%rax)
5191c: 5b pop %rbx
5191d: 5d pop %rbp
5191e: 41 5c pop %r12
51920: c3 ret
To:
5191c: 41 8d 50 01 lea 0x1(%r8),%edx
51920: 89 50 10 mov %edx,0x10(%rax)
51923: 3b 93 f8 05 00 00 cmp 0x5f8(%rbx),%edx
51929: 0f 8d 21 01 00 00 jge 51a50 <term_print.constprop.0+0x190>
5192f: 5b pop %rbx
51930: 5d pop %rbp
51931: 41 5c pop %r12
51933: c3 ret
...
51a50: c6 40 18 01 movb $0x1,0x18(%rax)
51a54: 44 89 40 10 mov %r8d,0x10(%rax)
51a58: 5b pop %rbx
51a59: 5d pop %rbp
51a5a: 41 5c pop %r12
51a5c: c3 ret
I.e. it cuts the normal path from 10 instructions down to 8. It
increases the "bad" path with one extra instruction.
2021-03-14 20:47:44 +01:00
|
|
|
|
if (unlikely(++term->grid->cursor.point.col >= term->cols)) {
|
2020-04-16 18:51:14 +02:00
|
|
|
|
term->grid->cursor.lcf = true;
|
term: term_print(): assume we’re *not* at the right margin
That is, assume we can, and should, increment the cursor column.
This changes the emitted assembly from:
518fb: 8b 8b f8 05 00 00 mov 0x5f8(%rbx),%ecx
51901: ff c9 dec %ecx
51903: 39 d1 cmp %edx,%ecx
51905: 7e 11 jle 51918 <term_print.constprop.0+0x78>
51907: ff c2 inc %edx
51909: 89 50 10 mov %edx,0x10(%rax)
5190c: 5b pop %rbx
5190d: 5d pop %rbp
5190e: 41 5c pop %r12
51910: c3 ret
51911: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
51918: c6 40 18 01 movb $0x1,0x18(%rax)
5191c: 5b pop %rbx
5191d: 5d pop %rbp
5191e: 41 5c pop %r12
51920: c3 ret
To:
5191c: 41 8d 50 01 lea 0x1(%r8),%edx
51920: 89 50 10 mov %edx,0x10(%rax)
51923: 3b 93 f8 05 00 00 cmp 0x5f8(%rbx),%edx
51929: 0f 8d 21 01 00 00 jge 51a50 <term_print.constprop.0+0x190>
5192f: 5b pop %rbx
51930: 5d pop %rbp
51931: 41 5c pop %r12
51933: c3 ret
...
51a50: c6 40 18 01 movb $0x1,0x18(%rax)
51a54: 44 89 40 10 mov %r8d,0x10(%rax)
51a58: 5b pop %rbx
51a59: 5d pop %rbp
51a5a: 41 5c pop %r12
51a5c: c3 ret
I.e. it cuts the normal path from 10 instructions down to 8. It
increases the "bad" path with one extra instruction.
2021-03-14 20:47:44 +01:00
|
|
|
|
term->grid->cursor.point.col--;
|
|
|
|
|
|
} else
|
|
|
|
|
|
xassert(!term->grid->cursor.lcf);
|
2020-01-20 18:34:32 +01:00
|
|
|
|
}
|
2020-02-24 22:38:35 +01:00
|
|
|
|
|
2021-03-14 19:19:10 +01:00
|
|
|
|
static void
|
|
|
|
|
|
ascii_printer_generic(struct terminal *term, wchar_t wc)
|
|
|
|
|
|
{
|
|
|
|
|
|
term_print(term, wc, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
ascii_printer_fast(struct terminal *term, wchar_t wc)
|
|
|
|
|
|
{
|
|
|
|
|
|
xassert(term->charsets.set[term->charsets.selected] == CHARSET_ASCII);
|
|
|
|
|
|
xassert(!term->insert_mode);
|
|
|
|
|
|
xassert(tll_length(term->grid->sixel_images) == 0);
|
|
|
|
|
|
|
|
|
|
|
|
print_linewrap(term);
|
|
|
|
|
|
|
|
|
|
|
|
/* *Must* get current cell *after* linewrap+insert */
|
|
|
|
|
|
struct row *row = term->grid->cur_row;
|
|
|
|
|
|
struct cell *cell = &row->cells[term->grid->cursor.point.col];
|
|
|
|
|
|
|
|
|
|
|
|
cell->wc = term->vt.last_printed = wc;
|
|
|
|
|
|
cell->attrs = term->vt.attrs;
|
|
|
|
|
|
|
|
|
|
|
|
row->dirty = true;
|
term: term_print(): clear line break flag
The line break flag is used by the text reflow and text
extraction (i.e. copy-paste) logic, to determine whether or not to
insert a newline between two lines.
There’s some amount of heuristics involved in this. For example, the
client application could emit a newline, move the cursor back up, and
print text. What does that mean for us?
Foot’s behavior up until now has been this:
The line break flag is set on the row, when the application emits an
explicit linefeed. The flag is cleared when the line is erased. But
otherwise not.
This meant that emitting a linefeed and then moving the cursor back up
and printing text, did not clear the line break flag. This in turn
meant that text copied always had newlines inserted, even though that
was not the client applications intention.
By clearing the line break flag whenever _anything_ is printed to a
row, the new behavior is, in practice, that the line break flag is
only set on a row if a linefeed was that *last* thing printed to that
row.
Closes #410
2021-03-23 11:02:51 +01:00
|
|
|
|
row->linebreak = false;
|
2021-03-14 19:19:10 +01:00
|
|
|
|
cell->attrs.clean = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Advance cursor */
|
|
|
|
|
|
if (unlikely(++term->grid->cursor.point.col >= term->cols)) {
|
|
|
|
|
|
term->grid->cursor.lcf = true;
|
|
|
|
|
|
term->grid->cursor.point.col--;
|
|
|
|
|
|
} else
|
|
|
|
|
|
xassert(!term->grid->cursor.lcf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_update_ascii_printer(struct terminal *term)
|
|
|
|
|
|
{
|
2021-03-16 12:57:25 +01:00
|
|
|
|
void (*new_printer)(struct terminal *term, wchar_t wc) =
|
2021-03-14 19:19:10 +01:00
|
|
|
|
unlikely(tll_length(term->grid->sixel_images) > 0 ||
|
|
|
|
|
|
term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC ||
|
|
|
|
|
|
term->insert_mode)
|
|
|
|
|
|
? &ascii_printer_generic
|
|
|
|
|
|
: &ascii_printer_fast;
|
2021-03-16 12:57:25 +01:00
|
|
|
|
|
|
|
|
|
|
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
|
|
|
|
|
if (term->ascii_printer != new_printer) {
|
|
|
|
|
|
LOG_DBG("switching ASCII printer %s -> %s",
|
|
|
|
|
|
term->ascii_printer == &ascii_printer_fast ? "fast" : "generic",
|
|
|
|
|
|
new_printer == &ascii_printer_fast ? "fast" : "generic");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
term->ascii_printer = new_printer;
|
2021-03-14 19:19:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-24 22:38:35 +01:00
|
|
|
|
enum term_surface
|
|
|
|
|
|
term_surface_kind(const struct terminal *term, const struct wl_surface *surface)
|
|
|
|
|
|
{
|
2020-08-14 07:35:01 +02:00
|
|
|
|
if (likely(surface == term->window->surface))
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_GRID;
|
2021-02-12 12:00:40 +01:00
|
|
|
|
else if (surface == term->window->search.surf)
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_SEARCH;
|
2021-02-12 12:00:40 +01:00
|
|
|
|
else if (surface == term->window->scrollback_indicator.surf)
|
2020-07-26 12:37:12 +02:00
|
|
|
|
return TERM_SURF_SCROLLBACK_INDICATOR;
|
2021-02-12 12:00:40 +01:00
|
|
|
|
else if (surface == term->window->render_timer.surf)
|
2020-08-14 07:35:01 +02:00
|
|
|
|
return TERM_SURF_RENDER_TIMER;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_TITLE].surf)
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_TITLE;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_LEFT].surf)
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_BORDER_LEFT;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_RIGHT].surf)
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_BORDER_RIGHT;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_TOP].surf)
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_BORDER_TOP;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_BOTTOM].surf)
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_BORDER_BOTTOM;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_MINIMIZE].surf)
|
2020-03-02 20:29:28 +01:00
|
|
|
|
return TERM_SURF_BUTTON_MINIMIZE;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_MAXIMIZE].surf)
|
2020-03-02 20:29:28 +01:00
|
|
|
|
return TERM_SURF_BUTTON_MAXIMIZE;
|
2021-02-12 11:39:25 +01:00
|
|
|
|
else if (surface == term->window->csd.surface[CSD_SURF_CLOSE].surf)
|
2020-03-02 20:29:28 +01:00
|
|
|
|
return TERM_SURF_BUTTON_CLOSE;
|
2021-02-06 11:30:40 +01:00
|
|
|
|
else {
|
|
|
|
|
|
tll_foreach(term->window->urls, it) {
|
2021-02-12 11:31:31 +01:00
|
|
|
|
if (surface == it->item.surf.surf)
|
2021-02-06 11:30:40 +01:00
|
|
|
|
return TERM_SURF_JUMP_LABEL;
|
|
|
|
|
|
}
|
2020-02-24 22:38:35 +01:00
|
|
|
|
return TERM_SURF_NONE;
|
2021-02-06 11:30:40 +01:00
|
|
|
|
}
|
2020-02-24 22:38:35 +01:00
|
|
|
|
}
|
2020-07-15 11:33:37 +02:00
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
rows_to_text(const struct terminal *term, int start, int end,
|
|
|
|
|
|
char **text, size_t *len)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct extraction_context *ctx = extract_begin(SELECTION_NONE);
|
|
|
|
|
|
if (ctx == NULL)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t r = start;
|
|
|
|
|
|
r != ((end + 1) & (term->grid->num_rows - 1));
|
|
|
|
|
|
r = (r + 1) & (term->grid->num_rows - 1))
|
|
|
|
|
|
{
|
|
|
|
|
|
const struct row *row = term->grid->rows[r];
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(row != NULL);
|
2020-07-15 11:33:37 +02:00
|
|
|
|
|
|
|
|
|
|
for (int c = 0; c < term->cols; c++)
|
|
|
|
|
|
if (!extract_one(term, row, &row->cells[c], c, ctx))
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
return extract_finish(ctx, text, len);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
term_scrollback_to_text(const struct terminal *term, char **text, size_t *len)
|
|
|
|
|
|
{
|
|
|
|
|
|
int start = term->grid->offset + term->rows;
|
|
|
|
|
|
int end = term->grid->offset + term->rows - 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* If scrollback isn't full yet, this may be NULL, so scan forward
|
|
|
|
|
|
* until we find the first non-NULL row */
|
|
|
|
|
|
while (term->grid->rows[start] == NULL) {
|
|
|
|
|
|
start++;
|
|
|
|
|
|
start &= term->grid->num_rows - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (end < 0)
|
|
|
|
|
|
end += term->grid->num_rows;
|
|
|
|
|
|
|
|
|
|
|
|
while (term->grid->rows[end] == NULL) {
|
|
|
|
|
|
end--;
|
|
|
|
|
|
if (end < 0)
|
|
|
|
|
|
end += term->grid->num_rows;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return rows_to_text(term, start, end, text, len);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
term_view_to_text(const struct terminal *term, char **text, size_t *len)
|
|
|
|
|
|
{
|
|
|
|
|
|
int start = grid_row_absolute_in_view(term->grid, 0);
|
|
|
|
|
|
int end = grid_row_absolute_in_view(term->grid, term->rows - 1);
|
|
|
|
|
|
return rows_to_text(term, start, end, text, len);
|
|
|
|
|
|
}
|
2020-12-03 18:36:56 +01:00
|
|
|
|
|
2020-12-04 18:39:11 +01:00
|
|
|
|
bool
|
|
|
|
|
|
term_ime_is_enabled(const struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
return term->ime_enabled;
|
2020-12-04 18:39:11 +01:00
|
|
|
|
#else
|
|
|
|
|
|
return false;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-03 18:36:56 +01:00
|
|
|
|
void
|
2020-12-04 18:39:11 +01:00
|
|
|
|
term_ime_enable(struct terminal *term)
|
2020-12-03 18:36:56 +01:00
|
|
|
|
{
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (term->ime_enabled)
|
2020-12-04 18:39:11 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("IME enabled");
|
|
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
term->ime_enabled = true;
|
2020-12-04 18:39:11 +01:00
|
|
|
|
|
2020-12-04 20:08:22 +01:00
|
|
|
|
/* IME is per seat - enable on all seat currently focusing us */
|
2020-12-04 18:39:11 +01:00
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term)
|
|
|
|
|
|
ime_enable(&it->item);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_ime_disable(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (!term->ime_enabled)
|
2020-12-04 18:39:11 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("IME disabled");
|
|
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
term->ime_enabled = false;
|
2020-12-04 18:39:11 +01:00
|
|
|
|
|
2020-12-04 20:33:15 +01:00
|
|
|
|
/* IME is per seat - disable on all seat currently focusing us */
|
2020-12-04 18:39:11 +01:00
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term)
|
|
|
|
|
|
ime_disable(&it->item);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
bool
|
2020-12-04 18:39:11 +01:00
|
|
|
|
term_ime_reset(struct terminal *term)
|
|
|
|
|
|
{
|
2021-03-23 13:03:07 +01:00
|
|
|
|
bool at_least_one_seat_was_reset = false;
|
|
|
|
|
|
|
2020-12-04 18:39:11 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
struct seat *seat = &it->item;
|
|
|
|
|
|
|
|
|
|
|
|
if (seat->kbd_focus != term)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
ime_reset_preedit(seat);
|
|
|
|
|
|
at_least_one_seat_was_reset = true;
|
2020-12-04 18:39:11 +01:00
|
|
|
|
}
|
2020-12-03 18:36:56 +01:00
|
|
|
|
#endif
|
2021-03-23 13:03:07 +01:00
|
|
|
|
|
|
|
|
|
|
return at_least_one_seat_was_reset;
|
2020-12-03 18:36:56 +01:00
|
|
|
|
}
|
2020-12-20 15:01:21 -07:00
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_ime_set_cursor_rect(struct terminal *term, int x, int y, int width,
|
|
|
|
|
|
int height)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
|
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term) {
|
|
|
|
|
|
it->item.ime.cursor_rect.pending.x = x;
|
|
|
|
|
|
it->item.ime.cursor_rect.pending.y = y;
|
|
|
|
|
|
it->item.ime.cursor_rect.pending.width = width;
|
|
|
|
|
|
it->item.ime.cursor_rect.pending.height = height;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
2021-01-31 11:12:07 +01:00
|
|
|
|
|
2021-02-13 12:34:48 +01:00
|
|
|
|
void
|
2021-02-13 13:44:07 +01:00
|
|
|
|
term_osc8_open(struct terminal *term, uint64_t id, const char *uri)
|
2021-02-13 12:34:48 +01:00
|
|
|
|
{
|
2021-02-14 17:12:43 +01:00
|
|
|
|
if (unlikely(term->vt.osc8.begin.row >= 0)) {
|
2021-02-13 12:34:48 +01:00
|
|
|
|
/* It’s valid to switch from one URI to another without
|
|
|
|
|
|
* closing the first one */
|
|
|
|
|
|
term_osc8_close(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
term->vt.osc8.begin = (struct coord){
|
|
|
|
|
|
.col = term->grid->cursor.point.col,
|
|
|
|
|
|
.row = grid_row_absolute(term->grid, term->grid->cursor.point.row),
|
|
|
|
|
|
};
|
2021-02-13 13:44:07 +01:00
|
|
|
|
term->vt.osc8.id = id;
|
2021-02-13 12:34:48 +01:00
|
|
|
|
term->vt.osc8.uri = xstrdup(uri);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
term_osc8_close(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->vt.osc8.begin.row < 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->vt.osc8.uri[0] == '\0')
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
|
|
struct coord start = term->vt.osc8.begin;
|
|
|
|
|
|
struct coord end = (struct coord){
|
|
|
|
|
|
.col = term->grid->cursor.point.col,
|
|
|
|
|
|
.row = grid_row_absolute(term->grid, term->grid->cursor.point.row),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-02-14 17:13:46 +01:00
|
|
|
|
if (start.row == end.row && start.col == end.col) {
|
|
|
|
|
|
/* Zero-length URL, e.g: \E]8;;http://foo\E\\\E]8;;\E\\ */
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-13 14:16:53 +01:00
|
|
|
|
/* end is *inclusive */
|
|
|
|
|
|
if (--end.col < 0) {
|
|
|
|
|
|
end.row--;
|
|
|
|
|
|
end.col = term->cols - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-13 12:34:48 +01:00
|
|
|
|
int r = start.row;
|
|
|
|
|
|
int start_col = start.col;
|
|
|
|
|
|
do {
|
|
|
|
|
|
int end_col = r == end.row ? end.col : term->cols - 1;
|
|
|
|
|
|
|
2021-02-14 21:29:22 +01:00
|
|
|
|
struct row *row = term->grid->rows[r];
|
|
|
|
|
|
|
|
|
|
|
|
switch (term->conf->osc8_underline) {
|
|
|
|
|
|
case OSC8_UNDERLINE_ALWAYS:
|
|
|
|
|
|
for (int c = start_col; c <= end_col; c++)
|
|
|
|
|
|
row->cells[c].attrs.url = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case OSC8_UNDERLINE_URL_MODE:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-13 12:34:48 +01:00
|
|
|
|
struct row_uri_range range = {
|
|
|
|
|
|
.start = start_col,
|
|
|
|
|
|
.end = end_col,
|
2021-02-13 13:44:58 +01:00
|
|
|
|
.id = term->vt.osc8.id,
|
2021-02-13 12:34:48 +01:00
|
|
|
|
.uri = xstrdup(term->vt.osc8.uri),
|
|
|
|
|
|
};
|
2021-02-14 21:29:22 +01:00
|
|
|
|
grid_row_add_uri_range(row, range);
|
2021-02-13 12:34:48 +01:00
|
|
|
|
start_col = 0;
|
|
|
|
|
|
} while (r++ != end.row);
|
|
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
free(term->vt.osc8.uri);
|
2021-02-13 13:44:07 +01:00
|
|
|
|
term->vt.osc8.id = 0;
|
2021-02-13 12:34:48 +01:00
|
|
|
|
term->vt.osc8.uri = NULL;
|
|
|
|
|
|
term->vt.osc8.begin = (struct coord){-1, -1};
|
|
|
|
|
|
}
|