[metacity] libmetacity: don't expose MetaButton struct
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] libmetacity: don't expose MetaButton struct
- Date: Thu, 18 Aug 2016 16:49:44 +0000 (UTC)
commit 2ee0ffbee0b52cb8fc3112906bea1eaa737559f7
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Aug 18 18:54:38 2016 +0300
libmetacity: don't expose MetaButton struct
libmetacity/Makefile.am | 1 +
libmetacity/meta-button-layout-private.h | 2 +-
libmetacity/meta-button-private.h | 22 ++++++++++++++++++-
libmetacity/meta-button.c | 33 +++++++++++++++++++++++++++++
libmetacity/meta-button.h | 21 +++---------------
libmetacity/meta-theme.c | 14 +++++-------
libmetacity/meta-theme.h | 5 +--
src/ui/frames.c | 34 +++++++++++++++---------------
8 files changed, 85 insertions(+), 47 deletions(-)
---
diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am
index c26d310..3620645 100644
--- a/libmetacity/Makefile.am
+++ b/libmetacity/Makefile.am
@@ -3,6 +3,7 @@ NULL =
lib_LTLIBRARIES = libmetacity.la
libmetacity_la_SOURCES = \
+ meta-button.c \
meta-button.h \
meta-button-layout.c \
meta-button-layout-private.h \
diff --git a/libmetacity/meta-button-layout-private.h b/libmetacity/meta-button-layout-private.h
index 4926b1d..d4397ef 100644
--- a/libmetacity/meta-button-layout-private.h
+++ b/libmetacity/meta-button-layout-private.h
@@ -19,7 +19,7 @@
#ifndef META_BUTTON_LAYOUT_PRIVATE_H
#define META_BUTTON_LAYOUT_PRIVATE_H
-#include "meta-button.h"
+#include "meta-button-private.h"
G_BEGIN_DECLS
diff --git a/libmetacity/meta-button-private.h b/libmetacity/meta-button-private.h
index d6e2ec6..f849e08 100644
--- a/libmetacity/meta-button-private.h
+++ b/libmetacity/meta-button-private.h
@@ -18,7 +18,7 @@
#ifndef META_BUTTON_PRIVATE_H
#define META_BUTTON_PRIVATE_H
-#include <glib.h>
+#include "meta-button.h"
G_BEGIN_DECLS
@@ -47,6 +47,26 @@ typedef enum
META_BUTTON_FUNCTION_LAST
} MetaButtonFunction;
+struct _MetaButton
+{
+ MetaButtonType type;
+ MetaButtonState state;
+
+ /* The computed size of a button (really just a way of tying its visible
+ * and clickable areas together). The reason for two different rectangles
+ * here is Fitts' law & maximized windows; See bug #97703 for more details.
+ */
+ struct {
+ /* The area where the button's image is drawn. */
+ GdkRectangle visible;
+
+ /* The area where the button can be activated by clicking */
+ GdkRectangle clickable;
+ } rect;
+
+ gboolean visible;
+};
+
G_END_DECLS
#endif
diff --git a/libmetacity/meta-button.c b/libmetacity/meta-button.c
new file mode 100644
index 0000000..e3d4e76
--- /dev/null
+++ b/libmetacity/meta-button.c
@@ -0,0 +1,33 @@
+/*
+ * 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-private.h"
+
+MetaButtonType
+meta_button_get_type (MetaButton *button)
+{
+ return button->type;
+}
+
+void
+meta_button_get_event_rect (MetaButton *button,
+ GdkRectangle *rect)
+{
+ *rect = button->rect.clickable;
+}
diff --git a/libmetacity/meta-button.h b/libmetacity/meta-button.h
index a087e14..9edf275 100644
--- a/libmetacity/meta-button.h
+++ b/libmetacity/meta-button.h
@@ -48,25 +48,12 @@ typedef enum
META_BUTTON_STATE_LAST
} MetaButtonState;
-typedef struct
-{
- MetaButtonType type;
- MetaButtonState state;
-
- /* The computed size of a button (really just a way of tying its visible
- * and clickable areas together). The reason for two different rectangles
- * here is Fitts' law & maximized windows; See bug #97703 for more details.
- */
- struct {
- /* The area where the button's image is drawn. */
- GdkRectangle visible;
+typedef struct _MetaButton MetaButton;
- /* The area where the button can be activated by clicking */
- GdkRectangle clickable;
- } rect;
+MetaButtonType meta_button_get_type (MetaButton *button);
- gboolean visible;
-} MetaButton;
+void meta_button_get_event_rect (MetaButton *button,
+ GdkRectangle *rect);
G_END_DECLS
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index 7084ef4..bd03f05 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -570,11 +570,10 @@ meta_theme_set_button_layout (MetaTheme *theme,
theme->button_layout = meta_button_layout_new (button_layout, invert);
}
-gboolean
-meta_theme_get_button (MetaTheme *theme,
- gint x,
- gint y,
- MetaButton *button)
+MetaButton *
+meta_theme_get_button (MetaTheme *theme,
+ gint x,
+ gint y)
{
gint side;
@@ -618,13 +617,12 @@ meta_theme_get_button (MetaTheme *theme,
if (x >= rect.x && x < (rect.x + rect.width) &&
y >= rect.y && y < (rect.y + rect.height))
{
- *button = *btn;
- return TRUE;
+ return btn;
}
}
}
- return FALSE;
+ return NULL;
}
void
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 4174ffe..f3228d4 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -113,10 +113,9 @@ void meta_theme_set_button_layout (MetaTheme *theme,
const gchar *button_layout,
gboolean invert);
-gboolean meta_theme_get_button (MetaTheme *theme,
+MetaButton *meta_theme_get_button (MetaTheme *theme,
gint x,
- gint y,
- MetaButton *button);
+ gint y);
void meta_theme_set_composited (MetaTheme *theme,
gboolean composited);
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 3274142..31fe269 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -129,13 +129,12 @@ get_control (MetaFrames *frames,
GdkRectangle client;
MetaFrameBorders borders;
MetaTheme *theme;
- MetaButton button;
+ MetaButton *button;
meta_frames_calc_geometry (frames, frame, &fgeom);
get_client_rect (&fgeom, &client);
borders = fgeom.borders;
- theme = meta_ui_get_theme ();
if (x < borders.invisible.left - borders.resize.left ||
y < borders.invisible.top - borders.resize.top ||
@@ -151,9 +150,12 @@ get_control (MetaFrames *frames,
META_CORE_GET_FRAME_TYPE, &type,
META_CORE_GET_END);
- if (meta_theme_get_button (theme, x, y, &button))
+ theme = meta_ui_get_theme ();
+ button = meta_theme_get_button (theme, x, y);
+
+ if (button != NULL)
{
- switch (button.type)
+ switch (meta_button_get_type (button))
{
case META_BUTTON_TYPE_CLOSE:
return META_FRAME_CONTROL_DELETE;
@@ -290,9 +292,7 @@ get_control_rect (MetaFrameControl control,
{
MetaButtonType type;
MetaTheme *theme;
- MetaButton button;
-
- type = META_BUTTON_TYPE_LAST;
+ MetaButton *button;
switch (control)
{
@@ -356,22 +356,22 @@ get_control_rect (MetaFrameControl control,
case META_FRAME_CONTROL_RESIZE_E:
case META_FRAME_CONTROL_NONE:
default:
+ type = META_BUTTON_TYPE_LAST;
break;
}
+ if (type == META_BUTTON_TYPE_LAST)
+ return FALSE;
+
theme = meta_ui_get_theme ();
+ button = meta_theme_get_button (theme, x, y);
- if (type != META_BUTTON_TYPE_LAST &&
- meta_theme_get_button (theme, x, y, &button))
- {
- if (type == button.type)
- {
- *rect = button.rect.clickable;
- return TRUE;
- }
- }
+ if (button == NULL || meta_button_get_type (button) != type)
+ return FALSE;
- return FALSE;
+ meta_button_get_event_rect (button, rect);
+
+ return TRUE;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]