diff --git a/elma/ElmaService.cpp b/elma/ElmaService.cpp new file mode 100644 index 0000000..5f4d3fa --- /dev/null +++ b/elma/ElmaService.cpp @@ -0,0 +1,105 @@ +/* + * $Id$ + * + * ELMA, Ede Login MAnager + * Part of Equinox Desktop Environment (EDE). + * Copyright (c) 2008 EDE Authors. + * + * This program is licensed under terms of the + * GNU General Public License version 2 or newer. + * See COPYING for details. + */ + +#include "ElmaService.h" +#include "ElmaWindow.h" + +#include + +#include +#include +#include + +ElmaService::ElmaService() : config(NULL), theme(NULL) { +} + +ElmaService::~ElmaService() { + delete config; + elma_theme_clear(theme); +} + +ElmaService* ElmaService::instance(void) { + static ElmaService es; + return &es; +} + +void ElmaService::execute(const char* cmd) { + system(cmd); +} + +bool ElmaService::load_config(void) { + config = new ConfigData; + + edelib::Config cfile; + + if(!cfile.load("elma.conf")) + return false; + + char buff[256]; + unsigned int buffsz = sizeof(buff); + + if(cfile.get("elma", "xserver", buff, buffsz)) + config->xserver_cmd = buff; + + if(cfile.get("elma", "halt", buff, buffsz)) + config->halt_cmd = buff; + + if(cfile.get("elma", "reboot", buff, buffsz)) + config->reboot_cmd = buff; + + if(cfile.get("elma", "login_cmd", buff, buffsz)) + config->login_cmd = buff; + + if(cfile.get("elma", "xauth", buff, buffsz)) + config->xauth_cmd = buff; + + if(cfile.get("elma", "xauth_file", buff, buffsz)) + config->xauth_file = buff; + + if(cfile.get("elma", "theme", buff, buffsz)) + config->theme = buff; + + cfile.get("elma", "numlock", config->numlock, false); + cfile.get("elma", "cursor", config->show_cursor, false); + + return true; +} + +bool ElmaService::load_theme(void) { + theme = elma_theme_init("themes/default"); + + if(theme == NULL) + return false; + return true; +} + +void ElmaService::display_window(void) { + fl_open_display(); + + int dx, dy, dw, dh; + Fl::screen_xywh(dx, dy, dw, dh); + + //numlock_xkb_init(fl_display); + + ElmaWindow* win = new ElmaWindow(dw, dh); + + if(!win->create_window(theme)) { + delete win; + return; + } + + win->clear_border(); + win->show(); + win->cursor(FL_CURSOR_NONE); + + Fl::run(); +} diff --git a/elma/ElmaService.h b/elma/ElmaService.h new file mode 100644 index 0000000..75d028b --- /dev/null +++ b/elma/ElmaService.h @@ -0,0 +1,50 @@ +/* + * $Id$ + * + * ELMA, Ede Login MAnager + * Part of Equinox Desktop Environment (EDE). + * Copyright (c) 2008 EDE Authors. + * + * This program is licensed under terms of the + * GNU General Public License version 2 or newer. + * See COPYING for details. + */ + +#ifndef __ELMASERVICE_H__ +#define __ELMASERVICE_H__ + +#include "Theme.h" + +struct ConfigData { + edelib::String xserver_cmd; + edelib::String halt_cmd; + edelib::String reboot_cmd; + edelib::String login_cmd; + edelib::String xauth_cmd; + + edelib::String xauth_file; + edelib::String theme; + + bool numlock; + bool show_cursor; +}; + +class ElmaService { + private: + ConfigData* config; + ElmaTheme* theme; + + void execute(const char* cmd); + + public: + ElmaService(); + ~ElmaService(); + static ElmaService* instance(void); + + bool load_config(void); + bool load_theme(void); + + void display_window(void); +}; + +#endif diff --git a/elma/ElmaWindow.cpp b/elma/ElmaWindow.cpp index 7dcd526..3bc39c1 100644 --- a/elma/ElmaWindow.cpp +++ b/elma/ElmaWindow.cpp @@ -19,6 +19,10 @@ #include "ElmaWindow.h" #include "Background.h" #include "TextArea.h" +#include "Theme.h" + +#define USER_AND_PASS_BOX_VISIBLE 1 +#define USER_OR_PASS_BOX_VISIBLE 2 static void timeout_cb(void* e) { ElmaWindow* win = (ElmaWindow*)e; @@ -29,45 +33,66 @@ ElmaWindow::ElmaWindow(int W, int H) : Fl_Double_Window(0, 0, W, H), bkg(0), user_in(0), pass_in(0), error_display(0), info_display(0) { deny_mode = false; + box_mode = USER_AND_PASS_BOX_VISIBLE; } ElmaWindow::~ElmaWindow() { } -bool ElmaWindow::load_everything(void) { +bool ElmaWindow::create_window(ElmaTheme* et) { + EASSERT(et != NULL); + begin(); bkg = new Background(0, 0, w(), h()); - if(!bkg->load_images("themes/default/background.jpg", "themes/default/panel.png")) + if(!bkg->load_images(et->background.c_str(), et->panel.c_str())) return false; - //bkg->panel_pos(35, 189); - bkg->panel_pos(235, 489); + bkg->panel_pos(et->panel_x, et->panel_y); + + ThemeBox* tb; + + tb = et->user; + user_in = new TextArea(tb->x, tb->y, tb->w, tb->h); + if(tb->label) + user_in->label(tb->label->c_str()); - //user_in = new TextArea(428, 351, 184, 28, "Username: "); - user_in = new TextArea(240, 489, 184, 30, "Username: "); user_in->labelcolor(FL_WHITE); user_in->textfont(FL_HELVETICA_BOLD); - user_in->textsize(14); + user_in->textsize(tb->font_size); - //pass_in = new TextArea(428, 351, 184, 28, "Password: "); - pass_in = new TextArea(240, 489, 184, 30, "Password: "); + tb = et->pass; + pass_in = new TextArea(tb->x, tb->y, tb->w, tb->h); + if(tb->label) + pass_in->label(tb->label->c_str()); + + pass_in->type(FL_SECRET_INPUT); pass_in->labelcolor(FL_WHITE); pass_in->textfont(FL_HELVETICA_BOLD); - pass_in->textsize(14); - pass_in->type(FL_SECRET_INPUT); - pass_in->hide(); + pass_in->textsize(tb->font_size); - //error_display = new Fl_Box(418, 390, 184, 28); - error_display = new Fl_Box(240, 520, 184, 28); + /* + * If username box and password box are at the same place, hide + * password box. With this, password box will be shown when user + * press enter on username box and reverse. + */ + if(pass_in->x() == user_in->x() && pass_in->y() == user_in->y()) { + box_mode = USER_OR_PASS_BOX_VISIBLE; + pass_in->hide(); + } + + tb = et->error; + error_display = new Fl_Box(tb->x, tb->y, tb->w, tb->h); error_display->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_CLIP); error_display->labelcolor(FL_WHITE); - error_display->labelsize(14); + error_display->labelsize(tb->font_size); error_display->hide(); - info_display = new Fl_Box(10, 10, 184, 28); + tb = et->info; + info_display = new Fl_Box(tb->x, tb->y, tb->w, tb->h); info_display->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_CLIP); info_display->labelcolor(FL_GRAY); - info_display->label("EDE version 2.0"); + if(tb->label) + info_display->label(tb->label->c_str()); end(); return true; @@ -114,16 +139,27 @@ int ElmaWindow::handle(int event) { return 1; if(Fl::event_key() == FL_Enter) { - if(user_in->visible()) { - user_in->hide(); - pass_in->show(); - // don't remember password - pass_in->value(0); + if(box_mode == USER_AND_PASS_BOX_VISIBLE) { + if(Fl::focus() == user_in) + Fl::focus(pass_in); + else { + validate_user(); + // don't remember password + pass_in->value(0); + Fl::focus(user_in); + } } else { - user_in->show(); - pass_in->hide(); + if(user_in->visible()) { + user_in->hide(); + pass_in->show(); + // don't remember password + pass_in->value(0); + } else { + user_in->show(); + pass_in->hide(); - validate_user(); + validate_user(); + } } return 1; diff --git a/elma/ElmaWindow.h b/elma/ElmaWindow.h index 6ffbbc2..1ff9532 100644 --- a/elma/ElmaWindow.h +++ b/elma/ElmaWindow.h @@ -18,6 +18,7 @@ class Background; class TextArea; class Fl_Box; +struct ElmaTheme; class ElmaWindow : public Fl_Double_Window { private: @@ -27,6 +28,7 @@ class ElmaWindow : public Fl_Double_Window { Fl_Box* error_display; Fl_Box* info_display; bool deny_mode; + int box_mode; void validate_user(void); @@ -37,7 +39,7 @@ class ElmaWindow : public Fl_Double_Window { void allow_input(void); void deny_input(void); - bool load_everything(void); + bool create_window(ElmaTheme* et); virtual int handle(int event); }; #endif diff --git a/elma/Jamfile b/elma/Jamfile index c12c0a5..291f89c 100644 --- a/elma/Jamfile +++ b/elma/Jamfile @@ -10,7 +10,7 @@ SubDir TOP elma ; -SOURCE = Background.cpp NumLock.cpp ElmaWindow.cpp elma.cpp ; +SOURCE = Background.cpp NumLock.cpp Theme.cpp ElmaService.cpp ElmaWindow.cpp elma.cpp ; EdeProgram elma : $(SOURCE) ; TranslationStrings locale : $(SOURCE) ; diff --git a/elma/TextArea.h b/elma/TextArea.h index a734ebc..f78c863 100644 --- a/elma/TextArea.h +++ b/elma/TextArea.h @@ -14,7 +14,6 @@ #define __TEXTAREA_H__ #include - #include /* @@ -40,6 +39,10 @@ class TextArea : public Fl_Input { if(event == FL_SHOW || event == FL_HIDE) return 1; + // don't allow input when we are disabled + if(event == FL_KEYBOARD && !active()) + return 1; + int ret = Fl_Input::handle(event); if(ret); parent()->damage(FL_DAMAGE_ALL, x(), y(), w(), h()); diff --git a/elma/Theme.cpp b/elma/Theme.cpp new file mode 100644 index 0000000..e965355 --- /dev/null +++ b/elma/Theme.cpp @@ -0,0 +1,128 @@ +/* + * $Id$ + * + * ELMA, Ede Login MAnager + * Part of Equinox Desktop Environment (EDE). + * Copyright (c) 2008 EDE Authors. + * + * This program is licensed under terms of the + * GNU General Public License version 2 or newer. + * See COPYING for details. + */ + +#include "Theme.h" +#include +#include +#include + +#define DEFAULT_THEME_FILE "elma.theme" + +ElmaTheme* elma_theme_init(const char* directory) { + edelib::String path; + path.printf("%s/%s", directory, DEFAULT_THEME_FILE); + + edelib::Config conf; + + if(!conf.load(path.c_str())) { + EWARNING(ESTRLOC ": Can' load %s\n", path.c_str()); + return NULL; + } + + ElmaTheme* et = new ElmaTheme; + char buff[1024]; + + conf.get("theme", "background", buff, sizeof(buff)); + et->background.printf("%s/%s", directory, buff); + + conf.get("theme", "panel", buff, sizeof(buff)); + et->panel.printf("%s/%s", directory, buff); + + conf.get("theme", "panel_x", et->panel_x, 5); + conf.get("theme", "panel_y", et->panel_y, 5); + + ThemeBox* info = new ThemeBox; + + conf.get("theme", "info_x", info->x, 5); + conf.get("theme", "info_y", info->y, 5); + conf.get("theme", "info_width", info->w, 5); + conf.get("theme", "info_height", info->h, 5); + conf.get("theme", "info_color", info->font_color, 255); // FL_WHITE default + conf.get("theme", "info_font_size", info->font_size, 12); + if(conf.get("theme", "info_text", buff, sizeof(buff))) + info->label = new edelib::String(buff); + else + info->label = NULL; + + et->info = info; + + ThemeBox* user = new ThemeBox; + + conf.get("theme", "username_x", user->x, 10); + conf.get("theme", "username_y", user->y, 10); + conf.get("theme", "username_width", user->w, 95); + conf.get("theme", "username_height", user->h, 25); + conf.get("theme", "username_color", user->font_color, 255); // FL_WHITE default + conf.get("theme", "username_font_size", user->font_size, 12); + if(conf.get("theme", "username_text", buff, sizeof(buff))) { + user->label = new edelib::String(buff); + // append few spaces + *(user->label) += " "; + } else + user->label = NULL; + + et->user = user; + + ThemeBox* pass = new ThemeBox; + + conf.get("theme", "password_x", pass->x, 50); + conf.get("theme", "password_y", pass->y, 50); + conf.get("theme", "password_width", pass->w, 95); + conf.get("theme", "password_height", pass->h, 25); + conf.get("theme", "password_color", pass->font_color, 255); // FL_WHITE default + conf.get("theme", "password_font_size", pass->font_size, 12); + if(conf.get("theme", "password_text", buff, sizeof(buff))) { + pass->label = new edelib::String(buff); + // append few spaces + *(pass->label) += " "; + } else + pass->label = NULL; + + et->pass = pass; + + ThemeBox* error = new ThemeBox; + + conf.get("theme", "error_x", error->x, 30); + conf.get("theme", "error_y", error->y, 30); + conf.get("theme", "error_width", error->w, 100); + conf.get("theme", "error_height", error->h, 25); + conf.get("theme", "error_color", error->font_color, 255); // FL_WHITE default + conf.get("theme", "error_font_size", error->font_size, 12); // FL_WHITE default + error->label = NULL; + + et->error = error; + + return et; +} + +void elma_theme_clear(ElmaTheme* et) { + if(!et) + return; + + if(et->info) { + delete et->info->label; + delete et->info; + } + + if(et->user) { + delete et->user->label; + delete et->user; + } + + if(et->pass) { + delete et->pass->label; + delete et->pass; + } + + delete et->error; + delete et; +} diff --git a/elma/Theme.h b/elma/Theme.h new file mode 100644 index 0000000..2070949 --- /dev/null +++ b/elma/Theme.h @@ -0,0 +1,41 @@ +/* + * $Id$ + * + * ELMA, Ede Login MAnager + * Part of Equinox Desktop Environment (EDE). + * Copyright (c) 2008 EDE Authors. + * + * This program is licensed under terms of the + * GNU General Public License version 2 or newer. + * See COPYING for details. + */ + +#ifndef __THEME_H__ +#define __THEME_H__ + +#include + +struct ThemeBox { + int x, y, w, h; + int font_color; + int font_size; + edelib::String* label; +}; + +struct ElmaTheme { + ThemeBox* info; + ThemeBox* user; + ThemeBox* pass; + ThemeBox* error; + + int panel_x; + int panel_y; + edelib::String panel; + + edelib::String background; +}; + +ElmaTheme* elma_theme_init(const char* directory); +void elma_theme_clear(ElmaTheme* et); + +#endif diff --git a/elma/elma.conf b/elma/elma.conf index 242439b..884acde 100644 --- a/elma/elma.conf +++ b/elma/elma.conf @@ -1,7 +1,7 @@ [elma] # path for X server -default_xserver = /usr/X11R6/bin/X +xserver = /usr/X11R6/bin/X # commands for login and halt halt = /sbin/shutdown -h now @@ -26,3 +26,6 @@ theme = default # enable/disable NumLock (1/0, true/false) numlock = true + +# enable/disable cursor +cursor = true diff --git a/elma/elma.cpp b/elma/elma.cpp index 5327bbf..999c73d 100644 --- a/elma/elma.cpp +++ b/elma/elma.cpp @@ -11,14 +11,21 @@ */ #include + +#if 0 #include #include #include #include +#include + #include "Background.h" #include "TextArea.h" #include "ElmaWindow.h" #include "NumLock.h" +#endif + +#include "ElmaService.h" #define CHECK_ARGV(argv, pshort, plong) ((strcmp(argv, pshort) == 0) || (strcmp(argv, plong) == 0)) @@ -29,6 +36,7 @@ void help(void) { puts("Options:"); puts(" -h, --help this help"); puts(" -c, --config [FILE] use FILE as config file"); + puts(" -d, --daemon daemon mode"); puts(" -t, --test test mode for theme preview (assume X server is running)\n"); } @@ -44,6 +52,7 @@ const char* next_param(int curr, char** argv, int argc) { int main(int argc, char** argv) { const char* config_file = NULL; bool test_mode = false; + bool daemon_mode = false; if(argc > 1) { const char* a; @@ -59,6 +68,8 @@ int main(int argc, char** argv) { return 1; } i++; + } else if(CHECK_ARGV(a, "-d", "--daemon")) { + daemon_mode = true; } else if(CHECK_ARGV(a, "-t", "--test")) { test_mode = true; } else { @@ -68,24 +79,19 @@ int main(int argc, char** argv) { } } - fl_open_display(); + ElmaService* service = ElmaService::instance(); - int dx, dy, dw, dh; - Fl::screen_xywh(dx, dy, dw, dh); - - numlock_xkb_init(fl_display); - - ElmaWindow* win = new ElmaWindow(dw, dh); - if(!win->load_everything()) { - delete win; + if(!service->load_config()) { + puts("Unable to load config file"); return 1; } - win->clear_border(); - win->show(); - win->cursor(FL_CURSOR_NONE); + if(!service->load_theme()) { + puts("Unable to load theme file"); + return 1; + } - numlock_off(fl_display); + service->display_window(); - return Fl::run(); + return 0; } diff --git a/elma/themes/default/elma.theme b/elma/themes/default/elma.theme new file mode 100644 index 0000000..4353b4d --- /dev/null +++ b/elma/themes/default/elma.theme @@ -0,0 +1,52 @@ +# +# Default theme inspired with one of the SLiM themes. +# +# Shows usage when username and password box are at the +# same x/y positions. +# +# Blame Sanel for this... + +[theme] + +# background image +background = background.jpg + +# panel image +panel = panel.png +panel_x = 235 +panel_y = 489 + +# info box +info_x = 10 +info_y = 10 +info_width = 484 +info_height = 28 +info_text = Welcome to EDE 2.0 +info_color = 12 +info_font_size = 12 + +# username box +username_x = 240 +username_y = 489 +username_width = 184 +username_height = 30 +username_color = 12 +username_font_size = 12 +username_text = Username: + +# password box +password_x = 240 +password_y = 489 +password_width = 184 +password_height = 30 +password_color = 12 +password_font_size = 12 +password_text = Password: + +# error box +error_x = 240 +error_y = 520 +error_width = 184 +error_height = 28 +error_font_size = 12 +error_color = 12 diff --git a/elma/themes/sky/background.jpg b/elma/themes/sky/background.jpg index 7a78049..7d8b745 100644 Binary files a/elma/themes/sky/background.jpg and b/elma/themes/sky/background.jpg differ diff --git a/elma/themes/sky/elma.theme b/elma/themes/sky/elma.theme new file mode 100644 index 0000000..01b5d1f --- /dev/null +++ b/elma/themes/sky/elma.theme @@ -0,0 +1,50 @@ +# +# sky theme +# +# Shows usage when username and password box have +# different x/y positions and are given without labels. +# +# Blame Sanel for this... + +[theme] + +# background image +background = background.jpg + +# panel image +panel = panel.png +panel_x = 347 +panel_y = 251 + +# info box +info_x = 10 +info_y = 10 +info_width = 484 +info_height = 28 +info_text = Welcome to EDE 2.0 +info_color = 12 +info_font_size = 12 + +# username box +username_x = 418 +username_y = 379 +username_width = 184 +username_height = 30 +username_color = 12 +username_font_size = 12 + +# password box +password_x = 418 +password_y = 431 +password_width = 184 +password_height = 30 +password_color = 12 +password_font_size = 12 + +# error box +error_x = 418 +error_y = 471 +error_width = 184 +error_height = 28 +error_font_size = 14 +error_color = 12 diff --git a/elma/themes/sky/panel.png b/elma/themes/sky/panel.png new file mode 100644 index 0000000..ac92f22 Binary files /dev/null and b/elma/themes/sky/panel.png differ