source: context.c @ 1d74663

release-1.7release-1.8release-1.9
Last change on this file since 1d74663 was 1d74663, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Add deactivate and delete hooks for owl_context Also make pushing and popping slightly more flexible.
  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <string.h>
2#include "owl.h"
3
4#define SET_ACTIVE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_ACTIVE_BITS)|new
5#define SET_MODE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_MODE_BITS)|new
6
7int owl_context_init(owl_context *ctx)
8{
9  ctx->mode = OWL_CTX_STARTUP;
10  ctx->data = NULL;
11  ctx->cursor = NULL;
12  return 0;
13}
14
15
16/* returns whether test matches the current context */
17int owl_context_matches(const owl_context *ctx, int test)
18{
19  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
20  if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
21       || !(test&OWL_CTX_MODE_BITS))
22      && 
23      (((ctx->mode&OWL_CTX_ACTIVE_BITS) & test) 
24       || !(test&OWL_CTX_ACTIVE_BITS))) {
25    return 1;
26  } else {
27    return 0;
28  }
29}
30
31void *owl_context_get_data(const owl_context *ctx)
32{
33  return ctx->data;
34}
35
36int owl_context_get_mode(const owl_context *ctx)
37{
38  return ctx->mode & OWL_CTX_MODE_BITS;
39}
40
41int owl_context_get_active(const owl_context *ctx)
42{
43  return ctx->mode & OWL_CTX_ACTIVE_BITS;
44}
45
46int owl_context_is_startup(const owl_context *ctx)
47{
48  return (ctx->mode & OWL_CTX_STARTUP)?1:0;
49}
50
51int owl_context_is_interactive(const owl_context *ctx)
52{
53  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
54}
55
56void owl_context_deactivate(owl_context *ctx)
57{
58  if (ctx->deactivate_cb)
59    ctx->deactivate_cb(ctx);
60}
61
62void owl_context_delete(owl_context *ctx)
63{
64  if (ctx->cursor)
65    g_object_unref(ctx->cursor);
66  owl_free(ctx->keymap);
67  if (ctx->delete_cb)
68    ctx->delete_cb(ctx);
69  owl_free(ctx);
70}
Note: See TracBrowser for help on using the repository browser.