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. */ |
---|
8 | CALLER_OWN owl_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 */ |
---|
22 | int 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 | |
---|
36 | void *owl_context_get_data(const owl_context *ctx) |
---|
37 | { |
---|
38 | return ctx->data; |
---|
39 | } |
---|
40 | |
---|
41 | int owl_context_get_mode(const owl_context *ctx) |
---|
42 | { |
---|
43 | return ctx->mode & OWL_CTX_MODE_BITS; |
---|
44 | } |
---|
45 | |
---|
46 | int owl_context_get_active(const owl_context *ctx) |
---|
47 | { |
---|
48 | return ctx->mode & OWL_CTX_ACTIVE_BITS; |
---|
49 | } |
---|
50 | |
---|
51 | int owl_context_is_startup(const owl_context *ctx) |
---|
52 | { |
---|
53 | return (ctx->mode & OWL_CTX_STARTUP)?1:0; |
---|
54 | } |
---|
55 | |
---|
56 | int owl_context_is_interactive(const owl_context *ctx) |
---|
57 | { |
---|
58 | return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0; |
---|
59 | } |
---|
60 | |
---|
61 | void owl_context_deactivate(owl_context *ctx) |
---|
62 | { |
---|
63 | if (ctx->deactivate_cb) |
---|
64 | ctx->deactivate_cb(ctx); |
---|
65 | } |
---|
66 | |
---|
67 | void 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 | } |
---|