diff options
Diffstat (limited to 'src/Slit.cc')
-rw-r--r-- | src/Slit.cc | 133 |
1 files changed, 71 insertions, 62 deletions
diff --git a/src/Slit.cc b/src/Slit.cc index 6b4344e..210c2a5 100644 --- a/src/Slit.cc +++ b/src/Slit.cc | |||
@@ -164,7 +164,67 @@ private: | |||
164 | unsigned int Slit::s_eventmask = SubstructureRedirectMask | ButtonPressMask | | 164 | unsigned int Slit::s_eventmask = SubstructureRedirectMask | ButtonPressMask | |
165 | EnterWindowMask | LeaveWindowMask | ExposureMask; | 165 | EnterWindowMask | LeaveWindowMask | ExposureMask; |
166 | 166 | ||
167 | Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) | 167 | void Slit::SlitClientsRes::setFromLua(lua::state &l) { |
168 | lua::stack_sentry s(l, -1); | ||
169 | l.checkstack(1); | ||
170 | |||
171 | // to avoid modifying the master copy until we are sure the new list is ok | ||
172 | SlitClients copy(*this); | ||
173 | // this will be the new list once we are done | ||
174 | SlitClients t; | ||
175 | |||
176 | if(l.type(-1) != lua::TTABLE) { | ||
177 | std::cerr << "Cannot convert to a client list from lua type " | ||
178 | << l.type_name(l.type(-1)) << std::endl; | ||
179 | return; | ||
180 | } | ||
181 | for(size_t i = 1; l.rawgeti(-1, i), !l.isnil(-1); l.pop(), ++i) { | ||
182 | if(l.type(-1) != lua::TSTRING && l.type(-1) != lua::TNUMBER) { | ||
183 | std::cerr << "Cannot convert to a client name from lua type " | ||
184 | << l.type_name(l.type(-1)) << std::endl; | ||
185 | continue; | ||
186 | } | ||
187 | const std::string &name = l.tostring(-1); | ||
188 | // look for a matching window | ||
189 | bool found = false; | ||
190 | for(SlitClients::iterator j = copy.begin(); j != copy.end(); ++j) { | ||
191 | if((*j)->matchName().logical() == name) { | ||
192 | t.push_back(*j); | ||
193 | copy.erase(j); | ||
194 | found = true; | ||
195 | break; | ||
196 | } | ||
197 | } | ||
198 | if(!found) { | ||
199 | // no matching window, create a placeholder | ||
200 | t.push_back( new SlitClient(name.c_str()) ); | ||
201 | } | ||
202 | } l.pop(); | ||
203 | |||
204 | // move remaining non-placeholder clients to the new list | ||
205 | while(!copy.empty()) { | ||
206 | if(copy.front()->window() != None) | ||
207 | t.push_back(copy.front()); | ||
208 | copy.pop_front(); | ||
209 | } | ||
210 | SlitClients::operator=(t); | ||
211 | |||
212 | l.pop(); | ||
213 | } | ||
214 | |||
215 | void Slit::SlitClientsRes::pushToLua(lua::state &l) const { | ||
216 | l.checkstack(2); | ||
217 | l.createtable(size()); | ||
218 | lua::stack_sentry s(l); | ||
219 | |||
220 | int j = 1; | ||
221 | for(const_iterator i = begin(); i != end(); ++i) { | ||
222 | l.pushstring((*i)->matchName().logical()); | ||
223 | l.rawseti(-2, j++); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | Slit::Slit(BScreen &scr, FbTk::Layer &layer) | ||
168 | : m_hidden(false), m_visible(false), | 228 | : m_hidden(false), m_visible(false), |
169 | m_screen(scr), | 229 | m_screen(scr), |
170 | m_clientlist_menu(scr.menuTheme(), | 230 | m_clientlist_menu(scr.menuTheme(), |
@@ -188,7 +248,7 @@ Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) | |||
188 | m_slit_theme(new SlitTheme(scr.rootWindow().screenNumber())), | 248 | m_slit_theme(new SlitTheme(scr.rootWindow().screenNumber())), |
189 | m_strut(0), | 249 | m_strut(0), |
190 | // resources | 250 | // resources |
191 | // lock in first resource | 251 | m_client_list(scr.resourceManager(), scr.name() + ".slit.clientList"), |
192 | m_rc_kde_dockapp(scr.resourceManager(), true, scr.name() + ".slit.acceptKdeDockapps"), | 252 | m_rc_kde_dockapp(scr.resourceManager(), true, scr.name() + ".slit.acceptKdeDockapps"), |
193 | m_rc_auto_hide(scr.resourceManager(), false, scr.name() + ".slit.autoHide"), | 253 | m_rc_auto_hide(scr.resourceManager(), false, scr.name() + ".slit.autoHide"), |
194 | // TODO: this resource name must change | 254 | // TODO: this resource name must change |
@@ -245,11 +305,6 @@ Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) | |||
245 | 305 | ||
246 | moveToLayer(static_cast<int>(*m_rc_layernum)); | 306 | moveToLayer(static_cast<int>(*m_rc_layernum)); |
247 | 307 | ||
248 | |||
249 | |||
250 | // Get client list for sorting purposes | ||
251 | loadClientList(filename); | ||
252 | |||
253 | setupMenu(); | 308 | setupMenu(); |
254 | } | 309 | } |
255 | 310 | ||
@@ -802,7 +857,6 @@ void Slit::reposition() { | |||
802 | 857 | ||
803 | 858 | ||
804 | void Slit::shutdown() { | 859 | void Slit::shutdown() { |
805 | saveClientList(); | ||
806 | while (!m_client_list.empty()) | 860 | while (!m_client_list.empty()) |
807 | removeClient(m_client_list.front(), true, true); | 861 | removeClient(m_client_list.front(), true, true); |
808 | } | 862 | } |
@@ -826,6 +880,8 @@ void Slit::clientUp(SlitClient* client) { | |||
826 | break; | 880 | break; |
827 | } | 881 | } |
828 | } | 882 | } |
883 | |||
884 | saveClientList(); | ||
829 | } | 885 | } |
830 | 886 | ||
831 | void Slit::clientDown(SlitClient* client) { | 887 | void Slit::clientDown(SlitClient* client) { |
@@ -847,6 +903,8 @@ void Slit::clientDown(SlitClient* client) { | |||
847 | break; | 903 | break; |
848 | } | 904 | } |
849 | } | 905 | } |
906 | |||
907 | saveClientList(); | ||
850 | } | 908 | } |
851 | 909 | ||
852 | void Slit::cycleClientsUp() { | 910 | void Slit::cycleClientsUp() { |
@@ -859,6 +917,8 @@ void Slit::cycleClientsUp() { | |||
859 | m_client_list.erase(it); | 917 | m_client_list.erase(it); |
860 | m_client_list.push_back(client); | 918 | m_client_list.push_back(client); |
861 | reconfigure(); | 919 | reconfigure(); |
920 | |||
921 | saveClientList(); | ||
862 | } | 922 | } |
863 | 923 | ||
864 | void Slit::cycleClientsDown() { | 924 | void Slit::cycleClientsDown() { |
@@ -870,6 +930,8 @@ void Slit::cycleClientsDown() { | |||
870 | m_client_list.remove(client); | 930 | m_client_list.remove(client); |
871 | m_client_list.push_front(client); | 931 | m_client_list.push_front(client); |
872 | reconfigure(); | 932 | reconfigure(); |
933 | |||
934 | saveClientList(); | ||
873 | } | 935 | } |
874 | 936 | ||
875 | void Slit::handleEvent(XEvent &event) { | 937 | void Slit::handleEvent(XEvent &event) { |
@@ -1000,40 +1062,6 @@ void Slit::toggleHidden() { | |||
1000 | frame.window.move(frame.x, frame.y); | 1062 | frame.window.move(frame.x, frame.y); |
1001 | } | 1063 | } |
1002 | 1064 | ||
1003 | void Slit::loadClientList(const char *filename) { | ||
1004 | if (filename == 0 || filename[0] == '\0') | ||
1005 | return; | ||
1006 | |||
1007 | // save filename so we can save client list later | ||
1008 | m_filename = filename; | ||
1009 | string real_filename= FbTk::StringUtil::expandFilename(filename); | ||
1010 | |||
1011 | struct stat buf; | ||
1012 | if (stat(real_filename.c_str(), &buf) == 0) { | ||
1013 | ifstream file(real_filename.c_str()); | ||
1014 | string name; | ||
1015 | while (! file.eof()) { | ||
1016 | name = ""; | ||
1017 | getline(file, name); // get the entire line | ||
1018 | if (name.empty()) | ||
1019 | continue; | ||
1020 | |||
1021 | // remove whitespaces from start and end | ||
1022 | FbTk::StringUtil::removeFirstWhitespace(name); | ||
1023 | |||
1024 | // the cleaned string could still be a comment, or blank | ||
1025 | if ( name.empty() || name[0] == '#' || name[0] == '!' ) | ||
1026 | continue; | ||
1027 | |||
1028 | // trailing whitespace won't affect the above test | ||
1029 | FbTk::StringUtil::removeTrailingWhitespace(name); | ||
1030 | |||
1031 | SlitClient *client = new SlitClient(name.c_str()); | ||
1032 | m_client_list.push_back(client); | ||
1033 | } | ||
1034 | } | ||
1035 | } | ||
1036 | |||
1037 | void Slit::updateClientmenu() { | 1065 | void Slit::updateClientmenu() { |
1038 | if (screen().isShuttingdown()) | 1066 | if (screen().isShuttingdown()) |
1039 | return; | 1067 | return; |
@@ -1057,30 +1085,11 @@ void Slit::updateClientmenu() { | |||
1057 | m_clientlist_menu.insert(new SlitClientMenuItem(*this, *(*it), reconfig)); | 1085 | m_clientlist_menu.insert(new SlitClientMenuItem(*this, *(*it), reconfig)); |
1058 | } | 1086 | } |
1059 | 1087 | ||
1060 | m_clientlist_menu.insert(new FbTk::MenuSeparator()); | ||
1061 | FbTk::RefCount<FbTk::Command<void> > savecmd(new FbTk::SimpleCommand<Slit>(*this, &Slit::saveClientList)); | ||
1062 | m_clientlist_menu.insert(_FB_XTEXT(Slit, | ||
1063 | SaveSlitList, | ||
1064 | "Save SlitList", "Saves the current order in the slit"), | ||
1065 | savecmd); | ||
1066 | |||
1067 | m_clientlist_menu.updateMenu(); | 1088 | m_clientlist_menu.updateMenu(); |
1068 | } | 1089 | } |
1069 | 1090 | ||
1070 | void Slit::saveClientList() { | 1091 | void Slit::saveClientList() { |
1071 | 1092 | Fluxbox::instance()->save_rc(); | |
1072 | ofstream file(FbTk::StringUtil::expandFilename(m_filename).c_str()); | ||
1073 | SlitClients::iterator it = m_client_list.begin(); | ||
1074 | SlitClients::iterator it_end = m_client_list.end(); | ||
1075 | string prevName; | ||
1076 | string name; | ||
1077 | for (; it != it_end; ++it) { | ||
1078 | name = (*it)->matchName().logical(); | ||
1079 | if (name != prevName) | ||
1080 | file << name.c_str() << endl; | ||
1081 | |||
1082 | prevName = name; | ||
1083 | } | ||
1084 | } | 1093 | } |
1085 | 1094 | ||
1086 | void Slit::setupMenu() { | 1095 | void Slit::setupMenu() { |