[gimp] app: config folder migration update for GIMP 3.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: config folder migration update for GIMP 3.
- Date: Mon, 23 Aug 2021 11:47:58 +0000 (UTC)
commit c43de62e998cbb26e0a13c14f77c1d052502d2a3
Author: Jehan <jehan girinstud io>
Date: Mon Aug 23 13:26:43 2021 +0200
app: config folder migration update for GIMP 3.
Fix the search for previous folders, which was broken as it was
specifically expecting 1-digit numbers so far.
The differences of the GIMP 3 config import are:
- update sizes and positions in the sessionrc according to the scale
factor, because GTK2 doesn't have scale support. It means that, e.g.
with a 2× display, all sizes and positions in GIMP 2.x must be divided
by 2 (otherwise the first thing many people will get when testing GIMP
3 for the first time is an off-screen window).
Of course, I even wondered if it would not be nice to just drop the
sessionrc altogether and start with a nice blank slate, but then you
also lose the opened dock and their organization and some settings
(such as whether you chose single or multi window mode, etc.).
- scripts/ and plug-ins/ are not imported. Probably makes no sense so
far as they would end up broken (but maybe it's not true for all
script-fu scripts?).
app/app.c | 4 +-
app/config/gimpconfig-file.c | 5 +-
app/config/gimpconfig-file.h | 1 +
app/core/gimp-user-install.c | 100 ++++++++++++++++++++++++++++++++++++--
app/core/gimp-user-install.h | 3 +-
app/dialogs/user-install-dialog.c | 3 +-
6 files changed, 107 insertions(+), 9 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index 136e130cb2..2fd30176fa 100644
--- a/app/app.c
+++ b/app/app.c
@@ -272,10 +272,10 @@ app_run (const gchar *full_prog_name,
be_verbose);
#ifdef GIMP_CONSOLE_COMPILATION
- gimp_user_install_run (install);
+ gimp_user_install_run (install, 1);
#else
if (! (no_interface ?
- gimp_user_install_run (install) :
+ gimp_user_install_run (install, 1) :
user_install_dialog_run (install)))
exit (EXIT_FAILURE);
#endif
diff --git a/app/config/gimpconfig-file.c b/app/config/gimpconfig-file.c
index 9823b8f419..0bfa8fe61d 100644
--- a/app/config/gimpconfig-file.c
+++ b/app/config/gimpconfig-file.c
@@ -45,6 +45,7 @@ gimp_config_file_copy (const gchar *source,
const gchar *dest,
const gchar *old_options_pattern,
GRegexEvalCallback update_callback,
+ gpointer user_data,
GError **error)
{
gchar buffer[8192];
@@ -129,7 +130,7 @@ gimp_config_file_copy (const gchar *source,
write_bytes = g_regex_replace_eval (old_options_regexp, buffer,
read_len, 0, 0, update_callback,
- NULL, error);
+ user_data, error);
if (write_bytes == NULL)
{
/* error already set. */
@@ -226,7 +227,7 @@ gimp_config_file_backup_on_error (GFile *file,
path = g_file_get_path (file);
backup = g_strconcat (path, "~", NULL);
- success = gimp_config_file_copy (path, backup, NULL, NULL, error);
+ success = gimp_config_file_copy (path, backup, NULL, NULL, NULL, error);
if (success)
g_message (_("There was an error parsing your '%s' file. "
diff --git a/app/config/gimpconfig-file.h b/app/config/gimpconfig-file.h
index fc61886266..7638c707e7 100644
--- a/app/config/gimpconfig-file.h
+++ b/app/config/gimpconfig-file.h
@@ -26,6 +26,7 @@ gboolean gimp_config_file_copy (const gchar *source,
const gchar *dest,
const gchar *old_options_regexp,
GRegexEvalCallback update_callback,
+ gpointer user_data,
GError **error);
gboolean gimp_config_file_backup_on_error (GFile *file,
diff --git a/app/core/gimp-user-install.c b/app/core/gimp-user-install.c
index 118bcb2733..232f69e91c 100644
--- a/app/core/gimp-user-install.c
+++ b/app/core/gimp-user-install.c
@@ -69,6 +69,8 @@ struct _GimpUserInstall
gint old_major;
gint old_minor;
+ gint scale_factor;
+
const gchar *migrate;
GimpUserInstallLogFunc log;
@@ -202,12 +204,14 @@ gimp_user_install_new (GObject *gimp,
}
gboolean
-gimp_user_install_run (GimpUserInstall *install)
+gimp_user_install_run (GimpUserInstall *install,
+ gint scale_factor)
{
gchar *dirname;
g_return_val_if_fail (install != NULL, FALSE);
+ install->scale_factor = scale_factor;
dirname = g_filename_display_name (gimp_directory ());
if (install->migrate)
@@ -269,6 +273,7 @@ user_install_detect_old (GimpUserInstall *install,
gboolean migrate = FALSE;
version = strstr (dir, GIMP_APP_VERSION);
+ g_snprintf (version, 5, "%d.XY", 2);
if (version)
{
@@ -277,7 +282,7 @@ user_install_detect_old (GimpUserInstall *install,
for (i = (GIMP_MINOR_VERSION & ~1); i >= 0; i -= 2)
{
/* we assume that GIMP_APP_VERSION is in the form '2.x' */
- g_snprintf (version + 2, 2, "%d", i);
+ g_snprintf (version + 2, 3, "%d", i);
migrate = g_file_test (dir, G_FILE_TEST_IS_DIR);
@@ -420,7 +425,7 @@ user_install_file_copy (GimpUserInstall *install,
gimp_filename_to_utf8 (dest),
gimp_filename_to_utf8 (source));
- success = gimp_config_file_copy (source, dest, old_options_regexp, update_callback, &error);
+ success = gimp_config_file_copy (source, dest, old_options_regexp, update_callback, install, &error);
user_install_log_error (install, &error);
@@ -612,6 +617,79 @@ user_update_controllerrc (const GMatchInfo *matched_value,
return FALSE;
}
+#define SESSIONRC_UPDATE_PATTERN \
+ "\\(position [0-9]* [0-9]*\\)" "|" \
+ "\\(size [0-9]* [0-9]*\\)"
+
+static gboolean
+user_update_sessionrc (const GMatchInfo *matched_value,
+ GString *new_value,
+ gpointer data)
+{
+ GimpUserInstall *install = (GimpUserInstall *) data;
+ gchar *original;
+
+ original = g_match_info_fetch (matched_value, 0);
+
+ if (install->scale_factor != 1 && install->scale_factor > 0)
+ {
+ /* GTK < 3.0 didn't have scale factor support. It means that any
+ * size and position back then would be in real pixel size. Now
+ * with GTK3 and over, we need to think of position and size in
+ * virtual/application pixels.
+ * In particular it means that if we were to just copy the numbers
+ * from GTK2 to GTK3 on a display with scale factor of 2, every
+ * width, height and position would be 2 times too big (a full
+ * screen window would end up off-screen).
+ */
+ GRegex *regexp;
+ GMatchInfo *match_info;
+ gchar *match;
+
+ /* First copy the pattern title. */
+ regexp = g_regex_new ("\\((position|size) ", 0, 0, NULL);
+ g_regex_match (regexp, original, 0, &match_info);
+ match = g_match_info_fetch (match_info, 0);
+ g_string_append (new_value, match);
+
+ g_match_info_free (match_info);
+ g_regex_unref (regexp);
+ g_free (match);
+
+ /* Now copy the numbers. */
+ regexp = g_regex_new ("[0-9]+", 0, 0, NULL);
+ g_regex_match (regexp, original, 0, &match_info);
+
+ while (g_match_info_matches (match_info))
+ {
+ gint num;
+
+ match = g_match_info_fetch (match_info, 0);
+ num = g_ascii_strtoll (match, NULL, 10);
+ num /= install->scale_factor;
+
+ g_string_append_printf (new_value, " %d", num);
+
+ g_free (match);
+ g_match_info_next (match_info, NULL);
+ }
+
+ g_match_info_free (match_info);
+ g_regex_unref (regexp);
+
+ g_string_append (new_value, ")");
+ }
+ else
+ {
+ /* Just copy as-is. */
+ g_string_append (new_value, original);
+ }
+
+ g_free (original);
+
+ return FALSE;
+}
+
#define GIMPRC_UPDATE_PATTERN \
"\\(theme [^)]*\\)" "|" \
"\\(.*-path [^)]*\\)"
@@ -891,6 +969,15 @@ user_install_migrate_files (GimpUserInstall *install)
{
goto next_file;
}
+ else if (install->old_major < 3 &&
+ strcmp (basename, "sessionrc") == 0)
+ {
+ /* We need to update size and positions because of scale
+ * factor support.
+ */
+ update_pattern = SESSIONRC_UPDATE_PATTERN;
+ update_callback = user_update_sessionrc;
+ }
else if (strcmp (basename, "menurc") == 0)
{
switch (install->old_minor)
@@ -940,6 +1027,13 @@ user_install_migrate_files (GimpUserInstall *install)
{
goto next_file;
}
+ else if (install->old_major < 3 &&
+ (strcmp (basename, "plug-ins") == 0 ||
+ strcmp (basename, "scripts") == 0))
+ {
+ /* Major API update. */
+ goto next_file;
+ }
if (strcmp (basename, "gimpressionist") == 0)
{
diff --git a/app/core/gimp-user-install.h b/app/core/gimp-user-install.h
index 1bac6861ac..e96792efb8 100644
--- a/app/core/gimp-user-install.h
+++ b/app/core/gimp-user-install.h
@@ -28,7 +28,8 @@ typedef void (* GimpUserInstallLogFunc) (const gchar *message,
GimpUserInstall * gimp_user_install_new (GObject *gimp,
gboolean verbose);
-gboolean gimp_user_install_run (GimpUserInstall *install);
+gboolean gimp_user_install_run (GimpUserInstall *install,
+ gint scale_factor);
void gimp_user_install_free (GimpUserInstall *install);
void gimp_user_install_set_log_handler (GimpUserInstall *install,
diff --git a/app/dialogs/user-install-dialog.c b/app/dialogs/user-install-dialog.c
index af9edd4bbc..0143348079 100644
--- a/app/dialogs/user-install-dialog.c
+++ b/app/dialogs/user-install-dialog.c
@@ -53,7 +53,8 @@ user_install_dialog_run (GimpUserInstall *install)
dialog = user_install_dialog_new (install);
- success = gimp_user_install_run (install);
+ success = gimp_user_install_run (install,
+ gtk_widget_get_scale_factor (dialog));
if (! success)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]