From 611b6aa57e34ed8e52cb6b88c9adbafe4d67c6e2 Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Mon, 11 Feb 2008 10:17:45 -0800 Subject: more fun with the window menu --- src/FbMenu.cc | 19 +++++++++++++++++++ src/FbMenu.hh | 10 ++++++++++ src/IconbarTool.cc | 2 +- src/Keys.cc | 8 +++++++- src/Keys.hh | 3 ++- src/Screen.cc | 8 +------- src/Toolbar.cc | 13 +------------ src/Window.cc | 30 +++++++++--------------------- 8 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/FbMenu.cc b/src/FbMenu.cc index 54b6c4a..12ee2f1 100644 --- a/src/FbMenu.cc +++ b/src/FbMenu.cc @@ -23,6 +23,9 @@ #include "fluxbox.hh" #include "Screen.hh" +#include "WindowCmd.hh" + +FluxboxWindow *FbMenu::s_window = 0; FbMenu::FbMenu(FbTk::ThemeProxy &tm, FbTk::ImageControl &imgctrl, FbTk::XLayer &layer): @@ -31,6 +34,16 @@ FbMenu::FbMenu(FbTk::ThemeProxy &tm, } +void FbMenu::show() { + WindowCmd::setWindow(s_window); + FbTk::Menu::show(); +} + +void FbMenu::buttonPressEvent(XButtonEvent &be) { + WindowCmd::setWindow(s_window); + FbTk::Menu::buttonPressEvent(be); +} + void FbMenu::buttonReleaseEvent(XButtonEvent &be) { BScreen *screen = Fluxbox::instance()->findScreen(screenNumber()); if (be.window == titleWindow() && isMoving() && screen) { @@ -41,7 +54,13 @@ void FbMenu::buttonReleaseEvent(XButtonEvent &be) { screen->getHeadWidth(head), screen->getHeadHeight(head)); } + WindowCmd::setWindow(s_window); // now get on with the show FbTk::Menu::buttonReleaseEvent(be); } + +void FbMenu::keyPressEvent(XKeyEvent &ke) { + WindowCmd::setWindow(s_window); + FbTk::Menu::keyPressEvent(ke); +} diff --git a/src/FbMenu.hh b/src/FbMenu.hh index 9114192..b9c4654 100644 --- a/src/FbMenu.hh +++ b/src/FbMenu.hh @@ -25,6 +25,8 @@ #include "FbTk/Menu.hh" #include "FbTk/XLayerItem.hh" +class FluxboxWindow; + namespace FbTk { class MenuTheme; } @@ -37,9 +39,17 @@ public: virtual ~FbMenu() { } void raise() { m_layeritem.raise(); } void lower() { m_layeritem.lower(); } + void show(); + void buttonPressEvent(XButtonEvent &be); void buttonReleaseEvent(XButtonEvent &be); + void keyPressEvent(XKeyEvent &ke); + + static void setWindow(FluxboxWindow *win) { s_window = win; } + static FluxboxWindow *window() { return s_window; } + private: FbTk::XLayerItem m_layeritem; + static FluxboxWindow *s_window; }; #endif // FBMENU_HH diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 8aa0db8..b2a57d0 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -215,7 +215,7 @@ public: explicit ShowMenu(FluxboxWindow &win):m_win(win) { } void execute() { // hide the menu if it's already showing for this FluxboxWindow - if (m_win.menu().isVisible() && WindowCmd::window() == &m_win) { + if (m_win.menu().isVisible() && FbMenu::window() == &m_win) { m_win.menu().hide(); return; } diff --git a/src/Keys.cc b/src/Keys.cc index d85c696..76224ef 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -23,6 +23,8 @@ #include "fluxbox.hh" #include "Screen.hh" +#include "WinClient.hh" +#include "WindowCmd.hh" #include "FbTk/EventManager.hh" #include "FbTk/StringUtil.hh" @@ -480,7 +482,7 @@ bool Keys::addBinding(const string &linebuffer) { // return true if bound to a command, else false bool Keys::doAction(int type, unsigned int mods, unsigned int key, - int context, Time time) { + int context, WinClient *current, Time time) { static Time last_button_time = 0; static unsigned int last_button = 0; @@ -546,7 +548,11 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key, return false; } + WinClient *old = WindowCmd::client(); + WindowCmd::setClient(current); temp_key->m_command->execute(); + WindowCmd::setClient(old); + if (saved_keymode) { if (next_key == m_keylist) // don't reset keymode if command changed it setKeyMode(saved_keymode); diff --git a/src/Keys.hh b/src/Keys.hh index 439ecac..7ebb0a7 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -28,6 +28,7 @@ #include #include +class WinClient; namespace FbTk { class EventHandler; @@ -75,7 +76,7 @@ public: do action from XKeyEvent; return false if not bound to anything */ bool doAction(int type, unsigned int mods, unsigned int key, int context, - Time time = 0); + WinClient *current = 0, Time time = 0); /// register a window so that proper keys/buttons get grabbed on it void registerWindow(Window win, FbTk::EventHandler &handler, int context); diff --git a/src/Screen.cc b/src/Screen.cc index a97f1aa..bf5a625 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -832,11 +832,8 @@ void BScreen::propertyNotify(Atom atom) { } void BScreen::keyPressEvent(XKeyEvent &ke) { - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(FocusControl::focusedFbWindow()); Fluxbox::instance()->keys()->doAction(ke.type, ke.state, ke.keycode, Keys::GLOBAL|Keys::ON_DESKTOP); - WindowCmd::setClient(old); } void BScreen::keyReleaseEvent(XKeyEvent &ke) { @@ -855,11 +852,8 @@ void BScreen::buttonPressEvent(XButtonEvent &be) { imageControl().installRootColormap(); Keys *keys = Fluxbox::instance()->keys(); - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(FocusControl::focusedFbWindow()); keys->doAction(be.type, be.state, be.button, Keys::GLOBAL|Keys::ON_DESKTOP, - be.time); - WindowCmd::setClient(old); + 0, be.time); } void BScreen::notifyUngrabKeyboard() { diff --git a/src/Toolbar.cc b/src/Toolbar.cc index 00cdfee..61402f1 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -520,14 +520,9 @@ void Toolbar::reconfigure() { void Toolbar::buttonPressEvent(XButtonEvent &be) { - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(0); if (Fluxbox::instance()->keys()->doAction(be.type, be.state, be.button, - Keys::ON_TOOLBAR, be.time)) { - WindowCmd::setClient(old); + Keys::ON_TOOLBAR, 0, be.time)) return; - } - WindowCmd::setClient(old); if (be.button == 1) raise(); @@ -553,11 +548,8 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) { } void Toolbar::enterNotifyEvent(XCrossingEvent &ce) { - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(0); Fluxbox::instance()->keys()->doAction(ce.type, ce.state, 0, Keys::ON_TOOLBAR); - WindowCmd::setClient(old); if (! doAutoHide()) { if (isHidden()) @@ -580,11 +572,8 @@ void Toolbar::leaveNotifyEvent(XCrossingEvent &event) { event.y_root > y() && event.y_root <= (int)(y() + height())) return; - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(0); Fluxbox::instance()->keys()->doAction(event.type, event.state, 0, Keys::ON_TOOLBAR); - WindowCmd::setClient(old); if (! doAutoHide()) return; diff --git a/src/Window.cc b/src/Window.cc index d4e79b1..133a84f 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -1986,11 +1986,8 @@ void FluxboxWindow::setFocusFlag(bool focus) { m_focussig.notify(); if (m_client) m_client->focusSig().notify(); - WinClient *old = WindowCmd::client(); - WindowCmd::setClient(m_client); Fluxbox::instance()->keys()->doAction(focus ? FocusIn : FocusOut, 0, 0, - Keys::ON_WINDOW); - WindowCmd::setClient(old); + Keys::ON_WINDOW, m_client); } } @@ -2168,7 +2165,7 @@ void FluxboxWindow::showMenu(int menu_x, int menu_y) { else if (menu_x + static_cast(menu().width()) >= static_cast(screen().maxRight(head))) menu_x = screen().maxRight(head) - menu().width() - 1; - WindowCmd::setWindow(this); + FbMenu::setWindow(this); menu().move(menu_x, menu_y); menu().show(); menu().raise(); @@ -2182,7 +2179,7 @@ void FluxboxWindow::showMenu(int menu_x, int menu_y) { void FluxboxWindow::popupMenu() { // hide menu if it was opened for this window before - if (menu().isVisible() && WindowCmd::window() == this) { + if (menu().isVisible() && FbMenu::window() == this) { menu().hide(); return; } @@ -2639,11 +2636,11 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { raise(); // check keys file first - WindowCmd::setWindow(this); Keys *k = Fluxbox::instance()->keys(); if (onTitlebar && k->doAction(be.type, be.state, be.button, - Keys::ON_TITLEBAR, be.time) || - k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, be.time)) { + Keys::ON_TITLEBAR, m_client, be.time) || + k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, m_client, + be.time)) { return; } @@ -2926,14 +2923,9 @@ void FluxboxWindow::enterNotifyEvent(XCrossingEvent &ev) { return; } - if (ev.window == frame().window()) { - // save old value, so we can restore it later - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(this); + if (ev.window == frame().window()) Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0, - Keys::ON_WINDOW); - WindowCmd::setClient(old); - } + Keys::ON_WINDOW, m_client); WinClient *client = 0; if (screen().focusControl().isMouseTabFocus()) { @@ -2989,12 +2981,8 @@ void FluxboxWindow::leaveNotifyEvent(XCrossingEvent &ev) { ev.y_root <= (int)(frame().y() + frame().height())) return; - // save old value, so we can restore it later - WinClient *old = WindowCmd::client(); - WindowCmd::setWindow(this); Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0, - Keys::ON_WINDOW); - WindowCmd::setClient(old); + Keys::ON_WINDOW, m_client); // I hope commenting this out is right - simon 21jul2003 //if (ev.window == frame().window()) -- cgit v0.11.2