Browse Source

Reworked windowmanager-sessions

Rather then hard coding the possible windowmanagers find the installed
sessions in the system and use them

Signed-off-by: madanyang <toganm@opensuse.org>
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
madanyang 11 years ago
parent
commit
059d9c7562
5 changed files with 47 additions and 23 deletions
  1. 3 0
      app.cpp
  2. 26 10
      cfg.cpp
  3. 2 2
      cfg.h
  4. 13 9
      panel.cpp
  5. 3 2
      panel.h

+ 3 - 0
app.cpp

@@ -364,6 +364,9 @@ void App::Run() {
 			LoginPanel->SetName(cfg->getOption("default_user") );
 		}
 
+        if (firstloop) {
+            LoginPanel->SwitchSession();
+        }
 
 		if (!AuthenticateUser(focuspass && firstloop)){
 			panelclosed = 0;

+ 26 - 10
cfg.cpp

@@ -54,7 +54,6 @@ Cfg::Cfg()
 	options.insert(option("authfile","/var/run/slim.auth"));
 	options.insert(option("shutdown_msg","The system is halting..."));
 	options.insert(option("reboot_msg","The system is rebooting..."));
-	options.insert(option("sessions","wmaker,blackbox,icewm"));
 	options.insert(option("sessiondir",""));
 	options.insert(option("hidecursor","false"));
 
@@ -292,7 +291,6 @@ void Cfg::split(vector<string>& v, const string& str, char c, bool useEmpty) {
 }
 
 void Cfg::fillSessionList(){
-	string strSessionList = getOption("sessions");
 	string strSessionDir  = getOption("sessiondir");
 
 	sessions.clear();
@@ -311,9 +309,29 @@ void Cfg::fillSessionList(){
 				struct stat oFileStat;
 
 				if (stat(strFile.c_str(), &oFileStat) == 0) {
-					if (S_ISREG(oFileStat.st_mode) &&
-						access(strFile.c_str(), R_OK | X_OK) == 0) {
-						sessions.push_back(string(pDirent->d_name));
+                    if (S_ISREG(oFileStat.st_mode) &&
+                            access(strFile.c_str(), R_OK) == 0){
+                        ifstream desktop_file( strFile.c_str() );
+                        if (desktop_file){
+                             string line, session_name = "", session_exec = "";
+                             while (getline( desktop_file, line )) {
+                                 if (line.substr(0, 5) == "Name=") {
+                                     session_name = line.substr(5);
+                                     if (!session_exec.empty())
+                                         break;
+                                 } else
+                                     if (line.substr(0, 5) == "Exec=") {
+                                         session_exec = line.substr(5);
+                                         if (!session_name.empty())
+                                             break;
+                                     }
+                             }
+                             desktop_file.close();
+                             pair<string,string> session(session_name,session_exec);
+                             sessions.push_back(session);
+                             cout << session_exec << " - " << session_name << endl;
+                        }
+
 					}
 				}
 			}
@@ -322,14 +340,12 @@ void Cfg::fillSessionList(){
 	}
 
 	if (sessions.empty()){
-		split(sessions, strSessionList, ',', false);
+        pair<string,string> session("","");
+        sessions.push_back(session);
 	}
 }
 
-string Cfg::nextSession(string current) {
-	if (sessions.size() < 1)
-		return current;
-
+pair<string,string> Cfg::nextSession() {
 	currentSession = (currentSession + 1) % sessions.size();
 	return sessions[currentSession];
 }

+ 2 - 2
cfg.h

@@ -41,14 +41,14 @@ public:
 					  char c, bool useEmpty=true);
 	static std::string Trim(const std::string &s);
 
-	std::string nextSession(std::string current);
+    std::pair<std::string,std::string> nextSession();
 
 private:
 	void fillSessionList();
 
 private:
 	std::map<std::string,std::string> options;
-	std::vector<std::string> sessions;
+    std::vector<std::pair<std::string,std::string> > sessions;
 	int currentSession;
 	std::string error;
 };

+ 13 - 9
panel.cpp

@@ -25,7 +25,8 @@ Panel::Panel(Display* dpy, int scr, Window root, Cfg* config,
 	cfg = config;
 	mode = panel_mode;
 
-	session = "";
+	session_name = "";
+    session_exec = "";
 	if (mode == Mode_Lock) {
 		Win = root;
 		viewport = GetPrimaryViewport();
@@ -265,7 +266,8 @@ void Panel::ClosePanel() {
 }
 
 void Panel::ClearPanel() {
-	session = "";
+	session_name = "";
+    session_exec = "";
 	Reset();
 	XClearWindow(Dpy, Root);
 	XClearWindow(Dpy, Win);
@@ -741,22 +743,24 @@ void Panel::ShowText(){
 }
 
 string Panel::getSession() {
-	return session;
+	return session_exec;
 }
 
 /* choose next available session type */
 void Panel::SwitchSession() {
-	session = cfg->nextSession(session);
-	if (session.size() > 0) {
-		ShowSession();
-	}
-}
+        pair<string,string> ses = cfg->nextSession();
+        session_name = ses.first;
+        session_exec = ses.second;
+        if (session_name.size() > 0) {
+                ShowSession();
+        }
+ }
 
 /* Display session type on the screen */
 void Panel::ShowSession() {
 	string msg_x, msg_y;
 	XClearWindow(Dpy, Root);
-	string currsession = cfg->getOption("session_msg") + " " + session;
+	string currsession = cfg->getOption("session_msg") + " " + session_name;
 	XGlyphInfo extents;
 
 	sessionfont = XftFontOpenName(Dpy, Scr, cfg->getOption("session_font").c_str());

+ 3 - 2
panel.h

@@ -88,6 +88,7 @@ public:
 	void SetName(const std::string &name);
 	const std::string& GetName(void) const;
 	const std::string& GetPasswd(void) const;
+	void SwitchSession();
 private:
 	Panel();
 	void Cursor(int visible);
@@ -95,7 +96,6 @@ private:
 	void OnExpose(void);
 	bool OnKeyPress(XEvent& event);
 	void ShowText();
-	void SwitchSession();
 	void ShowSession();
 
 	void SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
@@ -180,7 +180,8 @@ private:
 	std::string themedir;
 
 	/* Session handling */
-	std::string session;
+	std::string session_name;
+    std::string session_exec;
 };
 
 #endif /* _PANEL_H_ */