wmfs: Add signal handler for SIGTERM and SIGINT

This commit is contained in:
Martin Duquesnoy 2008-11-09 04:58:10 +01:00
parent 0a15b3ba6f
commit bd2b1b83b0
4 changed files with 59 additions and 19 deletions

View File

@ -468,7 +468,6 @@ client_unmanage(Client *c)
* and set the withdraw state */
client_detach(c);
setwinstate(c->win, WithdrawnState);
XDestroySubwindows(dpy, c->frame);
XDestroyWindow(dpy, c->frame);
XFree(c->title);

View File

@ -306,7 +306,6 @@ propertynotify(XPropertyEvent *ev)
return;
}
void
unmapnotify(XUnmapEvent *ev)
{
@ -328,17 +327,17 @@ getevent(XEvent ev)
{
switch (ev.type)
{
case ButtonPress: buttonpress(&ev.xbutton); break;
case ButtonPress: buttonpress(&ev.xbutton); break;
case ConfigureRequest: configurerequest(&ev.xconfigurerequest); break;
case DestroyNotify: destroynotify(&ev.xdestroywindow); break;
case EnterNotify: enternotify(&ev.xcrossing); break;
case Expose: expose(&ev.xexpose); break;
case FocusIn: focusin(&ev.xfocus); break;
case KeyPress: keypress(&ev.xkey); break;
case MapRequest: maprequest(&ev.xmaprequest); break;
case MappingNotify: mapnotify(&ev.xmapping); break;
case PropertyNotify: propertynotify(&ev.xproperty); break;
case UnmapNotify: unmapnotify(&ev.xunmap); break;
case DestroyNotify: destroynotify(&ev.xdestroywindow); break;
case EnterNotify: enternotify(&ev.xcrossing); break;
case Expose: expose(&ev.xexpose); break;
case FocusIn: focusin(&ev.xfocus); break;
case KeyPress: keypress(&ev.xkey); break;
case MapRequest: maprequest(&ev.xmaprequest); break;
case MappingNotify: mapnotify(&ev.xmapping); break;
case PropertyNotify: propertynotify(&ev.xproperty); break;
case UnmapNotify: unmapnotify(&ev.xunmap); break;
}
return;

View File

@ -158,15 +158,24 @@ scan(void)
XWindowAttributes wa;
if(XQueryTree(dpy, root, &d, &d, &wins, &num))
{
for(i = 0; i < num; i++)
{
if(wins[i] && wins[i] != infobar->bar->win)
{
XGetWindowAttributes(dpy, wins[i], &wa);
if(wa.override_redirect && wa.map_state == IsViewable)
client_manage(wins[i], &wa);
}
if(!XGetWindowAttributes(dpy, wins[i], &wa)
|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d))
continue;
if(wa.map_state == IsViewable || getwinstate(wins[i]) == IconicState)
client_manage(wins[i], &wa);
}
for(i = 0; i < num; i++)
{
if(!XGetWindowAttributes(dpy, wins[i], &wa))
continue;
if(XGetTransientForHint(dpy, wins[i], &d)
&& (wa.map_state == IsViewable || getwinstate(wins[i]) == IconicState))
client_manage(wins[i], &wa);
}
}
XFree(wins);
arrange();
@ -174,10 +183,33 @@ scan(void)
return;
}
void
handle_signal(int signum)
{
Client *c;
if(signum == SIGTERM || signum == SIGINT)
{
XSetErrorHandler(errorhandlerdummy);
for(c = clients; c; c = c->next)
{
XReparentWindow(dpy, c->win, root, 0, 0);
XDestroySubwindows(dpy, c->frame);
XDestroyWindow(dpy, c->frame);
}
fprintf(stderr, "\nExit WMFS... Bye !!\n");
quit();
exit(EXIT_FAILURE);
}
return;
}
int
main(int argc, char **argv)
{
int i;
struct sigaction sig;
static struct option long_options[] = {
@ -222,6 +254,14 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
/* Set signal handle */
sig.sa_handler = handle_signal;
sig.sa_flags = 0;
memset(&sig.sa_mask, 0, sizeof(sigset_t));
sigaction(SIGTERM, &sig, NULL);
sigaction(SIGINT, &sig, NULL);
/* Check if an other WM is already running; set the error handler */
XSetErrorHandler(errorhandler);
XSetErrorHandler(errorhandlerdummy);
@ -231,7 +271,7 @@ main(int argc, char **argv)
init();
scan();
mainloop();
quit();
raise(SIGTERM);
XCloseDisplay(dpy);

View File

@ -39,6 +39,7 @@
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>
@ -205,6 +206,7 @@ int errorhandlerstart(Display *d, XErrorEvent *event);
void quit(void);
void mainloop(void);
void scan(void);
void handle_signal(int signum);
void uicb_quit(uicb_t);
/* Variables */