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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
* ion/ioncore/bindmaps.c
*
* Copyright (c) Tuomo Valkonen 1999-2007.
*
* See the included file LICENSE for details.
*/
#include <X11/XKBlib.h>
#include <libtu/rb.h>
#include <libextl/extl.h>
#include "common.h"
#include "conf-bindings.h"
#include "binding.h"
#include "framep.h"
#include "bindmaps.h"
#include "global.h"
#include "regbind.h"
/*
* This file contains higher-level bindmap management code
*/
WBindmap *ioncore_screen_bindmap=NULL;
WBindmap *ioncore_mplex_bindmap=NULL;
WBindmap *ioncore_mplex_toplevel_bindmap=NULL;
WBindmap *ioncore_frame_bindmap=NULL;
WBindmap *ioncore_frame_toplevel_bindmap=NULL;
WBindmap *ioncore_frame_floating_bindmap=NULL;
WBindmap *ioncore_frame_tiled_bindmap=NULL;
WBindmap *ioncore_frame_transient_bindmap=NULL;
WBindmap *ioncore_moveres_bindmap=NULL;
WBindmap *ioncore_group_bindmap=NULL;
WBindmap *ioncore_groupcw_bindmap=NULL;
WBindmap *ioncore_groupws_bindmap=NULL;
WBindmap *ioncore_clientwin_bindmap=NULL;
static Rb_node known_bindmaps=NULL;
static StringIntMap frame_areas[]={
{"border", FRAME_AREA_BORDER},
{"tab", FRAME_AREA_TAB},
{"empty_tab", FRAME_AREA_TAB},
{"client", FRAME_AREA_CLIENT},
END_STRINGINTMAP
};
#define DO_FREE(X, Y) \
if(ioncore_ ## X ## _bindmap!=NULL){ \
ioncore_free_bindmap(Y, ioncore_ ## X ## _bindmap); \
ioncore_ ## X ## _bindmap=NULL; \
} ((void)0)
void ioncore_deinit_bindmaps()
{
DO_FREE(screen, "WScreen");
DO_FREE(mplex, "WMPlex");
DO_FREE(mplex_toplevel, "WMPlex.toplevel");
DO_FREE(frame, "WFrame");
DO_FREE(frame_toplevel, "WFrame.toplevel");
DO_FREE(frame_floating, "WFrame.floating");
DO_FREE(frame_tiled, "WFrame.tiled");
DO_FREE(frame_transient, "WFrame.transient");
DO_FREE(moveres, "WMoveresMode");
DO_FREE(group, "WGroup");
DO_FREE(groupcw, "WGroupCW");
DO_FREE(groupws, "WGroupWS");
DO_FREE(clientwin, "WClientWin");
rb_free_tree(known_bindmaps);
known_bindmaps=NULL;
}
#define DO_ALLOC(X, Y, Z) \
ioncore_ ## X ## _bindmap=ioncore_alloc_bindmap(Y, Z); \
if(ioncore_ ## X ## _bindmap==NULL){ \
return FALSE; \
} ((void)0)
bool ioncore_init_bindmaps()
{
known_bindmaps=make_rb();
if(known_bindmaps==NULL)
return FALSE;
DO_ALLOC(screen, "WScreen", NULL);
DO_ALLOC(mplex, "WMPlex", NULL);
DO_ALLOC(mplex_toplevel, "WMPlex.toplevel", NULL);
DO_ALLOC(frame, "WFrame", frame_areas);
DO_ALLOC(frame_toplevel, "WFrame.toplevel", frame_areas);
DO_ALLOC(frame_floating, "WFrame.floating", frame_areas);
DO_ALLOC(frame_tiled, "WFrame.tiled", frame_areas);
DO_ALLOC(frame_transient, "WFrame.transient", frame_areas);
DO_ALLOC(moveres, "WMoveresMode", NULL);
DO_ALLOC(group, "WGroup", NULL);
DO_ALLOC(groupcw, "WGroupCW", NULL);
DO_ALLOC(groupws, "WGroupWS", NULL);
DO_ALLOC(clientwin, "WClientWin", NULL);
return TRUE;
}
void ioncore_refresh_bindmaps()
{
Rb_node node;
ioncore_update_modmap();
rb_traverse(node,known_bindmaps){
bindmap_refresh((WBindmap*)rb_val(node));
}
}
WBindmap *ioncore_alloc_bindmap(const char *name, const StringIntMap *areas)
{
WBindmap *bm=create_bindmap();
if(bm==NULL)
return NULL;
bm->areamap=areas;
if(!rb_insert(known_bindmaps, name, bm)){
bindmap_destroy(bm);
return NULL;
}
return bm;
}
WBindmap *ioncore_alloc_bindmap_frame(const char *name)
{
return ioncore_alloc_bindmap(name, frame_areas);
}
void ioncore_free_bindmap(const char *name, WBindmap *bm)
{
int found=0;
Rb_node node;
node=rb_find_key_n(known_bindmaps, name, &found);
assert(found!=0 && rb_val(node)==(void*)bm);
rb_delete_node(node);
bindmap_destroy(bm);
}
WBindmap *ioncore_lookup_bindmap(const char *name)
{
int found=0;
Rb_node node;
node=rb_find_key_n(known_bindmaps, name, &found);
if(found==0)
return NULL;
return (WBindmap*)rb_val(node);
}
EXTL_EXPORT
bool ioncore_do_defbindings(const char *name, ExtlTab tab)
{
WBindmap *bm=ioncore_lookup_bindmap(name);
if(bm==NULL)
bm=ioncore_alloc_bindmap(name, NULL);
if(bm==NULL){
warn("Unknown bindmap %s.", name);
return FALSE;
}
return bindmap_defbindings(bm, tab, FALSE);
}
EXTL_SAFE
EXTL_EXPORT
ExtlTab ioncore_do_getbindings()
{
Rb_node node;
ExtlTab tab;
tab=extl_create_table();
rb_traverse(node, known_bindmaps){
ExtlTab bmtab=bindmap_getbindings((WBindmap*)rb_val(node));
extl_table_sets_t(tab, (const char*)node->k.key, bmtab);
extl_unref_table(bmtab);
}
return tab;
}
WBindmap *ioncore_create_cycle_bindmap(uint kcb, uint state,
ExtlFn cycle, ExtlFn bcycle)
{
WBindmap *bindmap=create_bindmap();
WBinding b;
if(bindmap==NULL)
return NULL;
b.ksb=XkbKeycodeToKeysym(ioncore_g.dpy, kcb, 0, 0);
b.kcb=kcb;
b.state=state;
b.act=BINDING_KEYPRESS;
b.area=0;
b.wait=FALSE;
b.submap=NULL;
b.func=extl_ref_fn(cycle);
b.doc=NULL;
b.label=NULL;
if(!bindmap_add_binding(bindmap, &b)){
extl_unref_fn(b.func);
bindmap_destroy(bindmap);
return NULL;
}
if((b.state&ShiftMask)==0 && bcycle!=extl_fn_none()){
b.func=extl_ref_fn(bcycle);
b.state|=ShiftMask;
bindmap_add_binding(bindmap, &b);
}
return bindmap;
}
WBindmap *region_add_cycle_bindmap(WRegion *reg, uint kcb, uint state,
ExtlFn cycle, ExtlFn bcycle)
{
WBindmap *bindmap=ioncore_create_cycle_bindmap(kcb, state, cycle, bcycle);
if(bindmap!=NULL){
if(!region_add_bindmap(reg, bindmap)){
bindmap_destroy(bindmap);
return NULL;
}
}
return bindmap;
}
|