From 8d3c97389f23271c7b44a726111c97d34bc2ced2 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 12 Apr 2002 06:05:04 +0000 Subject: [PATCH] save_rc() using the obResource class to save blackbox's configuration. renamed BScreen::getCount to BScreen::getWorkspaceCount. --- src/Makefile.am | 30 ++--- src/Makefile.in | 30 ++--- src/Netizen.cc | 2 +- src/Resource.cc | 4 + src/Resource.h | 1 + src/Screen.h | 4 +- src/Toolbar.cc | 6 +- src/Window.cc | 9 +- src/Windowmenu.cc | 4 +- src/Workspacemenu.cc | 2 +- src/openbox.cc | 305 ++++++++++++++++++------------------------- src/openbox.h | 3 + 12 files changed, 177 insertions(+), 223 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4fa80868..f44dad32 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,65 +45,65 @@ BaseDisplay.o: BaseDisplay.cc i18n.h BaseDisplay.h LinkedList.h \ Basemenu.o: Basemenu.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Screen.h Configmenu.h Netizen.h Rootmenu.h \ - Workspace.h Workspacemenu.h + Workspace.h Workspacemenu.h Resource.h Clientmenu.o: Clientmenu.cc openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Clientmenu.h Workspace.h Screen.h Configmenu.h Netizen.h \ - Rootmenu.h Workspacemenu.h + Rootmenu.h Workspacemenu.h Resource.h Configmenu.o: Configmenu.cc i18n.h Configmenu.h Basemenu.h \ LinkedList.h Screen.h BaseDisplay.h Timer.h Iconmenu.h Netizen.h \ Rootmenu.h Workspace.h Workspacemenu.h openbox.h Image.h \ - Window.h Windowmenu.h Slit.h Toolbar.h + Window.h Windowmenu.h Slit.h Toolbar.h Resource.h Icon.o: Iconmenu.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Screen.h Configmenu.h Netizen.h Rootmenu.h Workspace.h \ - Workspacemenu.h Toolbar.h + Workspacemenu.h Toolbar.h Resource.h Image.o: Image.cc i18n.h BaseDisplay.h LinkedList.h Timer.h \ Image.h LinkedList.o: LinkedList.cc LinkedList.h Netizen.o: Netizen.cc Netizen.h BaseDisplay.h LinkedList.h Timer.h \ Screen.h Configmenu.h Basemenu.h openbox.h Image.h Window.h \ Iconmenu.h Windowmenu.h Slit.h Rootmenu.h Workspace.h \ - Workspacemenu.h + Workspacemenu.h Resource.h Rootmenu.o: Rootmenu.cc openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Rootmenu.h Screen.h Configmenu.h Netizen.h Workspace.h \ - Workspacemenu.h + Workspacemenu.h Resource.h Screen.o: Screen.cc i18n.h bsd-snprintf.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Clientmenu.h Workspace.h Screen.h Configmenu.h \ - Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h + Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h Resource.h Slit.o: Slit.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Screen.h Configmenu.h Netizen.h Rootmenu.h Workspace.h \ - Workspacemenu.h Toolbar.h + Workspacemenu.h Toolbar.h Resource.h Timer.o: Timer.cc BaseDisplay.h LinkedList.h Timer.h Toolbar.o: Toolbar.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Clientmenu.h Workspace.h Rootmenu.h Screen.h Configmenu.h \ - Netizen.h Workspacemenu.h Toolbar.h + Netizen.h Workspacemenu.h Toolbar.h Resource.h Window.o: Window.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Screen.h Configmenu.h Netizen.h Rootmenu.h Workspace.h \ - Workspacemenu.h Toolbar.h + Workspacemenu.h Toolbar.h Resource.h Windowmenu.o: Windowmenu.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Screen.h Configmenu.h Netizen.h Rootmenu.h \ - Workspace.h Workspacemenu.h + Workspace.h Workspacemenu.h Resource.h Workspace.o: Workspace.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Clientmenu.h Workspace.h Screen.h \ - Configmenu.h Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h + Configmenu.h Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h Resource.h Workspacemenu.o: Workspacemenu.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Screen.h Configmenu.h Netizen.h Rootmenu.h \ - Workspace.h Workspacemenu.h Toolbar.h + Workspace.h Workspacemenu.h Toolbar.h Resource.h openbox.o: openbox.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Clientmenu.h Workspace.h Rootmenu.h \ - Screen.h Configmenu.h Netizen.h Workspacemenu.h Toolbar.h + Screen.h Configmenu.h Netizen.h Workspacemenu.h Toolbar.h Resource.h bsd-snprintf.o: bsd-snprintf.c bsd-snprintf.h i18n.o: i18n.cc i18n.h main.o: main.cc ../version.h i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ - Windowmenu.h Slit.h + Windowmenu.h Slit.h Resource.h diff --git a/src/Makefile.in b/src/Makefile.in index 786e888a..8f0657c5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -395,68 +395,68 @@ BaseDisplay.o: BaseDisplay.cc i18n.h BaseDisplay.h LinkedList.h \ Basemenu.o: Basemenu.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Screen.h Configmenu.h Netizen.h Rootmenu.h \ - Workspace.h Workspacemenu.h + Workspace.h Workspacemenu.h Resource.h Clientmenu.o: Clientmenu.cc openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Clientmenu.h Workspace.h Screen.h Configmenu.h Netizen.h \ - Rootmenu.h Workspacemenu.h + Rootmenu.h Workspacemenu.h Resource.h Configmenu.o: Configmenu.cc i18n.h Configmenu.h Basemenu.h \ LinkedList.h Screen.h BaseDisplay.h Timer.h Iconmenu.h Netizen.h \ Rootmenu.h Workspace.h Workspacemenu.h openbox.h Image.h \ - Window.h Windowmenu.h Slit.h Toolbar.h + Window.h Windowmenu.h Slit.h Toolbar.h Resource.h Icon.o: Iconmenu.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Screen.h Configmenu.h Netizen.h Rootmenu.h Workspace.h \ - Workspacemenu.h Toolbar.h + Workspacemenu.h Toolbar.h Resource.h Image.o: Image.cc i18n.h BaseDisplay.h LinkedList.h Timer.h \ Image.h LinkedList.o: LinkedList.cc LinkedList.h Netizen.o: Netizen.cc Netizen.h BaseDisplay.h LinkedList.h Timer.h \ Screen.h Configmenu.h Basemenu.h openbox.h Image.h Window.h \ Iconmenu.h Windowmenu.h Slit.h Rootmenu.h Workspace.h \ - Workspacemenu.h + Workspacemenu.h Resource.h Rootmenu.o: Rootmenu.cc openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Rootmenu.h Screen.h Configmenu.h Netizen.h Workspace.h \ - Workspacemenu.h + Workspacemenu.h Resource.h Screen.o: Screen.cc i18n.h bsd-snprintf.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Clientmenu.h Workspace.h Screen.h Configmenu.h \ - Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h + Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h Resource.h Slit.o: Slit.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Screen.h Configmenu.h Netizen.h Rootmenu.h Workspace.h \ - Workspacemenu.h Toolbar.h + Workspacemenu.h Toolbar.h Resource.h Timer.o: Timer.cc BaseDisplay.h LinkedList.h Timer.h Toolbar.o: Toolbar.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Clientmenu.h Workspace.h Rootmenu.h Screen.h Configmenu.h \ - Netizen.h Workspacemenu.h Toolbar.h + Netizen.h Workspacemenu.h Toolbar.h Resource.h Window.o: Window.cc i18n.h openbox.h BaseDisplay.h LinkedList.h \ Timer.h Image.h Window.h Iconmenu.h Basemenu.h Windowmenu.h Slit.h \ Screen.h Configmenu.h Netizen.h Rootmenu.h Workspace.h \ - Workspacemenu.h Toolbar.h + Workspacemenu.h Toolbar.h Resource.h Windowmenu.o: Windowmenu.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Screen.h Configmenu.h Netizen.h Rootmenu.h \ - Workspace.h Workspacemenu.h + Workspace.h Workspacemenu.h Resource.h Workspace.o: Workspace.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Clientmenu.h Workspace.h Screen.h \ - Configmenu.h Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h + Configmenu.h Netizen.h Rootmenu.h Workspacemenu.h Toolbar.h Resource.h Workspacemenu.o: Workspacemenu.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Screen.h Configmenu.h Netizen.h Rootmenu.h \ - Workspace.h Workspacemenu.h Toolbar.h + Workspace.h Workspacemenu.h Toolbar.h Resource.h openbox.o: openbox.cc i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ Windowmenu.h Slit.h Clientmenu.h Workspace.h Rootmenu.h \ - Screen.h Configmenu.h Netizen.h Workspacemenu.h Toolbar.h + Screen.h Configmenu.h Netizen.h Workspacemenu.h Toolbar.h Resource.h bsd-snprintf.o: bsd-snprintf.c bsd-snprintf.h i18n.o: i18n.cc i18n.h main.o: main.cc ../version.h i18n.h openbox.h BaseDisplay.h \ LinkedList.h Timer.h Image.h Window.h Iconmenu.h Basemenu.h \ - Windowmenu.h Slit.h + Windowmenu.h Slit.h Resource.h # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/Netizen.cc b/src/Netizen.cc index 22d47958..bb159483 100644 --- a/src/Netizen.cc +++ b/src/Netizen.cc @@ -53,7 +53,7 @@ Netizen::Netizen(BScreen *scr, Window win) { void Netizen::sendWorkspaceCount(void) { event.xclient.data.l[0] = basedisplay->getOpenboxNotifyWorkspaceCountAtom(); - event.xclient.data.l[1] = screen->getCount(); + event.xclient.data.l[1] = screen->getWorkspaceCount(); XSendEvent(basedisplay->getXDisplay(), window, False, NoEventMask, &event); } diff --git a/src/Resource.cc b/src/Resource.cc index ec29ac9a..b3605218 100644 --- a/src/Resource.cc +++ b/src/Resource.cc @@ -88,6 +88,10 @@ void obResource::setValue(const std::string &rname, bool value) { save(); } +void obResource::setValue(const std::string &rname, int value) { + setValue(rname, (long)value); +} + void obResource::setValue(const std::string &rname, long value) { assert(m_database != NULL); diff --git a/src/Resource.h b/src/Resource.h index 253c09ee..985e29d8 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -52,6 +52,7 @@ public: bool load(); void setValue(const std::string &rname, bool value); + void setValue(const std::string &rname, int value); void setValue(const std::string &rname, long value); void setValue(const std::string &rname, const std::string &value); void setValue(const std::string &rname, const char *value); diff --git a/src/Screen.h b/src/Screen.h index 1bf2a8cd..851c45dd 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -52,6 +52,8 @@ #endif // SLIT #include "Image.h" +#include + // forward declaration class BScreen; @@ -239,7 +241,7 @@ public: inline const int getCurrentWorkspaceID() { return current_workspace->getWorkspaceID(); } - inline const int getCount(void) { return workspacesList->count(); } + inline const int getWorkspaceCount(void) { return workspacesList->count(); } inline const int getIconCount(void) { return iconList->count(); } inline const int &getNumberOfWorkspaces(void) const { return resource.workspaces; } diff --git a/src/Toolbar.cc b/src/Toolbar.cc index d2e39c85..88cf1a02 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -314,7 +314,7 @@ void Toolbar::reconfigure(void) { unsigned int w = 0; frame.workspace_label_w = 0; - for (i = 0; i < screen->getCount(); i++) { + for (i = 0; i < screen->getWorkspaceCount(); i++) { if (i18n->multibyte()) { XRectangle ink, logical; XmbTextExtents(screen->getToolbarStyle()->fontset, @@ -926,14 +926,14 @@ void Toolbar::buttonReleaseEvent(XButtonEvent *re) { screen->changeWorkspaceID(screen->getCurrentWorkspace()-> getWorkspaceID() - 1); else - screen->changeWorkspaceID(screen->getCount() - 1); + screen->changeWorkspaceID(screen->getWorkspaceCount() - 1); } else if (re->window == frame.nsbutton) { redrawNextWorkspaceButton(False, True); if (re->x >= 0 && re->x < (signed) frame.button_w && re->y >= 0 && re->y < (signed) frame.button_w) if (screen->getCurrentWorkspace()->getWorkspaceID() < - screen->getCount() - 1) + screen->getWorkspaceCount() - 1) screen->changeWorkspaceID(screen->getCurrentWorkspace()-> getWorkspaceID() + 1); else diff --git a/src/Window.cc b/src/Window.cc index 4133ac00..b81f1b90 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -284,7 +284,7 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { decorate(); - if (workspace_number < 0 || workspace_number >= screen->getCount()) + if (workspace_number < 0 || workspace_number >= screen->getWorkspaceCount()) screen->getCurrentWorkspace()->addWindow(this, place_window); else screen->getWorkspace(workspace_number)->addWindow(this, place_window); @@ -1927,7 +1927,7 @@ void OpenboxWindow::restoreAttributes(void) { } if (((int) openbox_attrib.workspace != screen->getCurrentWorkspaceID()) && - ((int) openbox_attrib.workspace < screen->getCount())) { + ((int) openbox_attrib.workspace < screen->getWorkspaceCount())) { screen->reassociateWindow(this, openbox_attrib.workspace, True); if (current_state == NormalState) current_state = WithdrawnState; @@ -2688,9 +2688,10 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { (re->x >= 0) && ((unsigned) re->x <= frame.button_w) && (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) { close(); - } else { - redrawCloseButton(False); } + //we should always redraw the close button. some applications + //eg. acroread don't honour the close. + redrawCloseButton(False); } // middle button released } else if (re->button == 2) { diff --git a/src/Windowmenu.cc b/src/Windowmenu.cc index d9da5b86..70636996 100644 --- a/src/Windowmenu.cc +++ b/src/Windowmenu.cc @@ -171,7 +171,7 @@ Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w) void Windowmenu::SendtoWorkspacemenu::itemSelected(int button, int index) { if (button > 2) return; - if (index <= windowmenu->screen->getCount()) { + if (index <= windowmenu->screen->getWorkspaceCount()) { if (index == windowmenu->screen->getCurrentWorkspaceID()) return; if (windowmenu->window->isStuck()) windowmenu->window->stick(); @@ -190,7 +190,7 @@ void Windowmenu::SendtoWorkspacemenu::update(void) { for (i = 0; i < r; ++i) remove(0); - for (i = 0; i < windowmenu->screen->getCount(); ++i) + for (i = 0; i < windowmenu->screen->getWorkspaceCount(); ++i) insert(windowmenu->screen->getWorkspace(i)->getName()); Basemenu::update(); diff --git a/src/Workspacemenu.cc b/src/Workspacemenu.cc index bec5f455..7f94e5fb 100644 --- a/src/Workspacemenu.cc +++ b/src/Workspacemenu.cc @@ -61,7 +61,7 @@ void Workspacemenu::itemSelected(int button, int index) { else if (index == 1) screen->removeLastWorkspace(); else if ((screen->getCurrentWorkspace()->getWorkspaceID() != - (index - 2)) && ((index - 2) < screen->getCount())) + (index - 2)) && ((index - 2) < screen->getWorkspaceCount())) screen->changeWorkspaceID(index - 2); if (! (screen->getWorkspacemenu()->isTorn() || isTorn())) diff --git a/src/openbox.cc b/src/openbox.cc index ffbe166c..2f41fcbb 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -381,11 +381,11 @@ void Openbox::process_event(XEvent *e) { } } else if (e->xbutton.button == 4) { if ((screen->getCurrentWorkspaceID()-1)<0) - screen->changeWorkspaceID(screen->getCount()-1); + screen->changeWorkspaceID(screen->getWorkspaceCount()-1); else screen->changeWorkspaceID(screen->getCurrentWorkspaceID()-1); } else if (e->xbutton.button == 5) { - if ((screen->getCurrentWorkspaceID()+1)>screen->getCount()-1) + if ((screen->getCurrentWorkspaceID()+1)>screen->getWorkspaceCount()-1) screen->changeWorkspaceID(0); else screen->changeWorkspaceID(screen->getCurrentWorkspaceID()+1); @@ -688,7 +688,7 @@ void Openbox::process_event(XEvent *e) { BScreen *screen = searchScreen(e->xclient.window); if (screen && e->xclient.data.l[0] >= 0 && - e->xclient.data.l[0] < screen->getCount()) + e->xclient.data.l[0] < screen->getWorkspaceCount()) screen->changeWorkspaceID(e->xclient.data.l[0]); } else if (e->xclient.message_type == getOpenboxChangeWindowFocusAtom()) { OpenboxWindow *win = searchWindow(e->xclient.window); @@ -969,239 +969,181 @@ void Openbox::shutdown(void) { void Openbox::save_rc(void) { - XrmDatabase new_openboxrc = (XrmDatabase) 0; - char rc_string[1024]; - - load_rc(); - - sprintf(rc_string, "session.menuFile: %s", resource.menu_file); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.colorsPerChannel: %d", - resource.colors_per_channel); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.titlebarLayout: %s", - resource.titlebar_layout); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.doubleClickInterval: %lu", - resource.double_click_interval); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.autoRaiseDelay: %lu", + config.setAutoSave(false); + + config.setValue("session.menuFile", getMenuFilename()); + config.setValue("session.colorsPerChannel", + resource.colors_per_channel); + config.setValue("session.doubleClickInterval", + (long)resource.double_click_interval); + config.setValue("session.autoRaiseDelay", ((resource.auto_raise_delay.tv_sec * 1000) + (resource.auto_raise_delay.tv_usec / 1000))); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.cacheLife: %lu", resource.cache_life / 60000); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.cacheMax: %lu", resource.cache_max); - XrmPutLineResource(&new_openboxrc, rc_string); + config.setValue("session.cacheLife", (long)resource.cache_life / 60000); + config.setValue("session.cacheMax", (long)resource.cache_max); LinkedListIterator it(screenList); for (BScreen *screen = it.current(); screen; it++, screen = it.current()) { - int screen_number = screen->getScreenNumber(); +// ScreenList::iterator it = screenList.begin(); +// for (; it != screenList.end(); ++it) { +// BScreen *screen = *it; + char rc_string[1024]; + const int screen_number = screen->getScreenNumber(); -#ifdef SLIT - char *slit_placement = (char *) 0; + char *placement = (char *) 0; switch (screen->getSlitPlacement()) { - case Slit::TopLeft: slit_placement = "TopLeft"; break; - case Slit::CenterLeft: slit_placement = "CenterLeft"; break; - case Slit::BottomLeft: slit_placement = "BottomLeft"; break; - case Slit::TopCenter: slit_placement = "TopCenter"; break; - case Slit::BottomCenter: slit_placement = "BottomCenter"; break; - case Slit::TopRight: slit_placement = "TopRight"; break; - case Slit::BottomRight: slit_placement = "BottomRight"; break; - case Slit::CenterRight: default: slit_placement = "CenterRight"; break; + 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.placement: %s", screen_number, - slit_placement); - XrmPutLineResource(&new_openboxrc, rc_string); + 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.direction: %s", screen_number, - ((screen->getSlitDirection() == Slit::Horizontal) ? "Horizontal" : - "Vertical")); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.slit.onTop", screen_number); + config.setValue(rc_string, screen->getSlit()->isOnTop() ? "True" : "False"); - const char *rootcmd; - if ((rootcmd = screen->getRootCommand()) != NULL) { - sprintf(rc_string, "session.screen%d.rootCommand: %s", screen_number, - rootcmd); - XrmPutLineResource(&new_openboxrc, rc_string); - } + sprintf(rc_string, "session.screen%d.slit.autoHide", screen_number); + config.setValue(rc_string, screen->getSlit()->doAutoHide() ? + "True" : "False"); - sprintf(rc_string, "session.screen%d.slit.onTop: %s", screen_number, - ((screen->getSlit()->isOnTop()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); + config.setValue("session.opaqueMove", + (screen->doOpaqueMove()) ? "True" : "False"); + config.setValue("session.imageDither", + (screen->getImageControl()->doDither()) ? "True" : "False"); - sprintf(rc_string, "session.screen%d.slit.autoHide: %s", screen_number, - ((screen->getSlit()->doAutoHide()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); -#endif // SLIT + sprintf(rc_string, "session.screen%d.fullMaximization", screen_number); + config.setValue(rc_string, screen->doFullMax() ? "True" : "False"); - sprintf(rc_string, "session.opaqueMove: %s", - ((screen->doOpaqueMove()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.focusNewWindows", screen_number); + config.setValue(rc_string, screen->doFocusNew() ? "True" : "False"); - sprintf(rc_string, "session.imageDither: %s", - ((screen->getImageControl()->doDither()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.focusLastWindow", screen_number); + config.setValue(rc_string, screen->doFocusLast() ? "True" : "False"); - sprintf(rc_string, "session.screen%d.fullMaximization: %s", screen_number, - ((screen->doFullMax()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.rowPlacementDirection", screen_number); + config.setValue(rc_string, + screen->getRowPlacementDirection() == BScreen::LeftRight ? + "LeftToRight" : "RightToLeft"); - sprintf(rc_string, "session.screen%d.focusNewWindows: %s", screen_number, - ((screen->doFocusNew()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.colPlacementDirection", screen_number); + config.setValue(rc_string, + screen->getColPlacementDirection() == BScreen::TopBottom ? + "TopToBottom" : "BottomToTop"); - sprintf(rc_string, "session.screen%d.focusLastWindow: %s", screen_number, - ((screen->doFocusLast()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.screen%d.rowPlacementDirection: %s", - screen_number, - ((screen->getRowPlacementDirection() == BScreen::LeftRight) ? - "LeftToRight" : "RightToLeft")); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.screen%d.colPlacementDirection: %s", - screen_number, - ((screen->getColPlacementDirection() == BScreen::TopBottom) ? - "TopToBottom" : "BottomToTop")); - XrmPutLineResource(&new_openboxrc, rc_string); - - char *placement = (char *) 0; switch (screen->getPlacementPolicy()) { - case BScreen::CascadePlacement: - placement = "CascadePlacement"; - break; - - case BScreen::ColSmartPlacement: - placement = "ColSmartPlacement"; - break; - - case BScreen::RowSmartPlacement: + case BScreen::CascadePlacement: placement = "CascadePlacement"; break; + case BScreen::ColSmartPlacement: placement = "ColSmartPlacement"; break; default: - placement = "RowSmartPlacement"; - break; + case BScreen::RowSmartPlacement: placement = "RowSmartPlacement"; break; } - sprintf(rc_string, "session.screen%d.windowPlacement: %s", screen_number, - placement); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.windowPlacement", screen_number); + config.setValue(rc_string, placement); - sprintf(rc_string, "session.screen%d.windowZones: %i", screen_number, - screen->getWindowZones()); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.focusModel", screen_number); + config.setValue(rc_string, + (screen->isSloppyFocus() ? + (screen->doAutoRaise() ? "AutoRaiseSloppyFocus" : + "SloppyFocus") : "ClickToFocus")); - sprintf(rc_string, "session.screen%d.focusModel: %s", screen_number, - ((screen->isSloppyFocus()) ? - ((screen->doAutoRaise()) ? "AutoRaiseSloppyFocus" : - "SloppyFocus") : - "ClickToFocus")); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.workspaces", screen_number); + config.setValue(rc_string, screen->getWorkspaceCount()); - sprintf(rc_string, "session.screen%d.workspaces: %d", screen_number, - screen->getCount()); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.toolbar.onTop", screen_number); + config.setValue(rc_string, screen->getToolbar()->isOnTop() ? + "True" : "False"); - sprintf(rc_string, "session.screen%d.toolbar.onTop: %s", screen_number, - ((screen->getToolbar()->isOnTop()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.screen%d.toolbar.autoHide: %s", screen_number, - ((screen->getToolbar()->doAutoHide()) ? "True" : "False")); - XrmPutLineResource(&new_openboxrc, rc_string); - - char *toolbar_placement = (char *) 0; + sprintf(rc_string, "session.screen%d.toolbar.autoHide", screen_number); + config.setValue(rc_string, screen->getToolbar()->doAutoHide() ? + "True" : "False"); switch (screen->getToolbarPlacement()) { - case Toolbar::TopLeft: toolbar_placement = "TopLeft"; break; - case Toolbar::BottomLeft: toolbar_placement = "BottomLeft"; break; - case Toolbar::TopCenter: toolbar_placement = "TopCenter"; break; - case Toolbar::TopRight: toolbar_placement = "TopRight"; break; - case Toolbar::BottomRight: toolbar_placement = "BottomRight"; break; - case Toolbar::BottomCenter: default: - toolbar_placement = "BottomCenter"; break; + case Toolbar::TopLeft: placement = "TopLeft"; break; + case Toolbar::BottomLeft: placement = "BottomLeft"; break; + case Toolbar::TopCenter: placement = "TopCenter"; break; + case Toolbar::TopRight: placement = "TopRight"; break; + case Toolbar::BottomRight: placement = "BottomRight"; break; + default: + case Toolbar::BottomCenter: placement = "BottomCenter"; break; } - sprintf(rc_string, "session.screen%d.toolbar.placement: %s", screen_number, - toolbar_placement); - XrmPutLineResource(&new_openboxrc, rc_string); - - load_rc(screen); - - // these are static, but may not be saved in the users .openbox/rc, - // writing these resources will allow the user to edit them at a later - // time... but loading the defaults before saving allows us to rewrite the - // users changes... + sprintf(rc_string, "session.screen%d.toolbar.placement", screen_number); + config.setValue(rc_string, placement); #ifdef HAVE_STRFTIME - sprintf(rc_string, "session.screen%d.strftimeFormat: %s", screen_number, - screen->getStrftimeFormat()); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.strftimeFormat", screen_number); + config.setValue(rc_string, screen->getStrftimeFormat()); #else // !HAVE_STRFTIME - sprintf(rc_string, "session.screen%d.dateFormat: %s", screen_number, - ((screen->getDateFormat() == B_EuropeanDate) ? - "European" : "American")); - XrmPutLineResource(&new_openboxrc, rc_string); - - sprintf(rc_string, "session.screen%d.clockFormat: %d", screen_number, - ((screen->isClock24Hour()) ? 24 : 12)); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.dateFormat", screen_number); + config.setValue(rc_string, screen->getDateFormat() == B_EuropeanDate ? + "European" : "American"); + + sprintf(rc_string, "session.screen%d.clockFormat", screen_number); + config.setValue(rc_string, screen->isClock24Hour() ? 24 : 12); #endif // HAVE_STRFTIME - sprintf(rc_string, "session.screen%d.edgeSnapThreshold: %d", screen_number, - screen->getEdgeSnapThreshold()); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.edgeSnapThreshold", screen_number); + config.setValue(rc_string, screen->getEdgeSnapThreshold()); - sprintf(rc_string, "session.screen%d.toolbar.widthPercent: %d", - screen_number, screen->getToolbarWidthPercent()); - XrmPutLineResource(&new_openboxrc, rc_string); + sprintf(rc_string, "session.screen%d.toolbar.widthPercent", screen_number); + config.setValue(rc_string, screen->getToolbarWidthPercent()); - // write out the users workspace names + // write out the user's workspace names int i, len = 0; - for (i = 0; i < screen->getCount(); i++) + for (i = 0; i < screen->getWorkspaceCount(); i++) len += strlen((screen->getWorkspace(i)->getName()) ? - screen->getWorkspace(i)->getName() : "Null") + 1; + screen->getWorkspace(i)->getName() : "Null") + 1; char *resource_string = new char[len + 1024], *save_string = new char[len], *save_string_pos = save_string, *name_string_pos; if (save_string) { - for (i = 0; i < screen->getCount(); i++) { - len = strlen((screen->getWorkspace(i)->getName()) ? - screen->getWorkspace(i)->getName() : "Null") + 1; - name_string_pos = - (char *) ((screen->getWorkspace(i)->getName()) ? - screen->getWorkspace(i)->getName() : "Null"); - - while (--len) *(save_string_pos++) = *(name_string_pos++); - *(save_string_pos++) = ','; + for (i = 0; i < screen->getWorkspaceCount(); i++) { + len = strlen((screen->getWorkspace(i)->getName()) ? + screen->getWorkspace(i)->getName() : "Null") + 1; + name_string_pos = + (char *) ((screen->getWorkspace(i)->getName()) ? + screen->getWorkspace(i)->getName() : "Null"); + + while (--len) *(save_string_pos++) = *(name_string_pos++); + *(save_string_pos++) = ','; } } *(--save_string_pos) = '\0'; - sprintf(resource_string, "session.screen%d.workspaceNames: %s", - screen_number, save_string); - XrmPutLineResource(&new_openboxrc, resource_string); + sprintf(resource_string, "session.screen%d.workspaceNames", screen_number); + config.setValue(resource_string, save_string); delete [] resource_string; delete [] save_string; - } +/* + std::string save_string = screen->getWorkspace(0)->getName(); + for (unsigned int i = 1; i < screen->getWorkspaceCount(); ++i) { + save_string += ','; + save_string += screen->getWorkspace(i)->getName(); + } - XrmDatabase old_openboxrc = XrmGetFileDatabase(rc_file); + char *resource_string = new char[save_string.length() + 48]; + sprintf(resource_string, "session.screen%d.workspaceNames", screen_number); + config.setValue(rc_string, save_string); - XrmMergeDatabases(new_openboxrc, &old_openboxrc); - XrmPutFileDatabase(old_openboxrc, rc_file); - XrmDestroyDatabase(old_openboxrc); -} + delete [] resource_string;*/ + } + config.setAutoSave(true); + config.save(); +} void Openbox::load_rc(void) { if (!config.load()) @@ -1391,6 +1333,7 @@ void Openbox::load_rc(BScreen *screen) { sprintf(name_lookup, "session.screen%d.focusModel", screen_number); sprintf(class_lookup, "Session.Screen%d.FocusModel", screen_number); if (config.getValue(name_lookup, class_lookup, s)) { + cout << s << endl; if (0 == strncasecmp(s.c_str(), "clicktofocus", s.length())) { screen->saveAutoRaise(False); screen->saveSloppyFocus(False); diff --git a/src/openbox.h b/src/openbox.h index 33bcb213..3e3d1ef2 100644 --- a/src/openbox.h +++ b/src/openbox.h @@ -145,6 +145,9 @@ public: BScreen *getScreen(int); BScreen *searchScreen(Window); + inline obResource &getConfig() { + return config; + } inline const Time &getDoubleClickInterval(void) const { return resource.double_click_interval; } inline const Time &getLastTime(void) const { return last_time; } -- 2.45.2