#include "Slit.h"
#include "Toolbar.h"
-
-Slit::Slit(BScreen &scr) : screen(scr), openbox(scr.getOpenbox()) {
- on_top = screen.isSlitOnTop();
- hidden = do_auto_hide = screen.doSlitAutoHide();
-
+#include <string>
+#include <strstream>
+
+Slit::Slit(BScreen &scr, Resource &conf) : screen(scr),
+ openbox(scr.getOpenbox()), config(conf)
+{
+ // default values
+ m_placement = CenterRight;
+ m_direction = Vertical;
+ m_ontop = false;
+ m_hidden = m_autohide = false;
+
display = screen.getBaseDisplay().getXDisplay();
frame.window = frame.pixmap = None;
openbox.ungrab();
}
+void Slit::setOnTop(bool b) {
+ m_ontop = b;
+ ostrstream s;
+ s << "session.screen" << screen.getScreenNumber() << ".slit.onTop" << ends;
+ config.setValue(s.str(), m_ontop ? "True" : "False");
+}
+
+void Slit::setAutoHide(bool b) {
+ m_autohide = b;
+ ostrstream s;
+ s << "session.screen" << screen.getScreenNumber() << ".slit.autoHide" << ends;
+ config.setValue(s.str(), m_autohide ? "True" : "False");
+}
+
+void Slit::setPlacement(int p) {
+ m_placement = p;
+ cout << "setting " << p << " " << m_placement << endl;
+ ostrstream s;
+ s << "session.screen" << screen.getScreenNumber() << ".slit.placement" <<
+ ends;
+ const char *placement;
+ switch (m_placement) {
+ case TopLeft: placement = "TopLeft"; break;
+ case CenterLeft: placement = "CenterLeft"; break;
+ case BottomLeft: placement = "BottomLeft"; break;
+ case TopCenter: placement = "TopCenter"; break;
+ case BottomCenter: placement = "BottomCenter"; break;
+ case TopRight: placement = "TopRight"; break;
+ case BottomRight: placement = "BottomRight"; break;
+ case CenterRight: default: placement = "CenterRight"; break;
+ }
+ config.setValue(s.str(), placement);
+}
+
+void Slit::setDirection(int d) {
+ m_direction = d;
+ ostrstream s;
+ s << "session.screen" << screen.getScreenNumber() << ".slit.direction" <<
+ ends;
+ config.setValue(s.str(),
+ m_direction == Horizontal ? "Horizontal" : "Vertical");
+}
+
+void Slit::load() {
+ std::ostrstream rscreen, rname, rclass;
+ std::string s;
+ bool b;
+ rscreen << "session.screen" << screen.getScreenNumber() << '.' << ends;
+
+ rname << rscreen.str() << "slit.placement" << ends;
+ rclass << rscreen.str() << "Slit.Placement" << ends;
+ if (config.getValue(rname.str(), rclass.str(), s)) {
+ cout << "getting " << s.c_str() << endl;
+ if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
+ m_placement = TopLeft;
+ else if (0 == strncasecmp(s.c_str(), "CenterLeft", s.length()))
+ m_placement = CenterLeft;
+ else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
+ m_placement = BottomLeft;
+ else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
+ m_placement = TopCenter;
+ else if (0 == strncasecmp(s.c_str(), "BottomCenter", s.length()))
+ m_placement = BottomCenter;
+ else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
+ m_placement = TopRight;
+ else if (0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
+ m_placement = BottomRight;
+ else if (0 == strncasecmp(s.c_str(), "CenterRight", s.length()))
+ m_placement = CenterRight;
+ }
+
+ rname.seekp(0); rclass.seekp(0);
+ rname << rscreen.str() << "slit.direction" << ends;
+ rclass << rscreen.str() << "Slit.Direction" << ends;
+ if (config.getValue(rname.str(), rclass.str(), s)) {
+ if (0 == strncasecmp(s.c_str(), "Horizontal", s.length()))
+ m_direction = Horizontal;
+ else if (0 == strncasecmp(s.c_str(), "Vertical", s.length()))
+ m_direction = Vertical;
+ }
+
+ rname.seekp(0); rclass.seekp(0);
+ rname << rscreen.str() << "slit.onTop" << ends;
+ rclass << rscreen.str() << "Slit.OnTop" << ends;
+ if (config.getValue(rname.str(), rclass.str(), b))
+ m_ontop = b;
+
+ rname.seekp(0); rclass.seekp(0);
+ rname << rscreen.str() << "slit.autoHide" << ends;
+ rclass << rscreen.str() << "Slit.AutoHide" << ends;
+ if (config.getValue(rname.str(), rclass.str(), b))
+ m_hidden = m_autohide = b;
+}
void Slit::reconfigure(void) {
+ load();
+
frame.area.setSize(0, 0);
LinkedListIterator<SlitClient> it(clientList);
SlitClient *client;
- switch (screen.getSlitDirection()) {
+ switch (m_direction) {
case Vertical:
for (client = it.current(); client; it++, client = it.current()) {
frame.area.setH(frame.area.h() + client->height + screen.getBevelWidth());
int x, y;
it.reset();
- switch (screen.getSlitDirection()) {
+ switch (m_direction) {
case Vertical:
x = 0;
y = screen.getBevelWidth();
void Slit::reposition(void) {
// place the slit in the appropriate place
- switch (screen.getSlitPlacement()) {
+ switch (m_placement) {
case TopLeft:
frame.area.setOrigin(0, 0);
- if (screen.getSlitDirection() == Vertical) {
+ if (m_direction == Vertical) {
frame.hidden = Point(screen.getBevelWidth() - screen.getBorderWidth()
- frame.area.w(), 0);
} else {
case BottomLeft:
frame.area.setOrigin(0, screen.size().h() - frame.area.h()
- (screen.getBorderWidth() * 2));
- if (screen.getSlitDirection() == Vertical)
+ if (m_direction == Vertical)
frame.hidden = Point(screen.getBevelWidth() - screen.getBorderWidth()
- frame.area.w(), frame.area.y());
else
case TopRight:
frame.area.setOrigin(screen.size().w() - frame.area.w()
- (screen.getBorderWidth() * 2), 0);
- if (screen.getSlitDirection() == Vertical)
+ if (m_direction == Vertical)
frame.hidden = Point(screen.size().w() - screen.getBevelWidth()
- screen.getBorderWidth(), 0);
else
- (screen.getBorderWidth() * 2),
screen.size().h() - frame.area.h()
- (screen.getBorderWidth() * 2));
- if (screen.getSlitDirection() == Vertical)
+ if (m_direction == Vertical)
frame.hidden = Point(screen.size().w() - screen.getBevelWidth()
- screen.getBorderWidth(), frame.area.y());
else
- frame.hidden = Point(frame.area.x(), screen.size().h() - screen.getBevelWidth()
- - screen.getBorderWidth());
+ frame.hidden = Point(frame.area.x(), screen.size().h() -
+ screen.getBevelWidth() - screen.getBorderWidth());
break;
}
tw = tbar->getWidth() + screen.getBorderWidth(),
th = tbar->getHeight() + screen.getBorderWidth();
- if (tbar->getX() < frame.area.x() + sw && tbar->getX() + tw > frame.area.x() &&
- tbar->getY() < frame.area.y() + sh && tbar->getY() + th > frame.area.y()) {
+ if (tbar->getX() < frame.area.x() + sw &&
+ tbar->getX() + tw > frame.area.x() &&
+ tbar->getY() < frame.area.y() + sh &&
+ tbar->getY() + th > frame.area.y()) {
if (frame.area.y() < th) {
frame.area.setY(frame.area.y() + tbar->getExposedHeight());
- if (screen.getSlitDirection() == Vertical)
+ if (m_direction == Vertical)
frame.hidden.setY(frame.hidden.y() + tbar->getExposedHeight());
else
frame.hidden.setY(frame.area.y());
} else {
frame.area.setY(frame.area.y() - tbar->getExposedHeight());
- if (screen.getSlitDirection() == Vertical)
+ if (m_direction == Vertical)
frame.hidden.setY(frame.area.y() - tbar->getExposedHeight());
else
frame.hidden.setY(frame.area.y());
}
}
- if (hidden)
+ if (m_hidden)
XMoveResizeWindow(display, frame.window, frame.hidden.x(),
frame.hidden.y(), frame.area.w(), frame.area.h());
else
void Slit::buttonPressEvent(XButtonEvent *e) {
if (e->window != frame.window) return;
- if (e->button == Button1 && (! on_top)) {
+ if (e->button == Button1 && !m_ontop) {
Window w[1] = { frame.window };
screen.raiseWindows(w, 1);
- } else if (e->button == Button2 && (! on_top)) {
+ } else if (e->button == Button2 && !m_ontop) {
XLowerWindow(display, frame.window);
} else if (e->button == Button3) {
if (! slitmenu->isVisible()) {
void Slit::enterNotifyEvent(XCrossingEvent *) {
- if (! do_auto_hide)
+ if (!m_autohide)
return;
- if (hidden) {
+ if (m_hidden) {
if (! timer->isTiming()) timer->start();
} else {
if (timer->isTiming()) timer->stop();
void Slit::leaveNotifyEvent(XCrossingEvent *) {
- if (! do_auto_hide)
+ if (!m_autohide)
return;
- if (hidden) {
+ if (m_hidden) {
if (timer->isTiming()) timer->stop();
} else if (! slitmenu->isVisible()) {
- if (! timer->isTiming()) timer->start();
+ if (!timer->isTiming()) timer->start();
}
}
void Slit::timeout(void) {
- hidden = ! hidden;
- if (hidden)
+ m_hidden = !m_hidden;
+ if (m_hidden)
XMoveWindow(display, frame.window, frame.hidden.x(), frame.hidden.y());
else
XMoveWindow(display, frame.window, frame.area.x(), frame.area.y());
update();
- if (slit.isOnTop()) setItemSelected(2, True);
- if (slit.doAutoHide()) setItemSelected(3, True);
+ if (slit.onTop()) setItemSelected(2, True);
+ if (slit.autoHide()) setItemSelected(3, True);
}
switch (item->function()) {
case 1: { // always on top
- Bool change = ((slit.isOnTop()) ? False : True);
- slit.on_top = change;
+ bool change = ((slit.onTop()) ? false : true);
+ slit.setOnTop(change);
setItemSelected(2, change);
- if (slit.isOnTop()) slit.screen.raiseWindows((Window *) 0, 0);
+ if (slit.onTop()) slit.screen.raiseWindows((Window *) 0, 0);
break;
}
case 2: { // auto hide
- Bool change = ((slit.doAutoHide()) ? False : True);
- slit.do_auto_hide = change;
+ Bool change = ((slit.autoHide()) ? false : true);
+ slit.setAutoHide(change);
setItemSelected(3, change);
break;
void Slitmenu::internal_hide(void) {
Basemenu::internal_hide();
- if (slit.doAutoHide())
+ if (slit.autoHide())
slit.timeout();
}
update();
- if (sm.slit.screen.getSlitDirection() == Slit::Horizontal)
+ if (sm.slit.direction() == Slit::Horizontal)
setItemSelected(0, True);
else
setItemSelected(1, True);
BasemenuItem *item = find(index);
if (! item) return;
- slitmenu.slit.screen.saveSlitDirection(item->function());
+ slitmenu.slit.setDirection(item->function());
if (item->function() == Slit::Horizontal) {
setItemSelected(0, True);
BasemenuItem *item = find(index);
if (! (item && item->function())) return;
- slitmenu.slit.screen.saveSlitPlacement(item->function());
+ slitmenu.slit.setPlacement(item->function());
hide();
slitmenu.slit.reconfigure();
}
-
#endif // SLIT
protected:
virtual void itemSelected(int, int);
- virtual void internal_hide(void);
+ virtual void internal_hide();
public:
Slitmenu(Slit &);
- virtual ~Slitmenu(void);
+ virtual ~Slitmenu();
- inline Basemenu *getDirectionmenu(void) { return directionmenu; }
- inline Basemenu *getPlacementmenu(void) { return placementmenu; }
+ inline Basemenu *getDirectionmenu() { return directionmenu; }
+ inline Basemenu *getPlacementmenu() { return placementmenu; }
- void reconfigure(void);
+ void reconfigure();
};
unsigned int width, height;
};
- Bool on_top, hidden, do_auto_hide;
+ bool m_ontop, m_autohide, m_hidden;
+ int m_direction, m_placement;
Display *display;
Openbox &openbox;
BScreen &screen;
+ Resource &config;
BTimer *timer;
LinkedList<SlitClient> *clientList;
Pixmap pixmap;
Window window;
- //int x, y, x_hidden, y_hidden;
- //unsigned int width, height;
Rect area;
Point hidden;
} frame;
public:
- Slit(BScreen &);
+ Slit(BScreen &, Resource &);
virtual ~Slit();
- inline const Bool &isOnTop(void) const { return on_top; }
- inline const Bool &isHidden(void) const { return hidden; }
- inline const Bool &doAutoHide(void) const { return do_auto_hide; }
-
inline Slitmenu *getMenu() { return slitmenu; }
inline const Window &getWindowID() const { return frame.window; }
- //inline const int &getX(void) const
- //{ return ((hidden) ? frame.x_hidden : frame.x); }
- //inline const int &getY(void) const
- //{ return ((hidden) ? frame.y_hidden : frame.y); }
inline const Point &origin() const { return frame.area.origin(); }
-
- //inline const unsigned int &getWidth(void) const { return frame.width; }
- //inline const unsigned int &getHeight(void) const { return frame.height; }
inline const Size &size() const { return frame.area.size(); }
-
inline const Rect &area() const { return frame.area; }
void addClient(Window);
void removeClient(SlitClient *, Bool = True);
void removeClient(Window, Bool = True);
- void reconfigure(void);
- void reposition(void);
- void shutdown(void);
+ void reconfigure();
+ void load();
+ void reposition();
+ void shutdown();
void buttonPressEvent(XButtonEvent *);
void enterNotifyEvent(XCrossingEvent *);
void leaveNotifyEvent(XCrossingEvent *);
void configureRequestEvent(XConfigureRequestEvent *);
- virtual void timeout(void);
+ virtual void timeout();
+
+ inline bool isHidden() const { return m_hidden; }
+
+ inline bool onTop() const { return m_ontop; }
+ void setOnTop(bool);
+
+ inline bool autoHide() const { return m_autohide; }
+ void setAutoHide(bool);
+
+ inline int placement() const { return m_placement; }
+ void setPlacement(int);
+
+ inline int direction() const { return m_direction; }
+ void setDirection(int);
enum { Vertical = 1, Horizontal };
enum { TopLeft = 1, CenterLeft, BottomLeft, TopCenter, BottomCenter,
rc_file = bstrdup(rc);
}
config.setFile(rc_file);
+ config.load();
no_focus = False;
screenList = new LinkedList<BScreen>;
for (int i = 0; i < getNumberOfScreens(); i++) {
- BScreen *screen = new BScreen(*this, i);
+ BScreen *screen = new BScreen(*this, i, config);
if (! screen->isScreenManaged()) {
delete screen;
char rc_string[1024];
const int screen_number = screen->getScreenNumber();
- char *placement = (char *) 0;
-
- switch (screen->getSlitPlacement()) {
- case Slit::TopLeft: placement = "TopLeft"; break;
- case Slit::CenterLeft: placement = "CenterLeft"; break;
- case Slit::BottomLeft: placement = "BottomLeft"; break;
- case Slit::TopCenter: placement = "TopCenter"; break;
- case Slit::BottomCenter: placement = "BottomCenter"; break;
- case Slit::TopRight: placement = "TopRight"; break;
- case Slit::BottomRight: placement = "BottomRight"; break;
- case Slit::CenterRight: default: placement = "CenterRight"; break;
- }
- sprintf(rc_string, "session.screen%d.slit.placement", screen_number);
- config.setValue(rc_string, placement);
-
- sprintf(rc_string, "session.screen%d.slit.direction", screen_number);
- config.setValue(rc_string,
- screen->getSlitDirection() == Slit::Horizontal ?
- "Horizontal" : "Vertical");
-
- sprintf(rc_string, "session.screen%d.slit.onTop", screen_number);
- config.setValue(rc_string, screen->getSlit()->isOnTop() ? "True" : "False");
-
- sprintf(rc_string, "session.screen%d.slit.autoHide", screen_number);
- config.setValue(rc_string, screen->getSlit()->doAutoHide() ?
- "True" : "False");
-
config.setValue("session.opaqueMove",
(screen->doOpaqueMove()) ? "True" : "False");
config.setValue("session.imageDither",
screen->getColPlacementDirection() == BScreen::TopBottom ?
"TopToBottom" : "BottomToTop");
+ const char *placement;
switch (screen->getPlacementPolicy()) {
case BScreen::CascadePlacement: placement = "CascadePlacement"; break;
case BScreen::BestFitPlacement: placement = "BestFitPlacement"; break;
screen->savePlacementPolicy(BScreen::RowSmartPlacement);
#ifdef SLIT
- sprintf(name_lookup, "session.screen%d.slit.placement", screen_number);
- sprintf(class_lookup, "Session.Screen%d.Slit.Placement", screen_number);
- if (config.getValue(name_lookup, class_lookup, s)) {
- if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
- screen->saveSlitPlacement(Slit::TopLeft);
- else if (0 == strncasecmp(s.c_str(), "CenterLeft", s.length()))
- screen->saveSlitPlacement(Slit::CenterLeft);
- else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
- screen->saveSlitPlacement(Slit::BottomLeft);
- else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
- screen->saveSlitPlacement(Slit::TopCenter);
- else if (0 == strncasecmp(s.c_str(), "BottomCenter", s.length()))
- screen->saveSlitPlacement(Slit::BottomCenter);
- else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
- screen->saveSlitPlacement(Slit::TopRight);
- else if (0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
- screen->saveSlitPlacement(Slit::BottomRight);
- else
- screen->saveSlitPlacement(Slit::CenterRight);
- } else
- screen->saveSlitPlacement(Slit::CenterRight);
-
- sprintf(name_lookup, "session.screen%d.slit.direction", screen_number);
- sprintf(class_lookup, "Session.Screen%d.Slit.Direction", screen_number);
- if (config.getValue(name_lookup, class_lookup, s)) {
- if (0 == strncasecmp(s.c_str(), "Horizontal", s.length()))
- screen->saveSlitDirection(Slit::Horizontal);
- else
- screen->saveSlitDirection(Slit::Vertical);
- } else
- screen->saveSlitDirection(Slit::Vertical);
-
- sprintf(name_lookup, "session.screen%d.slit.onTop", screen_number);
- sprintf(class_lookup, "Session.Screen%d.Slit.OnTop", screen_number);
- if (config.getValue(name_lookup, class_lookup, b))
- screen->saveSlitOnTop((Bool)b);
- else
- screen->saveSlitOnTop(False);
-
- sprintf(name_lookup, "session.screen%d.slit.autoHide", screen_number);
- sprintf(class_lookup, "Session.Screen%d.Slit.AutoHide", screen_number);
- if (config.getValue(name_lookup, class_lookup, b))
- screen->saveSlitAutoHide((Bool)b);
- else
- screen->saveSlitAutoHide(False);
#endif // SLIT
#ifdef HAVE_STRFTIME