aboutsummaryrefslogtreecommitdiff
path: root/src/Slit.cc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-02 15:21:24 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-07-02 15:21:24 (GMT)
commit442e69c89b721329883113389f889675138e7da7 (patch)
tree211111eb98eb3da6155baea0a24c5cd9d8c6137d /src/Slit.cc
parentbd94eaa6cadfd0a7d83f3068a84b27f987bdee4b (diff)
downloadfluxbox_pavel-442e69c89b721329883113389f889675138e7da7.zip
fluxbox_pavel-442e69c89b721329883113389f889675138e7da7.tar.bz2
Store menus if smart pointers (RefCount)
This was originally intended to be a bugfix for an memory error reported by valgrind (accessing freed memory). While debugging it, I found the menu ownership semantics confusing (setInternalMenu() et al.), so I decided to get rid of it and store it in smart pointers everywhere. Looking back, I'm not sure if this was worth all the trouble, but the good news is that the valgrind error disappeared. :)
Diffstat (limited to 'src/Slit.cc')
-rw-r--r--src/Slit.cc78
1 files changed, 36 insertions, 42 deletions
diff --git a/src/Slit.cc b/src/Slit.cc
index 2e32f27..5f7cfcf 100644
--- a/src/Slit.cc
+++ b/src/Slit.cc
@@ -227,12 +227,12 @@ void Slit::SlitClientsRes::pushToLua(lua::state &l) const {
227Slit::Slit(BScreen &scr, FbTk::Layer &layer) 227Slit::Slit(BScreen &scr, FbTk::Layer &layer)
228 : m_hidden(false), m_visible(false), 228 : m_hidden(false), m_visible(false),
229 m_screen(scr), 229 m_screen(scr),
230 m_clientlist_menu(scr.menuTheme(), 230 m_clientlist_menu(new FbMenu(scr.menuTheme(),
231 scr.imageControl(), 231 scr.imageControl(),
232 *scr.layerManager().getLayer(ResourceLayer::MENU)), 232 *scr.layerManager().getLayer(ResourceLayer::MENU)) ),
233 m_slitmenu(scr.menuTheme(), 233 m_slitmenu(new FbMenu(scr.menuTheme(),
234 scr.imageControl(), 234 scr.imageControl(),
235 *scr.layerManager().getLayer(ResourceLayer::MENU)), 235 *scr.layerManager().getLayer(ResourceLayer::MENU)) ),
236#ifdef XINERAMA 236#ifdef XINERAMA
237 m_xineramaheadmenu(0), 237 m_xineramaheadmenu(0),
238#endif // XINERAMA 238#endif // XINERAMA
@@ -727,7 +727,7 @@ void Slit::reconfigure() {
727 else if (!doAutoHide() && isHidden()) 727 else if (!doAutoHide() && isHidden())
728 toggleHidden(); // restore visible 728 toggleHidden(); // restore visible
729 729
730 m_slitmenu.reconfigure(); 730 m_slitmenu->reconfigure();
731 updateClientmenu(); 731 updateClientmenu();
732 updateStrut(); 732 updateStrut();
733 733
@@ -950,11 +950,11 @@ void Slit::buttonPressEvent(XButtonEvent &be) {
950 return; 950 return;
951 951
952 if (be.button == Button3) { 952 if (be.button == Button3) {
953 if (! m_slitmenu.isVisible()) { 953 if (! m_slitmenu->isVisible()) {
954 screen().placementStrategy() 954 screen().placementStrategy()
955 .placeAndShowMenu(m_slitmenu, be.x_root, be.y_root, false); 955 .placeAndShowMenu(*m_slitmenu, be.x_root, be.y_root, false);
956 } else 956 } else
957 m_slitmenu.hide(); 957 m_slitmenu->hide();
958 } 958 }
959} 959}
960 960
@@ -983,7 +983,7 @@ void Slit::leaveNotifyEvent(XCrossingEvent &ev) {
983 } else { 983 } else {
984 if (! m_timer.isTiming()) { 984 if (! m_timer.isTiming()) {
985 // the menu is open, keep it firing until it closes 985 // the menu is open, keep it firing until it closes
986 if (m_slitmenu.isVisible()) 986 if (m_slitmenu->isVisible())
987 m_timer.fireOnce(false); 987 m_timer.fireOnce(false);
988 m_timer.start(); 988 m_timer.start();
989 } 989 }
@@ -1046,7 +1046,7 @@ void Slit::clearWindow() {
1046 1046
1047void Slit::toggleHidden() { 1047void Slit::toggleHidden() {
1048 if (doAutoHide()) { 1048 if (doAutoHide()) {
1049 if (!m_slitmenu.isVisible()) { 1049 if (!m_slitmenu->isVisible()) {
1050 m_timer.fireOnce(true); 1050 m_timer.fireOnce(true);
1051 } else 1051 } else
1052 return; 1052 return;
@@ -1066,24 +1066,24 @@ void Slit::updateClientmenu() {
1066 _FB_USES_NLS; 1066 _FB_USES_NLS;
1067 1067
1068 // clear old items 1068 // clear old items
1069 m_clientlist_menu.removeAll(); 1069 m_clientlist_menu->removeAll();
1070 m_clientlist_menu.setLabel(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu")); 1070 m_clientlist_menu->setLabel(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"));
1071 1071
1072 FbTk::RefCount<FbTk::Command<void> > cycle_up(new FbTk::SimpleCommand<Slit>(*this, &Slit::cycleClientsUp)); 1072 FbTk::RefCount<FbTk::Command<void> > cycle_up(new FbTk::SimpleCommand<Slit>(*this, &Slit::cycleClientsUp));
1073 FbTk::RefCount<FbTk::Command<void> > cycle_down(new FbTk::SimpleCommand<Slit>(*this, &Slit::cycleClientsDown)); 1073 FbTk::RefCount<FbTk::Command<void> > cycle_down(new FbTk::SimpleCommand<Slit>(*this, &Slit::cycleClientsDown));
1074 m_clientlist_menu.insert(_FB_XTEXT(Slit, CycleUp, "Cycle Up", "Cycle clients upwards"), cycle_up); 1074 m_clientlist_menu->insert(_FB_XTEXT(Slit, CycleUp, "Cycle Up", "Cycle clients upwards"), cycle_up);
1075 m_clientlist_menu.insert(_FB_XTEXT(Slit, CycleDown, "Cycle Down", "Cycle clients downwards"), cycle_down); 1075 m_clientlist_menu->insert(_FB_XTEXT(Slit, CycleDown, "Cycle Down", "Cycle clients downwards"), cycle_down);
1076 1076
1077 m_clientlist_menu.insert(new FbTk::MenuSeparator()); 1077 m_clientlist_menu->insert(new FbTk::MenuSeparator());
1078 1078
1079 FbTk::RefCount<FbTk::Command<void> > reconfig(new FbTk::SimpleCommand<Slit>(*this, &Slit::reconfigure)); 1079 FbTk::RefCount<FbTk::Command<void> > reconfig(new FbTk::SimpleCommand<Slit>(*this, &Slit::reconfigure));
1080 SlitClients::iterator it = m_client_list.begin(); 1080 SlitClients::iterator it = m_client_list.begin();
1081 for (; it != m_client_list.end(); ++it) { 1081 for (; it != m_client_list.end(); ++it) {
1082 if ((*it) != 0 && (*it)->window() != 0) 1082 if ((*it) != 0 && (*it)->window() != 0)
1083 m_clientlist_menu.insert(new SlitClientMenuItem(*this, *(*it), reconfig)); 1083 m_clientlist_menu->insert(new SlitClientMenuItem(*this, *(*it), reconfig));
1084 } 1084 }
1085 1085
1086 m_clientlist_menu.updateMenu(); 1086 m_clientlist_menu->updateMenu();
1087} 1087}
1088 1088
1089void Slit::saveClientList() { 1089void Slit::saveClientList() {
@@ -1110,39 +1110,35 @@ void Slit::setupMenu() {
1110 FbTk::RefCount<FbTk::Command<void> > save_and_reconfigure_slit(s_a_reconf_slit_macro); 1110 FbTk::RefCount<FbTk::Command<void> > save_and_reconfigure_slit(s_a_reconf_slit_macro);
1111 1111
1112 1112
1113 // it'll be freed by the slitmenu (since not marked internal) 1113 FbTk::RefCount<FbTk::Menu> placement_menu( new FbMenu(m_screen.menuTheme(),
1114 FbMenu *placement_menu = new FbMenu(m_screen.menuTheme(),
1115 m_screen.imageControl(), 1114 m_screen.imageControl(),
1116 *m_screen.layerManager().getLayer(::ResourceLayer::MENU)); 1115 *m_screen.layerManager().getLayer(::ResourceLayer::MENU)) );
1117 1116
1118 1117
1119 // setup base menu 1118 // setup base menu
1120 m_slitmenu.setLabel(_FB_XTEXT(Slit, Slit, "Slit", "The Slit")); 1119 m_slitmenu->setLabel(_FB_XTEXT(Slit, Slit, "Slit", "The Slit"));
1121 m_slitmenu.insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), 1120 m_slitmenu->insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"),
1122 placement_menu); 1121 placement_menu);
1123 1122
1124 m_slitmenu.insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), m_layermenu.get()); 1123 m_slitmenu->insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"),
1124 FbTk::RefCount<FbTk::Menu>(m_layermenu) );
1125 1125
1126#ifdef XINERAMA 1126#ifdef XINERAMA
1127 if (screen().hasXinerama()) { 1127 if (screen().hasXinerama()) {
1128 m_slitmenu.insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), 1128 m_xineramaheadmenu.reset( new XineramaHeadMenu<Slit>(
1129 m_xineramaheadmenu = 1129 screen().menuTheme(), screen(), screen().imageControl(),
1130 new XineramaHeadMenu<Slit>( 1130 *screen().layerManager().getLayer(::ResourceLayer::MENU), *this,
1131 screen().menuTheme(), 1131 _FB_XTEXT(Slit, OnHead, "Slit on Head", "Title of Slits On Head menu")) );
1132 screen(), 1132 m_slitmenu->insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"),
1133 screen().imageControl(), 1133 FbTk::RefCount<FbTk::Menu>(m_xineramaheadmenu));
1134 *screen().layerManager().getLayer(::ResourceLayer::MENU),
1135 *this,
1136 _FB_XTEXT(Slit, OnHead, "Slit on Head", "Title of Slits On Head menu")
1137 ));
1138 } 1134 }
1139#endif //XINERAMA 1135#endif //XINERAMA
1140 1136
1141 m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"), 1137 m_slitmenu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"),
1142 m_rc_auto_hide, 1138 m_rc_auto_hide,
1143 save_and_reconfigure_slit)); 1139 save_and_reconfigure_slit));
1144 1140
1145 m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), 1141 m_slitmenu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"),
1146 m_rc_maximize_over, 1142 m_rc_maximize_over,
1147 save_and_reconfigure_slit)); 1143 save_and_reconfigure_slit));
1148 1144
@@ -1150,7 +1146,7 @@ void Slit::setupMenu() {
1150 FbTk::MenuItem *alpha_menuitem = 1146 FbTk::MenuItem *alpha_menuitem =
1151 new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), 1147 new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"),
1152 m_rc_alpha, 1148 m_rc_alpha,
1153 0, 255, m_slitmenu); 1149 0, 255, *m_slitmenu);
1154 // setup command for alpha value 1150 // setup command for alpha value
1155 MacroCommand *alpha_macrocmd = new MacroCommand(); 1151 MacroCommand *alpha_macrocmd = new MacroCommand();
1156 RefCount<Command<void> > alpha_cmd(new SimpleCommand<Slit>(*this, &Slit::updateAlpha)); 1152 RefCount<Command<void> > alpha_cmd(new SimpleCommand<Slit>(*this, &Slit::updateAlpha));
@@ -1159,17 +1155,15 @@ void Slit::setupMenu() {
1159 RefCount<Command<void> > set_alpha_cmd(alpha_macrocmd); 1155 RefCount<Command<void> > set_alpha_cmd(alpha_macrocmd);
1160 alpha_menuitem->setCommand(set_alpha_cmd); 1156 alpha_menuitem->setCommand(set_alpha_cmd);
1161 1157
1162 m_slitmenu.insert(alpha_menuitem); 1158 m_slitmenu->insert(alpha_menuitem);
1163 1159
1164 m_slitmenu.insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu); 1160 m_slitmenu->insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"),
1165 m_slitmenu.updateMenu(); 1161 FbTk::RefCount<FbTk::Menu>(m_clientlist_menu) );
1162 m_slitmenu->updateMenu();
1166 1163
1167 // setup sub menu 1164 // setup sub menu
1168 placement_menu->setLabel(_FB_XTEXT(Slit, Placement, "Slit Placement", "Slit Placement")); 1165 placement_menu->setLabel(_FB_XTEXT(Slit, Placement, "Slit Placement", "Slit Placement"));
1169 placement_menu->setMinimumColumns(3); 1166 placement_menu->setMinimumColumns(3);
1170 m_layermenu->setInternalMenu();
1171 m_clientlist_menu.setInternalMenu();
1172 m_slitmenu.setInternalMenu();
1173 1167
1174 typedef pair<FbTk::FbString, Slit::Placement> PlacementP; 1168 typedef pair<FbTk::FbString, Slit::Placement> PlacementP;
1175 typedef list<PlacementP> Placements; 1169 typedef list<PlacementP> Placements;