summaryrefslogtreecommitdiff
path: root/libmetacity/meta-theme.h
blob: 110dd9e05a55711e7d576ff9c190206e9be7219b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * 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_THEME_H
#define META_THEME_H

#include <gtk/gtk.h>
#include <libmetacity/meta-button-enums.h>
#include <libmetacity/meta-button-layout.h>
#include <libmetacity/meta-frame-borders.h>
#include <libmetacity/meta-frame-enums.h>
#include <libmetacity/meta-frame-style.h>

G_BEGIN_DECLS

typedef struct _MetaButtonSpace MetaButtonSpace;
typedef struct _MetaFrameGeometry MetaFrameGeometry;

#define META_TYPE_THEME meta_theme_get_type ()
G_DECLARE_FINAL_TYPE (MetaTheme, meta_theme, META, THEME, GObject)

/**
 * META_THEME_ERROR:
 *
 * Domain for #MetaThemeError errors.
 */
#define META_THEME_ERROR (meta_theme_error_quark ())

/**
 * MetaThemeError:
 * @META_THEME_ERROR_TOO_OLD:
 * @META_THEME_ERROR_FRAME_GEOMETRY:
 * @META_THEME_ERROR_BAD_CHARACTER:
 * @META_THEME_ERROR_BAD_PARENS:
 * @META_THEME_ERROR_UNKNOWN_VARIABLE:
 * @META_THEME_ERROR_DIVIDE_BY_ZERO:
 * @META_THEME_ERROR_MOD_ON_FLOAT:
 * @META_THEME_ERROR_FAILED:
 *
 * Error codes for %META_THEME_ERROR.
 */
typedef enum
{
  META_THEME_ERROR_TOO_OLD,
  META_THEME_ERROR_FRAME_GEOMETRY,
  META_THEME_ERROR_BAD_CHARACTER,
  META_THEME_ERROR_BAD_PARENS,
  META_THEME_ERROR_UNKNOWN_VARIABLE,
  META_THEME_ERROR_DIVIDE_BY_ZERO,
  META_THEME_ERROR_MOD_ON_FLOAT,
  META_THEME_ERROR_FAILED
} MetaThemeError;

/**
 * MetaThemeType:
 * @META_THEME_TYPE_GTK:
 * @META_THEME_TYPE_METACITY:
 *
 * Theme types.
 */
typedef enum
{
  META_THEME_TYPE_GTK,
  META_THEME_TYPE_METACITY,
} MetaThemeType;

/**
 * The computed size of a button (really just a way of tying its
 * visible and clickable areas together).
 * The reason for two different rectangles here is Fitts' law & maximized
 * windows; see bug #97703 for more details.
 */
struct _MetaButtonSpace
{
  /** The screen area where the button's image is drawn */
  GdkRectangle visible;
  /** The screen area where the button can be activated by clicking */
  GdkRectangle clickable;
};

/**
 * Calculated actual geometry of the frame
 */
struct _MetaFrameGeometry
{
  MetaFrameBorders borders;

  int width;
  int height;

  GdkRectangle title_rect;

  /* used for a memset hack */
#define ADDRESS_OF_BUTTON_RECTS(fgeom) (((char*)(fgeom)) + G_STRUCT_OFFSET (MetaFrameGeometry, close_rect))
#define LENGTH_OF_BUTTON_RECTS (G_STRUCT_OFFSET (MetaFrameGeometry, right_single_background) + sizeof (GdkRectangle) - G_STRUCT_OFFSET (MetaFrameGeometry, close_rect))

  /* The button rects (if changed adjust memset hack) */
  MetaButtonSpace close_rect;
  MetaButtonSpace max_rect;
  MetaButtonSpace min_rect;
  MetaButtonSpace menu_rect;
  MetaButtonSpace appmenu_rect;
  MetaButtonSpace shade_rect;
  MetaButtonSpace above_rect;
  MetaButtonSpace stick_rect;
  MetaButtonSpace unshade_rect;
  MetaButtonSpace unabove_rect;
  MetaButtonSpace unstick_rect;

#define MAX_MIDDLE_BACKGROUNDS (META_BUTTON_FUNCTION_LAST - 2)
  GdkRectangle left_left_background;
  GdkRectangle left_middle_backgrounds[MAX_MIDDLE_BACKGROUNDS];
  GdkRectangle left_right_background;
  GdkRectangle left_single_background;
  GdkRectangle right_left_background;
  GdkRectangle right_middle_backgrounds[MAX_MIDDLE_BACKGROUNDS];
  GdkRectangle right_right_background;
  GdkRectangle right_single_background;
  /* End of button rects (if changed adjust memset hack) */

  /* Saved button layout */
  MetaButtonLayout button_layout;
  int n_left_buttons;
  int n_right_buttons;

  /* Round corners */
  guint top_left_corner_rounded_radius;
  guint top_right_corner_rounded_radius;
  guint bottom_left_corner_rounded_radius;
  guint bottom_right_corner_rounded_radius;
};

GQuark                meta_theme_error_quark               (void);

MetaTheme            *meta_theme_new                       (MetaThemeType                type);

gboolean              meta_theme_load                      (MetaTheme                   *theme,
                                                            const gchar                 *theme_name,
                                                            GError                     **error);

void                  meta_theme_invalidate                (MetaTheme                   *theme);

void                  meta_theme_set_composited            (MetaTheme                   *theme,
                                                            gboolean                     composited);

void                  meta_theme_set_titlebar_font         (MetaTheme                   *theme,
                                                            const PangoFontDescription  *titlebar_font);

gchar                *meta_theme_get_name                  (MetaTheme                   *theme);

MetaFrameStyle       *meta_theme_get_frame_style           (MetaTheme                   *theme,
                                                            MetaFrameType                type,
                                                            MetaFrameFlags               flags);

PangoFontDescription *meta_theme_create_font_desc          (MetaTheme                   *theme,
                                                            const gchar                 *variant);

gint                  meta_pango_font_desc_get_text_height (const PangoFontDescription  *font_desc,
                                                            PangoContext                *context);

MetaFrameType         meta_frame_type_from_string          (const gchar                 *str);

gdouble               meta_theme_get_title_scale           (MetaTheme                   *theme,
                                                            MetaFrameType                type,
                                                            MetaFrameFlags               flags);

void                  meta_theme_get_frame_borders         (MetaTheme                   *theme,
                                                            const gchar                 *variant,
                                                            MetaFrameType                type,
                                                            gint                         text_height,
                                                            MetaFrameFlags               flags,
                                                            MetaFrameBorders            *borders);

void                  meta_theme_calc_geometry             (MetaTheme                   *theme,
                                                            const gchar                 *variant,
                                                            MetaFrameType                type,
                                                            gint                         text_height,
                                                            MetaFrameFlags               flags,
                                                            gint                         client_width,
                                                            gint                         client_height,
                                                            const MetaButtonLayout      *button_layout,
                                                            MetaFrameGeometry           *fgeom);

void                  meta_theme_draw_frame                (MetaTheme                   *theme,
                                                            const gchar                 *variant,
                                                            cairo_t                     *cr,
                                                            MetaFrameType                type,
                                                            MetaFrameFlags               flags,
                                                            gint                         client_width,
                                                            gint                         client_height,
                                                            PangoLayout                 *title_layout,
                                                            int                          text_height,
                                                            const MetaButtonLayout      *button_layout,
                                                            MetaButtonState              button_states[META_BUTTON_TYPE_LAST],
                                                            GdkPixbuf                   *mini_icon,
                                                            GdkPixbuf                   *icon);

G_END_DECLS

#endif