Commit 8f760966 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

move MetaButtonFunction to libmetacity

parent 37a2d205
......@@ -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 \
......
/*
* 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;
}
}
/*
* 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
......@@ -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;
......
......@@ -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;
......
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