00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "FbCommands.hh"
00025 #include "fluxbox.hh"
00026 #include "Screen.hh"
00027 #include "CommandDialog.hh"
00028 #include "Workspace.hh"
00029 #include "Keys.hh"
00030
00031 #include "FbTk/Theme.hh"
00032 #include "FbTk/Menu.hh"
00033
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036
00037 #include <fstream>
00038 #include <iostream>
00039 using namespace std;
00040
00041 namespace FbCommands {
00042
00043 ExecuteCmd::ExecuteCmd(const std::string &cmd, int screen_num):m_cmd(cmd), m_screen_num(screen_num) {
00044
00045 }
00046
00047 void ExecuteCmd::execute() {
00048 #ifndef __EMX__
00049 if (! fork()) {
00050 std::string displaystring("DISPLAY=");
00051 displaystring += DisplayString(FbTk::App::instance()->display());
00052 char intbuff[64];
00053 int screen_num = m_screen_num;
00054 if (screen_num < 0) {
00055 if (Fluxbox::instance()->mouseScreen() == 0)
00056 screen_num = 0;
00057 else
00058 screen_num = Fluxbox::instance()->mouseScreen()->screenNumber();
00059 }
00060
00061 sprintf(intbuff, "%d", screen_num);
00062
00063
00064 displaystring.erase(displaystring.size()-1);
00065 displaystring += intbuff;
00066 setsid();
00067 putenv(const_cast<char *>(displaystring.c_str()));
00068 execl("/bin/sh", "/bin/sh", "-c", m_cmd.c_str(), 0);
00069 exit(0);
00070 }
00071 #else // __EMX__
00072 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", item->exec().c_str(), 0);
00073 #endif // !__EMX__
00074
00075 }
00076
00077 void ExitFluxboxCmd::execute() {
00078 Fluxbox::instance()->shutdown();
00079 }
00080
00081 void SaveResources::execute() {
00082 Fluxbox::instance()->save_rc();
00083 }
00084
00085 RestartFluxboxCmd::RestartFluxboxCmd(const std::string &cmd):m_cmd(cmd){
00086 }
00087
00088 void RestartFluxboxCmd::execute() {
00089 if (m_cmd.size() == 0) {
00090 Fluxbox::instance()->restart();
00091 } else {
00092 Fluxbox::instance()->restart(m_cmd.c_str());
00093 }
00094 }
00095
00096 void ReconfigureFluxboxCmd::execute() {
00097 Fluxbox::instance()->reconfigure();
00098 }
00099
00100
00101 void ReloadStyleCmd::execute() {
00102 SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename());
00103 cmd.execute();
00104 }
00105
00106 SetStyleCmd::SetStyleCmd(const std::string &filename):m_filename(filename) {
00107
00108 }
00109
00110 void SetStyleCmd::execute() {
00111 Fluxbox::instance()->saveStyleFilename(m_filename.c_str());
00112 Fluxbox::instance()->save_rc();
00113 FbTk::ThemeManager::instance().load(m_filename);
00114 }
00115
00116 void ShowRootMenuCmd::execute() {
00117 BScreen *screen = Fluxbox::instance()->mouseScreen();
00118 if (screen == 0)
00119 return;
00120
00121 Window root_ret;
00122 Window window_ret;
00123
00124 int rx, ry;
00125 int wx, wy;
00126 unsigned int mask;
00127
00128 if ( XQueryPointer(FbTk::App::instance()->display(),
00129 screen->rootWindow().window(), &root_ret, &window_ret,
00130 &rx, &ry, &wx, &wy, &mask) ) {
00131
00132 if ( rx - (screen->getRootmenu().width()/2) > 0 )
00133 rx-= screen->getRootmenu().width()/2;
00134 screen->getRootmenu().move(rx, ry);
00135 }
00136
00137 screen->getRootmenu().show();
00138 screen->getRootmenu().grabInputFocus();
00139
00140 }
00141
00142 void ShowWorkspaceMenuCmd::execute() {
00143 BScreen *screen = Fluxbox::instance()->mouseScreen();
00144 if (screen == 0)
00145 return;
00146
00147
00148
00149 Window root_ret;
00150 Window window_ret;
00151
00152 int rx, ry;
00153 int wx, wy;
00154 unsigned int mask;
00155
00156 if ( XQueryPointer(FbTk::App::instance()->display(),
00157 screen->rootWindow().window(), &root_ret, &window_ret,
00158 &rx, &ry, &wx, &wy, &mask) ) {
00159
00160 if ( rx - (screen->getWorkspacemenu().width()/2) > 0 )
00161 rx-= screen->getWorkspacemenu().width()/2;
00162 screen->getWorkspacemenu().move(rx, ry);
00163 }
00164 screen->getWorkspacemenu().show();
00165 screen->getWorkspacemenu().grabInputFocus();
00166
00167 }
00168
00169
00170
00171 SetWorkspaceNameCmd::SetWorkspaceNameCmd(const std::string &name, int spaceid):
00172 m_name(name), m_workspace(spaceid) { }
00173
00174 void SetWorkspaceNameCmd::execute() {
00175 BScreen *screen = Fluxbox::instance()->mouseScreen();
00176 if (screen == 0) {
00177 screen = Fluxbox::instance()->keyScreen();
00178 if (screen == 0)
00179 return;
00180 }
00181
00182 if (m_workspace < 0) {
00183 screen->currentWorkspace()->setName(m_name);
00184 } else {
00185 Workspace *space = screen->getWorkspace(m_workspace);
00186 if (space == 0)
00187 return;
00188 space->setName(m_name);
00189 }
00190
00191 screen->updateWorkspaceNamesAtom();
00192 Fluxbox::instance()->save_rc();
00193 }
00194
00195 void WorkspaceNameDialogCmd::execute() {
00196
00197 BScreen *screen = Fluxbox::instance()->mouseScreen();
00198 if (screen == 0)
00199 return;
00200
00201 CommandDialog *win = new CommandDialog(*screen, "Set Workspace Name:", "SetWorkspaceName ");
00202 win->setText(screen->currentWorkspace()->name());
00203 win->show();
00204 }
00205
00206 void CommandDialogCmd::execute() {
00207 BScreen *screen = Fluxbox::instance()->mouseScreen();
00208 if (screen == 0)
00209 return;
00210
00211 FbTk::FbWindow *win = new CommandDialog(*screen, "Fluxbox Command");
00212 win->show();
00213 }
00214
00215
00216 SetResourceValueCmd::SetResourceValueCmd(const std::string &resname,
00217 const std::string &value):
00218 m_resname(resname),
00219 m_value(value) {
00220
00221 }
00222
00223 void SetResourceValueCmd::execute() {
00224 BScreen *screen = Fluxbox::instance()->mouseScreen();
00225 if (screen == 0)
00226 return;
00227 screen->resourceManager().setResourceValue(m_resname, m_value);
00228 Fluxbox::instance()->save_rc();
00229 }
00230
00231 void SetResourceValueDialogCmd::execute() {
00232 BScreen *screen = Fluxbox::instance()->mouseScreen();
00233 if (screen == 0)
00234 return;
00235
00236 FbTk::FbWindow *win = new CommandDialog(*screen, "Type resource name and the value", "SetResourceValue ");
00237 win->show();
00238 };
00239
00240 BindKeyCmd::BindKeyCmd(const std::string &keybind):m_keybind(keybind) { }
00241
00242 void BindKeyCmd::execute() {
00243 if (Fluxbox::instance()->keys() != 0) {
00244 if (Fluxbox::instance()->keys()->addBinding(m_keybind)) {
00245 ofstream ofile(Fluxbox::instance()->keys()->filename().c_str(), ios::app);
00246 if (!ofile)
00247 return;
00248 ofile<<m_keybind<<endl;
00249 }
00250 }
00251 }
00252
00253 };