aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/LResource.cc21
-rw-r--r--src/FbTk/LResource.hh11
-rw-r--r--src/FbTk/Resource.hh11
-rw-r--r--src/Screen.cc52
-rw-r--r--src/fluxbox.cc2
5 files changed, 60 insertions, 37 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index 31362bd..de90b95 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -26,8 +26,11 @@
26 26
27#include "I18n.hh" 27#include "I18n.hh"
28#include "LuaUtil.hh" 28#include "LuaUtil.hh"
29#include "MemFun.hh"
29#include "Resource.hh" 30#include "Resource.hh"
30 31
32// defined in LResourceHelper-lua.cc
33// contains the compiled code of LResourceHelper.lua
31extern const char LResourceHelper[]; 34extern const char LResourceHelper[];
32extern const unsigned int LResourceHelper_size; 35extern const unsigned int LResourceHelper_size;
33 36
@@ -101,8 +104,15 @@ void LResourceManager::convert(ResourceManager &old, const std::string &new_file
101 new_rm.save(new_file.c_str(), NULL); 104 new_rm.save(new_file.c_str(), NULL);
102} 105}
103 106
104LResourceManager::LResourceManager(const std::string &root, Lua &l) 107LResourceManager::LResourceManager(const std::string &root, Lua &l, unsigned int autosave)
105 : ResourceManager_base(root), m_l(&l) { 108 : ResourceManager_base(root), m_l(&l) {
109
110 m_savetimer.setInterval(autosave);
111 m_savetimer.fireOnce(true);
112 m_savetimer.setFunctor( MemFunBind(*this, &LResourceManager::save,
113 static_cast<const char *>(NULL), static_cast<const char *>(NULL)
114 ) );
115
106 setLua(l); 116 setLua(l);
107} 117}
108 118
@@ -143,6 +153,8 @@ bool LResourceManager::save(const char *filename, const char *) {
143 if(filename == NULL) 153 if(filename == NULL)
144 filename = m_filename.c_str(); 154 filename = m_filename.c_str();
145 155
156 std::cerr << "XXX SAVING " << filename << std::endl;
157
146 m_l->getfield(lua::REGISTRYINDEX, dump_resources); 158 m_l->getfield(lua::REGISTRYINDEX, dump_resources);
147 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); 159 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str());
148 m_l->pushstring(filename); 160 m_l->pushstring(filename);
@@ -194,6 +206,11 @@ void LResourceManager::doRemoveResource(Resource_base &r) {
194 m_l->pop(); 206 m_l->pop();
195} 207}
196 208
209void LResourceManager::resourceChanged(Resource_base &r) {
210 if(! m_savetimer.isTiming())
211 m_savetimer.start();
212}
213
197void LResourceManager::setLua(Lua &l) { 214void LResourceManager::setLua(Lua &l) {
198 l.checkstack(2); 215 l.checkstack(2);
199 lua::stack_sentry s(l); 216 lua::stack_sentry s(l);
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh
index f0f8050..30f0e02 100644
--- a/src/FbTk/LResource.hh
+++ b/src/FbTk/LResource.hh
@@ -28,6 +28,7 @@
28#include <string> 28#include <string>
29 29
30#include "Resource.hh" 30#include "Resource.hh"
31#include "Timer.hh"
31 32
32namespace FbTk { 33namespace FbTk {
33 34
@@ -37,11 +38,18 @@ class LResourceManager: public ResourceManager_base {
37public: 38public:
38 static void convert(ResourceManager &old, const std::string &new_file); 39 static void convert(ResourceManager &old, const std::string &new_file);
39 40
40 LResourceManager(const std::string &root, Lua &l); 41 /**
42 * @param root the name of the table where settings will reside
43 * @param l lua context
44 * @param autosave delay (in seconds) for automatic saving of resources. Modifying a resource
45 * starts a timer. If another resource is modified, the timer is restarted. 0 = disabled
46 */
47 LResourceManager(const std::string &root, Lua &l, unsigned int autosave = 0);
41 void load(const std::string &filename, const std::string &fallback); 48 void load(const std::string &filename, const std::string &fallback);
42 virtual bool save(const char *filename, const char *); 49 virtual bool save(const char *filename, const char *);
43 virtual void addResource(Resource_base &r); 50 virtual void addResource(Resource_base &r);
44 virtual void removeResource(Resource_base &r); 51 virtual void removeResource(Resource_base &r);
52 virtual void resourceChanged(Resource_base &r);
45 void setLua(Lua &l); 53 void setLua(Lua &l);
46 54
47private: 55private:
@@ -50,6 +58,7 @@ private:
50 58
51 Lua *m_l; 59 Lua *m_l;
52 std::string m_filename; 60 std::string m_filename;
61 Timer m_savetimer;
53}; 62};
54 63
55} // end namespace FbTk 64} // end namespace FbTk
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh
index 7a797a1..c4a7951 100644
--- a/src/FbTk/Resource.hh
+++ b/src/FbTk/Resource.hh
@@ -96,8 +96,6 @@ public:
96 /// @return true on success 96 /// @return true on success
97 virtual bool save(const char *filename, const char *mergefilename=0) = 0; 97 virtual bool save(const char *filename, const char *mergefilename=0) = 0;
98 98
99
100
101 /// Add resource to list, only used in Resource<T> 99 /// Add resource to list, only used in Resource<T>
102 virtual void addResource(Resource_base &r); 100 virtual void addResource(Resource_base &r);
103 101
@@ -106,6 +104,9 @@ public:
106 m_resourcelist.remove(&r); 104 m_resourcelist.remove(&r);
107 } 105 }
108 106
107 /// Called by Resources when their value changes
108 virtual void resourceChanged(Resource_base &r) = 0;
109
109 /// searches for the resource with the resourcename 110 /// searches for the resource with the resourcename
110 /// @return pointer to resource base on success, else 0. 111 /// @return pointer to resource base on success, else 0.
111 Resource_base *findResource(const std::string &resourcename); 112 Resource_base *findResource(const std::string &resourcename);
@@ -154,6 +155,8 @@ public:
154 /// Add resource to list, only used in Resource<T> 155 /// Add resource to list, only used in Resource<T>
155 virtual void addResource(Resource_base &r); 156 virtual void addResource(Resource_base &r);
156 157
158 virtual void resourceChanged(Resource_base &r) {};
159
157 // this marks the database as "in use" and will avoid reloading 160 // this marks the database as "in use" and will avoid reloading
158 // resources unless it is zero. 161 // resources unless it is zero.
159 // It returns this resource manager. Useful for passing to 162 // It returns this resource manager. Useful for passing to
@@ -211,12 +214,14 @@ public:
211 214
212 void setDefaultValue() { 215 void setDefaultValue() {
213 m_value = m_defaultval; 216 m_value = m_defaultval;
217 m_rm.resourceChanged(*this);
214 m_modified_sig.emit(m_value); 218 m_modified_sig.emit(m_value);
215 } 219 }
216 /// sets resource from string, specialized, must be implemented 220 /// sets resource from string, specialized, must be implemented
217 void setFromString(const char *strval) { 221 void setFromString(const char *strval) {
218 try { 222 try {
219 m_value = Traits::fromString(strval); 223 m_value = Traits::fromString(strval);
224 m_rm.resourceChanged(*this);
220 m_modified_sig.emit(m_value); 225 m_modified_sig.emit(m_value);
221 } 226 }
222 catch(ConversionError &e) { 227 catch(ConversionError &e) {
@@ -226,6 +231,7 @@ public:
226 } 231 }
227 Accessor<T> &operator =(const T& newvalue) { 232 Accessor<T> &operator =(const T& newvalue) {
228 m_value = newvalue; 233 m_value = newvalue;
234 m_rm.resourceChanged(*this);
229 m_modified_sig.emit(m_value); 235 m_modified_sig.emit(m_value);
230 return *this; 236 return *this;
231 } 237 }
@@ -236,6 +242,7 @@ public:
236 virtual void setFromLua(lua::state &l) { 242 virtual void setFromLua(lua::state &l) {
237 try { 243 try {
238 m_value = Traits::fromLua(l); 244 m_value = Traits::fromLua(l);
245 m_rm.resourceChanged(*this);
239 m_modified_sig.emit(m_value); 246 m_modified_sig.emit(m_value);
240 } 247 }
241 catch(ConversionError &e) { 248 catch(ConversionError &e) {
diff --git a/src/Screen.cc b/src/Screen.cc
index 1e3d1c4..1acefc1 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -184,9 +184,8 @@ int calcSquareDistance(int x1, int y1, int x2, int y2) {
184class TabPlacementMenuItem: public FbTk::RadioMenuItem { 184class TabPlacementMenuItem: public FbTk::RadioMenuItem {
185public: 185public:
186 TabPlacementMenuItem(const FbTk::FbString & label, BScreen &screen, 186 TabPlacementMenuItem(const FbTk::FbString & label, BScreen &screen,
187 FbWinFrame::TabPlacement place, 187 FbWinFrame::TabPlacement place):
188 FbTk::RefCount<FbTk::Command<void> > &cmd): 188 FbTk::RadioMenuItem(label),
189 FbTk::RadioMenuItem(label, cmd),
190 m_screen(screen), 189 m_screen(screen),
191 m_place(place) { 190 m_place(place) {
192 setCloseOnClick(false); 191 setCloseOnClick(false);
@@ -1442,15 +1441,8 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1442 1441
1443 menu.removeAll(); 1442 menu.removeAll();
1444 1443
1445 FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand();
1446 FbTk::RefCount<FbTk::Command<void> > saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
1447 *Fluxbox::instance(),
1448 &Fluxbox::save_rc));
1449 FbTk::RefCount<FbTk::Command<void> > reconf_cmd(FbTk::CommandParser<void>::instance().parse("reconfigure")); 1444 FbTk::RefCount<FbTk::Command<void> > reconf_cmd(FbTk::CommandParser<void>::instance().parse("reconfigure"));
1450 1445
1451 s_a_reconf_macro->add(saverc_cmd);
1452 s_a_reconf_macro->add(reconf_cmd);
1453 FbTk::RefCount<FbTk::Command<void> > save_and_reconfigure(s_a_reconf_macro);
1454 // create focus menu 1446 // create focus menu
1455 // we don't set this to internal menu so will 1447 // we don't set this to internal menu so will
1456 // be deleted toghether with the parent 1448 // be deleted toghether with the parent
@@ -1459,12 +1451,12 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1459 "Method used to give focus to windows"); 1451 "Method used to give focus to windows");
1460 FbTk::RefCount<FbTk::Menu> focus_menu( createMenu(focusmenu_label) ); 1452 FbTk::RefCount<FbTk::Menu> focus_menu( createMenu(focusmenu_label) );
1461 1453
1462#define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) 1454#define _BOOLITEM(m,a, b, c, d, e) (m).insert(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e))
1463 1455
1464 1456
1465#define _FOCUSITEM(a, b, c, d, e) \ 1457#define _FOCUSITEM(a, b, c, d, e) \
1466 focus_menu->insert(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), focusControl(), \ 1458 focus_menu->insert(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), focusControl(), \
1467 e, save_and_reconfigure)) 1459 e, reconf_cmd))
1468 1460
1469 _FOCUSITEM(Configmenu, ClickFocus, 1461 _FOCUSITEM(Configmenu, ClickFocus,
1470 "Click To Focus", "Click to focus", 1462 "Click To Focus", "Click to focus",
@@ -1482,27 +1474,26 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1482 focus_menu->insert(new FbTk::MenuSeparator()); 1474 focus_menu->insert(new FbTk::MenuSeparator());
1483 focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, 1475 focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu,
1484 ClickTabFocus, "ClickTabFocus", "Click tab to focus windows"), 1476 ClickTabFocus, "ClickTabFocus", "Click tab to focus windows"),
1485 focusControl(), FocusControl::CLICKTABFOCUS, save_and_reconfigure)); 1477 focusControl(), FocusControl::CLICKTABFOCUS, reconf_cmd));
1486 focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, 1478 focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu,
1487 MouseTabFocus, "MouseTabFocus", "Hover over tab to focus windows"), 1479 MouseTabFocus, "MouseTabFocus", "Hover over tab to focus windows"),
1488 focusControl(), FocusControl::MOUSETABFOCUS, save_and_reconfigure)); 1480 focusControl(), FocusControl::MOUSETABFOCUS, reconf_cmd));
1489 focus_menu->insert(new FbTk::MenuSeparator()); 1481 focus_menu->insert(new FbTk::MenuSeparator());
1490 1482
1491 try { 1483 try {
1492 focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, 1484 focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew,
1493 "Focus New Windows", "Focus newly created windows"), 1485 "Focus New Windows", "Focus newly created windows"),
1494 m_resource_manager.getResource<bool, FbTk::BoolTraits>(name() + ".focusNewWindows"), 1486 m_resource_manager.getResource<bool, FbTk::BoolTraits>(name() + ".focusNewWindows")));
1495 saverc_cmd));
1496 } catch (FbTk::ResourceException e) { 1487 } catch (FbTk::ResourceException e) {
1497 cerr<<e.what()<<endl; 1488 cerr<<e.what()<<endl;
1498 } 1489 }
1499 1490
1500 _BOOLITEM(*focus_menu, Configmenu, AutoRaise, 1491 _BOOLITEM(*focus_menu, Configmenu, AutoRaise,
1501 "Auto Raise", "Auto Raise windows on sloppy", 1492 "Auto Raise", "Auto Raise windows on sloppy",
1502 resource.auto_raise, saverc_cmd); 1493 resource.auto_raise);
1503 _BOOLITEM(*focus_menu, Configmenu, ClickRaises, 1494 _BOOLITEM(*focus_menu, Configmenu, ClickRaises,
1504 "Click Raises", "Click Raises", 1495 "Click Raises", "Click Raises",
1505 resource.click_raises, saverc_cmd); 1496 resource.click_raises);
1506 1497
1507 focus_menu->updateMenu(); 1498 focus_menu->updateMenu();
1508 1499
@@ -1518,17 +1509,17 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1518 1509
1519 _BOOLITEM(*maxmenu, Configmenu, FullMax, 1510 _BOOLITEM(*maxmenu, Configmenu, FullMax,
1520 "Full Maximization", "Maximise over slit, toolbar, etc", 1511 "Full Maximization", "Maximise over slit, toolbar, etc",
1521 resource.full_max, saverc_cmd); 1512 resource.full_max);
1522 _BOOLITEM(*maxmenu, Configmenu, MaxIgnoreInc, 1513 _BOOLITEM(*maxmenu, Configmenu, MaxIgnoreInc,
1523 "Ignore Resize Increment", 1514 "Ignore Resize Increment",
1524 "Maximizing Ignores Resize Increment (e.g. xterm)", 1515 "Maximizing Ignores Resize Increment (e.g. xterm)",
1525 resource.max_ignore_inc, saverc_cmd); 1516 resource.max_ignore_inc);
1526 _BOOLITEM(*maxmenu, Configmenu, MaxDisableMove, 1517 _BOOLITEM(*maxmenu, Configmenu, MaxDisableMove,
1527 "Disable Moving", "Don't Allow Moving While Maximized", 1518 "Disable Moving", "Don't Allow Moving While Maximized",
1528 resource.max_disable_move, saverc_cmd); 1519 resource.max_disable_move);
1529 _BOOLITEM(*maxmenu, Configmenu, MaxDisableResize, 1520 _BOOLITEM(*maxmenu, Configmenu, MaxDisableResize,
1530 "Disable Resizing", "Don't Allow Resizing While Maximized", 1521 "Disable Resizing", "Don't Allow Resizing While Maximized",
1531 resource.max_disable_resize, saverc_cmd); 1522 resource.max_disable_resize);
1532 1523
1533 maxmenu->updateMenu(); 1524 maxmenu->updateMenu();
1534 menu.insert(maxmenu_label, maxmenu); 1525 menu.insert(maxmenu_label, maxmenu);
@@ -1548,13 +1539,13 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1548 1539
1549 _BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar, 1540 _BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar,
1550 "Tabs in Titlebar", "Tabs in Titlebar", 1541 "Tabs in Titlebar", "Tabs in Titlebar",
1551 resource.default_internal_tabs, saverc_cmd); 1542 resource.default_internal_tabs);
1552 tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, 1543 tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,
1553 "Maximize Over", "Maximize over this thing when maximizing"), 1544 "Maximize Over", "Maximize over this thing when maximizing"),
1554 resource.max_over_tabs, save_and_reconfigure)); 1545 resource.max_over_tabs, reconf_cmd));
1555 tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, 1546 tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons,
1556 "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), 1547 "Show Pictures", "chooses if little icons are shown next to title in the iconbar"),
1557 resource.tabs_use_pixmap, save_and_reconfigure)); 1548 resource.tabs_use_pixmap, reconf_cmd));
1558 1549
1559 FbTk::MenuItem *tab_width_item = 1550 FbTk::MenuItem *tab_width_item =
1560 new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, ExternalTabWidth, 1551 new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, ExternalTabWidth,
@@ -1562,7 +1553,6 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1562 "Width of external-style tabs"), 1553 "Width of external-style tabs"),
1563 resource.tab_width, 10, 3000, /* silly number */ 1554 resource.tab_width, 10, 3000, /* silly number */
1564 *tab_menu); 1555 *tab_menu);
1565 tab_width_item->setCommand(saverc_cmd);
1566 tab_menu->insert(tab_width_item); 1556 tab_menu->insert(tab_width_item);
1567 1557
1568 // menu is 3 wide, 5 down 1558 // menu is 3 wide, 5 down
@@ -1597,7 +1587,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1597 tabplacement_menu->insert(p.label); 1587 tabplacement_menu->insert(p.label);
1598 tabplacement_menu->setItemEnabled(i, false); 1588 tabplacement_menu->setItemEnabled(i, false);
1599 } else 1589 } else
1600 tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement, saverc_cmd)); 1590 tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement));
1601 } 1591 }
1602 tabplacement_menu->updateMenu(); 1592 tabplacement_menu->updateMenu();
1603 1593
@@ -1616,13 +1606,13 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1616 alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, 1606 alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans,
1617 "Force Pseudo-Transparency", 1607 "Force Pseudo-Transparency",
1618 "When composite is available, still use old pseudo-transparency"), 1608 "When composite is available, still use old pseudo-transparency"),
1619 Fluxbox::instance()->getPseudoTransResource(), save_and_reconfigure)); 1609 Fluxbox::instance()->getPseudoTransResource(), reconf_cmd));
1620 } 1610 }
1621 1611
1622 // in order to save system resources, don't save or reconfigure alpha 1612 // in order to save system resources, don't save or reconfigure alpha
1623 // settings until after the user is done changing them 1613 // settings until after the user is done changing them
1624 FbTk::RefCount<FbTk::Command<void> > delayed_save_and_reconf( 1614 FbTk::RefCount<FbTk::Command<void> > delayed_save_and_reconf(
1625 new FbTk::DelayedCmd(save_and_reconfigure)); 1615 new FbTk::DelayedCmd(reconf_cmd));
1626 1616
1627 FbTk::MenuItem *focused_alpha_item = 1617 FbTk::MenuItem *focused_alpha_item =
1628 new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha, 1618 new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha,
@@ -1662,11 +1652,11 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1662 _BOOLITEM(menu, Configmenu, OpaqueMove, 1652 _BOOLITEM(menu, Configmenu, OpaqueMove,
1663 "Opaque Window Moving", 1653 "Opaque Window Moving",
1664 "Window Moving with whole window visible (as opposed to outline moving)", 1654 "Window Moving with whole window visible (as opposed to outline moving)",
1665 resource.opaque_move, saverc_cmd); 1655 resource.opaque_move);
1666 _BOOLITEM(menu, Configmenu, WorkspaceWarping, 1656 _BOOLITEM(menu, Configmenu, WorkspaceWarping,
1667 "Workspace Warping", 1657 "Workspace Warping",
1668 "Workspace Warping - dragging windows to the edge and onto the next workspace", 1658 "Workspace Warping - dragging windows to the edge and onto the next workspace",
1669 resource.workspace_warping, saverc_cmd); 1659 resource.workspace_warping);
1670 1660
1671#undef _BOOLITEM 1661#undef _BOOLITEM
1672 1662
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 8ffd9f3..68888f1 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -230,7 +230,7 @@ Fluxbox::Fluxbox(int argc, char **argv,
230 : FbTk::App(dpy_name.c_str()), 230 : FbTk::App(dpy_name.c_str()),
231 m_l(new Lua), 231 m_l(new Lua),
232 m_fbatoms(FbAtoms::instance()), 232 m_fbatoms(FbAtoms::instance()),
233 m_resourcemanager("session", *m_l), 233 m_resourcemanager("session", *m_l, 5),
234 234
235 m_RC_PATH(rc_path), 235 m_RC_PATH(rc_path),
236 m_RC_INIT_FILE("init"), 236 m_RC_INIT_FILE("init"),