source: context.c @ 00842c3

release-1.10release-1.8release-1.9
Last change on this file since 00842c3 was d4927a7, checked in by Anders Kaseorg <andersk@mit.edu>, 14 years ago
Replace owl_strdup with g_strdup. Signed-off-by: Anders Kaseorg <andersk@mit.edu> Reviewed-by: Karl Ramm <kcr@mit.edu>
  • 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 = g_new0(owl_context, 1);
14  c->mode = mode;
15  c->data = data;
16  c->cursor = cursor ? g_object_ref(cursor) : NULL;
17  c->keymap = g_strdup(keymap);
18  return c;
19}
20
21/* returns whether test matches the current context */
22int owl_context_matches(const owl_context *ctx, int test)
23{
24  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
25  if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
26       || !(test&OWL_CTX_MODE_BITS))
27      && 
28      (((ctx->mode&OWL_CTX_ACTIVE_BITS) & test) 
29       || !(test&OWL_CTX_ACTIVE_BITS))) {
30    return 1;
31  } else {
32    return 0;
33  }
34}
35
36void *owl_context_get_data(const owl_context *ctx)
37{
38  return ctx->data;
39}
40
41int owl_context_get_mode(const owl_context *ctx)
42{
43  return ctx->mode & OWL_CTX_MODE_BITS;
44}
45
46int owl_context_get_active(const owl_context *ctx)
47{
48  return ctx->mode & OWL_CTX_ACTIVE_BITS;
49}
50
51int owl_context_is_startup(const owl_context *ctx)
52{
53  return (ctx->mode & OWL_CTX_STARTUP)?1:0;
54}
55
56int owl_context_is_interactive(const owl_context *ctx)
57{
58  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
59}
60
61void owl_context_deactivate(owl_context *ctx)
62{
63  if (ctx->deactivate_cb)
64    ctx->deactivate_cb(ctx);
65}
66
67void owl_context_delete(owl_context *ctx)
68{
69  if (ctx->cursor)
70    g_object_unref(ctx->cursor);
71  g_free(ctx->keymap);
72  if (ctx->delete_cb)
73    ctx->delete_cb(ctx);
74  g_free(ctx);
75}
Note: See TracBrowser for help on using the repository browser.