From 059d9c7562fa454ccc8047a0e9a91da111335359 Mon Sep 17 00:00:00 2001 From: madanyang Date: Thu, 2 May 2013 10:24:46 +0200 Subject: [PATCH] Reworked windowmanager-sessions Rather then hard coding the possible windowmanagers find the installed sessions in the system and use them Signed-off-by: madanyang Signed-off-by: Nobuhiro Iwamatsu --- app.cpp | 3 +++ cfg.cpp | 36 ++++++++++++++++++++++++++---------- cfg.h | 4 ++-- panel.cpp | 22 +++++++++++++--------- panel.h | 5 +++-- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/app.cpp b/app.cpp index b1b9d98..4558989 100644 --- a/app.cpp +++ b/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; diff --git a/cfg.cpp b/cfg.cpp index d77c62f..2719c51 100644 --- a/cfg.cpp +++ b/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& 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 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 session("",""); + sessions.push_back(session); } } -string Cfg::nextSession(string current) { - if (sessions.size() < 1) - return current; - +pair Cfg::nextSession() { currentSession = (currentSession + 1) % sessions.size(); return sessions[currentSession]; } diff --git a/cfg.h b/cfg.h index da48f9a..678d00d 100644 --- a/cfg.h +++ b/cfg.h @@ -41,14 +41,14 @@ class Cfg { char c, bool useEmpty=true); static std::string Trim(const std::string &s); - std::string nextSession(std::string current); + std::pair nextSession(); private: void fillSessionList(); private: std::map options; - std::vector sessions; + std::vector > sessions; int currentSession; std::string error; }; diff --git a/panel.cpp b/panel.cpp index 8904143..143f892 100644 --- a/panel.cpp +++ b/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 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()); diff --git a/panel.h b/panel.h index 95e611f..6f1a1cf 100644 --- a/panel.h +++ b/panel.h @@ -88,6 +88,7 @@ class Panel { 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 @@ class Panel { 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 @@ class Panel { std::string themedir; /* Session handling */ - std::string session; + std::string session_name; + std::string session_exec; }; #endif /* _PANEL_H_ */