Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / dtwm / WmSignal.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* 
24  * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC. 
25  * ALL RIGHTS RESERVED 
26 */ 
27 /* 
28  * Motif Release 1.2
29 */ 
30 /*
31  * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
32
33 /*
34  * Included Files:
35  */
36
37 #include "WmGlobal.h" /* This should be the first include */
38 #include <signal.h>
39 #include <unistd.h>
40
41
42 /*
43  * include extern functions
44  */
45
46 #include "WmFeedback.h"
47 #include "WmFunction.h"
48
49
50 /*
51  * Function Declarations:
52  */
53
54 #include "WmSignal.h" 
55
56
57 /*
58  * Global Variables:
59  */
60
61
62 \f
63 /*************************************<->*************************************
64  *
65  *  AbortWmSignalHandler ()
66  *
67  *
68  *  Description:
69  *  -----------
70  *  This function is called on receipt of a fatal signal. We reset
71  *  the keyboard focus to pointer root before aborting.
72  *
73  *************************************<->***********************************/
74 static void
75 AbortWmSignalHandler (int sig)
76 {
77     struct sigaction sa;
78
79     /*
80      * Set input focus back to pointer root
81      */
82     XSetInputFocus(DISPLAY, PointerRoot, RevertToPointerRoot, CurrentTime);
83     XSync (DISPLAY, False);
84     XCloseDisplay (DISPLAY);
85
86     /*
87      * Invoke the default handler
88      */
89     (void) sigemptyset(&sa.sa_mask);
90     sa.sa_flags = 0;
91     sa.sa_handler = SIG_DFL;
92     (void) sigaction (sig, &sa, (struct sigaction *) 0);
93
94     kill (getpid(), sig);
95
96 } /* END OF FUNCTION AbortSignalHandler */
97
98 \f
99 /*************************************<->*************************************
100  *
101  *  RestoreDefaultSignalHandlers ()
102  *
103  *
104  *  Description:
105  *  -----------
106  *  This function sets up the signal handlers for the window manager.
107  *
108  *************************************<->***********************************/
109
110 void
111 RestoreDefaultSignalHandlers (void)
112 {
113     struct sigaction sa;
114     struct sigaction osa;
115
116     /*
117      * Restore default action for signals we're interested in.
118      */
119
120     (void) sigemptyset(&sa.sa_mask);
121     sa.sa_flags = 0;
122     sa.sa_handler = SIG_DFL;
123
124     if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
125         (osa.sa_handler != SIG_IGN))
126     {
127         (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
128     }
129
130     if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
131         (osa.sa_handler != SIG_IGN))
132     {
133         (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
134     }
135
136     (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
137     (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
138     (void) sigaction (SIGPIPE, &sa, (struct sigaction *) 0);
139     (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
140     (void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
141     (void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
142     (void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
143     (void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
144 #ifdef SIGSYS
145     (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
146 #endif
147 }
148
149 \f
150 /*************************************<->*************************************
151  *
152  *  SetupWmSignalHandlers ()
153  *
154  *
155  *  Description:
156  *  -----------
157  *  This function sets up the signal handlers for the window manager.
158  *
159  *************************************<->***********************************/
160
161 void SetupWmSignalHandlers (int dummy)
162 {
163     struct sigaction    sa;
164     struct sigaction    osa;
165
166     /*
167      * Catch software signals that we ask the user about
168      * before quitting.
169      */
170     (void) sigemptyset(&sa.sa_mask);
171     sa.sa_flags = 0;
172     sa.sa_handler = QuitWmSignalHandler;
173
174     if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
175         (osa.sa_handler != SIG_IGN))
176     {
177         (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
178     }
179
180     if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
181         (osa.sa_handler != SIG_IGN))
182     {
183         (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
184     }
185
186     (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
187     (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
188
189     /*
190      * Ignore child death
191      */
192
193 #ifdef SA_NOCLDWAIT
194     sa.sa_flags = SA_NOCLDWAIT;  /* Don't create zombies */
195 #else
196     sa.sa_flags = 0;
197 #endif
198     sa.sa_handler = SIG_IGN;
199     (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
200     sa.sa_flags = 0;
201
202     /* 
203      * Catch other fatal signals so we can reset the 
204      * keyboard focus to pointer root before aborting
205      */
206     sa.sa_handler = AbortWmSignalHandler;
207
208     (void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
209     (void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
210     (void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
211     (void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
212 #ifdef SIGSYS
213     (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
214 #endif
215
216 } /* END OF FUNCTION SetupWmSignalHandlers */
217
218 \f
219 /*************************************<->*************************************
220  *
221  *  QuitWmSignalHandler ()
222  *
223  *
224  *  Description:
225  *  -----------
226  *  This function is called on receipt of a signal that is to terminate the
227  *  window manager.
228  *
229  *************************************<->***********************************/
230
231 void QuitWmSignalHandler (int dummy)
232 {
233     if (wmGD.showFeedback & WM_SHOW_FB_KILL)
234     {
235         ConfirmAction (ACTIVE_PSD, QUIT_MWM_ACTION);
236         XFlush(DISPLAY);
237     }
238     else
239     {
240         Do_Quit_Mwm(False);
241     }
242
243 } /* END OF FUNCTION QuitWmSignalHandler */