]>
Dogcows Code - chaz/openbox/blob - util/epist/keytree.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // keytree.cc for Epistophy - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
30 keytree::keytree(Display
*display
) : _display(display
)
34 _head
->action
= NULL
; // head's action is always NULL
43 void keytree::clearTree(keynode
*node
)
48 ChildList::iterator it
, end
= node
->children
.end();
49 for (it
= node
->children
.begin(); it
!= end
; ++it
)
57 void keytree::grabDefaults(screen
*scr
)
59 grabChildren(_head
, scr
);
62 void keytree::grabChildren(keynode
*node
, screen
*scr
)
64 ChildList::const_iterator it
, end
= node
->children
.end();
65 for (it
= node
->children
.begin(); it
!= end
; ++it
)
67 scr
->grabKey( (*it
)->action
->keycode(), (*it
)->action
->modifierMask() );
70 void keytree::ungrabChildren(keynode
*node
, screen
*scr
)
72 ChildList::const_iterator head_it
, head_end
= _head
->children
.end();
73 ChildList::const_iterator it
, end
= node
->children
.end();
76 // when ungrabbing children, make sure that we don't ungrab any topmost keys
77 // (children of the head node) This would render those topmost keys useless.
78 // Topmost keys are _never_ ungrabbed, since they are only grabbed at startup
80 for (it
= node
->children
.begin(); it
!= end
; ++it
) {
81 if ( (*it
)->action
) {
82 for (head_it
= _head
->children
.begin(); head_it
!= head_end
; ++head_it
) {
83 if ( (*it
)->action
->modifierMask() == (*head_it
)->action
->modifierMask() &&
84 (*it
)->action
->keycode() == (*head_it
)->action
->keycode())
92 scr
->ungrabKey( (*it
)->action
->keycode(), (*it
)->action
->modifierMask());
99 const Action
* keytree::getAction(const XEvent
&e
, unsigned int state
,
104 // we're done with the children. ungrab them
105 if (_current
!= _head
)
106 ungrabChildren(_current
, scr
);
108 ChildList::const_iterator it
, end
= _current
->children
.end();
109 for (it
= _current
->children
.begin(); it
!= end
; ++it
) {
111 if (e
.xkey
.keycode
== act
->keycode() && state
== act
->modifierMask()) {
113 // node is a leaf, so an action will be executed
118 // node is not a leaf, so we advance down the tree, and grab the
119 // children of the new current node. no action is executed
121 grabChildren(_current
, scr
);
122 return (const Action
*)NULL
;
127 // action not found. back to the head
129 return (const Action
*)NULL
;
132 void keytree::addAction(Action::ActionType action
, unsigned int mask
,
133 string key
, string arg
)
135 // can't grab non-modifier as topmost key
136 // XXX: do we allow Esc to be grabbed at the top?
137 if (_current
== _head
&& (mask
== 0 || mask
== ShiftMask
))
140 keynode
*tmp
= new keynode
;
141 tmp
->action
= new Action(action
,
142 XKeysymToKeycode(_display
,
143 XStringToKeysym(key
.c_str())),
145 tmp
->parent
= _current
;
146 _current
->children
.push_back(tmp
);
149 void keytree::advanceOnNewNode()
151 keynode
*tmp
= new keynode
;
153 tmp
->parent
= _current
;
154 _current
->children
.push_back(tmp
);
158 void keytree::retract()
160 if (_current
!= _head
)
161 _current
= _current
->parent
;
164 void keytree::setCurrentNodeProps(Action::ActionType action
, unsigned int mask
,
165 string key
, string arg
)
167 if (_current
->action
)
168 delete _current
->action
;
170 _current
->action
= new Action(action
,
171 XKeysymToKeycode(_display
,
172 XStringToKeysym(key
.c_str())),
This page took 0.042928 seconds and 4 git commands to generate.