]>
Dogcows Code - chaz/openbox/blob - util/epist/keytree.cc
cf0dd379ea148be1faca259b1b3834683efa8e94
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 it
, end
= node
->children
.end();
73 for (it
= node
->children
.begin(); it
!= end
; ++it
)
75 scr
->ungrabKey( (*it
)->action
->keycode(), (*it
)->action
->modifierMask());
78 const Action
* keytree::getAction(const XEvent
&e
, unsigned int state
,
83 if (_current
!= _head
)
84 ungrabChildren(_current
, scr
);
86 ChildList::const_iterator it
, end
= _current
->children
.end();
87 for (it
= _current
->children
.begin(); it
!= end
; ++it
) {
89 if (e
.xkey
.keycode
== act
->keycode() && state
== act
->modifierMask()) {
96 grabChildren(_current
, scr
);
97 return (const Action
*)NULL
;
102 // action not found. back to the head
104 return (const Action
*)NULL
;
107 void keytree::addAction(Action::ActionType action
, unsigned int mask
,
108 string key
, string arg
)
110 // can't grab non-modifier as topmost key
111 if (_current
== _head
&& (mask
== 0 || mask
== ShiftMask
))
114 keynode
*tmp
= new keynode
;
115 tmp
->action
= new Action(action
,
116 XKeysymToKeycode(_display
,
117 XStringToKeysym(key
.c_str())),
119 tmp
->parent
= _current
;
120 _current
->children
.push_back(tmp
);
123 void keytree::advanceOnNewNode()
125 keynode
*tmp
= new keynode
;
127 tmp
->parent
= _current
;
128 _current
->children
.push_back(tmp
);
132 void keytree::retract()
134 if (_current
!= _head
)
135 _current
= _current
->parent
;
138 void keytree::setCurrentNodeProps(Action::ActionType action
, unsigned int mask
,
139 string key
, string arg
)
141 if (_current
->action
)
142 delete _current
->action
;
143 _current
->action
= new Action(action
,
144 XKeysymToKeycode(_display
,
145 XStringToKeysym(key
.c_str())),
This page took 0.036957 seconds and 4 git commands to generate.