aboutsummaryrefslogtreecommitdiff
path: root/src/Xinerama.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xinerama.hh')
-rw-r--r--src/Xinerama.hh105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/Xinerama.hh b/src/Xinerama.hh
new file mode 100644
index 0000000..977d42c
--- /dev/null
+++ b/src/Xinerama.hh
@@ -0,0 +1,105 @@
1// Xinerama.hh for Fluxbox - helpful tools for multiple heads
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
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:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
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.
22
23// $Id: Xinerama.hh,v 1.7 2003/12/10 23:08:03 fluxgen Exp $
24
25#ifndef XINERAMA_HH
26#define XINERAMA_HH
27
28#include "MenuItem.hh"
29#include "FbMenu.hh"
30#include "RefCount.hh"
31#include "SimpleCommand.hh"
32
33#include "fluxbox.hh"
34
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)
39
40/// this class holds the xinerama items
41template <typename ItemType>
42class XineramaHeadMenuItem : public FbTk::MenuItem {
43public:
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) {}
49
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);
54 }
55
56private:
57 ItemType &m_object;
58 int m_headnum;
59};
60
61
62/// Create a xinerama menu
63template <typename ItemType>
64class XineramaHeadMenu : public FbMenu {
65public:
66 XineramaHeadMenu(MenuTheme &tm, BScreen &screen, FbTk::ImageControl &imgctrl,
67 FbTk::XLayer &layer, ItemType &item, const char * title);
68
69private:
70 ItemType &m_object;
71};
72
73
74template <typename ItemType>
75XineramaHeadMenu<ItemType>::XineramaHeadMenu(MenuTheme &tm, BScreen &screen, FbTk::ImageControl &imgctrl,
76 FbTk::XLayer &layer, ItemType &item, const char * title = 0):
77 FbMenu(tm, imgctrl, layer),
78 m_object(item)
79{
80 if (title)
81 setLabel(title);
82 FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
83 *Fluxbox::instance(),
84 &Fluxbox::save_rc));
85 char tname[128];
86 for (int i=1; i <= screen.numHeads(); ++i) {
87 // TODO: nls
88/*
89 sprintf(tname, I18n::instance()->
90 getMessage(
91 FBNLS::ScreenSet,
92 FBNLS::XineramaDefaultHeadFormat,
93 "Head %d"), i); //m_id starts at 0
94*/
95 sprintf(tname, "Head %d", i);
96 insert(new XineramaHeadMenuItem<ItemType>(
97 tname, m_object, i, saverc_cmd));
98 }
99 // TODO: nls
100 insert(new XineramaHeadMenuItem<ItemType>(
101 "All Heads", m_object, 0, saverc_cmd));
102 update();
103}
104
105#endif // XINERAMA_HH