]>
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) 2006 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
21 #include "translate.h"
24 void tree_destroy(KeyBindingTree
*tree
)
29 tree_destroy(tree
->next_sibling
);
30 c
= tree
->first_child
;
34 for (it
= tree
->keylist
; it
!= NULL
; it
= it
->next
)
36 g_list_free(tree
->keylist
);
37 for (sit
= tree
->actions
; sit
!= NULL
; sit
= sit
->next
)
38 action_unref(sit
->data
);
39 g_slist_free(tree
->actions
);
46 KeyBindingTree
*tree_build(GList
*keylist
)
49 KeyBindingTree
*ret
= NULL
, *p
;
51 if (g_list_length(keylist
) <= 0)
52 return NULL
; /* nothing in the list.. */
54 for (it
= g_list_last(keylist
); it
; it
= g_list_previous(it
)) {
56 ret
= g_new0(KeyBindingTree
, 1);
60 /* this is the first built node, the bottom node of the tree */
61 ret
->keylist
= g_list_copy(keylist
); /* shallow copy */
62 for (it
= ret
->keylist
; it
; it
= g_list_next(it
)) /* deep copy */
63 it
->data
= g_strdup(it
->data
);
66 if (!translate_key(it
->data
, &ret
->state
, &ret
->key
)) {
74 void tree_assimilate(KeyBindingTree
*node
)
76 KeyBindingTree
*a
, *b
, *tmp
, *last
;
78 if (keyboard_firstnode
== NULL
) {
79 /* there are no nodes at this level yet */
80 keyboard_firstnode
= node
;
82 a
= keyboard_firstnode
;
87 if (!(a
->state
== b
->state
&& a
->key
== b
->key
)) {
96 if (!(last
->state
== b
->state
&& last
->key
== b
->key
))
97 last
->next_sibling
= b
;
99 last
->first_child
= b
->first_child
;
105 KeyBindingTree
*tree_find(KeyBindingTree
*search
, gboolean
*conflict
)
107 KeyBindingTree
*a
, *b
;
111 a
= keyboard_firstnode
;
114 if (!(a
->state
== b
->state
&& a
->key
== b
->key
)) {
117 if ((a
->first_child
== NULL
) == (b
->first_child
== NULL
)) {
118 if (a
->first_child
== NULL
) {
119 /* found it! (return the actual node, not the search's) */
124 return NULL
; /* the chain status' don't match (conflict!) */
130 return NULL
; /* it just isn't in here */
This page took 0.045707 seconds and 4 git commands to generate.