X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fbindings.cc;h=1a102b5452b78c30e65a05f6716bbc36f9e885d9;hb=db1fb534b8f5a1f19710ac77ef2ce85c4c1270ec;hp=4cffb559bcada1e449a0d97856882fa22af48c0c;hpb=40f3dfbaadef7e5b008d320ab92d47dbb63db1a9;p=chaz%2Fopenbox diff --git a/src/bindings.cc b/src/bindings.cc index 4cffb559..1a102b54 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -17,9 +17,9 @@ extern "C" { namespace ob { #include -static void print_branch(BindingTree *first, std::string str) +static void print_branch(const BindingTree *first, std::string str) { - BindingTree *p = first; + const BindingTree *p = first; while (p) { if (p->first_child) @@ -95,7 +95,8 @@ static bool modvalue(const std::string &mod, unsigned int *val) return true; } -bool OBBindings::translate(const std::string &str, Binding &b, bool askey) +bool OBBindings::translate(const std::string &str, Binding &b, + bool askey) const { // parse out the base key name std::string::size_type keybegin = str.find_last_of('-'); @@ -138,7 +139,7 @@ static void destroytree(BindingTree *tree) } } -BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) +BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const { if (keylist.empty()) return 0; // nothing in the list.. return 0 @@ -148,7 +149,7 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) for (it = keylist.rbegin(); it != end; ++it) { p = ret; ret = new BindingTree(id); - if (!p) ret->chain = false; + if (!p) ret->chain = false; // only the first built node ret->first_child = p; if (!translate(*it, ret->binding, true)) { destroytree(ret); @@ -210,41 +211,35 @@ void OBBindings::assimilate(BindingTree *node) { BindingTree *a, *b, *tmp, *last; - printf("node=%lx\n", (long)node); if (!_keytree.first_child) { // there are no nodes at this level yet _keytree.first_child = node; - return; } else { a = _keytree.first_child; last = a; b = node; while (a) { - printf("in while.. b=%lx\n", (long)b); last = a; if (a->binding != b->binding) { a = a->next_sibling; } else { - printf("a: %s %d %d\n", a->text.c_str(), a->binding.key, a->binding.modifiers); - printf("b: %s %d %d\n", b->text.c_str(), b->binding.key, b->binding.modifiers); - printf("moving up one in b\n"); tmp = b; b = b->first_child; delete tmp; a = a->first_child; } } - printf("after while.. b=%lx\n", (long)b); if (last->binding != b->binding) last->next_sibling = b; - else + else { last->first_child = b->first_child; - delete b; + delete b; + } } } -int OBBindings::find_key(BindingTree *search) { +int OBBindings::find_key(BindingTree *search) const { BindingTree *a, *b; a = _keytree.first_child; b = search; @@ -253,10 +248,12 @@ int OBBindings::find_key(BindingTree *search) { a = a->next_sibling; } else { if (a->chain == b->chain) { - if (!a->chain) + if (!a->chain) { return a->id; // found it! (return the actual id, not the search's) - } else - return -2; // the chain status' don't match (conflict!) + } + } else { + return -2; // the chain status' don't match (conflict!) + } b = b->first_child; a = a->first_child; } @@ -279,6 +276,7 @@ bool OBBindings::add_key(const StringVect &keylist, int id) // assimilate this built tree into the main tree assimilate(tree); // assimilation destroys/uses the tree + return true; }