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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
FvwmPipe v0.1 Copyright 1996 Matthias Ettrich
(ettrich@informatik.uni-tuebingen.de)
Permission is granted to distribute this software freely
for any purpose as long as the copyright and this
copyright notice remain intact.
Simple hacked module to control fvwm from outside.
When invoked this module creates a pipe "$HOME/.fvwmpipe.in".
Whatever you write to this pipe will be passed through to fvwm.
For example:
echo "restart" > $HOME/.fvwmpipe.in
(restarts fvwm)
or
echo "AddtoMenu \"StartMenu\" \"Emacs\" Exec emacs " > $HOME/.fvwmpipe.in
(adds emacs to the StartMenu)
or
echo "DestroyMenu \"StartMenu\" " > $HOME/.fvwmpipe.in
(destroys the StartMenu)
The module makes it possible to write config-tools for fvwm
in any language, for example TCL/TK.
The code is somewhat based on the FvwmTalk module.
*/
/* This module, and the entire NoClutter program, and the concept for
* interfacing this module to the Window Manager, are all original work
* by Robert Nation
*
* Copyright 1994, Robert Nation. No guarantees or warantees or anything
* are provided or implied in any way whatsoever. Use this program at your
* own risk. Permission to use this program for any purpose is given,
* as long as the copyright is kept intact. */
#define TRUE 1
#define FALSE
#define UPDATE_ONLY 1
#define ALL 2
#define PROP_SIZE 1024
#include "config.h"
#if HAVE_SYS_BSDTYPES
#include <sys/bsdtypes.h> /* Saul */
#endif
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/time.h>
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include "fvwmlib.h"
#include "../../fvwm/module.h"
char *MyName;
int fd_width;
int fd[2];
/***********************************************************************
*
* Procedure:
* SIGPIPE handler - SIGPIPE means fvwm is dying
*
***********************************************************************/
void DeadPipe(int nonsense)
{
fprintf(stderr,"FvwmPipe: dead pipe\n");
exit(0);
}
void Loop(int *fvwmfd){
int fd;
int res;
char s[256];
int a,i;
char* Home;
int HomeLen;
char* inpipename;
fd_set fdset;
Home = getenv("HOME");
if (Home == NULL)
Home = "./";
HomeLen = strlen(Home);
inpipename = safemalloc(HomeLen + 17);
strcpy(inpipename,Home);
strcat(inpipename,"/.fvwmpipe.in");
fd = open(inpipename, O_RDWR|O_NONBLOCK);
if (fd){
/* send an empty message to end elder FvwmPipes */
write (fd, "\n", 1);
close(fd);
}
mkfifo(inpipename, 0600);
fd = open(inpipename, O_RDONLY|O_NONBLOCK);
if (fd<0){
fprintf(stderr,"FvwmPipe: cannot create %s\n", inpipename);
exit(0);
}
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
FD_SET(fvwmfd[1], &fdset);
while (1){
select(fd_width,SELECT_TYPE_ARG234 &fdset, 0, 0, NULL);
if (FD_ISSET(fd, &fdset)){
/* read from the fvwmpipe.in and send the stuff to fvwm */
res = read(fd, s, 255);
if(res>=0) {
s[res] = '\0';
a = 0;
for (i=0; i<res;i++)
if (s[i] == '\n'){
s[i] = '\0';
SendText(fvwmfd,(s+a),0);
a = i+1;
}
}
}
else {
/* ignore what comes from fvwm but empty the pipe */
do {
res = read(fvwmfd[1], s, 99);
} while (res >= 0);
}
}
}
int main(int argc, char **argv)
{
char *temp, *s;
/* Save the program name - its used for error messages and option parsing */
temp = argv[0];
s=strrchr(argv[0], '/');
if (s != NULL)
temp = s + 1;
MyName = safemalloc(strlen(temp)+2);
strcpy(MyName,"*");
strcat(MyName, temp);
if((argc != 6)&&(argc != 7))
{
fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
VERSION);
exit(1);
}
/* Save the program name - its used for error messages and option parsing */
temp = argv[0];
s=strrchr(argv[0], '/');
if (s != NULL)
temp = s + 1;
MyName = safemalloc(strlen(temp)+2);
strcpy(MyName,"*");
strcat(MyName, temp);
/* Dead pipes mean fvwm died */
signal (SIGPIPE, DeadPipe);
fd[0] = atoi(argv[1]);
fd[1] = atoi(argv[2]);
fd_width = GetFdWidth();
Loop(fd);
return 0;
}
|