1/* 2 * Copyright © 2000 Compaq Computer Corporation, Inc. 3 * Copyright © 2002 Hewlett-Packard Company, Inc. 4 * Copyright © 2006 Intel Corporation 5 * Copyright © 2008 Red Hat, Inc. 6 * 7 * Permission to use, copy, modify, distribute, and sell this software and its 8 * documentation for any purpose is hereby granted without fee, provided that 9 * the above copyright notice appear in all copies and that both that copyright 10 * notice and this permission notice appear in supporting documentation, and 11 * that the name of the copyright holders not be used in advertising or 12 * publicity pertaining to distribution of the software without specific, 13 * written prior permission. The copyright holders make no representations 14 * about the suitability of this software for any purpose. It is provided "as 15 * is" without express or implied warranty. 16 * 17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 23 * OF THIS SOFTWARE. 24 * 25 * Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc. 26 * Keith Packard, Intel Corporation 27 */ 28 29#ifndef _XRANDR_H_ 30#define _XRANDR_H_ 31 32#include <X11/extensions/randr.h> 33#include <X11/extensions/Xrender.h> 34 35#include <X11/Xfuncproto.h> 36 37_XFUNCPROTOBEGIN 38 39typedef XID RROutput; 40typedef XID RRCrtc; 41typedef XID RRMode; 42typedef XID RRProvider; 43 44typedef struct { 45 int width, height; 46 int mwidth, mheight; 47} XRRScreenSize; 48 49/* 50 * Events. 51 */ 52 53typedef struct { 54 int type; /* event base */ 55 unsigned long serial; /* # of last request processed by server */ 56 Bool send_event; /* true if this came from a SendEvent request */ 57 Display *display; /* Display the event was read from */ 58 Window window; /* window which selected for this event */ 59 Window root; /* Root window for changed screen */ 60 Time timestamp; /* when the screen change occurred */ 61 Time config_timestamp; /* when the last configuration change */ 62 SizeID size_index; 63 SubpixelOrder subpixel_order; 64 Rotation rotation; 65 int width; 66 int height; 67 int mwidth; 68 int mheight; 69} XRRScreenChangeNotifyEvent; 70 71typedef struct { 72 int type; /* event base */ 73 unsigned long serial; /* # of last request processed by server */ 74 Bool send_event; /* true if this came from a SendEvent request */ 75 Display *display; /* Display the event was read from */ 76 Window window; /* window which selected for this event */ 77 int subtype; /* RRNotify_ subtype */ 78} XRRNotifyEvent; 79 80typedef struct { 81 int type; /* event base */ 82 unsigned long serial; /* # of last request processed by server */ 83 Bool send_event; /* true if this came from a SendEvent request */ 84 Display *display; /* Display the event was read from */ 85 Window window; /* window which selected for this event */ 86 int subtype; /* RRNotify_OutputChange */ 87 RROutput output; /* affected output */ 88 RRCrtc crtc; /* current crtc (or None) */ 89 RRMode mode; /* current mode (or None) */ 90 Rotation rotation; /* current rotation of associated crtc */ 91 Connection connection; /* current connection status */ 92 SubpixelOrder subpixel_order; 93} XRROutputChangeNotifyEvent; 94 95typedef struct { 96 int type; /* event base */ 97 unsigned long serial; /* # of last request processed by server */ 98 Bool send_event; /* true if this came from a SendEvent request */ 99 Display *display; /* Display the event was read from */ 100 Window window; /* window which selected for this event */ 101 int subtype; /* RRNotify_CrtcChange */ 102 RRCrtc crtc; /* current crtc (or None) */ 103 RRMode mode; /* current mode (or None) */ 104 Rotation rotation; /* current rotation of associated crtc */ 105 int x, y; /* position */ 106 unsigned int width, height; /* size */ 107} XRRCrtcChangeNotifyEvent; 108 109typedef struct { 110 int type; /* event base */ 111 unsigned long serial; /* # of last request processed by server */ 112 Bool send_event; /* true if this came from a SendEvent request */ 113 Display *display; /* Display the event was read from */ 114 Window window; /* window which selected for this event */ 115 int subtype; /* RRNotify_OutputProperty */ 116 RROutput output; /* related output */ 117 Atom property; /* changed property */ 118 Time timestamp; /* time of change */ 119 int state; /* NewValue, Deleted */ 120} XRROutputPropertyNotifyEvent; 121 122typedef struct { 123 int type; /* event base */ 124 unsigned long serial; /* # of last request processed by server */ 125 Bool send_event; /* true if this came from a SendEvent request */ 126 Display *display; /* Display the event was read from */ 127 Window window; /* window which selected for this event */ 128 int subtype; /* RRNotify_ProviderChange */ 129 RRProvider provider; /* current provider (or None) */ 130 Time timestamp; /* time of change */ 131 unsigned int current_role; 132} XRRProviderChangeNotifyEvent; 133 134typedef struct { 135 int type; /* event base */ 136 unsigned long serial; /* # of last request processed by server */ 137 Bool send_event; /* true if this came from a SendEvent request */ 138 Display *display; /* Display the event was read from */ 139 Window window; /* window which selected for this event */ 140 int subtype; /* RRNotify_ProviderProperty */ 141 RRProvider provider; /* related provider */ 142 Atom property; /* changed property */ 143 Time timestamp; /* time of change */ 144 int state; /* NewValue, Deleted */ 145} XRRProviderPropertyNotifyEvent; 146 147typedef struct { 148 int type; /* event base */ 149 unsigned long serial; /* # of last request processed by server */ 150 Bool send_event; /* true if this came from a SendEvent request */ 151 Display *display; /* Display the event was read from */ 152 Window window; /* window which selected for this event */ 153 int subtype; /* RRNotify_ResourceChange */ 154 Time timestamp; /* time of change */ 155} XRRResourceChangeNotifyEvent; 156 157/* internal representation is private to the library */ 158typedef struct _XRRScreenConfiguration XRRScreenConfiguration; 159 160Bool XRRQueryExtension (Display *dpy, 161 int *event_base_return, 162 int *error_base_return); 163Status XRRQueryVersion (Display *dpy, 164 int *major_version_return, 165 int *minor_version_return); 166 167XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy, 168 Window window); 169 170void XRRFreeScreenConfigInfo (XRRScreenConfiguration *config); 171 172/* 173 * Note that screen configuration changes are only permitted if the client can 174 * prove it has up to date configuration information. We are trying to 175 * insist that it become possible for screens to change dynamically, so 176 * we want to ensure the client knows what it is talking about when requesting 177 * changes. 178 */ 179Status XRRSetScreenConfig (Display *dpy, 180 XRRScreenConfiguration *config, 181 Drawable draw, 182 int size_index, 183 Rotation rotation, 184 Time timestamp); 185 186/* added in v1.1, sorry for the lame name */ 187Status XRRSetScreenConfigAndRate (Display *dpy, 188 XRRScreenConfiguration *config, 189 Drawable draw, 190 int size_index, 191 Rotation rotation, 192 short rate, 193 Time timestamp); 194 195 196Rotation XRRConfigRotations(XRRScreenConfiguration *config, Rotation *current_rotation); 197 198Time XRRConfigTimes (XRRScreenConfiguration *config, Time *config_timestamp); 199 200XRRScreenSize *XRRConfigSizes(XRRScreenConfiguration *config, int *nsizes); 201 202short *XRRConfigRates (XRRScreenConfiguration *config, int sizeID, int *nrates); 203 204SizeID XRRConfigCurrentConfiguration (XRRScreenConfiguration *config, 205 Rotation *rotation); 206 207short XRRConfigCurrentRate (XRRScreenConfiguration *config); 208 209int XRRRootToScreen(Display *dpy, Window root); 210 211/* 212 * returns the screen configuration for the specified screen; does a lazy 213 * evaluation to delay getting the information, and caches the result. 214 * These routines should be used in preference to XRRGetScreenInfo 215 * to avoid unneeded round trips to the X server. These are new 216 * in protocol version 0.1. 217 */ 218 219 220void XRRSelectInput(Display *dpy, Window window, int mask); 221 222/* 223 * the following are always safe to call, even if RandR is not implemented 224 * on a screen 225 */ 226 227 228Rotation XRRRotations(Display *dpy, int screen, Rotation *current_rotation); 229XRRScreenSize *XRRSizes(Display *dpy, int screen, int *nsizes); 230short *XRRRates (Display *dpy, int screen, int sizeID, int *nrates); 231Time XRRTimes (Display *dpy, int screen, Time *config_timestamp); 232 233 234/* Version 1.2 additions */ 235 236Status 237XRRGetScreenSizeRange (Display *dpy, Window window, 238 int *minWidth, int *minHeight, 239 int *maxWidth, int *maxHeight); 240 241void 242XRRSetScreenSize (Display *dpy, Window window, 243 int width, int height, 244 int mmWidth, int mmHeight); 245 246typedef unsigned long XRRModeFlags; 247 248typedef struct _XRRModeInfo { 249 RRMode id; 250 unsigned int width; 251 unsigned int height; 252 unsigned long dotClock; 253 unsigned int hSyncStart; 254 unsigned int hSyncEnd; 255 unsigned int hTotal; 256 unsigned int hSkew; 257 unsigned int vSyncStart; 258 unsigned int vSyncEnd; 259 unsigned int vTotal; 260 char *name; 261 unsigned int nameLength; 262 XRRModeFlags modeFlags; 263} XRRModeInfo; 264 265typedef struct _XRRScreenResources { 266 Time timestamp; 267 Time configTimestamp; 268 int ncrtc; 269 RRCrtc *crtcs; 270 int noutput; 271 RROutput *outputs; 272 int nmode; 273 XRRModeInfo *modes; 274} XRRScreenResources; 275 276XRRScreenResources * 277XRRGetScreenResources (Display *dpy, Window window); 278 279void 280XRRFreeScreenResources (XRRScreenResources *resources); 281 282typedef struct _XRROutputInfo { 283 Time timestamp; 284 RRCrtc crtc; 285 char *name; 286 int nameLen; 287 unsigned long mm_width; 288 unsigned long mm_height; 289 Connection connection; 290 SubpixelOrder subpixel_order; 291 int ncrtc; 292 RRCrtc *crtcs; 293 int nclone; 294 RROutput *clones; 295 int nmode; 296 int npreferred; 297 RRMode *modes; 298} XRROutputInfo; 299 300XRROutputInfo * 301XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output); 302 303void 304XRRFreeOutputInfo (XRROutputInfo *outputInfo); 305 306Atom * 307XRRListOutputProperties (Display *dpy, RROutput output, int *nprop); 308 309typedef struct { 310 Bool pending; 311 Bool range; 312 Bool immutable; 313 int num_values; 314 long *values; 315} XRRPropertyInfo; 316 317XRRPropertyInfo * 318XRRQueryOutputProperty (Display *dpy, RROutput output, Atom property); 319 320void 321XRRConfigureOutputProperty (Display *dpy, RROutput output, Atom property, 322 Bool pending, Bool range, int num_values, 323 long *values); 324 325void 326XRRChangeOutputProperty (Display *dpy, RROutput output, 327 Atom property, Atom type, 328 int format, int mode, 329 _Xconst unsigned char *data, int nelements); 330 331void 332XRRDeleteOutputProperty (Display *dpy, RROutput output, Atom property); 333 334int 335XRRGetOutputProperty (Display *dpy, RROutput output, 336 Atom property, long offset, long length, 337 Bool _delete, Bool pending, Atom req_type, 338 Atom *actual_type, int *actual_format, 339 unsigned long *nitems, unsigned long *bytes_after, 340 unsigned char **prop); 341 342XRRModeInfo * 343XRRAllocModeInfo (_Xconst char *name, int nameLength); 344 345RRMode 346XRRCreateMode (Display *dpy, Window window, XRRModeInfo *modeInfo); 347 348void 349XRRDestroyMode (Display *dpy, RRMode mode); 350 351void 352XRRAddOutputMode (Display *dpy, RROutput output, RRMode mode); 353 354void 355XRRDeleteOutputMode (Display *dpy, RROutput output, RRMode mode); 356 357void 358XRRFreeModeInfo (XRRModeInfo *modeInfo); 359 360typedef struct _XRRCrtcInfo { 361 Time timestamp; 362 int x, y; 363 unsigned int width, height; 364 RRMode mode; 365 Rotation rotation; 366 int noutput; 367 RROutput *outputs; 368 Rotation rotations; 369 int npossible; 370 RROutput *possible; 371} XRRCrtcInfo; 372 373XRRCrtcInfo * 374XRRGetCrtcInfo (Display *dpy, XRRScreenResources *resources, RRCrtc crtc); 375 376void 377XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo); 378 379Status 380XRRSetCrtcConfig (Display *dpy, 381 XRRScreenResources *resources, 382 RRCrtc crtc, 383 Time timestamp, 384 int x, int y, 385 RRMode mode, 386 Rotation rotation, 387 RROutput *outputs, 388 int noutputs); 389 390int 391XRRGetCrtcGammaSize (Display *dpy, RRCrtc crtc); 392 393typedef struct _XRRCrtcGamma { 394 int size; 395 unsigned short *red; 396 unsigned short *green; 397 unsigned short *blue; 398} XRRCrtcGamma; 399 400XRRCrtcGamma * 401XRRGetCrtcGamma (Display *dpy, RRCrtc crtc); 402 403XRRCrtcGamma * 404XRRAllocGamma (int size); 405 406void 407XRRSetCrtcGamma (Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma); 408 409void 410XRRFreeGamma (XRRCrtcGamma *gamma); 411 412/* Version 1.3 additions */ 413 414XRRScreenResources * 415XRRGetScreenResourcesCurrent (Display *dpy, Window window); 416 417void 418XRRSetCrtcTransform (Display *dpy, 419 RRCrtc crtc, 420 XTransform *transform, 421 _Xconst char *filter, 422 XFixed *params, 423 int nparams); 424 425typedef struct _XRRCrtcTransformAttributes { 426 XTransform pendingTransform; 427 char *pendingFilter; 428 int pendingNparams; 429 XFixed *pendingParams; 430 XTransform currentTransform; 431 char *currentFilter; 432 int currentNparams; 433 XFixed *currentParams; 434} XRRCrtcTransformAttributes; 435 436/* 437 * Get current crtc transforms and filters. 438 * Pass *attributes to XFree to free 439 */ 440Status 441XRRGetCrtcTransform (Display *dpy, 442 RRCrtc crtc, 443 XRRCrtcTransformAttributes **attributes); 444 445/* 446 * intended to take RRScreenChangeNotify, or 447 * ConfigureNotify (on the root window) 448 * returns 1 if it is an event type it understands, 0 if not 449 */ 450int XRRUpdateConfiguration(XEvent *event); 451 452typedef struct _XRRPanning { 453 Time timestamp; 454 unsigned int left; 455 unsigned int top; 456 unsigned int width; 457 unsigned int height; 458 unsigned int track_left; 459 unsigned int track_top; 460 unsigned int track_width; 461 unsigned int track_height; 462 int border_left; 463 int border_top; 464 int border_right; 465 int border_bottom; 466} XRRPanning; 467 468XRRPanning * 469XRRGetPanning (Display *dpy, XRRScreenResources *resources, RRCrtc crtc); 470 471void 472XRRFreePanning (XRRPanning *panning); 473 474Status 475XRRSetPanning (Display *dpy, 476 XRRScreenResources *resources, 477 RRCrtc crtc, 478 XRRPanning *panning); 479 480void 481XRRSetOutputPrimary(Display *dpy, 482 Window window, 483 RROutput output); 484 485RROutput 486XRRGetOutputPrimary(Display *dpy, 487 Window window); 488 489typedef struct _XRRProviderResources { 490 Time timestamp; 491 int nproviders; 492 RRProvider *providers; 493} XRRProviderResources; 494 495XRRProviderResources * 496XRRGetProviderResources(Display *dpy, Window window); 497 498void 499XRRFreeProviderResources(XRRProviderResources *resources); 500 501typedef struct _XRRProviderInfo { 502 unsigned int capabilities; 503 int ncrtcs; 504 RRCrtc *crtcs; 505 int noutputs; 506 RROutput *outputs; 507 char *name; 508 int nassociatedproviders; 509 RRProvider *associated_providers; 510 unsigned int *associated_capability; 511 int nameLen; 512} XRRProviderInfo; 513 514XRRProviderInfo * 515XRRGetProviderInfo(Display *dpy, XRRScreenResources *resources, RRProvider provider); 516 517void 518XRRFreeProviderInfo(XRRProviderInfo *provider); 519 520int 521XRRSetProviderOutputSource(Display *dpy, XID provider, XID source_provider); 522 523int 524XRRSetProviderOffloadSink(Display *dpy, XID provider, XID sink_provider); 525 526Atom * 527XRRListProviderProperties (Display *dpy, RRProvider provider, int *nprop); 528 529XRRPropertyInfo * 530XRRQueryProviderProperty (Display *dpy, RRProvider provider, Atom property); 531 532void 533XRRConfigureProviderProperty (Display *dpy, RRProvider provider, Atom property, 534 Bool pending, Bool range, int num_values, 535 long *values); 536 537void 538XRRChangeProviderProperty (Display *dpy, RRProvider provider, 539 Atom property, Atom type, 540 int format, int mode, 541 _Xconst unsigned char *data, int nelements); 542 543void 544XRRDeleteProviderProperty (Display *dpy, RRProvider provider, Atom property); 545 546int 547XRRGetProviderProperty (Display *dpy, RRProvider provider, 548 Atom property, long offset, long length, 549 Bool _delete, Bool pending, Atom req_type, 550 Atom *actual_type, int *actual_format, 551 unsigned long *nitems, unsigned long *bytes_after, 552 unsigned char **prop); 553 554 555typedef struct _XRRMonitorInfo { 556 Atom name; 557 Bool primary; 558 Bool automatic; 559 int noutput; 560 int x; 561 int y; 562 int width; 563 int height; 564 int mwidth; 565 int mheight; 566 RROutput *outputs; 567} XRRMonitorInfo; 568 569XRRMonitorInfo * 570XRRAllocateMonitor(Display *dpy, int noutput); 571 572XRRMonitorInfo * 573XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors); 574 575void 576XRRSetMonitor(Display *dpy, Window window, XRRMonitorInfo *monitor); 577 578void 579XRRDeleteMonitor(Display *dpy, Window window, Atom name); 580 581void 582XRRFreeMonitors(XRRMonitorInfo *monitors); 583 584_XFUNCPROTOEND 585 586#endif /* _XRANDR_H_ */ 587