termio/termptyesc: clean up mess with color classes

This commit is contained in:
Boris Faure 2020-11-15 00:15:10 +01:00
parent 5b186b69a3
commit 11abaaa0b4
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
5 changed files with 76 additions and 87 deletions

View File

@ -76,22 +76,30 @@ void
termio_theme_set(Evas_Object *obj, Evas_Object *theme) termio_theme_set(Evas_Object *obj, Evas_Object *theme)
{ {
Termio *sd = evas_object_smart_data_get(obj); Termio *sd = evas_object_smart_data_get(obj);
Evas_Object *bg;
EINA_SAFETY_ON_NULL_RETURN(sd); EINA_SAFETY_ON_NULL_RETURN(sd);
EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj); EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj);
EINA_SAFETY_ON_NULL_RETURN(theme); EINA_SAFETY_ON_NULL_RETURN(theme);
sd->theme = theme; sd->theme = theme;
bg = term_bg_get(sd->term);
EINA_SAFETY_ON_NULL_RETURN(bg);
termio_color_class_get(obj, "BG", edje_object_color_class_get(bg, "BG",
&sd->saved_bg.r, &sd->saved_bg.r,
&sd->saved_bg.g, &sd->saved_bg.g,
&sd->saved_bg.b, &sd->saved_bg.b,
&sd->saved_bg.a); &sd->saved_bg.a,
termio_color_class_get(sd->cursor.obj, "CURSOR", NULL, NULL, NULL, NULL,
&sd->saved_cursor.r, NULL, NULL, NULL, NULL);
&sd->saved_cursor.g, edje_object_color_class_get(sd->cursor.obj, "CURSOR",
&sd->saved_cursor.b, &sd->saved_cursor.r,
&sd->saved_cursor.a); &sd->saved_cursor.g,
&sd->saved_cursor.b,
&sd->saved_cursor.a,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
evas_object_textgrid_palette_get( evas_object_textgrid_palette_get(
sd->grid.obj, sd->grid.obj,
EVAS_TEXTGRID_PALETTE_STANDARD, 0, EVAS_TEXTGRID_PALETTE_STANDARD, 0,
@ -107,10 +115,22 @@ termio_reset_main_colors(Evas_Object *termio)
if (termio) if (termio)
{ {
Termio *sd = evas_object_smart_data_get(termio); Termio *sd = evas_object_smart_data_get(termio);
Evas_Object *bg;
EINA_SAFETY_ON_NULL_RETURN(sd); EINA_SAFETY_ON_NULL_RETURN(sd);
EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj); EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj);
termio_color_class_set(termio, "BG", bg = term_bg_get(sd->term);
EINA_SAFETY_ON_NULL_RETURN(bg);
edje_object_color_class_set(bg, "BG",
sd->saved_bg.r,
sd->saved_bg.g,
sd->saved_bg.b,
sd->saved_bg.a,
sd->saved_bg.r,
sd->saved_bg.g,
sd->saved_bg.b,
sd->saved_bg.a,
sd->saved_bg.r, sd->saved_bg.r,
sd->saved_bg.g, sd->saved_bg.g,
sd->saved_bg.b, sd->saved_bg.b,
@ -329,6 +349,15 @@ termio_term_get(const Evas_Object *obj)
return sd->term; return sd->term;
} }
Evas_Object *
termio_bg_get(const Evas_Object *obj)
{
Termio *sd = evas_object_smart_data_get(obj);
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
return term_bg_get(sd->term);
}
static void static void
_font_size_set(Evas_Object *obj, int size) _font_size_set(Evas_Object *obj, int size)
{ {
@ -4187,62 +4216,3 @@ termio_key_down(Evas_Object *termio,
edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology"); edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology");
ev->event_flags = EVAS_EVENT_FLAG_ON_HOLD; ev->event_flags = EVAS_EVENT_FLAG_ON_HOLD;
} }
int
termio_color_class_get(Evas_Object *termio, const char *key,
int *r, int *g, int *b, int *a)
{
Termio *sd = evas_object_smart_data_get(termio);
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, -1);
if (sd->term)
{
Evas_Object *bg = term_bg_get(sd->term);
if (!edje_object_color_class_get(bg, key,
r,
g,
b,
a,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL))
{
ERR("color class '%s' not found in theme", key);
return -1;
}
}
else
{
ERR("term not found");
return -1;
}
return 0;
}
int
termio_color_class_set(Evas_Object *termio, const char *key,
int r, int g, int b, int a)
{
Termio *sd = evas_object_smart_data_get(termio);
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, -1);
if (sd->term)
{
Evas_Object *bg = term_bg_get(sd->term);
if (!edje_object_color_class_set(bg, key,
r, g, b, a,
r, g, b, a,
r, g, b, a))
{
ERR("can not set color class '%s'", key);
return -1;
}
}
else
{
ERR("term not found");
return -1;
}
return 0;
}

View File

@ -65,6 +65,7 @@ termio_imf_cursor_set(Evas_Object *obj, Ecore_IMF_Context *imf);
Termpty *termio_pty_get(const Evas_Object *obj); Termpty *termio_pty_get(const Evas_Object *obj);
Evas_Object * termio_miniview_get(const Evas_Object *obj); Evas_Object * termio_miniview_get(const Evas_Object *obj);
Term* termio_term_get(const Evas_Object *obj); Term* termio_term_get(const Evas_Object *obj);
Evas_Object *termio_bg_get(const Evas_Object *obj);
void termio_key_down(Evas_Object *termio, void termio_key_down(Evas_Object *termio,
Evas_Event_Key_Down *ev, Evas_Event_Key_Down *ev,
@ -84,12 +85,6 @@ void
termio_block_activate(Evas_Object *obj, Termblock *blk); termio_block_activate(Evas_Object *obj, Termblock *blk);
const char * const char *
term_preedit_str_get(Term *term); term_preedit_str_get(Term *term);
int
termio_color_class_get(Evas_Object *termio, const char *key,
int *r, int *g, int *b, int *a);
int
termio_color_class_set(Evas_Object *termio, const char *key,
int r, int g, int b, int a);
void void
termio_reset_main_colors(Evas_Object *termio); termio_reset_main_colors(Evas_Object *termio);
#endif #endif

View File

@ -4173,12 +4173,14 @@ _handle_xterm_set_color_class(Termpty *ty, Eina_Unicode *p, int len,
char buf[64]; char buf[64];
size_t l; size_t l;
if (termio_color_class_get(obj, color_class, &r, &g, &b, NULL) != 0) if (edje_object_color_class_get(obj, color_class, &r, &g, &b, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL) != 0)
{ {
ERR("error getting color class '%s'", color_class); ERR("error getting color class '%s'", color_class);
} }
l = snprintf(buf, sizeof(buf), l = snprintf(buf, sizeof(buf),
"\033]%d;rgb:%.2x%.2x/%.2x%.2x/%.2x%.2x\033\\", "\033]%d;rgb:%.2x%.2x/%.2x%.2x/%.2x%.2x\007",
number, r, r, g, g, b, b); number, r, r, g, g, b, b);
termpty_write(ty, buf, l); termpty_write(ty, buf, l);
} }
@ -4187,13 +4189,10 @@ _handle_xterm_set_color_class(Termpty *ty, Eina_Unicode *p, int len,
unsigned char r, g, b; unsigned char r, g, b;
if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0) if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0)
goto err; goto err;
if (obj == ty->obj) edje_object_color_class_set(obj, color_class,
termio_color_class_set(obj, color_class, r, g, b, 0xff); r, g, b, 0xff,
else r, g, b, 0xff,
edje_object_color_class_set(obj, "CURSOR", r, g, b, 0xff);
r, g, b, 0xff,
r, g, b, 0xff,
r, g, b, 0xff);
} }
return; return;
@ -4325,7 +4324,8 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
case 11: case 11:
DBG("Set background color"); DBG("Set background color");
_handle_xterm_set_color_class(ty, p, cc - c - (p - buf), _handle_xterm_set_color_class(ty, p, cc - c - (p - buf),
ty->obj, "BG", 11); termio_bg_get(ty->obj),
"BG", 11);
break; break;
case 12: case 12:
DBG("Set cursor color"); DBG("Set cursor color");

View File

@ -16,6 +16,19 @@ test_textgrid_palette_get(const Evas_Object *obj,
Evas_Textgrid_Cell * Evas_Textgrid_Cell *
tytest_textgrid_cellrow_get(Evas_Object *obj, int y); tytest_textgrid_cellrow_get(Evas_Object *obj, int y);
#define edje_object_color_class_get tytest_edje_object_color_class_get
int
tytest_edje_object_color_class_get(Evas_Object *termio EINA_UNUSED, const char *key,
int *r, int *g, int *b, int *a,
int *r1 EINA_UNUSED, int *g1 EINA_UNUSED, int *b1 EINA_UNUSED, int *a1 EINA_UNUSED,
int *r2 EINA_UNUSED, int *g2 EINA_UNUSED, int *b2 EINA_UNUSED, int *a2 EINA_UNUSED);
#define edje_object_color_class_set tytest_edje_object_color_class_set
int
tytest_edje_object_color_class_set(Evas_Object *termio EINA_UNUSED, const char *key,
int r, int g, int b, int a,
int r1 EINA_UNUSED, int g1 EINA_UNUSED, int b1 EINA_UNUSED, int a1 EINA_UNUSED,
int r2 EINA_UNUSED, int g2 EINA_UNUSED, int b2 EINA_UNUSED, int a2 EINA_UNUSED);
void void
tytest_termio_resize(int w, int h); tytest_termio_resize(int w, int h);
#endif #endif

View File

@ -277,8 +277,10 @@ termio_set_cursor_shape(Evas_Object *obj EINA_UNUSED,
int int
termio_color_class_get(Evas_Object *termio EINA_UNUSED, const char *key, tytest_edje_object_color_class_get(Evas_Object *termio EINA_UNUSED, const char *key,
int *r, int *g, int *b, int *a) int *r, int *g, int *b, int *a,
int *r1 EINA_UNUSED, int *g1 EINA_UNUSED, int *b1 EINA_UNUSED, int *a1 EINA_UNUSED,
int *r2 EINA_UNUSED, int *g2 EINA_UNUSED, int *b2 EINA_UNUSED, int *a2 EINA_UNUSED)
{ {
if (strncmp(key, "BG", strlen("BG")) == 0) if (strncmp(key, "BG", strlen("BG")) == 0)
{ {
@ -306,9 +308,12 @@ termio_color_class_get(Evas_Object *termio EINA_UNUSED, const char *key,
} }
return -1; return -1;
} }
int int
termio_color_class_set(Evas_Object *termio EINA_UNUSED, const char *key, tytest_edje_object_color_class_set(Evas_Object *termio EINA_UNUSED, const char *key,
int r, int g, int b, int a) int r, int g, int b, int a,
int r1 EINA_UNUSED, int g1 EINA_UNUSED, int b1 EINA_UNUSED, int a1 EINA_UNUSED,
int r2 EINA_UNUSED, int g2 EINA_UNUSED, int b2 EINA_UNUSED, int a2 EINA_UNUSED)
{ {
if (strncmp(key, "BG", strlen("BG")) == 0) if (strncmp(key, "BG", strlen("BG")) == 0)
{ {
@ -348,6 +353,12 @@ termio_textgrid_get(const Evas_Object *obj EINA_UNUSED)
return NULL; return NULL;
} }
Evas_Object *
termio_bg_get(const Evas_Object *obj EINA_UNUSED)
{
return NULL;
}
#if defined(BINARY_TYTEST) #if defined(BINARY_TYTEST)
void void
test_textgrid_palette_get(const Evas_Object *obj EINA_UNUSED, test_textgrid_palette_get(const Evas_Object *obj EINA_UNUSED,