Somewhat streamline event loop/restart/quit handling; most notable
change allows a restart to trigger proper teardown first, even though teardown is not (yet) complete. After some discussion with oga@nicotinebsd.org regarding a more complicated version/idea.
This commit is contained in:
parent
1dbe3a3b01
commit
3b8ad25f38
@ -15,7 +15,7 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $OpenBSD: calmwm.c,v 1.83 2014/01/21 15:42:44 okan Exp $
|
||||
* $OpenBSD: calmwm.c,v 1.84 2014/01/22 21:48:27 okan Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -47,10 +47,12 @@ struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
|
||||
int HasRandr, Randr_ev;
|
||||
struct conf Conf;
|
||||
const char *homedir;
|
||||
volatile sig_atomic_t cwm_status;
|
||||
|
||||
static void sigchld_cb(int);
|
||||
static int x_errorhandler(Display *, XErrorEvent *);
|
||||
static void x_init(const char *);
|
||||
static void x_restart(void);
|
||||
static void x_teardown(void);
|
||||
static int x_wmerrorhandler(Display *, XErrorEvent *);
|
||||
|
||||
@ -111,8 +113,12 @@ main(int argc, char **argv)
|
||||
free(conf_path);
|
||||
|
||||
x_init(display_name);
|
||||
xev_loop();
|
||||
cwm_status = CWM_RUNNING;
|
||||
while (cwm_status == CWM_RUNNING)
|
||||
xev_process();
|
||||
x_teardown();
|
||||
if (cwm_status == CWM_RESTART)
|
||||
x_restart();
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -140,6 +146,13 @@ x_init(const char *dpyname)
|
||||
screen_init(i);
|
||||
}
|
||||
|
||||
static void
|
||||
x_restart(void)
|
||||
{
|
||||
(void)setsid();
|
||||
(void)execvp(cwm_argv[0], cwm_argv);
|
||||
}
|
||||
|
||||
static void
|
||||
x_teardown(void)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $OpenBSD: calmwm.h,v 1.246 2014/01/21 15:42:44 okan Exp $
|
||||
* $OpenBSD: calmwm.h,v 1.247 2014/01/22 21:48:27 okan Exp $
|
||||
*/
|
||||
|
||||
#ifndef _CALMWM_H_
|
||||
@ -85,6 +85,10 @@
|
||||
|
||||
#define CWM_WIN 0x0001
|
||||
|
||||
#define CWM_QUIT 0x0000
|
||||
#define CWM_RUNNING 0x0001
|
||||
#define CWM_RESTART 0x0002
|
||||
|
||||
union arg {
|
||||
char *c;
|
||||
int i;
|
||||
@ -327,6 +331,7 @@ extern struct client_ctx_q Clientq;
|
||||
extern struct conf Conf;
|
||||
extern const char *homedir;
|
||||
extern int HasRandr, Randr_ev;
|
||||
extern volatile sig_atomic_t cwm_status;
|
||||
|
||||
enum {
|
||||
WM_STATE,
|
||||
@ -473,11 +478,10 @@ void kbfunc_client_search(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_vmaximize(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_cmdexec(struct client_ctx *, union arg *);
|
||||
void kbfunc_cwm_status(struct client_ctx *, union arg *);
|
||||
void kbfunc_exec(struct client_ctx *, union arg *);
|
||||
void kbfunc_lock(struct client_ctx *, union arg *);
|
||||
void kbfunc_menu_search(struct client_ctx *, union arg *);
|
||||
void kbfunc_quit_wm(struct client_ctx *, union arg *);
|
||||
void kbfunc_restart(struct client_ctx *, union arg *);
|
||||
void kbfunc_ssh(struct client_ctx *, union arg *);
|
||||
void kbfunc_term(struct client_ctx *, union arg *);
|
||||
void kbfunc_tile(struct client_ctx *, union arg *);
|
||||
@ -527,7 +531,7 @@ void conf_init(struct conf *);
|
||||
void conf_ignore(struct conf *, const char *);
|
||||
void conf_screen(struct screen_ctx *);
|
||||
|
||||
void xev_loop(void);
|
||||
void xev_process(void);
|
||||
|
||||
void xu_btn_grab(Window, int, unsigned int);
|
||||
void xu_btn_ungrab(Window);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $OpenBSD: conf.c,v 1.160 2014/01/21 15:42:44 okan Exp $
|
||||
* $OpenBSD: conf.c,v 1.161 2014/01/22 21:48:27 okan Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -373,8 +373,8 @@ static const struct {
|
||||
{ "vmaximize", kbfunc_client_vmaximize, CWM_WIN, {0} },
|
||||
{ "hmaximize", kbfunc_client_hmaximize, CWM_WIN, {0} },
|
||||
{ "freeze", kbfunc_client_freeze, CWM_WIN, {0} },
|
||||
{ "restart", kbfunc_restart, 0, {0} },
|
||||
{ "quit", kbfunc_quit_wm, 0, {0} },
|
||||
{ "restart", kbfunc_cwm_status, 0, {.i = CWM_RESTART} },
|
||||
{ "quit", kbfunc_cwm_status, 0, {.i = CWM_QUIT} },
|
||||
{ "exec", kbfunc_exec, 0, {.i = CWM_EXEC_PROGRAM} },
|
||||
{ "exec_wm", kbfunc_exec, 0, {.i = CWM_EXEC_WM} },
|
||||
{ "ssh", kbfunc_ssh, 0, {0} },
|
||||
|
@ -15,7 +15,7 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $OpenBSD: kbfunc.c,v 1.90 2014/01/21 15:42:45 okan Exp $
|
||||
* $OpenBSD: kbfunc.c,v 1.91 2014/01/22 21:48:27 okan Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -35,9 +35,6 @@
|
||||
|
||||
#define HASH_MARKER "|1|"
|
||||
|
||||
extern char **cwm_argv;
|
||||
extern sig_atomic_t xev_quit;
|
||||
|
||||
void
|
||||
kbfunc_client_lower(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
@ -464,16 +461,9 @@ kbfunc_client_freeze(struct client_ctx *cc, union arg *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_quit_wm(struct client_ctx *cc, union arg *arg)
|
||||
kbfunc_cwm_status(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
xev_quit = 1;
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_restart(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
(void)setsid();
|
||||
(void)execvp(cwm_argv[0], cwm_argv);
|
||||
cwm_status = arg->i;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -15,7 +15,7 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $OpenBSD: xevents.c,v 1.105 2014/01/20 23:03:51 okan Exp $
|
||||
* $OpenBSD: xevents.c,v 1.106 2014/01/22 21:48:27 okan Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -400,18 +400,14 @@ xev_handle_expose(XEvent *ee)
|
||||
client_draw_border(cc);
|
||||
}
|
||||
|
||||
volatile sig_atomic_t xev_quit = 0;
|
||||
|
||||
void
|
||||
xev_loop(void)
|
||||
xev_process(void)
|
||||
{
|
||||
XEvent e;
|
||||
|
||||
while (xev_quit == 0) {
|
||||
XNextEvent(X_Dpy, &e);
|
||||
if (e.type - Randr_ev == RRScreenChangeNotify)
|
||||
xev_handle_randr(&e);
|
||||
else if (e.type < LASTEvent && xev_handlers[e.type] != NULL)
|
||||
(*xev_handlers[e.type])(&e);
|
||||
}
|
||||
XNextEvent(X_Dpy, &e);
|
||||
if (e.type - Randr_ev == RRScreenChangeNotify)
|
||||
xev_handle_randr(&e);
|
||||
else if (e.type < LASTEvent && xev_handlers[e.type] != NULL)
|
||||
(*xev_handlers[e.type])(&e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user