vnc-test.c

来自「eCos操作系统源码」· C语言 代码 · 共 446 行 · 第 1/2 页

C
446
字号
    while(1)    {        FD_ZERO(&sock_desc);  /* Zero the socket set descriptor */        if (kbd_handle)        {            FD_SET(kbd_handle, &sock_desc);  /* Add the keyboard handle to the set */        }        if (mouse_handle)        {            FD_SET(mouse_handle, &sock_desc);  /* Add the mouse handle to the set */        }        /* Use select to wait until a keyboard or mouse event occurs*/        select(max_handle+1, &sock_desc, NULL, NULL, NULL);        /* Check for a keyboard event */        if (FD_ISSET(kbd_handle, &sock_desc))        {            kbd_len = 4;            /* Read keyboard data until there is none left */            while (kbd_len == 4)                {                /* Read 4 bytes from keyboard */                kbd_len = read(kbd_handle, kbd_data, 4);                if (kbd_len == 4)        {            if (kbd_data[1])            {                diag_printf("Keyboard data: keysym value 0x%x is pressed\n",                             kbd_data[2]*256 + kbd_data[3]);            }            else            {                diag_printf("Keyboard data: keysym value 0x%x is released\n",                             kbd_data[2]*256 + kbd_data[3]);            }                }            }        }        /* Check for a mouse event */        if (FD_ISSET(mouse_handle, &sock_desc))        {            mouse_len = 8;            /* Read mouse data until there is none left */            while (mouse_len == 8)            {                /* Read 8 bytes from mouse */                mouse_len = read(mouse_handle, mouse_data, 8);                if (mouse_len == 8)                {                    HideCursor();  /* Hide the old cursor */                    cursor_x = mouse_data[2]*256 + mouse_data[3];                    cursor_y = mouse_data[4]*256 + mouse_data[5];                    if (mouse_data[1] && !last_mouse_button)                    {                        /* Ring bell and change colours of bell message text if the */                        /* mouse button is pressed on a yellow pixel                */                        if (VncReadPixel(mouse_data[2]*256 + mouse_data[3],                                         mouse_data[4]*256 + mouse_data[5]) == VNC_YELLOW)                        {                            VncSoundBell();  /* Ring bell on the client */                            if (bell_text_state)                            {                                bell_text_state = 0;                                /* Draw a background for the text */                                VncFillRect(bell_text_x_pos,  /* x1 */                                            bell_text_y_pos,  /* y1 */                                            bell_text_x_pos + bell_text_width,  /* x2 */                                            bell_text_y_pos + bell_text_height, /* y2 */                                            VNC_BLUE);  /* Colour */                                /* Write the text on the background */                                print_area = VncPrintf(0, 1, VNC_YELLOW, bell_text_x_pos, bell_text_y_pos, "%s", bell_message);                            }                            else                            {                                bell_text_state = 1;                                /* Draw a background for the text */                                VncFillRect(bell_text_x_pos,  /* x1 */                                            bell_text_y_pos,  /* y1 */                                            bell_text_x_pos + bell_text_width,  /* x2 */                                            bell_text_y_pos + bell_text_height, /* y2 */                                            VNC_YELLOW);  /* Colour */                                /* Write the text on the background */                                print_area = VncPrintf(0, 1, VNC_BLUE, bell_text_x_pos, bell_text_y_pos, "%s", bell_message);                            }                        }                    }                    last_mouse_button = mouse_data[1];  /* Save mouse button data */                    DrawCursor();  /* Draw the new cursor */                }            }        }    }    return 1;}vnc_colour_t under_cursor[16][16];  /* Buffer to hold display area under cursor */    /* Buffer holding cursor data */#define BLK VNC_BLACK#define TRN VNC_BLUE#define WHT VNC_WHITE#define GRY VNC_LTGRAYvnc_colour_t cursor[16][16] = {{BLK, BLK, BLK, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN},                               {BLK, GRY, GRY, BLK, BLK, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN},                               {BLK, WHT, GRY, GRY, GRY, BLK, BLK, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN},                               {TRN, BLK, WHT, GRY, GRY, GRY, GRY, BLK, BLK, TRN, TRN, TRN, TRN, TRN, TRN, TRN},                               {TRN, BLK, WHT, WHT, GRY, GRY, GRY, GRY, GRY, BLK, BLK, TRN, TRN, TRN, TRN, TRN},                               {TRN, TRN, BLK, WHT, WHT, GRY, GRY, GRY, GRY, GRY, GRY, BLK, BLK, TRN, TRN, TRN},                               {TRN, TRN, BLK, WHT, WHT, WHT, GRY, GRY, GRY, GRY, GRY, GRY, GRY, BLK, TRN, TRN},                               {TRN, TRN, TRN, BLK, WHT, WHT, WHT, GRY, GRY, BLK, BLK, BLK, BLK, BLK, TRN, TRN},                               {TRN, TRN, TRN, BLK, WHT, WHT, WHT, WHT, GRY, GRY, BLK, TRN, TRN, TRN, TRN, TRN},                               {TRN, TRN, TRN, TRN, BLK, WHT, WHT, BLK, WHT, GRY, GRY, BLK, TRN, TRN, TRN, TRN},                               {TRN, TRN, TRN, TRN, BLK, WHT, WHT, BLK, BLK, WHT, GRY, GRY, BLK, TRN, TRN, TRN},                               {TRN, TRN, TRN, TRN, TRN, BLK, WHT, BLK, TRN, BLK, WHT, GRY, GRY, BLK, TRN, TRN},                               {TRN, TRN, TRN, TRN, TRN, BLK, WHT, BLK, TRN, TRN, BLK, WHT, GRY, GRY, BLK, TRN},                               {TRN, TRN, TRN, TRN, TRN, TRN, BLK, TRN, TRN, TRN, TRN, BLK, WHT, GRY, GRY, BLK},                               {TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, BLK, WHT, BLK, TRN},                               {TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, TRN, BLK, TRN, TRN}};#undef BLK#undef TRN#undef WHT#undef GRYvoid DrawCursor(void){    int rect_width, rect_height;    if (cursor_x >= display_info->frame_width)    {        /* Cursor is off the screen */        return;    }    else if ((cursor_x + 16) >= display_info->frame_width)    {        /* Cursor is partially off the screen */        rect_width = display_info->frame_width - cursor_x;    }    else    {        /* Cursor is fully on the screen */        rect_width = 16;    }    if (cursor_y >= display_info->frame_height)    {        /* Cursor is off the screen */        return;    }    else if ((cursor_y + 16) >= display_info->frame_height)    {        /* Cursor is partially off the screen */        rect_height = display_info->frame_height - cursor_y;    }    else    {        /* Cursor is fully on the screen */        rect_height = 16;    }    /* Save the area under the cursor */    VncCopyRect2Buffer(cursor_x, cursor_y, rect_width, rect_height, under_cursor, 16, 16, 0, 0);    /* Draw the new cursor */    VncCopyBuffer2RectMask(cursor, 16, 16, 0, 0, cursor_x, cursor_y, rect_width, rect_height, VNC_BLUE);}void HideCursor(void){    int rect_width, rect_height;    if (cursor_x >= display_info->frame_width)    {        /* Cursor is off the screen */        return;    }    else if ((cursor_x + 16) >= display_info->frame_width)    {        /* Cursor is partially off the screen */        rect_width = display_info->frame_width - cursor_x;    }    else    {        /* Cursor is fully on the screen */        rect_width = 16;    }    if (cursor_y >= display_info->frame_height)    {        /* Cursor is off the screen */        return;    }    else if ((cursor_y + 16) >= display_info->frame_height)    {        /* Cursor is partially off the screen */        rect_height = display_info->frame_height - cursor_y;    }    else    {        /* Cursor is fully on the screen */        rect_height = 16;    }    /* Restore the saved area under the cursor */    VncCopyBuffer2Rect(under_cursor, 16, 16, 0, 0, cursor_x, cursor_y, rect_width, rect_height);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?