1 /*
2  * Copyright 1993 Claude Lecommandeur.
3  */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xatom.h>
8 
9 #include "ctwm_client.h"
10 
11 Window awindow = 0x5c0000d;
12 char *awspc1 = "lecom", *awspc2 = "root";
13 
14 int
main(int argc,char * argv[])15 main(int argc, char *argv[])
16 {
17 	Display *dpy;
18 	char   **wlist, **wl, **occupation;
19 	char   *cur;
20 	int    status;
21 
22 	dpy = XOpenDisplay(NULL);
23 	if(dpy == NULL) {
24 		fprintf(stderr, "Can't open display\n");
25 		exit(1);
26 	}
27 
28 	/****************************************************************/
29 
30 	if(! CtwmIsRunning(dpy, 0)) {
31 		fprintf(stderr, "ctwm is not running\n");
32 		exit(1);
33 	}
34 
35 	/****************************************************************/
36 
37 	wlist = CtwmListWorkspaces(dpy, 0);
38 	if(wlist == NULL) {
39 		fprintf(stderr, "cannot obtain workspaces list\n");
40 		exit(1);
41 	}
42 	printf("list of workspaces : ");
43 	wl = wlist;
44 	while(*wl) {
45 		printf("\"%s\" ", *wl++);
46 	}
47 	printf("\n");
48 
49 	/****************************************************************/
50 
51 	cur = CtwmCurrentWorkspace(dpy, 0);
52 	if(cur == NULL) {
53 		fprintf(stderr, "cannot obtain current workspace\n");
54 		exit(1);
55 	}
56 	printf("current workspace : %s\n", cur);
57 
58 	/****************************************************************/
59 
60 	status = CtwmChangeWorkspace(dpy, 0, awspc1);
61 	if(! status) {
62 		fprintf(stderr, "cannot change the current workspace\n");
63 		exit(1);
64 	}
65 
66 	/****************************************************************/
67 
68 	wlist = CtwmCurrentOccupation(dpy, awindow);
69 	if(wlist == NULL) {
70 		fprintf(stderr, "cannot obtain occupation of window %lu\n", awindow);
71 		exit(1);
72 	}
73 	printf("Occupation of window %lu: ", awindow);
74 	wl = wlist;
75 	while(*wl) {
76 		printf("\"%s\" ", *wl++);
77 	}
78 	printf("\n");
79 
80 	/****************************************************************/
81 
82 	occupation = calloc(3, sizeof(char *));
83 	occupation [0] = awspc1;
84 	occupation [1] = awspc2;
85 	occupation [2] = NULL;
86 	status = CtwmSetOccupation(dpy, awindow, occupation);
87 	if(! status) {
88 		fprintf(stderr, "cannot change the occupation of window %lu\n", awindow);
89 	}
90 	printf("occupation of window %lu changed to 'lecom', 'root'\n", awindow);
91 
92 	/****************************************************************/
93 	status = CtwmAddToCurrentWorkspace(dpy, awindow);
94 	if(! status) {
95 		fprintf(stderr, "cannot change the occupation of window %lu\n", awindow);
96 	}
97 	printf("window %lu now occupy the current workspace\n", awindow);
98 }
99 
100