From bc2b21547b290f599ca83297e3131c6c0c87759f Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Fri, 20 Aug 2010 19:01:25 +0200 Subject: implemented 'ActivateTab' action to (re)allow activation of tabs via mouse --- data/keys | 3 +- doc/asciidoc/fluxbox-keys.txt | 3 ++ src/CurrentWindowCmd.cc | 21 +++++++++ src/Keys.cc | 2 + src/Window.cc | 101 ++++++++++++----------------------------- src/Window.hh | 2 + src/fluxbox.cc | 2 +- util/fluxbox-update_configs.cc | 16 +++++++ 8 files changed, 77 insertions(+), 73 deletions(-) diff --git a/data/keys b/data/keys index d29e81b..3bfca00 100644 --- a/data/keys +++ b/data/keys @@ -29,7 +29,8 @@ OnTitlebar Control Mouse1 :StartTabbing OnTitlebar Double Mouse1 :Shade # left click on the titlebar to move the window -OnTitlebar Mouse1 :StartMoving +OnTitlebar Mouse1 :MacroCmd {ActivateTab} {Raise} {Focus} +OnTitlebar Move1 :StartMoving # middle click on the titlebar to lower OnTitlebar Mouse2 :Lower diff --git a/doc/asciidoc/fluxbox-keys.txt b/doc/asciidoc/fluxbox-keys.txt index 3f3431d..41ad1e2 100644 --- a/doc/asciidoc/fluxbox-keys.txt +++ b/doc/asciidoc/fluxbox-keys.txt @@ -184,6 +184,9 @@ Bottom BottomRight* *StartTabbing*:: Start dragging to add this window to another's tabgroup. +*ActivateTab*:: + Activates the tab underneath the mouse. + Window Commands ~~~~~~~~~~~~~~~ These commands ordinarily affect only the currently focused window. The diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc index 713c32a..4d25d54 100644 --- a/src/CurrentWindowCmd.cc +++ b/src/CurrentWindowCmd.cc @@ -223,6 +223,27 @@ FbTk::Command *parseFocusCmd(const string &command, const string &args, REGISTER_COMMAND_PARSER(activate, parseFocusCmd, void); REGISTER_COMMAND_PARSER(focus, parseFocusCmd, void); + +class ActivateTabCmd: public WindowHelperCmd { +public: + ActivateTabCmd() { } +protected: + void real_execute(); +}; + + +void ActivateTabCmd::real_execute() { + + WinClient* winclient = fbwindow().winClientOfLabelButtonWindow( + Fluxbox::instance()->lastEvent().xany.window); + + if (winclient && winclient != &fbwindow().winClient()) { + fbwindow().setCurrentClient(*winclient, true); + } +} + +REGISTER_COMMAND(activatetab, ActivateTabCmd, void); + } // end anonymous namespace void SetHeadCmd::real_execute() { diff --git a/src/Keys.cc b/src/Keys.cc index e8e2ab7..7cd77eb 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -354,6 +354,8 @@ void Keys::loadDefaults() { addBinding("OnDesktop Mouse2 :WorkspaceMenu"); addBinding("OnDesktop Mouse3 :RootMenu"); addBinding("OnTitlebar Mouse3 :WindowMenu"); + addBinding("OnWindow Mouse1 :MacroCmd {Raise} {Focus} {StartMoving}"); + addBinding("OnTitlebar Mouse1 :MacroCmd {ActivateTab} {Raise} {Focus}"); addBinding("OnTitlebar Move1 :StartMoving"); addBinding("OnLeftGrip Move1 :StartResizing bottomleft"); addBinding("OnRightGrip Move1 :StartResizing bottomright"); diff --git a/src/Window.cc b/src/Window.cc index 56cbd96..bf100e2 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -812,16 +812,10 @@ FluxboxWindow::ClientList::iterator FluxboxWindow::getClientInsertPosition(int x &labelbutton)) return m_clientlist.end(); - Client2ButtonMap::iterator it = - find_if(m_labelbuttons.begin(), - m_labelbuttons.end(), - Compose(bind2nd(equal_to(), labelbutton), - Compose(mem_fun(&TextButton::window), - Select2nd()))); - + WinClient* c = winClientOfLabelButtonWindow(labelbutton); // label button not found - if (it == m_labelbuttons.end()) + if (!c) return m_clientlist.end(); Window child_return=0; @@ -834,8 +828,8 @@ FluxboxWindow::ClientList::iterator FluxboxWindow::getClientInsertPosition(int x ClientList::iterator client = find(m_clientlist.begin(), m_clientlist.end(), - it->first); - if (x > static_cast((*it).second->width()) / 2) + c); + if (x > static_cast(m_labelbuttons[c]->width()) / 2) client++; return client; @@ -853,15 +847,9 @@ void FluxboxWindow::moveClientTo(WinClient &win, int x, int y) { &labelbutton)) return; - Client2ButtonMap::iterator it = - find_if(m_labelbuttons.begin(), - m_labelbuttons.end(), - Compose(bind2nd(equal_to(), labelbutton), - Compose(mem_fun(&TextButton::window), - Select2nd()))); + WinClient* client = winClientOfLabelButtonWindow(labelbutton); - // label button not found - if (it == m_labelbuttons.end()) + if (!client) return; Window child_return = 0; @@ -871,10 +859,10 @@ void FluxboxWindow::moveClientTo(WinClient &win, int x, int y) { dest_x, dest_y, &x, &y, &child_return)) return; - if (x > static_cast((*it).second->width()) / 2) - moveClientRightOf(win, *it->first); + if (x > static_cast(m_labelbuttons[client]->width()) / 2) + moveClientRightOf(win, *client); else - moveClientLeftOf(win, *it->first); + moveClientLeftOf(win, *client); } @@ -2360,40 +2348,15 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { frame().insideTitlebar( be.window ) && frame().handle().window() != be.window; -#if 0 // disabled - if (onTitlebar && be.button == 1) - raise(); -#endif - - // check keys file first Keys *k = Fluxbox::instance()->keys(); - if ((onTitlebar && k->doAction(be.type, be.state, be.button, - Keys::ON_TITLEBAR, m_client, be.time)) || - k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, m_client, - be.time)) { + if ((onTitlebar && k->doAction(be.type, be.state, be.button, Keys::ON_TITLEBAR, &winClient(), be.time)) || + k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, &winClient(), be.time)) { + return; } - frame().tabcontainer().tryButtonPressEvent(be); - if (be.button == 1) { - if (frame().window().window() == be.window || - frame().tabcontainer().window() == be.window) { - if (screen().clickRaises()) - raise(); - - fbdbg<<"FluxboxWindow::buttonPressEvent: AllowEvent"<(), ev.window), - Compose(mem_fun(&TextButton::window), - Select2nd()))); - if (it != m_labelbuttons.end()) - client = (*it).first; - + client = winClientOfLabelButtonWindow(ev.window); } if (ev.window == frame().window() || @@ -3149,21 +3104,26 @@ void FluxboxWindow::stopResizing(bool interrupted) { ungrabPointer(CurrentTime); } -void FluxboxWindow::startTabbing(const XButtonEvent &be) { - - if (s_num_grabs > 0) - return; - - m_attaching_tab = 0; - // determine if we're in titlebar +WinClient* FluxboxWindow::winClientOfLabelButtonWindow(Window window) { + WinClient* result = 0; Client2ButtonMap::iterator it = find_if(m_labelbuttons.begin(), m_labelbuttons.end(), - Compose(bind2nd(equal_to(), be.window), - Compose(mem_fun(&TextButton::window), + Compose(bind2nd(equal_to(), window), + Compose(mem_fun(&FbTk::Button::window), Select2nd()))); if (it != m_labelbuttons.end()) - m_attaching_tab = it->first; + result = it->first; + + return result; +} + +void FluxboxWindow::startTabbing(const XButtonEvent &be) { + + if (s_num_grabs > 0) + return; + + m_attaching_tab = winClientOfLabelButtonWindow(be.window); // start drag'n'drop for tab grabPointer(be.window, False, ButtonMotionMask | @@ -3704,8 +3664,6 @@ void FluxboxWindow::associateClient(WinClient &client) { frame().theme().unfocusedTheme()->iconbarTheme(), client); frame().createTab(*btn); - FbTk::RefCount > setcmd(new SetClientCmd(client)); - btn->setOnClick(setcmd, 1); btn->setTextPadding(Fluxbox::instance()->getTabsPadding()); btn->setPixmap(screen().getTabsUsePixmap()); @@ -3715,6 +3673,7 @@ void FluxboxWindow::associateClient(WinClient &client) { evm.add(*this, btn->window()); // we take care of button events for this evm.add(*this, client.window()); + client.setFluxboxWindow(this); join(client.titleSig(), FbTk::MemFun(*this, &FluxboxWindow::setTitle)); diff --git a/src/Window.hh b/src/Window.hh index 5554ad3..d7fd812 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -398,6 +398,8 @@ public: WinClient &winClient() { return *m_client; } const WinClient &winClient() const { return *m_client; } + WinClient* winClientOfLabelButtonWindow(Window w); + bool isTyping() const; const FbTk::XLayerItem &layerItem() const { return m_frame.layerItem(); } diff --git a/src/fluxbox.cc b/src/fluxbox.cc index e8445bb..192b44c 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -605,7 +605,7 @@ void Fluxbox::setupConfigFiles() { if (create_windowmenu) FbTk::FileUtil::copyFile(DEFAULT_WINDOWMENU, windowmenu_file.c_str()); -#define CONFIG_VERSION 11 +#define CONFIG_VERSION 12 FbTk::Resource config_version(m_resourcemanager, 0, "session.configVersion", "Session.ConfigVersion"); if (*config_version < CONFIG_VERSION) { diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc index f4a2019..129833c 100644 --- a/util/fluxbox-update_configs.cc +++ b/util/fluxbox-update_configs.cc @@ -391,11 +391,27 @@ int run_updates(int old_version, FbTk::ResourceManager &rm) { new_keyfile += "OnWindowBorder Move1 :StartMoving\n\n"; new_keyfile += whole_keyfile; // don't forget user's old keybindings + new_keyfile += "\n"; // just for good looks write_file(keyfilename, new_keyfile); new_version = 11; } + if (old_version < 12) { // update keys for ActivateTab + + string whole_file = read_file(keyfilename); + string new_keyfile = ""; + + new_keyfile += "!mouse actions added by fluxbox-update_configs\n"; + new_keyfile += "OnTitlebar Mouse1 :MacroCmd {ActivateTab} {Raise} {Focus}\n"; + new_keyfile += whole_file; + + new_keyfile += "\n"; // just for good looks + write_file(keyfilename, new_keyfile); + + new_version = 12; + } + return new_version; } -- cgit v0.11.2