diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-20 20:16:30 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-17 00:09:34 (GMT) |
commit | cb42b13e5dfcbebad6ac6d6cf757870b7b8a65ae (patch) | |
tree | b860751172054b5342a9674c9dc44c132831b435 /src | |
parent | d57c93b1576879ba29ef172b58a0ef2e04403b1b (diff) | |
download | fluxbox_pavel-cb42b13e5dfcbebad6ac6d6cf757870b7b8a65ae.zip fluxbox_pavel-cb42b13e5dfcbebad6ac6d6cf757870b7b8a65ae.tar.bz2 |
Convert slitlist from a separate file to a regular lua resource
Diffstat (limited to 'src')
-rw-r--r-- | src/Screen.cc | 3 | ||||
-rw-r--r-- | src/Slit.cc | 133 | ||||
-rw-r--r-- | src/Slit.hh | 27 | ||||
-rw-r--r-- | src/fluxbox.cc | 8 | ||||
-rw-r--r-- | src/fluxbox.hh | 3 |
5 files changed, 96 insertions, 78 deletions
diff --git a/src/Screen.cc b/src/Screen.cc index 24e086c..6ddc74c 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -480,8 +480,7 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, | |||
480 | changeWorkspaceID(first_desktop); | 480 | changeWorkspaceID(first_desktop); |
481 | 481 | ||
482 | #ifdef USE_SLIT | 482 | #ifdef USE_SLIT |
483 | m_slit.reset(new Slit(*this, *layerManager().getLayer(ResourceLayer::DESKTOP), | 483 | m_slit.reset(new Slit(*this, *layerManager().getLayer(ResourceLayer::DESKTOP))); |
484 | fluxbox->getSlitlistFilename().c_str())); | ||
485 | #endif // USE_SLIT | 484 | #endif // USE_SLIT |
486 | 485 | ||
487 | XFlush(disp); | 486 | XFlush(disp); |
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() { |
diff --git a/src/Slit.hh b/src/Slit.hh index 5c69a8c..9384ad6 100644 --- a/src/Slit.hh +++ b/src/Slit.hh | |||
@@ -68,7 +68,7 @@ public: | |||
68 | RIGHTBOTTOM, RIGHTCENTER, RIGHTTOP | 68 | RIGHTBOTTOM, RIGHTCENTER, RIGHTTOP |
69 | }; | 69 | }; |
70 | 70 | ||
71 | Slit(BScreen &screen, FbTk::Layer &layer, const char *filename = 0); | 71 | Slit(BScreen &screen, FbTk::Layer &layer); |
72 | virtual ~Slit(); | 72 | virtual ~Slit(); |
73 | 73 | ||
74 | void show() { frame.window.show(); m_visible = true; } | 74 | void show() { frame.window.show(); m_visible = true; } |
@@ -137,7 +137,6 @@ private: | |||
137 | void setupMenu(); | 137 | void setupMenu(); |
138 | 138 | ||
139 | void removeClient(SlitClient *client, bool remap, bool destroy); | 139 | void removeClient(SlitClient *client, bool remap, bool destroy); |
140 | void loadClientList(const char *filename); | ||
141 | void updateClientmenu(); | 140 | void updateClientmenu(); |
142 | void clearStrut(); | 141 | void clearStrut(); |
143 | void updateStrut(); | 142 | void updateStrut(); |
@@ -148,13 +147,11 @@ private: | |||
148 | BScreen &m_screen; | 147 | BScreen &m_screen; |
149 | FbTk::Timer m_timer; | 148 | FbTk::Timer m_timer; |
150 | 149 | ||
151 | SlitClients m_client_list; | ||
152 | std::auto_ptr<LayerMenu> m_layermenu; | 150 | std::auto_ptr<LayerMenu> m_layermenu; |
153 | FbMenu m_clientlist_menu, m_slitmenu; | 151 | FbMenu m_clientlist_menu, m_slitmenu; |
154 | #ifdef XINERAMA | 152 | #ifdef XINERAMA |
155 | XineramaHeadMenu<Slit> *m_xineramaheadmenu; | 153 | XineramaHeadMenu<Slit> *m_xineramaheadmenu; |
156 | #endif // XINERAMA | 154 | #endif // XINERAMA |
157 | std::string m_filename; | ||
158 | 155 | ||
159 | struct frame { | 156 | struct frame { |
160 | frame(const FbTk::FbWindow &parent): | 157 | frame(const FbTk::FbWindow &parent): |
@@ -179,6 +176,28 @@ private: | |||
179 | static unsigned int s_eventmask; | 176 | static unsigned int s_eventmask; |
180 | Strut *m_strut; | 177 | Strut *m_strut; |
181 | 178 | ||
179 | class SlitClientsRes: public FbTk::Resource_base, public SlitClients { | ||
180 | public: | ||
181 | SlitClientsRes(FbTk::ResourceManager_base &rm, const std::string &name) | ||
182 | : FbTk::Resource_base(name, name), m_rm(rm) { | ||
183 | m_rm.addResource(*this); | ||
184 | } | ||
185 | |||
186 | ~SlitClientsRes() { | ||
187 | m_rm.removeResource(*this); | ||
188 | } | ||
189 | |||
190 | virtual void setDefaultValue() {} | ||
191 | virtual void setFromString(const char *) { assert(0); } | ||
192 | virtual std::string getString() const { assert(0); } | ||
193 | virtual void setFromLua(lua::state &l); | ||
194 | virtual void pushToLua(lua::state &l) const; | ||
195 | |||
196 | private: | ||
197 | FbTk::ResourceManager_base &m_rm; | ||
198 | }; | ||
199 | |||
200 | SlitClientsRes m_client_list; | ||
182 | FbTk::BoolResource m_rc_kde_dockapp, m_rc_auto_hide, m_rc_maximize_over; | 201 | FbTk::BoolResource m_rc_kde_dockapp, m_rc_auto_hide, m_rc_maximize_over; |
183 | FbTk::Resource<Slit::Placement, FbTk::EnumTraits<Slit::Placement> > m_rc_placement; | 202 | FbTk::Resource<Slit::Placement, FbTk::EnumTraits<Slit::Placement> > m_rc_placement; |
184 | FbTk::IntResource m_rc_alpha, m_rc_on_head; | 203 | FbTk::IntResource m_rc_alpha, m_rc_on_head; |
diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 8e9c543..177e985 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc | |||
@@ -251,7 +251,6 @@ Fluxbox::Fluxbox(int argc, char **argv, | |||
251 | m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"), | 251 | m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"), |
252 | m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "menuFile", "MenuFile"), | 252 | m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "menuFile", "MenuFile"), |
253 | m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), | 253 | m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), |
254 | m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "slitlistFile", "SlitlistFile"), | ||
255 | m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"), | 254 | m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"), |
256 | m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"), | 255 | m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"), |
257 | m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"), | 256 | m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"), |
@@ -1183,13 +1182,6 @@ void Fluxbox::load_rc() { | |||
1183 | 1182 | ||
1184 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); | 1183 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); |
1185 | 1184 | ||
1186 | if (!m_rc_slitlistfile->empty()) { | ||
1187 | *m_rc_slitlistfile = StringUtil::expandFilename(*m_rc_slitlistfile); | ||
1188 | } else { | ||
1189 | string filename = getDefaultDataFilename("slitlist"); | ||
1190 | m_rc_slitlistfile.setFromString(filename.c_str()); | ||
1191 | } | ||
1192 | |||
1193 | *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6); | 1185 | *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6); |
1194 | 1186 | ||
1195 | if (m_rc_stylefile->empty()) | 1187 | if (m_rc_stylefile->empty()) |
diff --git a/src/fluxbox.hh b/src/fluxbox.hh index 2e0aabb..97ea211 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh | |||
@@ -121,7 +121,6 @@ public: | |||
121 | const std::string &getStyleOverlayFilename() const { return *m_rc_styleoverlayfile; } | 121 | const std::string &getStyleOverlayFilename() const { return *m_rc_styleoverlayfile; } |
122 | 122 | ||
123 | const std::string &getMenuFilename() const { return *m_rc_menufile; } | 123 | const std::string &getMenuFilename() const { return *m_rc_menufile; } |
124 | const std::string &getSlitlistFilename() const { return *m_rc_slitlistfile; } | ||
125 | const std::string &getAppsFilename() const { return *m_rc_appsfile; } | 124 | const std::string &getAppsFilename() const { return *m_rc_appsfile; } |
126 | const std::string &getKeysFilename() const { return *m_rc_keyfile; } | 125 | const std::string &getKeysFilename() const { return *m_rc_keyfile; } |
127 | int colorsPerChannel() const { return *m_rc_colors_per_channel; } | 126 | int colorsPerChannel() const { return *m_rc_colors_per_channel; } |
@@ -241,7 +240,7 @@ private: | |||
241 | m_rc_tabs_padding; | 240 | m_rc_tabs_padding; |
242 | FbTk::StringResource m_rc_stylefile, | 241 | FbTk::StringResource m_rc_stylefile, |
243 | m_rc_styleoverlayfile, | 242 | m_rc_styleoverlayfile, |
244 | m_rc_menufile, m_rc_keyfile, m_rc_slitlistfile, | 243 | m_rc_menufile, m_rc_keyfile, |
245 | m_rc_appsfile; | 244 | m_rc_appsfile; |
246 | 245 | ||
247 | 246 | ||