fluxbox/src/Slit.cc

1353 lines
42 KiB
C++
Raw Normal View History

2002-11-14 00:23:19 +00:00
// Slit.cc for fluxbox
2006-02-16 06:53:05 +00:00
// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
2002-11-14 00:23:19 +00:00
//
2001-12-11 20:47:02 +00:00
// Slit.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
2001-12-11 20:47:02 +00:00
//
// 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
2001-12-11 20:47:02 +00:00
// 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.
2004-11-19 11:37:27 +00:00
// $Id$
#include "Slit.hh"
2002-04-08 18:58:47 +00:00
2002-03-11 12:29:57 +00:00
//use GNU extensions
2001-12-11 20:47:02 +00:00
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif // _GNU_SOURCE
2002-10-13 21:47:54 +00:00
#ifdef HAVE_CONFIG_H
2003-05-04 20:50:15 +00:00
#include "config.h"
2001-12-11 20:47:02 +00:00
#endif // HAVE_CONFIG_H
#include "Screen.hh"
2002-11-30 20:29:27 +00:00
#include "ImageControl.hh"
#include "RefCount.hh"
#include "BoolMenuItem.hh"
#include "EventManager.hh"
#include "SimpleCommand.hh"
#include "MacroCommand.hh"
#include "FbCommands.hh"
2006-02-27 22:43:42 +00:00
#include "Layer.hh"
#include "LayerMenu.hh"
#include "XLayer.hh"
2003-04-25 10:46:07 +00:00
#include "RootTheme.hh"
#include "FbTk/Theme.hh"
2003-05-06 01:45:17 +00:00
#include "FbMenu.hh"
2003-05-13 21:12:18 +00:00
#include "Transparent.hh"
#include "IntResMenuItem.hh"
#ifdef XINERAMA
#include "Xinerama.hh"
#endif // XINERAMA
#include "SlitTheme.hh"
#include "SlitClient.hh"
2003-06-22 12:31:37 +00:00
#include "Xutil.hh"
2003-06-27 15:05:19 +00:00
#include "FbAtoms.hh"
2006-02-27 21:43:01 +00:00
#include "FbTk/App.hh"
#include "FbTk/MenuSeparator.hh"
2004-01-30 11:06:25 +00:00
#include "FbTk/StringUtil.hh"
2004-06-07 11:46:05 +00:00
#include "FbTk/I18n.hh"
2002-02-04 22:33:09 +00:00
#include <algorithm>
2002-05-29 06:21:59 +00:00
#include <iostream>
2004-08-31 15:26:40 +00:00
#ifdef HAVE_CASSERT
#include <cassert>
#else
#include <assert.h>
#endif
2002-02-04 22:33:09 +00:00
2002-05-29 06:21:59 +00:00
#ifdef HAVE_SYS_STAT_H
#include <sys/types.h>
#include <sys/stat.h>
2002-05-29 06:21:59 +00:00
#endif // HAVE_SYS_STAT_H
#include <X11/Xatom.h>
2003-06-27 15:05:19 +00:00
#include <X11/Xlib.h>
2002-05-29 06:21:59 +00:00
#include <iostream>
#include <algorithm>
using namespace std;
namespace FbTk {
template<>
void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) {
if (strcasecmp(strval, "TopLeft")==0)
m_value = Slit::TOPLEFT;
2004-06-07 11:46:05 +00:00
else if (strcasecmp(strval, "LeftCenter")==0
|| strcasecmp(strval, "CenterLeft")==0)
m_value = Slit::LEFTCENTER;
else if (strcasecmp(strval, "BottomLeft")==0)
m_value = Slit::BOTTOMLEFT;
else if (strcasecmp(strval, "TopCenter")==0)
m_value = Slit::TOPCENTER;
else if (strcasecmp(strval, "BottomCenter")==0)
m_value = Slit::BOTTOMCENTER;
else if (strcasecmp(strval, "TopRight")==0)
m_value = Slit::TOPRIGHT;
2004-06-07 11:46:05 +00:00
else if (strcasecmp(strval, "RightCenter")==0
|| strcasecmp(strval, "CenterRight")==0)
m_value = Slit::RIGHTCENTER;
else if (strcasecmp(strval, "BottomRight")==0)
m_value = Slit::BOTTOMRIGHT;
else
setDefaultValue();
}
template<>
void FbTk::Resource<Slit::Direction>::setFromString(const char *strval) {
if (strcasecmp(strval, "Vertical") == 0)
m_value = Slit::VERTICAL;
else if (strcasecmp(strval, "Horizontal") == 0)
m_value = Slit::HORIZONTAL;
else
setDefaultValue();
}
2004-02-10 18:45:26 +00:00
template<>
2005-11-22 21:09:14 +00:00
string FbTk::Resource<Slit::Placement>::getString() const {
switch (m_value) {
case Slit::TOPLEFT:
return string("TopLeft");
break;
2004-06-07 11:46:05 +00:00
case Slit::LEFTCENTER:
return string("LeftCenter");
break;
case Slit::BOTTOMLEFT:
return string("BottomLeft");
break;
case Slit::TOPCENTER:
return string("TopCenter");
break;
case Slit::BOTTOMCENTER:
return string("BottomCenter");
break;
case Slit::TOPRIGHT:
return string("TopRight");
break;
2004-06-07 11:46:05 +00:00
case Slit::RIGHTCENTER:
return string("RightCenter");
break;
case Slit::BOTTOMRIGHT:
return string("BottomRight");
break;
}
//default string
return string("BottomRight");
}
template<>
2005-11-22 21:09:14 +00:00
string FbTk::Resource<Slit::Direction>::getString() const {
switch (m_value) {
case Slit::VERTICAL:
return string("Vertical");
break;
case Slit::HORIZONTAL:
return string("Horizontal");
break;
}
// default string
return string("Vertical");
}
} // end namespace FbTk
namespace {
class SlitClientMenuItem: public FbTk::MenuItem{
public:
explicit SlitClientMenuItem(Slit& slit, SlitClient &client, FbTk::RefCount<FbTk::Command> &cmd):
FbTk::MenuItem(client.matchName().c_str(), cmd), m_slit(slit), m_client(client) {
setCommand(cmd);
FbTk::MenuItem::setSelected(client.visible());
setToggleItem(true);
}
const std::string &label() const {
return m_client.matchName();
}
bool isSelected() const {
return m_client.visible();
}
void click(int button, int time) {
if (button == 4 || button == 2) { // wheel up
m_slit.clientUp(&m_client);
} else if (button == 5 || button == 3) { // wheel down
m_slit.clientDown(&m_client);
} else {
m_client.setVisible(!m_client.visible());
FbTk::MenuItem::setSelected(m_client.visible());
FbTk::MenuItem::click(button, time);
}
}
private:
Slit& m_slit;
SlitClient &m_client;
};
class SlitDirMenuItem: public FbTk::MenuItem {
public:
SlitDirMenuItem(const char *label, Slit &slit, FbTk::RefCount<FbTk::Command> &cmd)
:FbTk::MenuItem(label,cmd),
m_slit(slit),
m_label(label ? label : "") {
setLabel(m_label.c_str()); // update label
}
2003-06-22 12:31:37 +00:00
void click(int button, int time) {
// toggle direction
if (m_slit.direction() == Slit::HORIZONTAL)
m_slit.setDirection(Slit::VERTICAL);
else
m_slit.setDirection(Slit::HORIZONTAL);
setLabel(m_label.c_str());
FbTk::MenuItem::click(button, time);
}
void setLabel(const char *label) {
2004-06-07 11:46:05 +00:00
_FB_USES_NLS;
m_label = (label ? label : "");
std::string reallabel = m_label + " " +
( m_slit.direction() == Slit::HORIZONTAL ?
2004-06-07 11:46:05 +00:00
_FBTEXT(Align, Horizontal, "Horizontal", "Horizontal"):
_FBTEXT(Align, Vertical, "Vertical", "Vertical"));
FbTk::MenuItem::setLabel(reallabel.c_str());
}
private:
Slit &m_slit;
std::string m_label;
};
class PlaceSlitMenuItem: public FbTk::MenuItem {
public:
PlaceSlitMenuItem(const char *label, Slit &slit, Slit::Placement place, FbTk::RefCount<FbTk::Command> &cmd):
FbTk::MenuItem(label, cmd), m_slit(slit), m_place(place) {
}
bool isEnabled() const { return m_slit.placement() != m_place; }
void click(int button, int time) {
m_slit.setPlacement(m_place);
FbTk::MenuItem::click(button, time);
}
private:
Slit &m_slit;
Slit::Placement m_place;
};
2002-05-29 06:21:59 +00:00
}; // End anonymous namespace
2001-12-11 20:47:02 +00:00
2003-06-05 11:30:06 +00:00
unsigned int Slit::s_eventmask = SubstructureRedirectMask | ButtonPressMask |
EnterWindowMask | LeaveWindowMask | ExposureMask;
Slit::Slit(BScreen &scr, FbTk::XLayer &layer, const char *filename)
2003-06-22 12:31:37 +00:00
: m_hidden(false),
2003-08-11 16:05:18 +00:00
m_screen(scr),
2003-12-18 18:03:23 +00:00
m_slitmenu(scr.menuTheme(),
2003-05-15 23:30:07 +00:00
scr.imageControl(),
*scr.layerManager().getLayer(Layer::MENU)),
2003-12-18 18:03:23 +00:00
m_placement_menu(scr.menuTheme(),
2003-05-15 23:30:07 +00:00
scr.imageControl(),
*scr.layerManager().getLayer(Layer::MENU)),
2003-12-18 18:03:23 +00:00
m_clientlist_menu(scr.menuTheme(),
2003-05-15 23:30:07 +00:00
scr.imageControl(),
*scr.layerManager().getLayer(Layer::MENU)),
2004-09-11 18:58:27 +00:00
frame(scr.rootWindow()),
2004-06-07 21:36:06 +00:00
//For KDE dock applets
2003-05-11 17:42:51 +00:00
m_kwm1_dockwindow(XInternAtom(FbTk::App::instance()->display(),
"KWM_DOCKWINDOW", False)), //KDE v1.x
m_kwm2_dockwindow(XInternAtom(FbTk::App::instance()->display(),
"_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False)), //KDE v2.x
2003-04-25 10:46:07 +00:00
m_layeritem(0),
2003-08-29 10:30:46 +00:00
m_slit_theme(new SlitTheme(scr.rootWindow().screenNumber())),
m_strut(0),
2003-06-22 12:31:37 +00:00
// resources
// lock in first resource
m_rc_auto_hide(scr.resourceManager().lock(), false,
scr.name() + ".slit.autoHide", scr.altName() + ".Slit.AutoHide"),
// TODO: this resource name must change
m_rc_maximize_over(scr.resourceManager(), false,
2003-06-22 12:31:37 +00:00
scr.name() + ".slit.maxOver", scr.altName() + ".Slit.MaxOver"),
m_rc_placement(scr.resourceManager(), BOTTOMRIGHT,
scr.name() + ".slit.placement", scr.altName() + ".Slit.Placement"),
m_rc_direction(scr.resourceManager(), VERTICAL,
scr.name() + ".slit.direction", scr.altName() + ".Slit.Direction"),
m_rc_alpha(scr.resourceManager(), 255,
scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"),
m_rc_on_head(scr.resourceManager(), 0,
scr.name() + ".slit.onhead", scr.altName() + ".Slit.onHead"),
m_rc_layernum(scr.resourceManager(), Layer(Layer::DOCK),
scr.name() + ".slit.layer", scr.altName() + ".Slit.Layer") {
2004-06-07 11:46:05 +00:00
_FB_USES_NLS;
2003-08-29 10:30:46 +00:00
// attach to theme and root window change signal
m_slit_theme->reconfigSig().attach(this);
scr.resizeSig().attach(this);
2003-08-30 01:02:09 +00:00
scr.reconfigureSig().attach(this); // if alpha changed (we disablethis signal when we get theme change sig)
2001-12-11 20:47:02 +00:00
frame.pixmap = None;
// move the frame out of sight for a moment
frame.window.move(-frame.window.width(), -frame.window.height());
2003-08-11 16:05:18 +00:00
// setup timer
2003-05-11 17:42:51 +00:00
m_timer.setTimeout(200); // default timeout
m_timer.fireOnce(true);
2003-08-11 16:05:18 +00:00
FbTk::RefCount<FbTk::Command> toggle_hidden(new FbTk::SimpleCommand<Slit>(*this, &Slit::toggleHidden));
m_timer.setCommand(toggle_hidden);
2002-12-01 13:42:15 +00:00
FbTk::EventManager::instance()->add(*this, frame.window);
2004-05-17 15:20:32 +00:00
if (FbTk::Transparent::haveComposite()) {
frame.window.setOpaque(*m_rc_alpha);
} else {
frame.window.setAlpha(*m_rc_alpha);
}
m_layeritem.reset(new FbTk::XLayerItem(frame.window, layer));
m_layermenu.reset(new LayerMenu(scr.menuTheme(),
scr.imageControl(),
*scr.layerManager().
getLayer(Layer::MENU),
this,
true));
m_layermenu->setLabel(_FBTEXT(Slit, Layer, "Slit Layer", "Title of Slit Layer Menu"));
moveToLayer((*m_rc_layernum).getNum());
2002-12-01 13:42:15 +00:00
// Get client list for sorting purposes
loadClientList(filename);
setupMenu();
2002-12-01 13:42:15 +00:00
scr.resourceManager().unlock();
2001-12-11 20:47:02 +00:00
}
2003-06-05 11:30:06 +00:00
2001-12-11 20:47:02 +00:00
Slit::~Slit() {
2003-06-18 13:55:17 +00:00
clearStrut();
if (frame.pixmap != 0)
2003-05-15 23:30:07 +00:00
screen().imageControl().removeImage(frame.pixmap);
2003-06-22 12:31:37 +00:00
shutdown();
2001-12-11 20:47:02 +00:00
}
2003-06-18 13:55:17 +00:00
void Slit::clearStrut() {
if (m_strut != 0) {
screen().clearStrut(m_strut);
m_strut = 0;
}
}
void Slit::updateStrut() {
bool had_strut = m_strut ? true : false;
2003-06-18 13:55:17 +00:00
clearStrut();
// no need for area if we're autohiding or set maximize over
if (doAutoHide() || *m_rc_maximize_over) {
// update screen area if we had a strut before
if (had_strut)
screen().updateAvailableWorkspaceArea();
2003-06-18 13:55:17 +00:00
return;
}
unsigned int bw = m_slit_theme->borderWidth();
2003-06-18 13:55:17 +00:00
int left = 0, right = 0, top = 0, bottom = 0;
switch (placement()) {
case TOPLEFT:
if (direction() == HORIZONTAL)
top = height() + 2 * bw;
else
left = width() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
case TOPCENTER:
if (direction() == HORIZONTAL)
top = height() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
case TOPRIGHT:
if (direction() == HORIZONTAL)
top = height() + 2 * bw;
else
right = width() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
case BOTTOMLEFT:
if (direction() == HORIZONTAL)
bottom = height() + 2 * bw;
else
left = width() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
case BOTTOMCENTER:
// would be strange to have it request size on vertical direction
// each time we add a client
if (direction() == HORIZONTAL)
bottom = height() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
case BOTTOMRIGHT:
if (direction() == HORIZONTAL)
bottom = height() + 2 * bw;
2003-06-18 13:55:17 +00:00
else
right = width() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
2004-06-07 11:46:05 +00:00
case LEFTCENTER:
2003-06-18 13:55:17 +00:00
if (direction() == VERTICAL)
left = width() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
2004-06-07 11:46:05 +00:00
case RIGHTCENTER:
2003-06-18 13:55:17 +00:00
if (direction() == VERTICAL)
right = width() + 2 * bw;
2003-06-18 13:55:17 +00:00
break;
}
m_strut = screen().requestStrut(getOnHead(), left, right, top, bottom);
2003-06-18 13:55:17 +00:00
screen().updateAvailableWorkspaceArea();
}
2001-12-11 20:47:02 +00:00
void Slit::addClient(Window w) {
#ifdef DEBUG
cerr<<__FILE__": addClient(w = 0x"<<hex<<w<<dec<<")"<<endl;
#endif // DEBUG
2003-05-11 17:42:51 +00:00
// Can't add non existent window
2002-12-01 13:42:15 +00:00
if (w == None)
return;
// Look for slot in client list by name
SlitClient *client = 0;
std::string match_name;
2004-01-30 11:06:25 +00:00
match_name = Xutil::getWMClassName(w);
2003-05-11 17:42:51 +00:00
SlitClients::iterator it = m_client_list.begin();
SlitClients::iterator it_end = m_client_list.end();
2002-12-01 13:42:15 +00:00
bool found_match = false;
for (; it != it_end; ++it) {
// If the name matches...
if ((*it)->matchName() == match_name) {
2002-12-01 13:42:15 +00:00
// Use the slot if no window is assigned
if ((*it)->window() == None) {
2002-12-01 13:42:15 +00:00
client = (*it);
client->initialize(&screen(), w);
2002-12-01 13:42:15 +00:00
break;
}
// Otherwise keep looking for an unused match or a non-match
found_match = true; // Possibly redundant
2002-11-14 00:23:19 +00:00
2002-12-01 13:42:15 +00:00
} else if (found_match) {
// Insert before first non-match after a previously found match?
client = new SlitClient(&screen(), w);
2003-05-11 17:42:51 +00:00
m_client_list.insert(it, client);
2002-12-01 13:42:15 +00:00
break;
}
}
// Append to client list?
if (client == 0) {
client = new SlitClient(&screen(), w);
2003-05-11 17:42:51 +00:00
m_client_list.push_back(client);
2002-12-01 13:42:15 +00:00
}
Display *disp = FbTk::App::instance()->display();
2002-12-01 13:42:15 +00:00
XWMHints *wmhints = XGetWMHints(disp, w);
if (wmhints != 0) {
2002-12-01 13:42:15 +00:00
if ((wmhints->flags & IconWindowHint) &&
(wmhints->icon_window != None)) {
XMoveWindow(disp, client->clientWindow(), screen().width() + 10,
screen().height() + 10);
XMapWindow(disp, client->clientWindow());
client->setIconWindow(wmhints->icon_window);
client->setWindow(client->iconWindow());
2002-12-01 13:42:15 +00:00
} else {
client->setIconWindow(None);
client->setWindow(client->clientWindow());
2002-12-01 13:42:15 +00:00
}
2003-06-27 15:05:19 +00:00
XFree((void *) wmhints);
2002-12-01 13:42:15 +00:00
} else {
client->setIconWindow(None);
client->setWindow(client->clientWindow());
2002-12-01 13:42:15 +00:00
}
2003-06-27 15:05:19 +00:00
Atom *proto = 0;
int num_return = 0;
FbAtoms *fbatoms = FbAtoms::instance();
if (XGetWMProtocols(disp, w, &proto, &num_return)) {
for (int i = 0; i < num_return; ++i) {
if (proto[i] == fbatoms->getFluxboxStructureMessagesAtom())
screen().addNetizen(w);
}
XFree((void *) proto);
2004-08-30 11:34:56 +00:00
#ifdef DEBUG
2003-06-27 15:05:19 +00:00
} else {
cerr<<"Warning: Failed to read WM Protocols. "<<endl;
2004-08-30 11:34:56 +00:00
#endif // DEBUG
2003-06-27 15:05:19 +00:00
}
2002-12-01 13:42:15 +00:00
XWindowAttributes attrib;
2002-11-14 00:23:19 +00:00
#ifdef KDE
2004-04-19 22:42:26 +00:00
if (screen().isKdeDockapp(w))
client->resize(24, 24);
2002-12-01 13:42:15 +00:00
else
2002-11-14 00:23:19 +00:00
#endif // KDE
{
if (XGetWindowAttributes(disp, client->window(), &attrib)) {
client->resize(attrib.width, attrib.height);
} else { // set default size if we failed to get window attributes
client->resize(64, 64);
2002-12-01 13:42:15 +00:00
}
}
2001-12-11 20:47:02 +00:00
// disable border for client window
XSetWindowBorderWidth(disp, client->window(), 0);
2001-12-11 20:47:02 +00:00
// disable events to frame.window
frame.window.setEventMask(NoEventMask);
client->disableEvents();
2003-06-05 11:30:06 +00:00
2001-12-11 20:47:02 +00:00
XReparentWindow(disp, client->window(), frame.window.window(), 0, 0);
XMapRaised(disp, client->window());
XChangeSaveSet(disp, client->window(), SetModeInsert);
// reactivate events for frame.window
2003-05-17 11:00:50 +00:00
frame.window.setEventMask(s_eventmask);
// setup event for slit client window
client->enableEvents();
2003-06-05 11:30:06 +00:00
// flush events
2004-04-19 22:42:26 +00:00
// XFlush(disp);
// add slit client to eventmanager
FbTk::EventManager::instance()->add(*this, client->clientWindow());
FbTk::EventManager::instance()->add(*this, client->iconWindow());
2001-12-11 20:47:02 +00:00
2004-04-19 22:42:26 +00:00
// frame.window.show();
2003-05-13 21:12:18 +00:00
clearWindow();
2002-12-01 13:42:15 +00:00
reconfigure();
2002-05-29 06:21:59 +00:00
updateClientmenu();
2002-12-01 13:42:15 +00:00
saveClientList();
2001-12-11 20:47:02 +00:00
}
void Slit::setDirection(Direction dir) {
*m_rc_direction = dir;
reconfigure();
}
void Slit::setPlacement(Placement place) {
*m_rc_placement = place;
reconfigure();
}
2001-12-11 20:47:02 +00:00
2002-05-29 06:21:59 +00:00
void Slit::removeClient(SlitClient *client, bool remap, bool destroy) {
2003-06-22 12:31:37 +00:00
if (client == 0)
return;
// remove from event manager
if (client->clientWindow() != 0)
FbTk::EventManager::instance()->remove(client->clientWindow());
if (client->iconWindow() != 0)
FbTk::EventManager::instance()->remove(client->iconWindow());
2002-12-01 13:42:15 +00:00
// Destructive removal?
if (destroy)
2003-05-11 17:42:51 +00:00
m_client_list.remove(client);
2002-12-01 13:42:15 +00:00
else // Clear the window info, but keep around to help future sorting?
client->initialize();
screen().removeNetizen(client->window());
2002-12-01 13:42:15 +00:00
if (remap && client->window() != 0) {
Display *disp = FbTk::App::instance()->display();
if (!client->visible())
client->show();
client->disableEvents();
// stop events to frame.window temporarly
frame.window.setEventMask(NoEventMask);
XReparentWindow(disp, client->window(), screen().rootWindow().window(),
client->x(), client->y());
XChangeSaveSet(disp, client->window(), SetModeDelete);
// reactivate events to frame.window
2003-05-17 11:00:50 +00:00
frame.window.setEventMask(s_eventmask);
2002-12-01 13:42:15 +00:00
XFlush(disp);
}
// Destructive removal?
if (destroy)
delete client;
2003-02-17 12:53:21 +00:00
updateClientmenu();
2001-12-11 20:47:02 +00:00
}
2002-02-04 22:33:09 +00:00
void Slit::removeClient(Window w, bool remap) {
2003-08-04 12:57:23 +00:00
2003-06-05 11:30:06 +00:00
if (w == frame.window)
return;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
bool reconf = false;
2001-12-11 20:47:02 +00:00
2003-05-11 17:42:51 +00:00
SlitClients::iterator it = m_client_list.begin();
SlitClients::iterator it_end = m_client_list.end();
2002-12-01 13:42:15 +00:00
for (; it != it_end; ++it) {
if ((*it)->window() == w) {
2002-12-01 13:42:15 +00:00
removeClient((*it), remap, false);
reconf = true;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
break;
}
}
if (reconf)
reconfigure();
2001-12-11 20:47:02 +00:00
}
2002-11-14 00:23:19 +00:00
void Slit::reconfigure() {
2002-12-01 13:42:15 +00:00
frame.width = 0;
frame.height = 0;
// Need to count windows because not all client list entries
// actually correspond to mapped windows.
int num_windows = 0;
const int bevel_width = theme().bevelWidth();
// determine width or height increase
bool height_inc = false;
switch (direction()) {
case VERTICAL:
height_inc = true;
break;
case HORIZONTAL: // already false
break;
}
2002-12-01 13:42:15 +00:00
SlitClients::iterator client_it = m_client_list.begin();
SlitClients::iterator client_it_end = m_client_list.end();
for (; client_it != client_it_end; ++client_it) {
// client created window?
if ((*client_it)->window() != None && (*client_it)->visible()) {
num_windows++;
if (height_inc) {
// increase height of slit for each client (VERTICAL mode)
frame.height += (*client_it)->height() + bevel_width;
// the slit should always have the width of the largest client
if (frame.width < (*client_it)->width())
frame.width = (*client_it)->width();
} else {
// increase width of slit for each client (HORIZONTAL mode)
frame.width += (*client_it)->width() + bevel_width;
// the slit should always have the width of the largest client
if (frame.height < (*client_it)->height())
frame.height = (*client_it)->height();
2002-12-01 13:42:15 +00:00
}
}
2003-05-04 20:50:15 +00:00
}
2002-12-01 13:42:15 +00:00
2003-06-05 11:30:06 +00:00
if (frame.width < 1)
frame.width = 1;
else
frame.width += bevel_width;
2002-12-01 13:42:15 +00:00
2003-06-05 11:30:06 +00:00
if (frame.height < 1)
frame.height = 1;
else
frame.height += bevel_width*2;
2002-12-01 13:42:15 +00:00
Display *disp = FbTk::App::instance()->display();
2002-12-01 13:42:15 +00:00
frame.window.setBorderWidth(theme().borderWidth());
frame.window.setBorderColor(theme().borderColor());
2002-12-01 13:42:15 +00:00
Pixmap tmp = frame.pixmap;
2003-05-15 23:30:07 +00:00
FbTk::ImageControl &image_ctrl = screen().imageControl();
2003-04-25 10:46:07 +00:00
const FbTk::Texture &texture = m_slit_theme->texture();
2003-12-07 16:39:43 +00:00
if (!texture.usePixmap()) {
frame.pixmap = 0;
frame.window.setBackgroundColor(texture.color());
2002-12-01 13:42:15 +00:00
} else {
2003-05-15 23:30:07 +00:00
frame.pixmap = image_ctrl.renderImage(frame.width, frame.height,
texture);
2003-05-13 13:28:28 +00:00
if (frame.pixmap == 0)
frame.window.setBackgroundColor(texture.color());
else
frame.window.setBackgroundPixmap(frame.pixmap);
2002-12-01 13:42:15 +00:00
}
if (tmp)
2003-05-15 23:30:07 +00:00
image_ctrl.removeImage(tmp);
if (FbTk::Transparent::haveComposite()) {
frame.window.setOpaque(*m_rc_alpha);
} else {
frame.window.setAlpha(*m_rc_alpha);
}
// reposition clears the bg
reposition();
// did we actually use slit slots
if (num_windows == 0)
frame.window.hide();
else
frame.window.show();
2002-12-01 13:42:15 +00:00
int x = 0, y = 0;
height_inc = false;
switch (direction()) {
2002-12-01 13:42:15 +00:00
case VERTICAL:
x = 0;
2003-04-25 10:46:07 +00:00
y = bevel_width;
height_inc = true;
2002-12-01 13:42:15 +00:00
break;
case HORIZONTAL:
2003-04-25 10:46:07 +00:00
x = bevel_width;
2002-12-01 13:42:15 +00:00
y = 0;
break;
}
2002-12-01 13:42:15 +00:00
client_it = m_client_list.begin();
for (; client_it != client_it_end; ++client_it) {
if ((*client_it)->window() == None)
continue;
//client created window?
if ((*client_it)->visible())
(*client_it)->show();
else {
(*client_it)->disableEvents();
(*client_it)->hide();
(*client_it)->enableEvents();
continue;
}
2003-06-22 12:31:37 +00:00
if (height_inc)
x = (frame.width - (*client_it)->width()) / 2;
else
y = (frame.height - (*client_it)->height()) / 2;
XMoveResizeWindow(disp, (*client_it)->window(), x, y,
(*client_it)->width(), (*client_it)->height());
2002-12-01 13:42:15 +00:00
// for ICCCM compliance
(*client_it)->move(x, y);
2002-12-01 13:42:15 +00:00
XEvent event;
event.type = ConfigureNotify;
2002-12-01 13:42:15 +00:00
event.xconfigure.display = disp;
event.xconfigure.event = (*client_it)->window();
event.xconfigure.window = (*client_it)->window();
event.xconfigure.x = (*client_it)->x();
event.xconfigure.y = (*client_it)->y();
event.xconfigure.width = (*client_it)->width();
event.xconfigure.height = (*client_it)->height();
event.xconfigure.border_width = 0;
event.xconfigure.above = frame.window.window();
event.xconfigure.override_redirect = False;
2002-12-01 13:42:15 +00:00
XSendEvent(disp, (*client_it)->window(), False, StructureNotifyMask,
&event);
2002-12-01 13:42:15 +00:00
if (height_inc)
y += (*client_it)->height() + bevel_width;
else
x += (*client_it)->width() + bevel_width;
} // end for
2002-12-01 13:42:15 +00:00
2003-05-11 17:42:51 +00:00
if (doAutoHide() && !isHidden() && !m_timer.isTiming())
m_timer.start();
2003-12-20 19:10:49 +00:00
else if (!doAutoHide() && isHidden())
toggleHidden(); // restore visible
2003-05-01 15:03:36 +00:00
2003-05-11 17:42:51 +00:00
m_slitmenu.reconfigure();
updateClientmenu();
2003-06-18 13:55:17 +00:00
updateStrut();
2003-06-22 12:31:37 +00:00
2001-12-11 20:47:02 +00:00
}
2002-08-14 21:51:07 +00:00
void Slit::reposition() {
2002-12-01 13:42:15 +00:00
int head_x = 0,
head_y = 0,
head_w,
head_h;
if (screen().hasXinerama()) {
int head = *m_rc_on_head;
head_x = screen().getHeadX(head);
head_y = screen().getHeadY(head);
head_w = screen().getHeadWidth(head);
head_h = screen().getHeadHeight(head);
2003-05-19 15:32:47 +00:00
} else {
head_w = screen().width();
head_h = screen().height();
}
int border_width = theme().borderWidth();
int bevel_width = theme().bevelWidth();
// make sure at leaste one pixel is visible
if (border_width >= bevel_width)
bevel_width = border_width + 1;
2002-12-01 13:42:15 +00:00
// place the slit in the appropriate place
switch (placement()) {
2002-12-01 13:42:15 +00:00
case TOPLEFT:
frame.x = head_x;
frame.y = head_y;
if (direction() == VERTICAL) {
2003-04-25 10:46:07 +00:00
frame.x_hidden = bevel_width -
border_width - frame.width;
2002-12-01 13:42:15 +00:00
frame.y_hidden = head_y;
} else {
frame.x_hidden = head_x;
2003-04-25 10:46:07 +00:00
frame.y_hidden = bevel_width -
border_width - frame.height;
2002-12-01 13:42:15 +00:00
}
break;
2004-06-07 11:46:05 +00:00
case LEFTCENTER:
2002-12-01 13:42:15 +00:00
frame.x = head_x;
frame.y = head_y + (head_h - frame.height) / 2;
2003-04-25 10:46:07 +00:00
frame.x_hidden = head_x + bevel_width -
border_width - frame.width;
2002-12-01 13:42:15 +00:00
frame.y_hidden = frame.y;
break;
case BOTTOMLEFT:
frame.x = head_x;
2003-04-25 10:46:07 +00:00
frame.y = head_h - frame.height - border_width*2;
if (direction() == VERTICAL) {
2003-04-25 10:46:07 +00:00
frame.x_hidden = head_x + bevel_width -
border_width - frame.width;
2002-12-01 13:42:15 +00:00
frame.y_hidden = frame.y;
} else {
frame.x_hidden = head_x;
frame.y_hidden = head_y + head_h -
2003-04-25 10:46:07 +00:00
bevel_width - border_width;
2002-12-01 13:42:15 +00:00
}
break;
case TOPCENTER:
frame.x = head_x + ((head_w - frame.width) / 2);
frame.y = head_y;
frame.x_hidden = frame.x;
2003-04-25 10:46:07 +00:00
frame.y_hidden = head_y + bevel_width -
border_width - frame.height;
2002-12-01 13:42:15 +00:00
break;
case BOTTOMCENTER:
frame.x = head_x + ((head_w - frame.width) / 2);
2003-04-25 10:46:07 +00:00
frame.y = head_y + head_h - frame.height - border_width*2;
2002-12-01 13:42:15 +00:00
frame.x_hidden = frame.x;
frame.y_hidden = head_y + head_h -
2003-04-25 10:46:07 +00:00
bevel_width - border_width;
2002-12-01 13:42:15 +00:00
break;
case TOPRIGHT:
2003-04-25 10:46:07 +00:00
frame.x = head_x + head_w - frame.width - border_width*2;
2002-12-01 13:42:15 +00:00
frame.y = head_y;
if (direction() == VERTICAL) {
2002-12-01 13:42:15 +00:00
frame.x_hidden = head_x + head_w -
2003-04-25 10:46:07 +00:00
bevel_width - border_width;
2002-12-01 13:42:15 +00:00
frame.y_hidden = head_y;
} else {
frame.x_hidden = frame.x;
2003-04-25 10:46:07 +00:00
frame.y_hidden = head_y + bevel_width -
border_width - frame.height;
2002-12-01 13:42:15 +00:00
}
break;
2004-06-07 11:46:05 +00:00
case RIGHTCENTER:
2002-12-01 13:42:15 +00:00
default:
2003-04-25 10:46:07 +00:00
frame.x = head_x + head_w - frame.width - border_width*2;
2002-12-01 13:42:15 +00:00
frame.y = head_y + ((head_h - frame.height) / 2);
frame.x_hidden = head_x + head_w -
2003-04-25 10:46:07 +00:00
bevel_width - border_width;
2002-12-01 13:42:15 +00:00
frame.y_hidden = frame.y;
break;
case BOTTOMRIGHT:
2003-04-25 10:46:07 +00:00
frame.x = head_x + head_w - frame.width - border_width*2;
frame.y = head_y + head_h - frame.height - border_width*2;
if (direction() == VERTICAL) {
2002-12-01 13:42:15 +00:00
frame.x_hidden = head_x + head_w -
2003-04-25 10:46:07 +00:00
bevel_width - border_width;
2002-12-01 13:42:15 +00:00
frame.y_hidden = frame.y;
} else {
frame.x_hidden = frame.x;
frame.y_hidden = head_y + head_h -
2003-04-25 10:46:07 +00:00
bevel_width - border_width;
2002-12-01 13:42:15 +00:00
}
break;
}
2003-05-11 17:42:51 +00:00
if (isHidden()) {
2003-05-13 13:28:28 +00:00
frame.window.moveResize(frame.x_hidden, frame.y_hidden,
frame.width, frame.height);
2002-12-01 13:42:15 +00:00
} else {
2003-05-13 13:28:28 +00:00
frame.window.moveResize(frame.x, frame.y,
frame.width, frame.height);
2002-12-01 13:42:15 +00:00
}
2006-04-21 16:23:24 +00:00
frame.window.updateBackground(true);
if (*m_rc_alpha != 255)
clearWindow();
2001-12-11 20:47:02 +00:00
}
2002-08-14 21:51:07 +00:00
void Slit::shutdown() {
2002-12-01 13:42:15 +00:00
saveClientList();
2003-05-11 17:42:51 +00:00
while (!m_client_list.empty())
removeClient(m_client_list.front(), true, true);
2001-12-11 20:47:02 +00:00
}
void Slit::clientUp(SlitClient* client) {
if (!client || m_client_list.size() < 2)
return;
if (client == m_client_list.front()) {
cycleClientsUp();
return;
}
SlitClients::iterator it = m_client_list.begin();
for(it++; it != m_client_list.end(); it++) {
if ((*it) == client) {
SlitClients::iterator prev = it;
prev--;
iter_swap(it, prev);
reconfigure();
break;
}
}
}
void Slit::clientDown(SlitClient* client) {
if (!client || m_client_list.size() < 2)
return;
if (client == m_client_list.back()) {
cycleClientsDown();
return;
}
SlitClients::reverse_iterator it = m_client_list.rbegin();
for(it++; it != m_client_list.rend(); it++) {
if ((*it) == client) {
SlitClients::reverse_iterator next = it;
next--;
iter_swap(it, next);
reconfigure();
break;
}
}
}
void Slit::cycleClientsUp() {
2003-05-11 17:42:51 +00:00
if (m_client_list.size() < 2)
2003-01-12 23:52:37 +00:00
return;
// rotate client list up, ie the first goes last
2003-05-11 17:42:51 +00:00
SlitClients::iterator it = m_client_list.begin();
SlitClient *client = *it;
2003-05-11 17:42:51 +00:00
m_client_list.erase(it);
m_client_list.push_back(client);
reconfigure();
}
void Slit::cycleClientsDown() {
2003-05-11 17:42:51 +00:00
if (m_client_list.size() < 2)
2003-01-12 23:52:37 +00:00
return;
// rotate client list down, ie the last goes first
2003-05-11 17:42:51 +00:00
SlitClient *client = m_client_list.back();
m_client_list.remove(client);
m_client_list.push_front(client);
reconfigure();
}
void Slit::handleEvent(XEvent &event) {
if (event.type == ConfigureRequest) {
configureRequestEvent(event.xconfigurerequest);
} else if (event.type == DestroyNotify) {
removeClient(event.xdestroywindow.window, false);
} else if (event.type == UnmapNotify && event.xany.send_event) {
// we ignore server-generated events, which can occur
// on restart. The ICCCM says that a client must send
// a synthetic event for the withdrawn state
2003-08-15 13:50:42 +00:00
removeClient(event.xunmap.window);
}
}
void Slit::buttonPressEvent(XButtonEvent &e) {
if (e.window != frame.window.window())
2002-12-01 13:42:15 +00:00
return;
if (e.button == Button3) {
2003-05-11 17:42:51 +00:00
if (! m_slitmenu.isVisible()) {
int x = e.x_root - (m_slitmenu.width() / 2),
y = e.y_root - (m_slitmenu.height() / 2);
2002-12-01 13:42:15 +00:00
if (x < 0)
x = 0;
2003-05-15 12:00:46 +00:00
else if (x + m_slitmenu.width() > screen().width())
x = screen().width() - m_slitmenu.width();
2002-12-01 13:42:15 +00:00
if (y < 0)
y = 0;
2003-05-15 12:00:46 +00:00
else if (y + m_slitmenu.height() > screen().height())
y = screen().height() - m_slitmenu.height();
2002-12-01 13:42:15 +00:00
2003-05-11 17:42:51 +00:00
m_slitmenu.move(x, y);
m_slitmenu.show();
2002-12-01 13:42:15 +00:00
} else
2003-05-11 17:42:51 +00:00
m_slitmenu.hide();
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void Slit::enterNotifyEvent(XCrossingEvent &) {
2003-05-11 17:42:51 +00:00
if (! doAutoHide())
2002-12-01 13:42:15 +00:00
return;
2003-05-11 17:42:51 +00:00
if (isHidden()) {
if (! m_timer.isTiming())
m_timer.start();
2002-12-01 13:42:15 +00:00
} else {
2003-05-11 17:42:51 +00:00
if (m_timer.isTiming())
m_timer.stop();
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void Slit::leaveNotifyEvent(XCrossingEvent &ev) {
2003-05-11 17:42:51 +00:00
if (! doAutoHide())
2002-12-01 13:42:15 +00:00
return;
2003-05-11 17:42:51 +00:00
if (isHidden()) {
if (m_timer.isTiming())
m_timer.stop();
2003-05-01 15:03:36 +00:00
} else {
2003-05-11 17:42:51 +00:00
if (! m_timer.isTiming()) {
2003-05-01 15:35:24 +00:00
// the menu is open, keep it firing until it closes
2003-05-11 17:42:51 +00:00
if (m_slitmenu.isVisible())
m_timer.fireOnce(false);
m_timer.start();
2003-05-01 15:35:24 +00:00
}
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
2001-12-11 20:47:02 +00:00
2002-11-14 00:23:19 +00:00
void Slit::configureRequestEvent(XConfigureRequestEvent &event) {
2002-12-01 13:42:15 +00:00
bool reconf = false;
XWindowChanges xwc;
2002-11-14 00:23:19 +00:00
xwc.x = event.x;
xwc.y = event.y;
xwc.width = event.width;
xwc.height = event.height;
2002-12-01 13:42:15 +00:00
xwc.border_width = 0;
xwc.sibling = event.above;
xwc.stack_mode = event.detail;
2002-11-14 00:23:19 +00:00
XConfigureWindow(FbTk::App::instance()->display(),
event.window, event.value_mask, &xwc);
2002-11-14 00:23:19 +00:00
2003-05-11 17:42:51 +00:00
SlitClients::iterator it = m_client_list.begin();
SlitClients::iterator it_end = m_client_list.end();
2002-12-01 13:42:15 +00:00
for (; it != it_end; ++it) {
if ((*it)->window() == event.window) {
if ((*it)->width() != ((unsigned) event.width) ||
(*it)->height() != ((unsigned) event.height)) {
(*it)->resize(event.width, event.height);;
2002-11-14 00:23:19 +00:00
2002-12-01 13:42:15 +00:00
reconf = true; //requires reconfiguration
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
break;
}
}
}
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
if (reconf)
reconfigure();
2001-12-11 20:47:02 +00:00
}
2003-05-13 13:28:28 +00:00
void Slit::exposeEvent(XExposeEvent &ev) {
2003-06-24 13:48:34 +00:00
// we don't need to clear the entire window
// just the are that gets exposed
frame.window.clearArea(ev.x, ev.y, ev.width, ev.height);
2003-05-13 21:12:18 +00:00
}
2003-08-29 10:30:46 +00:00
void Slit::update(FbTk::Subject *subj) {
reconfigure();
}
2003-05-13 21:12:18 +00:00
void Slit::clearWindow() {
2003-05-07 22:53:21 +00:00
frame.window.clear();
}
2001-12-11 20:47:02 +00:00
2003-08-11 16:05:18 +00:00
void Slit::toggleHidden() {
2003-05-11 17:42:51 +00:00
if (doAutoHide()) {
if (!m_slitmenu.isVisible()) {
m_timer.fireOnce(true);
2003-05-01 15:35:24 +00:00
} else
return;
2003-05-01 15:03:36 +00:00
} else
2003-05-11 17:42:51 +00:00
if (!isHidden()) return;
2003-05-01 15:35:24 +00:00
2003-05-11 17:42:51 +00:00
m_hidden = ! m_hidden; // toggle hidden state
if (isHidden())
frame.window.move(frame.x_hidden, frame.y_hidden);
2002-12-01 13:42:15 +00:00
else
frame.window.move(frame.x, frame.y);
2001-12-11 20:47:02 +00:00
}
void Slit::loadClientList(const char *filename) {
2004-01-30 11:06:25 +00:00
if (filename == 0 || filename[0] == '\0')
return;
2004-01-30 11:06:25 +00:00
// save filename so we can save client list later
2004-02-20 09:29:07 +00:00
m_filename = filename;
std::string real_filename= FbTk::StringUtil::expandFilename(filename);
2002-12-01 13:42:15 +00:00
struct stat buf;
2004-02-20 09:29:07 +00:00
if (stat(real_filename.c_str(), &buf) == 0) {
std::ifstream file(real_filename.c_str());
2002-12-01 13:42:15 +00:00
std::string name;
while (! file.eof()) {
name = "";
std::getline(file, name); // get the entire line
if (name.empty())
2004-01-30 11:06:25 +00:00
continue;
// remove whitespaces from start and end
FbTk::StringUtil::removeFirstWhitespace(name);
// the cleaned string could still be a comment, or blank
if ( name.empty() || name[0] == '#' || name[0] == '!' )
2004-01-30 11:06:25 +00:00
continue;
// trailing whitespace won't affect the above test
FbTk::StringUtil::removeTrailingWhitespace(name);
SlitClient *client = new SlitClient(name.c_str());
m_client_list.push_back(client);
2002-12-01 13:42:15 +00:00
}
}
2002-05-29 06:21:59 +00:00
}
void Slit::updateClientmenu() {
2004-01-10 02:58:21 +00:00
if (screen().isShuttingdown())
return;
2004-06-07 11:46:05 +00:00
_FB_USES_NLS;
2004-01-10 02:58:21 +00:00
// clear old items
2003-05-11 17:42:51 +00:00
m_clientlist_menu.removeAll();
2004-06-07 11:46:05 +00:00
m_clientlist_menu.setLabel(_FBTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"));
2003-05-11 17:42:51 +00:00
FbTk::RefCount<FbTk::Command> cycle_up(new FbTk::SimpleCommand<Slit>(*this, &Slit::cycleClientsUp));
FbTk::RefCount<FbTk::Command> cycle_down(new FbTk::SimpleCommand<Slit>(*this, &Slit::cycleClientsDown));
2004-06-07 11:46:05 +00:00
m_clientlist_menu.insert(_FBTEXT(Slit, CycleUp, "Cycle Up", "Cycle clients upwards"), cycle_up);
m_clientlist_menu.insert(_FBTEXT(Slit, CycleDown, "Cycle Down", "Cycle clients downwards"), cycle_down);
2003-05-11 17:42:51 +00:00
m_clientlist_menu.insert(new FbTk::MenuSeparator());
2003-05-11 17:42:51 +00:00
FbTk::RefCount<FbTk::Command> reconfig(new FbTk::SimpleCommand<Slit>(*this, &Slit::reconfigure));
2003-05-11 17:42:51 +00:00
SlitClients::iterator it = m_client_list.begin();
for (; it != m_client_list.end(); ++it) {
if ((*it) != 0 && (*it)->window() != 0)
m_clientlist_menu.insert(new SlitClientMenuItem(*this, *(*it), reconfig));
}
m_clientlist_menu.insert(new FbTk::MenuSeparator());
FbTk::RefCount<FbTk::Command> savecmd(new FbTk::SimpleCommand<Slit>(*this, &Slit::saveClientList));
m_clientlist_menu.insert(_FBTEXT(Slit,
SaveSlitList,
"Save SlitList", "Saves the current order in the slit"),
savecmd);
m_clientlist_menu.updateMenu();
}
2002-11-14 00:23:19 +00:00
void Slit::saveClientList() {
2004-02-20 09:29:07 +00:00
std::ofstream file(FbTk::StringUtil::expandFilename(m_filename).c_str());
2003-05-11 17:42:51 +00:00
SlitClients::iterator it = m_client_list.begin();
SlitClients::iterator it_end = m_client_list.end();
2002-12-01 13:42:15 +00:00
std::string prevName;
std::string name;
for (; it != it_end; ++it) {
name = (*it)->matchName();
2002-12-01 13:42:15 +00:00
if (name != prevName)
file << name.c_str() << std::endl;
prevName = name;
}
2002-05-29 06:21:59 +00:00
}
2002-11-14 00:23:19 +00:00
void Slit::setAutoHide(bool val) {
*m_rc_auto_hide = val;
2003-05-11 17:42:51 +00:00
if (doAutoHide()) {
if (! m_timer.isTiming()) {
if (m_slitmenu.isVisible())
m_timer.fireOnce(false);
m_timer.start();
2003-05-01 15:35:24 +00:00
}
2003-05-11 17:42:51 +00:00
}
2002-11-14 00:23:19 +00:00
}
void Slit::setupMenu() {
2004-06-07 11:46:05 +00:00
_FB_USES_NLS;
using namespace FbTk;
FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand();
2003-05-13 21:12:18 +00:00
FbTk::MacroCommand *s_a_reconf_slit_macro = new FbTk::MacroCommand();
FbTk::RefCount<FbTk::Command> saverc_cmd(new FbCommands::SaveResources());
FbTk::RefCount<FbTk::Command> reconf_cmd(new FbCommands::ReconfigureFluxboxCmd());
2003-05-13 21:12:18 +00:00
FbTk::RefCount<FbTk::Command> reconf_slit_cmd(new FbTk::SimpleCommand<Slit>(*this, &Slit::reconfigure));
s_a_reconf_macro->add(saverc_cmd);
s_a_reconf_macro->add(reconf_cmd);
2003-05-13 21:12:18 +00:00
s_a_reconf_slit_macro->add(saverc_cmd);
s_a_reconf_slit_macro->add(reconf_slit_cmd);
FbTk::RefCount<FbTk::Command> save_and_reconfigure(s_a_reconf_macro);
2003-05-13 21:12:18 +00:00
FbTk::RefCount<FbTk::Command> save_and_reconfigure_slit(s_a_reconf_slit_macro);
// setup base menu
2004-06-07 11:46:05 +00:00
m_slitmenu.setLabel(_FBTEXT(Slit, Slit, "Slit", "The Slit"));
m_slitmenu.insert(_FBTEXT(Menu, Placement, "Placement", "Title of Placement menu"),
2003-05-11 17:42:51 +00:00
&m_placement_menu);
2004-06-07 11:46:05 +00:00
m_slitmenu.insert(_FBTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), m_layermenu.get());
2003-05-11 17:42:51 +00:00
#ifdef XINERAMA
if (screen().hasXinerama()) {
2004-06-07 11:46:05 +00:00
m_slitmenu.insert(_FBTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"),
new XineramaHeadMenu<Slit>(
screen().menuTheme(),
screen(),
screen().imageControl(),
2006-02-27 22:43:42 +00:00
*screen().layerManager().getLayer(::Layer::MENU),
2004-06-07 11:46:05 +00:00
*this,
_FBTEXT(Slit, OnHead, "Slit on Head", "Title of Slits On Head menu")
));
}
#endif //XINERAMA
2006-02-27 22:43:42 +00:00
2004-06-07 11:46:05 +00:00
m_slitmenu.insert(new BoolMenuItem(_FBTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"),
*m_rc_auto_hide,
2003-05-13 21:12:18 +00:00
save_and_reconfigure_slit));
2004-06-07 11:46:05 +00:00
m_slitmenu.insert(new BoolMenuItem(_FBTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"),
2003-06-22 12:31:37 +00:00
*m_rc_maximize_over,
save_and_reconfigure_slit));
2003-06-24 13:48:34 +00:00
// this saves resources and clears the slit window to update alpha value
2004-06-07 11:46:05 +00:00
FbTk::MenuItem *alpha_menuitem =
new IntResMenuItem(_FBTEXT(Common, Alpha, "Alpha", "Transparency level"),
m_rc_alpha,
2005-05-03 13:53:25 +00:00
0, 255, m_slitmenu);
2003-06-24 20:19:36 +00:00
// setup command for alpha value
MacroCommand *alpha_macrocmd = new MacroCommand();
RefCount<Command> alpha_cmd(new SimpleCommand<Slit>(*this, &Slit::updateAlpha));
2003-06-24 20:19:36 +00:00
alpha_macrocmd->add(saverc_cmd);
alpha_macrocmd->add(alpha_cmd);
2003-06-24 20:19:36 +00:00
RefCount<Command> set_alpha_cmd(alpha_macrocmd);
2003-06-24 13:48:34 +00:00
alpha_menuitem->setCommand(set_alpha_cmd);
2003-06-24 20:19:36 +00:00
2003-05-13 21:12:18 +00:00
m_slitmenu.insert(alpha_menuitem);
2003-05-11 17:42:51 +00:00
2004-06-07 11:46:05 +00:00
m_slitmenu.insert(new SlitDirMenuItem(_FBTEXT(Slit, Direction, "Slit Direction", "Orientation of slit"),
2003-05-11 17:42:51 +00:00
*this,
save_and_reconfigure));
2004-06-07 11:46:05 +00:00
m_slitmenu.insert(_FBTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu);
m_slitmenu.updateMenu();
// setup sub menu
2004-06-07 11:46:05 +00:00
m_placement_menu.setLabel(_FBTEXT(Slit, Placement, "Slit Placement", "Slit Placement"));
2003-05-11 17:42:51 +00:00
m_placement_menu.setMinimumSublevels(3);
2003-05-24 13:13:22 +00:00
m_layermenu->setInternalMenu();
m_clientlist_menu.setInternalMenu();
typedef pair<const char *, Slit::Placement> PlacementP;
typedef list<PlacementP> Placements;
2004-06-07 11:46:05 +00:00
Placements place_menu;
// menu is 3 wide, 5 down
place_menu.push_back(PlacementP(_FBTEXT(Align, TopLeft, "Top Left", "Top Left"), Slit::TOPLEFT));
place_menu.push_back(PlacementP(_FBTEXT(Align, LeftCenter, "Left Center", "Left Center"), Slit::LEFTCENTER));
place_menu.push_back(PlacementP(_FBTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), Slit::BOTTOMLEFT));
place_menu.push_back(PlacementP(_FBTEXT(Align, TopCenter, "Top Center", "Top Center"), Slit::TOPCENTER));
place_menu.push_back(PlacementP((const char *)0, Slit::TOPLEFT));
place_menu.push_back(PlacementP(_FBTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), Slit::BOTTOMCENTER));
place_menu.push_back(PlacementP(_FBTEXT(Align, TopRight, "Top Right", "Top Right"), Slit::TOPRIGHT));
place_menu.push_back(PlacementP(_FBTEXT(Align, RightCenter, "Right Center", "Right Center"), Slit::RIGHTCENTER));
place_menu.push_back(PlacementP(_FBTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Slit::BOTTOMRIGHT));
2004-06-07 11:46:05 +00:00
// create items in sub menu
for (size_t i=0; i<9; ++i) {
2004-06-07 11:46:05 +00:00
const char *str = place_menu.front().first;
Slit::Placement placement = place_menu.front().second;
if (str == 0) {
2003-05-11 17:42:51 +00:00
m_placement_menu.insert("");
2004-06-07 11:46:05 +00:00
m_placement_menu.setItemEnabled(i, false);
2002-12-01 13:42:15 +00:00
} else {
2004-06-07 11:46:05 +00:00
m_placement_menu.insert(new PlaceSlitMenuItem(str, *this,
placement,
2003-06-24 13:48:34 +00:00
save_and_reconfigure));
2004-06-07 11:46:05 +00:00
2002-12-01 13:42:15 +00:00
}
2004-06-07 11:46:05 +00:00
place_menu.pop_front();
2002-12-01 13:42:15 +00:00
}
2004-06-07 11:46:05 +00:00
// finaly update sub menu
m_placement_menu.updateMenu();
2001-12-11 20:47:02 +00:00
}
void Slit::moveToLayer(int layernum) {
m_layeritem->moveToLayer(layernum);
2003-07-06 07:09:53 +00:00
*m_rc_layernum = layernum;
}
void Slit::saveOnHead(int head) {
m_rc_on_head = head;
// reposition
reconfigure();
}
void Slit::updateAlpha() {
// called when the alpha resource is changed
if (FbTk::Transparent::haveComposite()) {
frame.window.setOpaque(*m_rc_alpha);
} else {
frame.window.setAlpha(*m_rc_alpha);
2006-04-21 16:23:24 +00:00
frame.window.updateBackground(true);
clearWindow();
}
}