--- sourceforge.net/trunk/rdesktop/xwin.c 2003/02/10 12:58:51 318 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/08/01 17:01:58 438 @@ -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,6 +23,7 @@ #include #include #include "rdesktop.h" +#include "xproto.h" extern int width; extern int height; @@ -31,15 +32,17 @@ extern BOOL grab_keyboard; extern BOOL hide_decorations; extern char title[]; -extern int server_bpp; +extern int g_server_bpp; +extern int win_button_size; BOOL enable_compose = False; BOOL focused; BOOL 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; @@ -58,6 +61,11 @@ 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 @@ -79,6 +87,7 @@ } PixelColour; + #define FILL_RECTANGLE(x,y,cx,cy)\ { \ XFillRectangle(display, wnd, gc, x, y, cx, cy); \ @@ -96,7 +105,7 @@ static Colormap xcolmap; static uint32 *colmap; -#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(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)); @@ -122,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; @@ -144,7 +153,7 @@ (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); } -PixelColour +static PixelColour split_colour15(uint32 colour) { PixelColour rv; @@ -157,7 +166,7 @@ return rv; } -PixelColour +static PixelColour split_colour16(uint32 colour) { PixelColour rv; @@ -170,7 +179,7 @@ return rv; } -PixelColour +static PixelColour split_colour24(uint32 colour) { PixelColour rv; @@ -180,7 +189,7 @@ return rv; } -uint32 +static uint32 make_colour16(PixelColour pc) { pc.red = (pc.red * 0x1f) / 0xff; @@ -189,13 +198,13 @@ return (pc.red << 11) | (pc.green << 5) | pc.blue; } -uint32 +static uint32 make_colour24(PixelColour pc) { return (pc.red << 16) | (pc.green << 8) | pc.blue; } -uint32 +static uint32 make_colour32(PixelColour pc) { return (pc.red << 16) | (pc.green << 8) | pc.blue; @@ -209,7 +218,7 @@ static uint32 translate_colour(uint32 colour) { - switch (server_bpp) + switch (g_server_bpp) { case 15: switch (bpp) @@ -396,8 +405,9 @@ uint32 pixel = 0; while (out < end) { - memcpy(&pixel, data, 3); - data += 3; + pixel = *(data++); + pixel |= *(data++) << 8; + pixel |= *(data++) << 16; *(out++) = pixel; } } @@ -406,10 +416,10 @@ translate_image(int width, int height, uint8 * data) { int size = width * height * bpp / 8; - uint8 *out = xmalloc(size); + uint8 *out = (uint8 *) xmalloc(size); uint8 *end = out + size; - switch (server_bpp) + switch (g_server_bpp) { case 24: switch (bpp) @@ -603,9 +613,10 @@ 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", server_bpp, bpp, depth); + printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, bpp, depth); return True; } @@ -780,18 +791,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", @@ -826,6 +838,7 @@ break; case KeyRelease: + last_gesturetime = xevent.xkey.time; XLookupString((XKeyEvent *) & xevent, str, sizeof(str), &keysym, NULL); @@ -850,15 +863,73 @@ /* 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 >= width - win_button_size) + { + /* The close button, continue */ + ; + } + else if (xevent.xbutton.x >= 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 >= 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) && !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 (fullscreen && !focused) XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); @@ -929,6 +1000,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 */ @@ -985,7 +1069,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, server_bpp == 8 ? 8 : bpp, 0); + (char *) tdata, width, height, g_server_bpp == 8 ? 8 : bpp, 0); XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); @@ -1002,7 +1086,7 @@ uint8 *tdata; tdata = (owncolmap ? data : translate_image(width, height, data)); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); + (char *) tdata, width, height, g_server_bpp == 8 ? 8 : bpp, 0); if (ownbackstore) { @@ -1073,10 +1157,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 */ @@ -1155,7 +1239,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; @@ -1233,7 +1317,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]; @@ -1263,7 +1347,7 @@ ui_set_colourmap(HCOLOURMAP map) { if (!owncolmap) - colmap = map; + colmap = (uint32 *) map; else XSetWindowColormap(display, wnd, (Colormap) map); } @@ -1307,6 +1391,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, @@ -1324,6 +1417,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];