source: context.c @ ecfbdcc

release-1.10release-1.9
Last change on this file since ecfbdcc was f271129, checked in by Jason Gross <jgross@mit.edu>, 13 years ago
Fix up headers The additions to owl.h and some of the removals were done by Alejandro Sedeño <asedeno@mit.edu> in commit 77a0258b3919468fc9d7f7602588ac427ab36e6c. Notes: * I think owl.c lost the need for sys/time.h when we punted select() in favor of glib's main loop. * We don't actually need to include things like stdarg.h, stdio.h, glib/gstdio.h, glib-object.h. I think they get indirectly included via owl.h and/or glib.h. They're left in (or added in to) the files that use functions/types from them. * I'm not entirely sure what sys/socket.h is doing in message.c. It is there from the initial commit. I suspect it might have had something to do with the call to getnameinfo. message.c compiles without it, but http://pubs.opengroup.org/onlinepubs/009695399/functions/getnameinfo.html suggests that we're supposed to include it? *shrugs* I'm leaving it in, for now. (Rather, I'll leave one copy of the #include in.)
  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include "owl.h"
2
3#define SET_ACTIVE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_ACTIVE_BITS)|new
4#define SET_MODE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_MODE_BITS)|new
5
6/* TODO: dependency from owl_context -> owl_window is annoying. */
7CALLER_OWN owl_context *owl_context_new(int mode, void *data, const char *keymap, owl_window *cursor)
8{
9  owl_context *c;
10  if (!(mode & OWL_CTX_MODE_BITS))
11    mode |= OWL_CTX_INTERACTIVE;
12  c = g_new0(owl_context, 1);
13  c->mode = mode;
14  c->data = data;
15  c->cursor = cursor ? g_object_ref(cursor) : NULL;
16  c->keymap = g_strdup(keymap);
17  return c;
18}
19
20/* returns whether test matches the current context */
21int owl_context_matches(const owl_context *ctx, int test)
22{
23  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
24  if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
25       || !(test&OWL_CTX_MODE_BITS))
26      && 
27      (((ctx->mode&OWL_CTX_ACTIVE_BITS) & test) 
28       || !(test&OWL_CTX_ACTIVE_BITS))) {
29    return 1;
30  } else {
31    return 0;
32  }
33}
34
35void *owl_context_get_data(const owl_context *ctx)
36{
37  return ctx->data;
38}
39
40int owl_context_get_mode(const owl_context *ctx)
41{
42  return ctx->mode & OWL_CTX_MODE_BITS;
43}
44
45int owl_context_get_active(const owl_context *ctx)
46{
47  return ctx->mode & OWL_CTX_ACTIVE_BITS;
48}
49
50int owl_context_is_startup(const owl_context *ctx)
51{
52  return (ctx->mode & OWL_CTX_STARTUP)?1:0;
53}
54
55int owl_context_is_interactive(const owl_context *ctx)
56{
57  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
58}
59
60void owl_context_deactivate(owl_context *ctx)
61{
62  if (ctx->deactivate_cb)
63    ctx->deactivate_cb(ctx);
64}
65
66void owl_context_delete(owl_context *ctx)
67{
68  if (ctx->cursor)
69    g_object_unref(ctx->cursor);
70  g_free(ctx->keymap);
71  if (ctx->delete_cb)
72    ctx->delete_cb(ctx);
73  g_free(ctx);
74}
Note: See TracBrowser for help on using the repository browser.