2019-07-05 10:16:56 +02:00
|
|
|
#include "render.h"
|
|
|
|
|
|
|
|
|
|
#include <string.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>
|
2019-08-01 20:09:16 +02:00
|
|
|
#include <sys/prctl.h>
|
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-02-15 18:58:36 +01:00
|
|
|
#include "config.h"
|
2019-07-08 13:57:31 +02:00
|
|
|
#include "grid.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"
|
2020-05-01 11:46:24 +02:00
|
|
|
#include "util.h"
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
#define TIME_FRAME_RENDERING 0
|
|
|
|
|
#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-04-13 12:03:11 +02:00
|
|
|
} presentation_statistics = {};
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct renderer *renderer = calloc(1, sizeof(*renderer));
|
|
|
|
|
*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
|
|
|
}
|
|
|
|
|
|
2019-12-31 15:39:40 +01:00
|
|
|
static void __attribute__((destructor))
|
|
|
|
|
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);
|
2019-12-31 20:01:47 +01:00
|
|
|
chars += snprintf(&msg[chars], sizeof(msg) - chars,
|
2019-12-31 20:31:06 +01:00
|
|
|
"input - %lu µs -> ", 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);
|
2019-12-31 20:01:47 +01:00
|
|
|
chars += snprintf(&msg[chars], sizeof(msg) - chars,
|
2019-12-31 20:31:06 +01:00
|
|
|
"commit - %lu µs -> ", diff.tv_usec);
|
2019-12-31 15:39:40 +01:00
|
|
|
|
2020-01-01 11:37:47 +01:00
|
|
|
if (use_input) {
|
2020-01-21 18:51:04 +01:00
|
|
|
assert(timercmp(&presented, input, >));
|
|
|
|
|
timersub(&presented, input, &diff);
|
2020-01-01 11:37:47 +01:00
|
|
|
} else {
|
2020-01-21 18:51:04 +01:00
|
|
|
assert(timercmp(&presented, commit, >));
|
|
|
|
|
timersub(&presented, commit, &diff);
|
2020-01-01 11:37:47 +01:00
|
|
|
}
|
2019-12-31 15:39:40 +01:00
|
|
|
|
2019-12-31 20:01:47 +01:00
|
|
|
chars += snprintf(&msg[chars], sizeof(msg) - chars,
|
2019-12-31 20:31:06 +01:00
|
|
|
"presented (total: %lu µs)", 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
|
|
|
{
|
2020-02-28 18:35:21 +01:00
|
|
|
if (alpha == 0)
|
|
|
|
|
return (pixman_color_t){0, 0, 0, 0};
|
|
|
|
|
|
2019-08-16 22:06:06 +02:00
|
|
|
int alpha_div = 0xffff / alpha;
|
2019-08-16 20:40:32 +02:00
|
|
|
return (pixman_color_t){
|
2019-08-16 22:06:06 +02:00
|
|
|
.red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) / alpha_div,
|
|
|
|
|
.green = ((color >> 8 & 0xff) | (color >> 0 & 0xff00)) / alpha_div,
|
|
|
|
|
.blue = ((color >> 0 & 0xff) | (color << 8 & 0xff00)) / alpha_div,
|
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-16 20:40:32 +02:00
|
|
|
static inline void
|
2020-04-09 13:41:16 +02:00
|
|
|
color_dim(pixman_color_t *color)
|
2019-08-16 20:40:32 +02:00
|
|
|
{
|
|
|
|
|
color->red /= 2;
|
|
|
|
|
color->green /= 2;
|
|
|
|
|
color->blue /= 2;
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-11-30 14:51:44 +01:00
|
|
|
return 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
|
2019-08-16 22:06:06 +02:00
|
|
|
draw_bar(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)
|
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,
|
2019-11-26 18:54:32 +01:00
|
|
|
font->underline.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
|
|
|
{
|
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->underline.position,
|
|
|
|
|
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
|
|
|
|
|
draw_cursor(const struct terminal *term, const struct cell *cell,
|
2020-04-21 19:29:36 +02:00
|
|
|
const struct fcft_font *font, pixman_image_t *pix, pixman_color_t *fg,
|
2020-01-04 12:03:04 +01:00
|
|
|
const pixman_color_t *bg, int x, int y, int cols)
|
2019-12-19 07:28:49 +01:00
|
|
|
{
|
|
|
|
|
pixman_color_t cursor_color;
|
|
|
|
|
pixman_color_t text_color;
|
|
|
|
|
|
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) {
|
|
|
|
|
cursor_color = color_hex_to_pixman(term->cursor_color.cursor);
|
2020-01-20 18:36:44 +01:00
|
|
|
text_color = color_hex_to_pixman(
|
|
|
|
|
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) {
|
|
|
|
|
pixman_color_t swap = cursor_color;
|
|
|
|
|
cursor_color = text_color;
|
|
|
|
|
text_color = swap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (term->is_searching && !is_selected) {
|
2020-04-09 13:41:16 +02:00
|
|
|
color_dim_for_search(&cursor_color);
|
|
|
|
|
color_dim_for_search(&text_color);
|
2019-12-19 07:28:49 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cursor_color = *fg;
|
|
|
|
|
text_color = *bg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (term->cursor_style) {
|
|
|
|
|
case CURSOR_BLOCK:
|
2020-01-02 19:37:21 +01:00
|
|
|
if (!term->visual_focus)
|
2019-12-19 07:28:49 +01:00
|
|
|
draw_unfocused_block(term, pix, &cursor_color, x, y, cols);
|
|
|
|
|
|
|
|
|
|
else if (term->cursor_blink.state == CURSOR_BLINK_ON) {
|
|
|
|
|
*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;
|
|
|
|
|
|
|
|
|
|
case CURSOR_BAR:
|
2020-01-02 19:37:21 +01:00
|
|
|
if (term->cursor_blink.state == CURSOR_BLINK_ON || !term->visual_focus)
|
2019-12-19 07:28:49 +01:00
|
|
|
draw_bar(term, pix, font, &cursor_color, x, y);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CURSOR_UNDERLINE:
|
2020-01-02 19:37:21 +01:00
|
|
|
if (term->cursor_blink.state == CURSOR_BLINK_ON || !term->visual_focus) {
|
2019-12-19 07:28:49 +01:00
|
|
|
draw_underline(
|
|
|
|
|
term, pix, attrs_to_font(term, &cell->attrs), &cursor_color,
|
|
|
|
|
x, y, cols);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-01-06 11:56:18 +01:00
|
|
|
assert(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;
|
|
|
|
|
|
2019-12-19 07:28:49 +01:00
|
|
|
/* 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
|
|
|
|
2019-07-08 15:56:15 +02:00
|
|
|
/* If *one* is set, we reverse */
|
2019-12-19 07:28:49 +01:00
|
|
|
if (term->reverse ^ cell->attrs.reverse ^ is_selected) {
|
2019-07-16 19:52:45 +02:00
|
|
|
uint32_t swap = _fg;
|
|
|
|
|
_fg = _bg;
|
|
|
|
|
_bg = swap;
|
2019-07-08 13:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-22 19:17:57 +02:00
|
|
|
if (cell->attrs.blink && term->blink.state == BLINK_OFF)
|
2019-07-21 20:11:20 +02:00
|
|
|
_fg = _bg;
|
|
|
|
|
|
2019-08-16 20:40:32 +02:00
|
|
|
pixman_color_t fg = color_hex_to_pixman(_fg);
|
2019-12-19 07:28:49 +01:00
|
|
|
pixman_color_t bg = color_hex_to_pixman_with_alpha(_bg, term->colors.alpha);
|
2019-07-16 13:17:51 +02:00
|
|
|
|
2019-07-18 10:04:13 +02:00
|
|
|
if (cell->attrs.dim)
|
2020-04-09 13:41:16 +02:00
|
|
|
color_dim(&fg);
|
2019-07-16 14:20:39 +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;
|
|
|
|
|
|
|
|
|
|
if (cell->wc != 0)
|
|
|
|
|
glyph = fcft_glyph_rasterize(font, cell->wc, term->font_subpixel);
|
2019-07-31 21:15:40 +02:00
|
|
|
|
2019-08-16 20:40:32 +02:00
|
|
|
int cell_cols = glyph != NULL ? max(1, glyph->cols) : 1;
|
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
|
|
|
|
2019-12-17 19:11:27 +01:00
|
|
|
if (cell->attrs.blink)
|
|
|
|
|
term_arm_blink_timer(term);
|
2019-07-21 20:11:20 +02:00
|
|
|
|
2020-03-17 11:47:47 +01:00
|
|
|
if (has_cursor && term->cursor_style == CURSOR_BLOCK)
|
|
|
|
|
draw_cursor(term, cell, font, pix, &fg, &bg, x, y, cell_cols);
|
|
|
|
|
|
2019-08-02 18:19:07 +02:00
|
|
|
if (cell->wc == 0 || cell->attrs.conceal)
|
2020-03-17 11:47:47 +01:00
|
|
|
goto draw_cursor;
|
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) {
|
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,
|
2019-11-30 14:51:44 +01:00
|
|
|
x + glyph->x, y + font_baseline(term) - glyph->y,
|
2019-08-16 20:40:32 +02:00
|
|
|
glyph->width, glyph->height);
|
2019-07-31 21:15:40 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Glyph surface is an alpha mask */
|
2019-08-17 17:36:27 +02:00
|
|
|
pixman_image_composite32(
|
2020-05-02 22:14:48 +02:00
|
|
|
PIXMAN_OP_OVER, clr_pix, glyph->pix, pix, 0, 0, 0, 0,
|
2019-11-30 14:51:44 +01:00
|
|
|
x + glyph->x, y + font_baseline(term) - glyph->y,
|
2019-08-16 20:40:32 +02:00
|
|
|
glyph->width, glyph->height);
|
2019-07-31 21:15:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 17:29:00 +02:00
|
|
|
#if FOOT_UNICODE_MAX_COMBINING_CHARS > 0
|
2020-05-01 11:56:13 +02:00
|
|
|
/* Combining characters */
|
|
|
|
|
const struct combining_chars *comb_chars = &row->comb_chars[col];
|
|
|
|
|
for (size_t i = 0; i < comb_chars->count; i++) {
|
|
|
|
|
const struct fcft_glyph *g = fcft_glyph_rasterize(
|
|
|
|
|
font, comb_chars->chars[i], term->font_subpixel);
|
|
|
|
|
|
|
|
|
|
if (g == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
pixman_image_composite32(
|
2020-05-02 22:14:48 +02:00
|
|
|
PIXMAN_OP_OVER, clr_pix, g->pix, pix, 0, 0, 0, 0,
|
2020-05-01 11:56:13 +02:00
|
|
|
/* Some fonts use a negative offset, while others use a
|
|
|
|
|
* "normal" offset */
|
|
|
|
|
x + (g->x < 0 ? term->cell_width : 0) + g->x,
|
|
|
|
|
y + font_baseline(term) - g->y,
|
|
|
|
|
g->width, g->height);
|
|
|
|
|
}
|
2020-05-01 12:05:38 +02:00
|
|
|
#endif
|
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 */
|
2019-08-16 22:06:06 +02:00
|
|
|
if (cell->attrs.underline) {
|
|
|
|
|
draw_underline(term, pix, attrs_to_font(term, &cell->attrs),
|
2019-08-18 18:11:38 +02:00
|
|
|
&fg, x, y, cell_cols);
|
2019-08-16 22:06:06 +02:00
|
|
|
}
|
2019-07-16 15:08:02 +02:00
|
|
|
|
2019-08-16 22:06:06 +02:00
|
|
|
if (cell->attrs.strikethrough) {
|
|
|
|
|
draw_strikeout(term, pix, attrs_to_font(term, &cell->attrs),
|
2019-08-18 18:11:38 +02:00
|
|
|
&fg, x, y, cell_cols);
|
2019-08-16 22:06:06 +02:00
|
|
|
}
|
2019-08-01 20:09:39 +02:00
|
|
|
|
2020-03-17 11:47:47 +01:00
|
|
|
draw_cursor:
|
|
|
|
|
if (has_cursor && term->cursor_style != CURSOR_BLOCK)
|
|
|
|
|
draw_cursor(term, cell, font, pix, &fg, &bg, x, y, cell_cols);
|
|
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
return cell_cols;
|
2019-07-08 13:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
static void
|
2020-03-23 20:14:30 +01:00
|
|
|
render_margin(struct terminal *term, struct buffer *buf, int start_line, int end_line,
|
|
|
|
|
bool top, bool bottom)
|
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;
|
|
|
|
|
pixman_color_t bg = color_hex_to_pixman_with_alpha(_bg, term->colors.alpha);
|
|
|
|
|
if (term->is_searching)
|
2020-04-09 13:41:16 +02:00
|
|
|
color_dim(&bg);
|
2020-03-22 20:22:17 +01:00
|
|
|
|
2020-03-23 20:14:30 +01:00
|
|
|
if (top) {
|
2020-03-22 20:22:17 +01:00
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix, &bg, 1,
|
|
|
|
|
&(pixman_rectangle16_t){0, 0, term->width, term->margins.top});
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
term->window->surface, 0, 0, term->width, term->margins.top);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 20:14:30 +01:00
|
|
|
if (bottom) {
|
2020-03-22 20:22:17 +01:00
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix, &bg, 1,
|
|
|
|
|
&(pixman_rectangle16_t){0, bmargin, term->width, term->margins.bottom});
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
term->window->surface, 0, bmargin, term->width, term->margins.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix, &bg, 2,
|
|
|
|
|
(pixman_rectangle16_t[]){
|
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},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* Left */
|
2020-03-22 20:22:17 +01:00
|
|
|
wl_surface_damage_buffer(
|
2020-03-23 20:12:19 +01:00
|
|
|
term->window->surface,
|
|
|
|
|
0, term->margins.top + start_line * term->cell_height,
|
|
|
|
|
term->margins.left, line_count * term->cell_height);
|
|
|
|
|
|
|
|
|
|
/* Right */
|
2020-03-22 20:22:17 +01:00
|
|
|
wl_surface_damage_buffer(
|
2020-03-23 20:12:19 +01:00
|
|
|
term->window->surface,
|
|
|
|
|
rmargin, term->margins.top + start_line * term->cell_height,
|
|
|
|
|
term->margins.right, line_count * term->cell_height);
|
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.
|
|
|
|
|
*
|
|
|
|
|
* For now, assume that the both methods perform rougly the same,
|
|
|
|
|
* 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-04-26 12:47:19 +02:00
|
|
|
term, buf, dmg->region.end - dmg->lines, term->rows,
|
2020-03-23 20:14:30 +01:00
|
|
|
true, true);
|
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-04-26 12:47:19 +02:00
|
|
|
term, buf, dmg->region.start, dmg->region.start + dmg->lines,
|
2020-03-23 21:14:51 +01:00
|
|
|
true, true);
|
|
|
|
|
} 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-02-22 00:05:25 +01:00
|
|
|
render_sixel(struct terminal *term, pixman_image_t *pix,
|
|
|
|
|
const struct sixel *sixel)
|
2020-02-21 23:48:45 +01:00
|
|
|
{
|
|
|
|
|
int view_end = (term->grid->view + term->rows - 1) & (term->grid->num_rows - 1);
|
|
|
|
|
int first_visible_row = -1;
|
|
|
|
|
|
2020-02-22 00:05:25 +01:00
|
|
|
for (size_t i = sixel->pos.row; i < sixel->pos.row + sixel->rows; i++) {
|
|
|
|
|
int row = i & (term->grid->num_rows - 1);
|
|
|
|
|
|
|
|
|
|
if (view_end >= term->grid->view) {
|
|
|
|
|
/* Not wrapped */
|
2020-02-21 23:48:45 +01:00
|
|
|
if (row >= term->grid->view && row <= view_end) {
|
|
|
|
|
first_visible_row = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-02-22 00:05:25 +01:00
|
|
|
} else {
|
|
|
|
|
/* Wrapped */
|
2020-02-21 23:48:45 +01:00
|
|
|
if (row >= term->grid->view || row <= view_end) {
|
|
|
|
|
first_visible_row = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (first_visible_row < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-02-22 00:05:25 +01:00
|
|
|
/* First visible (0 based) row of the image */
|
2020-02-21 23:48:45 +01:00
|
|
|
const int first_img_row = first_visible_row - sixel->pos.row;
|
2020-02-22 00:05:25 +01:00
|
|
|
|
|
|
|
|
/* Map first visible line to current grid view */
|
2020-02-21 23:48:45 +01:00
|
|
|
const int row = first_visible_row & (term->grid->num_rows - 1);
|
|
|
|
|
const int view_aligned =
|
|
|
|
|
(row - term->grid->view + term->grid->num_rows) & (term->grid->num_rows - 1);
|
|
|
|
|
|
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-02-22 00:05:25 +01:00
|
|
|
const int y = max(
|
2020-02-24 18:38:11 +01:00
|
|
|
term->margins.top, term->margins.top + view_aligned * 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-02-24 18:38:11 +01:00
|
|
|
const int width = min(sixel->width, term->width - x - term->margins.right);
|
2020-02-21 23:48:45 +01:00
|
|
|
const int height = min(
|
|
|
|
|
sixel->height - first_img_row * term->cell_height,
|
2020-02-24 18:38:11 +01:00
|
|
|
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 */
|
2020-02-24 18:38:11 +01:00
|
|
|
assert(x >= term->margins.left);
|
|
|
|
|
assert(y >= term->margins.top);
|
|
|
|
|
assert(x + width <= term->width - term->margins.right);
|
|
|
|
|
assert(y + height <= term->height - term->margins.bottom);
|
2020-02-21 23:48:45 +01:00
|
|
|
|
|
|
|
|
pixman_image_composite(
|
|
|
|
|
PIXMAN_OP_SRC,
|
|
|
|
|
sixel->pix,
|
|
|
|
|
NULL,
|
|
|
|
|
pix,
|
|
|
|
|
0, first_img_row * term->cell_height,
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
render_sixel_images(struct terminal *term, pixman_image_t *pix)
|
|
|
|
|
{
|
2020-03-13 18:44:23 +01:00
|
|
|
tll_foreach(term->grid->sixel_images, it)
|
2020-02-21 23:48:45 +01:00
|
|
|
render_sixel(term, pix, &it->item);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-24 20:31:21 +02:00
|
|
|
static void
|
2019-08-16 22:06:06 +02:00
|
|
|
render_row(struct terminal *term, pixman_image_t *pix, struct row *row, int row_no)
|
2019-07-24 20:31:21 +02:00
|
|
|
{
|
font: initial support for double-width *and* color emoji glyphs
Fonts are now loaded with FT_LOAD_COLOR and we recognize and support
the FT_PIXEL_MODE_BGRA pixel mode.
This is mapped to a CAIRO_FORMAT_ARGB32 surface, that is blitted
as-is (instead of used as a mask like we do for gray and mono glyphs).
Furthermore, since many emojis are double-width, we add initial
support for double-width glyphs.
These are assumed to always be utf8. When PRINT:ing an utf8 character,
we check its width, and add empty "spacer" cells after the cell with
the multi-column glyph.
When rendering, we render the columns in each row backwards. This
ensures the spacer cells get cleared *before* we render the glyph (so
that we don't end up erasing part of the glyph).
Finally, emoji fonts are usually bitmap fonts with *large*
glyphs. These aren't automatically scaled down. I.e. even if we
request a glyph of 13 pixels, we might end up getting a 100px glyph.
To handle this, fontconfig must be configured to scale bitmap
fonts. When it is, we can look at the 'scalable' and 'pixelsizefixup'
properties, and use these to scale the rendered glyph.
2019-07-31 18:03:35 +02:00
|
|
|
for (int col = term->cols - 1; col >= 0; col--)
|
2020-05-01 11:56:13 +02:00
|
|
|
render_cell(term, pix, row, col, row_no, false);
|
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
|
|
|
|
2019-08-01 20:09:16 +02:00
|
|
|
char proc_title[16];
|
|
|
|
|
snprintf(proc_title, sizeof(proc_title), "foot:render:%d", my_id);
|
|
|
|
|
|
|
|
|
|
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
|
|
|
|
|
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;
|
|
|
|
|
cnd_t *cond = &term->render.workers.cond;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
sem_wait(start);
|
|
|
|
|
|
|
|
|
|
struct buffer *buf = term->render.workers.buf;
|
|
|
|
|
bool frame_done = false;
|
|
|
|
|
|
|
|
|
|
while (!frame_done) {
|
|
|
|
|
mtx_lock(lock);
|
|
|
|
|
while (tll_length(term->render.workers.queue) == 0)
|
|
|
|
|
cnd_wait(cond, lock);
|
|
|
|
|
|
|
|
|
|
int row_no = tll_pop_front(term->render.workers.queue);
|
|
|
|
|
mtx_unlock(lock);
|
|
|
|
|
|
|
|
|
|
switch (row_no) {
|
|
|
|
|
default:
|
|
|
|
|
assert(buf != NULL);
|
2019-08-16 22:54:05 +02:00
|
|
|
render_row(term, buf->pix, grid_row_in_view(term->grid, row_no), row_no);
|
2019-07-29 20:13:26 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
assert(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-02-29 18:02:38 +01:00
|
|
|
const int title_height = !term->window->is_fullscreen
|
2020-03-02 18:42:49 +01:00
|
|
|
? term->conf->csd.title_height * term->scale : 0;
|
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-03-01 12:28:01 +01:00
|
|
|
switch (surf_idx) {
|
|
|
|
|
case CSD_SURF_TITLE: return (struct csd_data){ 0, -title_height, term->width, title_height};
|
|
|
|
|
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 */
|
|
|
|
|
case CSD_SURF_MINIMIZE: return (struct csd_data){term->width - 3 * button_width, 0, button_width, title_height};
|
|
|
|
|
case CSD_SURF_MAXIMIZE: return (struct csd_data){term->width - 2 * button_width, 0, button_width, title_height};
|
|
|
|
|
case CSD_SURF_CLOSE: return (struct csd_data){term->width - 1 * button_width, 0, button_width, title_height};
|
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
case CSD_SURF_COUNT:
|
|
|
|
|
assert(false);
|
2020-04-13 12:03:11 +02:00
|
|
|
return (struct csd_data){};
|
2020-03-01 12:28:01 +01:00
|
|
|
}
|
2020-02-28 18:49:34 +01:00
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
assert(false);
|
2020-04-13 12:03:11 +02:00
|
|
|
return (struct csd_data){};
|
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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
assert(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(
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix, color, 1,
|
|
|
|
|
&(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)
|
|
|
|
|
{
|
2020-03-06 19:16:54 +01:00
|
|
|
assert(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);
|
2020-02-29 18:02:38 +01:00
|
|
|
struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE];
|
2020-02-23 14:17:48 +01:00
|
|
|
|
2020-03-01 13:17:54 +01:00
|
|
|
assert(info.width > 0 && info.height > 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-03-25 18:26:58 +01:00
|
|
|
term->wl->shm, info.width, info.height, cookie, false);
|
2020-02-23 14:17:48 +01:00
|
|
|
|
2020-03-06 19:13:10 +01:00
|
|
|
uint32_t _color = term->colors.default_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-03-02 18:42:49 +01:00
|
|
|
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
|
2020-02-29 18:02:38 +01:00
|
|
|
if (!term->visual_focus)
|
2020-04-09 13:41:16 +02:00
|
|
|
color_dim(&color);
|
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)
|
|
|
|
|
{
|
2020-03-06 19:16:54 +01:00
|
|
|
assert(term->window->use_csd == CSD_YES);
|
2020-02-29 18:02:38 +01:00
|
|
|
assert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM);
|
|
|
|
|
|
2020-03-01 12:28:01 +01:00
|
|
|
struct csd_data info = get_csd_data(term, surf_idx);
|
2020-02-29 18:02:38 +01:00
|
|
|
struct wl_surface *surf = term->window->csd.surface[surf_idx];
|
|
|
|
|
|
2020-03-01 13:17:54 +01:00
|
|
|
if (info.width == 0 || info.height == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
unsigned long cookie = shm_cookie_csd(term, surf_idx);
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
2020-03-25 18:26:58 +01:00
|
|
|
term->wl->shm, info.width, info.height, cookie, false);
|
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)
|
|
|
|
|
{
|
2020-03-06 19:15:09 +01:00
|
|
|
pixman_color_t color = color_hex_to_pixman(term->colors.default_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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(width <= max_width);
|
|
|
|
|
assert(height <= max_height);
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
PIXMAN_OP_OVER, src, buf->pix, PIXMAN_a1,
|
|
|
|
|
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
|
|
|
{
|
2020-03-06 19:15:09 +01:00
|
|
|
pixman_color_t color = color_hex_to_pixman(term->colors.default_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-03-06 19:15:09 +01:00
|
|
|
PIXMAN_OP_SRC, buf->pix, &color, 4,
|
|
|
|
|
(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)
|
|
|
|
|
{
|
|
|
|
|
pixman_color_t color = color_hex_to_pixman(term->colors.default_bg);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(width <= max_width);
|
|
|
|
|
assert(height <= max_height);
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
PIXMAN_OP_OVER, src, buf->pix, PIXMAN_a1,
|
|
|
|
|
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)
|
|
|
|
|
{
|
2020-03-06 19:15:09 +01:00
|
|
|
pixman_color_t color = color_hex_to_pixman(term->colors.default_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-03-06 19:15:09 +01:00
|
|
|
PIXMAN_OP_SRC, buf->pix, &color, 1,
|
|
|
|
|
&(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)
|
|
|
|
|
{
|
2020-03-06 19:16:54 +01:00
|
|
|
assert(term->window->use_csd == CSD_YES);
|
|
|
|
|
assert(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);
|
|
|
|
|
struct wl_surface *surf = term->window->csd.surface[surf_idx];
|
|
|
|
|
|
|
|
|
|
if (info.width == 0 || info.height == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
unsigned long cookie = shm_cookie_csd(term, surf_idx);
|
|
|
|
|
struct buffer *buf = shm_get_buffer(
|
2020-03-25 18:26:58 +01:00
|
|
|
term->wl->shm, info.width, info.height, cookie, false);
|
2020-03-02 20:29:28 +01:00
|
|
|
|
|
|
|
|
uint32_t _color;
|
|
|
|
|
uint16_t alpha = 0xffff;
|
|
|
|
|
bool is_active = false;
|
|
|
|
|
const bool *is_set = NULL;
|
|
|
|
|
const uint32_t *conf_color = NULL;
|
|
|
|
|
|
|
|
|
|
switch (surf_idx) {
|
|
|
|
|
case CSD_SURF_MINIMIZE:
|
2020-04-29 20:06:16 +02:00
|
|
|
_color = term->colors.default_table[4]; /* blue */
|
2020-03-02 20:29:28 +01:00
|
|
|
is_set = &term->conf->csd.color.minimize_set;
|
|
|
|
|
conf_color = &term->conf->csd.color.minimize;
|
|
|
|
|
is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CSD_SURF_MAXIMIZE:
|
2020-04-29 20:06:16 +02:00
|
|
|
_color = term->colors.default_table[2]; /* green */
|
2020-03-02 20:29:28 +01:00
|
|
|
is_set = &term->conf->csd.color.maximize_set;
|
|
|
|
|
conf_color = &term->conf->csd.color.maximize;
|
|
|
|
|
is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CSD_SURF_CLOSE:
|
2020-04-29 20:06:16 +02:00
|
|
|
_color = term->colors.default_table[1]; /* red */
|
2020-03-02 20:29:28 +01:00
|
|
|
is_set = &term->conf->csd.color.close_set;
|
|
|
|
|
conf_color = &term->conf->csd.color.close;
|
|
|
|
|
is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_active) {
|
|
|
|
|
if (*is_set) {
|
|
|
|
|
_color = *conf_color;
|
|
|
|
|
alpha = _color >> 24 | (_color >> 24 << 8);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_color = 0;
|
|
|
|
|
alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
|
|
|
|
|
if (!term->visual_focus)
|
2020-04-09 13:41:16 +02:00
|
|
|
color_dim(&color);
|
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:
|
|
|
|
|
assert(false);
|
|
|
|
|
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)
|
|
|
|
|
{
|
2020-03-06 19:16:54 +01:00
|
|
|
assert(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
|
|
|
|
|
|
|
|
struct wl_surface *surf = term->window->csd.surface[i];
|
|
|
|
|
struct wl_subsurface *sub = term->window->csd.sub_surface[i];
|
|
|
|
|
|
2020-03-03 18:24:31 +01:00
|
|
|
assert(surf != NULL);
|
|
|
|
|
assert(sub != NULL);
|
|
|
|
|
|
2020-02-29 18:02:38 +01:00
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
|
/* CSD borders aren't rendered in maximized mode */
|
2020-03-02 20:29:28 +01:00
|
|
|
assert(term->window->is_maximized || term->window->is_fullscreen);
|
2020-02-29 18:02:38 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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
|
2019-07-05 10:16:56 +02:00
|
|
|
grid_render(struct terminal *term)
|
|
|
|
|
{
|
2019-12-19 07:27:14 +01:00
|
|
|
if (term->is_shutting_down)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-07-18 10:35:27 +02:00
|
|
|
#if TIME_FRAME_RENDERING
|
2019-07-18 09:33:49 +02:00
|
|
|
struct timeval start_time;
|
|
|
|
|
gettimeofday(&start_time, NULL);
|
2019-07-18 10:35:27 +02:00
|
|
|
#endif
|
2019-07-18 09:33:49 +02:00
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
assert(term->width > 0);
|
|
|
|
|
assert(term->height > 0);
|
|
|
|
|
|
2020-02-23 14:17:48 +01:00
|
|
|
unsigned long cookie = shm_cookie_grid(term);
|
2019-11-02 00:33:37 +01:00
|
|
|
struct buffer *buf = shm_get_buffer(
|
2020-03-25 18:26:58 +01:00
|
|
|
term->wl->shm, term->width, term->height, cookie, true);
|
2019-11-02 00:33:37 +01:00
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
pixman_image_set_clip_region(buf->pix, NULL);
|
2019-07-24 18:15:24 +02:00
|
|
|
|
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
|
|
|
/* If we resized the window, or is flashing, or just stopped flashing */
|
2019-11-02 01:28:29 +01:00
|
|
|
if (term->render.last_buf != buf ||
|
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
|
|
|
term->flash.active || term->render.was_flashing ||
|
|
|
|
|
term->is_searching != term->render.was_searching)
|
|
|
|
|
{
|
2019-11-02 01:28:29 +01:00
|
|
|
if (term->render.last_buf != NULL &&
|
|
|
|
|
term->render.last_buf->width == buf->width &&
|
|
|
|
|
term->render.last_buf->height == buf->height &&
|
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
|
|
|
!term->flash.active &&
|
|
|
|
|
!term->render.was_flashing &&
|
|
|
|
|
term->is_searching == term->render.was_searching)
|
|
|
|
|
{
|
|
|
|
|
static bool has_warned = false;
|
|
|
|
|
if (!has_warned) {
|
2020-03-22 20:22:17 +01:00
|
|
|
LOG_WARN(
|
|
|
|
|
"it appears your Wayland compositor does not support "
|
|
|
|
|
"buffer re-use for SHM clients; expect lower "
|
|
|
|
|
"performance.");
|
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
|
|
|
has_warned = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 01:28:29 +01:00
|
|
|
assert(term->render.last_buf->size == buf->size);
|
|
|
|
|
memcpy(buf->mmapped, term->render.last_buf->mmapped, buf->size);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
2020-03-24 17:45:16 +01:00
|
|
|
tll_free(term->grid->scroll_damage);
|
2020-03-23 20:14:30 +01:00
|
|
|
render_margin(term, buf, 0, term->rows, true, 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
|
|
|
term_damage_view(term);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 01:28:29 +01:00
|
|
|
term->render.last_buf = buf;
|
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
|
|
|
term->render.was_flashing = term->flash.active;
|
|
|
|
|
term->render.was_searching = term->is_searching;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 21:04:30 +01:00
|
|
|
/* Set clip region to prevent cells from overflowing into the margins */
|
2020-03-22 20:22:17 +01:00
|
|
|
pixman_region16_t clip;
|
|
|
|
|
pixman_region_init_rect(
|
|
|
|
|
&clip,
|
|
|
|
|
term->margins.left, term->margins.top,
|
|
|
|
|
term->cols * term->cell_width, term->rows * term->cell_height);
|
|
|
|
|
pixman_image_set_clip_region(buf->pix, &clip);
|
|
|
|
|
|
2019-07-24 18:15:24 +02:00
|
|
|
/* Erase old cursor (if we rendered a cursor last time) */
|
2020-05-01 11:56:13 +02:00
|
|
|
if (term->render.last_cursor.row != NULL) {
|
2019-12-17 19:12:08 +01:00
|
|
|
|
2020-05-01 11:56:13 +02:00
|
|
|
struct row *row = term->render.last_cursor.row;
|
2019-07-30 20:18:58 +02:00
|
|
|
struct coord at = term->render.last_cursor.in_view;
|
2020-05-01 11:56:13 +02:00
|
|
|
term->render.last_cursor.row = NULL;
|
|
|
|
|
|
|
|
|
|
struct cell *cell = &row->cells[at.col];
|
2019-07-30 20:18:58 +02:00
|
|
|
|
2019-12-19 07:29:05 +01:00
|
|
|
/* If cell is already dirty, it will be rendered anyway */
|
2019-07-30 20:18:58 +02:00
|
|
|
if (cell->attrs.clean) {
|
|
|
|
|
cell->attrs.clean = 0;
|
2020-05-01 11:56:13 +02:00
|
|
|
int cols = render_cell(term, buf->pix, row, at.col, at.row, false);
|
2019-07-30 20:18:58 +02:00
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
2019-10-27 19:08:48 +01:00
|
|
|
term->window->surface,
|
2020-02-24 18:38:11 +01:00
|
|
|
term->margins.left + at.col * term->cell_width,
|
|
|
|
|
term->margins.top + at.row * term->cell_height,
|
2019-12-19 07:29:05 +01:00
|
|
|
cols * term->cell_width, term->cell_height);
|
2019-07-30 20:18:58 +02:00
|
|
|
}
|
2019-10-28 17:58:44 +01:00
|
|
|
}
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-10-29 21:09:37 +01:00
|
|
|
tll_foreach(term->grid->scroll_damage, it) {
|
|
|
|
|
switch (it->item.type) {
|
|
|
|
|
case DAMAGE_SCROLL:
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
2019-10-28 17:58:44 +01:00
|
|
|
grid_render_scroll(term, buf, &it->item);
|
2019-10-29 21:09:37 +01:00
|
|
|
break;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-10-29 21:09:37 +01:00
|
|
|
case DAMAGE_SCROLL_REVERSE:
|
|
|
|
|
if (term->grid->view == term->grid->offset)
|
2019-10-28 17:58:44 +01:00
|
|
|
grid_render_scroll_reverse(term, buf, &it->item);
|
2019-10-29 21:09:37 +01:00
|
|
|
break;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-10-29 21:09:37 +01:00
|
|
|
case DAMAGE_SCROLL_IN_VIEW:
|
|
|
|
|
grid_render_scroll(term, buf, &it->item);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DAMAGE_SCROLL_REVERSE_IN_VIEW:
|
|
|
|
|
grid_render_scroll_reverse(term, buf, &it->item);
|
|
|
|
|
break;
|
2019-10-28 17:58:44 +01:00
|
|
|
}
|
2019-10-29 21:09:37 +01:00
|
|
|
|
|
|
|
|
tll_remove(term->grid->scroll_damage, it);
|
|
|
|
|
}
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2020-03-24 17:45:38 +01:00
|
|
|
/* Reset clip region since scrolling may have instantiated a new pixman image */
|
2020-03-22 20:22:17 +01:00
|
|
|
pixman_image_set_clip_region(buf->pix, &clip);
|
|
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
if (term->render.workers.count > 0) {
|
2019-07-29 20:13:26 +02:00
|
|
|
|
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
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
assert(tll_length(term->render.workers.queue) == 0);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
for (int r = 0; r < term->rows; r++) {
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, r);
|
|
|
|
|
|
|
|
|
|
if (!row->dirty)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
mtx_lock(&term->render.workers.lock);
|
|
|
|
|
tll_push_back(term->render.workers.queue, r);
|
|
|
|
|
cnd_signal(&term->render.workers.cond);
|
|
|
|
|
mtx_unlock(&term->render.workers.lock);
|
|
|
|
|
|
|
|
|
|
row->dirty = false;
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
2019-10-27 19:08:48 +01:00
|
|
|
term->window->surface,
|
2020-02-24 18:38:11 +01:00
|
|
|
term->margins.left, term->margins.top + r * term->cell_height,
|
|
|
|
|
term->width - term->margins.left - term->margins.right, term->cell_height);
|
2019-08-01 20:09:39 +02:00
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-07-29 20:13:26 +02:00
|
|
|
mtx_lock(&term->render.workers.lock);
|
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);
|
|
|
|
|
cnd_broadcast(&term->render.workers.cond);
|
2019-07-29 20:13:26 +02:00
|
|
|
mtx_unlock(&term->render.workers.lock);
|
2019-08-01 20:09:39 +02:00
|
|
|
} else {
|
|
|
|
|
for (int r = 0; r < term->rows; r++) {
|
|
|
|
|
struct row *row = grid_row_in_view(term->grid, r);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
if (!row->dirty)
|
|
|
|
|
continue;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
render_row(term, buf->pix, row, r);
|
2019-08-01 20:09:39 +02:00
|
|
|
row->dirty = false;
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
2019-10-27 19:08:48 +01:00
|
|
|
term->window->surface,
|
2020-02-24 18:38:11 +01:00
|
|
|
term->margins.left, term->margins.top + r * term->cell_height,
|
|
|
|
|
term->width - term->margins.left - term->margins.right, term->cell_height);
|
2019-08-01 20:09:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-07-29 20:13:26 +02:00
|
|
|
|
2019-07-24 18:15:24 +02:00
|
|
|
/*
|
|
|
|
|
* Determine if we need to render a cursor or not. The cursor
|
|
|
|
|
* could be hidden. Or it could have been scrolled out of view.
|
|
|
|
|
*/
|
2019-07-10 09:51:42 +02:00
|
|
|
bool cursor_is_visible = false;
|
2019-08-22 17:33:23 +02:00
|
|
|
int view_end = (term->grid->view + term->rows - 1) & (term->grid->num_rows - 1);
|
2020-04-16 18:51:14 +02:00
|
|
|
int cursor_row = (term->grid->offset + term->grid->cursor.point.row) & (term->grid->num_rows - 1);
|
2019-07-10 09:51:42 +02:00
|
|
|
if (view_end >= term->grid->view) {
|
|
|
|
|
/* Not wrapped */
|
|
|
|
|
if (cursor_row >= term->grid->view && cursor_row <= view_end)
|
|
|
|
|
cursor_is_visible = true;
|
|
|
|
|
} else {
|
|
|
|
|
/* Wrapped */
|
|
|
|
|
if (cursor_row >= term->grid->view || cursor_row <= view_end)
|
|
|
|
|
cursor_is_visible = true;
|
|
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-08-01 20:09:39 +02:00
|
|
|
/*
|
|
|
|
|
* Wait for workers to finish before we render the cursor. This is
|
|
|
|
|
* because the cursor cell might be dirty, in which case a worker
|
|
|
|
|
* will render it (but without the cursor).
|
|
|
|
|
*/
|
|
|
|
|
if (term->render.workers.count > 0) {
|
|
|
|
|
for (size_t i = 0; i < term->render.workers.count; i++)
|
|
|
|
|
sem_wait(&term->render.workers.done);
|
|
|
|
|
term->render.workers.buf = NULL;
|
|
|
|
|
}
|
2019-07-29 20:13:26 +02:00
|
|
|
|
2019-07-11 09:59:51 +02:00
|
|
|
if (cursor_is_visible && !term->hide_cursor) {
|
2019-07-24 18:15:24 +02:00
|
|
|
/* Remember cursor coordinates so that we can erase it next
|
|
|
|
|
* time. Note that we need to re-align it against the view. */
|
2019-07-24 20:21:41 +02:00
|
|
|
int view_aligned_row
|
2019-08-22 17:33:23 +02:00
|
|
|
= (cursor_row - term->grid->view + term->grid->num_rows) & (term->grid->num_rows - 1);
|
2019-07-24 18:15:24 +02:00
|
|
|
|
2020-04-16 18:51:14 +02:00
|
|
|
term->render.last_cursor.actual = term->grid->cursor.point;
|
2019-07-24 20:21:41 +02:00
|
|
|
term->render.last_cursor.in_view = (struct coord) {
|
2020-04-16 18:51:14 +02:00
|
|
|
term->grid->cursor.point.col, view_aligned_row};
|
2019-07-24 18:15:24 +02:00
|
|
|
|
2019-07-24 20:21:41 +02:00
|
|
|
struct row *row = grid_row_in_view(term->grid, view_aligned_row);
|
2020-04-16 18:51:14 +02:00
|
|
|
struct cell *cell = &row->cells[term->grid->cursor.point.col];
|
2019-07-24 20:21:41 +02:00
|
|
|
|
2019-07-30 18:04:28 +02:00
|
|
|
cell->attrs.clean = 0;
|
2020-05-01 11:56:13 +02:00
|
|
|
term->render.last_cursor.row = row;
|
2019-08-01 20:09:39 +02:00
|
|
|
int cols_updated = render_cell(
|
2020-05-01 11:56:13 +02:00
|
|
|
term, buf->pix, row, term->grid->cursor.point.col, view_aligned_row, true);
|
2019-07-10 09:51:42 +02:00
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
2019-10-27 19:08:48 +01:00
|
|
|
term->window->surface,
|
2020-04-16 18:51:14 +02:00
|
|
|
term->margins.left + term->grid->cursor.point.col * term->cell_width,
|
2020-02-24 18:38:11 +01:00
|
|
|
term->margins.top + view_aligned_row * term->cell_height,
|
2019-08-01 20:09:39 +02:00
|
|
|
cols_updated * term->cell_width, term->cell_height);
|
2019-07-10 09:51:42 +02:00
|
|
|
}
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2020-03-22 20:22:17 +01:00
|
|
|
render_sixel_images(term, buf->pix);
|
2020-02-21 21:53:23 +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 */
|
2020-03-24 17:45:45 +01:00
|
|
|
pixman_image_set_clip_region(buf->pix, NULL);
|
2019-08-16 22:06:06 +02:00
|
|
|
pixman_image_fill_rectangles(
|
2020-03-22 20:22:17 +01:00
|
|
|
PIXMAN_OP_OVER, buf->pix,
|
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
|
|
|
}
|
|
|
|
|
|
2019-07-08 15:27:44 +02:00
|
|
|
assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows);
|
2019-07-09 16:26:36 +02:00
|
|
|
assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-10-27 19:08:48 +01:00
|
|
|
assert(term->window->frame_callback == NULL);
|
|
|
|
|
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-01-21 18:51:04 +01:00
|
|
|
struct presentation_context *ctx = malloc(sizeof(*ctx));
|
|
|
|
|
*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-03-24 17:45:38 +01:00
|
|
|
wl_surface_attach(term->window->surface, buf->wl_buf, 0, 0);
|
|
|
|
|
quirk_kde_damage_before_attach(term->window->surface);
|
2019-10-27 19:08:48 +01:00
|
|
|
wl_surface_commit(term->window->surface);
|
2019-07-18 09:33:49 +02:00
|
|
|
|
2019-07-18 10:35:27 +02:00
|
|
|
#if TIME_FRAME_RENDERING
|
2019-07-18 09:33:49 +02:00
|
|
|
struct timeval end_time;
|
|
|
|
|
gettimeofday(&end_time, NULL);
|
|
|
|
|
|
|
|
|
|
struct timeval render_time;
|
|
|
|
|
timersub(&end_time, &start_time, &render_time);
|
2019-08-24 11:32:28 +02:00
|
|
|
LOG_INFO("frame rendered in %lds %ldus",
|
|
|
|
|
render_time.tv_sec, render_time.tv_usec);
|
2019-07-18 10:35:27 +02:00
|
|
|
#endif
|
2019-07-05 10:16:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-08-29 20:18:06 +02:00
|
|
|
render_search_box(struct terminal *term)
|
|
|
|
|
{
|
2019-10-27 19:08:48 +01:00
|
|
|
assert(term->window->search_sub_surface != NULL);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
2020-01-05 15:16:40 +01:00
|
|
|
const size_t wanted_visible_chars = max(20, term->search.len);
|
|
|
|
|
|
2020-02-25 20:30:45 +01:00
|
|
|
assert(term->scale >= 1);
|
|
|
|
|
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,
|
|
|
|
|
2 * margin + wanted_visible_chars * term->cell_width);
|
|
|
|
|
const size_t height = min(
|
|
|
|
|
term->height - 2 * margin,
|
|
|
|
|
2 * margin + 1 * term->cell_height);
|
|
|
|
|
|
2020-03-01 12:28:33 +01:00
|
|
|
const size_t visible_chars = (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-03-25 18:26:58 +01:00
|
|
|
struct buffer *buf = shm_get_buffer(term->wl->shm, width, height, cookie, false);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
|
|
|
/* Background - yellow on empty/match, red on mismatch */
|
|
|
|
|
pixman_color_t color = color_hex_to_pixman(
|
2019-08-30 21:01:13 +02:00
|
|
|
term->search.match_len == term->search.len
|
|
|
|
|
? term->colors.table[3] : term->colors.table[1]);
|
2019-08-29 20:18:06 +02:00
|
|
|
|
|
|
|
|
pixman_image_fill_rectangles(
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix, &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(
|
|
|
|
|
PIXMAN_OP_SRC, buf->pix, &transparent,
|
|
|
|
|
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-03-01 12:28:33 +01:00
|
|
|
int x = width - visible_width + margin;
|
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-04-19 14:50:48 +02:00
|
|
|
/* Ensure cursor is visible */
|
|
|
|
|
if (term->search.cursor < glyph_offset)
|
2020-01-05 15:25:24 +01:00
|
|
|
term->render.search_glyph_offset = glyph_offset = term->search.cursor;
|
2020-04-19 14:50:48 +02:00
|
|
|
else if (term->search.cursor > glyph_offset + visible_chars) {
|
|
|
|
|
term->render.search_glyph_offset = glyph_offset =
|
|
|
|
|
term->search.cursor - min(term->search.cursor, visible_chars);
|
2020-01-05 15:16:40 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-19 14:50:48 +02:00
|
|
|
/* Move offset if there is free space available */
|
|
|
|
|
if (term->search.len - glyph_offset < visible_chars)
|
|
|
|
|
term->render.search_glyph_offset = glyph_offset =
|
|
|
|
|
term->search.len - min(term->search.len, visible_chars);
|
|
|
|
|
|
2019-08-29 20:18:06 +02:00
|
|
|
/* Text (what the user entered - *not* match(es)) */
|
2020-01-05 15:25:24 +01:00
|
|
|
for (size_t i = glyph_offset;
|
2020-02-29 11:41:40 +01:00
|
|
|
i < term->search.len && i - glyph_offset < visible_chars;
|
2020-01-05 15:16:40 +01:00
|
|
|
i++)
|
|
|
|
|
{
|
2019-08-29 21:03:00 +02:00
|
|
|
if (i == term->search.cursor)
|
2019-08-30 19:42:33 +02:00
|
|
|
draw_bar(term, buf->pix, font, &fg, x, y);
|
2019-08-29 21:03:00 +02:00
|
|
|
|
2020-04-24 10:53:34 +02:00
|
|
|
const struct fcft_glyph *glyph = fcft_glyph_rasterize(
|
|
|
|
|
font, term->search.buf[i], true);
|
|
|
|
|
|
2019-08-29 20:18:06 +02:00
|
|
|
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,
|
2019-11-30 14:51:44 +01:00
|
|
|
x + glyph->x, y + font_baseline(term) - glyph->y,
|
2019-08-29 20:18:06 +02:00
|
|
|
glyph->width, glyph->height);
|
|
|
|
|
pixman_image_unref(src);
|
|
|
|
|
|
2019-08-30 19:35:47 +02:00
|
|
|
x += term->cell_width;
|
2019-08-29 20:18:06 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-29 21:03:00 +02:00
|
|
|
if (term->search.cursor >= term->search.len)
|
2019-08-30 19:42:33 +02:00
|
|
|
draw_bar(term, buf->pix, font, &fg, x, y);
|
2019-08-29 21:03:00 +02:00
|
|
|
|
2020-03-01 13:06:00 +01:00
|
|
|
quirk_weston_subsurface_desync_on(term->window->search_sub_surface);
|
|
|
|
|
|
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(
|
2019-10-27 19:08:48 +01:00
|
|
|
term->window->search_sub_surface,
|
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
|
|
|
|
2020-03-01 12:28:33 +01:00
|
|
|
wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0);
|
|
|
|
|
wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height);
|
|
|
|
|
wl_surface_set_buffer_scale(term->window->search_surface, scale);
|
|
|
|
|
|
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);
|
|
|
|
|
wl_surface_set_opaque_region(term->window->search_surface, region);
|
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-27 19:08:48 +01:00
|
|
|
wl_surface_commit(term->window->search_surface);
|
2020-03-01 13:06:00 +01:00
|
|
|
quirk_weston_subsurface_desync_off(term->window->search_sub_surface);
|
2019-08-29 20:18:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-25 18:23:55 +01:00
|
|
|
static void
|
|
|
|
|
render_update_title(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
/* TODO: figure out what the limit actually is */
|
|
|
|
|
static const size_t max_len = 100;
|
|
|
|
|
|
|
|
|
|
const char *title = term->window_title != NULL ? term->window_title : "foot";
|
|
|
|
|
char *copy = NULL;
|
|
|
|
|
|
|
|
|
|
if (strlen(title) > max_len) {
|
|
|
|
|
copy = strndup(title, max_len);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
assert(term->window->frame_callback == wl_callback);
|
|
|
|
|
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;
|
|
|
|
|
bool search = term->render.pending.search;
|
2020-03-25 18:23:55 +01:00
|
|
|
bool title = term->render.pending.title;
|
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;
|
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);
|
|
|
|
|
|
2020-03-24 17:42:29 +01:00
|
|
|
if (search && term->is_searching)
|
|
|
|
|
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
|
|
|
|
2020-03-24 17:42:29 +01:00
|
|
|
if (grid && (!term->delayed_render_timer.is_armed || csd || search))
|
|
|
|
|
grid_render(term);
|
2020-03-06 19:16:54 +01:00
|
|
|
}
|
|
|
|
|
|
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? */
|
|
|
|
|
scale = 1;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
if (term->unmaximized_width != 0 && term->unmaximized_height != 0) {
|
|
|
|
|
width = term->unmaximized_width;
|
|
|
|
|
height = term->unmaximized_height;
|
|
|
|
|
} else {
|
2020-02-28 18:50:15 +01:00
|
|
|
width = term->conf->width;
|
|
|
|
|
height = term->conf->height;
|
|
|
|
|
|
|
|
|
|
if (term->window->use_csd == CSD_YES) {
|
2020-03-03 18:26:15 +01:00
|
|
|
/* Take CSD title bar into account */
|
2020-02-28 18:50:15 +01:00
|
|
|
assert(!term->window->is_fullscreen);
|
2020-03-03 18:26:15 +01:00
|
|
|
height -= term->conf->csd.title_height;
|
2020-02-28 18:50:15 +01:00
|
|
|
}
|
2020-02-26 20:59:11 +01:00
|
|
|
|
2020-02-28 18:50:15 +01:00
|
|
|
width *= scale;
|
|
|
|
|
height *= scale;
|
2020-02-26 20:59:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 19:10:48 +01:00
|
|
|
/* Don't shrink grid too much */
|
|
|
|
|
const int min_cols = 20;
|
|
|
|
|
const int min_rows = 4;
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
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
|
|
|
|
2020-02-15 19:01:26 +01:00
|
|
|
assert(new_cols >= 1);
|
|
|
|
|
assert(new_rows >= 1);
|
|
|
|
|
|
|
|
|
|
/* Margins */
|
2020-03-02 18:42:49 +01:00
|
|
|
term->margins.left = pad_x;
|
|
|
|
|
term->margins.top = pad_y;
|
2020-02-24 18:38:11 +01:00
|
|
|
term->margins.right = term->width - new_cols * term->cell_width - term->margins.left;
|
|
|
|
|
term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top;
|
2019-08-27 15:25:35 +02:00
|
|
|
|
2020-03-02 18:42:49 +01:00
|
|
|
assert(term->margins.left >= pad_x);
|
|
|
|
|
assert(term->margins.right >= pad_x);
|
|
|
|
|
assert(term->margins.top >= pad_y);
|
|
|
|
|
assert(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
|
|
|
|
2020-04-17 22:18:02 +02:00
|
|
|
struct coord *const tracking_points[] = {
|
|
|
|
|
&term->selection.start,
|
|
|
|
|
&term->selection.end,
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-15 22:19:08 +01:00
|
|
|
/* Reflow grids */
|
2020-04-17 22:18:02 +02:00
|
|
|
grid_reflow(
|
|
|
|
|
&term->normal, new_normal_grid_rows, new_cols, old_rows, new_rows,
|
|
|
|
|
term->grid == &term->normal ? ALEN(tracking_points) : 0,
|
|
|
|
|
term->grid == &term->normal ? tracking_points : NULL);
|
|
|
|
|
|
|
|
|
|
grid_reflow(
|
|
|
|
|
&term->alt, new_alt_grid_rows, new_cols, old_rows, new_rows,
|
|
|
|
|
term->grid == &term->alt ? ALEN(tracking_points) : 0,
|
|
|
|
|
term->grid == &term->alt ? tracking_points : NULL);
|
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-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);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
|
|
|
/* Signal TIOCSWINSZ */
|
|
|
|
|
if (ioctl(term->ptmx, TIOCSWINSZ,
|
|
|
|
|
&(struct winsize){
|
|
|
|
|
.ws_row = term->rows,
|
|
|
|
|
.ws_col = term->cols,
|
2020-01-12 14:42:49 +01:00
|
|
|
.ws_xpixel = term->cols * term->cell_width,
|
|
|
|
|
.ws_ypixel = term->rows * term->cell_height}) == -1)
|
2019-07-05 10:16:56 +02:00
|
|
|
{
|
|
|
|
|
LOG_ERRNO("TIOCSWINSZ");
|
|
|
|
|
}
|
|
|
|
|
|
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:
|
2020-02-29 17:25:08 +01:00
|
|
|
if (!term->window->is_maximized && !term->window->is_fullscreen) {
|
2020-02-26 20:59:11 +01:00
|
|
|
term->unmaximized_width = term->width;
|
|
|
|
|
term->unmaximized_height = term->height;
|
|
|
|
|
}
|
|
|
|
|
|
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-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
|
|
|
|
|
render_xcursor_update(struct wayland *wayl, const struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
/* If called from a frame callback, we may no longer have mouse focus */
|
|
|
|
|
if (wayl->mouse_focus != term)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wayl->pointer.cursor = wl_cursor_theme_get_cursor(wayl->pointer.theme, term->xcursor);
|
|
|
|
|
if (wayl->pointer.cursor == NULL) {
|
|
|
|
|
LOG_ERR("%s: failed to load xcursor pointer '%s'",
|
|
|
|
|
wayl->pointer.theme_name, term->xcursor);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wayl->pointer.xcursor = term->xcursor;
|
|
|
|
|
|
|
|
|
|
const int scale = term->scale;
|
|
|
|
|
struct wl_cursor_image *image = wayl->pointer.cursor->images[0];
|
|
|
|
|
|
|
|
|
|
wl_surface_attach(
|
|
|
|
|
wayl->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0);
|
|
|
|
|
|
|
|
|
|
wl_pointer_set_cursor(
|
|
|
|
|
wayl->pointer.pointer, wayl->pointer.serial,
|
|
|
|
|
wayl->pointer.surface,
|
|
|
|
|
image->hotspot_x / scale, image->hotspot_y / scale);
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
wayl->pointer.surface, 0, 0, INT32_MAX, INT32_MAX);
|
|
|
|
|
|
|
|
|
|
wl_surface_set_buffer_scale(wayl->pointer.surface, scale);
|
|
|
|
|
|
|
|
|
|
assert(wayl->pointer.xcursor_callback == NULL);
|
|
|
|
|
wayl->pointer.xcursor_callback = wl_surface_frame(wayl->pointer.surface);
|
|
|
|
|
wl_callback_add_listener(wayl->pointer.xcursor_callback, &xcursor_listener, wayl);
|
|
|
|
|
|
|
|
|
|
wl_surface_commit(wayl->pointer.surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data)
|
|
|
|
|
{
|
|
|
|
|
struct wayland *wayl = data;
|
|
|
|
|
|
|
|
|
|
assert(wayl->pointer.xcursor_callback == wl_callback);
|
|
|
|
|
wl_callback_destroy(wl_callback);
|
|
|
|
|
wayl->pointer.xcursor_callback = NULL;
|
|
|
|
|
|
2020-01-05 00:10:44 +01:00
|
|
|
if (wayl->pointer.pending_terminal != NULL) {
|
|
|
|
|
render_xcursor_update(wayl, wayl->pointer.pending_terminal);
|
|
|
|
|
wayl->pointer.pending_terminal = NULL;
|
|
|
|
|
}
|
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-01-05 00:10:44 +01:00
|
|
|
struct wayland *wayl = renderer->wayl;
|
|
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
tll_foreach(renderer->wayl->terms, it) {
|
|
|
|
|
struct terminal *term = it->item;
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
if (!term->render.refresh.grid &&
|
|
|
|
|
!term->render.refresh.csd &&
|
|
|
|
|
!term->render.refresh.search)
|
|
|
|
|
{
|
2020-01-04 22:01:19 +01:00
|
|
|
continue;
|
2020-03-06 19:16:54 +01:00
|
|
|
}
|
2020-01-04 22:01:19 +01:00
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
if (term->render.app_sync_updates.enabled &&
|
|
|
|
|
!term->render.refresh.csd &&
|
|
|
|
|
!term->render.refresh.search)
|
|
|
|
|
{
|
2020-01-12 12:19:38 +01:00
|
|
|
continue;
|
2020-03-06 19:16:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (term->render.refresh.csd || term->render.refresh.search) {
|
|
|
|
|
/* Force update of parent surface */
|
|
|
|
|
term->render.refresh.grid = true;
|
|
|
|
|
}
|
2020-01-12 12:19:38 +01:00
|
|
|
|
2020-01-04 22:01:19 +01:00
|
|
|
assert(term->window->is_configured);
|
|
|
|
|
|
2020-03-06 19:16:54 +01:00
|
|
|
bool grid = term->render.refresh.grid;
|
|
|
|
|
bool csd = term->render.refresh.csd;
|
|
|
|
|
bool search = term->render.refresh.search;
|
2020-03-25 18:23:55 +01:00
|
|
|
bool title = term->render.refresh.title;
|
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;
|
2020-03-06 19:16:54 +01:00
|
|
|
|
|
|
|
|
if (term->window->frame_callback == NULL) {
|
|
|
|
|
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);
|
|
|
|
|
if (grid)
|
|
|
|
|
grid_render(term);
|
|
|
|
|
} 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;
|
2020-01-05 00:10:44 +01:00
|
|
|
}
|
2020-01-04 22:01:19 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 00:10:44 +01:00
|
|
|
if (wayl->pointer.pending_terminal != NULL) {
|
|
|
|
|
if (wayl->pointer.xcursor_callback == NULL) {
|
|
|
|
|
render_xcursor_update(wayl, wayl->pointer.pending_terminal);
|
|
|
|
|
wayl->pointer.pending_terminal = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
/* Frame callback will call render_xcursor_update() */
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
render_xcursor_set(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
struct wayland *wayl = term->wl;
|
|
|
|
|
|
|
|
|
|
if (wayl->pointer.theme == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (wayl->mouse_focus == NULL) {
|
|
|
|
|
wayl->pointer.xcursor = NULL;
|
|
|
|
|
wayl->pointer.pending_terminal = NULL;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wayl->mouse_focus != term) {
|
|
|
|
|
/* This terminal doesn't have mouse focus */
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wayl->pointer.xcursor == term->xcursor)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
/* FDM hook takes care of actual rendering */
|
|
|
|
|
wayl->pointer.pending_terminal = term;
|
|
|
|
|
return true;
|
|
|
|
|
}
|