From dce0e2e40c9fed226139c3def26e423b75c6bb9c Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 2 May 2005 12:10:01 +0000 Subject: using Select2nd --- src/Screen.cc | 35 +++++++------ src/Window.cc | 162 ++++++++++++++++++++++++++++++--------------------------- src/fluxbox.cc | 38 +++++++------- src/fluxbox.hh | 6 ++- 4 files changed, 124 insertions(+), 117 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index b83296e..36ab193 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -69,6 +69,8 @@ #include "FbTk/ImageControl.hh" #include "FbTk/EventManager.hh" #include "FbTk/Transparent.hh" +#include "FbTk/Select2nd.hh" +#include "FbTk/Compose.hh" //use GNU extensions #ifndef _GNU_SOURCE @@ -830,16 +832,17 @@ void BScreen::removeClient(WinClient &client) { for_each(getWorkspacesList().begin(), getWorkspacesList().end(), mem_fun(&Workspace::updateClientmenu)); + using namespace FbTk; + // remove any grouping this is expecting - Groupables::iterator it = m_expecting_groups.begin(); - Groupables::iterator it_end = m_expecting_groups.end(); - for (; it != it_end; ++it) { - if (it->second == &client) { - m_expecting_groups.erase(it); - // it should only be in there a maximum of once - break; - } - } + Groupables::iterator erase_it = find_if(m_expecting_groups.begin(), + m_expecting_groups.end(), + Compose(bind2nd(equal_to(), &client), + Select2nd())); + + if (erase_it != m_expecting_groups.end()) + m_expecting_groups.erase(erase_it); + // the client could be on icon menu so we update it //!! TODO: check this with the new icon menu // updateIconMenu(); @@ -1711,14 +1714,12 @@ void BScreen::addConfigMenu(const char *label, FbTk::Menu &menu) { } void BScreen::removeConfigMenu(FbTk::Menu &menu) { - Configmenus::iterator it = m_configmenu_list.begin(); - Configmenus::iterator it_end = m_configmenu_list.end(); - for (; it != it_end; ++it) { - if (it->second == &menu) { - m_configmenu_list.erase(it); - break; - } - } + Configmenus::iterator erase_it = find_if(m_configmenu_list.begin(), + m_configmenu_list.end(), + FbTk::Compose(bind2nd(equal_to(), &menu), + FbTk::Select2nd())); + if (erase_it != m_configmenu_list.end()) + m_configmenu_list.erase(erase_it); setupConfigmenu(*m_configmenu.get()); } diff --git a/src/Window.cc b/src/Window.cc index 50b6f53..02a9d7f 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -45,6 +45,7 @@ #include "FbTk/EventManager.hh" #include "FbTk/KeyUtil.hh" #include "FbTk/SimpleCommand.hh" +#include "FbTk/Select2nd.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -81,15 +82,18 @@ #include using namespace std; +using namespace FbTk; namespace { -void grabButton(Display *display, unsigned int button, +void grabButton(unsigned int button, Window window, Cursor cursor) { - const int numlock = FbTk::KeyUtil::instance().numlock(); - const int capslock = FbTk::KeyUtil::instance().capslock(); - const int scrolllock = FbTk::KeyUtil::instance().scrolllock(); + static Display *display = App::instance()->display(); + + const int numlock = KeyUtil::instance().numlock(); + const int capslock = KeyUtil::instance().capslock(); + const int scrolllock = KeyUtil::instance().scrolllock(); // Grab with Mod1 and with all lock modifiers // (num, scroll and caps) @@ -863,8 +867,8 @@ bool FluxboxWindow::removeClient(WinClient &client) { WinClient *FluxboxWindow::findClient(Window win) { ClientList::iterator it = find_if(clientList().begin(), clientList().end(), - FbTk::Compose(bind2nd(equal_to(), win), - mem_fun(&WinClient::window))); + Compose(bind2nd(equal_to(), win), + mem_fun(&WinClient::window))); return (it == clientList().end() ? 0 : *it); } @@ -941,74 +945,77 @@ void FluxboxWindow::moveClientRight() { //std::list<*WinClient>::iterator FluxboxWindow::getClientInsertPosition(int x, int y) { FluxboxWindow::ClientList::iterator FluxboxWindow::getClientInsertPosition(int x, int y) { - int dest_x=0, dest_y=0; - Window labelbutton=0; - if(!XTranslateCoordinates(FbTk::App::instance()->display(), - parent().window(), frame().label().window(), - x,y, &dest_x, &dest_y, - &labelbutton)) - return m_clientlist.end(); - Client2ButtonMap::iterator it = m_labelbuttons.begin(); - Client2ButtonMap::iterator it_end = m_labelbuttons.end(); - //find the label button to move next to - for(; it!=it_end; it++) { - if( (*it).second->window()==labelbutton) - break; - } - //label button not found - if(it==it_end) { - return m_clientlist.end(); - } - Window child_return=0; - //make x and y relative to our labelbutton - if(!XTranslateCoordinates(FbTk::App::instance()->display(), - frame().label().window(),labelbutton, - dest_x,dest_y, &x, &y, - &child_return)) - return m_clientlist.end(); - ClientList::iterator client = find(m_clientlist.begin(), - m_clientlist.end(), - it->first); - if(x>(*it).second->width()/2) - client++; - return client; - + int dest_x = 0, dest_y = 0; + Window labelbutton = 0; + if (!XTranslateCoordinates(FbTk::App::instance()->display(), + parent().window(), frame().label().window(), + x, y, &dest_x, &dest_y, + &labelbutton)) + return m_clientlist.end(); + + Client2ButtonMap::iterator it = m_labelbuttons.begin(); + Client2ButtonMap::iterator it_end = m_labelbuttons.end(); + // find the label button to move next to + for (; it != it_end; it++) { + if ((*it).second->window() == labelbutton) + break; + } + + // label button not found + if (it == m_labelbuttons.end()) + return m_clientlist.end(); + + Window child_return=0; + // make x and y relative to our labelbutton + if (!XTranslateCoordinates(FbTk::App::instance()->display(), + frame().label().window(), labelbutton, + dest_x, dest_y, &x, &y, + &child_return)) + return m_clientlist.end(); + + ClientList::iterator client = find(m_clientlist.begin(), + m_clientlist.end(), + it->first); + if (x > (*it).second->width() / 2) + client++; + + return client; } void FluxboxWindow::moveClientTo(WinClient &win, int x, int y) { - int dest_x=0, dest_y=0; - Window labelbutton=0; - if(!XTranslateCoordinates(FbTk::App::instance()->display(), - parent().window(), frame().label().window(), - x,y, &dest_x, &dest_y, - &labelbutton)) - return; - Client2ButtonMap::iterator it = m_labelbuttons.begin(); - Client2ButtonMap::iterator it_end = m_labelbuttons.end(); - //find the label button to move next to - for(; it!=it_end; it++) { - if( (*it).second->window()==labelbutton) - break; - } - //label button not found - if(it==it_end) { - return; - } - Window child_return=0; - //make x and y relative to our labelbutton - if(!XTranslateCoordinates(FbTk::App::instance()->display(), - frame().label().window(),labelbutton, - dest_x,dest_y, &x, &y, - &child_return)) - return; - if(x>(*it).second->width()/2) { - moveClientRightOf(win, *it->first); - } else { - moveClientLeftOf(win, *it->first); - } + int dest_x = 0, dest_y = 0; + Window labelbutton = 0; + if (!XTranslateCoordinates(FbTk::App::instance()->display(), + parent().window(), frame().label().window(), + x, y, &dest_x, &dest_y, + &labelbutton)) + return; + Client2ButtonMap::iterator it = m_labelbuttons.begin(); + Client2ButtonMap::iterator it_end = m_labelbuttons.end(); + //find the label button to move next to + for (; it != it_end; it++) { + if ((*it).second->window() == labelbutton) + break; + } + + // label button not found + if (it == it_end) + return; + + Window child_return = 0; + //make x and y relative to our labelbutton + if (!XTranslateCoordinates(FbTk::App::instance()->display(), + frame().label().window(), labelbutton, + dest_x, dest_y, &x, &y, + &child_return)) + return; + if (x > (*it).second->width() / 2) + moveClientRightOf(win, *it->first); + else + moveClientLeftOf(win, *it->first); } @@ -1154,7 +1161,7 @@ void FluxboxWindow::grabButtons() { GrabModeAsync, None, frame().theme().moveCursor()); //----grab with "all" modifiers - grabButton(display, Button1, frame().window().window(), frame().theme().moveCursor()); + grabButton(Button1, frame().window().window(), frame().theme().moveCursor()); XGrabButton(display, Button2, Mod1Mask, frame().window().window(), True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); @@ -1164,7 +1171,7 @@ void FluxboxWindow::grabButtons() { GrabModeAsync, None, None); //---grab with "all" modifiers - grabButton(display, Button3, frame().window().window(), None); + grabButton(Button3, frame().window().window(), None); } } @@ -3772,14 +3779,13 @@ void FluxboxWindow::addExtraMenu(const char *label, FbTk::Menu *menu) { } void FluxboxWindow::removeExtraMenu(FbTk::Menu *menu) { - ExtraMenus::iterator it = m_extramenus.begin(); - ExtraMenus::iterator it_end = m_extramenus.end(); - for (; it != it_end; ++it) { - if (it->second == menu) { - m_extramenus.erase(it); - break; - } - } + ExtraMenus::iterator it = find_if(m_extramenus.begin(), + m_extramenus.end(), + Compose(bind2nd(equal_to(), menu), + Select2nd())); + if (it != m_extramenus.end()) + m_extramenus.erase(it); + setupMenu(); } diff --git a/src/fluxbox.cc b/src/fluxbox.cc index ce3161a..cd289ed 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -51,6 +51,8 @@ #include "FbTk/SimpleCommand.hh" #include "FbTk/CompareEqual.hh" #include "FbTk/Transparent.hh" +#include "FbTk/Select2nd.hh" +#include "FbTk/Compose.hh" //Use GNU extensions #ifndef _GNU_SOURCE @@ -1329,11 +1331,13 @@ BScreen *Fluxbox::searchScreen(Window window) { AtomHandler* Fluxbox::getAtomHandler(const std::string &name) { if ( name != "" ) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); it++ ) { - if ( name == (*it).second ) - return (*it).first; - } + using namespace FbTk; + AtomHandlerContainerIt it = find_if(m_atomhandler.begin(), + m_atomhandler.end(), + Compose(bind2nd(equal_to(), name), + Select2nd())); + if (it != m_atomhandler.end()) + return (*it).first; } return 0; } @@ -1342,7 +1346,6 @@ void Fluxbox::addAtomHandler(AtomHandler *atomh, const std::string &name) { } void Fluxbox::removeAtomHandler(AtomHandler *atomh) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); it != m_atomhandler.end(); ++it) { @@ -1354,11 +1357,11 @@ void Fluxbox::removeAtomHandler(AtomHandler *atomh) { } WinClient *Fluxbox::searchWindow(Window window) { - std::map::iterator it = m_window_search.find(window); + WinClientMap::iterator it = m_window_search.find(window); if (it != m_window_search.end()) return it->second; - std::map::iterator git = m_window_search_group.find(window); + WindowMap::iterator git = m_window_search_group.find(window); return git == m_window_search_group.end() ? 0 : &git->second->winClient(); } @@ -1806,18 +1809,13 @@ void Fluxbox::setFocusedWindow(WinClient *client) { if (m_focused_window != 0) { // check if m_focused_window is valid - bool found = false; - std::map::iterator it = m_window_search.begin(); - std::map::iterator it_end = m_window_search.end(); - for (; it != it_end; ++it) { - if (it->second == m_focused_window) { - // we found it, end loop - found = true; - break; - } - } - - if (!found) { + WinClientMap::iterator it = find_if(m_window_search.begin(), + m_window_search.end(), + Compose(bind2nd(equal_to(), m_focused_window), + Select2nd())); + + // if not found... + if (it == m_window_search.end()) { m_focused_window = 0; } else { old_client = m_focused_window; diff --git a/src/fluxbox.hh b/src/fluxbox.hh index a995bd5..f96e7eb 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -273,8 +273,10 @@ private: FbTk::Resource m_rc_auto_raise_delay; FbTk::Resource m_rc_use_mod1; /// temporary!, to disable mod1 for resize/move - std::map m_window_search; - std::map m_window_search_group; + typedef std::map WinClientMap; + WinClientMap m_window_search; + typedef std::map WindowMap; + WindowMap m_window_search_group; // A window is the group leader, which can map to several // WinClients in the group, it is *not* fluxbox's concept of groups // See ICCCM section 4.1.11 -- cgit v0.11.2