25 |
#define XK_MISCELLANY |
#define XK_MISCELLANY |
26 |
#include <X11/keysymdef.h> |
#include <X11/keysymdef.h> |
27 |
#include "rdesktop.h" |
#include "rdesktop.h" |
28 |
|
#include "scancodes.h" |
29 |
|
|
30 |
extern int width; |
extern int width; |
31 |
extern int height; |
extern int height; |
32 |
extern BOOL sendmotion; |
extern BOOL sendmotion; |
33 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
34 |
|
extern BOOL grab_keyboard; |
35 |
|
|
36 |
Display *display = NULL; |
Display *display = NULL; |
37 |
static int x_socket; |
static int x_socket; |
217 |
It seems to work alright anyway, though. */ |
It seems to work alright anyway, though. */ |
218 |
if (IC != NULL) |
if (IC != NULL) |
219 |
{ |
{ |
220 |
if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) |
if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL) |
|
!= NULL) |
|
221 |
{ |
{ |
222 |
error("Failed to obtain XNFilterEvents value from IC\n"); |
error("Failed to obtain XNFilterEvents value from IC\n"); |
223 |
filtered_events = 0; |
filtered_events = 0; |
240 |
} |
} |
241 |
} |
} |
242 |
|
|
243 |
|
BOOL |
244 |
|
ui_init() |
245 |
|
{ |
246 |
|
Screen *screen; |
247 |
|
display = XOpenDisplay(NULL); |
248 |
|
if (display == NULL) |
249 |
|
{ |
250 |
|
error("Failed to open display\n"); |
251 |
|
return False; |
252 |
|
} |
253 |
|
if (fullscreen) |
254 |
|
{ |
255 |
|
screen = DefaultScreenOfDisplay(display); |
256 |
|
width = WidthOfScreen(screen); |
257 |
|
height = HeightOfScreen(screen); |
258 |
|
} |
259 |
|
return True; |
260 |
|
} |
261 |
|
|
262 |
BOOL |
BOOL |
263 |
ui_create_window(char *title) |
ui_create_window(char *title) |
271 |
uint16 test; |
uint16 test; |
272 |
int i; |
int i; |
273 |
|
|
|
display = XOpenDisplay(NULL); |
|
|
|
|
|
if (display == NULL) |
|
|
{ |
|
|
error("Failed to open display\n"); |
|
|
return False; |
|
|
} |
|
|
|
|
274 |
x_socket = ConnectionNumber(display); |
x_socket = ConnectionNumber(display); |
275 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
276 |
visual = DefaultVisualOfScreen(screen); |
visual = DefaultVisualOfScreen(screen); |
283 |
desirable, e.g. 24 bits->32 bits. */ |
desirable, e.g. 24 bits->32 bits. */ |
284 |
while (i--) |
while (i--) |
285 |
{ |
{ |
286 |
if ((pfm[i].depth == depth) |
if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp)) |
|
&& (pfm[i].bits_per_pixel > bpp)) |
|
287 |
{ |
{ |
288 |
bpp = pfm[i].bits_per_pixel; |
bpp = pfm[i].bits_per_pixel; |
289 |
} |
} |
330 |
wnd = XCreateWindow(display, RootWindowOfScreen(screen), |
wnd = XCreateWindow(display, RootWindowOfScreen(screen), |
331 |
0, 0, width, height, 0, CopyFromParent, |
0, 0, width, height, 0, CopyFromParent, |
332 |
InputOutput, CopyFromParent, |
InputOutput, CopyFromParent, |
333 |
CWBackingStore | CWBackPixel | CWOverrideRedirect, |
CWBackingStore | CWBackPixel | CWOverrideRedirect, &attribs); |
|
&attribs); |
|
334 |
|
|
335 |
XStoreName(display, wnd, title); |
XStoreName(display, wnd, title); |
336 |
|
|
354 |
|
|
355 |
xkeymap_init2(); |
xkeymap_init2(); |
356 |
|
|
357 |
input_mask = |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask; |
358 |
KeyPressMask | KeyReleaseMask | ButtonPressMask | |
if (grab_keyboard) |
359 |
ButtonReleaseMask | EnterWindowMask | LeaveWindowMask; |
input_mask |= EnterWindowMask | LeaveWindowMask; |
360 |
if (sendmotion) |
if (sendmotion) |
361 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
362 |
|
|
419 |
{ |
{ |
420 |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
421 |
{ |
{ |
422 |
DEBUG_KBD("Filtering event\n"); |
DEBUG_KBD(("Filtering event\n")); |
423 |
continue; |
continue; |
424 |
} |
} |
425 |
|
|
434 |
{ |
{ |
435 |
XmbLookupString(IC, |
XmbLookupString(IC, |
436 |
(XKeyPressedEvent *) & |
(XKeyPressedEvent *) & |
437 |
xevent, str, |
xevent, str, sizeof(str), &keysym, &status); |
438 |
sizeof(str), &keysym, |
if (!((status == XLookupKeySym) || (status == XLookupBoth))) |
|
&status); |
|
|
if (! |
|
|
((status == XLookupKeySym) |
|
|
|| (status == XLookupBoth))) |
|
439 |
{ |
{ |
440 |
error("XmbLookupString failed with status 0x%x\n", status); |
error("XmbLookupString failed with status 0x%x\n", |
441 |
|
status); |
442 |
break; |
break; |
443 |
} |
} |
444 |
} |
} |
445 |
else |
else |
446 |
{ |
{ |
447 |
/* Plain old XLookupString */ |
/* Plain old XLookupString */ |
448 |
DEBUG_KBD |
DEBUG_KBD(("No input context, using XLookupString\n")); |
|
("No input context, using XLookupString\n"); |
|
449 |
XLookupString((XKeyEvent *) & xevent, |
XLookupString((XKeyEvent *) & xevent, |
450 |
str, sizeof(str), |
str, sizeof(str), &keysym, NULL); |
|
&keysym, NULL); |
|
451 |
} |
} |
452 |
|
|
453 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
454 |
DEBUG_KBD |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
|
("\nKeyPress for (keysym 0x%lx, %s)\n", |
|
|
keysym, ksname); |
|
455 |
|
|
456 |
if (inhibit_key(keysym)) |
if (inhibit_key(keysym)) |
457 |
{ |
{ |
458 |
DEBUG_KBD("Inhibiting key\n"); |
DEBUG_KBD(("Inhibiting key\n")); |
459 |
break; |
break; |
460 |
} |
} |
461 |
|
|
462 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
463 |
xevent.xkey. |
xevent.xkey.keycode, xevent.xkey.state); |
|
keycode, |
|
|
xevent.xkey.state); |
|
464 |
|
|
465 |
ensure_remote_modifiers(ev_time, tr); |
ensure_remote_modifiers(ev_time, tr); |
466 |
|
|
467 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
468 |
break; |
break; |
469 |
|
|
470 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
|
tr.scancode); |
|
471 |
break; |
break; |
472 |
case KeyRelease: |
case KeyRelease: |
473 |
XLookupString((XKeyEvent *) & xevent, str, |
XLookupString((XKeyEvent *) & xevent, str, |
474 |
sizeof(str), &keysym, NULL); |
sizeof(str), &keysym, NULL); |
475 |
|
|
476 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
477 |
DEBUG_KBD |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
478 |
("\nKeyRelease for (keysym 0x%lx, %s)\n", |
ksname)); |
|
keysym, ksname); |
|
479 |
|
|
480 |
if (inhibit_key(keysym)) |
if (inhibit_key(keysym)) |
481 |
break; |
break; |
482 |
|
|
483 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
484 |
xevent.xkey. |
xevent.xkey.keycode, xevent.xkey.state); |
|
keycode, |
|
|
xevent.xkey.state); |
|
485 |
|
|
486 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
487 |
break; |
break; |
488 |
|
|
489 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode); |
|
tr.scancode); |
|
490 |
break; |
break; |
491 |
|
|
492 |
case ButtonPress: |
case ButtonPress: |
494 |
/* fall through */ |
/* fall through */ |
495 |
|
|
496 |
case ButtonRelease: |
case ButtonRelease: |
497 |
button = xkeymap_translate_button(xevent. |
button = xkeymap_translate_button(xevent.xbutton.button); |
|
xbutton. |
|
|
button); |
|
498 |
if (button == 0) |
if (button == 0) |
499 |
break; |
break; |
500 |
|
|
501 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
502 |
flags | button, |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
|
xevent.xbutton.x, |
|
|
xevent.xbutton.y); |
|
503 |
break; |
break; |
504 |
|
|
505 |
case MotionNotify: |
case MotionNotify: |
506 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
507 |
MOUSE_FLAG_MOVE, |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
|
xevent.xmotion.x, |
|
|
xevent.xmotion.y); |
|
508 |
break; |
break; |
509 |
|
|
510 |
|
case FocusIn: |
511 |
|
/* fall through */ |
512 |
case EnterNotify: |
case EnterNotify: |
513 |
XGrabKeyboard(display, wnd, True, |
if (grab_keyboard) |
514 |
GrabModeAsync, GrabModeAsync, |
XGrabKeyboard(display, wnd, True, |
515 |
CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
516 |
break; |
break; |
517 |
|
|
518 |
|
case FocusOut: |
519 |
|
/* reset keys */ |
520 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, |
521 |
|
KBD_FLAG_DOWN | KBD_FLAG_UP, SCANCODE_CHAR_LCTRL, 0); |
522 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, |
523 |
|
KBD_FLAG_DOWN | KBD_FLAG_UP, SCANCODE_CHAR_LALT, 0); |
524 |
|
/* fall through */ |
525 |
case LeaveNotify: |
case LeaveNotify: |
526 |
XUngrabKeyboard(display, CurrentTime); |
if (grab_keyboard) |
527 |
|
XUngrabKeyboard(display, CurrentTime); |
528 |
break; |
break; |
529 |
|
|
530 |
case Expose: |
case Expose: |
588 |
|
|
589 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
590 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
591 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, tdata, width, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
592 |
height, 8, 0); |
(char *) tdata, width, height, 8, 0); |
593 |
|
|
594 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
595 |
|
|
600 |
} |
} |
601 |
|
|
602 |
void |
void |
603 |
ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, |
ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 * data) |
|
uint8 * data) |
|
604 |
{ |
{ |
605 |
XImage *image; |
XImage *image; |
606 |
uint8 *tdata; |
uint8 *tdata; |
607 |
|
|
608 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
609 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, tdata, width, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
610 |
height, 8, 0); |
(char *) tdata, width, height, 8, 0); |
611 |
|
|
612 |
if (ownbackstore) |
if (ownbackstore) |
613 |
{ |
{ |
643 |
bitmap = XCreatePixmap(display, wnd, width, height, 1); |
bitmap = XCreatePixmap(display, wnd, width, height, 1); |
644 |
gc = XCreateGC(display, bitmap, 0, NULL); |
gc = XCreateGC(display, bitmap, 0, NULL); |
645 |
|
|
646 |
image = XCreateImage(display, visual, 1, ZPixmap, 0, data, width, |
image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data, |
647 |
height, 8, scanline); |
width, height, 8, scanline); |
648 |
image->byte_order = MSBFirst; |
image->byte_order = MSBFirst; |
649 |
image->bitmap_bit_order = MSBFirst; |
image->bitmap_bit_order = MSBFirst; |
650 |
XInitImage(image); |
XInitImage(image); |
884 |
SET_BACKGROUND(fgcolour); |
SET_BACKGROUND(fgcolour); |
885 |
XSetFillStyle(display, gc, FillOpaqueStippled); |
XSetFillStyle(display, gc, FillOpaqueStippled); |
886 |
XSetStipple(display, gc, fill); |
XSetStipple(display, gc, fill); |
887 |
XSetTSOrigin(display, gc, brush->xorigin, |
XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin); |
|
brush->yorigin); |
|
888 |
|
|
889 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE(x, y, cx, cy); |
890 |
|
|
891 |
XSetFillStyle(display, gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
892 |
|
XSetTSOrigin(display, gc, 0, 0); |
893 |
ui_destroy_glyph((HGLYPH) fill); |
ui_destroy_glyph((HGLYPH) fill); |
894 |
break; |
break; |
895 |
|
|
908 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
909 |
XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y); |
910 |
if (ownbackstore) |
if (ownbackstore) |
911 |
XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, |
XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, cy, x, y); |
|
cy, x, y); |
|
912 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
913 |
} |
} |
914 |
|
|
920 |
SET_FUNCTION(opcode); |
SET_FUNCTION(opcode); |
921 |
XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y); |
XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y); |
922 |
if (ownbackstore) |
if (ownbackstore) |
923 |
XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, |
XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, cx, cy, x, y); |
|
cx, cy, x, y); |
|
924 |
RESET_FUNCTION(opcode); |
RESET_FUNCTION(opcode); |
925 |
} |
} |
926 |
|
|
937 |
{ |
{ |
938 |
case 0x69: /* PDSxxn */ |
case 0x69: /* PDSxxn */ |
939 |
ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy); |
ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy); |
940 |
ui_patblt(ROP2_NXOR, x, y, cx, cy, brush, bgcolour, |
ui_patblt(ROP2_NXOR, x, y, cx, cy, brush, bgcolour, fgcolour); |
|
fgcolour); |
|
941 |
break; |
break; |
942 |
|
|
943 |
case 0xb8: /* PSDPxax */ |
case 0xb8: /* PSDPxax */ |
944 |
ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, |
ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour); |
|
fgcolour); |
|
945 |
ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy); |
ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy); |
946 |
ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, |
ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour); |
|
fgcolour); |
|
947 |
break; |
break; |
948 |
|
|
949 |
case 0xc0: /* PSa */ |
case 0xc0: /* PSa */ |
950 |
ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy); |
ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy); |
951 |
ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour, |
ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour, fgcolour); |
|
fgcolour); |
|
952 |
break; |
break; |
953 |
|
|
954 |
default: |
default: |
989 |
SET_BACKGROUND(bgcolour); |
SET_BACKGROUND(bgcolour); |
990 |
|
|
991 |
XSetFillStyle(display, gc, |
XSetFillStyle(display, gc, |
992 |
(mixmode == |
(mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled); |
|
MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled); |
|
993 |
XSetStipple(display, gc, (Pixmap) glyph); |
XSetStipple(display, gc, (Pixmap) glyph); |
994 |
XSetTSOrigin(display, gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
995 |
|
|
1007 |
if ((xyoffset & 0x80))\ |
if ((xyoffset & 0x80))\ |
1008 |
{\ |
{\ |
1009 |
if (flags & TEXT2_VERTICAL) \ |
if (flags & TEXT2_VERTICAL) \ |
1010 |
y += ttext[++idx] | (ttext[++idx] << 8);\ |
y += ttext[idx+1] | (ttext[idx+2] << 8);\ |
1011 |
else\ |
else\ |
1012 |
x += ttext[++idx] | (ttext[++idx] << 8);\ |
x += ttext[idx+1] | (ttext[idx+2] << 8);\ |
1013 |
|
idx += 2;\ |
1014 |
}\ |
}\ |
1015 |
else\ |
else\ |
1016 |
{\ |
{\ |
1059 |
{ |
{ |
1060 |
case 0xff: |
case 0xff: |
1061 |
if (i + 2 < length) |
if (i + 2 < length) |
1062 |
cache_put_text(text[i + 1], text, |
cache_put_text(text[i + 1], text, text[i + 2]); |
|
text[i + 2]); |
|
1063 |
else |
else |
1064 |
{ |
{ |
1065 |
error("this shouldn't be happening\n"); |
error("this shouldn't be happening\n"); |
1076 |
if (entry != NULL) |
if (entry != NULL) |
1077 |
{ |
{ |
1078 |
if ((((uint8 *) (entry->data))[1] == |
if ((((uint8 *) (entry->data))[1] == |
1079 |
0) |
0) && (!(flags & TEXT2_IMPLICIT_X))) |
|
&& (!(flags & TEXT2_IMPLICIT_X))) |
|
1080 |
{ |
{ |
1081 |
if (flags & TEXT2_VERTICAL) |
if (flags & TEXT2_VERTICAL) |
1082 |
y += text[i + 2]; |
y += text[i + 2]; |
1092 |
text = &(text[i]); |
text = &(text[i]); |
1093 |
i = 0; |
i = 0; |
1094 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
1095 |
DO_GLYPH(((uint8 *) (entry-> |
DO_GLYPH(((uint8 *) (entry->data)), j); |
|
data)), |
|
|
j); |
|
1096 |
} |
} |
1097 |
break; |
break; |
1098 |
|
|
1114 |
|
|
1115 |
if (ownbackstore) |
if (ownbackstore) |
1116 |
{ |
{ |
1117 |
image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, |
image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap); |
|
ZPixmap); |
|
1118 |
} |
} |
1119 |
else |
else |
1120 |
{ |
{ |
1121 |
pix = XCreatePixmap(display, wnd, cx, cy, depth); |
pix = XCreatePixmap(display, wnd, cx, cy, depth); |
1122 |
XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0); |
XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0); |
1123 |
image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, |
image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap); |
|
ZPixmap); |
|
1124 |
XFreePixmap(display, pix); |
XFreePixmap(display, pix); |
1125 |
} |
} |
1126 |
|
|
1127 |
offset *= bpp / 8; |
offset *= bpp / 8; |
1128 |
cache_put_desktop(offset, cx, cy, image->bytes_per_line, bpp / 8, |
cache_put_desktop(offset, cx, cy, image->bytes_per_line, bpp / 8, (uint8 *) image->data); |
|
(uint8 *) image->data); |
|
1129 |
|
|
1130 |
XDestroyImage(image); |
XDestroyImage(image); |
1131 |
} |
} |
1141 |
if (data == NULL) |
if (data == NULL) |
1142 |
return; |
return; |
1143 |
|
|
1144 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, data, cx, cy, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
1145 |
BitmapPad(display), cx * bpp / 8); |
(char *) data, cx, cy, BitmapPad(display), cx * bpp / 8); |
1146 |
|
|
1147 |
if (ownbackstore) |
if (ownbackstore) |
1148 |
{ |
{ |