summaryrefslogtreecommitdiff
path: root/src/FvwmIvyRelay.c
blob: bc6096fe9de359b89fad9dee2c206858a2d10ea5 (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
142
143
144
145
146
147
148
149
150
151
152
/*
 *	FvwmIvyRelay, a relay between Fvwm2 and an Ivy bus 
 *
 *	Copyright (C) 2000
 *	Stéphane Chatty
 *
 * 	Main and only file
 *
 *	Authors: Stéphane Chatty <chatty@free.fr>
 *
 *	$Id$
 * 
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License
 *	as published by the Free Software Foundation; either version 2
 *	of the License, or (at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, U
SA.
 *
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>

#include "module.h"

#include "ivyloop.h"
#include "ivysocket.h"
#include "ivy.h"
#include "timer.h"


void
HandleInPipe (Channel channel, HANDLE fd, void *data)
{
	unsigned long *b;
	unsigned long header[HEADER_SIZE];

	if (ReadFvwmPacket(fd, header, &b) > 0) {
		char buf [1024];
		switch (header[1]) {
		case M_NEW_PAGE:
			sprintf (buf, "Page id=%d x=%d y=%d maxx=%d maxy=%d",
					b[2], b[0], b[1], b[3], b[4]);
			break;
		case M_NEW_DESK:
			sprintf (buf, "ChangedDesk id=%d", b[0]);
			break;
		case M_CONFIGURE_WINDOW:
		case M_ADD_WINDOW:
			sprintf (buf, "%s Window id=%d x=%d y=%d w=%d h=%d desk=%d",
					(header[1] == M_ADD_WINDOW) ? "New" : "Configured",
					b[0], b[3], b[4], b[5], b[6], b[7]);
			break;
		case M_RAISE_WINDOW:
			sprintf (buf, "Raised Window id=%d", b[0]);
			break;
		case M_LOWER_WINDOW:
			sprintf (buf, "Lower Window id=%d", b[0]);
			break;
		case M_DESTROY_WINDOW:
			sprintf (buf, "Destroyed Window id=%d", b[0]);
			break;
		case M_FOCUS_CHANGE:
		case M_ICONIFY:
		case M_DEICONIFY:
		case M_WINDOW_NAME:
		case M_ICON_NAME:
		case M_RES_CLASS:
		case M_RES_NAME:
		case M_END_WINDOWLIST:
		case M_ICON_LOCATION:
		case M_MAP:
		case M_ERROR:
		case M_CONFIG_INFO:
		case M_END_CONFIG_INFO:
		case M_ICON_FILE:
		case M_DEFAULTICON:
		case M_STRING:
		case M_MINI_ICON:
		case M_WINDOWSHADE:
		case M_DEWINDOWSHADE:
		case M_LOCKONSEND:
		case M_SENDCONFIG:
		case MAX_MESSAGES:
		default:
			sprintf (buf, "UNKNOWN");
		}
		IvySendMsg ("FVWM::0 %s", buf);
		free (b);
	}
}

void
DeadPipe (int flag)
{
	exit (flag);
}

void
callback (IvyClientPtr app, void *user_data, int argc, char **argv)
{
	SendText (user_data, argv[0], 0);
}

int
main (int argc, char *argv[])
{
	int c;
	int in, out;
	int timer_test = 0;
	char busbuf [1024] = "";
	const char* bus = 0;

	if (argc < 6) {
		fprintf (stderr, "%s should only be called by fvwm2!\n", argv[0]);
		exit (1);
	}
	in = atoi (argv[2]);
	out = atoi (argv[1]);

	while ((c = getopt(argc, argv, "d:b:w:t")) != EOF)
		switch (c) {
		case 'b':
			strcpy (busbuf, optarg);
			bus = busbuf;
			break;
		}


	IvyInit ("IVY2FVWM", "IVY2FVWM READY", 0, 0, 0, 0);
	IvyChannelSetUp (in, 0, 0, HandleInPipe);
	IvyStart (bus);

	SetMessageMask (&out, 0x00ffffff); /* a bit brutal and approximate? */
	IvyBindMsg (callback, &out, "FVWM (.*)");

	IvyMainLoop (0);
	return 0;
}