console: add margin API

Allow external subsystems to modify the margin sizes. When setting the
margins we must take care to first perform the shrink operation and then
the grow operations. For instance, if our current top margin is 10 and
the bottom margin is 0 and the application requests to swap the margin
sizes, we should *first* shrink the top margin to 0 and then grow the
bottom margin to 10. Otherwise, we might end up with garbled margins on
a buffer which is smaller than 20 lines.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-02-03 17:48:09 +01:00
parent cd62b330be
commit b367a9682c
2 changed files with 41 additions and 0 deletions

View File

@ -60,6 +60,10 @@ void kmscon_buffer_draw(struct kmscon_buffer *buf, struct kmscon_font *font);
void kmscon_buffer_set_max_sb(struct kmscon_buffer *buf, unsigned int max);
void kmscon_buffer_clear_sb(struct kmscon_buffer *buf);
int kmscon_buffer_set_margins(struct kmscon_buffer *buf, unsigned int top,
unsigned int bottom);
unsigned int kmscon_buffer_get_mtop(struct kmscon_buffer *buf);
unsigned int kmscon_buffer_get_mbottom(struct kmscon_buffer *buf);
unsigned int kmscon_buffer_get_width(struct kmscon_buffer *buf);
unsigned int kmscon_buffer_get_height(struct kmscon_buffer *buf);
void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,

View File

@ -617,6 +617,43 @@ int kmscon_buffer_resize(struct kmscon_buffer *buf, unsigned int x,
return 0;
}
int kmscon_buffer_set_margins(struct kmscon_buffer *buf, unsigned int top,
unsigned int bottom)
{
int ret;
if (!buf)
return -EINVAL;
if (top < buf->mtop_y) {
ret = resize_mtop(buf, top);
if (ret)
return ret;
return resize_mbottom(buf, bottom);
} else {
ret = resize_mbottom(buf, bottom);
if (ret)
return ret;
return resize_mtop(buf, top);
}
}
unsigned int kmscon_buffer_get_mtop(struct kmscon_buffer *buf)
{
if (!buf)
return 0;
return buf->mtop_y;
}
unsigned int kmscon_buffer_get_mbottom(struct kmscon_buffer *buf)
{
if (!buf)
return 0;
return buf->mbottom_y;
}
void kmscon_buffer_draw(struct kmscon_buffer *buf, struct kmscon_font *font)
{
float xs, ys;