xref: /OK3568_Linux_fs/external/xserver/hw/dmx/examples/dmxaddscreen.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * All Rights Reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining
7*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
8*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun  * without limitation on the rights to use, copy, modify, merge,
10*4882a593Smuzhiyun  * publish, distribute, sublicense, and/or sell copies of the Software,
11*4882a593Smuzhiyun  * and to permit persons to whom the Software is furnished to do so,
12*4882a593Smuzhiyun  * subject to the following conditions:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial
16*4882a593Smuzhiyun  * portions of the Software.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21*4882a593Smuzhiyun  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25*4882a593Smuzhiyun  * SOFTWARE.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  * Authors:
30*4882a593Smuzhiyun  *   Kevin E. Martin <kem@redhat.com>
31*4882a593Smuzhiyun  *   Rickard E. (Rik) Faith <faith@redhat.com>
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include <stdio.h>
36*4882a593Smuzhiyun #include <stdlib.h>
37*4882a593Smuzhiyun #include <X11/Xlib.h>
38*4882a593Smuzhiyun #include <X11/extensions/dmxext.h>
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun int
main(int argc,char ** argv)41*4882a593Smuzhiyun main(int argc, char **argv)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun     Display *display = NULL;
44*4882a593Smuzhiyun     int event_base;
45*4882a593Smuzhiyun     int error_base;
46*4882a593Smuzhiyun     int major_version, minor_version, patch_version;
47*4882a593Smuzhiyun     int screenNum;
48*4882a593Smuzhiyun     DMXScreenAttributes attr;
49*4882a593Smuzhiyun     unsigned int mask = 0;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun     if (argc != 4 && argc != 14) {
52*4882a593Smuzhiyun         printf
53*4882a593Smuzhiyun             ("Usage: %s display screenNum displayName [scrnx scrny scrnw scrnh rootx rooty rootw rooth originx originy]\n",
54*4882a593Smuzhiyun              argv[0]);
55*4882a593Smuzhiyun         return -1;
56*4882a593Smuzhiyun     }
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun     if (!(display = XOpenDisplay(argv[1]))) {
59*4882a593Smuzhiyun         printf("Cannot open display %s\n", argv[1]);
60*4882a593Smuzhiyun         return -1;
61*4882a593Smuzhiyun     }
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun     screenNum = strtol(argv[2], NULL, 0);
64*4882a593Smuzhiyun     if (argc == 14) {
65*4882a593Smuzhiyun         mask |= (DMXScreenWindowXoffset |
66*4882a593Smuzhiyun                  DMXScreenWindowYoffset |
67*4882a593Smuzhiyun                  DMXScreenWindowWidth | DMXScreenWindowHeight);
68*4882a593Smuzhiyun         attr.screenWindowXoffset = strtol(argv[4], NULL, 0);
69*4882a593Smuzhiyun         attr.screenWindowYoffset = strtol(argv[5], NULL, 0);
70*4882a593Smuzhiyun         attr.screenWindowWidth = strtol(argv[6], NULL, 0);
71*4882a593Smuzhiyun         attr.screenWindowHeight = strtol(argv[7], NULL, 0);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun         mask |= (DMXRootWindowXoffset |
74*4882a593Smuzhiyun                  DMXRootWindowYoffset |
75*4882a593Smuzhiyun                  DMXRootWindowWidth | DMXRootWindowHeight);
76*4882a593Smuzhiyun         attr.rootWindowXoffset = strtol(argv[8], NULL, 0);
77*4882a593Smuzhiyun         attr.rootWindowYoffset = strtol(argv[9], NULL, 0);
78*4882a593Smuzhiyun         attr.rootWindowWidth = strtol(argv[10], NULL, 0);
79*4882a593Smuzhiyun         attr.rootWindowHeight = strtol(argv[11], NULL, 0);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun         mask |= DMXRootWindowXorigin | DMXRootWindowYorigin;
82*4882a593Smuzhiyun         attr.rootWindowXorigin = strtol(argv[12], NULL, 0);
83*4882a593Smuzhiyun         attr.rootWindowYorigin = strtol(argv[13], NULL, 0);
84*4882a593Smuzhiyun     }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun     if (!DMXQueryExtension(display, &event_base, &error_base)) {
87*4882a593Smuzhiyun         printf("DMX extension not present\n");
88*4882a593Smuzhiyun         return -1;
89*4882a593Smuzhiyun     }
90*4882a593Smuzhiyun     printf("DMX extension present: event_base = %d, error_base = %d\n",
91*4882a593Smuzhiyun            event_base, error_base);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun     if (!DMXQueryVersion(display,
94*4882a593Smuzhiyun                          &major_version, &minor_version, &patch_version)) {
95*4882a593Smuzhiyun         printf("Could not get extension version\n");
96*4882a593Smuzhiyun         return -1;
97*4882a593Smuzhiyun     }
98*4882a593Smuzhiyun     printf("Extension version: %d.%d patch %d\n",
99*4882a593Smuzhiyun            major_version, minor_version, patch_version);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun     if (!DMXAddScreen(display, argv[3], mask, &attr, &screenNum))
102*4882a593Smuzhiyun         printf("Failed to add %s as screen #%d\n", argv[2], screenNum);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun     XCloseDisplay(display);
105*4882a593Smuzhiyun     return 0;
106*4882a593Smuzhiyun }
107