2019-07-05 10:16:56 +02:00
|
|
|
|
#include "render.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2021-02-06 23:03:05 +01:00
|
|
|
|
#include <wctype.h>
|
2021-01-17 16:12:54 +01:00
|
|
|
|
#include <unistd.h>
|
2021-02-10 16:22:36 +01:00
|
|
|
|
#include <signal.h>
|
2019-08-01 20:09:16 +02:00
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
#include <sys/ioctl.h>
|
2019-07-18 09:33:49 +02:00
|
|
|
|
#include <sys/time.h>
|
2019-07-21 20:11:20 +02:00
|
|
|
|
#include <sys/timerfd.h>
|
2021-01-17 16:12:54 +01:00
|
|
|
|
#include <sys/epoll.h>
|
render: set thread name in a portable way
prctl is Linux-only but pthread_setname_np is same as PR_SET_NAME.
Solaris and FreeBSD >= 13 have pthread_setname_np similar to Linux.
DragonFly, OpenBSD, FreeBSD < 13 lack pthread_setname_np but provide
pthread_set_name_np which doesn't return a value. NetBSD requires 3
arguments for pthread_setname_np where the last one is void *.
render.c:8:10: fatal error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
^~~~~~~~~~~~~
render.c:1234:9: error: implicit declaration of function 'prctl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
render.c:1234:15: error: use of undeclared identifier 'PR_SET_NAME'
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
2021-01-19 14:49:43 +00:00
|
|
|
|
#include <pthread.h>
|
2021-02-09 03:12:26 +00:00
|
|
|
|
|
|
|
|
|
|
#include "macros.h"
|
|
|
|
|
|
#if HAS_INCLUDE(<pthread_np.h>)
|
render: set thread name in a portable way
prctl is Linux-only but pthread_setname_np is same as PR_SET_NAME.
Solaris and FreeBSD >= 13 have pthread_setname_np similar to Linux.
DragonFly, OpenBSD, FreeBSD < 13 lack pthread_setname_np but provide
pthread_set_name_np which doesn't return a value. NetBSD requires 3
arguments for pthread_setname_np where the last one is void *.
render.c:8:10: fatal error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
^~~~~~~~~~~~~
render.c:1234:9: error: implicit declaration of function 'prctl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
render.c:1234:15: error: use of undeclared identifier 'PR_SET_NAME'
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
2021-01-19 14:49:43 +00:00
|
|
|
|
#include <pthread_np.h>
|
|
|
|
|
|
#define pthread_setname_np(thread, name) (pthread_set_name_np(thread, name), 0)
|
|
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
|
|
#define pthread_setname_np(thread, name) pthread_setname_np(thread, "%s", (void *)name)
|
|
|
|
|
|
#endif
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2019-07-05 10:44:09 +02:00
|
|
|
|
#include <wayland-cursor.h>
|
2019-07-05 10:16:56 +02:00
|
|
|
|
#include <xdg-shell.h>
|
2019-12-31 15:39:40 +01:00
|
|
|
|
#include <presentation-time.h>
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2019-12-01 14:03:24 +01:00
|
|
|
|
#include <fcft/fcft.h>
|
2019-12-01 13:43:51 +01:00
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
#define LOG_MODULE "render"
|
|
|
|
|
|
#define LOG_ENABLE_DBG 0
|
|
|
|
|
|
#include "log.h"
|
2020-12-26 16:24:16 +01:00
|
|
|
|
#include "box-drawing.h"
|
2020-02-15 18:58:36 +01:00
|
|
|
|
#include "config.h"
|
2019-07-08 13:57:31 +02:00
|
|
|
|
#include "grid.h"
|
2020-11-15 20:05:01 +01:00
|
|
|
|
#include "hsl.h"
|
2021-01-31 11:12:07 +01:00
|
|
|
|
#include "ime.h"
|
2020-03-01 13:06:00 +01:00
|
|
|
|
#include "quirks.h"
|
2020-02-15 18:58:36 +01:00
|
|
|
|
#include "selection.h"
|
|
|
|
|
|
#include "shm.h"
|
2021-01-31 11:12:07 +01:00
|
|
|
|
#include "sixel.h"
|
|
|
|
|
|
#include "url-mode.h"
|
2020-05-01 11:46:24 +02:00
|
|
|
|
#include "util.h"
|
2020-08-08 20:34:30 +01:00
|
|
|
|
#include "xmalloc.h"
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
|
#define TIME_SCROLL_DAMAGE 0
|
|
|
|
|
|
|
2020-01-04 19:49:26 +01:00
|
|
|
|
struct renderer {
|
|
|
|
|
|
struct fdm *fdm;
|
|
|
|
|
|
struct wayland *wayl;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-12-31 15:39:40 +01:00
|
|
|
|
static struct {
|
|
|
|
|
|
size_t total;
|
|
|
|
|
|
size_t zero; /* commits presented in less than one frame interval */
|
|
|
|
|
|
size_t one; /* commits presented in one frame interval */
|
|
|
|
|
|
size_t two; /* commits presented in two or more frame intervals */
|
2020-08-23 07:42:20 +02:00
|
|
|
|
} presentation_statistics = {0};
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
|
static void fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data);
|
2020-01-04 19:49:26 +01:00
|
|
|
|
|
|
|
|
|
|
struct renderer *
|
|
|
|
|
|
render_init(struct fdm *fdm, struct wayland *wayl)
|
|
|
|
|
|
{
|
2020-08-08 20:34:30 +01:00
|
|
|
|
struct renderer *renderer = malloc(sizeof(*renderer));
|
|
|
|
|
|
if (unlikely(renderer == NULL)) {
|
|
|
|
|
|
LOG_ERRNO("malloc() failed");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-04 19:49:26 +01:00
|
|
|
|
*renderer = (struct renderer) {
|
|
|
|
|
|
.fdm = fdm,
|
|
|
|
|
|
.wayl = wayl,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-01-04 23:26:27 +01:00
|
|
|
|
if (!fdm_hook_add(fdm, &fdm_hook_refresh_pending_terminals, renderer,
|
|
|
|
|
|
FDM_HOOK_PRIORITY_NORMAL))
|
|
|
|
|
|
{
|
2020-01-04 19:49:26 +01:00
|
|
|
|
LOG_ERR("failed to register FDM hook");
|
|
|
|
|
|
free(renderer);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return renderer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
render_destroy(struct renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (renderer == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-01-04 23:26:27 +01:00
|
|
|
|
fdm_hook_del(renderer->fdm, &fdm_hook_refresh_pending_terminals,
|
|
|
|
|
|
FDM_HOOK_PRIORITY_NORMAL);
|
2020-01-04 23:41:26 +01:00
|
|
|
|
|
|
|
|
|
|
free(renderer);
|
2020-01-04 19:49:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-03 08:56:47 +00:00
|
|
|
|
static void DESTRUCTOR
|
2019-12-31 15:39:40 +01:00
|
|
|
|
log_presentation_statistics(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (presentation_statistics.total == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
const size_t total = presentation_statistics.total;
|
|
|
|
|
|
LOG_INFO("presentation statistics: zero=%f%%, one=%f%%, two=%f%%",
|
|
|
|
|
|
100. * presentation_statistics.zero / total,
|
|
|
|
|
|
100. * presentation_statistics.one / total,
|
|
|
|
|
|
100. * presentation_statistics.two / total);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
sync_output(void *data,
|
|
|
|
|
|
struct wp_presentation_feedback *wp_presentation_feedback,
|
|
|
|
|
|
struct wl_output *output)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-21 18:51:04 +01:00
|
|
|
|
struct presentation_context {
|
|
|
|
|
|
struct terminal *term;
|
|
|
|
|
|
struct timeval input;
|
|
|
|
|
|
struct timeval commit;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-12-31 15:39:40 +01:00
|
|
|
|
static void
|
|
|
|
|
|
presented(void *data,
|
|
|
|
|
|
struct wp_presentation_feedback *wp_presentation_feedback,
|
|
|
|
|
|
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
|
|
|
|
|
|
uint32_t refresh, uint32_t seq_hi, uint32_t seq_lo, uint32_t flags)
|
|
|
|
|
|
{
|
2020-01-21 18:51:04 +01:00
|
|
|
|
struct presentation_context *ctx = data;
|
|
|
|
|
|
struct terminal *term = ctx->term;
|
|
|
|
|
|
const struct timeval *input = &ctx->input;
|
|
|
|
|
|
const struct timeval *commit = &ctx->commit;
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2020-01-01 11:37:47 +01:00
|
|
|
|
const struct timeval presented = {
|
2019-12-31 15:39:40 +01:00
|
|
|
|
.tv_sec = (uint64_t)tv_sec_hi << 32 | tv_sec_lo,
|
|
|
|
|
|
.tv_usec = tv_nsec / 1000,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-01-21 18:51:04 +01:00
|
|
|
|
bool use_input = (input->tv_sec > 0 || input->tv_usec > 0) &&
|
|
|
|
|
|
timercmp(&presented, input, >);
|
2019-12-31 20:01:47 +01:00
|
|
|
|
char msg[1024];
|
|
|
|
|
|
int chars = 0;
|
|
|
|
|
|
|
2020-01-21 18:51:04 +01:00
|
|
|
|
if (use_input && timercmp(&presented, input, <))
|
2020-01-01 11:37:47 +01:00
|
|
|
|
return;
|
2020-01-21 18:51:04 +01:00
|
|
|
|
else if (timercmp(&presented, commit, <))
|
2020-01-01 11:37:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("commit: %lu s %lu µs, presented: %lu s %lu µs",
|
2020-01-21 18:51:04 +01:00
|
|
|
|
commit->tv_sec, commit->tv_usec, presented.tv_sec, presented.tv_usec);
|
2020-01-01 11:37:47 +01:00
|
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
|
if (use_input) {
|
|
|
|
|
|
struct timeval diff;
|
2020-01-21 18:51:04 +01:00
|
|
|
|
timersub(commit, input, &diff);
|
2020-08-11 17:29:56 +02:00
|
|
|
|
chars += snprintf(
|
|
|
|
|
|
&msg[chars], sizeof(msg) - chars,
|
|
|
|
|
|
"input - %llu µs -> ", (unsigned long long)diff.tv_usec);
|
2019-12-31 20:01:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct timeval diff;
|
2020-01-21 18:51:04 +01:00
|
|
|
|
timersub(&presented, commit, &diff);
|
2020-08-11 17:29:56 +02:00
|
|
|
|
chars += snprintf(
|
|
|
|
|
|
&msg[chars], sizeof(msg) - chars,
|
|
|
|
|
|
"commit - %llu µs -> ", (unsigned long long)diff.tv_usec);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2020-01-01 11:37:47 +01:00
|
|
|
|
if (use_input) {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(timercmp(&presented, input, >));
|
2020-01-21 18:51:04 +01:00
|
|
|
|
timersub(&presented, input, &diff);
|
2020-01-01 11:37:47 +01:00
|
|
|
|
} else {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(timercmp(&presented, commit, >));
|
2020-01-21 18:51:04 +01:00
|
|
|
|
timersub(&presented, commit, &diff);
|
2020-01-01 11:37:47 +01:00
|
|
|
|
}
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2020-08-11 17:29:56 +02:00
|
|
|
|
chars += snprintf(
|
|
|
|
|
|
&msg[chars], sizeof(msg) - chars,
|
|
|
|
|
|
"presented (total: %llu µs)", (unsigned long long)diff.tv_usec);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
|
unsigned frame_count = 0;
|
2019-12-31 20:04:44 +01:00
|
|
|
|
if (tll_length(term->window->on_outputs) > 0) {
|
2019-12-31 20:01:47 +01:00
|
|
|
|
const struct monitor *mon = tll_front(term->window->on_outputs);
|
2020-01-01 11:19:13 +01:00
|
|
|
|
frame_count = (diff.tv_sec * 1000000. + diff.tv_usec) / (1000000. / mon->refresh);
|
2019-12-31 20:01:47 +01:00
|
|
|
|
}
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
|
presentation_statistics.total++;
|
|
|
|
|
|
if (frame_count >= 2)
|
|
|
|
|
|
presentation_statistics.two++;
|
|
|
|
|
|
else if (frame_count >= 1)
|
|
|
|
|
|
presentation_statistics.one++;
|
|
|
|
|
|
else
|
|
|
|
|
|
presentation_statistics.zero++;
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
|
#define _log_fmt "%s (more than %u frames)"
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
|
if (frame_count >= 2)
|
|
|
|
|
|
LOG_ERR(_log_fmt, msg, frame_count);
|
|
|
|
|
|
else if (frame_count >= 1)
|
|
|
|
|
|
LOG_WARN(_log_fmt, msg, frame_count);
|
|
|
|
|
|
else
|
|
|
|
|
|
LOG_INFO(_log_fmt, msg, frame_count);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
|
#undef _log_fmt
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
|
|
|
|
|
wp_presentation_feedback_destroy(wp_presentation_feedback);
|
2020-01-21 18:51:04 +01:00
|
|
|
|
free(ctx);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
discarded(void *data, struct wp_presentation_feedback *wp_presentation_feedback)
|
|
|
|
|
|
{
|
2020-01-21 18:51:04 +01:00
|
|
|
|
struct presentation_context *ctx = data;
|
2019-12-31 15:39:40 +01:00
|
|
|
|
wp_presentation_feedback_destroy(wp_presentation_feedback);
|
2020-01-21 18:51:04 +01:00
|
|
|
|
free(ctx);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wp_presentation_feedback_listener presentation_feedback_listener = {
|
|
|
|
|
|
.sync_output = &sync_output,
|
|
|
|
|
|
.presented = &presented,
|
|
|
|
|
|
.discarded = &discarded,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-04-21 19:29:36 +02:00
|
|
|
|
static struct fcft_font *
|
2019-12-19 07:28:33 +01:00
|
|
|
|
attrs_to_font(const struct terminal *term, const struct attributes *attrs)
|
2019-07-05 10:16:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
int idx = attrs->italic << 1 | attrs->bold;
|
2019-10-16 21:52:12 +02:00
|
|
|
|
return term->fonts[idx];
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 20:40:32 +02:00
|
|
|
|
static inline pixman_color_t
|
2019-08-16 22:06:06 +02:00
|
|
|
|
color_hex_to_pixman_with_alpha(uint32_t color, uint16_t alpha)
|
2019-08-16 20:40:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
return (pixman_color_t){
|
2020-12-20 12:25:12 +01:00
|
|
|
|
.red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) * alpha / 0xffff,
|
|
|
|
|
|
.green = ((color >> 8 & 0xff) | (color >> 0 & 0xff00)) * alpha / 0xffff,
|
|
|
|
|
|
.blue = ((color >> 0 & 0xff) | (color << 8 & 0xff00)) * alpha / 0xffff,
|
2019-08-16 22:06:06 +02:00
|
|
|
|
.alpha = alpha,
|
2019-08-16 20:40:32 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 22:06:06 +02:00
|
|
|
|
static inline pixman_color_t
|
|
|
|
|
|
color_hex_to_pixman(uint32_t color)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Count on the compiler optimizing this */
|
|
|
|
|
|
return color_hex_to_pixman_with_alpha(color, 0xffff);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-15 20:05:01 +01:00
|
|
|
|
static inline uint32_t
|
|
|
|
|
|
color_dim(uint32_t color)
|
2019-08-16 20:40:32 +02:00
|
|
|
|
{
|
2020-11-15 20:05:01 +01:00
|
|
|
|
int hue, sat, lum;
|
|
|
|
|
|
rgb_to_hsl(color, &hue, &sat, &lum);
|
2020-11-15 21:04:21 +01:00
|
|
|
|
return hsl_to_rgb(hue, sat, lum / 1.5);
|
2019-08-16 20:40:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-15 20:05:01 +01:00
|
|
|
|
static inline uint32_t
|
2021-04-17 21:02:02 +02:00
|
|
|
|
color_brighten(const struct terminal *term, uint32_t color)
|
2020-11-14 11:22:35 +01:00
|
|
|
|
{
|
2021-04-17 21:02:02 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* First try to match the color against the base 8 colors. If we
|
|
|
|
|
|
* find a match, return the corresponding bright color.
|
|
|
|
|
|
*/
|
2021-04-17 21:57:08 +02:00
|
|
|
|
if (term->conf->bold_in_bright.palette_based) {
|
|
|
|
|
|
for (size_t i = 0; i < 8; i++) {
|
|
|
|
|
|
if (term->colors.table[i] == color)
|
|
|
|
|
|
return term->colors.table[i + 8];
|
|
|
|
|
|
}
|
2021-04-17 21:02:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-15 20:05:01 +01:00
|
|
|
|
int hue, sat, lum;
|
|
|
|
|
|
rgb_to_hsl(color, &hue, &sat, &lum);
|
2020-11-15 21:04:21 +01:00
|
|
|
|
return hsl_to_rgb(hue, sat, min(100, lum * 1.3));
|
2020-11-14 11:22:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-29 19:33:25 +02:00
|
|
|
|
static inline void
|
2020-04-09 13:41:16 +02:00
|
|
|
|
color_dim_for_search(pixman_color_t *color)
|
2019-08-29 19:33:25 +02:00
|
|
|
|
{
|
2020-04-10 17:51:33 +02:00
|
|
|
|
color->red /= 2;
|
|
|
|
|
|
color->green /= 2;
|
|
|
|
|
|
color->blue /= 2;
|
2019-08-29 19:33:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-29 20:39:22 +02:00
|
|
|
|
static inline int
|
|
|
|
|
|
font_baseline(const struct terminal *term)
|
|
|
|
|
|
{
|
2021-01-07 17:00:58 +01:00
|
|
|
|
return term->font_y_ofs + term->fonts[0]->ascent;
|
2019-08-29 20:39:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-16 21:34:38 +01:00
|
|
|
|
static void
|
|
|
|
|
|
draw_unfocused_block(const struct terminal *term, pixman_image_t *pix,
|
|
|
|
|
|
const pixman_color_t *color, int x, int y, int cell_cols)
|
|
|
|
|
|
{
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, pix, color, 4,
|
|
|
|
|
|
(pixman_rectangle16_t []){
|
|
|
|
|
|
{x, y, cell_cols * term->cell_width, 1}, /* top */
|
|
|
|
|
|
{x, y, 1, term->cell_height}, /* left */
|
|
|
|
|
|
{x + cell_cols * term->cell_width - 1, y, 1, term->cell_height}, /* right */
|
|
|
|
|
|
{x, y + term->cell_height - 1, cell_cols * term->cell_width, 1}, /* bottom */
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
|
static void
|
2021-04-30 20:31:47 +02:00
|
|
|
|
draw_beam(const struct terminal *term, pixman_image_t *pix,
|
|
|
|
|
|
const struct fcft_font *font,
|
|
|
|
|
|
const pixman_color_t *color, int x, int y)
|
2019-07-08 13:57:31 +02:00
|
|
|
|
{
|
2019-11-26 18:54:32 +01:00
|
|
|
|
int baseline = y + font_baseline(term) - term->fonts[0]->ascent;
|
2019-08-16 22:06:06 +02:00
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, pix, color,
|
2019-08-29 20:41:40 +02:00
|
|
|
|
1, &(pixman_rectangle16_t){
|
|
|
|
|
|
x, baseline,
|
2021-04-30 20:31:47 +02:00
|
|
|
|
term_pt_or_px_as_pixels(term, &term->conf->cursor.beam_thickness),
|
|
|
|
|
|
term->fonts[0]->ascent + term->fonts[0]->descent});
|
2019-07-22 20:07:34 +02:00
|
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2019-07-22 20:07:34 +02:00
|
|
|
|
static void
|
2019-08-16 22:06:06 +02:00
|
|
|
|
draw_underline(const struct terminal *term, pixman_image_t *pix,
|
2020-04-21 19:29:36 +02:00
|
|
|
|
const struct fcft_font *font,
|
2019-08-16 22:06:06 +02:00
|
|
|
|
const pixman_color_t *color, int x, int y, int cols)
|
2019-07-22 20:07:34 +02:00
|
|
|
|
{
|
2021-05-11 17:40:59 +02:00
|
|
|
|
/* Make sure the line isn't positioned below the cell */
|
|
|
|
|
|
int y_ofs = font_baseline(term) - font->underline.position;
|
|
|
|
|
|
y_ofs = min(y_ofs, term->cell_height - font->underline.thickness);
|
|
|
|
|
|
|
2019-08-16 22:06:06 +02:00
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, pix, color,
|
2019-11-30 14:53:22 +01:00
|
|
|
|
1, &(pixman_rectangle16_t){
|
2021-05-11 17:40:59 +02:00
|
|
|
|
x, y + y_ofs, cols * term->cell_width, font->underline.thickness});
|
2019-07-22 20:07:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2019-08-16 22:06:06 +02:00
|
|
|
|
draw_strikeout(const struct terminal *term, pixman_image_t *pix,
|
2020-04-21 19:29:36 +02:00
|
|
|
|
const struct fcft_font *font,
|
2019-08-16 22:06:06 +02:00
|
|
|
|
const pixman_color_t *color, int x, int y, int cols)
|
2019-07-22 20:07:34 +02:00
|
|
|
|
{
|
2019-08-16 22:06:06 +02:00
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, pix, color,
|
2019-11-30 14:53:22 +01:00
|
|
|
|
1, &(pixman_rectangle16_t){
|
2019-12-03 21:00:48 +01:00
|
|
|
|
x, y + font_baseline(term) - font->strikeout.position,
|
|
|
|
|
|
cols * term->cell_width, font->strikeout.thickness});
|
2019-07-22 20:07:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-19 07:28:49 +01:00
|
|
|
|
static void
|
2020-12-02 18:52:50 +01:00
|
|
|
|
cursor_colors_for_cell(const struct terminal *term, const struct cell *cell,
|
|
|
|
|
|
const pixman_color_t *fg, const pixman_color_t *bg,
|
|
|
|
|
|
pixman_color_t *cursor_color, pixman_color_t *text_color)
|
2019-12-19 07:28:49 +01:00
|
|
|
|
{
|
2020-01-04 12:03:04 +01:00
|
|
|
|
bool is_selected = cell->attrs.selected;
|
|
|
|
|
|
|
2019-12-19 07:28:49 +01:00
|
|
|
|
if (term->cursor_color.cursor >> 31) {
|
2020-12-02 18:52:50 +01:00
|
|
|
|
*cursor_color = color_hex_to_pixman(term->cursor_color.cursor);
|
|
|
|
|
|
*text_color = color_hex_to_pixman(
|
2020-01-20 18:36:44 +01:00
|
|
|
|
term->cursor_color.text >> 31
|
|
|
|
|
|
? term->cursor_color.text : term->colors.bg);
|
2019-12-19 07:28:49 +01:00
|
|
|
|
|
|
|
|
|
|
if (term->reverse ^ cell->attrs.reverse ^ is_selected) {
|
2020-12-02 18:52:50 +01:00
|
|
|
|
pixman_color_t swap = *cursor_color;
|
|
|
|
|
|
*cursor_color = *text_color;
|
|
|
|
|
|
*text_color = swap;
|
2019-12-19 07:28:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (term->is_searching && !is_selected) {
|
2020-12-02 18:52:50 +01:00
|
|
|
|
color_dim_for_search(cursor_color);
|
|
|
|
|
|
color_dim_for_search(text_color);
|
2019-12-19 07:28:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2020-12-02 18:52:50 +01:00
|
|
|
|
*cursor_color = *fg;
|
|
|
|
|
|
*text_color = *bg;
|
2019-12-19 07:28:49 +01:00
|
|
|
|
}
|
2020-12-02 18:52:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
draw_cursor(const struct terminal *term, const struct cell *cell,
|
|
|
|
|
|
const struct fcft_font *font, pixman_image_t *pix, pixman_color_t *fg,
|
|
|
|
|
|
const pixman_color_t *bg, int x, int y, int cols)
|
|
|
|
|
|
{
|
|
|
|
|
|
pixman_color_t cursor_color;
|
|
|
|
|
|
pixman_color_t text_color;
|
|
|
|
|
|
cursor_colors_for_cell(term, cell, fg, bg, &cursor_color, &text_color);
|
2019-12-19 07:28:49 +01:00
|
|
|
|
|
|
|
|
|
|
switch (term->cursor_style) {
|
|
|
|
|
|
case CURSOR_BLOCK:
|
2020-12-03 18:37:12 +01:00
|
|
|
|
if (unlikely(!term->kbd_focus))
|
2019-12-19 07:28:49 +01:00
|
|
|
|
draw_unfocused_block(term, pix, &cursor_color, x, y, cols);
|
|
|
|
|
|
|
2020-12-02 18:52:50 +01:00
|
|
|
|
else if (likely(term->cursor_blink.state == CURSOR_BLINK_ON)) {
|
2019-12-19 07:28:49 +01:00
|
|
|
|
*fg = text_color;
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, pix, &cursor_color, 1,
|
|
|
|
|
|
&(pixman_rectangle16_t){x, y, cols * term->cell_width, term->cell_height});
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2021-04-30 20:31:47 +02:00
|
|
|
|
case CURSOR_BEAM:
|
2020-12-02 18:52:50 +01:00
|
|
|
|
if (likely(term->cursor_blink.state == CURSOR_BLINK_ON ||
|
|
|
|
|
|
!term->kbd_focus))
|
|
|
|
|
|
{
|
2021-04-30 20:31:47 +02:00
|
|
|
|
draw_beam(term, pix, font, &cursor_color, x, y);
|
2020-12-02 18:52:50 +01:00
|
|
|
|
}
|
2019-12-19 07:28:49 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CURSOR_UNDERLINE:
|
2020-12-02 18:52:50 +01:00
|
|
|
|
if (likely(term->cursor_blink.state == CURSOR_BLINK_ON ||
|
|
|
|
|
|
!term->kbd_focus))
|
|
|
|
|
|
{
|
2021-04-09 21:47:57 +02:00
|
|
|
|
struct fcft_font *font = attrs_to_font(term, &cell->attrs);
|
2019-12-19 07:28:49 +01:00
|
|
|
|
draw_underline(
|
2021-04-09 21:47:57 +02:00
|
|
|
|
term, pix, font, &cursor_color,
|
|
|
|
|
|
x, y + font->underline.thickness, cols);
|
2019-12-19 07:28:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
|
static int
|
2019-08-16 22:06:06 +02:00
|
|
|
|
render_cell(struct terminal *term, pixman_image_t *pix,
|
2020-05-01 11:56:13 +02:00
|
|
|
|
struct row *row, int col, int row_no, bool has_cursor)
|
2019-07-22 20:07:34 +02:00
|
|
|
|
{
|
2020-05-01 11:56:13 +02:00
|
|
|
|
struct cell *cell = &row->cells[col];
|
2019-07-30 18:03:03 +02:00
|
|
|
|
if (cell->attrs.clean)
|
2019-08-01 20:09:39 +02:00
|
|
|
|
return 0;
|
2019-07-30 18:03:03 +02:00
|
|
|
|
|
|
|
|
|
|
cell->attrs.clean = 1;
|
|
|
|
|
|
|
2019-08-16 22:06:06 +02:00
|
|
|
|
int width = term->cell_width;
|
|
|
|
|
|
int height = term->cell_height;
|
2020-02-24 18:38:11 +01:00
|
|
|
|
int x = term->margins.left + col * width;
|
2020-05-01 11:56:13 +02:00
|
|
|
|
int y = term->margins.top + row_no * height;
|
2019-07-22 20:07:34 +02:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(cell->attrs.selected == 0 || cell->attrs.selected == 1);
|
2020-01-04 12:03:04 +01:00
|
|
|
|
bool is_selected = cell->attrs.selected;
|
2019-07-22 20:07:34 +02:00
|
|
|
|
|
2019-11-28 19:22:21 +01:00
|
|
|
|
uint32_t _fg = 0;
|
|
|
|
|
|
uint32_t _bg = 0;
|
|
|
|
|
|
|
2021-05-01 20:17:54 +02:00
|
|
|
|
bool apply_alpha = false;
|
|
|
|
|
|
|
2021-04-07 08:09:40 +02:00
|
|
|
|
if (is_selected && term->colors.use_custom_selection) {
|
|
|
|
|
|
_fg = term->colors.selection_fg;
|
|
|
|
|
|
_bg = term->colors.selection_bg;
|
2020-08-12 18:53:32 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
/* Use cell specific color, if set, otherwise the default colors (possible reversed) */
|
|
|
|
|
|
_fg = cell->attrs.have_fg ? cell->attrs.fg : term->colors.fg;
|
|
|
|
|
|
_bg = cell->attrs.have_bg ? cell->attrs.bg : term->colors.bg;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2020-08-12 18:53:32 +02:00
|
|
|
|
if (term->reverse ^ cell->attrs.reverse ^ is_selected) {
|
|
|
|
|
|
uint32_t swap = _fg;
|
|
|
|
|
|
_fg = _bg;
|
|
|
|
|
|
_bg = swap;
|
2021-05-01 20:17:54 +02:00
|
|
|
|
} else
|
|
|
|
|
|
apply_alpha = !cell->attrs.have_bg;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-23 21:30:47 +02:00
|
|
|
|
if (unlikely(is_selected && _fg == _bg)) {
|
|
|
|
|
|
/* Invert bg when selected/highlighted text has same fg/bg */
|
|
|
|
|
|
_bg = ~_bg;
|
2021-05-01 20:17:54 +02:00
|
|
|
|
apply_alpha = false;
|
2021-04-23 21:30:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-15 20:05:01 +01:00
|
|
|
|
if (cell->attrs.dim)
|
|
|
|
|
|
_fg = color_dim(_fg);
|
2021-04-17 21:57:08 +02:00
|
|
|
|
if (term->conf->bold_in_bright.enabled && cell->attrs.bold)
|
2021-04-17 21:02:02 +02:00
|
|
|
|
_fg = color_brighten(term, _fg);
|
2020-11-15 20:05:01 +01:00
|
|
|
|
|
|
|
|
|
|
if (cell->attrs.blink && term->blink.state == BLINK_OFF)
|
|
|
|
|
|
_fg = color_dim(_fg);
|
|
|
|
|
|
|
2019-08-16 20:40:32 +02:00
|
|
|
|
pixman_color_t fg = color_hex_to_pixman(_fg);
|
2020-05-16 16:26:52 +02:00
|
|
|
|
pixman_color_t bg = color_hex_to_pixman_with_alpha(
|
2021-05-01 20:17:54 +02:00
|
|
|
|
_bg, apply_alpha ? term->colors.alpha : 0xffff);
|
2019-07-16 13:17:51 +02:00
|
|
|
|
|
2019-08-27 19:40:07 +02:00
|
|
|
|
if (term->is_searching && !is_selected) {
|
2020-04-09 13:41:16 +02:00
|
|
|
|
color_dim_for_search(&fg);
|
|
|
|
|
|
color_dim_for_search(&bg);
|
2019-08-27 17:23:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-21 19:29:36 +02:00
|
|
|
|
struct fcft_font *font = attrs_to_font(term, &cell->attrs);
|
2020-04-26 12:39:42 +02:00
|
|
|
|
const struct fcft_glyph *glyph = NULL;
|
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
|
|
|
|
const struct composed *composed = NULL;
|
2020-04-26 12:39:42 +02: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
|
|
|
|
if (cell->wc != 0) {
|
|
|
|
|
|
wchar_t base = cell->wc;
|
|
|
|
|
|
|
2020-07-14 16:41:57 +02:00
|
|
|
|
if (base >= CELL_COMB_CHARS_LO &&
|
|
|
|
|
|
base < (CELL_COMB_CHARS_LO + term->composed_count))
|
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
|
|
|
|
{
|
2020-07-14 16:41:57 +02:00
|
|
|
|
composed = &term->composed[base - CELL_COMB_CHARS_LO];
|
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
|
|
|
|
base = composed->base;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-03 17:57:16 +02:00
|
|
|
|
if (unlikely(
|
|
|
|
|
|
/* Classic box drawings */
|
|
|
|
|
|
(base >= 0x2500 && base <= 0x259f) ||
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Unicode 13 "Symbols for Legacy Computing"
|
|
|
|
|
|
* sub-ranges below.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note, the full range is U+1FB00 - U+1FBF9
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Unicode 13 sextants */
|
|
|
|
|
|
(base >= 0x1fb00 && base <= 0x1fb3b) ||
|
|
|
|
|
|
|
|
|
|
|
|
/* Unicode 13 partial blocks */
|
|
|
|
|
|
/* TODO: there's more here! */
|
|
|
|
|
|
(base >= 0x1fb70 && base <= 0x1fb8b)) &&
|
|
|
|
|
|
|
2021-04-09 23:19:20 +02:00
|
|
|
|
likely(!term->conf->box_drawings_uses_font_glyphs))
|
|
|
|
|
|
{
|
2020-12-26 16:24:16 +01:00
|
|
|
|
/* Box drawing characters */
|
2021-05-03 17:57:16 +02:00
|
|
|
|
size_t idx = base >= 0x1fb00
|
|
|
|
|
|
? (base >= 0x1fb70
|
|
|
|
|
|
? base - 0x1fb70 + 220
|
|
|
|
|
|
: base - 0x1fb00 + 160)
|
|
|
|
|
|
: base - 0x2500;
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(idx < ALEN(term->box_drawing));
|
2020-12-26 16:24:16 +01:00
|
|
|
|
|
|
|
|
|
|
if (likely(term->box_drawing[idx] != NULL))
|
|
|
|
|
|
glyph = term->box_drawing[idx];
|
|
|
|
|
|
else {
|
|
|
|
|
|
mtx_lock(&term->render.workers.lock);
|
|
|
|
|
|
|
|
|
|
|
|
/* Parallel thread may have instantiated it while we took the lock */
|
|
|
|
|
|
if (term->box_drawing[idx] == NULL)
|
|
|
|
|
|
term->box_drawing[idx] = box_drawing(term, base);
|
|
|
|
|
|
mtx_unlock(&term->render.workers.lock);
|
|
|
|
|
|
|
|
|
|
|
|
glyph = term->box_drawing[idx];
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(glyph != NULL);
|
2020-12-26 16:24:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
} else
|
|
|
|
|
|
glyph = fcft_glyph_rasterize(font, base, term->font_subpixel);
|
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
|
|
|
|
}
|
2019-07-31 21:15:40 +02:00
|
|
|
|
|
2020-06-05 08:10:38 +02:00
|
|
|
|
const int cols_left = term->cols - col;
|
|
|
|
|
|
int cell_cols = glyph != NULL ? max(1, min(glyph->cols, cols_left)) : 1;
|
|
|
|
|
|
|
2020-09-03 17:37:44 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Hack!
|
|
|
|
|
|
*
|
|
|
|
|
|
* Deal with double-width glyphs for which wcwidth() returns
|
|
|
|
|
|
* 1. Typically Unicode private usage area characters,
|
|
|
|
|
|
* e.g. powerline, or nerd hack fonts.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Users can enable a tweak option that lets this glyphs
|
|
|
|
|
|
* overflow/bleed into the neighbouring cell.
|
|
|
|
|
|
*
|
|
|
|
|
|
* We only apply this workaround if:
|
|
|
|
|
|
* - the user has explicitly enabled this feature
|
|
|
|
|
|
* - the *character* width is 1
|
|
|
|
|
|
* - the *glyph* width is at least 1.5 cells
|
|
|
|
|
|
* - the *glyph* width is less than 3 cells
|
2020-11-16 08:40:11 +01:00
|
|
|
|
* - *this* column isn’t the last column
|
|
|
|
|
|
* - *this* cells is followed by an empty cell, or a space
|
2020-09-03 17:37:44 +02:00
|
|
|
|
*/
|
|
|
|
|
|
if (term->conf->tweak.allow_overflowing_double_width_glyphs &&
|
|
|
|
|
|
glyph != NULL &&
|
|
|
|
|
|
glyph->cols == 1 &&
|
|
|
|
|
|
glyph->width >= term->cell_width * 15 / 10 &&
|
2020-11-16 08:40:11 +01:00
|
|
|
|
glyph->width < 3 * term->cell_width &&
|
|
|
|
|
|
col < term->cols - 1 &&
|
|
|
|
|
|
(row->cells[col + 1].wc == 0 || row->cells[col + 1].wc == L' '))
|
2020-09-03 17:37:44 +02:00
|
|
|
|
{
|
2021-01-02 22:24:49 +01:00
|
|
|
|
cell_cols = 2;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Ensure the cell we’re overflowing into gets re-rendered, to
|
|
|
|
|
|
* ensure it is erased if *this* cell is erased. Note that we
|
|
|
|
|
|
* do *not* mark the row as dirty - we don’t need to re-render
|
|
|
|
|
|
* the cell if nothing else on the row has changed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
row->cells[col].attrs.clean = 0;
|
|
|
|
|
|
row->cells[col + 1].attrs.clean = 0;
|
2020-09-03 17:37:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-05 08:10:38 +02:00
|
|
|
|
pixman_region32_t clip;
|
|
|
|
|
|
pixman_region32_init_rect(
|
|
|
|
|
|
&clip, x, y,
|
|
|
|
|
|
cell_cols * term->cell_width, term->cell_height);
|
|
|
|
|
|
pixman_image_set_clip_region32(pix, &clip);
|
2019-07-31 21:15:40 +02:00
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
|
/* Background */
|
2019-08-16 20:40:32 +02:00
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, pix, &bg, 1,
|
|
|
|
|
|
&(pixman_rectangle16_t){x, y, cell_cols * width, height});
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2020-11-23 19:26:00 +01:00
|
|
|
|
if (cell->attrs.blink && term->blink.fd < 0) {
|
|
|
|
|
|
/* TODO: use a custom lock for this? */
|
|
|
|
|
|
mtx_lock(&term->render.workers.lock);
|
2019-12-17 19:11:27 +01:00
|
|
|
|
term_arm_blink_timer(term);
|
2020-11-23 19:26:00 +01:00
|
|
|
|
mtx_unlock(&term->render.workers.lock);
|
|
|
|
|
|
}
|
2019-07-21 20:11:20 +02:00
|
|
|
|
|
2020-07-11 09:06:36 +02:00
|
|
|
|
if (has_cursor && term->cursor_style == CURSOR_BLOCK && term->kbd_focus)
|
2020-03-17 11:47:47 +01:00
|
|
|
|
draw_cursor(term, cell, font, pix, &fg, &bg, x, y, cell_cols);
|
|
|
|
|
|
|
term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition
Instead of using CELL_SPACER for *all* cells that previously used
CELL_MULT_COL_SPACER, include the remaining number of spacers
following, and including, itself. This is encoded by adding to the
CELL_SPACER value.
So, a double width character will now store the character itself in
the first cell (just like before), and CELL_SPACER+1 in the second
cell.
A three-cell character would store the character itself, then
CELL_SPACER+2, and finally CELL_SPACER+1.
In other words, the last spacer is always CELL_SPACER+1.
CELL_SPACER+0 is used when padding at the right margin. I.e. when
writing e.g. a double width character in the last column, we insert a
CELL_SPACER+0 pad character, and then write the double width character
in the first column on the next row.
2021-05-14 14:41:02 +02:00
|
|
|
|
if (cell->wc == 0 || cell->wc >= CELL_SPACER ||
|
2021-04-23 21:27:32 +02:00
|
|
|
|
(unlikely(cell->attrs.conceal) && !is_selected))
|
|
|
|
|
|
{
|
2020-03-17 11:47:47 +01:00
|
|
|
|
goto draw_cursor;
|
2021-04-23 21:27:32 +02:00
|
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2020-05-02 22:14:48 +02:00
|
|
|
|
pixman_image_t *clr_pix = pixman_image_create_solid_fill(&fg);
|
|
|
|
|
|
|
2019-07-31 21:15:40 +02:00
|
|
|
|
if (glyph != NULL) {
|
2021-01-07 17:00:58 +01:00
|
|
|
|
const int letter_x_ofs = term->font_x_ofs;
|
2021-01-07 11:18:07 +01:00
|
|
|
|
|
2019-08-18 18:11:38 +02:00
|
|
|
|
if (unlikely(pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)) {
|
2019-07-31 21:15:40 +02:00
|
|
|
|
/* Glyph surface is a pre-rendered image (typically a color emoji...) */
|
|
|
|
|
|
if (!(cell->attrs.blink && term->blink.state == BLINK_OFF)) {
|
2019-08-17 17:36:27 +02:00
|
|
|
|
pixman_image_composite32(
|
2019-08-16 20:40:32 +02:00
|
|
|
|
PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0,
|
2021-01-07 11:18:07 +01:00
|
|
|
|
x + letter_x_ofs + glyph->x, y + font_baseline(term) - glyph->y,
|
2020-06-04 15:39:19 +02:00
|
|
|
|
glyph->width, glyph->height);
|
2019-07-31 21:15:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2019-08-17 17:36:27 +02:00
|
|
|
|
pixman_image_composite32(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_OVER, clr_pix, glyph->pix, pix, 0, 0, 0, 0,
|
2021-01-07 11:18:07 +01:00
|
|
|
|
x + letter_x_ofs + glyph->x, y + font_baseline(term) - glyph->y,
|
2020-06-04 15:39:19 +02:00
|
|
|
|
glyph->width, glyph->height);
|
2020-06-03 17:32:57 +02: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
|
|
|
|
}
|
2020-06-04 15:39:19 +02:00
|
|
|
|
|
2021-01-04 18:32:55 +01:00
|
|
|
|
/* Combining characters */
|
|
|
|
|
|
if (composed != NULL) {
|
|
|
|
|
|
for (size_t i = 0; i < composed->count; i++) {
|
|
|
|
|
|
const struct fcft_glyph *g = fcft_glyph_rasterize(
|
|
|
|
|
|
font, composed->combining[i], term->font_subpixel);
|
|
|
|
|
|
|
|
|
|
|
|
if (g == NULL)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Fonts _should_ assume the pen position is now
|
|
|
|
|
|
* *after* the base glyph, and thus use negative
|
|
|
|
|
|
* offsets for combining glyphs.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Not all fonts behave like this however, and we
|
2021-01-04 19:49:24 +01:00
|
|
|
|
* try to accommodate both variants.
|
2021-01-04 18:32:55 +01:00
|
|
|
|
*
|
|
|
|
|
|
* Since we haven't moved our pen position yet, we
|
|
|
|
|
|
* add a full cell width to the offset (or two, in
|
|
|
|
|
|
* case of double-width characters).
|
|
|
|
|
|
*
|
|
|
|
|
|
* If the font does *not* use negative offsets,
|
|
|
|
|
|
* we'd normally use an offset of 0. However, to
|
|
|
|
|
|
* somewhat deal with double-width glyphs we use
|
|
|
|
|
|
* an offset of *one* cell.
|
|
|
|
|
|
*/
|
|
|
|
|
|
int x_ofs = g->x < 0
|
|
|
|
|
|
? cell_cols * term->cell_width
|
|
|
|
|
|
: (cell_cols - 1) * term->cell_width;
|
|
|
|
|
|
|
|
|
|
|
|
pixman_image_composite32(
|
|
|
|
|
|
PIXMAN_OP_OVER, clr_pix, g->pix, pix, 0, 0, 0, 0,
|
2021-01-07 11:18:07 +01:00
|
|
|
|
x + letter_x_ofs + x_ofs + g->x, y + font_baseline(term) - g->y,
|
2021-01-04 18:32:55 +01:00
|
|
|
|
g->width, g->height);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-01 11:56:13 +02: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
|
|
|
|
|
2020-05-02 22:14:48 +02:00
|
|
|
|
pixman_image_unref(clr_pix);
|
2020-05-01 11:56:13 +02:00
|
|
|
|
|
2019-07-16 14:20:39 +02:00
|
|
|
|
/* Underline */
|
2020-11-19 19:13:00 +01:00
|
|
|
|
if (cell->attrs.underline)
|
|
|
|
|
|
draw_underline(term, pix, font, &fg, x, y, cell_cols);
|
2019-07-16 15:08:02 +02:00
|
|
|
|
|
2020-11-19 19:13:00 +01:00
|
|
|
|
if (cell->attrs.strikethrough)
|
|
|
|
|
|
draw_strikeout(term, pix, font, &fg, x, y, cell_cols);
|
2019-08-01 20:09:39 +02:00
|
|
|
|
|
2021-02-06 11:51:58 +01:00
|
|
|
|
if (unlikely(cell->attrs.url)) {
|
|
|
|
|
|
pixman_color_t url_color = color_hex_to_pixman(
|
|
|
|
|
|
term->conf->colors.use_custom.url
|
|
|
|
|
|
? term->conf->colors.url
|
|
|
|
|
|
: term->colors.table[3]
|
|
|
|
|
|
);
|
|
|
|
|
|
draw_underline(term, pix, font, &url_color, x, y, cell_cols);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-17 11:47:47 +01:00
|
|
|
|
draw_cursor:
|
2020-07-11 09:06:36 +02:00
|
|
|
|
if (has_cursor && (term->cursor_style != CURSOR_BLOCK || !term->kbd_focus))
|
2020-03-17 11:47:47 +01:00
|
|
|
|
draw_cursor(term, cell, font, pix, &fg, &bg, x, y, cell_cols);
|
|
|
|
|
|
|
2020-06-06 14:22:25 +02:00
|
|
|
|
pixman_image_set_clip_region32(pix, NULL);
|
2019-08-01 20:09:39 +02:00
|
|
|
|
return cell_cols;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-09 17:23:55 +01:00
|
|
|
|
static void
|
|
|
|
|
|
render_row(struct terminal *term, pixman_image_t *pix, struct row *row,
|
|
|
|
|
|
int row_no, int cursor_col)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int col = term->cols - 1; col >= 0; col--)
|
|
|
|
|
|
render_cell(term, pix, row, col, row_no, cursor_col == col);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-08 19:55:32 +02:00
|
|
|
|
static void
|
|
|
|
|
|
render_urgency(struct terminal *term, struct buffer *buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint32_t red = term->colors.table[1];
|
2020-11-15 20:05:01 +01:00
|
|
|
|
if (term->is_searching)
|
|
|
|
|
|
red = color_dim(red);
|
|
|
|
|
|
|
2020-10-08 19:55:32 +02:00
|
|
|
|
pixman_color_t bg = color_hex_to_pixman(red);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int width = min(min(term->margins.left, term->margins.right),
|
|
|
|
|
|
min(term->margins.top, term->margins.bottom));
|
|
|
|
|
|
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &bg, 4,
|
|
|
|
|
|
(pixman_rectangle16_t[]){
|
|
|
|
|
|
/* Top */
|
|
|
|
|
|
{0, 0, term->width, width},
|
|
|
|
|
|
|
|
|
|
|
|
/* Bottom */
|
|
|
|
|
|
{0, term->height - width, term->width, width},
|
|
|
|
|
|
|
|
|
|
|
|
/* Left */
|
|
|
|
|
|
{0, width, width, term->height - 2 * width},
|
|
|
|
|
|
|
|
|
|
|
|
/* Right */
|
|
|
|
|
|
{term->width - width, width, width, term->height - 2 * width},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
|
static void
|
2020-07-13 14:03:58 +02:00
|
|
|
|
render_margin(struct terminal *term, struct buffer *buf,
|
2020-07-13 14:19:07 +02:00
|
|
|
|
int start_line, int end_line, bool apply_damage)
|
2020-03-22 20:22:17 +01:00
|
|
|
|
{
|
|
|
|
|
|
/* Fill area outside the cell grid with the default background color */
|
2020-03-23 20:14:30 +01:00
|
|
|
|
const int rmargin = term->width - term->margins.right;
|
|
|
|
|
|
const int bmargin = term->height - term->margins.bottom;
|
|
|
|
|
|
const int line_count = end_line - start_line;
|
2020-03-22 20:22:17 +01:00
|
|
|
|
|
|
|
|
|
|
uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg;
|
2020-11-15 20:05:01 +01:00
|
|
|
|
if (term->is_searching)
|
|
|
|
|
|
_bg = color_dim(_bg);
|
2020-10-08 19:53:11 +02:00
|
|
|
|
|
2020-05-16 16:26:52 +02:00
|
|
|
|
pixman_color_t bg = color_hex_to_pixman_with_alpha(
|
2020-10-08 19:53:11 +02:00
|
|
|
|
_bg,
|
|
|
|
|
|
(_bg == (term->reverse ? term->colors.fg : term->colors.bg)
|
|
|
|
|
|
? term->colors.alpha : 0xffff));
|
|
|
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
|
pixman_image_fill_rectangles(
|
2020-07-13 14:03:58 +02:00
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &bg, 4,
|
2020-03-22 20:22:17 +01:00
|
|
|
|
(pixman_rectangle16_t[]){
|
2020-07-13 14:03:58 +02:00
|
|
|
|
/* Top */
|
|
|
|
|
|
{0, 0, term->width, term->margins.top},
|
|
|
|
|
|
|
|
|
|
|
|
/* Bottom */
|
|
|
|
|
|
{0, bmargin, term->width, term->margins.bottom},
|
|
|
|
|
|
|
2020-03-23 20:12:19 +01:00
|
|
|
|
/* Left */
|
|
|
|
|
|
{0, term->margins.top + start_line * term->cell_height,
|
|
|
|
|
|
term->margins.left, line_count * term->cell_height},
|
2020-03-22 20:22:17 +01:00
|
|
|
|
|
2020-03-23 20:12:19 +01:00
|
|
|
|
/* Right */
|
|
|
|
|
|
{rmargin, term->margins.top + start_line * term->cell_height,
|
|
|
|
|
|
term->margins.right, line_count * term->cell_height},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-10-08 19:55:32 +02:00
|
|
|
|
if (term->render.urgency)
|
|
|
|
|
|
render_urgency(term, buf);
|
|
|
|
|
|
|
2021-05-10 17:56:12 +02:00
|
|
|
|
/* Ensure the updated regions are copied to the next frame's
|
|
|
|
|
|
* buffer when we're double buffering */
|
|
|
|
|
|
pixman_region32_union_rect(
|
|
|
|
|
|
&buf->dirty, &buf->dirty, 0, 0, term->width, term->margins.top);
|
|
|
|
|
|
pixman_region32_union_rect(
|
|
|
|
|
|
&buf->dirty, &buf->dirty, 0, bmargin, term->width, term->margins.bottom);
|
|
|
|
|
|
pixman_region32_union_rect(
|
|
|
|
|
|
&buf->dirty, &buf->dirty, 0, 0, term->margins.left, term->height);
|
|
|
|
|
|
pixman_region32_union_rect(
|
|
|
|
|
|
&buf->dirty, &buf->dirty,
|
|
|
|
|
|
rmargin, 0, term->margins.right, term->height);
|
|
|
|
|
|
|
2020-07-13 14:19:07 +02:00
|
|
|
|
if (apply_damage) {
|
|
|
|
|
|
/* Top */
|
2020-07-13 14:06:02 +02:00
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface, 0, 0, term->width, term->margins.top);
|
|
|
|
|
|
|
2020-07-13 14:19:07 +02:00
|
|
|
|
/* Bottom */
|
2020-07-13 14:06:02 +02:00
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface, 0, bmargin, term->width, term->margins.bottom);
|
|
|
|
|
|
|
2020-07-13 14:19:07 +02:00
|
|
|
|
/* Left */
|
2020-07-13 14:06:02 +02:00
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface,
|
|
|
|
|
|
0, term->margins.top + start_line * term->cell_height,
|
|
|
|
|
|
term->margins.left, line_count * term->cell_height);
|
|
|
|
|
|
|
2020-07-13 14:19:07 +02:00
|
|
|
|
/* Right */
|
2020-07-13 14:06:02 +02:00
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface,
|
|
|
|
|
|
rmargin, term->margins.top + start_line * term->cell_height,
|
|
|
|
|
|
term->margins.right, line_count * term->cell_height);
|
2020-07-13 14:19:07 +02:00
|
|
|
|
}
|
2020-03-22 20:22:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
static void
|
|
|
|
|
|
grid_render_scroll(struct terminal *term, struct buffer *buf,
|
|
|
|
|
|
const struct damage *dmg)
|
|
|
|
|
|
{
|
2020-04-26 12:47:19 +02:00
|
|
|
|
int height = (dmg->region.end - dmg->region.start - dmg->lines) * term->cell_height;
|
2020-03-22 20:22:17 +01:00
|
|
|
|
|
|
|
|
|
|
LOG_DBG(
|
|
|
|
|
|
"damage: SCROLL: %d-%d by %d lines",
|
2020-04-26 12:47:19 +02:00
|
|
|
|
dmg->region.start, dmg->region.end, dmg->lines);
|
2020-03-22 20:22:17 +01:00
|
|
|
|
|
|
|
|
|
|
if (height <= 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
#if TIME_SCROLL_DAMAGE
|
|
|
|
|
|
struct timeval start_time;
|
|
|
|
|
|
gettimeofday(&start_time, NULL);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-04-26 12:47:19 +02:00
|
|
|
|
int dst_y = term->margins.top + (dmg->region.start + 0) * term->cell_height;
|
|
|
|
|
|
int src_y = term->margins.top + (dmg->region.start + dmg->lines) * term->cell_height;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* SHM scrolling can be *much* faster, but it depends on how many
|
|
|
|
|
|
* lines we're scrolling, and how much repairing we need to do.
|
|
|
|
|
|
*
|
|
|
|
|
|
* In short, scrolling a *large* number of rows is faster with a
|
|
|
|
|
|
* memmove, while scrolling a *small* number of lines is faster
|
|
|
|
|
|
* with SHM scrolling.
|
|
|
|
|
|
*
|
2020-03-23 20:45:27 +01:00
|
|
|
|
* However, since we need to restore the scrolling regions when
|
|
|
|
|
|
* SHM scrolling, we also need to take this into account.
|
2020-03-22 20:22:17 +01:00
|
|
|
|
*
|
2020-03-23 20:45:27 +01:00
|
|
|
|
* Finally, we also have to restore the window margins, and this
|
|
|
|
|
|
* is a *huge* performance hit when scrolling a large number of
|
|
|
|
|
|
* lines (in addition to the sloweness of SHM scrolling as
|
|
|
|
|
|
* method).
|
2020-03-22 20:22:17 +01:00
|
|
|
|
*
|
|
|
|
|
|
* So, we need to figure out when to SHM scroll, and when to
|
|
|
|
|
|
* memmove.
|
|
|
|
|
|
*
|
2020-08-15 19:39:00 +01:00
|
|
|
|
* For now, assume that the both methods perform roughly the same,
|
2020-03-22 20:22:17 +01:00
|
|
|
|
* given an equal number of bytes to move/allocate, and use the
|
|
|
|
|
|
* method that results in the least amount of bytes to touch.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Since number of lines directly translates to bytes, we can
|
|
|
|
|
|
* simply count lines.
|
|
|
|
|
|
*
|
|
|
|
|
|
* SHM scrolling needs to first "move" (punch hole + allocate)
|
2020-04-26 12:47:19 +02:00
|
|
|
|
* dmg->lines number of lines, and then we need to restore
|
2020-03-22 20:22:17 +01:00
|
|
|
|
* the bottom scroll region.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If the total number of lines is less than half the screen - use
|
|
|
|
|
|
* SHM. Otherwise use memmove.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool try_shm_scroll =
|
2020-03-25 18:26:58 +01:00
|
|
|
|
shm_can_scroll(buf) && (
|
2020-04-26 12:47:19 +02:00
|
|
|
|
dmg->lines +
|
|
|
|
|
|
dmg->region.start +
|
|
|
|
|
|
(term->rows - dmg->region.end)) < term->rows / 2;
|
2020-03-22 20:22:17 +01:00
|
|
|
|
|
|
|
|
|
|
bool did_shm_scroll = false;
|
|
|
|
|
|
|
|
|
|
|
|
//try_shm_scroll = false;
|
|
|
|
|
|
//try_shm_scroll = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (try_shm_scroll) {
|
|
|
|
|
|
did_shm_scroll = shm_scroll(
|
2020-04-26 12:47:19 +02:00
|
|
|
|
term->wl->shm, buf, dmg->lines * term->cell_height,
|
|
|
|
|
|
term->margins.top, dmg->region.start * term->cell_height,
|
|
|
|
|
|
term->margins.bottom, (term->rows - dmg->region.end) * term->cell_height);
|
2020-03-22 20:22:17 +01:00
|
|
|
|
}
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
|
if (did_shm_scroll) {
|
|
|
|
|
|
/* Restore margins */
|
|
|
|
|
|
render_margin(
|
2020-07-13 14:19:07 +02:00
|
|
|
|
term, buf, dmg->region.end - dmg->lines, term->rows, false);
|
2020-03-23 20:45:27 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
/* Fallback for when we either cannot do SHM scrolling, or it failed */
|
2019-08-16 20:40:32 +02:00
|
|
|
|
uint8_t *raw = buf->mmapped;
|
|
|
|
|
|
memmove(raw + dst_y * buf->stride,
|
|
|
|
|
|
raw + src_y * buf->stride,
|
|
|
|
|
|
height * buf->stride);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
2020-03-22 20:22:17 +01:00
|
|
|
|
|
|
|
|
|
|
#if TIME_SCROLL_DAMAGE
|
|
|
|
|
|
struct timeval end_time;
|
|
|
|
|
|
gettimeofday(&end_time, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
struct timeval memmove_time;
|
|
|
|
|
|
timersub(&end_time, &start_time, &memmove_time);
|
|
|
|
|
|
LOG_INFO("scrolled %dKB (%d lines) using %s in %lds %ldus",
|
2020-04-26 12:47:19 +02:00
|
|
|
|
height * buf->stride / 1024, dmg->lines,
|
2020-03-22 20:22:17 +01:00
|
|
|
|
did_shm_scroll ? "SHM" : try_shm_scroll ? "memmove (SHM failed)" : "memmove",
|
|
|
|
|
|
memmove_time.tv_sec, memmove_time.tv_usec);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface, term->margins.left, dst_y,
|
|
|
|
|
|
term->width - term->margins.left - term->margins.right, height);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
|
|
|
|
|
|
const struct damage *dmg)
|
|
|
|
|
|
{
|
2020-04-26 12:47:19 +02:00
|
|
|
|
int height = (dmg->region.end - dmg->region.start - dmg->lines) * term->cell_height;
|
2020-03-23 21:14:51 +01:00
|
|
|
|
|
|
|
|
|
|
LOG_DBG(
|
csi: implement CSI Ps ; Ps ; Ps t reporting escape sequences
A lot of the escape sequences on the "CSI Ps ; Ps ; Ps t" form are
expected to return a reply. Thus, not having these implemented means
we will hang if the client sends these escapes.
Not all of these escapes can be meaningfully implemented on Wayland,
and thus this implementation is best effort.
We now support the following escapes:
* 11t - report if window is iconified (always replies "no")
* 13t - report window position (always replies 0,0)
* 13;2t - report text area position (replies with margins, since we
cannot get the window's position)
* 14t - report text area size, in pixels
* 14;2t - report window size, in pixels
* 15t - report screen size, in pixels
* 16t - report cell size, in pixels
* 18t - report text area size, in cells
* 19t - report screen size, in cells
2020-04-17 23:03:20 +02:00
|
|
|
|
"damage: SCROLL REVERSE: %d-%d by %d lines",
|
2020-04-26 12:47:19 +02:00
|
|
|
|
dmg->region.start, dmg->region.end, dmg->lines);
|
2020-03-23 21:14:51 +01:00
|
|
|
|
|
|
|
|
|
|
if (height <= 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
#if TIME_SCROLL_DAMAGE
|
|
|
|
|
|
struct timeval start_time;
|
|
|
|
|
|
gettimeofday(&start_time, NULL);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-04-26 12:47:19 +02:00
|
|
|
|
int src_y = term->margins.top + (dmg->region.start + 0) * term->cell_height;
|
|
|
|
|
|
int dst_y = term->margins.top + (dmg->region.start + dmg->lines) * term->cell_height;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-03-23 21:14:51 +01:00
|
|
|
|
bool try_shm_scroll =
|
2020-03-25 18:26:58 +01:00
|
|
|
|
shm_can_scroll(buf) && (
|
2020-04-26 12:47:19 +02:00
|
|
|
|
dmg->lines +
|
|
|
|
|
|
dmg->region.start +
|
|
|
|
|
|
(term->rows - dmg->region.end)) < term->rows / 2;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-03-23 21:14:51 +01:00
|
|
|
|
bool did_shm_scroll = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (try_shm_scroll) {
|
|
|
|
|
|
did_shm_scroll = shm_scroll(
|
2020-04-26 12:47:19 +02:00
|
|
|
|
term->wl->shm, buf, -dmg->lines * term->cell_height,
|
|
|
|
|
|
term->margins.top, dmg->region.start * term->cell_height,
|
|
|
|
|
|
term->margins.bottom, (term->rows - dmg->region.end) * term->cell_height);
|
2020-03-23 21:14:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (did_shm_scroll) {
|
|
|
|
|
|
/* Restore margins */
|
|
|
|
|
|
render_margin(
|
2020-07-13 14:19:07 +02:00
|
|
|
|
term, buf, dmg->region.start, dmg->region.start + dmg->lines, false);
|
2020-03-23 21:14:51 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
/* Fallback for when we either cannot do SHM scrolling, or it failed */
|
2019-08-16 20:40:32 +02:00
|
|
|
|
uint8_t *raw = buf->mmapped;
|
|
|
|
|
|
memmove(raw + dst_y * buf->stride,
|
|
|
|
|
|
raw + src_y * buf->stride,
|
|
|
|
|
|
height * buf->stride);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
2020-03-23 21:14:51 +01:00
|
|
|
|
|
|
|
|
|
|
#if TIME_SCROLL_DAMAGE
|
|
|
|
|
|
struct timeval end_time;
|
|
|
|
|
|
gettimeofday(&end_time, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
struct timeval memmove_time;
|
|
|
|
|
|
timersub(&end_time, &start_time, &memmove_time);
|
|
|
|
|
|
LOG_INFO("scrolled REVERSE %dKB (%d lines) using %s in %lds %ldus",
|
2020-04-26 12:47:19 +02:00
|
|
|
|
height * buf->stride / 1024, dmg->lines,
|
2020-03-23 21:14:51 +01:00
|
|
|
|
did_shm_scroll ? "SHM" : try_shm_scroll ? "memmove (SHM failed)" : "memmove",
|
|
|
|
|
|
memmove_time.tv_sec, memmove_time.tv_usec);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface, term->margins.left, dst_y,
|
|
|
|
|
|
term->width - term->margins.left - term->margins.right, height);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-21 23:48:45 +01:00
|
|
|
|
static void
|
2020-11-13 16:54:40 +01:00
|
|
|
|
render_sixel_chunk(struct terminal *term, pixman_image_t *pix, const struct sixel *sixel,
|
|
|
|
|
|
int term_start_row, int img_start_row, int count)
|
2020-02-21 23:48:45 +01:00
|
|
|
|
{
|
2020-02-22 00:05:25 +01:00
|
|
|
|
/* Translate row/column to x/y pixel values */
|
2020-02-24 18:38:11 +01:00
|
|
|
|
const int x = term->margins.left + sixel->pos.col * term->cell_width;
|
2020-11-13 16:54:40 +01:00
|
|
|
|
const int y = term->margins.top + term_start_row * term->cell_height;
|
2020-02-21 23:48:45 +01:00
|
|
|
|
|
2020-02-22 00:05:25 +01:00
|
|
|
|
/* Width/height, in pixels - and don't touch the window margins */
|
2020-11-13 16:54:40 +01:00
|
|
|
|
const int width = max(
|
|
|
|
|
|
0,
|
|
|
|
|
|
min(sixel->width,
|
|
|
|
|
|
term->width - x - term->margins.right));
|
|
|
|
|
|
const int height = max(
|
|
|
|
|
|
0,
|
|
|
|
|
|
min(
|
|
|
|
|
|
min(count * term->cell_height, /* 'count' number of rows */
|
|
|
|
|
|
sixel->height - img_start_row * term->cell_height), /* What remains of the sixel */
|
|
|
|
|
|
term->height - y - term->margins.bottom));
|
2020-02-21 23:48:45 +01:00
|
|
|
|
|
2020-02-22 00:05:25 +01:00
|
|
|
|
/* Verify we're not stepping outside the grid */
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(x >= term->margins.left);
|
|
|
|
|
|
xassert(y >= term->margins.top);
|
|
|
|
|
|
xassert(width == 0 || x + width <= term->width - term->margins.right);
|
|
|
|
|
|
xassert(height == 0 || y + height <= term->height - term->margins.bottom);
|
2020-02-21 23:48:45 +01:00
|
|
|
|
|
2020-11-13 16:54:40 +01:00
|
|
|
|
//LOG_DBG("sixel chunk: %dx%d %dx%d", x, y, width, height);
|
|
|
|
|
|
|
2020-06-06 14:22:54 +02:00
|
|
|
|
pixman_image_composite32(
|
2021-04-14 11:09:02 +02:00
|
|
|
|
sixel->opaque ? PIXMAN_OP_SRC : PIXMAN_OP_OVER,
|
2020-02-21 23:48:45 +01:00
|
|
|
|
sixel->pix,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
pix,
|
2020-11-13 16:54:40 +01:00
|
|
|
|
0, img_start_row * term->cell_height,
|
2020-02-21 23:48:45 +01:00
|
|
|
|
0, 0,
|
|
|
|
|
|
x, y,
|
|
|
|
|
|
width, height);
|
|
|
|
|
|
|
2020-02-22 00:05:25 +01:00
|
|
|
|
wl_surface_damage_buffer(term->window->surface, x, y, width, height);
|
2020-02-21 23:48:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-13 16:54:40 +01:00
|
|
|
|
static void
|
|
|
|
|
|
render_sixel(struct terminal *term, pixman_image_t *pix,
|
2021-03-09 17:23:55 +01:00
|
|
|
|
const struct coord *cursor, const struct sixel *sixel)
|
2020-11-13 16:54:40 +01:00
|
|
|
|
{
|
|
|
|
|
|
const int view_end = (term->grid->view + term->rows - 1) & (term->grid->num_rows - 1);
|
|
|
|
|
|
const bool last_row_needs_erase = sixel->height % term->cell_height != 0;
|
|
|
|
|
|
const bool last_col_needs_erase = sixel->width % term->cell_width != 0;
|
|
|
|
|
|
|
|
|
|
|
|
int chunk_img_start = -1; /* Image-relative start row of chunk */
|
|
|
|
|
|
int chunk_term_start = -1; /* Viewport relative start row of chunk */
|
|
|
|
|
|
int chunk_row_count = 0; /* Number of rows to emit */
|
|
|
|
|
|
|
|
|
|
|
|
#define maybe_emit_sixel_chunk_then_reset() \
|
|
|
|
|
|
if (chunk_row_count != 0) { \
|
|
|
|
|
|
render_sixel_chunk( \
|
|
|
|
|
|
term, pix, sixel, \
|
|
|
|
|
|
chunk_term_start, chunk_img_start, chunk_row_count); \
|
|
|
|
|
|
chunk_term_start = chunk_img_start = -1; \
|
|
|
|
|
|
chunk_row_count = 0; \
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Iterate all sixel rows:
|
|
|
|
|
|
*
|
|
|
|
|
|
* - ignore rows that aren't visible on-screen
|
|
|
|
|
|
* - ignore rows that aren't dirty (they have already been rendered)
|
|
|
|
|
|
* - chunk consecutive dirty rows into a 'chunk'
|
|
|
|
|
|
* - emit (render) chunk as soon as a row isn't visible, or is clean
|
|
|
|
|
|
* - emit final chunk after we've iterated all rows
|
|
|
|
|
|
*
|
|
|
|
|
|
* The purpose of this is to reduce the amount of pixels that
|
|
|
|
|
|
* needs to be composited and marked as damaged for the
|
|
|
|
|
|
* compositor.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Since we do CPU based composition, rendering is a slow and
|
|
|
|
|
|
* heavy task for foot, and thus it is important to not re-render
|
|
|
|
|
|
* things unnecessarily.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
for (int _abs_row_no = sixel->pos.row;
|
|
|
|
|
|
_abs_row_no < sixel->pos.row + sixel->rows;
|
|
|
|
|
|
_abs_row_no++)
|
|
|
|
|
|
{
|
|
|
|
|
|
const int abs_row_no = _abs_row_no & (term->grid->num_rows - 1);
|
|
|
|
|
|
const int term_row_no =
|
|
|
|
|
|
(abs_row_no - term->grid->view + term->grid->num_rows) &
|
|
|
|
|
|
(term->grid->num_rows - 1);
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if row is in the visible viewport */
|
|
|
|
|
|
if (view_end >= term->grid->view) {
|
|
|
|
|
|
/* Not wrapped */
|
|
|
|
|
|
if (!(abs_row_no >= term->grid->view && abs_row_no <= view_end)) {
|
|
|
|
|
|
/* Not visible */
|
|
|
|
|
|
maybe_emit_sixel_chunk_then_reset();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Wrapped */
|
|
|
|
|
|
if (!(abs_row_no >= term->grid->view || abs_row_no <= view_end)) {
|
|
|
|
|
|
/* Not visible */
|
|
|
|
|
|
maybe_emit_sixel_chunk_then_reset();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Is the row dirty? */
|
|
|
|
|
|
struct row *row = term->grid->rows[abs_row_no];
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(row != NULL); /* Should be visible */
|
2020-11-13 16:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
if (!row->dirty) {
|
|
|
|
|
|
maybe_emit_sixel_chunk_then_reset();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-09 17:32:04 +01:00
|
|
|
|
int cursor_col = cursor->row == term_row_no ? cursor->col : -1;
|
|
|
|
|
|
|
2020-11-13 16:54:40 +01:00
|
|
|
|
/*
|
2021-03-09 17:23:55 +01:00
|
|
|
|
* If image contains transparent parts, render all (dirty)
|
|
|
|
|
|
* cells beneath it.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If image is opaque, loop cells and set their 'clean' bit,
|
|
|
|
|
|
* to prevent the grid rendered from overwriting the sixel
|
2020-11-13 16:54:40 +01:00
|
|
|
|
*
|
|
|
|
|
|
* If the last sixel row only partially covers the cell row,
|
|
|
|
|
|
* 'erase' the cell by rendering them.
|
2021-03-09 17:23:55 +01:00
|
|
|
|
*
|
|
|
|
|
|
* In all cases, do *not* clear the ‘dirty’ bit on the row, to
|
|
|
|
|
|
* ensure the regular renderer includes them in the damage
|
|
|
|
|
|
* rect.
|
2020-11-13 16:54:40 +01:00
|
|
|
|
*/
|
2021-03-09 17:23:55 +01:00
|
|
|
|
if (!sixel->opaque) {
|
|
|
|
|
|
/* TODO: multithreading */
|
|
|
|
|
|
int cursor_col = cursor->row == term_row_no ? cursor->col : -1;
|
|
|
|
|
|
render_row(term, pix, row, term_row_no, cursor_col);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (int col = sixel->pos.col;
|
|
|
|
|
|
col < min(sixel->pos.col + sixel->cols, term->cols);
|
|
|
|
|
|
col++)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct cell *cell = &row->cells[col];
|
|
|
|
|
|
|
|
|
|
|
|
if (!cell->attrs.clean) {
|
|
|
|
|
|
bool last_row = abs_row_no == sixel->pos.row + sixel->rows - 1;
|
|
|
|
|
|
bool last_col = col == sixel->pos.col + sixel->cols - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ((last_row_needs_erase && last_row) ||
|
|
|
|
|
|
(last_col_needs_erase && last_col))
|
|
|
|
|
|
{
|
2021-03-09 17:32:04 +01:00
|
|
|
|
render_cell(term, pix, row, col, term_row_no, cursor_col == col);
|
2021-03-09 17:23:55 +01:00
|
|
|
|
} else
|
|
|
|
|
|
cell->attrs.clean = 1;
|
|
|
|
|
|
}
|
2020-11-13 16:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (chunk_term_start == -1) {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(chunk_img_start == -1);
|
2020-11-13 16:54:40 +01:00
|
|
|
|
chunk_term_start = term_row_no;
|
|
|
|
|
|
chunk_img_start = _abs_row_no - sixel->pos.row;
|
|
|
|
|
|
chunk_row_count = 1;
|
|
|
|
|
|
} else
|
|
|
|
|
|
chunk_row_count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
maybe_emit_sixel_chunk_then_reset();
|
|
|
|
|
|
#undef maybe_emit_sixel_chunk_then_reset
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-21 23:48:45 +01:00
|
|
|
|
static void
|
2021-03-09 17:23:55 +01:00
|
|
|
|
render_sixel_images(struct terminal *term, pixman_image_t *pix,
|
|
|
|
|
|
const struct coord *cursor)
|
2020-02-21 23:48:45 +01:00
|
|
|
|
{
|
2020-06-28 14:19:43 +02:00
|
|
|
|
if (likely(tll_length(term->grid->sixel_images)) == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
const int scrollback_end
|
|
|
|
|
|
= (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
|
|
|
|
|
|
|
|
|
|
|
|
const int view_start
|
|
|
|
|
|
= (term->grid->view
|
|
|
|
|
|
- scrollback_end
|
|
|
|
|
|
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
2020-06-28 10:45:30 +02:00
|
|
|
|
|
2020-06-28 14:19:43 +02:00
|
|
|
|
const int view_end = view_start + term->rows - 1;
|
|
|
|
|
|
|
|
|
|
|
|
//LOG_DBG("SIXELS: %zu images, view=%d-%d",
|
|
|
|
|
|
// tll_length(term->grid->sixel_images), view_start, view_end);
|
2020-06-28 10:45:30 +02:00
|
|
|
|
|
|
|
|
|
|
tll_foreach(term->grid->sixel_images, it) {
|
|
|
|
|
|
const struct sixel *six = &it->item;
|
2020-06-28 14:19:43 +02:00
|
|
|
|
const int start
|
|
|
|
|
|
= (six->pos.row
|
|
|
|
|
|
- scrollback_end
|
|
|
|
|
|
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
2020-06-28 10:45:30 +02:00
|
|
|
|
const int end = start + six->rows - 1;
|
|
|
|
|
|
|
|
|
|
|
|
//LOG_DBG(" sixel: %d-%d", start, end);
|
|
|
|
|
|
if (start > view_end) {
|
|
|
|
|
|
/* Sixel starts after view ends, no need to try to render it */
|
|
|
|
|
|
continue;
|
|
|
|
|
|
} else if (end < view_start) {
|
|
|
|
|
|
/* Image ends before view starts. Since the image list is
|
|
|
|
|
|
* sorted, we can safely stop here */
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-09 17:23:55 +01:00
|
|
|
|
render_sixel(term, pix, cursor, &it->item);
|
2020-06-28 10:45:30 +02:00
|
|
|
|
}
|
2020-02-21 23:48:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2020-12-02 18:52:50 +01:00
|
|
|
|
static void
|
2021-03-23 13:03:07 +01:00
|
|
|
|
render_ime_preedit_for_seat(struct terminal *term, struct seat *seat,
|
|
|
|
|
|
struct buffer *buf)
|
2020-12-02 18:52:50 +01:00
|
|
|
|
{
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (likely(seat->ime.preedit.cells == NULL))
|
2020-12-02 18:52:50 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-12-05 11:42:21 +01:00
|
|
|
|
if (unlikely(term->is_searching))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-12-03 18:38:26 +01:00
|
|
|
|
/* Adjust cursor position to viewport */
|
|
|
|
|
|
struct coord cursor;
|
|
|
|
|
|
cursor = term->grid->cursor.point;
|
|
|
|
|
|
cursor.row += term->grid->offset;
|
|
|
|
|
|
cursor.row -= term->grid->view;
|
|
|
|
|
|
cursor.row &= term->grid->num_rows - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor.row < 0 || cursor.row >= term->rows)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
int cells_needed = seat->ime.preedit.count;
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (seat->ime.preedit.cursor.start == cells_needed &&
|
|
|
|
|
|
seat->ime.preedit.cursor.end == cells_needed)
|
2021-01-25 21:57:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
/* Cursor will be drawn *after* the pre-edit string, i.e. in
|
|
|
|
|
|
* the cell *after*. This means we need to copy, and dirty,
|
|
|
|
|
|
* one extra cell from the original grid, or we’ll leave
|
|
|
|
|
|
* trailing “cursors” after us if the user deletes text while
|
|
|
|
|
|
* pre-editing */
|
|
|
|
|
|
cells_needed++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-02 18:52:50 +01:00
|
|
|
|
int row_idx = cursor.row;
|
|
|
|
|
|
int col_idx = cursor.col;
|
2020-12-08 19:17:46 +01:00
|
|
|
|
int ime_ofs = 0; /* Offset into pre-edit string to start rendering at */
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
|
|
|
|
|
int cells_left = term->cols - cursor.col;
|
|
|
|
|
|
int cells_used = min(cells_needed, term->cols);
|
|
|
|
|
|
|
|
|
|
|
|
/* Adjust start of pre-edit text to the left if string doesn't fit on row */
|
|
|
|
|
|
if (cells_left < cells_used)
|
|
|
|
|
|
col_idx -= cells_used - cells_left;
|
|
|
|
|
|
|
2020-12-08 19:17:46 +01:00
|
|
|
|
if (cells_needed > cells_used) {
|
2021-03-23 13:03:07 +01:00
|
|
|
|
int start = seat->ime.preedit.cursor.start;
|
|
|
|
|
|
int end = seat->ime.preedit.cursor.end;
|
2020-12-08 19:17:46 +01:00
|
|
|
|
|
|
|
|
|
|
if (start == end) {
|
|
|
|
|
|
/* Ensure *end* of pre-edit string is visible */
|
|
|
|
|
|
ime_ofs = cells_needed - cells_used;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Ensure the *beginning* of the cursor-area is visible */
|
|
|
|
|
|
ime_ofs = start;
|
|
|
|
|
|
|
|
|
|
|
|
/* Display as much as possible of the pre-edit string */
|
|
|
|
|
|
if (cells_needed - ime_ofs < cells_used)
|
|
|
|
|
|
ime_ofs = cells_needed - cells_used;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Make sure we don't start in the middle of a character */
|
|
|
|
|
|
while (ime_ofs < cells_needed &&
|
term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition
Instead of using CELL_SPACER for *all* cells that previously used
CELL_MULT_COL_SPACER, include the remaining number of spacers
following, and including, itself. This is encoded by adding to the
CELL_SPACER value.
So, a double width character will now store the character itself in
the first cell (just like before), and CELL_SPACER+1 in the second
cell.
A three-cell character would store the character itself, then
CELL_SPACER+2, and finally CELL_SPACER+1.
In other words, the last spacer is always CELL_SPACER+1.
CELL_SPACER+0 is used when padding at the right margin. I.e. when
writing e.g. a double width character in the last column, we insert a
CELL_SPACER+0 pad character, and then write the double width character
in the first column on the next row.
2021-05-14 14:41:02 +02:00
|
|
|
|
seat->ime.preedit.cells[ime_ofs].wc >= CELL_SPACER)
|
2020-12-08 19:17:46 +01:00
|
|
|
|
{
|
|
|
|
|
|
ime_ofs++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(col_idx >= 0);
|
|
|
|
|
|
xassert(col_idx < term->cols);
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, row_idx);
|
|
|
|
|
|
|
|
|
|
|
|
/* Don't start pre-edit text in the middle of a double-width character */
|
term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition
Instead of using CELL_SPACER for *all* cells that previously used
CELL_MULT_COL_SPACER, include the remaining number of spacers
following, and including, itself. This is encoded by adding to the
CELL_SPACER value.
So, a double width character will now store the character itself in
the first cell (just like before), and CELL_SPACER+1 in the second
cell.
A three-cell character would store the character itself, then
CELL_SPACER+2, and finally CELL_SPACER+1.
In other words, the last spacer is always CELL_SPACER+1.
CELL_SPACER+0 is used when padding at the right margin. I.e. when
writing e.g. a double width character in the last column, we insert a
CELL_SPACER+0 pad character, and then write the double width character
in the first column on the next row.
2021-05-14 14:41:02 +02:00
|
|
|
|
while (col_idx > 0 && row->cells[col_idx].wc >= CELL_SPACER) {
|
2020-12-02 18:52:50 +01:00
|
|
|
|
cells_used++;
|
|
|
|
|
|
col_idx--;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Copy original content (render_cell() reads cell data directly
|
|
|
|
|
|
* from grid), and mark all cells as dirty. This ensures they are
|
|
|
|
|
|
* re-rendered when the pre-edit text is modified or removed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct cell *real_cells = malloc(cells_used * sizeof(real_cells[0]));
|
|
|
|
|
|
for (int i = 0; i < cells_used; i++) {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(col_idx + i < term->cols);
|
2020-12-02 18:52:50 +01:00
|
|
|
|
real_cells[i] = row->cells[col_idx + i];
|
|
|
|
|
|
real_cells[i].attrs.clean = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
row->dirty = true;
|
|
|
|
|
|
|
|
|
|
|
|
/* Render pre-edit text */
|
term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition
Instead of using CELL_SPACER for *all* cells that previously used
CELL_MULT_COL_SPACER, include the remaining number of spacers
following, and including, itself. This is encoded by adding to the
CELL_SPACER value.
So, a double width character will now store the character itself in
the first cell (just like before), and CELL_SPACER+1 in the second
cell.
A three-cell character would store the character itself, then
CELL_SPACER+2, and finally CELL_SPACER+1.
In other words, the last spacer is always CELL_SPACER+1.
CELL_SPACER+0 is used when padding at the right margin. I.e. when
writing e.g. a double width character in the last column, we insert a
CELL_SPACER+0 pad character, and then write the double width character
in the first column on the next row.
2021-05-14 14:41:02 +02:00
|
|
|
|
xassert(seat->ime.preedit.cells[ime_ofs].wc < CELL_SPACER);
|
2021-03-23 13:03:07 +01:00
|
|
|
|
for (int i = 0, idx = ime_ofs; idx < seat->ime.preedit.count; i++, idx++) {
|
|
|
|
|
|
const struct cell *cell = &seat->ime.preedit.cells[idx];
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition
Instead of using CELL_SPACER for *all* cells that previously used
CELL_MULT_COL_SPACER, include the remaining number of spacers
following, and including, itself. This is encoded by adding to the
CELL_SPACER value.
So, a double width character will now store the character itself in
the first cell (just like before), and CELL_SPACER+1 in the second
cell.
A three-cell character would store the character itself, then
CELL_SPACER+2, and finally CELL_SPACER+1.
In other words, the last spacer is always CELL_SPACER+1.
CELL_SPACER+0 is used when padding at the right margin. I.e. when
writing e.g. a double width character in the last column, we insert a
CELL_SPACER+0 pad character, and then write the double width character
in the first column on the next row.
2021-05-14 14:41:02 +02:00
|
|
|
|
if (cell->wc >= CELL_SPACER)
|
2020-12-02 18:52:50 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-12-08 19:17:46 +01:00
|
|
|
|
int width = max(1, wcwidth(cell->wc));
|
2020-12-02 18:52:50 +01:00
|
|
|
|
if (col_idx + i + width > term->cols)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-12-08 19:17:46 +01:00
|
|
|
|
row->cells[col_idx + i] = *cell;
|
2020-12-02 18:52:50 +01:00
|
|
|
|
render_cell(term, buf->pix[0], row, col_idx + i, row_idx, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
int start = seat->ime.preedit.cursor.start - ime_ofs;
|
|
|
|
|
|
int end = seat->ime.preedit.cursor.end - ime_ofs;
|
2020-12-03 18:39:34 +01:00
|
|
|
|
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (!seat->ime.preedit.cursor.hidden) {
|
|
|
|
|
|
const struct cell *start_cell = &seat->ime.preedit.cells[0];
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
|
|
|
|
|
pixman_color_t fg = color_hex_to_pixman(term->colors.fg);
|
|
|
|
|
|
pixman_color_t bg = color_hex_to_pixman(term->colors.bg);
|
|
|
|
|
|
|
|
|
|
|
|
pixman_color_t cursor_color, text_color;
|
|
|
|
|
|
cursor_colors_for_cell(
|
2020-12-04 18:43:06 +01:00
|
|
|
|
term, start_cell, &fg, &bg, &cursor_color, &text_color);
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
|
|
|
|
|
int x = term->margins.left + (col_idx + start) * term->cell_width;
|
|
|
|
|
|
int y = term->margins.top + row_idx * term->cell_height;
|
|
|
|
|
|
|
2020-12-04 18:43:06 +01:00
|
|
|
|
if (end == start) {
|
|
|
|
|
|
/* Bar */
|
2020-12-08 19:17:46 +01:00
|
|
|
|
if (start >= 0) {
|
|
|
|
|
|
struct fcft_font *font = attrs_to_font(term, &start_cell->attrs);
|
2021-04-30 20:31:47 +02:00
|
|
|
|
draw_beam(term, buf->pix[0], font, &cursor_color, x, y);
|
2020-12-08 19:17:46 +01:00
|
|
|
|
}
|
2020-12-20 15:01:21 -07:00
|
|
|
|
term_ime_set_cursor_rect(term, x, y, 1, term->cell_height);
|
2020-12-04 18:43:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (end > start) {
|
|
|
|
|
|
/* Hollow cursor */
|
2020-12-08 19:17:46 +01:00
|
|
|
|
if (start >= 0 && end <= term->cols) {
|
|
|
|
|
|
int cols = end - start;
|
|
|
|
|
|
draw_unfocused_block(term, buf->pix[0], &cursor_color, x, y, cols);
|
|
|
|
|
|
}
|
2020-12-20 15:01:21 -07:00
|
|
|
|
|
|
|
|
|
|
term_ime_set_cursor_rect(
|
|
|
|
|
|
term, x, y, (end - start) * term->cell_width, term->cell_height);
|
2020-12-04 18:43:06 +01:00
|
|
|
|
}
|
2020-12-02 18:52:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Restore original content (but do not render) */
|
|
|
|
|
|
for (int i = 0; i < cells_used; i++)
|
|
|
|
|
|
row->cells[col_idx + i] = real_cells[i];
|
|
|
|
|
|
free(real_cells);
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface,
|
|
|
|
|
|
term->margins.left,
|
|
|
|
|
|
term->margins.top + row_idx * term->cell_height,
|
|
|
|
|
|
term->width - term->margins.left - term->margins.right,
|
|
|
|
|
|
1 * term->cell_height);
|
2021-03-23 13:03:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_ime_preedit(struct terminal *term, struct buffer *buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
|
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term)
|
|
|
|
|
|
render_ime_preedit_for_seat(term, &it->item, buf);
|
|
|
|
|
|
}
|
2020-12-03 18:36:56 +01:00
|
|
|
|
#endif
|
2020-12-02 18:52:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-29 20:13:26 +02:00
|
|
|
|
int
|
|
|
|
|
|
render_worker_thread(void *_ctx)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct render_worker_context *ctx = _ctx;
|
|
|
|
|
|
struct terminal *term = ctx->term;
|
|
|
|
|
|
const int my_id = ctx->my_id;
|
2019-10-28 18:48:43 +01:00
|
|
|
|
free(ctx);
|
2019-07-29 20:13:26 +02:00
|
|
|
|
|
2021-02-10 16:22:36 +01:00
|
|
|
|
sigset_t mask;
|
|
|
|
|
|
sigfillset(&mask);
|
|
|
|
|
|
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
|
|
|
|
|
|
2019-08-01 20:09:16 +02:00
|
|
|
|
char proc_title[16];
|
|
|
|
|
|
snprintf(proc_title, sizeof(proc_title), "foot:render:%d", my_id);
|
|
|
|
|
|
|
render: set thread name in a portable way
prctl is Linux-only but pthread_setname_np is same as PR_SET_NAME.
Solaris and FreeBSD >= 13 have pthread_setname_np similar to Linux.
DragonFly, OpenBSD, FreeBSD < 13 lack pthread_setname_np but provide
pthread_set_name_np which doesn't return a value. NetBSD requires 3
arguments for pthread_setname_np where the last one is void *.
render.c:8:10: fatal error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
^~~~~~~~~~~~~
render.c:1234:9: error: implicit declaration of function 'prctl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
render.c:1234:15: error: use of undeclared identifier 'PR_SET_NAME'
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
2021-01-19 14:49:43 +00:00
|
|
|
|
if (pthread_setname_np(pthread_self(), proc_title) < 0)
|
2019-08-01 20:09:16 +02:00
|
|
|
|
LOG_ERRNO("render worker %d: failed to set process title", my_id);
|
|
|
|
|
|
|
2019-07-29 20:13:26 +02:00
|
|
|
|
sem_t *start = &term->render.workers.start;
|
|
|
|
|
|
sem_t *done = &term->render.workers.done;
|
|
|
|
|
|
mtx_t *lock = &term->render.workers.lock;
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
sem_wait(start);
|
|
|
|
|
|
|
|
|
|
|
|
struct buffer *buf = term->render.workers.buf;
|
|
|
|
|
|
bool frame_done = false;
|
|
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
/* Translate offset-relative cursor row to view-relative */
|
|
|
|
|
|
struct coord cursor = {-1, -1};
|
|
|
|
|
|
if (!term->hide_cursor) {
|
|
|
|
|
|
cursor = term->grid->cursor.point;
|
|
|
|
|
|
cursor.row += term->grid->offset;
|
|
|
|
|
|
cursor.row -= term->grid->view;
|
|
|
|
|
|
cursor.row &= term->grid->num_rows - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-29 20:13:26 +02:00
|
|
|
|
while (!frame_done) {
|
|
|
|
|
|
mtx_lock(lock);
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(tll_length(term->render.workers.queue) > 0);
|
2019-07-29 20:13:26 +02:00
|
|
|
|
|
|
|
|
|
|
int row_no = tll_pop_front(term->render.workers.queue);
|
|
|
|
|
|
mtx_unlock(lock);
|
|
|
|
|
|
|
|
|
|
|
|
switch (row_no) {
|
render: remove most of the special handling of cursor rendering
Previously, we had to explicitly render the old cursor cell *before*
applying scrolling damage.
We then rendered all the dirty rows, *without* rendering the cursor -
even if the cursor cell was among the dirty rows.
Finally, when everything else was done, we explicitly rendered the
cursor cell.
This meant a lot of code, and unnecessary render_cell() calls, along
with unnecessary wl_surface_damage_buffer() calls.
This was a necessary in the early design of foot, but not anymore.
We can simply mark both the old cursor cell, and the current one, as
dirty and let the normal rendering framework render it. All we need to
do is pass the cursor column to render_row(), so that it can pass
has_cursor=true in the appropriate call to render_cell(). We pass -1
here for all rows, except the cursor's row, where we pass the actual
cursor column.
With this, there's no need to calculate whether the cursor is visible
or not; just mark it's cell as dirty, and if that row is visible, the
normal rendering will take care of it.
This also simplifies the state needed to be saved between two frames;
we only need a row pointer, and the cursor column index.
Part of https://codeberg.org/dnkl/foot/issues/35
2020-07-12 12:56:10 +02:00
|
|
|
|
default: {
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(buf != NULL);
|
render: remove most of the special handling of cursor rendering
Previously, we had to explicitly render the old cursor cell *before*
applying scrolling damage.
We then rendered all the dirty rows, *without* rendering the cursor -
even if the cursor cell was among the dirty rows.
Finally, when everything else was done, we explicitly rendered the
cursor cell.
This meant a lot of code, and unnecessary render_cell() calls, along
with unnecessary wl_surface_damage_buffer() calls.
This was a necessary in the early design of foot, but not anymore.
We can simply mark both the old cursor cell, and the current one, as
dirty and let the normal rendering framework render it. All we need to
do is pass the cursor column to render_row(), so that it can pass
has_cursor=true in the appropriate call to render_cell(). We pass -1
here for all rows, except the cursor's row, where we pass the actual
cursor column.
With this, there's no need to calculate whether the cursor is visible
or not; just mark it's cell as dirty, and if that row is visible, the
normal rendering will take care of it.
This also simplifies the state needed to be saved between two frames;
we only need a row pointer, and the cursor column index.
Part of https://codeberg.org/dnkl/foot/issues/35
2020-07-12 12:56:10 +02:00
|
|
|
|
|
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, row_no);
|
2020-07-13 13:44:52 +02:00
|
|
|
|
int cursor_col = cursor.row == row_no ? cursor.col : -1;
|
render: remove most of the special handling of cursor rendering
Previously, we had to explicitly render the old cursor cell *before*
applying scrolling damage.
We then rendered all the dirty rows, *without* rendering the cursor -
even if the cursor cell was among the dirty rows.
Finally, when everything else was done, we explicitly rendered the
cursor cell.
This meant a lot of code, and unnecessary render_cell() calls, along
with unnecessary wl_surface_damage_buffer() calls.
This was a necessary in the early design of foot, but not anymore.
We can simply mark both the old cursor cell, and the current one, as
dirty and let the normal rendering framework render it. All we need to
do is pass the cursor column to render_row(), so that it can pass
has_cursor=true in the appropriate call to render_cell(). We pass -1
here for all rows, except the cursor's row, where we pass the actual
cursor column.
With this, there's no need to calculate whether the cursor is visible
or not; just mark it's cell as dirty, and if that row is visible, the
normal rendering will take care of it.
This also simplifies the state needed to be saved between two frames;
we only need a row pointer, and the cursor column index.
Part of https://codeberg.org/dnkl/foot/issues/35
2020-07-12 12:56:10 +02:00
|
|
|
|
|
|
|
|
|
|
render_row(term, buf->pix[my_id], row, row_no, cursor_col);
|
2019-07-29 20:13:26 +02:00
|
|
|
|
break;
|
render: remove most of the special handling of cursor rendering
Previously, we had to explicitly render the old cursor cell *before*
applying scrolling damage.
We then rendered all the dirty rows, *without* rendering the cursor -
even if the cursor cell was among the dirty rows.
Finally, when everything else was done, we explicitly rendered the
cursor cell.
This meant a lot of code, and unnecessary render_cell() calls, along
with unnecessary wl_surface_damage_buffer() calls.
This was a necessary in the early design of foot, but not anymore.
We can simply mark both the old cursor cell, and the current one, as
dirty and let the normal rendering framework render it. All we need to
do is pass the cursor column to render_row(), so that it can pass
has_cursor=true in the appropriate call to render_cell(). We pass -1
here for all rows, except the cursor's row, where we pass the actual
cursor column.
With this, there's no need to calculate whether the cursor is visible
or not; just mark it's cell as dirty, and if that row is visible, the
normal rendering will take care of it.
This also simplifies the state needed to be saved between two frames;
we only need a row pointer, and the cursor column index.
Part of https://codeberg.org/dnkl/foot/issues/35
2020-07-12 12:56:10 +02:00
|
|
|
|
}
|
2019-07-29 20:13:26 +02:00
|
|
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
|
|
frame_done = true;
|
|
|
|
|
|
sem_post(done);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case -2:
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
2019-07-24 20:31:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
struct csd_data {
|
|
|
|
|
|
int x;
|
|
|
|
|
|
int y;
|
|
|
|
|
|
int width;
|
|
|
|
|
|
int height;
|
|
|
|
|
|
};
|
2020-02-23 14:17:48 +01:00
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
|
static struct csd_data
|
2020-02-29 18:02:38 +01:00
|
|
|
|
get_csd_data(const struct terminal *term, enum csd_surface surf_idx)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->use_csd == CSD_YES);
|
2020-02-26 12:39:17 +01:00
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
/* Only title bar is rendered in maximized mode */
|
|
|
|
|
|
const int border_width = !term->window->is_maximized
|
2020-03-02 18:42:49 +01:00
|
|
|
|
? term->conf->csd.border_width * term->scale : 0;
|
2020-02-28 18:49:34 +01:00
|
|
|
|
|
2020-09-09 18:43:23 +02:00
|
|
|
|
const int title_height = term->window->is_fullscreen
|
|
|
|
|
|
? 0
|
|
|
|
|
|
: term->conf->csd.title_height * term->scale;
|
2020-02-26 12:17:58 +01:00
|
|
|
|
|
2020-03-02 20:29:28 +01:00
|
|
|
|
const int button_width = !term->window->is_fullscreen
|
|
|
|
|
|
? term->conf->csd.button_width * term->scale : 0;
|
|
|
|
|
|
|
2020-09-09 18:43:23 +02:00
|
|
|
|
const int button_close_width = term->width >= 1 * button_width
|
|
|
|
|
|
? button_width : 0;
|
|
|
|
|
|
|
|
|
|
|
|
const int button_maximize_width = term->width >= 2 * button_width
|
|
|
|
|
|
? button_width : 0;
|
|
|
|
|
|
|
|
|
|
|
|
const int button_minimize_width = term->width >= 3 * button_width
|
|
|
|
|
|
? button_width : 0;
|
|
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
|
switch (surf_idx) {
|
2020-09-09 18:43:23 +02:00
|
|
|
|
case CSD_SURF_TITLE: return (struct csd_data){ 0, -title_height, term->width, title_height};
|
2020-03-01 12:28:01 +01:00
|
|
|
|
case CSD_SURF_LEFT: return (struct csd_data){-border_width, -title_height, border_width, title_height + term->height};
|
|
|
|
|
|
case CSD_SURF_RIGHT: return (struct csd_data){ term->width, -title_height, border_width, title_height + term->height};
|
|
|
|
|
|
case CSD_SURF_TOP: return (struct csd_data){-border_width, -title_height - border_width, term->width + 2 * border_width, border_width};
|
|
|
|
|
|
case CSD_SURF_BOTTOM: return (struct csd_data){-border_width, term->height, term->width + 2 * border_width, border_width};
|
|
|
|
|
|
|
2020-03-02 20:29:28 +01:00
|
|
|
|
/* Positioned relative to CSD_SURF_TITLE */
|
2020-09-09 18:43:23 +02:00
|
|
|
|
case CSD_SURF_MINIMIZE: return (struct csd_data){term->width - 3 * button_width, 0, button_minimize_width, title_height};
|
|
|
|
|
|
case CSD_SURF_MAXIMIZE: return (struct csd_data){term->width - 2 * button_width, 0, button_maximize_width, title_height};
|
|
|
|
|
|
case CSD_SURF_CLOSE: return (struct csd_data){term->width - 1 * button_width, 0, button_close_width, title_height};
|
2020-03-02 20:29:28 +01:00
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
|
case CSD_SURF_COUNT:
|
2021-02-09 13:52:33 +00:00
|
|
|
|
break;
|
2020-03-01 12:28:01 +01:00
|
|
|
|
}
|
2020-02-28 18:49:34 +01:00
|
|
|
|
|
2021-02-09 13:52:33 +00:00
|
|
|
|
BUG("Invalid csd_surface type");
|
2020-08-23 07:42:20 +02:00
|
|
|
|
return (struct csd_data){0};
|
2020-02-29 18:02:38 +01:00
|
|
|
|
}
|
2020-02-28 18:51:09 +01:00
|
|
|
|
|
2020-03-02 21:06:15 +01:00
|
|
|
|
static void
|
|
|
|
|
|
csd_commit(struct terminal *term, struct wl_surface *surf, struct buffer *buf)
|
|
|
|
|
|
{
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(buf->width % term->scale == 0);
|
|
|
|
|
|
xassert(buf->height % term->scale == 0);
|
|
|
|
|
|
|
2020-03-02 21:06:15 +01:00
|
|
|
|
wl_surface_attach(surf, buf->wl_buf, 0, 0);
|
|
|
|
|
|
wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height);
|
|
|
|
|
|
wl_surface_set_buffer_scale(surf, term->scale);
|
|
|
|
|
|
wl_surface_commit(surf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
static void
|
|
|
|
|
|
render_csd_part(struct terminal *term,
|
|
|
|
|
|
struct wl_surface *surf, struct buffer *buf,
|
|
|
|
|
|
int width, int height, pixman_color_t *color)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->use_csd == CSD_YES);
|
2020-02-23 14:17:48 +01:00
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(color);
|
2020-02-23 14:17:48 +01:00
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
pixman_image_fill_rectangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], color, 1,
|
2020-02-29 18:02:38 +01:00
|
|
|
|
&(pixman_rectangle16_t){0, 0, buf->width, buf->height});
|
|
|
|
|
|
pixman_image_unref(src);
|
|
|
|
|
|
}
|
2020-02-25 19:09:29 +01:00
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
static void
|
2020-02-29 18:02:38 +01:00
|
|
|
|
render_csd_title(struct terminal *term)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->use_csd == CSD_YES);
|
2020-03-03 18:23:37 +01:00
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
|
struct csd_data info = get_csd_data(term, CSD_SURF_TITLE);
|
2021-02-12 11:39:25 +01:00
|
|
|
|
struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE].surf;
|
2020-02-23 14:17:48 +01:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(info.width > 0 && info.height > 0);
|
2020-03-01 13:17:54 +01:00
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(info.width % term->scale == 0);
|
|
|
|
|
|
xassert(info.height % term->scale == 0);
|
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE);
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
term->wl->shm, info.width, info.height, cookie, false, 1);
|
2020-02-23 14:17:48 +01:00
|
|
|
|
|
2021-04-07 08:07:43 +02:00
|
|
|
|
uint32_t _color = term->conf->colors.fg;
|
2020-03-02 18:42:49 +01:00
|
|
|
|
uint16_t alpha = 0xffff;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->conf->csd.color.title_set) {
|
|
|
|
|
|
_color = term->conf->csd.color.title;
|
|
|
|
|
|
alpha = _color >> 24 | (_color >> 24 << 8);
|
|
|
|
|
|
}
|
2020-02-25 19:09:29 +01:00
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
if (!term->visual_focus)
|
2020-11-15 20:05:01 +01:00
|
|
|
|
_color = color_dim(_color);
|
|
|
|
|
|
|
|
|
|
|
|
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
|
2020-03-01 12:28:01 +01:00
|
|
|
|
render_csd_part(term, surf, buf, info.width, info.height, &color);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
csd_commit(term, surf, buf);
|
2020-02-29 18:02:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_csd_border(struct terminal *term, enum csd_surface surf_idx)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->use_csd == CSD_YES);
|
|
|
|
|
|
xassert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM);
|
2020-02-29 18:02:38 +01:00
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
|
struct csd_data info = get_csd_data(term, surf_idx);
|
2021-02-12 11:39:25 +01:00
|
|
|
|
struct wl_surface *surf = term->window->csd.surface[surf_idx].surf;
|
2020-02-29 18:02:38 +01:00
|
|
|
|
|
2020-03-01 13:17:54 +01:00
|
|
|
|
if (info.width == 0 || info.height == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(info.width % term->scale == 0);
|
|
|
|
|
|
xassert(info.height % term->scale == 0);
|
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
unsigned long cookie = shm_cookie_csd(term, surf_idx);
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
term->wl->shm, info.width, info.height, cookie, false, 1);
|
2020-02-29 18:02:38 +01:00
|
|
|
|
|
2020-03-03 18:18:59 +01:00
|
|
|
|
pixman_color_t color = color_hex_to_pixman_with_alpha(0, 0);
|
2020-03-01 12:28:01 +01:00
|
|
|
|
render_csd_part(term, surf, buf, info.width, info.height, &color);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
csd_commit(term, surf, buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_csd_button_minimize(struct terminal *term, struct buffer *buf)
|
|
|
|
|
|
{
|
2021-04-07 08:07:43 +02:00
|
|
|
|
pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(&color);
|
|
|
|
|
|
|
2020-03-06 19:15:09 +01:00
|
|
|
|
const int max_height = buf->height / 2;
|
|
|
|
|
|
const int max_width = buf->width / 2;
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
2020-03-06 19:15:09 +01:00
|
|
|
|
int width = max_width;
|
|
|
|
|
|
int height = max_width / 2;
|
|
|
|
|
|
|
|
|
|
|
|
if (height > max_height) {
|
|
|
|
|
|
height = max_height;
|
|
|
|
|
|
width = height * 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(width <= max_width);
|
|
|
|
|
|
xassert(height <= max_height);
|
2020-03-06 19:15:09 +01:00
|
|
|
|
|
|
|
|
|
|
int x_margin = (buf->width - width) / 2.;
|
|
|
|
|
|
int y_margin = (buf->height - height) / 2.;
|
|
|
|
|
|
|
|
|
|
|
|
pixman_triangle_t tri = {
|
|
|
|
|
|
.p1 = {
|
|
|
|
|
|
.x = pixman_int_to_fixed(x_margin),
|
|
|
|
|
|
.y = pixman_int_to_fixed(y_margin),
|
|
|
|
|
|
},
|
|
|
|
|
|
.p2 = {
|
|
|
|
|
|
.x = pixman_int_to_fixed(x_margin + width),
|
|
|
|
|
|
.y = pixman_int_to_fixed(y_margin),
|
|
|
|
|
|
},
|
|
|
|
|
|
.p3 = {
|
|
|
|
|
|
.x = pixman_int_to_fixed(buf->width / 2),
|
|
|
|
|
|
.y = pixman_int_to_fixed(y_margin + height),
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
2020-03-06 19:15:09 +01:00
|
|
|
|
pixman_composite_triangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1,
|
2020-03-06 19:15:09 +01:00
|
|
|
|
0, 0, 0, 0, 1, &tri);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
pixman_image_unref(src);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-06 19:15:09 +01:00
|
|
|
|
render_csd_button_maximize_maximized(
|
|
|
|
|
|
struct terminal *term, struct buffer *buf)
|
2020-03-02 21:06:15 +01:00
|
|
|
|
{
|
2021-04-07 08:07:43 +02:00
|
|
|
|
pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(&color);
|
|
|
|
|
|
|
2020-03-06 19:15:09 +01:00
|
|
|
|
const int max_height = buf->height / 3;
|
|
|
|
|
|
const int max_width = buf->width / 3;
|
|
|
|
|
|
|
|
|
|
|
|
int width = min(max_height, max_width);
|
|
|
|
|
|
int thick = 1 * term->scale;
|
|
|
|
|
|
|
|
|
|
|
|
const int x_margin = (buf->width - width) / 2;
|
|
|
|
|
|
const int y_margin = (buf->height - width) / 2;
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &color, 4,
|
2020-03-06 19:15:09 +01:00
|
|
|
|
(pixman_rectangle16_t[]){
|
|
|
|
|
|
{x_margin, y_margin, width, thick},
|
|
|
|
|
|
{x_margin, y_margin + thick, thick, width - 2 * thick},
|
|
|
|
|
|
{x_margin + width - thick, y_margin + thick, thick, width - 2 * thick},
|
|
|
|
|
|
{x_margin, y_margin + width - thick, width, thick}});
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
pixman_image_unref(src);
|
2020-03-06 19:15:09 +01:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_csd_button_maximize_window(
|
|
|
|
|
|
struct terminal *term, struct buffer *buf)
|
|
|
|
|
|
{
|
2021-04-07 08:07:43 +02:00
|
|
|
|
pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
|
2020-03-06 19:15:09 +01:00
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(&color);
|
|
|
|
|
|
|
|
|
|
|
|
const int max_height = buf->height / 2;
|
|
|
|
|
|
const int max_width = buf->width / 2;
|
|
|
|
|
|
|
|
|
|
|
|
int width = max_width;
|
|
|
|
|
|
int height = max_width / 2;
|
|
|
|
|
|
|
|
|
|
|
|
if (height > max_height) {
|
|
|
|
|
|
height = max_height;
|
|
|
|
|
|
width = height * 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(width <= max_width);
|
|
|
|
|
|
xassert(height <= max_height);
|
2020-03-06 19:15:09 +01:00
|
|
|
|
|
|
|
|
|
|
int x_margin = (buf->width - width) / 2.;
|
|
|
|
|
|
int y_margin = (buf->height - height) / 2.;
|
|
|
|
|
|
|
|
|
|
|
|
pixman_triangle_t tri = {
|
|
|
|
|
|
.p1 = {
|
|
|
|
|
|
.x = pixman_int_to_fixed(buf->width / 2),
|
|
|
|
|
|
.y = pixman_int_to_fixed(y_margin),
|
|
|
|
|
|
},
|
|
|
|
|
|
.p2 = {
|
|
|
|
|
|
.x = pixman_int_to_fixed(x_margin),
|
|
|
|
|
|
.y = pixman_int_to_fixed(y_margin + height),
|
|
|
|
|
|
},
|
|
|
|
|
|
.p3 = {
|
|
|
|
|
|
.x = pixman_int_to_fixed(x_margin + width),
|
|
|
|
|
|
.y = pixman_int_to_fixed(y_margin + height),
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
pixman_composite_triangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_OVER, src, buf->pix[0], PIXMAN_a1,
|
2020-03-06 19:15:09 +01:00
|
|
|
|
0, 0, 0, 0, 1, &tri);
|
|
|
|
|
|
|
|
|
|
|
|
pixman_image_unref(src);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_csd_button_maximize(struct terminal *term, struct buffer *buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->window->is_maximized)
|
|
|
|
|
|
render_csd_button_maximize_maximized(term, buf);
|
|
|
|
|
|
else
|
|
|
|
|
|
render_csd_button_maximize_window(term, buf);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_csd_button_close(struct terminal *term, struct buffer *buf)
|
|
|
|
|
|
{
|
2021-04-07 08:07:43 +02:00
|
|
|
|
pixman_color_t color = color_hex_to_pixman(term->conf->colors.bg);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(&color);
|
|
|
|
|
|
|
2020-03-06 19:15:09 +01:00
|
|
|
|
const int max_height = buf->height / 3;
|
|
|
|
|
|
const int max_width = buf->width / 3;
|
|
|
|
|
|
|
|
|
|
|
|
int width = min(max_height, max_width);
|
|
|
|
|
|
|
|
|
|
|
|
const int x_margin = (buf->width - width) / 2;
|
|
|
|
|
|
const int y_margin = (buf->height - width) / 2;
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
2020-03-06 19:15:09 +01:00
|
|
|
|
&(pixman_rectangle16_t){x_margin, y_margin, width, width});
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
pixman_image_unref(src);
|
2020-02-29 18:02:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
static void
|
2020-03-02 20:29:28 +01:00
|
|
|
|
render_csd_button(struct terminal *term, enum csd_surface surf_idx)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->use_csd == CSD_YES);
|
|
|
|
|
|
xassert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE);
|
2020-03-03 18:23:37 +01:00
|
|
|
|
|
2020-03-02 20:29:28 +01:00
|
|
|
|
struct csd_data info = get_csd_data(term, surf_idx);
|
2021-02-12 11:39:25 +01:00
|
|
|
|
struct wl_surface *surf = term->window->csd.surface[surf_idx].surf;
|
2020-03-02 20:29:28 +01:00
|
|
|
|
|
|
|
|
|
|
if (info.width == 0 || info.height == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(info.width % term->scale == 0);
|
|
|
|
|
|
xassert(info.height % term->scale == 0);
|
|
|
|
|
|
|
2020-03-02 20:29:28 +01:00
|
|
|
|
unsigned long cookie = shm_cookie_csd(term, surf_idx);
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
term->wl->shm, info.width, info.height, cookie, false, 1);
|
2020-03-02 20:29:28 +01:00
|
|
|
|
|
|
|
|
|
|
uint32_t _color;
|
|
|
|
|
|
uint16_t alpha = 0xffff;
|
|
|
|
|
|
bool is_active = false;
|
2021-02-06 11:12:22 +01:00
|
|
|
|
bool is_set = false;
|
2020-03-02 20:29:28 +01:00
|
|
|
|
const uint32_t *conf_color = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
switch (surf_idx) {
|
|
|
|
|
|
case CSD_SURF_MINIMIZE:
|
2021-04-07 08:07:43 +02:00
|
|
|
|
_color = term->conf->colors.table[4]; /* blue */
|
2021-02-06 11:12:22 +01:00
|
|
|
|
is_set = term->conf->csd.color.minimize_set;
|
2020-03-02 20:29:28 +01:00
|
|
|
|
conf_color = &term->conf->csd.color.minimize;
|
|
|
|
|
|
is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CSD_SURF_MAXIMIZE:
|
2021-04-07 08:07:43 +02:00
|
|
|
|
_color = term->conf->colors.table[2]; /* green */
|
2021-02-06 11:12:22 +01:00
|
|
|
|
is_set = term->conf->csd.color.maximize_set;
|
2020-03-02 20:29:28 +01:00
|
|
|
|
conf_color = &term->conf->csd.color.maximize;
|
|
|
|
|
|
is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CSD_SURF_CLOSE:
|
2021-04-07 08:07:43 +02:00
|
|
|
|
_color = term->conf->colors.table[1]; /* red */
|
2021-02-06 11:12:22 +01:00
|
|
|
|
is_set = term->conf->csd.color.close_set;
|
2020-03-02 20:29:28 +01:00
|
|
|
|
conf_color = &term->conf->csd.color.close;
|
|
|
|
|
|
is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2021-02-10 09:01:51 +00:00
|
|
|
|
BUG("unhandled surface type: %u", (unsigned)surf_idx);
|
2020-03-02 20:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (is_active) {
|
2021-02-06 11:12:22 +01:00
|
|
|
|
if (is_set) {
|
2020-03-02 20:29:28 +01:00
|
|
|
|
_color = *conf_color;
|
|
|
|
|
|
alpha = _color >> 24 | (_color >> 24 << 8);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
_color = 0;
|
|
|
|
|
|
alpha = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!term->visual_focus)
|
2020-11-15 20:05:01 +01:00
|
|
|
|
_color = color_dim(_color);
|
|
|
|
|
|
|
|
|
|
|
|
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
|
2020-03-02 20:29:28 +01:00
|
|
|
|
render_csd_part(term, surf, buf, info.width, info.height, &color);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
|
|
|
|
|
|
switch (surf_idx) {
|
|
|
|
|
|
case CSD_SURF_MINIMIZE: render_csd_button_minimize(term, buf); break;
|
|
|
|
|
|
case CSD_SURF_MAXIMIZE: render_csd_button_maximize(term, buf); break;
|
|
|
|
|
|
case CSD_SURF_CLOSE: render_csd_button_close(term, buf); break;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2021-02-09 15:16:19 +00:00
|
|
|
|
BUG("unhandled surface type: %u", (unsigned)surf_idx);
|
2020-03-02 21:06:15 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
csd_commit(term, surf, buf);
|
2020-03-02 20:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
static void
|
2020-02-29 18:02:38 +01:00
|
|
|
|
render_csd(struct terminal *term)
|
|
|
|
|
|
{
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->use_csd == CSD_YES);
|
2020-03-03 18:23:37 +01:00
|
|
|
|
|
2020-03-03 18:23:52 +01:00
|
|
|
|
if (term->window->is_fullscreen)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
for (size_t i = 0; i < CSD_SURF_COUNT; i++) {
|
2020-03-01 12:28:01 +01:00
|
|
|
|
struct csd_data info = get_csd_data(term, i);
|
|
|
|
|
|
const int x = info.x;
|
|
|
|
|
|
const int y = info.y;
|
|
|
|
|
|
const int width = info.width;
|
|
|
|
|
|
const int height = info.height;
|
2020-02-29 18:02:38 +01:00
|
|
|
|
|
2021-02-12 11:39:25 +01:00
|
|
|
|
struct wl_surface *surf = term->window->csd.surface[i].surf;
|
|
|
|
|
|
struct wl_subsurface *sub = term->window->csd.surface[i].sub;
|
2020-02-29 18:02:38 +01:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(surf != NULL);
|
|
|
|
|
|
xassert(sub != NULL);
|
2020-03-03 18:24:31 +01:00
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
|
|
wl_subsurface_set_position(sub, 0, 0);
|
|
|
|
|
|
wl_surface_attach(surf, NULL, 0, 0);
|
|
|
|
|
|
wl_surface_commit(surf);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wl_subsurface_set_position(sub, x / term->scale, y / term->scale);
|
2020-02-26 12:17:58 +01:00
|
|
|
|
}
|
2020-02-29 18:02:38 +01:00
|
|
|
|
|
|
|
|
|
|
for (size_t i = CSD_SURF_LEFT; i <= CSD_SURF_BOTTOM; i++)
|
|
|
|
|
|
render_csd_border(term, i);
|
2020-03-03 18:24:51 +01:00
|
|
|
|
for (size_t i = CSD_SURF_MINIMIZE; i <= CSD_SURF_CLOSE; i++)
|
2020-03-02 20:29:28 +01:00
|
|
|
|
render_csd_button(term, i);
|
2020-03-03 18:24:51 +01:00
|
|
|
|
render_csd_title(term);
|
2020-02-23 14:17:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-13 18:35:17 +02:00
|
|
|
|
static void
|
|
|
|
|
|
render_osd(struct terminal *term,
|
|
|
|
|
|
struct wl_surface *surf, struct wl_subsurface *sub_surf,
|
|
|
|
|
|
struct buffer *buf,
|
2021-02-07 10:34:36 +01:00
|
|
|
|
const wchar_t *text, uint32_t _fg, uint32_t _bg,
|
2021-03-24 20:51:18 +01:00
|
|
|
|
unsigned x, unsigned y)
|
2020-08-13 18:35:17 +02:00
|
|
|
|
{
|
2021-02-07 10:34:36 +01:00
|
|
|
|
pixman_color_t bg = color_hex_to_pixman(_bg);
|
2020-08-13 18:35:17 +02:00
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &bg, 1,
|
2021-03-24 20:51:18 +01:00
|
|
|
|
&(pixman_rectangle16_t){0, 0, buf->width, buf->height});
|
2020-08-13 18:35:17 +02:00
|
|
|
|
|
|
|
|
|
|
struct fcft_font *font = term->fonts[0];
|
|
|
|
|
|
pixman_color_t fg = color_hex_to_pixman(_fg);
|
|
|
|
|
|
|
2021-01-07 17:00:58 +01:00
|
|
|
|
const int x_ofs = term->font_x_ofs;
|
2021-01-07 11:18:07 +01:00
|
|
|
|
|
2020-08-13 18:35:17 +02:00
|
|
|
|
for (size_t i = 0; i < wcslen(text); i++) {
|
|
|
|
|
|
const struct fcft_glyph *glyph = fcft_glyph_rasterize(
|
|
|
|
|
|
font, text[i], term->font_subpixel);
|
|
|
|
|
|
|
|
|
|
|
|
if (glyph == NULL)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(&fg);
|
|
|
|
|
|
pixman_image_composite32(
|
|
|
|
|
|
PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0,
|
2021-01-07 11:18:07 +01:00
|
|
|
|
x + x_ofs + glyph->x, y + font_baseline(term) - glyph->y,
|
2020-08-13 18:35:17 +02:00
|
|
|
|
glyph->width, glyph->height);
|
|
|
|
|
|
pixman_image_unref(src);
|
|
|
|
|
|
|
|
|
|
|
|
x += term->cell_width;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(buf->width % term->scale == 0);
|
|
|
|
|
|
xassert(buf->height % term->scale == 0);
|
|
|
|
|
|
|
2020-08-13 18:35:17 +02:00
|
|
|
|
quirk_weston_subsurface_desync_on(sub_surf);
|
|
|
|
|
|
wl_surface_attach(surf, buf->wl_buf, 0, 0);
|
2021-03-24 20:51:18 +01:00
|
|
|
|
wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height);
|
2020-08-13 18:35:17 +02:00
|
|
|
|
wl_surface_set_buffer_scale(surf, term->scale);
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_region *region = wl_compositor_create_region(term->wl->compositor);
|
|
|
|
|
|
if (region != NULL) {
|
2021-03-24 20:51:18 +01:00
|
|
|
|
wl_region_add(region, 0, 0, buf->width, buf->height);
|
2020-08-13 18:35:17 +02:00
|
|
|
|
wl_surface_set_opaque_region(surf, region);
|
|
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_commit(surf);
|
|
|
|
|
|
quirk_weston_subsurface_desync_off(sub_surf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-24 17:51:40 +02:00
|
|
|
|
static void
|
|
|
|
|
|
render_scrollback_position(struct terminal *term)
|
|
|
|
|
|
{
|
2020-07-27 20:02:51 +02:00
|
|
|
|
if (term->conf->scrollback.indicator.position == SCROLLBACK_INDICATOR_POSITION_NONE)
|
2020-07-24 17:51:40 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-07-26 10:01:26 +02:00
|
|
|
|
struct wl_window *win = term->window;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->grid->view == term->grid->offset) {
|
2021-02-12 12:00:40 +01:00
|
|
|
|
if (win->scrollback_indicator.surf != NULL)
|
|
|
|
|
|
wayl_win_subsurface_destroy(&win->scrollback_indicator);
|
2020-07-26 10:01:26 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-12 12:00:40 +01:00
|
|
|
|
if (win->scrollback_indicator.surf == NULL) {
|
|
|
|
|
|
if (!wayl_win_subsurface_new(win, &win->scrollback_indicator)) {
|
2020-07-26 10:01:26 +02:00
|
|
|
|
LOG_ERR("failed to create scrollback indicator surface");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-12 12:00:40 +01:00
|
|
|
|
xassert(win->scrollback_indicator.surf != NULL);
|
|
|
|
|
|
xassert(win->scrollback_indicator.sub != NULL);
|
2020-07-26 10:01:26 +02:00
|
|
|
|
|
2020-07-24 17:51:40 +02:00
|
|
|
|
/* Find absolute row number of the scrollback start */
|
|
|
|
|
|
int scrollback_start = term->grid->offset + term->rows;
|
2020-08-25 18:39:50 +02:00
|
|
|
|
int empty_rows = 0;
|
|
|
|
|
|
while (term->grid->rows[scrollback_start & (term->grid->num_rows - 1)] == NULL) {
|
2020-07-24 17:51:40 +02:00
|
|
|
|
scrollback_start++;
|
2020-08-25 18:39:50 +02:00
|
|
|
|
empty_rows++;
|
|
|
|
|
|
}
|
2020-07-24 17:51:40 +02:00
|
|
|
|
|
|
|
|
|
|
/* Rebase viewport against scrollback start (so that 0 is at
|
|
|
|
|
|
* the beginning of the scrollback) */
|
|
|
|
|
|
int rebased_view = term->grid->view - scrollback_start + term->grid->num_rows;
|
|
|
|
|
|
rebased_view &= term->grid->num_rows - 1;
|
|
|
|
|
|
|
2020-08-25 18:39:50 +02:00
|
|
|
|
/* How much of the scrollback is actually used? */
|
|
|
|
|
|
int populated_rows = term->grid->num_rows - empty_rows;
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(populated_rows > 0);
|
|
|
|
|
|
xassert(populated_rows <= term->grid->num_rows);
|
2020-08-25 18:39:50 +02:00
|
|
|
|
|
2020-07-24 17:51:40 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* How far down in the scrollback we are.
|
|
|
|
|
|
*
|
|
|
|
|
|
* 0% -> at the beginning of the scrollback
|
|
|
|
|
|
* 100% -> at the bottom, i.e. where new lines are inserted
|
|
|
|
|
|
*/
|
2020-07-27 16:39:08 +02:00
|
|
|
|
double percent =
|
2020-08-25 18:39:50 +02:00
|
|
|
|
rebased_view + term->rows == populated_rows
|
2020-07-27 16:39:08 +02:00
|
|
|
|
? 1.0
|
2020-08-26 19:10:00 +02:00
|
|
|
|
: (double)rebased_view / (populated_rows - term->rows);
|
2020-07-24 17:51:40 +02:00
|
|
|
|
|
2020-07-28 19:56:53 +02:00
|
|
|
|
wchar_t _text[64];
|
|
|
|
|
|
const wchar_t *text = _text;
|
2020-07-29 07:25:56 +02:00
|
|
|
|
int cell_count = 0;
|
2020-07-26 10:18:05 +02:00
|
|
|
|
|
|
|
|
|
|
/* *What* to render */
|
|
|
|
|
|
switch (term->conf->scrollback.indicator.format) {
|
2020-07-26 11:39:02 +02:00
|
|
|
|
case SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE:
|
2020-07-28 19:56:53 +02:00
|
|
|
|
swprintf(_text, sizeof(_text) / sizeof(_text[0]), L"%u%%", (int)(100 * percent));
|
2020-07-26 10:18:05 +02:00
|
|
|
|
cell_count = 3;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SCROLLBACK_INDICATOR_FORMAT_LINENO:
|
2020-07-28 19:56:53 +02:00
|
|
|
|
swprintf(_text, sizeof(_text) / sizeof(_text[0]), L"%d", rebased_view + 1);
|
2020-07-26 10:18:05 +02:00
|
|
|
|
cell_count = 1 + (int)log10(term->grid->num_rows);
|
|
|
|
|
|
break;
|
2020-07-28 19:56:53 +02:00
|
|
|
|
|
|
|
|
|
|
case SCROLLBACK_INDICATOR_FORMAT_TEXT:
|
|
|
|
|
|
text = term->conf->scrollback.indicator.text;
|
|
|
|
|
|
cell_count = wcslen(text);
|
|
|
|
|
|
break;
|
2020-07-26 10:18:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 10:01:26 +02:00
|
|
|
|
const int scale = term->scale;
|
|
|
|
|
|
const int margin = 3 * scale;
|
2021-03-24 20:52:58 +01:00
|
|
|
|
|
|
|
|
|
|
const int width =
|
|
|
|
|
|
(2 * margin + cell_count * term->cell_width + scale - 1) / scale * scale;
|
|
|
|
|
|
const int height =
|
|
|
|
|
|
(2 * margin + term->cell_height + scale - 1) / scale * scale;
|
2020-07-26 10:01:26 +02:00
|
|
|
|
|
|
|
|
|
|
unsigned long cookie = shm_cookie_scrollback_indicator(term);
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
|
|
|
|
|
term->wl->shm, width, height, cookie, false, 1);
|
|
|
|
|
|
|
2020-07-26 10:18:05 +02:00
|
|
|
|
/* *Where* to render - parent relative coordinates */
|
|
|
|
|
|
int surf_top = 0;
|
2020-07-27 20:02:51 +02:00
|
|
|
|
switch (term->conf->scrollback.indicator.position) {
|
|
|
|
|
|
case SCROLLBACK_INDICATOR_POSITION_NONE:
|
2021-02-10 09:01:51 +00:00
|
|
|
|
BUG("Invalid scrollback indicator position type");
|
2020-07-26 10:18:05 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-07-27 20:02:51 +02:00
|
|
|
|
case SCROLLBACK_INDICATOR_POSITION_FIXED:
|
2020-07-26 12:37:57 +02:00
|
|
|
|
surf_top = term->cell_height - margin;
|
2020-07-26 10:18:05 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
2020-07-27 20:02:51 +02:00
|
|
|
|
case SCROLLBACK_INDICATOR_POSITION_RELATIVE: {
|
2020-08-26 19:12:12 +02:00
|
|
|
|
int lines = term->rows - 2; /* Avoid using first and last rows */
|
|
|
|
|
|
if (term->is_searching) {
|
|
|
|
|
|
/* Make sure we don't collide with the scrollback search box */
|
|
|
|
|
|
lines--;
|
|
|
|
|
|
}
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(lines > 0);
|
2020-07-26 10:18:05 +02:00
|
|
|
|
|
2020-07-27 16:39:08 +02:00
|
|
|
|
int pixels = lines * term->cell_height - height + 2 * margin;
|
|
|
|
|
|
surf_top = term->cell_height - margin + (int)(percent * pixels);
|
2020-07-26 10:18:05 +02:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 10:01:26 +02:00
|
|
|
|
wl_subsurface_set_position(
|
2021-02-12 12:00:40 +01:00
|
|
|
|
win->scrollback_indicator.sub,
|
2020-07-26 12:37:57 +02:00
|
|
|
|
(term->width - margin - width) / scale,
|
|
|
|
|
|
(term->margins.top + surf_top) / scale);
|
2020-07-26 10:01:26 +02:00
|
|
|
|
|
2020-08-13 18:35:17 +02:00
|
|
|
|
render_osd(
|
|
|
|
|
|
term,
|
2021-02-12 12:00:40 +01:00
|
|
|
|
win->scrollback_indicator.surf,
|
|
|
|
|
|
win->scrollback_indicator.sub,
|
2020-08-13 18:35:17 +02:00
|
|
|
|
buf, text,
|
2021-02-07 10:34:36 +01:00
|
|
|
|
term->colors.table[0], term->colors.table[8 + 4],
|
2021-03-24 20:51:18 +01:00
|
|
|
|
width - margin - wcslen(text) * term->cell_width, margin);
|
2020-07-26 10:01:26 +02:00
|
|
|
|
|
2020-08-13 18:35:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
render_render_timer(struct terminal *term, struct timeval render_time)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct wl_window *win = term->window;
|
|
|
|
|
|
|
|
|
|
|
|
wchar_t text[256];
|
|
|
|
|
|
double usecs = render_time.tv_sec * 1000000 + render_time.tv_usec;
|
2020-08-13 18:46:57 +02:00
|
|
|
|
swprintf(text, sizeof(text) / sizeof(text[0]), L"%.2f µs", usecs);
|
2020-08-13 18:35:17 +02:00
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
const int scale = term->scale;
|
2020-08-13 18:35:17 +02:00
|
|
|
|
const int cell_count = wcslen(text);
|
2021-03-24 20:52:58 +01:00
|
|
|
|
const int margin = 3 * scale;
|
|
|
|
|
|
const int width =
|
|
|
|
|
|
(2 * margin + cell_count * term->cell_width + scale - 1) / scale * scale;
|
|
|
|
|
|
const int height =
|
|
|
|
|
|
(2 * margin + term->cell_height + scale - 1) / scale * scale;
|
2020-08-13 18:35:17 +02:00
|
|
|
|
|
|
|
|
|
|
unsigned long cookie = shm_cookie_render_timer(term);
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
|
|
|
|
|
term->wl->shm, width, height, cookie, false, 1);
|
|
|
|
|
|
|
2020-08-14 07:48:40 +02:00
|
|
|
|
wl_subsurface_set_position(
|
2021-02-12 12:00:40 +01:00
|
|
|
|
win->render_timer.sub,
|
2020-08-14 07:48:40 +02:00
|
|
|
|
margin / term->scale,
|
|
|
|
|
|
(term->margins.top + term->cell_height - margin) / term->scale);
|
|
|
|
|
|
|
2020-08-13 18:35:17 +02:00
|
|
|
|
render_osd(
|
|
|
|
|
|
term,
|
2021-02-12 12:00:40 +01:00
|
|
|
|
win->render_timer.surf,
|
|
|
|
|
|
win->render_timer.sub,
|
2020-08-13 18:35:17 +02:00
|
|
|
|
buf, text,
|
2021-02-07 10:34:36 +01:00
|
|
|
|
term->colors.table[0], term->colors.table[8 + 1],
|
2021-03-24 20:51:18 +01:00
|
|
|
|
margin, margin);
|
2020-07-24 17:51:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
static void frame_callback(
|
|
|
|
|
|
void *data, struct wl_callback *wl_callback, uint32_t callback_data);
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
|
|
.done = &frame_callback,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
|
static void
|
2021-05-08 10:25:14 +02:00
|
|
|
|
force_full_repaint(struct terminal *term, struct buffer *buf)
|
2019-07-05 10:16:56 +02:00
|
|
|
|
{
|
2021-05-08 10:25:14 +02:00
|
|
|
|
tll_free(term->grid->scroll_damage);
|
|
|
|
|
|
render_margin(term, buf, 0, term->rows, true);
|
|
|
|
|
|
term_damage_view(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
reapply_old_damage(struct terminal *term, struct buffer *new, struct buffer *old)
|
|
|
|
|
|
{
|
2021-05-08 20:52:06 +02:00
|
|
|
|
static int counter = 0;
|
|
|
|
|
|
static bool have_warned = false;
|
|
|
|
|
|
if (!have_warned && ++counter > 5) {
|
|
|
|
|
|
LOG_WARN("compositor is not releasing buffers immediately; "
|
|
|
|
|
|
"expect lower rendering performance");
|
|
|
|
|
|
have_warned = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
if (new->age > 1) {
|
|
|
|
|
|
memcpy(new->mmapped, old->mmapped, new->size);
|
2019-12-19 07:27:14 +01:00
|
|
|
|
return;
|
2021-05-08 10:25:14 +02:00
|
|
|
|
}
|
2019-12-19 07:27:14 +01:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* TODO: remove this frame’s damage from the region we copy from
|
|
|
|
|
|
* the old frame.
|
|
|
|
|
|
*
|
|
|
|
|
|
* - this frame’s dirty region is only valid *after* we’ve applied
|
|
|
|
|
|
* its scroll damage.
|
|
|
|
|
|
* - last frame’s dirty region is only valid *before* we’ve
|
|
|
|
|
|
* applied this frame’s scroll damage.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Can we transform one of the regions? It’s not trivial, since
|
|
|
|
|
|
* scroll damage isn’t just about counting lines; there may be
|
|
|
|
|
|
* multiple damage records, each with different scrolling regions.
|
|
|
|
|
|
*/
|
|
|
|
|
|
pixman_region32_t dirty;
|
|
|
|
|
|
pixman_region32_init(&dirty);
|
2019-07-18 09:33:49 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
bool full_repaint_needed = true;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
for (int r = 0; r < term->rows; r++) {
|
|
|
|
|
|
const struct row *row = grid_row_in_view(term->grid, r);
|
|
|
|
|
|
|
|
|
|
|
|
bool row_all_dirty = true;
|
|
|
|
|
|
for (int c = 0; c < term->cols; c++) {
|
|
|
|
|
|
if (row->cells[c].attrs.clean) {
|
|
|
|
|
|
row_all_dirty = false;
|
|
|
|
|
|
full_repaint_needed = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (row_all_dirty) {
|
|
|
|
|
|
pixman_region32_union_rect(
|
|
|
|
|
|
&dirty, &dirty,
|
|
|
|
|
|
term->margins.left,
|
|
|
|
|
|
term->margins.top + r * term->cell_height,
|
|
|
|
|
|
term->width - term->margins.left - term->margins.right,
|
|
|
|
|
|
term->cell_height);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (full_repaint_needed) {
|
|
|
|
|
|
force_full_repaint(term, new);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < old->scroll_damage_count; i++) {
|
|
|
|
|
|
const struct damage *dmg = &old->scroll_damage[i];
|
|
|
|
|
|
|
|
|
|
|
|
switch (dmg->type) {
|
|
|
|
|
|
case DAMAGE_SCROLL:
|
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
|
|
|
|
|
grid_render_scroll(term, new, dmg);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case DAMAGE_SCROLL_REVERSE:
|
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
|
|
|
|
|
grid_render_scroll_reverse(term, new, dmg);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case DAMAGE_SCROLL_IN_VIEW:
|
|
|
|
|
|
grid_render_scroll(term, new, dmg);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case DAMAGE_SCROLL_REVERSE_IN_VIEW:
|
|
|
|
|
|
grid_render_scroll_reverse(term, new, dmg);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-02 00:33:37 +01:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
if (tll_length(term->grid->scroll_damage) == 0) {
|
|
|
|
|
|
pixman_region32_subtract(&dirty, &old->dirty, &dirty);
|
|
|
|
|
|
pixman_image_set_clip_region32(new->pix[0], &dirty);
|
|
|
|
|
|
} else
|
|
|
|
|
|
pixman_image_set_clip_region32(new->pix[0], &old->dirty);
|
|
|
|
|
|
|
|
|
|
|
|
pixman_image_composite32(
|
|
|
|
|
|
PIXMAN_OP_SRC, old->pix[0], NULL, new->pix[0],
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, term->width, term->height);
|
|
|
|
|
|
|
|
|
|
|
|
pixman_image_set_clip_region32(new->pix[0], NULL);
|
|
|
|
|
|
pixman_region32_fini(&dirty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
dirty_old_cursor(struct terminal *term)
|
|
|
|
|
|
{
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
if (term->render.last_cursor.row != NULL && !term->render.last_cursor.hidden) {
|
|
|
|
|
|
struct row *row = term->render.last_cursor.row;
|
|
|
|
|
|
struct cell *cell = &row->cells[term->render.last_cursor.col];
|
|
|
|
|
|
cell->attrs.clean = 0;
|
|
|
|
|
|
row->dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Remember current cursor position, for the next frame */
|
|
|
|
|
|
term->render.last_cursor.row = grid_row(term->grid, term->grid->cursor.point.row);
|
|
|
|
|
|
term->render.last_cursor.col = term->grid->cursor.point.col;
|
|
|
|
|
|
term->render.last_cursor.hidden = term->hide_cursor;
|
2021-05-08 10:25:14 +02:00
|
|
|
|
}
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
static void
|
|
|
|
|
|
dirty_cursor(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->hide_cursor)
|
|
|
|
|
|
return;
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
const struct coord *cursor = &term->grid->cursor.point;
|
2021-05-07 18:18:35 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
struct row *row = grid_row(term->grid, cursor->row);
|
|
|
|
|
|
struct cell *cell = &row->cells[cursor->col];
|
|
|
|
|
|
cell->attrs.clean = 0;
|
|
|
|
|
|
row->dirty = true;
|
|
|
|
|
|
}
|
render: handle compositors that does buffer swapping
Not all compositors support buffer re-use. I.e. they will call the
frame callback *before* the previous buffer has been
released. Effectively causing us to swap between two buffers.
Previously, this made us enter an infinite re-render loop, since we
considered the window 'dirty' (and in need of re-draw) when the buffer
is different from last redraw.
Now, we detect the buffer swapping case; size must match, and we must
not have any other condition that require a full repaint.
In this case, we can memcpy() the old buffer to the new one, without
dirtying the entire grid. We then update only the dirty cells (and
scroll damage).
Note that there was a bug here, where we erased the old
cursor *before* checking for a new buffer. This worked when the buffer
had *not* changed.
Now that we need to handle the case where it *has* changed, we must do
the memcpy() *before* we erase the cursor, or the re-painted cell is
lost.
This makes foot work on Plasma, without burning CPU. The memcpy() does
incur a performance penalty, but we're still (much) faster than
e.g. konsole. In fact, we're still mostly on par with Alacritty.
2019-09-27 19:33:45 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
static void
|
|
|
|
|
|
grid_render(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->is_shutting_down)
|
|
|
|
|
|
return;
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
struct timeval start_time, start_double_buffering = {0}, stop_double_buffering = {0};
|
|
|
|
|
|
if (term->conf->tweak.render_timer_osd || term->conf->tweak.render_timer_log)
|
|
|
|
|
|
gettimeofday(&start_time, NULL);
|
2021-05-08 09:18:45 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
xassert(term->width > 0);
|
|
|
|
|
|
xassert(term->height > 0);
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
unsigned long cookie = shm_cookie_grid(term);
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
|
|
|
|
|
term->wl->shm, term->width, term->height, cookie, true, 1 + term->render.workers.count);
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
/* Dirty old and current cursor cell, to ensure they’re repainted */
|
|
|
|
|
|
dirty_old_cursor(term);
|
|
|
|
|
|
dirty_cursor(term);
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
if (term->render.last_buf == NULL ||
|
2021-05-10 17:56:35 +02:00
|
|
|
|
term->render.last_buf->width != buf->width ||
|
|
|
|
|
|
term->render.last_buf->height != buf->height ||
|
2021-05-08 10:25:14 +02:00
|
|
|
|
term->flash.active || term->render.was_flashing ||
|
|
|
|
|
|
term->is_searching != term->render.was_searching ||
|
|
|
|
|
|
term->render.margins)
|
|
|
|
|
|
{
|
|
|
|
|
|
force_full_repaint(term, buf);
|
|
|
|
|
|
}
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
else if (buf->age > 0) {
|
|
|
|
|
|
LOG_DBG("buffer age: %u", buf->age);
|
2021-05-10 17:56:35 +02:00
|
|
|
|
|
|
|
|
|
|
xassert(term->render.last_buf != NULL);
|
2021-05-08 10:25:14 +02:00
|
|
|
|
xassert(term->render.last_buf != buf);
|
2021-05-10 17:56:35 +02:00
|
|
|
|
xassert(term->render.last_buf->width == buf->width);
|
|
|
|
|
|
xassert(term->render.last_buf->height == buf->height);
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-10 17:56:35 +02:00
|
|
|
|
gettimeofday(&start_double_buffering, NULL);
|
|
|
|
|
|
reapply_old_damage(term, buf, term->render.last_buf);
|
|
|
|
|
|
gettimeofday(&stop_double_buffering, NULL);
|
2021-05-08 10:25:14 +02:00
|
|
|
|
}
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
if (term->render.last_buf != NULL) {
|
|
|
|
|
|
free(term->render.last_buf->scroll_damage);
|
|
|
|
|
|
term->render.last_buf->scroll_damage = NULL;
|
|
|
|
|
|
}
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
term->render.last_buf = buf;
|
|
|
|
|
|
term->render.was_flashing = term->flash.active;
|
|
|
|
|
|
term->render.was_searching = term->is_searching;
|
render: handle compositors that does buffer swapping
Not all compositors support buffer re-use. I.e. they will call the
frame callback *before* the previous buffer has been
released. Effectively causing us to swap between two buffers.
Previously, this made us enter an infinite re-render loop, since we
considered the window 'dirty' (and in need of re-draw) when the buffer
is different from last redraw.
Now, we detect the buffer swapping case; size must match, and we must
not have any other condition that require a full repaint.
In this case, we can memcpy() the old buffer to the new one, without
dirtying the entire grid. We then update only the dirty cells (and
scroll damage).
Note that there was a bug here, where we erased the old
cursor *before* checking for a new buffer. This worked when the buffer
had *not* changed.
Now that we need to handle the case where it *has* changed, we must do
the memcpy() *before* we erase the cursor, or the re-painted cell is
lost.
This makes foot work on Plasma, without burning CPU. The memcpy() does
incur a performance penalty, but we're still (much) faster than
e.g. konsole. In fact, we're still mostly on par with Alacritty.
2019-09-27 19:33:45 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
buf->age = 0;
|
render: handle compositors that does buffer swapping
Not all compositors support buffer re-use. I.e. they will call the
frame callback *before* the previous buffer has been
released. Effectively causing us to swap between two buffers.
Previously, this made us enter an infinite re-render loop, since we
considered the window 'dirty' (and in need of re-draw) when the buffer
is different from last redraw.
Now, we detect the buffer swapping case; size must match, and we must
not have any other condition that require a full repaint.
In this case, we can memcpy() the old buffer to the new one, without
dirtying the entire grid. We then update only the dirty cells (and
scroll damage).
Note that there was a bug here, where we erased the old
cursor *before* checking for a new buffer. This worked when the buffer
had *not* changed.
Now that we need to handle the case where it *has* changed, we must do
the memcpy() *before* we erase the cursor, or the re-painted cell is
lost.
This makes foot work on Plasma, without burning CPU. The memcpy() does
incur a performance penalty, but we're still (much) faster than
e.g. konsole. In fact, we're still mostly on par with Alacritty.
2019-09-27 19:33:45 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
xassert(buf->scroll_damage == NULL);
|
|
|
|
|
|
buf->scroll_damage_count = tll_length(term->grid->scroll_damage);
|
|
|
|
|
|
buf->scroll_damage = xmalloc(
|
|
|
|
|
|
buf->scroll_damage_count * sizeof(buf->scroll_damage[0]));
|
render: handle compositors that does buffer swapping
Not all compositors support buffer re-use. I.e. they will call the
frame callback *before* the previous buffer has been
released. Effectively causing us to swap between two buffers.
Previously, this made us enter an infinite re-render loop, since we
considered the window 'dirty' (and in need of re-draw) when the buffer
is different from last redraw.
Now, we detect the buffer swapping case; size must match, and we must
not have any other condition that require a full repaint.
In this case, we can memcpy() the old buffer to the new one, without
dirtying the entire grid. We then update only the dirty cells (and
scroll damage).
Note that there was a bug here, where we erased the old
cursor *before* checking for a new buffer. This worked when the buffer
had *not* changed.
Now that we need to handle the case where it *has* changed, we must do
the memcpy() *before* we erase the cursor, or the re-painted cell is
lost.
This makes foot work on Plasma, without burning CPU. The memcpy() does
incur a performance penalty, but we're still (much) faster than
e.g. konsole. In fact, we're still mostly on par with Alacritty.
2019-09-27 19:33:45 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
{
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
tll_foreach(term->grid->scroll_damage, it) {
|
|
|
|
|
|
buf->scroll_damage[i++] = it->item;
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
switch (it->item.type) {
|
|
|
|
|
|
case DAMAGE_SCROLL:
|
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
|
|
|
|
|
grid_render_scroll(term, buf, &it->item);
|
|
|
|
|
|
break;
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
case DAMAGE_SCROLL_REVERSE:
|
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
|
|
|
|
|
grid_render_scroll_reverse(term, buf, &it->item);
|
|
|
|
|
|
break;
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
case DAMAGE_SCROLL_IN_VIEW:
|
2019-10-28 17:58:44 +01:00
|
|
|
|
grid_render_scroll(term, buf, &it->item);
|
2021-05-08 10:25:14 +02:00
|
|
|
|
break;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
case DAMAGE_SCROLL_REVERSE_IN_VIEW:
|
2019-10-28 17:58:44 +01:00
|
|
|
|
grid_render_scroll_reverse(term, buf, &it->item);
|
2021-05-08 10:25:14 +02:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-10-29 21:09:37 +01:00
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
tll_remove(term->grid->scroll_damage, it);
|
2019-10-28 17:58:44 +01:00
|
|
|
|
}
|
2019-10-29 21:09:37 +01:00
|
|
|
|
}
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-05-16 21:36:08 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Ensure selected cells have their 'selected' bit set. This is
|
|
|
|
|
|
* normally "automatically" true - the bit is set when the
|
|
|
|
|
|
* selection is made.
|
|
|
|
|
|
*
|
|
|
|
|
|
* However, if the cell is updated (printed to) while the
|
|
|
|
|
|
* selection is active, the 'selected' bit is cleared. Checking
|
|
|
|
|
|
* for this and re-setting the bit in term_print() is too
|
|
|
|
|
|
* expensive performance wise.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Instead, we synchronize the selection bits here and now. This
|
|
|
|
|
|
* makes the performance impact linear to the number of selected
|
|
|
|
|
|
* cells rather than to the number of updated cells.
|
|
|
|
|
|
*
|
|
|
|
|
|
* (note that selection_dirty_cells() will not set the dirty flag
|
|
|
|
|
|
* on cells where the 'selected' bit is already set)
|
|
|
|
|
|
*/
|
|
|
|
|
|
selection_dirty_cells(term);
|
|
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
/* Translate offset-relative row to view-relative, unless cursor
|
|
|
|
|
|
* is hidden, then we just set it to -1 */
|
|
|
|
|
|
struct coord cursor = {-1, -1};
|
|
|
|
|
|
if (!term->hide_cursor) {
|
|
|
|
|
|
cursor = term->grid->cursor.point;
|
|
|
|
|
|
cursor.row += term->grid->offset;
|
|
|
|
|
|
cursor.row -= term->grid->view;
|
|
|
|
|
|
cursor.row &= term->grid->num_rows - 1;
|
|
|
|
|
|
}
|
2019-07-29 20:13:26 +02:00
|
|
|
|
|
2021-03-24 20:46:51 +01:00
|
|
|
|
render_sixel_images(term, buf->pix[0], &cursor);
|
|
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
if (term->render.workers.count > 0) {
|
2020-07-13 13:27:23 +02:00
|
|
|
|
mtx_lock(&term->render.workers.lock);
|
2019-08-01 20:09:39 +02:00
|
|
|
|
term->render.workers.buf = buf;
|
|
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++)
|
|
|
|
|
|
sem_post(&term->render.workers.start);
|
2019-07-29 20:13:26 +02:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(tll_length(term->render.workers.queue) == 0);
|
2020-07-13 13:44:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int first_dirty_row = -1;
|
|
|
|
|
|
for (int r = 0; r < term->rows; r++) {
|
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, r);
|
|
|
|
|
|
|
|
|
|
|
|
if (!row->dirty) {
|
|
|
|
|
|
if (first_dirty_row >= 0) {
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
int x = term->margins.left;
|
|
|
|
|
|
int y = term->margins.top + first_dirty_row * term->cell_height;
|
|
|
|
|
|
int width = term->width - term->margins.left - term->margins.right;
|
|
|
|
|
|
int height = (r - first_dirty_row) * term->cell_height;
|
|
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
wl_surface_damage_buffer(
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
term->window->surface, x, y, width, height);
|
|
|
|
|
|
pixman_region32_union_rect(
|
2021-05-08 10:25:14 +02:00
|
|
|
|
&buf->dirty, &buf->dirty, 0, y, buf->width, height);
|
2020-07-13 13:44:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
first_dirty_row = -1;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
if (first_dirty_row < 0)
|
|
|
|
|
|
first_dirty_row = r;
|
2019-08-01 20:09:39 +02:00
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
row->dirty = false;
|
2019-08-01 20:09:39 +02:00
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
if (term->render.workers.count > 0)
|
2019-08-01 20:09:39 +02:00
|
|
|
|
tll_push_back(term->render.workers.queue, r);
|
|
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
else {
|
|
|
|
|
|
int cursor_col = cursor.row == r ? cursor.col : -1;
|
|
|
|
|
|
render_row(term, buf->pix[0], row, r, cursor_col);
|
|
|
|
|
|
}
|
2020-07-13 14:18:43 +02:00
|
|
|
|
}
|
2020-07-13 13:44:52 +02:00
|
|
|
|
|
2020-07-13 14:18:43 +02:00
|
|
|
|
if (first_dirty_row >= 0) {
|
render: wip: re-apply last frame’s damage when forced to double buffer
When we are forced to swap between two buffers, re-apply the old
frame’s damage to the current buffer, before applying the current
frame’s damage.
First, while applying this frame’s scroll damage, copy it to the
buffer’s scroll damage list (so that we can access it via
term->render.last_buf).
Also, when iterating and rendering the grid, build a pixman region of
the damaged regions. This is currently done on a per-row basis. This
is also stored in the buffer.
Now, when being forced to double buffer, first iterate the old
buffer’s damage, and re-apply it to the current buffer. Then,
composite the old buffer on top of the current buffer, using the old
frame’s damage region as clip region. This effectively copies
everything that was rendered to the last frame. Remember, this is on a
per-row basis.
Then we go on and render the frame as usual.
Note that it would be _really_ nice if we could subtract the current
frame’s damage region from the clip region (no point in copying areas
we’re going to overwrite anyway). Unfortunately, that’s harder than it
looks; the current frame’s damage region is only valid *after* this
frame’s scroll damage have been applied, while the last frame’s damage
region is only valid *before* it’s been applied.
Translating one to the other isn’t easy, since scroll damage isn’t
just about counting lines - there may be multiple scroll damage
records, each with its own scrolling region. This creates very complex
scenarios.
2021-05-07 20:21:27 +02:00
|
|
|
|
int x = term->margins.left;
|
|
|
|
|
|
int y = term->margins.top + first_dirty_row * term->cell_height;
|
|
|
|
|
|
int width = term->width - term->margins.left - term->margins.right;
|
|
|
|
|
|
int height = (term->rows - first_dirty_row) * term->cell_height;
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(term->window->surface, x, y, width, height);
|
2021-05-08 10:25:14 +02:00
|
|
|
|
pixman_region32_union_rect(&buf->dirty, &buf->dirty, 0, y, buf->width, height);
|
2020-07-13 13:44:52 +02:00
|
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2020-07-13 13:44:52 +02:00
|
|
|
|
/* Signal workers the frame is done */
|
|
|
|
|
|
if (term->render.workers.count > 0) {
|
2019-08-01 20:09:39 +02:00
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++)
|
|
|
|
|
|
tll_push_back(term->render.workers.queue, -1);
|
2019-07-29 20:13:26 +02:00
|
|
|
|
mtx_unlock(&term->render.workers.lock);
|
render: remove most of the special handling of cursor rendering
Previously, we had to explicitly render the old cursor cell *before*
applying scrolling damage.
We then rendered all the dirty rows, *without* rendering the cursor -
even if the cursor cell was among the dirty rows.
Finally, when everything else was done, we explicitly rendered the
cursor cell.
This meant a lot of code, and unnecessary render_cell() calls, along
with unnecessary wl_surface_damage_buffer() calls.
This was a necessary in the early design of foot, but not anymore.
We can simply mark both the old cursor cell, and the current one, as
dirty and let the normal rendering framework render it. All we need to
do is pass the cursor column to render_row(), so that it can pass
has_cursor=true in the appropriate call to render_cell(). We pass -1
here for all rows, except the cursor's row, where we pass the actual
cursor column.
With this, there's no need to calculate whether the cursor is visible
or not; just mark it's cell as dirty, and if that row is visible, the
normal rendering will take care of it.
This also simplifies the state needed to be saved between two frames;
we only need a row pointer, and the cursor column index.
Part of https://codeberg.org/dnkl/foot/issues/35
2020-07-12 12:56:10 +02:00
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++)
|
|
|
|
|
|
sem_wait(&term->render.workers.done);
|
|
|
|
|
|
term->render.workers.buf = NULL;
|
2019-08-01 20:09:39 +02:00
|
|
|
|
}
|
2019-07-29 20:13:26 +02:00
|
|
|
|
|
2020-12-02 18:52:50 +01:00
|
|
|
|
/* Render IME pre-edit text */
|
2020-12-03 18:38:26 +01:00
|
|
|
|
render_ime_preedit(term, buf);
|
2020-12-02 18:52:50 +01:00
|
|
|
|
|
2019-07-22 19:15:56 +02:00
|
|
|
|
if (term->flash.active) {
|
2019-08-16 22:06:06 +02:00
|
|
|
|
/* Note: alpha is pre-computed in each color component */
|
2019-08-27 17:23:28 +02:00
|
|
|
|
/* TODO: dim while searching */
|
2019-08-16 22:06:06 +02:00
|
|
|
|
pixman_image_fill_rectangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_OVER, buf->pix[0],
|
2019-08-16 22:06:06 +02:00
|
|
|
|
&(pixman_color_t){.red=0x7fff, .green=0x7fff, .blue=0, .alpha=0x7fff},
|
|
|
|
|
|
1, &(pixman_rectangle16_t){0, 0, term->width, term->height});
|
2019-07-21 19:14:19 +02:00
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
2019-10-27 19:08:48 +01:00
|
|
|
|
term->window->surface, 0, 0, term->width, term->height);
|
2019-07-21 19:14:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-24 17:51:40 +02:00
|
|
|
|
render_scrollback_position(term);
|
|
|
|
|
|
|
2020-08-14 07:52:08 +02:00
|
|
|
|
if (term->conf->tweak.render_timer_osd || term->conf->tweak.render_timer_log) {
|
|
|
|
|
|
struct timeval end_time;
|
|
|
|
|
|
gettimeofday(&end_time, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
struct timeval render_time;
|
|
|
|
|
|
timersub(&end_time, &start_time, &render_time);
|
|
|
|
|
|
|
2021-05-08 10:25:14 +02:00
|
|
|
|
struct timeval double_buffering_time;
|
|
|
|
|
|
timersub(&stop_double_buffering, &start_double_buffering, &double_buffering_time);
|
|
|
|
|
|
|
2020-08-14 07:52:08 +02:00
|
|
|
|
if (term->conf->tweak.render_timer_log) {
|
2021-05-08 10:25:14 +02:00
|
|
|
|
LOG_INFO("frame rendered in %llds %lld µs "
|
|
|
|
|
|
"(%llds %lld µs double buffering)",
|
2020-08-14 07:52:08 +02:00
|
|
|
|
(long long)render_time.tv_sec,
|
2021-05-08 10:25:14 +02:00
|
|
|
|
(long long)render_time.tv_usec,
|
|
|
|
|
|
(long long)double_buffering_time.tv_sec,
|
|
|
|
|
|
(long long)double_buffering_time.tv_usec);
|
2020-08-14 07:52:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (term->conf->tweak.render_timer_osd)
|
|
|
|
|
|
render_render_timer(term, render_time);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows);
|
|
|
|
|
|
xassert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->frame_callback == NULL);
|
2019-10-27 19:08:48 +01:00
|
|
|
|
term->window->frame_callback = wl_surface_frame(term->window->surface);
|
|
|
|
|
|
wl_callback_add_listener(term->window->frame_callback, &frame_listener, term);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2019-10-27 19:08:48 +01:00
|
|
|
|
wl_surface_set_buffer_scale(term->window->surface, term->scale);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
|
|
|
|
|
if (term->wl->presentation != NULL && term->render.presentation_timings) {
|
2020-01-21 18:51:04 +01:00
|
|
|
|
struct timespec commit_time;
|
|
|
|
|
|
clock_gettime(term->wl->presentation_clock_id, &commit_time);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
|
|
|
|
|
|
struct wp_presentation_feedback *feedback = wp_presentation_feedback(
|
|
|
|
|
|
term->wl->presentation, term->window->surface);
|
|
|
|
|
|
|
|
|
|
|
|
if (feedback == NULL) {
|
|
|
|
|
|
LOG_WARN("failed to create presentation feedback");
|
|
|
|
|
|
} else {
|
2020-08-08 20:34:30 +01:00
|
|
|
|
struct presentation_context *ctx = xmalloc(sizeof(*ctx));
|
2020-01-21 18:51:04 +01:00
|
|
|
|
*ctx = (struct presentation_context){
|
|
|
|
|
|
.term = term,
|
|
|
|
|
|
.input.tv_sec = term->render.input_time.tv_sec,
|
|
|
|
|
|
.input.tv_usec = term->render.input_time.tv_nsec / 1000,
|
|
|
|
|
|
.commit.tv_sec = commit_time.tv_sec,
|
|
|
|
|
|
.commit.tv_usec = commit_time.tv_nsec / 1000,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-12-31 15:39:40 +01:00
|
|
|
|
wp_presentation_feedback_add_listener(
|
2020-01-21 18:51:04 +01:00
|
|
|
|
feedback, &presentation_feedback_listener, ctx);
|
|
|
|
|
|
|
|
|
|
|
|
term->render.input_time.tv_sec = 0;
|
|
|
|
|
|
term->render.input_time.tv_nsec = 0;
|
2019-12-31 15:39:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-06 17:52:07 +02:00
|
|
|
|
if (term->conf->tweak.damage_whole_window) {
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
|
term->window->surface, 0, 0, INT32_MAX, INT32_MAX);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(buf->width % term->scale == 0);
|
|
|
|
|
|
xassert(buf->height % term->scale == 0);
|
|
|
|
|
|
|
2020-03-24 17:45:38 +01:00
|
|
|
|
wl_surface_attach(term->window->surface, buf->wl_buf, 0, 0);
|
2019-10-27 19:08:48 +01:00
|
|
|
|
wl_surface_commit(term->window->surface);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2019-08-29 20:18:06 +02:00
|
|
|
|
render_search_box(struct terminal *term)
|
|
|
|
|
|
{
|
2021-02-12 12:00:40 +01:00
|
|
|
|
xassert(term->window->search.sub != NULL);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* We treat the search box pretty much like a row of cells. That
|
|
|
|
|
|
* is, a glyph is either 1 or 2 (or more) “cells” wide.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The search ‘length’, and ‘cursor’ (position) is in
|
|
|
|
|
|
* *characters*, not cells. This means we need to translate from
|
2020-12-05 23:34:27 +01:00
|
|
|
|
* character count to cell count when calculating the length of
|
2020-12-05 23:29:12 +01:00
|
|
|
|
* the search box, where in the search string we should start
|
|
|
|
|
|
* rendering etc.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
/* TODO: do we want to/need to handle multi-seat? */
|
|
|
|
|
|
struct seat *ime_seat = NULL;
|
|
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term) {
|
|
|
|
|
|
ime_seat = &it->item;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-06 12:18:46 +01:00
|
|
|
|
size_t text_len = term->search.len;
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (ime_seat != NULL && ime_seat->ime.preedit.text != NULL)
|
|
|
|
|
|
text_len += wcslen(ime_seat->ime.preedit.text);
|
2020-12-06 12:18:46 +01:00
|
|
|
|
|
|
|
|
|
|
wchar_t *text = xmalloc((text_len + 1) * sizeof(wchar_t));
|
2020-12-07 18:58:01 +01:00
|
|
|
|
text[0] = L'\0';
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy everything up to the cursor */
|
|
|
|
|
|
wcsncpy(text, term->search.buf, term->search.cursor);
|
|
|
|
|
|
text[term->search.cursor] = L'\0';
|
|
|
|
|
|
|
|
|
|
|
|
/* Insert pre-edit text at cursor */
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (ime_seat != NULL && ime_seat->ime.preedit.text != NULL)
|
|
|
|
|
|
wcscat(text, ime_seat->ime.preedit.text);
|
2020-12-07 18:58:01 +01:00
|
|
|
|
|
|
|
|
|
|
/* And finally everything after the cursor */
|
|
|
|
|
|
wcsncat(text, &term->search.buf[term->search.cursor],
|
|
|
|
|
|
term->search.len - term->search.cursor);
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#else
|
2020-12-05 23:34:42 +01:00
|
|
|
|
const wchar_t *text = term->search.buf;
|
|
|
|
|
|
const size_t text_len = term->search.len;
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#endif
|
2020-12-05 23:34:42 +01:00
|
|
|
|
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* Calculate the width of each character */
|
|
|
|
|
|
int widths[text_len + 1];
|
|
|
|
|
|
for (size_t i = 0; i < text_len; i++)
|
2021-01-25 10:00:43 +01:00
|
|
|
|
widths[i] = max(0, wcwidth(text[i]));
|
2020-12-07 18:58:01 +01:00
|
|
|
|
widths[text_len] = 0;
|
|
|
|
|
|
|
2020-12-05 23:34:42 +01:00
|
|
|
|
const size_t total_cells = wcswidth(text, text_len);
|
2020-12-05 23:29:12 +01:00
|
|
|
|
const size_t wanted_visible_cells = max(20, total_cells);
|
2020-01-05 15:16:40 +01:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->scale >= 1);
|
2020-02-25 20:30:45 +01:00
|
|
|
|
const int scale = term->scale;
|
|
|
|
|
|
|
2020-03-02 18:42:49 +01:00
|
|
|
|
const size_t margin = 3 * scale;
|
2020-01-05 15:16:40 +01:00
|
|
|
|
|
2020-03-01 12:28:33 +01:00
|
|
|
|
const size_t width = term->width - 2 * margin;
|
|
|
|
|
|
const size_t visible_width = min(
|
2020-01-05 15:16:40 +01:00
|
|
|
|
term->width - 2 * margin,
|
2021-03-24 20:52:58 +01:00
|
|
|
|
(2 * margin + wanted_visible_cells * term->cell_width + scale - 1) / scale * scale);
|
2020-01-05 15:16:40 +01:00
|
|
|
|
const size_t height = min(
|
|
|
|
|
|
term->height - 2 * margin,
|
2021-03-24 20:52:58 +01:00
|
|
|
|
(2 * margin + 1 * term->cell_height + scale - 1) / scale * scale);
|
2020-01-05 15:16:40 +01:00
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
const size_t visible_cells = (visible_width - 2 * margin) / term->cell_width;
|
2020-01-05 15:25:24 +01:00
|
|
|
|
size_t glyph_offset = term->render.search_glyph_offset;
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-02-23 14:17:48 +01:00
|
|
|
|
unsigned long cookie = shm_cookie_search(term);
|
2020-06-04 15:39:19 +02:00
|
|
|
|
struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie, false, 1);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-12-20 15:01:21 -07:00
|
|
|
|
#define WINDOW_X(x) (margin + x)
|
|
|
|
|
|
#define WINDOW_Y(y) (term->height - margin - height + y)
|
|
|
|
|
|
|
2019-08-29 20:18:06 +02:00
|
|
|
|
/* Background - yellow on empty/match, red on mismatch */
|
|
|
|
|
|
pixman_color_t color = color_hex_to_pixman(
|
2020-12-05 23:34:42 +01:00
|
|
|
|
term->search.match_len == text_len
|
2019-08-30 21:01:13 +02:00
|
|
|
|
? term->colors.table[3] : term->colors.table[1]);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &color,
|
2020-03-01 12:28:33 +01:00
|
|
|
|
1, &(pixman_rectangle16_t){width - visible_width, 0, visible_width, height});
|
|
|
|
|
|
|
|
|
|
|
|
pixman_color_t transparent = color_hex_to_pixman_with_alpha(0, 0);
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
2020-06-04 15:39:19 +02:00
|
|
|
|
PIXMAN_OP_SRC, buf->pix[0], &transparent,
|
2020-03-01 12:28:33 +01:00
|
|
|
|
1, &(pixman_rectangle16_t){0, 0, width - visible_width, height});
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-04-21 19:29:36 +02:00
|
|
|
|
struct fcft_font *font = term->fonts[0];
|
2020-12-06 12:18:46 +01:00
|
|
|
|
const int x_left = width - visible_width + margin;
|
2021-01-07 17:00:58 +01:00
|
|
|
|
const int x_ofs = term->font_x_ofs;
|
2020-12-06 12:18:46 +01:00
|
|
|
|
int x = x_left;
|
2019-08-29 20:18:06 +02:00
|
|
|
|
int y = margin;
|
2019-08-30 21:01:13 +02:00
|
|
|
|
pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* Move offset we start rendering at, to ensure the cursor is visible */
|
|
|
|
|
|
for (size_t i = 0, cell_idx = 0; i <= term->search.cursor; cell_idx += widths[i], i++) {
|
2020-12-05 23:29:12 +01:00
|
|
|
|
if (i != term->search.cursor)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#if (FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (ime_seat != NULL && ime_seat->ime.preedit.cells != NULL) {
|
|
|
|
|
|
if (ime_seat->ime.preedit.cursor.start == ime_seat->ime.preedit.cursor.end) {
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* All IME's I've seen so far keeps the cursor at
|
|
|
|
|
|
* index 0, so ensure the *end* of the pre-edit string
|
|
|
|
|
|
* is visible */
|
2021-03-23 13:03:07 +01:00
|
|
|
|
cell_idx += ime_seat->ime.preedit.count;
|
2020-12-07 18:58:01 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
/* Try to predict in which direction we'll shift the text */
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (cell_idx + ime_seat->ime.preedit.cursor.start > glyph_offset)
|
|
|
|
|
|
cell_idx += ime_seat->ime.preedit.cursor.end;
|
2020-12-07 18:58:01 +01:00
|
|
|
|
else
|
2021-03-23 13:03:07 +01:00
|
|
|
|
cell_idx += ime_seat->ime.preedit.cursor.start;
|
2020-12-07 18:58:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-12-07 18:58:01 +01:00
|
|
|
|
if (cell_idx < glyph_offset) {
|
|
|
|
|
|
/* Shift to the *left*, making *this* character the
|
|
|
|
|
|
* *first* visible one */
|
2020-12-05 23:29:12 +01:00
|
|
|
|
term->render.search_glyph_offset = glyph_offset = cell_idx;
|
2020-12-07 18:58:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
else if (cell_idx > glyph_offset + visible_cells) {
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* Shift to the *right*, making *this* character the
|
|
|
|
|
|
* *last* visible one */
|
2020-12-05 23:29:12 +01:00
|
|
|
|
term->render.search_glyph_offset = glyph_offset =
|
|
|
|
|
|
cell_idx - min(cell_idx, visible_cells);
|
|
|
|
|
|
}
|
2020-12-07 18:58:01 +01:00
|
|
|
|
|
|
|
|
|
|
/* Adjust offset if there is free space available */
|
|
|
|
|
|
if (total_cells - glyph_offset < visible_cells) {
|
|
|
|
|
|
term->render.search_glyph_offset = glyph_offset =
|
|
|
|
|
|
total_cells - min(total_cells, visible_cells);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
break;
|
2020-01-05 15:16:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* Ensure offset is at a character boundary */
|
|
|
|
|
|
for (size_t i = 0, cell_idx = 0; i <= text_len; cell_idx += widths[i], i++) {
|
|
|
|
|
|
if (cell_idx >= glyph_offset) {
|
|
|
|
|
|
term->render.search_glyph_offset = glyph_offset = cell_idx;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-12-06 12:24:45 +01:00
|
|
|
|
}
|
2020-04-19 14:50:48 +02:00
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* Render the search string, starting at ‘glyph_offset’. Note that
|
|
|
|
|
|
* glyph_offset is in cells, not characters
|
|
|
|
|
|
*/
|
|
|
|
|
|
for (size_t i = 0,
|
|
|
|
|
|
cell_idx = 0,
|
2020-12-07 18:58:01 +01:00
|
|
|
|
width = widths[i],
|
2020-12-05 23:29:12 +01:00
|
|
|
|
next_cell_idx = width;
|
2020-12-05 23:34:42 +01:00
|
|
|
|
i < text_len;
|
2020-12-05 23:29:12 +01:00
|
|
|
|
i++,
|
|
|
|
|
|
cell_idx = next_cell_idx,
|
2020-12-07 18:58:01 +01:00
|
|
|
|
width = widths[i],
|
2020-12-05 23:29:12 +01:00
|
|
|
|
next_cell_idx += width)
|
2020-01-05 15:16:40 +01:00
|
|
|
|
{
|
2020-12-20 15:01:21 -07:00
|
|
|
|
/* Convert subsurface coordinates to window coordinates*/
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* Render cursor */
|
|
|
|
|
|
if (i == term->search.cursor) {
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
bool have_preedit =
|
|
|
|
|
|
ime_seat != NULL && ime_seat->ime.preedit.cells != NULL;
|
|
|
|
|
|
bool hidden =
|
|
|
|
|
|
ime_seat != NULL && ime_seat->ime.preedit.cursor.hidden;
|
2020-12-07 18:58:01 +01:00
|
|
|
|
|
|
|
|
|
|
if (have_preedit && !hidden) {
|
|
|
|
|
|
/* Cursor may be outside the visible area:
|
|
|
|
|
|
* cell_idx-glyph_offset can be negative */
|
|
|
|
|
|
int cells_left = visible_cells - max(
|
|
|
|
|
|
(ssize_t)(cell_idx - glyph_offset), 0);
|
|
|
|
|
|
|
|
|
|
|
|
/* If cursor is outside the visible area, we need to
|
|
|
|
|
|
* adjust our rectangle's position */
|
2021-03-23 13:03:07 +01:00
|
|
|
|
int start = ime_seat->ime.preedit.cursor.start
|
2020-12-07 18:58:01 +01:00
|
|
|
|
+ min((ssize_t)(cell_idx - glyph_offset), 0);
|
2021-03-23 13:03:07 +01:00
|
|
|
|
int end = ime_seat->ime.preedit.cursor.end
|
2020-12-07 18:58:01 +01:00
|
|
|
|
+ min((ssize_t)(cell_idx - glyph_offset), 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (start == end) {
|
2021-03-23 13:03:07 +01:00
|
|
|
|
int count = min(ime_seat->ime.preedit.count, cells_left);
|
2020-12-07 18:58:01 +01:00
|
|
|
|
|
|
|
|
|
|
/* Underline the entire (visible part of) pre-edit text */
|
|
|
|
|
|
draw_underline(term, buf->pix[0], font, &fg, x, y, count);
|
|
|
|
|
|
|
|
|
|
|
|
/* Bar-styled cursor, if in the visible area */
|
|
|
|
|
|
if (start >= 0 && start <= visible_cells)
|
2021-04-30 20:31:47 +02:00
|
|
|
|
draw_beam(term, buf->pix[0], font, &fg, x + start * term->cell_width, y);
|
2020-12-20 15:01:21 -07:00
|
|
|
|
term_ime_set_cursor_rect(term,
|
|
|
|
|
|
WINDOW_X(x + start * term->cell_width), WINDOW_Y(y),
|
|
|
|
|
|
1, term->cell_height);
|
2020-12-07 18:58:01 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
/* Underline everything before and after the cursor */
|
|
|
|
|
|
int count1 = min(start, cells_left);
|
|
|
|
|
|
int count2 = max(
|
2021-03-23 13:03:07 +01:00
|
|
|
|
min(ime_seat->ime.preedit.count - ime_seat->ime.preedit.cursor.end,
|
2020-12-07 18:58:01 +01:00
|
|
|
|
cells_left - end),
|
|
|
|
|
|
0);
|
|
|
|
|
|
draw_underline(term, buf->pix[0], font, &fg, x, y, count1);
|
|
|
|
|
|
draw_underline(term, buf->pix[0], font, &fg, x + end * term->cell_width, y, count2);
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO: how do we handle a partially hidden rectangle? */
|
|
|
|
|
|
if (start >= 0 && end <= visible_cells) {
|
|
|
|
|
|
draw_unfocused_block(
|
|
|
|
|
|
term, buf->pix[0], &fg, x + start * term->cell_width, y, end - start);
|
|
|
|
|
|
}
|
2020-12-20 15:01:21 -07:00
|
|
|
|
term_ime_set_cursor_rect(term,
|
|
|
|
|
|
WINDOW_X(x + start * term->cell_width), WINDOW_Y(y),
|
|
|
|
|
|
term->cell_width * (end - start), term->cell_height);
|
2020-12-07 18:58:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
} else if (!have_preedit)
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#endif
|
2020-12-07 18:58:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
/* Cursor *should* be in the visible area */
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(cell_idx >= glyph_offset);
|
|
|
|
|
|
xassert(cell_idx <= glyph_offset + visible_cells);
|
2021-04-30 20:31:47 +02:00
|
|
|
|
draw_beam(term, buf->pix[0], font, &fg, x, y);
|
2020-12-20 15:01:21 -07:00
|
|
|
|
term_ime_set_cursor_rect(
|
|
|
|
|
|
term, WINDOW_X(x), WINDOW_Y(y), 1, term->cell_height);
|
2020-12-07 18:58:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-08-29 21:03:00 +02:00
|
|
|
|
|
2020-12-07 18:58:01 +01:00
|
|
|
|
if (next_cell_idx >= glyph_offset && next_cell_idx - glyph_offset > visible_cells) {
|
|
|
|
|
|
/* We're now beyond the visible area - nothing more to render */
|
2020-12-05 23:29:12 +01:00
|
|
|
|
break;
|
2020-12-07 18:58:01 +01:00
|
|
|
|
}
|
2020-12-05 23:29:12 +01:00
|
|
|
|
|
|
|
|
|
|
if (cell_idx < glyph_offset) {
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* We haven't yet reached the visible part of the string */
|
2020-12-05 23:29:12 +01:00
|
|
|
|
cell_idx = next_cell_idx;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-24 10:53:34 +02:00
|
|
|
|
const struct fcft_glyph *glyph = fcft_glyph_rasterize(
|
2020-12-05 23:34:42 +01:00
|
|
|
|
font, text[i], term->font_subpixel);
|
2020-04-24 10:53:34 +02:00
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
if (glyph == NULL) {
|
|
|
|
|
|
cell_idx = next_cell_idx;
|
2019-08-29 20:18:06 +02:00
|
|
|
|
continue;
|
2020-12-05 23:29:12 +01:00
|
|
|
|
}
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-12-05 11:59:41 +01:00
|
|
|
|
if (unlikely(pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)) {
|
|
|
|
|
|
/* Glyph surface is a pre-rendered image (typically a color emoji...) */
|
|
|
|
|
|
pixman_image_composite32(
|
|
|
|
|
|
PIXMAN_OP_OVER, glyph->pix, NULL, buf->pix[0], 0, 0, 0, 0,
|
2021-01-07 11:18:07 +01:00
|
|
|
|
x + x_ofs + glyph->x, y + font_baseline(term) - glyph->y,
|
2020-12-05 11:59:41 +01:00
|
|
|
|
glyph->width, glyph->height);
|
|
|
|
|
|
} else {
|
2021-01-25 10:00:43 +01:00
|
|
|
|
int combining_ofs = width == 0
|
|
|
|
|
|
? (glyph->x < 0
|
|
|
|
|
|
? width * term->cell_width
|
|
|
|
|
|
: (width - 1) * term->cell_width)
|
|
|
|
|
|
: 0; /* Not a zero-width character - no additional offset */
|
2020-12-05 11:59:41 +01:00
|
|
|
|
pixman_image_t *src = pixman_image_create_solid_fill(&fg);
|
|
|
|
|
|
pixman_image_composite32(
|
|
|
|
|
|
PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0,
|
2021-01-25 10:00:43 +01:00
|
|
|
|
x + x_ofs + combining_ofs + glyph->x,
|
|
|
|
|
|
y + font_baseline(term) - glyph->y,
|
2019-08-29 20:18:06 +02:00
|
|
|
|
glyph->width, glyph->height);
|
2020-12-05 11:59:41 +01:00
|
|
|
|
pixman_image_unref(src);
|
|
|
|
|
|
}
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2020-12-05 23:29:12 +01:00
|
|
|
|
x += width * term->cell_width;
|
|
|
|
|
|
cell_idx = next_cell_idx;
|
2019-08-29 20:18:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
2021-03-23 13:03:07 +01:00
|
|
|
|
if (ime_seat != NULL && ime_seat->ime.preedit.cells != NULL)
|
2020-12-07 18:58:01 +01:00
|
|
|
|
/* Already rendered */;
|
|
|
|
|
|
else
|
2020-12-06 12:18:46 +01:00
|
|
|
|
#endif
|
2020-12-20 15:01:21 -07:00
|
|
|
|
if (term->search.cursor >= term->search.len) {
|
2021-04-30 20:31:47 +02:00
|
|
|
|
draw_beam(term, buf->pix[0], font, &fg, x, y);
|
2020-12-20 15:01:21 -07:00
|
|
|
|
term_ime_set_cursor_rect(
|
|
|
|
|
|
term, WINDOW_X(x), WINDOW_Y(y), 1, term->cell_height);
|
|
|
|
|
|
}
|
2019-08-29 21:03:00 +02:00
|
|
|
|
|
2021-02-12 12:00:40 +01:00
|
|
|
|
quirk_weston_subsurface_desync_on(term->window->search.sub);
|
2020-03-01 13:06:00 +01:00
|
|
|
|
|
2020-03-01 12:54:50 +01:00
|
|
|
|
/* TODO: this is only necessary on a window resize */
|
2019-08-29 20:18:06 +02:00
|
|
|
|
wl_subsurface_set_position(
|
2021-02-12 12:00:40 +01:00
|
|
|
|
term->window->search.sub,
|
2020-03-01 12:28:33 +01:00
|
|
|
|
margin / scale,
|
2020-02-29 11:40:41 +01:00
|
|
|
|
max(0, (int32_t)term->height - height - margin) / scale);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
xassert(buf->width % scale == 0);
|
|
|
|
|
|
xassert(buf->height % scale == 0);
|
|
|
|
|
|
|
2021-02-12 12:00:40 +01:00
|
|
|
|
wl_surface_attach(term->window->search.surf, buf->wl_buf, 0, 0);
|
|
|
|
|
|
wl_surface_damage_buffer(term->window->search.surf, 0, 0, width, height);
|
|
|
|
|
|
wl_surface_set_buffer_scale(term->window->search.surf, scale);
|
2020-03-01 12:28:33 +01:00
|
|
|
|
|
2020-03-01 12:54:27 +01:00
|
|
|
|
struct wl_region *region = wl_compositor_create_region(term->wl->compositor);
|
|
|
|
|
|
if (region != NULL) {
|
|
|
|
|
|
wl_region_add(region, width - visible_width, 0, visible_width, height);
|
2021-02-12 12:00:40 +01:00
|
|
|
|
wl_surface_set_opaque_region(term->window->search.surf, region);
|
2020-03-01 12:54:27 +01:00
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-12 12:00:40 +01:00
|
|
|
|
wl_surface_commit(term->window->search.surf);
|
|
|
|
|
|
quirk_weston_subsurface_desync_off(term->window->search.sub);
|
2020-12-06 12:18:46 +01:00
|
|
|
|
|
|
|
|
|
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
|
|
|
|
|
free(text);
|
|
|
|
|
|
#endif
|
2020-12-20 15:01:21 -07:00
|
|
|
|
#undef WINDOW_X
|
|
|
|
|
|
#undef WINDOW_Y
|
2019-08-29 20:18:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
static void
|
|
|
|
|
|
render_urls(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct wl_window *win = term->window;
|
|
|
|
|
|
xassert(tll_length(win->urls) > 0);
|
|
|
|
|
|
|
2021-02-06 11:47:59 +01:00
|
|
|
|
/* Calculate view start, counted from the *current* scrollback start */
|
|
|
|
|
|
const int scrollback_end
|
|
|
|
|
|
= (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
|
|
|
|
|
|
const int view_start
|
|
|
|
|
|
= (term->grid->view
|
|
|
|
|
|
- scrollback_end
|
|
|
|
|
|
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
|
|
|
|
|
const int view_end = view_start + term->rows - 1;
|
|
|
|
|
|
|
2021-02-14 14:18:11 +01:00
|
|
|
|
const bool show_url = term->urls_show_uri_on_jump_label;
|
|
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
tll_foreach(win->urls, it) {
|
|
|
|
|
|
const struct url *url = it->item.url;
|
|
|
|
|
|
const wchar_t *key = url->key;
|
2021-02-06 20:52:04 +01:00
|
|
|
|
const size_t entered_key_len = wcslen(term->url_keys);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
|
2021-02-13 13:45:59 +01:00
|
|
|
|
if (key == NULL) {
|
|
|
|
|
|
/* TODO: if we decide to use the .text field, we cannot
|
|
|
|
|
|
* just skip the entire jump label like this */
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-12 11:31:31 +01:00
|
|
|
|
struct wl_surface *surf = it->item.surf.surf;
|
|
|
|
|
|
struct wl_subsurface *sub_surf = it->item.surf.sub;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
|
|
|
|
|
|
if (surf == NULL || sub_surf == NULL)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2021-02-06 20:52:04 +01:00
|
|
|
|
bool hide = false;
|
2021-02-06 11:47:59 +01:00
|
|
|
|
const struct coord *pos = &url->start;
|
|
|
|
|
|
const int _row
|
|
|
|
|
|
= (pos->row
|
|
|
|
|
|
- scrollback_end
|
|
|
|
|
|
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
|
|
|
|
|
|
2021-02-06 20:52:04 +01:00
|
|
|
|
if (_row < view_start || _row > view_end)
|
|
|
|
|
|
hide = true;
|
|
|
|
|
|
if (wcslen(key) <= entered_key_len)
|
|
|
|
|
|
hide = true;
|
2021-03-04 08:55:55 +01:00
|
|
|
|
if (wcsncasecmp(term->url_keys, key, entered_key_len) != 0)
|
2021-02-06 20:52:04 +01:00
|
|
|
|
hide = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (hide) {
|
2021-02-06 11:47:59 +01:00
|
|
|
|
wl_surface_attach(surf, NULL, 0, 0);
|
|
|
|
|
|
wl_surface_commit(surf);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
int col = pos->col;
|
|
|
|
|
|
int row = pos->row - term->grid->view;
|
|
|
|
|
|
while (row < 0)
|
|
|
|
|
|
row += term->grid->num_rows;
|
|
|
|
|
|
row &= (term->grid->num_rows - 1);
|
|
|
|
|
|
|
|
|
|
|
|
/* Position label slightly above and to the left */
|
|
|
|
|
|
int x = col * term->cell_width - 15 * term->cell_width / 10;
|
|
|
|
|
|
int y = row * term->cell_height - 5 * term->cell_height / 10;
|
|
|
|
|
|
|
|
|
|
|
|
/* Don’t position it outside our window */
|
|
|
|
|
|
if (x < -term->margins.left)
|
|
|
|
|
|
x = -term->margins.left;
|
|
|
|
|
|
if (y < -term->margins.top)
|
|
|
|
|
|
y = -term->margins.top;
|
|
|
|
|
|
|
|
|
|
|
|
/* Maximum width of label, in pixels */
|
|
|
|
|
|
const int max_width =
|
|
|
|
|
|
term->width - term->margins.left - term->margins.right - x;
|
|
|
|
|
|
|
2021-02-14 14:18:11 +01:00
|
|
|
|
const size_t key_len = wcslen(key);
|
|
|
|
|
|
|
|
|
|
|
|
size_t url_len = mbstowcs(NULL, url->url, 0);
|
|
|
|
|
|
if (url_len == (size_t)-1)
|
|
|
|
|
|
url_len = 0;
|
|
|
|
|
|
|
|
|
|
|
|
wchar_t url_wchars[url_len + 1];
|
|
|
|
|
|
mbstowcs(url_wchars, url->url, url_len + 1);
|
|
|
|
|
|
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
/* Format label, not yet subject to any size limitations */
|
2021-02-14 14:18:11 +01:00
|
|
|
|
size_t chars = key_len + (show_url ? (2 + url_len) : 0);
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
wchar_t label[chars + 1];
|
|
|
|
|
|
label[chars] = L'\0';
|
2021-02-14 14:18:11 +01:00
|
|
|
|
|
|
|
|
|
|
if (show_url)
|
|
|
|
|
|
swprintf(label, chars + 1, L"%ls: %ls", key, url_wchars);
|
|
|
|
|
|
else
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
wcsncpy(label, key, chars);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
/* Upper case the key characters */
|
2021-02-06 23:03:05 +01:00
|
|
|
|
for (size_t i = 0; i < wcslen(key); i++)
|
|
|
|
|
|
label[i] = towupper(label[i]);
|
|
|
|
|
|
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
/* Blank already entered key characters */
|
2021-02-07 10:51:28 +01:00
|
|
|
|
for (size_t i = 0; i < entered_key_len; i++)
|
|
|
|
|
|
label[i] = L' ';
|
|
|
|
|
|
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* Don’t extend outside our window
|
|
|
|
|
|
*
|
|
|
|
|
|
* Truncate label so that it doesn’t extend outside our
|
|
|
|
|
|
* window.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Do it in a way such that we don’t cut the label in the
|
|
|
|
|
|
* middle of a double-width character.
|
|
|
|
|
|
*/
|
2021-03-24 20:52:58 +01:00
|
|
|
|
const int scale = term->scale;
|
|
|
|
|
|
const int x_margin = 2 * scale;
|
|
|
|
|
|
const int y_margin = 1 * scale;
|
render: don’t let URL jump label sub-surfaces extend outside window geometry
We have no guarantee that sub-surfaces extending outside the window
geometry are rendered correctly (if at all).
For example, both Sway and River will render the window border on top
of the sub-surface.
Future versions of Sway may clip the sub-surface.
Since jump-labels are positioned slightly above, and to the left of
the URLs first character, having a label on either the top row, or on
the first column, will likely position it outside the window. This is
handled by simply setting x/y to 0 (or, to -margin, since the label
coordinate is later offsetted with the window margins).
Second, if the label is very long, it may extend outside the
window. This is very unusual for labels only showing the key, and not
the URL itself, but could happen in this case too, if e.g. the user
has configured double-width key characters.
This is handled by calculating its maximum width, and then truncating
the label.
Although very unlikely, it is possible for a label to also extend
outside the window’s vertical size. This could happen for very small
font sizes, where the label’s own margins are large, relative to the
font size. This case is currently not handled.
Closes #443
2021-04-10 13:16:39 +02:00
|
|
|
|
const int max_cols = max_width / term->cell_width;
|
|
|
|
|
|
|
|
|
|
|
|
int cols = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i <= wcslen(label); i++) {
|
|
|
|
|
|
int _cols = wcswidth(label, i);
|
|
|
|
|
|
|
|
|
|
|
|
if (_cols == (size_t)-1)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (_cols >= max_cols) {
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
|
label[i - 1] = L'…';
|
|
|
|
|
|
label[i] = L'\0';
|
|
|
|
|
|
cols = max_cols;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
cols = _cols;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cols == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2021-03-24 20:52:58 +01:00
|
|
|
|
const int width =
|
|
|
|
|
|
(2 * x_margin + cols * term->cell_width + scale - 1) / scale * scale;
|
|
|
|
|
|
const int height =
|
|
|
|
|
|
(2 * y_margin + term->cell_height + scale - 1) / scale * scale;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
|
|
|
|
|
term->wl->shm, width, height, shm_cookie_url(url), false, 1);
|
|
|
|
|
|
|
|
|
|
|
|
wl_subsurface_set_position(
|
|
|
|
|
|
sub_surf,
|
2021-02-01 10:04:25 +01:00
|
|
|
|
(term->margins.left + x) / term->scale,
|
|
|
|
|
|
(term->margins.top + y) / term->scale);
|
|
|
|
|
|
|
2021-02-06 11:10:40 +01:00
|
|
|
|
uint32_t fg = term->conf->colors.use_custom.jump_label
|
|
|
|
|
|
? term->conf->colors.jump_label.fg
|
|
|
|
|
|
: term->colors.table[0];
|
|
|
|
|
|
uint32_t bg = term->conf->colors.use_custom.jump_label
|
|
|
|
|
|
? term->conf->colors.jump_label.bg
|
|
|
|
|
|
: term->colors.table[3];
|
|
|
|
|
|
|
2021-03-24 20:51:18 +01:00
|
|
|
|
render_osd(
|
|
|
|
|
|
term, surf, sub_surf, buf, label, fg, bg, x_margin, y_margin);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-25 18:23:55 +01:00
|
|
|
|
static void
|
|
|
|
|
|
render_update_title(struct terminal *term)
|
|
|
|
|
|
{
|
2020-07-22 21:07:57 +02:00
|
|
|
|
static const size_t max_len = 2048;
|
2020-03-25 18:23:55 +01:00
|
|
|
|
|
|
|
|
|
|
const char *title = term->window_title != NULL ? term->window_title : "foot";
|
|
|
|
|
|
char *copy = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(title) > max_len) {
|
2020-08-08 20:34:30 +01:00
|
|
|
|
copy = xstrndup(title, max_len);
|
2020-03-25 18:23:55 +01:00
|
|
|
|
title = copy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
xdg_toplevel_set_title(term->window->xdg_toplevel, title);
|
|
|
|
|
|
free(copy);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
static void
|
|
|
|
|
|
frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->window->frame_callback == wl_callback);
|
2020-03-06 19:16:54 +01:00
|
|
|
|
wl_callback_destroy(wl_callback);
|
|
|
|
|
|
term->window->frame_callback = NULL;
|
|
|
|
|
|
|
2020-03-24 17:42:29 +01:00
|
|
|
|
bool grid = term->render.pending.grid;
|
|
|
|
|
|
bool csd = term->render.pending.csd;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
bool search = term->is_searching && term->render.pending.search;
|
2020-03-25 18:23:55 +01:00
|
|
|
|
bool title = term->render.pending.title;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
bool urls = urls_mode_is_active(term) > 0 && term->render.pending.urls;
|
2020-03-24 17:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
term->render.pending.grid = false;
|
|
|
|
|
|
term->render.pending.csd = false;
|
|
|
|
|
|
term->render.pending.search = false;
|
2020-03-25 18:23:55 +01:00
|
|
|
|
term->render.pending.title = false;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
term->render.pending.urls = false;
|
2020-03-24 17:42:29 +01:00
|
|
|
|
|
url-mode: snapshot screen state when entering URL mode
Previously, we automatically exited URL mode whenever we received data
on the PTY. This was done since we don’t know _what_ has changed on
the screen, and we don’t want to display misleading jump labels.
However, this becomes a problem in curses-like applications that
periodically updates part of the screen. For example, a statusbar with
a clock.
This patch changes this behavior; instead of cancelling URL mode when
receiving PTY data, we snapshot the grid when entering URL mode.
When *rendering*, we use the snapshot:ed grid, while PTY updates
modify the “real” grid.
Snapshot:ing the grid means taking a full/deep copy of the current
grid, including sixel images etc.
Finally, it isn’t necessary to “damage” the entire view
when *entering* URL mode, since we’re at that point the renderer is in
sync with the grid. But we *do* need to damage the entire view when
exiting URL mode, since the grid changes on the “real” grid hasn’t
been tracked by the renderer.
2021-02-22 10:22:41 +01:00
|
|
|
|
struct grid *original_grid = term->grid;
|
|
|
|
|
|
if (urls_mode_is_active(term)) {
|
|
|
|
|
|
xassert(term->url_grid_snapshot != NULL);
|
|
|
|
|
|
term->grid = term->url_grid_snapshot;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-24 17:42:29 +01:00
|
|
|
|
if (csd && term->window->use_csd == CSD_YES) {
|
|
|
|
|
|
quirk_weston_csd_on(term);
|
|
|
|
|
|
render_csd(term);
|
|
|
|
|
|
quirk_weston_csd_off(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-25 18:23:55 +01:00
|
|
|
|
if (title)
|
|
|
|
|
|
render_update_title(term);
|
|
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
if (search)
|
2020-03-24 17:42:29 +01:00
|
|
|
|
render_search_box(term);
|
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
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
if (urls)
|
|
|
|
|
|
render_urls(term);
|
2020-12-20 15:01:21 -07:00
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
if (grid && (!term->delayed_render_timer.is_armed | csd | search | urls))
|
2020-09-29 10:04:41 +02:00
|
|
|
|
grid_render(term);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
|
|
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
|
|
|
|
|
if (it->item.kbd_focus == term)
|
2021-03-23 13:56:33 +01:00
|
|
|
|
ime_update_cursor_rect(&it->item);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
}
|
url-mode: snapshot screen state when entering URL mode
Previously, we automatically exited URL mode whenever we received data
on the PTY. This was done since we don’t know _what_ has changed on
the screen, and we don’t want to display misleading jump labels.
However, this becomes a problem in curses-like applications that
periodically updates part of the screen. For example, a statusbar with
a clock.
This patch changes this behavior; instead of cancelling URL mode when
receiving PTY data, we snapshot the grid when entering URL mode.
When *rendering*, we use the snapshot:ed grid, while PTY updates
modify the “real” grid.
Snapshot:ing the grid means taking a full/deep copy of the current
grid, including sixel images etc.
Finally, it isn’t necessary to “damage” the entire view
when *entering* URL mode, since we’re at that point the renderer is in
sync with the grid. But we *do* need to damage the entire view when
exiting URL mode, since the grid changes on the “real” grid hasn’t
been tracked by the renderer.
2021-02-22 10:22:41 +01:00
|
|
|
|
|
|
|
|
|
|
term->grid = original_grid;
|
2020-03-06 19:16:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-17 16:12:54 +01:00
|
|
|
|
static void
|
|
|
|
|
|
tiocswinsz(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->ptmx >= 0) {
|
|
|
|
|
|
if (ioctl(term->ptmx, (unsigned int)TIOCSWINSZ,
|
|
|
|
|
|
&(struct winsize){
|
|
|
|
|
|
.ws_row = term->rows,
|
|
|
|
|
|
.ws_col = term->cols,
|
|
|
|
|
|
.ws_xpixel = term->cols * term->cell_width,
|
|
|
|
|
|
.ws_ypixel = term->rows * term->cell_height}) < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_ERRNO("TIOCSWINSZ");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
fdm_tiocswinsz(struct fdm *fdm, int fd, int events, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
|
2021-01-17 16:41:22 +01:00
|
|
|
|
if (events & EPOLLIN)
|
2021-01-17 16:12:54 +01:00
|
|
|
|
tiocswinsz(term);
|
|
|
|
|
|
|
|
|
|
|
|
fdm_del(fdm, fd);
|
|
|
|
|
|
term->window->resize_timeout_fd = -1;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
send_dimensions_to_client(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct wl_window *win = term->window;
|
|
|
|
|
|
|
2021-01-21 15:14:43 +01:00
|
|
|
|
if (!win->is_resizing || term->conf->resize_delay_ms == 0) {
|
2021-01-17 16:12:54 +01:00
|
|
|
|
/* Send new dimensions to client immediately */
|
|
|
|
|
|
tiocswinsz(term);
|
|
|
|
|
|
|
|
|
|
|
|
/* And make sure to reset and deallocate a lingering timer */
|
|
|
|
|
|
if (win->resize_timeout_fd >= 0) {
|
|
|
|
|
|
fdm_del(term->fdm, win->resize_timeout_fd);
|
|
|
|
|
|
win->resize_timeout_fd = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Send new dimensions to client “in a while” */
|
2021-01-21 15:14:43 +01:00
|
|
|
|
assert(win->is_resizing && term->conf->resize_delay_ms > 0);
|
2021-01-17 16:12:54 +01:00
|
|
|
|
|
|
|
|
|
|
int fd = win->resize_timeout_fd;
|
2021-01-21 15:14:43 +01:00
|
|
|
|
uint16_t delay_ms = term->conf->resize_delay_ms;
|
2021-01-17 16:12:54 +01:00
|
|
|
|
bool successfully_scheduled = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
|
/* Lazy create timer fd */
|
|
|
|
|
|
fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
|
LOG_ERRNO("failed to create TIOCSWINSZ timer");
|
|
|
|
|
|
else if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_tiocswinsz, term)) {
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
fd = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
win->resize_timeout_fd = fd;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fd >= 0) {
|
2021-01-17 16:38:24 +01:00
|
|
|
|
/* Reset timeout */
|
2021-01-17 16:12:54 +01:00
|
|
|
|
const struct itimerspec timeout = {
|
|
|
|
|
|
.it_value = {.tv_sec = 0, .tv_nsec = delay_ms * 1000000},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (timerfd_settime(fd, 0, &timeout, NULL) < 0) {
|
|
|
|
|
|
LOG_ERRNO("failed to arm TIOCSWINSZ timer");
|
|
|
|
|
|
fdm_del(term->fdm, fd);
|
|
|
|
|
|
win->resize_timeout_fd = -1;
|
|
|
|
|
|
} else
|
|
|
|
|
|
successfully_scheduled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!successfully_scheduled)
|
|
|
|
|
|
tiocswinsz(term);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
/* Move to terminal.c? */
|
2020-02-25 19:51:03 +01:00
|
|
|
|
static bool
|
2020-02-08 14:08:16 +01:00
|
|
|
|
maybe_resize(struct terminal *term, int width, int height, bool force)
|
2019-07-05 10:16:56 +02:00
|
|
|
|
{
|
2020-03-17 13:27:26 +01:00
|
|
|
|
if (term->is_shutting_down)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-02-26 12:21:03 +01:00
|
|
|
|
if (!term->window->is_configured)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-02-25 20:29:44 +01:00
|
|
|
|
if (term->cell_width == 0 && term->cell_height == 0)
|
2020-02-25 19:51:03 +01:00
|
|
|
|
return false;
|
2020-01-03 12:54:03 +01:00
|
|
|
|
|
2019-08-12 21:49:17 +02:00
|
|
|
|
int scale = -1;
|
2019-10-27 19:08:48 +01:00
|
|
|
|
tll_foreach(term->window->on_outputs, it) {
|
2019-08-12 21:49:17 +02:00
|
|
|
|
if (it->item->scale > scale)
|
|
|
|
|
|
scale = it->item->scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scale == -1) {
|
|
|
|
|
|
/* Haven't 'entered' an output yet? */
|
2020-09-14 17:34:04 +02:00
|
|
|
|
scale = term->scale;
|
2019-08-12 21:49:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-21 17:56:41 +02:00
|
|
|
|
width *= scale;
|
|
|
|
|
|
height *= scale;
|
2019-08-12 21:22:38 +02:00
|
|
|
|
|
2020-02-26 20:59:11 +01:00
|
|
|
|
if (width == 0 && height == 0) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* The compositor is letting us choose the size
|
|
|
|
|
|
*
|
|
|
|
|
|
* If we have a "last" used size - use that. Otherwise, use
|
|
|
|
|
|
* the size from the user configuration.
|
|
|
|
|
|
*/
|
2020-10-20 20:58:03 +02:00
|
|
|
|
if (term->stashed_width != 0 && term->stashed_height != 0) {
|
|
|
|
|
|
width = term->stashed_width;
|
|
|
|
|
|
height = term->stashed_height;
|
2020-02-26 20:59:11 +01:00
|
|
|
|
} else {
|
2020-09-08 19:17:29 +02:00
|
|
|
|
switch (term->conf->size.type) {
|
|
|
|
|
|
case CONF_SIZE_PX:
|
2020-11-30 02:24:38 +00:00
|
|
|
|
width = term->conf->size.width;
|
|
|
|
|
|
height = term->conf->size.height;
|
2020-09-08 19:17:29 +02:00
|
|
|
|
|
|
|
|
|
|
if (term->window->use_csd == CSD_YES) {
|
|
|
|
|
|
/* Take CSD title bar into account */
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(!term->window->is_fullscreen);
|
2020-09-08 19:17:29 +02:00
|
|
|
|
height -= term->conf->csd.title_height;
|
|
|
|
|
|
}
|
2020-09-14 17:34:04 +02:00
|
|
|
|
|
|
|
|
|
|
width *= scale;
|
|
|
|
|
|
height *= scale;
|
2020-09-08 19:17:29 +02:00
|
|
|
|
break;
|
2020-02-28 18:50:15 +01:00
|
|
|
|
|
2020-09-08 19:17:29 +02:00
|
|
|
|
case CONF_SIZE_CELLS:
|
2020-11-30 02:24:38 +00:00
|
|
|
|
width = term->conf->size.width * term->cell_width;
|
|
|
|
|
|
height = term->conf->size.height * term->cell_height;
|
2020-09-17 17:37:58 +02:00
|
|
|
|
|
|
|
|
|
|
width += 2 * term->conf->pad_x * scale;
|
|
|
|
|
|
height += 2 * term->conf->pad_y * scale;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Ensure we can scale to logical size, and back to
|
|
|
|
|
|
* pixels without truncating.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (width % scale)
|
|
|
|
|
|
width += scale - width % scale;
|
|
|
|
|
|
if (height % scale)
|
|
|
|
|
|
height += scale - height % scale;
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(width % scale == 0);
|
|
|
|
|
|
xassert(height % scale == 0);
|
2020-09-08 19:17:29 +02:00
|
|
|
|
break;
|
2020-02-28 18:50:15 +01:00
|
|
|
|
}
|
2020-02-26 20:59:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-25 19:10:48 +01:00
|
|
|
|
/* Don't shrink grid too much */
|
2020-09-07 19:34:06 +02:00
|
|
|
|
const int min_cols = 2;
|
|
|
|
|
|
const int min_rows = 1;
|
2020-02-25 19:10:48 +01:00
|
|
|
|
|
|
|
|
|
|
/* Minimum window size */
|
2020-03-02 18:42:49 +01:00
|
|
|
|
const int min_width = min_cols * term->cell_width;
|
|
|
|
|
|
const int min_height = min_rows * term->cell_height;
|
2020-02-25 19:10:48 +01:00
|
|
|
|
|
|
|
|
|
|
width = max(width, min_width);
|
|
|
|
|
|
height = max(height, min_height);
|
|
|
|
|
|
|
2020-03-02 18:42:49 +01:00
|
|
|
|
/* Padding */
|
|
|
|
|
|
const int max_pad_x = (width - min_width) / 2;
|
|
|
|
|
|
const int max_pad_y = (height - min_height) / 2;
|
|
|
|
|
|
const int pad_x = min(max_pad_x, scale * term->conf->pad_x);
|
|
|
|
|
|
const int pad_y = min(max_pad_y, scale * term->conf->pad_y);
|
|
|
|
|
|
|
2020-02-08 14:08:16 +01:00
|
|
|
|
if (!force && width == term->width && height == term->height && scale == term->scale)
|
2020-02-25 19:51:03 +01:00
|
|
|
|
return false;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-01-12 12:19:38 +01:00
|
|
|
|
/* Cancel an application initiated "Synchronized Update" */
|
2020-01-12 12:55:19 +01:00
|
|
|
|
term_disable_app_sync_updates(term);
|
2020-01-12 12:19:38 +01:00
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
/* Drop out of URL mode */
|
|
|
|
|
|
urls_reset(term);
|
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
term->width = width;
|
|
|
|
|
|
term->height = height;
|
2019-08-12 21:32:38 +02:00
|
|
|
|
term->scale = scale;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
|
const int scrollback_lines = term->render.scrollback_lines;
|
2019-07-09 16:26:36 +02:00
|
|
|
|
|
2020-02-15 19:01:26 +01:00
|
|
|
|
/* Screen rows/cols before resize */
|
2019-07-09 09:12:41 +02:00
|
|
|
|
const int old_cols = term->cols;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
const int old_rows = term->rows;
|
2020-02-15 19:01:26 +01:00
|
|
|
|
|
|
|
|
|
|
/* Screen rows/cols after resize */
|
2020-03-02 18:42:49 +01:00
|
|
|
|
const int new_cols = (term->width - 2 * pad_x) / term->cell_width;
|
|
|
|
|
|
const int new_rows = (term->height - 2 * pad_y) / term->cell_height;
|
2020-02-15 19:01:26 +01:00
|
|
|
|
|
|
|
|
|
|
/* Grid rows/cols after resize */
|
2019-08-22 17:33:23 +02:00
|
|
|
|
const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1));
|
|
|
|
|
|
const int new_alt_grid_rows = 1 << (32 - __builtin_clz(new_rows));
|
2019-07-09 09:12:41 +02:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(new_cols >= 1);
|
|
|
|
|
|
xassert(new_rows >= 1);
|
2020-02-15 19:01:26 +01:00
|
|
|
|
|
|
|
|
|
|
/* Margins */
|
2021-01-06 11:17:29 +01:00
|
|
|
|
const int grid_width = new_cols * term->cell_width;
|
|
|
|
|
|
const int grid_height = new_rows * term->cell_height;
|
|
|
|
|
|
const int total_x_pad = term->width - grid_width;
|
|
|
|
|
|
const int total_y_pad = term->height - grid_height;
|
|
|
|
|
|
|
2021-01-18 09:52:11 +01:00
|
|
|
|
if (term->conf->center && !term->window->is_resizing) {
|
2021-01-06 11:17:29 +01:00
|
|
|
|
term->margins.left = total_x_pad / 2;
|
|
|
|
|
|
term->margins.top = total_y_pad / 2;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
term->margins.left = pad_x;
|
|
|
|
|
|
term->margins.top = pad_y;
|
|
|
|
|
|
}
|
|
|
|
|
|
term->margins.right = total_x_pad - term->margins.left;
|
|
|
|
|
|
term->margins.bottom = total_y_pad - term->margins.top;
|
2019-08-27 15:25:35 +02:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(term->margins.left >= pad_x);
|
|
|
|
|
|
xassert(term->margins.right >= pad_x);
|
|
|
|
|
|
xassert(term->margins.top >= pad_y);
|
|
|
|
|
|
xassert(term->margins.bottom >= pad_y);
|
2020-02-25 19:10:48 +01:00
|
|
|
|
|
2020-02-15 22:19:08 +01:00
|
|
|
|
if (new_cols == old_cols && new_rows == old_rows) {
|
|
|
|
|
|
LOG_DBG("grid layout unaffected; skipping reflow");
|
|
|
|
|
|
goto damage_view;
|
render: initial support for text reflow
The algorithm is as follows:
Start at the beginning of the scrollback. That is, at the oldest
emitted lines. This is done by taking the current offset, and adding
the number of (old) screen rows, and then iterating until we find the
first allocated line.
Next, we iterate the entire old grid. At the beginning, we allocate a
line for the new grid, and setup a global pointer for that line, and
the current cell index.
For each line in the old grid, iterate its cells. Copy the the cells
over to the new line. Whenever the new line reaches its maximum number
of columns, we line break it by increasing the current row index and
allocating a new row (if necessary - we may be overwriting old
scrollback if the new grid is smaller than the old grid).
Whenever we reach the end of a line of the old grid, we insert a line
break in the new grid's line too **if** the last cell in the old line
was empty. If it was **not** empty, we **don't** line break the new
line.
Furthermore, empty cells in general need special consideration. A line
ending with a string of empty cells doesn't have to be copied the new
line. And more importantly, should **not** increase the new line's
cell index (which may cause line breaks, which is incorrect).
However, if a string of empty cells is followed by non empty cells, we
need to copy all the preceding empty cells to the line too.
When the entire scrollback history has been reflowed, we need to
figure out the new grid's offset.
This is done by trying to put the **last** emitted line at the bottom
of the screen. I.e. the new offset is typically "last_line_idx -
term->rows". However, we need to handle empty lines. So, after
subtracting the number of screen rows, we _increase_ the offset until
we see a non-empty line. This ensures we handle grid's that doesn't
fill an entire screen.
Finally, we need to re-position the cursor. This is done by trying to
place the cursor **at** (_not_ after) the last emitted line. We keep
the current cursor column as is (but possibly truncated, if the grid's
width decreased).
2020-02-10 20:35:24 +01:00
|
|
|
|
}
|
2019-07-09 09:12:41 +02:00
|
|
|
|
|
resize: don’t reflow text on alt screen
Alt screen applications normally reflow/readjust themselves on a
window resize.
When we do it too, the result is graphical glitches/flashes since our
re-flowed text is rendered in one frame, and the application re-flowed
text soon thereafter.
We can’t avoid rendering some kind of re-flowed frame, since we don’t
know when, or even if, the application will update itself. To avoid
glitches, we need to render, as closely as possible, what the
application itself will render shortly.
This is actually pretty simple; we just need to copy the visible
content over from the old grid to the new grid. We don’t bother with
text re-flow, but simply truncate long lines.
To simplify things, we simply cancel any active selection (since often
times, it will be corrupted anyway when the application redraws
itself).
Since we’re not reflowing text, there’s no need to translate e.g. the
cursor position - we just keep the current position (but bounded to
the new dimensions).
Fun thing: ‘less’ gets corrupted if we don’t leave the cursor at
the (new) bottom row. To handle this, we check if the cursor (before
resize) is at the bottom row, and if so, we move it to the new bottom
row.
Closes #221
2020-11-24 19:00:57 +01:00
|
|
|
|
if (term->grid == &term->alt)
|
|
|
|
|
|
selection_cancel(term);
|
|
|
|
|
|
|
2020-04-17 22:18:02 +02:00
|
|
|
|
struct coord *const tracking_points[] = {
|
|
|
|
|
|
&term->selection.start,
|
|
|
|
|
|
&term->selection.end,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
resize: don’t reflow text on alt screen
Alt screen applications normally reflow/readjust themselves on a
window resize.
When we do it too, the result is graphical glitches/flashes since our
re-flowed text is rendered in one frame, and the application re-flowed
text soon thereafter.
We can’t avoid rendering some kind of re-flowed frame, since we don’t
know when, or even if, the application will update itself. To avoid
glitches, we need to render, as closely as possible, what the
application itself will render shortly.
This is actually pretty simple; we just need to copy the visible
content over from the old grid to the new grid. We don’t bother with
text re-flow, but simply truncate long lines.
To simplify things, we simply cancel any active selection (since often
times, it will be corrupted anyway when the application redraws
itself).
Since we’re not reflowing text, there’s no need to translate e.g. the
cursor position - we just keep the current position (but bounded to
the new dimensions).
Fun thing: ‘less’ gets corrupted if we don’t leave the cursor at
the (new) bottom row. To handle this, we check if the cursor (before
resize) is at the bottom row, and if so, we move it to the new bottom
row.
Closes #221
2020-11-24 19:00:57 +01:00
|
|
|
|
/* Resize grids */
|
|
|
|
|
|
grid_resize_and_reflow(
|
2020-04-17 22:18:02 +02:00
|
|
|
|
&term->normal, new_normal_grid_rows, new_cols, old_rows, new_rows,
|
resize: don’t reflow text on alt screen
Alt screen applications normally reflow/readjust themselves on a
window resize.
When we do it too, the result is graphical glitches/flashes since our
re-flowed text is rendered in one frame, and the application re-flowed
text soon thereafter.
We can’t avoid rendering some kind of re-flowed frame, since we don’t
know when, or even if, the application will update itself. To avoid
glitches, we need to render, as closely as possible, what the
application itself will render shortly.
This is actually pretty simple; we just need to copy the visible
content over from the old grid to the new grid. We don’t bother with
text re-flow, but simply truncate long lines.
To simplify things, we simply cancel any active selection (since often
times, it will be corrupted anyway when the application redraws
itself).
Since we’re not reflowing text, there’s no need to translate e.g. the
cursor position - we just keep the current position (but bounded to
the new dimensions).
Fun thing: ‘less’ gets corrupted if we don’t leave the cursor at
the (new) bottom row. To handle this, we check if the cursor (before
resize) is at the bottom row, and if so, we move it to the new bottom
row.
Closes #221
2020-11-24 19:00:57 +01:00
|
|
|
|
ALEN(tracking_points), tracking_points,
|
2020-09-06 19:14:46 +02:00
|
|
|
|
term->composed_count, term->composed);
|
2020-04-17 22:18:02 +02:00
|
|
|
|
|
resize: don’t reflow text on alt screen
Alt screen applications normally reflow/readjust themselves on a
window resize.
When we do it too, the result is graphical glitches/flashes since our
re-flowed text is rendered in one frame, and the application re-flowed
text soon thereafter.
We can’t avoid rendering some kind of re-flowed frame, since we don’t
know when, or even if, the application will update itself. To avoid
glitches, we need to render, as closely as possible, what the
application itself will render shortly.
This is actually pretty simple; we just need to copy the visible
content over from the old grid to the new grid. We don’t bother with
text re-flow, but simply truncate long lines.
To simplify things, we simply cancel any active selection (since often
times, it will be corrupted anyway when the application redraws
itself).
Since we’re not reflowing text, there’s no need to translate e.g. the
cursor position - we just keep the current position (but bounded to
the new dimensions).
Fun thing: ‘less’ gets corrupted if we don’t leave the cursor at
the (new) bottom row. To handle this, we check if the cursor (before
resize) is at the bottom row, and if so, we move it to the new bottom
row.
Closes #221
2020-11-24 19:00:57 +01:00
|
|
|
|
grid_resize_without_reflow(
|
|
|
|
|
|
&term->alt, new_alt_grid_rows, new_cols, old_rows, new_rows);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
2019-11-16 10:54:56 +01:00
|
|
|
|
/* Reset tab stops */
|
|
|
|
|
|
tll_free(term->tab_stops);
|
|
|
|
|
|
for (int c = 0; c < new_cols; c += 8)
|
|
|
|
|
|
tll_push_back(term->tab_stops, c);
|
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
|
term->cols = new_cols;
|
|
|
|
|
|
term->rows = new_rows;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2020-10-04 13:14:09 +02:00
|
|
|
|
sixel_reflow(term);
|
|
|
|
|
|
|
2021-05-03 17:57:16 +02:00
|
|
|
|
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
2020-02-28 18:51:51 +01:00
|
|
|
|
LOG_DBG("resize: %dx%d, grid: cols=%d, rows=%d "
|
|
|
|
|
|
"(left-margin=%d, right-margin=%d, top-margin=%d, bottom-margin=%d)",
|
|
|
|
|
|
term->width, term->height, term->cols, term->rows,
|
|
|
|
|
|
term->margins.left, term->margins.right, term->margins.top, term->margins.bottom);
|
2021-05-03 17:57:16 +02:00
|
|
|
|
#else
|
|
|
|
|
|
LOG_INFO("resize: %dx%d pixels, %dx%d chars",
|
|
|
|
|
|
term->width, term->height, term->cols, term->rows);
|
|
|
|
|
|
#endif
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
|
if (term->scroll_region.start >= term->rows)
|
|
|
|
|
|
term->scroll_region.start = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->scroll_region.end >= old_rows)
|
2019-07-05 10:16:56 +02:00
|
|
|
|
term->scroll_region.end = term->rows;
|
|
|
|
|
|
|
2020-05-01 11:56:13 +02:00
|
|
|
|
term->render.last_cursor.row = NULL;
|
2020-02-15 22:19:08 +01:00
|
|
|
|
|
|
|
|
|
|
damage_view:
|
2021-01-17 16:12:54 +01:00
|
|
|
|
/* Signal TIOCSWINSZ */
|
|
|
|
|
|
send_dimensions_to_client(term);
|
|
|
|
|
|
|
2020-10-20 20:58:03 +02:00
|
|
|
|
if (!term->window->is_maximized &&
|
|
|
|
|
|
!term->window->is_fullscreen &&
|
|
|
|
|
|
!term->window->is_tiled)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Stash current size, to enable us to restore it when we're
|
|
|
|
|
|
* being un-maximized/fullscreened/tiled */
|
|
|
|
|
|
term->stashed_width = term->width;
|
|
|
|
|
|
term->stashed_height = term->height;
|
2020-02-26 20:59:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 18:26:15 +01:00
|
|
|
|
#if 0
|
|
|
|
|
|
/* TODO: doesn't include CSD title bar */
|
2020-02-25 19:51:03 +01:00
|
|
|
|
xdg_toplevel_set_min_size(
|
|
|
|
|
|
term->window->xdg_toplevel, min_width / scale, min_height / scale);
|
2020-03-03 18:26:15 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
bool title_shown = !term->window->is_fullscreen &&
|
|
|
|
|
|
term->window->use_csd == CSD_YES;
|
|
|
|
|
|
|
|
|
|
|
|
int title_height = title_shown ? term->conf->csd.title_height : 0;
|
|
|
|
|
|
xdg_surface_set_window_geometry(
|
|
|
|
|
|
term->window->xdg_surface,
|
|
|
|
|
|
0,
|
|
|
|
|
|
-title_height,
|
|
|
|
|
|
term->width / term->scale,
|
|
|
|
|
|
term->height / term->scale + title_height);
|
2020-03-03 18:29:46 +01:00
|
|
|
|
}
|
2020-02-29 11:42:00 +01:00
|
|
|
|
|
2020-02-08 18:22:14 +01:00
|
|
|
|
tll_free(term->normal.scroll_damage);
|
|
|
|
|
|
tll_free(term->alt.scroll_damage);
|
2020-02-29 11:42:00 +01:00
|
|
|
|
|
2020-02-08 14:08:16 +01:00
|
|
|
|
term->render.last_buf = NULL;
|
2019-07-26 18:51:47 +02:00
|
|
|
|
term_damage_view(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
|
render_refresh_csd(term);
|
|
|
|
|
|
render_refresh_search(term);
|
2020-01-03 13:56:10 +01:00
|
|
|
|
render_refresh(term);
|
2020-02-29 11:42:00 +01:00
|
|
|
|
|
2020-02-25 19:51:03 +01:00
|
|
|
|
return true;
|
2020-02-08 14:08:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-25 19:51:03 +01:00
|
|
|
|
bool
|
2020-02-08 14:08:16 +01:00
|
|
|
|
render_resize(struct terminal *term, int width, int height)
|
|
|
|
|
|
{
|
|
|
|
|
|
return maybe_resize(term, width, height, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-25 19:51:03 +01:00
|
|
|
|
bool
|
2020-02-08 14:08:16 +01:00
|
|
|
|
render_resize_force(struct terminal *term, int width, int height)
|
|
|
|
|
|
{
|
|
|
|
|
|
return maybe_resize(term, width, height, true);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
}
|
2020-07-08 18:08:39 +02:00
|
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
|
static void xcursor_callback(
|
|
|
|
|
|
void *data, struct wl_callback *wl_callback, uint32_t callback_data);
|
|
|
|
|
|
static const struct wl_callback_listener xcursor_listener = {
|
|
|
|
|
|
.done = &xcursor_callback,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-09 09:52:11 +02:00
|
|
|
|
render_xcursor_update(struct seat *seat)
|
2020-01-04 22:01:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
/* If called from a frame callback, we may no longer have mouse focus */
|
2020-07-09 09:52:11 +02:00
|
|
|
|
if (!seat->mouse_focus)
|
2020-01-04 22:01:19 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(seat->pointer.xcursor != NULL);
|
2020-07-31 17:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
if (seat->pointer.xcursor == XCURSOR_HIDDEN) {
|
|
|
|
|
|
/* Hide cursor */
|
|
|
|
|
|
wl_surface_attach(seat->pointer.surface, NULL, 0, 0);
|
|
|
|
|
|
wl_surface_commit(seat->pointer.surface);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-09 09:52:11 +02:00
|
|
|
|
seat->pointer.cursor = wl_cursor_theme_get_cursor(
|
|
|
|
|
|
seat->pointer.theme, seat->pointer.xcursor);
|
|
|
|
|
|
|
2020-07-08 18:08:39 +02:00
|
|
|
|
if (seat->pointer.cursor == NULL) {
|
2020-07-10 12:06:55 +02:00
|
|
|
|
LOG_ERR("failed to load xcursor pointer '%s'", seat->pointer.xcursor);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-09 09:52:11 +02:00
|
|
|
|
const int scale = seat->pointer.scale;
|
2020-07-08 18:08:39 +02:00
|
|
|
|
struct wl_cursor_image *image = seat->pointer.cursor->images[0];
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
|
|
|
|
|
wl_surface_attach(
|
2020-07-08 18:08:39 +02:00
|
|
|
|
seat->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
|
|
|
|
|
wl_pointer_set_cursor(
|
2020-07-08 18:08:39 +02:00
|
|
|
|
seat->wl_pointer, seat->pointer.serial,
|
|
|
|
|
|
seat->pointer.surface,
|
2020-01-04 22:01:19 +01:00
|
|
|
|
image->hotspot_x / scale, image->hotspot_y / scale);
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
2020-07-08 18:08:39 +02:00
|
|
|
|
seat->pointer.surface, 0, 0, INT32_MAX, INT32_MAX);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
2020-07-08 18:08:39 +02:00
|
|
|
|
wl_surface_set_buffer_scale(seat->pointer.surface, scale);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(seat->pointer.xcursor_callback == NULL);
|
2020-07-08 18:08:39 +02:00
|
|
|
|
seat->pointer.xcursor_callback = wl_surface_frame(seat->pointer.surface);
|
|
|
|
|
|
wl_callback_add_listener(seat->pointer.xcursor_callback, &xcursor_listener, seat);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
2020-07-08 18:08:39 +02:00
|
|
|
|
wl_surface_commit(seat->pointer.surface);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data)
|
|
|
|
|
|
{
|
2020-07-08 18:08:39 +02:00
|
|
|
|
struct seat *seat = data;
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
2021-01-16 20:16:00 +00:00
|
|
|
|
xassert(seat->pointer.xcursor_callback == wl_callback);
|
2020-01-04 22:01:19 +01:00
|
|
|
|
wl_callback_destroy(wl_callback);
|
2020-07-08 18:08:39 +02:00
|
|
|
|
seat->pointer.xcursor_callback = NULL;
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
2020-07-09 09:52:11 +02:00
|
|
|
|
if (seat->pointer.xcursor_pending) {
|
|
|
|
|
|
render_xcursor_update(seat);
|
|
|
|
|
|
seat->pointer.xcursor_pending = false;
|
2020-01-05 00:10:44 +01:00
|
|
|
|
}
|
2020-01-04 22:01:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct renderer *renderer = data;
|
2020-07-08 18:08:39 +02:00
|
|
|
|
struct wayland *wayl = renderer->wayl;
|
2020-01-05 00:10:44 +01:00
|
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
|
tll_foreach(renderer->wayl->terms, it) {
|
|
|
|
|
|
struct terminal *term = it->item;
|
|
|
|
|
|
|
2020-12-06 12:18:46 +01:00
|
|
|
|
if (unlikely(!term->window->is_configured))
|
2020-01-04 22:01:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
bool grid = term->render.refresh.grid;
|
|
|
|
|
|
bool csd = term->render.refresh.csd;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
bool search = term->is_searching && term->render.refresh.search;
|
2020-03-25 18:23:55 +01:00
|
|
|
|
bool title = term->render.refresh.title;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
bool urls = urls_mode_is_active(term) && term->render.refresh.urls;
|
2020-03-06 19:16:54 +01:00
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
if (!(grid | csd | search | title | urls))
|
2020-12-06 12:18:46 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
if (term->render.app_sync_updates.enabled && !(csd | search | title | urls))
|
2020-12-06 12:18:46 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
term->render.refresh.grid = false;
|
|
|
|
|
|
term->render.refresh.csd = false;
|
|
|
|
|
|
term->render.refresh.search = false;
|
2020-03-25 18:23:55 +01:00
|
|
|
|
term->render.refresh.title = false;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
term->render.refresh.urls = false;
|
2020-03-06 19:16:54 +01:00
|
|
|
|
|
|
|
|
|
|
if (term->window->frame_callback == NULL) {
|
url-mode: snapshot screen state when entering URL mode
Previously, we automatically exited URL mode whenever we received data
on the PTY. This was done since we don’t know _what_ has changed on
the screen, and we don’t want to display misleading jump labels.
However, this becomes a problem in curses-like applications that
periodically updates part of the screen. For example, a statusbar with
a clock.
This patch changes this behavior; instead of cancelling URL mode when
receiving PTY data, we snapshot the grid when entering URL mode.
When *rendering*, we use the snapshot:ed grid, while PTY updates
modify the “real” grid.
Snapshot:ing the grid means taking a full/deep copy of the current
grid, including sixel images etc.
Finally, it isn’t necessary to “damage” the entire view
when *entering* URL mode, since we’re at that point the renderer is in
sync with the grid. But we *do* need to damage the entire view when
exiting URL mode, since the grid changes on the “real” grid hasn’t
been tracked by the renderer.
2021-02-22 10:22:41 +01:00
|
|
|
|
struct grid *original_grid = term->grid;
|
|
|
|
|
|
if (urls_mode_is_active(term)) {
|
|
|
|
|
|
xassert(term->url_grid_snapshot != NULL);
|
|
|
|
|
|
term->grid = term->url_grid_snapshot;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
|
if (csd && term->window->use_csd == CSD_YES) {
|
|
|
|
|
|
quirk_weston_csd_on(term);
|
|
|
|
|
|
render_csd(term);
|
|
|
|
|
|
quirk_weston_csd_off(term);
|
|
|
|
|
|
}
|
2020-03-25 18:23:55 +01:00
|
|
|
|
if (title)
|
|
|
|
|
|
render_update_title(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
|
if (search)
|
|
|
|
|
|
render_search_box(term);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
if (urls)
|
|
|
|
|
|
render_urls(term);
|
|
|
|
|
|
if (grid | csd | search | urls)
|
|
|
|
|
|
grid_render(term);
|
|
|
|
|
|
|
|
|
|
|
|
tll_foreach(term->wl->seats, it) {
|
2020-12-20 15:01:21 -07:00
|
|
|
|
if (it->item.kbd_focus == term)
|
2021-03-23 13:56:33 +01:00
|
|
|
|
ime_update_cursor_rect(&it->item);
|
2021-01-31 11:12:07 +01:00
|
|
|
|
}
|
url-mode: snapshot screen state when entering URL mode
Previously, we automatically exited URL mode whenever we received data
on the PTY. This was done since we don’t know _what_ has changed on
the screen, and we don’t want to display misleading jump labels.
However, this becomes a problem in curses-like applications that
periodically updates part of the screen. For example, a statusbar with
a clock.
This patch changes this behavior; instead of cancelling URL mode when
receiving PTY data, we snapshot the grid when entering URL mode.
When *rendering*, we use the snapshot:ed grid, while PTY updates
modify the “real” grid.
Snapshot:ing the grid means taking a full/deep copy of the current
grid, including sixel images etc.
Finally, it isn’t necessary to “damage” the entire view
when *entering* URL mode, since we’re at that point the renderer is in
sync with the grid. But we *do* need to damage the entire view when
exiting URL mode, since the grid changes on the “real” grid hasn’t
been tracked by the renderer.
2021-02-22 10:22:41 +01:00
|
|
|
|
|
|
|
|
|
|
term->grid = original_grid;
|
2020-03-06 19:16:54 +01:00
|
|
|
|
} else {
|
2020-01-05 00:10:44 +01:00
|
|
|
|
/* Tells the frame callback to render again */
|
2020-03-24 17:42:29 +01:00
|
|
|
|
term->render.pending.grid |= grid;
|
|
|
|
|
|
term->render.pending.csd |= csd;
|
|
|
|
|
|
term->render.pending.search |= search;
|
2020-03-25 18:23:55 +01:00
|
|
|
|
term->render.pending.title |= title;
|
2021-01-31 11:12:07 +01:00
|
|
|
|
term->render.pending.urls |= urls;
|
2020-01-05 00:10:44 +01:00
|
|
|
|
}
|
2020-01-04 22:01:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-08 18:08:39 +02:00
|
|
|
|
tll_foreach(wayl->seats, it) {
|
2020-07-09 09:52:11 +02:00
|
|
|
|
if (it->item.pointer.xcursor_pending) {
|
2020-07-08 18:08:39 +02:00
|
|
|
|
if (it->item.pointer.xcursor_callback == NULL) {
|
2020-07-09 09:52:11 +02:00
|
|
|
|
render_xcursor_update(&it->item);
|
|
|
|
|
|
it->item.pointer.xcursor_pending = false;
|
2020-07-08 18:08:39 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
/* Frame callback will call render_xcursor_update() */
|
|
|
|
|
|
}
|
2020-01-05 00:10:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-01-04 22:01:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
|
void
|
2020-03-25 18:23:55 +01:00
|
|
|
|
render_refresh_title(struct terminal *term)
|
2019-07-05 10:16:56 +02:00
|
|
|
|
{
|
2020-03-25 18:23:55 +01:00
|
|
|
|
term->render.refresh.title = true;
|
2019-07-05 10:44:09 +02:00
|
|
|
|
}
|
2019-07-24 20:09:49 +02:00
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
render_refresh(struct terminal *term)
|
|
|
|
|
|
{
|
2020-03-06 19:16:54 +01:00
|
|
|
|
term->render.refresh.grid = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
render_refresh_csd(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->window->use_csd == CSD_YES)
|
|
|
|
|
|
term->render.refresh.csd = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
render_refresh_search(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (term->is_searching)
|
|
|
|
|
|
term->render.refresh.search = true;
|
2019-07-24 20:09:49 +02:00
|
|
|
|
}
|
2020-01-04 22:01:19 +01:00
|
|
|
|
|
2021-01-31 11:12:07 +01:00
|
|
|
|
void
|
|
|
|
|
|
render_refresh_urls(struct terminal *term)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (urls_mode_is_active(term))
|
|
|
|
|
|
term->render.refresh.urls = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
|
bool
|
2020-07-09 09:52:11 +02:00
|
|
|
|
render_xcursor_set(struct seat *seat, struct terminal *term, const char *xcursor)
|
2020-01-04 22:01:19 +01:00
|
|
|
|
{
|
2020-07-08 18:08:39 +02:00
|
|
|
|
if (seat->pointer.theme == NULL)
|
2020-01-04 22:01:19 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-07-08 18:08:39 +02:00
|
|
|
|
if (seat->mouse_focus == NULL) {
|
|
|
|
|
|
seat->pointer.xcursor = NULL;
|
2020-01-04 22:01:19 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-08 18:08:39 +02:00
|
|
|
|
if (seat->mouse_focus != term) {
|
2020-01-04 22:01:19 +01:00
|
|
|
|
/* This terminal doesn't have mouse focus */
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-09 09:52:11 +02:00
|
|
|
|
if (seat->pointer.xcursor == xcursor)
|
2020-01-04 22:01:19 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
/* FDM hook takes care of actual rendering */
|
2020-07-09 09:52:11 +02:00
|
|
|
|
seat->pointer.xcursor_pending = true;
|
|
|
|
|
|
seat->pointer.xcursor = xcursor;
|
2020-07-08 16:45:26 +02:00
|
|
|
|
return true;
|
2020-01-04 22:01:19 +01:00
|
|
|
|
}
|