source: context.c @ b8a3e00

release-1.10release-1.8release-1.9
Last change on this file since b8a3e00 was 6829afc, checked in by David Benjamin <davidben@mit.edu>, 13 years ago
Define CALLER_OWN macro Replace our exising uses of G_GNUC_WARN_UNUSED_RESULT with it. The old macro is just way too long. This also more clearly specifies the intent.
  • 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. */
[6829afc]8CALLER_OWN owl_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;
[96828e4]13  c = g_new0(owl_context, 1);
[cb81570]14  c->mode = mode;
15  c->data = data;
16  c->cursor = cursor ? g_object_ref(cursor) : NULL;
[d4927a7]17  c->keymap = g_strdup(keymap);
[cb81570]18  return c;
[7d4fbcd]19}
20
21/* returns whether test matches the current context */
[3f8514b]22int owl_context_matches(const owl_context *ctx, int test)
[53f421b]23{
[10b866d]24  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
[7d4fbcd]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
[3f8514b]36void *owl_context_get_data(const owl_context *ctx)
[53f421b]37{
[7d4fbcd]38  return ctx->data;
39}
40
[3f8514b]41int owl_context_get_mode(const owl_context *ctx)
[53f421b]42{
[7d4fbcd]43  return ctx->mode & OWL_CTX_MODE_BITS;
44}
45
[3f8514b]46int owl_context_get_active(const owl_context *ctx)
[53f421b]47{
[7d4fbcd]48  return ctx->mode & OWL_CTX_ACTIVE_BITS;
49}
50
[3f8514b]51int owl_context_is_startup(const owl_context *ctx)
[53f421b]52{
[7d4fbcd]53  return (ctx->mode & OWL_CTX_STARTUP)?1:0;
54}
55
[3f8514b]56int owl_context_is_interactive(const owl_context *ctx)
[53f421b]57{
[ecd5dc5]58  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
59}
[1d74663]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);
[ddbbcffa]71  g_free(ctx->keymap);
[1d74663]72  if (ctx->delete_cb)
73    ctx->delete_cb(ctx);
[ddbbcffa]74  g_free(ctx);
[1d74663]75}
Note: See TracBrowser for help on using the repository browser.