From 467fefaae453e0c1eae0340f1d1d7d89eafd3e22 Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Wed, 28 May 2008 02:32:57 -0700 Subject: more more fun with the window menu --- src/AlphaMenu.cc | 10 +++---- src/AlphaMenu.hh | 3 +- src/MenuCreator.cc | 7 +++-- src/WindowCmd.hh | 45 ---------------------------- src/WindowMenuAccessor.hh | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 src/WindowMenuAccessor.hh diff --git a/src/AlphaMenu.cc b/src/AlphaMenu.cc index ef67956..03aca47 100644 --- a/src/AlphaMenu.cc +++ b/src/AlphaMenu.cc @@ -23,10 +23,8 @@ #include "AlphaMenu.hh" #include "Window.hh" -#include "WindowCmd.hh" #include "Screen.hh" #include "Workspace.hh" -#include "WindowCmd.hh" #include "fluxbox.hh" #include "Layer.hh" #include "FbTk/IntMenuItem.hh" @@ -39,10 +37,10 @@ AlphaMenu::AlphaMenu(FbTk::ThemeProxy &tm, ToggleMenu(tm, imgctrl, layer) { - static WindowAccessor m_focused_alpha((WindowAccessor::Getter)&FluxboxWindow::getFocusedAlpha, - (WindowAccessor::Setter)&FluxboxWindow::setFocusedAlpha, 255); - static WindowAccessor m_unfocused_alpha((WindowAccessor::Getter)&FluxboxWindow::getUnfocusedAlpha, - (WindowAccessor::Setter)&FluxboxWindow::setUnfocusedAlpha, 255); + static WindowMenuAccessor m_focused_alpha((WindowMenuAccessor::Getter)&FluxboxWindow::getFocusedAlpha, + (WindowMenuAccessor::Setter)&FluxboxWindow::setFocusedAlpha, 255); + static WindowMenuAccessor m_unfocused_alpha((WindowMenuAccessor::Getter)&FluxboxWindow::getUnfocusedAlpha, + (WindowMenuAccessor::Setter)&FluxboxWindow::setUnfocusedAlpha, 255); _FB_USES_NLS; diff --git a/src/AlphaMenu.hh b/src/AlphaMenu.hh index 41580c3..833b0d2 100644 --- a/src/AlphaMenu.hh +++ b/src/AlphaMenu.hh @@ -25,6 +25,7 @@ #include "ToggleMenu.hh" #include "WindowCmd.hh" +#include "WindowMenuAccessor.hh" #include "FbTk/MenuItem.hh" class AlphaMenu : public ToggleMenu { @@ -47,7 +48,7 @@ public: } bool isSelected() const { - static ConstWindowAccessor s_is_default(&FluxboxWindow::getUseDefaultAlpha, true); + static ConstWindowMenuAccessor s_is_default(&FluxboxWindow::getUseDefaultAlpha, true); return s_is_default; } void click(int button, int time, unsigned int mods) { diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 1af5482..8c3ee6b 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -28,6 +28,7 @@ #include "fluxbox.hh" #include "Window.hh" #include "WindowCmd.hh" +#include "WindowMenuAccessor.hh" #include "ClientMenu.hh" #include "WorkspaceMenu.hh" @@ -480,7 +481,7 @@ bool MenuCreator::createWindowMenuItem(const string &type, static MenuContext context; if (type == "shade") { - static WindowAccessor res(&FluxboxWindow::isShaded, &FluxboxWindow::setShaded, false); + static WindowMenuAccessor res(&FluxboxWindow::isShaded, &FluxboxWindow::setShaded, false); menu.insert(new FbTk::BoolMenuItem( label.empty()?_FB_XTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label, res)); @@ -504,7 +505,7 @@ bool MenuCreator::createWindowMenuItem(const string &type, maximize_item->setCommand(3, maximize_horiz_cmd); menu.insert(maximize_item); } else if (type == "iconify") { - static WindowAccessor res(&FluxboxWindow::isIconic, &FluxboxWindow::setIconic, false); + static WindowMenuAccessor res(&FluxboxWindow::isIconic, &FluxboxWindow::setIconic, false); menu.insert(new FbTk::BoolMenuItem( label.empty() ? _FB_XTEXT(Windowmenu, Iconify, @@ -536,7 +537,7 @@ bool MenuCreator::createWindowMenuItem(const string &type, label, raise_cmd); } else if (type == "stick") { - static WindowAccessor res(&FluxboxWindow::isStuck, &FluxboxWindow::setStuck, false); + static WindowMenuAccessor res(&FluxboxWindow::isStuck, &FluxboxWindow::setStuck, false); menu.insert(new FbTk::BoolMenuItem( label.empty() ? _FB_XTEXT(Windowmenu, Stick, diff --git a/src/WindowCmd.hh b/src/WindowCmd.hh index f979f2b..34699ad 100644 --- a/src/WindowCmd.hh +++ b/src/WindowCmd.hh @@ -63,49 +63,4 @@ private: Action m_action; }; -/// accesses values in current window -template -class WindowAccessor: public FbTk::Accessor { -public: - typedef Ret (FluxboxWindow:: *Getter)() const; - typedef void (FluxboxWindow:: *Setter)(Ret); - WindowAccessor(Getter g, Setter s, Def def): - m_getter(g), m_setter(s), m_def(def) { } - - operator Ret() const { - FluxboxWindow *fbwin = WindowCmd::window(); - return fbwin ? (fbwin->*m_getter)() : m_def; - } - FbTk::Accessor &operator =(const Ret &val) { - FluxboxWindow *fbwin = WindowCmd::window(); - if (fbwin) - (fbwin->*m_setter)(val); - return *this; - } - -private: - Getter m_getter; - Setter m_setter; - Def m_def; -}; - -/// same as above but only reads -template -class ConstWindowAccessor: public FbTk::Accessor { -public: - typedef Ret (FluxboxWindow:: *Getter)() const; - ConstWindowAccessor(Getter g, Def def): - m_getter(g), m_def(def) { } - - operator Ret() const { - FluxboxWindow *fbwin = WindowCmd::window(); - return fbwin ? (fbwin->*m_getter)() : m_def; - } - FbTk::Accessor &operator =(const Ret &val) { return *this; } - -private: - Getter m_getter; - Def m_def; -}; - #endif // WINDOWCMD_HH diff --git a/src/WindowMenuAccessor.hh b/src/WindowMenuAccessor.hh new file mode 100644 index 0000000..91994b9 --- /dev/null +++ b/src/WindowMenuAccessor.hh @@ -0,0 +1,74 @@ +// WindowMenuAccessor.hh +// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef WINDOW_MENU_ACCESSOR_HH +#define WINDOW_MENU_ACCESSOR_HH + +#include "FbTk/Accessor.hh" + +#include "FbMenu.hh" + +/// accesses values in current window +template +class WindowMenuAccessor: public FbTk::Accessor { +public: + typedef Ret (FluxboxWindow:: *Getter)() const; + typedef void (FluxboxWindow:: *Setter)(Ret); + WindowMenuAccessor(Getter g, Setter s, Def def): + m_getter(g), m_setter(s), m_def(def) { } + + operator Ret() const { + FluxboxWindow *fbwin = FbMenu::window(); + return fbwin ? (fbwin->*m_getter)() : m_def; + } + FbTk::Accessor &operator =(const Ret &val) { + FluxboxWindow *fbwin = FbMenu::window(); + if (fbwin) + (fbwin->*m_setter)(val); + return *this; + } + +private: + Getter m_getter; + Setter m_setter; + Def m_def; +}; + +/// same as above but only reads +template +class ConstWindowMenuAccessor: public FbTk::Accessor { +public: + typedef Ret (FluxboxWindow:: *Getter)() const; + ConstWindowMenuAccessor(Getter g, Def def): + m_getter(g), m_def(def) { } + + operator Ret() const { + FluxboxWindow *fbwin = FbMenu::window(); + return fbwin ? (fbwin->*m_getter)() : m_def; + } + FbTk::Accessor &operator =(const Ret &val) { return *this; } + +private: + Getter m_getter; + Def m_def; +}; + +#endif // WINDOW_MENU_ACCESSOR_HH -- cgit v0.11.2