/*
 *  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.
 */

/*
 * vncviewer.h
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rfbproto.h"

extern int supporttight;
extern int bpp;
extern int debug;
extern int displaycursor;
extern int checkclientbitmap;
extern int dither8;
extern int addrectshift;
extern unsigned short rgb332_rgb555_table[256];

//#define Swap16IfLE(s)
//    (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
//
//#define Swap32IfLE(l)
//    (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) |
//			     (((l) & 0x00ff0000) >> 8)  |
//			     (((l) & 0x0000ff00) << 8)  |
//			     (((l) & 0x000000ff) << 24))  : (l))
#define Swap16IfLE(s)  ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
#define Swap32IfLE(l)  ((((l) & 0xff000000) >> 24) |         \
		        (((l) & 0x00ff0000) >> 8)  |         \
		        (((l) & 0x0000ff00) << 8)  |         \
		        (((l) & 0x000000ff) << 24))

#define MAX_ENCODINGS 10

#define FLASH_PORT_OFFSET 5400
#define LISTEN_PORT_OFFSET 5500
#define SERVER_PORT_OFFSET 5900


extern char vncServerHost[];
extern int vncServerPort;

extern int numCmdLineOptions;

/* rfbproto.c */

extern int rfbsock;
extern Bool canUseCoRRE;
extern Bool canUseHextile;
extern char *desktopName;
extern rfbPixelFormat myFormat;
extern rfbServerInitMsg si;
extern char *serverCutText;
extern Bool newServerCutText;

extern char password[9];

extern Bool ConnectToRFBServer(unsigned int hostname, int port);
extern Bool InitialiseRFBConnection(void);
extern Bool SetFormatAndEncodings(void);
extern Bool SendIncrementalFramebufferUpdateRequest(void);
extern Bool SendFramebufferUpdateRequest(int x, int y, int w, int h,
					 Bool incremental);
extern Bool SendPointerEvent(int x, int y, int buttonMask);
extern Bool SendKeyEvent(CARD32 key, Bool down);
extern Bool SendClientCutText(char *str, int len);
extern Bool HandleRFBServerMessage(void);
extern void CloseConnection(void);

extern void PrintPixelFormat(rfbPixelFormat *format);

/* sockets.c */

extern Bool errorMessageOnReadFailure;

extern Bool ReadFromRFBServer(char *out, unsigned int n);
extern Bool WriteExact(int sock, void *buf, int n);
extern int ConnectToTcpAddr(unsigned int host, int port);
extern Bool SetNonBlocking(int sock);
extern void CloseSocket(int sock);

extern int totalread;

/* vncviewer.c */
void UpdateWindow(int x, int y, int w, int h);
int fast_copy_ok(void);
void BlockCopy(int rx, int ry, int rw, int rh, int sx, int sy);

/* cursor.c */

extern Bool HandleXCursor(int xhot, int yhot, int width, int height);


void poll(void);
