1a241306cSmrg#include <stdio.h>
2a241306cSmrg#include <X11/Xlib.h>
3a241306cSmrg#include <X11/Xlibint.h>
4a241306cSmrg#include <X11/Xproto.h>
5a241306cSmrg#include <X11/extensions/panoramiXproto.h>
6a241306cSmrg#include <string.h>
7a241306cSmrg#include <stdlib.h>
8a241306cSmrg
9a241306cSmrg#include "libvmwarectrl.h"
10a241306cSmrg
11a241306cSmrgint
12a241306cSmrgmain (int argc, char **argv)
13a241306cSmrg{
14a241306cSmrg   Display *dpy;
15a241306cSmrg   char *displayName = NULL;
16a241306cSmrg   int screen;
17a241306cSmrg   int major, minor;
18a241306cSmrg
19a241306cSmrg   dpy = XOpenDisplay(displayName);
20a241306cSmrg   if (!dpy) {
21a241306cSmrg      printf("Could not open default X Display\n");
22a241306cSmrg      exit(EXIT_FAILURE);
23a241306cSmrg   }
24a241306cSmrg   screen = DefaultScreen(dpy);
25a241306cSmrg
26a241306cSmrg   if (VMwareCtrl_QueryVersion(dpy, &major, &minor)) {
27a241306cSmrg      printf("Got Extension version %d.%d\n", major, minor);
28a241306cSmrg   } else {
29a241306cSmrg      printf("VMWARE_CTRL Extension not found.\n");
30a241306cSmrg      exit(EXIT_FAILURE);
31a241306cSmrg   }
32a241306cSmrg
33a241306cSmrg   if (argc >= 2) {
34a241306cSmrg      if (strcmp(argv[1], "setres") == 0) {
35a241306cSmrg         int x, y;
36a241306cSmrg         if (argc < 4) {
37a241306cSmrg            printf("Setres needs x and y too\n");
38a241306cSmrg            exit(EXIT_FAILURE);
39a241306cSmrg         }
40a241306cSmrg
41a241306cSmrg         x = atoi(argv[2]);
42a241306cSmrg         y = atoi(argv[3]);
43a241306cSmrg
44a241306cSmrg         if (VMwareCtrl_SetRes(dpy, screen, x, y)) {
45a241306cSmrg            printf("Set Res was successful\n");
46a241306cSmrg         } else {
47a241306cSmrg            printf("Set Res failed\n");
48a241306cSmrg         }
49a241306cSmrg      } else if (strcmp(argv[1], "settopology") == 0) {
50a241306cSmrg         xXineramaScreenInfo extents[2];
51a241306cSmrg
52a241306cSmrg         if (major == 0 && minor < 2) {
53a241306cSmrg            printf("VMWARE_CTRL version >= 0.2 is required\n");
54a241306cSmrg            exit(EXIT_FAILURE);
55a241306cSmrg         }
56a241306cSmrg
57a241306cSmrg         printf("Requesting hard-coded topology\n");
58a241306cSmrg
59a241306cSmrg         extents[0].x_org = 0;
60a241306cSmrg         extents[0].y_org = 0;
61a241306cSmrg         extents[0].width = 800;
62a241306cSmrg         extents[0].height = 600;
63a241306cSmrg         extents[1].x_org = 800;
64a241306cSmrg         extents[1].y_org = 0;
65a241306cSmrg         extents[1].width = 800;
66a241306cSmrg         extents[1].height = 600;
67a241306cSmrg         if (VMwareCtrl_SetTopology(dpy, screen, extents, 2)) {
68a241306cSmrg            printf("SetTopology was successful\n");
69a241306cSmrg         } else {
70a241306cSmrg            printf("SetTopology failed\n");
71a241306cSmrg         }
72a241306cSmrg      }
73a241306cSmrg   }
74a241306cSmrg
75a241306cSmrg   return EXIT_SUCCESS;
76a241306cSmrg}
77