1/* 2 * Copyright 2003 Red Hat Inc., Durham, North Carolina. 3 * 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation on the rights to use, copy, modify, merge, 10 * publish, distribute, sublicense, and/or sell copies of the Software, 11 * and to permit persons to whom the Software is furnished to do so, 12 * subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial 16 * portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS 22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 * SOFTWARE. 26 */ 27 28/* 29 * Authors: 30 * Kevin E. Martin <kem@redhat.com> 31 * 32 */ 33 34#include <stdio.h> 35#include <stdlib.h> 36#include <X11/Xlib.h> 37#include <X11/extensions/dmxext.h> 38 39int main(int argc, char **argv) 40{ 41 Display *display = NULL; 42 int event_base; 43 int error_base; 44 int major_version, minor_version, patch_version; 45 int screen; 46 DMXScreenAttributes attr; 47 unsigned int mask = 0; 48 int status; 49 int errorScreen; 50 51 if (argc != 13) { 52 fprintf(stderr, "Usage: %s display screen scrnx scrny scrnw scrnh rootx rooty rootw rooth originx originy\n", argv[0]); 53 return -1; 54 } 55 56 if (!(display = XOpenDisplay(argv[1]))) { 57 fprintf(stderr, "Cannot open display %s\n", argv[1]); 58 return -1; 59 } 60 61 screen = strtol(argv[2], NULL, 0); 62 63 mask |= (DMXScreenWindowXoffset | 64 DMXScreenWindowYoffset | 65 DMXScreenWindowWidth | 66 DMXScreenWindowHeight); 67 attr.screenWindowXoffset = strtol(argv[3], NULL, 0); 68 attr.screenWindowYoffset = strtol(argv[4], NULL, 0); 69 attr.screenWindowWidth = strtol(argv[5], NULL, 0); 70 attr.screenWindowHeight = strtol(argv[6], NULL, 0); 71 72 mask |= (DMXRootWindowXoffset | 73 DMXRootWindowYoffset | 74 DMXRootWindowWidth | 75 DMXRootWindowHeight); 76 attr.rootWindowXoffset = strtol(argv[7], NULL, 0); 77 attr.rootWindowYoffset = strtol(argv[8], NULL, 0); 78 attr.rootWindowWidth = strtol(argv[9], NULL, 0); 79 attr.rootWindowHeight = strtol(argv[10], NULL, 0); 80 81 mask |= DMXRootWindowXorigin | DMXRootWindowYorigin; 82 attr.rootWindowXorigin = strtol(argv[11], NULL, 0); 83 attr.rootWindowYorigin = strtol(argv[12], NULL, 0); 84 85 if (!DMXQueryExtension(display, &event_base, &error_base)) { 86 fprintf(stderr, "DMX extension not present\n"); 87 return -1; 88 } 89 printf("DMX extension present: event_base = %d, error_base = %d\n", 90 event_base, error_base); 91 92 if (!DMXQueryVersion(display, 93 &major_version, &minor_version, &patch_version)) { 94 fprintf(stderr, "Could not get extension version\n"); 95 return -1; 96 } 97 printf("Extension version: %d.%d patch %d\n", 98 major_version, minor_version, patch_version); 99 100 if (major_version == 1 && minor_version < 3) { 101 fprintf(stderr, 102 "ReconfigureScreen not supported in this extension version\n"); 103 return -1; 104 } 105 106 if (major_version < 2) { 107 fprintf(stderr, 108 "ChangeScreensAttributes not supported in this extension " 109 "version\n"); 110 return -1; 111 } 112 113 if (!(status = DMXChangeScreensAttributes(display, 1, &screen, 1, &mask, 114 &attr, &errorScreen))) { 115 printf("Reconfigured screen #%d to " 116 "%dx%d%s%d%s%d %dx%d%s%d%s%d %s%d%s%d\n", 117 screen, 118 attr.screenWindowWidth, 119 attr.screenWindowHeight, 120 (attr.screenWindowXoffset < 0 ? "" : "+"), 121 attr.screenWindowXoffset, 122 (attr.screenWindowYoffset < 0 ? "" : "+"), 123 attr.screenWindowYoffset, 124 attr.rootWindowWidth, 125 attr.rootWindowHeight, 126 (attr.rootWindowXoffset < 0 ? "" : "+"), 127 attr.rootWindowXoffset, 128 (attr.rootWindowYoffset < 0 ? "" : "+"), 129 attr.rootWindowYoffset, 130 (attr.rootWindowXorigin < 0 ? "" : "+"), 131 attr.rootWindowXorigin, 132 (attr.rootWindowYorigin < 0 ? "" : "+"), 133 attr.rootWindowYorigin); 134 } else { 135 fprintf(stderr, 136 "Could not set screen #%d to " 137 "%dx%d%s%d%s%d %dx%d%s%d%s%d %s%d%s%d\n" 138 "[status = %d, errorScreen=%d]\n", 139 screen, 140 attr.screenWindowWidth, 141 attr.screenWindowHeight, 142 (attr.screenWindowXoffset < 0 ? "" : "+"), 143 attr.screenWindowXoffset, 144 (attr.screenWindowYoffset < 0 ? "" : "+"), 145 attr.screenWindowYoffset, 146 attr.rootWindowWidth, 147 attr.rootWindowHeight, 148 (attr.rootWindowXoffset < 0 ? "" : "+"), 149 attr.rootWindowXoffset, 150 (attr.rootWindowYoffset < 0 ? "" : "+"), 151 attr.rootWindowYoffset, 152 (attr.rootWindowXorigin < 0 ? "" : "+"), 153 attr.rootWindowXorigin, 154 (attr.rootWindowYorigin < 0 ? "" : "+"), 155 attr.rootWindowYorigin, 156 status, errorScreen); 157 return -1; 158 } 159 160 XCloseDisplay(display); 161 return 0; 162} 163