--- sourceforge.net/trunk/rdesktop/xwin.c 2002/11/26 10:09:14 279 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/08/27 08:21:53 448 @@ -1,4 +1,4 @@ -/* +/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. User interface services - X Window System Copyright (C) Matthew Chapman 1999-2002 @@ -23,22 +23,26 @@ #include #include #include "rdesktop.h" +#include "xproto.h" -extern int width; -extern int height; -extern BOOL sendmotion; -extern BOOL fullscreen; +extern int g_width; +extern int g_height; +extern BOOL g_sendmotion; +extern BOOL g_fullscreen; extern BOOL grab_keyboard; extern BOOL hide_decorations; extern char title[]; -BOOL enable_compose = False; -BOOL focused; -BOOL mouse_in_wnd; +extern int g_server_bpp; +extern int win_button_size; +BOOL g_enable_compose = False; +BOOL g_focused; +BOOL g_mouse_in_wnd; Display *display; +Time last_gesturetime; static int x_socket; static Screen *screen; -static Window wnd; +Window wnd; static GC gc; static Visual *visual; static int depth; @@ -57,19 +61,32 @@ static BOOL ownbackstore; static Pixmap backstore; +/* Moving in single app mode */ +static BOOL moving_wnd; +static int move_x_offset = 0; +static int move_y_offset = 0; + /* MWM decorations */ #define MWM_HINTS_DECORATIONS (1L << 1) #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 typedef struct { - unsigned long flags; - unsigned long functions; - unsigned long decorations; - long inputMode; - unsigned long status; + uint32 flags; + uint32 functions; + uint32 decorations; + sint32 inputMode; + uint32 status; } PropMotifWmHints; +typedef struct +{ + uint32 red; + uint32 green; + uint32 blue; +} +PixelColour; + #define FILL_RECTANGLE(x,y,cx,cy)\ { \ @@ -78,12 +95,17 @@ XFillRectangle(display, backstore, gc, x, y, cx, cy); \ } +#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ +{ \ + XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ +} + /* colour maps */ BOOL owncolmap = False; static Colormap xcolmap; -static uint32 *colmap; +static uint32 *colmap = NULL; -#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) +#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) #define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); #define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); @@ -109,7 +131,7 @@ #define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } #define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } -void +static void mwm_hide_decorations(void) { PropMotifWmHints motif_hints; @@ -123,7 +145,7 @@ hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); if (!hintsatom) { - 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"); return; } @@ -131,15 +153,144 @@ (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); } +static PixelColour +split_colour15(uint32 colour) +{ + PixelColour rv; + rv.red = (colour & 0x7c00) >> 10; + rv.red = (rv.red * 0xff) / 0x1f; + rv.green = (colour & 0x03e0) >> 5; + rv.green = (rv.green * 0xff) / 0x1f; + rv.blue = (colour & 0x1f); + rv.blue = (rv.blue * 0xff) / 0x1f; + return rv; +} + +static PixelColour +split_colour16(uint32 colour) +{ + PixelColour rv; + rv.red = (colour & 0xf800) >> 11; + rv.red = (rv.red * 0xff) / 0x1f; + rv.green = (colour & 0x07e0) >> 5; + rv.green = (rv.green * 0xff) / 0x3f; + rv.blue = (colour & 0x001f); + rv.blue = (rv.blue * 0xff) / 0x1f; + return rv; +} + +static PixelColour +split_colour24(uint32 colour) +{ + PixelColour rv; + rv.blue = (colour & 0xff0000) >> 16; + rv.green = (colour & 0xff00) >> 8; + rv.red = (colour & 0xff); + return rv; +} + +static uint32 +make_colour16(PixelColour pc) +{ + pc.red = (pc.red * 0x1f) / 0xff; + pc.green = (pc.green * 0x3f) / 0xff; + pc.blue = (pc.blue * 0x1f) / 0xff; + return (pc.red << 11) | (pc.green << 5) | pc.blue; +} + +static uint32 +make_colour24(PixelColour pc) +{ + return (pc.red << 16) | (pc.green << 8) | pc.blue; +} + +static uint32 +make_colour32(PixelColour pc) +{ + return (pc.red << 16) | (pc.green << 8) | pc.blue; +} + +#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } +#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } +#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ + x = (x << 16) | (x >> 16); } + +static uint32 +translate_colour(uint32 colour) +{ + switch (g_server_bpp) + { + case 15: + switch (bpp) + { + case 16: + colour = make_colour16(split_colour15(colour)); + break; + case 24: + colour = make_colour24(split_colour15(colour)); + break; + case 32: + colour = make_colour32(split_colour15(colour)); + break; + } + break; + case 16: + switch (bpp) + { + case 16: + break; + case 24: + colour = make_colour24(split_colour16(colour)); + break; + case 32: + colour = make_colour32(split_colour16(colour)); + break; + } + break; + case 24: + switch (bpp) + { + case 16: + colour = make_colour16(split_colour24(colour)); + break; + case 24: + break; + case 32: + colour = make_colour32(split_colour24(colour)); + break; + } + break; + } + switch (bpp) + { + case 16: + if (host_be != xserver_be) + BSWAP16(colour); + break; + + case 24: + if (xserver_be) + BSWAP24(colour); + break; + + case 32: + if (host_be != xserver_be) + BSWAP32(colour); + break; + } + + return colour; +} + static void -translate8(uint8 * data, uint8 * out, uint8 * end) +translate8to8(uint8 * data, uint8 * out, uint8 * end) { while (out < end) *(out++) = (uint8) colmap[*(data++)]; } static void -translate16(uint8 * data, uint16 * out, uint16 * end) +translate8to16(uint8 * data, uint16 * out, uint16 * end) { while (out < end) *(out++) = (uint16) colmap[*(data++)]; @@ -147,7 +298,7 @@ /* little endian - conversion happens when colourmap is built */ static void -translate24(uint8 * data, uint8 * out, uint8 * end) +translate8to24(uint8 * data, uint8 * out, uint8 * end) { uint32 value; @@ -161,68 +312,180 @@ } static void -translate32(uint8 * data, uint32 * out, uint32 * end) +translate8to32(uint8 * data, uint32 * out, uint32 * end) { while (out < end) *(out++) = colmap[*(data++)]; } -static uint8 * -translate_image(int width, int height, uint8 * data) +/* todo the remaining translate function might need some big endian check ?? */ + +static void +translate15to16(uint16 * data, uint16 * out, uint16 * end) { - int size = width * height * bpp / 8; - uint8 *out = xmalloc(size); - uint8 *end = out + size; + while (out < end) + *(out++) = (uint16) make_colour16(split_colour15(*(data++))); +} - switch (bpp) +static void +translate15to24(uint16 * data, uint8 * out, uint8 * end) +{ + uint32 value; + + while (out < end) { - case 8: - translate8(data, out, end); - break; + value = make_colour24(split_colour15(*(data++))); + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } +} - case 16: - translate16(data, (uint16 *) out, (uint16 *) end); - break; +static void +translate15to32(uint16 * data, uint32 * out, uint32 * end) +{ + while (out < end) + *(out++) = make_colour32(split_colour15(*(data++))); +} - case 24: - translate24(data, out, end); - break; +static void +translate16to16(uint16 * data, uint16 * out, uint16 * end) +{ + while (out < end) + *(out++) = (uint16) (*(data++)); +} - case 32: - translate32(data, (uint32 *) out, (uint32 *) end); - break; + +static void +translate16to24(uint16 * data, uint8 * out, uint8 * end) +{ + uint32 value; + + while (out < end) + { + value = make_colour24(split_colour16(*(data++))); + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; } +} - return out; +static void +translate16to32(uint16 * data, uint32 * out, uint32 * end) +{ + while (out < end) + *(out++) = make_colour32(split_colour16(*(data++))); } -#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } -#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } -#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ - x = (x << 16) | (x >> 16); } +static void +translate24to16(uint8 * data, uint16 * out, uint16 * end) +{ + uint32 pixel = 0; + while (out < end) + { + pixel = *(data++) << 16; + pixel |= *(data++) << 8; + pixel |= *(data++); + *(out++) = (uint16) make_colour16(split_colour24(pixel)); + } +} -static uint32 -translate_colour(uint32 colour) +static void +translate24to24(uint8 * data, uint8 * out, uint8 * end) { - switch (bpp) + while (out < end) { - case 16: - if (host_be != xserver_be) - BSWAP16(colour); - break; + *(out++) = (*(data++)); + } +} + +static void +translate24to32(uint8 * data, uint32 * out, uint32 * end) +{ + uint32 pixel = 0; + while (out < end) + { + pixel = *(data++); + pixel |= *(data++) << 8; + pixel |= *(data++) << 16; + *(out++) = pixel; + } +} + +static uint8 * +translate_image(int width, int height, uint8 * data) +{ + int size = width * height * bpp / 8; + uint8 *out = (uint8 *) xmalloc(size); + uint8 *end = out + size; + switch (g_server_bpp) + { case 24: - if (xserver_be) - BSWAP24(colour); + switch (bpp) + { + case 32: + translate24to32(data, (uint32 *) out, (uint32 *) end); + break; + case 24: + translate24to24(data, out, end); + break; + case 16: + translate24to16(data, (uint16 *) out, (uint16 *) end); + break; + } break; - - case 32: - if (host_be != xserver_be) - BSWAP32(colour); + case 16: + switch (bpp) + { + case 32: + translate16to32((uint16 *) data, (uint32 *) out, + (uint32 *) end); + break; + case 24: + translate16to24((uint16 *) data, out, end); + break; + case 16: + translate16to16((uint16 *) data, (uint16 *) out, + (uint16 *) end); + break; + } + break; + case 15: + switch (bpp) + { + case 32: + translate15to32((uint16 *) data, (uint32 *) out, + (uint32 *) end); + break; + case 24: + translate15to24((uint16 *) data, out, end); + break; + case 16: + translate15to16((uint16 *) data, (uint16 *) out, + (uint16 *) end); + break; + } + break; + case 8: + switch (bpp) + { + case 8: + translate8to8(data, out, end); + break; + case 16: + translate8to16(data, (uint16 *) out, (uint16 *) end); + break; + case 24: + translate8to24(data, out, end); + break; + case 32: + translate8to32(data, (uint32 *) out, (uint32 *) end); + break; + } break; } - - return colour; + return out; } BOOL @@ -295,10 +558,7 @@ { xcolmap = DefaultColormapOfScreen(screen); if (depth <= 8) - { - printf("You're using a screen depth of 8-bits or lower\n"); - printf("If you get scewed colours, try the -C switch\n"); - } + warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); } gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); @@ -310,46 +570,55 @@ host_be = !(BOOL) (*(uint8 *) (&test)); xserver_be = (ImageByteOrder(display) == MSBFirst); - if ((width == 0) || (height == 0)) + if ((g_width == 0) || (g_height == 0)) { /* Fetch geometry from _NET_WORKAREA */ - uint32 xpos, ypos; + uint32 x, y, cx, cy; - if (get_current_workarea(&xpos, &ypos, &width, &height) < 0) + if (get_current_workarea(&x, &y, &cx, &cy) == 0) + { + g_width = cx; + g_height = cy; + } + else { - error("Failed to get workarea.\n"); - error("Perhaps your window manager does not support EWMH?\n"); - error("Defaulting to geometry 800x600\n"); - width = 800; - height = 600; + warning("Failed to get workarea: probably your window manager does not support extended hints\n"); + g_width = 800; + g_height = 600; } } - if (fullscreen) + if (g_fullscreen) { - width = WidthOfScreen(screen); - height = HeightOfScreen(screen); + g_width = WidthOfScreen(screen); + g_height = HeightOfScreen(screen); } /* make sure width is a multiple of 4 */ - width = (width + 3) & ~3; + g_width = (g_width + 3) & ~3; if (ownbackstore) { backstore = - XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); + XCreatePixmap(display, RootWindowOfScreen(screen), g_width, g_height, + depth); /* clear to prevent rubbish being exposed at startup */ XSetForeground(display, gc, BlackPixelOfScreen(screen)); - XFillRectangle(display, backstore, gc, 0, 0, width, height); + XFillRectangle(display, backstore, gc, 0, 0, g_width, g_height); } mod_map = XGetModifierMapping(display); - if (enable_compose) + if (g_enable_compose) IM = XOpenIM(display, NULL, NULL, NULL); xkeymap_init(); + xclip_init(); + + /* todo take this out when high colour is done */ + printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, bpp, depth); + return True; } @@ -379,12 +648,12 @@ long input_mask, ic_input_mask; XEvent xevent; - wndwidth = fullscreen ? WidthOfScreen(screen) : width; - wndheight = fullscreen ? HeightOfScreen(screen) : height; + wndwidth = g_fullscreen ? WidthOfScreen(screen) : g_width; + wndheight = g_fullscreen ? HeightOfScreen(screen) : g_height; attribs.background_pixel = BlackPixelOfScreen(screen); attribs.backing_store = ownbackstore ? NotUseful : Always; - attribs.override_redirect = fullscreen; + attribs.override_redirect = g_fullscreen; wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight, 0, CopyFromParent, InputOutput, CopyFromParent, @@ -407,8 +676,8 @@ if (sizehints) { sizehints->flags = PMinSize | PMaxSize; - sizehints->min_width = sizehints->max_width = width; - sizehints->min_height = sizehints->max_height = height; + sizehints->min_width = sizehints->max_width = g_width; + sizehints->min_height = sizehints->max_height = g_height; XSetWMNormalHints(display, wnd, sizehints); XFree(sizehints); } @@ -416,11 +685,11 @@ input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | FocusChangeMask; - if (sendmotion) + if (g_sendmotion) input_mask |= PointerMotionMask; if (ownbackstore) input_mask |= ExposureMask; - if (fullscreen || grab_keyboard) + if (g_fullscreen || grab_keyboard) input_mask |= EnterWindowMask; if (grab_keyboard) input_mask |= LeaveWindowMask; @@ -445,8 +714,8 @@ } while (xevent.type != VisibilityNotify); - focused = False; - mouse_in_wnd = False; + g_focused = False; + g_mouse_in_wnd = False; /* handle the WM_DELETE_WINDOW protocol */ protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True); @@ -473,24 +742,24 @@ if (!ownbackstore) { /* need to save contents of window */ - contents = XCreatePixmap(display, wnd, width, height, depth); - XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0); + contents = XCreatePixmap(display, wnd, g_width, g_height, depth); + XCopyArea(display, wnd, contents, gc, 0, 0, g_width, g_height, 0, 0); } ui_destroy_window(); - fullscreen = !fullscreen; + g_fullscreen = !g_fullscreen; ui_create_window(); XDefineCursor(display, wnd, current_cursor); if (!ownbackstore) { - XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0); + XCopyArea(display, contents, wnd, gc, 0, 0, g_width, g_height, 0, 0); XFreePixmap(display, contents); } } -/* Process all events in Xlib queue +/* Process all events in Xlib queue Returns 0 after user quit, 1 otherwise */ static int xwin_process_events(void) @@ -523,18 +792,19 @@ case ClientMessage: /* the window manager told us to quit */ if ((xevent.xclient.message_type == protocol_atom) - && (xevent.xclient.data.l[0] == kill_atom)) + && ((Atom) xevent.xclient.data.l[0] == kill_atom)) /* Quit */ return 0; break; case KeyPress: + last_gesturetime = xevent.xkey.time; if (IC != NULL) /* Multi_key compatible version */ { XmbLookupString(IC, - (XKeyPressedEvent *) & - xevent, str, sizeof(str), &keysym, &status); + &xevent.xkey, str, sizeof(str), &keysym, + &status); if (!((status == XLookupKeySym) || (status == XLookupBoth))) { error("XmbLookupString failed with status 0x%x\n", @@ -569,6 +839,7 @@ break; case KeyRelease: + last_gesturetime = xevent.xkey.time; XLookupString((XKeyEvent *) & xevent, str, sizeof(str), &keysym, NULL); @@ -593,15 +864,76 @@ /* fall through */ case ButtonRelease: + last_gesturetime = xevent.xbutton.time; button = xkeymap_translate_button(xevent.xbutton.button); if (button == 0) break; + /* If win_button_size is nonzero, enable single app mode */ + if (xevent.xbutton.y < win_button_size) + { + /* Stop moving window when button is released, regardless of cursor position */ + if (moving_wnd && (xevent.type == ButtonRelease)) + moving_wnd = False; + + /* Check from right to left: */ + + if (xevent.xbutton.x >= g_width - win_button_size) + { + /* The close button, continue */ + ; + } + else if (xevent.xbutton.x >= g_width - win_button_size * 2) + { + /* The maximize/restore button. Do not send to + server. It might be a good idea to change the + cursor or give some other visible indication + that rdesktop inhibited this click */ + break; + } + else if (xevent.xbutton.x >= g_width - win_button_size * 3) + { + /* The minimize button. Iconify window. */ + XIconifyWindow(display, wnd, + DefaultScreen(display)); + break; + } + else if (xevent.xbutton.x <= win_button_size) + { + /* The system menu. Ignore. */ + break; + } + else + { + /* The title bar. */ + if ((xevent.type == ButtonPress) && !g_fullscreen + && hide_decorations) + { + moving_wnd = True; + move_x_offset = xevent.xbutton.x; + move_y_offset = xevent.xbutton.y; + } + break; + + } + } + rdp_send_input(time(NULL), RDP_INPUT_MOUSE, flags | button, xevent.xbutton.x, xevent.xbutton.y); break; case MotionNotify: + if (moving_wnd) + { + XMoveWindow(display, wnd, + xevent.xmotion.x_root - move_x_offset, + xevent.xmotion.y_root - move_y_offset); + break; + } + + if (g_fullscreen && !g_focused) + XSetInputFocus(display, wnd, RevertToPointerRoot, + CurrentTime); rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); break; @@ -609,11 +941,11 @@ case FocusIn: if (xevent.xfocus.mode == NotifyGrab) break; - focused = True; + g_focused = True; XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); reset_modifier_keys(state); - if (grab_keyboard && mouse_in_wnd) + if (grab_keyboard && g_mouse_in_wnd) XGrabKeyboard(display, wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime); break; @@ -621,7 +953,7 @@ case FocusOut: if (xevent.xfocus.mode == NotifyUngrab) break; - focused = False; + g_focused = False; if (xevent.xfocus.mode == NotifyWhileGrabbed) XUngrabKeyboard(display, CurrentTime); break; @@ -629,21 +961,21 @@ case EnterNotify: /* we only register for this event when in fullscreen mode */ /* or grab_keyboard */ - mouse_in_wnd = True; - if (fullscreen) + g_mouse_in_wnd = True; + if (g_fullscreen) { XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); break; } - if (focused) + if (g_focused) XGrabKeyboard(display, wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime); break; case LeaveNotify: /* we only register for this event when grab_keyboard */ - mouse_in_wnd = False; + g_mouse_in_wnd = False; XUngrabKeyboard(display, CurrentTime); break; @@ -669,6 +1001,19 @@ } break; + /* clipboard stuff */ + case SelectionNotify: + xclip_handle_SelectionNotify(&xevent.xselection); + break; + case SelectionRequest: + xclip_handle_SelectionRequest(&xevent.xselectionrequest); + break; + case SelectionClear: + xclip_handle_SelectionClear(); + break; + case PropertyNotify: + xclip_handle_PropertyNotify(&xevent.xproperty); + break; } } /* Keep going */ @@ -725,7 +1070,7 @@ tdata = (owncolmap ? data : translate_image(width, height, data)); bitmap = XCreatePixmap(display, wnd, width, height, depth); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, 8, 0); + (char *) tdata, width, height, g_server_bpp == 8 ? 8 : bpp, 0); XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); @@ -740,10 +1085,9 @@ { XImage *image; uint8 *tdata; - tdata = (owncolmap ? data : translate_image(width, height, data)); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, 8, 0); + (char *) tdata, width, height, g_server_bpp == 8 ? 8 : bpp, 0); if (ownbackstore) { @@ -814,10 +1158,10 @@ scanline = (width + 7) / 8; offset = scanline * height; - cursor = xmalloc(offset); + cursor = (uint8 *) xmalloc(offset); memset(cursor, 0, offset); - mask = xmalloc(offset); + mask = (uint8 *) xmalloc(offset); memset(mask, 0, offset); /* approximate AND and XOR masks with a monochrome X pointer */ @@ -896,7 +1240,7 @@ int i, ncolours = colours->ncolours; if (!owncolmap) { - uint32 *map = xmalloc(sizeof(*colmap) * ncolours); + uint32 *map = (uint32 *) xmalloc(sizeof(*colmap) * ncolours); XColor xentry; XColor xc_cache[256]; uint32 colour; @@ -974,7 +1318,7 @@ XColor *xcolours, *xentry; Colormap map; - xcolours = xmalloc(sizeof(XColor) * ncolours); + xcolours = (XColor *) xmalloc(sizeof(XColor) * ncolours); for (i = 0; i < ncolours; i++) { entry = &colours->colours[i]; @@ -1004,7 +1348,12 @@ ui_set_colourmap(HCOLOURMAP map) { if (!owncolmap) - colmap = map; + { + if (colmap) + xfree(colmap); + + colmap = (uint32 *) map; + } else XSetWindowColormap(display, wnd, (Colormap) map); } @@ -1028,8 +1377,8 @@ rect.x = 0; rect.y = 0; - rect.width = width; - rect.height = height; + rect.width = g_width; + rect.height = g_height; XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded); } @@ -1048,6 +1397,15 @@ RESET_FUNCTION(opcode); } +static uint8 hatch_patterns[] = { + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0 - bsHorizontal */ + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 1 - bsVertical */ + 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, /* 2 - bsFDiagonal */ + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, /* 3 - bsBDiagonal */ + 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, /* 4 - bsCross */ + 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 /* 5 - bsDiagCross */ +}; + void ui_patblt(uint8 opcode, /* dest */ int x, int y, int cx, int cy, @@ -1065,6 +1423,20 @@ FILL_RECTANGLE(x, y, cx, cy); break; + case 2: /* Hatch */ + fill = (Pixmap) ui_create_glyph(8, 8, + hatch_patterns + brush->pattern[0] * 8); + SET_FOREGROUND(bgcolour); + SET_BACKGROUND(fgcolour); + XSetFillStyle(display, gc, FillOpaqueStippled); + XSetStipple(display, gc, fill); + XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin); + FILL_RECTANGLE(x, y, cx, cy); + XSetFillStyle(display, gc, FillSolid); + XSetTSOrigin(display, gc, 0, 0); + ui_destroy_glyph((HGLYPH) fill); + break; + case 3: /* Pattern */ for (i = 0; i != 8; i++) ipattern[7 - i] = brush->pattern[i]; @@ -1184,10 +1556,7 @@ XSetStipple(display, gc, (Pixmap) glyph); XSetTSOrigin(display, gc, x, y); - if (ownbackstore) - XFillRectangle(display, backstore, gc, x, y, cx, cy); - else - XFillRectangle(display, wnd, gc, x, y, cx, cy); + FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); XSetFillStyle(display, gc, FillSolid); } @@ -1216,8 +1585,8 @@ }\ if (glyph != NULL)\ {\ - ui_draw_glyph (mixmode, x + (short) glyph->offset,\ - y + (short) glyph->baseline,\ + ui_draw_glyph (mixmode, x + glyph->offset,\ + y + glyph->baseline,\ glyph->width, glyph->height,\ glyph->pixmap, 0, 0, bgcolour, fgcolour);\ if (flags & TEXT2_IMPLICIT_X)\ @@ -1239,11 +1608,11 @@ if (boxcx > 1) { - FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); + FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); } else if (mixmode == MIX_OPAQUE) { - FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); + FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); } /* Paint text, character by character */ @@ -1277,17 +1646,17 @@ else x += text[i + 2]; } - 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; for (j = 0; j < entry->size; j++) DO_GLYPH(((uint8 *) (entry->data)), j); } + 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; break; default: