[1aee7d9] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[7d4fbcd] | 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 | |
---|
[cb81570] | 6 | /* TODO: dependency from owl_context -> owl_window is annoying. */ |
---|
[6829afc] | 7 | CALLER_OWN owl_context *owl_context_new(int mode, void *data, const char *keymap, owl_window *cursor) |
---|
[53f421b] | 8 | { |
---|
[cb81570] | 9 | owl_context *c; |
---|
| 10 | if (!(mode & OWL_CTX_MODE_BITS)) |
---|
| 11 | mode |= OWL_CTX_INTERACTIVE; |
---|
[96828e4] | 12 | c = g_new0(owl_context, 1); |
---|
[cb81570] | 13 | c->mode = mode; |
---|
| 14 | c->data = data; |
---|
| 15 | c->cursor = cursor ? g_object_ref(cursor) : NULL; |
---|
[d4927a7] | 16 | c->keymap = g_strdup(keymap); |
---|
[cb81570] | 17 | return c; |
---|
[7d4fbcd] | 18 | } |
---|
| 19 | |
---|
| 20 | /* returns whether test matches the current context */ |
---|
[3f8514b] | 21 | int owl_context_matches(const owl_context *ctx, int test) |
---|
[53f421b] | 22 | { |
---|
[10b866d] | 23 | /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/ |
---|
[7d4fbcd] | 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 | |
---|
[3f8514b] | 35 | void *owl_context_get_data(const owl_context *ctx) |
---|
[53f421b] | 36 | { |
---|
[7d4fbcd] | 37 | return ctx->data; |
---|
| 38 | } |
---|
| 39 | |
---|
[3f8514b] | 40 | int owl_context_get_mode(const owl_context *ctx) |
---|
[53f421b] | 41 | { |
---|
[7d4fbcd] | 42 | return ctx->mode & OWL_CTX_MODE_BITS; |
---|
| 43 | } |
---|
| 44 | |
---|
[3f8514b] | 45 | int owl_context_get_active(const owl_context *ctx) |
---|
[53f421b] | 46 | { |
---|
[7d4fbcd] | 47 | return ctx->mode & OWL_CTX_ACTIVE_BITS; |
---|
| 48 | } |
---|
| 49 | |
---|
[3f8514b] | 50 | int owl_context_is_startup(const owl_context *ctx) |
---|
[53f421b] | 51 | { |
---|
[7d4fbcd] | 52 | return (ctx->mode & OWL_CTX_STARTUP)?1:0; |
---|
| 53 | } |
---|
| 54 | |
---|
[3f8514b] | 55 | int owl_context_is_interactive(const owl_context *ctx) |
---|
[53f421b] | 56 | { |
---|
[ecd5dc5] | 57 | return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0; |
---|
| 58 | } |
---|
[1d74663] | 59 | |
---|
| 60 | void owl_context_deactivate(owl_context *ctx) |
---|
| 61 | { |
---|
| 62 | if (ctx->deactivate_cb) |
---|
| 63 | ctx->deactivate_cb(ctx); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void owl_context_delete(owl_context *ctx) |
---|
| 67 | { |
---|
| 68 | if (ctx->cursor) |
---|
| 69 | g_object_unref(ctx->cursor); |
---|
[ddbbcffa] | 70 | g_free(ctx->keymap); |
---|
[1d74663] | 71 | if (ctx->delete_cb) |
---|
| 72 | ctx->delete_cb(ctx); |
---|
[ddbbcffa] | 73 | g_free(ctx); |
---|
[1d74663] | 74 | } |
---|