[metacity] move MetaStyleInfo to libmetacity
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] move MetaStyleInfo to libmetacity
- Date: Thu, 28 Jan 2016 21:42:09 +0000 (UTC)
commit 624308207a1692a5e13d17c58e2554891bb1b5a9
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Jan 28 23:37:42 2016 +0200
move MetaStyleInfo to libmetacity
libmetacity/Makefile.am | 3 +
libmetacity/meta-style-info.c | 220 +++++++++++++++++++++++++++++++++++++++++
libmetacity/meta-style-info.h | 56 +++++++++++
src/ui/frames.c | 10 +--
src/ui/preview-widget.c | 4 +-
src/ui/theme-viewer.c | 4 +-
src/ui/theme.c | 199 -------------------------------------
src/ui/theme.h | 33 +------
src/ui/ui.c | 2 +-
9 files changed, 287 insertions(+), 244 deletions(-)
---
diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am
index 2e0adda..5c2a89b 100644
--- a/libmetacity/Makefile.am
+++ b/libmetacity/Makefile.am
@@ -23,6 +23,8 @@ libmetacity_la_SOURCES = \
meta-gradient-spec.h \
meta-hsla.c \
meta-hsla-private.h \
+ meta-style-info.c \
+ meta-style-info.h \
meta-theme.c \
meta-theme.h \
meta-theme-gtk.c \
@@ -64,6 +66,7 @@ libmetacity_include_HEADERS = \
meta-frame-type.h \
meta-gradient.h \
meta-gradient-spec.h \
+ meta-style-info.h \
meta-theme.h \
meta-theme-gtk.h \
meta-theme-impl.h \
diff --git a/libmetacity/meta-style-info.c b/libmetacity/meta-style-info.c
new file mode 100644
index 0000000..d2c0092
--- /dev/null
+++ b/libmetacity/meta-style-info.c
@@ -0,0 +1,220 @@
+/*
+ * 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-frame-flags.h"
+#include "meta-style-info.h"
+
+static void
+add_toplevel_class (GtkStyleContext *style,
+ const gchar *class_name)
+{
+ if (gtk_style_context_get_parent (style))
+ {
+ GtkWidgetPath *path;
+
+ path = gtk_widget_path_copy (gtk_style_context_get_path (style));
+ gtk_widget_path_iter_add_class (path, 0, class_name);
+ gtk_style_context_set_path (style, path);
+ gtk_widget_path_unref (path);
+ }
+ else
+ gtk_style_context_add_class (style, class_name);
+}
+
+static void
+remove_toplevel_class (GtkStyleContext *style,
+ const gchar *class_name)
+{
+ if (gtk_style_context_get_parent (style))
+ {
+ GtkWidgetPath *path;
+
+ path = gtk_widget_path_copy (gtk_style_context_get_path (style));
+ gtk_widget_path_iter_remove_class (path, 0, class_name);
+ gtk_style_context_set_path (style, path);
+ gtk_widget_path_unref (path);
+ }
+ else
+ gtk_style_context_remove_class (style, class_name);
+}
+
+static GtkStyleContext *
+create_style_context (GtkStyleContext *parent,
+ GtkCssProvider *provider,
+ const char *object_name,
+ const char *first_class,
+ ...)
+{
+ GtkWidgetPath *path;
+ GtkStyleContext *context;
+ const char *name;
+ va_list ap;
+
+ if (parent)
+ path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
+ else
+ path = gtk_widget_path_new ();
+
+ gtk_widget_path_append_type (path, G_TYPE_NONE);
+ gtk_widget_path_iter_set_object_name (path, -1, object_name);
+
+ va_start (ap, first_class);
+ for (name = first_class; name; name = va_arg (ap, const char *))
+ gtk_widget_path_iter_add_class (path, -1, name);
+ va_end (ap);
+
+ context = gtk_style_context_new ();
+ gtk_style_context_set_path (context, path);
+ gtk_style_context_set_parent (context, parent);
+ gtk_widget_path_unref (path);
+
+ gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
+
+ return context;
+}
+
+MetaStyleInfo *
+meta_style_info_new (const gchar *variant,
+ gboolean composited)
+{
+ MetaStyleInfo *style_info;
+ GtkCssProvider *provider;
+ char *theme_name;
+
+ g_object_get (gtk_settings_get_default (),
+ "gtk-theme-name", &theme_name,
+ NULL);
+
+ if (theme_name && *theme_name)
+ provider = gtk_css_provider_get_named (theme_name, variant);
+ else
+ provider = gtk_css_provider_get_default ();
+ g_free (theme_name);
+
+ style_info = g_new0 (MetaStyleInfo, 1);
+ style_info->refcount = 1;
+
+ style_info->styles[META_STYLE_ELEMENT_WINDOW] =
+ create_style_context (NULL,
+ provider,
+ "window",
+ GTK_STYLE_CLASS_BACKGROUND,
+ composited == TRUE ? "ssd" : "solid-csd",
+ NULL);
+ style_info->styles[META_STYLE_ELEMENT_DECORATION] =
+ create_style_context (style_info->styles[META_STYLE_ELEMENT_WINDOW],
+ provider,
+ "decoration",
+ NULL);
+ style_info->styles[META_STYLE_ELEMENT_TITLEBAR] =
+ create_style_context (style_info->styles[META_STYLE_ELEMENT_DECORATION],
+ provider,
+ "headerbar",
+ GTK_STYLE_CLASS_TITLEBAR,
+ GTK_STYLE_CLASS_HORIZONTAL,
+ "default-decoration",
+ NULL);
+ style_info->styles[META_STYLE_ELEMENT_TITLE] =
+ create_style_context (style_info->styles[META_STYLE_ELEMENT_TITLEBAR],
+ provider,
+ "label",
+ GTK_STYLE_CLASS_TITLE,
+ NULL);
+ style_info->styles[META_STYLE_ELEMENT_BUTTON] =
+ create_style_context (style_info->styles[META_STYLE_ELEMENT_TITLEBAR],
+ provider,
+ "button",
+ "titlebutton",
+ NULL);
+ style_info->styles[META_STYLE_ELEMENT_IMAGE] =
+ create_style_context (style_info->styles[META_STYLE_ELEMENT_BUTTON],
+ provider,
+ "image",
+ NULL);
+
+ return style_info;
+}
+
+MetaStyleInfo *
+meta_style_info_ref (MetaStyleInfo *style_info)
+{
+ g_return_val_if_fail (style_info != NULL, NULL);
+ g_return_val_if_fail (style_info->refcount > 0, NULL);
+
+ g_atomic_int_inc ((volatile int *)&style_info->refcount);
+ return style_info;
+}
+
+void
+meta_style_info_unref (MetaStyleInfo *style_info)
+{
+ g_return_if_fail (style_info != NULL);
+ g_return_if_fail (style_info->refcount > 0);
+
+ if (g_atomic_int_dec_and_test ((volatile int *)&style_info->refcount))
+ {
+ int i;
+ for (i = 0; i < META_STYLE_ELEMENT_LAST; i++)
+ g_object_unref (style_info->styles[i]);
+ g_free (style_info);
+ }
+}
+
+void
+meta_style_info_set_flags (MetaStyleInfo *style_info,
+ MetaFrameFlags flags)
+{
+ GtkStyleContext *style;
+ gboolean backdrop;
+ int i;
+
+ backdrop = !(flags & META_FRAME_HAS_FOCUS);
+ if (flags & META_FRAME_IS_FLASHING)
+ backdrop = !backdrop;
+
+ for (i = 0; i < META_STYLE_ELEMENT_LAST; i++)
+ {
+ GtkStateFlags state;
+
+ style = style_info->styles[i];
+
+ state = gtk_style_context_get_state (style);
+ if (backdrop)
+ gtk_style_context_set_state (style, state | GTK_STATE_FLAG_BACKDROP);
+ else
+ gtk_style_context_set_state (style, state & ~GTK_STATE_FLAG_BACKDROP);
+
+ if (flags & META_FRAME_TILED_LEFT || flags & META_FRAME_TILED_RIGHT)
+ add_toplevel_class (style, "tiled");
+ else
+ remove_toplevel_class (style, "tiled");
+
+ if (flags & META_FRAME_MAXIMIZED)
+ add_toplevel_class (style, "maximized");
+ else
+ remove_toplevel_class (style, "maximized");
+
+ if (flags & META_FRAME_FULLSCREEN)
+ add_toplevel_class (style, "fullscreen");
+ else
+ remove_toplevel_class (style, "fullscreen");
+ }
+}
diff --git a/libmetacity/meta-style-info.h b/libmetacity/meta-style-info.h
new file mode 100644
index 0000000..a4b826a
--- /dev/null
+++ b/libmetacity/meta-style-info.h
@@ -0,0 +1,56 @@
+/*
+ * 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_STYLE_INFO_H
+#define META_STYLE_INFO_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+ META_STYLE_ELEMENT_WINDOW,
+ META_STYLE_ELEMENT_DECORATION,
+ META_STYLE_ELEMENT_TITLEBAR,
+ META_STYLE_ELEMENT_TITLE,
+ META_STYLE_ELEMENT_BUTTON,
+ META_STYLE_ELEMENT_IMAGE,
+ META_STYLE_ELEMENT_LAST
+} MetaStyleElement;
+
+typedef struct
+{
+ int refcount;
+
+ GtkStyleContext *styles[META_STYLE_ELEMENT_LAST];
+} MetaStyleInfo;
+
+MetaStyleInfo *meta_style_info_new (const gchar *variant,
+ gboolean composited);
+
+MetaStyleInfo *meta_style_info_ref (MetaStyleInfo *style_info);
+
+void meta_style_info_unref (MetaStyleInfo *style_info);
+
+void meta_style_info_set_flags (MetaStyleInfo *style_info,
+ MetaFrameFlags flags);
+
+G_END_DECLS
+
+#endif
diff --git a/src/ui/frames.c b/src/ui/frames.c
index bfcd69e..30c4723 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -183,9 +183,7 @@ meta_frames_get_theme_variant (MetaFrames *frames,
style_info = g_hash_table_lookup (frames->style_variants, variant);
if (style_info == NULL)
{
- style_info = meta_theme_create_style_info (meta_theme_get_current (),
- gtk_widget_get_screen (GTK_WIDGET (frames)),
- variant);
+ style_info = meta_style_info_new (variant, meta_theme_get_current ()->composited);
g_hash_table_insert (frames->style_variants, g_strdup (variant), style_info);
}
@@ -198,19 +196,17 @@ update_style_contexts (MetaFrames *frames)
MetaStyleInfo *style_info;
GList *variants, *variant;
MetaTheme *theme;
- GdkScreen *screen;
theme = meta_theme_get_current ();
- screen = gtk_widget_get_screen (GTK_WIDGET (frames));
if (frames->normal_style)
meta_style_info_unref (frames->normal_style);
- frames->normal_style = meta_theme_create_style_info (theme, screen, NULL);
+ frames->normal_style = meta_style_info_new (NULL, theme->composited);
variants = g_hash_table_get_keys (frames->style_variants);
for (variant = variants; variant; variant = variants->next)
{
- style_info = meta_theme_create_style_info (theme, screen, (char *)variant->data);
+ style_info = meta_style_info_new ((char *)variant->data, theme->composited);
g_hash_table_insert (frames->style_variants,
g_strdup (variant->data), style_info);
}
diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c
index ac15ad3..64df2fa 100644
--- a/src/ui/preview-widget.c
+++ b/src/ui/preview-widget.c
@@ -264,9 +264,7 @@ meta_preview_realize (GtkWidget *widget)
GTK_WIDGET_CLASS (meta_preview_parent_class)->realize (widget);
- preview->style_info = meta_theme_create_style_info (preview->theme,
- gtk_widget_get_screen (widget),
- NULL);
+ preview->style_info = meta_style_info_new (NULL, preview->theme->composited);
}
#define NO_CHILD_WIDTH 80
diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c
index b1f2932..723121c 100644
--- a/src/ui/theme-viewer.c
+++ b/src/ui/theme-viewer.c
@@ -916,7 +916,7 @@ main (int argc, char **argv)
gtk_widget_realize (window);
- style_info = meta_theme_create_style_info (global_theme, gtk_widget_get_screen (window), NULL);
+ style_info = meta_style_info_new (NULL, global_theme->composited);
gtk_style_context_get (style_info->styles[META_STYLE_ELEMENT_DECORATION],
GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL);
meta_style_info_unref (style_info);
@@ -1043,7 +1043,7 @@ run_theme_benchmark (void)
widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_realize (widget);
- style_info = meta_theme_create_style_info (global_theme, gtk_widget_get_screen (widget), NULL);
+ style_info = meta_style_info_new (NULL, global_theme->composited);
meta_theme_get_frame_borders (global_theme,
style_info,
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 782bea4..a0de20a 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -5128,205 +5128,6 @@ meta_theme_get_title_scale (MetaTheme *theme,
return style->layout->title_scale;
}
-static GtkStyleContext *
-create_style_context (GtkStyleContext *parent,
- GtkCssProvider *provider,
- const char *object_name,
- const char *first_class,
- ...)
-{
- GtkWidgetPath *path;
- GtkStyleContext *context;
- const char *name;
- va_list ap;
-
- if (parent)
- path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
- else
- path = gtk_widget_path_new ();
-
- gtk_widget_path_append_type (path, G_TYPE_NONE);
- gtk_widget_path_iter_set_object_name (path, -1, object_name);
-
- va_start (ap, first_class);
- for (name = first_class; name; name = va_arg (ap, const char *))
- gtk_widget_path_iter_add_class (path, -1, name);
- va_end (ap);
-
- context = gtk_style_context_new ();
- gtk_style_context_set_path (context, path);
- gtk_style_context_set_parent (context, parent);
- gtk_widget_path_unref (path);
-
- gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider),
- GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
-
- return context;
-}
-
-MetaStyleInfo *
-meta_theme_create_style_info (MetaTheme *theme,
- GdkScreen *screen,
- const gchar *variant)
-{
- MetaStyleInfo *style_info;
- GtkCssProvider *provider;
- char *theme_name;
-
- g_object_get (gtk_settings_get_for_screen (screen),
- "gtk-theme-name", &theme_name,
- NULL);
-
- if (theme_name && *theme_name)
- provider = gtk_css_provider_get_named (theme_name, variant);
- else
- provider = gtk_css_provider_get_default ();
- g_free (theme_name);
-
- style_info = g_new0 (MetaStyleInfo, 1);
- style_info->refcount = 1;
-
- style_info->styles[META_STYLE_ELEMENT_WINDOW] =
- create_style_context (NULL,
- provider,
- "window",
- GTK_STYLE_CLASS_BACKGROUND,
- theme->composited == TRUE ? "ssd" : "solid-csd",
- NULL);
- style_info->styles[META_STYLE_ELEMENT_DECORATION] =
- create_style_context (style_info->styles[META_STYLE_ELEMENT_WINDOW],
- provider,
- "decoration",
- NULL);
- style_info->styles[META_STYLE_ELEMENT_TITLEBAR] =
- create_style_context (style_info->styles[META_STYLE_ELEMENT_DECORATION],
- provider,
- "headerbar",
- GTK_STYLE_CLASS_TITLEBAR,
- GTK_STYLE_CLASS_HORIZONTAL,
- "default-decoration",
- NULL);
- style_info->styles[META_STYLE_ELEMENT_TITLE] =
- create_style_context (style_info->styles[META_STYLE_ELEMENT_TITLEBAR],
- provider,
- "label",
- GTK_STYLE_CLASS_TITLE,
- NULL);
- style_info->styles[META_STYLE_ELEMENT_BUTTON] =
- create_style_context (style_info->styles[META_STYLE_ELEMENT_TITLEBAR],
- provider,
- "button",
- "titlebutton",
- NULL);
- style_info->styles[META_STYLE_ELEMENT_IMAGE] =
- create_style_context (style_info->styles[META_STYLE_ELEMENT_BUTTON],
- provider,
- "image",
- NULL);
-
- return style_info;
-}
-
-MetaStyleInfo *
-meta_style_info_ref (MetaStyleInfo *style_info)
-{
- g_return_val_if_fail (style_info != NULL, NULL);
- g_return_val_if_fail (style_info->refcount > 0, NULL);
-
- g_atomic_int_inc ((volatile int *)&style_info->refcount);
- return style_info;
-}
-
-void
-meta_style_info_unref (MetaStyleInfo *style_info)
-{
- g_return_if_fail (style_info != NULL);
- g_return_if_fail (style_info->refcount > 0);
-
- if (g_atomic_int_dec_and_test ((volatile int *)&style_info->refcount))
- {
- int i;
- for (i = 0; i < META_STYLE_ELEMENT_LAST; i++)
- g_object_unref (style_info->styles[i]);
- g_free (style_info);
- }
-}
-
-static void
-add_toplevel_class (GtkStyleContext *style,
- const gchar *class_name)
-{
- if (gtk_style_context_get_parent (style))
- {
- GtkWidgetPath *path;
-
- path = gtk_widget_path_copy (gtk_style_context_get_path (style));
- gtk_widget_path_iter_add_class (path, 0, class_name);
- gtk_style_context_set_path (style, path);
- gtk_widget_path_unref (path);
- }
- else
- gtk_style_context_add_class (style, class_name);
-}
-
-static void
-remove_toplevel_class (GtkStyleContext *style,
- const gchar *class_name)
-{
- if (gtk_style_context_get_parent (style))
- {
- GtkWidgetPath *path;
-
- path = gtk_widget_path_copy (gtk_style_context_get_path (style));
- gtk_widget_path_iter_remove_class (path, 0, class_name);
- gtk_style_context_set_path (style, path);
- gtk_widget_path_unref (path);
- }
- else
- gtk_style_context_remove_class (style, class_name);
-}
-
-void
-meta_style_info_set_flags (MetaStyleInfo *style_info,
- MetaFrameFlags flags)
-{
- GtkStyleContext *style;
- gboolean backdrop;
- int i;
-
- backdrop = !(flags & META_FRAME_HAS_FOCUS);
- if (flags & META_FRAME_IS_FLASHING)
- backdrop = !backdrop;
-
- for (i = 0; i < META_STYLE_ELEMENT_LAST; i++)
- {
- GtkStateFlags state;
-
- style = style_info->styles[i];
-
- state = gtk_style_context_get_state (style);
- if (backdrop)
- gtk_style_context_set_state (style, state | GTK_STATE_FLAG_BACKDROP);
- else
- gtk_style_context_set_state (style, state & ~GTK_STATE_FLAG_BACKDROP);
-
- if (flags & META_FRAME_TILED_LEFT || flags & META_FRAME_TILED_RIGHT)
- add_toplevel_class (style, "tiled");
- else
- remove_toplevel_class (style, "tiled");
-
- if (flags & META_FRAME_MAXIMIZED)
- add_toplevel_class (style, "maximized");
- else
- remove_toplevel_class (style, "maximized");
-
- if (flags & META_FRAME_FULLSCREEN)
- add_toplevel_class (style, "fullscreen");
- else
- remove_toplevel_class (style, "fullscreen");
- }
-}
-
PangoFontDescription*
meta_style_info_create_font_desc (MetaTheme *theme,
MetaStyleInfo *style_info)
diff --git a/src/ui/theme.h b/src/ui/theme.h
index 1b218fd..7fb8e54 100644
--- a/src/ui/theme.h
+++ b/src/ui/theme.h
@@ -28,12 +28,8 @@
#include <libmetacity/meta-frame-flags.h>
#include <libmetacity/meta-frame-type.h>
#include <libmetacity/meta-theme.h>
+#include <libmetacity/meta-style-info.h>
-/**
- * MetaStyleInfo: (skip)
- *
- */
-typedef struct _MetaStyleInfo MetaStyleInfo;
typedef struct _MetaButtonSpace MetaButtonSpace;
typedef struct _MetaFrameGeometry MetaFrameGeometry;
typedef struct _MetaTheme MetaTheme;
@@ -143,24 +139,6 @@ typedef enum
META_BUTTON_TYPE_LAST
} MetaButtonType;
-typedef enum
-{
- META_STYLE_ELEMENT_WINDOW,
- META_STYLE_ELEMENT_DECORATION,
- META_STYLE_ELEMENT_TITLEBAR,
- META_STYLE_ELEMENT_TITLE,
- META_STYLE_ELEMENT_BUTTON,
- META_STYLE_ELEMENT_IMAGE,
- META_STYLE_ELEMENT_LAST
-} MetaStyleElement;
-
-struct _MetaStyleInfo
-{
- int refcount;
-
- GtkStyleContext *styles[META_STYLE_ELEMENT_LAST];
-};
-
MetaTheme* meta_theme_get_current (void);
void meta_theme_set_current (const char *name,
gboolean force_reload,
@@ -183,15 +161,6 @@ double meta_theme_get_title_scale (MetaTheme *theme,
MetaFrameType type,
MetaFrameFlags flags);
-MetaStyleInfo* meta_theme_create_style_info (MetaTheme *theme,
- GdkScreen *screen,
- const gchar *variant);
-MetaStyleInfo* meta_style_info_ref (MetaStyleInfo *style);
-void meta_style_info_unref (MetaStyleInfo *style_info);
-
-void meta_style_info_set_flags (MetaStyleInfo *style_info,
- MetaFrameFlags flags);
-
void meta_theme_draw_frame (MetaTheme *theme,
MetaStyleInfo *style_info,
cairo_t *cr,
diff --git a/src/ui/ui.c b/src/ui/ui.c
index cca5126..4a8e3da 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -678,7 +678,7 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
MetaTheme *current;
current = meta_theme_get_current ();
- style_info = meta_theme_create_style_info (current, screen, NULL);
+ style_info = meta_style_info_new (NULL, current->composited);
context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames));
font_desc = meta_prefs_get_titlebar_font ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]