architecture astronomy

This commit is contained in:
Mark Tiefenbruck 2007-12-27 13:55:24 -08:00
parent 1f5cd12fac
commit b5c354b994
20 changed files with 306 additions and 401 deletions

View file

@ -25,24 +25,27 @@
#include "AlphaMenu.hh" #include "AlphaMenu.hh"
#include "Window.hh" #include "Window.hh"
#include "WindowCmd.hh"
#include "Screen.hh" #include "Screen.hh"
#include "Workspace.hh" #include "Workspace.hh"
#include "WindowCmd.hh" #include "WindowCmd.hh"
#include "fluxbox.hh" #include "fluxbox.hh"
#include "Layer.hh" #include "Layer.hh"
#include "IntResMenuItem.hh" #include "FbTk/IntMenuItem.hh"
#include "FbTk/I18n.hh" #include "FbTk/I18n.hh"
#include "Window.hh" #include "Window.hh"
#include "WindowCmd.hh"
AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
FbTk::XLayer &layer, AlphaObject &object): FbTk::XLayer &layer):
ToggleMenu(tm, imgctrl, layer), ToggleMenu(tm, imgctrl, layer)
m_focused_alpha_resource(&object, &AlphaObject::getFocusedAlpha, &AlphaObject::setFocusedAlpha, 255),
m_unfocused_alpha_resource(&object, &AlphaObject::getUnfocusedAlpha, &AlphaObject::setUnfocusedAlpha, 255)
{ {
static WindowAccessor<int> m_focused_alpha((WindowAccessor<int>::Getter)&FluxboxWindow::getFocusedAlpha,
(WindowAccessor<int>::Setter)&FluxboxWindow::setFocusedAlpha, 255);
static WindowAccessor<int> m_unfocused_alpha((WindowAccessor<int>::Getter)&FluxboxWindow::getUnfocusedAlpha,
(WindowAccessor<int>::Setter)&FluxboxWindow::setUnfocusedAlpha, 255);
_FB_USES_NLS; _FB_USES_NLS;
// build menu... // build menu...
@ -53,7 +56,7 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
"Transparency level of the focused window"); "Transparency level of the focused window");
FbTk::MenuItem *focused_alpha_item = FbTk::MenuItem *focused_alpha_item =
new IntResMenuItem< ObjectResource<AlphaObject, int> >(focused_alpha_label, m_focused_alpha_resource, 0, 255, *this); new FbTk::IntMenuItem(focused_alpha_label, m_focused_alpha, 0, 255, *this);
insert(focused_alpha_item); insert(focused_alpha_item);
const FbTk::FbString unfocused_alpha_label = const FbTk::FbString unfocused_alpha_label =
@ -62,14 +65,14 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
"Transparency level of unfocused windows"); "Transparency level of unfocused windows");
FbTk::MenuItem *unfocused_alpha_item = FbTk::MenuItem *unfocused_alpha_item =
new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); new FbTk::IntMenuItem(unfocused_alpha_label, m_unfocused_alpha, 0, 255, *this);
insert(unfocused_alpha_item); insert(unfocused_alpha_item);
const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha, const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha,
"Use Defaults", "Use Defaults",
"Default transparency settings for this window"); "Default transparency settings for this window");
FbTk::MenuItem *usedefault_item = FbTk::MenuItem *usedefault_item =
new AlphaMenuSelectItem(usedefault_label, &object, *this); new AlphaMenuSelectItem(usedefault_label, *this);
insert(usedefault_item); insert(usedefault_item);
updateMenu(); updateMenu();
@ -81,8 +84,8 @@ void AlphaMenu::move(int x, int y) {
if (isVisible()) { if (isVisible()) {
// TODO: hardcoding the indices is a bad idea // TODO: hardcoding the indices is a bad idea
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(0))->updateLabel(); ((FbTk::IntMenuItem *)find(0))->updateLabel();
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); ((FbTk::IntMenuItem *)find(1))->updateLabel();
frameWindow().updateBackground(false); frameWindow().updateBackground(false);
FbTk::Menu::clearWindow(); FbTk::Menu::clearWindow();
} }
@ -90,8 +93,8 @@ void AlphaMenu::move(int x, int y) {
void AlphaMenu::show() { void AlphaMenu::show() {
// TODO: hardcoding the indices is a bad idea // TODO: hardcoding the indices is a bad idea
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(0))->updateLabel(); ((FbTk::IntMenuItem *)find(0))->updateLabel();
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); ((FbTk::IntMenuItem *)find(1))->updateLabel();
frameWindow().updateBackground(false); frameWindow().updateBackground(false);
FbTk::Menu::clearWindow(); FbTk::Menu::clearWindow();

View file

@ -26,56 +26,40 @@
#define ALPHAMENU_HH #define ALPHAMENU_HH
#include "ToggleMenu.hh" #include "ToggleMenu.hh"
#include "WindowCmd.hh"
#include "FbTk/MenuItem.hh" #include "FbTk/MenuItem.hh"
#include "ObjectResource.hh"
class AlphaObject {
public:
virtual int getFocusedAlpha() const = 0;
virtual int getUnfocusedAlpha() const = 0;
virtual bool getUseDefaultAlpha() const = 0;
virtual void setFocusedAlpha(int alpha) = 0;
virtual void setUnfocusedAlpha(int alpha) = 0;
virtual void setDefaultAlpha() = 0;
virtual ~AlphaObject() {};
};
class AlphaMenu : public ToggleMenu { class AlphaMenu : public ToggleMenu {
public: public:
AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
FbTk::XLayer &layer, AlphaObject &object); FbTk::XLayer &layer);
// we override these to update the menu when the active window changes // we override these to update the menu when the active window changes
void move(int x, int y); void move(int x, int y);
void show(); void show();
ObjectResource<AlphaObject, int> m_focused_alpha_resource;
ObjectResource<AlphaObject, int> m_unfocused_alpha_resource;
}; };
class AlphaMenuSelectItem : public FbTk::MenuItem { class AlphaMenuSelectItem : public FbTk::MenuItem {
public: public:
AlphaMenuSelectItem(const FbTk::FbString &label, AlphaObject *object, AlphaMenu &parent): AlphaMenuSelectItem(const FbTk::FbString &label, AlphaMenu &parent):
FbTk::MenuItem(label), m_object(object), m_parent(parent) { FbTk::MenuItem(label), m_parent(parent) {
setToggleItem(true); setToggleItem(true);
setCloseOnClick(false); setCloseOnClick(false);
} }
bool isSelected() const { return m_object->getUseDefaultAlpha(); } bool isSelected() const {
static ConstWindowAccessor<bool> s_is_default(&FluxboxWindow::getUseDefaultAlpha, true);
return s_is_default;
}
void click(int button, int time, unsigned int mods) { void click(int button, int time, unsigned int mods) {
m_object->setDefaultAlpha(); static WindowCmd<void> s_set_default(&FluxboxWindow::setDefaultAlpha);
s_set_default.execute();
m_parent.show(); // cheat to refreshing the window m_parent.show(); // cheat to refreshing the window
FbTk::MenuItem::click(button, time, mods); FbTk::MenuItem::click(button, time, mods);
} }
private: private:
AlphaObject *m_object;
AlphaMenu &m_parent; AlphaMenu &m_parent;
}; };

85
src/FbTk/Accessor.hh Normal file
View file

@ -0,0 +1,85 @@
// Accessor.hh
// Copyright (c) 2007 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 FBTK_ACCESSOR_HH
#define FBTK_ACCESSOR_HH
namespace FbTk {
// base class for objects that act like data type T
template <typename T>
class Accessor {
public:
virtual Accessor<T> &operator =(const T &val) = 0;
virtual operator T() const = 0;
};
// essentially just a reference
template <typename T>
class SimpleAccessor: public Accessor<T> {
public:
SimpleAccessor(T &val): m_val(val) { }
inline Accessor<T> &operator =(const T &val) { m_val = val; return *this; }
inline operator T() const { return m_val; }
private:
T &m_val;
};
// use object methods as an accessor
template <typename T, typename Receiver>
class ObjectAccessor: public Accessor<T> {
public:
typedef T (Receiver:: *Getter)() const;
typedef void (Receiver:: *Setter)(T &);
ObjectAccessor(Receiver &r, Getter g, Setter s):
m_receiver(r), m_getter(g), m_setter(s) { }
inline operator T() const { return (m_receiver.*m_getter)(); }
inline Accessor<T> &operator =(const T &val) {
(m_receiver.*m_setter)(val); return *this;
}
private:
Receiver &m_receiver;
Getter m_getter;
Setter m_setter;
};
// same as above but with no set method
template <typename T, typename Receiver>
class ConstObjectAccessor: public Accessor<T> {
public:
typedef T (Receiver:: *Getter)() const;
ConstObjectAccessor(const Receiver &r, Getter g):
m_receiver(r), m_getter(g) { }
inline operator T() const { return (m_receiver.*m_getter)(); }
inline Accessor<T> &operator =(const T &val) { return *this; }
private:
const Receiver &m_receiver;
Getter m_getter;
};
}; // end namespace FbTk
#endif // FBTK_ACCESSOR_HH

View file

@ -1,5 +1,5 @@
// BoolMenuItem.hh for Fluxbox Window Manager // BoolMenuItem.hh for FbTk
// Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) // Copyright (c) 2003 - 2007 Henrik Kinnunen (fluxgen at fluxbox dot org)
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@ -19,24 +19,25 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id$ #ifndef FBTK_BOOLMENUITEM_HH
#define FBTK_BOOLMENUITEM_HH
#ifndef BOOLMENUITEM_HH
#define BOOLMENUITEM_HH
#include "MenuItem.hh" #include "MenuItem.hh"
#include "Accessor.hh"
namespace FbTk {
/// a bool menu item /// a bool menu item
class BoolMenuItem: public FbTk::MenuItem { class BoolMenuItem: public FbTk::MenuItem {
public: public:
BoolMenuItem(const FbTk::FbString &label, bool &item, BoolMenuItem(const FbTk::FbString &label, Accessor<bool> &item,
FbTk::RefCount<FbTk::Command> &cmd): FbTk::RefCount<FbTk::Command> &cmd):
FbTk::MenuItem(label, cmd), m_item(item) { FbTk::MenuItem(label, cmd), m_item(item) {
FbTk::MenuItem::setSelected(m_item); FbTk::MenuItem::setSelected(m_item);
setToggleItem(true); setToggleItem(true);
setCloseOnClick(false); setCloseOnClick(false);
} }
BoolMenuItem(const FbTk::FbString &label, bool &item): BoolMenuItem(const FbTk::FbString &label, Accessor<bool> &item):
FbTk::MenuItem(label), m_item(item) { FbTk::MenuItem(label), m_item(item) {
FbTk::MenuItem::setSelected(m_item); FbTk::MenuItem::setSelected(m_item);
setToggleItem(true); setToggleItem(true);
@ -53,38 +54,9 @@ public:
FbTk::MenuItem::setSelected(m_item); FbTk::MenuItem::setSelected(m_item);
} }
private: private:
bool &m_item; Accessor<bool> &m_item;
}; };
/// a bool menu item }; // end namespace FbTk
template <typename Type>
class BoolResMenuItem: public FbTk::MenuItem {
public:
BoolResMenuItem(const FbTk::FbString &label, Type &res,
FbTk::RefCount<FbTk::Command> &cmd):
FbTk::MenuItem(label, cmd), m_res(res) {
FbTk::MenuItem::setSelected(*m_res);
setToggleItem(true);
setCloseOnClick(false);
}
BoolResMenuItem(const FbTk::FbString &label, Type &res):
FbTk::MenuItem(label), m_res(res) {
FbTk::MenuItem::setSelected(*m_res);
setToggleItem(true);
setCloseOnClick(false);
}
bool isSelected() const { return *m_res; }
// toggle state
void click(int button, int time, unsigned int mods) {
setSelected(!*m_res);
FbTk::MenuItem::click(button, time, mods);
}
void setSelected(bool value) {
m_res = value;
FbTk::MenuItem::setSelected(*m_res);
}
private:
Type &m_res;
};
#endif // BOOLMENUITEM_HH #endif // FBTK_BOOLMENUITEM_HH

View file

@ -22,58 +22,32 @@
#ifndef FBTK_DEFAULTVALUE_HH #ifndef FBTK_DEFAULTVALUE_HH
#define FBTK_DEFAULTVALUE_HH #define FBTK_DEFAULTVALUE_HH
#include "Accessor.hh"
namespace FbTk { namespace FbTk {
// classes for overriding default values without having to listen for changes // class for overriding default values and restoring them later
template <typename T>
class DefaultValue { // Ret = type of value that gets returned
// Def = type of default value -- may be Accessor<Ret> &, for example
template <typename Ret, typename Def=Ret &>
class DefaultValue: public Accessor<Ret> {
public: public:
DefaultValue(const T &def): DefaultValue(const Def def):
m_default(def), m_actual(def), m_use_default(true) { } m_default(def), m_actual(def), m_use_default(true) { }
inline const T &get() const { return m_use_default ? m_default : m_actual; }
inline void set(const T &val) { m_use_default = false; m_actual = val; }
inline void restoreDefault() { m_use_default = true; } inline void restoreDefault() { m_use_default = true; }
inline bool isDefault() const { return m_use_default; } inline bool isDefault() const { return m_use_default; }
inline DefaultValue<T> &operator =(const T &val) { inline DefaultValue<Ret, Def> &operator =(const Ret &val) {
set(val); return *this; m_use_default = false; m_actual = val; return *this;
} }
inline operator T() const { return get(); } inline operator Ret() const { return m_use_default ? m_default : m_actual; }
private: private:
const T &m_default; const Def m_default;
T m_actual; Ret m_actual;
bool m_use_default;
};
// designed for use with built-in types T, thus no need to return references
template <typename T, typename Receiver>
class DefaultAccessor {
public:
typedef T (Receiver:: *Accessor)() const;
DefaultAccessor(const Receiver &r, Accessor a):
m_receiver(r), m_accessor(a), m_actual((r.*a)()),
m_use_default(true) { }
inline const T get() const {
return m_use_default ? (m_receiver.*m_accessor)() : m_actual;
}
inline void set(const T &val) { m_use_default = false; m_actual = val; }
inline void restoreDefault() { m_use_default = true; }
inline bool isDefault() const { return m_use_default; }
inline DefaultAccessor<T, Receiver> &operator =(const T &val) {
set(val); return *this;
}
inline operator T() const { return get(); }
private:
const Receiver &m_receiver;
Accessor m_accessor;
T m_actual;
bool m_use_default; bool m_use_default;
}; };

View file

@ -1,5 +1,5 @@
// IntResMenuItem.hh for Fluxbox Window Manager // IntMenuItem.hh for FbTk
// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) // Copyright (c) 2003-2007 Henrik Kinnunen (fluxgen at fluxbox dot org)
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@ -19,21 +19,21 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id$ #ifndef FBTK_INTMENUITEM_HH
#define FBTK_INTMENUITEM_HH
#ifndef INTRESMENUITEM_HH
#define INTRESMENUITEM_HH
#include "MenuItem.hh" #include "MenuItem.hh"
#include "Resource.hh" #include "Accessor.hh"
#include <string> #include <string>
namespace FbTk {
/// Changes an resource integer value between min and max /// Changes an resource integer value between min and max
template <typename Type> class IntMenuItem: public FbTk::MenuItem {
class IntResMenuItem: public FbTk::MenuItem {
public: public:
IntResMenuItem(const FbTk::FbString &label, Type &res, int min_val, int max_val, FbTk::Menu &host_menu) : IntMenuItem(const FbTk::FbString &label, Accessor<int> &res,
int min_val, int max_val, FbTk::Menu &host_menu) :
FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()), FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()),
m_max(max_val), m_min(min_val), m_res(res) { m_max(max_val), m_min(min_val), m_res(res) {
updateLabel(); updateLabel();
@ -61,16 +61,16 @@ public:
// make sure values stay within bounds _before_ we try to set m_res // make sure values stay within bounds _before_ we try to set m_res
// otherwise, this may cause bugs (say, with casting to unsigned char) // otherwise, this may cause bugs (say, with casting to unsigned char)
if ((button == 4 || button == 3) && *m_res < m_max) { // up if ((button == 4 || button == 3) && m_res < m_max) { // up
if (*m_res + inc_val < m_max) if (m_res + inc_val < m_max)
m_res.get() += inc_val; m_res = m_res + inc_val;
else else
m_res.get() = m_max; m_res = m_max;
} else if ((button == 5 || button == 1) && *m_res > m_min) { // down } else if ((button == 5 || button == 1) && m_res > m_min) { // down
if (*m_res - inc_val >= m_min) if (m_res - inc_val >= m_min)
m_res.get() -= inc_val; m_res = m_res - inc_val;
else else
m_res.get() = m_min; m_res = m_min;
} }
// update label // update label
@ -87,14 +87,16 @@ public:
} }
void updateLabel() { void updateLabel() {
setLabel(appendIntValue(m_org_label, *m_res)); setLabel(appendIntValue(m_org_label, m_res));
} }
private: private:
std::string m_org_label; ///< original label std::string m_org_label; ///< original label
const int m_max; ///< maximum value the integer can have const int m_max; ///< maximum value the integer can have
const int m_min; ///< minimum value the integer can have const int m_min; ///< minimum value the integer can have
Type &m_res; ///< resource item to be changed Accessor<int> &m_res; ///< resource item to be changed
}; };
#endif // INTRESMENUITEM_HH }; // end namespace FbTk
#endif // FBTK_INTMENUITEM_HH

View file

@ -16,7 +16,7 @@ imlib2_SOURCE= ImageImlib2.hh ImageImlib2.cc
endif endif
libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
ObjectRegistry.hh DefaultValue.hh \ ObjectRegistry.hh Accessor.hh DefaultValue.hh \
FileUtil.hh FileUtil.cc \ FileUtil.hh FileUtil.cc \
EventHandler.hh EventManager.hh EventManager.cc \ EventHandler.hh EventManager.hh EventManager.cc \
FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \ FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \
@ -25,6 +25,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
LogicCommands.hh LogicCommands.cc \ LogicCommands.hh LogicCommands.cc \
MacroCommand.hh MacroCommand.cc \ MacroCommand.hh MacroCommand.cc \
Menu.hh Menu.cc MenuItem.hh MenuItem.cc \ Menu.hh Menu.cc MenuItem.hh MenuItem.cc \
BoolMenuItem.hh IntMenuItem.hh \
MultiButtonMenuItem.hh MultiButtonMenuItem.cc \ MultiButtonMenuItem.hh MultiButtonMenuItem.cc \
MenuTheme.hh MenuTheme.cc NotCopyable.hh \ MenuTheme.hh MenuTheme.cc NotCopyable.hh \
RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \ RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \

View file

@ -25,6 +25,7 @@
#define FBTK_RESOURCE_HH #define FBTK_RESOURCE_HH
#include "NotCopyable.hh" #include "NotCopyable.hh"
#include "Accessor.hh"
#include <string> #include <string>
#include <list> #include <list>
@ -160,23 +161,22 @@ private:
/// Real resource class /// Real resource class
/** /**
* usage: Resource<int> someresource(resourcemanager, 10, "someresourcename", "somealternativename"); \n * usage: Resource<int> someresource(resourcemanager, 10, "someresourcename", "somealternativename");
* and then implement setFromString and getString \n * and then implement setFromString and getString
* example: \n * example:
* template <> \n * template <>
* void Resource<int>::setFromString(const char *str) { \n * void Resource<int>::setFromString(const char *str) {
* *(*this) = atoi(str); \n * *(*this) = atoi(str);
* } * }
*/ */
template <typename T> template <typename T>
class Resource:public Resource_base class Resource:public Resource_base, public Accessor<T> {
{
public: public:
typedef T Type; typedef T Type;
Resource(ResourceManager &rm, T val, Resource(ResourceManager &rm, T val,
const std::string &name, const std::string &altname): const std::string &name, const std::string &altname):
Resource_base(name, altname), Resource_base(name, altname),
m_value(val), m_defaultval(val), m_value(val), m_defaultval(val),
m_rm(rm) { m_rm(rm) {
m_rm.addResource(*this); // add this to resource handler m_rm.addResource(*this); // add this to resource handler
} }
@ -192,6 +192,7 @@ public:
/// @return string value of resource /// @return string value of resource
std::string getString() const; std::string getString() const;
inline operator T() const { return m_value; }
inline T& get() { return m_value; } inline T& get() { return m_value; }
inline T& operator*() { return m_value; } inline T& operator*() { return m_value; }
inline const T& operator*() const { return m_value; } inline const T& operator*() const { return m_value; }

View file

@ -95,8 +95,8 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr
m_button_size(1), m_button_size(1),
m_height_before_shade(1), m_height_before_shade(1),
m_shaded(false), m_shaded(false),
m_focused_alpha(theme, &FbWinFrameTheme::focusedAlpha), m_focused_alpha(AlphaAcc(theme, &FbWinFrameTheme::focusedAlpha)),
m_unfocused_alpha(theme, &FbWinFrameTheme::unfocusedAlpha), m_unfocused_alpha(AlphaAcc(theme, &FbWinFrameTheme::unfocusedAlpha)),
m_themelistener(*this), m_themelistener(*this),
m_shape(m_window, theme.shapePlace()), m_shape(m_window, theme.shapePlace()),
m_disable_themeshape(false) { m_disable_themeshape(false) {

View file

@ -400,8 +400,9 @@ private:
unsigned int m_height_before_shade; ///< height before shade, so we can restore it when we unshade unsigned int m_height_before_shade; ///< height before shade, so we can restore it when we unshade
bool m_shaded; ///< wheter we're shaded or not bool m_shaded; ///< wheter we're shaded or not
/// alpha values /// alpha values
FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_focused_alpha; typedef FbTk::ConstObjectAccessor<unsigned char, FbWinFrameTheme> AlphaAcc;
FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_unfocused_alpha; FbTk::DefaultValue<unsigned char, AlphaAcc> m_focused_alpha;
FbTk::DefaultValue<unsigned char, AlphaAcc> m_unfocused_alpha;
class ThemeListener: public FbTk::Observer { class ThemeListener: public FbTk::Observer {
public: public:

View file

@ -32,7 +32,6 @@
#include "IconButton.hh" #include "IconButton.hh"
#include "Workspace.hh" #include "Workspace.hh"
#include "FbMenu.hh" #include "FbMenu.hh"
#include "BoolMenuItem.hh"
#include "FbTk/ObjectRegistry.hh" #include "FbTk/ObjectRegistry.hh"
#include "WinClient.hh" #include "WinClient.hh"
#include "FocusControl.hh" #include "FocusControl.hh"
@ -43,6 +42,7 @@
#include "FbTk/I18n.hh" #include "FbTk/I18n.hh"
#include "FbTk/Menu.hh" #include "FbTk/Menu.hh"
#include "FbTk/MenuItem.hh" #include "FbTk/MenuItem.hh"
#include "FbTk/BoolMenuItem.hh"
#include "FbTk/RefCount.hh" #include "FbTk/RefCount.hh"
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
#include "FbTk/ImageControl.hh" #include "FbTk/ImageControl.hh"
@ -288,9 +288,9 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme,
save_and_reconfig->add(reconfig); save_and_reconfig->add(reconfig);
save_and_reconfig->add(save); save_and_reconfig->add(save);
RefCount<Command> s_and_reconfig(save_and_reconfig); RefCount<Command> s_and_reconfig(save_and_reconfig);
m_menu.insert(new BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, m_menu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons,
"Show Pictures", "chooses if little icons are shown next to title in the iconbar"), "Show Pictures", "chooses if little icons are shown next to title in the iconbar"),
*m_rc_use_pixmap, s_and_reconfig)); m_rc_use_pixmap, s_and_reconfig));
m_menu.updateMenu(); m_menu.updateMenu();
// must be internal menu, otherwise toolbar main menu tries to delete it. // must be internal menu, otherwise toolbar main menu tries to delete it.
m_menu.setInternalMenu(); m_menu.setInternalMenu();

View file

@ -96,7 +96,6 @@ TOOLBAR_SOURCE = Toolbar.hh Toolbar.cc \
endif endif
fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \ fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \
BoolMenuItem.hh \
FbAtoms.hh FbAtoms.cc FbWinFrame.hh FbWinFrame.cc \ FbAtoms.hh FbAtoms.cc FbWinFrame.hh FbWinFrame.cc \
FbWinFrameTheme.hh FbWinFrameTheme.cc \ FbWinFrameTheme.hh FbWinFrameTheme.cc \
fluxbox.cc fluxbox.hh \ fluxbox.cc fluxbox.hh \
@ -111,7 +110,7 @@ fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \
Workspace.cc Workspace.hh \ Workspace.cc Workspace.hh \
FbCommands.hh FbCommands.cc LayerMenu.hh LayerMenu.cc \ FbCommands.hh FbCommands.cc LayerMenu.hh LayerMenu.cc \
Layer.hh \ Layer.hh \
IntResMenuItem.hh FbMenu.hh FbMenu.cc \ FbMenu.hh FbMenu.cc \
WinClient.hh WinClient.cc \ WinClient.hh WinClient.cc \
Strut.hh \ Strut.hh \
Xinerama.hh \ Xinerama.hh \

View file

@ -37,7 +37,6 @@
#include "SendToMenu.hh" #include "SendToMenu.hh"
#include "AlphaMenu.hh" #include "AlphaMenu.hh"
#include "Layer.hh" #include "Layer.hh"
#include "BoolMenuItem.hh"
#include "FbMenuParser.hh" #include "FbMenuParser.hh"
#include "StyleMenuItem.hh" #include "StyleMenuItem.hh"
@ -45,6 +44,7 @@
#include "FbTk/I18n.hh" #include "FbTk/I18n.hh"
#include "FbTk/MultiButtonMenuItem.hh" #include "FbTk/MultiButtonMenuItem.hh"
#include "FbTk/BoolMenuItem.hh"
#include "FbTk/RefCount.hh" #include "FbTk/RefCount.hh"
#include "FbTk/MacroCommand.hh" #include "FbTk/MacroCommand.hh"
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
@ -157,7 +157,7 @@ private:
FbTk::Menu *m_menu; FbTk::Menu *m_menu;
}; };
class MenuContext: public LayerObject, public AlphaObject { class MenuContext: public LayerObject {
public: public:
void moveToLayer(int layer_number) { void moveToLayer(int layer_number) {
if (WindowCmd<void>::window() == 0) if (WindowCmd<void>::window() == 0)
@ -170,42 +170,6 @@ public:
return WindowCmd<void>::window()->layerItem().getLayerNum(); return WindowCmd<void>::window()->layerItem().getLayerNum();
} }
int getFocusedAlpha() const {
if (WindowCmd<void>::window() == 0)
return 255;
return WindowCmd<void>::window()->getFocusedAlpha();
}
int getUnfocusedAlpha() const {
if (WindowCmd<void>::window() == 0)
return 255;
return WindowCmd<void>::window()->getUnfocusedAlpha();
}
bool getUseDefaultAlpha() const {
if (WindowCmd<void>::window() == 0)
return true;
return WindowCmd<void>::window()->getUseDefaultAlpha();
}
void setFocusedAlpha(int alpha) {
if (WindowCmd<void>::window() == 0)
return;
WindowCmd<void>::window()->setFocusedAlpha(alpha);
}
void setUnfocusedAlpha(int alpha) {
if (WindowCmd<void>::window() == 0)
return;
WindowCmd<void>::window()->setUnfocusedAlpha(alpha);
}
void setDefaultAlpha() {
if (WindowCmd<void>::window() == 0)
return;
WindowCmd<void>::window()->setDefaultAlpha();
}
}; };
static void translateMenuItem(Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); static void translateMenuItem(Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor);
@ -551,8 +515,8 @@ bool MenuCreator::createWindowMenuItem(const string &type,
static MenuContext context; static MenuContext context;
if (type == "shade") { if (type == "shade") {
static ObjectResource<FluxboxWindow, bool> res(&WindowCmd<void>::window, &FluxboxWindow::isShaded, &FluxboxWindow::shade, false); static WindowAccessor<bool> res(&FluxboxWindow::isShaded, &FluxboxWindow::setShaded, false);
menu.insert(new BoolResMenuItem<ObjectResource<FluxboxWindow, bool> >( menu.insert(new FbTk::BoolMenuItem(
label.empty()?_FB_XTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label, label.empty()?_FB_XTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label,
res)); res));
@ -575,8 +539,8 @@ bool MenuCreator::createWindowMenuItem(const string &type,
maximize_item->setCommand(3, maximize_horiz_cmd); maximize_item->setCommand(3, maximize_horiz_cmd);
menu.insert(maximize_item); menu.insert(maximize_item);
} else if (type == "iconify") { } else if (type == "iconify") {
static ObjectResource<FluxboxWindow, bool> res(&WindowCmd<void>::window, &FluxboxWindow::isIconic, &FluxboxWindow::toggleIconic, false); static WindowAccessor<bool> res(&FluxboxWindow::isIconic, &FluxboxWindow::setIconic, false);
menu.insert(new BoolResMenuItem<ObjectResource<FluxboxWindow, bool> >( menu.insert(new FbTk::BoolMenuItem(
label.empty() ? label.empty() ?
_FB_XTEXT(Windowmenu, Iconify, _FB_XTEXT(Windowmenu, Iconify,
"Iconify", "Iconify the window") : "Iconify", "Iconify the window") :
@ -607,8 +571,8 @@ bool MenuCreator::createWindowMenuItem(const string &type,
label, raise_cmd); label, raise_cmd);
} else if (type == "stick") { } else if (type == "stick") {
static ObjectResource<FluxboxWindow, bool> res(&WindowCmd<void>::window, &FluxboxWindow::isStuck, &FluxboxWindow::stick, false); static WindowAccessor<bool> res(&FluxboxWindow::isStuck, &FluxboxWindow::setStuck, false);
menu.insert(new BoolResMenuItem<ObjectResource<FluxboxWindow, bool> >( menu.insert(new FbTk::BoolMenuItem(
label.empty() ? label.empty() ?
_FB_XTEXT(Windowmenu, Stick, _FB_XTEXT(Windowmenu, Stick,
"Stick", "Stick the window"): "Stick", "Stick the window"):
@ -625,8 +589,7 @@ bool MenuCreator::createWindowMenuItem(const string &type,
"Menu containing various transparency options"): label, "Menu containing various transparency options"): label,
new AlphaMenu(screen->menuTheme(), new AlphaMenu(screen->menuTheme(),
screen->imageControl(), screen->imageControl(),
*screen->layerManager().getLayer(Layer::MENU), *screen->layerManager().getLayer(Layer::MENU)));
context));
} }
#endif // HAVE_XRENDER #endif // HAVE_XRENDER
} else if (type == "extramenus") { } else if (type == "extramenus") {

View file

@ -1,145 +0,0 @@
// ObjectResource.hh for Fluxbox
// Copyright (c) 2007 Henrik Kinnunen (fluxgen at fluxbox dot org)
// and Simon Bowden (rathnor at users.sourceforge.net)
//
// 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.
// $Id$
#ifndef OBJECTRESOURCE_HH
#define OBJECTRESOURCE_HH
/* This is a generic resource that can be used as an accessor to a value in an object.
The constructors allow to select between:
1a. giving an object of ObjectType, OR
1b. giving a function returning an object of ObjectType
2a. a function that sets a value
2b. a function that toggles a value
*/
template <typename ObjectType, typename ValueType>
class ObjectResource {
public:
typedef ValueType (ObjectType::* getResourceType)() const;
typedef void (ObjectType::* setResourceType)(ValueType);
typedef void (ObjectType::* toggleResourceType)();
typedef ObjectType* (*getResourceObject)();
ObjectResource(ObjectType *object, getResourceType get, setResourceType set, ValueType a_default) :
m_get(get), m_set(set), m_istoggle(false), m_object(object),
m_default(a_default), m_use_accessor(false) {
}
ObjectResource(ObjectType *object, getResourceType get, toggleResourceType toggle, ValueType a_default) :
m_get(get), m_toggle(toggle), m_istoggle(true), m_object(object),
m_default(a_default), m_use_accessor(false) {
}
ObjectResource(getResourceObject object_accessor, getResourceType get, setResourceType set, ValueType a_default) :
m_get(get), m_set(set), m_istoggle(false), m_object_accessor(object_accessor),
m_default(a_default), m_use_accessor(true) {
}
ObjectResource(getResourceObject object_accessor, getResourceType get, toggleResourceType toggle, ValueType a_default) :
m_get(get), m_toggle(toggle), m_istoggle(true), m_object_accessor(object_accessor),
m_default(a_default), m_use_accessor(true) {
}
ObjectResource<ObjectType, ValueType>& operator = (const ValueType newvalue) {
ObjectType * obj = getObject();
if (!obj)
return *this;
if (m_istoggle) {
if (newvalue != (operator*)())
(obj->*m_toggle)();
} else {
(obj->*m_set)(newvalue);
}
return *this;
}
ObjectResource<ObjectType, ValueType>& operator += (const ValueType newvalue) {
ObjectType * obj = getObject();
if (obj && !m_istoggle)
(obj->*m_set)((operator*)()+newvalue);
return *this;
}
ObjectResource<ObjectType, ValueType>& operator -= (const ValueType newvalue) {
ObjectType * obj = getObject();
if (obj && !m_istoggle)
(obj->*m_set)((operator*)()-newvalue);
return *this;
}
// this is a touch dirty, but it makes us compatible with FbTk::Resource<int> in IntResMenuItem
ObjectResource<ObjectType, ValueType>& get() {
return *this;
}
ValueType operator*() {
ObjectType * obj = getObject();
if (!obj)
return m_default;
return (obj->*m_get)();
}
const ValueType operator*() const {
ObjectType * obj = getObject();
if (!obj)
return m_default;
return (obj->*m_get)();
}
private:
// choose one get and one set function
ObjectType * getObject() {
if (m_use_accessor)
return (*m_object_accessor)();
else
return m_object;
}
getResourceType m_get;
union {
setResourceType m_set;
toggleResourceType m_toggle;
};
bool m_istoggle;
union {
ObjectType *m_object;
getResourceObject m_object_accessor;
};
// default is only used when object isn't set (saves crashes)
ValueType m_default;
bool m_use_accessor;
};
#endif // OBJECTRESOURCE_HH

View file

@ -47,8 +47,8 @@
#include "SlitTheme.hh" #include "SlitTheme.hh"
// menu items // menu items
#include "BoolMenuItem.hh" #include "FbTk/BoolMenuItem.hh"
#include "IntResMenuItem.hh" #include "FbTk/IntMenuItem.hh"
#include "FocusModelMenuItem.hh" #include "FocusModelMenuItem.hh"
// menus // menus
@ -1576,7 +1576,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
"Method used to give focus to windows"); "Method used to give focus to windows");
FbTk::Menu *focus_menu = createMenu(focusmenu_label); FbTk::Menu *focus_menu = createMenu(focusmenu_label);
#define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) #define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f))
#define _FOCUSITEM(a, b, c, d, e) \ #define _FOCUSITEM(a, b, c, d, e) \
@ -1599,19 +1599,19 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
focusControl(), FocusControl::MOUSETABFOCUS, save_and_reconfigure)); focusControl(), FocusControl::MOUSETABFOCUS, save_and_reconfigure));
try { try {
focus_menu->insert(new BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew,
"Focus New Windows", "Focus newly created windows"), "Focus New Windows", "Focus newly created windows"),
*m_resource_manager.getResource<bool>(name() + ".focusNewWindows"), m_resource_manager.getResource<bool>(name() + ".focusNewWindows"),
saverc_cmd)); saverc_cmd));
} catch (FbTk::ResourceException e) { } catch (FbTk::ResourceException e) {
cerr<<e.what()<<endl; cerr<<e.what()<<endl;
} }
focus_menu->insert(new BoolMenuItem(_FB_XTEXT(Configmenu, focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu,
AutoRaise, AutoRaise,
"Auto Raise", "Auto Raise",
"Auto Raise windows on sloppy"), "Auto Raise windows on sloppy"),
*resource.auto_raise, resource.auto_raise,
save_and_reconfigure)); save_and_reconfigure));
focus_menu->updateMenu(); focus_menu->updateMenu();
@ -1628,17 +1628,17 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
_BOOLITEM(*maxmenu, Configmenu, FullMax, _BOOLITEM(*maxmenu, Configmenu, FullMax,
"Full Maximization", "Maximise over slit, toolbar, etc", "Full Maximization", "Maximise over slit, toolbar, etc",
*resource.full_max, saverc_cmd); resource.full_max, saverc_cmd);
_BOOLITEM(*maxmenu, Configmenu, MaxIgnoreInc, _BOOLITEM(*maxmenu, Configmenu, MaxIgnoreInc,
"Ignore Resize Increment", "Ignore Resize Increment",
"Maximizing Ignores Resize Increment (e.g. xterm)", "Maximizing Ignores Resize Increment (e.g. xterm)",
*resource.max_ignore_inc, saverc_cmd); resource.max_ignore_inc, saverc_cmd);
_BOOLITEM(*maxmenu, Configmenu, MaxDisableMove, _BOOLITEM(*maxmenu, Configmenu, MaxDisableMove,
"Disable Moving", "Don't Allow Moving While Maximized", "Disable Moving", "Don't Allow Moving While Maximized",
*resource.max_disable_move, saverc_cmd); resource.max_disable_move, saverc_cmd);
_BOOLITEM(*maxmenu, Configmenu, MaxDisableResize, _BOOLITEM(*maxmenu, Configmenu, MaxDisableResize,
"Disable Resizing", "Don't Allow Resizing While Maximized", "Disable Resizing", "Don't Allow Resizing While Maximized",
*resource.max_disable_resize, saverc_cmd); resource.max_disable_resize, saverc_cmd);
maxmenu->updateMenu(); maxmenu->updateMenu();
menu.insert(maxmenu_label, maxmenu); menu.insert(maxmenu_label, maxmenu);
@ -1658,16 +1658,16 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
_BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar, _BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar,
"Tabs in Titlebar", "Tabs in Titlebar", "Tabs in Titlebar", "Tabs in Titlebar",
*resource.default_internal_tabs, save_and_reconftabs); resource.default_internal_tabs, save_and_reconftabs);
tab_menu->insert(new BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,
"Maximize Over", "Maximize over this thing when maximizing"), "Maximize Over", "Maximize over this thing when maximizing"),
*resource.max_over_tabs, save_and_reconfigure)); resource.max_over_tabs, save_and_reconfigure));
tab_menu->insert(new BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons,
"Show Pictures", "chooses if little icons are shown next to title in the iconbar"), "Show Pictures", "chooses if little icons are shown next to title in the iconbar"),
*resource.tabs_use_pixmap, save_and_reconfigure)); resource.tabs_use_pixmap, save_and_reconfigure));
FbTk::MenuItem *tab_width_item = FbTk::MenuItem *tab_width_item =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Configmenu, ExternalTabWidth, new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, ExternalTabWidth,
"External Tab Width", "External Tab Width",
"Width of external-style tabs"), "Width of external-style tabs"),
resource.tab_width, 10, 3000, /* silly number */ resource.tab_width, 10, 3000, /* silly number */
@ -1715,10 +1715,11 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
FbTk::Menu *alpha_menu = createMenu(alphamenu_label); FbTk::Menu *alpha_menu = createMenu(alphamenu_label);
if (FbTk::Transparent::haveComposite(true)) { if (FbTk::Transparent::haveComposite(true)) {
alpha_menu->insert(new BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, static FbTk::SimpleAccessor<bool> s_pseudo(Fluxbox::instance()->getPseudoTrans());
alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans,
"Force Pseudo-Transparency", "Force Pseudo-Transparency",
"When composite is available, still use old pseudo-transparency"), "When composite is available, still use old pseudo-transparency"),
Fluxbox::instance()->getPseudoTrans(), save_and_reconfigure)); s_pseudo, save_and_reconfigure));
} }
// in order to save system resources, don't save or reconfigure alpha // in order to save system resources, don't save or reconfigure alpha
@ -1727,7 +1728,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
new ::DelayedCmd(save_and_reconfigure)); new ::DelayedCmd(save_and_reconfigure));
FbTk::MenuItem *focused_alpha_item = FbTk::MenuItem *focused_alpha_item =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Configmenu, FocusedAlpha, new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha,
"Focused Window Alpha", "Focused Window Alpha",
"Transparency level of the focused window"), "Transparency level of the focused window"),
resource.focused_alpha, 0, 255, *alpha_menu); resource.focused_alpha, 0, 255, *alpha_menu);
@ -1735,7 +1736,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
alpha_menu->insert(focused_alpha_item); alpha_menu->insert(focused_alpha_item);
FbTk::MenuItem *unfocused_alpha_item = FbTk::MenuItem *unfocused_alpha_item =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Configmenu, new FbTk::IntMenuItem(_FB_XTEXT(Configmenu,
UnfocusedAlpha, UnfocusedAlpha,
"Unfocused Window Alpha", "Unfocused Window Alpha",
"Transparency level of unfocused windows"), "Transparency level of unfocused windows"),
@ -1745,7 +1746,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
alpha_menu->insert(unfocused_alpha_item); alpha_menu->insert(unfocused_alpha_item);
FbTk::MenuItem *menu_alpha_item = FbTk::MenuItem *menu_alpha_item =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Configmenu, MenuAlpha, new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, MenuAlpha,
"Menu Alpha", "Transparency level of menu"), "Menu Alpha", "Transparency level of menu"),
resource.menu_alpha, 0, 255, *alpha_menu); resource.menu_alpha, 0, 255, *alpha_menu);
menu_alpha_item->setCommand(delayed_save_and_reconf); menu_alpha_item->setCommand(delayed_save_and_reconf);
@ -1763,21 +1764,21 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
_BOOLITEM(menu, Configmenu, ImageDithering, _BOOLITEM(menu, Configmenu, ImageDithering,
"Image Dithering", "Image Dithering", "Image Dithering", "Image Dithering",
*resource.image_dither, save_and_reconfigure); resource.image_dither, save_and_reconfigure);
_BOOLITEM(menu, Configmenu, OpaqueMove, _BOOLITEM(menu, Configmenu, OpaqueMove,
"Opaque Window Moving", "Opaque Window Moving",
"Window Moving with whole window visible (as opposed to outline moving)", "Window Moving with whole window visible (as opposed to outline moving)",
*resource.opaque_move, saverc_cmd); resource.opaque_move, saverc_cmd);
_BOOLITEM(menu, Configmenu, WorkspaceWarping, _BOOLITEM(menu, Configmenu, WorkspaceWarping,
"Workspace Warping", "Workspace Warping",
"Workspace Warping - dragging windows to the edge and onto the next workspace", "Workspace Warping - dragging windows to the edge and onto the next workspace",
*resource.workspace_warping, saverc_cmd); resource.workspace_warping, saverc_cmd);
_BOOLITEM(menu, Configmenu, DecorateTransient, _BOOLITEM(menu, Configmenu, DecorateTransient,
"Decorate Transient Windows", "Decorate Transient Windows", "Decorate Transient Windows", "Decorate Transient Windows",
*resource.decorate_transient, saverc_cmd); resource.decorate_transient, saverc_cmd);
_BOOLITEM(menu, Configmenu, ClickRaises, _BOOLITEM(menu, Configmenu, ClickRaises,
"Click Raises", "Click Raises", "Click Raises", "Click Raises",
*resource.click_raises, saverc_cmd); resource.click_raises, saverc_cmd);
#undef _BOOLITEM #undef _BOOLITEM

View file

@ -38,7 +38,6 @@
#include "Screen.hh" #include "Screen.hh"
#include "ImageControl.hh" #include "ImageControl.hh"
#include "RefCount.hh" #include "RefCount.hh"
#include "BoolMenuItem.hh"
#include "EventManager.hh" #include "EventManager.hh"
#include "SimpleCommand.hh" #include "SimpleCommand.hh"
#include "MacroCommand.hh" #include "MacroCommand.hh"
@ -50,7 +49,6 @@
#include "FbTk/Theme.hh" #include "FbTk/Theme.hh"
#include "FbMenu.hh" #include "FbMenu.hh"
#include "Transparent.hh" #include "Transparent.hh"
#include "IntResMenuItem.hh"
#ifdef XINERAMA #ifdef XINERAMA
#include "Xinerama.hh" #include "Xinerama.hh"
@ -63,6 +61,8 @@
#include "FbTk/MenuSeparator.hh" #include "FbTk/MenuSeparator.hh"
#include "FbTk/StringUtil.hh" #include "FbTk/StringUtil.hh"
#include "FbTk/I18n.hh" #include "FbTk/I18n.hh"
#include "FbTk/BoolMenuItem.hh"
#include "FbTk/IntMenuItem.hh"
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
#include <sys/types.h> #include <sys/types.h>
@ -1268,17 +1268,17 @@ void Slit::setupMenu() {
} }
#endif //XINERAMA #endif //XINERAMA
m_slitmenu.insert(new BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"), m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"),
*m_rc_auto_hide, m_rc_auto_hide,
save_and_reconfigure_slit)); save_and_reconfigure_slit));
m_slitmenu.insert(new BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"),
*m_rc_maximize_over, m_rc_maximize_over,
save_and_reconfigure_slit)); save_and_reconfigure_slit));
// this saves resources and clears the slit window to update alpha value // this saves resources and clears the slit window to update alpha value
FbTk::MenuItem *alpha_menuitem = FbTk::MenuItem *alpha_menuitem =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"),
m_rc_alpha, m_rc_alpha,
0, 255, m_slitmenu); 0, 255, m_slitmenu);
// setup command for alpha value // setup command for alpha value

View file

@ -36,8 +36,6 @@
#include "Keys.hh" #include "Keys.hh"
#include "Screen.hh" #include "Screen.hh"
#include "WindowCmd.hh" #include "WindowCmd.hh"
#include "IntResMenuItem.hh"
#include "BoolMenuItem.hh"
#ifdef XINERAMA #ifdef XINERAMA
#include "Xinerama.hh" #include "Xinerama.hh"
@ -54,6 +52,8 @@
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
#include "FbTk/StringUtil.hh" #include "FbTk/StringUtil.hh"
#include "FbTk/Transparent.hh" #include "FbTk/Transparent.hh"
#include "FbTk/BoolMenuItem.hh"
#include "FbTk/IntMenuItem.hh"
// use GNU extensions // use GNU extensions
@ -835,17 +835,17 @@ void Toolbar::setupMenus(bool skip_new_placement) {
visible_macro->add(reconfig_toolbar); visible_macro->add(reconfig_toolbar);
visible_macro->add(save_resources); visible_macro->add(save_resources);
RefCommand toggle_visible_cmd(visible_macro); RefCommand toggle_visible_cmd(visible_macro);
menu().insert(new BoolMenuItem(_FB_XTEXT(Common, Visible, menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible,
"Visible", "Whether this item is visible"), "Visible", "Whether this item is visible"),
*m_rc_visible, toggle_visible_cmd)); m_rc_visible, toggle_visible_cmd));
menu().insert(new BoolMenuItem(_FB_XTEXT(Common, AutoHide, menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide,
"Auto hide", "Toggle auto hide of toolbar"), "Auto hide", "Toggle auto hide of toolbar"),
*m_rc_auto_hide, m_rc_auto_hide,
reconfig_toolbar_and_save_resource)); reconfig_toolbar_and_save_resource));
MenuItem *toolbar_menuitem = MenuItem *toolbar_menuitem =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Toolbar, WidthPercent, new FbTk::IntMenuItem(_FB_XTEXT(Toolbar, WidthPercent,
"Toolbar width percent", "Toolbar width percent",
"Percentage of screen width taken by toolbar"), "Percentage of screen width taken by toolbar"),
m_rc_width_percent, m_rc_width_percent,
@ -855,10 +855,10 @@ void Toolbar::setupMenus(bool skip_new_placement) {
toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource);
menu().insert(toolbar_menuitem); menu().insert(toolbar_menuitem);
menu().insert(new BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,
"Maximize Over", "Maximize Over",
"Maximize over this thing when maximizing"), "Maximize over this thing when maximizing"),
*m_rc_maximize_over, m_rc_maximize_over,
reconfig_toolbar_and_save_resource)); reconfig_toolbar_and_save_resource));
menu().insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu()); menu().insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu());
#ifdef XINERAMA #ifdef XINERAMA
@ -922,7 +922,7 @@ void Toolbar::setupMenus(bool skip_new_placement) {
// this saves resources and clears the slit window to update alpha value // this saves resources and clears the slit window to update alpha value
FbTk::MenuItem *alpha_menuitem = FbTk::MenuItem *alpha_menuitem =
new IntResMenuItem< FbTk::Resource<int> >(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"),
m_rc_alpha, m_rc_alpha,
0, 255, menu()); 0, 255, menu());
// setup command for alpha value // setup command for alpha value

View file

@ -264,8 +264,8 @@ FluxboxWindow::FluxboxWindow(WinClient &client, FbWinFrameTheme &tm,
m_toggled_decos(false), m_toggled_decos(false),
m_icon_hidden(false), m_icon_hidden(false),
m_focus_hidden(false), m_focus_hidden(false),
m_focus_new(screen().focusControl(), &FocusControl::focusNew), m_focus_new(BoolAcc(screen().focusControl(), &FocusControl::focusNew)),
m_mouse_focus(screen().focusControl(), &FocusControl::isMouseFocus), m_mouse_focus(BoolAcc(screen().focusControl(), &FocusControl::isMouseFocus)),
m_click_focus(true), m_click_focus(true),
m_old_pos_x(0), m_old_pos_y(0), m_old_pos_x(0), m_old_pos_y(0),
m_old_width(1), m_old_height(1), m_old_width(1), m_old_height(1),
@ -1745,17 +1745,18 @@ void FluxboxWindow::shade() {
} }
void FluxboxWindow::shadeOn() { void FluxboxWindow::shadeOn() {
if (!shaded) if (!shaded)
shade(); shade();
} }
void FluxboxWindow::shadeOff() { void FluxboxWindow::shadeOff() {
if (shaded) if (shaded)
shade(); shade();
}
void FluxboxWindow::setShaded(bool val) {
if (val != shaded)
shade();
} }
void FluxboxWindow::stick() { void FluxboxWindow::stick() {
@ -1783,6 +1784,17 @@ void FluxboxWindow::stick() {
} }
void FluxboxWindow::setStuck(bool val) {
if (val != stuck)
stick();
}
void FluxboxWindow::setIconic(bool val) {
if (val && isIconic())
deiconify();
if (!val && !isIconic())
iconify();
}
void FluxboxWindow::raise() { void FluxboxWindow::raise() {
if (isIconic()) if (isIconic())

View file

@ -270,10 +270,16 @@ public:
void shadeOn(); void shadeOn();
/// unshades window /// unshades window
void shadeOff(); void shadeOff();
/// sets shaded state
void setShaded(bool val);
/// toggles sticky /// toggles sticky
void stick(); void stick();
/// sets stuck state
void setStuck(bool val);
/// toggles iconic /// toggles iconic
void toggleIconic(); void toggleIconic();
/// sets iconic state
void setIconic(bool val);
void raise(); void raise();
void lower(); void lower();
void tempRaise(); void tempRaise();
@ -611,10 +617,11 @@ private:
bool m_icon_hidden; ///< if the window is in the iconbar bool m_icon_hidden; ///< if the window is in the iconbar
bool m_focus_hidden; ///< if the window is in the NextWindow list bool m_focus_hidden; ///< if the window is in the NextWindow list
typedef FbTk::ConstObjectAccessor<bool, FocusControl> BoolAcc;
/// if the window is normally focused when mapped /// if the window is normally focused when mapped
FbTk::DefaultAccessor<bool, FocusControl> m_focus_new; FbTk::DefaultValue<bool, BoolAcc> m_focus_new;
/// if the window is focused with EnterNotify /// if the window is focused with EnterNotify
FbTk::DefaultAccessor<bool, FocusControl> m_mouse_focus; FbTk::DefaultValue<bool, BoolAcc> m_mouse_focus;
bool m_click_focus; ///< if the window is focused by clicking bool m_click_focus; ///< if the window is focused by clicking
int m_old_pos_x, m_old_pos_y; ///< old position so we can restore from maximized int m_old_pos_x, m_old_pos_y; ///< old position so we can restore from maximized
unsigned int m_old_width, m_old_height; ///< old size so we can restore from maximized state unsigned int m_old_width, m_old_height; ///< old size so we can restore from maximized state

View file

@ -25,6 +25,7 @@
#define WINDOWCMD_HH #define WINDOWCMD_HH
#include "FbTk/Command.hh" #include "FbTk/Command.hh"
#include "FbTk/Accessor.hh"
#include "Window.hh" #include "Window.hh"
#include "WinClient.hh" #include "WinClient.hh"
@ -64,5 +65,49 @@ private:
Action m_action; Action m_action;
}; };
/// accesses values in current window
template <typename Ret, typename Def=Ret>
class WindowAccessor: public FbTk::Accessor<Ret> {
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) { }
inline operator Ret() const {
FluxboxWindow *fbwin = WindowCmd<void>::window();
return fbwin ? (fbwin->*m_getter)() : m_def;
}
inline FbTk::Accessor<Ret> &operator =(const Ret &val) {
FluxboxWindow *fbwin = WindowCmd<void>::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 <typename Ret, typename Def=Ret>
class ConstWindowAccessor: public FbTk::Accessor<Ret> {
public:
typedef Ret (FluxboxWindow:: *Getter)() const;
ConstWindowAccessor(Getter g, Def def):
m_getter(g), m_def(def) { }
inline operator Ret() const {
FluxboxWindow *fbwin = WindowCmd<void>::window();
return fbwin ? (fbwin->*m_getter)() : m_def;
}
inline FbTk::Accessor<Ret> &operator =(const Ret &val) { return *this; }
private:
Getter m_getter;
Def m_def;
};
#endif // WINDOWCMD_HH #endif // WINDOWCMD_HH