[Q] Xorg VNC driver?

Pat Kane pekane52 at gmail.com
Tue Sep 29 17:19:56 PDT 2009


On Tue, Sep 29, 2009 at 6:23 PM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
 > To get the wheel support, just inc NBUTTONS to 7 and set it up with the

Thanks for the info, attached is a new version of hw/vnc/init.c that has
mouse wheel support (copied from hw/xquartz/darwin.c).
Oh, and this version actually compiles with the current git tree.

BTW, my built Xvnc does not yet work correctly, I am currently
trying to debug this problem (the "=+=" msg is my debug printf) :

Starting program: /pek/Git/Xorg_test/xserver/hw/vnc/Xvnc :2
[Thread debugging using libthread_db enabled]
[New Thread 0xb7b446c0 (LWP 16365)]
29/09/2009 19:16:08 Xvnc version X.org/xf4vnc custom version
29/09/2009 19:16:08 Copyright (C) 2001-2004 Alan Hourihane.
29/09/2009 19:16:08 Copyright (C) 2000-2004 Constantin Kaplinsky
29/09/2009 19:16:08 Copyright (C) 1999 AT&T Laboratories Cambridge
29/09/2009 19:16:08 All Rights Reserved.
29/09/2009 19:16:08 See http://www.tightvnc.com/ for information on TightVNC
29/09/2009 19:16:08 See http://xf4vnc.sf.net for xf4vnc-specific information
29/09/2009 19:16:08 Desktop name 'x11' (vost:2)
29/09/2009 19:16:08 Protocol versions supported: 3.7, 3.3
29/09/2009 19:16:09 Listening for VNC connections on TCP port 5902
=+= ActivateDevice: dev: 0x98b9df0  se: 1
	deviceProc: 0x8152980
	 IM:1 sO: 0x1  DCI: 0x80a6c10

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7b446c0 (LWP 16365)]
0x00000000 in ?? ()
(gdb) where
#0  0x00000000 in ?? ()
#1  0x0815359b in ActivateDevice (dev=0x98b9df0, sendevent=<value
optimized out>)
    at devices.c:501
#2  0x08154538 in InitCoreDevices () at devices.c:634
#3  0x0813982e in main (argc=2, argv=0xbfa429e4, envp=0xb7cc3170) at main.c:256


Pat
----


On Tue, Sep 29, 2009 at 6:23 PM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> On Tue, Sep 29, 2009 at 05:59:34PM +0200, Matthias Hopf wrote:
>> On Sep 23, 09 14:33:24 -0500, Pat Kane wrote:
>> > On Wed, Sep 23, 2009 at 8:46 AM, Matthias Hopf <mhopf at suse.de> wrote:
>> > > Sorry, porting was only to 1.6.3.901 (just noted that). However, they
>> > > will probably a good start.
>> > They provide a very good staring point and  have saved me a lot of
>> > work, thank you.
>> >
>> > I think the the mouse init code, init.c, needs to look somthing like
>> > the attached snippet
>> >  of code (sorry I can not make patches yet).  Does that look right?
>>
>> It doesn't look wrong (though I'm unsure how z axis i.e. mouse wheel is
>> handled, and in the code I can only see handling of 3 buttons and 2
>> axes), but I'm not exactly fluent in that area.
>
> if the driver posts wheels as buttons 4/5 the server will ignore them if it
> isn't set up. So the previous snippet is correct though without mouse
> wheel support.
>
> To get the wheel support, just inc NBUTTONS to 7 and set it up with the
> labels BTN_LABEL_PROP_BTN_WHEEL_UP, BTN_LABEL_PROP_BTN_WHEEL_DOWN,
> BTN_LABEL_PROP_BTN_HWHEEL_LEFT, BTN_LABEL_PROP_BTN_HWHEEL_RIGHT.
>
> Note that button labelling is still optional, a label of 0 is permitted.
> Labels are a hint to clients so they know what a given button does. For any
> button from 1-7 labels are arguably superfluous since we can't change much
> anyway - too many clients rely on the current behaviour.
>
> Cheers,
>  Peter
> _______________________________________________
> xorg mailing list
> xorg at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xorg
>
-------------- next part --------------
/*
 * init.c
 *
 * Modified for XFree86 4.x by Alan Hourihane <alanh at fairlite.demon.co.uk>
 * Modified for Xorg 1.7    by Pat Kane <pekane52 at gmail.com>
 */

/*
 *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
 *
 *  This is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This software is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this software; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 *  USA.
 */

/*

Copyright (c) 1993  X Consortium

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 X CONSORTIUM 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.

Except as contained in this notice, the name of the X Consortium shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the X Consortium.

*/

/* Use ``#define CORBA'' to enable CORBA control interface */

/* XXX this definition should probably go elsewhere */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

#ifndef XVNCRELEASE
#define XVNCRELEASE "X.org/xf4vnc custom version"
#endif

#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "X11/X.h"
#define NEED_EVENTS
#include "X11/Xproto.h"
#include "X11/Xos.h"
#include "scrnintstr.h"
#include "servermd.h"
#include "fb.h"
#include "mibstore.h"
#include "colormapst.h"
#include "gcstruct.h"
#include "input.h"
#include "mipointer.h"
#include "dixstruct.h"
#include <X11/Xatom.h>
#include <errno.h>
#include <sys/param.h>
#include "dix.h"
#include "micmap.h"
#include "rfb.h"

#include <xserver-properties.h>
#include <inputstr.h>

#ifdef CORBA
#include <vncserverctrl.h>
#endif

#define RFB_DEFAULT_WIDTH  640
#define RFB_DEFAULT_HEIGHT 480
#define RFB_DEFAULT_DEPTH  8
#define RFB_DEFAULT_WHITEPIXEL 0
#define RFB_DEFAULT_BLACKPIXEL 1

static unsigned long VNCGeneration = 0;
rfbScreenInfo rfbScreen;
extern char dispatchExceptionAtReset;

extern void VncExtensionInit(void);

static Bool initOutputCalled = FALSE;
static Bool noCursor = FALSE;
char *desktopName = "x11";

char rfbThisHost[256];

Atom VNC_LAST_CLIENT_ID;
Atom VNC_CONNECT;

#if 0
static HWEventQueueType alwaysCheckForInput[2] = { 0, 1 };
static HWEventQueueType *mieqCheckForInput[2];
#endif

static char primaryOrder[4] = "";
static int redBits, greenBits, blueBits;

static Bool rfbScreenInit(int index, ScreenPtr pScreen, int argc,
			  char **argv);
static int rfbKeybdProc(DeviceIntPtr pDevice, int onoff);
static int rfbMouseProc(DeviceIntPtr pDevice, int onoff);
static Bool CheckDisplayNumber(int n);

static Bool rfbAlwaysTrue(void);
static unsigned char *rfbAllocateFramebufferMemory(rfbScreenInfoPtr prfb);
static Bool rfbCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y);
static void rfbCrossScreen(ScreenPtr pScreen, Bool entering);

DeviceIntPtr vncPointerDevice;

static void
PointerWarpCursor(ScreenPtr pScreen, int x, int y)
{
#if 0
   DeviceIntPtr pDev = NULL;
   miPointerSetPosition(pDev, &x, &y, GetTimeInMillis());
#endif
}


static miPointerScreenFuncRec rfbPointerCursorFuncs = {
    rfbCursorOffScreen,
    rfbCrossScreen,
    PointerWarpCursor,
    NULL/*dmxeqEnqueue*/,
    NULL/*dmxeqSwitchScreen*/
};


int inetdSock = -1;
static char inetdDisplayNumStr[10];


void
DDXRingBell(int volume, int pitch, int duration)
{
   /* NO-OP - stub to solve link problem */
}


/*
 * ddxProcessArgument is our first entry point and will be called at the
 * very start for each argument.  It is not called again on server reset.
 */

int
ddxProcessArgument (int argc, char *argv[], int i)
{
    VNCSCREENPTR(screenInfo.screens[i]);
    static Bool firstTime = TRUE;

    if (firstTime)
    {
	pVNC->width  = RFB_DEFAULT_WIDTH;
	pVNC->height = RFB_DEFAULT_HEIGHT;
	pVNC->depth  = RFB_DEFAULT_DEPTH;
	pVNC->blackPixel = RFB_DEFAULT_BLACKPIXEL;
	pVNC->whitePixel = RFB_DEFAULT_WHITEPIXEL;
	pVNC->pfbMemory = NULL;
    	pVNC->httpPort = 0;
    	pVNC->httpDir = NULL;
        pVNC->rfbAuthPasswdFile = NULL;
        pVNC->udpPort = 0;
    	pVNC->rfbPort = 0;
    	pVNC->rdpPort = 3389;
	noCursor = FALSE;
  	pVNC->loginAuthEnabled = FALSE;
	pVNC->rfbAlwaysShared = FALSE;
	pVNC->rfbNeverShared = FALSE;
	pVNC->rfbDontDisconnect = FALSE;
	pVNC->rfbViewOnly = FALSE;

	gethostname(rfbThisHost, 255);
	pVNC->interface.s_addr = htonl (INADDR_ANY);
	firstTime = FALSE;
    }

    if (strcmp (argv[i], "-geometry") == 0)	/* -geometry WxH */
    {
	if (i + 1 >= argc) UseMsg();
	if (sscanf(argv[i+1],"%dx%d",
		   &pVNC->width,&pVNC->height) != 2) {
	    ErrorF("Invalid geometry %s\n", argv[i+1]);
	    UseMsg();
	}
#ifdef CORBA
	screenWidth= pVNC->width;
	screenHeight= pVNC->height;
#endif
	return 2;
    }

    if (strcmp (argv[i], "-depth") == 0)	/* -depth D */
    {
	if (i + 1 >= argc) UseMsg();
	pVNC->depth = atoi(argv[i+1]);
#ifdef CORBA
	screenDepth= pVNC->depth;
#endif
	return 2;
    }

    if (strcmp (argv[i], "-pixelformat") == 0) {
	if (i + 1 >= argc) UseMsg();
	if (sscanf(argv[i+1], "%3s", primaryOrder) < 1) {
	    ErrorF("Invalid pixel format %s\n", argv[i+1]);
	    UseMsg();
	}

	return 2;
    }

    if (strcmp (argv[i], "-blackpixel") == 0) {	/* -blackpixel n */
	if (i + 1 >= argc) UseMsg();
	pVNC->blackPixel = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp (argv[i], "-whitepixel") == 0) {	/* -whitepixel n */
	if (i + 1 >= argc) UseMsg();
	pVNC->whitePixel = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp(argv[i], "-udpinputport") == 0) { /* -udpinputport port */
	if (i + 1 >= argc) UseMsg();
	pVNC->udpPort = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp(argv[i], "-rfbport") == 0) {	/* -rfbport port */
	if (i + 1 >= argc) UseMsg();
	pVNC->rfbPort = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp(argv[i], "-rfbwait") == 0) {	/* -rfbwait ms */
	if (i + 1 >= argc) UseMsg();
	rfbMaxClientWait = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp(argv[i], "-nocursor") == 0) {
	noCursor = TRUE;
	return 1;
    }

    if (strcmp(argv[i], "-rfbauth") == 0) {	/* -rfbauth passwd-file */
	if (i + 1 >= argc) UseMsg();
	pVNC->rfbAuthPasswdFile = argv[i+1];
	return 2;
    }

    if (strcmp(argv[i], "-loginauth") == 0) {
	if (geteuid() == 0) {
	    /* Only when run as root! */
	    pVNC->loginAuthEnabled = TRUE;
	}
	return 1;
    }

    if (strcmp(argv[i], "-httpd") == 0) {
	if (i + 1 >= argc) UseMsg();
	pVNC->httpDir = argv[i+1];
	return 2;
    }

    if (strcmp(argv[i], "-httpport") == 0) {
	if (i + 1 >= argc) UseMsg();
	pVNC->httpPort = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp(argv[i], "-deferupdate") == 0) {	/* -deferupdate ms */
	if (i + 1 >= argc) UseMsg();
	rfbDeferUpdateTime = atoi(argv[i+1]);
	return 2;
    }

    if (strcmp(argv[i], "-economictranslate") == 0) {
	rfbEconomicTranslate = TRUE;
	return 1;
    }

    if (strcmp(argv[i], "-lazytight") == 0) {
	rfbTightDisableGradient = TRUE;
	return 1;
    }

    if (strcmp(argv[i], "-desktop") == 0) {	/* -desktop desktop-name */
	if (i + 1 >= argc) UseMsg();
	desktopName = argv[i+1];
	return 2;
    }

#if 0 /* not deemed useful on standalone server - leave for completeness */
    if (strcmp(argv[i], "-useraccept") == 0) {
	pVNC->rfbUserAccept = TRUE;
	return 1;
    }
#endif

    if (strcmp(argv[i], "-alwaysshared") == 0) {
	pVNC->rfbAlwaysShared = TRUE;
	return 1;
    }

    if (strcmp(argv[i], "-nevershared") == 0) {
	pVNC->rfbNeverShared = TRUE;
	return 1;
    }

    if (strcmp(argv[i], "-dontdisconnect") == 0) {
	pVNC->rfbDontDisconnect = TRUE;
	return 1;
    }

    /* Run server in view-only mode - Ehud Karni SW */
    if (strcmp(argv[i], "-viewonly") == 0) {
	pVNC->rfbViewOnly = TRUE;
	return 1;
    }

    if (strcmp(argv[i], "-localhost") == 0) {
	pVNC->interface.s_addr = htonl (INADDR_LOOPBACK);
	return 1;
    }

    if (strcmp(argv[i], "-interface") == 0) {	/* -interface ipaddr */
	struct in_addr got;
	unsigned long octet;
	char *p, *end;
	int q;
	got.s_addr = 0;
	if (i + 1 >= argc) {
	    UseMsg();
	    return 2;
	}
	if (pVNC->interface.s_addr != htonl (INADDR_ANY)) {
	    /* Already set (-localhost?). */
	    return 2;
	}
	p = argv[i + 1];
	for (q = 0; q < 4; q++) {
	    octet = strtoul (p, &end, 10);
	    if (p == end || octet > 255) {
		UseMsg ();
		return 2;
	    }
	    if ((q < 3 && *end != '.') ||
	        (q == 3 && *end != '\0')) {
		UseMsg ();
		return 2;
	    }
	    got.s_addr = (got.s_addr << 8) | octet;
	    p = end + 1;
	}
	pVNC->interface.s_addr = htonl (got.s_addr);
	return 2;
    }

    if (strcmp(argv[i], "-inetd") == 0) {	/* -inetd */ 
	int n;
	for (n = 1; n < 100; n++) {
	    if (CheckDisplayNumber(n))
		break;
	}

	if (n >= 100)
	    FatalError("-inetd: couldn't find free display number");

	sprintf(inetdDisplayNumStr, "%d", n);
	display = inetdDisplayNumStr;

	/* fds 0, 1 and 2 (stdin, out and err) are all the same socket to the
           RFB client.  OsInit() closes stdout and stdin, and we don't want
           stderr to go to the RFB client, so make the client socket 3 and
           close stderr.  OsInit() will redirect stderr logging to an
           appropriate log file or /dev/null if that doesn't work. */

	dup2(0,3);
	inetdSock = 3;
	close(2);

	return 1;
    }

    if (strcmp(argv[i], "-version") == 0) {
	ErrorF("Xvnc version %s\n", XVNCRELEASE);
	exit(0);
    }

    if (inetdSock != -1 && argv[i][0] == ':') {
	FatalError("can't specify both -inetd and :displaynumber");
    }

    return 0;
}


/*
 * InitOutput is called every time the server resets.  It should call
 * AddScreen for each screen (FIXME - but we only ever have one), 
 * and in turn this will call rfbScreenInit.
 */

/* Common pixmap formats */

static PixmapFormatRec formats[MAXFORMATS] = {
	{ 1,	1,	BITMAP_SCANLINE_PAD },
	{ 4,	8,	BITMAP_SCANLINE_PAD },
	{ 8,	8,	BITMAP_SCANLINE_PAD },
	{ 15,	16,	BITMAP_SCANLINE_PAD },
	{ 16,	16,	BITMAP_SCANLINE_PAD },
	{ 24,	32,	BITMAP_SCANLINE_PAD },
#ifdef RENDER
	{ 32,	32,	BITMAP_SCANLINE_PAD },
#endif
};
#ifdef RENDER
static int numFormats = 7;
#else
static int numFormats = 6;
#endif

void
InitOutput(ScreenInfo * screenInfo, int argc, char **argv)
{
    int i;
    initOutputCalled = TRUE;

    rfbLog("Xvnc version %s\n", XVNCRELEASE);
    rfbLog("Copyright (C) 2001-2004 Alan Hourihane.\n");
    rfbLog("Copyright (C) 2000-2004 Constantin Kaplinsky\n");
    rfbLog("Copyright (C) 1999 AT&T Laboratories Cambridge\n");
    rfbLog("All Rights Reserved.\n");
    rfbLog("See http://www.tightvnc.com/ for information on TightVNC\n");
    rfbLog("See http://xf4vnc.sf.net for xf4vnc-specific information\n");
    rfbLog("Desktop name '%s' (%s:%s)\n",desktopName,rfbThisHost,display);
    rfbLog("Protocol versions supported: %d.%d, %d.%d\n",
	   rfbProtocolMajorVersion, rfbProtocolMinorVersion,
	   rfbProtocolMajorVersion, rfbProtocolFallbackMinorVersion);

    VNC_LAST_CLIENT_ID = MakeAtom("VNC_LAST_CLIENT_ID",
				  strlen("VNC_LAST_CLIENT_ID"), TRUE);
    VNC_CONNECT = MakeAtom("VNC_CONNECT", strlen("VNC_CONNECT"), TRUE);

    /* initialize pixmap formats */

    screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
    screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
    screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
    screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
    screenInfo->numPixmapFormats = numFormats;
    for (i = 0; i < numFormats; i++)
    	screenInfo->formats[i] = formats[i];

    /* initialize screen */

    if (AddScreen(rfbScreenInit, argc, argv) == -1) {
	FatalError("Couldn't add screen");
    }

#ifdef CORBA
    initialiseCORBA(argc, argv, desktopName);
#endif
}

static void
rfbWakeupHandler (
    int 	i,	
    pointer     blockData,
    unsigned long err,
    pointer     pReadmask
){
    ScreenPtr      pScreen = screenInfo.screens[i];
    VNCSCREENPTR(pScreen);
    int e = (int)err;

    if (e < 0)
	goto SKIPME;
	
    rfbRootPropertyChange(pScreen);

#if XFREE86VNC
    if (pScrn->vtSema) {
    	rfbCheckFds(pScreen);
    	httpCheckFds(pScreen);
#if 0
	rdpCheckFds(pScreen);
#endif
#ifdef CORBA
    	corbaCheckFds();
#endif
    } else {
    	rfbCheckFds(pScreen);
#if 0
	rdpCheckFds(pScreen);
#endif
    }
#else
    rfbCheckFds(pScreen);
    httpCheckFds(pScreen);
#if 0
    rdpCheckFds(pScreen);
#endif
#ifdef CORBA
    corbaCheckFds();
#endif
#endif

SKIPME:

    pScreen->WakeupHandler = pVNC->WakeupHandler;
    (*pScreen->WakeupHandler) (i, blockData, err, pReadmask);
    pScreen->WakeupHandler = rfbWakeupHandler;
}

static Bool
rfbScreenInit(int index, ScreenPtr pScreen, int argc, char ** argv)
{
    rfbScreenInfoPtr prfb = &rfbScreen;
    int dpix = 75, dpiy = 75;
    int ret;
    unsigned char *pbits;
    VisualPtr vis;
#ifdef RENDER
    PictureScreenPtr	ps;
#endif

    if (VNCGeneration != serverGeneration) {
	VncExtensionInit();
	VNCGeneration = serverGeneration;
    }

    if (monitorResolution != 0) {
	dpix = monitorResolution;
	dpiy = monitorResolution;
    }

    prfb->rfbAuthTries = 0;
    prfb->rfbAuthTooManyTries = FALSE;
    prfb->rfbUserAccept = FALSE;
    prfb->udpSockConnected = FALSE;
    prfb->timer = NULL;
    prfb->httpListenSock = -1;
    prfb->httpSock = -1;
    prfb->rfbListenSock = -1;
    prfb->rdpListenSock = -1;
    prfb->paddedWidthInBytes = PixmapBytePad(prfb->width, prfb->depth);
    prfb->bitsPerPixel = rfbBitsPerPixel(prfb->depth);
    pbits = rfbAllocateFramebufferMemory(prfb);
    if (!pbits) return FALSE;

    miClearVisualTypes();

    if (defaultColorVisualClass == -1)
    	defaultColorVisualClass = TrueColor;

    if (!miSetVisualTypes(prfb->depth, miGetDefaultVisualMask(prfb->depth), 8,
						defaultColorVisualClass) )
	return FALSE;

    miSetPixmapDepths();

    switch (prfb->bitsPerPixel)
    {
    case 8:
	ret = fbScreenInit(pScreen, pbits, prfb->width, prfb->height,
			    dpix, dpiy, prfb->paddedWidthInBytes, 8);
	break;
    case 16:
	ret = fbScreenInit(pScreen, pbits, prfb->width, prfb->height,
			      dpix, dpiy, prfb->paddedWidthInBytes / 2, 16);
	if (prfb->depth == 15) {
  	    blueBits = 5; greenBits = 5; redBits = 5;
	} else {
	    blueBits = 5; greenBits = 6; redBits = 5;
	}
	break;
    case 32:
	ret = fbScreenInit(pScreen, pbits, prfb->width, prfb->height,
			      dpix, dpiy, prfb->paddedWidthInBytes / 4, 32);
	blueBits = 8; greenBits = 8; redBits = 8;
	break;
    default:
	return FALSE;
    }

    if (!ret) return FALSE;

    miInitializeBackingStore(pScreen);

    if (prfb->bitsPerPixel > 8) {
    	if (strcasecmp(primaryOrder, "bgr") == 0) {
	    rfbLog("BGR format %d %d %d\n", blueBits, greenBits, redBits);
            vis = pScreen->visuals + pScreen->numVisuals;
            while (--vis >= pScreen->visuals) {
	    	if ((vis->class | DynamicClass) == DirectColor) {
		    vis->offsetRed = 0;
		    vis->redMask = (1 << redBits) - 1;
		    vis->offsetGreen = redBits;
		    vis->greenMask = ((1 << greenBits) - 1) << vis->offsetGreen;
		    vis->offsetBlue = redBits + greenBits;
		    vis->blueMask = ((1 << blueBits) - 1) << vis->offsetBlue;
	    	}
	    }
    	} else {
	    rfbLog("RGB format %d %d %d\n", blueBits, greenBits, redBits);
       	    vis = pScreen->visuals + pScreen->numVisuals;
            while (--vis >= pScreen->visuals) {
	    	if ((vis->class | DynamicClass) == DirectColor) {
		    vis->offsetBlue = 0;
		    vis->blueMask = (1 << blueBits) - 1;
		    vis->offsetGreen = blueBits;
		    vis->greenMask = ((1 << greenBits) - 1) << vis->offsetGreen;
		    vis->offsetRed = blueBits + greenBits;
		    vis->redMask = ((1 << redBits) - 1) << vis->offsetRed;
	    	}
	    }
    	}
    }

    if (prfb->bitsPerPixel > 4)
	fbPictureInit(pScreen, 0, 0);

    prfb->cursorIsDrawn = FALSE;
    prfb->dontSendFramebufferUpdate = FALSE;

    prfb->CloseScreen = pScreen->CloseScreen;
    prfb->WakeupHandler = pScreen->WakeupHandler;
    prfb->CreateGC = pScreen->CreateGC;
    prfb->PaintWindowBackground = pScreen->PaintWindowBackground;
    prfb->PaintWindowBorder = pScreen->PaintWindowBorder;
    prfb->CopyWindow = pScreen->CopyWindow;
    prfb->ClearToBackground = pScreen->ClearToBackground;
    prfb->RestoreAreas = pScreen->RestoreAreas;
#ifdef CHROMIUM
    prfb->RealizeWindow = pScreen->RealizeWindow;
    prfb->UnrealizeWindow = pScreen->UnrealizeWindow;
    prfb->DestroyWindow = pScreen->DestroyWindow;
    prfb->PositionWindow = pScreen->PositionWindow;
    prfb->ResizeWindow = pScreen->ResizeWindow;
    prfb->ClipNotify = pScreen->ClipNotify;
#endif
#ifdef RENDER
    ps = GetPictureScreenIfSet(pScreen);
    if (ps)
    	prfb->Composite = ps->Composite;
#endif
    pScreen->CloseScreen = rfbCloseScreen;
    pScreen->WakeupHandler = rfbWakeupHandler;
    pScreen->CreateGC = rfbCreateGC;
    pScreen->PaintWindowBackground = rfbPaintWindowBackground;
    pScreen->PaintWindowBorder = rfbPaintWindowBorder;
    pScreen->CopyWindow = rfbCopyWindow;
    pScreen->ClearToBackground = rfbClearToBackground;
    pScreen->RestoreAreas = rfbRestoreAreas;
#ifdef CHROMIUM
    pScreen->RealizeWindow = rfbRealizeWindow;
    pScreen->UnrealizeWindow = rfbUnrealizeWindow;
    pScreen->DestroyWindow = rfbDestroyWindow;
    pScreen->PositionWindow = rfbPositionWindow;
    pScreen->ResizeWindow = rfbResizeWindow;
    pScreen->ClipNotify = rfbClipNotify;
#endif
#ifdef RENDER
    if (ps)
    	ps->Composite = rfbComposite;
#endif

    pScreen->InstallColormap = rfbInstallColormap;
    pScreen->UninstallColormap = rfbUninstallColormap;
    pScreen->ListInstalledColormaps = rfbListInstalledColormaps;
    pScreen->StoreColors = rfbStoreColors;

    pScreen->SaveScreen = (SaveScreenProcPtr)rfbAlwaysTrue;

    rfbDCInitialize(pScreen, &rfbPointerCursorFuncs);

    if (noCursor) {
	pScreen->DisplayCursor = (DisplayCursorProcPtr)rfbAlwaysTrue;
	prfb->cursorIsDrawn = TRUE;
    }

    pScreen->blackPixel = prfb->blackPixel;
    pScreen->whitePixel = prfb->whitePixel;

    prfb->rfbServerFormat.bitsPerPixel = prfb->bitsPerPixel;
    prfb->rfbServerFormat.depth = prfb->depth;
    prfb->rfbServerFormat.bigEndian = !(*(char *)&rfbEndianTest);

    /* Find the root visual and set the server format */
    for (vis = pScreen->visuals; vis->vid != pScreen->rootVisual; vis++)
	;
    prfb->rfbServerFormat.trueColour = (vis->class == TrueColor);

    if ( (vis->class == TrueColor) || (vis->class == DirectColor) ) {
	prfb->rfbServerFormat.redMax = vis->redMask >> vis->offsetRed;
	prfb->rfbServerFormat.greenMax = vis->greenMask >> vis->offsetGreen;
	prfb->rfbServerFormat.blueMax = vis->blueMask >> vis->offsetBlue;
	prfb->rfbServerFormat.redShift = vis->offsetRed;
	prfb->rfbServerFormat.greenShift = vis->offsetGreen;
	prfb->rfbServerFormat.blueShift = vis->offsetBlue;
    } else {
	prfb->rfbServerFormat.redMax
	    = prfb->rfbServerFormat.greenMax 
	    = prfb->rfbServerFormat.blueMax = 0;
	prfb->rfbServerFormat.redShift
	    = prfb->rfbServerFormat.greenShift 
	    = prfb->rfbServerFormat.blueShift = 0;
    }

    ret = fbCreateDefColormap(pScreen);

    rfbInitSockets(pScreen);
#if 0
    rdpInitSockets(pScreen);
#endif
    if (inetdSock == -1)
	httpInitSockets(pScreen);

    return ret;

} /* end rfbScreenInit */



/*
 * InitInput is also called every time the server resets.  It is called after
 * InitOutput so we can assume that rfbInitSockets has already been called.
 */
void
InitInput(int argc, char *argv[])
{
    DeviceIntPtr p, k;

    k = AddInputDevice(serverClient, rfbKeybdProc, TRUE);
    p = AddInputDevice(serverClient, rfbMouseProc, TRUE);
    vncPointerDevice = p;

    RegisterKeyboardDevice(k);
    RegisterPointerDevice(p);

    mieqInit();

#if 0
    mieqCheckForInput[0] = checkForInput[0];
    mieqCheckForInput[1] = checkForInput[1];
    SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
#endif
}


static int
rfbKeybdProc(DeviceIntPtr pDevice, int onoff)
{
    KeySymsRec		keySyms;
    CARD8 		modMap[MAP_LENGTH];
    DevicePtr pDev = (DevicePtr)pDevice;


    switch (onoff)
    {
    case DEVICE_INIT: 
        vncSetKeyboardDevice(pDevice);
	KbdDeviceInit(pDevice, &keySyms, modMap);
	InitKeyboardDeviceStruct(pDev, &keySyms,
				 (BellProcPtr)rfbSendBell,
				 (KbdCtrlProcPtr)NoopDDA);
        break;
    case DEVICE_ON: 
	pDev->on = TRUE;
	KbdDeviceOn();
	break;
    case DEVICE_OFF: 
	pDev->on = FALSE;
	KbdDeviceOff();
	break;
    case DEVICE_CLOSE:
	vncSetKeyboardDevice(NULL);
	if (pDev->on)
	    KbdDeviceOff();
	break;
    }
    return Success;
}

static int
rfbMouseProc(DeviceIntPtr pDevice, int onoff)
{
#define NBUTTONS 7
#define NAXES 2
    // 7 buttons: left, right, middle, then four scroll wheel "buttons"
    CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3, 4, 5, 6, 7};
    Atom btn_labels[NBUTTONS] = {0};
    Atom axes_labels[NAXES] = {0};
    DevicePtr pDev = (DevicePtr)pDevice;

    
    switch (onoff)
    {
    case DEVICE_INIT:
	PtrDeviceInit();

        btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
        btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
        btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
        btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
        btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
        btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
        btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);

        axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
        axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);

	if (! InitPointerDeviceStruct(pDev, map, 
                                      NBUTTONS, btn_labels,
                                      (PtrCtrlProcPtr)NoopDDA, 
                                      GetMotionHistorySize(), 
                                      NAXES, axes_labels))
        {
            ErrorF("Could not initialize device '%s'. Out of memory.\n",
                   pDevice->name);
            return BadAlloc; /* IPDS only fails on allocs */
        }
        pDevice->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
        pDevice->last.valuators[0]    = pDevice->valuator->axisVal[0];
        pDevice->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
        pDevice->last.valuators[1]    = pDevice->valuator->axisVal[1];

        vncSetPointerDevice(pDevice);
	break;

    case DEVICE_ON:
	pDev->on = TRUE;
	PtrDeviceOn(pDevice);
        break;

    case DEVICE_OFF:
	pDev->on = FALSE;
	PtrDeviceOff();
	break;

    case DEVICE_CLOSE:
	vncSetPointerDevice(NULL);
	if (pDev->on)
	    PtrDeviceOff();
	break;
    }
    return Success;
}


Bool
LegalModifier(unsigned int key, DeviceIntPtr pDev)
{
    return TRUE;
}


void
ProcessInputEvents(void)
{
#if 0
    if (*mieqCheckForInput[0] != *mieqCheckForInput[1]) {
#endif
	mieqProcessInputEvents();
#if 0
    }
#endif
}


static Bool CheckDisplayNumber(int n)
{
    char fname[32];
    int sock;
    struct sockaddr_in addr;

    sock = socket(AF_INET, SOCK_STREAM, 0);

    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons(6000+n);
    if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
	close(sock);
	return FALSE;
    }
    close(sock);

    sprintf(fname, "/tmp/.X%d-lock", n);
    if (access(fname, F_OK) == 0)
	return FALSE;

    sprintf(fname, "/tmp/.X11-unix/X%d", n);
    if (access(fname, F_OK) == 0)
	return FALSE;

    return TRUE;
}

static Bool
rfbAlwaysTrue(void)
{
    return TRUE;
}


static unsigned char *
rfbAllocateFramebufferMemory(rfbScreenInfoPtr prfb)
{
    if (prfb->pfbMemory) return prfb->pfbMemory; /* already done */

    prfb->sizeInBytes = (prfb->paddedWidthInBytes * prfb->height);

    prfb->pfbMemory = (unsigned char *)Xalloc(prfb->sizeInBytes);

    return prfb->pfbMemory;
}


static Bool
rfbCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y)
{
  return FALSE;
}

static void
rfbCrossScreen (ScreenPtr Screen, Bool entering)
{
}

void
ddxGiveUp()
{
    Xfree(rfbScreen.pfbMemory);
    if (initOutputCalled) {
	char unixSocketName[32];
	sprintf(unixSocketName,"/tmp/.X11-unix/X%s",display);
	unlink(unixSocketName);
#ifdef CORBA
	shutdownCORBA();
#endif
    }
}

void
AbortDDX()
{
    ddxGiveUp();
}

void
OsVendorInit()
{
}

void
OsVendorFatalError()
{
}

#ifdef DDXTIME /* from ServerOSDefines */
CARD32
GetTimeInMillis()
{
    struct timeval  tp;

    X_GETTIMEOFDAY(&tp);
    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
}
#endif

void
ddxUseMsg()
{
    ErrorF("-geometry WxH          set framebuffer width & height\n");
    ErrorF("-depth D               set framebuffer depth\n");
    ErrorF("-pixelformat format    set pixel format (BGRnnn or RGBnnn)\n");
    ErrorF("-udpinputport port     UDP port for keyboard/pointer data\n");
    ErrorF("-rfbport port          TCP port for RFB protocol\n");
    ErrorF("-rfbwait time          max time in ms to wait for RFB client\n");
    ErrorF("-nocursor              don't put up a cursor\n");
    ErrorF("-rfbauth passwd-file   use authentication on RFB protocol\n");
    ErrorF("-loginauth             use login-style Unix authentication\n");
    ErrorF("-httpd dir             serve files via HTTP from here\n");
    ErrorF("-httpport port         port for HTTP\n");
    ErrorF("-deferupdate time      time in ms to defer updates "
							     "(default 40)\n");
    ErrorF("-economictranslate     less memory-hungry translation\n");
    ErrorF("-lazytight             disable \"gradient\" filter in tight "
								"encoding\n");
    ErrorF("-desktop name          VNC desktop name (default x11)\n");
    ErrorF("-alwaysshared          always treat new clients as shared\n");
    ErrorF("-nevershared           never treat new clients as shared\n");
    ErrorF("-dontdisconnect        don't disconnect existing clients when a "
                                                             "new non-shared\n"
	   "                       connection comes in (refuse new connection "
								 "instead)\n");
    ErrorF("-localhost             only allow connections from localhost\n"
	   "			   to the vnc ports. Use -nolisten tcp to disable\n"
	   "			   remote X clients as well.\n");
    ErrorF("-viewonly              let clients only view the desktop\n");
    ErrorF("-interface ipaddr      only bind to specified interface "
								"address\n");
    ErrorF("-inetd                 Xvnc is launched by inetd\n");
    exit(1);
}


void ddxInitGlobals(void)
{
   /* dummy function called by InitGlobals in os/utils.c */
}

int
NewInputDeviceRequest(InputOption *options, DeviceIntPtr *pdev)
{
    return BadValue;
}

void
DeleteInputDeviceRequest(DeviceIntPtr dev)
{
}


/*
 * rfbLog prints a time-stamped message to the log file (stderr).
 */

void rfbLog(char *format, ...)
{
    va_list args;
    char buf[256];
    time_t clock;

    va_start(args, format);

    time(&clock);
    strftime(buf, 255, "%d/%m/%Y %H:%M:%S ", localtime(&clock));
    fprintf(stderr, buf);

    vfprintf(stderr, format, args);
    fflush(stderr);

    va_end(args);
}

void rfbLogPerror(char *str)
{
    rfbLog("");
    perror(str);
}


More information about the xorg mailing list