42 |
static Screen *g_screen; |
static Screen *g_screen; |
43 |
Window g_wnd; |
Window g_wnd; |
44 |
BOOL g_enable_compose = False; |
BOOL g_enable_compose = False; |
45 |
static GC g_gc; |
static GC g_gc = NULL; |
46 |
static Visual *g_visual; |
static Visual *g_visual; |
47 |
static int g_depth; |
static int g_depth; |
48 |
static int g_bpp; |
static int g_bpp; |
50 |
static XIC g_IC; |
static XIC g_IC; |
51 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
52 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
53 |
static HCURSOR g_null_cursor; |
static HCURSOR g_null_cursor = NULL; |
54 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
55 |
static BOOL g_focused; |
static BOOL g_focused; |
56 |
static BOOL g_mouse_in_wnd; |
static BOOL g_mouse_in_wnd; |
63 |
|
|
64 |
/* software backing store */ |
/* software backing store */ |
65 |
static BOOL g_ownbackstore; |
static BOOL g_ownbackstore; |
66 |
static Pixmap g_backstore; |
static Pixmap g_backstore = NULL; |
67 |
|
|
68 |
/* Moving in single app mode */ |
/* Moving in single app mode */ |
69 |
static BOOL g_moving_wnd; |
static BOOL g_moving_wnd; |
699 |
XVisualInfo vi; |
XVisualInfo vi; |
700 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
701 |
uint16 test; |
uint16 test; |
702 |
int i, screen_num; |
int i, screen_num, nvisuals; |
703 |
|
XVisualInfo *vmatches = NULL; |
704 |
|
XVisualInfo template; |
705 |
|
Bool TrueColorVisual = False; |
706 |
|
|
707 |
g_display = XOpenDisplay(NULL); |
g_display = XOpenDisplay(NULL); |
708 |
if (g_display == NULL) |
if (g_display == NULL) |
716 |
g_screen = ScreenOfDisplay(g_display, screen_num); |
g_screen = ScreenOfDisplay(g_display, screen_num); |
717 |
g_depth = DefaultDepthOfScreen(g_screen); |
g_depth = DefaultDepthOfScreen(g_screen); |
718 |
|
|
719 |
if (g_server_bpp == 8) |
/* Search for best TrueColor depth */ |
720 |
|
template.class = TrueColor; |
721 |
|
vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); |
722 |
|
|
723 |
|
nvisuals--; |
724 |
|
while (nvisuals >= 0) |
725 |
|
{ |
726 |
|
if ((vmatches + nvisuals)->depth > g_depth) |
727 |
|
{ |
728 |
|
g_depth = (vmatches + nvisuals)->depth; |
729 |
|
} |
730 |
|
nvisuals--; |
731 |
|
TrueColorVisual = True; |
732 |
|
} |
733 |
|
|
734 |
|
if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) |
735 |
{ |
{ |
736 |
/* we use a colourmap, so any visual should do */ |
/* we use a colourmap, so the default visual should do */ |
737 |
g_visual = DefaultVisualOfScreen(g_screen); |
g_visual = DefaultVisualOfScreen(g_screen); |
738 |
|
g_depth = DefaultDepthOfScreen(g_screen); |
739 |
|
|
740 |
|
/* Do not allocate colours on a TrueColor visual */ |
741 |
|
if (g_visual->class == TrueColor) |
742 |
|
{ |
743 |
|
g_owncolmap = False; |
744 |
|
} |
745 |
} |
} |
746 |
else |
else |
747 |
{ |
{ |
783 |
|
|
784 |
if (!g_owncolmap) |
if (!g_owncolmap) |
785 |
{ |
{ |
786 |
g_xcolmap = DefaultColormapOfScreen(g_screen); |
g_xcolmap = |
787 |
|
XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual, |
788 |
|
AllocNone); |
789 |
if (g_depth <= 8) |
if (g_depth <= 8) |
790 |
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
791 |
} |
} |
792 |
|
|
|
g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL); |
|
|
|
|
793 |
if (DoesBackingStore(g_screen) != Always) |
if (DoesBackingStore(g_screen) != Always) |
794 |
g_ownbackstore = True; |
g_ownbackstore = True; |
795 |
|
|
832 |
/* make sure width is a multiple of 4 */ |
/* make sure width is a multiple of 4 */ |
833 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
834 |
|
|
|
if (g_ownbackstore) |
|
|
{ |
|
|
g_backstore = |
|
|
XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height, |
|
|
g_depth); |
|
|
|
|
|
/* clear to prevent rubbish being exposed at startup */ |
|
|
XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); |
|
|
XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); |
|
|
} |
|
|
|
|
835 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
836 |
|
|
837 |
xkeymap_init(); |
xkeymap_init(); |
852 |
if (g_IM != NULL) |
if (g_IM != NULL) |
853 |
XCloseIM(g_IM); |
XCloseIM(g_IM); |
854 |
|
|
855 |
|
if (g_null_cursor != NULL) |
856 |
|
ui_destroy_cursor(g_null_cursor); |
857 |
|
|
858 |
XFreeModifiermap(g_mod_map); |
XFreeModifiermap(g_mod_map); |
859 |
|
|
860 |
if (g_ownbackstore) |
if (g_ownbackstore) |
881 |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; |
882 |
|
|
883 |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
attribs.background_pixel = BlackPixelOfScreen(g_screen); |
884 |
|
attribs.border_pixel = WhitePixelOfScreen(g_screen); |
885 |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
attribs.backing_store = g_ownbackstore ? NotUseful : Always; |
886 |
attribs.override_redirect = g_fullscreen; |
attribs.override_redirect = g_fullscreen; |
887 |
|
attribs.colormap = g_xcolmap; |
888 |
|
|
889 |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, |
890 |
0, CopyFromParent, InputOutput, CopyFromParent, |
0, g_depth, InputOutput, g_visual, |
891 |
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
CWBackPixel | CWBackingStore | CWOverrideRedirect | |
892 |
|
CWColormap | CWBorderPixel, &attribs); |
893 |
|
|
894 |
|
if (g_gc == NULL) |
895 |
|
g_gc = XCreateGC(g_display, g_wnd, 0, NULL); |
896 |
|
|
897 |
|
if ((g_ownbackstore) && (g_backstore == NULL)) |
898 |
|
{ |
899 |
|
g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); |
900 |
|
|
901 |
|
/* clear to prevent rubbish being exposed at startup */ |
902 |
|
XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); |
903 |
|
XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); |
904 |
|
} |
905 |
|
|
906 |
XStoreName(g_display, g_wnd, g_title); |
XStoreName(g_display, g_wnd, g_title); |
907 |
|
|
967 |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
968 |
|
|
969 |
/* create invisible 1x1 cursor to be used as null cursor */ |
/* create invisible 1x1 cursor to be used as null cursor */ |
970 |
g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); |
if (g_null_cursor == NULL) |
971 |
|
g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); |
972 |
|
|
973 |
return True; |
return True; |
974 |
} |
} |
1271 |
int |
int |
1272 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
1273 |
{ |
{ |
1274 |
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; |
int n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; |
1275 |
fd_set rfds, wfds; |
fd_set rfds, wfds; |
1276 |
|
struct timeval tv; |
1277 |
|
BOOL s_timeout = False; |
1278 |
|
|
1279 |
while (True) |
while (True) |
1280 |
{ |
{ |
1293 |
if (g_dsp_busy) |
if (g_dsp_busy) |
1294 |
{ |
{ |
1295 |
FD_SET(g_dsp_fd, &wfds); |
FD_SET(g_dsp_fd, &wfds); |
1296 |
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
n = (g_dsp_fd > n) ? g_dsp_fd : n; |
1297 |
} |
} |
1298 |
#endif |
#endif |
1299 |
|
/* default timeout */ |
1300 |
|
tv.tv_sec = 60; |
1301 |
|
tv.tv_usec = 0; |
1302 |
|
|
1303 |
switch (select(n, &rfds, &wfds, NULL, NULL)) |
/* add redirection handles */ |
1304 |
|
rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); |
1305 |
|
|
1306 |
|
n++; |
1307 |
|
|
1308 |
|
switch (select(n, &rfds, &wfds, NULL, &tv)) |
1309 |
{ |
{ |
1310 |
case -1: |
case -1: |
1311 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
1312 |
|
|
1313 |
case 0: |
case 0: |
1314 |
|
/* TODO: if tv.tv_sec just times out |
1315 |
|
* we will segfault. |
1316 |
|
* FIXME: |
1317 |
|
*/ |
1318 |
|
//s_timeout = True; |
1319 |
|
//rdpdr_check_fds(&rfds, &wfds, (BOOL) True); |
1320 |
continue; |
continue; |
1321 |
} |
} |
1322 |
|
|
1323 |
|
rdpdr_check_fds(&rfds, &wfds, (BOOL) False); |
1324 |
|
|
1325 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
1326 |
return 1; |
return 1; |
1327 |
|
|