Xrandr.h revision b042e37f
1/*
2 * Copyright © 2000 Compaq Computer Corporation, Inc.
3 * Copyright © 2002 Hewlett-Packard Company, Inc.
4 * Copyright © 2006 Intel Corporation
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting documentation, and
10 * that the name of the copyright holders not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission.  The copyright holders make no representations
13 * about the suitability of this software for any purpose.  It is provided "as
14 * is" without express or implied warranty.
15 *
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 *
24 * Author:  Jim Gettys, HP Labs, Hewlett-Packard, Inc.
25 *	    Keith Packard, Intel Corporation
26 */
27
28#ifndef _XRANDR_H_
29#define _XRANDR_H_
30
31#include <X11/extensions/randr.h>
32
33#include <X11/Xfuncproto.h>
34
35_XFUNCPROTOBEGIN
36
37typedef XID RROutput;
38typedef XID RRCrtc;
39typedef XID RRMode;
40
41typedef struct {
42    int	width, height;
43    int	mwidth, mheight;
44} XRRScreenSize;
45
46/*
47 *  Events.
48 */
49
50typedef struct {
51    int type;			/* event base */
52    unsigned long serial;	/* # of last request processed by server */
53    Bool send_event;		/* true if this came from a SendEvent request */
54    Display *display;		/* Display the event was read from */
55    Window window;		/* window which selected for this event */
56    Window root;		/* Root window for changed screen */
57    Time timestamp;		/* when the screen change occurred */
58    Time config_timestamp;	/* when the last configuration change */
59    SizeID size_index;
60    SubpixelOrder subpixel_order;
61    Rotation rotation;
62    int width;
63    int height;
64    int mwidth;
65    int mheight;
66} XRRScreenChangeNotifyEvent;
67
68typedef struct {
69    int type;			/* event base */
70    unsigned long serial;	/* # of last request processed by server */
71    Bool send_event;		/* true if this came from a SendEvent request */
72    Display *display;		/* Display the event was read from */
73    Window window;		/* window which selected for this event */
74    int subtype;		/* RRNotify_ subtype */
75} XRRNotifyEvent;
76
77typedef struct {
78    int type;			/* event base */
79    unsigned long serial;	/* # of last request processed by server */
80    Bool send_event;		/* true if this came from a SendEvent request */
81    Display *display;		/* Display the event was read from */
82    Window window;		/* window which selected for this event */
83    int subtype;		/* RRNotify_OutputChange */
84    RROutput output;		/* affected output */
85    RRCrtc crtc;	    	/* current crtc (or None) */
86    RRMode mode;	    	/* current mode (or None) */
87    Rotation rotation;		/* current rotation of associated crtc */
88    Connection connection;	/* current connection status */
89    SubpixelOrder subpixel_order;
90} XRROutputChangeNotifyEvent;
91
92typedef struct {
93    int type;			/* event base */
94    unsigned long serial;	/* # of last request processed by server */
95    Bool send_event;		/* true if this came from a SendEvent request */
96    Display *display;		/* Display the event was read from */
97    Window window;		/* window which selected for this event */
98    int subtype;		/* RRNotify_CrtcChange */
99    RRCrtc crtc;    		/* current crtc (or None) */
100    RRMode mode;	    	/* current mode (or None) */
101    Rotation rotation;		/* current rotation of associated crtc */
102    int x, y;			/* position */
103    unsigned int width, height;	/* size */
104} XRRCrtcChangeNotifyEvent;
105
106typedef struct {
107    int type;			/* event base */
108    unsigned long serial;	/* # of last request processed by server */
109    Bool send_event;		/* true if this came from a SendEvent request */
110    Display *display;		/* Display the event was read from */
111    Window window;		/* window which selected for this event */
112    int subtype;		/* RRNotify_OutputProperty */
113    RROutput output;		/* related output */
114    Atom property;		/* changed property */
115    Time timestamp;		/* time of change */
116    int state;			/* NewValue, Deleted */
117} XRROutputPropertyNotifyEvent;
118
119/* internal representation is private to the library */
120typedef struct _XRRScreenConfiguration XRRScreenConfiguration;
121
122Bool XRRQueryExtension (Display *dpy, int *event_basep, int *error_basep);
123Status XRRQueryVersion (Display *dpy,
124			    int     *major_versionp,
125			    int     *minor_versionp);
126
127XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy,
128					  Window window);
129
130void XRRFreeScreenConfigInfo (XRRScreenConfiguration *config);
131
132/*
133 * Note that screen configuration changes are only permitted if the client can
134 * prove it has up to date configuration information.  We are trying to
135 * insist that it become possible for screens to change dynamically, so
136 * we want to ensure the client knows what it is talking about when requesting
137 * changes.
138 */
139Status XRRSetScreenConfig (Display *dpy,
140			   XRRScreenConfiguration *config,
141			   Drawable draw,
142			   int size_index,
143			   Rotation rotation,
144			   Time timestamp);
145
146/* added in v1.1, sorry for the lame name */
147Status XRRSetScreenConfigAndRate (Display *dpy,
148				  XRRScreenConfiguration *config,
149				  Drawable draw,
150				  int size_index,
151				  Rotation rotation,
152				  short rate,
153				  Time timestamp);
154
155
156Rotation XRRConfigRotations(XRRScreenConfiguration *config, Rotation *current_rotation);
157
158Time XRRConfigTimes (XRRScreenConfiguration *config, Time *config_timestamp);
159
160XRRScreenSize *XRRConfigSizes(XRRScreenConfiguration *config, int *nsizes);
161
162short *XRRConfigRates (XRRScreenConfiguration *config, int sizeID, int *nrates);
163
164SizeID XRRConfigCurrentConfiguration (XRRScreenConfiguration *config,
165			      Rotation *rotation);
166
167short XRRConfigCurrentRate (XRRScreenConfiguration *config);
168
169int XRRRootToScreen(Display *dpy, Window root);
170
171/*
172 * returns the screen configuration for the specified screen; does a lazy
173 * evalution to delay getting the information, and caches the result.
174 * These routines should be used in preference to XRRGetScreenInfo
175 * to avoid unneeded round trips to the X server.  These are new
176 * in protocol version 0.1.
177 */
178
179
180XRRScreenConfiguration *XRRScreenConfig(Display *dpy, int screen);
181XRRScreenConfiguration *XRRConfig(Screen *screen);
182void XRRSelectInput(Display *dpy, Window window, int mask);
183
184/*
185 * the following are always safe to call, even if RandR is not implemented
186 * on a screen
187 */
188
189
190Rotation XRRRotations(Display *dpy, int screen, Rotation *current_rotation);
191XRRScreenSize *XRRSizes(Display *dpy, int screen, int *nsizes);
192short *XRRRates (Display *dpy, int screen, int sizeID, int *nrates);
193Time XRRTimes (Display *dpy, int screen, Time *config_timestamp);
194
195
196/* Version 1.2 additions */
197
198Status
199XRRGetScreenSizeRange (Display *dpy, Window window,
200		       int *minWidth, int *minHeight,
201		       int *maxWidth, int *maxHeight);
202
203void
204XRRSetScreenSize (Display *dpy, Window window,
205		  int width, int height,
206		  int mmWidth, int mmHeight);
207
208typedef unsigned long XRRModeFlags;
209
210typedef struct _XRRModeInfo {
211    RRMode		id;
212    unsigned int	width;
213    unsigned int	height;
214    unsigned long	dotClock;
215    unsigned int	hSyncStart;
216    unsigned int	hSyncEnd;
217    unsigned int	hTotal;
218    unsigned int	hSkew;
219    unsigned int	vSyncStart;
220    unsigned int	vSyncEnd;
221    unsigned int	vTotal;
222    char		*name;
223    unsigned int	nameLength;
224    XRRModeFlags	modeFlags;
225} XRRModeInfo;
226
227typedef struct _XRRScreenResources {
228    Time	timestamp;
229    Time	configTimestamp;
230    int		ncrtc;
231    RRCrtc	*crtcs;
232    int		noutput;
233    RROutput	*outputs;
234    int		nmode;
235    XRRModeInfo	*modes;
236} XRRScreenResources;
237
238XRRScreenResources *
239XRRGetScreenResources (Display *dpy, Window window);
240
241void
242XRRFreeScreenResources (XRRScreenResources *resources);
243
244typedef struct _XRROutputInfo {
245    Time	    timestamp;
246    RRCrtc	    crtc;
247    char	    *name;
248    int		    nameLen;
249    unsigned long   mm_width;
250    unsigned long   mm_height;
251    Connection	    connection;
252    SubpixelOrder   subpixel_order;
253    int		    ncrtc;
254    RRCrtc	    *crtcs;
255    int		    nclone;
256    RROutput	    *clones;
257    int		    nmode;
258    int		    npreferred;
259    RRMode	    *modes;
260} XRROutputInfo;
261
262XRROutputInfo *
263XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output);
264
265void
266XRRFreeOutputInfo (XRROutputInfo *outputInfo);
267
268Atom *
269XRRListOutputProperties (Display *dpy, RROutput output, int *nprop);
270
271typedef struct {
272    Bool    pending;
273    Bool    range;
274    Bool    immutable;
275    int	    num_values;
276    long    *values;
277} XRRPropertyInfo;
278
279XRRPropertyInfo *
280XRRQueryOutputProperty (Display *dpy, RROutput output, Atom property);
281
282void
283XRRConfigureOutputProperty (Display *dpy, RROutput output, Atom property,
284			    Bool pending, Bool range, int num_values,
285			    long *values);
286
287void
288XRRChangeOutputProperty (Display *dpy, RROutput output,
289			 Atom property, Atom type,
290			 int format, int mode,
291			 _Xconst unsigned char *data, int nelements);
292
293void
294XRRDeleteOutputProperty (Display *dpy, RROutput output, Atom property);
295
296int
297XRRGetOutputProperty (Display *dpy, RROutput output,
298		      Atom property, long offset, long length,
299		      Bool _delete, Bool pending, Atom req_type,
300		      Atom *actual_type, int *actual_format,
301		      unsigned long *nitems, unsigned long *bytes_after,
302		      unsigned char **prop);
303
304XRRModeInfo *
305XRRAllocModeInfo (char *name, int nameLength);
306
307RRMode
308XRRCreateMode (Display *dpy, Window window, XRRModeInfo *modeInfo);
309
310void
311XRRDestroyMode (Display *dpy, RRMode mode);
312
313void
314XRRAddOutputMode (Display *dpy, RROutput output, RRMode mode);
315
316void
317XRRDeleteOutputMode (Display *dpy, RROutput output, RRMode mode);
318
319void
320XRRFreeModeInfo (XRRModeInfo *modeInfo);
321
322typedef struct _XRRCrtcInfo {
323    Time	    timestamp;
324    int		    x, y;
325    unsigned int    width, height;
326    RRMode	    mode;
327    Rotation	    rotation;
328    int		    noutput;
329    RROutput	    *outputs;
330    Rotation	    rotations;
331    int		    npossible;
332    RROutput	    *possible;
333} XRRCrtcInfo;
334
335XRRCrtcInfo *
336XRRGetCrtcInfo (Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
337
338void
339XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo);
340
341Status
342XRRSetCrtcConfig (Display *dpy,
343		  XRRScreenResources *resources,
344		  RRCrtc crtc,
345		  Time timestamp,
346		  int x, int y,
347		  RRMode mode,
348		  Rotation rotation,
349		  RROutput *outputs,
350		  int noutputs);
351
352int
353XRRGetCrtcGammaSize (Display *dpy, RRCrtc crtc);
354
355typedef struct _XRRCrtcGamma {
356    int		    size;
357    unsigned short  *red;
358    unsigned short  *green;
359    unsigned short  *blue;
360} XRRCrtcGamma;
361
362XRRCrtcGamma *
363XRRGetCrtcGamma (Display *dpy, RRCrtc crtc);
364
365XRRCrtcGamma *
366XRRAllocGamma (int size);
367
368void
369XRRSetCrtcGamma (Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma);
370
371void
372XRRFreeGamma (XRRCrtcGamma *gamma);
373
374/*
375 * intended to take RRScreenChangeNotify,  or
376 * ConfigureNotify (on the root window)
377 * returns 1 if it is an event type it understands, 0 if not
378 */
379int XRRUpdateConfiguration(XEvent *event);
380
381_XFUNCPROTOEND
382
383#endif /* _XRANDR_H_ */
384