"Fossies" - the Fresh Open Source Software Archive 
Member "bbkeys-0.9.1/src/actions.cc" (22 Dec 2008, 5598 Bytes) of package /linux/privat/old/bbkeys-0.9.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "actions.cc" see the
Fossies "Dox" file reference documentation.
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // actions.cc for Epistrophy - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
4 //
5 // Adapted slightly for inclusion in bbkeys by Jason 'vanRijn' Kasper
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
24
25 #include "actions.hh"
26
27 #include <cstdlib>
28 #include <iostream>
29 #include <string>
30 #include <sstream>
31
32 Action::Action(enum ActionType type, Display * display, KeyCode keycode,
33 unsigned int modifierMask, const std::string &str)
34 : _type(type), _display(display), _keycode(keycode), _modifierMask(modifierMask)
35 {
36 // These are the action types that take string arguments. This
37 // should probably be moved to a static member
38 ActionType str_types[] = {
39 execute,
40 nextWindowOfClass,
41 prevWindowOfClass,
42 nextWindowOfClassOnAllWorkspaces,
43 prevWindowOfClassOnAllWorkspaces,
44 sendToNextWorkspace,
45 sendToPrevWorkspace,
46 noaction
47 };
48
49 for (int i = 0; str_types[i] != noaction; ++i) {
50 if (type == str_types[i]) {
51 _stringParam = str;
52 return;
53 }
54 }
55
56 _numberParam = atoi( str.c_str() );
57
58 // workspace 1 to the user is workspace 0 to us
59 if (type == changeWorkspace || type == sendToWorkspace)
60 _numberParam--;
61 }
62
63 const char * Action::getActionName() {
64 struct {
65 const char* str;
66 Action::ActionType act;
67 }
68 actions[] = {
69 { "noaction", Action::noaction },
70 { "execute", Action::execute },
71 { "iconify", Action::iconify },
72 { "raise", Action::raise },
73 { "lower", Action::lower },
74 { "close", Action::close },
75 { "toggleShade", Action::toggleShade },
76 { "toggleOmnipresent", Action::toggleOmnipresent },
77 { "movewindowup", Action::moveWindowUp },
78 { "movewindowdown", Action::moveWindowDown },
79 { "movewindowleft", Action::moveWindowLeft },
80 { "movewindowright", Action::moveWindowRight },
81 { "resizewindowwidth", Action::resizeWindowWidth },
82 { "resizewindowheight", Action::resizeWindowHeight },
83 { "togglemaximizefull", Action::toggleMaximizeFull },
84 { "togglemaximizevertical", Action::toggleMaximizeVertical },
85 { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
86 { "sendtoworkspace", Action::sendToWorkspace },
87 { "sendtonextworkspace", Action::sendToNextWorkspace },
88 { "sendtoprevworkspace", Action::sendToPrevWorkspace },
89 { "nextwindow", Action::nextWindow },
90 { "prevwindow", Action::prevWindow },
91 { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
92 { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
93 { "nextwindowonallscreens", Action::nextWindowOnAllScreens },
94 { "prevwindowonallscreens", Action::prevWindowOnAllScreens },
95 { "nextwindowofclass", Action::nextWindowOfClass },
96 { "prevwindowofclass", Action::prevWindowOfClass },
97 { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
98 { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
99 { "changeworkspace", Action::changeWorkspace },
100 { "nextworkspace", Action::nextWorkspace },
101 { "prevworkspace", Action::prevWorkspace },
102 { "nextworkspacerow", Action::upWorkspace },
103 { "prevworkspacerow", Action::downWorkspace },
104 { "prevworkspacecolumn", Action::leftWorkspace },
105 { "nextworkspacecolumn", Action::rightWorkspace },
106 { "nextscreen", Action::nextScreen },
107 { "prevscreen", Action::prevScreen },
108 { "showrootmenu", Action::showRootMenu },
109 { "showworkspacemenu", Action::showWorkspaceMenu },
110 { "toggledecorations", Action::toggleDecorations },
111 { "togglegrabs", Action::toggleGrabs },
112 { "stringchain", Action::stringChain },
113 { "keychain", Action::keyChain },
114 { "numberchain", Action::numberChain },
115 { "cancelchain", Action::cancelChain },
116 { "chain", Action::chain },
117 { "", Action::noaction }
118 };
119
120 for (int i = 0; actions[i].str[0] != '\0' ; ++i) {
121 if ( actions[i].act == _type) {
122 return actions[i].str;
123 }
124 }
125
126 std::cout << BBTOOL << ": " << "ERROR: Invalid action (" << _type << ").\n";
127 return "not found";
128
129 }
130
131
132 const std::string Action::toString() {
133 std::string key;
134 KeySym _sym = XKeycodeToKeysym(_display, keycode(), 0);
135
136 if (_sym == NoSymbol) key="key not found";
137 else key = XKeysymToString(_sym);
138
139 std::ostringstream val;
140 val << "action: [" << getActionName()
141 << "], key: [" << key
142 << "], mask: [" << modifierMask()
143 << "], string: [" << string() << "]";
144
145 return val.str();
146
147
148 }