[metacity] move MetaButtonLayout to libmetacity
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] move MetaButtonLayout to libmetacity
- Date: Thu, 28 Jan 2016 17:30:11 +0000 (UTC)
commit 4e9843d9bd3743352750ad6b1aead1a7d2a4c7bf
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Jan 28 19:29:55 2016 +0200
move MetaButtonLayout to libmetacity
libmetacity/Makefile.am | 3 +
libmetacity/meta-button-layout.c | 155 ++++++++++++++++++++++++++++++++++
libmetacity/meta-button-layout.h | 42 ++++++++++
src/core/prefs.c | 169 +-------------------------------------
src/include/common.h | 14 +---
5 files changed, 204 insertions(+), 179 deletions(-)
---
diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am
index 47c445b..4966489 100644
--- a/libmetacity/Makefile.am
+++ b/libmetacity/Makefile.am
@@ -5,6 +5,8 @@ lib_LTLIBRARIES = libmetacity.la
libmetacity_la_SOURCES = \
meta-button-function.c \
meta-button-function.h \
+ meta-button-layout.c \
+ meta-button-layout.h \
meta-color.c \
meta-color.h \
meta-color-private.h \
@@ -52,6 +54,7 @@ libmetacity_la_LIBADD = \
libmetacity_includedir = $(includedir)/metacity/libmetacity
libmetacity_include_HEADERS = \
meta-button-function.h \
+ meta-button-layout.h \
meta-color.h \
meta-color-spec.h \
meta-frame-borders.h \
diff --git a/libmetacity/meta-button-layout.c b/libmetacity/meta-button-layout.c
new file mode 100644
index 0000000..fc29910
--- /dev/null
+++ b/libmetacity/meta-button-layout.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "meta-button-layout.h"
+
+static void
+meta_button_layout_init (MetaButtonLayout *layout)
+{
+ gint i;
+
+ for (i = 0; i < META_BUTTON_FUNCTION_LAST; i++)
+ {
+ layout->left_buttons[i] = META_BUTTON_FUNCTION_LAST;
+ layout->left_buttons_has_spacer[i] = FALSE;
+
+ layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST;
+ layout->right_buttons_has_spacer[i] = FALSE;
+ }
+}
+
+static void
+string_to_buttons (const gchar *str,
+ MetaButtonFunction side_buttons[META_BUTTON_FUNCTION_LAST],
+ gboolean side_has_spacer[META_BUTTON_FUNCTION_LAST])
+{
+ gint i;
+ gint b;
+ gboolean used[META_BUTTON_FUNCTION_LAST];
+ gchar **buttons;
+
+ i = 0;
+ while (i < META_BUTTON_FUNCTION_LAST)
+ used[i++] = FALSE;
+
+ buttons = g_strsplit (str, ",", -1);
+
+ i = b = 0;
+ while (buttons[b] != NULL)
+ {
+ MetaButtonFunction f;
+
+ f = meta_button_function_from_string (buttons[b]);
+
+ if (i > 0 && g_strcmp0 ("spacer", buttons[b]) == 0)
+ {
+ side_has_spacer[i - 1] = TRUE;
+
+ f = meta_button_function_get_opposite (f);
+ if (f != META_BUTTON_FUNCTION_LAST)
+ side_has_spacer[i - 2] = TRUE;
+ }
+ else
+ {
+ if (f != META_BUTTON_FUNCTION_LAST && !used[f])
+ {
+ side_buttons[i] = f;
+ used[f] = TRUE;
+ i++;
+
+ f = meta_button_function_get_opposite (f);
+ if (f != META_BUTTON_FUNCTION_LAST)
+ side_buttons[i++] = f;
+ }
+ else
+ {
+ g_debug ("Ignoring unknown or already-used button name - '%s'",
+ buttons[b]);
+ }
+ }
+
+ b++;
+ }
+
+ g_strfreev (buttons);
+}
+
+MetaButtonLayout
+meta_button_layout_new (const gchar *str,
+ gboolean invert)
+{
+ gchar **sides;
+ MetaButtonLayout layout;
+ MetaButtonLayout rtl_layout;
+ gint i;
+ gint j;
+
+ sides = g_strsplit (str, ":", 2);
+ meta_button_layout_init (&layout);
+
+ if (sides[0] != NULL)
+ {
+ string_to_buttons (sides[0], layout.left_buttons,
+ layout.left_buttons_has_spacer);
+ }
+
+ if (sides[0] != NULL && sides[1] != NULL)
+ {
+ string_to_buttons (sides[1], layout.right_buttons,
+ layout.right_buttons_has_spacer);
+ }
+
+ g_strfreev (sides);
+
+ if (!invert)
+ return layout;
+
+ meta_button_layout_init (&rtl_layout);
+
+ i = 0;
+ while (rtl_layout.left_buttons[i] != META_BUTTON_FUNCTION_LAST)
+ i++;
+
+ for (j = 0; j < i; j++)
+ {
+ rtl_layout.right_buttons[j] = layout.left_buttons[i - j - 1];
+
+ if (j == 0)
+ rtl_layout.right_buttons_has_spacer[i - 1] = layout.left_buttons_has_spacer[i - j - 1];
+ else
+ rtl_layout.right_buttons_has_spacer[j - 1] = layout.left_buttons_has_spacer[i - j - 1];
+ }
+
+ i = 0;
+ while (rtl_layout.left_buttons[i] != META_BUTTON_FUNCTION_LAST)
+ i++;
+
+ for (j = 0; j < i; j++)
+ {
+ rtl_layout.left_buttons[j] = layout.right_buttons[i - j - 1];
+
+ if (j == 0)
+ rtl_layout.left_buttons_has_spacer[i - 1] = layout.right_buttons_has_spacer[i - j - 1];
+ else
+ rtl_layout.left_buttons_has_spacer[j - 1] = layout.right_buttons_has_spacer[i - j - 1];
+ }
+
+ return rtl_layout;
+}
diff --git a/libmetacity/meta-button-layout.h b/libmetacity/meta-button-layout.h
new file mode 100644
index 0000000..434d5a7
--- /dev/null
+++ b/libmetacity/meta-button-layout.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef META_BUTTON_LAYOUT_H
+#define META_BUTTON_LAYOUT_H
+
+#include <libmetacity/meta-button-function.h>
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+ /* buttons in the group on the left side */
+ MetaButtonFunction left_buttons[META_BUTTON_FUNCTION_LAST];
+ gboolean left_buttons_has_spacer[META_BUTTON_FUNCTION_LAST];
+
+ /* buttons in the group on the right side */
+ MetaButtonFunction right_buttons[META_BUTTON_FUNCTION_LAST];
+ gboolean right_buttons_has_spacer[META_BUTTON_FUNCTION_LAST];
+} MetaButtonLayout;
+
+MetaButtonLayout meta_button_layout_new (const gchar *str,
+ gboolean invert);
+
+G_END_DECLS
+
+#endif
diff --git a/src/core/prefs.c b/src/core/prefs.c
index 54a784f..7b9400c 100644
--- a/src/core/prefs.c
+++ b/src/core/prefs.c
@@ -1140,174 +1140,11 @@ button_layout_equal (const MetaButtonLayout *a,
static void
update_button_layout (const gchar *string_value)
{
+ gboolean invert;
MetaButtonLayout new_layout;
- char **sides = NULL;
- int i;
-
- /* We need to ignore unknown button functions, for
- * compat with future versions
- */
-
- sides = g_strsplit (string_value, ":", 2);
- i = 0;
-
- if (sides != NULL && sides[0] != NULL)
- {
- char **buttons;
- int b;
- gboolean used[META_BUTTON_FUNCTION_LAST];
-
- while (i < META_BUTTON_FUNCTION_LAST)
- {
- used[i] = FALSE;
- new_layout.left_buttons_has_spacer[i] = FALSE;
- i++;
- }
-
- buttons = g_strsplit (sides[0], ",", -1);
- i = 0;
- b = 0;
- while (buttons[b] != NULL)
- {
- MetaButtonFunction f = meta_button_function_from_string (buttons[b]);
- if (i > 0 && strcmp("spacer", buttons[b]) == 0)
- {
- new_layout.left_buttons_has_spacer[i-1] = TRUE;
- f = meta_button_function_get_opposite (f);
-
- if (f != META_BUTTON_FUNCTION_LAST)
- {
- new_layout.left_buttons_has_spacer[i-2] = TRUE;
- }
- }
- else
- {
- if (f != META_BUTTON_FUNCTION_LAST && !used[f])
- {
- new_layout.left_buttons[i] = f;
- used[f] = TRUE;
- i++;
-
- f = meta_button_function_get_opposite (f);
-
- if (f != META_BUTTON_FUNCTION_LAST)
- new_layout.left_buttons[i++] = f;
-
- }
- else
- {
- meta_topic (META_DEBUG_PREFS, "Ignoring unknown or already-used button name \"%s\"\n",
- buttons[b]);
- }
- }
-
- ++b;
- }
-
- g_strfreev (buttons);
- }
-
- /* Close the buttons list even if it's empty */
- new_layout.left_buttons[i] = META_BUTTON_FUNCTION_LAST;
- new_layout.left_buttons_has_spacer[i] = FALSE;
-
-
- i = 0;
-
- if (sides != NULL && sides[0] != NULL && sides[1] != NULL)
- {
- char **buttons;
- int b;
- gboolean used[META_BUTTON_FUNCTION_LAST];
-
- while (i < META_BUTTON_FUNCTION_LAST)
- {
- used[i] = FALSE;
- new_layout.right_buttons_has_spacer[i] = FALSE;
- i++;
- }
-
- buttons = g_strsplit (sides[1], ",", -1);
- i = 0;
- b = 0;
- while (buttons[b] != NULL)
- {
- MetaButtonFunction f = meta_button_function_from_string (buttons[b]);
- if (i > 0 && strcmp("spacer", buttons[b]) == 0)
- {
- new_layout.right_buttons_has_spacer[i-1] = TRUE;
- f = meta_button_function_get_opposite (f);
- if (f != META_BUTTON_FUNCTION_LAST)
- {
- new_layout.right_buttons_has_spacer[i-2] = TRUE;
- }
- }
- else
- {
- if (f != META_BUTTON_FUNCTION_LAST && !used[f])
- {
- new_layout.right_buttons[i] = f;
- used[f] = TRUE;
- i++;
-
- f = meta_button_function_get_opposite (f);
-
- if (f != META_BUTTON_FUNCTION_LAST)
- new_layout.right_buttons[i++] = f;
-
- }
- else
- {
- meta_topic (META_DEBUG_PREFS, "Ignoring unknown or already-used button name \"%s\"\n",
- buttons[b]);
- }
- }
-
- ++b;
- }
-
- g_strfreev (buttons);
- }
-
- /* Close the buttons list even if it's empty */
- new_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST;
- new_layout.right_buttons_has_spacer[i] = FALSE;
-
- if (sides)
- g_strfreev (sides);
-
- /* Invert the button layout for RTL languages */
- if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
- {
- MetaButtonLayout rtl_layout;
- int j;
-
- for (i = 0; new_layout.left_buttons[i] != META_BUTTON_FUNCTION_LAST; i++);
- for (j = 0; j < i; j++)
- {
- rtl_layout.right_buttons[j] = new_layout.left_buttons[i - j - 1];
- if (j == 0)
- rtl_layout.right_buttons_has_spacer[i - 1] = new_layout.left_buttons_has_spacer[i - j - 1];
- else
- rtl_layout.right_buttons_has_spacer[j - 1] = new_layout.left_buttons_has_spacer[i - j - 1];
- }
- rtl_layout.right_buttons[j] = META_BUTTON_FUNCTION_LAST;
- rtl_layout.right_buttons_has_spacer[j] = FALSE;
-
- for (i = 0; new_layout.right_buttons[i] != META_BUTTON_FUNCTION_LAST; i++);
- for (j = 0; j < i; j++)
- {
- rtl_layout.left_buttons[j] = new_layout.right_buttons[i - j - 1];
- if (j == 0)
- rtl_layout.left_buttons_has_spacer[i - 1] = new_layout.right_buttons_has_spacer[i - j - 1];
- else
- rtl_layout.left_buttons_has_spacer[j - 1] = new_layout.right_buttons_has_spacer[i - j - 1];
- }
- rtl_layout.left_buttons[j] = META_BUTTON_FUNCTION_LAST;
- rtl_layout.left_buttons_has_spacer[j] = FALSE;
- new_layout = rtl_layout;
- }
+ invert = meta_ui_get_direction() == META_UI_DIRECTION_RTL;
+ new_layout = meta_button_layout_new (string_value, invert);
if (!button_layout_equal (&button_layout, &new_layout))
{
diff --git a/src/include/common.h b/src/include/common.h
index 9343b8e..1c117d3 100644
--- a/src/include/common.h
+++ b/src/include/common.h
@@ -30,7 +30,7 @@
#include <X11/Xlib.h>
#include <glib.h>
#include <gtk/gtk.h>
-#include <libmetacity/meta-button-function.h>
+#include <libmetacity/meta-button-layout.h>
typedef struct _MetaResizePopup MetaResizePopup;
@@ -231,18 +231,6 @@ typedef enum
#define MAX_BUTTONS_PER_CORNER META_BUTTON_FUNCTION_LAST
-typedef struct _MetaButtonLayout MetaButtonLayout;
-struct _MetaButtonLayout
-{
- /* buttons in the group on the left side */
- MetaButtonFunction left_buttons[MAX_BUTTONS_PER_CORNER];
- gboolean left_buttons_has_spacer[MAX_BUTTONS_PER_CORNER];
-
- /* buttons in the group on the right side */
- MetaButtonFunction right_buttons[MAX_BUTTONS_PER_CORNER];
- gboolean right_buttons_has_spacer[MAX_BUTTONS_PER_CORNER];
-};
-
/* should investigate changing these to whatever most apps use */
#define META_ICON_WIDTH 96
#define META_ICON_HEIGHT 96
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]