using Select2nd

This commit is contained in:
fluxgen 2005-05-02 12:10:01 +00:00
parent 6b943ec69a
commit dce0e2e40c
4 changed files with 124 additions and 117 deletions

View file

@ -69,6 +69,8 @@
#include "FbTk/ImageControl.hh" #include "FbTk/ImageControl.hh"
#include "FbTk/EventManager.hh" #include "FbTk/EventManager.hh"
#include "FbTk/Transparent.hh" #include "FbTk/Transparent.hh"
#include "FbTk/Select2nd.hh"
#include "FbTk/Compose.hh"
//use GNU extensions //use GNU extensions
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
@ -830,16 +832,17 @@ void BScreen::removeClient(WinClient &client) {
for_each(getWorkspacesList().begin(), getWorkspacesList().end(), for_each(getWorkspacesList().begin(), getWorkspacesList().end(),
mem_fun(&Workspace::updateClientmenu)); mem_fun(&Workspace::updateClientmenu));
using namespace FbTk;
// remove any grouping this is expecting // remove any grouping this is expecting
Groupables::iterator it = m_expecting_groups.begin(); Groupables::iterator erase_it = find_if(m_expecting_groups.begin(),
Groupables::iterator it_end = m_expecting_groups.end(); m_expecting_groups.end(),
for (; it != it_end; ++it) { Compose(bind2nd(equal_to<WinClient *>(), &client),
if (it->second == &client) { Select2nd<Groupables::value_type>()));
m_expecting_groups.erase(it);
// it should only be in there a maximum of once if (erase_it != m_expecting_groups.end())
break; m_expecting_groups.erase(erase_it);
}
}
// the client could be on icon menu so we update it // the client could be on icon menu so we update it
//!! TODO: check this with the new icon menu //!! TODO: check this with the new icon menu
// updateIconMenu(); // updateIconMenu();
@ -1711,14 +1714,12 @@ void BScreen::addConfigMenu(const char *label, FbTk::Menu &menu) {
} }
void BScreen::removeConfigMenu(FbTk::Menu &menu) { void BScreen::removeConfigMenu(FbTk::Menu &menu) {
Configmenus::iterator it = m_configmenu_list.begin(); Configmenus::iterator erase_it = find_if(m_configmenu_list.begin(),
Configmenus::iterator it_end = m_configmenu_list.end(); m_configmenu_list.end(),
for (; it != it_end; ++it) { FbTk::Compose(bind2nd(equal_to<FbTk::Menu *>(), &menu),
if (it->second == &menu) { FbTk::Select2nd<Configmenus::value_type>()));
m_configmenu_list.erase(it); if (erase_it != m_configmenu_list.end())
break; m_configmenu_list.erase(erase_it);
}
}
setupConfigmenu(*m_configmenu.get()); setupConfigmenu(*m_configmenu.get());
} }

View file

@ -45,6 +45,7 @@
#include "FbTk/EventManager.hh" #include "FbTk/EventManager.hh"
#include "FbTk/KeyUtil.hh" #include "FbTk/KeyUtil.hh"
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
#include "FbTk/Select2nd.hh"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -81,15 +82,18 @@
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
using namespace FbTk;
namespace { namespace {
void grabButton(Display *display, unsigned int button, void grabButton(unsigned int button,
Window window, Cursor cursor) { Window window, Cursor cursor) {
const int numlock = FbTk::KeyUtil::instance().numlock(); static Display *display = App::instance()->display();
const int capslock = FbTk::KeyUtil::instance().capslock();
const int scrolllock = FbTk::KeyUtil::instance().scrolllock(); 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 // Grab with Mod1 and with all lock modifiers
// (num, scroll and caps) // (num, scroll and caps)
@ -863,8 +867,8 @@ bool FluxboxWindow::removeClient(WinClient &client) {
WinClient *FluxboxWindow::findClient(Window win) { WinClient *FluxboxWindow::findClient(Window win) {
ClientList::iterator it = find_if(clientList().begin(), ClientList::iterator it = find_if(clientList().begin(),
clientList().end(), clientList().end(),
FbTk::Compose(bind2nd(equal_to<Window>(), win), Compose(bind2nd(equal_to<Window>(), win),
mem_fun(&WinClient::window))); mem_fun(&WinClient::window)));
return (it == clientList().end() ? 0 : *it); return (it == clientList().end() ? 0 : *it);
} }
@ -941,74 +945,77 @@ void FluxboxWindow::moveClientRight() {
//std::list<*WinClient>::iterator FluxboxWindow::getClientInsertPosition(int x, int y) { //std::list<*WinClient>::iterator FluxboxWindow::getClientInsertPosition(int x, int y) {
FluxboxWindow::ClientList::iterator FluxboxWindow::getClientInsertPosition(int x, int y) { FluxboxWindow::ClientList::iterator FluxboxWindow::getClientInsertPosition(int x, int y) {
int dest_x=0, dest_y=0; int dest_x = 0, dest_y = 0;
Window labelbutton=0; Window labelbutton = 0;
if(!XTranslateCoordinates(FbTk::App::instance()->display(), if (!XTranslateCoordinates(FbTk::App::instance()->display(),
parent().window(), frame().label().window(), parent().window(), frame().label().window(),
x,y, &dest_x, &dest_y, x, y, &dest_x, &dest_y,
&labelbutton)) &labelbutton))
return m_clientlist.end(); return m_clientlist.end();
Client2ButtonMap::iterator it = m_labelbuttons.begin();
Client2ButtonMap::iterator it_end = m_labelbuttons.end(); Client2ButtonMap::iterator it = m_labelbuttons.begin();
//find the label button to move next to Client2ButtonMap::iterator it_end = m_labelbuttons.end();
for(; it!=it_end; it++) { // find the label button to move next to
if( (*it).second->window()==labelbutton) for (; it != it_end; it++) {
break; if ((*it).second->window() == labelbutton)
} break;
//label button not found }
if(it==it_end) {
return m_clientlist.end(); // label button not found
} if (it == m_labelbuttons.end())
Window child_return=0; return m_clientlist.end();
//make x and y relative to our labelbutton
if(!XTranslateCoordinates(FbTk::App::instance()->display(), Window child_return=0;
frame().label().window(),labelbutton, // make x and y relative to our labelbutton
dest_x,dest_y, &x, &y, if (!XTranslateCoordinates(FbTk::App::instance()->display(),
&child_return)) frame().label().window(), labelbutton,
return m_clientlist.end(); dest_x, dest_y, &x, &y,
ClientList::iterator client = find(m_clientlist.begin(), &child_return))
m_clientlist.end(), return m_clientlist.end();
it->first);
if(x>(*it).second->width()/2) ClientList::iterator client = find(m_clientlist.begin(),
client++; m_clientlist.end(),
return client; it->first);
if (x > (*it).second->width() / 2)
client++;
return client;
} }
void FluxboxWindow::moveClientTo(WinClient &win, int x, int y) { void FluxboxWindow::moveClientTo(WinClient &win, int x, int y) {
int dest_x=0, dest_y=0; int dest_x = 0, dest_y = 0;
Window labelbutton=0; Window labelbutton = 0;
if(!XTranslateCoordinates(FbTk::App::instance()->display(), if (!XTranslateCoordinates(FbTk::App::instance()->display(),
parent().window(), frame().label().window(), parent().window(), frame().label().window(),
x,y, &dest_x, &dest_y, x, y, &dest_x, &dest_y,
&labelbutton)) &labelbutton))
return; return;
Client2ButtonMap::iterator it = m_labelbuttons.begin(); Client2ButtonMap::iterator it = m_labelbuttons.begin();
Client2ButtonMap::iterator it_end = m_labelbuttons.end(); Client2ButtonMap::iterator it_end = m_labelbuttons.end();
//find the label button to move next to //find the label button to move next to
for(; it!=it_end; it++) { for (; it != it_end; it++) {
if( (*it).second->window()==labelbutton) if ((*it).second->window() == labelbutton)
break; break;
} }
//label button not found
if(it==it_end) { // label button not found
return; if (it == it_end)
} return;
Window child_return=0;
//make x and y relative to our labelbutton Window child_return = 0;
if(!XTranslateCoordinates(FbTk::App::instance()->display(), //make x and y relative to our labelbutton
frame().label().window(),labelbutton, if (!XTranslateCoordinates(FbTk::App::instance()->display(),
dest_x,dest_y, &x, &y, frame().label().window(), labelbutton,
&child_return)) dest_x, dest_y, &x, &y,
return; &child_return))
if(x>(*it).second->width()/2) { return;
moveClientRightOf(win, *it->first); if (x > (*it).second->width() / 2)
} else { moveClientRightOf(win, *it->first);
moveClientLeftOf(win, *it->first); else
} moveClientLeftOf(win, *it->first);
} }
@ -1154,7 +1161,7 @@ void FluxboxWindow::grabButtons() {
GrabModeAsync, None, frame().theme().moveCursor()); GrabModeAsync, None, frame().theme().moveCursor());
//----grab with "all" modifiers //----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, XGrabButton(display, Button2, Mod1Mask, frame().window().window(), True,
ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None);
@ -1164,7 +1171,7 @@ void FluxboxWindow::grabButtons() {
GrabModeAsync, None, None); GrabModeAsync, None, None);
//---grab with "all" modifiers //---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) { void FluxboxWindow::removeExtraMenu(FbTk::Menu *menu) {
ExtraMenus::iterator it = m_extramenus.begin(); ExtraMenus::iterator it = find_if(m_extramenus.begin(),
ExtraMenus::iterator it_end = m_extramenus.end(); m_extramenus.end(),
for (; it != it_end; ++it) { Compose(bind2nd(equal_to<Menu *>(), menu),
if (it->second == menu) { Select2nd<ExtraMenus::value_type>()));
m_extramenus.erase(it); if (it != m_extramenus.end())
break; m_extramenus.erase(it);
}
}
setupMenu(); setupMenu();
} }

View file

@ -51,6 +51,8 @@
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
#include "FbTk/CompareEqual.hh" #include "FbTk/CompareEqual.hh"
#include "FbTk/Transparent.hh" #include "FbTk/Transparent.hh"
#include "FbTk/Select2nd.hh"
#include "FbTk/Compose.hh"
//Use GNU extensions //Use GNU extensions
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
@ -1329,11 +1331,13 @@ BScreen *Fluxbox::searchScreen(Window window) {
AtomHandler* Fluxbox::getAtomHandler(const std::string &name) { AtomHandler* Fluxbox::getAtomHandler(const std::string &name) {
if ( name != "" ) { if ( name != "" ) {
for (AtomHandlerContainerIt it= m_atomhandler.begin(); using namespace FbTk;
it != m_atomhandler.end(); it++ ) { AtomHandlerContainerIt it = find_if(m_atomhandler.begin(),
if ( name == (*it).second ) m_atomhandler.end(),
return (*it).first; Compose(bind2nd(equal_to<string>(), name),
} Select2nd<AtomHandlerContainer::value_type>()));
if (it != m_atomhandler.end())
return (*it).first;
} }
return 0; return 0;
} }
@ -1342,7 +1346,6 @@ void Fluxbox::addAtomHandler(AtomHandler *atomh, const std::string &name) {
} }
void Fluxbox::removeAtomHandler(AtomHandler *atomh) { void Fluxbox::removeAtomHandler(AtomHandler *atomh) {
for (AtomHandlerContainerIt it= m_atomhandler.begin(); for (AtomHandlerContainerIt it= m_atomhandler.begin();
it != m_atomhandler.end(); it != m_atomhandler.end();
++it) { ++it) {
@ -1354,11 +1357,11 @@ void Fluxbox::removeAtomHandler(AtomHandler *atomh) {
} }
WinClient *Fluxbox::searchWindow(Window window) { WinClient *Fluxbox::searchWindow(Window window) {
std::map<Window, WinClient *>::iterator it = m_window_search.find(window); WinClientMap::iterator it = m_window_search.find(window);
if (it != m_window_search.end()) if (it != m_window_search.end())
return it->second; return it->second;
std::map<Window, FluxboxWindow *>::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(); 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) { if (m_focused_window != 0) {
// check if m_focused_window is valid // check if m_focused_window is valid
bool found = false; WinClientMap::iterator it = find_if(m_window_search.begin(),
std::map<Window, WinClient *>::iterator it = m_window_search.begin(); m_window_search.end(),
std::map<Window, WinClient *>::iterator it_end = m_window_search.end(); Compose(bind2nd(equal_to<WinClient *>(), m_focused_window),
for (; it != it_end; ++it) { Select2nd<WinClientMap::value_type>()));
if (it->second == m_focused_window) {
// we found it, end loop // if not found...
found = true; if (it == m_window_search.end()) {
break;
}
}
if (!found) {
m_focused_window = 0; m_focused_window = 0;
} else { } else {
old_client = m_focused_window; old_client = m_focused_window;

View file

@ -273,8 +273,10 @@ private:
FbTk::Resource<time_t> m_rc_auto_raise_delay; FbTk::Resource<time_t> m_rc_auto_raise_delay;
FbTk::Resource<bool> m_rc_use_mod1; /// temporary!, to disable mod1 for resize/move FbTk::Resource<bool> m_rc_use_mod1; /// temporary!, to disable mod1 for resize/move
std::map<Window, WinClient *> m_window_search; typedef std::map<Window, WinClient *> WinClientMap;
std::map<Window, FluxboxWindow *> m_window_search_group; WinClientMap m_window_search;
typedef std::map<Window, FluxboxWindow *> WindowMap;
WindowMap m_window_search_group;
// A window is the group leader, which can map to several // A window is the group leader, which can map to several
// WinClients in the group, it is *not* fluxbox's concept of groups // WinClients in the group, it is *not* fluxbox's concept of groups
// See ICCCM section 4.1.11 // See ICCCM section 4.1.11