From e49a07163434b095e756a5717329589b44b56616 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Tue, 13 Jan 2009 14:21:59 +0000 Subject: [PATCH] Let vrious DPMS and screensaver timeout be written. Corrected merging temporary file with our values with .xscreensaver one if exists, and if not, re-create .xscreensaver again --- ede-screensaver-conf/XScreenSaver.cpp | 44 ++++++++++++++++--- ede-screensaver-conf/ede-screensaver-conf.cpp | 37 ++++++++++------ 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/ede-screensaver-conf/XScreenSaver.cpp b/ede-screensaver-conf/XScreenSaver.cpp index 57fad3f..d25f78e 100644 --- a/ede-screensaver-conf/XScreenSaver.cpp +++ b/ede-screensaver-conf/XScreenSaver.cpp @@ -22,6 +22,7 @@ EDELIB_NS_USING(String) EDELIB_NS_USING(file_path) EDELIB_NS_USING(file_remove) +EDELIB_NS_USING(file_rename) EDELIB_NS_USING(run_program) EDELIB_NS_USING(dir_home) EDELIB_NS_USING(dir_exists) @@ -483,10 +484,27 @@ void xscreensaver_save_config(SaverPrefs *sp) { fprintf(fd, "# XScreenSaver Preferences File\n"); fprintf(fd, "# Written by ede-screensaver-conf\n\n"); + const char* val; + + switch(sp->mode) { + case SAVER_OFF: + val = "off"; + break; + case SAVER_BLANK: + val = "blank"; + break; + case SAVER_RANDOM: + val = "random"; + break; + default: + val = "one"; + break; + } + + fprintf(fd, "mode: %s\n", val); fprintf(fd, "selected: %i\n", sp->curr_hack); fprintf(fd, "timeout: 00:%i:00\n", sp->timeout); - const char* val; if(sp->dpms_enabled) val = "yes"; @@ -504,22 +522,34 @@ void xscreensaver_save_config(SaverPrefs *sp) { fprintf(fd, "\t\t \"%s\" %s\t\t \\n\\\n", (*it)->name.c_str(), (*it)->exec.c_str()); fprintf(fd, "\n\n"); + + /* some defaults */ + fprintf(fd, "sgiSaverExtension: True\n"); + fprintf(fd, "xidleExtension: True\n"); + fprintf(fd, "procInterrupts: True\n"); + fprintf(fd, "GetViewPortIsFullOfLies: False\n"); + fprintf(fd, "demoCommand: xscreensaver-demo\n"); + fprintf(fd, "prefsCommand: xscreensaver-demo -prefs\n"); + fclose(fd); /* - * now open it as Xresource database and merge with the real ~/.xscreensaver - * file, so other values we didn't wrote/used are preserved + * Now open it as Xresource database and merge with the real ~/.xscreensaver + * file, so other values we didn't wrote/used are preserved. If it does not + * exists, save it as ordinary file */ XrmInitialize(); - XrmDatabase db = XrmGetFileDatabase(tmp_path.c_str()); + + XrmDatabase db = XrmGetFileDatabase(path.c_str()); if(db) { - XrmCombineFileDatabase(path.c_str(), &db, 1); + XrmCombineFileDatabase(tmp_path.c_str(), &db, True); /* and store it as ~/.xscreensaver */ XrmPutFileDatabase(db, path.c_str()); XrmDestroyDatabase(db); + file_remove(tmp_path.c_str()); + } else { + file_rename(tmp_path.c_str(), path.c_str()); } - - //file_remove(tmp_path.c_str()); } /* run screensaver in in FLTK window */ diff --git a/ede-screensaver-conf/ede-screensaver-conf.cpp b/ede-screensaver-conf/ede-screensaver-conf.cpp index 255c6c8..e496e01 100644 --- a/ede-screensaver-conf/ede-screensaver-conf.cpp +++ b/ede-screensaver-conf/ede-screensaver-conf.cpp @@ -20,6 +20,7 @@ static Fl_Pixmap image_energy(energy_star_xpm); static Fl_Spinner* standby_val; static Fl_Spinner* suspend_val; static Fl_Spinner* off_val; +static Fl_Spinner* timeout_val; static Fl_Double_Window* main_win; static Fl_Double_Window* preview_win; @@ -60,6 +61,9 @@ static void choice_cb(Fl_Widget* w, void* s) { return; } + /* FIXME: for now only one is allowed */ + sp->mode = SAVER_ONE; + /* 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) { @@ -79,8 +83,14 @@ static void close_cb(Fl_Widget*, void*) { static void ok_cb(Fl_Widget*, void* s) { SaverPrefs* sp = (SaverPrefs*)s; - if(sp) + 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(); + xscreensaver_save_config(sp); + } close_cb(0, 0); } @@ -132,37 +142,36 @@ int main(int argc, char **argv) { saver_list->add("(None)", 0, 0); if(sp) { - saver_list->callback((Fl_Callback*)choice_cb, sp); - - /* 1 is first item, 0 is '(None)' */ int sel = 0; + saver_list->callback((Fl_Callback*)choice_cb, sp); /* fix possible error */ if(sp->curr_hack >= sp->hacks.size()) - sp->curr_hack = 1; + sp->curr_hack = 0; HackListIter it = sp->hacks.begin(), it_end = sp->hacks.end(); - for(int i = 0; it != it_end; ++it, i++) { + for(int i = 1; it != it_end; ++it, i++) { saver_list->add((*it)->name.c_str(), 0, 0); /* - * check real hack index number against current one - * and let it match position in our Fl_Choice list + * 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 */ - if(sp->mode != SAVER_OFF && sel == 0 && (*it)->sindex == sp->curr_hack) + if(sp->mode != SAVER_OFF && (*it)->sindex == sp->curr_hack) sel = i; } saver_list->value(sel); } - Fl_Spinner* timeout = new Fl_Spinner(275, 226, 45, 25, _("Timeout:")); - timeout->tooltip(_("Idle time in minutes after screensaver is started")); - timeout->range(1, 500); + 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); if(sp) - timeout->value(sp->timeout); + timeout_val->value(sp->timeout); else - timeout->value(1); + timeout_val->value(1); g1->end();