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