31 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
32 |
extern BOOL hide_decorations; |
extern BOOL hide_decorations; |
33 |
extern char title[]; |
extern char title[]; |
34 |
|
extern int server_bpp; |
35 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
36 |
BOOL focused; |
BOOL focused; |
37 |
BOOL mouse_in_wnd; |
BOOL mouse_in_wnd; |
63 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
64 |
typedef struct |
typedef struct |
65 |
{ |
{ |
66 |
unsigned long flags; |
uint32 flags; |
67 |
unsigned long functions; |
uint32 functions; |
68 |
unsigned long decorations; |
uint32 decorations; |
69 |
long inputMode; |
sint32 inputMode; |
70 |
unsigned long status; |
uint32 status; |
71 |
} |
} |
72 |
PropMotifWmHints; |
PropMotifWmHints; |
73 |
|
|
79 |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
80 |
} |
} |
81 |
|
|
82 |
|
#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ |
83 |
|
{ \ |
84 |
|
XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ |
85 |
|
} |
86 |
|
|
87 |
/* colour maps */ |
/* colour maps */ |
88 |
|
BOOL owncolmap = False; |
89 |
static Colormap xcolmap; |
static Colormap xcolmap; |
90 |
static uint32 *colmap; |
static uint32 *colmap; |
91 |
|
|
92 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, translate_colour(colmap[col])); |
#define TRANSLATE(col) ( server_bpp != 8 ? col : owncolmap ? col : translate_colour(colmap[col]) ) |
93 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, translate_colour(colmap[col])); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
94 |
|
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
95 |
|
|
96 |
static int rop2_map[] = { |
static int rop2_map[] = { |
97 |
GXclear, /* 0 */ |
GXclear, /* 0 */ |
129 |
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
130 |
if (!hintsatom) |
if (!hintsatom) |
131 |
{ |
{ |
132 |
error("Failed to get atom _MOTIF_WM_HINTS\n"); |
warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n"); |
133 |
return; |
return; |
134 |
} |
} |
135 |
|
|
297 |
return False; |
return False; |
298 |
} |
} |
299 |
|
|
300 |
xcolmap = DefaultColormapOfScreen(screen); |
if (owncolmap != True) |
301 |
|
{ |
302 |
|
xcolmap = DefaultColormapOfScreen(screen); |
303 |
|
if (depth <= 8) |
304 |
|
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
305 |
|
} |
306 |
|
|
307 |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
308 |
|
|
309 |
if (DoesBackingStore(screen) != Always) |
if (DoesBackingStore(screen) != Always) |
316 |
if ((width == 0) || (height == 0)) |
if ((width == 0) || (height == 0)) |
317 |
{ |
{ |
318 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
319 |
uint32 xpos, ypos; |
uint32 x, y, cx, cy; |
320 |
|
|
321 |
if (get_current_workarea(&xpos, &ypos, &width, &height) < 0) |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
322 |
{ |
{ |
323 |
error("Failed to get workarea.\n"); |
width = cx; |
324 |
error("Perhaps your window manager does not support EWMH?\n"); |
height = cy; |
325 |
error("Defaulting to geometry 800x600\n"); |
} |
326 |
|
else |
327 |
|
{ |
328 |
|
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
329 |
width = 800; |
width = 800; |
330 |
height = 600; |
height = 600; |
331 |
} |
} |
608 |
break; |
break; |
609 |
|
|
610 |
case MotionNotify: |
case MotionNotify: |
611 |
|
if (fullscreen && !focused) |
612 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
613 |
|
CurrentTime); |
614 |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
615 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
616 |
break; |
break; |
731 |
Pixmap bitmap; |
Pixmap bitmap; |
732 |
uint8 *tdata; |
uint8 *tdata; |
733 |
|
|
734 |
tdata = translate_image(width, height, data); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
735 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
736 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
737 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, 8, 0); |
739 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
740 |
|
|
741 |
XFree(image); |
XFree(image); |
742 |
xfree(tdata); |
if (!owncolmap) |
743 |
|
xfree(tdata); |
744 |
return (HBITMAP) bitmap; |
return (HBITMAP) bitmap; |
745 |
} |
} |
746 |
|
|
750 |
XImage *image; |
XImage *image; |
751 |
uint8 *tdata; |
uint8 *tdata; |
752 |
|
|
753 |
tdata = translate_image(width, height, data); |
if (server_bpp == 16) |
754 |
|
{ |
755 |
|
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
756 |
|
(char *) data, width, height, 16, 0); |
757 |
|
|
758 |
|
if (ownbackstore) |
759 |
|
{ |
760 |
|
XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy); |
761 |
|
XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y); |
762 |
|
} |
763 |
|
else |
764 |
|
{ |
765 |
|
XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy); |
766 |
|
} |
767 |
|
|
768 |
|
XFree(image); |
769 |
|
return; |
770 |
|
} |
771 |
|
tdata = (owncolmap ? data : translate_image(width, height, data)); |
772 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
773 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, 8, 0); |
774 |
|
|
783 |
} |
} |
784 |
|
|
785 |
XFree(image); |
XFree(image); |
786 |
xfree(tdata); |
if (!owncolmap) |
787 |
|
xfree(tdata); |
788 |
} |
} |
789 |
|
|
790 |
void |
void |
915 |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
916 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
917 |
|
|
918 |
|
|
919 |
HCOLOURMAP |
HCOLOURMAP |
920 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
921 |
{ |
{ |
922 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
923 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
924 |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
if (!owncolmap) |
|
XColor xentry; |
|
|
XColor xc_cache[256]; |
|
|
uint32 colour; |
|
|
int colLookup = 256; |
|
|
for (i = 0; i < ncolours; i++) |
|
925 |
{ |
{ |
926 |
entry = &colours->colours[i]; |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
927 |
MAKE_XCOLOR(&xentry, entry); |
XColor xentry; |
928 |
|
XColor xc_cache[256]; |
929 |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
uint32 colour; |
930 |
|
int colLookup = 256; |
931 |
|
for (i = 0; i < ncolours; i++) |
932 |
{ |
{ |
933 |
/* Allocation failed, find closest match. */ |
entry = &colours->colours[i]; |
934 |
int j = 256; |
MAKE_XCOLOR(&xentry, entry); |
|
int nMinDist = 3 * 256 * 256; |
|
|
long nDist = nMinDist; |
|
935 |
|
|
936 |
/* only get the colors once */ |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
|
while (colLookup--) |
|
937 |
{ |
{ |
938 |
xc_cache[colLookup].pixel = colLookup; |
/* Allocation failed, find closest match. */ |
939 |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
int j = 256; |
940 |
xc_cache[colLookup].blue = 0; |
int nMinDist = 3 * 256 * 256; |
941 |
xc_cache[colLookup].flags = 0; |
long nDist = nMinDist; |
|
XQueryColor(display, |
|
|
DefaultColormap(display, DefaultScreen(display)), |
|
|
&xc_cache[colLookup]); |
|
|
} |
|
|
colLookup = 0; |
|
942 |
|
|
943 |
/* approximate the pixel */ |
/* only get the colors once */ |
944 |
while (j--) |
while (colLookup--) |
|
{ |
|
|
if (xc_cache[j].flags) |
|
945 |
{ |
{ |
946 |
nDist = ((long) (xc_cache[j].red >> 8) - |
xc_cache[colLookup].pixel = colLookup; |
947 |
(long) (xentry.red >> 8)) * |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
948 |
((long) (xc_cache[j].red >> 8) - |
xc_cache[colLookup].blue = 0; |
949 |
(long) (xentry.red >> 8)) + |
xc_cache[colLookup].flags = 0; |
950 |
((long) (xc_cache[j].green >> 8) - |
XQueryColor(display, |
951 |
(long) (xentry.green >> 8)) * |
DefaultColormap(display, |
952 |
((long) (xc_cache[j].green >> 8) - |
DefaultScreen(display)), |
953 |
(long) (xentry.green >> 8)) + |
&xc_cache[colLookup]); |
|
((long) (xc_cache[j].blue >> 8) - |
|
|
(long) (xentry.blue >> 8)) * |
|
|
((long) (xc_cache[j].blue >> 8) - |
|
|
(long) (xentry.blue >> 8)); |
|
954 |
} |
} |
955 |
if (nDist < nMinDist) |
colLookup = 0; |
956 |
|
|
957 |
|
/* approximate the pixel */ |
958 |
|
while (j--) |
959 |
{ |
{ |
960 |
nMinDist = nDist; |
if (xc_cache[j].flags) |
961 |
xentry.pixel = j; |
{ |
962 |
|
nDist = ((long) (xc_cache[j].red >> 8) - |
963 |
|
(long) (xentry.red >> 8)) * |
964 |
|
((long) (xc_cache[j].red >> 8) - |
965 |
|
(long) (xentry.red >> 8)) + |
966 |
|
((long) (xc_cache[j].green >> 8) - |
967 |
|
(long) (xentry.green >> 8)) * |
968 |
|
((long) (xc_cache[j].green >> 8) - |
969 |
|
(long) (xentry.green >> 8)) + |
970 |
|
((long) (xc_cache[j].blue >> 8) - |
971 |
|
(long) (xentry.blue >> 8)) * |
972 |
|
((long) (xc_cache[j].blue >> 8) - |
973 |
|
(long) (xentry.blue >> 8)); |
974 |
|
} |
975 |
|
if (nDist < nMinDist) |
976 |
|
{ |
977 |
|
nMinDist = nDist; |
978 |
|
xentry.pixel = j; |
979 |
|
} |
980 |
} |
} |
981 |
} |
} |
982 |
|
colour = xentry.pixel; |
983 |
|
|
984 |
|
/* update our cache */ |
985 |
|
if (xentry.pixel < 256) |
986 |
|
{ |
987 |
|
xc_cache[xentry.pixel].red = xentry.red; |
988 |
|
xc_cache[xentry.pixel].green = xentry.green; |
989 |
|
xc_cache[xentry.pixel].blue = xentry.blue; |
990 |
|
|
991 |
|
} |
992 |
|
|
993 |
|
|
994 |
|
/* byte swap here to make translate_image faster */ |
995 |
|
map[i] = translate_colour(colour); |
996 |
} |
} |
997 |
colour = xentry.pixel; |
return map; |
998 |
|
} |
999 |
|
else |
1000 |
|
{ |
1001 |
|
XColor *xcolours, *xentry; |
1002 |
|
Colormap map; |
1003 |
|
|
1004 |
/* update our cache */ |
xcolours = xmalloc(sizeof(XColor) * ncolours); |
1005 |
if (xentry.pixel < 256) |
for (i = 0; i < ncolours; i++) |
1006 |
{ |
{ |
1007 |
xc_cache[xentry.pixel].red = xentry.red; |
entry = &colours->colours[i]; |
1008 |
xc_cache[xentry.pixel].green = xentry.green; |
xentry = &xcolours[i]; |
1009 |
xc_cache[xentry.pixel].blue = xentry.blue; |
xentry->pixel = i; |
1010 |
|
MAKE_XCOLOR(xentry, entry); |
1011 |
} |
} |
1012 |
|
|
1013 |
|
map = XCreateColormap(display, wnd, visual, AllocAll); |
1014 |
|
XStoreColors(display, map, xcolours, ncolours); |
1015 |
|
|
1016 |
/* byte swap here to make translate_image faster */ |
xfree(xcolours); |
1017 |
map[i] = translate_colour(colour); |
return (HCOLOURMAP) map; |
1018 |
} |
} |
|
|
|
|
return map; |
|
1019 |
} |
} |
1020 |
|
|
1021 |
void |
void |
1022 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(HCOLOURMAP map) |
1023 |
{ |
{ |
1024 |
xfree(map); |
if (!owncolmap) |
1025 |
|
xfree(map); |
1026 |
|
else |
1027 |
|
XFreeColormap(display, (Colormap) map); |
1028 |
} |
} |
1029 |
|
|
1030 |
void |
void |
1031 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(HCOLOURMAP map) |
1032 |
{ |
{ |
1033 |
colmap = map; |
if (!owncolmap) |
1034 |
|
colmap = map; |
1035 |
|
else |
1036 |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
1037 |
} |
} |
1038 |
|
|
1039 |
void |
void |
1211 |
XSetStipple(display, gc, (Pixmap) glyph); |
XSetStipple(display, gc, (Pixmap) glyph); |
1212 |
XSetTSOrigin(display, gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
1213 |
|
|
1214 |
if (ownbackstore) |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
|
XFillRectangle(display, backstore, gc, x, y, cx, cy); |
|
|
else |
|
|
XFillRectangle(display, wnd, gc, x, y, cx, cy); |
|
1215 |
|
|
1216 |
XSetFillStyle(display, gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
1217 |
} |
} |
1240 |
}\ |
}\ |
1241 |
if (glyph != NULL)\ |
if (glyph != NULL)\ |
1242 |
{\ |
{\ |
1243 |
ui_draw_glyph (mixmode, x + (short) glyph->offset,\ |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
1244 |
y + (short) glyph->baseline,\ |
y + glyph->baseline,\ |
1245 |
glyph->width, glyph->height,\ |
glyph->width, glyph->height,\ |
1246 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
1247 |
if (flags & TEXT2_IMPLICIT_X)\ |
if (flags & TEXT2_IMPLICIT_X)\ |
1263 |
|
|
1264 |
if (boxcx > 1) |
if (boxcx > 1) |
1265 |
{ |
{ |
1266 |
FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
1267 |
} |
} |
1268 |
else if (mixmode == MIX_OPAQUE) |
else if (mixmode == MIX_OPAQUE) |
1269 |
{ |
{ |
1270 |
FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1271 |
} |
} |
1272 |
|
|
1273 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1301 |
else |
else |
1302 |
x += text[i + 2]; |
x += text[i + 2]; |
1303 |
} |
} |
|
if (i + 2 < length) |
|
|
i += 3; |
|
|
else |
|
|
i += 2; |
|
|
length -= i; |
|
|
/* this will move pointer from start to first character after FE command */ |
|
|
text = &(text[i]); |
|
|
i = 0; |
|
1304 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
1305 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
1306 |
} |
} |
1307 |
|
if (i + 2 < length) |
1308 |
|
i += 3; |
1309 |
|
else |
1310 |
|
i += 2; |
1311 |
|
length -= i; |
1312 |
|
/* this will move pointer from start to first character after FE command */ |
1313 |
|
text = &(text[i]); |
1314 |
|
i = 0; |
1315 |
break; |
break; |
1316 |
|
|
1317 |
default: |
default: |