1
// Xinerama.hh for Fluxbox - helpful tools for multiple heads
2
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
// and Simon Bowden (rathnor at users.sourceforge.net)
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
// copy of this software and associated documentation files (the "Software"),
7
// to deal in the Software without restriction, including without limitation
8
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
// and/or sell copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following conditions:
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
// DEALINGS IN THE SOFTWARE.
23
// $Id: Xinerama.hh 3865 2005-01-24 18:34:57Z mathias $
28
#include "MenuItem.hh"
30
#include "RefCount.hh"
31
#include "SimpleCommand.hh"
35
// provides a generic way for giving an object a xinerama head menu
36
// The object must have two functions:
37
// int getOnHead(), and
38
// void setOnHead(int)
40
/// this class holds the xinerama items
41
template <typename ItemType>
42
class XineramaHeadMenuItem : public FbTk::MenuItem {
44
XineramaHeadMenuItem(const char *label, ItemType &object, int headnum,
45
FbTk::RefCount<FbTk::Command> &cmd):
46
FbTk::MenuItem(label,cmd), m_object(object), m_headnum(headnum) {}
47
XineramaHeadMenuItem(const char *label, ItemType &object, int headnum):
48
FbTk::MenuItem(label), m_object(object), m_headnum(headnum) {}
50
bool isEnabled() const { return m_object.getOnHead() != m_headnum; }
51
void click(int button, int time) {
52
m_object.saveOnHead(m_headnum);
53
FbTk::MenuItem::click(button, time);
62
/// Create a xinerama menu
63
template <typename ItemType>
64
class XineramaHeadMenu : public FbMenu {
66
XineramaHeadMenu(MenuTheme &tm, BScreen &screen, FbTk::ImageControl &imgctrl,
67
FbTk::XLayer &layer, ItemType &item, const char * title = 0);
74
template <typename ItemType>
75
XineramaHeadMenu<ItemType>::XineramaHeadMenu(MenuTheme &tm, BScreen &screen, FbTk::ImageControl &imgctrl,
76
FbTk::XLayer &layer, ItemType &item, const char * title):
77
FbMenu(tm, imgctrl, layer),
82
FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
86
for (int i=1; i <= screen.numHeads(); ++i) {
89
sprintf(tname, I18n::instance()->
92
FBNLS::XineramaDefaultHeadFormat,
93
"Head %d"), i); //m_id starts at 0
95
sprintf(tname, "Head %d", i);
96
insert(new XineramaHeadMenuItem<ItemType>(
97
tname, m_object, i, saverc_cmd));
100
insert(new XineramaHeadMenuItem<ItemType>(
101
"All Heads", m_object, 0, saverc_cmd));
105
#endif // XINERAMA_HH