From 9cd9d92bb1d66db9329bf5cd6e42e8b0096945e6 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 17 Apr 2002 08:30:55 +0000 Subject: [PATCH] configuration changes "done"!! on start, the config file is read entirely off the disc, and missing values are assigned defaults. the config file is immediately written back to the disk to populate missing defaults in the file. any time a config option is changed the control, the config file is re-written with the change. choosing reconfig will reload the current config file on the disc. on shutdown, nothing is written to the config file. --- CHANGELOG | 7 + src/Configmenu.cc | 76 ++++----- src/Screen.cc | 411 ++++++++++++++++++++++++++++++++++++++++++---- src/Screen.h | 132 ++++++++------- src/Slit.cc | 7 + src/Slit.h | 1 + src/Toolbar.cc | 13 +- src/Toolbar.h | 1 + src/Window.cc | 26 +-- src/Workspace.cc | 33 ++-- src/openbox.cc | 342 +++----------------------------------- src/openbox.h | 48 +++--- 12 files changed, 587 insertions(+), 510 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1460b9b4..afecb7c4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ Changelog for Openbox: 1.0.0: + * better handling of teh rc file and its configuration + options. The file is written each time an option in + the file is changed, instead of being written at + shutdown. This means that you can edit the file by + hand while in Openbox, and then choose reconfig or + restart to have it use the new rc file. (Ben Jansens) + * added a runtime option for hiding the toolbar. (Scott Moynes) * made shaded windows edge-snap correctly to the diff --git a/src/Configmenu.cc b/src/Configmenu.cc index 4548b89e..9de8864d 100644 --- a/src/Configmenu.cc +++ b/src/Configmenu.cc @@ -64,10 +64,10 @@ Configmenu::Configmenu(BScreen &scr) : Basemenu(scr), screen(scr) update(); setItemSelected(2, screen.getImageControl()->doDither()); - setItemSelected(3, screen.doOpaqueMove()); - setItemSelected(4, screen.doFullMax()); - setItemSelected(5, screen.doFocusNew()); - setItemSelected(6, screen.doFocusLast()); + setItemSelected(3, screen.opaqueMove()); + setItemSelected(4, screen.fullMax()); + setItemSelected(5, screen.focusNew()); + setItemSelected(6, screen.focusLast()); setItemSelected(7, screen.hideToolbar()); } @@ -96,30 +96,30 @@ void Configmenu::itemSelected(int button, int index) { } case 2: { // opaque move - screen.saveOpaqueMove((! screen.doOpaqueMove())); + screen.setOpaqueMove(!screen.opaqueMove()); - setItemSelected(index, screen.doOpaqueMove()); + setItemSelected(index, screen.opaqueMove()); break; } case 3: { // full maximization - screen.saveFullMax((! screen.doFullMax())); + screen.setFullMax(!screen.fullMax()); - setItemSelected(index, screen.doFullMax()); + setItemSelected(index, screen.fullMax()); break; } case 4: { // focus new windows - screen.saveFocusNew((! screen.doFocusNew())); + screen.setFocusNew(!screen.focusNew()); - setItemSelected(index, screen.doFocusNew()); + setItemSelected(index, screen.focusNew()); break; } case 5: { // focus last window on workspace - screen.saveFocusLast(!(screen.doFocusLast())); - setItemSelected(index, screen.doFocusLast()); + screen.setFocusLast(!screen.focusLast()); + setItemSelected(index, screen.focusLast()); break; } case 6:{ //toggle toolbar hide @@ -152,10 +152,10 @@ Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->screen) { "Auto Raise"), 3); update(); - setItemSelected(0, (! configmenu->screen.isSloppyFocus())); - setItemSelected(1, configmenu->screen.isSloppyFocus()); - setItemEnabled(2, configmenu->screen.isSloppyFocus()); - setItemSelected(2, configmenu->screen.doAutoRaise()); + setItemSelected(0, !configmenu->screen.sloppyFocus()); + setItemSelected(1, configmenu->screen.sloppyFocus()); + setItemEnabled(2, configmenu->screen.sloppyFocus()); + setItemSelected(2, configmenu->screen.autoRaise()); } void Configmenu::Focusmenu::itemSelected(int button, int index) { @@ -169,8 +169,8 @@ void Configmenu::Focusmenu::itemSelected(int button, int index) { switch (item->function()) { case 1: // click to focus - configmenu->screen.saveSloppyFocus(False); - configmenu->screen.saveAutoRaise(False); + configmenu->screen.setSloppyFocus(false); + configmenu->screen.setAutoRaise(false); if (! configmenu->screen.getOpenbox().getFocusedWindow()) XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(), @@ -187,23 +187,23 @@ void Configmenu::Focusmenu::itemSelected(int button, int index) { break; case 2: // sloppy focus - configmenu->screen.saveSloppyFocus(True); + configmenu->screen.setSloppyFocus(true); configmenu->screen.reconfigure(); break; case 3: // auto raise with sloppy focus - Bool change = ((configmenu->screen.doAutoRaise()) ? False : True); - configmenu->screen.saveAutoRaise(change); + bool change = ((configmenu->screen.autoRaise()) ? false : true); + configmenu->screen.setAutoRaise(change); break; } - setItemSelected(0, (! configmenu->screen.isSloppyFocus())); - setItemSelected(1, configmenu->screen.isSloppyFocus()); - setItemEnabled(2, configmenu->screen.isSloppyFocus()); - setItemSelected(2, configmenu->screen.doAutoRaise()); + setItemSelected(0, !configmenu->screen.sloppyFocus()); + setItemSelected(1, configmenu->screen.sloppyFocus()); + setItemEnabled(2, configmenu->screen.sloppyFocus()); + setItemSelected(2, configmenu->screen.autoRaise()); } Configmenu::Placementmenu::Placementmenu(Configmenu *cm) : @@ -234,7 +234,7 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm) : "Bottom to Top"), BScreen::BottomTop); update(); - switch (configmenu->screen.getPlacementPolicy()) { + switch (configmenu->screen.placementPolicy()) { case BScreen::RowSmartPlacement: setItemSelected(0, True); break; @@ -252,16 +252,16 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm) : break; } - Bool rl = (configmenu->screen.getRowPlacementDirection() == + Bool rl = (configmenu->screen.rowPlacementDirection() == BScreen::LeftRight), - tb = (configmenu->screen.getColPlacementDirection() == + tb = (configmenu->screen.colPlacementDirection() == BScreen::TopBottom); setItemSelected(4, rl); - setItemSelected(5, ! rl); + setItemSelected(5, !rl); setItemSelected(6, tb); - setItemSelected(7, ! tb); + setItemSelected(7, !tb); } void Configmenu::Placementmenu::itemSelected(int button, int index) { @@ -275,7 +275,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { switch (item->function()) { case BScreen::RowSmartPlacement: - configmenu->screen.savePlacementPolicy(item->function()); + configmenu->screen.setPlacementPolicy(item->function()); setItemSelected(0, True); setItemSelected(1, False); @@ -285,7 +285,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::ColSmartPlacement: - configmenu->screen.savePlacementPolicy(item->function()); + configmenu->screen.setPlacementPolicy(item->function()); setItemSelected(0, False); setItemSelected(1, True); @@ -295,7 +295,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::CascadePlacement: - configmenu->screen.savePlacementPolicy(item->function()); + configmenu->screen.setPlacementPolicy(item->function()); setItemSelected(0, False); setItemSelected(1, False); @@ -305,7 +305,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::BestFitPlacement: - configmenu->screen.savePlacementPolicy(item->function()); + configmenu->screen.setPlacementPolicy(item->function()); setItemSelected(0, False); setItemSelected(1, False); @@ -315,7 +315,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::LeftRight: - configmenu->screen.saveRowPlacementDirection(BScreen::LeftRight); + configmenu->screen.setRowPlacementDirection(BScreen::LeftRight); setItemSelected(4, True); setItemSelected(5, False); @@ -323,7 +323,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::RightLeft: - configmenu->screen.saveRowPlacementDirection(BScreen::RightLeft); + configmenu->screen.setRowPlacementDirection(BScreen::RightLeft); setItemSelected(4, False); setItemSelected(5, True); @@ -331,7 +331,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::TopBottom: - configmenu->screen.saveColPlacementDirection(BScreen::TopBottom); + configmenu->screen.setColPlacementDirection(BScreen::TopBottom); setItemSelected(5, True); setItemSelected(6, False); @@ -339,7 +339,7 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { break; case BScreen::BottomTop: - configmenu->screen.saveColPlacementDirection(BScreen::BottomTop); + configmenu->screen.setColPlacementDirection(BScreen::BottomTop); setItemSelected(5, False); setItemSelected(6, True); diff --git a/src/Screen.cc b/src/Screen.cc index e1231b8b..251faadd 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -189,6 +189,28 @@ static const char *getFontSize(const char *pattern, int *size) { BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), openbox(ob), config(conf) { + // default values + resource.full_max = false; + resource.focus_new = false; + resource.focus_last = false; + resource.row_direction = LeftRight; + resource.col_direction = TopBottom; + resource.workspaces = 1; + resource.sloppy_focus = true; + resource.auto_raise = false; + resource.zones = 1; + resource.placement_policy = CascadePlacement; +#ifdef HAVE_STRFTIME + resource.strftime_format = bstrdup("%I:%M %p"); +#else // !have_strftime + resource.date_format = B_AmericanDate; + resource.clock24hour = false; +#endif // HAVE_STRFTIME + resource.edge_snap_threshold = 4; + resource.image_dither = true; + resource.root_command = NULL; + resource.opaque_move = false; + event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask; @@ -213,11 +235,6 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), resource.tstyle.fontset = resource.wstyle.fontset = (XFontSet) 0; resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font = resource.wstyle.font = (XFontStruct *) 0; - resource.root_command = NULL; - -#ifdef HAVE_STRFTIME - resource.strftime_format = 0; -#endif // HAVE_STRFTIME #ifdef HAVE_GETPID pid_t bpid = getpid(); @@ -232,6 +249,9 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), openbox.getSessionCursor()); workspaceNames = new LinkedList; + + load(); // load config options from Resources + workspacesList = new LinkedList; rootmenuList = new LinkedList; netizenList = new LinkedList; @@ -243,8 +263,6 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), image_control->installRootColormap(); root_colormap_installed = True; - openbox.load_rc(this); - image_control->setDither(resource.image_dither); LoadStyle(); @@ -404,11 +422,13 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), for (int i = 0; i < resource.workspaces; ++i) { wkspc = new Workspace(*this, workspacesList->count()); workspacesList->insert(wkspc); + saveWorkspaceNames(); workspacemenu->insert(wkspc->getName(), wkspc->getMenu()); } } else { wkspc = new Workspace(*this, workspacesList->count()); workspacesList->insert(wkspc); + saveWorkspaceNames(); workspacemenu->insert(wkspc->getName(), wkspc->getMenu()); } @@ -824,6 +844,210 @@ XFontSet BScreen::createFontSet(const char *fontname) { return fs; } +void BScreen::setSloppyFocus(bool b) { + resource.sloppy_focus = b; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".focusModel" << ends; + config.setValue(s.str(), + (resource.sloppy_focus ? + (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus") + : "ClickToFocus")); +} + +void BScreen::setAutoRaise(bool a) { + resource.auto_raise = a; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".focusModel" << ends; + config.setValue(s.str(), + (resource.sloppy_focus ? + (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus") + : "ClickToFocus")); +} + +void BScreen::setImageDither(bool d) { + resource.image_dither = d; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".imageDither" << ends; + config.setValue(s.str(), resource.image_dither); +} + +void BScreen::setOpaqueMove(bool o) { + resource.opaque_move = o; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends; + config.setValue(s.str(), resource.opaque_move); +} + +void BScreen::setFullMax(bool f) { + resource.full_max = f; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends; + config.setValue(s.str(), resource.full_max); +} + +void BScreen::setFocusNew(bool f) { + resource.focus_new = f; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends; + config.setValue(s.str(), resource.focus_new); +} + +void BScreen::setFocusLast(bool f) { + resource.focus_last = f; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends; + config.setValue(s.str(), resource.focus_last); +} + +void BScreen::setWindowZones(int z) { + resource.zones = z; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".windowZones" << ends; + config.setValue(s.str(), resource.zones); +} + +void BScreen::setWorkspaceCount(int w) { + resource.workspaces = w; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".workspaces" << ends; + config.setValue(s.str(), resource.workspaces); +} + +void BScreen::setPlacementPolicy(int p) { + resource.placement_policy = p; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".windowPlacement" << ends; + const char *placement; + switch (resource.placement_policy) { + case CascadePlacement: placement = "CascadePlacement"; break; + case BestFitPlacement: placement = "BestFitPlacement"; break; + case ColSmartPlacement: placement = "ColSmartPlacement"; break; + default: + case RowSmartPlacement: placement = "RowSmartPlacement"; break; + } + config.setValue(s.str(), placement); +} + +void BScreen::setEdgeSnapThreshold(int t) { + resource.edge_snap_threshold = t; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends; + config.setValue(s.str(), resource.edge_snap_threshold); +} + +void BScreen::setRowPlacementDirection(int d) { + resource.row_direction = d; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" << + ends; + config.setValue(s.str(), + resource.row_direction == LeftRight ? + "LeftToRight" : "RightToLeft"); +} + +void BScreen::setColPlacementDirection(int d) { + resource.col_direction = d; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".colPlacementDirection" << + ends; + config.setValue(s.str(), + resource.col_direction == TopBottom ? + "TopToBottom" : "BottomToTop"); +} + +void BScreen::setRootCommand(const char *cmd) { +if (resource.root_command != NULL) + delete [] resource.root_command; + if (cmd != NULL) + resource.root_command = bstrdup(cmd); + else + resource.root_command = NULL; + // this doesn't save to the Resources config because it can't be changed + // inside Openbox, and this way we dont add an empty command which would over- + // ride the styles commend when none has been specified +} +#ifdef HAVE_STRFTIME +void BScreen::setStrftimeFormat(const char *f) { + if (resource.strftime_format != NULL) + delete [] resource.strftime_format; + + resource.strftime_format = bstrdup(f); + ostrstream s; + s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends; + config.setValue(s.str(), resource.strftime_format); +} + +#else // !HAVE_STRFTIME +void BScreen::setDateFormat(int f) { + resource.date_format = f; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".dateFormat" << ends; + config.setValue(s.str(), resource.date_format == B_EuropeanDate ? + "European" : "American"); +} + +void BScreen::setClock24Hour(Bool c) { + resource.clock24hour = c; + ostrstream s; + s << "session.screen" << getScreenNumber() << ".clockFormat" << ends; + config.setValue(s.str(), resource.clock24hour ? 24 : 12); +} +#endif // HAVE_STRFTIME + +void BScreen::setHideToolbar(bool b) { + resource.hide_toolbar = b; + if (resource.hide_toolbar) + getToolbar()->unMapToolbar(); + else + getToolbar()->mapToolbar(); + ostrstream s; + s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends; + config.setValue(s.str(), resource.hide_toolbar ? "True" : "False"); +} + +void BScreen::saveWorkspaceNames() { + ostrstream rc, names; + + for (int i = 0; i < resource.workspaces; i++) { + Workspace *w = getWorkspace(i); + if (w != NULL) { + names << w->getName(); + if (i < resource.workspaces-1) + names << ','; + } + } + names << ends; + + rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends; + config.setValue(rc.str(), names.str()); +} + +void BScreen::save() { + setSloppyFocus(resource.sloppy_focus); + setAutoRaise(resource.auto_raise); + setImageDither(resource.image_dither); + setOpaqueMove(resource.opaque_move); + setFullMax(resource.full_max); + setFocusNew(resource.focus_new); + setFocusLast(resource.focus_last); + setWindowZones(resource.zones); + setWorkspaceCount(resource.workspaces); + setPlacementPolicy(resource.placement_policy); + setEdgeSnapThreshold(resource.edge_snap_threshold); + setRowPlacementDirection(resource.row_direction); + setColPlacementDirection(resource.col_direction); + setRootCommand(resource.root_command); +#ifdef HAVE_STRFTIME + // it deletes the current value before setting the new one, so we have to + // duplicate the current value. + setStrftimeFormat(bstrdup(resource.strftime_format)); +#else // !HAVE_STRFTIME + setDateFormat(resource.date_format); + setClock24Hour(resource.clock24hour); +#endif // HAVE_STRFTIME + setHideToolbar(resource.hide_toolbar); +} + void BScreen::load() { std::ostrstream rscreen, rname, rclass; std::string s; @@ -836,6 +1060,153 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), b)) resource.hide_toolbar = b; + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "fullMaximization" << ends; + rclass << rscreen.str() << "FullMaximization" << ends; + if (config.getValue(rname.str(), rclass.str(), b)) + resource.full_max = b; + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "focusNewWindows" << ends; + rclass << rscreen.str() << "FocusNewWindows" << ends; + if (config.getValue(rname.str(), rclass.str(), b)) + resource.focus_new = b; + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "focusLastWindow" << ends; + rclass << rscreen.str() << "FocusLastWindow" << ends; + if (config.getValue(rname.str(), rclass.str(), b)) + resource.focus_last = b; + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "rowPlacementDirection" << ends; + rclass << rscreen.str() << "RowPlacementDirection" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) { + if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length())) + resource.row_direction = RightLeft; + else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length())) + resource.row_direction = LeftRight; + } + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "colPlacementDirection" << ends; + rclass << rscreen.str() << "ColPlacementDirection" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) { + if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length())) + resource.col_direction = BottomTop; + else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length())) + resource.col_direction = TopBottom; + } + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "workspaces" << ends; + rclass << rscreen.str() << "Workspaces" << ends; + if (config.getValue(rname.str(), rclass.str(), l)) + resource.workspaces = l; + + removeWorkspaceNames(); + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "workspaceNames" << ends; + rclass << rscreen.str() << "WorkspaceNames" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) { + std::string::const_iterator it = s.begin(), end = s.end(); + while(1) { + std::string::const_iterator tmp = it;// current string.begin() + it = std::find(tmp, end, ','); // look for comma between tmp and end + std::string name(tmp, it); // name = s[tmp:it] + addWorkspaceName(name.c_str()); + if (it == end) + break; + ++it; + } + } + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "focusModel" << ends; + rclass << rscreen.str() << "FocusModel" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) { + if (0 == strncasecmp(s.c_str(), "ClickToFocus", s.length())) { + resource.auto_raise = false; + resource.sloppy_focus = false; + } else if (0 == strncasecmp(s.c_str(), "AutoRaiseSloppyFocus", + s.length())) { + resource.sloppy_focus = true; + resource.auto_raise = true; + } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) { + resource.sloppy_focus = true; + resource.auto_raise = false; + } + } + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "windowZones" << ends; + rclass << rscreen.str() << "WindowZones" << ends; + if (config.getValue(rname.str(), rclass.str(), l)) + resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1; + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "windowPlacement" << ends; + rclass << rscreen.str() << "WindowPlacement" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) { + if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length())) + resource.placement_policy = RowSmartPlacement; + else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length())) + resource.placement_policy = ColSmartPlacement; + else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length())) + resource.placement_policy = BestFitPlacement; + else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length())) + resource.placement_policy = CascadePlacement; + } + +#ifdef HAVE_STRFTIME + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "strftimeFormat" << ends; + rclass << rscreen.str() << "StrftimeFormat" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) + resource.strftime_format = bstrdup(s.c_str()); +#else // !HAVE_STRFTIME + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "dateFormat" << ends; + rclass << rscreen.str() << "DateFormat" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) { + if (strncasecmp(s.c_str(), "European", s.length())) + resource.date_format = B_EuropeanDate; + else if (strncasecmp(s.c_str(), "American", s.length())) + resource.date_format = B_AmericanDate; + } + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "clockFormat" << ends; + rclass << rscreen.str() << "ClockFormat" << ends; + if (config.getValue(rname.str(), rclass.str(), l)) { + if (clock == 24) + resource.clock24hour = true; + else if (clock == 12) + resource.clock24hour = false; +#endif // HAVE_STRFTIME + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "edgeSnapThreshold" << ends; + rclass << rscreen.str() << "EdgeSnapThreshold" << ends; + if (config.getValue(rname.str(), rclass.str(), l)) + resource.edge_snap_threshold = l; + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "imageDither" << ends; + rclass << rscreen.str() << "ImageDither" << ends; + if (config.getValue(rname.str(), rclass.str(), b)) + resource.image_dither = b; + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "rootCommand" << ends; + rclass << rscreen.str() << "RootCommand" << ends; + if (config.getValue(rname.str(), rclass.str(), s)) + resource.root_command = bstrdup(s.c_str()); + + rname.seekp(0); rclass.seekp(0); + rname << rscreen.str() << "opaqueMove" << ends; + rclass << rscreen.str() << "OpaqueMove" << ends; + resource.opaque_move = b; } void BScreen::reconfigure(void) { @@ -1008,7 +1379,7 @@ void BScreen::rereadMenu(void) { void BScreen::removeWorkspaceNames(void) { while (workspaceNames->count()) - delete [] workspaceNames->remove(0); + delete [] workspaceNames->remove(0); } @@ -1362,6 +1733,7 @@ OpenboxWindow *BScreen::getIcon(int index) { int BScreen::addWorkspace(void) { Workspace *wkspc = new Workspace(*this, workspacesList->count()); workspacesList->insert(wkspc); + saveWorkspaceNames(); workspacemenu->insert(wkspc->getName(), wkspc->getMenu(), wkspc->getWorkspaceID() + 2); @@ -1575,21 +1947,10 @@ void BScreen::raiseWindows(Window *workspace_stack, int num) { } -#ifdef HAVE_STRFTIME -void BScreen::saveStrftimeFormat(const char *format) { - if (resource.strftime_format) - delete [] resource.strftime_format; - - resource.strftime_format = bstrdup(format); -} -#endif // HAVE_STRFTIME - - void BScreen::addWorkspaceName(const char *name) { workspaceNames->insert(bstrdup(name)); } - char* BScreen::getNameOfWorkspace(int id) { char *name = (char *) 0; @@ -2280,15 +2641,3 @@ void BScreen::hideGeometry(void) { geom_visible = False; } } - -void BScreen::setHideToolbar(bool b) { - resource.hide_toolbar = b; - if (resource.hide_toolbar) - getToolbar()->unMapToolbar(); - else - getToolbar()->mapToolbar(); - ostrstream s; - s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends; - config.setValue(s.str(), resource.hide_toolbar ? "True" : "False"); -} - diff --git a/src/Screen.h b/src/Screen.h index 3d03f53c..8acae7ee 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -132,23 +132,21 @@ private: ToolbarStyle tstyle; MenuStyle mstyle; - Bool sloppy_focus, auto_raise, - auto_edge_balance, image_dither, ordered_dither, opaque_move, full_max, - focus_new, focus_last; - bool hide_toolbar; + bool sloppy_focus, auto_raise, auto_edge_balance, image_dither, focus_last, + ordered_dither, opaque_move, hide_toolbar, full_max, focus_new; BColor border_color; Resource styleconfig; - int workspaces, toolbar_placement, toolbar_width_percent, placement_policy, - edge_snap_threshold, row_direction, col_direction; + int workspaces, placement_policy, edge_snap_threshold, row_direction, + col_direction; unsigned int handle_width, bevel_width, frame_width, border_width; - unsigned int zones; // number of zones to be used when alt-resizing a window + int zones; // number of zones to be used when alt-resizing a window #ifdef HAVE_STRFTIME char *strftime_format; #else // !HAVE_STRFTIME - Bool clock24hour; + bool clock24hour; int date_format; #endif // HAVE_STRFTIME @@ -175,21 +173,7 @@ public: BScreen(Openbox &, int, Resource &); ~BScreen(); - inline const Bool &isSloppyFocus() const - { return resource.sloppy_focus; } - inline const Bool &isRootColormapInstalled() const - { return root_colormap_installed; } - inline const Bool &doAutoRaise() const { return resource.auto_raise; } inline const Bool &isScreenManaged() const { return managed; } - inline const Bool &doImageDither() const - { return resource.image_dither; } - inline const Bool &doOrderedDither() const - { return resource.ordered_dither; } - inline const Bool &doOpaqueMove() const { return resource.opaque_move; } - inline const Bool &doFullMax() const { return resource.full_max; } - inline const Bool &doFocusNew() const { return resource.focus_new; } - inline const Bool &doFocusLast() const { return resource.focus_last; } - inline const GC &getOpGC() const { return opGC; } inline Openbox &getOpenbox() { return openbox; } @@ -201,16 +185,14 @@ public: inline Slit *getSlit() { return slit; } #endif // SLIT - inline int getWindowZones() const - { return resource.zones; } - inline void saveWindowZones(int z) { resource.zones = z; } - inline Toolbar *getToolbar() { return toolbar; } inline Workspace *getWorkspace(int w) { return workspacesList->find(w); } inline Workspace *getCurrentWorkspace() { return current_workspace; } inline Workspacemenu *getWorkspacemenu() { return workspacemenu; } + + inline void iconUpdate() { iconmenu->update(); } inline const unsigned int &getHandleWidth() const { return resource.handle_width; } @@ -225,51 +207,63 @@ public: { return current_workspace->getWorkspaceID(); } inline const int getWorkspaceCount() { return workspacesList->count(); } inline const int getIconCount() { return iconList->count(); } - inline const int &getNumberOfWorkspaces() const - { return resource.workspaces; } - inline const int &getPlacementPolicy() const - { return resource.placement_policy; } - inline const int &getEdgeSnapThreshold() const - { return resource.edge_snap_threshold; } - inline const int &getRowPlacementDirection() const - { return resource.row_direction; } - inline const int &getColPlacementDirection() const - { return resource.col_direction; } - - inline void saveRootCommand(const char *cmd) { - if (resource.root_command != NULL) - delete [] resource.root_command; - if (cmd != NULL) - resource.root_command = bstrdup(cmd); - else - resource.root_command = NULL; - } - inline const char *getRootCommand() const - { return resource.root_command; } - + + inline const Bool &isRootColormapInstalled() const + { return root_colormap_installed; } inline void setRootColormapInstalled(Bool r) { root_colormap_installed = r; } - inline void saveSloppyFocus(Bool s) { resource.sloppy_focus = s; } - inline void saveAutoRaise(Bool a) { resource.auto_raise = a; } - inline void saveWorkspaces(int w) { resource.workspaces = w; } - inline void savePlacementPolicy(int p) { resource.placement_policy = p; } - inline void saveRowPlacementDirection(int d) { resource.row_direction = d; } - inline void saveColPlacementDirection(int d) { resource.col_direction = d; } - inline void saveEdgeSnapThreshold(int t) - { resource.edge_snap_threshold = t; } - inline void saveImageDither(Bool d) { resource.image_dither = d; } - inline void saveOpaqueMove(Bool o) { resource.opaque_move = o; } - inline void saveFullMax(Bool f) { resource.full_max = f; } - inline void saveFocusNew(Bool f) { resource.focus_new = f; } - inline void saveFocusLast(Bool f) { resource.focus_last = f; } - inline void iconUpdate() { iconmenu->update(); } + + inline bool sloppyFocus() const { return resource.sloppy_focus; } + void setSloppyFocus(bool s); + + inline bool autoRaise() const { return resource.auto_raise; } + void setAutoRaise(bool a); + + inline bool imageDither() const { return resource.image_dither; } + void setImageDither(bool d); + + inline bool orderedDither() const { return resource.ordered_dither; } + + inline bool opaqueMove() const { return resource.opaque_move; } + void setOpaqueMove(bool o); + + inline bool fullMax() const { return resource.full_max; } + void setFullMax(bool f); + + inline bool focusNew() const { return resource.focus_new; } + void setFocusNew(bool f); + + inline bool focusLast() const { return resource.focus_last; } + void setFocusLast(bool f); + + inline int getWindowZones() const { return resource.zones; } + void setWindowZones(int z); + + inline int workspaceCount() const { return resource.workspaces; } + void setWorkspaceCount(int w); + + inline int placementPolicy() const { return resource.placement_policy; } + void setPlacementPolicy(int p); + + inline int edgeSnapThreshold() const { return resource.edge_snap_threshold; } + void setEdgeSnapThreshold(int t); + + inline int rowPlacementDirection() const { return resource.row_direction; } + void setRowPlacementDirection(int d); + + inline int colPlacementDirection() const { return resource.col_direction; } + void setColPlacementDirection(int d); + + inline char *rootCommand() const { return resource.root_command; } + inline void setRootCommand(const char *cmd); + #ifdef HAVE_STRFTIME - inline char *getStrftimeFormat() { return resource.strftime_format; } - void saveStrftimeFormat(const char *); + inline char *strftimeFormat() { return resource.strftime_format; } + void setStrftimeFormat(const char *); #else // !HAVE_STRFTIME - inline int getDateFormat() { return resource.date_format; } - inline void saveDateFormat(int f) { resource.date_format = f; } - inline Bool isClock24Hour() { return resource.clock24hour; } - inline void saveClock24Hour(Bool c) { resource.clock24hour = c; } + inline int dateFormat() { return resource.date_format; } + void setDateFormat(int f); + inline bool clock24Hour() { return resource.clock24hour; } + void setClock24Hour(Bool c); #endif // HAVE_STRFTIME inline bool hideToolbar() const { return resource.hide_toolbar; } @@ -286,6 +280,7 @@ public: void removeWorkspaceNames(); void addWorkspaceName(const char *); + void saveWorkspaceNames(); void addNetizen(Netizen *); void removeNetizen(Window); void addIcon(OpenboxWindow *); @@ -299,6 +294,7 @@ public: void raiseFocus(); void reconfigure(); void load(); + void save(); void rereadMenu(); void shutdown(); void showPosition(int, int); diff --git a/src/Slit.cc b/src/Slit.cc index 7124e003..19796814 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -256,6 +256,13 @@ void Slit::setDirection(int d) { m_direction == Horizontal ? "Horizontal" : "Vertical"); } +void Slit::save() { + setOnTop(m_ontop); + setAutoHide(m_autohide); + setPlacement(m_placement); + setDirection(m_direction); +} + void Slit::load() { std::ostrstream rscreen, rname, rclass; std::string s; diff --git a/src/Slit.h b/src/Slit.h index 60bbdfcb..cb6b454a 100644 --- a/src/Slit.h +++ b/src/Slit.h @@ -137,6 +137,7 @@ public: void removeClient(Window, Bool = True); void reconfigure(); void load(); + void save(); void reposition(); void shutdown(); diff --git a/src/Toolbar.cc b/src/Toolbar.cc index b6469957..f5aa7f90 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -257,6 +257,13 @@ void Toolbar::setPlacement(int p) { config.setValue(s.str(), placement); } +void Toolbar::save() { + setOnTop(m_ontop); + setAutoHide(m_autohide); + setWidthPercent(m_width_percent); + setPlacement(m_placement); +} + void Toolbar::load() { std::ostrstream rscreen, rname, rclass; std::string s; @@ -379,7 +386,7 @@ void Toolbar::reconfigure() { tt = localtime(&ttmp); if (tt) { char t[1025], *time_string = (char *) 0; - int len = strftime(t, 1024, screen.getStrftimeFormat(), tt); + int len = strftime(t, 1024, screen.strftimeFormat(), tt); t[len++-1] = ' '; // add a space to the string for padding t[len] = '\0'; @@ -616,7 +623,7 @@ void Toolbar::checkClock(Bool redraw, Bool date) { if (redraw) { #ifdef HAVE_STRFTIME char t[1024]; - if (! strftime(t, 1024, screen.getStrftimeFormat(), tt)) + if (! strftime(t, 1024, screen.strftimeFormat(), tt)) return; #else // !HAVE_STRFTIME char t[9]; @@ -950,7 +957,7 @@ void Toolbar::edit() { return; XSetInputFocus(display, frame.workspace_label, - ((screen.isSloppyFocus()) ? RevertToPointerRoot : + ((screen.sloppyFocus()) ? RevertToPointerRoot : RevertToParent), CurrentTime); XClearWindow(display, frame.workspace_label); diff --git a/src/Toolbar.h b/src/Toolbar.h index c1b3c2cd..ecf2fd2a 100644 --- a/src/Toolbar.h +++ b/src/Toolbar.h @@ -136,6 +136,7 @@ public: void edit(); void reconfigure(); void load(); + void save(); void mapToolbar(); void unMapToolbar(); #ifdef HAVE_STRFTIME diff --git a/src/Window.cc b/src/Window.cc index da4d6437..c2e8644b 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -259,7 +259,7 @@ OpenboxWindow::OpenboxWindow(Openbox &o, Window w, BScreen *s) : openbox(o) { associateClientWindow(); - if (! screen->isSloppyFocus()) + if (! screen->sloppyFocus()) openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask, GrabModeSync, GrabModeSync, None, None); @@ -847,7 +847,7 @@ void OpenboxWindow::reconfigure(void) { configure(frame.x, frame.y, frame.width, frame.height); - if (! screen->isSloppyFocus()) + if (! screen->sloppyFocus()) openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask, GrabModeSync, GrabModeSync, None, None); else @@ -1407,7 +1407,7 @@ Bool OpenboxWindow::setInputFocus(void) { XSendEvent(display, client.window, False, NoEventMask, &ce); } - if (screen->isSloppyFocus() && screen->doAutoRaise()) + if (screen->sloppyFocus() && screen->autoRaise()) timer->start(); ret = True; @@ -1465,7 +1465,7 @@ void OpenboxWindow::deiconify(Bool reassoc, Bool raise) { XMapSubwindows(display, frame.window); XMapWindow(display, frame.window); - if (flags.iconic && screen->doFocusNew()) setInputFocus(); + if (flags.iconic && screen->focusNew()) setInputFocus(); flags.visible = True; flags.iconic = False; @@ -1553,7 +1553,7 @@ void OpenboxWindow::maximize(unsigned int button) { dh -= client.base_height; dh -= frame.y_border; - if (! screen->doFullMax()) + if (! screen->fullMax()) dh -= screen->getToolbar()->getExposedHeight() + frame.border_w; if (dw < client.min_width) dw = client.min_width; @@ -1573,7 +1573,7 @@ void OpenboxWindow::maximize(unsigned int button) { dx += ((screen->size().w() - dw) / 2) - frame.border_w; - if (screen->doFullMax()) { + if (screen->fullMax()) { dy += ((screen->size().h() - dh) / 2) - frame.border_w; } else { dy += (((screen->size().h() - screen->getToolbar()->getExposedHeight()) @@ -1740,7 +1740,7 @@ void OpenboxWindow::setFocusFlag(Bool focus) { XSetWindowBorder(display, frame.plate, frame.uborder_pixel); } - if (screen->isSloppyFocus() && screen->doAutoRaise() && timer->isTiming()) + if (screen->sloppyFocus() && screen->autoRaise() && timer->isTiming()) timer->stop(); } @@ -2258,7 +2258,7 @@ void OpenboxWindow::mapNotifyEvent(XMapEvent *ne) { redrawAllButtons(); - if (flags.transient || screen->doFocusNew()) + if (flags.transient || screen->focusNew()) setInputFocus(); else setFocusFlag(False); @@ -2641,7 +2641,7 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { shade(); } - if (! (flags.focused || screen->isSloppyFocus()) ) { + if (! (flags.focused || screen->sloppyFocus()) ) { setInputFocus(); // any click focus' the window in 'click to focus' } if (stack_change < 0) { @@ -2722,7 +2722,7 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { flags.moving = False; openbox.maskWindowEvents(0, (OpenboxWindow *) 0); - if (!screen->doOpaqueMove()) { + if (!screen->opaqueMove()) { XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), frame.move_x, frame.move_y, frame.resize_w - 1, frame.resize_h - 1); @@ -2781,7 +2781,7 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { openbox.maskWindowEvents(client.window, this); - if (! screen->doOpaqueMove()) { + if (! screen->opaqueMove()) { openbox.grab(); frame.move_x = frame.x; @@ -2802,7 +2802,7 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { dx -= frame.border_w; dy -= frame.border_w; - int snap_distance = screen->getEdgeSnapThreshold(); + int snap_distance = screen->edgeSnapThreshold(); // width/height of the snapping window unsigned int snap_w = frame.width + (frame.border_w * 2); unsigned int snap_h = size().h() + (frame.border_w * 2); @@ -2843,7 +2843,7 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { dy = dbby - snap_h; } - if (screen->doOpaqueMove()) { + if (screen->opaqueMove()) { configure(dx, dy, frame.width, frame.height); } else { XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), diff --git a/src/Workspace.cc b/src/Workspace.cc index 9c44d797..41eb3ef0 100644 --- a/src/Workspace.cc +++ b/src/Workspace.cc @@ -120,7 +120,7 @@ const int Workspace::removeWindow(OpenboxWindow *w) { if (w->isTransient() && w->getTransientFor() && w->getTransientFor()->isVisible()) { w->getTransientFor()->setInputFocus(); - } else if (screen.isSloppyFocus()) { + } else if (screen.sloppyFocus()) { screen.getOpenbox().setFocusedWindow((OpenboxWindow *) 0); } else { OpenboxWindow *top = stackingList->first(); @@ -321,6 +321,7 @@ void Workspace::setName(char *new_name) { clientmenu->setLabel(name); clientmenu->update(); + screen.saveWorkspaceNames(); } @@ -406,22 +407,22 @@ inline Point *Workspace::rowSmartPlacement(const Size &win_size, int test_x, test_y, place_x = 0, place_y = 0; int start_pos = 0; int change_y = - ((screen.getColPlacementDirection() == BScreen::TopBottom) ? 1 : -1); + ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1); int change_x = - ((screen.getRowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); + ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); int delta_x = 8, delta_y = 8; LinkedListIterator it(windowList); - test_y = (screen.getColPlacementDirection() == BScreen::TopBottom) ? + test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ? start_pos : screen.size().h() - win_size.h() - start_pos; while(!placed && - ((screen.getColPlacementDirection() == BScreen::BottomTop) ? + ((screen.colPlacementDirection() == BScreen::BottomTop) ? test_y > 0 : test_y + win_size.h() < (signed) space.h())) { - test_x = (screen.getRowPlacementDirection() == BScreen::LeftRight) ? + test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ? start_pos : space.w() - win_size.w() - start_pos; while (!placed && - ((screen.getRowPlacementDirection() == BScreen::RightLeft) ? + ((screen.rowPlacementDirection() == BScreen::RightLeft) ? test_x > 0 : test_x + win_size.w() < (signed) space.w())) { placed = true; @@ -467,23 +468,23 @@ inline Point * Workspace::colSmartPlacement(const Size &win_size, int test_x, test_y; int start_pos = 0; int change_y = - ((screen.getColPlacementDirection() == BScreen::TopBottom) ? 1 : -1); + ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1); int change_x = - ((screen.getRowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); + ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1); int delta_x = 8, delta_y = 8; LinkedListIterator it(windowList); - test_x = (screen.getRowPlacementDirection() == BScreen::LeftRight) ? + test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ? start_pos : screen.size().w() - win_size.w() - start_pos; while(!placed && - ((screen.getRowPlacementDirection() == BScreen::RightLeft) ? + ((screen.rowPlacementDirection() == BScreen::RightLeft) ? test_x > 0 : test_x + win_size.w() < (signed) space.w())) { - test_y = (screen.getColPlacementDirection() == BScreen::TopBottom) ? + test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ? start_pos : screen.size().h() - win_size.h() - start_pos; while(!placed && - ((screen.getColPlacementDirection() == BScreen::BottomTop) ? + ((screen.colPlacementDirection() == BScreen::BottomTop) ? test_y > 0 : test_y + win_size.h() < (signed) space.h())){ placed = true; @@ -555,9 +556,9 @@ void Workspace::placeWindow(OpenboxWindow *win) { (screen.getBorderWidth() * 4), start_pos = 0, change_y = - ((screen.getColPlacementDirection() == BScreen::TopBottom) ? 1 : -1), + ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1), change_x = - ((screen.getRowPlacementDirection() == BScreen::LeftRight) ? 1 : -1), + ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1), delta_x = 8, delta_y = 8; LinkedListIterator it(windowList); @@ -570,7 +571,7 @@ void Workspace::placeWindow(OpenboxWindow *win) { win->size().h()+screen.getBorderWidth() * 4); Point *place = NULL; - switch (screen.getPlacementPolicy()) { + switch (screen.placementPolicy()) { case BScreen::BestFitPlacement: place = bestFitPlacement(window_size, space); break; diff --git a/src/openbox.cc b/src/openbox.cc index e4ea5306..c86b2124 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -201,7 +201,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) menuTimestamps = new LinkedList; - load_rc(); + load(); #ifdef HAVE_GETPID openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False); @@ -226,6 +226,9 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) ::exit(3); } + // save current settings and default values + save(); + XSynchronize(getXDisplay(), False); XSync(getXDisplay(), False); @@ -239,7 +242,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) } -Openbox::~Openbox(void) { +Openbox::~Openbox() { while (screenList->count()) delete screenList->remove(0); @@ -583,7 +586,7 @@ void Openbox::process_event(XEvent *e) { (screen = searchScreen(e->xcrossing.window))) { screen->getImageControl()->installRootColormap(); } else if ((win = searchWindow(e->xcrossing.window))) { - if (win->getScreen()->isSloppyFocus() && + if (win->getScreen()->sloppyFocus() && (! win->isFocused()) && (! no_focus)) { grab(); @@ -748,11 +751,8 @@ void Openbox::process_event(XEvent *e) { Bool Openbox::handleSignal(int sig) { switch (sig) { case SIGHUP: - reconfigure(); - break; - case SIGUSR1: - reload_rc(); + reconfigure(); break; case SIGUSR2: @@ -957,7 +957,7 @@ void Openbox::restart(const char *prog) { } -void Openbox::shutdown(void) { +void Openbox::shutdown() { BaseDisplay::shutdown(); XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime); @@ -967,14 +967,15 @@ void Openbox::shutdown(void) { s->shutdown(); XSync(getXDisplay(), False); - - save_rc(); } -void Openbox::save_rc(void) { +void Openbox::save() { config.setAutoSave(false); + // save all values as they are so that the defaults will be written to the rc + // file + config.setValue("session.menuFile", getMenuFilename()); config.setValue("session.colorsPerChannel", resource.colors_per_channel); @@ -985,122 +986,20 @@ void Openbox::save_rc(void) { (resource.auto_raise_delay.tv_usec / 1000))); config.setValue("session.cacheLife", (long)resource.cache_life / 60000); config.setValue("session.cacheMax", (long)resource.cache_max); + config.setValue("session.styleFile", resource.style_file); LinkedListIterator it(screenList); - for (BScreen *screen = it.current(); screen; it++, screen = it.current()) { -// ScreenList::iterator it = screenList.begin(); -// for (; it != screenList.end(); ++it) { -// BScreen *screen = *it; - char rc_string[1024]; - const int screen_number = screen->getScreenNumber(); - - config.setValue("session.opaqueMove", - (screen->doOpaqueMove()) ? "True" : "False"); - config.setValue("session.imageDither", - (screen->getImageControl()->doDither()) ? "True" : "False"); - - sprintf(rc_string, "session.screen%d.fullMaximization", screen_number); - config.setValue(rc_string, screen->doFullMax() ? "True" : "False"); - - sprintf(rc_string, "session.screen%d.focusNewWindows", screen_number); - config.setValue(rc_string, screen->doFocusNew() ? "True" : "False"); - - sprintf(rc_string, "session.screen%d.focusLastWindow", screen_number); - config.setValue(rc_string, screen->doFocusLast() ? "True" : "False"); - - 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.colPlacementDirection", screen_number); - config.setValue(rc_string, - screen->getColPlacementDirection() == BScreen::TopBottom ? - "TopToBottom" : "BottomToTop"); - - const char *placement; - switch (screen->getPlacementPolicy()) { - case BScreen::CascadePlacement: placement = "CascadePlacement"; break; - case BScreen::BestFitPlacement: placement = "BestFitPlacement"; break; - case BScreen::ColSmartPlacement: placement = "ColSmartPlacement"; break; - default: - case BScreen::RowSmartPlacement: placement = "RowSmartPlacement"; break; - } - sprintf(rc_string, "session.screen%d.windowPlacement", screen_number); - config.setValue(rc_string, placement); - - 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.workspaces", screen_number); - config.setValue(rc_string, screen->getWorkspaceCount()); - -#ifdef HAVE_STRFTIME - 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", 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", screen_number); - config.setValue(rc_string, screen->getEdgeSnapThreshold()); - - // write out the user's workspace names - int i, len = 0; - for (i = 0; i < screen->getWorkspaceCount(); i++) - len += strlen((screen->getWorkspace(i)->getName()) ? - 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->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", 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(); - } - - char *resource_string = new char[save_string.length() + 48]; - sprintf(resource_string, "session.screen%d.workspaceNames", screen_number); - config.setValue(rc_string, save_string); - - delete [] resource_string;*/ + for (BScreen *s = it.current(); s != NULL; it++, s = it.current()) { + s->save(); + s->getToolbar()->save(); + s->getSlit()->save(); } config.setAutoSave(true); config.save(); } -void Openbox::load_rc(void) { +void Openbox::load() { if (!config.load()) return; @@ -1162,207 +1061,18 @@ void Openbox::load_rc(void) { } -void Openbox::load_rc(BScreen *screen) { - ASSERT (screen != NULL); - const int screen_number = screen->getScreenNumber(); - ASSERT (screen_number >= 0); - - if (!config.load()) - return; - - std::string s; - long l; - bool b; - char name_lookup[1024], class_lookup[1024]; - - sprintf(name_lookup, "session.screen%d.fullMaximization", screen_number); - sprintf(class_lookup, "Session.Screen%d.FullMaximization", screen_number); - if (config.getValue(name_lookup, class_lookup, b)) - screen->saveFullMax((Bool)b); - else - screen->saveFullMax(False); - - sprintf(name_lookup, "session.screen%d.focusNewWindows", screen_number); - sprintf(class_lookup, "Session.Screen%d.FocusNewWindows", screen_number); - if (config.getValue(name_lookup, class_lookup, b)) - screen->saveFocusNew((Bool)b); - else - screen->saveFocusNew(False); - - sprintf(name_lookup, "session.screen%d.focusLastWindow", screen_number); - sprintf(class_lookup, "Session.Screen%d.focusLastWindow", screen_number); - if (config.getValue(name_lookup, class_lookup, b)) - screen->saveFocusLast((Bool)b); - else - screen->saveFocusLast(False); - - sprintf(name_lookup, "session.screen%d.rowPlacementDirection", - screen_number); - sprintf(class_lookup, "Session.Screen%d.RowPlacementDirection", - screen_number); - if (config.getValue(name_lookup, class_lookup, s)) { - if (0 == strncasecmp(s.c_str(), "righttoleft", s.length())) - screen->saveRowPlacementDirection(BScreen::RightLeft); - else - screen->saveRowPlacementDirection(BScreen::LeftRight); - } else - screen->saveRowPlacementDirection(BScreen::LeftRight); - - sprintf(name_lookup, "session.screen%d.colPlacementDirection", - screen_number); - sprintf(class_lookup, "Session.Screen%d.ColPlacementDirection", - screen_number); - if (config.getValue(name_lookup, class_lookup, s)) { - if (0 == strncasecmp(s.c_str(), "bottomtotop", s.length())) - screen->saveColPlacementDirection(BScreen::BottomTop); - else - screen->saveColPlacementDirection(BScreen::TopBottom); - } else - screen->saveColPlacementDirection(BScreen::TopBottom); - - sprintf(name_lookup, "session.screen%d.workspaces", screen_number); - sprintf(class_lookup, "Session.Screen%d.Workspaces", screen_number); - if (config.getValue(name_lookup, class_lookup, l)) - screen->saveWorkspaces(l); - else - screen->saveWorkspaces(1); - - screen->removeWorkspaceNames(); - sprintf(name_lookup, "session.screen%d.workspaceNames", screen_number); - sprintf(class_lookup, "Session.Screen%d.WorkspaceNames", screen_number); - if (config.getValue(name_lookup, class_lookup, s)) { - // for (int i = 0; i < screen->getNumberOfWorkspaces(); i++) { - std::string::const_iterator it = s.begin(), end = s.end(); - while(1) { - std::string::const_iterator tmp = it;// current string.begin() - it = std::find(tmp, end, ','); // look for comma between tmp and end - std::string name(tmp, it); // name = s[tmp:it] - screen->addWorkspaceName(name.c_str()); - if (it == end) - break; - ++it; - } - } - - 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)) { - if (0 == strncasecmp(s.c_str(), "clicktofocus", s.length())) { - screen->saveAutoRaise(False); - screen->saveSloppyFocus(False); - } else if (0 == strncasecmp(s.c_str(), "autoraisesloppyfocus", - s.length())) { - screen->saveSloppyFocus(True); - screen->saveAutoRaise(True); - } else { - screen->saveSloppyFocus(True); - screen->saveAutoRaise(False); - } - } else { - screen->saveSloppyFocus(True); - screen->saveAutoRaise(False); - } - - sprintf(name_lookup, "session.screen%d.windowZones", screen_number); - sprintf(class_lookup, "Session.Screen%d.WindowZones", screen_number); - if (config.getValue(name_lookup, class_lookup, l)) - screen->saveWindowZones((l == 1 || l == 2 || l == 4) ? l : 1); - else - screen->saveWindowZones(1); - - sprintf(name_lookup, "session.screen%d.windowPlacement", screen_number); - sprintf(class_lookup, "Session.Screen%d.WindowPlacement", screen_number); - if (config.getValue(name_lookup, class_lookup, s)) { - if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length())) - screen->savePlacementPolicy(BScreen::RowSmartPlacement); - else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length())) - screen->savePlacementPolicy(BScreen::ColSmartPlacement); - else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length())) - screen->savePlacementPolicy(BScreen::BestFitPlacement); - else - screen->savePlacementPolicy(BScreen::CascadePlacement); - } else - screen->savePlacementPolicy(BScreen::RowSmartPlacement); - -#ifdef SLIT -#endif // SLIT - -#ifdef HAVE_STRFTIME - sprintf(name_lookup, "session.screen%d.strftimeFormat", screen_number); - sprintf(class_lookup, "Session.Screen%d.StrftimeFormat", screen_number); - if (config.getValue(name_lookup, class_lookup, s)) - screen->saveStrftimeFormat(s.c_str()); - else - screen->saveStrftimeFormat("%I:%M %p"); - -#else // HAVE_STRFTIME - sprintf(name_lookup, "session.screen%d.dateFormat", screen_number); - sprintf(class_lookup, "Session.Screen%d.DateFormat", screen_number); - if (config.getValue(name_lookup, class_lookup, s)) { - if (strncasecmp(s.c_str(), "european", s.length())) - screen->saveDateFormat(B_AmericanDate); - else - screen->saveDateFormat(B_EuropeanDate); - } else - screen->saveDateFormat(B_AmericanDate); - - sprintf(name_lookup, "session.screen%d.clockFormat", screen_number); - sprintf(class_lookup, "Session.Screen%d.ClockFormat", screen_number); - if (config.getValue(name_lookup, class_lookup, l)) { - if (clock == 24) - screen->saveClock24Hour(True); - else - screen->saveClock24Hour(False); - } else - screen->saveClock24Hour(False); -#endif // HAVE_STRFTIME - - sprintf(name_lookup, "session.screen%d.edgeSnapThreshold", screen_number); - sprintf(class_lookup, "Session.Screen%d.EdgeSnapThreshold", screen_number); - if (config.getValue(name_lookup, class_lookup, l)) - screen->saveEdgeSnapThreshold(l); - else - screen->saveEdgeSnapThreshold(4); - - sprintf(name_lookup, "session.screen%d.imageDither", screen_number); - sprintf(class_lookup, "Session.Screen%d.ImageDither", screen_number); - if (config.getValue("session.imageDither", "Session.ImageDither", b)) - screen->saveImageDither((Bool)b); - else - screen->saveImageDither(True); - - sprintf(name_lookup, "session.screen%d.rootCommand", screen_number); - sprintf(class_lookup, "Session.Screen%d.RootCommand", screen_number); - if (config.getValue(name_lookup, class_lookup, s)) - screen->saveRootCommand(s.c_str()); - else - screen->saveRootCommand(NULL); - - if (config.getValue("session.opaqueMove", "Session.OpaqueMove", b)) - screen->saveOpaqueMove((Bool)b); - else - screen->saveOpaqueMove(False); -} - - -void Openbox::reload_rc(void) { - load_rc(); - reconfigure(); -} - - -void Openbox::reconfigure(void) { +void Openbox::reconfigure() { reconfigure_wait = True; if (! timer->isTiming()) timer->start(); } -void Openbox::real_reconfigure(void) { +void Openbox::real_reconfigure() { grab(); - config.load(); - config.setValue("session.styleFile", resource.style_file); // autosave's + load(); + save(); for (int i = 0, n = menuTimestamps->count(); i < n; i++) { MenuTimestamp *ts = menuTimestamps->remove(0); @@ -1384,7 +1094,7 @@ void Openbox::real_reconfigure(void) { } -void Openbox::checkMenu(void) { +void Openbox::checkMenu() { Bool reread = False; LinkedListIterator it(menuTimestamps); for (MenuTimestamp *tmp = it.current(); tmp && (! reread); @@ -1403,14 +1113,14 @@ void Openbox::checkMenu(void) { } -void Openbox::rereadMenu(void) { +void Openbox::rereadMenu() { reread_menu_wait = True; if (! timer->isTiming()) timer->start(); } -void Openbox::real_rereadMenu(void) { +void Openbox::real_rereadMenu() { for (int i = 0, n = menuTimestamps->count(); i < n; i++) { MenuTimestamp *ts = menuTimestamps->remove(0); @@ -1459,7 +1169,7 @@ void Openbox::saveMenuFilename(const char *filename) { } -void Openbox::timeout(void) { +void Openbox::timeout() { if (reconfigure_wait) real_reconfigure(); diff --git a/src/openbox.h b/src/openbox.h index 7881d602..144888bb 100644 --- a/src/openbox.h +++ b/src/openbox.h @@ -66,8 +66,8 @@ private: public: DataSearch(Window w, Z *d): window(w), data(d) {} - inline const Window &getWindow(void) const { return window; } - inline Z *getData(void) { return data; } + inline const Window &getWindow() const { return window; } + inline Z *getData() { return data; } }; @@ -119,28 +119,27 @@ private: protected: - void load_rc(void); - void save_rc(void); - void reload_rc(void); - void real_rereadMenu(void); - void real_reconfigure(void); + void load(); + void save(); + void real_rereadMenu(); + void real_reconfigure(); virtual void process_event(XEvent *); public: Openbox(int, char **, char * = 0, char * = 0); - virtual ~Openbox(void); + virtual ~Openbox(); #ifdef HAVE_GETPID - inline const Atom &getOpenboxPidAtom(void) const { return openbox_pid; } + inline const Atom &getOpenboxPidAtom() const { return openbox_pid; } #endif // HAVE_GETPID Basemenu *searchMenu(Window); OpenboxWindow *searchGroup(Window, OpenboxWindow *); OpenboxWindow *searchWindow(Window); - inline OpenboxWindow *getFocusedWindow(void) { return focused_window; } + inline OpenboxWindow *getFocusedWindow() { return focused_window; } BScreen *getScreen(int); BScreen *searchScreen(Window); @@ -148,29 +147,29 @@ public: inline Resource &getConfig() { return config; } - inline const Time &getDoubleClickInterval(void) const + inline const Time &getDoubleClickInterval() const { return resource.double_click_interval; } - inline const Time &getLastTime(void) const { return last_time; } + inline const Time &getLastTime() const { return last_time; } Toolbar *searchToolbar(Window); - inline const char *getStyleFilename(void) const + inline const char *getStyleFilename() const { return resource.style_file; } - inline const char *getMenuFilename(void) const + inline const char *getMenuFilename() const { return resource.menu_file; } - inline const int &getColorsPerChannel(void) const + inline const int &getColorsPerChannel() const { return resource.colors_per_channel; } - inline const timeval &getAutoRaiseDelay(void) const + inline const timeval &getAutoRaiseDelay() const { return resource.auto_raise_delay; } - inline const char *getTitleBarLayout(void) const + inline const char *getTitleBarLayout() const { return resource.titlebar_layout; } - inline const unsigned long &getCacheLife(void) const + inline const unsigned long &getCacheLife() const { return resource.cache_life; } - inline const unsigned long &getCacheMax(void) const + inline const unsigned long &getCacheMax() const { return resource.cache_max; } inline void maskWindowEvents(Window w, OpenboxWindow *bw) @@ -178,8 +177,7 @@ public: inline void setNoFocus(Bool f) { no_focus = f; } void setFocusedWindow(OpenboxWindow *w); - void shutdown(void); - void load_rc(BScreen *); + void shutdown(); void saveStyleFilename(const char *); void saveMenuFilename(const char *); void saveMenuSearch(Window, Basemenu *); @@ -191,13 +189,13 @@ public: void removeToolbarSearch(Window); void removeGroupSearch(Window); void restart(const char * = 0); - void reconfigure(void); - void rereadMenu(void); - void checkMenu(void); + void reconfigure(); + void rereadMenu(); + void checkMenu(); virtual Bool handleSignal(int); - virtual void timeout(void); + virtual void timeout(); #ifdef SLIT Slit *searchSlit(Window); -- 2.45.2