Commit 4e9843d9 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

move MetaButtonLayout to libmetacity

parent 8f760966
......@@ -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 \
......
/*
* 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;
}
/*
* 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
......@@ -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))
{
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment