/trunk/uspace/srv/console/console.c |
---|
40,7 → 40,6 |
#include <ipc/services.h> |
#include <errno.h> |
#include <key_buffer.h> |
#include <console.h> |
#include <ipc/console.h> |
#include <unistd.h> |
#include <async.h> |
50,6 → 49,7 |
#include <stdio.h> |
#include <sysinfo.h> |
#include "console.h" |
#include "gcons.h" |
#define MAX_KEYREQUESTS_BUFFERED 32 |
124,17 → 124,39 |
async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
} |
static void set_style(style_t *style) |
static void set_style(int style) |
{ |
async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color, |
style->bg_color); |
async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
} |
static void set_style_col(int fgcolor, int bgcolor) |
static void set_color(int fgcolor, int bgcolor, int flags) |
{ |
async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor); |
async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
} |
static void set_rgb_color(int fgcolor, int bgcolor) |
{ |
async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); |
} |
static void set_attrs(attrs_t *attrs) |
{ |
switch (attrs->t) { |
case at_style: |
set_style(attrs->a.s.style); |
break; |
case at_idx: |
set_color(attrs->a.i.fg_color, attrs->a.i.bg_color, |
attrs->a.i.flags); |
break; |
case at_rgb: |
set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color); |
break; |
} |
} |
static void prtchr(char c, int row, int col) |
{ |
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
198,7 → 220,7 |
connection_t *conn; |
int i, j, rc; |
keyfield_t *field; |
style_t *style; |
attrs_t *attrs; |
if (newcons == active_console) |
return; |
226,7 → 248,7 |
gcons_change_console(newcons); |
conn = &connections[active_console]; |
set_style(&conn->screenbuffer.style); |
set_attrs(&conn->screenbuffer.attrs); |
curs_visibility(false); |
if (interbuffer) { |
for (i = 0; i < conn->screenbuffer.size_x; i++) |
242,21 → 264,21 |
} |
if ((!interbuffer) || (rc != 0)) { |
set_style(&conn->screenbuffer.style); |
set_attrs(&conn->screenbuffer.attrs); |
clrscr(); |
style = &conn->screenbuffer.style; |
attrs = &conn->screenbuffer.attrs; |
for (j = 0; j < conn->screenbuffer.size_y; j++) |
for (i = 0; i < conn->screenbuffer.size_x; i++) { |
field = get_field_at(&conn->screenbuffer, i, j); |
if (!style_same(*style, field->style)) |
set_style(&field->style); |
style = &field->style; |
if (!attrs_same(*attrs, field->attrs)) |
set_attrs(&field->attrs); |
attrs = &field->attrs; |
if ((field->character == ' ') && |
(style_same(field->style, |
conn->screenbuffer.style))) |
(attrs_same(field->attrs, |
conn->screenbuffer.attrs))) |
continue; |
prtchr(field->character, j, i); |
} |
} |
341,7 → 363,7 |
ipc_callid_t callid; |
ipc_call_t call; |
int consnum; |
ipcarg_t arg1, arg2; |
ipcarg_t arg1, arg2, arg3; |
connection_t *conn; |
if ((consnum = find_free_connection()) == -1) { |
409,11 → 431,26 |
break; |
case CONSOLE_SET_STYLE: |
arg1 = IPC_GET_ARG1(call); |
screenbuffer_set_style(&conn->screenbuffer, arg1); |
if (consnum == active_console) |
set_style(arg1); |
break; |
case CONSOLE_SET_COLOR: |
arg1 = IPC_GET_ARG1(call); |
arg2 = IPC_GET_ARG2(call); |
screenbuffer_set_style(&conn->screenbuffer, arg1, |
arg3 = IPC_GET_ARG3(call); |
screenbuffer_set_color(&conn->screenbuffer, arg1, |
arg2, arg3); |
if (consnum == active_console) |
set_color(arg1, arg2, arg3); |
break; |
case CONSOLE_SET_RGB_COLOR: |
arg1 = IPC_GET_ARG1(call); |
arg2 = IPC_GET_ARG2(call); |
screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
arg2); |
if (consnum == active_console) |
set_style_col(arg1, arg2); |
set_rgb_color(arg1, arg2); |
break; |
case CONSOLE_CURSOR_VISIBILITY: |
arg1 = IPC_GET_ARG1(call); |
487,7 → 524,7 |
async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
&fb_info.cols); |
set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
clrscr(); |
/* Init virtual consoles */ |
/trunk/uspace/srv/console/screenbuffer.c |
---|
33,6 → 33,7 |
*/ |
#include <screenbuffer.h> |
#include <console/style.h> |
#include <malloc.h> |
#include <unistd.h> |
49,7 → 50,7 |
field = get_field_at(scr, scr->position_x, scr->position_y); |
field->character = c; |
field->style = scr->style; |
field->attrs = scr->attrs; |
} |
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size. |
67,8 → 68,8 |
scr->size_x = size_x; |
scr->size_y = size_y; |
scr->style.fg_color = DEFAULT_FOREGROUND; |
scr->style.bg_color = DEFAULT_BACKGROUND; |
scr->attrs.t = at_style; |
scr->attrs.a.s.style = STYLE_NORMAL; |
scr->is_cursor_visible = 1; |
screenbuffer_clear(scr); |
85,7 → 86,7 |
for (i = 0; i < (scr->size_x * scr->size_y); i++) { |
scr->buffer[i].character = ' '; |
scr->buffer[i].style = scr->style; |
scr->buffer[i].attrs = scr->attrs; |
} |
scr->top_line = 0; |
103,7 → 104,7 |
for (i = 0; i < scr->size_x; i++) { |
scr->buffer[i + line * scr->size_x].character = ' '; |
scr->buffer[i + line * scr->size_x].style = scr->style; |
scr->buffer[i + line * scr->size_x].attrs = scr->attrs; |
} |
} |
136,12 → 137,37 |
* @param fg_color |
* @param bg_color |
*/ |
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color) |
void screenbuffer_set_style(screenbuffer_t *scr, int style) |
{ |
scr->style.fg_color = fg_color; |
scr->style.bg_color = bg_color; |
scr->attrs.t = at_style; |
scr->attrs.a.s.style = style; |
} |
/** Set new color. |
* @param scr |
* @param fg_color |
* @param bg_color |
*/ |
void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color, unsigned int flags) |
{ |
scr->attrs.t = at_idx; |
scr->attrs.a.i.fg_color = fg_color; |
scr->attrs.a.i.bg_color = bg_color; |
scr->attrs.a.i.flags = flags; |
} |
/** Set new RGB color. |
* @param scr |
* @param fg_color |
* @param bg_color |
*/ |
void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color) |
{ |
scr->attrs.t = at_rgb; |
scr->attrs.a.r.fg_color = fg_color; |
scr->attrs.a.r.bg_color = bg_color; |
} |
/** @} |
*/ |
/trunk/uspace/srv/console/gcons.c |
---|
97,9 → 97,9 |
async_msg_0(fbphone, FB_CLEAR); |
} |
static void set_style(int fgcolor, int bgcolor) |
static void set_rgb_color(int fgcolor, int bgcolor) |
{ |
async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor); |
} |
/** Transparent putchar */ |
346,7 → 346,7 |
return; |
vp_switch(0); |
set_style(MAIN_COLOR, MAIN_COLOR); |
set_rgb_color(MAIN_COLOR, MAIN_COLOR); |
clear(); |
draw_pixmap(_binary_helenos_ppm_start, |
(size_t) &_binary_helenos_ppm_size, xres - 66, 2); |
481,7 → 481,7 |
if (cstatus_vp[i] < 0) |
return; |
vp_switch(cstatus_vp[i]); |
set_style(0x202020, 0xffffff); |
set_rgb_color(0x202020, 0xffffff); |
} |
/* Initialize icons */ |
/trunk/uspace/srv/console/screenbuffer.h |
---|
41,23 → 41,46 |
#define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
typedef struct { |
uint8_t style; |
} attr_style_t; |
typedef struct { |
uint8_t fg_color; |
uint8_t bg_color; |
uint8_t flags; |
} attr_idx_t; |
typedef struct { |
uint32_t bg_color; /**< background color */ |
uint32_t fg_color; /**< foreground color */ |
} style_t; |
} attr_rgb_t; |
typedef struct { |
enum { |
at_style, |
at_idx, |
at_rgb |
} t; |
union { |
attr_style_t s; |
attr_idx_t i; |
attr_rgb_t r; |
} a; |
} attrs_t; |
/** One field on screen. It contain one character and its attributes. */ |
typedef struct { |
char character; /**< Character itself */ |
style_t style; /**< Character`s attributes */ |
attrs_t attrs; /**< Character`s attributes */ |
} keyfield_t; |
/** Structure for buffering state of one virtual console. |
*/ |
typedef struct { |
keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclyc buffer. */ |
keyfield_t *buffer; /**< Screen content - characters and their attributes. Used as a circular buffer. */ |
unsigned int size_x, size_y; /**< Number of columns and rows */ |
unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
style_t style; /**< Current style */ |
attrs_t attrs; /**< Current attributes. */ |
unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
unsigned char is_cursor_visible; /**< Cursor state - default is visible */ |
} screenbuffer_t; |
73,14 → 96,23 |
return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
} |
/** Compares two styles. |
/** Compares two sets of attributes. |
* @param s1 first style |
* @param s2 second style |
* @return nonzero on equality |
*/ |
static inline int style_same(style_t s1, style_t s2) |
static inline int attrs_same(attrs_t a1, attrs_t a2) |
{ |
return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color; |
if (a1.t != a2.t) return 0; |
switch (a1.t) { |
case at_style: return a1.a.s.style == a2.a.s.style; |
case at_idx: return a1.a.i.fg_color == a2.a.i.fg_color && |
a1.a.i.bg_color == a2.a.i.bg_color && |
a1.a.i.flags == a2.a.i.flags; |
case at_rgb: return a1.a.r.fg_color == a2.a.r.fg_color && |
a1.a.r.bg_color == a2.a.r.bg_color; |
} |
} |
91,7 → 123,11 |
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color); |
void screenbuffer_set_style(screenbuffer_t *scr, int style); |
void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, |
unsigned int bg_color, unsigned int attr); |
void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, |
unsigned int bg_color); |
#endif |