diff options
Diffstat (limited to 'src/WindowCmd.hh')
-rw-r--r-- | src/WindowCmd.hh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/WindowCmd.hh b/src/WindowCmd.hh new file mode 100644 index 0000000..309e62b --- /dev/null +++ b/src/WindowCmd.hh | |||
@@ -0,0 +1,32 @@ | |||
1 | #ifndef WINDOWCMD_HH | ||
2 | #define WINDOWCMD_HH | ||
3 | |||
4 | #include "FbTk/Command.hh" | ||
5 | #include "Window.hh" | ||
6 | |||
7 | /// holds context for WindowCmd | ||
8 | class WindowCmd_base { | ||
9 | public: | ||
10 | static void setWindow(FluxboxWindow *win) { s_win = win; } | ||
11 | static FluxboxWindow *window() { return s_win; } | ||
12 | protected: | ||
13 | static FluxboxWindow *s_win; | ||
14 | }; | ||
15 | |||
16 | |||
17 | /// executes action for a dynamic context set in WindowCmd_base | ||
18 | template <typename ReturnType=void> | ||
19 | class WindowCmd: public WindowCmd_base, public FbTk::Command { | ||
20 | public: | ||
21 | typedef ReturnType (FluxboxWindow::* Action)(); | ||
22 | WindowCmd(Action a):m_action(a) {} | ||
23 | void execute() { | ||
24 | if (window() != 0) | ||
25 | (*window().*m_action)(); | ||
26 | } | ||
27 | private: | ||
28 | Action m_action; | ||
29 | }; | ||
30 | |||
31 | |||
32 | #endif // WINDOWCMD_HH | ||