summaryrefslogtreecommitdiff
path: root/gtk/window-decorator/cairo.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/window-decorator/cairo.c')
-rw-r--r--gtk/window-decorator/cairo.c163
1 files changed, 101 insertions, 62 deletions
diff --git a/gtk/window-decorator/cairo.c b/gtk/window-decorator/cairo.c
index a9b8f42..c600cf1 100644
--- a/gtk/window-decorator/cairo.c
+++ b/gtk/window-decorator/cairo.c
@@ -1,3 +1,28 @@
+/*
+ * Copyright © 2006 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Reveman <davidr@novell.com>
+ *
+ * 2D Mode: Copyright © 2010 Sam Spilsbury <smspillaz@gmail.com>
+ * Frames Management: Copright © 2011 Canonical Ltd.
+ * Authored By: Sam Spilsbury <sam.spilsbury@canonical.com>
+ */
+
#include "gtk-window-decorator.h"
void
@@ -280,7 +305,8 @@ draw_window_decoration (decor_t *d)
if (!d->pixmap)
return;
- style = gtk_widget_get_style (style_window_rgba);
+
+ style = gtk_widget_get_style (d->frame->style_window_rgba);
if (d->state & (WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY |
WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY))
@@ -310,12 +336,12 @@ draw_window_decoration (decor_t *d)
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- top = _win_extents.top + titlebar_height;
+ top = d->frame->win_extents.top + d->frame->titlebar_height;
- x1 = d->context->left_space - _win_extents.left;
- y1 = d->context->top_space - _win_extents.top - titlebar_height;
- x2 = d->width - d->context->right_space + _win_extents.right;
- y2 = d->height - d->context->bottom_space + _win_extents.bottom;
+ x1 = d->context->left_space - d->frame->win_extents.left;
+ y1 = d->context->top_space - d->frame->win_extents.top - d->frame->titlebar_height;
+ x2 = d->width - d->context->right_space + d->frame->win_extents.right;
+ y2 = d->height - d->context->bottom_space + d->frame->win_extents.bottom;
h = d->height - d->context->top_space - d->context->bottom_space;
@@ -328,31 +354,31 @@ draw_window_decoration (decor_t *d)
{
decor_color_t *title_color = _title_color;
- alpha = decoration_alpha + 0.3;
+ alpha = settings->decoration_alpha + 0.3;
fill_rounded_rectangle (cr,
x1 + 0.5,
y1 + 0.5,
- _win_extents.left - 0.5,
+ d->frame->win_extents.left - 0.5,
top - 0.5,
5.0, CORNER_TOPLEFT & corners,
&title_color[0], 1.0, &title_color[1], alpha,
SHADE_TOP | SHADE_LEFT);
fill_rounded_rectangle (cr,
- x1 + _win_extents.left,
+ x1 + d->frame->win_extents.left,
y1 + 0.5,
- x2 - x1 - _win_extents.left -
- _win_extents.right,
+ x2 - x1 - d->frame->win_extents.left -
+ d->frame->win_extents.right,
top - 0.5,
5.0, 0,
&title_color[0], 1.0, &title_color[1], alpha,
SHADE_TOP);
fill_rounded_rectangle (cr,
- x2 - _win_extents.right,
+ x2 - d->frame->win_extents.right,
y1 + 0.5,
- _win_extents.right - 0.5,
+ d->frame->win_extents.right - 0.5,
top - 0.5,
5.0, CORNER_TOPRIGHT & corners,
&title_color[0], 1.0, &title_color[1], alpha,
@@ -360,31 +386,31 @@ draw_window_decoration (decor_t *d)
}
else
{
- alpha = decoration_alpha;
+ alpha = settings->decoration_alpha;
fill_rounded_rectangle (cr,
x1 + 0.5,
y1 + 0.5,
- _win_extents.left - 0.5,
+ d->frame->win_extents.left - 0.5,
top - 0.5,
5.0, CORNER_TOPLEFT & corners,
&color, 1.0, &color, alpha,
SHADE_TOP | SHADE_LEFT);
fill_rounded_rectangle (cr,
- x1 + _win_extents.left,
+ x1 + d->frame->win_extents.left,
y1 + 0.5,
- x2 - x1 - _win_extents.left -
- _win_extents.right,
+ x2 - x1 - d->frame->win_extents.left -
+ d->frame->win_extents.right,
top - 0.5,
5.0, 0,
&color, 1.0, &color, alpha,
SHADE_TOP);
fill_rounded_rectangle (cr,
- x2 - _win_extents.right,
+ x2 - d->frame->win_extents.right,
y1 + 0.5,
- _win_extents.right - 0.5,
+ d->frame->win_extents.right - 0.5,
top - 0.5,
5.0, CORNER_TOPRIGHT & corners,
&color, 1.0, &color, alpha,
@@ -394,16 +420,16 @@ draw_window_decoration (decor_t *d)
fill_rounded_rectangle (cr,
x1 + 0.5,
y1 + top,
- _win_extents.left - 0.5,
+ d->frame->win_extents.left - 0.5,
h,
5.0, 0,
&color, 1.0, &color, alpha,
SHADE_LEFT);
fill_rounded_rectangle (cr,
- x2 - _win_extents.right,
+ x2 - d->frame->win_extents.right,
y1 + top,
- _win_extents.right - 0.5,
+ d->frame->win_extents.right - 0.5,
h,
5.0, 0,
&color, 1.0, &color, alpha,
@@ -412,28 +438,28 @@ draw_window_decoration (decor_t *d)
fill_rounded_rectangle (cr,
x1 + 0.5,
- y2 - _win_extents.bottom,
- _win_extents.left - 0.5,
- _win_extents.bottom - 0.5,
+ y2 - d->frame->win_extents.bottom,
+ d->frame->win_extents.left - 0.5,
+ d->frame->win_extents.bottom - 0.5,
5.0, CORNER_BOTTOMLEFT & corners,
&color, 1.0, &color, alpha,
SHADE_BOTTOM | SHADE_LEFT);
fill_rounded_rectangle (cr,
- x1 + _win_extents.left,
- y2 - _win_extents.bottom,
- x2 - x1 - _win_extents.left -
- _win_extents.right,
- _win_extents.bottom - 0.5,
+ x1 + d->frame->win_extents.left,
+ y2 - d->frame->win_extents.bottom,
+ x2 - x1 - d->frame->win_extents.left -
+ d->frame->win_extents.right,
+ d->frame->win_extents.bottom - 0.5,
5.0, 0,
&color, 1.0, &color, alpha,
SHADE_BOTTOM);
fill_rounded_rectangle (cr,
- x2 - _win_extents.right,
- y2 - _win_extents.bottom,
- _win_extents.right - 0.5,
- _win_extents.bottom - 0.5,
+ x2 - d->frame->win_extents.right,
+ y2 - d->frame->win_extents.bottom,
+ d->frame->win_extents.right - 0.5,
+ d->frame->win_extents.bottom - 0.5,
5.0, CORNER_BOTTOMRIGHT & corners,
&color, 1.0, &color, alpha,
SHADE_BOTTOM | SHADE_RIGHT);
@@ -520,7 +546,7 @@ draw_window_decoration (decor_t *d)
if (d->actions & WNCK_WINDOW_ACTION_CLOSE)
{
button_state_offsets (button_x,
- y1 - 3.0 + titlebar_height / 2,
+ y1 - 3.0 + d->frame->titlebar_height / 2,
d->button_states[BUTTON_CLOSE], &x, &y);
button_x -= 17;
@@ -547,7 +573,7 @@ draw_window_decoration (decor_t *d)
if (d->actions & WNCK_WINDOW_ACTION_MAXIMIZE)
{
button_state_offsets (button_x,
- y1 - 3.0 + titlebar_height / 2,
+ y1 - 3.0 + d->frame->titlebar_height / 2,
d->button_states[BUTTON_MAX], &x, &y);
button_x -= 17;
@@ -592,7 +618,7 @@ draw_window_decoration (decor_t *d)
if (d->actions & WNCK_WINDOW_ACTION_MINIMIZE)
{
button_state_offsets (button_x,
- y1 - 3.0 + titlebar_height / 2,
+ y1 - 3.0 + d->frame->titlebar_height / 2,
d->button_states[BUTTON_MIN], &x, &y);
button_x -= 17;
@@ -627,7 +653,7 @@ draw_window_decoration (decor_t *d)
{
cairo_move_to (cr,
d->context->left_space + 21.0,
- y1 + 2.0 + (titlebar_height - text_height) / 2.0);
+ y1 + 2.0 + (d->frame->titlebar_height - d->frame->text_height) / 2.0);
gdk_cairo_set_source_color_alpha (cr,
&style->fg[GTK_STATE_NORMAL],
@@ -647,7 +673,7 @@ draw_window_decoration (decor_t *d)
cairo_move_to (cr,
d->context->left_space + 21.0,
- y1 + 2.0 + (titlebar_height - text_height) / 2.0);
+ y1 + 2.0 + (d->frame->titlebar_height - d->frame->text_height) / 2.0);
pango_cairo_show_layout (cr, d->layout);
}
@@ -655,7 +681,7 @@ draw_window_decoration (decor_t *d)
if (d->icon)
{
cairo_translate (cr, d->context->left_space + 1,
- y1 - 5.0 + titlebar_height / 2);
+ y1 - 5.0 + d->frame->titlebar_height / 2);
cairo_set_source (cr, d->icon);
cairo_rectangle (cr, 0.0, 0.0, 16.0, 16.0);
cairo_clip (cr);
@@ -740,7 +766,7 @@ calc_decoration_size (decor_t *d,
if (w < top_width)
top_width = MAX (ICON_SPACE + d->button_width, w);
- decor_get_default_layout (&window_context, top_width, 1, &layout);
+ decor_get_default_layout (&d->frame->window_context, top_width, 1, &layout);
if (!d->context || memcmp (&layout, &d->border_layout, sizeof (layout)))
{
@@ -748,8 +774,8 @@ calc_decoration_size (decor_t *d,
*height = layout.height;
d->border_layout = layout;
- d->context = &window_context;
- d->shadow = border_shadow;
+ d->context = &d->frame->window_context;
+ d->shadow = d->frame->border_shadow;
return TRUE;
}
@@ -764,15 +790,15 @@ calc_decoration_size (decor_t *d,
if (w < top_width)
top_width = MAX (ICON_SPACE + d->button_width, w);
- decor_get_default_layout (&window_context_no_shadow,
+ decor_get_default_layout (&d->frame->window_context_no_shadow,
d->client_width, d->client_height, &layout);
*width = layout.width;
*height = layout.height;
d->border_layout = layout;
- d->context = &window_context_no_shadow;
- d->shadow = border_no_shadow;
+ d->context = &d->frame->window_context_no_shadow;
+ d->shadow = d->frame->border_no_shadow;
return TRUE;
}
@@ -795,20 +821,20 @@ get_button_position (decor_t *d,
if (d->frame_window)
{
- *x = bpos[i].x + bpos[i].xw * width + _win_extents.left + 4;
+ *x = bpos[i].x + bpos[i].xw * width + d->frame->win_extents.left + 4;
*y = bpos[i].y + bpos[i].yh * height + bpos[i].yth *
- (titlebar_height - 17) + _win_extents.top + 2;
+ (d->frame->titlebar_height - 17) + d->frame->win_extents.top + 2;
}
else
{
*x = bpos[i].x + bpos[i].xw * width;
*y = bpos[i].y + bpos[i].yh * height + bpos[i].yth *
- (titlebar_height - 17);
+ (d->frame->titlebar_height - 17);
}
*w = bpos[i].w + bpos[i].ww * width;
*h = bpos[i].h + bpos[i].hh * height + bpos[i].hth +
- (titlebar_height - 17);
+ (d->frame->titlebar_height - 17);
/* hack to position multiple buttons on the right */
if (i != BUTTON_MENU)
@@ -830,18 +856,18 @@ get_event_window_position (decor_t *d,
{
if (d->frame_window)
{
- *x = pos[i][j].x + pos[i][j].xw * width + _win_extents.left;
- *y = pos[i][j].y + _win_extents.top +
- pos[i][j].yh * height + pos[i][j].yth * (titlebar_height - 17);
+ *x = pos[i][j].x + pos[i][j].xw * width + d->frame->win_extents.left;
+ *y = pos[i][j].y + d->frame->win_extents.top +
+ pos[i][j].yh * height + pos[i][j].yth * (d->frame->titlebar_height - 17);
if (i == 0 && (j == 0 || j == 2))
- *y -= titlebar_height;
+ *y -= d->frame->titlebar_height;
}
else
{
*x = pos[i][j].x + pos[i][j].xw * width;
*y = pos[i][j].y +
- pos[i][j].yh * height + pos[i][j].yth * (titlebar_height - 17);
+ pos[i][j].yh * height + pos[i][j].yth * (d->frame->titlebar_height - 17);
}
if ((d->state & WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY) &&
@@ -862,15 +888,28 @@ get_event_window_position (decor_t *d,
else
{
*h = pos[i][j].h +
- pos[i][j].hh * height + pos[i][j].hth * (titlebar_height - 17);
+ pos[i][j].hh * height + pos[i][j].hth * (d->frame->titlebar_height - 17);
}
}
+gfloat
+get_title_scale (decor_frame_t *frame)
+{
+ return 1.0f;
+}
+
void
-update_border_extents (gint text_height)
+update_border_extents (decor_frame_t *frame)
{
- _win_extents = _default_win_extents;
- _max_win_extents = _default_win_extents;
- max_titlebar_height = titlebar_height =
- (text_height < 17) ? 17 : text_height;
+ decor_frame_t *default_frame = gwd_get_decor_frame ("default");
+
+ frame = gwd_decor_frame_ref (frame);
+
+ frame->win_extents = default_frame->win_extents;
+ frame->max_win_extents = default_frame->win_extents;
+ frame->titlebar_height = frame->max_titlebar_height =
+ (frame->text_height < 17) ? 17 : frame->text_height;
+
+ gwd_decor_frame_unref (frame);
+ gwd_decor_frame_unref (default_frame);
}