Browse Source

Fix coding style

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/slim/trunk@224 7c53e7cc-98ea-0310-8f1f-a0b24da60408
iwamatsu 11 years ago
parent
commit
b7a2dbdc6d
23 changed files with 3517 additions and 3545 deletions
  1. 77 77
      Ck.cpp
  2. 13 13
      Ck.h
  3. 245 247
      PAM.cpp
  4. 65 65
      PAM.h
  5. 976 994
      app.cpp
  6. 62 64
      app.h
  7. 234 235
      cfg.cpp
  8. 23 23
      cfg.h
  9. 17 19
      const.h
  10. 767 769
      image.cpp
  11. 45 45
      image.h
  12. 83 83
      jpeg.c
  13. 22 22
      log.h
  14. 6 5
      main.cpp
  15. 42 42
      numlock.cpp
  16. 1 1
      numlock.h
  17. 535 535
      panel.cpp
  18. 117 119
      panel.h
  19. 142 142
      png.c
  20. 25 25
      switchuser.cpp
  21. 15 15
      switchuser.h
  22. 1 1
      util.cpp
  23. 4 4
      util.h

+ 77 - 77
Ck.cpp

@@ -19,126 +19,126 @@
 
 namespace Ck {
   Exception::Exception(const std::string &func,
-                       const std::string &errstr):
-    func(func),
-    errstr(errstr)
+					   const std::string &errstr):
+	func(func),
+	errstr(errstr)
   {}
 
   dbus_bool_t Session::ck_connector_open_graphic_session(const std::string &display,
-                                                         uid_t uid)
+														 uid_t uid)
   {
-    dbus_bool_t local        = true;
-    const char *session_type = "x11";
-    const char *x11_display  = display.c_str();
-    const char *x11_device   = get_x11_device(display);
-    const char *remote_host  = "";
-    const char *display_dev  = "";
-
-    return ck_connector_open_session_with_parameters(ckc, &error,
-                                                     "unix-user", &uid,
-                                                     "session-type", &session_type,
-                                                     "x11-display", &x11_display,
-                                                     "x11-display-device", &x11_device,
-                                                     "display-device", &display_dev,
-                                                     "remote-host-name", &remote_host,
-                                                     "is-local", &local,
-                                                     NULL);
+	dbus_bool_t local		= true;
+	const char *session_type = "x11";
+	const char *x11_display  = display.c_str();
+	const char *x11_device   = get_x11_device(display);
+	const char *remote_host  = "";
+	const char *display_dev  = "";
+
+	return ck_connector_open_session_with_parameters(ckc, &error,
+													 "unix-user", &uid,
+													 "session-type", &session_type,
+													 "x11-display", &x11_display,
+													 "x11-display-device", &x11_device,
+													 "display-device", &display_dev,
+													 "remote-host-name", &remote_host,
+													 "is-local", &local,
+													 NULL);
   }
 
   const char * Session::get_x11_device(const std::string &display)
   {
-    static char device[32];
+	static char device[32];
 
-    Display *xdisplay = XOpenDisplay(display.c_str());
+	Display *xdisplay = XOpenDisplay(display.c_str());
 
-    if(!xdisplay)
-      throw Exception(__func__, "cannot open display");
+	if(!xdisplay)
+	  throw Exception(__func__, "cannot open display");
 
-    Window root;
-    Atom xfree86_vt_atom;
-    Atom return_type_atom;
-    int return_format;
-    unsigned long return_count;
-    unsigned long bytes_left;
-    unsigned char *return_value;
-    long vt;
+	Window root;
+	Atom xfree86_vt_atom;
+	Atom return_type_atom;
+	int return_format;
+	unsigned long return_count;
+	unsigned long bytes_left;
+	unsigned char *return_value;
+	long vt;
 
-    xfree86_vt_atom = XInternAtom(xdisplay, "XFree86_VT", true);
+	xfree86_vt_atom = XInternAtom(xdisplay, "XFree86_VT", true);
 
-    if(xfree86_vt_atom == None)
-      throw Exception(__func__, "cannot get XFree86_VT");
+	if(xfree86_vt_atom == None)
+	  throw Exception(__func__, "cannot get XFree86_VT");
 
-    root = DefaultRootWindow(xdisplay);
+	root = DefaultRootWindow(xdisplay);
 
-    if(XGetWindowProperty(xdisplay, root, xfree86_vt_atom,
-                          0L, 1L, false, XA_INTEGER,
-                          &return_type_atom, &return_format,
-                          &return_count, &bytes_left,
-                          &return_value) != Success)
-      throw Exception(__func__, "cannot get root window property");
+	if(XGetWindowProperty(xdisplay, root, xfree86_vt_atom,
+						  0L, 1L, false, XA_INTEGER,
+						  &return_type_atom, &return_format,
+						  &return_count, &bytes_left,
+						  &return_value) != Success)
+	  throw Exception(__func__, "cannot get root window property");
 
-    if(return_type_atom != XA_INTEGER)
-      throw Exception(__func__, "bad atom type");
+	if(return_type_atom != XA_INTEGER)
+	  throw Exception(__func__, "bad atom type");
 
-    if(return_format != 32)
-      throw Exception(__func__, "invalid return format");
+	if(return_format != 32)
+	  throw Exception(__func__, "invalid return format");
 
-    if(return_count != 1)
-      throw Exception(__func__, "invalid count");
+	if(return_count != 1)
+	  throw Exception(__func__, "invalid count");
 
-    if(bytes_left != 0)
-      throw Exception(__func__, "invalid bytes left");
+	if(bytes_left != 0)
+	  throw Exception(__func__, "invalid bytes left");
 
-    vt = *((long *)return_value);
+	vt = *((long *)return_value);
 
-    std::snprintf(device, 32, "/dev/tty%ld", vt);
+	std::snprintf(device, 32, "/dev/tty%ld", vt);
 
-    if(return_value)
-      XFree(return_value);
+	if(return_value)
+	  XFree(return_value);
 
-    return device;
+	return device;
   }
 
   void Session::open_session(const std::string &display, uid_t uid)
   {
-    ckc = ck_connector_new();
-
-    if(!ckc)
-      throw Exception(__func__, "error setting up connection to ConsoleKit");
-
-    if(!ck_connector_open_graphic_session(display, uid)) {
-      if(dbus_error_is_set(&error))
-        throw Exception(__func__, error.message);
-      else
-        throw Exception(__func__, "cannot open ConsoleKit session: OOM, DBus system bus "
-                        " not available or insufficient privileges");
-    }
+	ckc = ck_connector_new();
+
+	if(!ckc)
+	  throw Exception(__func__, "error setting up connection to ConsoleKit");
+
+	if(!ck_connector_open_graphic_session(display, uid)) {
+	  if(dbus_error_is_set(&error))
+		throw Exception(__func__, error.message);
+	  else
+		throw Exception(__func__, "cannot open ConsoleKit session: OOM, DBus system bus "
+						" not available or insufficient privileges");
+	}
   }
 
   const char * Session::get_xdg_session_cookie()
   {
-    return ck_connector_get_cookie(ckc);
+	return ck_connector_get_cookie(ckc);
   }
 
   void Session::close_session()
   {
-    if(!ck_connector_close_session(ckc, &error)) {
-      if(dbus_error_is_set(&error))
-        throw Exception(__func__, error.message);
-      else
-        throw Exception(__func__, "cannot close ConsoleKit session: OOM, DBus system bus "
-                        " not available or insufficient privileges");
-    }
+	if(!ck_connector_close_session(ckc, &error)) {
+	  if(dbus_error_is_set(&error))
+		throw Exception(__func__, error.message);
+	  else
+		throw Exception(__func__, "cannot close ConsoleKit session: OOM, DBus system bus "
+						" not available or insufficient privileges");
+	}
   }
 
   Session::Session()
   {
-    dbus_error_init(&error);
+	dbus_error_init(&error);
   }
 
   Session::~Session()
   {
-    dbus_error_free(&error);
+	dbus_error_free(&error);
   }
 };
 

+ 13 - 13
Ck.h

@@ -18,26 +18,26 @@
 namespace Ck {
   class Exception {
   public:
-    std::string func;
-    std::string errstr;
-    Exception(const std::string &func, const std::string &errstr);
+	std::string func;
+	std::string errstr;
+	Exception(const std::string &func, const std::string &errstr);
   };
 
   class Session {
   private:
-    CkConnector *ckc;
-    DBusError error;
+	CkConnector *ckc;
+	DBusError error;
 
-    const char * get_x11_device(const std::string &display);
-    dbus_bool_t ck_connector_open_graphic_session(const std::string &display,
-                                                  uid_t uid);
+	const char * get_x11_device(const std::string &display);
+	dbus_bool_t ck_connector_open_graphic_session(const std::string &display,
+												  uid_t uid);
   public:
-    const char * get_xdg_session_cookie();
-    void open_session(const std::string &display, uid_t uid);
-    void close_session();
+	const char * get_xdg_session_cookie();
+	void open_session(const std::string &display, uid_t uid);
+	void close_session();
 
-    Session();
-    ~Session();
+	Session();
+	~Session();
   };
 };
 

+ 245 - 247
PAM.cpp

@@ -11,265 +11,263 @@
 #include "PAM.h"
 
 namespace PAM {
-    Exception::Exception(pam_handle_t* _pam_handle,
-               const std::string& _func_name,
-               int _errnum):
-        errnum(_errnum),
-        errstr(pam_strerror(_pam_handle, _errnum)),
-        func_name(_func_name)
-        {}
-
-    Exception::~Exception(void){}
-
-    Auth_Exception::Auth_Exception(pam_handle_t* _pam_handle,
-                                   const std::string& _func_name,
-                                   int _errnum):
-        Exception(_pam_handle, _func_name, _errnum){}
-
-    Cred_Exception::Cred_Exception(pam_handle_t* _pam_handle,
-                                   const std::string& _func_name,
-                                   int _errnum):
-        Exception(_pam_handle, _func_name, _errnum){}
-
-    int Authenticator::_end(void){
-        int result=pam_end(pam_handle, last_result);
-        pam_handle=0;
-        return result;
-    }
-
-    Authenticator::Authenticator(conversation* conv, void* data):
-        pam_handle(0),
-        last_result(PAM_SUCCESS)
-    {
-        pam_conversation.conv=conv;
-        pam_conversation.appdata_ptr=data;
-    }
-
-    Authenticator::~Authenticator(void){
-        if (pam_handle) _end();
-    }
-
-    void Authenticator::start(const std::string& service){
-        switch((last_result=pam_start(service.c_str(), NULL, &pam_conversation, &pam_handle))){
-            default:
-                throw Exception(pam_handle, "pam_start()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
-
-    void Authenticator::end(void){
-        switch((last_result=_end())){
-            default:
-                throw Exception(pam_handle, "pam_end()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-
-        }
-        return;
-    }
-
-    void Authenticator::set_item(const Authenticator::ItemType item, const void* value){
-        switch((last_result=pam_set_item(pam_handle, item, value))){
-            default:
-            _end();
-                throw Exception(pam_handle, "pam_set_item()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
-
-    const void* Authenticator::get_item(const Authenticator::ItemType item){
-        const void* data;
-        switch ((last_result=pam_get_item(pam_handle, item, &data))){
-            default:
-            case PAM_SYSTEM_ERR:
+	Exception::Exception(pam_handle_t* _pam_handle,
+			   const std::string& _func_name,
+			   int _errnum):
+		errnum(_errnum),
+		errstr(pam_strerror(_pam_handle, _errnum)),
+		func_name(_func_name)
+		{}
+
+	Exception::~Exception(void){}
+
+	Auth_Exception::Auth_Exception(pam_handle_t* _pam_handle,
+								   const std::string& _func_name,
+								   int _errnum):
+		Exception(_pam_handle, _func_name, _errnum){}
+
+	Cred_Exception::Cred_Exception(pam_handle_t* _pam_handle,
+								   const std::string& _func_name,
+								   int _errnum):
+		Exception(_pam_handle, _func_name, _errnum){}
+
+	int Authenticator::_end(void){
+		int result=pam_end(pam_handle, last_result);
+		pam_handle=0;
+		return result;
+	}
+
+	Authenticator::Authenticator(conversation* conv, void* data):
+		pam_handle(0),
+		last_result(PAM_SUCCESS)
+	{
+		pam_conversation.conv=conv;
+		pam_conversation.appdata_ptr=data;
+	}
+
+	Authenticator::~Authenticator(void){
+		if (pam_handle) _end();
+	}
+
+	void Authenticator::start(const std::string& service){
+		switch((last_result=pam_start(service.c_str(), NULL, &pam_conversation, &pam_handle))){
+			default:
+				throw Exception(pam_handle, "pam_start()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	void Authenticator::end(void){
+		switch((last_result=_end())){
+			default:
+				throw Exception(pam_handle, "pam_end()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	void Authenticator::set_item(const Authenticator::ItemType item, const void* value){
+		switch((last_result=pam_set_item(pam_handle, item, value))){
+			default:
+			_end();
+				throw Exception(pam_handle, "pam_set_item()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	const void* Authenticator::get_item(const Authenticator::ItemType item){
+		const void* data;
+		switch ((last_result=pam_get_item(pam_handle, item, &data))){
+			default:
+			case PAM_SYSTEM_ERR:
 #ifdef __LIBPAM_VERSION
-            case PAM_BAD_ITEM:
+			case PAM_BAD_ITEM:
 #endif
-                _end();
-                throw Exception(pam_handle, "pam_get_item()", last_result);
+				_end();
+				throw Exception(pam_handle, "pam_get_item()", last_result);
 
-            case PAM_PERM_DENIED: // The value of item was NULL
-            case PAM_SUCCESS:
-                break;
-        }
-        return data;
-    }
+			case PAM_PERM_DENIED: /* The value of item was NULL */
+			case PAM_SUCCESS:
+				break;
+		}
+		return data;
+	}
 
 #ifdef __LIBPAM_VERSION
-    void Authenticator::fail_delay(const unsigned int micro_sec){
-        switch((last_result=pam_fail_delay(pam_handle, micro_sec))){
-            default:
-                _end();
-                throw Exception(pam_handle, "fail_delay()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
+	void Authenticator::fail_delay(const unsigned int micro_sec){
+		switch((last_result=pam_fail_delay(pam_handle, micro_sec))){
+			default:
+				_end();
+				throw Exception(pam_handle, "fail_delay()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
 #endif
 
-    void Authenticator::authenticate(void){
-        switch((last_result=pam_authenticate(pam_handle, 0))){
-            default:
-            case PAM_ABORT:
-            case PAM_AUTHINFO_UNAVAIL:
-                _end();
-                throw Exception(pam_handle, "pam_authenticate()", last_result);
-
-            case PAM_USER_UNKNOWN:
-            case PAM_MAXTRIES:
-            case PAM_CRED_INSUFFICIENT:
-            case PAM_AUTH_ERR:
-                throw Auth_Exception(pam_handle, "pam_authentication()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-
-        switch((last_result=pam_acct_mgmt(pam_handle, PAM_SILENT))){
-            // The documentation and implementation of Linux PAM differs:
-            // PAM_NEW_AUTHTOKEN_REQD is described in the documentation but
-            // don't exists in the actual implementation. This issue needs
-            // to be fixes at some point.
-
-            default:
-            //case PAM_NEW_AUTHTOKEN_REQD:
-            case PAM_ACCT_EXPIRED:
-            case PAM_USER_UNKNOWN:
-                _end();
-                throw Exception(pam_handle, "pam_acct_mgmt()", last_result);
-                
-            case PAM_AUTH_ERR:
-            case PAM_PERM_DENIED:
-                throw Auth_Exception(pam_handle, "pam_acct_mgmt()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    void Authenticator::open_session(void){
-        switch((last_result=pam_setcred(pam_handle, PAM_ESTABLISH_CRED))){
-            default:
-            case PAM_CRED_ERR:
-            case PAM_CRED_UNAVAIL:
-                _end();
-                throw Exception(pam_handle, "pam_setcred()", last_result);
-
-            case PAM_CRED_EXPIRED:
-            case PAM_USER_UNKNOWN:
-                throw Cred_Exception(pam_handle, "pam_setcred()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-
-        switch((last_result=pam_open_session(pam_handle, 0))){
-            // The documentation and implementation of Linux PAM differs:
-            // PAM_SESSION_ERROR is described in the documentation but
-            // don't exists in the actual implementation. This issue needs
-            // to be fixes at some point.
-
-            default:
-            //case PAM_SESSION_ERROR:
-                pam_setcred(pam_handle, PAM_DELETE_CRED);
-                _end();
-                throw Exception(pam_handle, "pam_open_session()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    void Authenticator::close_session(void){
-        switch((last_result=pam_close_session(pam_handle, 0))){
-            // The documentation and implementation of Linux PAM differs:
-            // PAM_SESSION_ERROR is described in the documentation but
-            // don't exists in the actual implementation. This issue needs
-            // to be fixes at some point.
-
-            default:
-            //case PAM_SESSION_ERROR:
-                pam_setcred(pam_handle, PAM_DELETE_CRED);
-                _end();
-                throw Exception(pam_handle, "pam_close_session", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        switch((last_result=pam_setcred(pam_handle, PAM_DELETE_CRED))){
-            default:
-            case PAM_CRED_ERR:
-            case PAM_CRED_UNAVAIL:
-            case PAM_CRED_EXPIRED:
-            case PAM_USER_UNKNOWN:
-                _end();
-                throw Exception(pam_handle, "pam_setcred()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
-
-    void Authenticator::setenv(const std::string& key, const std::string& value){
-        std::string name_value = key+"="+value;
-        switch((last_result=pam_putenv(pam_handle, name_value.c_str()))){
-            default:
-            case PAM_PERM_DENIED:
-            case PAM_ABORT:
-            case PAM_BUF_ERR:
+	void Authenticator::authenticate(void){
+		switch((last_result=pam_authenticate(pam_handle, 0))){
+			default:
+			case PAM_ABORT:
+			case PAM_AUTHINFO_UNAVAIL:
+				_end();
+				throw Exception(pam_handle, "pam_authenticate()", last_result);
+
+			case PAM_USER_UNKNOWN:
+			case PAM_MAXTRIES:
+			case PAM_CRED_INSUFFICIENT:
+			case PAM_AUTH_ERR:
+				throw Auth_Exception(pam_handle, "pam_authentication()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+
+		switch((last_result=pam_acct_mgmt(pam_handle, PAM_SILENT))){
+			/* The documentation and implementation of Linux PAM differs:
+			   PAM_NEW_AUTHTOKEN_REQD is described in the documentation but
+			   don't exists in the actual implementation. This issue needs
+			   to be fixes at some point. */
+
+			default:
+			/* case PAM_NEW_AUTHTOKEN_REQD: */
+			case PAM_ACCT_EXPIRED:
+			case PAM_USER_UNKNOWN:
+				_end();
+				throw Exception(pam_handle, "pam_acct_mgmt()", last_result);
+				
+			case PAM_AUTH_ERR:
+			case PAM_PERM_DENIED:
+				throw Auth_Exception(pam_handle, "pam_acct_mgmt()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	void Authenticator::open_session(void){
+		switch((last_result=pam_setcred(pam_handle, PAM_ESTABLISH_CRED))){
+			default:
+			case PAM_CRED_ERR:
+			case PAM_CRED_UNAVAIL:
+				_end();
+				throw Exception(pam_handle, "pam_setcred()", last_result);
+
+			case PAM_CRED_EXPIRED:
+			case PAM_USER_UNKNOWN:
+				throw Cred_Exception(pam_handle, "pam_setcred()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+
+		switch((last_result=pam_open_session(pam_handle, 0))){
+			/* The documentation and implementation of Linux PAM differs:
+			   PAM_SESSION_ERROR is described in the documentation but 
+			   don't exists in the actual implementation. This issue needs 
+			   to be fixes at some point. */
+
+			default:
+			/* case PAM_SESSION_ERROR: */
+				pam_setcred(pam_handle, PAM_DELETE_CRED);
+				_end();
+				throw Exception(pam_handle, "pam_open_session()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	void Authenticator::close_session(void){
+		switch((last_result=pam_close_session(pam_handle, 0))){
+			/* The documentation and implementation of Linux PAM differs:
+			   PAM_SESSION_ERROR is described in the documentation but
+			   don't exists in the actual implementation. This issue needs
+			   to be fixes at some point. */
+
+			default:
+			/* case PAM_SESSION_ERROR: */
+				pam_setcred(pam_handle, PAM_DELETE_CRED);
+				_end();
+				throw Exception(pam_handle, "pam_close_session", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		switch((last_result=pam_setcred(pam_handle, PAM_DELETE_CRED))){
+			default:
+			case PAM_CRED_ERR:
+			case PAM_CRED_UNAVAIL:
+			case PAM_CRED_EXPIRED:
+			case PAM_USER_UNKNOWN:
+				_end();
+				throw Exception(pam_handle, "pam_setcred()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	void Authenticator::setenv(const std::string& key, const std::string& value){
+		std::string name_value = key+"="+value;
+		switch((last_result=pam_putenv(pam_handle, name_value.c_str()))){
+			default:
+			case PAM_PERM_DENIED:
+			case PAM_ABORT:
+			case PAM_BUF_ERR:
 #ifdef __LIBPAM_VERSION
-            case PAM_BAD_ITEM:
+			case PAM_BAD_ITEM:
 #endif
-                _end();
-                throw Exception(pam_handle, "pam_putenv()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    void Authenticator::delenv(const std::string& key){
-        switch((last_result=pam_putenv(pam_handle, key.c_str()))){
-            default:
-            case PAM_PERM_DENIED:
-            case PAM_ABORT:
-            case PAM_BUF_ERR:
+				_end();
+				throw Exception(pam_handle, "pam_putenv()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	void Authenticator::delenv(const std::string& key){
+		switch((last_result=pam_putenv(pam_handle, key.c_str()))){
+			default:
+			case PAM_PERM_DENIED:
+			case PAM_ABORT:
+			case PAM_BUF_ERR:
 #ifdef __LIBPAM_VERSION
-            case PAM_BAD_ITEM:
+			case PAM_BAD_ITEM:
 #endif
-                _end();
-                throw Exception(pam_handle, "pam_putenv()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    const char* Authenticator::getenv(const std::string& key){
-        return pam_getenv(pam_handle, key.c_str());
-    }
-
-    char** Authenticator::getenvlist(void){
-        return pam_getenvlist(pam_handle);
-    }
-
+				_end();
+				throw Exception(pam_handle, "pam_putenv()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	const char* Authenticator::getenv(const std::string& key){
+		return pam_getenv(pam_handle, key.c_str());
+	}
+
+	char** Authenticator::getenvlist(void){
+		return pam_getenvlist(pam_handle);
+	}
 };
 
 std::ostream& operator<<( std::ostream& os, const PAM::Exception& e){
-    os << e.func_name << ": " << e.errstr;
-    return os;
+	os << e.func_name << ": " << e.errstr;
+	return os;
 }

+ 65 - 65
PAM.h

@@ -17,83 +17,83 @@
 #endif
 
 namespace PAM {
-    class Exception{
-    public:
-        int errnum;
-        std::string errstr;
-        std::string func_name;
-        Exception(pam_handle_t* _pam_handle,
-                  const std::string& _func_name,
-                  int _errnum);
-        virtual ~Exception(void);
-    };
+	class Exception{
+	public:
+		int errnum;
+		std::string errstr;
+		std::string func_name;
+		Exception(pam_handle_t* _pam_handle,
+				  const std::string& _func_name,
+				  int _errnum);
+		virtual ~Exception(void);
+	};
 
-    class Auth_Exception: public Exception{
-    public:
-        Auth_Exception(pam_handle_t* _pam_handle,
-                       const std::string& _func_name,
-                       int _errnum);
-    };
+	class Auth_Exception: public Exception{
+	public:
+		Auth_Exception(pam_handle_t* _pam_handle,
+					   const std::string& _func_name,
+					   int _errnum);
+	};
 
-    class Cred_Exception: public Exception{
-    public:
-        Cred_Exception(pam_handle_t* _pam_handle,
-                       const std::string& _func_name,
-                       int _errnum);
-    };
+	class Cred_Exception: public Exception{
+	public:
+		Cred_Exception(pam_handle_t* _pam_handle,
+					   const std::string& _func_name,
+					   int _errnum);
+	};
 
 
-    class Authenticator{
-    private:
-        struct pam_conv pam_conversation;
-        pam_handle_t* pam_handle;
-        int last_result;
+	class Authenticator{
+	private:
+		struct pam_conv pam_conversation;
+		pam_handle_t* pam_handle;
+		int last_result;
 
-        int _end(void);
-    public:
-        typedef int (conversation)(int num_msg,
-                           const struct pam_message **msg,
-                           struct pam_response **resp,
-                           void *appdata_ptr);
+		int _end(void);
+	public:
+		typedef int (conversation)(int num_msg,
+						   const struct pam_message **msg,
+						   struct pam_response **resp,
+						   void *appdata_ptr);
 
-        enum ItemType {
-            Service     = PAM_SERVICE,
-            User        = PAM_USER,
-            User_Prompt = PAM_USER_PROMPT,
-            TTY         = PAM_TTY,
-            Requestor   = PAM_RUSER,
-            Host        = PAM_RHOST,
-            Conv        = PAM_CONV,
+		enum ItemType {
+			Service	 = PAM_SERVICE,
+			User		= PAM_USER,
+			User_Prompt = PAM_USER_PROMPT,
+			TTY		 = PAM_TTY,
+			Requestor   = PAM_RUSER,
+			Host		= PAM_RHOST,
+			Conv		= PAM_CONV,
 #ifdef __LIBPAM_VERSION
-            //Fail_Delay  = PAM_FAIL_DELAY
+			/* Fail_Delay  = PAM_FAIL_DELAY */
 #endif
-        };
+		};
 
-    public:
-        Authenticator(conversation* conv, void* data=0);
-        ~Authenticator(void);
-        
-        void start(const std::string& service);
-        void end(void);
-        void set_item(const ItemType item, const void* value);
-        const void* get_item(const ItemType item);
+	public:
+		Authenticator(conversation* conv, void* data=0);
+		~Authenticator(void);
+		
+		void start(const std::string& service);
+		void end(void);
+		void set_item(const ItemType item, const void* value);
+		const void* get_item(const ItemType item);
 #ifdef __LIBPAM_VERSION
-        void fail_delay(const unsigned int micro_sec);
+		void fail_delay(const unsigned int micro_sec);
 #endif
-        void authenticate(void);
-        void open_session(void);
-        void close_session(void);
-        void setenv(const std::string& key, const std::string& value);
-        void delenv(const std::string& key);
-        const char* getenv(const std::string& key);
-        char** getenvlist(void);
+		void authenticate(void);
+		void open_session(void);
+		void close_session(void);
+		void setenv(const std::string& key, const std::string& value);
+		void delenv(const std::string& key);
+		const char* getenv(const std::string& key);
+		char** getenvlist(void);
 
-    private:
-        // Explicitly disable copy constructor and copy assignment
-        Authenticator(const PAM::Authenticator&);
-        Authenticator& operator=(const PAM::Authenticator&);
-    };
+	private:
+		/* Explicitly disable copy constructor and copy assignment */
+		Authenticator(const PAM::Authenticator&);
+		Authenticator& operator=(const PAM::Authenticator&);
+	};
 };
 
 std::ostream& operator<<( std::ostream& os, const PAM::Exception& e);
-#endif
+#endif /* _PAM_H_ */

+ 976 - 994
app.cpp

@@ -9,7 +9,6 @@
    (at your option) any later version.
 */
 
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -27,7 +26,6 @@
 #include "numlock.h"
 #include "util.h"
 
-
 #ifdef HAVE_SHADOW
 #include <shadow.h>
 #endif
@@ -38,67 +36,67 @@ using namespace std;
 #include <string>
 
 int conv(int num_msg, const struct pam_message **msg,
-         struct pam_response **resp, void *appdata_ptr){
-    *resp = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
-    Panel* panel = *static_cast<Panel**>(appdata_ptr);
-    int result = PAM_SUCCESS;
-    for (int i=0; i<num_msg; i++){
-        (*resp)[i].resp=0;
-        (*resp)[i].resp_retcode=0;
-        switch(msg[i]->msg_style){
-            case PAM_PROMPT_ECHO_ON:
-                // We assume PAM is asking for the username
-                panel->EventHandler(Panel::Get_Name);
-                switch(panel->getAction()){
-                    case Panel::Suspend:
-                    case Panel::Halt:
-                    case Panel::Reboot:
-                        (*resp)[i].resp=strdup("root");
-                        break;
-
-                    case Panel::Console:
-                    case Panel::Exit:
-                    case Panel::Login:
-                        (*resp)[i].resp=strdup(panel->GetName().c_str());
-                        break;
-                }
-                break;
-
-            case PAM_PROMPT_ECHO_OFF:
-                // We assume PAM is asking for the password
-                switch(panel->getAction()){
-                    case Panel::Console:
-                    case Panel::Exit:
-                        // We should leave now!
-                        result=PAM_CONV_ERR;
-                        break;
-
-                    default:
-                        panel->EventHandler(Panel::Get_Passwd);
-                        (*resp)[i].resp=strdup(panel->GetPasswd().c_str());
-                        break;
-                }
-                break;
-
-            case PAM_ERROR_MSG:
-            case PAM_TEXT_INFO:
-                // We simply write these to the log
-                // TODO: Maybe we should simply ignore them
-                logStream << APPNAME << ": " << msg[i]->msg << endl;
-                break;
-        }
-        if (result!=PAM_SUCCESS) break;
-    }
-    if (result!=PAM_SUCCESS){
-        for (int i=0; i<num_msg; i++){
-            if ((*resp)[i].resp==0) continue;
-            free((*resp)[i].resp);
-            (*resp)[i].resp=0;
-        };
-        free(*resp);
-        *resp=0;
-    };
-    return result;
+		 struct pam_response **resp, void *appdata_ptr){
+	*resp = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
+	Panel* panel = *static_cast<Panel**>(appdata_ptr);
+	int result = PAM_SUCCESS;
+	for (int i=0; i<num_msg; i++){
+		(*resp)[i].resp=0;
+		(*resp)[i].resp_retcode=0;
+		switch(msg[i]->msg_style){
+			case PAM_PROMPT_ECHO_ON:
+				/* We assume PAM is asking for the username */
+				panel->EventHandler(Panel::Get_Name);
+				switch(panel->getAction()){
+					case Panel::Suspend:
+					case Panel::Halt:
+					case Panel::Reboot:
+						(*resp)[i].resp=strdup("root");
+						break;
+
+					case Panel::Console:
+					case Panel::Exit:
+					case Panel::Login:
+						(*resp)[i].resp=strdup(panel->GetName().c_str());
+						break;
+				}
+				break;
+
+			case PAM_PROMPT_ECHO_OFF:
+				/* We assume PAM is asking for the password */
+				switch(panel->getAction()){
+					case Panel::Console:
+					case Panel::Exit:
+						/* We should leave now! */
+						result=PAM_CONV_ERR;
+						break;
+
+					default:
+						panel->EventHandler(Panel::Get_Passwd);
+						(*resp)[i].resp=strdup(panel->GetPasswd().c_str());
+						break;
+				}
+				break;
+
+			case PAM_ERROR_MSG:
+			case PAM_TEXT_INFO:
+				/* We simply write these to the log
+				   TODO: Maybe we should simply ignore them */
+				logStream << APPNAME << ": " << msg[i]->msg << endl;
+				break;
+		}
+		if (result!=PAM_SUCCESS) break;
+	}
+	if (result!=PAM_SUCCESS){
+		for (int i=0; i<num_msg; i++){
+			if ((*resp)[i].resp==0) continue;
+			free((*resp)[i].resp);
+			(*resp)[i].resp=0;
+		};
+		free(*resp);
+		*resp=0;
+	};
+	return result;
 }
 #endif
 
@@ -106,24 +104,23 @@ extern App* LoginApp;
 
 int xioerror(Display *disp) {
 	LoginApp->RestartServer();
-    return 0;
+	return 0;
 }
 
 void CatchSignal(int sig) {
-    logStream << APPNAME << ": unexpected signal " << sig << endl;
+	logStream << APPNAME << ": unexpected signal " << sig << endl;
 
-    if (LoginApp->isServerStarted())
-        LoginApp->StopServer();
+	if (LoginApp->isServerStarted())
+		LoginApp->StopServer();
 
-    LoginApp->RemoveLock();
-    exit(ERR_EXIT);
+	LoginApp->RemoveLock();
+	exit(ERR_EXIT);
 }
 
 void User1Signal(int sig) {
-    signal(sig, User1Signal);
+	signal(sig, User1Signal);
 }
 
-
 #ifdef USE_PAM
 App::App(int argc, char** argv)
   : pam(conv, static_cast<void*>(&LoginPanel)),
@@ -131,1126 +128,1111 @@ App::App(int argc, char** argv)
 App::App(int argc, char** argv)
   :
 #endif
-    mcookiesize(32)		// Must be divisible by 4
+	mcookiesize(32)		/* Must be divisible by 4 */
 {
-    int tmp;
-    ServerPID = -1;
-    testing = false;
-    serverStarted = false;
-    mcookie = string(App::mcookiesize, 'a');
-    daemonmode = false;
-    force_nodaemon = false;
-    firstlogin = true;
-    Dpy = NULL;
-
-    // Parse command line
-    // Note: we force a option for nodaemon switch to handle "-nodaemon"
-    while((tmp = getopt(argc, argv, "vhp:n:d?")) != EOF) {
-        switch (tmp) {
-        case 'p':    // Test theme
-            testtheme = optarg;
-            testing = true;
-            if (testtheme == NULL) {
-                logStream << "The -p option requires an argument" << endl;
-                exit(ERR_EXIT);
-            }
-            break;
-        case 'd':    // Daemon mode
-            daemonmode = true;
-            break;
-        case 'n':    // Daemon mode
-            daemonmode = false;
-            force_nodaemon = true;
-            break;
-        case 'v':    // Version
-            std::cout << APPNAME << " version " << VERSION << endl;
-            exit(OK_EXIT);
-            break;
-        case '?':    // Illegal
-            logStream << endl;
-        case 'h':   // Help
-            logStream << "usage:  " << APPNAME << " [option ...]" << endl
-            << "options:" << endl
-            << "    -d: daemon mode" << endl
-            << "    -nodaemon: no-daemon mode" << endl
-            << "    -v: show version" << endl
-            << "    -p /path/to/theme/dir: preview theme" << endl;
-            exit(OK_EXIT);
-            break;
-        }
-    }
+	int tmp;
+	ServerPID = -1;
+	testing = false;
+	serverStarted = false;
+	mcookie = string(App::mcookiesize, 'a');
+	daemonmode = false;
+	force_nodaemon = false;
+	firstlogin = true;
+	Dpy = NULL;
+
+	/* Parse command line
+	   Note: we force a option for nodaemon switch to handle "-nodaemon" */
+	while((tmp = getopt(argc, argv, "vhp:n:d?")) != EOF) {
+		switch (tmp) {
+		case 'p':	/* Test theme */
+			testtheme = optarg;
+			testing = true;
+			if (testtheme == NULL) {
+				logStream << "The -p option requires an argument" << endl;
+				exit(ERR_EXIT);
+			}
+			break;
+		case 'd':	/* Daemon mode */
+			daemonmode = true;
+			break;
+		case 'n':	/* Daemon mode */
+			daemonmode = false;
+			force_nodaemon = true;
+			break;
+		case 'v':	/* Version */
+			std::cout << APPNAME << " version " << VERSION << endl;
+			exit(OK_EXIT);
+			break;
+		case '?':	/* Illegal */
+			logStream << endl;
+		case 'h':   /* Help */
+			logStream << "usage:  " << APPNAME << " [option ...]" << endl
+			<< "options:" << endl
+			<< "	-d: daemon mode" << endl
+			<< "	-nodaemon: no-daemon mode" << endl
+			<< "	-v: show version" << endl
+			<< "	-p /path/to/theme/dir: preview theme" << endl;
+			exit(OK_EXIT);
+			break;
+		}
+	}
 #ifndef XNEST_DEBUG 
-    if (getuid() != 0 && !testing) {
-        logStream << APPNAME << ": only root can run this program" << endl;
-        exit(ERR_EXIT);
-    }
+	if (getuid() != 0 && !testing) {
+		logStream << APPNAME << ": only root can run this program" << endl;
+		exit(ERR_EXIT);
+	}
 #endif /* XNEST_DEBUG */
 
 }
 
-
 void App::Run() {
-    DisplayName = DISPLAY;
+	DisplayName = DISPLAY;
 
 #ifdef XNEST_DEBUG
-    char* p = getenv("DISPLAY");
-    if (p && p[0]) {
-        DisplayName = p;
-        cout << "Using display name " << DisplayName << endl;
-    }
+	char* p = getenv("DISPLAY");
+	if (p && p[0]) {
+		DisplayName = p;
+		cout << "Using display name " << DisplayName << endl;
+	}
 #endif
 
-
-    // Read configuration and theme
-    cfg = new Cfg;
-    cfg->readConf(CFGFILE);
-    string themebase = "";
-    string themefile = "";
-    string themedir = "";
-    themeName = "";
-    if (testing) {
-        themeName = testtheme;
-    } else {
-        themebase = string(THEMESDIR) + "/";
-        themeName = cfg->getOption("current_theme");
-        string::size_type pos;
-        if ((pos = themeName.find(",")) != string::npos) {
-            // input is a set
-            themeName = findValidRandomTheme(themeName);
-            if (themeName == "") {
-                themeName = "default";
-            }
-        }
-    }
+	/* Read configuration and theme */
+	cfg = new Cfg;
+	cfg->readConf(CFGFILE);
+	string themebase = "";
+	string themefile = "";
+	string themedir = "";
+	themeName = "";
+	if (testing) {
+		themeName = testtheme;
+	} else {
+		themebase = string(THEMESDIR) + "/";
+		themeName = cfg->getOption("current_theme");
+		string::size_type pos;
+		if ((pos = themeName.find(",")) != string::npos) {
+			/* input is a set */
+			themeName = findValidRandomTheme(themeName);
+			if (themeName == "") {
+				themeName = "default";
+			}
+		}
+	}
 
 #ifdef USE_PAM
-    try{
-        pam.start("slim");
-        pam.set_item(PAM::Authenticator::TTY, DisplayName);
-        pam.set_item(PAM::Authenticator::Requestor, "root");
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    };
+	try{
+		pam.start("slim");
+		pam.set_item(PAM::Authenticator::TTY, DisplayName);
+		pam.set_item(PAM::Authenticator::Requestor, "root");
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	};
 #endif
 
-    bool loaded = false;
-    while (!loaded) {
-        themedir =  themebase + themeName;
-        themefile = themedir + THEMESFILE;
-        if (!cfg->readConf(themefile)) {
-            if (themeName == "default") {
-                logStream << APPNAME << ": Failed to open default theme file "
-                     << themefile << endl;
-                exit(ERR_EXIT);
-            } else {
-                logStream << APPNAME << ": Invalid theme in config: "
-                     << themeName << endl;
-                themeName = "default";
-            }
-        } else {
-            loaded = true;
-        }
-    }
-
-    if (!testing) {
-        // Create lock file
-        LoginApp->GetLock();
-
-        // Start x-server
-        setenv("DISPLAY", DisplayName, 1);
-        signal(SIGQUIT, CatchSignal);
-        signal(SIGTERM, CatchSignal);
-        signal(SIGKILL, CatchSignal);
-        signal(SIGINT, CatchSignal);
-        signal(SIGHUP, CatchSignal);
-        signal(SIGPIPE, CatchSignal);
-        signal(SIGUSR1, User1Signal);
+	bool loaded = false;
+	while (!loaded) {
+		themedir =  themebase + themeName;
+		themefile = themedir + THEMESFILE;
+		if (!cfg->readConf(themefile)) {
+			if (themeName == "default") {
+				logStream << APPNAME << ": Failed to open default theme file "
+					 << themefile << endl;
+				exit(ERR_EXIT);
+			} else {
+				logStream << APPNAME << ": Invalid theme in config: "
+					 << themeName << endl;
+				themeName = "default";
+			}
+		} else {
+			loaded = true;
+		}
+	}
+
+	if (!testing) {
+		/* Create lock file */
+		LoginApp->GetLock();
+
+		/* Start x-server */
+		setenv("DISPLAY", DisplayName, 1);
+		signal(SIGQUIT, CatchSignal);
+		signal(SIGTERM, CatchSignal);
+		signal(SIGKILL, CatchSignal);
+		signal(SIGINT, CatchSignal);
+		signal(SIGHUP, CatchSignal);
+		signal(SIGPIPE, CatchSignal);
+		signal(SIGUSR1, User1Signal);
 
 #ifndef XNEST_DEBUG
-        if (!force_nodaemon && cfg->getOption("daemon") == "yes") {
-            daemonmode = true;
-        }
+		if (!force_nodaemon && cfg->getOption("daemon") == "yes") {
+			daemonmode = true;
+		}
 
-        // Daemonize
-        if (daemonmode) {
-            if (daemon(0, 0) == -1) {
-                logStream << APPNAME << ": " << strerror(errno) << endl;
-                exit(ERR_EXIT);
-            }
-        }
+		/* Daemonize */
+		if (daemonmode) {
+			if (daemon(0, 0) == -1) {
+				logStream << APPNAME << ": " << strerror(errno) << endl;
+				exit(ERR_EXIT);
+			}
+		}
 
-        OpenLog();
+		OpenLog();
 
-        if (daemonmode)
-            UpdatePid();
+		if (daemonmode)
+			UpdatePid();
 
-        CreateServerAuth();
-        StartServer();
+		CreateServerAuth();
+		StartServer();
 #endif
 
-    }
-
-    // Open display
-    if((Dpy = XOpenDisplay(DisplayName)) == 0) {
-        logStream << APPNAME << ": could not open display '"
-             << DisplayName << "'" << endl;
-        if (!testing) StopServer();
-        exit(ERR_EXIT);
-    }
-
-    // Get screen and root window
-    Scr = DefaultScreen(Dpy);
-    Root = RootWindow(Dpy, Scr);
-
-    // for tests we use a standard window
-    if (testing) {
-        Window RealRoot = RootWindow(Dpy, Scr);
-        Root = XCreateSimpleWindow(Dpy, RealRoot, 0, 0, 1280, 1024, 0, 0, 0);
-        XMapWindow(Dpy, Root);
-        XFlush(Dpy);
-    } else {
-        blankScreen();
-    }
-
-    HideCursor();
-
-    // Create panel
-    LoginPanel = new Panel(Dpy, Scr, Root, cfg, themedir);
-    bool firstloop = true; // 1st time panel is shown (for automatic username)
-    bool focuspass = cfg->getOption("focus_password")=="yes";
-    bool autologin = cfg->getOption("auto_login")=="yes";
-    
-    if (firstlogin && cfg->getOption("default_user") != "") {
-        LoginPanel->SetName(cfg->getOption("default_user") );
-        #ifdef USE_PAM
-	pam.set_item(PAM::Authenticator::User, cfg->getOption("default_user").c_str());
-	#endif
-        firstlogin = false;
-        if (autologin) {
-            Login();
-        }
-    }
-
-    // Set NumLock
-    string numlock = cfg->getOption("numlock");
-    if (numlock == "on") {
-        NumLock::setOn(Dpy);
-    } else if (numlock == "off") {
-        NumLock::setOff(Dpy);
-    }
-    
-    // Start looping
-    int panelclosed = 1;
-    Panel::ActionType Action;
-
-    while(1) {
-        if(panelclosed) {
-            // Init root
-            setBackground(themedir);
-
-            // Close all clients
-            if (!testing) {
-                KillAllClients(False);
-                KillAllClients(True);
-            }
-
-            // Show panel
-            LoginPanel->OpenPanel();
-        }
-
-        LoginPanel->Reset();
+	}
+
+	/* Open display */
+	if((Dpy = XOpenDisplay(DisplayName)) == 0) {
+		logStream << APPNAME << ": could not open display '"
+			 << DisplayName << "'" << endl;
+		if (!testing) StopServer();
+		exit(ERR_EXIT);
+	}
+
+	/* Get screen and root window */
+	Scr = DefaultScreen(Dpy);
+	Root = RootWindow(Dpy, Scr);
+
+	/* for tests we use a standard window */
+	if (testing) {
+		Window RealRoot = RootWindow(Dpy, Scr);
+		Root = XCreateSimpleWindow(Dpy, RealRoot, 0, 0, 1280, 1024, 0, 0, 0);
+		XMapWindow(Dpy, Root);
+		XFlush(Dpy);
+	} else {
+		blankScreen();
+	}
+
+	HideCursor();
+
+	/* Create panel */
+	LoginPanel = new Panel(Dpy, Scr, Root, cfg, themedir);
+	bool firstloop = true; /* 1st time panel is shown (for automatic username) */
+	bool focuspass = cfg->getOption("focus_password")=="yes";
+	bool autologin = cfg->getOption("auto_login")=="yes";
 	
+	if (firstlogin && cfg->getOption("default_user") != "") {
+		LoginPanel->SetName(cfg->getOption("default_user") );
+#ifdef USE_PAM
+	pam.set_item(PAM::Authenticator::User, cfg->getOption("default_user").c_str());
+#endif
+		firstlogin = false;
+		if (autologin) {
+			Login();
+		}
+	}
+
+	/* Set NumLock */
+	string numlock = cfg->getOption("numlock");
+	if (numlock == "on") {
+		NumLock::setOn(Dpy);
+	} else if (numlock == "off") {
+		NumLock::setOff(Dpy);
+	}
 	
-        if (firstloop && cfg->getOption("default_user") != "") {
-            LoginPanel->SetName(cfg->getOption("default_user") );
-        }
-
-
-        if (!AuthenticateUser(focuspass && firstloop)){
-            panelclosed = 0;
-            firstloop = false;
-            LoginPanel->ClearPanel();
-            XBell(Dpy, 100);
-            continue;
-        }
+	/* Start looping */
+	int panelclosed = 1;
+	Panel::ActionType Action;
+
+	while(1) {
+		if(panelclosed) {
+			/* Init root */
+			setBackground(themedir);
+
+			/* Close all clients */
+			if (!testing) {
+				KillAllClients(False);
+				KillAllClients(True);
+			}
+
+			/* Show panel */
+			LoginPanel->OpenPanel();
+		}
+
+		LoginPanel->Reset();
+
+		if (firstloop && cfg->getOption("default_user") != "") {
+			LoginPanel->SetName(cfg->getOption("default_user") );
+		}
+
+
+		if (!AuthenticateUser(focuspass && firstloop)){
+			panelclosed = 0;
+			firstloop = false;
+			LoginPanel->ClearPanel();
+			XBell(Dpy, 100);
+			continue;
+		}
 	
-	firstloop = false;
-
-        Action = LoginPanel->getAction();
-        // for themes test we just quit
-        if (testing) {
-            Action = Panel::Exit;
-        }
-        panelclosed = 1;
-        LoginPanel->ClosePanel();
-
-        switch(Action) {
-            case Panel::Login:
-                Login();
-                break;
-            case Panel::Console:
-                Console();
-                break;
-            case Panel::Reboot:
-                Reboot();
-                break;
-            case Panel::Halt:
-                Halt();
-                break;
-            case Panel::Suspend:
-                Suspend();
-                break;
-            case Panel::Exit:
-                Exit();
-                break;
-        }
-    }
+		firstloop = false;
+
+		Action = LoginPanel->getAction();
+		/* for themes test we just quit */
+		if (testing) {
+			Action = Panel::Exit;
+		}
+		panelclosed = 1;
+		LoginPanel->ClosePanel();
+
+		switch(Action) {
+			case Panel::Login:
+				Login();
+				break;
+			case Panel::Console:
+				Console();
+				break;
+			case Panel::Reboot:
+				Reboot();
+				break;
+			case Panel::Halt:
+				Halt();
+				break;
+			case Panel::Suspend:
+				Suspend();
+				break;
+			case Panel::Exit:
+				Exit();
+				break;
+		}
+	}
 }
 
 #ifdef USE_PAM
 bool App::AuthenticateUser(bool focuspass){
-    // Reset the username
-    try{
-        if (!focuspass)
-		    pam.set_item(PAM::Authenticator::User, 0);
-        pam.authenticate();
-    }
-    catch(PAM::Auth_Exception& e){
-        switch(LoginPanel->getAction()){
-            case Panel::Exit:
-            case Panel::Console:
-                return true; // <--- This is simply fake!
-            default:
-                break;
-        };
-        logStream << APPNAME << ": " << e << endl;
-        return false;
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    };
-    return true;
+	/* Reset the username */
+	try{
+		if (!focuspass)
+			pam.set_item(PAM::Authenticator::User, 0);
+		pam.authenticate();
+	}
+	catch(PAM::Auth_Exception& e){
+		switch(LoginPanel->getAction()){
+			case Panel::Exit:
+			case Panel::Console:
+				return true; /* <--- This is simply fake! */
+			default:
+				break;
+		};
+		logStream << APPNAME << ": " << e << endl;
+		return false;
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	};
+	return true;
 }
 #else
 bool App::AuthenticateUser(bool focuspass){
-    if (!focuspass){
-        LoginPanel->EventHandler(Panel::Get_Name);
-        switch(LoginPanel->getAction()){
-            case Panel::Exit:
-            case Panel::Console:
-                logStream << APPNAME << ": Got a special command (" << LoginPanel->GetName() << ")" << endl;
-                return true; // <--- This is simply fake!
-            default:
-                break;
-        }
-    }
-    LoginPanel->EventHandler(Panel::Get_Passwd);
-    
-    char *encrypted, *correct;
-    struct passwd *pw;
-
-    switch(LoginPanel->getAction()){
-        case Panel::Suspend:
-        case Panel::Halt:
-        case Panel::Reboot:
-            pw = getpwnam("root");
-            break;
-        case Panel::Console:
-        case Panel::Exit:
-        case Panel::Login:
-            pw = getpwnam(LoginPanel->GetName().c_str());
-            break;
-    }
-    endpwent();
-    if(pw == 0)
-        return false;
+	if (!focuspass){
+		LoginPanel->EventHandler(Panel::Get_Name);
+		switch(LoginPanel->getAction()){
+			case Panel::Exit:
+			case Panel::Console:
+				logStream << APPNAME << ": Got a special command (" << LoginPanel->GetName() << ")" << endl;
+				return true; /* <--- This is simply fake! */
+			default:
+				break;
+		}
+	}
+	LoginPanel->EventHandler(Panel::Get_Passwd);
+	
+	char *encrypted, *correct;
+	struct passwd *pw;
+
+	switch(LoginPanel->getAction()){
+		case Panel::Suspend:
+		case Panel::Halt:
+		case Panel::Reboot:
+			pw = getpwnam("root");
+			break;
+		case Panel::Console:
+		case Panel::Exit:
+		case Panel::Login:
+			pw = getpwnam(LoginPanel->GetName().c_str());
+			break;
+	}
+	endpwent();
+	if(pw == 0)
+		return false;
 
 #ifdef HAVE_SHADOW
-    struct spwd *sp = getspnam(pw->pw_name);    
-    endspent();
-    if(sp)
-        correct = sp->sp_pwdp;
-    else
-#endif        // HAVE_SHADOW
-        correct = pw->pw_passwd;
-
-    if(correct == 0 || correct[0] == '\0')
-        return true;
-
-    encrypted = crypt(LoginPanel->GetPasswd().c_str(), correct);
-    return ((strcmp(encrypted, correct) == 0) ? true : false);
+	struct spwd *sp = getspnam(pw->pw_name);	
+	endspent();
+	if(sp)
+		correct = sp->sp_pwdp;
+	else
+#endif		/* HAVE_SHADOW */
+		correct = pw->pw_passwd;
+
+	if(correct == 0 || correct[0] == '\0')
+		return true;
+
+	encrypted = crypt(LoginPanel->GetPasswd().c_str(), correct);
+	return ((strcmp(encrypted, correct) == 0) ? true : false);
 }
 #endif
 
-
 int App::GetServerPID() {
-    return ServerPID;
+	return ServerPID;
 }
 
-// Hide the cursor
+/* Hide the cursor */
 void App::HideCursor() {
-    if (cfg->getOption("hidecursor") == "true") {
-        XColor            black;
-        char            cursordata[1];
-        Pixmap            cursorpixmap;
-        Cursor            cursor;
-        cursordata[0]=0;
-        cursorpixmap=XCreateBitmapFromData(Dpy,Root,cursordata,1,1);
-        black.red=0;
-        black.green=0;
-        black.blue=0;
-        cursor=XCreatePixmapCursor(Dpy,cursorpixmap,cursorpixmap,&black,&black,0,0);
-        XDefineCursor(Dpy,Root,cursor);
-    }
+	if (cfg->getOption("hidecursor") == "true") {
+		XColor			black;
+		char			cursordata[1];
+		Pixmap			cursorpixmap;
+		Cursor			cursor;
+		cursordata[0]=0;
+		cursorpixmap=XCreateBitmapFromData(Dpy,Root,cursordata,1,1);
+		black.red=0;
+		black.green=0;
+		black.blue=0;
+		cursor=XCreatePixmapCursor(Dpy,cursorpixmap,cursorpixmap,&black,&black,0,0);
+		XDefineCursor(Dpy,Root,cursor);
+	}
 }
 
 void App::Login() {
-    struct passwd *pw;
-    pid_t pid;
+	struct passwd *pw;
+	pid_t pid;
 
 #ifdef USE_PAM
-    try{
-        pam.open_session();
-        pw = getpwnam(static_cast<const char*>(pam.get_item(PAM::Authenticator::User)));
-    }
-    catch(PAM::Cred_Exception& e){
-        // Credentials couldn't be established
-        logStream << APPNAME << ": " << e << endl;
-        return;
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    };
+	try{
+		pam.open_session();
+		pw = getpwnam(static_cast<const char*>(pam.get_item(PAM::Authenticator::User)));
+	}
+	catch(PAM::Cred_Exception& e){
+		/* Credentials couldn't be established */
+		logStream << APPNAME << ": " << e << endl;
+		return;
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	};
 #else
-    pw = getpwnam(LoginPanel->GetName().c_str());
+	pw = getpwnam(LoginPanel->GetName().c_str());
 #endif
-    endpwent();
-    if(pw == 0)
-        return;
-    if (pw->pw_shell[0] == '\0') {
-        setusershell();
-        strcpy(pw->pw_shell, getusershell());
-        endusershell();
-    }
-
-    // Setup the environment
-    char* term = getenv("TERM");
-    string maildir = _PATH_MAILDIR;
-    maildir.append("/");
-    maildir.append(pw->pw_name);
-    string xauthority = pw->pw_dir;
-    xauthority.append("/.Xauthority");
-    
+	endpwent();
+	if(pw == 0)
+		return;
+	if (pw->pw_shell[0] == '\0') {
+		setusershell();
+		strcpy(pw->pw_shell, getusershell());
+		endusershell();
+	}
+
+	/* Setup the environment */
+	char* term = getenv("TERM");
+	string maildir = _PATH_MAILDIR;
+	maildir.append("/");
+	maildir.append(pw->pw_name);
+	string xauthority = pw->pw_dir;
+	xauthority.append("/.Xauthority");
+	
 #ifdef USE_PAM
-    // Setup the PAM environment
-    try{
-        if(term) pam.setenv("TERM", term);
-        pam.setenv("HOME", pw->pw_dir);
-        pam.setenv("PWD", pw->pw_dir);
-        pam.setenv("SHELL", pw->pw_shell);
-        pam.setenv("USER", pw->pw_name);
-        pam.setenv("LOGNAME", pw->pw_name);
-        pam.setenv("PATH", cfg->getOption("default_path").c_str());
-        pam.setenv("DISPLAY", DisplayName);
-        pam.setenv("MAIL", maildir.c_str());
-        pam.setenv("XAUTHORITY", xauthority.c_str());
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    }
+	/* Setup the PAM environment */
+	try{
+		if(term) pam.setenv("TERM", term);
+		pam.setenv("HOME", pw->pw_dir);
+		pam.setenv("PWD", pw->pw_dir);
+		pam.setenv("SHELL", pw->pw_shell);
+		pam.setenv("USER", pw->pw_name);
+		pam.setenv("LOGNAME", pw->pw_name);
+		pam.setenv("PATH", cfg->getOption("default_path").c_str());
+		pam.setenv("DISPLAY", DisplayName);
+		pam.setenv("MAIL", maildir.c_str());
+		pam.setenv("XAUTHORITY", xauthority.c_str());
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	}
 #endif
 
 #ifdef USE_CONSOLEKIT
-    // Setup the ConsoleKit session
-    try {
-        ck.open_session(DisplayName, pw->pw_uid);
-    }
-    catch(Ck::Exception &e) {
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    }
+	/* Setup the ConsoleKit session */
+	try {
+		ck.open_session(DisplayName, pw->pw_uid);
+	}
+	catch(Ck::Exception &e) {
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	}
 #endif
 
-    // Create new process
-    pid = fork();
-    if(pid == 0) {
+	/* Create new process */
+	pid = fork();
+	if(pid == 0) {
 #ifdef USE_PAM
-        // Get a copy of the environment and close the child's copy
-        // of the PAM-handle.
-        char** child_env = pam.getenvlist();
+		/* Get a copy of the environment and close the child's copy */
+		/* of the PAM-handle. */
+		char** child_env = pam.getenvlist();
 
 # ifdef USE_CONSOLEKIT
-        char** old_env = child_env;
+		char** old_env = child_env;
 
-        // Grow the copy of the environment for the session cookie
-        int n;
-        for(n = 0; child_env[n] != NULL ; n++);
+		/* Grow the copy of the environment for the session cookie */
+		int n;
+		for(n = 0; child_env[n] != NULL ; n++);
 
-        n++;
+		n++;
 
-        child_env = static_cast<char**>(malloc(sizeof(char*)*n));
-        memcpy(child_env, old_env, sizeof(char*)*n);
-        child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
-        child_env[n] = NULL;
+		child_env = static_cast<char**>(malloc(sizeof(char*)*n));
+		memcpy(child_env, old_env, sizeof(char*)*n);
+		child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
+		child_env[n] = NULL;
 # endif /* USE_CONSOLEKIT */
 
-        pam.end();
+		pam.end();
 #else
 
 # ifdef USE_CONSOLEKIT
-        const int Num_Of_Variables = 12; // Number of env. variables + 1
+		const int Num_Of_Variables = 12; /* Number of env. variables + 1 */
 # else
-        const int Num_Of_Variables = 11; // Number of env. variables + 1
+		const int Num_Of_Variables = 11; /* Number of env. variables + 1 */
 # endif /* USE_CONSOLEKIT */
-        char** child_env = static_cast<char**>(malloc(sizeof(char*)*Num_Of_Variables));
-        int n = 0;
-        if(term) child_env[n++]=StrConcat("TERM=", term);
-        child_env[n++]=StrConcat("HOME=", pw->pw_dir);
-        child_env[n++]=StrConcat("PWD=", pw->pw_dir);
-        child_env[n++]=StrConcat("SHELL=", pw->pw_shell);
-        child_env[n++]=StrConcat("USER=", pw->pw_name);
-        child_env[n++]=StrConcat("LOGNAME=", pw->pw_name);
-        child_env[n++]=StrConcat("PATH=", cfg->getOption("default_path").c_str());
-        child_env[n++]=StrConcat("DISPLAY=", DisplayName);
-        child_env[n++]=StrConcat("MAIL=", maildir.c_str());
-        child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str());
+		char** child_env = static_cast<char**>(malloc(sizeof(char*)*Num_Of_Variables));
+		int n = 0;
+		if(term) child_env[n++]=StrConcat("TERM=", term);
+		child_env[n++]=StrConcat("HOME=", pw->pw_dir);
+		child_env[n++]=StrConcat("PWD=", pw->pw_dir);
+		child_env[n++]=StrConcat("SHELL=", pw->pw_shell);
+		child_env[n++]=StrConcat("USER=", pw->pw_name);
+		child_env[n++]=StrConcat("LOGNAME=", pw->pw_name);
+		child_env[n++]=StrConcat("PATH=", cfg->getOption("default_path").c_str());
+		child_env[n++]=StrConcat("DISPLAY=", DisplayName);
+		child_env[n++]=StrConcat("MAIL=", maildir.c_str());
+		child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str());
 # ifdef USE_CONSOLEKIT
-        child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
+		child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
 # endif /* USE_CONSOLEKIT */
-        child_env[n++]=0;
+		child_env[n++]=0;
 
 #endif
 
-        // Login process starts here
-        SwitchUser Su(pw, cfg, DisplayName, child_env);
-        string session = LoginPanel->getSession();
-        string loginCommand = cfg->getOption("login_cmd");
-        replaceVariables(loginCommand, SESSION_VAR, session);
-        replaceVariables(loginCommand, THEME_VAR, themeName);
-        string sessStart = cfg->getOption("sessionstart_cmd");
-        if (sessStart != "") {
-            replaceVariables(sessStart, USER_VAR, pw->pw_name);
-            system(sessStart.c_str());
-        }
-        Su.Login(loginCommand.c_str(), mcookie.c_str());
-        _exit(OK_EXIT);
-    }
+		/* Login process starts here */
+		SwitchUser Su(pw, cfg, DisplayName, child_env);
+		string session = LoginPanel->getSession();
+		string loginCommand = cfg->getOption("login_cmd");
+		replaceVariables(loginCommand, SESSION_VAR, session);
+		replaceVariables(loginCommand, THEME_VAR, themeName);
+		string sessStart = cfg->getOption("sessionstart_cmd");
+		if (sessStart != "") {
+			replaceVariables(sessStart, USER_VAR, pw->pw_name);
+			system(sessStart.c_str());
+		}
+		Su.Login(loginCommand.c_str(), mcookie.c_str());
+		_exit(OK_EXIT);
+	}
 
 #ifndef XNEST_DEBUG
-    CloseLog();
+	CloseLog();
 #endif
 
-    // Wait until user is logging out (login process terminates)
-    pid_t wpid = -1;
-    int status;
-    while (wpid != pid) {
-        wpid = wait(&status);
+	/* Wait until user is logging out (login process terminates) */
+	pid_t wpid = -1;
+	int status;
+	while (wpid != pid) {
+		wpid = wait(&status);
 		if (wpid == ServerPID)
-			xioerror(Dpy);	// Server died, simulate IO error
-    }
-    if (WIFEXITED(status) && WEXITSTATUS(status)) {
-        LoginPanel->Message("Failed to execute login command");
-        sleep(3);
-    } else {
-         string sessStop = cfg->getOption("sessionstop_cmd");
-         if (sessStop != "") {
-            replaceVariables(sessStop, USER_VAR, pw->pw_name);
-            system(sessStop.c_str());
-        }
-    }
+			xioerror(Dpy);	/* Server died, simulate IO error */
+	}
+	if (WIFEXITED(status) && WEXITSTATUS(status)) {
+		LoginPanel->Message("Failed to execute login command");
+		sleep(3);
+	} else {
+		 string sessStop = cfg->getOption("sessionstop_cmd");
+		 if (sessStop != "") {
+			replaceVariables(sessStop, USER_VAR, pw->pw_name);
+			system(sessStop.c_str());
+		}
+	}
 
 #ifdef USE_CONSOLEKIT
-    try {
-        ck.close_session();
-    }
-    catch(Ck::Exception &e) {
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try {
+		ck.close_session();
+	}
+	catch(Ck::Exception &e) {
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
 #ifdef USE_PAM
-    try{
-        pam.close_session();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.close_session();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-// Close all clients
-    KillAllClients(False);
-    KillAllClients(True);
+/* Close all clients */
+	KillAllClients(False);
+	KillAllClients(True);
 
-    // Send HUP signal to clientgroup
-    killpg(pid, SIGHUP);
+	/* Send HUP signal to clientgroup */
+	killpg(pid, SIGHUP);
 
-    // Send TERM signal to clientgroup, if error send KILL
-    if(killpg(pid, SIGTERM))
-    killpg(pid, SIGKILL);
+	/* Send TERM signal to clientgroup, if error send KILL */
+	if(killpg(pid, SIGTERM))
+	killpg(pid, SIGKILL);
 
-    HideCursor();
+	HideCursor();
 
 #ifndef XNEST_DEBUG
-    // Re-activate log file
-    OpenLog();
-    RestartServer();
+	/* Re-activate log file */
+	OpenLog();
+	RestartServer();
 #endif
 
-
 }
 
-
 void App::Reboot() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    // Write message
-    LoginPanel->Message((char*)cfg->getOption("reboot_msg").c_str());
-    sleep(3);
+	/* Write message */
+	LoginPanel->Message((char*)cfg->getOption("reboot_msg").c_str());
+	sleep(3);
 
-    // Stop server and reboot
-    StopServer();
-    RemoveLock();
-    system(cfg->getOption("reboot_cmd").c_str());
-    exit(OK_EXIT);
+	/* Stop server and reboot */
+	StopServer();
+	RemoveLock();
+	system(cfg->getOption("reboot_cmd").c_str());
+	exit(OK_EXIT);
 }
 
 
 void App::Halt() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    // Write message
-    LoginPanel->Message((char*)cfg->getOption("shutdown_msg").c_str());
-    sleep(3);
+	/* Write message */
+	LoginPanel->Message((char*)cfg->getOption("shutdown_msg").c_str());
+	sleep(3);
 
-    // Stop server and halt
-    StopServer();
-    RemoveLock();
-    system(cfg->getOption("halt_cmd").c_str());
-    exit(OK_EXIT);
+	/* Stop server and halt */
+	StopServer();
+	RemoveLock();
+	system(cfg->getOption("halt_cmd").c_str());
+	exit(OK_EXIT);
 }
 
 void App::Suspend() {
-    sleep(1);
-    system(cfg->getOption("suspend_cmd").c_str());
+	sleep(1);
+	system(cfg->getOption("suspend_cmd").c_str());
 }
 
 
 void App::Console() {
-    int posx = 40;
-    int posy = 40;
-    int fontx = 9;
-    int fonty = 15;
-    int width = (XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posx * 2)) / fontx;
-    int height = (XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posy * 2)) / fonty;
-
-    // Execute console
-    const char* cmd = cfg->getOption("console_cmd").c_str();
-    char *tmp = new char[strlen(cmd) + 60];
-    sprintf(tmp, cmd, width, height, posx, posy, fontx, fonty);
-    system(tmp);
-    delete [] tmp;
+	int posx = 40;
+	int posy = 40;
+	int fontx = 9;
+	int fonty = 15;
+	int width = (XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posx * 2)) / fontx;
+	int height = (XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posy * 2)) / fonty;
+
+	/* Execute console */
+	const char* cmd = cfg->getOption("console_cmd").c_str();
+	char *tmp = new char[strlen(cmd) + 60];
+	sprintf(tmp, cmd, width, height, posx, posy, fontx, fonty);
+	system(tmp);
+	delete [] tmp;
 }
 
 
 void App::Exit() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    if (testing) {
-        const char* testmsg = "This is a test message :-)";
-        LoginPanel->Message(testmsg);
-        sleep(3);
-        delete LoginPanel;
-        XCloseDisplay(Dpy);
-    } else {
-        delete LoginPanel;
-        StopServer();
-        RemoveLock();
-    }
-    delete cfg;
-    exit(OK_EXIT);
+	if (testing) {
+		const char* testmsg = "This is a test message :-)";
+		LoginPanel->Message(testmsg);
+		sleep(3);
+		delete LoginPanel;
+		XCloseDisplay(Dpy);
+	} else {
+		delete LoginPanel;
+		StopServer();
+		RemoveLock();
+	}
+	delete cfg;
+	exit(OK_EXIT);
 }
 
-
 int CatchErrors(Display *dpy, XErrorEvent *ev) {
-    return 0;
+	return 0;
 }
 
 void App::RestartServer() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    StopServer(); 
-    RemoveLock();
-	while (waitpid(-1, NULL, WNOHANG) > 0); // Collects all dead childrens
-    Run();
+	StopServer(); 
+	RemoveLock();
+	while (waitpid(-1, NULL, WNOHANG) > 0); /* Collects all dead childrens */
+	Run();
 } 
 
 void App::KillAllClients(Bool top) {
-    Window dummywindow;
-    Window *children;
-    unsigned int nchildren;
-    unsigned int i;
-    XWindowAttributes attr;
-
-    XSync(Dpy, 0);
-    XSetErrorHandler(CatchErrors);
-
-    nchildren = 0;
-    XQueryTree(Dpy, Root, &dummywindow, &dummywindow, &children, &nchildren);
-    if(!top) {
-        for(i=0; i<nchildren; i++) {
-            if(XGetWindowAttributes(Dpy, children[i], &attr) && (attr.map_state == IsViewable))
-                children[i] = XmuClientWindow(Dpy, children[i]);
-            else
-                children[i] = 0;
-        }
-    }
-
-    for(i=0; i<nchildren; i++) {
-        if(children[i])
-            XKillClient(Dpy, children[i]);
-    }
-    XFree((char *)children);
-
-    XSync(Dpy, 0);
-    XSetErrorHandler(NULL);
+	Window dummywindow;
+	Window *children;
+	unsigned int nchildren;
+	unsigned int i;
+	XWindowAttributes attr;
+
+	XSync(Dpy, 0);
+	XSetErrorHandler(CatchErrors);
+
+	nchildren = 0;
+	XQueryTree(Dpy, Root, &dummywindow, &dummywindow, &children, &nchildren);
+	if(!top) {
+		for(i=0; i<nchildren; i++) {
+			if(XGetWindowAttributes(Dpy, children[i], &attr) && (attr.map_state == IsViewable))
+				children[i] = XmuClientWindow(Dpy, children[i]);
+			else
+				children[i] = 0;
+		}
+	}
+
+	for(i=0; i<nchildren; i++) {
+		if(children[i])
+			XKillClient(Dpy, children[i]);
+	}
+	XFree((char *)children);
+
+	XSync(Dpy, 0);
+	XSetErrorHandler(NULL);
 }
 
 
 int App::ServerTimeout(int timeout, char* text) {
-    int    i = 0;
-    int pidfound = -1;
-    static char    *lasttext;
-
-    for(;;) {
-        pidfound = waitpid(ServerPID, NULL, WNOHANG);
-        if(pidfound == ServerPID)
-            break;
-        if(timeout) {
-            if(i == 0 && text != lasttext)
-                logStream << endl << APPNAME << ": waiting for " << text;
-            else
-                logStream << ".";
-        }
-        if(timeout)
-            sleep(1);
-        if(++i > timeout)
-            break;
-    }
-
-    if(i > 0)
-        logStream << endl;
-    lasttext = text;
-
-    return (ServerPID != pidfound);
+	int	i = 0;
+	int pidfound = -1;
+	static char	*lasttext;
+
+	for(;;) {
+		pidfound = waitpid(ServerPID, NULL, WNOHANG);
+		if(pidfound == ServerPID)
+			break;
+		if(timeout) {
+			if(i == 0 && text != lasttext)
+				logStream << endl << APPNAME << ": waiting for " << text;
+			else
+				logStream << ".";
+		}
+		if(timeout)
+			sleep(1);
+		if(++i > timeout)
+			break;
+	}
+
+	if(i > 0)
+		logStream << endl;
+	lasttext = text;
+
+	return (ServerPID != pidfound);
 }
 
 
 int App::WaitForServer() {
-    int    ncycles     = 120;
-    int    cycles;
-
-    for(cycles = 0; cycles < ncycles; cycles++) {
-        if((Dpy = XOpenDisplay(DisplayName))) {
-            XSetIOErrorHandler(xioerror);
-            return 1;
-        } else {
-            if(!ServerTimeout(1, (char *) "X server to begin accepting connections"))
-                break;
-        }
-    }
-
-    logStream << "Giving up." << endl;
-
-    return 0;
+	int	ncycles	 = 120;
+	int	cycles;
+
+	for(cycles = 0; cycles < ncycles; cycles++) {
+		if((Dpy = XOpenDisplay(DisplayName))) {
+			XSetIOErrorHandler(xioerror);
+			return 1;
+		} else {
+			if(!ServerTimeout(1, (char *) "X server to begin accepting connections"))
+				break;
+		}
+	}
+
+	logStream << "Giving up." << endl;
+
+	return 0;
 }
 
 
 int App::StartServer() {
-    ServerPID = fork();
-
-    static const int MAX_XSERVER_ARGS = 256;
-    static char* server[MAX_XSERVER_ARGS+2] = { NULL };
-    server[0] = (char *)cfg->getOption("default_xserver").c_str();
-    string argOption = cfg->getOption("xserver_arguments");
-    /* Add mandatory -xauth option */
-    argOption = argOption + " -auth " + cfg->getOption("authfile");
-    char* args = new char[argOption.length()+2]; // NULL plus vt
-    strcpy(args, argOption.c_str());
-
-    serverStarted = false;
-
-    int argc = 1;
-    int pos = 0;
-    bool hasVtSet = false;
-    while (args[pos] != '\0') {
-        if (args[pos] == ' ' || args[pos] == '\t') {
-            *(args+pos) = '\0';
-            server[argc++] = args+pos+1;
-        } else if (pos == 0) {
-            server[argc++] = args+pos;
-        }
-        ++pos;
-
-        if (argc+1 >= MAX_XSERVER_ARGS) {
-            // ignore _all_ arguments to make sure the server starts at
-            // all
-            argc = 1;
-            break;
-        }
-    }
-
-    for (int i=0; i<argc; i++) {
-        if (server[i][0] == 'v' && server[i][1] == 't') {
-            bool ok = false;
-            Cfg::string2int(server[i]+2, &ok);
-            if (ok) {
-                hasVtSet = true;
-            }
-        }
-    }
-
-    if (!hasVtSet && daemonmode) {
-        server[argc++] = (char*)"vt07";
-    }
-    server[argc] = NULL;
-
-    switch(ServerPID) {
-    case 0:
-        signal(SIGTTIN, SIG_IGN);
-        signal(SIGTTOU, SIG_IGN);
-        signal(SIGUSR1, SIG_IGN);
-        setpgid(0,getpid());
-
-
-        execvp(server[0], server);
-        logStream << APPNAME << ": X server could not be started" << endl;
-        exit(ERR_EXIT);
-        break;
-
-    case -1:
-        break;
-
-    default:
-        errno = 0;
-        if(!ServerTimeout(0, (char *)"")) {
-            ServerPID = -1;
-            break;
-        }
-
-        // Wait for server to start up
-        if(WaitForServer() == 0) {
-            logStream << APPNAME << ": unable to connect to X server" << endl;
-            StopServer();
-            ServerPID = -1;
-            exit(ERR_EXIT);
-        }
-        break;
-    }
-
-    delete args;
-
-    serverStarted = true;
-
-    return ServerPID;
+	ServerPID = fork();
+
+	static const int MAX_XSERVER_ARGS = 256;
+	static char* server[MAX_XSERVER_ARGS+2] = { NULL };
+	server[0] = (char *)cfg->getOption("default_xserver").c_str();
+	string argOption = cfg->getOption("xserver_arguments");
+	/* Add mandatory -xauth option */
+	argOption = argOption + " -auth " + cfg->getOption("authfile");
+	char* args = new char[argOption.length()+2]; /* NULL plus vt */
+	strcpy(args, argOption.c_str());
+
+	serverStarted = false;
+
+	int argc = 1;
+	int pos = 0;
+	bool hasVtSet = false;
+	while (args[pos] != '\0') {
+		if (args[pos] == ' ' || args[pos] == '\t') {
+			*(args+pos) = '\0';
+			server[argc++] = args+pos+1;
+		} else if (pos == 0) {
+			server[argc++] = args+pos;
+		}
+		++pos;
+
+		if (argc+1 >= MAX_XSERVER_ARGS) {
+			/* ignore _all_ arguments to make sure the server starts at */
+			/* all */
+			argc = 1;
+			break;
+		}
+	}
+
+	for (int i=0; i<argc; i++) {
+		if (server[i][0] == 'v' && server[i][1] == 't') {
+			bool ok = false;
+			Cfg::string2int(server[i]+2, &ok);
+			if (ok) {
+				hasVtSet = true;
+			}
+		}
+	}
+
+	if (!hasVtSet && daemonmode) {
+		server[argc++] = (char*)"vt07";
+	}
+	server[argc] = NULL;
+
+	switch(ServerPID) {
+	case 0:
+		signal(SIGTTIN, SIG_IGN);
+		signal(SIGTTOU, SIG_IGN);
+		signal(SIGUSR1, SIG_IGN);
+		setpgid(0,getpid());
+
+		execvp(server[0], server);
+		logStream << APPNAME << ": X server could not be started" << endl;
+		exit(ERR_EXIT);
+		break;
+
+	case -1:
+		break;
+
+	default:
+		errno = 0;
+		if(!ServerTimeout(0, (char *)"")) {
+			ServerPID = -1;
+			break;
+		}
+
+		/* Wait for server to start up */
+		if(WaitForServer() == 0) {
+			logStream << APPNAME << ": unable to connect to X server" << endl;
+			StopServer();
+			ServerPID = -1;
+			exit(ERR_EXIT);
+		}
+		break;
+	}
+
+	delete args;
+
+	serverStarted = true;
+
+	return ServerPID;
 }
 
-
 jmp_buf CloseEnv;
 int IgnoreXIO(Display *d) {
-    logStream << APPNAME << ": connection to X server lost." << endl;
-    longjmp(CloseEnv, 1);
+	logStream << APPNAME << ": connection to X server lost." << endl;
+	longjmp(CloseEnv, 1);
 }
 
-
 void App::StopServer() {
-    signal(SIGQUIT, SIG_IGN);
-    signal(SIGINT, SIG_IGN);
-    signal(SIGHUP, SIG_IGN);
-    signal(SIGPIPE, SIG_IGN);
-    signal(SIGTERM, SIG_DFL);
-    signal(SIGKILL, SIG_DFL);
-
-    // Catch X error
-    XSetIOErrorHandler(IgnoreXIO);
-    if(!setjmp(CloseEnv) && Dpy)
-        XCloseDisplay(Dpy);
-
-    // Send HUP to process group
-    errno = 0;
-    if((killpg(getpid(), SIGHUP) != 0) && (errno != ESRCH))
-        logStream << APPNAME << ": can't send HUP to process group " << getpid() << endl;
-
-    // Send TERM to server
-    if(ServerPID < 0)
-        return;
-    errno = 0;
-    if(killpg(ServerPID, SIGTERM) < 0) {
-        if(errno == EPERM) {
-            logStream << APPNAME << ": can't kill X server" << endl;
-            exit(ERR_EXIT);
-        }
-        if(errno == ESRCH)
-            return;
-    }
-
-    // Wait for server to shut down
-    if(!ServerTimeout(10, (char *)"X server to shut down")) {
-        logStream << endl;
-        return;
-    }
-
-    logStream << endl << APPNAME << ":  X server slow to shut down, sending KILL signal." << endl;
-
-    // Send KILL to server
-    errno = 0;
-    if(killpg(ServerPID, SIGKILL) < 0) {
-        if(errno == ESRCH)
-            return;
-    }
-
-    // Wait for server to die
-    if(ServerTimeout(3, (char*)"server to die")) {
-        logStream << endl << APPNAME << ": can't kill server" << endl;
-        exit(ERR_EXIT);
-    }
-    logStream << endl;
+	signal(SIGQUIT, SIG_IGN);
+	signal(SIGINT, SIG_IGN);
+	signal(SIGHUP, SIG_IGN);
+	signal(SIGPIPE, SIG_IGN);
+	signal(SIGTERM, SIG_DFL);
+	signal(SIGKILL, SIG_DFL);
+
+	/* Catch X error */
+	XSetIOErrorHandler(IgnoreXIO);
+	if(!setjmp(CloseEnv) && Dpy)
+		XCloseDisplay(Dpy);
+
+	/* Send HUP to process group */
+	errno = 0;
+	if((killpg(getpid(), SIGHUP) != 0) && (errno != ESRCH))
+		logStream << APPNAME << ": can't send HUP to process group " << getpid() << endl;
+
+	/* Send TERM to server */
+	if(ServerPID < 0)
+		return;
+	errno = 0;
+	if(killpg(ServerPID, SIGTERM) < 0) {
+		if(errno == EPERM) {
+			logStream << APPNAME << ": can't kill X server" << endl;
+			exit(ERR_EXIT);
+		}
+		if(errno == ESRCH)
+			return;
+	}
+
+	/* Wait for server to shut down */
+	if(!ServerTimeout(10, (char *)"X server to shut down")) {
+		logStream << endl;
+		return;
+	}
+
+	logStream << endl << APPNAME << ":  X server slow to shut down, sending KILL signal." << endl;
+
+	/* Send KILL to server */
+	errno = 0;
+	if(killpg(ServerPID, SIGKILL) < 0) {
+		if(errno == ESRCH)
+			return;
+	}
+
+	/* Wait for server to die */
+	if(ServerTimeout(3, (char*)"server to die")) {
+		logStream << endl << APPNAME << ": can't kill server" << endl;
+		exit(ERR_EXIT);
+	}
+	logStream << endl;
 }
 
-
 void App::blankScreen()
 {
-    GC gc = XCreateGC(Dpy, Root, 0, 0);
-    XSetForeground(Dpy, gc, BlackPixel(Dpy, Scr));
-    XFillRectangle(Dpy, Root, gc, 0, 0,
-                   XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                   XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
-    XFlush(Dpy);
-    XFreeGC(Dpy, gc);
+	GC gc = XCreateGC(Dpy, Root, 0, 0);
+	XSetForeground(Dpy, gc, BlackPixel(Dpy, Scr));
+	XFillRectangle(Dpy, Root, gc, 0, 0,
+				   XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),
+				   XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+	XFlush(Dpy);
+	XFreeGC(Dpy, gc);
 
 }
 
 void App::setBackground(const string& themedir) {
-    string filename;
-    filename = themedir + "/background.png";
-    image = new Image;
-    bool loaded = image->Read(filename.c_str());
-    if (!loaded){ // try jpeg if png failed
-        filename = "";
-        filename = themedir + "/background.jpg";
-        loaded = image->Read(filename.c_str());
-    }
-    if (loaded) {
-        string bgstyle = cfg->getOption("background_style");
-        if (bgstyle == "stretch") {
-            image->Resize(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
-        } else if (bgstyle == "tile") {
-            image->Tile(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
-        } else if (bgstyle == "center") {
-            string hexvalue = cfg->getOption("background_color");
-            hexvalue = hexvalue.substr(1,6);
-            image->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                        hexvalue.c_str());
-        } else { // plain color or error
-            string hexvalue = cfg->getOption("background_color");
-            hexvalue = hexvalue.substr(1,6);
-            image->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                        hexvalue.c_str());
-        }
-        Pixmap p = image->createPixmap(Dpy, Scr, Root);
-        XSetWindowBackgroundPixmap(Dpy, Root, p);
-    }
-    XClearWindow(Dpy, Root);
-    
-    XFlush(Dpy);
-    delete image;
+	string filename;
+	filename = themedir + "/background.png";
+	image = new Image;
+	bool loaded = image->Read(filename.c_str());
+	if (!loaded){ /* try jpeg if png failed */
+		filename = "";
+		filename = themedir + "/background.jpg";
+		loaded = image->Read(filename.c_str());
+	}
+	if (loaded) {
+		string bgstyle = cfg->getOption("background_style");
+		if (bgstyle == "stretch") {
+			image->Resize(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+		} else if (bgstyle == "tile") {
+			image->Tile(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+		} else if (bgstyle == "center") {
+			string hexvalue = cfg->getOption("background_color");
+			hexvalue = hexvalue.substr(1,6);
+			image->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
+						hexvalue.c_str());
+		} else { /* plain color or error */
+			string hexvalue = cfg->getOption("background_color");
+			hexvalue = hexvalue.substr(1,6);
+			image->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
+						hexvalue.c_str());
+		}
+		Pixmap p = image->createPixmap(Dpy, Scr, Root);
+		XSetWindowBackgroundPixmap(Dpy, Root, p);
+	}
+	XClearWindow(Dpy, Root);
+	
+	XFlush(Dpy);
+	delete image;
 }
 
-// Check if there is a lockfile and a corresponding process
+/* Check if there is a lockfile and a corresponding process */
 void App::GetLock() {
-    std::ifstream lockfile(cfg->getOption("lockfile").c_str());
-    if (!lockfile) {
-        // no lockfile present, create one
-        std::ofstream lockfile(cfg->getOption("lockfile").c_str(), ios_base::out);
-        if (!lockfile) {
-            logStream << APPNAME << ": Could not create lock file: " << cfg->getOption("lockfile").c_str() << std::endl;
-            exit(ERR_EXIT);
-        }
-        lockfile << getpid() << std::endl;
-        lockfile.close();
-    } else {
-        // lockfile present, read pid from it
-        int pid = 0;
-        lockfile >> pid;
-        lockfile.close();
-        if (pid > 0) {
-            // see if process with this pid exists
-            int ret = kill(pid, 0);
-            if (ret == 0 || (ret == -1 && errno == EPERM) ) {
-                logStream << APPNAME << ": Another instance of the program is already running with PID " << pid << std::endl;
-                exit(0);
-            } else {
-                logStream << APPNAME << ": Stale lockfile found, removing it" << std::endl;
-                std::ofstream lockfile(cfg->getOption("lockfile").c_str(), ios_base::out);
-                if (!lockfile) {
-                    logStream << APPNAME << ": Could not create new lock file: " << cfg->getOption("lockfile") << std::endl;
-                    exit(ERR_EXIT);
-                }
-                lockfile << getpid() << std::endl;
-                lockfile.close();
-            }
-        }
-    }
+	std::ifstream lockfile(cfg->getOption("lockfile").c_str());
+	if (!lockfile) {
+		/* no lockfile present, create one */
+		std::ofstream lockfile(cfg->getOption("lockfile").c_str(), ios_base::out);
+		if (!lockfile) {
+			logStream << APPNAME << ": Could not create lock file: " << cfg->getOption("lockfile").c_str() << std::endl;
+			exit(ERR_EXIT);
+		}
+		lockfile << getpid() << std::endl;
+		lockfile.close();
+	} else {
+		/* lockfile present, read pid from it */
+		int pid = 0;
+		lockfile >> pid;
+		lockfile.close();
+		if (pid > 0) {
+			/* see if process with this pid exists */
+			int ret = kill(pid, 0);
+			if (ret == 0 || (ret == -1 && errno == EPERM) ) {
+				logStream << APPNAME << ": Another instance of the program is already running with PID " << pid << std::endl;
+				exit(0);
+			} else {
+				logStream << APPNAME << ": Stale lockfile found, removing it" << std::endl;
+				std::ofstream lockfile(cfg->getOption("lockfile").c_str(), ios_base::out);
+				if (!lockfile) {
+					logStream << APPNAME << ": Could not create new lock file: " << cfg->getOption("lockfile") << std::endl;
+					exit(ERR_EXIT);
+				}
+				lockfile << getpid() << std::endl;
+				lockfile.close();
+			}
+		}
+	}
 }
 
-// Remove lockfile and close logs
+/* Remove lockfile and close logs */
 void App::RemoveLock() {
-    remove(cfg->getOption("lockfile").c_str());
+	remove(cfg->getOption("lockfile").c_str());
 }
 
-// Get server start check flag.
+/* Get server start check flag. */
 bool App::isServerStarted() {
-    return serverStarted;
+	return serverStarted;
 }
 
-// Redirect stdout and stderr to log file
+/* Redirect stdout and stderr to log file */
 void App::OpenLog() {
 
-    if ( !logStream.openLog( cfg->getOption("logfile").c_str() ) ) {
-        logStream <<  APPNAME << ": Could not accesss log file: " << cfg->getOption("logfile") << endl;
-        RemoveLock();
-        exit(ERR_EXIT);
-    }
-    //
-    // I should set the buffers to imediate write, but I just flush on every
-    // << operation.
-    //
-    //
+	if ( !logStream.openLog( cfg->getOption("logfile").c_str() ) ) {
+		logStream <<  APPNAME << ": Could not accesss log file: " << cfg->getOption("logfile") << endl;
+		RemoveLock();
+		exit(ERR_EXIT);
+	}
+	/* I should set the buffers to imediate write, but I just flush on every 
+	   << operation. */ 
 }
 
-// Relases stdout/err
+/* Relases stdout/err */
 void App::CloseLog(){
-	// Simply closing the log
+	/* Simply closing the log */
 	logStream.closeLog();
 }
 
 string App::findValidRandomTheme(const string& set)
 {
-    // extract random theme from theme set; return empty string on error
-    string name = set;
-    struct stat buf;
-
-    if (name[name.length()-1] == ',') {
-        name = name.substr(0, name.length() - 1);
-    }
-
-    Util::srandom(Util::makeseed());
-
-    vector<string> themes;
-    string themefile;
-    Cfg::split(themes, name, ',');
-    do {
-        int sel = Util::random() % themes.size();
-
-        name = Cfg::Trim(themes[sel]);
-        themefile = string(THEMESDIR) +"/" + name + THEMESFILE;
-        if (stat(themefile.c_str(), &buf) != 0) {
-            themes.erase(find(themes.begin(), themes.end(), name));
-            logStream << APPNAME << ": Invalid theme in config: "
-                 << name << endl;
-            name = "";
-        }
-    } while (name == "" && themes.size());
-    return name;
+	/* extract random theme from theme set; return empty string on error */
+	string name = set;
+	struct stat buf;
+
+	if (name[name.length()-1] == ',') {
+		name = name.substr(0, name.length() - 1);
+	}
+
+	Util::srandom(Util::makeseed());
+
+	vector<string> themes;
+	string themefile;
+	Cfg::split(themes, name, ',');
+	do {
+		int sel = Util::random() % themes.size();
+
+		name = Cfg::Trim(themes[sel]);
+		themefile = string(THEMESDIR) +"/" + name + THEMESFILE;
+		if (stat(themefile.c_str(), &buf) != 0) {
+			themes.erase(find(themes.begin(), themes.end(), name));
+			logStream << APPNAME << ": Invalid theme in config: "
+				 << name << endl;
+			name = "";
+		}
+	} while (name == "" && themes.size());
+	return name;
 }
 
 
 void App::replaceVariables(string& input,
-               const string& var,
-               const string& value)
+			   const string& var,
+			   const string& value)
 {
-    string::size_type pos = 0;
-    int len = var.size();
-    while ((pos = input.find(var, pos)) != string::npos) {
-        input = input.substr(0, pos) + value + input.substr(pos+len);
-    }
+	string::size_type pos = 0;
+	int len = var.size();
+	while ((pos = input.find(var, pos)) != string::npos) {
+		input = input.substr(0, pos) + value + input.substr(pos+len);
+	}
 }
 
-
 /*
  * We rely on the fact that all bits generated by Util::random()
  * are usable, so we are taking full words from its output.
  */
 void App::CreateServerAuth() {
-    /* create mit cookie */
-    uint16_t word;
-    uint8_t hi, lo;
-    int i;
-    string authfile;
-    const char *digits = "0123456789abcdef";
-    Util::srandom(Util::makeseed());
-    for (i = 0; i < App::mcookiesize; i+=4) {
-        word = Util::random() & 0xffff;
-        lo = word & 0xff;
-        hi = word >> 8;
-        mcookie[i] = digits[lo & 0x0f];
-        mcookie[i+1] = digits[lo >> 4];
-        mcookie[i+2] = digits[hi & 0x0f];
-        mcookie[i+3] = digits[hi >> 4];
-    }
-    /* reinitialize auth file */
-    authfile = cfg->getOption("authfile");
-    remove(authfile.c_str());
-    putenv(StrConcat("XAUTHORITY=", authfile.c_str()));
-    Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
-      authfile);
+	/* create mit cookie */
+	uint16_t word;
+	uint8_t hi, lo;
+	int i;
+	string authfile;
+	const char *digits = "0123456789abcdef";
+	Util::srandom(Util::makeseed());
+	for (i = 0; i < App::mcookiesize; i+=4) {
+		word = Util::random() & 0xffff;
+		lo = word & 0xff;
+		hi = word >> 8;
+		mcookie[i] = digits[lo & 0x0f];
+		mcookie[i+1] = digits[lo >> 4];
+		mcookie[i+2] = digits[hi & 0x0f];
+		mcookie[i+3] = digits[hi >> 4];
+	}
+	/* reinitialize auth file */
+	authfile = cfg->getOption("authfile");
+	remove(authfile.c_str());
+	putenv(StrConcat("XAUTHORITY=", authfile.c_str()));
+	Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
+	  authfile);
 }
 
 char* App::StrConcat(const char* str1, const char* str2) {
-    char* tmp = new char[strlen(str1) + strlen(str2) + 1];
-    strcpy(tmp, str1);
-    strcat(tmp, str2);
-    return tmp;
+	char* tmp = new char[strlen(str1) + strlen(str2) + 1];
+	strcpy(tmp, str1);
+	strcat(tmp, str2);
+	return tmp;
 }
 
 void App::UpdatePid() {
-    std::ofstream lockfile(cfg->getOption("lockfile").c_str(), ios_base::out);
-    if (!lockfile) {
-        logStream << APPNAME << ": Could not update lock file: " << cfg->getOption("lockfile").c_str() << std::endl;
-        exit(ERR_EXIT);
-    }
-    lockfile << getpid() << std::endl;
-    lockfile.close();
+	std::ofstream lockfile(cfg->getOption("lockfile").c_str(), ios_base::out);
+	if (!lockfile) {
+		logStream << APPNAME << ": Could not update lock file: " << cfg->getOption("lockfile").c_str() << std::endl;
+		exit(ERR_EXIT);
+	}
+	lockfile << getpid() << std::endl;
+	lockfile.close();
 }

+ 62 - 64
app.h

@@ -33,87 +33,85 @@
 
 class App {
 public:
-    App(int argc, char** argv);
-    ~App();
-    void Run();
-    int GetServerPID();
-    void RestartServer();
-    void StopServer();
+	App(int argc, char** argv);
+	~App();
+	void Run();
+	int GetServerPID();
+	void RestartServer();
+	void StopServer();
 
-    // Lock functions
-    void GetLock();
-    void RemoveLock();
+	/* Lock functions */
+	void GetLock();
+	void RemoveLock();
 
-    bool isServerStarted();
+	bool isServerStarted();
 
 private:
-    void Login();
-    void Reboot();
-    void Halt();
-    void Suspend();
-    void Console();
-    void Exit();
-    void KillAllClients(Bool top);
-    void ReadConfig();
-    void OpenLog();
-    void CloseLog();
-    void HideCursor();
-    void CreateServerAuth();
-    char* StrConcat(const char* str1, const char* str2);
-    void UpdatePid();
-
-    bool AuthenticateUser(bool focuspass);
+	void Login();
+	void Reboot();
+	void Halt();
+	void Suspend();
+	void Console();
+	void Exit();
+	void KillAllClients(Bool top);
+	void ReadConfig();
+	void OpenLog();
+	void CloseLog();
+	void HideCursor();
+	void CreateServerAuth();
+	char* StrConcat(const char* str1, const char* str2);
+	void UpdatePid();
+
+	bool AuthenticateUser(bool focuspass);
  
-    static std::string findValidRandomTheme(const std::string& set);
-    static void replaceVariables(std::string& input,
-                                 const std::string& var,
-                                 const std::string& value);
-
-    // Server functions
-    int StartServer();
-    int ServerTimeout(int timeout, char *string);
-    int WaitForServer();
-
-    // Private data
-    Window Root;
-    Display* Dpy;
-    int Scr;
-    Panel* LoginPanel;
-    int ServerPID;
-    const char* DisplayName;
-    bool serverStarted;
+	static std::string findValidRandomTheme(const std::string& set);
+	static void replaceVariables(std::string& input,
+								 const std::string& var,
+								 const std::string& value);
+
+	/* Server functions */
+	int StartServer();
+	int ServerTimeout(int timeout, char *string);
+	int WaitForServer();
+
+	/* Private data */
+	Window Root;
+	Display* Dpy;
+	int Scr;
+	Panel* LoginPanel;
+	int ServerPID;
+	const char* DisplayName;
+	bool serverStarted;
 
 #ifdef USE_PAM
 	PAM::Authenticator pam;
 #endif
 #ifdef USE_CONSOLEKIT
-    Ck::Session ck;
+	Ck::Session ck;
 #endif
 
-    // Options
-    char* DispName;
+	/* Options */
+	char* DispName;
 
-    Cfg *cfg;
+	Cfg *cfg;
 
-    Pixmap BackgroundPixmap;
+	Pixmap BackgroundPixmap;
 
-    void blankScreen();
-    Image* image;
-    void setBackground(const std::string& themedir);
+	void blankScreen();
+	Image* image;
+	void setBackground(const std::string& themedir);
 
-    bool firstlogin;
-    bool daemonmode;
-    bool force_nodaemon;
-	// For testing themes
+	bool firstlogin;
+	bool daemonmode;
+	bool force_nodaemon;
+	/* For testing themes */
 	char* testtheme;
-    bool testing;
-    
-    std::string themeName;
-    std::string mcookie;
+	bool testing;
+	
+	std::string themeName;
+	std::string mcookie;
 
-    const int mcookiesize;
+	const int mcookiesize;
 };
 
-
-#endif
-
+#endif /* _APP_H_ */

+ 234 - 235
cfg.cpp

@@ -25,287 +25,286 @@ using namespace std;
 typedef pair<string,string> option;
 
 Cfg::Cfg() 
-    : currentSession(-1)
+	: currentSession(-1)
 {
-    // Configuration options
-    options.insert(option("default_path","/bin:/usr/bin:/usr/local/bin"));
-    options.insert(option("default_xserver","/usr/bin/X"));
-    options.insert(option("xserver_arguments",""));
-    options.insert(option("numlock",""));
-    options.insert(option("daemon",""));
-    options.insert(option("xauth_path","/usr/bin/xauth"));
-    options.insert(option("login_cmd","exec /bin/bash -login ~/.xinitrc %session"));
-    options.insert(option("halt_cmd","/sbin/shutdown -h now"));
-    options.insert(option("reboot_cmd","/sbin/shutdown -r now"));
-    options.insert(option("suspend_cmd",""));
-    options.insert(option("sessionstart_cmd",""));
-    options.insert(option("sessionstop_cmd",""));
-    options.insert(option("console_cmd","/usr/bin/xterm -C -fg white -bg black +sb -g %dx%d+%d+%d -fn %dx%d -T ""Console login"" -e /bin/sh -c ""/bin/cat /etc/issue; exec /bin/login"""));
-    options.insert(option("screenshot_cmd","import -window root /slim.png"));
-    options.insert(option("welcome_msg","Welcome to %host"));
-    options.insert(option("session_msg","Session:"));
-    options.insert(option("default_user",""));
-    options.insert(option("focus_password","no"));
-    options.insert(option("auto_login","no"));
-    options.insert(option("current_theme","default"));
-    options.insert(option("lockfile","/var/run/slim.lock"));
-    options.insert(option("logfile","/var/log/slim.log"));
-    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"));
-
-    // Theme stuff
-    options.insert(option("input_panel_x","50%"));
-    options.insert(option("input_panel_y","40%"));
-    options.insert(option("input_name_x","200"));
-    options.insert(option("input_name_y","154"));
-    options.insert(option("input_pass_x","-1")); // default is single inputbox
-    options.insert(option("input_pass_y","-1"));
-    options.insert(option("input_font","Verdana:size=11"));
-    options.insert(option("input_color", "#000000"));
-    options.insert(option("input_cursor_height","20"));
-    options.insert(option("input_maxlength_name","20"));
-    options.insert(option("input_maxlength_passwd","20"));
-    options.insert(option("input_shadow_xoffset", "0"));
-    options.insert(option("input_shadow_yoffset", "0"));
-    options.insert(option("input_shadow_color","#FFFFFF"));
-
-    options.insert(option("welcome_font","Verdana:size=14"));
-    options.insert(option("welcome_color","#FFFFFF"));
-    options.insert(option("welcome_x","-1"));
-    options.insert(option("welcome_y","-1"));
-    options.insert(option("welcome_shadow_xoffset", "0"));
-    options.insert(option("welcome_shadow_yoffset", "0"));
-    options.insert(option("welcome_shadow_color","#FFFFFF"));
-
-    options.insert(option("intro_msg",""));
-    options.insert(option("intro_font","Verdana:size=14"));
-    options.insert(option("intro_color","#FFFFFF"));
-    options.insert(option("intro_x","-1"));
-    options.insert(option("intro_y","-1"));
-
-    options.insert(option("background_style","stretch"));
-    options.insert(option("background_color","#CCCCCC"));
-
-    options.insert(option("username_font","Verdana:size=12"));
-    options.insert(option("username_color","#FFFFFF"));
-    options.insert(option("username_x","-1"));
-    options.insert(option("username_y","-1"));
-    options.insert(option("username_msg","Please enter your username"));
-    options.insert(option("username_shadow_xoffset", "0"));
-    options.insert(option("username_shadow_yoffset", "0"));
-    options.insert(option("username_shadow_color","#FFFFFF"));
-
-    options.insert(option("password_x","-1"));
-    options.insert(option("password_y","-1"));
-    options.insert(option("password_msg","Please enter your password"));
-
-    options.insert(option("msg_color","#FFFFFF"));
-    options.insert(option("msg_font","Verdana:size=16:bold"));
-    options.insert(option("msg_x","40"));
-    options.insert(option("msg_y","40"));
-    options.insert(option("msg_shadow_xoffset", "0"));
-    options.insert(option("msg_shadow_yoffset", "0"));
-    options.insert(option("msg_shadow_color","#FFFFFF"));
-    
-
-    options.insert(option("session_color","#FFFFFF"));
-    options.insert(option("session_font","Verdana:size=16:bold"));
-    options.insert(option("session_x","50%"));
-    options.insert(option("session_y","90%"));
-    options.insert(option("session_shadow_xoffset", "0"));
-    options.insert(option("session_shadow_yoffset", "0"));
-    options.insert(option("session_shadow_color","#FFFFFF"));
-
-    error = "";
+	/* Configuration options */
+	options.insert(option("default_path","/bin:/usr/bin:/usr/local/bin"));
+	options.insert(option("default_xserver","/usr/bin/X"));
+	options.insert(option("xserver_arguments",""));
+	options.insert(option("numlock",""));
+	options.insert(option("daemon",""));
+	options.insert(option("xauth_path","/usr/bin/xauth"));
+	options.insert(option("login_cmd","exec /bin/bash -login ~/.xinitrc %session"));
+	options.insert(option("halt_cmd","/sbin/shutdown -h now"));
+	options.insert(option("reboot_cmd","/sbin/shutdown -r now"));
+	options.insert(option("suspend_cmd",""));
+	options.insert(option("sessionstart_cmd",""));
+	options.insert(option("sessionstop_cmd",""));
+	options.insert(option("console_cmd","/usr/bin/xterm -C -fg white -bg black +sb -g %dx%d+%d+%d -fn %dx%d -T ""Console login"" -e /bin/sh -c ""/bin/cat /etc/issue; exec /bin/login"""));
+	options.insert(option("screenshot_cmd","import -window root /slim.png"));
+	options.insert(option("welcome_msg","Welcome to %host"));
+	options.insert(option("session_msg","Session:"));
+	options.insert(option("default_user",""));
+	options.insert(option("focus_password","no"));
+	options.insert(option("auto_login","no"));
+	options.insert(option("current_theme","default"));
+	options.insert(option("lockfile","/var/run/slim.lock"));
+	options.insert(option("logfile","/var/log/slim.log"));
+	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"));
+
+	/* Theme stuff */
+	options.insert(option("input_panel_x","50%"));
+	options.insert(option("input_panel_y","40%"));
+	options.insert(option("input_name_x","200"));
+	options.insert(option("input_name_y","154"));
+	options.insert(option("input_pass_x","-1")); /* default is single inputbox */
+	options.insert(option("input_pass_y","-1"));
+	options.insert(option("input_font","Verdana:size=11"));
+	options.insert(option("input_color", "#000000"));
+	options.insert(option("input_cursor_height","20"));
+	options.insert(option("input_maxlength_name","20"));
+	options.insert(option("input_maxlength_passwd","20"));
+	options.insert(option("input_shadow_xoffset", "0"));
+	options.insert(option("input_shadow_yoffset", "0"));
+	options.insert(option("input_shadow_color","#FFFFFF"));
+
+	options.insert(option("welcome_font","Verdana:size=14"));
+	options.insert(option("welcome_color","#FFFFFF"));
+	options.insert(option("welcome_x","-1"));
+	options.insert(option("welcome_y","-1"));
+	options.insert(option("welcome_shadow_xoffset", "0"));
+	options.insert(option("welcome_shadow_yoffset", "0"));
+	options.insert(option("welcome_shadow_color","#FFFFFF"));
+
+	options.insert(option("intro_msg",""));
+	options.insert(option("intro_font","Verdana:size=14"));
+	options.insert(option("intro_color","#FFFFFF"));
+	options.insert(option("intro_x","-1"));
+	options.insert(option("intro_y","-1"));
+
+	options.insert(option("background_style","stretch"));
+	options.insert(option("background_color","#CCCCCC"));
+
+	options.insert(option("username_font","Verdana:size=12"));
+	options.insert(option("username_color","#FFFFFF"));
+	options.insert(option("username_x","-1"));
+	options.insert(option("username_y","-1"));
+	options.insert(option("username_msg","Please enter your username"));
+	options.insert(option("username_shadow_xoffset", "0"));
+	options.insert(option("username_shadow_yoffset", "0"));
+	options.insert(option("username_shadow_color","#FFFFFF"));
+
+	options.insert(option("password_x","-1"));
+	options.insert(option("password_y","-1"));
+	options.insert(option("password_msg","Please enter your password"));
+
+	options.insert(option("msg_color","#FFFFFF"));
+	options.insert(option("msg_font","Verdana:size=16:bold"));
+	options.insert(option("msg_x","40"));
+	options.insert(option("msg_y","40"));
+	options.insert(option("msg_shadow_xoffset", "0"));
+	options.insert(option("msg_shadow_yoffset", "0"));
+	options.insert(option("msg_shadow_color","#FFFFFF"));
+	
+
+	options.insert(option("session_color","#FFFFFF"));
+	options.insert(option("session_font","Verdana:size=16:bold"));
+	options.insert(option("session_x","50%"));
+	options.insert(option("session_y","90%"));
+	options.insert(option("session_shadow_xoffset", "0"));
+	options.insert(option("session_shadow_yoffset", "0"));
+	options.insert(option("session_shadow_color","#FFFFFF"));
+
+	error = "";
 
 }
 
 Cfg::~Cfg() {
-    options.clear();
+	options.clear();
 }
 /*
  * Creates the Cfg object and parses
  * known options from the given configfile / themefile
  */
 bool Cfg::readConf(string configfile) {
-    int n = -1;
-    string line, fn(configfile);
-    map<string,string>::iterator it;
-    string op;
-    ifstream cfgfile( fn.c_str() );
-    if (cfgfile) {
-        while (getline( cfgfile, line )) {
-            it = options.begin();
-            while (it != options.end()) {
-                op = it->first;
-                n = line.find(op);
-                if (n == 0)
-                    options[op] = parseOption(line, op);
-                it++;
-            }
-        }
-        cfgfile.close();
-
-        fillSessionList();
-
-        return true;
-    } else {
-        error = "Cannot read configuration file: " + configfile;
-        return false;
-    }
+	int n = -1;
+	string line, fn(configfile);
+	map<string,string>::iterator it;
+	string op;
+	ifstream cfgfile( fn.c_str() );
+	if (cfgfile) {
+		while (getline( cfgfile, line )) {
+			it = options.begin();
+			while (it != options.end()) {
+				op = it->first;
+				n = line.find(op);
+				if (n == 0)
+					options[op] = parseOption(line, op);
+				it++;
+			}
+		}
+		cfgfile.close();
+
+		fillSessionList();
+
+		return true;
+	} else {
+		error = "Cannot read configuration file: " + configfile;
+		return false;
+	}
 }
 
 /* Returns the option value, trimmed */
 string Cfg::parseOption(string line, string option ) {
-    return Trim( line.substr(option.size(), line.size() - option.size()));
+	return Trim( line.substr(option.size(), line.size() - option.size()));
 }
 
-
 const string& Cfg::getError() const {
-    return error;
+	return error;
 }
 
 string& Cfg::getOption(string option) {
-    return options[option];
+	return options[option];
 }
 
 /* return a trimmed string */
 string Cfg::Trim( const string& s ) {
-    if ( s.empty() ) {
-        return s;
-    }
-    int pos = 0;
-    string line = s;
-    int len = line.length();
-    while ( pos < len && isspace( line[pos] ) ) {
-        ++pos;
-    }
-    line.erase( 0, pos );
-    pos = line.length()-1;
-    while ( pos > -1 && isspace( line[pos] ) ) {
-        --pos;
-    }
-    if ( pos != -1 ) {
-        line.erase( pos+1 );
-    }
-    return line;
+	if ( s.empty() ) {
+		return s;
+	}
+	int pos = 0;
+	string line = s;
+	int len = line.length();
+	while ( pos < len && isspace( line[pos] ) ) {
+		++pos;
+	}
+	line.erase( 0, pos );
+	pos = line.length()-1;
+	while ( pos > -1 && isspace( line[pos] ) ) {
+		--pos;
+	}
+	if ( pos != -1 ) {
+		line.erase( pos+1 );
+	}
+	return line;
 }
 
 /* Return the welcome message with replaced vars */
 string Cfg::getWelcomeMessage(){
-    string s = getOption("welcome_msg");
-    int n = -1;
-    n = s.find("%host");
-    if (n >= 0) {
-        string tmp = s.substr(0, n);
-        char host[40];
-        gethostname(host,40);
-        tmp = tmp + host;
-        tmp = tmp + s.substr(n+5, s.size() - n);
-        s = tmp;
-    }
-    n = s.find("%domain");
-    if (n >= 0) {
-        string tmp = s.substr(0, n);;
-        char domain[40];
-        getdomainname(domain,40);
-        tmp = tmp + domain;
-        tmp = tmp + s.substr(n+7, s.size() - n);
-        s = tmp;
-    }
-    return s;
+	string s = getOption("welcome_msg");
+	int n = -1;
+	n = s.find("%host");
+	if (n >= 0) {
+		string tmp = s.substr(0, n);
+		char host[40];
+		gethostname(host,40);
+		tmp = tmp + host;
+		tmp = tmp + s.substr(n+5, s.size() - n);
+		s = tmp;
+	}
+	n = s.find("%domain");
+	if (n >= 0) {
+		string tmp = s.substr(0, n);;
+		char domain[40];
+		getdomainname(domain,40);
+		tmp = tmp + domain;
+		tmp = tmp + s.substr(n+7, s.size() - n);
+		s = tmp;
+	}
+	return s;
 }
 
 int Cfg::string2int(const char* string, bool* ok) {
-    char* err = 0;
-    int l = (int)strtol(string, &err, 10);
-    if (ok) {
-        *ok = (*err == 0);
-    }
-    return (*err == 0) ? l : 0;
+	char* err = 0;
+	int l = (int)strtol(string, &err, 10);
+	if (ok) {
+		*ok = (*err == 0);
+	}
+	return (*err == 0) ? l : 0;
 }
 
 int Cfg::getIntOption(std::string option) {
-    return string2int(options[option].c_str());
+	return string2int(options[option].c_str());
 }
 
-// Get absolute position
+/* Get absolute position */
 int Cfg::absolutepos(const string& position, int max, int width) {
-    int n = -1;
-    n = position.find("%");
-    if (n>0) { // X Position expressed in percentage
-        int result = (max*string2int(position.substr(0, n).c_str())/100) - (width / 2);
-        return result < 0 ? 0 : result ;
-    } else { // Absolute X position
-        return string2int(position.c_str());
-    }
+	int n = -1;
+	n = position.find("%");
+	if (n>0) { /* X Position expressed in percentage */
+		int result = (max*string2int(position.substr(0, n).c_str())/100) - (width / 2);
+		return result < 0 ? 0 : result ;
+	} else { /* Absolute X position */
+		return string2int(position.c_str());
+	}
 }
 
-// split a comma separated string into a vector of strings
+/* split a comma separated string into a vector of strings */
 void Cfg::split(vector<string>& v, const string& str, char c, bool useEmpty) {
-    v.clear();
-    string::const_iterator s = str.begin();
-    string tmp;
-    while (true) {
-        string::const_iterator begin = s;
-        while (*s != c && s != str.end()) { ++s; }
-    tmp = string(begin, s);
-    if (useEmpty || tmp.size() > 0)
-            v.push_back(tmp);
-        if (s == str.end()) {
-            break;
-        }
-        if (++s == str.end()) {
-        if (useEmpty)
-                v.push_back("");
-            break;
-        }
-    }
+	v.clear();
+	string::const_iterator s = str.begin();
+	string tmp;
+	while (true) {
+		string::const_iterator begin = s;
+		while (*s != c && s != str.end()) { ++s; }
+	tmp = string(begin, s);
+	if (useEmpty || tmp.size() > 0)
+			v.push_back(tmp);
+		if (s == str.end()) {
+			break;
+		}
+		if (++s == str.end()) {
+		if (useEmpty)
+				v.push_back("");
+			break;
+		}
+	}
 }
 
 void Cfg::fillSessionList(){
-    string strSessionList = getOption("sessions");
-    string strSessionDir  = getOption("sessiondir");
-
-    sessions.clear();
-
-    if( !strSessionDir.empty() ) {
-        DIR *pDir = opendir(strSessionDir.c_str());
-
-        if (pDir != NULL) {
-            struct dirent *pDirent = NULL;
-
-            while ((pDirent = readdir(pDir)) != NULL) {
-                string strFile(strSessionDir);
-                strFile += "/";
-                strFile += pDirent->d_name;
-
-                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));
-                    }
-                }
-            }
-            closedir(pDir);
-        }
-    } 
-
-    if (sessions.empty()){
-        split(sessions, strSessionList, ',', false);
-    }
+	string strSessionList = getOption("sessions");
+	string strSessionDir  = getOption("sessiondir");
+
+	sessions.clear();
+
+	if( !strSessionDir.empty() ) {
+		DIR *pDir = opendir(strSessionDir.c_str());
+
+		if (pDir != NULL) {
+			struct dirent *pDirent = NULL;
+
+			while ((pDirent = readdir(pDir)) != NULL) {
+				string strFile(strSessionDir);
+				strFile += "/";
+				strFile += pDirent->d_name;
+
+				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));
+					}
+				}
+			}
+			closedir(pDir);
+		}
+	} 
+
+	if (sessions.empty()){
+		split(sessions, strSessionList, ',', false);
+	}
 }
 
 string Cfg::nextSession(string current) {
-    if (sessions.size() < 1)
-        return current;
+	if (sessions.size() < 1)
+		return current;
 
-    currentSession = (currentSession + 1) % sessions.size();
-    return sessions[currentSession];
+	currentSession = (currentSession + 1) % sessions.size();
+	return sessions[currentSession];
 }

+ 23 - 23
cfg.h

@@ -15,7 +15,7 @@
 #include <map>
 #include <vector>
 
-#define INPUT_MAXLENGTH_NAME    30
+#define INPUT_MAXLENGTH_NAME	30
 #define INPUT_MAXLENGTH_PASSWD  50
 
 #define CFGFILE SYSCONFDIR"/slim.conf"
@@ -25,32 +25,32 @@
 class Cfg {
 
 public:
-    Cfg();
-    ~Cfg();
-    bool readConf(std::string configfile);
-    std::string parseOption(std::string line, std::string option);
-    const std::string& getError() const;
-    std::string& getOption(std::string option);
-    int getIntOption(std::string option);
-    std::string getWelcomeMessage();
-
-    static int absolutepos(const std::string& position, int max, int width);
-    static int string2int(const char* string, bool* ok = 0);
-    static void split(std::vector<std::string>& v, const std::string& str, 
-                      char c, bool useEmpty=true);
-    static std::string Trim(const std::string& s);
-
-    std::string nextSession(std::string current);
+	Cfg();
+	~Cfg();
+	bool readConf(std::string configfile);
+	std::string parseOption(std::string line, std::string option);
+	const std::string& getError() const;
+	std::string& getOption(std::string option);
+	int getIntOption(std::string option);
+	std::string getWelcomeMessage();
+
+	static int absolutepos(const std::string& position, int max, int width);
+	static int string2int(const char* string, bool* ok = 0);
+	static void split(std::vector<std::string>& v, const std::string& str, 
+					  char c, bool useEmpty=true);
+	static std::string Trim(const std::string& s);
+
+	std::string nextSession(std::string current);
 
 private:
-    void fillSessionList();
+	void fillSessionList();
 
 private:
-    std::map<std::string,std::string> options;
-    std::vector<std::string> sessions;
-    int currentSession;
-    std::string error;
+	std::map<std::string,std::string> options;
+	std::vector<std::string> sessions;
+	int currentSession;
+	std::string error;
 
 };
 
-#endif
+#endif /* _CFG_H_ */

+ 17 - 19
const.h

@@ -12,39 +12,37 @@
 #ifndef _CONST_H_
 #define _CONST_H_
 
+#define APPNAME	"slim"
+#define DISPLAY	":0.0"
 
-#define APPNAME    "slim"
+#define CONSOLE_STR	 "console"
+#define HALT_STR		"halt"
+#define REBOOT_STR	  "reboot"
+#define EXIT_STR		"exit"
+#define SUSPEND_STR	 "suspend"
 
-#define DISPLAY    ":0.0"
+#define HIDE		0
+#define SHOW		1
 
-#define CONSOLE_STR     "console"
-#define HALT_STR        "halt"
-#define REBOOT_STR      "reboot"
-#define EXIT_STR        "exit"
-#define SUSPEND_STR     "suspend"
-
-#define HIDE        0
-#define SHOW        1
-
-#define GET_NAME    0
+#define GET_NAME	0
 #define GET_PASSWD  1
 
-#define OK_EXIT     0
-#define ERR_EXIT    1
+#define OK_EXIT	 0
+#define ERR_EXIT	1
 
 /* duration for showing error messages,
  * as "login command failed", in seconds 
  */
 #define ERROR_DURATION  5
 
-// variables replaced in login_cmd
-#define SESSION_VAR     "%session"
-#define THEME_VAR       "%theme"
+/* variables replaced in login_cmd */
+#define SESSION_VAR	 "%session"
+#define THEME_VAR	   "%theme"
 
 /* variables replaced in pre-session_cmd and post-session_cmd */
-#define USER_VAR       "%user"
+#define USER_VAR	   "%user"
 
 /* max height/width for images */
 #define MAX_DIMENSION 10000
 
-#endif
+#endif /* _CONST_H_ */

+ 767 - 769
image.cpp

@@ -1,8 +1,8 @@
 /* SLiM - Simple Login Manager
    Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
    Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
-   Copyright (C) 2012    Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
-      
+   Copyright (C) 2012	Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
+	  
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
@@ -24,8 +24,8 @@ using namespace std;
 #include "image.h"
 
 extern "C" {
-    #include <jpeglib.h>
-    #include <png.h>
+	#include <jpeglib.h>
+	#include <png.h>
 }
 
 Image::Image() : width(0), height(0), area(0),
@@ -33,209 +33,208 @@ rgb_data(NULL), png_alpha(NULL), quality_(80) {}
 
 Image::Image(const int w, const int h, const unsigned char *rgb, const unsigned char *alpha) :
 width(w), height(h), area(w*h), quality_(80) {
-    width = w;
-    height = h;
-    area = w * h;
-
-    rgb_data = (unsigned char *) malloc(3 * area);
-    memcpy(rgb_data, rgb, 3 * area);
-
-    if (alpha == NULL) {
-        png_alpha = NULL;
-    } else {
-        png_alpha = (unsigned char *) malloc(area);
-        memcpy(png_alpha, alpha, area);
-    }
+	width = w;
+	height = h;
+	area = w * h;
+
+	rgb_data = (unsigned char *) malloc(3 * area);
+	memcpy(rgb_data, rgb, 3 * area);
+
+	if (alpha == NULL) {
+		png_alpha = NULL;
+	} else {
+		png_alpha = (unsigned char *) malloc(area);
+		memcpy(png_alpha, alpha, area);
+	}
 }
 
 Image::~Image() {
-    free(rgb_data);
-    free(png_alpha);
+	free(rgb_data);
+	free(png_alpha);
 }
 
 bool
 Image::Read(const char *filename) {
-    char buf[4];
-    unsigned char *ubuf = (unsigned char *) buf;
-    int success = 0;
-
-    FILE *file;
-    file = fopen(filename, "rb");
-    if (file == NULL)
-        return(false);
-
-    /* see what kind of file we have */
-
-    fread(buf, 1, 4, file);
-    fclose(file);
-
-    if ((ubuf[0] == 0x89) && !strncmp("PNG", buf+1, 3)) {
-        success = readPng(filename, &width, &height, &rgb_data, &png_alpha);
-    }
-    else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8)){
-        success = readJpeg(filename, &width, &height, &rgb_data);
-    } else {
-        fprintf(stderr, "Unknown image format\n");
-        success = 0;
-    }
-    return(success == 1);
+	char buf[4];
+	unsigned char *ubuf = (unsigned char *) buf;
+	int success = 0;
+
+	FILE *file;
+	file = fopen(filename, "rb");
+	if (file == NULL)
+		return(false);
+
+	/* see what kind of file we have */
+
+	fread(buf, 1, 4, file);
+	fclose(file);
+
+	if ((ubuf[0] == 0x89) && !strncmp("PNG", buf+1, 3)) 
+		success = readPng(filename, &width, &height, &rgb_data, &png_alpha);
+	else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8))
+		success = readJpeg(filename, &width, &height, &rgb_data);
+	else {
+		fprintf(stderr, "Unknown image format\n");
+		success = 0;
+	}
+	return(success == 1);
 }
 
 void
 Image::Reduce(const int factor) {
-    if (factor < 1)
-        return;
-
-    int scale = 1;
-    for (int i = 0; i < factor; i++)
-        scale *= 2;
-
-    double scale2 = scale*scale;
-
-    int w = width / scale;
-    int h = height / scale;
-    int new_area = w * h;
-
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * new_area);
-    memset(new_rgb, 0, 3 * new_area);
-
-    unsigned char *new_alpha = NULL;
-    if (png_alpha != NULL) {
-        new_alpha = (unsigned char *) malloc(new_area);
-        memset(new_alpha, 0, new_area);
-    }
-
-    int ipos = 0;
-    for (int j = 0; j < height; j++) {
-        int js = j / scale;
-        for (int i = 0; i < width; i++) {
-            int is = i/scale;
-            for (int k = 0; k < 3; k++)
-                new_rgb[3*(js * w + is) + k] += static_cast<unsigned char> ((rgb_data[3*ipos + k] + 0.5) / scale2);
-
-            if (png_alpha != NULL)
-                new_alpha[js * w + is] += static_cast<unsigned char> (png_alpha[ipos]/scale2);
-            ipos++;
-        }
-    }
-
-    free(rgb_data);
-    free(png_alpha);
-
-    rgb_data = new_rgb;
-    png_alpha = new_alpha;
-    width = w;
-    height = h;
-
-    area = w * h;
+	if (factor < 1)
+		return;
+
+	int scale = 1;
+	for (int i = 0; i < factor; i++)
+		scale *= 2;
+
+	double scale2 = scale*scale;
+
+	int w = width / scale;
+	int h = height / scale;
+	int new_area = w * h;
+
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * new_area);
+	memset(new_rgb, 0, 3 * new_area);
+
+	unsigned char *new_alpha = NULL;
+	if (png_alpha != NULL) {
+		new_alpha = (unsigned char *) malloc(new_area);
+		memset(new_alpha, 0, new_area);
+	}
+
+	int ipos = 0;
+	for (int j = 0; j < height; j++) {
+		int js = j / scale;
+		for (int i = 0; i < width; i++) {
+			int is = i/scale;
+			for (int k = 0; k < 3; k++)
+				new_rgb[3*(js * w + is) + k] += static_cast<unsigned char> ((rgb_data[3*ipos + k] + 0.5) / scale2);
+
+			if (png_alpha != NULL)
+				new_alpha[js * w + is] += static_cast<unsigned char> (png_alpha[ipos]/scale2);
+			ipos++;
+		}
+	}
+
+	free(rgb_data);
+	free(png_alpha);
+
+	rgb_data = new_rgb;
+	png_alpha = new_alpha;
+	width = w;
+	height = h;
+
+	area = w * h;
 }
 
 void
 Image::Resize(const int w, const int h) {
-    
-    if (width==w && height==h){
-        return;
-    }
-
-    int new_area = w * h;
-
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * new_area);
-    unsigned char *new_alpha = NULL;
-    if (png_alpha != NULL)
-        new_alpha = (unsigned char *) malloc(new_area);
-
-    const double scale_x = ((double) w) / width;
-    const double scale_y = ((double) h) / height;
-
-    int ipos = 0;
-    for (int j = 0; j < h; j++) {
-        const double y = j / scale_y;
-        for (int i = 0; i < w; i++) {
-            const double x = i / scale_x;
-            if (new_alpha == NULL)
-                getPixel(x, y, new_rgb + 3*ipos);
-            else
-                getPixel(x, y, new_rgb + 3*ipos, new_alpha + ipos);
-            ipos++;
-        }
-    }
-
-    free(rgb_data);
-    free(png_alpha);
-
-    rgb_data = new_rgb;
-    png_alpha = new_alpha;
-    width = w;
-    height = h;
-
-    area = w * h;
+	
+	if (width==w && height==h){
+		return;
+	}
+
+	int new_area = w * h;
+
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * new_area);
+	unsigned char *new_alpha = NULL;
+	if (png_alpha != NULL)
+		new_alpha = (unsigned char *) malloc(new_area);
+
+	const double scale_x = ((double) w) / width;
+	const double scale_y = ((double) h) / height;
+
+	int ipos = 0;
+	for (int j = 0; j < h; j++) {
+		const double y = j / scale_y;
+		for (int i = 0; i < w; i++) {
+			const double x = i / scale_x;
+			if (new_alpha == NULL)
+				getPixel(x, y, new_rgb + 3*ipos);
+			else
+				getPixel(x, y, new_rgb + 3*ipos, new_alpha + ipos);
+			ipos++;
+		}
+	}
+
+	free(rgb_data);
+	free(png_alpha);
+
+	rgb_data = new_rgb;
+	png_alpha = new_alpha;
+	width = w;
+	height = h;
+
+	area = w * h;
 }
 
-// Find the color of the desired point using bilinear interpolation.
-// Assume the array indices refer to the denter of the pixel, so each
-// pixel has corners at (i - 0.5, j - 0.5) and (i + 0.5, j + 0.5)
+/* Find the color of the desired point using bilinear interpolation. */
+/* Assume the array indices refer to the denter of the pixel, so each */
+/* pixel has corners at (i - 0.5, j - 0.5) and (i + 0.5, j + 0.5) */
 void
 Image::getPixel(double x, double y, unsigned char *pixel) {
-    getPixel(x, y, pixel, NULL);
+	getPixel(x, y, pixel, NULL);
 }
 
 void
 Image::getPixel(double x, double y, unsigned char *pixel, unsigned char *alpha) {
-    if (x < -0.5)
-        x = -0.5;
-    if (x >= width - 0.5)
-        x = width - 0.5;
-
-    if (y < -0.5)
-        y = -0.5;
-    if (y >= height - 0.5)
-        y = height - 0.5;
-
-    int ix0 = (int) (floor(x));
-    int ix1 = ix0 + 1;
-    if (ix0 < 0)
-        ix0 = width - 1;
-    if (ix1 >= width)
-        ix1 = 0;
-
-    int iy0 = (int) (floor(y));
-    int iy1 = iy0 + 1;
-    if (iy0 < 0)
-        iy0 = 0;
-    if (iy1 >= height)
-        iy1 = height - 1;
-
-    const double t = x - floor(x);
-    const double u = 1 - (y - floor(y));
-
-    double weight[4];
-    weight[1] = t * u;
-    weight[0] = u - weight[1];
-    weight[2] = 1 - t - u + weight[1];
-    weight[3] = t - weight[1];
-
-    unsigned char *pixels[4];
-    pixels[0] = rgb_data + 3 * (iy0 * width + ix0);
-    pixels[1] = rgb_data + 3 * (iy0 * width + ix1);
-    pixels[2] = rgb_data + 3 * (iy1 * width + ix0);
-    pixels[3] = rgb_data + 3 * (iy1 * width + ix1);
-
-    memset(pixel, 0, 3);
-    for (int i = 0; i < 4; i++) {
-        for (int j = 0; j < 3; j++)
-            pixel[j] += (unsigned char) (weight[i] * pixels[i][j]);
-    }
-
-    if (alpha != NULL) {
-        unsigned char pixels[4];
-        pixels[0] = png_alpha[iy0 * width + ix0];
-        pixels[1] = png_alpha[iy0 * width + ix1];
-        pixels[2] = png_alpha[iy0 * width + ix0];
-        pixels[3] = png_alpha[iy1 * width + ix1];
-
-        for (int i = 0; i < 4; i++)
-            *alpha = (unsigned char) (weight[i] * pixels[i]);
-    }
+	if (x < -0.5)
+		x = -0.5;
+	if (x >= width - 0.5)
+		x = width - 0.5;
+
+	if (y < -0.5)
+		y = -0.5;
+	if (y >= height - 0.5)
+		y = height - 0.5;
+
+	int ix0 = (int) (floor(x));
+	int ix1 = ix0 + 1;
+	if (ix0 < 0)
+		ix0 = width - 1;
+	if (ix1 >= width)
+		ix1 = 0;
+
+	int iy0 = (int) (floor(y));
+	int iy1 = iy0 + 1;
+	if (iy0 < 0)
+		iy0 = 0;
+	if (iy1 >= height)
+		iy1 = height - 1;
+
+	const double t = x - floor(x);
+	const double u = 1 - (y - floor(y));
+
+	double weight[4];
+	weight[1] = t * u;
+	weight[0] = u - weight[1];
+	weight[2] = 1 - t - u + weight[1];
+	weight[3] = t - weight[1];
+
+	unsigned char *pixels[4];
+	pixels[0] = rgb_data + 3 * (iy0 * width + ix0);
+	pixels[1] = rgb_data + 3 * (iy0 * width + ix1);
+	pixels[2] = rgb_data + 3 * (iy1 * width + ix0);
+	pixels[3] = rgb_data + 3 * (iy1 * width + ix1);
+
+	memset(pixel, 0, 3);
+	for (int i = 0; i < 4; i++) {
+		for (int j = 0; j < 3; j++)
+			pixel[j] += (unsigned char) (weight[i] * pixels[i][j]);
+	}
+
+	if (alpha != NULL) {
+		unsigned char pixels[4];
+		pixels[0] = png_alpha[iy0 * width + ix0];
+		pixels[1] = png_alpha[iy0 * width + ix1];
+		pixels[2] = png_alpha[iy0 * width + ix0];
+		pixels[3] = png_alpha[iy1 * width + ix1];
+
+		for (int i = 0; i < 4; i++)
+			*alpha = (unsigned char) (weight[i] * pixels[i]);
+	}
 }
 
 /* Merge the image with a background, taking care of the
@@ -245,46 +244,45 @@ Image::getPixel(double x, double y, unsigned char *pixel, unsigned char *alpha)
  */
 void Image::Merge(Image* background, const int x, const int y) {
 
-    if (x + width > background->Width()|| y + height > background->Height()) {
-        return;
-    }
-
-    if (background->Width()*background->Height() != width*height)
-        background->Crop(x, y, width, height);
-
-    double tmp;
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * width * height);
-    memset(new_rgb, 0, 3 * width * height);
-    const unsigned char *bg_rgb = background->getRGBData();
-    
-    int ipos = 0;
-    if (png_alpha != NULL){
-        for (int j = 0; j < height; j++) {
-            for (int i = 0; i < width; i++) {
-                for (int k = 0; k < 3; k++) {
-                    tmp = rgb_data[3*ipos + k]*png_alpha[ipos]/255.0
-                            + bg_rgb[3*ipos + k]*(1-png_alpha[ipos]/255.0);
-                    new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
-                }
-                ipos++;
-            }
-        }
-    } else {
-        for (int j = 0; j < height; j++) {
-            for (int i = 0; i < width; i++) {
-                for (int k = 0; k < 3; k++) {
-                    tmp = rgb_data[3*ipos + k];
-                    new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
-                }
-                ipos++;
-            }
-        }
-    }
-
-    free(rgb_data);
-    free(png_alpha);
-    rgb_data = new_rgb;
-    png_alpha = NULL;
+	if (x + width > background->Width()|| y + height > background->Height()) 
+		return;
+
+	if (background->Width()*background->Height() != width*height)
+		background->Crop(x, y, width, height);
+
+	double tmp;
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * width * height);
+	memset(new_rgb, 0, 3 * width * height);
+	const unsigned char *bg_rgb = background->getRGBData();
+	
+	int ipos = 0;
+	if (png_alpha != NULL){
+		for (int j = 0; j < height; j++) {
+			for (int i = 0; i < width; i++) {
+				for (int k = 0; k < 3; k++) {
+					tmp = rgb_data[3*ipos + k]*png_alpha[ipos]/255.0
+							+ bg_rgb[3*ipos + k]*(1-png_alpha[ipos]/255.0);
+					new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
+				}
+				ipos++;
+			}
+		}
+	} else {
+		for (int j = 0; j < height; j++) {
+			for (int i = 0; i < width; i++) {
+				for (int k = 0; k < 3; k++) {
+					tmp = rgb_data[3*ipos + k];
+					new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
+				}
+				ipos++;
+			}
+		}
+	}
+
+	free(rgb_data);
+	free(png_alpha);
+	rgb_data = new_rgb;
+	png_alpha = NULL;
 
 }
 
@@ -295,47 +293,47 @@ void Image::Merge(Image* background, const int x, const int y) {
  */
 void Image::Tile(const int w, const int h) {
 
-    if (w < width || h < height)
-        return;
-
-    int nx = w / width;
-    if (w % width > 0)
-        nx++;
-    int ny = h / height;
-    if (h % height > 0)
-        ny++;
-
-    int newwidth = nx*width;
-    int newheight=ny*height;
-        
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * newwidth * newheight);
-    memset(new_rgb, 0, 3 * width * height * nx * ny);
-
-    int ipos = 0;
-    int opos = 0;
-
-    for (int r = 0; r < ny; r++) {
-        for (int c = 0; c < nx; c++) {
-            for (int j = 0; j < height; j++) {
-                for (int i = 0; i < width; i++) {
-                    opos = j*width + i;
-                    ipos = r*width*height*nx + j*newwidth + c*width +i;
-                    for (int k = 0; k < 3; k++) {
-                        new_rgb[3*ipos + k] = static_cast<unsigned char> (rgb_data[3*opos + k]);
-                    }
-                }
-            }
-        }
-    }
-
-    free(rgb_data);
-    free(png_alpha);
-    rgb_data = new_rgb;
-    png_alpha = NULL;
-    width = newwidth;
-    height = newheight;
-    area = width * height;
-    Crop(0,0,w,h);
+	if (w < width || h < height)
+		return;
+
+	int nx = w / width;
+	if (w % width > 0)
+		nx++;
+	int ny = h / height;
+	if (h % height > 0)
+		ny++;
+
+	int newwidth = nx*width;
+	int newheight=ny*height;
+		
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * newwidth * newheight);
+	memset(new_rgb, 0, 3 * width * height * nx * ny);
+
+	int ipos = 0;
+	int opos = 0;
+
+	for (int r = 0; r < ny; r++) {
+		for (int c = 0; c < nx; c++) {
+			for (int j = 0; j < height; j++) {
+				for (int i = 0; i < width; i++) {
+					opos = j*width + i;
+					ipos = r*width*height*nx + j*newwidth + c*width +i;
+					for (int k = 0; k < 3; k++) {
+						new_rgb[3*ipos + k] = static_cast<unsigned char> (rgb_data[3*opos + k]);
+					}
+				}
+			}
+		}
+	}
+
+	free(rgb_data);
+	free(png_alpha);
+	rgb_data = new_rgb;
+	png_alpha = NULL;
+	width = newwidth;
+	height = newheight;
+	area = width * height;
+	Crop(0,0,w,h);
 
 }
 
@@ -343,45 +341,45 @@ void Image::Tile(const int w, const int h) {
  */
 void Image::Crop(const int x, const int y, const int w, const int h) {
 
-    if (x+w > width || y+h > height) {
-        return;
-    }
-
-    int x2 = x + w;
-    int y2 = y + h;
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * w * h);
-    memset(new_rgb, 0, 3 * w * h);
-    unsigned char *new_alpha = NULL;
-    if (png_alpha != NULL) {
-        new_alpha = (unsigned char *) malloc(w * h);
-        memset(new_alpha, 0, w * h);
-    }
-
-    int ipos = 0;
-    int opos = 0;
-
-    for (int j = 0; j < height; j++) {
-        for (int i = 0; i < width; i++) {
-            if (j>=y && i>=x && j<y2 && i<x2) {
-                for (int k = 0; k < 3; k++) {
-                    new_rgb[3*ipos + k] = static_cast<unsigned char> (rgb_data[3*opos + k]);
-                }
-                if (png_alpha != NULL)
-                    new_alpha[ipos] = static_cast<unsigned char> (png_alpha[opos]);
-                ipos++;
-            }
-            opos++;
-        }
-    }
-
-    free(rgb_data);
-    free(png_alpha);
-    rgb_data = new_rgb;
-    if (png_alpha != NULL)
-        png_alpha = new_alpha;
-    width = w;
-    height = h;
-    area = w * h;
+	if (x+w > width || y+h > height) {
+		return;
+	}
+
+	int x2 = x + w;
+	int y2 = y + h;
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * w * h);
+	memset(new_rgb, 0, 3 * w * h);
+	unsigned char *new_alpha = NULL;
+	if (png_alpha != NULL) {
+		new_alpha = (unsigned char *) malloc(w * h);
+		memset(new_alpha, 0, w * h);
+	}
+
+	int ipos = 0;
+	int opos = 0;
+
+	for (int j = 0; j < height; j++) {
+		for (int i = 0; i < width; i++) {
+			if (j>=y && i>=x && j<y2 && i<x2) {
+				for (int k = 0; k < 3; k++) {
+					new_rgb[3*ipos + k] = static_cast<unsigned char> (rgb_data[3*opos + k]);
+				}
+				if (png_alpha != NULL)
+					new_alpha[ipos] = static_cast<unsigned char> (png_alpha[opos]);
+				ipos++;
+			}
+			opos++;
+		}
+	}
+
+	free(rgb_data);
+	free(png_alpha);
+	rgb_data = new_rgb;
+	if (png_alpha != NULL)
+		png_alpha = new_alpha;
+	width = w;
+	height = h;
+	area = w * h;
 
 
 }
@@ -391,79 +389,79 @@ void Image::Crop(const int x, const int y, const int w, const int h) {
  */
 void Image::Center(const int w, const int h, const char *hex) {
 
-    unsigned long packed_rgb;
-    sscanf(hex, "%lx", &packed_rgb);  
-
-    unsigned long r = packed_rgb>>16;
-    unsigned long g = packed_rgb>>8 & 0xff;
-    unsigned long b = packed_rgb & 0xff;    
-
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * w * h);
-    memset(new_rgb, 0, 3 * w * h);
-
-    int x = (w - width) / 2;
-    int y = (h - height) / 2;
-    
-    if (x<0) {
-        Crop((width - w)/2,0,w,height);
-        x = 0;
-    }
-    if (y<0) {
-        Crop(0,(height - h)/2,width,h);
-        y = 0;
-    }
-    int x2 = x + width;
-    int y2 = y + height;
-
-    int ipos = 0;
-    int opos = 0;
-    double tmp;
-
-    area = w * h;
-    for (int i = 0; i < area; i++) {
-        new_rgb[3*i] = r;
-        new_rgb[3*i+1] = g;
-        new_rgb[3*i+2] = b;
-    }
-
-    if (png_alpha != NULL) {
-        for (int j = 0; j < h; j++) {
-            for (int i = 0; i < w; i++) {
-                if (j>=y && i>=x && j<y2 && i<x2) {
-                    ipos = j*w + i;
-                    for (int k = 0; k < 3; k++) {
-                        tmp = rgb_data[3*opos + k]*png_alpha[opos]/255.0
-                              + new_rgb[k]*(1-png_alpha[opos]/255.0);
-                        new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
-                    }
-                    opos++;
-                }
-
-            }
-        }
-    } else {
-        for (int j = 0; j < h; j++) {
-            for (int i = 0; i < w; i++) {
-                if (j>=y && i>=x && j<y2 && i<x2) {
-                    ipos = j*w + i;
-                    for (int k = 0; k < 3; k++) {
-                        tmp = rgb_data[3*opos + k];
-                        new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
-                    }
-                    opos++;
-                }
-
-            }
-        }
-    }
-    
-    free(rgb_data);
-    free(png_alpha);
-    rgb_data = new_rgb;
-    png_alpha = NULL;
-    width = w;
-    height = h;
-    
+	unsigned long packed_rgb;
+	sscanf(hex, "%lx", &packed_rgb);  
+
+	unsigned long r = packed_rgb>>16;
+	unsigned long g = packed_rgb>>8 & 0xff;
+	unsigned long b = packed_rgb & 0xff;	
+
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * w * h);
+	memset(new_rgb, 0, 3 * w * h);
+
+	int x = (w - width) / 2;
+	int y = (h - height) / 2;
+	
+	if (x<0) {
+		Crop((width - w)/2,0,w,height);
+		x = 0;
+	}
+	if (y<0) {
+		Crop(0,(height - h)/2,width,h);
+		y = 0;
+	}
+	int x2 = x + width;
+	int y2 = y + height;
+
+	int ipos = 0;
+	int opos = 0;
+	double tmp;
+
+	area = w * h;
+	for (int i = 0; i < area; i++) {
+		new_rgb[3*i] = r;
+		new_rgb[3*i+1] = g;
+		new_rgb[3*i+2] = b;
+	}
+
+	if (png_alpha != NULL) {
+		for (int j = 0; j < h; j++) {
+			for (int i = 0; i < w; i++) {
+				if (j>=y && i>=x && j<y2 && i<x2) {
+					ipos = j*w + i;
+					for (int k = 0; k < 3; k++) {
+						tmp = rgb_data[3*opos + k]*png_alpha[opos]/255.0
+							  + new_rgb[k]*(1-png_alpha[opos]/255.0);
+						new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
+					}
+					opos++;
+				}
+
+			}
+		}
+	} else {
+		for (int j = 0; j < h; j++) {
+			for (int i = 0; i < w; i++) {
+				if (j>=y && i>=x && j<y2 && i<x2) {
+					ipos = j*w + i;
+					for (int k = 0; k < 3; k++) {
+						tmp = rgb_data[3*opos + k];
+						new_rgb[3*ipos + k] = static_cast<unsigned char> (tmp);
+					}
+					opos++;
+				}
+
+			}
+		}
+	}
+	
+	free(rgb_data);
+	free(png_alpha);
+	rgb_data = new_rgb;
+	png_alpha = NULL;
+	width = w;
+	height = h;
+	
 }
 
 /* Fill the image with the given color and adjust its dimensions
@@ -471,426 +469,426 @@ void Image::Center(const int w, const int h, const char *hex) {
  */
 void Image::Plain(const int w, const int h, const char *hex) {
 
-    unsigned long packed_rgb;
-    sscanf(hex, "%lx", &packed_rgb);  
-
-    unsigned long r = packed_rgb>>16;
-    unsigned long g = packed_rgb>>8 & 0xff;
-    unsigned long b = packed_rgb & 0xff;    
-
-    unsigned char *new_rgb = (unsigned char *) malloc(3 * w * h);
-    memset(new_rgb, 0, 3 * w * h);
-
-    area = w * h;
-    for (int i = 0; i < area; i++) {
-        new_rgb[3*i] = r;
-        new_rgb[3*i+1] = g;
-        new_rgb[3*i+2] = b;
-    }
-
-    free(rgb_data);
-    free(png_alpha);
-    rgb_data = new_rgb;
-    png_alpha = NULL;
-    width = w;
-    height = h;
-    
+	unsigned long packed_rgb;
+	sscanf(hex, "%lx", &packed_rgb);  
+
+	unsigned long r = packed_rgb>>16;
+	unsigned long g = packed_rgb>>8 & 0xff;
+	unsigned long b = packed_rgb & 0xff;	
+
+	unsigned char *new_rgb = (unsigned char *) malloc(3 * w * h);
+	memset(new_rgb, 0, 3 * w * h);
+
+	area = w * h;
+	for (int i = 0; i < area; i++) {
+		new_rgb[3*i] = r;
+		new_rgb[3*i+1] = g;
+		new_rgb[3*i+2] = b;
+	}
+
+	free(rgb_data);
+	free(png_alpha);
+	rgb_data = new_rgb;
+	png_alpha = NULL;
+	width = w;
+	height = h;
+	
 }
 
 void
 Image::computeShift(unsigned long mask,
-                    unsigned char &left_shift,
-                    unsigned char &right_shift) {
-    left_shift = 0;
-    right_shift = 8;
-    if (mask != 0) {
-        while ((mask & 0x01) == 0) {
-            left_shift++;
-            mask >>= 1;
-        }
-        while ((mask & 0x01) == 1) {
-            right_shift--;
-            mask >>= 1;
-        }
-    }
+					unsigned char &left_shift,
+					unsigned char &right_shift) {
+	left_shift = 0;
+	right_shift = 8;
+	if (mask != 0) {
+		while ((mask & 0x01) == 0) {
+			left_shift++;
+			mask >>= 1;
+		}
+		while ((mask & 0x01) == 1) {
+			right_shift--;
+			mask >>= 1;
+		}
+	}
 }
 
 Pixmap
 Image::createPixmap(Display* dpy, int scr, Window win) {
-    int i, j;   // loop variables
-
-    const int depth = DefaultDepth(dpy, scr);
-    Visual *visual = DefaultVisual(dpy, scr);
-    Colormap colormap = DefaultColormap(dpy, scr);
-
-    Pixmap tmp = XCreatePixmap(dpy, win, width, height,
-                               depth);
-
-    char *pixmap_data = NULL;
-    switch (depth) {
-    case 32:
-    case 24:
-        pixmap_data = new char[4 * width * height];
-        break;
-    case 16:
-    case 15:
-        pixmap_data = new char[2 * width * height];
-        break;
-    case 8:
-        pixmap_data = new char[width * height];
-        break;
-    default:
-        break;
-    }
-
-    XImage *ximage = XCreateImage(dpy, visual, depth, ZPixmap, 0,
-                                  pixmap_data, width, height,
-                                  8, 0);
-
-    int entries;
-    XVisualInfo v_template;
-    v_template.visualid = XVisualIDFromVisual(visual);
-    XVisualInfo *visual_info = XGetVisualInfo(dpy, VisualIDMask,
-                               &v_template, &entries);
-
-    unsigned long ipos = 0;
-    switch (visual_info->c_class) {
-    case PseudoColor: {
-            XColor xc;
-            xc.flags = DoRed | DoGreen | DoBlue;
-
-            int num_colors = 256;
-            XColor *colors = new XColor[num_colors];
-            for (i = 0; i < num_colors; i++)
-                colors[i].pixel = (unsigned long) i;
-            XQueryColors(dpy, colormap, colors, num_colors);
-
-            int *closest_color = new int[num_colors];
-
-            for (i = 0; i < num_colors; i++) {
-                xc.red = (i & 0xe0) << 8;           // highest 3 bits
-                xc.green = (i & 0x1c) << 11;        // middle 3 bits
-                xc.blue = (i & 0x03) << 14;         // lowest 2 bits
-
-                // find the closest color in the colormap
-                double distance, distance_squared, min_distance = 0;
-                for (int ii = 0; ii < num_colors; ii++) {
-                    distance = colors[ii].red - xc.red;
-                    distance_squared = distance * distance;
-                    distance = colors[ii].green - xc.green;
-                    distance_squared += distance * distance;
-                    distance = colors[ii].blue - xc.blue;
-                    distance_squared += distance * distance;
-
-                    if ((ii == 0) || (distance_squared <= min_distance)) {
-                        min_distance = distance_squared;
-                        closest_color[i] = ii;
-                    }
-                }
-            }
-
-            for (j = 0; j < height; j++) {
-                for (i = 0; i < width; i++) {
-                    xc.red = (unsigned short) (rgb_data[ipos++] & 0xe0);
-                    xc.green = (unsigned short) (rgb_data[ipos++] & 0xe0);
-                    xc.blue = (unsigned short) (rgb_data[ipos++] & 0xc0);
-
-                    xc.pixel = xc.red | (xc.green >> 3) | (xc.blue >> 6);
-                    XPutPixel(ximage, i, j,
-                              colors[closest_color[xc.pixel]].pixel);
-                }
-            }
-            delete [] colors;
-            delete [] closest_color;
-        }
-        break;
-    case TrueColor: {
-            unsigned char red_left_shift;
-            unsigned char red_right_shift;
-            unsigned char green_left_shift;
-            unsigned char green_right_shift;
-            unsigned char blue_left_shift;
-            unsigned char blue_right_shift;
-
-            computeShift(visual_info->red_mask, red_left_shift,
-                         red_right_shift);
-            computeShift(visual_info->green_mask, green_left_shift,
-                         green_right_shift);
-            computeShift(visual_info->blue_mask, blue_left_shift,
-                         blue_right_shift);
-
-            unsigned long pixel;
-            unsigned long red, green, blue;
-            for (j = 0; j < height; j++) {
-                for (i = 0; i < width; i++) {
-                    red = (unsigned long)
-                          rgb_data[ipos++] >> red_right_shift;
-                    green = (unsigned long)
-                            rgb_data[ipos++] >> green_right_shift;
-                    blue = (unsigned long)
-                           rgb_data[ipos++] >> blue_right_shift;
-
-                    pixel = (((red << red_left_shift) & visual_info->red_mask)
-                             | ((green << green_left_shift)
-                                & visual_info->green_mask)
-                             | ((blue << blue_left_shift)
-                                & visual_info->blue_mask));
-
-                    XPutPixel(ximage, i, j, pixel);
-                }
-            }
-        }
-        break;
-    default: {
-            logStream << "Login.app: could not load image" << endl;
-            return(tmp);
-        }
-    }
-
-    GC gc = XCreateGC(dpy, win, 0, NULL);
-    XPutImage(dpy, tmp, gc, ximage, 0, 0, 0, 0, width, height);
-
-    XFreeGC(dpy, gc);
-
-    XFree(visual_info);
-
-    delete [] pixmap_data;
-
-    // Set ximage data to NULL since pixmap data was deallocated above
-    ximage->data = NULL;
-    XDestroyImage(ximage);
-
-    return(tmp);
+	int i, j;   /* loop variables */
+
+	const int depth = DefaultDepth(dpy, scr);
+	Visual *visual = DefaultVisual(dpy, scr);
+	Colormap colormap = DefaultColormap(dpy, scr);
+
+	Pixmap tmp = XCreatePixmap(dpy, win, width, height,
+							   depth);
+
+	char *pixmap_data = NULL;
+	switch (depth) {
+	case 32:
+	case 24:
+		pixmap_data = new char[4 * width * height];
+		break;
+	case 16:
+	case 15:
+		pixmap_data = new char[2 * width * height];
+		break;
+	case 8:
+		pixmap_data = new char[width * height];
+		break;
+	default:
+		break;
+	}
+
+	XImage *ximage = XCreateImage(dpy, visual, depth, ZPixmap, 0,
+								  pixmap_data, width, height,
+								  8, 0);
+
+	int entries;
+	XVisualInfo v_template;
+	v_template.visualid = XVisualIDFromVisual(visual);
+	XVisualInfo *visual_info = XGetVisualInfo(dpy, VisualIDMask,
+							   &v_template, &entries);
+
+	unsigned long ipos = 0;
+	switch (visual_info->c_class) {
+	case PseudoColor: {
+			XColor xc;
+			xc.flags = DoRed | DoGreen | DoBlue;
+
+			int num_colors = 256;
+			XColor *colors = new XColor[num_colors];
+			for (i = 0; i < num_colors; i++)
+				colors[i].pixel = (unsigned long) i;
+			XQueryColors(dpy, colormap, colors, num_colors);
+
+			int *closest_color = new int[num_colors];
+
+			for (i = 0; i < num_colors; i++) {
+				xc.red = (i & 0xe0) << 8;		   /* highest 3 bits */
+				xc.green = (i & 0x1c) << 11;		/* middle 3 bits */
+				xc.blue = (i & 0x03) << 14;		 /* lowest 2 bits */
+
+				/* find the closest color in the colormap */
+				double distance, distance_squared, min_distance = 0;
+				for (int ii = 0; ii < num_colors; ii++) {
+					distance = colors[ii].red - xc.red;
+					distance_squared = distance * distance;
+					distance = colors[ii].green - xc.green;
+					distance_squared += distance * distance;
+					distance = colors[ii].blue - xc.blue;
+					distance_squared += distance * distance;
+
+					if ((ii == 0) || (distance_squared <= min_distance)) {
+						min_distance = distance_squared;
+						closest_color[i] = ii;
+					}
+				}
+			}
+
+			for (j = 0; j < height; j++) {
+				for (i = 0; i < width; i++) {
+					xc.red = (unsigned short) (rgb_data[ipos++] & 0xe0);
+					xc.green = (unsigned short) (rgb_data[ipos++] & 0xe0);
+					xc.blue = (unsigned short) (rgb_data[ipos++] & 0xc0);
+
+					xc.pixel = xc.red | (xc.green >> 3) | (xc.blue >> 6);
+					XPutPixel(ximage, i, j,
+							  colors[closest_color[xc.pixel]].pixel);
+				}
+			}
+			delete [] colors;
+			delete [] closest_color;
+		}
+		break;
+	case TrueColor: {
+			unsigned char red_left_shift;
+			unsigned char red_right_shift;
+			unsigned char green_left_shift;
+			unsigned char green_right_shift;
+			unsigned char blue_left_shift;
+			unsigned char blue_right_shift;
+
+			computeShift(visual_info->red_mask, red_left_shift,
+						 red_right_shift);
+			computeShift(visual_info->green_mask, green_left_shift,
+						 green_right_shift);
+			computeShift(visual_info->blue_mask, blue_left_shift,
+						 blue_right_shift);
+
+			unsigned long pixel;
+			unsigned long red, green, blue;
+			for (j = 0; j < height; j++) {
+				for (i = 0; i < width; i++) {
+					red = (unsigned long)
+						  rgb_data[ipos++] >> red_right_shift;
+					green = (unsigned long)
+							rgb_data[ipos++] >> green_right_shift;
+					blue = (unsigned long)
+						   rgb_data[ipos++] >> blue_right_shift;
+
+					pixel = (((red << red_left_shift) & visual_info->red_mask)
+							 | ((green << green_left_shift)
+								& visual_info->green_mask)
+							 | ((blue << blue_left_shift)
+								& visual_info->blue_mask));
+
+					XPutPixel(ximage, i, j, pixel);
+				}
+			}
+		}
+		break;
+	default: {
+			logStream << "Login.app: could not load image" << endl;
+			return(tmp);
+		}
+	}
+
+	GC gc = XCreateGC(dpy, win, 0, NULL);
+	XPutImage(dpy, tmp, gc, ximage, 0, 0, 0, 0, width, height);
+
+	XFreeGC(dpy, gc);
+
+	XFree(visual_info);
+
+	delete [] pixmap_data;
+
+	/* Set ximage data to NULL since pixmap data was deallocated above */
+	ximage->data = NULL;
+	XDestroyImage(ximage);
+
+	return(tmp);
 }
 
 int
 Image::readJpeg(const char *filename, int *width, int *height,
-                unsigned char **rgb)
+				unsigned char **rgb)
 {
-    int ret = 0;
-    struct jpeg_decompress_struct cinfo;
-    struct jpeg_error_mgr jerr;
-    unsigned char *ptr = NULL;
-
-    FILE *infile = fopen(filename, "rb");
-    if (infile == NULL) {
-        logStream << APPNAME << "Cannot fopen file: " << filename << endl;
-        return ret;
-    }
-
-    cinfo.err = jpeg_std_error(&jerr);
-    jpeg_create_decompress(&cinfo);
-    jpeg_stdio_src(&cinfo, infile);
-    jpeg_read_header(&cinfo, TRUE);
-    jpeg_start_decompress(&cinfo);
-
-    /* Prevent against integer overflow */
-    if(cinfo.output_width >= MAX_DIMENSION
-       || cinfo.output_height >= MAX_DIMENSION)
-    {
-        logStream << APPNAME << "Unreasonable dimension found in file: "
-                  << filename << endl;
-        goto close_file;
-    }
-
-    *width = cinfo.output_width;
-    *height = cinfo.output_height;
-
-    rgb[0] = (unsigned char*)
-                malloc(3 * cinfo.output_width * cinfo.output_height);
-    if (rgb[0] == NULL) {
-        logStream << APPNAME << ": Can't allocate memory for JPEG file."
-                  << endl;
-        goto close_file;
-    }
-
-    if (cinfo.output_components == 3) {
-        ptr = rgb[0];
-        while (cinfo.output_scanline < cinfo.output_height) {
-            jpeg_read_scanlines(&cinfo, &ptr, 1);
-            ptr += 3 * cinfo.output_width;
-        }
-    } else if (cinfo.output_components == 1) {
-        ptr = (unsigned char*) malloc(cinfo.output_width);
-        if (ptr == NULL) {
-            logStream << APPNAME << ": Can't allocate memory for JPEG file."
-                      << endl;
-            goto rgb_free;
-        }
-
-        unsigned int ipos = 0;
-        while (cinfo.output_scanline < cinfo.output_height) {
-            jpeg_read_scanlines(&cinfo, &ptr, 1);
-
-            for (unsigned int i = 0; i < cinfo.output_width; i++) {
-                memset(rgb[0] + ipos, ptr[i], 3);
-                ipos += 3;
-            }
-        }
-
-        free(ptr);
-    }
-
-    jpeg_finish_decompress(&cinfo);
-
-    ret = 1;
-    goto close_file;
+	int ret = 0;
+	struct jpeg_decompress_struct cinfo;
+	struct jpeg_error_mgr jerr;
+	unsigned char *ptr = NULL;
+
+	FILE *infile = fopen(filename, "rb");
+	if (infile == NULL) {
+		logStream << APPNAME << "Cannot fopen file: " << filename << endl;
+		return ret;
+	}
+
+	cinfo.err = jpeg_std_error(&jerr);
+	jpeg_create_decompress(&cinfo);
+	jpeg_stdio_src(&cinfo, infile);
+	jpeg_read_header(&cinfo, TRUE);
+	jpeg_start_decompress(&cinfo);
+
+	/* Prevent against integer overflow */
+	if(cinfo.output_width >= MAX_DIMENSION
+	   || cinfo.output_height >= MAX_DIMENSION)
+	{
+		logStream << APPNAME << "Unreasonable dimension found in file: "
+				  << filename << endl;
+		goto close_file;
+	}
+
+	*width = cinfo.output_width;
+	*height = cinfo.output_height;
+
+	rgb[0] = (unsigned char*)
+				malloc(3 * cinfo.output_width * cinfo.output_height);
+	if (rgb[0] == NULL) {
+		logStream << APPNAME << ": Can't allocate memory for JPEG file."
+				  << endl;
+		goto close_file;
+	}
+
+	if (cinfo.output_components == 3) {
+		ptr = rgb[0];
+		while (cinfo.output_scanline < cinfo.output_height) {
+			jpeg_read_scanlines(&cinfo, &ptr, 1);
+			ptr += 3 * cinfo.output_width;
+		}
+	} else if (cinfo.output_components == 1) {
+		ptr = (unsigned char*) malloc(cinfo.output_width);
+		if (ptr == NULL) {
+			logStream << APPNAME << ": Can't allocate memory for JPEG file."
+					  << endl;
+			goto rgb_free;
+		}
+
+		unsigned int ipos = 0;
+		while (cinfo.output_scanline < cinfo.output_height) {
+			jpeg_read_scanlines(&cinfo, &ptr, 1);
+
+			for (unsigned int i = 0; i < cinfo.output_width; i++) {
+				memset(rgb[0] + ipos, ptr[i], 3);
+				ipos += 3;
+			}
+		}
+
+		free(ptr);
+	}
+
+	jpeg_finish_decompress(&cinfo);
+
+	ret = 1;
+	goto close_file;
 
 rgb_free:
-    free(rgb[0]);
+	free(rgb[0]);
 
 close_file:
-    jpeg_destroy_decompress(&cinfo);
-    fclose(infile);
+	jpeg_destroy_decompress(&cinfo);
+	fclose(infile);
 
-    return(ret);
+	return(ret);
 }
 
 int
 Image::readPng(const char *filename, int *width, int *height,
-               unsigned char **rgb, unsigned char **alpha)
+			   unsigned char **rgb, unsigned char **alpha)
 {
-    int ret = 0;
-
-    png_structp png_ptr;
-    png_infop info_ptr;
-    png_bytepp row_pointers;
-
-    unsigned char *ptr = NULL;
-    png_uint_32 w, h;
-    int bit_depth, color_type, interlace_type;
-    int i;
-
-    FILE *infile = fopen(filename, "rb");
-    if (infile == NULL) {
-        logStream << APPNAME << "Can not fopen file: " << filename << endl;
-        return ret;
-    }
-
-    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
-                                     (png_voidp) NULL,
-                                     (png_error_ptr) NULL,
-                                     (png_error_ptr) NULL);
-    if (!png_ptr) {
-        goto file_close;
-    }
-
-    info_ptr = png_create_info_struct(png_ptr);
-    if (!info_ptr) {
-        png_destroy_read_struct(&png_ptr, (png_infopp) NULL,
-                                (png_infopp) NULL);
-    }
-
-    if (setjmp(png_ptr->jmpbuf)) {
-        goto png_destroy;
-    }
-
-    png_init_io(png_ptr, infile);
-    png_read_info(png_ptr, info_ptr);
-
-    png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
-                 &interlace_type, (int *) NULL, (int *) NULL);
-
-    /* Prevent against integer overflow */
-    if(w >= MAX_DIMENSION || h >= MAX_DIMENSION) {
-        logStream << APPNAME << "Unreasonable dimension found in file: "
-                  << filename << endl;
-        goto png_destroy;
-    }
-
-    *width = (int) w;
-    *height = (int) h;
-
-    if (color_type == PNG_COLOR_TYPE_RGB_ALPHA
-        || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-    {
-        alpha[0] = (unsigned char *) malloc(*width * *height);
-        if (alpha[0] == NULL) {
-            logStream << APPNAME
-                    << ": Can't allocate memory for alpha channel in PNG file."
-                    << endl;
-            goto png_destroy;
-        }
-    }
-
-    /* Change a paletted/grayscale image to RGB */
-    if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
-    {
-        png_set_expand(png_ptr);
-    }
-
-    /* Change a grayscale image to RGB */
-    if (color_type == PNG_COLOR_TYPE_GRAY
-        || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-    {
-        png_set_gray_to_rgb(png_ptr);
-    }
-
-    /* If the PNG file has 16 bits per channel, strip them down to 8 */
-    if (bit_depth == 16) {
-      png_set_strip_16(png_ptr);
-    }
-
-    /* use 1 byte per pixel */
-    png_set_packing(png_ptr);
-
-    row_pointers = (png_byte **) malloc(*height * sizeof(png_bytep));
-    if (row_pointers == NULL) {
-        logStream << APPNAME << ": Can't allocate memory for PNG file." << endl;
-        goto png_destroy;
-    }
-
-    for (i = 0; i < *height; i++) {
-        row_pointers[i] = (png_byte*) malloc(4 * *width);
-        if (row_pointers == NULL) {
-            logStream << APPNAME << ": Can't allocate memory for PNG file."
-                      << endl;
-            goto rows_free;
-        }
-    }
-
-    png_read_image(png_ptr, row_pointers);
-
-    rgb[0] = (unsigned char *) malloc(3 * (*width) * (*height));
-    if (rgb[0] == NULL) {
-        logStream << APPNAME << ": Can't allocate memory for PNG file." << endl;
-        goto rows_free;
-    }
-
-    if (alpha[0] == NULL) {
-        ptr = rgb[0];
-        for (i = 0; i < *height; i++) {
-            memcpy(ptr, row_pointers[i], 3 * (*width));
-            ptr += 3 * (*width);
-        }
-    } else {
-        ptr = rgb[0];
-        for (i = 0; i < *height; i++) {
-            unsigned int ipos = 0;
-            for (int j = 0; j < *width; j++) {
-                *ptr++ = row_pointers[i][ipos++];
-                *ptr++ = row_pointers[i][ipos++];
-                *ptr++ = row_pointers[i][ipos++];
-                alpha[0][i * (*width) + j] = row_pointers[i][ipos++];
-            }
-        }
-    }
-
-    ret = 1; /* data reading is OK */
+	int ret = 0;
+
+	png_structp png_ptr;
+	png_infop info_ptr;
+	png_bytepp row_pointers;
+
+	unsigned char *ptr = NULL;
+	png_uint_32 w, h;
+	int bit_depth, color_type, interlace_type;
+	int i;
+
+	FILE *infile = fopen(filename, "rb");
+	if (infile == NULL) {
+		logStream << APPNAME << "Can not fopen file: " << filename << endl;
+		return ret;
+	}
+
+	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+									 (png_voidp) NULL,
+									 (png_error_ptr) NULL,
+									 (png_error_ptr) NULL);
+	if (!png_ptr) {
+		goto file_close;
+	}
+
+	info_ptr = png_create_info_struct(png_ptr);
+	if (!info_ptr) {
+		png_destroy_read_struct(&png_ptr, (png_infopp) NULL,
+								(png_infopp) NULL);
+	}
+
+	if (setjmp(png_ptr->jmpbuf)) {
+		goto png_destroy;
+	}
+
+	png_init_io(png_ptr, infile);
+	png_read_info(png_ptr, info_ptr);
+
+	png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
+				 &interlace_type, (int *) NULL, (int *) NULL);
+
+	/* Prevent against integer overflow */
+	if(w >= MAX_DIMENSION || h >= MAX_DIMENSION) {
+		logStream << APPNAME << "Unreasonable dimension found in file: "
+				  << filename << endl;
+		goto png_destroy;
+	}
+
+	*width = (int) w;
+	*height = (int) h;
+
+	if (color_type == PNG_COLOR_TYPE_RGB_ALPHA
+		|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+	{
+		alpha[0] = (unsigned char *) malloc(*width * *height);
+		if (alpha[0] == NULL) {
+			logStream << APPNAME
+					<< ": Can't allocate memory for alpha channel in PNG file."
+					<< endl;
+			goto png_destroy;
+		}
+	}
+
+	/* Change a paletted/grayscale image to RGB */
+	if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
+	{
+		png_set_expand(png_ptr);
+	}
+
+	/* Change a grayscale image to RGB */
+	if (color_type == PNG_COLOR_TYPE_GRAY
+		|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+	{
+		png_set_gray_to_rgb(png_ptr);
+	}
+
+	/* If the PNG file has 16 bits per channel, strip them down to 8 */
+	if (bit_depth == 16) {
+	  png_set_strip_16(png_ptr);
+	}
+
+	/* use 1 byte per pixel */
+	png_set_packing(png_ptr);
+
+	row_pointers = (png_byte **) malloc(*height * sizeof(png_bytep));
+	if (row_pointers == NULL) {
+		logStream << APPNAME << ": Can't allocate memory for PNG file." << endl;
+		goto png_destroy;
+	}
+
+	for (i = 0; i < *height; i++) {
+		row_pointers[i] = (png_byte*) malloc(4 * *width);
+		if (row_pointers == NULL) {
+			logStream << APPNAME << ": Can't allocate memory for PNG file."
+					  << endl;
+			goto rows_free;
+		}
+	}
+
+	png_read_image(png_ptr, row_pointers);
+
+	rgb[0] = (unsigned char *) malloc(3 * (*width) * (*height));
+	if (rgb[0] == NULL) {
+		logStream << APPNAME << ": Can't allocate memory for PNG file." << endl;
+		goto rows_free;
+	}
+
+	if (alpha[0] == NULL) {
+		ptr = rgb[0];
+		for (i = 0; i < *height; i++) {
+			memcpy(ptr, row_pointers[i], 3 * (*width));
+			ptr += 3 * (*width);
+		}
+	} else {
+		ptr = rgb[0];
+		for (i = 0; i < *height; i++) {
+			unsigned int ipos = 0;
+			for (int j = 0; j < *width; j++) {
+				*ptr++ = row_pointers[i][ipos++];
+				*ptr++ = row_pointers[i][ipos++];
+				*ptr++ = row_pointers[i][ipos++];
+				alpha[0][i * (*width) + j] = row_pointers[i][ipos++];
+			}
+		}
+	}
+
+	ret = 1; /* data reading is OK */
 
 rows_free:
-    for (i = 0; i < *height; i++) {
-        if (row_pointers[i] != NULL ) {
-            free(row_pointers[i]);
-        }
-    }
+	for (i = 0; i < *height; i++) {
+		if (row_pointers[i] != NULL ) {
+			free(row_pointers[i]);
+		}
+	}
 
-    free(row_pointers);
+	free(row_pointers);
 
 png_destroy:
-    png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
+	png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
 
 file_close:
-    fclose(infile);
-    return(ret);
+	fclose(infile);
+	return(ret);
 }

+ 45 - 45
image.h

@@ -1,8 +1,8 @@
 /* SLiM - Simple Login Manager
    Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
    Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
-   Copyright (C) 2012    Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
-      
+   Copyright (C) 2012	Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
+	  
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
@@ -21,59 +21,59 @@
 
 class Image {
 public:
-    Image();
-    Image(const int w, const int h, const unsigned char *rgb,
-          const unsigned char *alpha);
+	Image();
+	Image(const int w, const int h, const unsigned char *rgb,
+		  const unsigned char *alpha);
 
-    ~Image();
+	~Image();
 
-    const unsigned char * getPNGAlpha() const {
-        return(png_alpha);
-    };
-    const unsigned char * getRGBData() const {
-        return(rgb_data);
-    };
+	const unsigned char * getPNGAlpha() const {
+		return(png_alpha);
+	};
+	const unsigned char * getRGBData() const {
+		return(rgb_data);
+	};
 
-    void getPixel(double px, double py, unsigned char *pixel);
-    void getPixel(double px, double py, unsigned char *pixel,
-                  unsigned char *alpha);
+	void getPixel(double px, double py, unsigned char *pixel);
+	void getPixel(double px, double py, unsigned char *pixel,
+				  unsigned char *alpha);
 
-    int Width() const  {
-        return(width);
-    };
-    int Height() const {
-        return(height);
-    };
-    void Quality(const int q) {
-        quality_ = q;
-    };
+	int Width() const  {
+		return(width);
+	};
+	int Height() const {
+		return(height);
+	};
+	void Quality(const int q) {
+		quality_ = q;
+	};
 
-    bool Read(const char *filename);
+	bool Read(const char *filename);
 
-    void Reduce(const int factor);
-    void Resize(const int w, const int h);
-    void Merge(Image* background, const int x, const int y);
-    void Crop(const int x, const int y, const int w, const int h);
-    void Tile(const int w, const int h);
-    void Center(const int w, const int h, const char *hex);
-    void Plain(const int w, const int h, const char *hex);
-    
-    void computeShift(unsigned long mask, unsigned char &left_shift,
-                      unsigned char &right_shift);
+	void Reduce(const int factor);
+	void Resize(const int w, const int h);
+	void Merge(Image* background, const int x, const int y);
+	void Crop(const int x, const int y, const int w, const int h);
+	void Tile(const int w, const int h);
+	void Center(const int w, const int h, const char *hex);
+	void Plain(const int w, const int h, const char *hex);
+	
+	void computeShift(unsigned long mask, unsigned char &left_shift,
+					  unsigned char &right_shift);
 
-    Pixmap createPixmap(Display* dpy, int scr, Window win);
+	Pixmap createPixmap(Display* dpy, int scr, Window win);
 
 private:
-    int width, height, area;
-    unsigned char *rgb_data;
-    unsigned char *png_alpha;
+	int width, height, area;
+	unsigned char *rgb_data;
+	unsigned char *png_alpha;
 
-    int quality_;
+	int quality_;
 
-    int readJpeg(const char *filename, int *width, int *height,
-        unsigned char **rgb);
-    int readPng(const char *filename, int *width, int *height,
-        unsigned char **rgb, unsigned char **alpha);
+	int readJpeg(const char *filename, int *width, int *height,
+		unsigned char **rgb);
+	int readPng(const char *filename, int *width, int *height,
+		unsigned char **rgb, unsigned char **alpha);
 };
 
-#endif
+#endif /* _IMAGE_H_ */

+ 83 - 83
jpeg.c

@@ -1,20 +1,20 @@
 /****************************************************************************
-    jpeg.c - read and write jpeg images using libjpeg routines
-    Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+	jpeg.c - read and write jpeg images using libjpeg routines
+	Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 2 of the License, or
+	(at your option) any later version.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, write to the Free Software
+	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ****************************************************************************/
 
 #include <stdio.h>
@@ -27,76 +27,76 @@
 int
 read_jpeg(const char *filename, int *width, int *height, unsigned char **rgb)
 {
-    int ret = 0;
-    struct jpeg_decompress_struct cinfo;
-    struct jpeg_error_mgr jerr;
-    unsigned char *ptr = NULL;
-    unsigned int i, ipos;
-
-    FILE *infile = fopen(filename, "rb");
-    if (infile == NULL) {
-        fprintf(stderr, "Can not fopen file: %s\n",filename);
-        return ret;
-    }
-
-    cinfo.err = jpeg_std_error(&jerr);
-    jpeg_create_decompress(&cinfo);
-    jpeg_stdio_src(&cinfo, infile);
-    jpeg_read_header(&cinfo, TRUE);
-    jpeg_start_decompress(&cinfo);
-
-    /* Prevent against integer overflow */
-    if(cinfo.output_width >= MAX_DIMENSION || cinfo.output_height >= MAX_DIMENSION) {
-        fprintf(stderr, "Unreasonable dimension found in file: %s\n",filename);
-        goto close_file;
-    }
-
-    *width = cinfo.output_width;
-    *height = cinfo.output_height;
-
-    rgb[0] = malloc(3 * cinfo.output_width * cinfo.output_height);
-    if (rgb[0] == NULL) {
-        fprintf(stderr, "Can't allocate memory for JPEG file.\n");
-        goto close_file;
-    }
-
-    if (cinfo.output_components == 3) {
-        ptr = rgb[0];
-        while (cinfo.output_scanline < cinfo.output_height) {
-            jpeg_read_scanlines(&cinfo, &ptr, 1);
-            ptr += 3 * cinfo.output_width;
-        }
-    } else if (cinfo.output_components == 1) {
-        ptr = malloc(cinfo.output_width);
-        if (ptr == NULL) {
-            fprintf(stderr, "Can't allocate memory for JPEG file.\n");
-            goto rgb_free;
-        }
-
-        ipos = 0;
-        while (cinfo.output_scanline < cinfo.output_height) {
-            jpeg_read_scanlines(&cinfo, &ptr, 1);
-
-            for (i = 0; i < cinfo.output_width; i++) {
-                memset(rgb[0] + ipos, ptr[i], 3);
-                ipos += 3;
-            }
-        }
-
-        free(ptr);
-    }
-
-    jpeg_finish_decompress(&cinfo);
-
-    ret = 1;
-    goto close_file;
+	int ret = 0;
+	struct jpeg_decompress_struct cinfo;
+	struct jpeg_error_mgr jerr;
+	unsigned char *ptr = NULL;
+	unsigned int i, ipos;
+
+	FILE *infile = fopen(filename, "rb");
+	if (infile == NULL) {
+		fprintf(stderr, "Can not fopen file: %s\n",filename);
+		return ret;
+	}
+
+	cinfo.err = jpeg_std_error(&jerr);
+	jpeg_create_decompress(&cinfo);
+	jpeg_stdio_src(&cinfo, infile);
+	jpeg_read_header(&cinfo, TRUE);
+	jpeg_start_decompress(&cinfo);
+
+	/* Prevent against integer overflow */
+	if(cinfo.output_width >= MAX_DIMENSION || cinfo.output_height >= MAX_DIMENSION) {
+		fprintf(stderr, "Unreasonable dimension found in file: %s\n",filename);
+		goto close_file;
+	}
+
+	*width = cinfo.output_width;
+	*height = cinfo.output_height;
+
+	rgb[0] = malloc(3 * cinfo.output_width * cinfo.output_height);
+	if (rgb[0] == NULL) {
+		fprintf(stderr, "Can't allocate memory for JPEG file.\n");
+		goto close_file;
+	}
+
+	if (cinfo.output_components == 3) {
+		ptr = rgb[0];
+		while (cinfo.output_scanline < cinfo.output_height) {
+			jpeg_read_scanlines(&cinfo, &ptr, 1);
+			ptr += 3 * cinfo.output_width;
+		}
+	} else if (cinfo.output_components == 1) {
+		ptr = malloc(cinfo.output_width);
+		if (ptr == NULL) {
+			fprintf(stderr, "Can't allocate memory for JPEG file.\n");
+			goto rgb_free;
+		}
+
+		ipos = 0;
+		while (cinfo.output_scanline < cinfo.output_height) {
+			jpeg_read_scanlines(&cinfo, &ptr, 1);
+
+			for (i = 0; i < cinfo.output_width; i++) {
+				memset(rgb[0] + ipos, ptr[i], 3);
+				ipos += 3;
+			}
+		}
+
+		free(ptr);
+	}
+
+	jpeg_finish_decompress(&cinfo);
+
+	ret = 1;
+	goto close_file;
 
 rgb_free:
-    free(rgb[0]);
+	free(rgb[0]);
 
 close_file:
-    jpeg_destroy_decompress(&cinfo);
-    fclose(infile);
+	jpeg_destroy_decompress(&cinfo);
+	fclose(infile);
 
-    return(ret);
+	return(ret);
 }

+ 22 - 22
log.h

@@ -7,28 +7,28 @@
 using namespace std;
 
 static class LogUnit {
-    ofstream logFile;
+	ofstream logFile;
 public:
-    bool openLog(const char * filename);
-    void closeLog();
-
-    ~LogUnit() { closeLog(); }
-
-    template<typename Type>
-    LogUnit & operator<<(const Type & text) {
-        logFile << text; logFile.flush();
-        return *this;
-    }
-
-    LogUnit & operator<<(ostream & (*fp)(ostream&)) {
-        logFile << fp; logFile.flush();
-        return *this;
-    }
-
-    LogUnit & operator<<(ios_base & (*fp)(ios_base&)) {
-        logFile << fp; logFile.flush();
-        return *this;
-    }
+	bool openLog(const char * filename);
+	void closeLog();
+
+	~LogUnit() { closeLog(); }
+
+	template<typename Type>
+	LogUnit & operator<<(const Type & text) {
+		logFile << text; logFile.flush();
+		return *this;
+	}
+
+	LogUnit & operator<<(ostream & (*fp)(ostream&)) {
+		logFile << fp; logFile.flush();
+		return *this;
+	}
+
+	LogUnit & operator<<(ios_base & (*fp)(ios_base&)) {
+		logFile << fp; logFile.flush();
+		return *this;
+	}
 } logStream;
 
-#endif
+#endif /* _LOG_H_ */

+ 6 - 5
main.cpp

@@ -2,7 +2,7 @@
    Copyright (C) 1997, 1998 Per Liden
    Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
    Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
-      
+	  
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
@@ -14,9 +14,10 @@
 
 App* LoginApp = 0;
 
-int main(int argc, char** argv) {
-    LoginApp = new App(argc, argv);
-    LoginApp->Run();
-    return 0;
+int main(int argc, char** argv)
+{
+	LoginApp = new App(argc, argv);
+	LoginApp->Run();
+	return 0;
 }
 

+ 42 - 42
numlock.cpp

@@ -1,7 +1,7 @@
 /* SLiM - Simple Login Manager
    Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
    Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
-   Copyright (C) 2012    Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
+   Copyright (C) 2012	Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,57 +20,57 @@ NumLock::NumLock() {
 }
 
 int NumLock::xkb_init(Display* dpy) {
-    int xkb_opcode, xkb_event, xkb_error;
-    int xkb_lmaj = XkbMajorVersion;
-    int xkb_lmin = XkbMinorVersion;
+	int xkb_opcode, xkb_event, xkb_error;
+	int xkb_lmaj = XkbMajorVersion;
+	int xkb_lmin = XkbMinorVersion;
 
-    return XkbLibraryVersion( &xkb_lmaj, &xkb_lmin )
-        && XkbQueryExtension( dpy, &xkb_opcode, &xkb_event, &xkb_error,
-                   &xkb_lmaj, &xkb_lmin );
+	return XkbLibraryVersion( &xkb_lmaj, &xkb_lmin )
+		&& XkbQueryExtension( dpy, &xkb_opcode, &xkb_event, &xkb_error,
+				   &xkb_lmaj, &xkb_lmin );
 }
-    
+	
 unsigned int NumLock::xkb_mask_modifier( XkbDescPtr xkb, const char *name ) {
-    int i;
-    if( !xkb || !xkb->names )
-        return 0;
-
-    for( i = 0; i < XkbNumVirtualMods; i++ ) {
-        char* modStr = XGetAtomName( xkb->dpy, xkb->names->vmods[i] );
-        if( modStr != NULL && strcmp(name, modStr) == 0 ) {
-            unsigned int mask;
-            XkbVirtualModsToReal( xkb, 1 << i, &mask );
-            return mask;
-        }
-    }
-    return 0;
+	int i;
+	if( !xkb || !xkb->names )
+		return 0;
+
+	for( i = 0; i < XkbNumVirtualMods; i++ ) {
+		char* modStr = XGetAtomName( xkb->dpy, xkb->names->vmods[i] );
+		if( modStr != NULL && strcmp(name, modStr) == 0 ) {
+			unsigned int mask;
+			XkbVirtualModsToReal( xkb, 1 << i, &mask );
+			return mask;
+		}
+	}
+	return 0;
 }
 
 unsigned int NumLock::xkb_numlock_mask(Display* dpy) {
-    XkbDescPtr xkb;
-
-    xkb = XkbGetKeyboard( dpy, XkbAllComponentsMask, XkbUseCoreKbd );
-    if( xkb != NULL ) {
-        unsigned int mask = xkb_mask_modifier( xkb, "NumLock" );
-        XkbFreeKeyboard( xkb, 0, True );
-        return mask;
-    }
-    return 0;
+	XkbDescPtr xkb;
+
+	xkb = XkbGetKeyboard( dpy, XkbAllComponentsMask, XkbUseCoreKbd );
+	if( xkb != NULL ) {
+		unsigned int mask = xkb_mask_modifier( xkb, "NumLock" );
+		XkbFreeKeyboard( xkb, 0, True );
+		return mask;
+	}
+	return 0;
 }
 
 void NumLock::control_numlock(Display *dpy, bool flag) {
-    unsigned int mask;
-    
+	unsigned int mask;
+	
 	if( !xkb_init(dpy) )
-        return;
+		return;
 
-    mask = xkb_numlock_mask(dpy);
-    if( mask == 0 )
-        return;
+	mask = xkb_numlock_mask(dpy);
+	if( mask == 0 )
+		return;
 
-    if( flag == true )
-        XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, mask);
-    else
-        XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, 0);
+	if( flag == true )
+		XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, mask);
+	else
+		XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, 0);
 }
 
 void NumLock::setOn(Display *dpy) {
@@ -82,8 +82,8 @@ void NumLock::setOff(Display *dpy) {
 }
 
 /* 
- Copyright (C) 2000-2001 Lubos Lunak        <l.lunak@kde.org>
- Copyright (C) 2001      Oswald Buddenhagen <ossi@kde.org>
+ Copyright (C) 2000-2001 Lubos Lunak		<l.lunak@kde.org>
+ Copyright (C) 2001	  Oswald Buddenhagen <ossi@kde.org>
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),

+ 1 - 1
numlock.h

@@ -30,4 +30,4 @@ private:
     static void control_numlock(Display *dpy, bool flag);
 };
 
-#endif
+#endif /* _NUMLOCK_H_ */

+ 535 - 535
panel.cpp

@@ -16,627 +16,627 @@
 using namespace std;
 
 Panel::Panel(Display* dpy, int scr, Window root, Cfg* config,
-             const string& themedir) {
-    // Set display
-    Dpy = dpy;
-    Scr = scr;
-    Root = root;
-    cfg = config;
-
-    session = "";
-
-    // Init GC
-    XGCValues gcv;
-    unsigned long gcm;
-    gcm = GCForeground|GCBackground|GCGraphicsExposures;
-    gcv.foreground = GetColor("black");
-    gcv.background = GetColor("white");
-    gcv.graphics_exposures = False;
-    TextGC = XCreateGC(Dpy, Root, gcm, &gcv);
-
-    font = XftFontOpenName(Dpy, Scr, cfg->getOption("input_font").c_str());
-    welcomefont = XftFontOpenName(Dpy, Scr, cfg->getOption("welcome_font").c_str());
-    introfont = XftFontOpenName(Dpy, Scr, cfg->getOption("intro_font").c_str());
-    enterfont = XftFontOpenName(Dpy, Scr, cfg->getOption("username_font").c_str());
-    msgfont = XftFontOpenName(Dpy, Scr, cfg->getOption("msg_font").c_str());
-
-    Visual* visual = DefaultVisual(Dpy, Scr);
-    Colormap colormap = DefaultColormap(Dpy, Scr);
-    // NOTE: using XftColorAllocValue() would be a better solution. Lazy me.
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("input_color").c_str(), &inputcolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("input_shadow_color").c_str(), &inputshadowcolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("welcome_color").c_str(), &welcomecolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("welcome_shadow_color").c_str(), &welcomeshadowcolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("username_color").c_str(), &entercolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("username_shadow_color").c_str(), &entershadowcolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("msg_color").c_str(), &msgcolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("msg_shadow_color").c_str(), &msgshadowcolor);
-    XftColorAllocName(Dpy, visual, colormap, cfg->getOption("intro_color").c_str(), &introcolor);
-    XftColorAllocName(Dpy, DefaultVisual(Dpy, Scr), colormap,
-                      cfg->getOption("session_color").c_str(), &sessioncolor);
-    XftColorAllocName(Dpy, DefaultVisual(Dpy, Scr), colormap,
-                      cfg->getOption("session_shadow_color").c_str(), &sessionshadowcolor);
-
-    // Load properties from config / theme
-    input_name_x = cfg->getIntOption("input_name_x");
-    input_name_y = cfg->getIntOption("input_name_y");
-    input_pass_x = cfg->getIntOption("input_pass_x");
-    input_pass_y = cfg->getIntOption("input_pass_y");
-    inputShadowXOffset = cfg->getIntOption("input_shadow_xoffset");
-    inputShadowYOffset = cfg->getIntOption("input_shadow_yoffset");
-
-    if (input_pass_x < 0 || input_pass_y < 0){ // single inputbox mode
-        input_pass_x = input_name_x;
-        input_pass_y = input_name_y;
-    }
-
-    // Load panel and background image
-    string panelpng = "";
-    panelpng = panelpng + themedir +"/panel.png";
-    image = new Image;
-    bool loaded = image->Read(panelpng.c_str());
-    if (!loaded) { // try jpeg if png failed
-        panelpng = themedir + "/panel.jpg";
-        loaded = image->Read(panelpng.c_str());
-        if (!loaded) {
-            logStream << APPNAME
-                 << ": could not load panel image for theme '"
-                 << basename((char*)themedir.c_str()) << "'"
-                 << endl;
-            exit(ERR_EXIT);
-        }
-    }
-
-    Image* bg = new Image();
-    string bgstyle = cfg->getOption("background_style");
-    if (bgstyle != "color") {
-        panelpng = themedir +"/background.png";
-        loaded = bg->Read(panelpng.c_str());
-        if (!loaded) { // try jpeg if png failed
-            panelpng = themedir + "/background.jpg";
-            loaded = bg->Read(panelpng.c_str());
-            if (!loaded){
-                logStream << APPNAME
-                     << ": could not load background image for theme '"
-                     << basename((char*)themedir.c_str()) << "'"
-                     << endl;
-                exit(ERR_EXIT);
-            }
-        }
-    }
-    if (bgstyle == "stretch") {
-        bg->Resize(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
-    } else if (bgstyle == "tile") {
-        bg->Tile(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
-    } else if (bgstyle == "center") {
-        string hexvalue = cfg->getOption("background_color");
-        hexvalue = hexvalue.substr(1,6);
-        bg->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                   XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                   hexvalue.c_str());
-    } else { // plain color or error
-        string hexvalue = cfg->getOption("background_color");
-        hexvalue = hexvalue.substr(1,6);
-        bg->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                   XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
-                   hexvalue.c_str());
-    }
-
-    string cfgX = cfg->getOption("input_panel_x");
-    string cfgY = cfg->getOption("input_panel_y");
-    X = Cfg::absolutepos(cfgX, XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), image->Width());
-    Y = Cfg::absolutepos(cfgY, XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)), image->Height());
-
-    // Merge image into background
-    image->Merge(bg, X, Y);
-    delete bg;
-    PanelPixmap = image->createPixmap(Dpy, Scr, Root);
-
-    // Read (and substitute vars in) the welcome message
-    welcome_message = cfg->getWelcomeMessage();
-    intro_message = cfg->getOption("intro_msg");
+			 const string& themedir) {
+	/* Set display */
+	Dpy = dpy;
+	Scr = scr;
+	Root = root;
+	cfg = config;
+
+	session = "";
+
+	/* Init GC */
+	XGCValues gcv;
+	unsigned long gcm;
+	gcm = GCForeground|GCBackground|GCGraphicsExposures;
+	gcv.foreground = GetColor("black");
+	gcv.background = GetColor("white");
+	gcv.graphics_exposures = False;
+	TextGC = XCreateGC(Dpy, Root, gcm, &gcv);
+
+	font = XftFontOpenName(Dpy, Scr, cfg->getOption("input_font").c_str());
+	welcomefont = XftFontOpenName(Dpy, Scr, cfg->getOption("welcome_font").c_str());
+	introfont = XftFontOpenName(Dpy, Scr, cfg->getOption("intro_font").c_str());
+	enterfont = XftFontOpenName(Dpy, Scr, cfg->getOption("username_font").c_str());
+	msgfont = XftFontOpenName(Dpy, Scr, cfg->getOption("msg_font").c_str());
+
+	Visual* visual = DefaultVisual(Dpy, Scr);
+	Colormap colormap = DefaultColormap(Dpy, Scr);
+	/* NOTE: using XftColorAllocValue() would be a better solution. Lazy me. */
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("input_color").c_str(), &inputcolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("input_shadow_color").c_str(), &inputshadowcolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("welcome_color").c_str(), &welcomecolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("welcome_shadow_color").c_str(), &welcomeshadowcolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("username_color").c_str(), &entercolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("username_shadow_color").c_str(), &entershadowcolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("msg_color").c_str(), &msgcolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("msg_shadow_color").c_str(), &msgshadowcolor);
+	XftColorAllocName(Dpy, visual, colormap, cfg->getOption("intro_color").c_str(), &introcolor);
+	XftColorAllocName(Dpy, DefaultVisual(Dpy, Scr), colormap,
+					  cfg->getOption("session_color").c_str(), &sessioncolor);
+	XftColorAllocName(Dpy, DefaultVisual(Dpy, Scr), colormap,
+					  cfg->getOption("session_shadow_color").c_str(), &sessionshadowcolor);
+
+	/* Load properties from config / theme */
+	input_name_x = cfg->getIntOption("input_name_x");
+	input_name_y = cfg->getIntOption("input_name_y");
+	input_pass_x = cfg->getIntOption("input_pass_x");
+	input_pass_y = cfg->getIntOption("input_pass_y");
+	inputShadowXOffset = cfg->getIntOption("input_shadow_xoffset");
+	inputShadowYOffset = cfg->getIntOption("input_shadow_yoffset");
+
+	if (input_pass_x < 0 || input_pass_y < 0){ /* single inputbox mode */
+		input_pass_x = input_name_x;
+		input_pass_y = input_name_y;
+	}
+
+	/* Load panel and background image */
+	string panelpng = "";
+	panelpng = panelpng + themedir +"/panel.png";
+	image = new Image;
+	bool loaded = image->Read(panelpng.c_str());
+	if (!loaded) { /* try jpeg if png failed */
+		panelpng = themedir + "/panel.jpg";
+		loaded = image->Read(panelpng.c_str());
+		if (!loaded) {
+			logStream << APPNAME
+				 << ": could not load panel image for theme '"
+				 << basename((char*)themedir.c_str()) << "'"
+				 << endl;
+			exit(ERR_EXIT);
+		}
+	}
+
+	Image* bg = new Image();
+	string bgstyle = cfg->getOption("background_style");
+	if (bgstyle != "color") {
+		panelpng = themedir +"/background.png";
+		loaded = bg->Read(panelpng.c_str());
+		if (!loaded) { /* try jpeg if png failed */
+			panelpng = themedir + "/background.jpg";
+			loaded = bg->Read(panelpng.c_str());
+			if (!loaded){
+				logStream << APPNAME
+					 << ": could not load background image for theme '"
+					 << basename((char*)themedir.c_str()) << "'"
+					 << endl;
+				exit(ERR_EXIT);
+			}
+		}
+	}
+	if (bgstyle == "stretch") {
+		bg->Resize(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+	} else if (bgstyle == "tile") {
+		bg->Tile(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+	} else if (bgstyle == "center") {
+		string hexvalue = cfg->getOption("background_color");
+		hexvalue = hexvalue.substr(1,6);
+		bg->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),
+				   XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
+				   hexvalue.c_str());
+	} else { /* plain color or error */
+		string hexvalue = cfg->getOption("background_color");
+		hexvalue = hexvalue.substr(1,6);
+		bg->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),
+				   XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
+				   hexvalue.c_str());
+	}
+
+	string cfgX = cfg->getOption("input_panel_x");
+	string cfgY = cfg->getOption("input_panel_y");
+	X = Cfg::absolutepos(cfgX, XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), image->Width());
+	Y = Cfg::absolutepos(cfgY, XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)), image->Height());
+
+	/* Merge image into background */
+	image->Merge(bg, X, Y);
+	delete bg;
+	PanelPixmap = image->createPixmap(Dpy, Scr, Root);
+
+	/* Read (and substitute vars in) the welcome message */
+	welcome_message = cfg->getWelcomeMessage();
+	intro_message = cfg->getOption("intro_msg");
 }
 
 Panel::~Panel() {
-    XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &inputcolor);
-    XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &msgcolor);
-    XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &welcomecolor);
-    XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &entercolor);
-    XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &sessioncolor);
-    XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &sessionshadowcolor);
-    XFreeGC(Dpy, TextGC);
-    XftFontClose(Dpy, font);
-    XftFontClose(Dpy, msgfont);
-    XftFontClose(Dpy, introfont);
-    XftFontClose(Dpy, welcomefont);
-    XftFontClose(Dpy, enterfont);
-    delete image;
+	XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &inputcolor);
+	XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &msgcolor);
+	XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &welcomecolor);
+	XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &entercolor);
+	XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &sessioncolor);
+	XftColorFree (Dpy, DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr), &sessionshadowcolor);
+	XFreeGC(Dpy, TextGC);
+	XftFontClose(Dpy, font);
+	XftFontClose(Dpy, msgfont);
+	XftFontClose(Dpy, introfont);
+	XftFontClose(Dpy, welcomefont);
+	XftFontClose(Dpy, enterfont);
+	delete image;
 
 }
 
 void Panel::OpenPanel() {
-    // Create window
-    Win = XCreateSimpleWindow(Dpy, Root, X, Y,
-                              image->Width(),
-                              image->Height(),
-                              0, GetColor("white"), GetColor("white"));
+	/* Create window */
+	Win = XCreateSimpleWindow(Dpy, Root, X, Y,
+							  image->Width(),
+							  image->Height(),
+							  0, GetColor("white"), GetColor("white"));
 
-    // Events
-    XSelectInput(Dpy, Win, ExposureMask | KeyPressMask);
+	/* Events */
+	XSelectInput(Dpy, Win, ExposureMask | KeyPressMask);
 
-    // Set background
-    XSetWindowBackgroundPixmap(Dpy, Win, PanelPixmap);
+	/* Set background */
+	XSetWindowBackgroundPixmap(Dpy, Win, PanelPixmap);
 
-    // Show window
-    XMapWindow(Dpy, Win);
-    XMoveWindow(Dpy, Win, X, Y); // override wm positioning (for tests)
+	/* Show window */
+	XMapWindow(Dpy, Win);
+	XMoveWindow(Dpy, Win, X, Y); /* override wm positioning (for tests) */
 
-    // Grab keyboard
-    XGrabKeyboard(Dpy, Win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
+	/* Grab keyboard */
+	XGrabKeyboard(Dpy, Win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
 
-    XFlush(Dpy);
+	XFlush(Dpy);
 
 }
 
 void Panel::ClosePanel() {
-    XUngrabKeyboard(Dpy, CurrentTime);
-    XUnmapWindow(Dpy, Win);
-    XDestroyWindow(Dpy, Win);
-    XFlush(Dpy);
+	XUngrabKeyboard(Dpy, CurrentTime);
+	XUnmapWindow(Dpy, Win);
+	XDestroyWindow(Dpy, Win);
+	XFlush(Dpy);
 }
 
 void Panel::ClearPanel() {
-    session = "";
-    Reset();
-    XClearWindow(Dpy, Root);
-    XClearWindow(Dpy, Win);
-    Cursor(SHOW);
-    ShowText();
-    XFlush(Dpy);
+	session = "";
+	Reset();
+	XClearWindow(Dpy, Root);
+	XClearWindow(Dpy, Win);
+	Cursor(SHOW);
+	ShowText();
+	XFlush(Dpy);
 }
 
 void Panel::Message(const string& text) {
-    string cfgX, cfgY;
-    XGlyphInfo extents;
-    XftDraw *draw = XftDrawCreate(Dpy, Root,
-                                  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
-    XftTextExtents8(Dpy, msgfont, reinterpret_cast<const XftChar8*>(text.c_str()),
-                    text.length(), &extents);
-    cfgX = cfg->getOption("msg_x");
-    cfgY = cfg->getOption("msg_y");
-    int shadowXOffset = cfg->getIntOption("msg_shadow_xoffset");
-    int shadowYOffset = cfg->getIntOption("msg_shadow_yoffset");
-    int msg_x = Cfg::absolutepos(cfgX, XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.width);
-    int msg_y = Cfg::absolutepos(cfgY, XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.height);
-
-    SlimDrawString8 (draw, &msgcolor, msgfont, msg_x, msg_y,
-                     text,
-                     &msgshadowcolor,
-                     shadowXOffset, shadowYOffset);
-    XFlush(Dpy);
-    XftDrawDestroy(draw);
+	string cfgX, cfgY;
+	XGlyphInfo extents;
+	XftDraw *draw = XftDrawCreate(Dpy, Root,
+								  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
+	XftTextExtents8(Dpy, msgfont, reinterpret_cast<const XftChar8*>(text.c_str()),
+					text.length(), &extents);
+	cfgX = cfg->getOption("msg_x");
+	cfgY = cfg->getOption("msg_y");
+	int shadowXOffset = cfg->getIntOption("msg_shadow_xoffset");
+	int shadowYOffset = cfg->getIntOption("msg_shadow_yoffset");
+	int msg_x = Cfg::absolutepos(cfgX, XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.width);
+	int msg_y = Cfg::absolutepos(cfgY, XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.height);
+
+	SlimDrawString8 (draw, &msgcolor, msgfont, msg_x, msg_y,
+					 text,
+					 &msgshadowcolor,
+					 shadowXOffset, shadowYOffset);
+	XFlush(Dpy);
+	XftDrawDestroy(draw);
 }
 
 void Panel::Error(const string& text) {
-    ClosePanel();
-    Message(text);
-    sleep(ERROR_DURATION);
-    OpenPanel();
-    ClearPanel();
+	ClosePanel();
+	Message(text);
+	sleep(ERROR_DURATION);
+	OpenPanel();
+	ClearPanel();
 }
 
 
 unsigned long Panel::GetColor(const char* colorname) {
-    XColor color;
-    XWindowAttributes attributes;
+	XColor color;
+	XWindowAttributes attributes;
 
-    XGetWindowAttributes(Dpy, Root, &attributes);
-    color.pixel = 0;
+	XGetWindowAttributes(Dpy, Root, &attributes);
+	color.pixel = 0;
 
-    if(!XParseColor(Dpy, attributes.colormap, colorname, &color))
-        logStream << APPNAME << ": can't parse color " << colorname << endl;
-    else if(!XAllocColor(Dpy, attributes.colormap, &color))
-        logStream << APPNAME << ": can't allocate color " << colorname << endl;
+	if(!XParseColor(Dpy, attributes.colormap, colorname, &color))
+		logStream << APPNAME << ": can't parse color " << colorname << endl;
+	else if(!XAllocColor(Dpy, attributes.colormap, &color))
+		logStream << APPNAME << ": can't allocate color " << colorname << endl;
 
-    return color.pixel;
+	return color.pixel;
 }
 
 void Panel::Cursor(int visible) {
-    const char* text;
-    int xx, yy, y2, cheight;
-    const char* txth = "Wj"; // used to get cursor height
-
-    switch(field) {
-        case Get_Passwd:
-            text = HiddenPasswdBuffer.c_str();
-            xx = input_pass_x;
-            yy = input_pass_y;
-            break;
-
-        case Get_Name:
-            text = NameBuffer.c_str();
-            xx = input_name_x;
-            yy = input_name_y;
-            break;
-    }
-
-    XGlyphInfo extents;
-    XftTextExtents8(Dpy, font, (XftChar8*)txth, strlen(txth), &extents);
-    cheight = extents.height;
-    y2 = yy - extents.y + extents.height;
-    XftTextExtents8(Dpy, font, (XftChar8*)text, strlen(text), &extents);
-    xx += extents.width;
-
-    if(visible == SHOW) {
-        XSetForeground(Dpy, TextGC,
-                       GetColor(cfg->getOption("input_color").c_str()));
-        XDrawLine(Dpy, Win, TextGC,
-                  xx+1, yy-cheight,
-                  xx+1, y2);
-    } else {
-        XClearArea(Dpy, Win, xx+1, yy-cheight,
-                   1, y2-(yy-cheight)+1, false);
-    }
+	const char* text;
+	int xx, yy, y2, cheight;
+	const char* txth = "Wj"; /* used to get cursor height */
+
+	switch(field) {
+		case Get_Passwd:
+			text = HiddenPasswdBuffer.c_str();
+			xx = input_pass_x;
+			yy = input_pass_y;
+			break;
+
+		case Get_Name:
+			text = NameBuffer.c_str();
+			xx = input_name_x;
+			yy = input_name_y;
+			break;
+	}
+
+	XGlyphInfo extents;
+	XftTextExtents8(Dpy, font, (XftChar8*)txth, strlen(txth), &extents);
+	cheight = extents.height;
+	y2 = yy - extents.y + extents.height;
+	XftTextExtents8(Dpy, font, (XftChar8*)text, strlen(text), &extents);
+	xx += extents.width;
+
+	if(visible == SHOW) {
+		XSetForeground(Dpy, TextGC,
+					   GetColor(cfg->getOption("input_color").c_str()));
+		XDrawLine(Dpy, Win, TextGC,
+				  xx+1, yy-cheight,
+				  xx+1, y2);
+	} else {
+		XClearArea(Dpy, Win, xx+1, yy-cheight,
+				   1, y2-(yy-cheight)+1, false);
+	}
 }
 
 void Panel::EventHandler(const Panel::FieldType& curfield) {
-    XEvent event;
-    field=curfield;
-    bool loop = true;
-    OnExpose();
-
-    struct pollfd x11_pfd = {0};
-    x11_pfd.fd = ConnectionNumber(Dpy);
-    x11_pfd.events = POLLIN;
-    while(loop) {
-        if(XPending(Dpy) || poll(&x11_pfd, 1, -1) > 0) {
-            while(XPending(Dpy)) {
-                XNextEvent(Dpy, &event);
-                switch(event.type) {
-                    case Expose:
-                        OnExpose();
-                        break;
-
-                    case KeyPress:
-                        loop=OnKeyPress(event);
-                        break;
-                }
-            }
-        }
-    }
-
-    return;
+	XEvent event;
+	field=curfield;
+	bool loop = true;
+	OnExpose();
+
+	struct pollfd x11_pfd = {0};
+	x11_pfd.fd = ConnectionNumber(Dpy);
+	x11_pfd.events = POLLIN;
+	while(loop) {
+		if(XPending(Dpy) || poll(&x11_pfd, 1, -1) > 0) {
+			while(XPending(Dpy)) {
+				XNextEvent(Dpy, &event);
+				switch(event.type) {
+					case Expose:
+						OnExpose();
+						break;
+
+					case KeyPress:
+						loop=OnKeyPress(event);
+						break;
+				}
+			}
+		}
+	}
+
+	return;
 }
 
 void Panel::OnExpose(void) {
-    XftDraw *draw = XftDrawCreate(Dpy, Win,
-                        DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
-    XClearWindow(Dpy, Win);
-    if (input_pass_x != input_name_x || input_pass_y != input_name_y){
-        SlimDrawString8 (draw, &inputcolor, font, input_name_x, input_name_y,
-                         NameBuffer,
-                         &inputshadowcolor,
-                         inputShadowXOffset, inputShadowYOffset);
-        SlimDrawString8 (draw, &inputcolor, font, input_pass_x, input_pass_y,
-                         HiddenPasswdBuffer,
-                         &inputshadowcolor,
-                         inputShadowXOffset, inputShadowYOffset);
-    } else { //single input mode
-        switch(field) {
-            case Get_Passwd:
-                SlimDrawString8 (draw, &inputcolor, font,
-                                 input_pass_x, input_pass_y,
-                                 HiddenPasswdBuffer,
-                                 &inputshadowcolor,
-                                 inputShadowXOffset, inputShadowYOffset);
-                break;
-            case Get_Name:
-                SlimDrawString8 (draw, &inputcolor, font,
-                                 input_name_x, input_name_y,
-                                 NameBuffer,
-                                 &inputshadowcolor,
-                                 inputShadowXOffset, inputShadowYOffset);
-                break;
-        }
-    }
-
-    XftDrawDestroy (draw);
-    Cursor(SHOW);
-    ShowText();
+	XftDraw *draw = XftDrawCreate(Dpy, Win,
+						DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
+	XClearWindow(Dpy, Win);
+	if (input_pass_x != input_name_x || input_pass_y != input_name_y){
+		SlimDrawString8 (draw, &inputcolor, font, input_name_x, input_name_y,
+						 NameBuffer,
+						 &inputshadowcolor,
+						 inputShadowXOffset, inputShadowYOffset);
+		SlimDrawString8 (draw, &inputcolor, font, input_pass_x, input_pass_y,
+						 HiddenPasswdBuffer,
+						 &inputshadowcolor,
+						 inputShadowXOffset, inputShadowYOffset);
+	} else { /*single input mode */
+		switch(field) {
+			case Get_Passwd:
+				SlimDrawString8 (draw, &inputcolor, font,
+								 input_pass_x, input_pass_y,
+								 HiddenPasswdBuffer,
+								 &inputshadowcolor,
+								 inputShadowXOffset, inputShadowYOffset);
+				break;
+			case Get_Name:
+				SlimDrawString8 (draw, &inputcolor, font,
+								 input_name_x, input_name_y,
+								 NameBuffer,
+								 &inputshadowcolor,
+								 inputShadowXOffset, inputShadowYOffset);
+				break;
+		}
+	}
+
+	XftDrawDestroy (draw);
+	Cursor(SHOW);
+	ShowText();
 }
 
 bool Panel::OnKeyPress(XEvent& event) {
-    char ascii;
-    KeySym keysym;
-    XComposeStatus compstatus;
-    int xx;
-    int yy;
-    string text;
-    string formerString = "";
-    
-    XLookupString(&event.xkey, &ascii, 1, &keysym, &compstatus);
-    switch(keysym){
-        case XK_F1:
-            SwitchSession();
-            return true;
-
-        case XK_F11:
-            // Take a screenshot
-            system(cfg->getOption("screenshot_cmd").c_str());
-            return true;
-
-        case XK_Return:
-        case XK_KP_Enter:
-            if (field==Get_Name){
-                // Don't allow an empty username
-                if (NameBuffer.empty()) return true;
-
-                if (NameBuffer==CONSOLE_STR){
-                    action = Console;
-                } else if (NameBuffer==HALT_STR){
-                    action = Halt;
-                } else if (NameBuffer==REBOOT_STR){
-                    action = Reboot;
-                } else if (NameBuffer==SUSPEND_STR){
-                    action = Suspend;
-                } else if (NameBuffer==EXIT_STR){
-                    action = Exit;
-                } else{
-                    action = Login;
-                }
-            };
-            return false;
-        default:
-            break;
-    };
-
-    Cursor(HIDE);
-    switch(keysym){
-        case XK_Delete:
-        case XK_BackSpace:
-            switch(field) {
-                case GET_NAME:
-                    if (! NameBuffer.empty()){
-                        formerString=NameBuffer;
-                        NameBuffer.erase(--NameBuffer.end());
-                    };
-                    break;
-                case GET_PASSWD:
-                    if (! PasswdBuffer.empty()){
-                        formerString=HiddenPasswdBuffer;
-                        PasswdBuffer.erase(--PasswdBuffer.end());
-                        HiddenPasswdBuffer.erase(--HiddenPasswdBuffer.end());
-                    };
-                    break;
-            };
-            break;
-
-        case XK_w:
-        case XK_u:
-            if (reinterpret_cast<XKeyEvent&>(event).state & ControlMask) {
-                switch(field) {
-                    case Get_Passwd:
-                        formerString = HiddenPasswdBuffer;
-                        HiddenPasswdBuffer.clear();
-                        PasswdBuffer.clear();
-                        break;
-
-                    case Get_Name:
-                        formerString = NameBuffer;
-                        NameBuffer.clear();
-                        break;
-                };
-                break;
-            }
-            // Deliberate fall-through
-        
-        default:
-            if (isprint(ascii) && (keysym < XK_Shift_L || keysym > XK_Hyper_R)){
-                switch(field) {
-                    case GET_NAME:
-                        formerString=NameBuffer;
-                        if (NameBuffer.length() < INPUT_MAXLENGTH_NAME-1){
-                            NameBuffer.append(&ascii,1);
-                        };
-                        break;
-                    case GET_PASSWD:
-                        formerString=HiddenPasswdBuffer;
-                        if (PasswdBuffer.length() < INPUT_MAXLENGTH_PASSWD-1){
-                            PasswdBuffer.append(&ascii,1);
-                            HiddenPasswdBuffer.append("*");
-                        };
-                    break;
-                };
-            };
-            break;
-    };
-
-    XGlyphInfo extents;
-    XftDraw *draw = XftDrawCreate(Dpy, Win,
-                                  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
+	char ascii;
+	KeySym keysym;
+	XComposeStatus compstatus;
+	int xx;
+	int yy;
+	string text;
+	string formerString = "";
+	
+	XLookupString(&event.xkey, &ascii, 1, &keysym, &compstatus);
+	switch(keysym){
+		case XK_F1:
+			SwitchSession();
+			return true;
+
+		case XK_F11:
+			/* Take a screenshot */
+			system(cfg->getOption("screenshot_cmd").c_str());
+			return true;
+
+		case XK_Return:
+		case XK_KP_Enter:
+			if (field==Get_Name){
+				/* Don't allow an empty username */
+				if (NameBuffer.empty()) return true;
+
+				if (NameBuffer==CONSOLE_STR){
+					action = Console;
+				} else if (NameBuffer==HALT_STR){
+					action = Halt;
+				} else if (NameBuffer==REBOOT_STR){
+					action = Reboot;
+				} else if (NameBuffer==SUSPEND_STR){
+					action = Suspend;
+				} else if (NameBuffer==EXIT_STR){
+					action = Exit;
+				} else{
+					action = Login;
+				}
+			};
+			return false;
+		default:
+			break;
+	};
+
+	Cursor(HIDE);
+	switch(keysym){
+		case XK_Delete:
+		case XK_BackSpace:
+			switch(field) {
+				case GET_NAME:
+					if (! NameBuffer.empty()){
+						formerString=NameBuffer;
+						NameBuffer.erase(--NameBuffer.end());
+					};
+					break;
+				case GET_PASSWD:
+					if (! PasswdBuffer.empty()){
+						formerString=HiddenPasswdBuffer;
+						PasswdBuffer.erase(--PasswdBuffer.end());
+						HiddenPasswdBuffer.erase(--HiddenPasswdBuffer.end());
+					};
+					break;
+			};
+			break;
+
+		case XK_w:
+		case XK_u:
+			if (reinterpret_cast<XKeyEvent&>(event).state & ControlMask) {
+				switch(field) {
+					case Get_Passwd:
+						formerString = HiddenPasswdBuffer;
+						HiddenPasswdBuffer.clear();
+						PasswdBuffer.clear();
+						break;
+
+					case Get_Name:
+						formerString = NameBuffer;
+						NameBuffer.clear();
+						break;
+				};
+				break;
+			}
+			/* Deliberate fall-through */
+		
+		default:
+			if (isprint(ascii) && (keysym < XK_Shift_L || keysym > XK_Hyper_R)){
+				switch(field) {
+					case GET_NAME:
+						formerString=NameBuffer;
+						if (NameBuffer.length() < INPUT_MAXLENGTH_NAME-1){
+							NameBuffer.append(&ascii,1);
+						};
+						break;
+					case GET_PASSWD:
+						formerString=HiddenPasswdBuffer;
+						if (PasswdBuffer.length() < INPUT_MAXLENGTH_PASSWD-1){
+							PasswdBuffer.append(&ascii,1);
+							HiddenPasswdBuffer.append("*");
+						};
+					break;
+				};
+			};
+			break;
+	};
+
+	XGlyphInfo extents;
+	XftDraw *draw = XftDrawCreate(Dpy, Win,
+								  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
 
    switch(field) {
-        case Get_Name:
-            text = NameBuffer;
-            xx = input_name_x;
-            yy = input_name_y;
-            break;
-
-        case Get_Passwd:
-            text = HiddenPasswdBuffer;
-            xx = input_pass_x;
-            yy = input_pass_y;
-            break;
-    }
-
-    if (!formerString.empty()){
-        const char* txth = "Wj"; // get proper maximum height ?
-        XftTextExtents8(Dpy, font, reinterpret_cast<const XftChar8*>(txth), strlen(txth), &extents);
-        int maxHeight = extents.height;
-
-        XftTextExtents8(Dpy, font, reinterpret_cast<const XftChar8*>(formerString.c_str()),
-                        formerString.length(), &extents);
-        int maxLength = extents.width;
-
-        XClearArea(Dpy, Win, xx-3, yy-maxHeight-3,
-                   maxLength+6, maxHeight+6, false);
-    }
-
-    if (!text.empty()) {
-        SlimDrawString8 (draw, &inputcolor, font, xx, yy,
-                         text,
-                         &inputshadowcolor,
-                         inputShadowXOffset, inputShadowYOffset);
-    }
-
-    XftDrawDestroy (draw);
-    Cursor(SHOW);
-    return true;
+		case Get_Name:
+			text = NameBuffer;
+			xx = input_name_x;
+			yy = input_name_y;
+			break;
+
+		case Get_Passwd:
+			text = HiddenPasswdBuffer;
+			xx = input_pass_x;
+			yy = input_pass_y;
+			break;
+	}
+
+	if (!formerString.empty()){
+		const char* txth = "Wj"; /* get proper maximum height ? */
+		XftTextExtents8(Dpy, font, reinterpret_cast<const XftChar8*>(txth), strlen(txth), &extents);
+		int maxHeight = extents.height;
+
+		XftTextExtents8(Dpy, font, reinterpret_cast<const XftChar8*>(formerString.c_str()),
+						formerString.length(), &extents);
+		int maxLength = extents.width;
+
+		XClearArea(Dpy, Win, xx-3, yy-maxHeight-3,
+				   maxLength+6, maxHeight+6, false);
+	}
+
+	if (!text.empty()) {
+		SlimDrawString8 (draw, &inputcolor, font, xx, yy,
+						 text,
+						 &inputshadowcolor,
+						 inputShadowXOffset, inputShadowYOffset);
+	}
+
+	XftDrawDestroy (draw);
+	Cursor(SHOW);
+	return true;
 }
 
-// Draw welcome and "enter username" message
+/* Draw welcome and "enter username" message */
 void Panel::ShowText(){
-    string cfgX, cfgY;
-    XGlyphInfo extents;
-
-    bool singleInputMode =
-    input_name_x == input_pass_x &&
-    input_name_y == input_pass_y;
-
-    XftDraw *draw = XftDrawCreate(Dpy, Win,
-                                  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
-    /* welcome message */
-    XftTextExtents8(Dpy, welcomefont, (XftChar8*)welcome_message.c_str(),
-                    strlen(welcome_message.c_str()), &extents);
-    cfgX = cfg->getOption("welcome_x");
-    cfgY = cfg->getOption("welcome_y");
-    int shadowXOffset = cfg->getIntOption("welcome_shadow_xoffset");
-    int shadowYOffset = cfg->getIntOption("welcome_shadow_yoffset");
-
-    welcome_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
-    welcome_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
-    if (welcome_x >= 0 && welcome_y >= 0) {
-        SlimDrawString8 (draw, &welcomecolor, welcomefont,
-                         welcome_x, welcome_y,
-                         welcome_message,
-                         &welcomeshadowcolor, shadowXOffset, shadowYOffset);
-    }
-
-    /* Enter username-password message */
-    string msg;
-    if (!singleInputMode|| field == Get_Passwd ) {
-        msg = cfg->getOption("password_msg");
-        XftTextExtents8(Dpy, enterfont, (XftChar8*)msg.c_str(),
-                        strlen(msg.c_str()), &extents);
-        cfgX = cfg->getOption("password_x");
-        cfgY = cfg->getOption("password_y");
-        int shadowXOffset = cfg->getIntOption("username_shadow_xoffset");
-        int shadowYOffset = cfg->getIntOption("username_shadow_yoffset");
-        password_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
-        password_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
-        if (password_x >= 0 && password_y >= 0){
-            SlimDrawString8 (draw, &entercolor, enterfont, password_x, password_y,
-                             msg, &entershadowcolor, shadowXOffset, shadowYOffset);
-        }
-    }
-    if (!singleInputMode|| field == Get_Name ) {
-        msg = cfg->getOption("username_msg");
-        XftTextExtents8(Dpy, enterfont, (XftChar8*)msg.c_str(),
-                        strlen(msg.c_str()), &extents);
-        cfgX = cfg->getOption("username_x");
-        cfgY = cfg->getOption("username_y");
-        int shadowXOffset = cfg->getIntOption("username_shadow_xoffset");
-        int shadowYOffset = cfg->getIntOption("username_shadow_yoffset");
-        username_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
-        username_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
-        if (username_x >= 0 && username_y >= 0){
-            SlimDrawString8 (draw, &entercolor, enterfont, username_x, username_y,
-                             msg, &entershadowcolor, shadowXOffset, shadowYOffset);
-        }
-    }
-    XftDrawDestroy(draw);
+	string cfgX, cfgY;
+	XGlyphInfo extents;
+
+	bool singleInputMode =
+	input_name_x == input_pass_x &&
+	input_name_y == input_pass_y;
+
+	XftDraw *draw = XftDrawCreate(Dpy, Win,
+								  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
+	/* welcome message */
+	XftTextExtents8(Dpy, welcomefont, (XftChar8*)welcome_message.c_str(),
+					strlen(welcome_message.c_str()), &extents);
+	cfgX = cfg->getOption("welcome_x");
+	cfgY = cfg->getOption("welcome_y");
+	int shadowXOffset = cfg->getIntOption("welcome_shadow_xoffset");
+	int shadowYOffset = cfg->getIntOption("welcome_shadow_yoffset");
+
+	welcome_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
+	welcome_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
+	if (welcome_x >= 0 && welcome_y >= 0) {
+		SlimDrawString8 (draw, &welcomecolor, welcomefont,
+						 welcome_x, welcome_y,
+						 welcome_message,
+						 &welcomeshadowcolor, shadowXOffset, shadowYOffset);
+	}
+
+	/* Enter username-password message */
+	string msg;
+	if (!singleInputMode|| field == Get_Passwd ) {
+		msg = cfg->getOption("password_msg");
+		XftTextExtents8(Dpy, enterfont, (XftChar8*)msg.c_str(),
+						strlen(msg.c_str()), &extents);
+		cfgX = cfg->getOption("password_x");
+		cfgY = cfg->getOption("password_y");
+		int shadowXOffset = cfg->getIntOption("username_shadow_xoffset");
+		int shadowYOffset = cfg->getIntOption("username_shadow_yoffset");
+		password_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
+		password_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
+		if (password_x >= 0 && password_y >= 0){
+			SlimDrawString8 (draw, &entercolor, enterfont, password_x, password_y,
+							 msg, &entershadowcolor, shadowXOffset, shadowYOffset);
+		}
+	}
+	if (!singleInputMode|| field == Get_Name ) {
+		msg = cfg->getOption("username_msg");
+		XftTextExtents8(Dpy, enterfont, (XftChar8*)msg.c_str(),
+						strlen(msg.c_str()), &extents);
+		cfgX = cfg->getOption("username_x");
+		cfgY = cfg->getOption("username_y");
+		int shadowXOffset = cfg->getIntOption("username_shadow_xoffset");
+		int shadowYOffset = cfg->getIntOption("username_shadow_yoffset");
+		username_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
+		username_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
+		if (username_x >= 0 && username_y >= 0){
+			SlimDrawString8 (draw, &entercolor, enterfont, username_x, username_y,
+							 msg, &entershadowcolor, shadowXOffset, shadowYOffset);
+		}
+	}
+	XftDrawDestroy(draw);
 }
 
 string Panel::getSession() {
-    return session;
+	return session;
 }
 
-// choose next available session type
+/* choose next available session type */
 void Panel::SwitchSession() {
-    session = cfg->nextSession(session);
-    if (session.size() > 0) {
-        ShowSession();
-    }
+	session = cfg->nextSession(session);
+	if (session.size() > 0) {
+		ShowSession();
+	}
 }
 
-// Display session type on the screen
+/* Display session type on the screen */
 void Panel::ShowSession() {
 	string msg_x, msg_y;
-    XClearWindow(Dpy, Root);
-    string currsession = cfg->getOption("session_msg") + " " + session;
-    XGlyphInfo extents;
+	XClearWindow(Dpy, Root);
+	string currsession = cfg->getOption("session_msg") + " " + session;
+	XGlyphInfo extents;
 	
 	sessionfont = XftFontOpenName(Dpy, Scr, cfg->getOption("session_font").c_str());
-    
+	
 	XftDraw *draw = XftDrawCreate(Dpy, Root,
-                                  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
-    XftTextExtents8(Dpy, sessionfont, reinterpret_cast<const XftChar8*>(currsession.c_str()),
-                    currsession.length(), &extents);
-    msg_x = cfg->getOption("session_x");
-    msg_y = cfg->getOption("session_y");
-    int x = Cfg::absolutepos(msg_x, XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.width);
-    int y = Cfg::absolutepos(msg_y, XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.height);
-    int shadowXOffset = cfg->getIntOption("session_shadow_xoffset");
-    int shadowYOffset = cfg->getIntOption("session_shadow_yoffset");
-
-    SlimDrawString8(draw, &sessioncolor, sessionfont, x, y,
-                    currsession, 
-                    &sessionshadowcolor,
-                    shadowXOffset, shadowYOffset);
-    XFlush(Dpy);
-    XftDrawDestroy(draw);
+								  DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
+	XftTextExtents8(Dpy, sessionfont, reinterpret_cast<const XftChar8*>(currsession.c_str()),
+					currsession.length(), &extents);
+	msg_x = cfg->getOption("session_x");
+	msg_y = cfg->getOption("session_y");
+	int x = Cfg::absolutepos(msg_x, XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.width);
+	int y = Cfg::absolutepos(msg_y, XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)), extents.height);
+	int shadowXOffset = cfg->getIntOption("session_shadow_xoffset");
+	int shadowYOffset = cfg->getIntOption("session_shadow_yoffset");
+
+	SlimDrawString8(draw, &sessioncolor, sessionfont, x, y,
+					currsession, 
+					&sessionshadowcolor,
+					shadowXOffset, shadowYOffset);
+	XFlush(Dpy);
+	XftDrawDestroy(draw);
 }
 
 
 void Panel::SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
-                            int x, int y, const string& str,
-                            XftColor* shadowColor,
-                            int xOffset, int yOffset)
+							int x, int y, const string& str,
+							XftColor* shadowColor,
+							int xOffset, int yOffset)
 {
-    if (xOffset && yOffset) {
-        XftDrawString8(d, shadowColor, font, x+xOffset, y+yOffset,
-                       reinterpret_cast<const FcChar8*>(str.c_str()), str.length());
-    }
-    XftDrawString8(d, color, font, x, y, reinterpret_cast<const FcChar8*>(str.c_str()), str.length());
+	if (xOffset && yOffset) {
+		XftDrawString8(d, shadowColor, font, x+xOffset, y+yOffset,
+					   reinterpret_cast<const FcChar8*>(str.c_str()), str.length());
+	}
+	XftDrawString8(d, color, font, x, y, reinterpret_cast<const FcChar8*>(str.c_str()), str.length());
 }
 
 Panel::ActionType Panel::getAction(void) const{
-    return action;
+	return action;
 };
 
 void Panel::Reset(void){
-    ResetName();
-    ResetPasswd();
+	ResetName();
+	ResetPasswd();
 };
 
 void Panel::ResetName(void){
-    NameBuffer.clear();
+	NameBuffer.clear();
 };
 
 void Panel::ResetPasswd(void){
-    PasswdBuffer.clear();
-    HiddenPasswdBuffer.clear();
+	PasswdBuffer.clear();
+	HiddenPasswdBuffer.clear();
 };
 
 void Panel::SetName(const string& name){
-    NameBuffer=name;
-    action = Login;
+	NameBuffer=name;
+	action = Login;
 };
 
 const string& Panel::GetName(void) const{
-    return NameBuffer;
+	return NameBuffer;
 };
 
 const string& Panel::GetPasswd(void) const{
-    return PasswdBuffer;
+	return PasswdBuffer;
 };

+ 117 - 119
panel.h

@@ -33,126 +33,124 @@
 
 class Panel {
 public:
-    enum ActionType {
-        Login,
-        Console,
-        Reboot,
-        Halt,
-        Exit,
-        Suspend
-    };
-    enum FieldType {
-        Get_Name,
-        Get_Passwd
-    };
-
-
-    Panel(Display* dpy, int scr, Window root, Cfg* config,
-          const std::string& themed);
-    ~Panel();
-    void OpenPanel();
-    void ClosePanel();
-    void ClearPanel();
-    void Message(const std::string& text);
-    void Error(const std::string& text);
-    void EventHandler(const FieldType& curfield);
-    std::string getSession();
-    ActionType getAction(void) const;
-
-    void Reset(void);
-    void ResetName(void);
-    void ResetPasswd(void);
-    void SetName(const std::string& name);
-    const std::string& GetName(void) const;
-    const std::string& GetPasswd(void) const;
+	enum ActionType {
+		Login,
+		Console,
+		Reboot,
+		Halt,
+		Exit,
+		Suspend
+	};
+	enum FieldType {
+		Get_Name,
+		Get_Passwd
+	};
+
+
+	Panel(Display* dpy, int scr, Window root, Cfg* config,
+		  const std::string& themed);
+	~Panel();
+	void OpenPanel();
+	void ClosePanel();
+	void ClearPanel();
+	void Message(const std::string& text);
+	void Error(const std::string& text);
+	void EventHandler(const FieldType& curfield);
+	std::string getSession();
+	ActionType getAction(void) const;
+
+	void Reset(void);
+	void ResetName(void);
+	void ResetPasswd(void);
+	void SetName(const std::string& name);
+	const std::string& GetName(void) const;
+	const std::string& GetPasswd(void) const;
 private:
-    Panel();
-    void Cursor(int visible);
-    unsigned long GetColor(const char* colorname);
-    void OnExpose(void);
-    bool OnKeyPress(XEvent& event);
-    void ShowText();
-    void SwitchSession();
-    void ShowSession();
-
-    void SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
-                            int x, int y, const std::string& str,
-                            XftColor* shadowColor,
-                            int xOffset, int yOffset);
-
-    Cfg* cfg;
-
-    // Private data
-    Window Win;
-    Window Root;
-    Display* Dpy;
-    int Scr;
-    int X, Y;
-    GC TextGC;
-    XftFont* font;
-    XftColor inputshadowcolor;
-    XftColor inputcolor;
-    XftColor msgcolor;
-    XftColor msgshadowcolor;
-    XftFont* msgfont;
-    XftColor introcolor;
-    XftFont* introfont;
-    XftFont* welcomefont;
-    XftColor welcomecolor;
-    XftFont* sessionfont;
-    XftColor sessioncolor;
-    XftColor sessionshadowcolor;
-    XftColor welcomeshadowcolor;
-    XftFont* enterfont;
-    XftColor entercolor;
-    XftColor entershadowcolor;
-    ActionType action;
-    FieldType field;
-    
-    // Username/Password
-    std::string NameBuffer;
-    std::string PasswdBuffer;
-    std::string HiddenPasswdBuffer;
-
-    // Configuration
-    int input_name_x;
-    int input_name_y;
-    int input_pass_x;
-    int input_pass_y;
-    int inputShadowXOffset;
-    int inputShadowYOffset;
-    int input_cursor_height;
-    int welcome_x;
-    int welcome_y;
-    int welcome_shadow_xoffset;
-    int welcome_shadow_yoffset;
-    int session_shadow_xoffset;
-    int session_shadow_yoffset;
-    int intro_x;
-    int intro_y;
-    int username_x;
-    int username_y;
-    int username_shadow_xoffset;
-    int username_shadow_yoffset;
-    int password_x;
-    int password_y;
-    std::string welcome_message;
-    std::string intro_message;
-
-    // Pixmap data
-    Pixmap PanelPixmap;
-
-    Image* image;
-
-    // For thesting themes
-    bool testing;
-    std::string themedir;
-
-    // Session handling
-    std::string session;
+	Panel();
+	void Cursor(int visible);
+	unsigned long GetColor(const char* colorname);
+	void OnExpose(void);
+	bool OnKeyPress(XEvent& event);
+	void ShowText();
+	void SwitchSession();
+	void ShowSession();
+
+	void SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
+							int x, int y, const std::string& str,
+							XftColor* shadowColor,
+							int xOffset, int yOffset);
+
+	Cfg* cfg;
+
+	/* Private data */
+	Window Win;
+	Window Root;
+	Display* Dpy;
+	int Scr;
+	int X, Y;
+	GC TextGC;
+	XftFont* font;
+	XftColor inputshadowcolor;
+	XftColor inputcolor;
+	XftColor msgcolor;
+	XftColor msgshadowcolor;
+	XftFont* msgfont;
+	XftColor introcolor;
+	XftFont* introfont;
+	XftFont* welcomefont;
+	XftColor welcomecolor;
+	XftFont* sessionfont;
+	XftColor sessioncolor;
+	XftColor sessionshadowcolor;
+	XftColor welcomeshadowcolor;
+	XftFont* enterfont;
+	XftColor entercolor;
+	XftColor entershadowcolor;
+	ActionType action;
+	FieldType field;
+	
+	/* Username/Password */
+	std::string NameBuffer;
+	std::string PasswdBuffer;
+	std::string HiddenPasswdBuffer;
+
+	/* Configuration */
+	int input_name_x;
+	int input_name_y;
+	int input_pass_x;
+	int input_pass_y;
+	int inputShadowXOffset;
+	int inputShadowYOffset;
+	int input_cursor_height;
+	int welcome_x;
+	int welcome_y;
+	int welcome_shadow_xoffset;
+	int welcome_shadow_yoffset;
+	int session_shadow_xoffset;
+	int session_shadow_yoffset;
+	int intro_x;
+	int intro_y;
+	int username_x;
+	int username_y;
+	int username_shadow_xoffset;
+	int username_shadow_yoffset;
+	int password_x;
+	int password_y;
+	std::string welcome_message;
+	std::string intro_message;
+
+	/* Pixmap data */
+	Pixmap PanelPixmap;
+
+	Image* image;
+
+	/* For thesting themes */
+	bool testing;
+	std::string themedir;
+
+	/* Session handling */
+	std::string session;
 
 };
 
-#endif
-
-
+#endif /* _PANEL_H_ */

+ 142 - 142
png.c

@@ -1,21 +1,21 @@
 /****************************************************************************
-    png.c - read and write png images using libpng routines.
-    Distributed with Xplanet.
-    Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+	png.c - read and write png images using libpng routines.
+	Distributed with Xplanet.
+	Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 2 of the License, or
+	(at your option) any later version.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, write to the Free Software
+	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ****************************************************************************/
 
 #include <stdio.h>
@@ -26,144 +26,144 @@
 
 int
 read_png(const char *filename, int *width, int *height, unsigned char **rgb, 
-     unsigned char **alpha)
+	 unsigned char **alpha)
 {
-    int ret = 0;
-
-    png_structp png_ptr;
-    png_infop info_ptr;
-    png_bytepp row_pointers;
-
-    unsigned char *ptr = NULL;
-    png_uint_32 w, h;
-    int bit_depth, color_type, interlace_type;
-    int i;
-
-    FILE *infile = fopen(filename, "rb");
-    if (infile == NULL) {
-        fprintf(stderr, "Can not fopen file: %s\n",filename);
-        return ret;
-    }
-
-    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 
-                                     (png_voidp) NULL, 
-                                     (png_error_ptr) NULL, 
-                                     (png_error_ptr) NULL);
-    if (!png_ptr)
-        goto file_close;
+	int ret = 0;
+
+	png_structp png_ptr;
+	png_infop info_ptr;
+	png_bytepp row_pointers;
+
+	unsigned char *ptr = NULL;
+	png_uint_32 w, h;
+	int bit_depth, color_type, interlace_type;
+	int i;
+
+	FILE *infile = fopen(filename, "rb");
+	if (infile == NULL) {
+		fprintf(stderr, "Can not fopen file: %s\n",filename);
+		return ret;
+	}
+
+	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 
+									 (png_voidp) NULL, 
+									 (png_error_ptr) NULL, 
+									 (png_error_ptr) NULL);
+	if (!png_ptr)
+		goto file_close;
   
-    info_ptr = png_create_info_struct(png_ptr);
-    if (!info_ptr) {
-        png_destroy_read_struct(&png_ptr, (png_infopp) NULL, 
-                                (png_infopp) NULL);
-    }
+	info_ptr = png_create_info_struct(png_ptr);
+	if (!info_ptr) {
+		png_destroy_read_struct(&png_ptr, (png_infopp) NULL, 
+								(png_infopp) NULL);
+	}
 
 #if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
 	if (setjmp(png_jmpbuf((png_ptr))))
 #else
-    if (setjmp(png_ptr->jmpbuf))
+	if (setjmp(png_ptr->jmpbuf))
 #endif
-        goto png_destroy;
+		goto png_destroy;
   
-    png_init_io(png_ptr, infile);
-    png_read_info(png_ptr, info_ptr);
-
-    png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
-                 &interlace_type, (int *) NULL, (int *) NULL);
-
-    /* Prevent against integer overflow */
-    if(w >= MAX_DIMENSION || h >= MAX_DIMENSION) {
-        fprintf(stderr, "Unreasonable dimension found in file: %s\n",filename);
-        goto png_destroy;
-    }
-
-    *width = (int) w;
-    *height = (int) h;
-    
-    if (color_type == PNG_COLOR_TYPE_RGB_ALPHA
-        || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
-        alpha[0] = malloc(*width * *height);
-        if (alpha[0] == NULL)
-        {
-            fprintf(stderr, "Can't allocate memory for alpha channel in PNG file.\n");
-            goto png_destroy;
-        }
-    }
-
-    /* Change a paletted/grayscale image to RGB */
-    if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8) 
-        png_set_expand(png_ptr);
-
-    /* Change a grayscale image to RGB */
-    if (color_type == PNG_COLOR_TYPE_GRAY 
-        || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-        png_set_gray_to_rgb(png_ptr);
-
-    /* If the PNG file has 16 bits per channel, strip them down to 8 */
-    if (bit_depth == 16)
-        png_set_strip_16(png_ptr);
-
-    /* use 1 byte per pixel */
-    png_set_packing(png_ptr);
-
-    row_pointers = malloc(*height * sizeof(png_bytep));
-    if (row_pointers == NULL) {
-        fprintf(stderr, "Can't allocate memory for PNG file.\n");
-        goto png_destroy;
-    }
-
-    for (i = 0; i < *height; i++) {
-        row_pointers[i] = malloc(4 * *width);
-        if (row_pointers == NULL) {
-            fprintf(stderr, "Can't allocate memory for PNG line.\n");
-            goto rows_free;
-        }
-    }
-
-    png_read_image(png_ptr, row_pointers);
-
-    rgb[0] = malloc(3 * *width * *height);
-    if (rgb[0] == NULL) {
-        fprintf(stderr, "Can't allocate memory for PNG file.\n");
-        goto rows_free;
-    }
-
-    if (alpha[0] == NULL)
-    {
-        ptr = rgb[0];
-        for (i = 0; i < *height; i++) {
-            memcpy(ptr, row_pointers[i], 3 * *width);
-            ptr += 3 * *width;
-        }
-    } else {
-        int j;
-        ptr = rgb[0];
-        for (i = 0; i < *height; i++) {
-            int ipos = 0;
-            for (j = 0; j < *width; j++) {
-                *ptr++ = row_pointers[i][ipos++];
-                *ptr++ = row_pointers[i][ipos++];
-                *ptr++ = row_pointers[i][ipos++];
-                alpha[0][i * *width + j] = row_pointers[i][ipos++];
-            }
-        }
-    }
-
-    ret = 1; /* data reading is OK */
+	png_init_io(png_ptr, infile);
+	png_read_info(png_ptr, info_ptr);
+
+	png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
+				 &interlace_type, (int *) NULL, (int *) NULL);
+
+	/* Prevent against integer overflow */
+	if(w >= MAX_DIMENSION || h >= MAX_DIMENSION) {
+		fprintf(stderr, "Unreasonable dimension found in file: %s\n",filename);
+		goto png_destroy;
+	}
+
+	*width = (int) w;
+	*height = (int) h;
+	
+	if (color_type == PNG_COLOR_TYPE_RGB_ALPHA
+		|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+		alpha[0] = malloc(*width * *height);
+		if (alpha[0] == NULL)
+		{
+			fprintf(stderr, "Can't allocate memory for alpha channel in PNG file.\n");
+			goto png_destroy;
+		}
+	}
+
+	/* Change a paletted/grayscale image to RGB */
+	if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8) 
+		png_set_expand(png_ptr);
+
+	/* Change a grayscale image to RGB */
+	if (color_type == PNG_COLOR_TYPE_GRAY 
+		|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+		png_set_gray_to_rgb(png_ptr);
+
+	/* If the PNG file has 16 bits per channel, strip them down to 8 */
+	if (bit_depth == 16)
+		png_set_strip_16(png_ptr);
+
+	/* use 1 byte per pixel */
+	png_set_packing(png_ptr);
+
+	row_pointers = malloc(*height * sizeof(png_bytep));
+	if (row_pointers == NULL) {
+		fprintf(stderr, "Can't allocate memory for PNG file.\n");
+		goto png_destroy;
+	}
+
+	for (i = 0; i < *height; i++) {
+		row_pointers[i] = malloc(4 * *width);
+		if (row_pointers == NULL) {
+			fprintf(stderr, "Can't allocate memory for PNG line.\n");
+			goto rows_free;
+		}
+	}
+
+	png_read_image(png_ptr, row_pointers);
+
+	rgb[0] = malloc(3 * *width * *height);
+	if (rgb[0] == NULL) {
+		fprintf(stderr, "Can't allocate memory for PNG file.\n");
+		goto rows_free;
+	}
+
+	if (alpha[0] == NULL)
+	{
+		ptr = rgb[0];
+		for (i = 0; i < *height; i++) {
+			memcpy(ptr, row_pointers[i], 3 * *width);
+			ptr += 3 * *width;
+		}
+	} else {
+		int j;
+		ptr = rgb[0];
+		for (i = 0; i < *height; i++) {
+			int ipos = 0;
+			for (j = 0; j < *width; j++) {
+				*ptr++ = row_pointers[i][ipos++];
+				*ptr++ = row_pointers[i][ipos++];
+				*ptr++ = row_pointers[i][ipos++];
+				alpha[0][i * *width + j] = row_pointers[i][ipos++];
+			}
+		}
+	}
+
+	ret = 1; /* data reading is OK */
 
 rows_free:
-    for (i = 0; i < *height; i++) {
-        if (row_pointers[i] != NULL ) {
-            free(row_pointers[i]);
-        }
-    }
+	for (i = 0; i < *height; i++) {
+		if (row_pointers[i] != NULL ) {
+			free(row_pointers[i]);
+		}
+	}
 
-    free(row_pointers);
+	free(row_pointers);
 
 png_destroy:
-    png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
+	png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
 
 file_close:
-    fclose(infile);
-    return(ret);
+	fclose(infile);
+	return(ret);
 }

+ 25 - 25
switchuser.cpp

@@ -16,45 +16,45 @@
 using namespace std;
 
 SwitchUser::SwitchUser(struct passwd *pw, Cfg *c, const string& display,
-                       char** _env)
-    : cfg(c),
-      Pw(pw),
-      displayName(display),
-      env(_env)
+					   char** _env)
+	: cfg(c),
+	  Pw(pw),
+	  displayName(display),
+	  env(_env)
 {
 }
 
 SwitchUser::~SwitchUser() {
-    // Never called
+	/* Never called */
 }
 
 void SwitchUser::Login(const char* cmd, const char* mcookie) {
-    SetUserId();
-    SetClientAuth(mcookie);
-    Execute(cmd);
+	SetUserId();
+	SetClientAuth(mcookie);
+	Execute(cmd);
 }
 
 void SwitchUser::SetUserId() {
-    if( (Pw == 0) ||
-            (initgroups(Pw->pw_name, Pw->pw_gid) != 0) ||
-            (setgid(Pw->pw_gid) != 0) ||
-            (setuid(Pw->pw_uid) != 0) ) {
-        logStream << APPNAME << ": could not switch user id" << endl;
-        exit(ERR_EXIT);
-    }
+	if( (Pw == 0) ||
+			(initgroups(Pw->pw_name, Pw->pw_gid) != 0) ||
+			(setgid(Pw->pw_gid) != 0) ||
+			(setuid(Pw->pw_uid) != 0) ) {
+		logStream << APPNAME << ": could not switch user id" << endl;
+		exit(ERR_EXIT);
+	}
 }
 
 void SwitchUser::Execute(const char* cmd) {
-    chdir(Pw->pw_dir);
-    execle(Pw->pw_shell, Pw->pw_shell, "-c", cmd, NULL, env);
-    logStream << APPNAME << ": could not execute login command" << endl;
+	chdir(Pw->pw_dir);
+	execle(Pw->pw_shell, Pw->pw_shell, "-c", cmd, NULL, env);
+	logStream << APPNAME << ": could not execute login command" << endl;
 }
 
 void SwitchUser::SetClientAuth(const char* mcookie) {
-    bool r;
-    string home = string(Pw->pw_dir);
-    string authfile = home + "/.Xauthority";
-    remove(authfile.c_str());
-    r = Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
-      authfile);
+	bool r;
+	string home = string(Pw->pw_dir);
+	string authfile = home + "/.Xauthority";
+	remove(authfile.c_str());
+	r = Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
+	  authfile);
 }

+ 15 - 15
switchuser.h

@@ -8,7 +8,7 @@
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 */
-    
+	
 #ifndef _SWITCHUSER_H_
 #define _SWITCHUSER_H_
 
@@ -26,22 +26,22 @@
 
 class SwitchUser {
 public:
-    SwitchUser(struct passwd *pw, Cfg *c, const std::string& display,
-               char** _env);
-    ~SwitchUser();
-    void Login(const char* cmd, const char* mcookie);
+	SwitchUser(struct passwd *pw, Cfg *c, const std::string& display,
+			   char** _env);
+	~SwitchUser();
+	void Login(const char* cmd, const char* mcookie);
 
 private:
-    SwitchUser();
-    void SetEnvironment();
-    void SetUserId();
-    void Execute(const char* cmd);
-    void SetClientAuth(const char* mcookie);
-    Cfg* cfg;
-    struct passwd *Pw;
+	SwitchUser();
+	void SetEnvironment();
+	void SetUserId();
+	void Execute(const char* cmd);
+	void SetClientAuth(const char* mcookie);
+	Cfg* cfg;
+	struct passwd *Pw;
 
-    std::string displayName;
-    char** env;
+	std::string displayName;
+	char** env;
 };
 
-#endif
+#endif /* _SWITCHUSER_H_ */

+ 1 - 1
util.cpp

@@ -21,7 +21,7 @@
  * Returns true on success, false on fault.
  */
 bool Util::add_mcookie(const std::string &mcookie, const char *display,
-    const std::string &xauth_cmd, const std::string &authfile)
+	const std::string &xauth_cmd, const std::string &authfile)
 {
 	FILE *fp;
 	std::string cmd = xauth_cmd + " -f " + authfile + " -q";

+ 4 - 4
util.h

@@ -6,14 +6,14 @@
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 */
-#ifndef __UTIL_H__
-#define __UTIL_H__
+#ifndef _UTIL_H__
+#define _UTIL_H__
 
 #include <string>
 
 namespace Util {
 	bool add_mcookie(const std::string &mcookie, const char *display,
-	    const std::string &xauth_cmd, const std::string &authfile);
+		const std::string &xauth_cmd, const std::string &authfile);
 
 	void srandom(unsigned long seed);
 	long random(void);
@@ -21,4 +21,4 @@ namespace Util {
 	long makeseed(void);
 };
 
-#endif /* __UTIL_H__ */
+#endif /* _UTIL_H__ */