void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, MetaFrameBorders *borders) { int text_height; GtkStyleContext *style = NULL; PangoContext *context; const PangoFontDescription *font_desc; PangoFontDescription *free_font_desc = NULL; if (meta_ui_have_a_theme ()) { context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay); GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen)); GtkWidgetPath *widget_path; style = gtk_style_context_new (); gtk_style_context_set_screen (style, screen); widget_path = gtk_widget_path_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); gtk_style_context_set_path (style, widget_path); gtk_widget_path_free (widget_path); gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, borders); if (free_font_desc) pango_font_description_free (free_font_desc); } else { meta_frame_borders_clear (borders); } if (style != NULL) g_object_unref (style); }
void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, MetaFrameBorders *borders) { int text_height; MetaStyleInfo *style_info = NULL; PangoContext *context; const PangoFontDescription *font_desc; PangoFontDescription *free_font_desc = NULL; GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay); GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen)); style_info = meta_theme_create_style_info (screen, NULL); context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { free_font_desc = meta_style_info_create_font_desc (style_info); font_desc = (const PangoFontDescription *) free_font_desc; } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_default (), style_info, type, text_height, flags, borders); if (free_font_desc) pango_font_description_free (free_font_desc); if (style_info != NULL) meta_style_info_unref (style_info); }
void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, int *top_height, int *bottom_height, int *left_width, int *right_width) { int text_height; PangoContext *context; const PangoFontDescription *font_desc; GtkStyle *default_style; if (meta_ui_have_a_theme ()) { context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, top_height, bottom_height, left_width, right_width); } else { *top_height = *bottom_height = *left_width = *right_width = 0; } }
static void run_theme_benchmark (void) { GtkWidget* widget; GdkPixmap *pixmap; int top_height, bottom_height, left_width, right_width; MetaButtonState button_states[META_BUTTON_TYPE_LAST] = { META_BUTTON_STATE_NORMAL, META_BUTTON_STATE_NORMAL, META_BUTTON_STATE_NORMAL, META_BUTTON_STATE_NORMAL }; PangoLayout *layout; clock_t start; clock_t end; GTimer *timer; int i; MetaButtonLayout button_layout; #define ITERATIONS 100 int client_width; int client_height; int inc; widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_realize (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); layout = create_title_layout (widget); i = 0; while (i < MAX_BUTTONS_PER_CORNER) { button_layout.left_buttons[i] = META_BUTTON_FUNCTION_LAST; button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST; ++i; } button_layout.left_buttons[0] = META_BUTTON_FUNCTION_MENU; button_layout.right_buttons[0] = META_BUTTON_FUNCTION_MINIMIZE; button_layout.right_buttons[1] = META_BUTTON_FUNCTION_MAXIMIZE; button_layout.right_buttons[2] = META_BUTTON_FUNCTION_CLOSE; timer = g_timer_new (); start = clock (); client_width = 50; client_height = 50; inc = 1000 / ITERATIONS; /* Increment to grow width/height, * eliminates caching effects. */ i = 0; while (i < ITERATIONS) { /* Creating the pixmap in the loop is right, since * GDK does the same with its double buffering. */ pixmap = gdk_pixmap_new (widget->window, client_width + left_width + right_width, client_height + top_height + bottom_height, -1); meta_theme_draw_frame (global_theme, widget, pixmap, NULL, 0, 0, META_FRAME_TYPE_NORMAL, get_flags (widget), client_width, client_height, layout, get_text_height (widget), &button_layout, button_states, meta_preview_get_mini_icon (), meta_preview_get_icon ()); g_object_unref (G_OBJECT (pixmap)); ++i; client_width += inc; client_height += inc; } end = clock (); g_timer_stop (timer); milliseconds_to_draw_frame = (g_timer_elapsed (timer, NULL) / (double) ITERATIONS) * 1000; g_print (_("Drew %d frames in %g client-side seconds (%g milliseconds per frame) and %g seconds wall clock time including X server resources (%g milliseconds per frame)\n"), ITERATIONS, ((double)end - (double)start) / CLOCKS_PER_SEC, (((double)end - (double)start) / CLOCKS_PER_SEC / (double) ITERATIONS) * 1000, g_timer_elapsed (timer, NULL), milliseconds_to_draw_frame); g_timer_destroy (timer); g_object_unref (G_OBJECT (layout)); gtk_widget_destroy (widget); #undef ITERATIONS }
void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, int *top_height, int *bottom_height, int *left_width, int *right_width) { int text_height; #if GTK_CHECK_VERSION (3, 0, 0) GtkStyleContext *style = NULL; PangoFontDescription *free_font_desc = NULL; #endif PangoContext *context; const PangoFontDescription *font_desc; if (meta_ui_have_a_theme ()) { context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { #if GTK_CHECK_VERSION (3, 0, 0) GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay); GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen)); GtkWidgetPath *widget_path; style = gtk_style_context_new (); gtk_style_context_set_screen (style, screen); widget_path = gtk_widget_path_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); gtk_style_context_set_path (style, widget_path); gtk_widget_path_free (widget_path); gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; #else GtkStyle *default_style; default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; #endif } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, top_height, bottom_height, left_width, right_width); #if GTK_CHECK_VERSION (3, 0, 0) if (free_font_desc) pango_font_description_free (free_font_desc); #endif } else { *top_height = *bottom_height = *left_width = *right_width = 0; } #if GTK_CHECK_VERSION (3, 0, 0) if (style != NULL) g_object_unref (style); #endif }
void meta_get_decoration_geometry (decor_t *d, MetaTheme *theme, MetaFrameFlags *flags, MetaFrameGeometry *fgeom, MetaButtonLayout *button_layout, MetaFrameType frame_type, GdkRectangle *clip) { #ifdef HAVE_METACITY_3_14_0 MetaFrameBorders borders; #endif gint left_width, right_width, top_height, bottom_height; if (!(frame_type < META_FRAME_TYPE_LAST)) frame_type = META_FRAME_TYPE_NORMAL; if (meta_button_layout_set) { *button_layout = meta_button_layout; } else { gint i; button_layout->left_buttons[0] = META_BUTTON_FUNCTION_MENU; for (i = 1; i < MAX_BUTTONS_PER_CORNER; ++i) button_layout->left_buttons[i] = META_BUTTON_FUNCTION_LAST; button_layout->right_buttons[0] = META_BUTTON_FUNCTION_MINIMIZE; button_layout->right_buttons[1] = META_BUTTON_FUNCTION_MAXIMIZE; button_layout->right_buttons[2] = META_BUTTON_FUNCTION_CLOSE; for (i = 3; i < MAX_BUTTONS_PER_CORNER; ++i) button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST; } *flags = 0; if (d->actions & WNCK_WINDOW_ACTION_CLOSE) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_DELETE; if (d->actions & WNCK_WINDOW_ACTION_MINIMIZE) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_MINIMIZE; if (d->actions & WNCK_WINDOW_ACTION_MAXIMIZE) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_MAXIMIZE; *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_MENU; if (d->actions & WNCK_WINDOW_ACTION_RESIZE) { if (!(d->state & WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY)) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_VERTICAL_RESIZE; if (!(d->state & WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY)) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_HORIZONTAL_RESIZE; } if (d->actions & WNCK_WINDOW_ACTION_MOVE) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_MOVE; if (d->actions & WNCK_WINDOW_ACTION_MAXIMIZE) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_MAXIMIZE; if (d->actions & WNCK_WINDOW_ACTION_SHADE) *flags |= (MetaFrameFlags ) META_FRAME_ALLOWS_SHADE; if (d->active) *flags |= (MetaFrameFlags ) META_FRAME_HAS_FOCUS; if ((d->state & META_MAXIMIZED) == META_MAXIMIZED) *flags |= (MetaFrameFlags ) META_FRAME_MAXIMIZED; if (d->state & WNCK_WINDOW_STATE_STICKY) *flags |= (MetaFrameFlags ) META_FRAME_STUCK; if (d->state & WNCK_WINDOW_STATE_FULLSCREEN) *flags |= (MetaFrameFlags ) META_FRAME_FULLSCREEN; if (d->state & WNCK_WINDOW_STATE_SHADED) *flags |= (MetaFrameFlags ) META_FRAME_SHADED; if (d->state & WNCK_WINDOW_STATE_ABOVE) *flags |= (MetaFrameFlags ) META_FRAME_ABOVE; #ifdef HAVE_METACITY_3_14_0 meta_theme_get_frame_borders (theme, frame_type, d->frame->text_height, *flags, &borders); top_height = borders.visible.top; bottom_height = borders.visible.bottom; left_width = borders.visible.left; right_width = borders.visible.right; #else meta_theme_get_frame_borders (theme, frame_type, d->frame->text_height, *flags, &top_height, &bottom_height, &left_width, &right_width); #endif clip->x = d->context->left_space - left_width; clip->y = d->context->top_space - top_height; clip->width = d->border_layout.top.x2 - d->border_layout.top.x1; clip->width -= d->context->right_space + d->context->left_space; if (d->border_layout.rotation) clip->height = d->border_layout.left.x2 - d->border_layout.left.x1; else clip->height = d->border_layout.left.y2 - d->border_layout.left.y1; meta_theme_calc_geometry (theme, frame_type, d->frame->text_height, *flags, clip->width, clip->height, button_layout, fgeom); clip->width += left_width + right_width; clip->height += top_height + bottom_height; }
void meta_update_border_extents (decor_frame_t *frame) { MetaTheme *theme = meta_theme_get_current (); #ifdef HAVE_METACITY_3_14_0 MetaFrameBorders borders; #endif gwd_decor_frame_ref (frame); MetaFrameType frame_type = meta_frame_type_from_string (frame->type); gint top_height, bottom_height, left_width, right_width; if (!(frame_type < META_FRAME_TYPE_LAST)) frame_type = META_FRAME_TYPE_NORMAL; #ifdef HAVE_METACITY_3_14_0 meta_theme_get_frame_borders (theme, frame_type, frame->text_height, 0, &borders); top_height = borders.visible.top; bottom_height = borders.visible.bottom; left_width = borders.visible.left; right_width = borders.visible.right; #else meta_theme_get_frame_borders (theme, frame_type, frame->text_height, 0, &top_height, &bottom_height, &left_width, &right_width); #endif frame->win_extents.top = frame->win_extents.top; frame->win_extents.bottom = bottom_height; frame->win_extents.left = left_width; frame->win_extents.right = right_width; frame->titlebar_height = top_height - frame->win_extents.top; #ifdef HAVE_METACITY_3_14_0 meta_theme_get_frame_borders (theme, frame_type, frame->text_height, META_FRAME_MAXIMIZED, &borders); top_height = borders.visible.top; bottom_height = borders.visible.bottom; left_width = borders.visible.left; right_width = borders.visible.right; #else meta_theme_get_frame_borders (theme, frame_type, frame->text_height, META_FRAME_MAXIMIZED, &top_height, &bottom_height, &left_width, &right_width); #endif frame->max_win_extents.top = frame->win_extents.top; frame->max_win_extents.bottom = bottom_height; frame->max_win_extents.left = left_width; frame->max_win_extents.right = right_width; frame->max_titlebar_height = top_height - frame->max_win_extents.top; gwd_decor_frame_unref (frame); }