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 "Screen.hh"
#include "WindowCmd.hh"
FluxboxWindow *FbMenu::s_window = 0;
FbMenu::FbMenu(FbTk::ThemeProxy<FbTk::MenuTheme> &tm,
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) {
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<void>::setWindow(s_window);
// now get on with the show
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/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

View file

@ -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<void>::window() == &m_win) {
if (m_win.menu().isVisible() && FbMenu::window() == &m_win) {
m_win.menu().hide();
return;
}

View file

@ -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<void>::client();
WindowCmd<void>::setClient(current);
temp_key->m_command->execute();
WindowCmd<void>::setClient(old);
if (saved_keymode) {
if (next_key == m_keylist) // don't reset keymode if command changed it
setKeyMode(saved_keymode);

View file

@ -28,6 +28,7 @@
#include <string>
#include <map>
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);

View file

@ -832,11 +832,8 @@ void BScreen::propertyNotify(Atom atom) {
}
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,
Keys::GLOBAL|Keys::ON_DESKTOP);
WindowCmd<void>::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<void>::client();
WindowCmd<void>::setWindow(FocusControl::focusedFbWindow());
keys->doAction(be.type, be.state, be.button, Keys::GLOBAL|Keys::ON_DESKTOP,
be.time);
WindowCmd<void>::setClient(old);
0, be.time);
}
void BScreen::notifyUngrabKeyboard() {

View file

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

View file

@ -1986,11 +1986,8 @@ void FluxboxWindow::setFocusFlag(bool focus) {
m_focussig.notify();
if (m_client)
m_client->focusSig().notify();
WinClient *old = WindowCmd<void>::client();
WindowCmd<void>::setClient(m_client);
Fluxbox::instance()->keys()->doAction(focus ? FocusIn : FocusOut, 0, 0,
Keys::ON_WINDOW);
WindowCmd<void>::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<signed>(menu().width()) >= static_cast<signed>(screen().maxRight(head)))
menu_x = screen().maxRight(head) - menu().width() - 1;
WindowCmd<void>::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<void>::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<void>::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<void>::client();
WindowCmd<void>::setWindow(this);
if (ev.window == frame().window())
Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0,
Keys::ON_WINDOW);
WindowCmd<void>::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<void>::client();
WindowCmd<void>::setWindow(this);
Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0,
Keys::ON_WINDOW);
WindowCmd<void>::setClient(old);
Keys::ON_WINDOW, m_client);
// I hope commenting this out is right - simon 21jul2003
//if (ev.window == frame().window())