cleanup and code deduplication

* ClientPattern.cc: make compiler happy (complaints about XPROP not handled in switch)
* FbTk/FbPixmap.cc FbTk/StringUtil.cc: signed vs unsigned
* FbTk/FbString.cc: missing return
* WinClient.cc: create atoms only once; use helper function
* Window.cc: use a helper function
This commit is contained in:
Mathias Gumz 2010-09-15 01:22:01 +02:00
parent c6047e9eba
commit 2b62cf9733
5 changed files with 54 additions and 51 deletions

View file

@ -373,7 +373,7 @@ bool ClientPattern::addTerm(const FbTk::FbString &str, WinProperty prop, bool ne
if (!term) if (!term)
return rc; return rc;
if (rc = !term->regexp.error()) { if ((rc = !term->regexp.error())) {
m_terms.push_back(term); m_terms.push_back(term);
} else { } else {
delete term; delete term;
@ -383,76 +383,84 @@ bool ClientPattern::addTerm(const FbTk::FbString &str, WinProperty prop, bool ne
} }
FbTk::FbString ClientPattern::getProperty(WinProperty prop, const Focusable &client) { FbTk::FbString ClientPattern::getProperty(WinProperty prop, const Focusable &client) {
FbTk::FbString result;
// we need this for some of the window properties // we need this for some of the window properties
const FluxboxWindow *fbwin = client.fbwindow(); const FluxboxWindow *fbwin = client.fbwindow();
switch (prop) { switch (prop) {
case TITLE: case TITLE:
return client.title().logical(); result = client.title().logical();
break; break;
case CLASS: case CLASS:
return client.getWMClassClass(); result = client.getWMClassClass();
break;
case NAME:
return client.getWMClassName();
break; break;
case ROLE: case ROLE:
return client.getWMRole(); result = client.getWMRole();
break; break;
case TRANSIENT: case TRANSIENT:
return client.isTransient() ? "yes" : "no"; result = client.isTransient() ? "yes" : "no";
break; break;
case MAXIMIZED: case MAXIMIZED:
return (fbwin && fbwin->isMaximized()) ? "yes" : "no"; result = (fbwin && fbwin->isMaximized()) ? "yes" : "no";
break; break;
case MINIMIZED: case MINIMIZED:
return (fbwin && fbwin->isIconic()) ? "yes" : "no"; result = (fbwin && fbwin->isIconic()) ? "yes" : "no";
break; break;
case SHADED: case SHADED:
return (fbwin && fbwin->isShaded()) ? "yes" : "no"; result = (fbwin && fbwin->isShaded()) ? "yes" : "no";
break; break;
case STUCK: case STUCK:
return (fbwin && fbwin->isStuck()) ? "yes" : "no"; result = (fbwin && fbwin->isStuck()) ? "yes" : "no";
break; break;
case FOCUSHIDDEN: case FOCUSHIDDEN:
return (fbwin && fbwin->isFocusHidden()) ? "yes" : "no"; result = (fbwin && fbwin->isFocusHidden()) ? "yes" : "no";
break; break;
case ICONHIDDEN: case ICONHIDDEN:
return (fbwin && fbwin->isIconHidden()) ? "yes" : "no"; result = (fbwin && fbwin->isIconHidden()) ? "yes" : "no";
break; break;
case WORKSPACE: { case WORKSPACE: {
unsigned int wsnum = (fbwin ? fbwin->workspaceNumber() : client.screen().currentWorkspaceID()); unsigned int wsnum = (fbwin ? fbwin->workspaceNumber() : client.screen().currentWorkspaceID());
return FbTk::StringUtil::number2String(wsnum); result = FbTk::StringUtil::number2String(wsnum);
break; break;
} }
case WORKSPACENAME: { case WORKSPACENAME: {
const Workspace *w = (fbwin ? const Workspace *w = (fbwin ?
client.screen().getWorkspace(fbwin->workspaceNumber()) : client.screen().getWorkspace(fbwin->workspaceNumber()) :
client.screen().currentWorkspace()); client.screen().currentWorkspace());
return w ? w->name() : ""; if (w) {
result = w->name();
}
break; break;
} }
case HEAD: { case HEAD:
if (!fbwin) if (fbwin) {
return ""; result = FbTk::StringUtil::number2String(client.screen().getHead(fbwin->fbWindow()));
int head = client.screen().getHead(fbwin->fbWindow()); }
return FbTk::StringUtil::number2String(head);
break; break;
}
case LAYER: case LAYER:
return fbwin ? ::Layer::getString(fbwin->layerNum()) : ""; if (fbwin) {
result = ::Layer::getString(fbwin->layerNum());
}
break; break;
case URGENT: case URGENT:
return Fluxbox::instance()->attentionHandler() result = Fluxbox::instance()->attentionHandler()
.isDemandingAttention(client) ? "yes" : "no"; .isDemandingAttention(client) ? "yes" : "no";
break; break;
case SCREEN: { case SCREEN:
int screenId = client.screen().screenNumber(); result = FbTk::StringUtil::number2String(client.screen().screenNumber());
return FbTk::StringUtil::number2String(screenId); break;
case XPROP:
break;
case NAME:
default:
result = client.getWMClassName();
break; break;
} }
} return result;
return client.getWMClassName();
} }
bool ClientPattern::operator ==(const ClientPattern &pat) const { bool ClientPattern::operator ==(const ClientPattern &pat) const {

View file

@ -369,7 +369,7 @@ bool FbPixmap::rootwinPropertyNotify(int screen_num, Atom atom) {
return false; return false;
checkAtoms(); checkAtoms();
for (int i=0; i < sizeof(root_props)/sizeof(RootProps); ++i) { for (size_t i = 0; i < sizeof(root_props)/sizeof(RootProps); ++i) {
if (root_props[i].atom == atom) { if (root_props[i].atom == atom) {
Pixmap root_pm = None; Pixmap root_pm = None;
Atom real_type; Atom real_type;

View file

@ -126,6 +126,7 @@ const FbString& BiDiString::setLogical(const FbString& logical) {
m_visual_dirty = true; m_visual_dirty = true;
} }
#endif #endif
return m_logical;
} }
const FbString& BiDiString::visual() const { const FbString& BiDiString::visual() const {

View file

@ -183,7 +183,7 @@ string findExtension(const string &filename) {
string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, char trigger, const char alphabet[], size_t len_alphabet, size_t* found) { string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, char trigger, const char alphabet[], size_t len_alphabet, size_t* found) {
for (const char* s = in.c_str(); *s != '\0'; ) { for (const char* s = in.c_str(); *s != '\0'; ) {
if (*s++ == trigger && *s != '\0') { if (*s++ == trigger && *s != '\0') {
for (const char* a = alphabet; (a - alphabet) < len_alphabet; ++a) { for (const char* a = alphabet; (a - alphabet) < static_cast<ssize_t>(len_alphabet); ++a) {
if (*s == *a) { if (*s == *a) {
if (found) { if (found) {
*found = a - alphabet; *found = a - alphabet;

View file

@ -133,6 +133,16 @@ WinClient *getRootTransientFor(WinClient *client) {
} }
void callForAllTransient(FluxboxWindow& win, void (*callFunc)(FluxboxWindow&)) {
WinClient::TransientList::const_iterator it = win.winClient().transientList().begin();
WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end();
for (; it != it_end; ++it) {
if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic())
// TODO: should we also check if it is the active client?
callFunc(*(*it)->fbwindow());
}
}
/// raise window and do the same for each transient of the current window /// raise window and do the same for each transient of the current window
void raiseFluxboxWindow(FluxboxWindow &win) { void raiseFluxboxWindow(FluxboxWindow &win) {
if (win.oplock) if (win.oplock)
@ -150,19 +160,10 @@ void raiseFluxboxWindow(FluxboxWindow &win) {
win.layerItem().raise(); win.layerItem().raise();
// for each transient do raise callForAllTransient(win, raiseFluxboxWindow);
WinClient::TransientList::const_iterator it = win.winClient().transientList().begin();
WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end();
for (; it != it_end; ++it) {
if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic())
// TODO: should we also check if it is the active client?
raiseFluxboxWindow(*(*it)->fbwindow());
}
win.oplock = false; win.oplock = false;
if (!win.winClient().transientList().empty()) if (!win.winClient().transientList().empty())
win.screen().layerManager().unlock(); win.screen().layerManager().unlock();
@ -210,16 +211,9 @@ void tempRaiseFluxboxWindow(FluxboxWindow &win) {
win.layerItem().tempRaise(); win.layerItem().tempRaise();
} }
// for each transient do raise callForAllTransient(win, tempRaiseFluxboxWindow);
WinClient::TransientList::const_iterator it = win.winClient().transientList().begin();
WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end();
for (; it != it_end; ++it) {
if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic())
// TODO: should we also check if it is the active client?
tempRaiseFluxboxWindow(*(*it)->fbwindow());
}
win.oplock = false;
win.oplock = false;
} }
class SetClientCmd:public FbTk::Command<void> { class SetClientCmd:public FbTk::Command<void> {
@ -1063,8 +1057,8 @@ void FluxboxWindow::reconfigure() {
m_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay()); m_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay());
updateButtons(); updateButtons();
frame().reconfigure();
frame().reconfigure();
menu().reconfigure(); menu().reconfigure();
Client2ButtonMap::iterator it = m_labelbuttons.begin(), Client2ButtonMap::iterator it = m_labelbuttons.begin(),