Fix button state saving. Save background and button configurations separately.

SVN revision: 13627
This commit is contained in:
Kim Woelders 2005-03-05 12:19:48 +00:00
parent 13efa62f2e
commit e1bc051e9e
6 changed files with 103 additions and 66 deletions

View File

@ -1206,7 +1206,6 @@ void ArrangeEwins(const char *params);
/* backgrounds.c */
int BackgroundsConfigLoad(FILE * fs);
int BackgroundsConfigSave(FILE * fs);
char *BackgroundGetUniqueString(Background * bg);
void BackgroundPixmapFree(Background * bg);
void BackgroundImagesFree(Background * bg, int free_pmap);
@ -1259,7 +1258,6 @@ void BordersSetupFallback(void);
/* buttons.c */
int ButtonsConfigLoad(FILE * fs);
int ButtonsConfigSave(FILE * fs);
Button *ButtonCreate(const char *name, int id, ImageClass * ic,
ActionClass * aclass, TextClass * tclass,
char *label, char ontop, int flags, int minw,
@ -1332,8 +1330,8 @@ char *ConfigFileFind(const char *name, const char *themepath,
int pp);
int ConfigFileLoad(const char *name, const char *themepath,
int (*parse) (FILE * fs), int preparse);
int ConfigFileRead(FILE * fs);
int ThemeConfigLoad(void);
void SaveUserControlConfig(void);
void RecoverUserConfig(void);
/* coords.c */

View File

@ -1113,16 +1113,38 @@ BackgroundsConfigLoad(FILE * fs)
return err;
}
int
BackgroundsConfigSave(FILE * fs)
static void
BackgroundsConfigLoadUser(void)
{
char s[4096];
Esnprintf(s, sizeof(s), "%s.backgrounds", EGetSavePrefix());
if (ConfigFileLoad(s, NULL, ConfigFileRead, 0))
{
/* FIXME - Keep around a bit, and then remove */
Esnprintf(s, sizeof(s), "%s.misc", EGetSavePrefix());
Eprintf("Fallback - loading %s\n", s);
ConfigFileLoad(s, NULL, ConfigFileRead, 0);
}
}
static void
BackgroundsConfigSave(void)
{
char s[FILEPATH_LEN_MAX], st[FILEPATH_LEN_MAX];
FILE *fs;
int i, num;
Background **bglist;
int j, b, r, g;
bglist = (Background **) ListItemType(&num, LIST_TYPE_BACKGROUND);
if (num <= 0)
return 0;
return;
Etmp(st);
fs = fopen(st, "w");
if (!fs)
return;
for (i = num - 1; i >= 0; i--)
{
@ -1186,9 +1208,13 @@ BackgroundsConfigSave(FILE * fs)
fprintf(fs, "1000\n");
}
Efree(bglist);
return 0;
fclose(fs);
Esnprintf(s, sizeof(s), "%s.backgrounds", EGetSavePrefix());
E_mv(st, s);
Efree(bglist);
}
/*
@ -1267,10 +1293,19 @@ BackgroundsSighan(int sig, void *prm __UNUSED__)
BackgroundCreate("NONE", NULL, NULL, 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0,
0);
break;
case ESIGNAL_CONFIGURE:
BackgroundsConfigLoadUser();
break;
case ESIGNAL_START:
DoIn("BACKGROUND_ACCOUNTING_TIMEOUT", 30.0, BackgroundsTimeout, 0,
NULL);
break;
case ESIGNAL_EXIT:
BackgroundsConfigSave();
break;
}
}

View File

@ -66,7 +66,8 @@ struct _button
static struct
{
Button *button;
} Mode_button;
char loading_user;
} Mode_buttons;
static void ButtonHandleEvents(XEvent * ev, void *btn);
@ -650,7 +651,7 @@ ButtonEventMouseDown(Button * b, XEvent * ev)
Window win = ev->xbutton.window;
ActionClass *ac;
Mode_button.button = b;
Mode_buttons.button = b;
GrabPointerSet(win, ECSR_GRAB, 0);
@ -695,8 +696,8 @@ ButtonEventMouseUp(Button * b, XEvent * ev)
b->left = 0;
if (Mode.mode == MODE_BUTTONDRAG)
ButtonDragEnd(Mode_button.button);
Mode_button.button = NULL;
ButtonDragEnd(Mode_buttons.button);
Mode_buttons.button = NULL;
GrabPointerRelease();
}
@ -860,7 +861,7 @@ ButtonsConfigLoad(FILE * ConfigFile)
switch (i1)
{
case CONFIG_CLOSE:
if (!pbt)
if (!pbt && !Mode_buttons.loading_user)
{
bt = ButtonCreate(name, 0, ic, ac, tc, label, ontop, flags,
minw, maxw, minh, maxh, xo, yo, xa, xr,
@ -876,9 +877,13 @@ ButtonsConfigLoad(FILE * ConfigFile)
pbt->tclass = tc;
break;
case BUTTON_LABEL:
_EFREE(label);
label = Estrdup(atword(s, 2));
if (pbt)
pbt->label = label;
{
_EFREE(pbt->label);
pbt->label = label;
}
break;
case BORDERPART_ONTOP:
ontop = atoi(s2);
@ -887,8 +892,7 @@ ButtonsConfigLoad(FILE * ConfigFile)
break;
case CONFIG_CLASSNAME:
case BUTTON_NAME:
if (name)
Efree(name);
_EFREE(name);
name = Estrdup(s2);
pbt = FindItem(name, 0, LIST_FINDBY_NAME, LIST_TYPE_BUTTON);
break;
@ -1011,23 +1015,41 @@ ButtonsConfigLoad(FILE * ConfigFile)
err = -1;
done:
if (name)
Efree(name);
_EFREE(name);
_EFREE(label);
return err;
}
int
ButtonsConfigSave(FILE * fs)
static void
ButtonsConfigLoadUser(void)
{
#if 0
char s[4096];
Esnprintf(s, sizeof(s), "%s.buttons", EGetSavePrefix());
Mode_buttons.loading_user = 1;
ConfigFileLoad(s, NULL, ConfigFileRead, 0);
Mode_buttons.loading_user = 0;
}
static void
ButtonsConfigSave(void)
{
char s[FILEPATH_LEN_MAX], st[FILEPATH_LEN_MAX];
FILE *fs;
int i, num;
Button **blst;
int flags;
blst = (Button **) ListItemTypeID(&num, LIST_TYPE_BUTTON, 0);
if (!blst)
return 0;
return;
Etmp(st);
fs = fopen(st, "w");
if (!fs)
return;
for (i = 0; i < num; i++)
{
@ -1080,12 +1102,13 @@ ButtonsConfigSave(FILE * fs)
}
fprintf(fs, "1000\n");
}
Efree(blst);
#else
fs = NULL;
#endif
return 0;
fclose(fs);
Esnprintf(s, sizeof(s), "%s.buttons", EGetSavePrefix());
E_mv(st, s);
Efree(blst);
}
/*
@ -1097,7 +1120,16 @@ ButtonsSighan(int sig, void *prm __UNUSED__)
{
switch (sig)
{
default:
case ESIGNAL_INIT:
memset(&Mode_buttons, 0, sizeof(Mode_buttons));
break;
case ESIGNAL_CONFIGURE:
ButtonsConfigLoadUser();
break;
case ESIGNAL_EXIT:
ButtonsConfigSave();
break;
}
}
@ -1222,8 +1254,8 @@ ButtonsIpc(const char *params, Client * c __UNUSED__)
}
else if (!strncmp(cmd, "move", 2))
{
if (Mode_button.button)
ButtonDragStart(Mode_button.button);
if (Mode_buttons.button)
ButtonDragStart(Mode_buttons.button);
}
}

View File

@ -234,7 +234,7 @@ ConfigFilePreparse(const char *path, const char *dest)
}
/* Split the process of finding the file from the process of loading it */
static int
int
ConfigFileRead(FILE * fs)
{
int err;
@ -478,6 +478,7 @@ ConfigFileLoad(const char *name, const char *themepath,
file = ConfigFileFind(name, themepath, preparse);
if (!file)
goto done;
fs = fopen(file, "r");
Efree(file);
if (!fs)
@ -548,47 +549,15 @@ ThemeConfigLoad(void)
if (p)
ProgressbarDestroy(p);
/* No longer needed */
/* Font mappings no longer needed */
FontConfigUnload();
/* Loose ends... */
Esnprintf(s, sizeof(s), "%s.misc", EGetSavePrefix());
ConfigFileLoad(s, NULL, ConfigFileRead, 0);
BordersSetupFallback();
return 0;
}
void
SaveUserControlConfig(void)
{
char s[4096], s2[4096];
FILE *fs;
/* Save the configuration parameters */
ConfigurationSave();
/* Save odd bits */
Etmp(s2);
fs = fopen(s2, "w");
if (!fs)
return;
fprintf(fs, "1001 0\n");
BackgroundsConfigSave(fs);
ButtonsConfigSave(fs);
fclose(fs);
Esnprintf(s, sizeof(s), "%s.misc", EGetSavePrefix());
E_mv(s2, s);
if (!isfile(s))
Alert(_("There was an error saving your autosave data - filing\n"
"system problems.\n"));
}
void
RecoverUserConfig(void)
{

View File

@ -1666,8 +1666,10 @@ DesktopsSighan(int sig, void *prm __UNUSED__)
/* toss down the dragbar and related */
DesksControlsCreate();
DesksControlsShow();
break;
/* then draw all the buttons that belong on the desktop */
case ESIGNAL_START:
/* Draw all the buttons that belong on the desktop */
DeskShowButtons();
break;
}

View File

@ -304,7 +304,8 @@ autosave(void)
Real_SaveSnapInfo(0, NULL);
SaveUserControlConfig();
/* Save the configuration parameters */
ConfigurationSave();
}
#ifdef HAVE_X11_SM_SMLIB_H