1
0
Fork 0
mutter-performance-source/src/theme.c

281 lines
7.8 KiB
C
Raw Normal View History

2001-05-31 16:18:40 +00:00
/* Metacity Default Theme Engine */
/*
* Copyright (C) 2001 Havoc Pennington
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include "theme.h"
2001-06-01 03:00:01 +00:00
#include "api.h"
2001-05-31 16:18:40 +00:00
typedef struct _DefaultFrameData DefaultFrameData;
2001-06-03 18:33:59 +00:00
typedef struct _DefaultScreenData DefaultScreenData;
2001-05-31 16:18:40 +00:00
struct _DefaultFrameData
{
PangoLayout *layout;
2001-06-03 18:33:59 +00:00
int title_height;
};
struct _DefaultScreenData
{
2001-06-01 03:00:01 +00:00
GC text_gc;
2001-06-02 04:14:18 +00:00
GC fg_gc;
2001-06-03 18:33:59 +00:00
GC light_gc;
GC dark_gc;
2001-05-31 16:18:40 +00:00
};
2001-06-03 18:33:59 +00:00
/* FIXME store this on the screen */
static DefaultScreenData *screen_data = NULL;
2001-05-31 16:18:40 +00:00
static gpointer
default_acquire_frame (MetaFrameInfo *info)
{
DefaultFrameData *d;
2001-06-01 03:00:01 +00:00
PangoFontDescription *desc;
XGCValues vals;
2001-06-03 18:33:59 +00:00
if (screen_data == NULL)
{
screen_data = g_new (DefaultScreenData, 1);
vals.foreground = meta_get_x_pixel (info->screen,
&info->colors->fg[META_STATE_NORMAL]);
/* FIXME memory-inefficient, could use the same one for all frames
* w/ the same root window
*/
screen_data->text_gc = XCreateGC (info->display,
RootWindowOfScreen (info->screen),
GCForeground,
&vals);
screen_data->fg_gc = XCreateGC (info->display,
RootWindowOfScreen (info->screen),
GCForeground,
&vals);
vals.foreground = meta_get_x_pixel (info->screen,
&info->colors->light[META_STATE_NORMAL]);
screen_data->light_gc = XCreateGC (info->display,
RootWindowOfScreen (info->screen),
GCForeground,
&vals);
vals.foreground = meta_get_x_pixel (info->screen,
&info->colors->dark[META_STATE_NORMAL]);
screen_data->dark_gc = XCreateGC (info->display,
RootWindowOfScreen (info->screen),
GCForeground,
&vals);
}
2001-06-01 03:00:01 +00:00
2001-05-31 16:18:40 +00:00
d = g_new (DefaultFrameData, 1);
2001-06-01 03:00:01 +00:00
desc = pango_font_description_from_string ("Sans 16");
d->layout = pango_layout_new (meta_get_pango_context (info->screen,
desc,
info->frame));
2001-06-03 18:33:59 +00:00
pango_font_description_free (desc);
2001-06-02 04:14:18 +00:00
d->title_height = 0;
2001-05-31 16:18:40 +00:00
return d;
}
2001-06-03 18:33:59 +00:00
static void
2001-05-31 16:18:40 +00:00
default_release_frame (MetaFrameInfo *info,
gpointer frame_data)
{
DefaultFrameData *d;
d = frame_data;
if (d->layout)
g_object_unref (G_OBJECT (d->layout));
2001-06-01 03:00:01 +00:00
2001-05-31 16:18:40 +00:00
g_free (d);
}
2001-06-01 03:00:01 +00:00
#define VERTICAL_TEXT_PAD 3
2001-06-02 04:14:18 +00:00
#define LEFT_WIDTH 15
#define RIGHT_WIDTH 15
#define BOTTOM_HEIGHT 20
2001-06-03 18:33:59 +00:00
#define SPACER_SPACING 3
static void
2001-05-31 16:18:40 +00:00
default_fill_frame_geometry (MetaFrameInfo *info,
2001-06-01 03:00:01 +00:00
MetaFrameGeometry *geom,
2001-05-31 16:18:40 +00:00
gpointer frame_data)
{
2001-06-01 03:00:01 +00:00
DefaultFrameData *d;
PangoRectangle rect;
d = frame_data;
if (info->title)
pango_layout_set_text (d->layout, info->title, -1);
else
pango_layout_set_text (d->layout, " ", -1);
2001-06-03 01:33:27 +00:00
2001-06-01 03:00:01 +00:00
pango_layout_get_pixel_extents (d->layout, NULL, &rect);
2001-05-31 16:18:40 +00:00
2001-06-02 04:14:18 +00:00
d->title_height = rect.height + VERTICAL_TEXT_PAD * 2;
geom->top_height = d->title_height;
2001-06-01 03:00:01 +00:00
geom->left_width = LEFT_WIDTH;
geom->right_width = RIGHT_WIDTH;
geom->bottom_height = BOTTOM_HEIGHT;
2001-06-03 18:33:59 +00:00
geom->background_pixel = meta_get_x_pixel (info->screen,
&info->colors->bg[META_STATE_NORMAL]);
}
static void
draw_vline (MetaFrameInfo *info,
Drawable drawable,
GC light_gc,
GC dark_gc,
int y1,
int y2,
int x)
{
int thickness_light;
int thickness_dark;
int i;
thickness_light = 1;
thickness_dark = 1;
2001-05-31 16:18:40 +00:00
2001-06-03 18:33:59 +00:00
for (i = 0; i < thickness_dark; i++)
{
XDrawLine (info->display, drawable, light_gc,
x + i, y2 - i - 1, x + i, y2);
XDrawLine (info->display, drawable, dark_gc,
x + i, y1, x + i, y2 - i - 1);
}
2001-06-01 03:00:01 +00:00
2001-06-03 18:33:59 +00:00
x += thickness_dark;
for (i = 0; i < thickness_light; i++)
{
XDrawLine (info->display, drawable, dark_gc,
x + i, y1, x + i, y1 + thickness_light - i);
XDrawLine (info->display, drawable, light_gc,
x + i, y1 + thickness_light - i, x + i, y2);
}
2001-05-31 16:18:40 +00:00
}
2001-06-03 18:33:59 +00:00
static void
2001-05-31 16:18:40 +00:00
default_expose_frame (MetaFrameInfo *info,
int x, int y,
int width, int height,
gpointer frame_data)
{
2001-06-01 03:00:01 +00:00
DefaultFrameData *d;
2001-06-02 04:14:18 +00:00
int close_size;
2001-06-03 18:33:59 +00:00
XGCValues vals;
2001-06-01 03:00:01 +00:00
d = frame_data;
pango_x_render_layout (info->display,
info->frame,
2001-06-03 18:33:59 +00:00
screen_data->text_gc,
2001-06-01 03:00:01 +00:00
d->layout,
LEFT_WIDTH,
VERTICAL_TEXT_PAD);
2001-06-02 04:14:18 +00:00
close_size = d->title_height;
2001-06-03 18:33:59 +00:00
vals.line_width = 2;
XChangeGC (info->display,
screen_data->fg_gc,
GCLineWidth,
&vals);
2001-06-02 04:14:18 +00:00
XDrawLine (info->display,
info->frame,
2001-06-03 18:33:59 +00:00
screen_data->fg_gc,
2001-06-02 04:14:18 +00:00
info->width - RIGHT_WIDTH - close_size,
VERTICAL_TEXT_PAD,
info->width - RIGHT_WIDTH,
d->title_height - VERTICAL_TEXT_PAD);
XDrawLine (info->display,
info->frame,
2001-06-03 18:33:59 +00:00
screen_data->fg_gc,
2001-06-02 04:14:18 +00:00
info->width - RIGHT_WIDTH,
VERTICAL_TEXT_PAD,
info->width - RIGHT_WIDTH - close_size,
d->title_height - VERTICAL_TEXT_PAD);
2001-06-03 18:33:59 +00:00
vals.line_width = 0;
XChangeGC (info->display,
screen_data->fg_gc,
GCLineWidth,
&vals);
draw_vline (info, info->frame,
screen_data->light_gc,
screen_data->dark_gc,
VERTICAL_TEXT_PAD,
d->title_height - VERTICAL_TEXT_PAD,
info->width - RIGHT_WIDTH - close_size - SPACER_SPACING);
2001-05-31 16:18:40 +00:00
}
2001-06-02 04:14:18 +00:00
#define RESIZE_EXTENDS 10
2001-06-03 18:33:59 +00:00
static MetaFrameControl
2001-05-31 16:18:40 +00:00
default_get_control (MetaFrameInfo *info,
int x, int y,
gpointer frame_data)
{
2001-06-02 04:14:18 +00:00
DefaultFrameData *d;
int close_size;
d = frame_data;
2001-05-31 16:18:40 +00:00
2001-06-02 04:14:18 +00:00
close_size = d->title_height;
if (y < d->title_height &&
x > info->width - RIGHT_WIDTH - close_size)
return META_FRAME_CONTROL_DELETE;
if (y < d->title_height)
return META_FRAME_CONTROL_TITLE;
if (y > (info->height - BOTTOM_HEIGHT - RESIZE_EXTENDS) &&
x > (info->width - RIGHT_WIDTH - RESIZE_EXTENDS))
return META_FRAME_CONTROL_RESIZE_SE;
2001-06-01 03:00:01 +00:00
return META_FRAME_CONTROL_NONE;
2001-05-31 16:18:40 +00:00
}
2001-06-03 18:33:59 +00:00
/* FIXME add this to engine vtable */
static void
default_release_screen (Screen *screen)
{
if (screen_data)
{
XFreeGC (DisplayOfScreen (screen), screen_data->text_gc);
XFreeGC (DisplayOfScreen (screen), screen_data->fg_gc);
}
}
2001-05-31 16:18:40 +00:00
MetaThemeEngine meta_default_engine = {
NULL,
default_acquire_frame,
default_release_frame,
default_fill_frame_geometry,
default_expose_frame,
default_get_control
};