diff options
Diffstat (limited to 'src/FbCommands.cc')
-rw-r--r-- | src/FbCommands.cc | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc new file mode 100644 index 0000000..d4ad87e --- /dev/null +++ b/src/FbCommands.cc | |||
@@ -0,0 +1,253 @@ | |||
1 | // FbCommands.cc for Fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: FbCommands.cc,v 1.22 2003/12/20 17:41:32 fluxgen Exp $ | ||
23 | |||
24 | #include "FbCommands.hh" | ||
25 | #include "fluxbox.hh" | ||
26 | #include "Screen.hh" | ||
27 | #include "CommandDialog.hh" | ||
28 | #include "Workspace.hh" | ||
29 | #include "Keys.hh" | ||
30 | |||
31 | #include "FbTk/Theme.hh" | ||
32 | #include "FbTk/Menu.hh" | ||
33 | |||
34 | #include <sys/types.h> | ||
35 | #include <unistd.h> | ||
36 | |||
37 | #include <fstream> | ||
38 | #include <iostream> | ||
39 | using namespace std; | ||
40 | |||
41 | namespace FbCommands { | ||
42 | |||
43 | ExecuteCmd::ExecuteCmd(const std::string &cmd, int screen_num):m_cmd(cmd), m_screen_num(screen_num) { | ||
44 | |||
45 | } | ||
46 | |||
47 | void ExecuteCmd::execute() { | ||
48 | #ifndef __EMX__ | ||
49 | if (! fork()) { | ||
50 | std::string displaystring("DISPLAY="); | ||
51 | displaystring += DisplayString(FbTk::App::instance()->display()); | ||
52 | char intbuff[64]; | ||
53 | int screen_num = m_screen_num; | ||
54 | if (screen_num < 0) { | ||
55 | if (Fluxbox::instance()->mouseScreen() == 0) | ||
56 | screen_num = 0; | ||
57 | else | ||
58 | screen_num = Fluxbox::instance()->mouseScreen()->screenNumber(); | ||
59 | } | ||
60 | |||
61 | sprintf(intbuff, "%d", screen_num); | ||
62 | |||
63 | // remove last number of display and add screen num | ||
64 | displaystring.erase(displaystring.size()-1); | ||
65 | displaystring += intbuff; | ||
66 | setsid(); | ||
67 | putenv(const_cast<char *>(displaystring.c_str())); | ||
68 | execl("/bin/sh", "/bin/sh", "-c", m_cmd.c_str(), 0); | ||
69 | exit(0); | ||
70 | } | ||
71 | #else // __EMX__ | ||
72 | spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", item->exec().c_str(), 0); | ||
73 | #endif // !__EMX__ | ||
74 | |||
75 | } | ||
76 | |||
77 | void ExitFluxboxCmd::execute() { | ||
78 | Fluxbox::instance()->shutdown(); | ||
79 | } | ||
80 | |||
81 | void SaveResources::execute() { | ||
82 | Fluxbox::instance()->save_rc(); | ||
83 | } | ||
84 | |||
85 | RestartFluxboxCmd::RestartFluxboxCmd(const std::string &cmd):m_cmd(cmd){ | ||
86 | } | ||
87 | |||
88 | void RestartFluxboxCmd::execute() { | ||
89 | if (m_cmd.size() == 0) { | ||
90 | Fluxbox::instance()->restart(); | ||
91 | } else { | ||
92 | Fluxbox::instance()->restart(m_cmd.c_str()); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | void ReconfigureFluxboxCmd::execute() { | ||
97 | Fluxbox::instance()->reconfigure(); | ||
98 | } | ||
99 | |||
100 | |||
101 | void ReloadStyleCmd::execute() { | ||
102 | SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename()); | ||
103 | cmd.execute(); | ||
104 | } | ||
105 | |||
106 | SetStyleCmd::SetStyleCmd(const std::string &filename):m_filename(filename) { | ||
107 | |||
108 | } | ||
109 | |||
110 | void SetStyleCmd::execute() { | ||
111 | Fluxbox::instance()->saveStyleFilename(m_filename.c_str()); | ||
112 | Fluxbox::instance()->save_rc(); | ||
113 | FbTk::ThemeManager::instance().load(m_filename); | ||
114 | } | ||
115 | |||
116 | void ShowRootMenuCmd::execute() { | ||
117 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
118 | if (screen == 0) | ||
119 | return; | ||
120 | |||
121 | Window root_ret; | ||
122 | Window window_ret; | ||
123 | |||
124 | int rx, ry; | ||
125 | int wx, wy; | ||
126 | unsigned int mask; | ||
127 | |||
128 | if ( XQueryPointer(FbTk::App::instance()->display(), | ||
129 | screen->rootWindow().window(), &root_ret, &window_ret, | ||
130 | &rx, &ry, &wx, &wy, &mask) ) { | ||
131 | |||
132 | if ( rx - (screen->getRootmenu().width()/2) > 0 ) | ||
133 | rx-= screen->getRootmenu().width()/2; | ||
134 | screen->getRootmenu().move(rx, ry); | ||
135 | } | ||
136 | |||
137 | screen->getRootmenu().show(); | ||
138 | screen->getRootmenu().grabInputFocus(); | ||
139 | |||
140 | } | ||
141 | |||
142 | void ShowWorkspaceMenuCmd::execute() { | ||
143 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
144 | if (screen == 0) | ||
145 | return; | ||
146 | |||
147 | |||
148 | |||
149 | Window root_ret; | ||
150 | Window window_ret; | ||
151 | |||
152 | int rx, ry; | ||
153 | int wx, wy; | ||
154 | unsigned int mask; | ||
155 | |||
156 | if ( XQueryPointer(FbTk::App::instance()->display(), | ||
157 | screen->rootWindow().window(), &root_ret, &window_ret, | ||
158 | &rx, &ry, &wx, &wy, &mask) ) { | ||
159 | |||
160 | if ( rx - (screen->getWorkspacemenu().width()/2) > 0 ) | ||
161 | rx-= screen->getWorkspacemenu().width()/2; | ||
162 | screen->getWorkspacemenu().move(rx, ry); | ||
163 | } | ||
164 | screen->getWorkspacemenu().show(); | ||
165 | screen->getWorkspacemenu().grabInputFocus(); | ||
166 | |||
167 | } | ||
168 | |||
169 | |||
170 | |||
171 | SetWorkspaceNameCmd::SetWorkspaceNameCmd(const std::string &name, int spaceid): | ||
172 | m_name(name), m_workspace(spaceid) { } | ||
173 | |||
174 | void SetWorkspaceNameCmd::execute() { | ||
175 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
176 | if (screen == 0) { | ||
177 | screen = Fluxbox::instance()->keyScreen(); | ||
178 | if (screen == 0) | ||
179 | return; | ||
180 | } | ||
181 | |||
182 | if (m_workspace < 0) { | ||
183 | screen->currentWorkspace()->setName(m_name); | ||
184 | } else { | ||
185 | Workspace *space = screen->getWorkspace(m_workspace); | ||
186 | if (space == 0) | ||
187 | return; | ||
188 | space->setName(m_name); | ||
189 | } | ||
190 | |||
191 | screen->updateWorkspaceNamesAtom(); | ||
192 | Fluxbox::instance()->save_rc(); | ||
193 | } | ||
194 | |||
195 | void WorkspaceNameDialogCmd::execute() { | ||
196 | |||
197 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
198 | if (screen == 0) | ||
199 | return; | ||
200 | |||
201 | CommandDialog *win = new CommandDialog(*screen, "Set Workspace Name:", "SetWorkspaceName "); | ||
202 | win->setText(screen->currentWorkspace()->name()); | ||
203 | win->show(); | ||
204 | } | ||
205 | |||
206 | void CommandDialogCmd::execute() { | ||
207 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
208 | if (screen == 0) | ||
209 | return; | ||
210 | |||
211 | FbTk::FbWindow *win = new CommandDialog(*screen, "Fluxbox Command"); | ||
212 | win->show(); | ||
213 | } | ||
214 | |||
215 | |||
216 | SetResourceValueCmd::SetResourceValueCmd(const std::string &resname, | ||
217 | const std::string &value): | ||
218 | m_resname(resname), | ||
219 | m_value(value) { | ||
220 | |||
221 | } | ||
222 | |||
223 | void SetResourceValueCmd::execute() { | ||
224 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
225 | if (screen == 0) | ||
226 | return; | ||
227 | screen->resourceManager().setResourceValue(m_resname, m_value); | ||
228 | Fluxbox::instance()->save_rc(); | ||
229 | } | ||
230 | |||
231 | void SetResourceValueDialogCmd::execute() { | ||
232 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | ||
233 | if (screen == 0) | ||
234 | return; | ||
235 | |||
236 | FbTk::FbWindow *win = new CommandDialog(*screen, "Type resource name and the value", "SetResourceValue "); | ||
237 | win->show(); | ||
238 | }; | ||
239 | |||
240 | BindKeyCmd::BindKeyCmd(const std::string &keybind):m_keybind(keybind) { } | ||
241 | |||
242 | void BindKeyCmd::execute() { | ||
243 | if (Fluxbox::instance()->keys() != 0) { | ||
244 | if (Fluxbox::instance()->keys()->addBinding(m_keybind)) { | ||
245 | ofstream ofile(Fluxbox::instance()->keys()->filename().c_str(), ios::app); | ||
246 | if (!ofile) | ||
247 | return; | ||
248 | ofile<<m_keybind<<endl; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | }; // end namespace FbCommands | ||