Skip to content

Commit

Permalink
Add cursor color options
Browse files Browse the repository at this point in the history
  • Loading branch information
91861 committed Feb 13, 2021
1 parent 2ddda51 commit fd91890
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 134 deletions.
3 changes: 1 addition & 2 deletions src/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ static double _fmt_eval_operand(Map_size_t_fmt_arg_t* vars, Vector_char* expr, c
case FMT_ARG_TYPE_FLOAT:
return *((float*)arg->addr);
case FMT_ARG_TYPE_STRING:
*e = "cannot cast string to numeric type";
return 0;
return *((const char**)arg->addr) ? strlen(*(const char**)arg->addr) : 0;
}
} else {
bool fnd_alpha = false;
Expand Down
34 changes: 17 additions & 17 deletions src/gfx_gl21.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ __attribute__((hot)) static inline void _GfxOpenGL21_rasterize_line_range(
const double scaley = 2.0 / texture_dims.second;

GLint bg_pixels_begin = range.first * gfx->glyph_width_pixels, bg_pixels_end;
ColorRGBA active_bg_color = is_for_cursor ? ColorRGBA_from_RGB(vt->colors.fg) : vt->colors.bg;
ColorRGBA active_bg_color = is_for_cursor ? Vt_rune_cursor_bg(vt, NULL) : vt->colors.bg;
VtRune* each_rune = vt_line->data.buf + range.first;
VtRune* same_bg_block_begin_rune = each_rune;

Expand Down Expand Up @@ -1933,10 +1933,11 @@ __attribute__((hot)) static inline void GfxOpenGL21_rasterize_line(
glUseProgram(0);

if (is_for_cursor) {
glClearColor(ColorRGB_get_float(vt->colors.fg, 0),
ColorRGB_get_float(vt->colors.fg, 1),
ColorRGB_get_float(vt->colors.fg, 2),
1.0f);
ColorRGBA clr = Vt_rune_cursor_bg(vt, NULL);
glClearColor(ColorRGBA_get_float(clr, 0),
ColorRGBA_get_float(clr, 1),
ColorRGBA_get_float(clr, 2),
ColorRGBA_get_float(clr, 3));
} else {
glClearColor(ColorRGBA_get_float(vt->colors.bg, 0),
ColorRGBA_get_float(vt->colors.bg, 1),
Expand Down Expand Up @@ -2167,7 +2168,7 @@ __attribute__((hot)) static inline void GfxOpenGL21_rasterize_line(
static void _GfxOpenGL21_draw_block_cursor(GfxOpenGL21* gfx,
const Vt* vt,
const Ui* ui,
ColorRGB clr,
ColorRGBA clr,
size_t row)
{
((vt_line_damage_t*)&ui->cursor_damage)->type = VT_LINE_DAMAGE_FULL; // test
Expand All @@ -2194,10 +2195,10 @@ static void _GfxOpenGL21_draw_block_cursor(GfxOpenGL21* gfx,
glScissor(x, y, w, h);
}

glClearColor(ColorRGB_get_float(clr, 0),
ColorRGB_get_float(clr, 1),
ColorRGB_get_float(clr, 2),
1.0f);
glClearColor(ColorRGBA_get_float(clr, 0),
ColorRGBA_get_float(clr, 1),
ColorRGBA_get_float(clr, 3),
ColorRGBA_get_float(clr, 4));

glClear(GL_COLOR_BUFFER_BIT);

Expand Down Expand Up @@ -2287,12 +2288,11 @@ static void GfxOpenGL21_draw_cursor(GfxOpenGL21* gfx, const Vt* vt, const Ui* ui
break;
}

ColorRGB clr;
VtRune* cursor_rune = NULL;
if (vt->lines.size > ui->cursor->row && vt->lines.buf[ui->cursor->row].data.size > st_col) {
clr = Vt_rune_fg(vt, &vt->lines.buf[ui->cursor->row].data.buf[st_col]);
} else {
clr = vt->colors.fg;
cursor_rune = &vt->lines.buf[ui->cursor->row].data.buf[st_col];
}
ColorRGBA clr = Vt_rune_cursor_bg(vt, cursor_rune);

if (!filled_block) {
Shader_use(&gfx->line_shader);
Expand All @@ -2302,9 +2302,9 @@ static void GfxOpenGL21_draw_cursor(GfxOpenGL21* gfx, const Vt* vt, const Ui* ui
glVertexAttribPointer(gfx->line_shader.attribs->location, 2, GL_FLOAT, GL_FALSE, 0, 0);

glUniform3f(gfx->line_shader.uniforms[1].location,
ColorRGB_get_float(clr, 0),
ColorRGB_get_float(clr, 1),
ColorRGB_get_float(clr, 2));
ColorRGBA_get_float(clr, 0),
ColorRGBA_get_float(clr, 1),
ColorRGBA_get_float(clr, 2));

size_t newsize = gfx->vec_vertex_buffer.size * sizeof(vertex_t);
ARRAY_BUFFER_SUB_OR_SWAP(gfx->vec_vertex_buffer.buf, gfx->flex_vbo.size, newsize);
Expand Down
28 changes: 19 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,10 @@ static void App_clamp_cursor(App* self, Pair_uint32_t chars)

static void App_exit_handler(void* self)
{
App* app = self;
app->exit = true;
App* app = self;
if (!settings.hold_after_child_process_exit) {
app->exit = true;
}
}

static int App_get_ksm_number(App* self)
Expand Down Expand Up @@ -1902,19 +1904,28 @@ static void App_set_text_area_size(void* self, int32_t width, int32_t height)

static Pair_uint32_t App_text_area_size(void* self)
{
App* app = self;

App* app = self;
Pair_uint32_t win_size = Window_size(app->win);
win_size.first -= settings.padding;
win_size.second -= settings.padding;

return win_size;
}

static void App_visual_scroll_reset_handler(void* self)
{
App* app = self;
if (app->ui.scrollbar.visible) {
App_update_scrollbar_dims(self);
App_show_scrollbar(self);
}
}

static void App_set_urgent(void* self)
{
if (!Window_is_focused(((App*)self)->win))
Window_set_urgent(((App*)self)->win);
App* app = self;
if (!Window_is_focused(app->win)) {
Window_set_urgent(app->win);
}
}

static void App_restack_to_front(void* self)
Expand All @@ -1925,11 +1936,9 @@ static void App_restack_to_front(void* self)
static const char* App_get_hostname(void* self)
{
App* app = self;

if (!app->hostname) {
app->hostname = get_hostname();
}

return app->hostname;
}

Expand Down Expand Up @@ -1968,6 +1977,7 @@ static void App_set_callbacks(App* self)
self->vt.callbacks.on_mouse_report_state_changed = App_mouse_report_changed;
self->vt.callbacks.on_buffer_changed = App_buffer_changed;
self->vt.callbacks.on_gui_pointer_mode_changed = App_gui_pointer_mode_change_handler;
self->vt.callbacks.on_visual_scroll_reset = App_visual_scroll_reset_handler;

self->win->callbacks.user_data = self;
self->win->callbacks.key_handler = App_key_handler;
Expand Down
Loading

0 comments on commit fd91890

Please sign in to comment.