/* * QEMU VNC display driver * * Copyright (c) 2003 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "vl.h" #include #ifndef _WIN32 #include #endif rfbScreenInfoPtr rfbScreen; int last_x_position; int last_y_position; static void vnc_update(DisplayState *ds, int x, int y, int w, int h) { // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h); rfbMarkRectAsModified(rfbScreen, x, y, x+w, y+h); } static void vnc_resize(DisplayState *ds, int w, int h) { printf("resize! w=%i h=%i\n", w, h); ds->data = rfbScreen->frameBuffer + ( 1024 - w ) + ( 768 - h ) * 1024; ds->linesize = 1024*2; ds->depth = 16; rfbFillRect(rfbScreen, 0, 0, 1023, 767, 0); } static void vnc_refresh(DisplayState *ds) { vga_update_display(); // rfbProcessEvents(rfbScreen,1000000); } static void vnc_pointer(int buttonMask, int x, int y, rfbClientPtr cl) { int dx, dy, buttons; dx = x - last_x_position; last_x_position = x; dy = y - last_y_position; last_y_position = y; buttons = 0; if ( buttonMask & 1 ) buttons |= MOUSE_EVENT_LBUTTON; if ( buttonMask & 2 ) buttons |= MOUSE_EVENT_MBUTTON; if ( buttonMask & 4 ) buttons |= MOUSE_EVENT_RBUTTON; kbd_mouse_event(dx, dy, 0, buttons); } static void vnc_keyboard(rfbBool down, rfbKeySym key, rfbClientPtr cl) { if (key == 'A') if (down) kbd_put_keycode(0x38); else kbd_put_keycode(0x38 | 0x80); } void vnc_display_init(DisplayState *ds) { int flags; last_x_position = 0; last_y_position = 0; rfbScreen = rfbGetScreen(0, NULL, 1024, 768, 5, 3, 2); rfbScreen->frameBuffer = (char*)malloc(1074*768*2); rfbScreen->rfbServerFormat.bitsPerPixel = 16; rfbScreen->rfbServerFormat.depth = 16; rfbScreen->rfbServerFormat.bigEndian = 0; rfbScreen->rfbServerFormat.trueColour = 1; rfbScreen->rfbServerFormat.redMax = (1 << 5) - 1; rfbScreen->rfbServerFormat.greenMax = (1 << 6) - 1; rfbScreen->rfbServerFormat.blueMax = (1 << 5) - 1; rfbScreen->rfbServerFormat.redShift = 11; rfbScreen->rfbServerFormat.greenShift = 5; rfbScreen->rfbServerFormat.blueShift = 0; rfbScreen->ptrAddEvent = vnc_pointer; rfbScreen->kbdAddEvent = vnc_keyboard; rfbInitServer(rfbScreen); rfbRunEventLoop(rfbScreen, 1000000, TRUE); vnc_resize(ds, 640, 480); ds->dpy_update = vnc_update; ds->dpy_resize = vnc_resize; ds->dpy_refresh = vnc_refresh; }