more fun with the window menu

This commit is contained in:
Mark Tiefenbruck 2008-02-11 10:17:45 -08:00
parent cd128d7a3e
commit 611b6aa57e
8 changed files with 50 additions and 43 deletions

View file

@ -23,6 +23,9 @@
#include "fluxbox.hh" #include "fluxbox.hh"
#include "Screen.hh" #include "Screen.hh"
#include "WindowCmd.hh"
FluxboxWindow *FbMenu::s_window = 0;
FbMenu::FbMenu(FbTk::ThemeProxy<FbTk::MenuTheme> &tm, FbMenu::FbMenu(FbTk::ThemeProxy<FbTk::MenuTheme> &tm,
FbTk::ImageControl &imgctrl, FbTk::XLayer &layer): FbTk::ImageControl &imgctrl, FbTk::XLayer &layer):
@ -31,6 +34,16 @@ FbMenu::FbMenu(FbTk::ThemeProxy<FbTk::MenuTheme> &tm,
} }
void FbMenu::show() {
WindowCmd<void>::setWindow(s_window);
FbTk::Menu::show();
}
void FbMenu::buttonPressEvent(XButtonEvent &be) {
WindowCmd<void>::setWindow(s_window);
FbTk::Menu::buttonPressEvent(be);
}
void FbMenu::buttonReleaseEvent(XButtonEvent &be) { void FbMenu::buttonReleaseEvent(XButtonEvent &be) {
BScreen *screen = Fluxbox::instance()->findScreen(screenNumber()); BScreen *screen = Fluxbox::instance()->findScreen(screenNumber());
if (be.window == titleWindow() && isMoving() && screen) { if (be.window == titleWindow() && isMoving() && screen) {
@ -41,7 +54,13 @@ void FbMenu::buttonReleaseEvent(XButtonEvent &be) {
screen->getHeadWidth(head), screen->getHeadWidth(head),
screen->getHeadHeight(head)); screen->getHeadHeight(head));
} }
WindowCmd<void>::setWindow(s_window);
// now get on with the show // now get on with the show
FbTk::Menu::buttonReleaseEvent(be); FbTk::Menu::buttonReleaseEvent(be);
} }
void FbMenu::keyPressEvent(XKeyEvent &ke) {
WindowCmd<void>::setWindow(s_window);
FbTk::Menu::keyPressEvent(ke);
}

View file

@ -25,6 +25,8 @@
#include "FbTk/Menu.hh" #include "FbTk/Menu.hh"
#include "FbTk/XLayerItem.hh" #include "FbTk/XLayerItem.hh"
class FluxboxWindow;
namespace FbTk { namespace FbTk {
class MenuTheme; class MenuTheme;
} }
@ -37,9 +39,17 @@ public:
virtual ~FbMenu() { } virtual ~FbMenu() { }
void raise() { m_layeritem.raise(); } void raise() { m_layeritem.raise(); }
void lower() { m_layeritem.lower(); } void lower() { m_layeritem.lower(); }
void show();
void buttonPressEvent(XButtonEvent &be);
void buttonReleaseEvent(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: private:
FbTk::XLayerItem m_layeritem; FbTk::XLayerItem m_layeritem;
static FluxboxWindow *s_window;
}; };
#endif // FBMENU_HH #endif // FBMENU_HH

View file

@ -215,7 +215,7 @@ public:
explicit ShowMenu(FluxboxWindow &win):m_win(win) { } explicit ShowMenu(FluxboxWindow &win):m_win(win) { }
void execute() { void execute() {
// hide the menu if it's already showing for this FluxboxWindow // hide the menu if it's already showing for this FluxboxWindow
if (m_win.menu().isVisible() && WindowCmd<void>::window() == &m_win) { if (m_win.menu().isVisible() && FbMenu::window() == &m_win) {
m_win.menu().hide(); m_win.menu().hide();
return; return;
} }

View file

@ -23,6 +23,8 @@
#include "fluxbox.hh" #include "fluxbox.hh"
#include "Screen.hh" #include "Screen.hh"
#include "WinClient.hh"
#include "WindowCmd.hh"
#include "FbTk/EventManager.hh" #include "FbTk/EventManager.hh"
#include "FbTk/StringUtil.hh" #include "FbTk/StringUtil.hh"
@ -480,7 +482,7 @@ bool Keys::addBinding(const string &linebuffer) {
// return true if bound to a command, else false // return true if bound to a command, else false
bool Keys::doAction(int type, unsigned int mods, unsigned int key, 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 Time last_button_time = 0;
static unsigned int last_button = 0; static unsigned int last_button = 0;
@ -546,7 +548,11 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key,
return false; return false;
} }
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setClient(current);
temp_key->m_command->execute(); temp_key->m_command->execute();
WindowCmd<void>::setClient(old);
if (saved_keymode) { if (saved_keymode) {
if (next_key == m_keylist) // don't reset keymode if command changed it if (next_key == m_keylist) // don't reset keymode if command changed it
setKeyMode(saved_keymode); setKeyMode(saved_keymode);

View file

@ -28,6 +28,7 @@
#include <string> #include <string>
#include <map> #include <map>
class WinClient;
namespace FbTk { namespace FbTk {
class EventHandler; class EventHandler;
@ -75,7 +76,7 @@ public:
do action from XKeyEvent; return false if not bound to anything do action from XKeyEvent; return false if not bound to anything
*/ */
bool doAction(int type, unsigned int mods, unsigned int key, int context, 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 /// register a window so that proper keys/buttons get grabbed on it
void registerWindow(Window win, FbTk::EventHandler &handler, int context); void registerWindow(Window win, FbTk::EventHandler &handler, int context);

View file

@ -832,11 +832,8 @@ void BScreen::propertyNotify(Atom atom) {
} }
void BScreen::keyPressEvent(XKeyEvent &ke) { void BScreen::keyPressEvent(XKeyEvent &ke) {
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(FocusControl::focusedFbWindow());
Fluxbox::instance()->keys()->doAction(ke.type, ke.state, ke.keycode, Fluxbox::instance()->keys()->doAction(ke.type, ke.state, ke.keycode,
Keys::GLOBAL|Keys::ON_DESKTOP); Keys::GLOBAL|Keys::ON_DESKTOP);
WindowCmd<void>::setClient(old);
} }
void BScreen::keyReleaseEvent(XKeyEvent &ke) { void BScreen::keyReleaseEvent(XKeyEvent &ke) {
@ -855,11 +852,8 @@ void BScreen::buttonPressEvent(XButtonEvent &be) {
imageControl().installRootColormap(); imageControl().installRootColormap();
Keys *keys = Fluxbox::instance()->keys(); Keys *keys = Fluxbox::instance()->keys();
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(FocusControl::focusedFbWindow());
keys->doAction(be.type, be.state, be.button, Keys::GLOBAL|Keys::ON_DESKTOP, keys->doAction(be.type, be.state, be.button, Keys::GLOBAL|Keys::ON_DESKTOP,
be.time); 0, be.time);
WindowCmd<void>::setClient(old);
} }
void BScreen::notifyUngrabKeyboard() { void BScreen::notifyUngrabKeyboard() {

View file

@ -520,14 +520,9 @@ void Toolbar::reconfigure() {
void Toolbar::buttonPressEvent(XButtonEvent &be) { void Toolbar::buttonPressEvent(XButtonEvent &be) {
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(0);
if (Fluxbox::instance()->keys()->doAction(be.type, be.state, be.button, if (Fluxbox::instance()->keys()->doAction(be.type, be.state, be.button,
Keys::ON_TOOLBAR, be.time)) { Keys::ON_TOOLBAR, 0, be.time))
WindowCmd<void>::setClient(old);
return; return;
}
WindowCmd<void>::setClient(old);
if (be.button == 1) if (be.button == 1)
raise(); raise();
@ -553,11 +548,8 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) {
} }
void Toolbar::enterNotifyEvent(XCrossingEvent &ce) { void Toolbar::enterNotifyEvent(XCrossingEvent &ce) {
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(0);
Fluxbox::instance()->keys()->doAction(ce.type, ce.state, 0, Fluxbox::instance()->keys()->doAction(ce.type, ce.state, 0,
Keys::ON_TOOLBAR); Keys::ON_TOOLBAR);
WindowCmd<void>::setClient(old);
if (! doAutoHide()) { if (! doAutoHide()) {
if (isHidden()) if (isHidden())
@ -580,11 +572,8 @@ void Toolbar::leaveNotifyEvent(XCrossingEvent &event) {
event.y_root > y() && event.y_root <= (int)(y() + height())) event.y_root > y() && event.y_root <= (int)(y() + height()))
return; return;
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(0);
Fluxbox::instance()->keys()->doAction(event.type, event.state, 0, Fluxbox::instance()->keys()->doAction(event.type, event.state, 0,
Keys::ON_TOOLBAR); Keys::ON_TOOLBAR);
WindowCmd<void>::setClient(old);
if (! doAutoHide()) if (! doAutoHide())
return; return;

View file

@ -1986,11 +1986,8 @@ void FluxboxWindow::setFocusFlag(bool focus) {
m_focussig.notify(); m_focussig.notify();
if (m_client) if (m_client)
m_client->focusSig().notify(); m_client->focusSig().notify();
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setClient(m_client);
Fluxbox::instance()->keys()->doAction(focus ? FocusIn : FocusOut, 0, 0, Fluxbox::instance()->keys()->doAction(focus ? FocusIn : FocusOut, 0, 0,
Keys::ON_WINDOW); Keys::ON_WINDOW, m_client);
WindowCmd<void>::setClient(old);
} }
} }
@ -2168,7 +2165,7 @@ void FluxboxWindow::showMenu(int menu_x, int menu_y) {
else if (menu_x + static_cast<signed>(menu().width()) >= static_cast<signed>(screen().maxRight(head))) else if (menu_x + static_cast<signed>(menu().width()) >= static_cast<signed>(screen().maxRight(head)))
menu_x = screen().maxRight(head) - menu().width() - 1; menu_x = screen().maxRight(head) - menu().width() - 1;
WindowCmd<void>::setWindow(this); FbMenu::setWindow(this);
menu().move(menu_x, menu_y); menu().move(menu_x, menu_y);
menu().show(); menu().show();
menu().raise(); menu().raise();
@ -2182,7 +2179,7 @@ void FluxboxWindow::showMenu(int menu_x, int menu_y) {
void FluxboxWindow::popupMenu() { void FluxboxWindow::popupMenu() {
// hide menu if it was opened for this window before // hide menu if it was opened for this window before
if (menu().isVisible() && WindowCmd<void>::window() == this) { if (menu().isVisible() && FbMenu::window() == this) {
menu().hide(); menu().hide();
return; return;
} }
@ -2639,11 +2636,11 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) {
raise(); raise();
// check keys file first // check keys file first
WindowCmd<void>::setWindow(this);
Keys *k = Fluxbox::instance()->keys(); Keys *k = Fluxbox::instance()->keys();
if (onTitlebar && k->doAction(be.type, be.state, be.button, if (onTitlebar && k->doAction(be.type, be.state, be.button,
Keys::ON_TITLEBAR, be.time) || Keys::ON_TITLEBAR, m_client, be.time) ||
k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, be.time)) { k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, m_client,
be.time)) {
return; return;
} }
@ -2926,14 +2923,9 @@ void FluxboxWindow::enterNotifyEvent(XCrossingEvent &ev) {
return; return;
} }
if (ev.window == frame().window()) { if (ev.window == frame().window())
// save old value, so we can restore it later
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(this);
Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0, Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0,
Keys::ON_WINDOW); Keys::ON_WINDOW, m_client);
WindowCmd<void>::setClient(old);
}
WinClient *client = 0; WinClient *client = 0;
if (screen().focusControl().isMouseTabFocus()) { if (screen().focusControl().isMouseTabFocus()) {
@ -2989,12 +2981,8 @@ void FluxboxWindow::leaveNotifyEvent(XCrossingEvent &ev) {
ev.y_root <= (int)(frame().y() + frame().height())) ev.y_root <= (int)(frame().y() + frame().height()))
return; return;
// save old value, so we can restore it later
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setWindow(this);
Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0, Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0,
Keys::ON_WINDOW); Keys::ON_WINDOW, m_client);
WindowCmd<void>::setClient(old);
// I hope commenting this out is right - simon 21jul2003 // I hope commenting this out is right - simon 21jul2003
//if (ev.window == frame().window()) //if (ev.window == frame().window())