21 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
22 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
23 |
#include <time.h> |
#include <time.h> |
24 |
|
#include <errno.h> |
25 |
#include "rdesktop.h" |
#include "rdesktop.h" |
26 |
|
|
27 |
extern int width; |
extern int width; |
30 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
31 |
|
|
32 |
static Display *display; |
static Display *display; |
33 |
|
static int x_socket; |
34 |
static Window wnd; |
static Window wnd; |
35 |
static GC gc; |
static GC gc; |
36 |
static Visual *visual; |
static Visual *visual; |
37 |
static int depth; |
static int depth; |
38 |
static int bpp; |
static int bpp; |
39 |
|
|
40 |
|
/* endianness */ |
41 |
|
static BOOL host_be; |
42 |
|
static BOOL xserver_be; |
43 |
|
|
44 |
|
/* software backing store */ |
45 |
static BOOL ownbackstore; |
static BOOL ownbackstore; |
46 |
static Pixmap backstore; |
static Pixmap backstore; |
47 |
|
|
52 |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
53 |
} |
} |
54 |
|
|
55 |
|
/* colour maps */ |
56 |
static BOOL owncolmap; |
static BOOL owncolmap; |
57 |
static Colormap xcolmap; |
static Colormap xcolmap; |
58 |
static uint32 white; |
static uint32 white; |
59 |
static uint32 *colmap; |
static uint32 *colmap; |
60 |
|
|
61 |
#define TRANSLATE(col) ( owncolmap ? col : colmap[col] ) |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
62 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
63 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
64 |
|
|
98 |
*(out++) = (uint16)colmap[*(data++)]; |
*(out++) = (uint16)colmap[*(data++)]; |
99 |
} |
} |
100 |
|
|
101 |
/* XXX endianness */ |
/* little endian - conversion happens when colourmap is built */ |
102 |
static void |
static void |
103 |
translate24(uint8 *data, uint8 *out, uint8 *end) |
translate24(uint8 *data, uint8 *out, uint8 *end) |
104 |
{ |
{ |
121 |
} |
} |
122 |
|
|
123 |
static uint8 * |
static uint8 * |
124 |
translate(int width, int height, uint8 *data) |
translate_image(int width, int height, uint8 *data) |
125 |
{ |
{ |
126 |
int size = width * height * bpp/8; |
int size = width * height * bpp/8; |
127 |
uint8 *out = xmalloc(size); |
uint8 *out = xmalloc(size); |
149 |
return out; |
return out; |
150 |
} |
} |
151 |
|
|
152 |
#define L_ENDIAN |
#define BSWAP16(x) x = (((x & 0xff) << 8) | (x >> 8)); |
153 |
int screen_msbfirst = 0; |
#define BSWAP24(x) x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); |
154 |
|
#define BSWAP32(x) x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
155 |
|
x = (x << 16) | (x >> 16); |
156 |
|
|
157 |
|
static uint32 |
158 |
|
translate_colour(uint32 colour) |
159 |
|
{ |
160 |
|
switch (bpp) |
161 |
|
{ |
162 |
|
case 16: |
163 |
|
if (host_be != xserver_be) |
164 |
|
BSWAP16(colour); |
165 |
|
break; |
166 |
|
|
167 |
|
case 24: |
168 |
|
if (xserver_be) |
169 |
|
BSWAP24(colour); |
170 |
|
break; |
171 |
|
|
172 |
|
case 32: |
173 |
|
if (host_be != xserver_be) |
174 |
|
BSWAP32(colour); |
175 |
|
break; |
176 |
|
} |
177 |
|
|
178 |
|
return colour; |
179 |
|
} |
180 |
|
|
181 |
BOOL |
BOOL |
182 |
ui_create_window(char *title) |
ui_create_window(char *title) |
187 |
unsigned long input_mask; |
unsigned long input_mask; |
188 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
189 |
Screen *screen; |
Screen *screen; |
190 |
|
uint16 test; |
191 |
int i; |
int i; |
192 |
|
|
|
|
|
193 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
194 |
if (display == NULL) |
if (display == NULL) |
195 |
{ |
{ |
197 |
return False; |
return False; |
198 |
} |
} |
199 |
|
|
200 |
|
x_socket = ConnectionNumber(display); |
201 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
202 |
visual = DefaultVisualOfScreen(screen); |
visual = DefaultVisualOfScreen(screen); |
203 |
depth = DefaultDepthOfScreen(screen); |
depth = DefaultDepthOfScreen(screen); |
230 |
else |
else |
231 |
xcolmap = DefaultColormapOfScreen(screen); |
xcolmap = DefaultColormapOfScreen(screen); |
232 |
|
|
233 |
|
test = 1; |
234 |
|
host_be = !(BOOL)(*(uint8 *)(&test)); |
235 |
|
xserver_be = (ImageByteOrder(display) == MSBFirst); |
236 |
|
|
237 |
white = WhitePixelOfScreen(screen); |
white = WhitePixelOfScreen(screen); |
238 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
239 |
attribs.backing_store = DoesBackingStore(screen); |
attribs.backing_store = DoesBackingStore(screen); |
381 |
return 0; |
return 0; |
382 |
} |
} |
383 |
|
|
384 |
void |
static void |
385 |
ui_process_events() |
xwin_process_events() |
386 |
{ |
{ |
387 |
XEvent event; |
XEvent event; |
388 |
uint8 scancode; |
uint8 scancode; |
466 |
} |
} |
467 |
|
|
468 |
void |
void |
469 |
|
ui_select(int rdp_socket) |
470 |
|
{ |
471 |
|
int n = (rdp_socket > x_socket) ? rdp_socket+1 : x_socket+1; |
472 |
|
fd_set rfds; |
473 |
|
|
474 |
|
XFlush(display); |
475 |
|
|
476 |
|
FD_ZERO(&rfds); |
477 |
|
|
478 |
|
while (True) |
479 |
|
{ |
480 |
|
FD_ZERO(&rfds); |
481 |
|
FD_SET(rdp_socket, &rfds); |
482 |
|
FD_SET(x_socket, &rfds); |
483 |
|
|
484 |
|
switch (select(n, &rfds, NULL, NULL, NULL)) |
485 |
|
{ |
486 |
|
case -1: |
487 |
|
error("select: %s\n", strerror(errno)); |
488 |
|
|
489 |
|
case 0: |
490 |
|
continue; |
491 |
|
} |
492 |
|
|
493 |
|
if (FD_ISSET(x_socket, &rfds)) |
494 |
|
xwin_process_events(); |
495 |
|
|
496 |
|
if (FD_ISSET(rdp_socket, &rfds)) |
497 |
|
return; |
498 |
|
} |
499 |
|
} |
500 |
|
|
501 |
|
void |
502 |
ui_move_pointer(int x, int y) |
ui_move_pointer(int x, int y) |
503 |
{ |
{ |
504 |
XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y); |
XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y); |
511 |
Pixmap bitmap; |
Pixmap bitmap; |
512 |
uint8 *tdata; |
uint8 *tdata; |
513 |
|
|
514 |
tdata = (owncolmap ? data : translate(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
515 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
516 |
image = XCreateImage(display, visual, depth, ZPixmap, |
image = XCreateImage(display, visual, depth, ZPixmap, |
517 |
0, tdata, width, height, 8, 0); |
0, tdata, width, height, 8, 0); |
531 |
XImage *image; |
XImage *image; |
532 |
uint8 *tdata; |
uint8 *tdata; |
533 |
|
|
534 |
tdata = (owncolmap ? data : translate(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
535 |
image = XCreateImage(display, visual, depth, ZPixmap, |
image = XCreateImage(display, visual, depth, ZPixmap, |
536 |
0, tdata, width, height, 8, 0); |
0, tdata, width, height, 8, 0); |
537 |
|
|
706 |
{ |
{ |
707 |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
708 |
XColor xentry; |
XColor xentry; |
709 |
|
uint32 colour; |
710 |
|
|
711 |
for (i = 0; i < ncolours; i++) |
for (i = 0; i < ncolours; i++) |
712 |
{ |
{ |
714 |
MAKE_XCOLOR(&xentry, entry); |
MAKE_XCOLOR(&xentry, entry); |
715 |
|
|
716 |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
717 |
map[i] = xentry.pixel; |
colour = translate_colour(xentry.pixel); |
718 |
else |
else |
719 |
map[i] = white; |
colour = translate_colour(white); |
720 |
|
|
721 |
|
/* byte swap here to make translate_image faster */ |
722 |
|
map[i] = translate_colour(colour); |
723 |
} |
} |
724 |
|
|
725 |
return map; |
return map; |