--- sourceforge.net/trunk/rdesktop/xwin.c 2003/05/15 14:26:15 373 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/08/21 23:23:15 447 @@ -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,24 +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[]; -extern int server_bpp; +extern int g_server_bpp; extern int win_button_size; -BOOL enable_compose = False; -BOOL focused; -BOOL mouse_in_wnd; +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; @@ -85,6 +87,7 @@ } PixelColour; + #define FILL_RECTANGLE(x,y,cx,cy)\ { \ XFillRectangle(display, wnd, gc, x, y, cx, cy); \ @@ -102,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)); @@ -215,7 +218,7 @@ static uint32 translate_colour(uint32 colour) { - switch (server_bpp) + switch (g_server_bpp) { case 15: switch (bpp) @@ -413,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) @@ -567,52 +570,53 @@ 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 x, y, cx, cy; if (get_current_workarea(&x, &y, &cx, &cy) == 0) { - width = cx; - height = cy; + g_width = cx; + g_height = cy; } else { warning("Failed to get workarea: probably your window manager does not support extended hints\n"); - width = 800; - height = 600; + 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", server_bpp, bpp, depth); + printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, bpp, depth); return True; } @@ -643,12 +647,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, @@ -671,8 +675,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); } @@ -680,11 +684,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; @@ -709,8 +713,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); @@ -737,24 +741,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) @@ -787,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", @@ -833,6 +838,7 @@ break; case KeyRelease: + last_gesturetime = xevent.xkey.time; XLookupString((XKeyEvent *) & xevent, str, sizeof(str), &keysym, NULL); @@ -857,6 +863,7 @@ /* fall through */ case ButtonRelease: + last_gesturetime = xevent.xbutton.time; button = xkeymap_translate_button(xevent.xbutton.button); if (button == 0) break; @@ -870,20 +877,20 @@ /* Check from right to left: */ - if (xevent.xbutton.x >= width - win_button_size) + if (xevent.xbutton.x >= g_width - win_button_size) { /* The close button, continue */ ; } - else if (xevent.xbutton.x >= width - win_button_size * 2) + 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 + cursor or give some other visible indication that rdesktop inhibited this click */ break; } - else if (xevent.xbutton.x >= width - win_button_size * 3) + else if (xevent.xbutton.x >= g_width - win_button_size * 3) { /* The minimize button. Iconify window. */ XIconifyWindow(display, wnd, @@ -898,7 +905,7 @@ else { /* The title bar. */ - if ((xevent.type == ButtonPress) && !fullscreen + if ((xevent.type == ButtonPress) && !g_fullscreen && hide_decorations) { moving_wnd = True; @@ -923,7 +930,7 @@ break; } - if (fullscreen && !focused) + if (g_fullscreen && !g_focused) XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); rdp_send_input(time(NULL), RDP_INPUT_MOUSE, @@ -933,11 +940,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; @@ -945,7 +952,7 @@ case FocusOut: if (xevent.xfocus.mode == NotifyUngrab) break; - focused = False; + g_focused = False; if (xevent.xfocus.mode == NotifyWhileGrabbed) XUngrabKeyboard(display, CurrentTime); break; @@ -953,21 +960,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; @@ -993,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 */ @@ -1049,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); @@ -1066,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) { @@ -1137,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 */ @@ -1219,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; @@ -1297,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]; @@ -1327,7 +1347,7 @@ ui_set_colourmap(HCOLOURMAP map) { if (!owncolmap) - colmap = map; + colmap = (uint32 *) map; else XSetWindowColormap(display, wnd, (Colormap) map); } @@ -1351,8 +1371,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); } @@ -1372,12 +1392,12 @@ } 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 */ + 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 @@ -1398,7 +1418,8 @@ break; case 2: /* Hatch */ - fill = (Pixmap) ui_create_glyph(8, 8, hatch_patterns + brush->pattern[0] * 8); + fill = (Pixmap) ui_create_glyph(8, 8, + hatch_patterns + brush->pattern[0] * 8); SET_FOREGROUND(bgcolour); SET_BACKGROUND(fgcolour); XSetFillStyle(display, gc, FillOpaqueStippled);