aboutsummaryrefslogtreecommitdiffstats
path: root/patches/add_bindings_interface-r5190.patch
blob: 43a5d7bbd5816fcedd1f01b49ad13bea3b9e768a (plain) (blame)
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
75
76
77
78
79
80
81
82
83
84
85
Index: ui/UI.xs
===================================================================
--- ui/UI.xs	(revision 5190)
+++ ui/UI.xs	(working copy)
@@ -106,3 +106,71 @@
 	irssi_boot(UI__Formats);
 	irssi_boot(UI__Themes);
 	irssi_boot(UI__Window);
+
+MODULE = Irssi::UI  PACKAGE = Irssi
+
+HV*
+bindings()
+PREINIT:
+    GSList *info;
+    GSList  *key;
+CODE:
+
+    RETVAL = newHV();
+    sv_2mortal((SV*)RETVAL);
+
+    /* loop stolen from keyboard.c#cmd_show_keys */
+
+    for (info = keyinfos; info != NULL; info = info->next) {
+        KEYINFO_REC *rec = info->data;
+		for (key = rec->keys; key != NULL; key = key->next) {
+			KEY_REC *key_rec = key->data;
+
+            /* return value { key => [ info, data ] } */
+            AV* value_array = newAV();
+
+            char *kinfo = key_rec->info->id;
+            char *kdata = key_rec->data;
+
+            /* store info, or undef if it's null */
+            av_push(value_array, kinfo != NULL
+                    ? newSVpv(kinfo, strlen(kinfo))
+                    : newSV(0));
+
+            /* ditto data */
+            av_push(value_array, kdata != NULL
+                    ? newSVpv(kdata, strlen(kdata))
+                    : newSV(0));
+
+            /* wedge it all into a reference so we can use it in the hash */
+            SV* value_ref = newRV_noinc((SV*)value_array);
+
+            /* and finally, set up the hash */
+            hv_store(RETVAL, key_rec->key, strlen(key_rec->key),
+                     value_ref, 0);
+		}
+    }
+OUTPUT:
+    RETVAL
+
+SV*
+binding_add(key, function, data)
+char *key
+char *function
+char *data
+CODE:
+
+    if (key_info_find(function) == NULL)
+        RETVAL = &PL_sv_no;
+	else {
+        key_configure_add(function, key, data);
+        RETVAL = &PL_sv_yes;
+    }
+OUTPUT:
+   RETVAL
+
+void
+binding_remove(key)
+char *key
+CODE:
+    key_configure_remove(key);
Index: ui/module.h
===================================================================
--- ui/module.h	(revision 5190)
+++ ui/module.h	(working copy)
@@ -12,3 +12,4 @@
 typedef TEXT_DEST_REC *Irssi__UI__TextDest;
 typedef THEME_REC *Irssi__UI__Theme;
 typedef KEYINFO_REC *Irssi__UI__Keyinfo;
+typedef KEY_REC *Irssi__UI__Key;