forked from barnowl/barnowl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.c
74 lines (64 loc) · 1.77 KB
/
context.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "owl.h"
#define SET_ACTIVE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_ACTIVE_BITS)|new
#define SET_MODE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_MODE_BITS)|new
/* TODO: dependency from owl_context -> owl_window is annoying. */
CALLER_OWN owl_context *owl_context_new(int mode, void *data, const char *keymap, owl_window *cursor)
{
owl_context *c;
if (!(mode & OWL_CTX_MODE_BITS))
mode |= OWL_CTX_INTERACTIVE;
c = g_slice_new0(owl_context);
c->mode = mode;
c->data = data;
c->cursor = cursor ? g_object_ref(cursor) : NULL;
c->keymap = g_strdup(keymap);
return c;
}
/* returns whether test matches the current context */
int owl_context_matches(const owl_context *ctx, int test)
{
/*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
|| !(test&OWL_CTX_MODE_BITS))
&&
(((ctx->mode&OWL_CTX_ACTIVE_BITS) & test)
|| !(test&OWL_CTX_ACTIVE_BITS))) {
return 1;
} else {
return 0;
}
}
void *owl_context_get_data(const owl_context *ctx)
{
return ctx->data;
}
int owl_context_get_mode(const owl_context *ctx)
{
return ctx->mode & OWL_CTX_MODE_BITS;
}
int owl_context_get_active(const owl_context *ctx)
{
return ctx->mode & OWL_CTX_ACTIVE_BITS;
}
int owl_context_is_startup(const owl_context *ctx)
{
return (ctx->mode & OWL_CTX_STARTUP)?1:0;
}
int owl_context_is_interactive(const owl_context *ctx)
{
return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
}
void owl_context_deactivate(owl_context *ctx)
{
if (ctx->deactivate_cb)
ctx->deactivate_cb(ctx);
}
void owl_context_delete(owl_context *ctx)
{
if (ctx->cursor)
g_object_unref(ctx->cursor);
g_free(ctx->keymap);
if (ctx->delete_cb)
ctx->delete_cb(ctx);
g_slice_free(owl_context, ctx);
}