1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * External interface to generic rootless mode 3*4882a593Smuzhiyun */ 4*4882a593Smuzhiyun /* 5*4882a593Smuzhiyun * Copyright (c) 2001 Greg Parker. All Rights Reserved. 6*4882a593Smuzhiyun * Copyright (c) 2002-2003 Torrey T. Lyons. All Rights Reserved. 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a 9*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"), 10*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation 11*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the 13*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions: 14*4882a593Smuzhiyun * 15*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in 16*4882a593Smuzhiyun * all copies or substantial portions of the Software. 17*4882a593Smuzhiyun * 18*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21*4882a593Smuzhiyun * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 22*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE. 25*4882a593Smuzhiyun * 26*4882a593Smuzhiyun * Except as contained in this notice, the name(s) of the above copyright 27*4882a593Smuzhiyun * holders shall not be used in advertising or otherwise to promote the sale, 28*4882a593Smuzhiyun * use or other dealings in this Software without prior written authorization. 29*4882a593Smuzhiyun */ 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H 32*4882a593Smuzhiyun #include <dix-config.h> 33*4882a593Smuzhiyun #endif 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun #ifndef _ROOTLESS_H 36*4882a593Smuzhiyun #define _ROOTLESS_H 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun #include "rootlessConfig.h" 39*4882a593Smuzhiyun #include "mi.h" 40*4882a593Smuzhiyun #include "gcstruct.h" 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun /* 43*4882a593Smuzhiyun Each top-level rootless window has a one-to-one correspondence to a physical 44*4882a593Smuzhiyun on-screen window. The physical window is refered to as a "frame". 45*4882a593Smuzhiyun */ 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun typedef void *RootlessFrameID; 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun /* 50*4882a593Smuzhiyun * RootlessWindowRec 51*4882a593Smuzhiyun * This structure stores the per-frame data used by the rootless code. 52*4882a593Smuzhiyun * Each top-level X window has one RootlessWindowRec associated with it. 53*4882a593Smuzhiyun */ 54*4882a593Smuzhiyun typedef struct _RootlessWindowRec { 55*4882a593Smuzhiyun // Position and size includes the window border 56*4882a593Smuzhiyun // Position is in per-screen coordinates 57*4882a593Smuzhiyun int x, y; 58*4882a593Smuzhiyun unsigned int width, height; 59*4882a593Smuzhiyun unsigned int borderWidth; 60*4882a593Smuzhiyun int level; 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun RootlessFrameID wid; // implementation specific frame id 63*4882a593Smuzhiyun WindowPtr win; // underlying X window 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun // Valid only when drawing (ie. is_drawing is set) 66*4882a593Smuzhiyun char *pixelData; 67*4882a593Smuzhiyun int bytesPerRow; 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun PixmapPtr pixmap; 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun unsigned int is_drawing:1; // Currently drawing? 72*4882a593Smuzhiyun unsigned int is_reorder_pending:1; 73*4882a593Smuzhiyun unsigned int is_offscreen:1; 74*4882a593Smuzhiyun unsigned int is_obscured:1; 75*4882a593Smuzhiyun } RootlessWindowRec, *RootlessWindowPtr; 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun /* Offset for screen-local to global coordinate transforms */ 78*4882a593Smuzhiyun extern int rootlessGlobalOffsetX; 79*4882a593Smuzhiyun extern int rootlessGlobalOffsetY; 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun /* The minimum number of bytes or pixels for which to use the 82*4882a593Smuzhiyun implementation's accelerated functions. */ 83*4882a593Smuzhiyun extern unsigned int rootless_CopyBytes_threshold; 84*4882a593Smuzhiyun extern unsigned int rootless_CopyWindow_threshold; 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun /* Gravity for window contents during resizing */ 87*4882a593Smuzhiyun enum rl_gravity_enum { 88*4882a593Smuzhiyun RL_GRAVITY_NONE = 0, /* no gravity, fill everything */ 89*4882a593Smuzhiyun RL_GRAVITY_NORTH_WEST = 1, /* anchor to top-left corner */ 90*4882a593Smuzhiyun RL_GRAVITY_NORTH_EAST = 2, /* anchor to top-right corner */ 91*4882a593Smuzhiyun RL_GRAVITY_SOUTH_EAST = 3, /* anchor to bottom-right corner */ 92*4882a593Smuzhiyun RL_GRAVITY_SOUTH_WEST = 4, /* anchor to bottom-left corner */ 93*4882a593Smuzhiyun }; 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun /*------------------------------------------ 96*4882a593Smuzhiyun Rootless Implementation Functions 97*4882a593Smuzhiyun ------------------------------------------*/ 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun /* 100*4882a593Smuzhiyun * Create a new frame. 101*4882a593Smuzhiyun * The frame is created unmapped. 102*4882a593Smuzhiyun * 103*4882a593Smuzhiyun * pFrame RootlessWindowPtr for this frame should be completely 104*4882a593Smuzhiyun * initialized before calling except for pFrame->wid, which 105*4882a593Smuzhiyun * is set by this function. 106*4882a593Smuzhiyun * pScreen Screen on which to place the new frame 107*4882a593Smuzhiyun * newX, newY Position of the frame. 108*4882a593Smuzhiyun * pNewShape Shape for the frame (in frame-local coordinates). NULL for 109*4882a593Smuzhiyun * unshaped frames. 110*4882a593Smuzhiyun */ 111*4882a593Smuzhiyun typedef Bool (*RootlessCreateFrameProc) 112*4882a593Smuzhiyun (RootlessWindowPtr pFrame, ScreenPtr pScreen, int newX, int newY, 113*4882a593Smuzhiyun RegionPtr pNewShape); 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun /* 116*4882a593Smuzhiyun * Destroy a frame. 117*4882a593Smuzhiyun * Drawing is stopped and all updates are flushed before this is called. 118*4882a593Smuzhiyun * 119*4882a593Smuzhiyun * wid Frame id 120*4882a593Smuzhiyun */ 121*4882a593Smuzhiyun typedef void (*RootlessDestroyFrameProc) 122*4882a593Smuzhiyun (RootlessFrameID wid); 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun /* 125*4882a593Smuzhiyun * Move a frame on screen. 126*4882a593Smuzhiyun * Drawing is stopped and all updates are flushed before this is called. 127*4882a593Smuzhiyun * 128*4882a593Smuzhiyun * wid Frame id 129*4882a593Smuzhiyun * pScreen Screen to move the new frame to 130*4882a593Smuzhiyun * newX, newY New position of the frame 131*4882a593Smuzhiyun */ 132*4882a593Smuzhiyun typedef void (*RootlessMoveFrameProc) 133*4882a593Smuzhiyun (RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY); 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun /* 136*4882a593Smuzhiyun * Resize and move a frame. 137*4882a593Smuzhiyun * Drawing is stopped and all updates are flushed before this is called. 138*4882a593Smuzhiyun * 139*4882a593Smuzhiyun * wid Frame id 140*4882a593Smuzhiyun * pScreen Screen to move the new frame to 141*4882a593Smuzhiyun * newX, newY New position of the frame 142*4882a593Smuzhiyun * newW, newH New size of the frame 143*4882a593Smuzhiyun * gravity Gravity for window contents (rl_gravity_enum). This is always 144*4882a593Smuzhiyun * RL_GRAVITY_NONE unless ROOTLESS_RESIZE_GRAVITY is set. 145*4882a593Smuzhiyun */ 146*4882a593Smuzhiyun typedef void (*RootlessResizeFrameProc) 147*4882a593Smuzhiyun (RootlessFrameID wid, ScreenPtr pScreen, 148*4882a593Smuzhiyun int newX, int newY, unsigned int newW, unsigned int newH, 149*4882a593Smuzhiyun unsigned int gravity); 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun /* 152*4882a593Smuzhiyun * Change frame ordering (AKA stacking, layering). 153*4882a593Smuzhiyun * Drawing is stopped before this is called. Unmapped frames are mapped by 154*4882a593Smuzhiyun * setting their ordering. 155*4882a593Smuzhiyun * 156*4882a593Smuzhiyun * wid Frame id 157*4882a593Smuzhiyun * nextWid Frame id of frame that is now above this one or NULL if this 158*4882a593Smuzhiyun * frame is at the top. 159*4882a593Smuzhiyun */ 160*4882a593Smuzhiyun typedef void (*RootlessRestackFrameProc) 161*4882a593Smuzhiyun (RootlessFrameID wid, RootlessFrameID nextWid); 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun /* 164*4882a593Smuzhiyun * Change frame's shape. 165*4882a593Smuzhiyun * Drawing is stopped before this is called. 166*4882a593Smuzhiyun * 167*4882a593Smuzhiyun * wid Frame id 168*4882a593Smuzhiyun * pNewShape New shape for the frame (in frame-local coordinates) 169*4882a593Smuzhiyun * or NULL if now unshaped. 170*4882a593Smuzhiyun */ 171*4882a593Smuzhiyun typedef void (*RootlessReshapeFrameProc) 172*4882a593Smuzhiyun (RootlessFrameID wid, RegionPtr pNewShape); 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun /* 175*4882a593Smuzhiyun * Unmap a frame. 176*4882a593Smuzhiyun * 177*4882a593Smuzhiyun * wid Frame id 178*4882a593Smuzhiyun */ 179*4882a593Smuzhiyun typedef void (*RootlessUnmapFrameProc) 180*4882a593Smuzhiyun (RootlessFrameID wid); 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun /* 183*4882a593Smuzhiyun * Start drawing to a frame. 184*4882a593Smuzhiyun * Prepare a frame for direct access to its backing buffer. 185*4882a593Smuzhiyun * 186*4882a593Smuzhiyun * wid Frame id 187*4882a593Smuzhiyun * pixelData Address of the backing buffer (returned) 188*4882a593Smuzhiyun * bytesPerRow Width in bytes of the backing buffer (returned) 189*4882a593Smuzhiyun */ 190*4882a593Smuzhiyun typedef void (*RootlessStartDrawingProc) 191*4882a593Smuzhiyun (RootlessFrameID wid, char **pixelData, int *bytesPerRow); 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun /* 194*4882a593Smuzhiyun * Stop drawing to a frame. 195*4882a593Smuzhiyun * No drawing to the frame's backing buffer will occur until drawing 196*4882a593Smuzhiyun * is started again. 197*4882a593Smuzhiyun * 198*4882a593Smuzhiyun * wid Frame id 199*4882a593Smuzhiyun * flush Flush drawing updates for this frame to the screen. 200*4882a593Smuzhiyun */ 201*4882a593Smuzhiyun typedef void (*RootlessStopDrawingProc) 202*4882a593Smuzhiyun (RootlessFrameID wid, Bool flush); 203*4882a593Smuzhiyun 204*4882a593Smuzhiyun /* 205*4882a593Smuzhiyun * Flush drawing updates to the screen. 206*4882a593Smuzhiyun * Drawing is stopped before this is called. 207*4882a593Smuzhiyun * 208*4882a593Smuzhiyun * wid Frame id 209*4882a593Smuzhiyun * pDamage Region containing all the changed pixels in frame-lcoal 210*4882a593Smuzhiyun * coordinates. This is clipped to the window's clip. 211*4882a593Smuzhiyun */ 212*4882a593Smuzhiyun typedef void (*RootlessUpdateRegionProc) 213*4882a593Smuzhiyun (RootlessFrameID wid, RegionPtr pDamage); 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun /* 216*4882a593Smuzhiyun * Mark damaged rectangles as requiring redisplay to screen. 217*4882a593Smuzhiyun * 218*4882a593Smuzhiyun * wid Frame id 219*4882a593Smuzhiyun * nrects Number of damaged rectangles 220*4882a593Smuzhiyun * rects Array of damaged rectangles in frame-local coordinates 221*4882a593Smuzhiyun * shift_x, Vector to shift rectangles by 222*4882a593Smuzhiyun * shift_y 223*4882a593Smuzhiyun */ 224*4882a593Smuzhiyun typedef void (*RootlessDamageRectsProc) 225*4882a593Smuzhiyun (RootlessFrameID wid, int nrects, const BoxRec * rects, 226*4882a593Smuzhiyun int shift_x, int shift_y); 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun /* 229*4882a593Smuzhiyun * Switch the window associated with a frame. (Optional) 230*4882a593Smuzhiyun * When a framed window is reparented, the frame is resized and set to 231*4882a593Smuzhiyun * use the new top-level parent. If defined this function will be called 232*4882a593Smuzhiyun * afterwards for implementation specific bookkeeping. 233*4882a593Smuzhiyun * 234*4882a593Smuzhiyun * pFrame Frame whose window has switched 235*4882a593Smuzhiyun * oldWin Previous window wrapped by this frame 236*4882a593Smuzhiyun */ 237*4882a593Smuzhiyun typedef void (*RootlessSwitchWindowProc) 238*4882a593Smuzhiyun (RootlessWindowPtr pFrame, WindowPtr oldWin); 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun /* 241*4882a593Smuzhiyun * Check if window should be reordered. (Optional) 242*4882a593Smuzhiyun * The underlying window system may animate windows being ordered in. 243*4882a593Smuzhiyun * We want them to be mapped but remain ordered out until the animation 244*4882a593Smuzhiyun * completes. If defined this function will be called to check if a 245*4882a593Smuzhiyun * framed window should be reordered now. If this function returns 246*4882a593Smuzhiyun * FALSE, the window will still be mapped from the X11 perspective, but 247*4882a593Smuzhiyun * the RestackFrame function will not be called for its frame. 248*4882a593Smuzhiyun * 249*4882a593Smuzhiyun * pFrame Frame to reorder 250*4882a593Smuzhiyun */ 251*4882a593Smuzhiyun typedef Bool (*RootlessDoReorderWindowProc) 252*4882a593Smuzhiyun (RootlessWindowPtr pFrame); 253*4882a593Smuzhiyun 254*4882a593Smuzhiyun /* 255*4882a593Smuzhiyun * Copy bytes. (Optional) 256*4882a593Smuzhiyun * Source and destinate may overlap and the right thing should happen. 257*4882a593Smuzhiyun * 258*4882a593Smuzhiyun * width Bytes to copy per row 259*4882a593Smuzhiyun * height Number of rows 260*4882a593Smuzhiyun * src Source data 261*4882a593Smuzhiyun * srcRowBytes Width of source in bytes 262*4882a593Smuzhiyun * dst Destination data 263*4882a593Smuzhiyun * dstRowBytes Width of destination in bytes 264*4882a593Smuzhiyun */ 265*4882a593Smuzhiyun typedef void (*RootlessCopyBytesProc) 266*4882a593Smuzhiyun (unsigned int width, unsigned int height, 267*4882a593Smuzhiyun const void *src, unsigned int srcRowBytes, 268*4882a593Smuzhiyun void *dst, unsigned int dstRowBytes); 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun /* 271*4882a593Smuzhiyun * Copy area in frame to another part of frame. (Optional) 272*4882a593Smuzhiyun * 273*4882a593Smuzhiyun * wid Frame id 274*4882a593Smuzhiyun * dstNrects Number of rectangles to copy 275*4882a593Smuzhiyun * dstRects Array of rectangles to copy 276*4882a593Smuzhiyun * dx, dy Number of pixels away to copy area 277*4882a593Smuzhiyun */ 278*4882a593Smuzhiyun typedef void (*RootlessCopyWindowProc) 279*4882a593Smuzhiyun (RootlessFrameID wid, int dstNrects, const BoxRec * dstRects, int dx, int dy); 280*4882a593Smuzhiyun 281*4882a593Smuzhiyun typedef void (*RootlessHideWindowProc) 282*4882a593Smuzhiyun (RootlessFrameID wid); 283*4882a593Smuzhiyun 284*4882a593Smuzhiyun typedef void (*RootlessUpdateColormapProc) 285*4882a593Smuzhiyun (RootlessFrameID wid, ScreenPtr pScreen); 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun /* 288*4882a593Smuzhiyun * Rootless implementation function list 289*4882a593Smuzhiyun */ 290*4882a593Smuzhiyun typedef struct _RootlessFrameProcs { 291*4882a593Smuzhiyun RootlessCreateFrameProc CreateFrame; 292*4882a593Smuzhiyun RootlessDestroyFrameProc DestroyFrame; 293*4882a593Smuzhiyun 294*4882a593Smuzhiyun RootlessMoveFrameProc MoveFrame; 295*4882a593Smuzhiyun RootlessResizeFrameProc ResizeFrame; 296*4882a593Smuzhiyun RootlessRestackFrameProc RestackFrame; 297*4882a593Smuzhiyun RootlessReshapeFrameProc ReshapeFrame; 298*4882a593Smuzhiyun RootlessUnmapFrameProc UnmapFrame; 299*4882a593Smuzhiyun 300*4882a593Smuzhiyun RootlessStartDrawingProc StartDrawing; 301*4882a593Smuzhiyun RootlessStopDrawingProc StopDrawing; 302*4882a593Smuzhiyun RootlessUpdateRegionProc UpdateRegion; 303*4882a593Smuzhiyun RootlessDamageRectsProc DamageRects; 304*4882a593Smuzhiyun 305*4882a593Smuzhiyun /* Optional frame functions */ 306*4882a593Smuzhiyun RootlessSwitchWindowProc SwitchWindow; 307*4882a593Smuzhiyun RootlessDoReorderWindowProc DoReorderWindow; 308*4882a593Smuzhiyun RootlessHideWindowProc HideWindow; 309*4882a593Smuzhiyun RootlessUpdateColormapProc UpdateColormap; 310*4882a593Smuzhiyun 311*4882a593Smuzhiyun /* Optional acceleration functions */ 312*4882a593Smuzhiyun RootlessCopyBytesProc CopyBytes; 313*4882a593Smuzhiyun RootlessCopyWindowProc CopyWindow; 314*4882a593Smuzhiyun } RootlessFrameProcsRec, *RootlessFrameProcsPtr; 315*4882a593Smuzhiyun 316*4882a593Smuzhiyun /* 317*4882a593Smuzhiyun * Initialize rootless mode on the given screen. 318*4882a593Smuzhiyun */ 319*4882a593Smuzhiyun Bool RootlessInit(ScreenPtr pScreen, RootlessFrameProcsPtr procs); 320*4882a593Smuzhiyun 321*4882a593Smuzhiyun /* 322*4882a593Smuzhiyun * Return the frame ID for the physical window displaying the given window. 323*4882a593Smuzhiyun * 324*4882a593Smuzhiyun * create If true and the window has no frame, attempt to create one 325*4882a593Smuzhiyun */ 326*4882a593Smuzhiyun RootlessFrameID RootlessFrameForWindow(WindowPtr pWin, Bool create); 327*4882a593Smuzhiyun 328*4882a593Smuzhiyun /* 329*4882a593Smuzhiyun * Return the top-level parent of a window. 330*4882a593Smuzhiyun * The root is the top-level parent of itself, even though the root is 331*4882a593Smuzhiyun * not otherwise considered to be a top-level window. 332*4882a593Smuzhiyun */ 333*4882a593Smuzhiyun WindowPtr TopLevelParent(WindowPtr pWindow); 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun /* 336*4882a593Smuzhiyun * Prepare a window for direct access to its backing buffer. 337*4882a593Smuzhiyun */ 338*4882a593Smuzhiyun void RootlessStartDrawing(WindowPtr pWindow); 339*4882a593Smuzhiyun 340*4882a593Smuzhiyun /* 341*4882a593Smuzhiyun * Finish drawing to a window's backing buffer. 342*4882a593Smuzhiyun * 343*4882a593Smuzhiyun * flush If true, damaged areas are flushed to the screen. 344*4882a593Smuzhiyun */ 345*4882a593Smuzhiyun void RootlessStopDrawing(WindowPtr pWindow, Bool flush); 346*4882a593Smuzhiyun 347*4882a593Smuzhiyun /* 348*4882a593Smuzhiyun * Alocate a new screen pixmap. 349*4882a593Smuzhiyun * miCreateScreenResources does not do this properly with a null 350*4882a593Smuzhiyun * framebuffer pointer. 351*4882a593Smuzhiyun */ 352*4882a593Smuzhiyun void RootlessUpdateScreenPixmap(ScreenPtr pScreen); 353*4882a593Smuzhiyun 354*4882a593Smuzhiyun /* 355*4882a593Smuzhiyun * Reposition all windows on a screen to their correct positions. 356*4882a593Smuzhiyun */ 357*4882a593Smuzhiyun void RootlessRepositionWindows(ScreenPtr pScreen); 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun /* 360*4882a593Smuzhiyun * Bring all windows to the front of the native stack 361*4882a593Smuzhiyun */ 362*4882a593Smuzhiyun void RootlessOrderAllWindows(Bool include_unhitable); 363*4882a593Smuzhiyun #endif /* _ROOTLESS_H */ 364