Fix XLibre TearFree rotation, st dirty-rect CPU usage, and SPM deep-sleep wake
This commit is contained in:
1 parent
dbc0275979
commit
1b93479666
14 files changed
+549
-62
No files matched your search
@@ -305,7 +305,12 @@ static void arm_timer_ms(int tmr_fd, uint64_t wait_ms) {
|
||||
timerfd_settime(tmr_fd, 0, &its, NULL);
|
||||
}
|
||||
|
||||
static void restore_consys_after_resume(powerd_ctx_t *ctx);
|
||||
|
||||
static void evaluate_idle(powerd_ctx_t *ctx) {
|
||||
if (ctx->consys_suspended && (!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy))) {
|
||||
restore_consys_after_resume(ctx);
|
||||
}
|
||||
uint64_t now = monotonic_ms();
|
||||
uint64_t elapsed = (now >= ctx->last_input_ms) ? (now - ctx->last_input_ms) : 0;
|
||||
uint64_t next_wait_ms = 0;
|
||||
@@ -330,6 +335,9 @@ static void evaluate_idle(powerd_ctx_t *ctx) {
|
||||
}
|
||||
|
||||
static void note_user_activity(powerd_ctx_t *ctx) {
|
||||
if (ctx->consys_suspended && !ctx->policy.lid_closed) {
|
||||
restore_consys_after_resume(ctx);
|
||||
}
|
||||
ctx->last_input_ms = monotonic_ms();
|
||||
if (ctx->idle_stage != IDLE_STAGE_ACTIVE) {
|
||||
ctx->idle_stage = IDLE_STAGE_ACTIVE;
|
||||
@@ -666,18 +674,23 @@ static void refresh_lid_state(powerd_ctx_t *ctx) {
|
||||
|
||||
/* gpio-keys SW_LID applies a 64 ms debounce timer on wakeup; wait up to
|
||||
* timeout_ms using poll() so a lid-open wake sees SW_LID == 0 before we
|
||||
* decide whether to light the backlight. */
|
||||
static void wait_post_resume_lid_events(powerd_ctx_t *ctx, int timeout_ms) {
|
||||
* decide whether to light the backlight. Returns true if an input/lid wake
|
||||
* event was observed or the lid is open. */
|
||||
static bool wait_post_resume_lid_events(powerd_ctx_t *ctx, int timeout_ms) {
|
||||
bool saw_wake_input = false;
|
||||
refresh_lid_state(ctx);
|
||||
if (!ctx->policy.lid_closed || ctx->num_ev <= 0) return;
|
||||
if (ctx->num_ev <= 0) return !ctx->policy.lid_closed;
|
||||
|
||||
uint64_t deadline = monotonic_ms() + (uint64_t)timeout_ms;
|
||||
uint64_t deadline = ctx->policy.lid_closed ? (monotonic_ms() + (uint64_t)timeout_ms) : 0;
|
||||
struct pollfd pfds[MAX_EVDEVS];
|
||||
while (ctx->policy.lid_closed) {
|
||||
uint64_t now = monotonic_ms();
|
||||
if (now >= deadline) break;
|
||||
int slice = (int)(deadline - now);
|
||||
if (slice > 20) slice = 20;
|
||||
for (;;) {
|
||||
int slice = 0;
|
||||
if (ctx->policy.lid_closed) {
|
||||
uint64_t now = monotonic_ms();
|
||||
if (now >= deadline) break;
|
||||
slice = (int)(deadline - now);
|
||||
if (slice > 20) slice = 20;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ctx->num_ev; i++) {
|
||||
pfds[i].fd = ctx->ev_fds[i];
|
||||
@@ -695,13 +708,21 @@ static void wait_post_resume_lid_events(powerd_ctx_t *ctx, int timeout_ms) {
|
||||
while (read(ctx->ev_fds[i], &iev, sizeof(iev)) == (ssize_t)sizeof(iev)) {
|
||||
if (iev.type == EV_SW && iev.code == SW_LID) {
|
||||
ctx->policy.lid_closed = (iev.value != 0);
|
||||
} else if (iev.type == EV_KEY || iev.type == EV_REL || iev.type == EV_ABS) {
|
||||
if (!ctx->policy.lid_closed) saw_wake_input = true;
|
||||
} else if ((iev.type == EV_KEY && iev.value != 0) ||
|
||||
iev.type == EV_REL || iev.type == EV_ABS) {
|
||||
ctx->last_input_ms = monotonic_ms();
|
||||
saw_wake_input = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
refresh_lid_state(ctx);
|
||||
if (!ctx->policy.lid_closed) {
|
||||
saw_wake_input = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return saw_wake_input;
|
||||
}
|
||||
|
||||
static void prepare_cpus_for_suspend(void) {
|
||||
@@ -749,18 +770,26 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
||||
bool suspended = (write_sysfs_str("/sys/power/state", "mem") == 0 ||
|
||||
write_sysfs_str("/sys/power/state", "freeze") == 0);
|
||||
restore_cpus_after_resume(ctx);
|
||||
restore_consys_after_resume(ctx);
|
||||
wait_post_resume_lid_events(ctx, 90);
|
||||
bool saw_wake_input = wait_post_resume_lid_events(ctx, 90);
|
||||
refresh_ac_and_hdmi(ctx);
|
||||
if (suspended && !ctx->policy.lid_closed) {
|
||||
if (!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy)) {
|
||||
restore_consys_after_resume(ctx);
|
||||
}
|
||||
if ((suspended || saw_wake_input) && !ctx->policy.lid_closed) {
|
||||
ctx->idle_stage = IDLE_STAGE_ACTIVE;
|
||||
ctx->last_input_ms = monotonic_ms();
|
||||
toggle_backlight(ctx, true);
|
||||
apply_cpu_policy(ctx, true);
|
||||
evaluate_idle(ctx);
|
||||
} else {
|
||||
toggle_backlight(ctx, false);
|
||||
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||
arm_timer_ms(ctx->tmr_fd, 0);
|
||||
if (ctx->policy.lid_closed ? geminux_should_suspend_on_lid(&ctx->policy)
|
||||
: (!ctx->policy.on_ac_power && !saw_wake_input)) {
|
||||
arm_timer_ms(ctx->tmr_fd, 2000);
|
||||
} else {
|
||||
arm_timer_ms(ctx->tmr_fd, 0);
|
||||
}
|
||||
apply_cpu_sysfs(ctx, true);
|
||||
}
|
||||
}
|
||||
@@ -817,6 +846,9 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
trigger_suspend(ctx);
|
||||
} else if (strncmp(buf, "inhibit add ", 12) == 0) {
|
||||
geminux_policy_add_inhibit(&ctx->policy, buf + 12);
|
||||
if (!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy)) {
|
||||
restore_consys_after_resume(ctx);
|
||||
}
|
||||
apply_cpu_policy(ctx, false);
|
||||
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
||||
} else if (strncmp(buf, "inhibit del ", 12) == 0) {
|
||||
@@ -828,6 +860,7 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
dprintf(cfd, "OK lid_suspend=on\n");
|
||||
} else if (strcmp(buf, "lid-suspend off") == 0) {
|
||||
ctx->policy.lid_suspend_enabled = false;
|
||||
restore_consys_after_resume(ctx);
|
||||
dprintf(cfd, "OK lid_suspend=off\n");
|
||||
} else if (strcmp(buf, "status") == 0) {
|
||||
dprintf(cfd, "profile=%s ac=%d hdmi=%d lid_closed=%d lid_suspend=%d inhibits=%d\n",
|
||||
@@ -943,7 +976,12 @@ int main(void) {
|
||||
uint64_t exp = 0;
|
||||
while (read(ctx.tmr_fd, &exp, sizeof(exp)) > 0) {}
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
evaluate_idle(&ctx);
|
||||
if (ctx.policy.lid_closed && geminux_should_suspend_on_lid(&ctx.policy)) {
|
||||
trigger_suspend(&ctx);
|
||||
} else {
|
||||
restore_consys_after_resume(&ctx);
|
||||
evaluate_idle(&ctx);
|
||||
}
|
||||
} else if (fd == ctx.uev_fd) {
|
||||
char ubuf[2048];
|
||||
ssize_t ur;
|
||||
@@ -973,6 +1011,9 @@ int main(void) {
|
||||
bool prev_ac = ctx.policy.on_ac_power;
|
||||
bool prev_hdmi = ctx.policy.hdmi_connected;
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
if (!ctx.policy.lid_closed || !geminux_should_suspend_on_lid(&ctx.policy)) {
|
||||
restore_consys_after_resume(&ctx);
|
||||
}
|
||||
if (prev_ac != ctx.policy.on_ac_power || prev_hdmi != ctx.policy.hdmi_connected) {
|
||||
if (!ctx.policy.lid_closed) {
|
||||
note_user_activity(&ctx);
|
||||
@@ -993,14 +1034,17 @@ int main(void) {
|
||||
if (geminux_should_suspend_on_lid(&ctx.policy)) {
|
||||
trigger_suspend(&ctx);
|
||||
} else {
|
||||
restore_consys_after_resume(&ctx);
|
||||
toggle_backlight(&ctx, false);
|
||||
}
|
||||
} else {
|
||||
restore_consys_after_resume(&ctx);
|
||||
ctx.idle_stage = IDLE_STAGE_ACTIVE;
|
||||
ctx.last_input_ms = monotonic_ms();
|
||||
toggle_backlight(&ctx, true);
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
apply_cpu_policy(&ctx, true);
|
||||
evaluate_idle(&ctx);
|
||||
}
|
||||
} else if (iev.type == EV_KEY && iev.code == KEY_POWER && iev.value == 1) {
|
||||
if (ctx.idle_stage == IDLE_STAGE_LOCKED_BLANK) {
|
||||
|
||||
+284
-6
@@ -286,10 +286,122 @@ static int invertcolors = 0;
|
||||
static int oldbutton = 3; /* button event on startup: 3 = release */
|
||||
static int selectionmodeenabled = 1;
|
||||
|
||||
#define MAX_XDIRTY_RECTS 32
|
||||
|
||||
typedef struct {
|
||||
int x1, y1, x2, y2;
|
||||
} XDirtyRect;
|
||||
|
||||
typedef struct {
|
||||
XftFont *font;
|
||||
FT_UInt glyph;
|
||||
uint32_t fg;
|
||||
uint32_t bg;
|
||||
ushort mode;
|
||||
uchar nonspace;
|
||||
uchar valid;
|
||||
} XRenderedCell;
|
||||
|
||||
static XDirtyRect xdirty[MAX_XDIRTY_RECTS];
|
||||
static int xdirty_cnt = 0;
|
||||
static int xw_buf_ready = 0;
|
||||
static XRenderedCell *xw_cells = NULL;
|
||||
static int xw_cells_cols = 0;
|
||||
static int xw_cells_rows = 0;
|
||||
static int xlast_cur_drawn = 0;
|
||||
|
||||
static void
|
||||
xinvalidatecells(void)
|
||||
{
|
||||
if (xw_cells && xw_cells_cols > 0 && xw_cells_rows > 0)
|
||||
memset(xw_cells, 0, (size_t)xw_cells_cols * (size_t)xw_cells_rows * sizeof(*xw_cells));
|
||||
xlast_cur_drawn = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
xinvalidatecellrange(int y, int x1, int x2)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (!xw_cells || y < 0 || y >= xw_cells_rows)
|
||||
return;
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 > xw_cells_cols)
|
||||
x2 = xw_cells_cols;
|
||||
for (x = x1; x < x2; x++)
|
||||
xw_cells[y * xw_cells_cols + x].valid = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
xmarkdirty(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (x2 > win.w)
|
||||
x2 = win.w;
|
||||
if (y2 > win.h)
|
||||
y2 = win.h;
|
||||
if (x1 >= x2 || y1 >= y2)
|
||||
return;
|
||||
|
||||
for (i = 0; i < xdirty_cnt; i++) {
|
||||
if (x1 >= xdirty[i].x1 && y1 >= xdirty[i].y1 &&
|
||||
x2 <= xdirty[i].x2 && y2 <= xdirty[i].y2)
|
||||
return;
|
||||
if ((y1 == xdirty[i].y1 && y2 == xdirty[i].y2 &&
|
||||
x1 <= xdirty[i].x2 + win.cw && x2 >= xdirty[i].x1 - win.cw) ||
|
||||
(x1 == xdirty[i].x1 && x2 == xdirty[i].x2 &&
|
||||
y1 <= xdirty[i].y2 && y2 >= xdirty[i].y1) ||
|
||||
(x1 < xdirty[i].x2 && x2 > xdirty[i].x1 &&
|
||||
y1 < xdirty[i].y2 && y2 > xdirty[i].y1)) {
|
||||
if (x1 < xdirty[i].x1)
|
||||
xdirty[i].x1 = x1;
|
||||
if (y1 < xdirty[i].y1)
|
||||
xdirty[i].y1 = y1;
|
||||
if (x2 > xdirty[i].x2)
|
||||
xdirty[i].x2 = x2;
|
||||
if (y2 > xdirty[i].y2)
|
||||
xdirty[i].y2 = y2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (xdirty_cnt >= MAX_XDIRTY_RECTS) {
|
||||
for (i = 1; i < xdirty_cnt; i++) {
|
||||
if (xdirty[i].x1 < xdirty[0].x1)
|
||||
xdirty[0].x1 = xdirty[i].x1;
|
||||
if (xdirty[i].y1 < xdirty[0].y1)
|
||||
xdirty[0].y1 = xdirty[i].y1;
|
||||
if (xdirty[i].x2 > xdirty[0].x2)
|
||||
xdirty[0].x2 = xdirty[i].x2;
|
||||
if (xdirty[i].y2 > xdirty[0].y2)
|
||||
xdirty[0].y2 = xdirty[i].y2;
|
||||
}
|
||||
if (x1 < xdirty[0].x1)
|
||||
xdirty[0].x1 = x1;
|
||||
if (y1 < xdirty[0].y1)
|
||||
xdirty[0].y1 = y1;
|
||||
if (x2 > xdirty[0].x2)
|
||||
xdirty[0].x2 = x2;
|
||||
if (y2 > xdirty[0].y2)
|
||||
xdirty[0].y2 = y2;
|
||||
xdirty_cnt = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
xdirty[xdirty_cnt++] = (XDirtyRect){ x1, y1, x2, y2 };
|
||||
}
|
||||
|
||||
void
|
||||
invert(const Arg *dummy)
|
||||
{
|
||||
invertcolors = !invertcolors;
|
||||
xinvalidatecells();
|
||||
redraw();
|
||||
}
|
||||
|
||||
@@ -814,6 +926,13 @@ xresize(int col, int row)
|
||||
win.tw = col * win.cw;
|
||||
win.th = row * win.ch;
|
||||
|
||||
xw_cells = xrealloc(xw_cells, (size_t)col * (size_t)row * sizeof(*xw_cells));
|
||||
xw_cells_cols = col;
|
||||
xw_cells_rows = row;
|
||||
xinvalidatecells();
|
||||
xw_buf_ready = 0;
|
||||
xdirty_cnt = 0;
|
||||
|
||||
XFreePixmap(xw.dpy, xw.buf);
|
||||
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
||||
DefaultDepth(xw.dpy, xw.scr));
|
||||
@@ -877,6 +996,7 @@ xloadcols(void)
|
||||
die("could not allocate color %d\n", i);
|
||||
}
|
||||
loaded = 1;
|
||||
xinvalidatecells();
|
||||
}
|
||||
|
||||
int
|
||||
@@ -892,6 +1012,7 @@ xsetcolorname(int x, const char *name)
|
||||
|
||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]);
|
||||
dc.col[x] = ncolor;
|
||||
xinvalidatecells();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -907,7 +1028,11 @@ xclear(int x1, int y1, int x2, int y2)
|
||||
if (invertcolors) {
|
||||
c = invertedcolor(&c);
|
||||
}
|
||||
if (x2 > borderpx && x1 < borderpx + win.tw &&
|
||||
y2 > borderpx && y1 < borderpx + win.th)
|
||||
xinvalidatecells();
|
||||
XftDrawRect(xw.draw, &c, x1, y1, x2-x1, y2-y1);
|
||||
xmarkdirty(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1239,6 +1364,12 @@ xinit(int cols, int rows)
|
||||
DefaultDepth(xw.dpy, xw.scr));
|
||||
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
|
||||
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
|
||||
xw_cells = xmalloc((size_t)cols * (size_t)rows * sizeof(*xw_cells));
|
||||
xw_cells_cols = cols;
|
||||
xw_cells_rows = rows;
|
||||
xinvalidatecells();
|
||||
xw_buf_ready = 0;
|
||||
xmarkdirty(0, 0, win.w, win.h);
|
||||
|
||||
/* font spec buffer */
|
||||
xw.specbuf = xmalloc(cols * sizeof(GlyphFontSpec));
|
||||
@@ -1586,6 +1717,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
|
||||
|
||||
/* Reset clip to none. */
|
||||
XftDrawSetClip(xw.draw, 0);
|
||||
xmarkdirty(winx, winy, winx + width, winy + win.ch);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1605,9 +1737,13 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
||||
XRenderColor colbg;
|
||||
|
||||
/* remove the old cursor */
|
||||
if (selected(ox, oy))
|
||||
og.mode ^= ATTR_REVERSE;
|
||||
xdrawglyph(og, ox, oy);
|
||||
if (xlast_cur_drawn || !IS_SET(MODE_HIDE)) {
|
||||
if (selected(ox, oy))
|
||||
og.mode ^= ATTR_REVERSE;
|
||||
xinvalidatecellrange(oy, ox, ox + ((og.mode & ATTR_WIDE) ? 2 : 1));
|
||||
xdrawglyph(og, ox, oy);
|
||||
xlast_cur_drawn = 0;
|
||||
}
|
||||
|
||||
if (IS_SET(MODE_HIDE))
|
||||
return;
|
||||
@@ -1666,6 +1802,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
||||
borderpx + (cy + 1) * win.ch - \
|
||||
cursorthickness,
|
||||
win.cw, cursorthickness);
|
||||
xmarkdirty(borderpx + cx * win.cw, borderpx + cy * win.ch,
|
||||
borderpx + (cx + 1) * win.cw, borderpx + (cy + 1) * win.ch);
|
||||
break;
|
||||
case 5: /* Blinking bar */
|
||||
case 6: /* Steady bar */
|
||||
@@ -1673,6 +1811,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
||||
borderpx + cx * win.cw,
|
||||
borderpx + cy * win.ch,
|
||||
cursorthickness, win.ch);
|
||||
xmarkdirty(borderpx + cx * win.cw, borderpx + cy * win.ch,
|
||||
borderpx + (cx + 1) * win.cw, borderpx + (cy + 1) * win.ch);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -1692,7 +1832,11 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
||||
borderpx + cx * win.cw,
|
||||
borderpx + (cy + 1) * win.ch - 1,
|
||||
win.cw, 1);
|
||||
xmarkdirty(borderpx + cx * win.cw, borderpx + cy * win.ch,
|
||||
borderpx + (cx + 1) * win.cw, borderpx + (cy + 1) * win.ch);
|
||||
}
|
||||
xinvalidatecellrange(cy, cx, cx + ((g.mode & ATTR_WIDE) ? 2 : 1));
|
||||
xlast_cur_drawn = 1;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1731,6 +1875,116 @@ xdrawline(Line line, int x1, int y1, int x2)
|
||||
XftGlyphFontSpec *specs = xw.specbuf;
|
||||
|
||||
numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
|
||||
if (xw_cells && y1 >= 0 && y1 < xw_cells_rows && x1 >= 0 && x2 <= xw_cells_cols &&
|
||||
x2 > x1 && (x2 - x1) <= 512) {
|
||||
int n = x2 - x1;
|
||||
uchar draw_col[512];
|
||||
uchar tok_col[512];
|
||||
int sidx = 0;
|
||||
int any_dirty = 0;
|
||||
|
||||
for (int k = 0; k < n; k++) {
|
||||
Glyph g = line[x1 + k];
|
||||
if (g.mode != ATTR_WDUMMY && selected(x1 + k, y1))
|
||||
g.mode ^= ATTR_REVERSE;
|
||||
ushort eff_mode = g.mode;
|
||||
if ((eff_mode & ATTR_BLINK) && (win.mode & MODE_BLINK))
|
||||
eff_mode |= ATTR_INVISIBLE;
|
||||
uchar cur_ns = (g.mode == ATTR_WDUMMY) || (g.u != ' ' && g.u != 0);
|
||||
XRenderedCell *rc = &xw_cells[y1 * xw_cells_cols + x1 + k];
|
||||
tok_col[k] = cur_ns || (rc->valid && rc->nonspace);
|
||||
|
||||
int matches = 0;
|
||||
if (g.mode == ATTR_WDUMMY) {
|
||||
matches = rc->valid && rc->mode == ATTR_WDUMMY;
|
||||
} else if (sidx < numspecs) {
|
||||
matches = rc->valid &&
|
||||
rc->font == specs[sidx].font &&
|
||||
rc->glyph == specs[sidx].glyph &&
|
||||
rc->fg == g.fg &&
|
||||
rc->bg == g.bg &&
|
||||
rc->mode == eff_mode;
|
||||
sidx++;
|
||||
}
|
||||
draw_col[k] = !matches;
|
||||
if (!matches)
|
||||
any_dirty = 1;
|
||||
}
|
||||
if (!any_dirty)
|
||||
return;
|
||||
|
||||
for (int k = 0; k < n - 1; k++) {
|
||||
if (draw_col[k] &&
|
||||
(line[x1 + k + 1].mode == ATTR_WDUMMY ||
|
||||
(tok_col[k] && tok_col[k + 1])))
|
||||
draw_col[k + 1] = 1;
|
||||
}
|
||||
for (int k = n - 1; k > 0; k--) {
|
||||
if (draw_col[k] &&
|
||||
(line[x1 + k].mode == ATTR_WDUMMY ||
|
||||
(tok_col[k] && tok_col[k - 1])))
|
||||
draw_col[k - 1] = 1;
|
||||
}
|
||||
|
||||
i = ox = 0;
|
||||
for (x = x1; x < x2; x++) {
|
||||
new = line[x];
|
||||
if (new.mode == ATTR_WDUMMY) {
|
||||
if (draw_col[x - x1]) {
|
||||
xw_cells[y1 * xw_cells_cols + x] = (XRenderedCell){
|
||||
.mode = ATTR_WDUMMY,
|
||||
.nonspace = 1,
|
||||
.valid = 1,
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (i >= numspecs)
|
||||
break;
|
||||
if (!draw_col[x - x1]) {
|
||||
if (i > 0) {
|
||||
xdrawglyphfontspecs(specs, base, i, ox, y1);
|
||||
specs += i;
|
||||
numspecs -= i;
|
||||
i = 0;
|
||||
}
|
||||
specs++;
|
||||
numspecs--;
|
||||
continue;
|
||||
}
|
||||
if (selected(x, y1))
|
||||
new.mode ^= ATTR_REVERSE;
|
||||
if (i > 0 && ATTRCMP(base, new)) {
|
||||
xdrawglyphfontspecs(specs, base, i, ox, y1);
|
||||
specs += i;
|
||||
numspecs -= i;
|
||||
i = 0;
|
||||
}
|
||||
if (i == 0) {
|
||||
ox = x;
|
||||
base = new;
|
||||
}
|
||||
{
|
||||
ushort eff_mode = new.mode;
|
||||
if ((eff_mode & ATTR_BLINK) && (win.mode & MODE_BLINK))
|
||||
eff_mode |= ATTR_INVISIBLE;
|
||||
xw_cells[y1 * xw_cells_cols + x] = (XRenderedCell){
|
||||
.font = specs[i].font,
|
||||
.glyph = specs[i].glyph,
|
||||
.fg = new.fg,
|
||||
.bg = new.bg,
|
||||
.mode = eff_mode,
|
||||
.nonspace = (new.u != ' ' && new.u != 0),
|
||||
.valid = 1,
|
||||
};
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (i > 0)
|
||||
xdrawglyphfontspecs(specs, base, i, ox, y1);
|
||||
return;
|
||||
}
|
||||
|
||||
i = ox = 0;
|
||||
for (x = x1; x < x2 && i < numspecs; x++) {
|
||||
new = line[x];
|
||||
@@ -1757,8 +2011,17 @@ xdrawline(Line line, int x1, int y1, int x2)
|
||||
void
|
||||
xfinishdraw(void)
|
||||
{
|
||||
XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
|
||||
win.h, 0, 0);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < xdirty_cnt; i++) {
|
||||
XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc,
|
||||
xdirty[i].x1, xdirty[i].y1,
|
||||
xdirty[i].x2 - xdirty[i].x1,
|
||||
xdirty[i].y2 - xdirty[i].y1,
|
||||
xdirty[i].x1, xdirty[i].y1);
|
||||
}
|
||||
xdirty_cnt = 0;
|
||||
xw_buf_ready = 1;
|
||||
XSetForeground(xw.dpy, dc.gc,
|
||||
dc.col[IS_SET(MODE_REVERSE)?
|
||||
defaultfg : defaultbg].pixel);
|
||||
@@ -1774,6 +2037,15 @@ xximspot(int x, int y)
|
||||
void
|
||||
expose(XEvent *ev)
|
||||
{
|
||||
XExposeEvent *e = &ev->xexpose;
|
||||
|
||||
if (xw_buf_ready && xw.buf != None) {
|
||||
if (e->width > 0 && e->height > 0)
|
||||
XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc,
|
||||
e->x, e->y, e->width, e->height, e->x, e->y);
|
||||
return;
|
||||
}
|
||||
xinvalidatecells();
|
||||
redraw();
|
||||
}
|
||||
|
||||
@@ -1855,8 +2127,10 @@ xsetmode(int set, unsigned int flags)
|
||||
{
|
||||
int mode = win.mode;
|
||||
MODBIT(win.mode, set, flags);
|
||||
if ((win.mode & MODE_REVERSE) != (mode & MODE_REVERSE))
|
||||
if ((win.mode & MODE_REVERSE) != (mode & MODE_REVERSE)) {
|
||||
xinvalidatecells();
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
@@ -1899,6 +2173,8 @@ focus(XEvent *ev)
|
||||
return;
|
||||
win.mode |= MODE_FOCUSED;
|
||||
xseturgency(0);
|
||||
if (!IS_SET(MODE_HIDE))
|
||||
xlast_cur_drawn = 1;
|
||||
if (IS_SET(MODE_FOCUS))
|
||||
ttywrite("\033[I", 3, 0);
|
||||
redraw();
|
||||
@@ -1909,6 +2185,8 @@ focus(XEvent *ev)
|
||||
if (e->mode == NotifyGrab)
|
||||
return;
|
||||
win.mode &= ~MODE_FOCUSED;
|
||||
if (!IS_SET(MODE_HIDE))
|
||||
xlast_cur_drawn = 1;
|
||||
if (IS_SET(MODE_FOCUS))
|
||||
ttywrite("\033[O", 3, 0);
|
||||
redraw();
|
||||
|
||||
Reference in new issue
Block a user