Changeset 424cd43 in mainline for uspace/srv/console/gcons.c


Ignore:
Timestamp:
2009-06-03T18:39:12Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8dc12ac
Parents:
b0a91acb
Message:

console server rewrite: use VFS_READ/VFS_WRITE for generic I/O, register separate virtual consoles using device mapper

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/console/gcons.c

    rb0a91acb r424cd43  
    4040#include <string.h>
    4141#include <align.h>
     42#include <bool.h>
    4243
    4344#include "console.h"
     
    5556#define MAIN_COLOR  0xffffff
    5657
    57 static int use_gcons = 0;
    58 static ipcarg_t xres,yres;
     58static bool use_gcons = false;
     59static ipcarg_t xres;
     60static ipcarg_t yres;
    5961
    6062enum butstate {
     
    7880static int animation = -1;
    7981
    80 static int active_console = 0;
     82static size_t active_console = 0;
     83
     84size_t mouse_x;
     85size_t mouse_y;
     86
     87bool btn_pressed;
     88size_t btn_x;
     89size_t btn_y;
    8190
    8291static void vp_switch(int vp)
     
    8695
    8796/** Create view port */
    88 static int vp_create(unsigned int x, unsigned int y, unsigned int width,
    89     unsigned int height)
     97static int vp_create(size_t x, size_t y, size_t width, size_t height)
    9098{
    9199        return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
     
    98106}
    99107
    100 static void set_rgb_color(int fgcolor, int bgcolor)
     108static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
    101109{
    102110        async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
     
    104112
    105113/** Transparent putchar */
    106 static void tran_putch(char c, int row, int col)
    107 {
    108         async_msg_3(fbphone, FB_PUTCHAR, c, row, col);
     114static void tran_putch(wchar_t ch, size_t col, size_t row)
     115{
     116        async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
    109117}
    110118
    111119/** Redraw the button showing state of a given console */
    112 static void redraw_state(int consnum)
    113 {
    114         char data[5];
    115         int i;
    116         enum butstate state = console_state[consnum];
    117        
    118         vp_switch(cstatus_vp[consnum]);
     120static void redraw_state(size_t index)
     121{
     122        vp_switch(cstatus_vp[index]);
     123       
     124        enum butstate state = console_state[index];
     125       
    119126        if (ic_pixmaps[state] != -1)
    120                 async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
     127                async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[index],
    121128                    ic_pixmaps[state]);
    122129       
    123         if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
    124             state != CONS_DISCONNECTED_SEL) {
    125                 snprintf(data, 5, "%d", consnum + 1);
    126                 for (i = 0; data[i]; i++)
    127                         tran_putch(data[i], 1, 2 + i);
     130        if ((state != CONS_DISCONNECTED) && (state != CONS_KERNEL)
     131            && (state != CONS_DISCONNECTED_SEL)) {
     132               
     133                char data[5];
     134                snprintf(data, 5, "%u", index + 1);
     135               
     136                size_t i;
     137                for (i = 0; data[i] != 0; i++)
     138                        tran_putch(data[i], 2 + i, 1);
    128139        }
    129140}
    130141
    131142/** Notification run on changing console (except kernel console) */
    132 void gcons_change_console(int consnum)
    133 {
    134         int i;
    135        
     143void gcons_change_console(size_t index)
     144{
    136145        if (!use_gcons)
    137146                return;
    138147       
    139148        if (active_console == KERNEL_CONSOLE) {
     149                size_t i;
     150               
    140151                for (i = 0; i < CONSOLE_COUNT; i++)
    141152                        redraw_state(i);
     153               
    142154                if (animation != -1)
    143155                        async_msg_1(fbphone, FB_ANIM_START, animation);
     
    147159                else
    148160                        console_state[active_console] = CONS_IDLE;
     161               
    149162                redraw_state(active_console);
    150163        }
    151         active_console = consnum;
    152        
    153         if (console_state[consnum] == CONS_DISCONNECTED) {
    154                 console_state[consnum] = CONS_DISCONNECTED_SEL;
    155                 redraw_state(consnum);
    156         } else
    157                 console_state[consnum] = CONS_SELECTED;
    158         redraw_state(consnum);
    159        
     164       
     165        active_console = index;
     166       
     167        if ((console_state[index] == CONS_DISCONNECTED)
     168            || (console_state[index] == CONS_DISCONNECTED_SEL))
     169                console_state[index] = CONS_DISCONNECTED_SEL;
     170        else
     171                console_state[index] = CONS_SELECTED;
     172       
     173        redraw_state(index);
    160174        vp_switch(console_vp);
    161175}
    162176
    163177/** Notification function that gets called on new output to virtual console */
    164 void gcons_notify_char(int consnum)
     178void gcons_notify_char(size_t index)
    165179{
    166180        if (!use_gcons)
    167181                return;
    168182       
    169         if ((consnum == active_console) ||
    170             (console_state[consnum] == CONS_HAS_DATA))
    171                 return;
    172        
    173         console_state[consnum] = CONS_HAS_DATA;
     183        if ((index == active_console)
     184            || (console_state[index] == CONS_HAS_DATA))
     185                return;
     186       
     187        console_state[index] = CONS_HAS_DATA;
    174188       
    175189        if (active_console == KERNEL_CONSOLE)
    176190                return;
    177191       
    178         redraw_state(consnum);
    179        
     192        redraw_state(index);
    180193        vp_switch(console_vp);
    181194}
    182195
    183196/** Notification function called on service disconnect from console */
    184 void gcons_notify_disconnect(int consnum)
     197void gcons_notify_disconnect(size_t index)
    185198{
    186199        if (!use_gcons)
    187200                return;
    188201       
    189         if (active_console == consnum)
    190                 console_state[consnum] = CONS_DISCONNECTED_SEL;
     202        if (index == active_console)
     203                console_state[index] = CONS_DISCONNECTED_SEL;
    191204        else
    192                 console_state[consnum] = CONS_DISCONNECTED;
     205                console_state[index] = CONS_DISCONNECTED;
    193206       
    194207        if (active_console == KERNEL_CONSOLE)
    195208                return;
    196209       
    197         redraw_state(consnum);
     210        redraw_state(index);
    198211        vp_switch(console_vp);
    199212}
    200213
    201214/** Notification function called on console connect */
    202 void gcons_notify_connect(int consnum)
     215void gcons_notify_connect(size_t index)
    203216{
    204217        if (!use_gcons)
    205218                return;
    206219       
    207         if (active_console == consnum)
    208                 console_state[consnum] = CONS_SELECTED;
     220        if (index == active_console)
     221                console_state[index] = CONS_SELECTED;
    209222        else
    210                 console_state[consnum] = CONS_IDLE;
     223                console_state[index] = CONS_IDLE;
    211224       
    212225        if (active_console == KERNEL_CONSOLE)
    213226                return;
    214227       
    215         redraw_state(consnum);
     228        redraw_state(index);
    216229        vp_switch(console_vp);
    217230}
     
    227240}
    228241
    229 /** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */
    230 static inline int limit(int a, int left, int right)
     242/** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */
     243static inline int limit(size_t a, size_t left, size_t right)
    231244{
    232245        if (a < left)
    233246                a = left;
     247       
    234248        if (a >= right)
    235249                a = right - 1;
     250       
    236251        return a;
    237252}
    238 
    239 int mouse_x, mouse_y;
    240 int btn_pressed, btn_x, btn_y;
    241253
    242254/** Handle mouse move
     
    245257 * @param dy Delta Y of mouse move
    246258 */
    247 void gcons_mouse_move(int dx, int dy)
     259void gcons_mouse_move(ssize_t dx, ssize_t dy)
    248260{
    249261        mouse_x = limit(mouse_x + dx, 0, xres);
     
    273285/** Handle mouse click
    274286 *
    275  * @param state New state (1-pressed, 0-depressed)
    276  */
    277 int gcons_mouse_btn(int state)
     287 * @param state New state (true - pressed, false - depressed)
     288 */
     289int gcons_mouse_btn(bool state)
    278290{
    279291        int conbut;
     
    282294                conbut = gcons_find_conbut(mouse_x, mouse_y);
    283295                if (conbut != -1) {
    284                         btn_pressed = 1;
     296                        btn_pressed = true;
    285297                        btn_x = mouse_x;
    286298                        btn_y = mouse_y;
     
    292304                return -1;
    293305       
    294         btn_pressed = 0;
     306        btn_pressed = false;
    295307       
    296308        conbut = gcons_find_conbut(mouse_x, mouse_y);
     
    374386 * @param data PPM data
    375387 * @param size PPM data size
     388 *
    376389 * @return Pixmap identification
    377  */
    378 static int make_pixmap(char *data, int size)
     390 *
     391 */
     392static int make_pixmap(char *data, size_t size)
    379393{
    380394        char *shm;
     
    465479void gcons_init(int phone)
    466480{
    467         int rc;
    468         int i;
    469         int status_start = STATUS_START;
    470        
    471481        fbphone = phone;
    472482       
    473         rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
     483        int rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
    474484        if (rc)
    475485                return;
     
    484494            ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
    485495            ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
     496       
    486497        if (console_vp < 0)
    487498                return;
    488499       
    489500        /* Create status buttons */
    490         status_start += (xres - 800) / 2;
     501        size_t status_start = STATUS_START + (xres - 800) / 2;
     502        size_t i;
    491503        for (i = 0; i < CONSOLE_COUNT; i++) {
    492504                cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
    493505                    i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
    494506                    STATUS_WIDTH, STATUS_HEIGHT);
     507               
    495508                if (cstatus_vp[i] < 0)
    496509                        return;
     510               
    497511                vp_switch(cstatus_vp[i]);
    498512                set_rgb_color(0x202020, 0xffffff);
     
    502516        ic_pixmaps[CONS_SELECTED] =
    503517            make_pixmap(_binary_gfx_cons_selected_ppm_start,
    504             (int) &_binary_gfx_cons_selected_ppm_size);
     518            (size_t) &_binary_gfx_cons_selected_ppm_size);
    505519        ic_pixmaps[CONS_IDLE] =
    506520            make_pixmap(_binary_gfx_cons_idle_ppm_start,
    507             (int) &_binary_gfx_cons_idle_ppm_size);
     521            (size_t) &_binary_gfx_cons_idle_ppm_size);
    508522        ic_pixmaps[CONS_HAS_DATA] =
    509523            make_pixmap(_binary_gfx_cons_has_data_ppm_start,
    510             (int) &_binary_gfx_cons_has_data_ppm_size);
     524            (size_t) &_binary_gfx_cons_has_data_ppm_size);
    511525        ic_pixmaps[CONS_DISCONNECTED] =
    512526            make_pixmap(_binary_gfx_cons_idle_ppm_start,
    513             (int) &_binary_gfx_cons_idle_ppm_size);
     527            (size_t) &_binary_gfx_cons_idle_ppm_size);
    514528        ic_pixmaps[CONS_KERNEL] =
    515529            make_pixmap(_binary_gfx_cons_kernel_ppm_start,
    516             (int) &_binary_gfx_cons_kernel_ppm_size);
     530            (size_t) &_binary_gfx_cons_kernel_ppm_size);
    517531        ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
    518532       
    519533        make_anim();
    520534       
    521         use_gcons = 1;
     535        use_gcons = true;
    522536        console_state[0] = CONS_DISCONNECTED_SEL;
    523537        console_state[KERNEL_CONSOLE] = CONS_KERNEL;
     538       
    524539        gcons_redraw_console();
    525540}
Note: See TracChangeset for help on using the changeset viewer.