From: Dana Jansens Date: Tue, 16 Apr 2002 23:50:53 +0000 (+0000) Subject: Slit loads its own settings and saves them as they are changed X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=73a3c979b39ae0b51298d16bc5e76b61d31c89d5;p=chaz%2Fopenbox Slit loads its own settings and saves them as they are changed added an assert in Resource --- diff --git a/src/Resource.cc b/src/Resource.cc index f3b0e5f9..cff9bd38 100644 --- a/src/Resource.cc +++ b/src/Resource.cc @@ -116,6 +116,7 @@ void Resource::setValue(const std::string &rname, long value) { void Resource::setValue(const std::string &rname, const char *value) { ASSERT(m_database != NULL); + ASSERT(value != NULL); std::string rc_string = rname + ": " + value; XrmPutLineResource(&m_database, rc_string.c_str()); diff --git a/src/Screen.cc b/src/Screen.cc index 08c2d9ee..7a3b9d7b 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -185,7 +185,9 @@ static const char *getFontSize(const char *pattern, int *size) { } -BScreen::BScreen(Openbox &ob, int scrn) : ScreenInfo(ob, scrn), openbox(ob) { +BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), + openbox(ob), config(conf) +{ event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask; @@ -419,7 +421,7 @@ BScreen::BScreen(Openbox &ob, int scrn) : ScreenInfo(ob, scrn), openbox(ob) { toolbar = new Toolbar(*this); #ifdef SLIT - slit = new Slit(*this); + slit = new Slit(*this, config); #endif // SLIT InitMenu(); @@ -1545,7 +1547,7 @@ void BScreen::raiseWindows(Window *workspace_stack, int num) { *(session_stack + i++) = toolbar->getWindowID(); #ifdef SLIT - if (slit->isOnTop()) + if (slit->onTop()) *(session_stack + i++) = slit->getWindowID(); #endif // SLIT diff --git a/src/Screen.h b/src/Screen.h index 4b3e4dc3..8d413529 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -103,6 +103,7 @@ private: Window geom_window; Openbox &openbox; + Resource &config; BImageControl *image_control; Configmenu *configmenu; Iconmenu *iconmenu; @@ -175,7 +176,7 @@ protected: public: - BScreen(Openbox &, int); + BScreen(Openbox &, int, Resource &); ~BScreen(void); inline const Bool &isToolbarOnTop(void) const @@ -207,18 +208,7 @@ public: inline Rootmenu *getRootmenu(void) { return rootmenu; } #ifdef SLIT - inline const Bool &isSlitOnTop(void) const { return resource.slit_on_top; } - inline const Bool &doSlitAutoHide(void) const - { return resource.slit_auto_hide; } inline Slit *getSlit(void) { return slit; } - inline const int &getSlitPlacement(void) const - { return resource.slit_placement; } - inline const int &getSlitDirection(void) const - { return resource.slit_direction; } - inline void saveSlitPlacement(int p) { resource.slit_placement = p; } - inline void saveSlitDirection(int d) { resource.slit_direction = d; } - inline void saveSlitOnTop(Bool t) { resource.slit_on_top = t; } - inline void saveSlitAutoHide(Bool t) { resource.slit_auto_hide = t; } #endif // SLIT inline int getWindowZones(void) const diff --git a/src/Slit.cc b/src/Slit.cc index 905bccc7..b180714a 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -41,11 +41,18 @@ #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 +#include + +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; @@ -207,13 +214,108 @@ void Slit::removeClient(Window w, Bool remap) { 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 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()); @@ -284,7 +386,7 @@ void Slit::reconfigure(void) { int x, y; it.reset(); - switch (screen.getSlitDirection()) { + switch (m_direction) { case Vertical: x = 0; y = screen.getBevelWidth(); @@ -364,10 +466,10 @@ void Slit::reconfigure(void) { 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 { @@ -385,7 +487,7 @@ void Slit::reposition(void) { 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 @@ -410,7 +512,7 @@ void Slit::reposition(void) { 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 @@ -432,12 +534,12 @@ void Slit::reposition(void) { - (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; } @@ -447,24 +549,26 @@ void Slit::reposition(void) { 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 @@ -482,10 +586,10 @@ void Slit::shutdown(void) { 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()) { @@ -514,10 +618,10 @@ void Slit::buttonPressEvent(XButtonEvent *e) { 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(); @@ -526,13 +630,13 @@ void Slit::enterNotifyEvent(XCrossingEvent *) { 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(); } } @@ -577,8 +681,8 @@ void Slit::configureRequestEvent(XConfigureRequestEvent *e) { 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()); @@ -601,8 +705,8 @@ Slitmenu::Slitmenu(Slit &sl) : Basemenu(sl.screen), slit(sl) { 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); } @@ -621,17 +725,17 @@ void Slitmenu::itemSelected(int button, int index) { 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; @@ -642,7 +746,7 @@ void Slitmenu::itemSelected(int button, int index) { void Slitmenu::internal_hide(void) { Basemenu::internal_hide(); - if (slit.doAutoHide()) + if (slit.autoHide()) slit.timeout(); } @@ -667,7 +771,7 @@ Slitmenu::Directionmenu::Directionmenu(Slitmenu &sm) update(); - if (sm.slit.screen.getSlitDirection() == Slit::Horizontal) + if (sm.slit.direction() == Slit::Horizontal) setItemSelected(0, True); else setItemSelected(1, True); @@ -681,7 +785,7 @@ void Slitmenu::Directionmenu::itemSelected(int button, int index) { 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); @@ -735,10 +839,9 @@ void Slitmenu::Placementmenu::itemSelected(int button, int index) { 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 diff --git a/src/Slit.h b/src/Slit.h index b7dedb5a..60bbdfcb 100644 --- a/src/Slit.h +++ b/src/Slit.h @@ -70,17 +70,17 @@ private: 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(); }; @@ -94,11 +94,13 @@ private: 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 *clientList; @@ -108,8 +110,6 @@ private: Pixmap pixmap; Window window; - //int x, y, x_hidden, y_hidden; - //unsigned int width, height; Rect area; Point hidden; } frame; @@ -121,42 +121,45 @@ private: 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, diff --git a/src/openbox.cc b/src/openbox.cc index 64123521..3519c767 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -179,6 +179,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) rc_file = bstrdup(rc); } config.setFile(rc_file); + config.load(); no_focus = False; @@ -209,7 +210,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) screenList = new LinkedList; 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; @@ -994,33 +995,6 @@ void Openbox::save_rc(void) { 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", @@ -1045,6 +1019,7 @@ void Openbox::save_rc(void) { screen->getColPlacementDirection() == BScreen::TopBottom ? "TopToBottom" : "BottomToTop"); + const char *placement; switch (screen->getPlacementPolicy()) { case BScreen::CascadePlacement: placement = "CascadePlacement"; break; case BScreen::BestFitPlacement: placement = "BestFitPlacement"; break; @@ -1388,51 +1363,6 @@ void Openbox::load_rc(BScreen *screen) { 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