]>
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.
25 keytree::keytree(Display
*display
) : _display(display
)
29 _head
->action
= NULL
; // head's action is always NULL
38 void keytree::clearTree(keynode
*node
)
43 ChildList::iterator it
, end
= node
->children
.end();
44 for (it
= node
->children
.begin(); it
!= end
; ++it
)
52 void keytree::grabDefaults(screen
*scr
)
54 grabChildren(_head
, scr
);
57 void keytree::grabChildren(keynode
*node
, screen
*scr
)
59 ChildList::const_iterator it
, end
= node
->children
.end();
60 for (it
= node
->children
.begin(); it
!= end
; ++it
)
62 scr
->grabKey( (*it
)->action
->keycode(), (*it
)->action
->modifierMask() );
65 void keytree::ungrabChildren(keynode
*node
, screen
*scr
)
67 ChildList::const_iterator it
, end
= node
->children
.end();
68 for (it
= node
->children
.begin(); it
!= end
; ++it
)
70 scr
->ungrabKey( (*it
)->action
->keycode(), (*it
)->action
->modifierMask());
73 const Action
* keytree::getAction(const XEvent
&e
, unsigned int state
,
78 if (_current
!= _head
)
79 ungrabChildren(_current
, scr
);
81 ChildList::const_iterator it
, end
= _current
->children
.end();
82 for (it
= _current
->children
.begin(); it
!= end
; ++it
) {
84 if (e
.xkey
.keycode
== act
->keycode() && state
== act
->modifierMask()) {
91 grabChildren(_current
, scr
);
92 return (const Action
*)NULL
;
97 // action not found. back to the head
99 return (const Action
*)NULL
;
102 void keytree::addAction(Action::ActionType action
, unsigned int mask
,
103 string key
, string arg
)
105 // can't grab non-modifier as topmost key
106 if (_current
== _head
&& (mask
== 0 || mask
== ShiftMask
))
109 keynode
*tmp
= new keynode
;
110 tmp
->action
= new Action(action
,
111 XKeysymToKeycode(_display
,
112 XStringToKeysym(key
.c_str())),
114 tmp
->parent
= _current
;
115 _current
->children
.push_back(tmp
);
118 void keytree::advanceOnNewNode()
120 keynode
*tmp
= new keynode
;
122 tmp
->parent
= _current
;
123 _current
->children
.push_back(tmp
);
127 void keytree::retract()
129 if (_current
!= _head
)
130 _current
= _current
->parent
;
133 void keytree::setCurrentNodeProps(Action::ActionType action
, unsigned int mask
,
134 string key
, string arg
)
136 if (_current
->action
)
137 delete _current
->action
;
138 _current
->action
= new Action(action
,
139 XKeysymToKeycode(_display
,
140 XStringToKeysym(key
.c_str())),
This page took 0.042273 seconds and 5 git commands to generate.