Changeset 1d74663 for global.c


Ignore:
Timestamp:
Sep 18, 2010, 5:07:39 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
cb81570
Parents:
818f19c
git-author:
David Benjamin <davidben@mit.edu> (08/07/10 16:15:02)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:39)
Message:
Add deactivate and delete hooks for owl_context

Also make pushing and popping slightly more flexible.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r818f19c r1d74663  
    174174    mode |= OWL_CTX_INTERACTIVE;
    175175  c = owl_malloc(sizeof *c);
     176  memset(c, 0, sizeof(*c));
    176177  c->mode = mode;
    177178  c->data = data;
    178179  c->cursor = cursor ? g_object_ref(cursor) : NULL;
    179180  c->keymap = owl_strdup(keymap);
     181  owl_global_push_context_obj(g, c);
     182}
     183
     184void owl_global_push_context_obj(owl_global *g, owl_context *c)
     185{
    180186  g->context_stack = g_list_prepend(g->context_stack, c);
    181187  owl_global_activate_context(g, owl_global_get_context(g));
    182188}
    183189
     190/* Pops the current context from the context stack and returns it. Caller is
     191 * responsible for freeing. */
     192owl_context *owl_global_pop_context_no_delete(owl_global *g) {
     193  owl_context *c;
     194  if (!g->context_stack)
     195    return NULL;
     196  c = owl_global_get_context(g);
     197  owl_context_deactivate(c);
     198  g->context_stack = g_list_delete_link(g->context_stack,
     199                                        g->context_stack);
     200  owl_global_activate_context(g, owl_global_get_context(g));
     201  return c;
     202}
     203
     204/* Pops the current context from the context stack and deletes it. */
    184205void owl_global_pop_context(owl_global *g) {
    185206  owl_context *c;
    186   if (!g->context_stack)
    187     return;
    188   c = owl_global_get_context(g);
    189   g->context_stack = g_list_delete_link(g->context_stack,
    190                                         g->context_stack);
    191   if (c->cursor)
    192     g_object_unref(c->cursor);
    193   owl_free(c->keymap);
    194   owl_free(c);
    195   owl_global_activate_context(g, owl_global_get_context(g));
     207  c = owl_global_pop_context_no_delete(g);
     208  if (c)
     209    owl_context_delete(c);
    196210}
    197211
Note: See TracChangeset for help on using the changeset viewer.