2009-01-23 16:12:52 +03:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ede-screensaver-conf, a tool to configure screensaver
|
|
|
|
* Part of Equinox Desktop Environment (EDE).
|
|
|
|
* Copyright (c) 2009 Sanel Zukan <karijes@equinox-project.org>
|
|
|
|
*
|
|
|
|
* This program is licensed under the terms of the
|
|
|
|
* GNU General Public License version 2 or later.
|
|
|
|
* See COPYING for the details.
|
|
|
|
*/
|
|
|
|
|
2010-03-28 16:54:45 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-01-09 19:32:14 +03:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Double_Window.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
#include <FL/Fl_Choice.H>
|
|
|
|
#include <FL/Fl_Spinner.H>
|
|
|
|
#include <FL/Fl_Check_Button.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Pixmap.H>
|
2009-01-12 16:49:54 +03:00
|
|
|
#include <FL/x.H>
|
2009-01-09 19:32:14 +03:00
|
|
|
|
|
|
|
#include <edelib/Debug.h>
|
2012-05-07 12:53:13 +04:00
|
|
|
#include <edelib/WindowUtils.h>
|
2010-03-28 16:54:45 +04:00
|
|
|
#include <edelib/Ede.h>
|
2009-01-09 19:32:14 +03:00
|
|
|
|
|
|
|
#include "XScreenSaver.h"
|
|
|
|
#include "icons/energy.xpm"
|
|
|
|
|
2012-05-07 12:53:13 +04:00
|
|
|
EDELIB_NS_USING(window_center_on_screen)
|
|
|
|
|
2009-03-30 19:17:00 +04:00
|
|
|
static Fl_Pixmap image_energy((const char**)energy_star_xpm);
|
2009-01-09 19:32:14 +03:00
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
static Fl_Spinner* standby_val;
|
|
|
|
static Fl_Spinner* suspend_val;
|
|
|
|
static Fl_Spinner* off_val;
|
2009-01-13 17:21:59 +03:00
|
|
|
static Fl_Spinner* timeout_val;
|
2009-01-12 16:49:54 +03:00
|
|
|
static Fl_Double_Window* main_win;
|
|
|
|
static Fl_Double_Window* preview_win;
|
2009-01-09 19:32:14 +03:00
|
|
|
|
2014-12-04 20:08:01 +03:00
|
|
|
static bool hacks_sorter(SaverHack* const& a, SaverHack* const& b) {
|
|
|
|
return a->name < b->name;
|
|
|
|
}
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
static void dpms_enable_cb(Fl_Widget* w, void* s) {
|
2009-01-09 19:32:14 +03:00
|
|
|
Fl_Check_Button* o = (Fl_Check_Button*)w;
|
2009-01-12 16:49:54 +03:00
|
|
|
SaverPrefs* sp = (SaverPrefs*)s;
|
|
|
|
|
2009-01-09 19:32:14 +03:00
|
|
|
if(o->value()) {
|
|
|
|
standby_val->activate();
|
|
|
|
suspend_val->activate();
|
|
|
|
off_val->activate();
|
|
|
|
} else {
|
|
|
|
standby_val->deactivate();
|
|
|
|
suspend_val->deactivate();
|
|
|
|
off_val->deactivate();
|
|
|
|
}
|
2009-01-12 16:49:54 +03:00
|
|
|
|
|
|
|
sp->dpms_enabled = o->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void choice_cb(Fl_Widget* w, void* s) {
|
|
|
|
Fl_Choice* c = (Fl_Choice*)w;
|
|
|
|
SaverPrefs* sp = (SaverPrefs*)s;
|
|
|
|
|
|
|
|
const char* saver_name = c->text();
|
|
|
|
if(!saver_name)
|
|
|
|
return;
|
|
|
|
|
2009-01-13 16:38:54 +03:00
|
|
|
/* when we want to disable it */
|
|
|
|
if(strcmp(saver_name, "(None)") == 0) {
|
|
|
|
xscreensaver_kill_preview();
|
|
|
|
/* just draw an empty box */
|
|
|
|
Fl_Box* b = new Fl_Box(0, 0, 180, 134);
|
|
|
|
preview_win->add(b);
|
|
|
|
preview_win->redraw();
|
|
|
|
|
|
|
|
sp->mode = SAVER_OFF;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-13 17:21:59 +03:00
|
|
|
/* FIXME: for now only one is allowed */
|
|
|
|
sp->mode = SAVER_ONE;
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
/* find the name matches in our list and run it's command */
|
|
|
|
HackListIter it = sp->hacks.begin(), it_end = sp->hacks.end();
|
|
|
|
for(; it != it_end; ++it) {
|
|
|
|
if((*it)->name == saver_name) {
|
|
|
|
xscreensaver_preview(fl_xid(preview_win), (*it)->exec.c_str());
|
|
|
|
sp->curr_hack = (*it)->sindex;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void close_cb(Fl_Widget*, void*) {
|
|
|
|
xscreensaver_kill_preview();
|
|
|
|
preview_win->hide();
|
|
|
|
main_win->hide();
|
2009-01-09 19:32:14 +03:00
|
|
|
}
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
static void ok_cb(Fl_Widget*, void* s) {
|
|
|
|
SaverPrefs* sp = (SaverPrefs*)s;
|
2009-01-13 17:21:59 +03:00
|
|
|
if(sp) {
|
|
|
|
sp->timeout = (int)timeout_val->value();
|
|
|
|
sp->dpms_standby = (int)standby_val->value();
|
|
|
|
sp->dpms_suspend = (int)suspend_val->value();
|
|
|
|
sp->dpms_off = (int)off_val->value();
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
xscreensaver_save_config(sp);
|
2009-01-13 17:21:59 +03:00
|
|
|
}
|
2009-01-12 16:49:54 +03:00
|
|
|
close_cb(0, 0);
|
2009-01-09 19:32:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2010-03-28 16:54:45 +04:00
|
|
|
EDE_APPLICATION("ede-screensaver-conf");
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
fl_open_display();
|
|
|
|
/* start daemon if not started */
|
|
|
|
xscreensaver_run_daemon(fl_display);
|
|
|
|
|
2009-01-09 19:32:14 +03:00
|
|
|
SaverPrefs* sp = xscreensaver_read_config();
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
main_win = new Fl_Double_Window(340, 445, _("Screensaver options"));
|
|
|
|
/* so ESC does not interrupt running process */
|
|
|
|
main_win->callback(close_cb);
|
|
|
|
|
|
|
|
main_win->begin();
|
2009-01-09 19:32:14 +03:00
|
|
|
/* monitor */
|
|
|
|
Fl_Box* b1 = new Fl_Box(120, 163, 100, 15);
|
|
|
|
b1->box(FL_BORDER_BOX);
|
|
|
|
Fl_Box* b2 = new Fl_Box(65, 10, 210, 158);
|
|
|
|
b2->box(FL_THIN_UP_BOX);
|
2009-01-12 16:49:54 +03:00
|
|
|
|
2009-01-09 19:32:14 +03:00
|
|
|
Fl_Box* b3 = new Fl_Box(78, 20, 184, 138);
|
|
|
|
b3->color(FL_BLACK);
|
2009-01-12 16:49:54 +03:00
|
|
|
b3->box(FL_DOWN_BOX);
|
|
|
|
|
|
|
|
/* preview window in 'b3' box */
|
|
|
|
preview_win = new Fl_Double_Window(80, 22, 180, 134);
|
|
|
|
preview_win->color(FL_BLACK);
|
|
|
|
preview_win->begin();
|
|
|
|
|
|
|
|
/* if failed to load any screensaver */
|
|
|
|
if(!sp) {
|
|
|
|
Fl_Box* b4 = new Fl_Box(0, 0, 180, 134, _("No screensavers found"));
|
|
|
|
b4->labelcolor(FL_GRAY);
|
|
|
|
b4->align(FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
preview_win->end();
|
|
|
|
|
2009-01-09 19:32:14 +03:00
|
|
|
Fl_Box* b4 = new Fl_Box(95, 173, 146, 14);
|
|
|
|
b4->box(FL_THIN_UP_BOX);
|
|
|
|
|
|
|
|
Fl_Group* g1 = new Fl_Group(10, 215, 320, 45, _("Screensaver"));
|
|
|
|
g1->box(FL_ENGRAVED_BOX);
|
|
|
|
g1->align(FL_ALIGN_TOP_LEFT);
|
|
|
|
g1->begin();
|
|
|
|
Fl_Choice* saver_list = new Fl_Choice(19, 225, 180, 25);
|
|
|
|
saver_list->down_box(FL_BORDER_BOX);
|
2009-01-13 16:38:54 +03:00
|
|
|
saver_list->add("(None)", 0, 0);
|
2009-01-09 19:32:14 +03:00
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
if(sp) {
|
2009-01-13 16:38:54 +03:00
|
|
|
int sel = 0;
|
2009-01-13 17:21:59 +03:00
|
|
|
saver_list->callback((Fl_Callback*)choice_cb, sp);
|
2009-01-12 16:49:54 +03:00
|
|
|
|
|
|
|
/* fix possible error */
|
|
|
|
if(sp->curr_hack >= sp->hacks.size())
|
2009-01-13 17:21:59 +03:00
|
|
|
sp->curr_hack = 0;
|
2009-01-12 16:49:54 +03:00
|
|
|
|
2014-12-04 20:08:01 +03:00
|
|
|
sp->hacks.sort(hacks_sorter);
|
2009-01-12 16:49:54 +03:00
|
|
|
HackListIter it = sp->hacks.begin(), it_end = sp->hacks.end();
|
2009-01-13 17:21:59 +03:00
|
|
|
for(int i = 1; it != it_end; ++it, i++) {
|
2009-01-12 16:49:54 +03:00
|
|
|
saver_list->add((*it)->name.c_str(), 0, 0);
|
|
|
|
|
|
|
|
/*
|
2009-01-13 17:21:59 +03:00
|
|
|
* Check real hack index number against current one and let it match
|
|
|
|
* position in our Fl_Choice list. Note that first item is '(None)'
|
|
|
|
* so 'i' starts from 1
|
2009-01-12 16:49:54 +03:00
|
|
|
*/
|
2009-01-13 17:21:59 +03:00
|
|
|
if(sp->mode != SAVER_OFF && (*it)->sindex == sp->curr_hack)
|
2009-01-12 16:49:54 +03:00
|
|
|
sel = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
saver_list->value(sel);
|
2009-01-09 19:32:14 +03:00
|
|
|
}
|
|
|
|
|
2009-01-13 17:21:59 +03:00
|
|
|
timeout_val = new Fl_Spinner(275, 226, 45, 25, _("Timeout:"));
|
|
|
|
timeout_val->tooltip(_("Idle time in minutes after screensaver is started"));
|
|
|
|
timeout_val->range(1, 500);
|
2009-01-12 16:49:54 +03:00
|
|
|
if(sp)
|
2009-01-13 17:21:59 +03:00
|
|
|
timeout_val->value(sp->timeout);
|
2009-01-12 16:49:54 +03:00
|
|
|
else
|
2009-01-13 17:21:59 +03:00
|
|
|
timeout_val->value(1);
|
2009-01-12 16:49:54 +03:00
|
|
|
|
2009-01-09 19:32:14 +03:00
|
|
|
g1->end();
|
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
Fl_Group* g2 = new Fl_Group(10, 290, 320, 110, _("Power management"));
|
2009-01-09 19:32:14 +03:00
|
|
|
g2->box(FL_ENGRAVED_BOX);
|
|
|
|
g2->align(FL_ALIGN_TOP_LEFT);
|
|
|
|
g2->begin();
|
|
|
|
Fl_Check_Button* denabled = new Fl_Check_Button(20, 299, 180, 26, _("Enabled"));
|
|
|
|
denabled->down_box(FL_DOWN_BOX);
|
|
|
|
denabled->tooltip(_("Enable or disable Display Power Management Signaling support"));
|
2009-10-08 13:45:27 +04:00
|
|
|
if(sp) {
|
|
|
|
denabled->callback((Fl_Callback*)dpms_enable_cb, sp);
|
2009-01-12 16:49:54 +03:00
|
|
|
denabled->value(sp->dpms_enabled);
|
2009-10-08 13:45:27 +04:00
|
|
|
} else {
|
2009-01-13 16:38:54 +03:00
|
|
|
denabled->value(1);
|
2009-10-08 13:45:27 +04:00
|
|
|
}
|
2009-01-09 19:32:14 +03:00
|
|
|
|
|
|
|
Fl_Box* energy_image = new Fl_Box(20, 341, 75, 49);
|
|
|
|
energy_image->image(image_energy);
|
|
|
|
|
|
|
|
standby_val = new Fl_Spinner(275, 301, 45, 24, _("Standby:"));
|
|
|
|
standby_val->tooltip(_("Minutes for standby"));
|
2009-01-13 16:38:54 +03:00
|
|
|
standby_val->range(1, 500);
|
2009-01-12 16:49:54 +03:00
|
|
|
if(sp)
|
|
|
|
standby_val->value(sp->dpms_standby);
|
|
|
|
else
|
2009-01-13 16:38:54 +03:00
|
|
|
standby_val->value(1);
|
2009-01-09 19:32:14 +03:00
|
|
|
|
|
|
|
suspend_val = new Fl_Spinner(275, 331, 45, 24, _("Suspend:"));
|
|
|
|
suspend_val->tooltip(_("Minutes for suspend"));
|
2009-01-13 16:38:54 +03:00
|
|
|
suspend_val->range(1, 500);
|
2009-01-12 16:49:54 +03:00
|
|
|
if(sp)
|
|
|
|
suspend_val->value(sp->dpms_suspend);
|
|
|
|
else
|
2009-01-13 16:38:54 +03:00
|
|
|
suspend_val->value(1);
|
2009-01-09 19:32:14 +03:00
|
|
|
|
|
|
|
off_val = new Fl_Spinner(275, 360, 45, 24, _("Off:"));
|
|
|
|
off_val->tooltip(_("Minutes to turn off the screen"));
|
2009-01-13 16:38:54 +03:00
|
|
|
off_val->range(1, 500);
|
2009-01-12 16:49:54 +03:00
|
|
|
if(sp)
|
|
|
|
off_val->value(sp->dpms_off);
|
|
|
|
else
|
2009-01-13 16:38:54 +03:00
|
|
|
off_val->value(1);
|
2009-01-09 19:32:14 +03:00
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
/* execute callback to apply changes before main_window is shown */
|
2009-01-09 19:32:14 +03:00
|
|
|
denabled->do_callback();
|
|
|
|
g2->end();
|
|
|
|
|
|
|
|
Fl_Button* ok_button = new Fl_Button(145, 410, 90, 25, _("&OK"));
|
2009-01-12 16:49:54 +03:00
|
|
|
ok_button->callback(ok_cb, sp);
|
2009-01-09 19:32:14 +03:00
|
|
|
|
|
|
|
Fl_Button* close_button = new Fl_Button(240, 410, 90, 25, _("&Cancel"));
|
2009-01-12 16:49:54 +03:00
|
|
|
close_button->callback(close_cb);
|
|
|
|
main_win->end();
|
|
|
|
|
2012-05-07 12:53:13 +04:00
|
|
|
window_center_on_screen(main_win);
|
2009-01-12 16:49:54 +03:00
|
|
|
main_win->show(argc, argv);
|
|
|
|
/* run preview immediately */
|
|
|
|
saver_list->do_callback();
|
|
|
|
int ret = Fl::run();
|
|
|
|
|
|
|
|
if(sp) {
|
|
|
|
HackListIter it = sp->hacks.begin(), it_end = sp->hacks.end();
|
|
|
|
for(; it != it_end; ++it)
|
|
|
|
delete *it;
|
|
|
|
delete sp;
|
|
|
|
}
|
2009-01-09 19:32:14 +03:00
|
|
|
|
2009-01-12 16:49:54 +03:00
|
|
|
return ret;
|
2009-01-09 19:32:14 +03:00
|
|
|
}
|