2
* $XFree86: xc/programs/xrandr/xrandr.c,v 1.12 2002/11/01 20:04:00 keithp Exp $
4
* Copyright � 2001 Keith Packard, member of The XFree86 Project, Inc.
5
* Copyright � 2002 Hewlett Pacard Company, Inc.
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
10
* copyright notice and this permission notice appear in supporting
11
* documentation, and that the name of Keith Packard or HP not be used in
12
* advertising or publicity pertaining to distribution of the software without
13
* specific, written prior permission. Keith Packard and HP makes no
14
* representations about the suitability of this software for any purpose. It
15
* is provided "as is" without express or implied warranty.
17
* KEITH PACKARD and HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19
* EVENT SHALL KEITH PACKARD 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
23
* PERFORMANCE OF THIS SOFTWARE.
25
* Blame Jim Gettys for any bugs; he wrote most of the client side code,
26
* and part of the server code for randr.
31
#include <X11/Xlibint.h>
32
#include <X11/Xproto.h>
33
#include <X11/extensions/Xrandr.h>
34
#include <X11/extensions/Xrender.h> /* we share subpixel information */
38
static char *program_name;
40
static char *direction[5] = {
48
static char *order[6] = {
60
fprintf(stderr, "usage: %s [options]\n", program_name);
61
fprintf(stderr, " where options are:\n");
62
fprintf(stderr, " -display <display> or -d <display>\n");
63
fprintf(stderr, " -help\n");
64
fprintf(stderr, " -o <normal,inverted,left,right,0,1,2,3>\n");
65
fprintf(stderr, " or --orientation <normal,inverted,left,right,0,1,2,3>\n");
66
fprintf(stderr, " -q or --query\n");
67
fprintf(stderr, " -s <size>/<width>x<height> or --size <size>/<width>x<height>\n");
68
fprintf(stderr, " -r <rate> or --rate <rate>\n");
69
fprintf(stderr, " -v or --version\n");
70
fprintf(stderr, " -x (reflect in x)\n");
71
fprintf(stderr, " -y (reflect in y)\n");
72
fprintf(stderr, " --screen <screen>\n");
73
fprintf(stderr, " --verbose\n");
80
main (int argc, char **argv)
84
XRRScreenConfiguration *sc;
89
Status status = RRSetConfigFailed;
91
int verbose = 0, query = 0;
92
Rotation rotation, current_rotation, rotations;
94
XRRScreenChangeNotifyEvent *sce;
95
char *display_name = NULL;
105
int event_base, error_base;
107
int width = 0, height = 0;
108
int have_pixel_size = 0;
110
program_name = argv[0];
111
if (argc == 1) query = 1;
112
for (i = 1; i < argc; i++) {
113
if (!strcmp ("-display", argv[i]) || !strcmp ("-d", argv[i])) {
114
if (++i>=argc) usage ();
115
display_name = argv[i];
118
if (!strcmp("-help", argv[i])) {
122
if (!strcmp ("--verbose", argv[i])) {
127
if (!strcmp ("-s", argv[i]) || !strcmp ("--size", argv[i])) {
128
if (++i>=argc) usage ();
129
if (sscanf (argv[i], "%dx%d", &width, &height) == 2)
132
size = atoi (argv[i]);
133
if (size < 0) usage();
139
if (!strcmp ("-r", argv[i]) || !strcmp ("--rate", argv[i])) {
140
if (++i>=argc) usage ();
141
rate = atoi (argv[i]);
142
if (rate < 0) usage();
147
if (!strcmp ("-v", argv[i]) || !strcmp ("--version", argv[i])) {
152
if (!strcmp ("-x", argv[i])) {
153
reflection |= RR_Reflect_X;
157
if (!strcmp ("-y", argv[i])) {
158
reflection |= RR_Reflect_Y;
162
if (!strcmp ("--screen", argv[i])) {
163
if (++i>=argc) usage ();
164
screen = atoi (argv[i]);
165
if (screen < 0) usage();
168
if (!strcmp ("-q", argv[i]) || !strcmp ("--query", argv[i])) {
172
if (!strcmp ("-o", argv[i]) || !strcmp ("--orientation", argv[i])) {
174
if (++i>=argc) usage ();
175
dirind = strtol(argv[i], &endptr, 0);
176
if (*endptr != '\0') {
177
for (dirind = 0; dirind < 4; dirind++) {
178
if (strcmp (direction[dirind], argv[i]) == 0) break;
180
if ((dirind < 0) || (dirind > 3)) usage();
188
if (verbose) query = 1;
190
dpy = XOpenDisplay (display_name);
193
fprintf (stderr, "Can't open display %s\n", display_name);
197
screen = DefaultScreen (dpy);
198
if (screen >= ScreenCount (dpy)) {
199
fprintf (stderr, "Invalid screen number %d (display has %d)\n",
200
screen, ScreenCount (dpy));
204
root = RootWindow (dpy, screen);
206
sc = XRRGetScreenInfo (dpy, root);
211
current_size = XRRConfigCurrentConfiguration (sc, ¤t_rotation);
213
sizes = XRRConfigSizes(sc, &nsize);
215
if (have_pixel_size) {
216
for (size = 0; size < nsize; size++)
218
if (sizes[size].width == width && sizes[size].height == height)
225
if (size >= nsize) usage();
229
for (rot = 0; rot < 4; rot++)
230
if (1 << rot == (current_rotation & 0xf))
234
current_rate = XRRConfigCurrentRate (sc);
238
if (size == current_size)
245
int major_version, minor_version;
246
XRRQueryVersion (dpy, &major_version, &minor_version);
247
printf("Server reports RandR version %d.%d\n",
248
major_version, minor_version);
252
printf(" SZ: Pixels Physical Refresh\n");
253
for (i = 0; i < nsize; i++) {
254
printf ("%c%-2d %5d x %-5d (%4dmm x%4dmm )",
255
i == current_size ? '*' : ' ',
256
i, sizes[i].width, sizes[i].height,
257
sizes[i].mwidth, sizes[i].mheight);
258
rates = XRRConfigRates (sc, i, &nrate);
259
if (nrate) printf (" ");
260
for (j = 0; j < nrate; j++)
262
i == current_size && rates[j] == current_rate ? '*' : ' ',
268
rotations = XRRConfigRotations(sc, ¤t_rotation);
270
rotation = 1 << rot ;
272
for (i = 0; i < 4; i ++) {
273
if ((current_rotation >> i) & 1)
274
printf("Current rotation - %s\n", direction[i]);
277
printf("Current reflection - ");
278
if (current_rotation & (RR_Reflect_X|RR_Reflect_Y))
280
if (current_rotation & RR_Reflect_X) printf ("X Axis ");
281
if (current_rotation & RR_Reflect_Y) printf ("Y Axis");
288
printf ("Rotations possible - ");
289
for (i = 0; i < 4; i ++) {
290
if ((rotations >> i) & 1) printf("%s ", direction[i]);
294
printf ("Reflections possible - ");
295
if (rotations & (RR_Reflect_X|RR_Reflect_Y))
297
if (rotations & RR_Reflect_X) printf ("X Axis ");
298
if (rotations & RR_Reflect_Y) printf ("Y Axis");
306
printf("Setting size to %d, rotation to %s\n", size, direction[rot]);
308
printf ("Setting reflection on ");
311
if (reflection & RR_Reflect_X) printf ("X Axis ");
312
if (reflection & RR_Reflect_Y) printf ("Y Axis");
315
printf ("neither axis");
318
if (reflection & RR_Reflect_X) printf("Setting reflection on X axis\n");
320
if (reflection & RR_Reflect_Y) printf("Setting reflection on Y axis\n");
323
/* we should test configureNotify on the root window */
324
XSelectInput (dpy, root, StructureNotifyMask);
326
if (setit) XRRSelectInput (dpy, root,
327
RRScreenChangeNotifyMask);
328
if (setit) status = XRRSetScreenConfigAndRate (dpy, sc,
329
DefaultRootWindow (dpy),
330
(SizeID) size, (Rotation) (rotation | reflection), rate, CurrentTime);
332
XRRQueryExtension(dpy, &event_base, &error_base);
333
if (verbose && setit) {
334
if (status == RRSetConfigSuccess)
338
XNextEvent(dpy, (XEvent *) &event);
340
printf ("Event received, type = %d\n", event.type);
341
/* update Xlib's knowledge of the event */
342
XRRUpdateConfiguration (&event);
343
if (event.type == ConfigureNotify)
344
printf("Received ConfigureNotify Event!\n");
346
switch (event.type - event_base) {
347
case RRScreenChangeNotify:
348
sce = (XRRScreenChangeNotifyEvent *) &event;
350
printf("Got a screen change notify event!\n");
351
printf(" window = %d\n root = %d\n size_index = %d\n rotation %d\n",
352
(int) sce->window, (int) sce->root,
353
sce->size_index, sce->rotation);
354
printf(" timestamp = %ld, config_timestamp = %ld\n",
355
sce->timestamp, sce->config_timestamp);
356
printf(" Rotation = %x\n", sce->rotation);
357
printf(" %d X %d pixels, %d X %d mm\n",
358
sce->width, sce->height, sce->mwidth, sce->mheight);
359
printf("Display width %d, height %d\n",
360
DisplayWidth(dpy, screen), DisplayHeight(dpy, screen));
361
printf("Display widthmm %d, heightmm %d\n",
362
DisplayWidthMM(dpy, screen), DisplayHeightMM(dpy, screen));
363
spo = sce->subpixel_order;
364
if ((spo < 0) || (spo > 5))
365
printf ("Unknown subpixel order, value = %d\n", spo);
366
else printf ("new Subpixel rendering model is %s\n", order[spo]);
369
if (event.type != ConfigureNotify)
370
printf("unknown event received, type = %d!\n", event.type);
375
XRRFreeScreenConfigInfo(sc);