Work on theming support...

This commit is contained in:
Sanel Zukan
2008-02-18 14:46:13 +00:00
parent 0ad832e770
commit 44687cb3a6
14 changed files with 519 additions and 43 deletions

105
elma/ElmaService.cpp Normal file
View File

@ -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 <edelib/Config.h>
#include <FL/Fl.h>
#include <FL/x.h>
#include <stdlib.h>
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();
}

50
elma/ElmaService.h Normal file
View File

@ -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

View File

@ -19,6 +19,10 @@
#include "ElmaWindow.h" #include "ElmaWindow.h"
#include "Background.h" #include "Background.h"
#include "TextArea.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) { static void timeout_cb(void* e) {
ElmaWindow* win = (ElmaWindow*)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) { bkg(0), user_in(0), pass_in(0), error_display(0), info_display(0) {
deny_mode = false; deny_mode = false;
box_mode = USER_AND_PASS_BOX_VISIBLE;
} }
ElmaWindow::~ElmaWindow() { ElmaWindow::~ElmaWindow() {
} }
bool ElmaWindow::load_everything(void) { bool ElmaWindow::create_window(ElmaTheme* et) {
EASSERT(et != NULL);
begin(); begin();
bkg = new Background(0, 0, w(), h()); 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; return false;
//bkg->panel_pos(35, 189); bkg->panel_pos(et->panel_x, et->panel_y);
bkg->panel_pos(235, 489);
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->labelcolor(FL_WHITE);
user_in->textfont(FL_HELVETICA_BOLD); 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: "); tb = et->pass;
pass_in = new TextArea(240, 489, 184, 30, "Password: "); 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->labelcolor(FL_WHITE);
pass_in->textfont(FL_HELVETICA_BOLD); pass_in->textfont(FL_HELVETICA_BOLD);
pass_in->textsize(14); pass_in->textsize(tb->font_size);
pass_in->type(FL_SECRET_INPUT);
pass_in->hide();
//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->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_CLIP);
error_display->labelcolor(FL_WHITE); error_display->labelcolor(FL_WHITE);
error_display->labelsize(14); error_display->labelsize(tb->font_size);
error_display->hide(); 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->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_CLIP);
info_display->labelcolor(FL_GRAY); info_display->labelcolor(FL_GRAY);
info_display->label("EDE version 2.0"); if(tb->label)
info_display->label(tb->label->c_str());
end(); end();
return true; return true;
@ -114,16 +139,27 @@ int ElmaWindow::handle(int event) {
return 1; return 1;
if(Fl::event_key() == FL_Enter) { if(Fl::event_key() == FL_Enter) {
if(user_in->visible()) { if(box_mode == USER_AND_PASS_BOX_VISIBLE) {
user_in->hide(); if(Fl::focus() == user_in)
pass_in->show(); Fl::focus(pass_in);
// don't remember password else {
pass_in->value(0); validate_user();
// don't remember password
pass_in->value(0);
Fl::focus(user_in);
}
} else { } else {
user_in->show(); if(user_in->visible()) {
pass_in->hide(); 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; return 1;

View File

@ -18,6 +18,7 @@
class Background; class Background;
class TextArea; class TextArea;
class Fl_Box; class Fl_Box;
struct ElmaTheme;
class ElmaWindow : public Fl_Double_Window { class ElmaWindow : public Fl_Double_Window {
private: private:
@ -27,6 +28,7 @@ class ElmaWindow : public Fl_Double_Window {
Fl_Box* error_display; Fl_Box* error_display;
Fl_Box* info_display; Fl_Box* info_display;
bool deny_mode; bool deny_mode;
int box_mode;
void validate_user(void); void validate_user(void);
@ -37,7 +39,7 @@ class ElmaWindow : public Fl_Double_Window {
void allow_input(void); void allow_input(void);
void deny_input(void); void deny_input(void);
bool load_everything(void); bool create_window(ElmaTheme* et);
virtual int handle(int event); virtual int handle(int event);
}; };
#endif #endif

View File

@ -10,7 +10,7 @@
SubDir TOP elma ; 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) ; EdeProgram elma : $(SOURCE) ;
TranslationStrings locale : $(SOURCE) ; TranslationStrings locale : $(SOURCE) ;

View File

@ -14,7 +14,6 @@
#define __TEXTAREA_H__ #define __TEXTAREA_H__
#include <FL/Fl_Input.h> #include <FL/Fl_Input.h>
#include <edelib/Debug.h> #include <edelib/Debug.h>
/* /*
@ -40,6 +39,10 @@ class TextArea : public Fl_Input {
if(event == FL_SHOW || event == FL_HIDE) if(event == FL_SHOW || event == FL_HIDE)
return 1; return 1;
// don't allow input when we are disabled
if(event == FL_KEYBOARD && !active())
return 1;
int ret = Fl_Input::handle(event); int ret = Fl_Input::handle(event);
if(ret); if(ret);
parent()->damage(FL_DAMAGE_ALL, x(), y(), w(), h()); parent()->damage(FL_DAMAGE_ALL, x(), y(), w(), h());

128
elma/Theme.cpp Normal file
View File

@ -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 <edelib/Config.h>
#include <edelib/File.h>
#include <edelib/Debug.h>
#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;
}

41
elma/Theme.h Normal file
View File

@ -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 <edelib/String.h>
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

View File

@ -1,7 +1,7 @@
[elma] [elma]
# path for X server # path for X server
default_xserver = /usr/X11R6/bin/X xserver = /usr/X11R6/bin/X
# commands for login and halt # commands for login and halt
halt = /sbin/shutdown -h now halt = /sbin/shutdown -h now
@ -26,3 +26,6 @@ theme = default
# enable/disable NumLock (1/0, true/false) # enable/disable NumLock (1/0, true/false)
numlock = true numlock = true
# enable/disable cursor
cursor = true

View File

@ -11,14 +11,21 @@
*/ */
#include <stdio.h> #include <stdio.h>
#if 0
#include <string.h> #include <string.h>
#include <FL/x.h> #include <FL/x.h>
#include <FL/Fl.h> #include <FL/Fl.h>
#include <edelib/String.h> #include <edelib/String.h>
#include <edelib/Config.h>
#include "Background.h" #include "Background.h"
#include "TextArea.h" #include "TextArea.h"
#include "ElmaWindow.h" #include "ElmaWindow.h"
#include "NumLock.h" #include "NumLock.h"
#endif
#include "ElmaService.h"
#define CHECK_ARGV(argv, pshort, plong) ((strcmp(argv, pshort) == 0) || (strcmp(argv, plong) == 0)) #define CHECK_ARGV(argv, pshort, plong) ((strcmp(argv, pshort) == 0) || (strcmp(argv, plong) == 0))
@ -29,6 +36,7 @@ void help(void) {
puts("Options:"); puts("Options:");
puts(" -h, --help this help"); puts(" -h, --help this help");
puts(" -c, --config [FILE] use FILE as config file"); 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"); 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) { int main(int argc, char** argv) {
const char* config_file = NULL; const char* config_file = NULL;
bool test_mode = false; bool test_mode = false;
bool daemon_mode = false;
if(argc > 1) { if(argc > 1) {
const char* a; const char* a;
@ -59,6 +68,8 @@ int main(int argc, char** argv) {
return 1; return 1;
} }
i++; i++;
} else if(CHECK_ARGV(a, "-d", "--daemon")) {
daemon_mode = true;
} else if(CHECK_ARGV(a, "-t", "--test")) { } else if(CHECK_ARGV(a, "-t", "--test")) {
test_mode = true; test_mode = true;
} else { } else {
@ -68,24 +79,19 @@ int main(int argc, char** argv) {
} }
} }
fl_open_display(); ElmaService* service = ElmaService::instance();
int dx, dy, dw, dh; if(!service->load_config()) {
Fl::screen_xywh(dx, dy, dw, dh); puts("Unable to load config file");
numlock_xkb_init(fl_display);
ElmaWindow* win = new ElmaWindow(dw, dh);
if(!win->load_everything()) {
delete win;
return 1; return 1;
} }
win->clear_border(); if(!service->load_theme()) {
win->show(); puts("Unable to load theme file");
win->cursor(FL_CURSOR_NONE); return 1;
}
numlock_off(fl_display); service->display_window();
return Fl::run(); return 0;
} }

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -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

BIN
elma/themes/sky/panel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB