[metacity] move MetaButtonFunction to libmetacity



commit 8f7609666f1eb40c02182df219123ed69aec1845
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Jan 28 18:29:16 2016 +0200

    move MetaButtonFunction to libmetacity

 libmetacity/Makefile.am            |    3 +
 libmetacity/meta-button-function.c |   95 ++++++++++++++++++++++++++++++++++++
 libmetacity/meta-button-function.h |   64 ++++++++++++++++++++++++
 src/core/prefs.c                   |   73 ++-------------------------
 src/include/common.h               |   21 +--------
 5 files changed, 169 insertions(+), 87 deletions(-)
---
diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am
index 14187b4..47c445b 100644
--- a/libmetacity/Makefile.am
+++ b/libmetacity/Makefile.am
@@ -3,6 +3,8 @@ NULL =
 lib_LTLIBRARIES = libmetacity.la
 
 libmetacity_la_SOURCES = \
+       meta-button-function.c \
+       meta-button-function.h \
        meta-color.c \
        meta-color.h \
        meta-color-private.h \
@@ -49,6 +51,7 @@ libmetacity_la_LIBADD = \
 
 libmetacity_includedir = $(includedir)/metacity/libmetacity
 libmetacity_include_HEADERS = \
+       meta-button-function.h \
        meta-color.h \
        meta-color-spec.h \
        meta-frame-borders.h \
diff --git a/libmetacity/meta-button-function.c b/libmetacity/meta-button-function.c
new file mode 100644
index 0000000..8ceb41c
--- /dev/null
+++ b/libmetacity/meta-button-function.c
@@ -0,0 +1,95 @@
+/*
+ * 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-function.h"
+
+/**
+ * meta_button_function_from_string:
+ * @str:
+ *
+ * Returns:
+ */
+MetaButtonFunction
+meta_button_function_from_string (const gchar *str)
+{
+  if (g_strcmp0 (str, "menu") == 0)
+    return META_BUTTON_FUNCTION_MENU;
+  else if (g_strcmp0 (str, "appmenu") == 0)
+    return META_BUTTON_FUNCTION_APPMENU;
+  else if (g_strcmp0 (str, "minimize") == 0)
+    return META_BUTTON_FUNCTION_MINIMIZE;
+  else if (g_strcmp0 (str, "maximize") == 0)
+    return META_BUTTON_FUNCTION_MAXIMIZE;
+  else if (g_strcmp0 (str, "close") == 0)
+    return META_BUTTON_FUNCTION_CLOSE;
+  else if (g_strcmp0 (str, "shade") == 0)
+    return META_BUTTON_FUNCTION_SHADE;
+  else if (g_strcmp0 (str, "unshade") == 0)
+    return META_BUTTON_FUNCTION_UNSHADE;
+  else if (g_strcmp0 (str, "above") == 0)
+    return META_BUTTON_FUNCTION_ABOVE;
+  else if (g_strcmp0 (str, "unabove") == 0)
+    return META_BUTTON_FUNCTION_UNABOVE;
+  else if (g_strcmp0 (str, "stick") == 0)
+    return META_BUTTON_FUNCTION_STICK;
+  else if (g_strcmp0 (str, "unstick") == 0)
+    return META_BUTTON_FUNCTION_UNSTICK;
+
+  return META_BUTTON_FUNCTION_LAST;
+}
+
+/**
+ * meta_button_function_get_opposite:
+ * @function:
+ *
+ * Returns:
+ */
+MetaButtonFunction
+meta_button_function_get_opposite (MetaButtonFunction function)
+{
+  switch (function)
+    {
+      case META_BUTTON_FUNCTION_SHADE:
+        return META_BUTTON_FUNCTION_UNSHADE;
+      case META_BUTTON_FUNCTION_UNSHADE:
+        return META_BUTTON_FUNCTION_SHADE;
+
+      case META_BUTTON_FUNCTION_ABOVE:
+        return META_BUTTON_FUNCTION_UNABOVE;
+      case META_BUTTON_FUNCTION_UNABOVE:
+        return META_BUTTON_FUNCTION_ABOVE;
+
+      case META_BUTTON_FUNCTION_STICK:
+        return META_BUTTON_FUNCTION_UNSTICK;
+      case META_BUTTON_FUNCTION_UNSTICK:
+        return META_BUTTON_FUNCTION_STICK;
+
+      case META_BUTTON_FUNCTION_MENU:
+      case META_BUTTON_FUNCTION_APPMENU:
+      case META_BUTTON_FUNCTION_MINIMIZE:
+      case META_BUTTON_FUNCTION_MAXIMIZE:
+      case META_BUTTON_FUNCTION_CLOSE:
+      case META_BUTTON_FUNCTION_LAST:
+        return META_BUTTON_FUNCTION_LAST;
+
+      default:
+        return META_BUTTON_FUNCTION_LAST;
+    }
+}
diff --git a/libmetacity/meta-button-function.h b/libmetacity/meta-button-function.h
new file mode 100644
index 0000000..30ae6c9
--- /dev/null
+++ b/libmetacity/meta-button-function.h
@@ -0,0 +1,64 @@
+/*
+ * 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_FUNCTION_H
+#define META_BUTTON_FUNCTION_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * MetaButtonFunction:
+ * @META_BUTTON_FUNCTION_MENU:
+ * @META_BUTTON_FUNCTION_APPMENU:
+ * @META_BUTTON_FUNCTION_MINIMIZE:
+ * @META_BUTTON_FUNCTION_MAXIMIZE:
+ * @META_BUTTON_FUNCTION_CLOSE:
+ * @META_BUTTON_FUNCTION_SHADE:
+ * @META_BUTTON_FUNCTION_UNSHADE:
+ * @META_BUTTON_FUNCTION_ABOVE:
+ * @META_BUTTON_FUNCTION_UNABOVE:
+ * @META_BUTTON_FUNCTION_STICK:
+ * @META_BUTTON_FUNCTION_UNSTICK:
+ * @META_BUTTON_FUNCTION_LAST:
+ *
+ */
+typedef enum
+{
+  META_BUTTON_FUNCTION_MENU,
+  META_BUTTON_FUNCTION_APPMENU,
+  META_BUTTON_FUNCTION_MINIMIZE,
+  META_BUTTON_FUNCTION_MAXIMIZE,
+  META_BUTTON_FUNCTION_CLOSE,
+  META_BUTTON_FUNCTION_SHADE,
+  META_BUTTON_FUNCTION_UNSHADE,
+  META_BUTTON_FUNCTION_ABOVE,
+  META_BUTTON_FUNCTION_UNABOVE,
+  META_BUTTON_FUNCTION_STICK,
+  META_BUTTON_FUNCTION_UNSTICK,
+  META_BUTTON_FUNCTION_LAST
+} MetaButtonFunction;
+
+MetaButtonFunction meta_button_function_from_string  (const gchar        *str);
+
+MetaButtonFunction meta_button_function_get_opposite (MetaButtonFunction  function);
+
+G_END_DECLS
+
+#endif
diff --git a/src/core/prefs.c b/src/core/prefs.c
index 6a29fdf..54a784f 100644
--- a/src/core/prefs.c
+++ b/src/core/prefs.c
@@ -1137,67 +1137,6 @@ button_layout_equal (const MetaButtonLayout *a,
   return TRUE;
 }
 
-/*
- * This conversion cannot be handled by GSettings since
- * several values are stored in the same key (as a string).
- */
-static MetaButtonFunction
-button_function_from_string (const char *str)
-{
-  if (strcmp (str, "menu") == 0)
-    return META_BUTTON_FUNCTION_MENU;
-  else if (strcmp (str, "appmenu") == 0)
-    return META_BUTTON_FUNCTION_APPMENU;
-  else if (strcmp (str, "minimize") == 0)
-    return META_BUTTON_FUNCTION_MINIMIZE;
-  else if (strcmp (str, "maximize") == 0)
-    return META_BUTTON_FUNCTION_MAXIMIZE;
-  else if (strcmp (str, "close") == 0)
-    return META_BUTTON_FUNCTION_CLOSE;
-  else if (strcmp (str, "shade") == 0)
-    return META_BUTTON_FUNCTION_SHADE;
-  else if (strcmp (str, "above") == 0)
-    return META_BUTTON_FUNCTION_ABOVE;
-  else if (strcmp (str, "stick") == 0)
-    return META_BUTTON_FUNCTION_STICK;
-  else
-    /* don't know; give up */
-    return META_BUTTON_FUNCTION_LAST;
-}
-
-static MetaButtonFunction
-button_opposite_function (MetaButtonFunction ofwhat)
-{
-  switch (ofwhat)
-    {
-    case META_BUTTON_FUNCTION_SHADE:
-      return META_BUTTON_FUNCTION_UNSHADE;
-    case META_BUTTON_FUNCTION_UNSHADE:
-      return META_BUTTON_FUNCTION_SHADE;
-
-    case META_BUTTON_FUNCTION_ABOVE:
-      return META_BUTTON_FUNCTION_UNABOVE;
-    case META_BUTTON_FUNCTION_UNABOVE:
-      return META_BUTTON_FUNCTION_ABOVE;
-
-    case META_BUTTON_FUNCTION_STICK:
-      return META_BUTTON_FUNCTION_UNSTICK;
-    case META_BUTTON_FUNCTION_UNSTICK:
-      return META_BUTTON_FUNCTION_STICK;
-
-    case META_BUTTON_FUNCTION_MENU:
-    case META_BUTTON_FUNCTION_APPMENU:
-    case META_BUTTON_FUNCTION_MINIMIZE:
-    case META_BUTTON_FUNCTION_MAXIMIZE:
-    case META_BUTTON_FUNCTION_CLOSE:
-    case META_BUTTON_FUNCTION_LAST:
-      return META_BUTTON_FUNCTION_LAST;
-
-    default:
-      return META_BUTTON_FUNCTION_LAST;
-    }
-}
-
 static void
 update_button_layout (const gchar *string_value)
 {
@@ -1230,11 +1169,11 @@ update_button_layout (const gchar *string_value)
       b = 0;
       while (buttons[b] != NULL)
         {
-          MetaButtonFunction f = button_function_from_string (buttons[b]);
+          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 = button_opposite_function (f);
+              f = meta_button_function_get_opposite (f);
 
               if (f != META_BUTTON_FUNCTION_LAST)
                 {
@@ -1249,7 +1188,7 @@ update_button_layout (const gchar *string_value)
                   used[f] = TRUE;
                   i++;
 
-                  f = button_opposite_function (f);
+                  f = meta_button_function_get_opposite (f);
 
                   if (f != META_BUTTON_FUNCTION_LAST)
                       new_layout.left_buttons[i++] = f;
@@ -1293,11 +1232,11 @@ update_button_layout (const gchar *string_value)
       b = 0;
       while (buttons[b] != NULL)
         {
-          MetaButtonFunction f = button_function_from_string (buttons[b]);
+          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 = button_opposite_function (f);
+              f = meta_button_function_get_opposite (f);
               if (f != META_BUTTON_FUNCTION_LAST)
                 {
                   new_layout.right_buttons_has_spacer[i-2] = TRUE;
@@ -1311,7 +1250,7 @@ update_button_layout (const gchar *string_value)
                   used[f] = TRUE;
                   i++;
 
-                  f = button_opposite_function (f);
+                  f = meta_button_function_get_opposite (f);
 
                   if (f != META_BUTTON_FUNCTION_LAST)
                       new_layout.right_buttons[i++] = f;
diff --git a/src/include/common.h b/src/include/common.h
index 1f25241..9343b8e 100644
--- a/src/include/common.h
+++ b/src/include/common.h
@@ -30,6 +30,7 @@
 #include <X11/Xlib.h>
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <libmetacity/meta-button-function.h>
 
 typedef struct _MetaResizePopup MetaResizePopup;
 
@@ -228,26 +229,6 @@ typedef enum
   META_SIDE_BOTTOM          = META_DIRECTION_BOTTOM
 } MetaSide;
 
-/* Function a window button can have.  Note, you can't add stuff here
- * without extending the theme format to draw a new function and
- * breaking all existing themes.
- */
-typedef enum
-{
-  META_BUTTON_FUNCTION_MENU,
-  META_BUTTON_FUNCTION_APPMENU,
-  META_BUTTON_FUNCTION_MINIMIZE,
-  META_BUTTON_FUNCTION_MAXIMIZE,
-  META_BUTTON_FUNCTION_CLOSE,
-  META_BUTTON_FUNCTION_SHADE,
-  META_BUTTON_FUNCTION_ABOVE,
-  META_BUTTON_FUNCTION_STICK,
-  META_BUTTON_FUNCTION_UNSHADE,
-  META_BUTTON_FUNCTION_UNABOVE,
-  META_BUTTON_FUNCTION_UNSTICK,
-  META_BUTTON_FUNCTION_LAST
-} MetaButtonFunction;
-
 #define MAX_BUTTONS_PER_CORNER META_BUTTON_FUNCTION_LAST
 
 typedef struct _MetaButtonLayout MetaButtonLayout;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]