Permalink
Browse files

Push and pop contexts whenever we change context.

This allows us to get rid of the awful hack in owl_process_input_char,
and opens the path to being able to invoke popup windows from the
editwin and vice versa (In fact, you can now do so without
segfaulting, although the display layer does not yet quite do the
right thing).
  • Loading branch information...
1 parent a999d9e commit 2a17b635c6895121650446d2529f46d7e291a486 @nelhage committed Dec 30, 2009
Showing with 19 additions and 96 deletions.
  1. +5 −1 commands.c
  2. +0 −45 context.c
  3. +6 −13 functions.c
  4. +0 −6 keys.c
  5. +7 −2 owl.c
  6. +1 −0 popexec.c
  7. +0 −29 select.c
View
@@ -2664,7 +2664,7 @@ void owl_command_edit_cancel(owl_editwin *e)
owl_global_set_typwin_inactive(&g);
owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
- owl_function_activate_keymap("recv");
+ owl_global_pop_context(&g);
}
void owl_command_edit_history_prev(owl_editwin *e)
@@ -2722,6 +2722,7 @@ void owl_command_editline_done(owl_editwin *e)
owl_history_store(hist, owl_editwin_get_text(e));
owl_history_reset(hist);
owl_global_set_typwin_inactive(&g);
+ owl_global_pop_context(&g);
cmd = owl_strdup(owl_editwin_get_text(e));
owl_editwin_fullclear(e);
rv = owl_function_command(cmd);
@@ -2742,6 +2743,7 @@ void owl_command_editresponse_done(owl_editwin *e)
owl_function_run_buffercommand();
owl_global_set_typwin_inactive(&g);
+ owl_global_pop_context(&g);
owl_editwin_fullclear(e);
wnoutrefresh(owl_editwin_get_curswin(e));
owl_global_set_needrefresh(&g);
@@ -2759,6 +2761,7 @@ void owl_command_edit_done(owl_editwin *e)
owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
owl_editwin_fullclear(e);
owl_global_set_typwin_inactive(&g);
+ owl_global_pop_context(&g);
owl_global_set_needrefresh(&g);
wnoutrefresh(owl_editwin_get_curswin(e));
}
@@ -2780,6 +2783,7 @@ void owl_command_edit_done_or_delete(owl_editwin *e)
void owl_command_popless_quit(owl_viewwin *vw)
{
owl_popwin_close(owl_global_get_popwin(&g));
+ owl_global_pop_context(&g);
owl_viewwin_free(vw);
owl_global_set_needrefresh(&g);
}
View
@@ -51,48 +51,3 @@ int owl_context_is_interactive(const owl_context *ctx)
{
return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
}
-
-void owl_context_set_startup(owl_context *ctx)
-{
- SET_MODE(ctx, OWL_CTX_STARTUP);
-}
-
-void owl_context_set_readconfig(owl_context *ctx)
-{
- SET_MODE(ctx, OWL_CTX_READCONFIG);
-}
-
-void owl_context_set_interactive(owl_context *ctx)
-{
- SET_MODE(ctx, OWL_CTX_INTERACTIVE);
-}
-
-void owl_context_set_popless(owl_context *ctx, owl_viewwin *vw)
-{
- ctx->data = vw;
- SET_ACTIVE(ctx, OWL_CTX_POPLESS);
-}
-
-void owl_context_set_recv(owl_context *ctx)
-{
- SET_ACTIVE(ctx, OWL_CTX_RECV);
-}
-
-void owl_context_set_editmulti(owl_context *ctx, owl_editwin *ew)
-{
- ctx->data = ew;
- SET_ACTIVE(ctx, OWL_CTX_EDITMULTI);
-}
-
-void owl_context_set_editline(owl_context *ctx, owl_editwin *ew)
-{
- ctx->data = ew;
- SET_ACTIVE(ctx, OWL_CTX_EDITLINE);
-}
-
-void owl_context_set_editresponse(owl_context *ctx, owl_editwin *ew)
-{
- ctx->data = ew;
- SET_ACTIVE(ctx, OWL_CTX_EDITRESPONSE);
-}
-
View
@@ -300,6 +300,7 @@ void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin
owl_editwin_set_cbdata(owl_global_get_typwin(&g), data);
owl_global_set_buffercallback(&g, callback);
+ owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti");
}
static void owl_function_write_setup(const char *line, const char *noun, void (*callback)(owl_editwin *))
@@ -1300,6 +1301,7 @@ void owl_function_popless_text(const char *text)
v=owl_global_get_viewwin(&g);
owl_popwin_up(pw);
+ owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
text);
@@ -1317,6 +1319,7 @@ void owl_function_popless_fmtext(const owl_fmtext *fm)
v=owl_global_get_viewwin(&g);
owl_popwin_up(pw);
+ owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
fm);
@@ -1939,8 +1942,7 @@ void owl_function_start_command(const char *line)
owl_editwin_insert_string(tw, line);
owl_editwin_redisplay(tw, 0);
- owl_context_set_editline(owl_global_get_context(&g), tw);
- owl_function_activate_keymap("editline");
+ owl_global_push_context(&g, OWL_CTX_EDITLINE, tw, "editline");
}
void owl_function_start_question(const char *line)
@@ -1956,8 +1958,7 @@ void owl_function_start_question(const char *line)
owl_editwin_redisplay(tw, 0);
- owl_context_set_editresponse(owl_global_get_context(&g), tw);
- owl_function_activate_keymap("editresponse");
+ owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editline");
}
void owl_function_start_password(const char *line)
@@ -1974,8 +1975,7 @@ void owl_function_start_password(const char *line)
owl_editwin_redisplay(tw, 0);
- owl_context_set_editresponse(owl_global_get_context(&g), tw);
- owl_function_activate_keymap("editresponse");
+ owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse");
}
char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type)
@@ -2832,13 +2832,6 @@ void owl_function_punt(const char *filter, int direction)
}
}
-void owl_function_activate_keymap(const char *keymap)
-{
- if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) {
- owl_function_error("Unable to activate keymap '%s'", keymap);
- }
-}
-
void owl_function_show_keymaps(void)
{
owl_list l;
View
6 keys.c
@@ -311,12 +311,6 @@ void owl_keys_setup_keymaps(owl_keyhandler *kh) {
BIND_CMD("C-c", "", "no effect in this mode");
BIND_CMD("C-g", "", "no effect in this mode");
-
-
- /**********************/
-
- owl_function_activate_keymap("recv");
-
}
View
9 owl.c
@@ -537,7 +537,10 @@ int main(int argc, char **argv, char **env)
/* Initialize perl */
owl_function_debugmsg("startup: processing config file");
- owl_context_set_readconfig(owl_global_get_context(&g));
+
+ owl_global_pop_context(&g);
+ owl_global_push_context(&g, OWL_CTX_READCONFIG, NULL, NULL);
+
perlerr=owl_perlconfig_initperl(opts.configfile, &argc, &argv, &env);
if (perlerr) {
endwin();
@@ -611,7 +614,9 @@ int main(int argc, char **argv, char **env)
owl_function_error("No such style: %s", owl_global_get_default_style(&g));
owl_function_debugmsg("startup: setting context interactive");
- owl_context_set_interactive(owl_global_get_context(&g));
+
+ owl_global_pop_context(&g);
+ owl_global_push_context(&g, OWL_CTX_READCONFIG|OWL_CTX_RECV, NULL, "recv");
owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
View
@@ -26,6 +26,7 @@ owl_popexec *owl_popexec_new(const char *command)
pe->vwin=v=owl_global_get_viewwin(&g);
owl_popwin_up(pw);
+ owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
"");
View
@@ -260,37 +260,8 @@ int owl_select_aim_hack(fd_set *rfds, fd_set *wfds)
void owl_process_input_char(owl_input j)
{
int ret;
- owl_popwin *pw;
- owl_editwin *tw;
owl_global_set_lastinputtime(&g, time(NULL));
- pw=owl_global_get_popwin(&g);
- tw=owl_global_get_typwin(&g);
-
- owl_global_set_lastinputtime(&g, time(NULL));
- /* find and activate the current keymap.
- * TODO: this should really get fixed by activating
- * keymaps as we switch between windows...
- */
- if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
- owl_context_set_popless(owl_global_get_context(&g),
- owl_global_get_viewwin(&g));
- owl_function_activate_keymap("popless");
- } else if (owl_global_is_typwin_active(&g)
- && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
- /*
- owl_context_set_editline(owl_global_get_context(&g), tw);
- owl_function_activate_keymap("editline");
- */
- } else if (owl_global_is_typwin_active(&g)
- && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
- owl_context_set_editmulti(owl_global_get_context(&g), tw);
- owl_function_activate_keymap("editmulti");
- } else {
- owl_context_set_recv(owl_global_get_context(&g));
- owl_function_activate_keymap("recv");
- }
- /* now actually handle the keypress */
ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
if (ret!=0 && ret!=1) {
owl_function_makemsg("Unable to handle keypress");

0 comments on commit 2a17b63

Please sign in to comment.