2003-05-19 14:26:30 +00:00
|
|
|
// Xinerama.hh for Fluxbox - helpful tools for multiple heads
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2003-05-19 14:26:30 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#ifndef XINERAMA_HH
|
|
|
|
#define XINERAMA_HH
|
|
|
|
|
|
|
|
#include "FbMenu.hh"
|
|
|
|
#include "fluxbox.hh"
|
2007-08-05 22:36:12 +00:00
|
|
|
#include "Screen.hh"
|
2003-05-19 14:26:30 +00:00
|
|
|
|
2007-12-30 15:32:53 +00:00
|
|
|
#include "FbTk/RefCount.hh"
|
|
|
|
#include "FbTk/SimpleCommand.hh"
|
2008-08-04 04:59:14 +00:00
|
|
|
#include "FbTk/RadioMenuItem.hh"
|
2007-12-30 15:32:53 +00:00
|
|
|
|
2003-05-19 14:26:30 +00:00
|
|
|
// provides a generic way for giving an object a xinerama head menu
|
|
|
|
// The object must have two functions:
|
|
|
|
// int getOnHead(), and
|
|
|
|
// void setOnHead(int)
|
|
|
|
|
|
|
|
/// this class holds the xinerama items
|
|
|
|
template <typename ItemType>
|
2008-08-04 04:59:14 +00:00
|
|
|
class XineramaHeadMenuItem : public FbTk::RadioMenuItem {
|
2003-05-19 14:26:30 +00:00
|
|
|
public:
|
2006-05-20 15:08:14 +00:00
|
|
|
XineramaHeadMenuItem(const FbTk::FbString &label, ItemType &object, int headnum,
|
2008-01-11 07:41:22 +00:00
|
|
|
FbTk::RefCount<FbTk::Command<void> > &cmd):
|
2008-08-04 04:59:14 +00:00
|
|
|
FbTk::RadioMenuItem(label,cmd), m_object(object), m_headnum(headnum) {}
|
2006-05-20 15:08:14 +00:00
|
|
|
XineramaHeadMenuItem(const FbTk::FbString &label, ItemType &object, int headnum):
|
2008-08-04 04:59:14 +00:00
|
|
|
FbTk::RadioMenuItem(label), m_object(object), m_headnum(headnum) {}
|
2003-05-19 14:26:30 +00:00
|
|
|
|
2008-08-04 04:59:14 +00:00
|
|
|
bool isSelected() const { return m_object.getOnHead() == m_headnum; }
|
2007-12-18 05:44:17 +00:00
|
|
|
void click(int button, int time, unsigned int mods) {
|
2003-07-19 11:55:49 +00:00
|
|
|
m_object.saveOnHead(m_headnum);
|
2008-08-04 04:59:14 +00:00
|
|
|
FbTk::RadioMenuItem::click(button, time, mods);
|
2003-05-19 14:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2003-07-19 11:55:49 +00:00
|
|
|
ItemType &m_object;
|
2003-05-19 14:26:30 +00:00
|
|
|
int m_headnum;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a xinerama menu
|
|
|
|
template <typename ItemType>
|
2007-08-05 22:36:12 +00:00
|
|
|
class XineramaHeadMenu : public ToggleMenu {
|
2003-05-19 14:26:30 +00:00
|
|
|
public:
|
2008-01-05 01:39:19 +00:00
|
|
|
XineramaHeadMenu(FbTk::ThemeProxy<FbTk::MenuTheme> &tm, BScreen &screen,
|
|
|
|
FbTk::ImageControl &imgctrl, FbTk::XLayer &layer,
|
|
|
|
ItemType &item, const FbTk::FbString & title = "");
|
2007-08-05 22:36:12 +00:00
|
|
|
void reloadHeads();
|
2003-05-19 14:26:30 +00:00
|
|
|
|
|
|
|
private:
|
2003-07-19 11:55:49 +00:00
|
|
|
ItemType &m_object;
|
2007-08-05 22:36:12 +00:00
|
|
|
BScreen &m_screen;
|
2003-05-19 14:26:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename ItemType>
|
2008-01-05 01:39:19 +00:00
|
|
|
XineramaHeadMenu<ItemType>::XineramaHeadMenu(
|
|
|
|
FbTk::ThemeProxy<FbTk::MenuTheme> &tm, BScreen &screen,
|
|
|
|
FbTk::ImageControl &imgctrl, FbTk::XLayer &layer, ItemType &item,
|
|
|
|
const FbTk::FbString & title):
|
2007-08-05 22:36:12 +00:00
|
|
|
ToggleMenu(tm, imgctrl, layer),
|
|
|
|
m_object(item), m_screen(screen)
|
2003-05-19 14:26:30 +00:00
|
|
|
{
|
2006-05-20 15:08:14 +00:00
|
|
|
setLabel(title);
|
2007-08-05 22:36:12 +00:00
|
|
|
reloadHeads();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ItemType>
|
|
|
|
void XineramaHeadMenu<ItemType>::reloadHeads()
|
|
|
|
{
|
|
|
|
removeAll();
|
2008-01-11 07:41:22 +00:00
|
|
|
FbTk::RefCount<FbTk::Command<void> > saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
|
2003-05-19 14:26:30 +00:00
|
|
|
*Fluxbox::instance(),
|
|
|
|
&Fluxbox::save_rc));
|
|
|
|
char tname[128];
|
2007-08-05 22:36:12 +00:00
|
|
|
for (int i=1; i <= m_screen.numHeads(); ++i) {
|
2003-05-19 14:26:30 +00:00
|
|
|
// TODO: nls
|
|
|
|
/*
|
|
|
|
sprintf(tname, I18n::instance()->
|
|
|
|
getMessage(
|
|
|
|
FBNLS::ScreenSet,
|
|
|
|
FBNLS::XineramaDefaultHeadFormat,
|
|
|
|
"Head %d"), i); //m_id starts at 0
|
|
|
|
*/
|
|
|
|
sprintf(tname, "Head %d", i);
|
|
|
|
insert(new XineramaHeadMenuItem<ItemType>(
|
|
|
|
tname, m_object, i, saverc_cmd));
|
|
|
|
}
|
|
|
|
// TODO: nls
|
|
|
|
insert(new XineramaHeadMenuItem<ItemType>(
|
|
|
|
"All Heads", m_object, 0, saverc_cmd));
|
2004-12-13 14:03:17 +00:00
|
|
|
updateMenu();
|
2003-05-19 14:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // XINERAMA_HH
|