release-1.10release-1.7release-1.8release-1.9
|
Last change
on this file since 1b8c3f8 was
c394de8,
checked in by David Benjamin <davidben@mit.edu>, 16 years ago
|
|
Use ref-counting to make editwin ownership saner
When creating an editwin, one creates an editcontext which takes a
reference to the editwin. Likewise, the pointer in owl_global holds
reference. The reference counting manages their ownership claims. In
addition, owl_global_set_typwin_inactive now does release a reference.
Instead, the callback-calling commands take a reference and release it
later. We may wish to further improve that so that the contexts are also
ref-counted such that, when their commands are running, they will not be
deallocated, even if popped. That will avoid the callback dance.
|
-
Property mode set to
100644
|
|
File size:
767 bytes
|
| Line | |
|---|
| 1 | #include "owl.h" |
|---|
| 2 | |
|---|
| 3 | #include <assert.h> |
|---|
| 4 | |
|---|
| 5 | bool owl_is_editcontext(const owl_context *ctx) |
|---|
| 6 | { |
|---|
| 7 | return owl_context_matches(ctx, OWL_CTX_TYPWIN); |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | owl_context *owl_editcontext_new(int mode, owl_editwin *e, const char *keymap) |
|---|
| 11 | { |
|---|
| 12 | owl_context *ctx = owl_context_new(mode, owl_editwin_ref(e), keymap, |
|---|
| 13 | owl_editwin_get_window(e)); |
|---|
| 14 | ctx->delete_cb = owl_editcontext_delete_cb; |
|---|
| 15 | /* TODO: the flags are really screwy. */ |
|---|
| 16 | assert(owl_is_editcontext(ctx)); |
|---|
| 17 | return ctx; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | owl_editwin *owl_editcontext_get_editwin(const owl_context *ctx) |
|---|
| 21 | { |
|---|
| 22 | if (!owl_is_editcontext(ctx)) return NULL; |
|---|
| 23 | return ctx->data; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | void owl_editcontext_delete_cb(owl_context *ctx) |
|---|
| 27 | { |
|---|
| 28 | if (owl_is_editcontext(ctx) && ctx->data) { |
|---|
| 29 | owl_editwin_unref(ctx->data); |
|---|
| 30 | ctx->data = NULL; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.