mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
use the preview widget here
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
This commit is contained in:
parent
813e6f459f
commit
a7378b709b
15
ChangeLog
15
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>
|
2002-02-14 Anders Carlsson <andersca@gnu.org>
|
||||||
|
|
||||||
* src/themes/Crux/metacity-theme-1.xml: Fix some bugs with
|
* src/themes/Crux/metacity-theme-1.xml: Fix some bugs with
|
||||||
|
@ -64,6 +64,8 @@ metacity_SOURCES= \
|
|||||||
metacity_theme_viewer_SOURCES= \
|
metacity_theme_viewer_SOURCES= \
|
||||||
gradient.c \
|
gradient.c \
|
||||||
gradient.h \
|
gradient.h \
|
||||||
|
preview-widget.c \
|
||||||
|
preview-widget.h \
|
||||||
theme.c \
|
theme.c \
|
||||||
theme.h \
|
theme.h \
|
||||||
theme-parser.c \
|
theme-parser.c \
|
||||||
|
32
src/frames.c
32
src/frames.c
@ -281,23 +281,43 @@ meta_frames_ensure_layout (MetaFrames *frames,
|
|||||||
MetaUIFrame *frame)
|
MetaUIFrame *frame)
|
||||||
{
|
{
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
MetaFrameFlags flags;
|
||||||
|
MetaFrameType type;
|
||||||
|
MetaFrameStyle *style;
|
||||||
|
|
||||||
g_return_if_fail (GTK_WIDGET_REALIZED (frames));
|
g_return_if_fail (GTK_WIDGET_REALIZED (frames));
|
||||||
|
|
||||||
widget = GTK_WIDGET (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)
|
if (frame->layout == NULL)
|
||||||
{
|
{
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
PangoFontDescription *font_desc;
|
PangoFontDescription *font_desc;
|
||||||
MetaFrameFlags flags;
|
|
||||||
MetaFrameType type;
|
|
||||||
double scale;
|
double scale;
|
||||||
int size;
|
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 (),
|
scale = meta_theme_get_title_scale (meta_theme_get_current (),
|
||||||
type,
|
type,
|
||||||
flags);
|
flags);
|
||||||
@ -346,6 +366,7 @@ meta_frames_ensure_layout (MetaFrames *frames,
|
|||||||
|
|
||||||
pango_font_description_free (font_desc);
|
pango_font_description_free (font_desc);
|
||||||
|
|
||||||
|
/* Save some RAM */
|
||||||
g_free (frame->title);
|
g_free (frame->title);
|
||||||
frame->title = NULL;
|
frame->title = NULL;
|
||||||
}
|
}
|
||||||
@ -404,6 +425,7 @@ meta_frames_manage_window (MetaFrames *frames,
|
|||||||
/* Don't set event mask here, it's in frame.c */
|
/* Don't set event mask here, it's in frame.c */
|
||||||
|
|
||||||
frame->xwindow = xwindow;
|
frame->xwindow = xwindow;
|
||||||
|
frame->cache_style = NULL;
|
||||||
frame->layout = NULL;
|
frame->layout = NULL;
|
||||||
frame->text_height = -1;
|
frame->text_height = -1;
|
||||||
frame->title = NULL;
|
frame->title = NULL;
|
||||||
|
@ -67,11 +67,13 @@ struct _MetaUIFrame
|
|||||||
{
|
{
|
||||||
Window xwindow;
|
Window xwindow;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
|
MetaFrameStyle *cache_style;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
int text_height;
|
int text_height;
|
||||||
char *title; /* NULL once we have a layout */
|
char *title; /* NULL once we have a layout */
|
||||||
guint expose_delayed : 1;
|
guint expose_delayed : 1;
|
||||||
|
|
||||||
|
/* FIXME get rid of this, it can just be in the MetaFrames struct */
|
||||||
MetaFrameControl prelit_control;
|
MetaFrameControl prelit_control;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "theme-parser.h"
|
#include "theme-parser.h"
|
||||||
#include "inlinepixbufs.h"
|
#include "preview-widget.h"
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -38,174 +38,14 @@ static void run_position_expression_timings (void);
|
|||||||
static void run_theme_benchmark (int client_width,
|
static void run_theme_benchmark (int client_width,
|
||||||
int client_height);
|
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
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *layout;
|
GtkWidget *layout;
|
||||||
GtkWidget *sw;
|
GtkWidget *sw;
|
||||||
GtkWidget *da;
|
GtkWidget *preview;
|
||||||
|
GtkWidget *contents;
|
||||||
GdkColor desktop_color;
|
GdkColor desktop_color;
|
||||||
GError *err;
|
GError *err;
|
||||||
clock_t start, end;
|
clock_t start, end;
|
||||||
@ -271,18 +111,19 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
gtk_widget_modify_bg (layout, GTK_STATE_NORMAL, &desktop_color);
|
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",
|
contents = gtk_button_new_with_label ("Application window contents\n"
|
||||||
G_CALLBACK (expose_handler), NULL);
|
"go in here");
|
||||||
|
|
||||||
|
gtk_container_add (GTK_CONTAINER (preview), contents);
|
||||||
|
|
||||||
gtk_layout_put (GTK_LAYOUT (layout),
|
gtk_layout_put (GTK_LAYOUT (layout),
|
||||||
da,
|
preview,
|
||||||
5, 5);
|
5, 5);
|
||||||
|
|
||||||
gtk_widget_realize (da);
|
gtk_widget_realize (preview); /* http://bugzilla.gnome.org/show_bug.cgi?id=71343 */
|
||||||
set_widget_to_frame_size (da);
|
|
||||||
|
|
||||||
gtk_widget_show_all (window);
|
gtk_widget_show_all (window);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
@ -290,6 +131,38 @@ main (int argc, char **argv)
|
|||||||
return 0;
|
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
|
static void
|
||||||
run_theme_benchmark (int client_width,
|
run_theme_benchmark (int client_width,
|
||||||
int client_height)
|
int client_height)
|
||||||
@ -345,8 +218,8 @@ run_theme_benchmark (int client_width,
|
|||||||
layout,
|
layout,
|
||||||
get_text_height (widget),
|
get_text_height (widget),
|
||||||
button_states,
|
button_states,
|
||||||
get_mini_icon (),
|
meta_preview_get_mini_icon (),
|
||||||
get_icon ());
|
meta_preview_get_icon ());
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
src/theme.c
14
src/theme.c
@ -4291,6 +4291,20 @@ theme_get_style (MetaTheme *theme,
|
|||||||
return style;
|
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
|
double
|
||||||
meta_theme_get_title_scale (MetaTheme *theme,
|
meta_theme_get_title_scale (MetaTheme *theme,
|
||||||
MetaFrameType type,
|
MetaFrameType type,
|
||||||
|
@ -649,6 +649,10 @@ GdkPixbuf* meta_theme_load_image (MetaTheme *theme,
|
|||||||
const char *filename,
|
const char *filename,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
MetaFrameStyle* meta_theme_get_frame_style (MetaTheme *theme,
|
||||||
|
MetaFrameType type,
|
||||||
|
MetaFrameFlags flags);
|
||||||
|
|
||||||
double meta_theme_get_title_scale (MetaTheme *theme,
|
double meta_theme_get_title_scale (MetaTheme *theme,
|
||||||
MetaFrameType type,
|
MetaFrameType type,
|
||||||
MetaFrameFlags flags);
|
MetaFrameFlags flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user