aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2006-02-12 08:03:47 (GMT)
committerfluxgen <fluxgen>2006-02-12 08:03:47 (GMT)
commit6eae743582c8fb4d95895f82ed809762b32898c5 (patch)
tree07bcb0554a0a0b7ad29b2e011d61e853054dd7eb
parent3ceb311a322081cd17b449df373d366dde2fad47 (diff)
downloadfluxbox_paul-6eae743582c8fb4d95895f82ed809762b32898c5.zip
fluxbox_paul-6eae743582c8fb4d95895f82ed809762b32898c5.tar.bz2
added run() for ExecuteCmd, which returns pid of the child process
-rw-r--r--src/FbCommands.cc58
-rw-r--r--src/FbCommands.hh4
2 files changed, 37 insertions, 25 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index e188a40..8e4f69b 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -113,34 +113,42 @@ ExecuteCmd::ExecuteCmd(const std::string &cmd, int screen_num):m_cmd(cmd), m_scr
113 113
114void ExecuteCmd::execute() { 114void ExecuteCmd::execute() {
115#ifndef __EMX__ 115#ifndef __EMX__
116 if (! fork()) { 116 run();
117 std::string displaystring("DISPLAY=");
118 displaystring += DisplayString(FbTk::App::instance()->display());
119 char intbuff[64];
120 int screen_num = m_screen_num;
121 if (screen_num < 0) {
122 if (Fluxbox::instance()->mouseScreen() == 0)
123 screen_num = 0;
124 else
125 screen_num = Fluxbox::instance()->mouseScreen()->screenNumber();
126 }
127
128 sprintf(intbuff, "%d", screen_num);
129
130 // remove last number of display and add screen num
131 displaystring.erase(displaystring.size()-1);
132 displaystring += intbuff;
133 setsid();
134 putenv(const_cast<char *>(displaystring.c_str()));
135 execl("/bin/sh", "/bin/sh", "-c", m_cmd.c_str(), static_cast<void*>(NULL));
136 exit(0);
137 }
138#else // __EMX__ 117#else // __EMX__
139 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", m_cmd.c_str(), static_cast<void*>(NULL)); 118 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", m_cmd.c_str(), static_cast<void*>(NULL));
140#endif // !__EMX__ 119#endif // !__EMX__
141 120
142} 121}
143 122
123int ExecuteCmd::run() {
124 pid_t pid = fork();
125 if (pid)
126 return pid;
127
128 std::string displaystring("DISPLAY=");
129 displaystring += DisplayString(FbTk::App::instance()->display());
130 char intbuff[64];
131 int screen_num = m_screen_num;
132 if (screen_num < 0) {
133 if (Fluxbox::instance()->mouseScreen() == 0)
134 screen_num = 0;
135 else
136 screen_num = Fluxbox::instance()->mouseScreen()->screenNumber();
137 }
138
139 sprintf(intbuff, "%d", screen_num);
140
141 // remove last number of display and add screen num
142 displaystring.erase(displaystring.size()-1);
143 displaystring += intbuff;
144 setsid();
145 putenv(const_cast<char *>(displaystring.c_str()));
146 execl("/bin/sh", "/bin/sh", "-c", m_cmd.c_str(), static_cast<void*>(NULL));
147 exit(0);
148
149 return pid; // compiler happy -> we are happy ;)
150}
151
144ExportCmd::ExportCmd(const std::string& name, const std::string& value) : 152ExportCmd::ExportCmd(const std::string& name, const std::string& value) :
145 m_name(name), m_value(value) { 153 m_name(name), m_value(value) {
146} 154}
@@ -214,7 +222,7 @@ void SetStyleCmd::execute() {
214 Fluxbox::instance()->saveStyleFilename(m_filename.c_str()); 222 Fluxbox::instance()->saveStyleFilename(m_filename.c_str());
215 Fluxbox::instance()->save_rc(); 223 Fluxbox::instance()->save_rc();
216 FbTk::ThemeManager::instance().load(m_filename, 224 FbTk::ThemeManager::instance().load(m_filename,
217 Fluxbox::instance()->getStyleOverlayFilename()); 225 Fluxbox::instance()->getStyleOverlayFilename());
218} 226}
219 227
220void ShowRootMenuCmd::execute() { 228void ShowRootMenuCmd::execute() {
@@ -339,7 +347,7 @@ void DeiconifyCmd::execute() {
339 for(; it != itend; it++) { 347 for(; it != itend; it++) {
340 old_workspace_num= (*it)->workspaceNumber(); 348 old_workspace_num= (*it)->workspaceNumber();
341 if (m_mode == ALL || old_workspace_num == workspace_num || 349 if (m_mode == ALL || old_workspace_num == workspace_num ||
342 (*it)->isStuck()) { 350 (*it)->isStuck()) {
343 if (m_dest == ORIGIN || m_dest == ORIGINQUIET) 351 if (m_dest == ORIGIN || m_dest == ORIGINQUIET)
344 screen->sendToWorkspace(old_workspace_num, (*it), change_ws); 352 screen->sendToWorkspace(old_workspace_num, (*it), change_ws);
345 else 353 else
@@ -354,7 +362,7 @@ void DeiconifyCmd::execute() {
354 for (; it != itend; it++) { 362 for (; it != itend; it++) {
355 old_workspace_num= (*it)->workspaceNumber(); 363 old_workspace_num= (*it)->workspaceNumber();
356 if(m_mode == LAST || old_workspace_num == workspace_num || 364 if(m_mode == LAST || old_workspace_num == workspace_num ||
357 (*it)->isStuck()) { 365 (*it)->isStuck()) {
358 if ((m_dest == ORIGIN || m_dest == ORIGINQUIET) && 366 if ((m_dest == ORIGIN || m_dest == ORIGINQUIET) &&
359 m_mode != LASTWORKSPACE) 367 m_mode != LASTWORKSPACE)
360 screen->sendToWorkspace(old_workspace_num, (*it), change_ws); 368 screen->sendToWorkspace(old_workspace_num, (*it), change_ws);
diff --git a/src/FbCommands.hh b/src/FbCommands.hh
index 1f7200d..2007e89 100644
--- a/src/FbCommands.hh
+++ b/src/FbCommands.hh
@@ -37,6 +37,10 @@ class ExecuteCmd: public FbTk::Command {
37public: 37public:
38 ExecuteCmd(const std::string &cmd, int screen_num = -1); 38 ExecuteCmd(const std::string &cmd, int screen_num = -1);
39 void execute(); 39 void execute();
40 /**
41 * same as execute but returns pid
42 */
43 int run();
40private: 44private:
41 std::string m_cmd; 45 std::string m_cmd;
42 const int m_screen_num; 46 const int m_screen_num;