summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--src/Makefile.am2
-rw-r--r--src/frames.c34
-rw-r--r--src/frames.h2
-rw-r--r--src/theme-viewer.c217
-rw-r--r--src/theme.c14
-rw-r--r--src/theme.h4
7 files changed, 110 insertions, 178 deletions
diff --git a/ChangeLog b/ChangeLog
index f47ea61..f428e23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2002-02-14 Havoc Pennington <hp@pobox.com>
+
+ * src/theme-viewer.c: use the preview widget here
+
+ * src/preview-widget.h, src/preview-widget.c: make the theme
+ preview into a nice widget
+
+ * src/frames.c (meta_frames_ensure_layout): replace frame layout
+ if the frame style changes, this only ends up mattering if you
+ e.g. changed the font size for windows in a different state such
+ as maximized, which is crack, but the code may as well be correct
+
+ * src/theme.c (meta_theme_get_frame_style): new function so we can
+ detect an invalid cache of the PangoLayout in a frame
+
2002-02-14 Anders Carlsson <andersca@gnu.org>
* src/themes/Crux/metacity-theme-1.xml: Fix some bugs with
diff --git a/src/Makefile.am b/src/Makefile.am
index 0c840c3..f84b0f6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,8 @@ metacity_SOURCES= \
metacity_theme_viewer_SOURCES= \
gradient.c \
gradient.h \
+ preview-widget.c \
+ preview-widget.h \
theme.c \
theme.h \
theme-parser.c \
diff --git a/src/frames.c b/src/frames.c
index d6e5764..148b12c 100644
--- a/src/frames.c
+++ b/src/frames.c
@@ -281,29 +281,49 @@ meta_frames_ensure_layout (MetaFrames *frames,
MetaUIFrame *frame)
{
GtkWidget *widget;
+ MetaFrameFlags flags;
+ MetaFrameType type;
+ MetaFrameStyle *style;
g_return_if_fail (GTK_WIDGET_REALIZED (frames));
widget = GTK_WIDGET (frames);
+
+ flags = meta_core_get_frame_flags (gdk_display, frame->xwindow);
+ type = meta_core_get_frame_type (gdk_display, frame->xwindow);
+
+ style = meta_theme_get_frame_style (meta_theme_get_current (),
+ type, flags);
+
+ if (style != frame->cache_style)
+ {
+ if (frame->layout)
+ {
+ /* save title to recreate layout */
+ g_free (frame->title);
+
+ frame->title = g_strdup (pango_layout_get_text (frame->layout));
+
+ g_object_unref (G_OBJECT (frame->layout));
+ frame->layout = NULL;
+ }
+ }
+
+ frame->cache_style = style;
if (frame->layout == NULL)
{
gpointer key, value;
PangoFontDescription *font_desc;
- MetaFrameFlags flags;
- MetaFrameType type;
double scale;
int size;
- flags = meta_core_get_frame_flags (gdk_display, frame->xwindow);
- type = meta_core_get_frame_type (gdk_display, frame->xwindow);
-
scale = meta_theme_get_title_scale (meta_theme_get_current (),
type,
flags);
frame->layout = gtk_widget_create_pango_layout (widget, frame->title);
-
+
font_desc = meta_gtk_widget_get_font_desc (widget, scale);
size = pango_font_description_get_size (font_desc);
@@ -346,6 +366,7 @@ meta_frames_ensure_layout (MetaFrames *frames,
pango_font_description_free (font_desc);
+ /* Save some RAM */
g_free (frame->title);
frame->title = NULL;
}
@@ -404,6 +425,7 @@ meta_frames_manage_window (MetaFrames *frames,
/* Don't set event mask here, it's in frame.c */
frame->xwindow = xwindow;
+ frame->cache_style = NULL;
frame->layout = NULL;
frame->text_height = -1;
frame->title = NULL;
diff --git a/src/frames.h b/src/frames.h
index 6b39214..dc81f7b 100644
--- a/src/frames.h
+++ b/src/frames.h
@@ -67,11 +67,13 @@ struct _MetaUIFrame
{
Window xwindow;
GdkWindow *window;
+ MetaFrameStyle *cache_style;
PangoLayout *layout;
int text_height;
char *title; /* NULL once we have a layout */
guint expose_delayed : 1;
+ /* FIXME get rid of this, it can just be in the MetaFrames struct */
MetaFrameControl prelit_control;
};
diff --git a/src/theme-viewer.c b/src/theme-viewer.c
index 765acad..2844d5b 100644
--- a/src/theme-viewer.c
+++ b/src/theme-viewer.c
@@ -23,7 +23,7 @@
#include "util.h"
#include "theme.h"
#include "theme-parser.h"
-#include "inlinepixbufs.h"
+#include "preview-widget.h"
#include <gtk/gtk.h>
#include <time.h>
#include <stdlib.h>
@@ -38,174 +38,14 @@ static void run_position_expression_timings (void);
static void run_theme_benchmark (int client_width,
int client_height);
-static MetaFrameFlags
-get_flags (GtkWidget *widget)
-{
- return META_FRAME_ALLOWS_DELETE |
- META_FRAME_ALLOWS_MENU |
- META_FRAME_ALLOWS_MINIMIZE |
- META_FRAME_ALLOWS_MAXIMIZE |
- META_FRAME_ALLOWS_VERTICAL_RESIZE |
- META_FRAME_ALLOWS_HORIZONTAL_RESIZE |
- META_FRAME_HAS_FOCUS |
- META_FRAME_ALLOWS_SHADE |
- META_FRAME_ALLOWS_MOVE;
-}
-
-static int
-get_text_height (GtkWidget *widget)
-{
- return meta_pango_font_desc_get_text_height (widget->style->font_desc,
- gtk_widget_get_pango_context (widget));
-}
-
-static PangoLayout*
-create_title_layout (GtkWidget *widget)
-{
- PangoLayout *layout;
-
- layout = gtk_widget_create_pango_layout (widget, "Window Title Goes Here");
-
- return layout;
-}
-
-
-#ifdef HAVE_GDK_PIXBUF_NEW_FROM_STREAM
-#define gdk_pixbuf_new_from_inline gdk_pixbuf_new_from_stream
-#endif
-
-static GdkPixbuf*
-get_icon (void)
-{
- static GdkPixbuf *default_icon = NULL;
-
- if (default_icon == NULL)
- {
- GdkPixbuf *base;
-
- base = gdk_pixbuf_new_from_inline (-1, default_icon_data,
- FALSE,
- NULL);
-
- g_assert (base);
-
- default_icon = gdk_pixbuf_scale_simple (base,
- META_ICON_WIDTH,
- META_ICON_HEIGHT,
- GDK_INTERP_BILINEAR);
-
- g_object_unref (G_OBJECT (base));
- }
-
- return default_icon;
-}
-
-static GdkPixbuf*
-get_mini_icon (void)
-{
- static GdkPixbuf *default_icon = NULL;
-
- if (default_icon == NULL)
- {
- GdkPixbuf *base;
-
- base = gdk_pixbuf_new_from_inline (-1, default_icon_data,
- FALSE,
- NULL);
-
- g_assert (base);
-
- default_icon = gdk_pixbuf_scale_simple (base,
- META_MINI_ICON_WIDTH,
- META_MINI_ICON_HEIGHT,
- GDK_INTERP_BILINEAR);
-
- g_object_unref (G_OBJECT (base));
- }
-
- return default_icon;
-}
-
-
-static void
-set_widget_to_frame_size (GtkWidget *widget)
-{
- int top_height, bottom_height, left_width, right_width;
-
- meta_theme_get_frame_borders (global_theme,
- META_FRAME_TYPE_NORMAL,
- get_text_height (widget),
- get_flags (widget),
- &top_height,
- &bottom_height,
- &left_width,
- &right_width);
-
- gtk_widget_set_size_request (widget,
- CLIENT_WIDTH + left_width + right_width,
- CLIENT_HEIGHT + top_height + bottom_height);
-}
-
-static gboolean
-expose_handler (GtkWidget *widget,
- GdkEventExpose *event,
- gpointer data)
-{
- MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
- {
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_NORMAL
- };
- int top_height, bottom_height, left_width, right_width;
- PangoLayout *layout;
-
- layout = create_title_layout (widget);
-
- meta_theme_get_frame_borders (global_theme,
- META_FRAME_TYPE_NORMAL,
- get_text_height (widget),
- get_flags (widget),
- &top_height,
- &bottom_height,
- &left_width,
- &right_width);
-
- meta_theme_draw_frame (global_theme,
- widget,
- widget->window,
- &event->area,
- 0, 0,
- META_FRAME_TYPE_NORMAL,
- get_flags (widget),
- CLIENT_WIDTH, CLIENT_HEIGHT,
- layout,
- get_text_height (widget),
- button_states,
- get_mini_icon (),
- get_icon ());
-
- /* Draw the "client" */
-
- gdk_draw_rectangle (widget->window,
- widget->style->white_gc,
- TRUE,
- left_width, top_height,
- CLIENT_WIDTH, CLIENT_HEIGHT);
-
- g_object_unref (G_OBJECT (layout));
-
- return TRUE;
-}
-
int
main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *layout;
GtkWidget *sw;
- GtkWidget *da;
+ GtkWidget *preview;
+ GtkWidget *contents;
GdkColor desktop_color;
GError *err;
clock_t start, end;
@@ -271,18 +111,19 @@ main (int argc, char **argv)
gtk_widget_modify_bg (layout, GTK_STATE_NORMAL, &desktop_color);
- da = gtk_drawing_area_new ();
+ preview = meta_preview_new ();
+ meta_preview_set_theme (META_PREVIEW (preview), global_theme);
- g_signal_connect (G_OBJECT (da), "expose_event",
- G_CALLBACK (expose_handler), NULL);
+ contents = gtk_button_new_with_label ("Application window contents\n"
+ "go in here");
+ gtk_container_add (GTK_CONTAINER (preview), contents);
+
gtk_layout_put (GTK_LAYOUT (layout),
- da,
+ preview,
5, 5);
- gtk_widget_realize (da);
- set_widget_to_frame_size (da);
-
+ gtk_widget_realize (preview); /* http://bugzilla.gnome.org/show_bug.cgi?id=71343 */
gtk_widget_show_all (window);
gtk_main ();
@@ -290,6 +131,38 @@ main (int argc, char **argv)
return 0;
}
+
+static MetaFrameFlags
+get_flags (GtkWidget *widget)
+{
+ return META_FRAME_ALLOWS_DELETE |
+ META_FRAME_ALLOWS_MENU |
+ META_FRAME_ALLOWS_MINIMIZE |
+ META_FRAME_ALLOWS_MAXIMIZE |
+ META_FRAME_ALLOWS_VERTICAL_RESIZE |
+ META_FRAME_ALLOWS_HORIZONTAL_RESIZE |
+ META_FRAME_HAS_FOCUS |
+ META_FRAME_ALLOWS_SHADE |
+ META_FRAME_ALLOWS_MOVE;
+}
+
+static int
+get_text_height (GtkWidget *widget)
+{
+ return meta_pango_font_desc_get_text_height (widget->style->font_desc,
+ gtk_widget_get_pango_context (widget));
+}
+
+static PangoLayout*
+create_title_layout (GtkWidget *widget)
+{
+ PangoLayout *layout;
+
+ layout = gtk_widget_create_pango_layout (widget, "Window Title Goes Here");
+
+ return layout;
+}
+
static void
run_theme_benchmark (int client_width,
int client_height)
@@ -345,8 +218,8 @@ run_theme_benchmark (int client_width,
layout,
get_text_height (widget),
button_states,
- get_mini_icon (),
- get_icon ());
+ meta_preview_get_mini_icon (),
+ meta_preview_get_icon ());
++i;
}
diff --git a/src/theme.c b/src/theme.c
index 028db0d..cb7e1db 100644
--- a/src/theme.c
+++ b/src/theme.c
@@ -4291,6 +4291,20 @@ theme_get_style (MetaTheme *theme,
return style;
}
+MetaFrameStyle*
+meta_theme_get_frame_style (MetaTheme *theme,
+ MetaFrameType type,
+ MetaFrameFlags flags)
+{
+ MetaFrameStyle *style;
+
+ g_return_val_if_fail (type < META_FRAME_TYPE_LAST, NULL);
+
+ style = theme_get_style (theme, type, flags);
+
+ return style;
+}
+
double
meta_theme_get_title_scale (MetaTheme *theme,
MetaFrameType type,
diff --git a/src/theme.h b/src/theme.h
index 17b2b4a..79f9ca4 100644
--- a/src/theme.h
+++ b/src/theme.h
@@ -649,6 +649,10 @@ GdkPixbuf* meta_theme_load_image (MetaTheme *theme,
const char *filename,
GError **error);
+MetaFrameStyle* meta_theme_get_frame_style (MetaTheme *theme,
+ MetaFrameType type,
+ MetaFrameFlags flags);
+
double meta_theme_get_title_scale (MetaTheme *theme,
MetaFrameType type,
MetaFrameFlags flags);