summaryrefslogtreecommitdiffstats
path: root/test.c
blob: 715c62baff4dcfb4d416c5eaaff16b5dd7856b80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "xas.h"

#include <stdlib.h>
#include <stdio.h>

#include <X11/Xatom.h>  /* XA_CARDINAL */

int 
main(int argc, char **argv)
{
  Display             *xdpy;
  int                  xscreen;
  Window               xwin_root;
  Atom                 atom, atom2;
  XasContext          *xas_ctx;
  XasCookie            cookie, cookie2, cookie3, cookie4;
  XWindowAttributes    wattr;

  if ((xdpy = XOpenDisplay(getenv("DISPLAY"))) == NULL)
    {
      fprintf(stderr, "failed to open DISPLAY\n");
      exit(-1);
    }

  xscreen   = DefaultScreen(xdpy);
  xwin_root = RootWindow(xdpy, xscreen); 
  
  xas_ctx = xas_context_new(xdpy);

  atom  = XInternAtom(xdpy, "_NET_CURRENT_DESKTOP", False);
  atom2 = XInternAtom(xdpy, "_NET_NUMBER_OF_DESKTOPS", False);

  cookie = xas_get_property(xas_ctx,
			    xwin_root,
			    atom,
			    0, 1L,
			    False,
			    XA_CARDINAL);

  /* Whack this in, in attempt to mess things up */
  XGetWindowAttributes(xdpy, xwin_root, &wattr);
  XSync(xdpy, False);

  cookie2 = xas_get_property(xas_ctx,
			     xwin_root,
			     atom2,
			     0, 1L,
			     False,
			     XA_CARDINAL);

  cookie3 = xas_get_window_attributes(xas_ctx, xwin_root);

  cookie4 = xas_get_geometry(xas_ctx, (Drawable)xwin_root);

  /* Make sure all our queued requested get processed by server */
  XSync(xdpy, False);

  { /* Now grab various results  */
    Atom               actual_type;
    int                actual_format;
    unsigned long      nitems;
    unsigned long      bytesafter;
    int               *result;

    XasWindowAttributes *attr;

    int                x_return;
    int                y_return; 
    unsigned int       width_return;
    unsigned int       height_return;
    unsigned int       border_width_return;
    unsigned int       depth_return;

    int                err;
    char               msg[255];

    xas_get_property_reply(xas_ctx,
			   cookie,
			   &actual_type,
			   &actual_format,
			   &nitems,
			   &bytesafter,
			   (unsigned char**)&result,
			   NULL);

    printf("got %li vs %li %li items, looks like %i\n", 
	   XA_CARDINAL, actual_type, nitems, *result);

    xas_get_property_reply(xas_ctx,
			   cookie2,
			   &actual_type,
			   &actual_format,
			   &nitems,
			   &bytesafter,
			   (unsigned char**)&result,
			   NULL);

    printf("got %li vs %li %li items, looks like %i\n", 
	   XA_CARDINAL, actual_type, nitems, *result);


    attr = xas_get_window_attributes_reply(xas_ctx, cookie3, &err); 

    if (attr)
      {
	printf("got window attr ok..\n");
	XFree(attr);
      }

    if (xas_get_geometry_reply (xas_ctx, cookie4,
				&x_return, 
				&y_return, 
				&width_return,
				&height_return, 
				&border_width_return,
				&depth_return,
				&err))
      {
	printf("xas_get_geometry_reply() success, x:%i, y%i, width:%i, height:%i, border:%i, depth:%i\n",
	       x_return, 
	       y_return, 
	       width_return,
	       height_return, 
	       border_width_return,
	       depth_return);
      }
    else
      {
	printf("xas_get_geometry_reply() failed.");
	if (err)
	  {
	    XGetErrorText(xdpy, err, msg, sizeof(msg));
	    printf(" Error was (%i) :'%s'\n", err, msg);
	  }
	else
	  printf("No Error set\n"); 
      }
  }

  return 0;
}