source: context.c @ 8510d5b

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 8510d5b 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
RevLine 
[7d4fbcd]1#include <string.h>
[1aee7d9]2#include "owl.h"
3
[7d4fbcd]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
[cb81570]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)
[53f421b]9{
[cb81570]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;
[7d4fbcd]20}
21
22/* returns whether test matches the current context */
[3f8514b]23int owl_context_matches(const owl_context *ctx, int test)
[53f421b]24{
[10b866d]25  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
[7d4fbcd]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
[3f8514b]37void *owl_context_get_data(const owl_context *ctx)
[53f421b]38{
[7d4fbcd]39  return ctx->data;
40}
41
[3f8514b]42int owl_context_get_mode(const owl_context *ctx)
[53f421b]43{
[7d4fbcd]44  return ctx->mode & OWL_CTX_MODE_BITS;
45}
46
[3f8514b]47int owl_context_get_active(const owl_context *ctx)
[53f421b]48{
[7d4fbcd]49  return ctx->mode & OWL_CTX_ACTIVE_BITS;
50}
51
[3f8514b]52int owl_context_is_startup(const owl_context *ctx)
[53f421b]53{
[7d4fbcd]54  return (ctx->mode & OWL_CTX_STARTUP)?1:0;
55}
56
[3f8514b]57int owl_context_is_interactive(const owl_context *ctx)
[53f421b]58{
[ecd5dc5]59  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
60}
[1d74663]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.