miniview: correctly handle resizing

This commit is contained in:
Boris Faure 2014-05-02 00:08:58 +02:00
parent c311cbf8da
commit e5c8da2cbd
6 changed files with 62 additions and 32 deletions

View File

@ -2212,7 +2212,7 @@ main_term_new(Win *wn, Config *config, const char *cmd,
} }
term->term = o = termio_add(wn->win, config, cmd, login_shell, cd, term->term = o = termio_add(wn->win, config, cmd, login_shell, cd,
size_w, size_h); size_w, size_h, term);
colors_term_init(termio_textgrid_get(term->term), term->bg, config); colors_term_init(termio_textgrid_get(term->term), term->bg, config);
termio_win_set(o, wn->win); termio_win_set(o, wn->win);
@ -2304,6 +2304,13 @@ Evas_Object *main_term_evas_object_get(Term *term)
return term->term; return term->term;
} }
Evas_Object *
term_miniview_get(Term *term)
{
return term->miniview;
}
static void static void
main_ipc_new(Ipc_Instance *inst) main_ipc_new(Ipc_Instance *inst)
{ {

View File

@ -26,5 +26,6 @@ Win *main_term_win_get(Term *term);
Evas_Object *main_win_evas_object_get(Win *wn); Evas_Object *main_win_evas_object_get(Win *wn);
Eina_List *main_win_terms_get(Win *wn); Eina_List *main_win_terms_get(Win *wn);
Evas_Object *main_term_evas_object_get(Term *term); Evas_Object *main_term_evas_object_get(Term *term);
Evas_Object *term_miniview_get(Term *term);
#endif #endif

View File

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "miniview.h"
#include "col.h" #include "col.h"
#include "termpty.h" #include "termpty.h"
#include "termio.h" #include "termio.h"
@ -58,6 +59,8 @@ struct _Miniview
int viewport_h; int viewport_h;
int rows; int rows;
int columns; int columns;
int is_shown;
}; };
static Evas_Smart *_smart = NULL; static Evas_Smart *_smart = NULL;
@ -249,6 +252,8 @@ _smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
EINA_SAFETY_ON_NULL_RETURN(mv); EINA_SAFETY_ON_NULL_RETURN(mv);
/* TODO handle keybinding to hide */
if (!strcmp(ev->key, "Prior")) if (!strcmp(ev->key, "Prior"))
_scroll(mv, -10); _scroll(mv, -10);
else if (!strcmp(ev->key, "Next")) else if (!strcmp(ev->key, "Next"))
@ -337,8 +342,15 @@ _smart_show(Evas_Object *obj)
{ {
Miniview *mv = evas_object_smart_data_get(obj); Miniview *mv = evas_object_smart_data_get(obj);
DBG("smart show obj:%p mv:%p", obj, mv);
if (!mv) return; if (!mv) return;
if (!mv->is_shown)
{
mv->is_shown = 1;
miniview_redraw(obj, mv->columns, mv->rows);
evas_object_show(mv->img);
}
/* /*
Evas_Coord ox, oy, ow, oh; Evas_Coord ox, oy, ow, oh;
evas_object_geometry_get(mv->img, &ox, &oy, &ow, &oh); evas_object_geometry_get(mv->img, &ox, &oy, &ow, &oh);
@ -351,7 +363,6 @@ _smart_show(Evas_Object *obj)
evas_object_layer_get(mv->termio)); evas_object_layer_get(mv->termio));
*/ */
evas_object_show(mv->img);
} }
static void static void
@ -359,36 +370,41 @@ _smart_hide(Evas_Object *obj)
{ {
Miniview *mv = evas_object_smart_data_get(obj); Miniview *mv = evas_object_smart_data_get(obj);
DBG("smart hide obj:%p mv:%p", obj, mv);
if (!mv) return; if (!mv) return;
evas_object_hide(mv->img); if (mv->is_shown)
{
mv->is_shown = 0;
evas_object_hide(mv->img);
}
} }
static void void
_smart_size(Evas_Object *obj) miniview_redraw(Evas_Object *obj, int columns, int rows)
{ {
Miniview *mv = evas_object_smart_data_get(obj); Miniview *mv;
Evas_Coord ox, oy, ow, oh, font_w, font_h; Evas_Coord ox, oy, ow, oh;
int history_len, h, y, wret; int history_len, h, y, wret;
unsigned int *pixels; unsigned int *pixels;
Termcell *cells; Termcell *cells;
if (!obj) return;
mv = evas_object_smart_data_get(obj);
if (!mv) return; if (!mv) return;
mv->columns = columns;
mv->rows = rows;
if (!mv->is_shown) return;
DBG("smart size %p", obj); DBG("smart size %p", obj);
evas_object_geometry_get(mv->termio, &ox, &oy, &ow, &oh); evas_object_geometry_get(mv->termio, &ox, &oy, &ow, &oh);
if (ow == 0 || oh == 0) return; if (ow == 0 || oh == 0) return;
evas_object_size_hint_min_get(mv->termio, &font_w, &font_h);
if (font_w <= 0) return;
mv->columns = ow / font_w;
mv->rows = oh / font_h;
mv->img_h = 3 * oh; mv->img_h = 3 * oh;
DBG("ox:%d oy:%d ow:%d oh:%d font_w:%d columns:%d rows:%d", DBG("ox:%d oy:%d ow:%d oh:%d columns:%d rows:%d",
ox, oy, ow, oh, font_w, mv->columns, mv->rows); ox, oy, ow, oh, mv->columns, mv->rows);
evas_object_resize(mv->img, mv->columns, mv->img_h); evas_object_resize(mv->img, mv->columns, mv->img_h);
evas_object_image_size_set(mv->img, mv->columns, mv->img_h); evas_object_image_size_set(mv->img, mv->columns, mv->img_h);
@ -397,6 +413,9 @@ _smart_size(Evas_Object *obj)
history_len = mv->pty->backscroll_num; history_len = mv->pty->backscroll_num;
DBG("backscroll_num:%d backmax:%d backpos:%d",
mv->pty->backscroll_num, mv->pty->backmax, mv->pty->backpos);
pixels = evas_object_image_data_get(mv->img, EINA_TRUE); pixels = evas_object_image_data_get(mv->img, EINA_TRUE);
memset(pixels, 0, sizeof(*pixels) * mv->columns * mv->img_h); memset(pixels, 0, sizeof(*pixels) * mv->columns * mv->img_h);
@ -447,9 +466,6 @@ _smart_size(Evas_Object *obj)
} }
static void static void
_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{ {
@ -458,7 +474,6 @@ _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
DBG("smart resize %p w:%d h:%d", obj, w, h); DBG("smart resize %p w:%d h:%d", obj, w, h);
evas_object_resize(mv->img, w, h); evas_object_resize(mv->img, w, h);
_smart_size(obj);
} }
@ -480,22 +495,13 @@ _smart_init(void)
_smart = evas_smart_class_new(&sc); _smart = evas_smart_class_new(&sc);
} }
void
miniview_update_scroll(Evas_Object *obj, int scroll_position)
{
Miniview *mv = evas_object_smart_data_get(obj);
if (!mv) return;
DBG("obj:%p mv:%p scroll_position:%d", obj, mv, scroll_position);
}
Evas_Object * Evas_Object *
miniview_add(Evas_Object *parent, Evas_Object *termio) miniview_add(Evas_Object *parent, Evas_Object *termio)
{ {
Evas *e; Evas *e;
Evas_Object *obj; Evas_Object *obj;
Miniview *mv; Miniview *mv;
Evas_Coord ow, oh, font_w, font_h;
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
e = evas_object_evas_get(parent); e = evas_object_evas_get(parent);
@ -512,7 +518,13 @@ miniview_add(Evas_Object *parent, Evas_Object *termio)
mv->termio = termio; mv->termio = termio;
mv->pty = termio_pty_get(termio); mv->pty = termio_pty_get(termio);
_smart_size(obj); evas_object_geometry_get(mv->termio, NULL, NULL, &ow, &oh);
if (ow == 0 || oh == 0) return obj;
evas_object_size_hint_min_get(mv->termio, &font_w, &font_h);
if (font_w <= 0 || font_h <= 0) return obj;
miniview_redraw(obj, ow / font_w, oh / font_h);
return obj; return obj;
} }

View File

@ -1,9 +1,11 @@
#ifndef _MINIVIEW_H__ #ifndef _MINIVIEW_H__
#define _MINIVIEW_H__ 1 #define _MINIVIEW_H__ 1
void miniview_update_scroll(Evas_Object *obj, int scroll_position);
Evas_Object * miniview_add(Evas_Object *parent, Evas_Object *termio); Evas_Object * miniview_add(Evas_Object *parent, Evas_Object *termio);
void miniview_redraw(Evas_Object *obj, int columns, int rows);
void miniview_init(void); void miniview_init(void);
void miniview_shutdown(void); void miniview_shutdown(void);
#endif #endif

View File

@ -16,6 +16,7 @@
#include "utils.h" #include "utils.h"
#include "media.h" #include "media.h"
#include "dbus.h" #include "dbus.h"
#include "miniview.h"
#if defined (__MacOSX__) || (defined (__MACH__) && defined (__APPLE__)) #if defined (__MacOSX__) || (defined (__MACH__) && defined (__APPLE__))
# include <sys/proc_info.h> # include <sys/proc_info.h>
@ -68,6 +69,8 @@ struct _Termio
Eina_List *seq; Eina_List *seq;
Evas_Object *self; Evas_Object *self;
Evas_Object *event; Evas_Object *event;
Term *term;
Termpty *pty; Termpty *pty;
Ecore_Animator *anim; Ecore_Animator *anim;
Ecore_Timer *delayed_size_timer; Ecore_Timer *delayed_size_timer;
@ -1649,6 +1652,7 @@ _smart_size(Evas_Object *obj, int w, int h, Eina_Bool force)
sd->font.chh * sd->grid.h); sd->font.chh * sd->grid.h);
_sel_set(obj, EINA_FALSE); _sel_set(obj, EINA_FALSE);
termpty_resize(sd->pty, w, h); termpty_resize(sd->pty, w, h);
miniview_redraw(term_miniview_get(sd->term), w, h);
_smart_calculate(obj); _smart_calculate(obj);
_smart_apply(obj); _smart_apply(obj);
@ -4448,7 +4452,9 @@ _smart_cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
#endif #endif
Evas_Object * Evas_Object *
termio_add(Evas_Object *parent, Config *config, const char *cmd, Eina_Bool login_shell, const char *cd, int w, int h) termio_add(Evas_Object *parent, Config *config,
const char *cmd, Eina_Bool login_shell, const char *cd,
int w, int h, Term *term)
{ {
Evas *e; Evas *e;
Evas_Object *obj, *g; Evas_Object *obj, *g;
@ -4477,6 +4483,7 @@ termio_add(Evas_Object *parent, Config *config, const char *cmd, Eina_Bool login
mod = modules[config->vidmod]; mod = modules[config->vidmod];
termio_config_set(obj, config); termio_config_set(obj, config);
sd->term = term;
sd->glayer = g = elm_gesture_layer_add(parent); sd->glayer = g = elm_gesture_layer_add(parent);
elm_gesture_layer_attach(g, sd->event); elm_gesture_layer_attach(g, sd->event);

View File

@ -2,10 +2,11 @@
#define _TERMIO_H__ 1 #define _TERMIO_H__ 1
#include "config.h" #include "config.h"
#include "main.h"
#include "col.h" #include "col.h"
#include "termpty.h" #include "termpty.h"
Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd, Eina_Bool login_shell, const char *cd, int w, int h); Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd, Eina_Bool login_shell, const char *cd, int w, int h, Term *term);
void termio_win_set(Evas_Object *obj, Evas_Object *win); void termio_win_set(Evas_Object *obj, Evas_Object *win);
void termio_theme_set(Evas_Object *obj, Evas_Object *theme); void termio_theme_set(Evas_Object *obj, Evas_Object *theme);
Evas_Object *termio_theme_get(Evas_Object *obj); Evas_Object *termio_theme_get(Evas_Object *obj);