From 4545f4dac81f61b7e99769006888a8688eeb542c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Wed, 14 Sep 2016 18:11:06 +0200 Subject: support OnWinButton, OnMinButton & OnMaxButton ... actions in keys. This allows to override the default behavior as well as adding actions for the mouse wheel. Special casing of the two "geometry" related buttons (eg. to perform smart maximization, reverse the partial maximzation, add shading to the min button or whatnot) All other buttons have a rather dedicated meaning and are only really interesting for adding mouse wheels or eg. the window menu on rmb clicks. Needs docu. --- src/Keys.cc | 6 ++++++ src/Keys.hh | 5 ++++- src/WinButton.cc | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 072cba9..846edea 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -400,6 +400,12 @@ bool Keys::addBinding(const string &linebuffer) { context |= ON_WINDOW; else if (arg == "ontitlebar") context |= ON_TITLEBAR; + else if (arg == "onwinbutton") + context |= ON_WINBUTTON; + else if (arg == "onminbutton") + context |= ON_MINBUTTON; // one char diff, oh great ... ... blast! + else if (arg == "onmaxbutton") + context |= ON_MAXBUTTON; else if (arg == "onwindowborder") context |= ON_WINDOWBORDER; else if (arg == "onleftgrip") diff --git a/src/Keys.hh b/src/Keys.hh index 7a6b3b8..a12efdb 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -53,7 +53,10 @@ public: ON_LEFTGRIP = 1 << 7, ON_RIGHTGRIP = 1 << 8, ON_TAB = 1 << 9, - ON_SLIT = 1 << 10 + ON_SLIT = 1 << 10, + ON_WINBUTTON = 1 << 11, + ON_MINBUTTON = 1 << 12, + ON_MAXBUTTON = 1 << 13 // and so on... }; diff --git a/src/WinButton.cc b/src/WinButton.cc index c790a03..0cd2cfb 100644 --- a/src/WinButton.cc +++ b/src/WinButton.cc @@ -20,6 +20,8 @@ // DEALINGS IN THE SOFTWARE. #include "WinButton.hh" +#include "fluxbox.hh" +#include "Keys.hh" #include "Window.hh" #include "WindowCmd.hh" #include "Screen.hh" @@ -27,6 +29,8 @@ #include "WinButtonTheme.hh" #include "FbTk/App.hh" #include "FbTk/Color.hh" +#include "FbTk/Command.hh" +#include "FbTk/RefCount.hh" #ifdef SHAPE #include @@ -56,11 +60,33 @@ void WinButton::exposeEvent(XExposeEvent &event) { drawType(); } -void WinButton::buttonReleaseEvent(XButtonEvent &event) { - WinClient *old = WindowCmd::client(); +void WinButton::buttonReleaseEvent(XButtonEvent &be) { + bool didCustomAction = false; + if (isPressed() && be.button > 0 && be.button <= 5 && + be.x >= -static_cast(borderWidth()) && + be.x <= static_cast(width()+borderWidth()) && + be.y >= -static_cast(borderWidth()) && + be.y <= static_cast(height()+borderWidth())) { + int context = Keys::ON_WINBUTTON; + if (m_type == MINIMIZE) + context = Keys::ON_MINBUTTON; + if (m_type == MAXIMIZE) + context = Keys::ON_MAXBUTTON; + Keys *k = Fluxbox::instance()->keys(); + didCustomAction = k->doAction(be.type, be.state, be.button, context, &m_listen_to.winClient(), be.time); + } + static FbTk::RefCount > noop = FbTk::RefCount >(0); + FbTk::RefCount > oldCmd; + if (didCustomAction) { + oldCmd = command(be.button); + setOnClick(noop, be.button); + } + WinClient *oldClient = WindowCmd::client(); WindowCmd::setWindow(&m_listen_to); - FbTk::Button::buttonReleaseEvent(event); - WindowCmd::setClient(old); + FbTk::Button::buttonReleaseEvent(be); + WindowCmd::setClient(oldClient); + if (didCustomAction) + setOnClick(oldCmd, be.button); } // when someone else tries to set the background, we may override it -- cgit v0.11.2