_info = _epist->getScreenInfo(_number);
_root = _info->getRootWindow();
- cout << "root window on screen " << _number << ": 0x" << hex << _root <<
- dec << endl;
-
// find a window manager supporting NETWM, waiting for it to load if we must
int count = 20; // try for 20 seconds
_managed = false;
while (! (_epist->doShutdown() || _managed || count <= 0)) {
if (! (_managed = findSupportingWM()))
- usleep(1000);
+ sleep(1);
--count;
}
if (_managed)
// find a window if one exists
WindowList::const_iterator it, end = _clients.end();
for (it = _clients.begin(); it != end; ++it)
- if ((*it)->getScreen() == this)
+ if ((*it)->getScreen() == this && ! (*it)->iconic() &&
+ ((*it)->desktop() == 0xffffffff || (*it)->desktop() == _active_desktop))
return *it;
// no windows on this screen
}
}
_active = it;
- _last_active = it;
+ if (it != end)
+ _last_active = it;
/* cout << "Active window is now: ";
if (_active == _clients.end()) cout << "None\n";
}
-void screen::execCommand(const std::string &cmd) const {
+void screen::execCommand(const string &cmd) const {
pid_t pid;
if ((pid = fork()) == 0) {
- extern char **environ;
-
- char *const argv[] = {
- "sh",
- "-c",
- const_cast<char *>(cmd.c_str()),
- 0
- };
// make the command run on the correct screen
if (putenv(const_cast<char*>(_info->displayString().c_str()))) {
cout << "warning: couldn't set environment variable 'DISPLAY'\n";
perror("putenv()");
}
- execve("/bin/sh", argv, environ);
- exit(127);
+ execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
+ exit(-1);
} else if (pid == -1) {
cout << _epist->getApplicationName() <<
": Could not fork a process for executing a command\n";
classname = (*_active)->appClass();
WindowList::const_iterator target = _active,
- first = _active,
begin = _clients.begin(),
end = _clients.end();
- do {
+ while (1) {
if (forward) {
if (target == end) {
target = begin;
}
// must be no window to focus
- if (target == first)
+ if (target == _active)
return;
- } while ((*target)->iconic() ||
- (! allscreens && (*target)->getScreen() != this) ||
- (! alldesktops && (*target)->desktop() != _active_desktop) ||
- (sameclass && ! classname.empty() &&
- (*target)->appClass() != classname));
-
- if (target != _clients.end())
- (*target)->focus();
+
+ // determine if this window is invalid for cycling to
+ const XWindow *t = *target;
+ if (t->iconic()) continue;
+ if (! allscreens && t->getScreen() != this) continue;
+ if (! alldesktops && ! (t->desktop() == _active_desktop ||
+ t->desktop() == 0xffffffff)) continue;
+ if (sameclass && ! classname.empty() &&
+ t->appClass() != classname) continue;
+ if (! t->canFocus()) continue;
+
+ // found a good window!
+ t->focus();
+ return;
+ }
}