source: context.c @ 52172cc

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 52172cc was cb81570, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Add a separate owl_context_new and remove owl_context_init The latter is unused anyway.
  • Property mode set to 100644
File size: 1.8 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
7/* TODO: dependency from owl_context -> owl_window is annoying. */
8owl_context *owl_context_new(int mode, void *data, const char *keymap, owl_window *cursor)
9{
10  owl_context *c;
11  if (!(mode & OWL_CTX_MODE_BITS))
12    mode |= OWL_CTX_INTERACTIVE;
13  c = owl_malloc(sizeof *c);
14  memset(c, 0, sizeof(*c));
15  c->mode = mode;
16  c->data = data;
17  c->cursor = cursor ? g_object_ref(cursor) : NULL;
18  c->keymap = owl_strdup(keymap);
19  return c;
20}
21
22/* returns whether test matches the current context */
23int owl_context_matches(const owl_context *ctx, int test)
24{
25  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
26  if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
27       || !(test&OWL_CTX_MODE_BITS))
28      && 
29      (((ctx->mode&OWL_CTX_ACTIVE_BITS) & test) 
30       || !(test&OWL_CTX_ACTIVE_BITS))) {
31    return 1;
32  } else {
33    return 0;
34  }
35}
36
37void *owl_context_get_data(const owl_context *ctx)
38{
39  return ctx->data;
40}
41
42int owl_context_get_mode(const owl_context *ctx)
43{
44  return ctx->mode & OWL_CTX_MODE_BITS;
45}
46
47int owl_context_get_active(const owl_context *ctx)
48{
49  return ctx->mode & OWL_CTX_ACTIVE_BITS;
50}
51
52int owl_context_is_startup(const owl_context *ctx)
53{
54  return (ctx->mode & OWL_CTX_STARTUP)?1:0;
55}
56
57int owl_context_is_interactive(const owl_context *ctx)
58{
59  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
60}
61
62void owl_context_deactivate(owl_context *ctx)
63{
64  if (ctx->deactivate_cb)
65    ctx->deactivate_cb(ctx);
66}
67
68void owl_context_delete(owl_context *ctx)
69{
70  if (ctx->cursor)
71    g_object_unref(ctx->cursor);
72  owl_free(ctx->keymap);
73  if (ctx->delete_cb)
74    ctx->delete_cb(ctx);
75  owl_free(ctx);
76}
Note: See TracBrowser for help on using the repository browser.