]>
Dogcows Code - chaz/openbox/blob - openbox/keytree.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 keytree.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
20 #include "translate.h"
23 void tree_destroy(KeyBindingTree
*tree
)
28 tree_destroy(tree
->next_sibling
);
29 c
= tree
->first_child
;
33 for (it
= tree
->keylist
; it
!= NULL
; it
= it
->next
)
35 g_list_free(tree
->keylist
);
36 for (sit
= tree
->actions
; sit
!= NULL
; sit
= sit
->next
)
37 action_unref(sit
->data
);
38 g_slist_free(tree
->actions
);
45 KeyBindingTree
*tree_build(GList
*keylist
)
48 KeyBindingTree
*ret
= NULL
, *p
;
50 if (g_list_length(keylist
) <= 0)
51 return NULL
; /* nothing in the list.. */
53 for (it
= g_list_last(keylist
); it
; it
= g_list_previous(it
)) {
55 ret
= g_new0(KeyBindingTree
, 1);
59 /* this is the first built node, the bottom node of the tree */
60 ret
->keylist
= g_list_copy(keylist
); /* shallow copy */
61 for (it
= ret
->keylist
; it
; it
= g_list_next(it
)) /* deep copy */
62 it
->data
= g_strdup(it
->data
);
65 if (!translate_key(it
->data
, &ret
->state
, &ret
->key
)) {
73 void tree_assimilate(KeyBindingTree
*node
)
75 KeyBindingTree
*a
, *b
, *tmp
, *last
;
77 if (keyboard_firstnode
== NULL
) {
78 /* there are no nodes at this level yet */
79 keyboard_firstnode
= node
;
81 a
= keyboard_firstnode
;
86 if (!(a
->state
== b
->state
&& a
->key
== b
->key
)) {
95 if (!(last
->state
== b
->state
&& last
->key
== b
->key
))
96 last
->next_sibling
= b
;
98 last
->first_child
= b
->first_child
;
104 KeyBindingTree
*tree_find(KeyBindingTree
*search
, gboolean
*conflict
)
106 KeyBindingTree
*a
, *b
;
110 a
= keyboard_firstnode
;
113 if (!(a
->state
== b
->state
&& a
->key
== b
->key
)) {
116 if ((a
->first_child
== NULL
) == (b
->first_child
== NULL
)) {
117 if (a
->first_child
== NULL
) {
118 /* found it! (return the actual node, not the search's) */
123 return NULL
; /* the chain status' don't match (conflict!) */
129 return NULL
; /* it just isn't in here */
This page took 0.04361 seconds and 4 git commands to generate.