Merge branch 'style' into 'master'
Style: Change classes to paths See merge request Librem5/squeekboard!178
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
.keyboard {
|
layout {
|
||||||
background-color: rgba(0, 0, 0, 255);
|
background-color: rgba(0, 0, 0, 255);
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-family: cantarell, sans-serif;
|
font-family: cantarell, sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
.key {
|
button {
|
||||||
color: #deddda;
|
color: #deddda;
|
||||||
background: #464448;
|
background: #464448;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
@ -13,7 +13,7 @@
|
|||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.key:active {
|
button:active {
|
||||||
background: #545256;
|
background: #545256;
|
||||||
border-color: #716e78;
|
border-color: #716e78;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,8 +52,6 @@ typedef struct _EekGtkKeyboardPrivate
|
|||||||
{
|
{
|
||||||
EekRenderer *renderer;
|
EekRenderer *renderer;
|
||||||
LevelKeyboard *keyboard;
|
LevelKeyboard *keyboard;
|
||||||
GtkCssProvider *css_provider;
|
|
||||||
GtkStyleContext *scontext;
|
|
||||||
|
|
||||||
GdkEventSequence *sequence; // unowned reference
|
GdkEventSequence *sequence; // unowned reference
|
||||||
} EekGtkKeyboardPrivate;
|
} EekGtkKeyboardPrivate;
|
||||||
@ -98,7 +96,7 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
|
|||||||
if (!priv->renderer) {
|
if (!priv->renderer) {
|
||||||
PangoContext *pcontext = gtk_widget_get_pango_context (self);
|
PangoContext *pcontext = gtk_widget_get_pango_context (self);
|
||||||
|
|
||||||
priv->renderer = eek_renderer_new (priv->keyboard, pcontext, priv->scontext);
|
priv->renderer = eek_renderer_new (priv->keyboard, pcontext);
|
||||||
|
|
||||||
eek_renderer_set_allocation_size (priv->renderer,
|
eek_renderer_set_allocation_size (priv->renderer,
|
||||||
allocation.width,
|
allocation.width,
|
||||||
@ -383,22 +381,7 @@ eek_gtk_keyboard_class_init (EekGtkKeyboardClass *klass)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
eek_gtk_keyboard_init (EekGtkKeyboard *self)
|
eek_gtk_keyboard_init (EekGtkKeyboard *self)
|
||||||
{
|
{}
|
||||||
EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (self);
|
|
||||||
|
|
||||||
/* Create a default CSS provider and load a style sheet */
|
|
||||||
priv->css_provider = gtk_css_provider_new ();
|
|
||||||
gtk_css_provider_load_from_resource (priv->css_provider,
|
|
||||||
"/sm/puri/squeekboard/style.css");
|
|
||||||
|
|
||||||
/* Apply the style to the widget */
|
|
||||||
priv->scontext = gtk_widget_get_style_context (GTK_WIDGET(self));
|
|
||||||
gtk_style_context_add_class (priv->scontext, "keyboard");
|
|
||||||
gtk_style_context_add_provider (priv->scontext,
|
|
||||||
GTK_STYLE_PROVIDER(priv->css_provider),
|
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
|
||||||
gtk_style_context_set_state (priv->scontext, GTK_STATE_FLAG_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eek_gtk_keyboard_new:
|
* eek_gtk_keyboard_new:
|
||||||
|
|||||||
@ -29,7 +29,6 @@
|
|||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_PCONTEXT,
|
PROP_PCONTEXT,
|
||||||
PROP_STYLE_CONTEXT,
|
|
||||||
PROP_LAST
|
PROP_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -38,8 +37,8 @@ typedef struct _EekRendererPrivate
|
|||||||
LevelKeyboard *keyboard;
|
LevelKeyboard *keyboard;
|
||||||
PangoContext *pcontext;
|
PangoContext *pcontext;
|
||||||
GtkCssProvider *css_provider;
|
GtkCssProvider *css_provider;
|
||||||
GtkStyleContext *scontext;
|
GtkStyleContext *layout_context;
|
||||||
GtkStyleContext *key_context;
|
GtkStyleContext *button_context;
|
||||||
|
|
||||||
EekColor default_foreground_color;
|
EekColor default_foreground_color;
|
||||||
EekColor default_background_color;
|
EekColor default_background_color;
|
||||||
@ -135,7 +134,7 @@ render_keyboard_surface (EekRenderer *renderer, struct squeek_view *view)
|
|||||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
|
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
|
||||||
EekColor foreground;
|
EekColor foreground;
|
||||||
|
|
||||||
eek_renderer_get_foreground_color (renderer, priv->scontext, &foreground);
|
eek_renderer_get_foreground_color (renderer, priv->layout_context, &foreground);
|
||||||
|
|
||||||
EekBounds bounds = squeek_view_get_bounds (level_keyboard_current(priv->keyboard));
|
EekBounds bounds = squeek_view_get_bounds (level_keyboard_current(priv->keyboard));
|
||||||
|
|
||||||
@ -146,11 +145,11 @@ render_keyboard_surface (EekRenderer *renderer, struct squeek_view *view)
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Paint the background covering the entire widget area */
|
/* Paint the background covering the entire widget area */
|
||||||
gtk_render_background (priv->scontext,
|
gtk_render_background (priv->layout_context,
|
||||||
data.cr,
|
data.cr,
|
||||||
0, 0,
|
0, 0,
|
||||||
priv->allocation_width, priv->allocation_height);
|
priv->allocation_width, priv->allocation_height);
|
||||||
gtk_render_frame (priv->scontext,
|
gtk_render_frame (priv->layout_context,
|
||||||
data.cr,
|
data.cr,
|
||||||
0, 0,
|
0, 0,
|
||||||
priv->allocation_width, priv->allocation_height);
|
priv->allocation_width, priv->allocation_height);
|
||||||
@ -186,24 +185,24 @@ render_button_outline (EekRenderer *renderer,
|
|||||||
/* Set the name of the button on the widget path, using the name obtained
|
/* Set the name of the button on the widget path, using the name obtained
|
||||||
from the button's symbol. */
|
from the button's symbol. */
|
||||||
g_autoptr (GtkWidgetPath) path = NULL;
|
g_autoptr (GtkWidgetPath) path = NULL;
|
||||||
path = gtk_widget_path_copy (gtk_style_context_get_path (priv->key_context));
|
path = gtk_widget_path_copy (gtk_style_context_get_path (priv->button_context));
|
||||||
const char *name = squeek_button_get_name(button);
|
const char *name = squeek_button_get_name(button);
|
||||||
gtk_widget_path_iter_set_name (path, -1, name);
|
gtk_widget_path_iter_set_name (path, -1, name);
|
||||||
|
|
||||||
/* Update the style context with the updated widget path. */
|
/* Update the style context with the updated widget path. */
|
||||||
gtk_style_context_set_path (priv->key_context, path);
|
gtk_style_context_set_path (priv->button_context, path);
|
||||||
|
|
||||||
/* Set the state to take into account whether the button is active
|
/* Set the state to take into account whether the button is active
|
||||||
(pressed) or normal. */
|
(pressed) or normal. */
|
||||||
gtk_style_context_set_state(priv->key_context,
|
gtk_style_context_set_state(priv->button_context,
|
||||||
active ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL);
|
active ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL);
|
||||||
|
|
||||||
gtk_render_background (priv->key_context,
|
gtk_render_background (priv->button_context,
|
||||||
cr, 0, 0, bounds.width, bounds.height);
|
cr, 0, 0, bounds.width, bounds.height);
|
||||||
gtk_render_frame (priv->key_context,
|
gtk_render_frame (priv->button_context,
|
||||||
cr, 0, 0, bounds.width, bounds.height);
|
cr, 0, 0, bounds.width, bounds.height);
|
||||||
|
|
||||||
gtk_style_context_set_state(priv->key_context, GTK_STATE_FLAG_NORMAL);
|
gtk_style_context_set_state(priv->button_context, GTK_STATE_FLAG_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -258,7 +257,7 @@ render_button (EekRenderer *self,
|
|||||||
cairo_set_source_surface (cr, outline_surface, 0.0, 0.0);
|
cairo_set_source_surface (cr, outline_surface, 0.0, 0.0);
|
||||||
cairo_paint (cr);
|
cairo_paint (cr);
|
||||||
|
|
||||||
eek_renderer_get_foreground_color (self, priv->key_context, &foreground);
|
eek_renderer_get_foreground_color (self, priv->button_context, &foreground);
|
||||||
/* render icon (if any) */
|
/* render icon (if any) */
|
||||||
const char *icon_name = squeek_button_get_icon_name(place->button);
|
const char *icon_name = squeek_button_get_icon_name(place->button);
|
||||||
|
|
||||||
@ -491,10 +490,6 @@ eek_renderer_set_property (GObject *object,
|
|||||||
priv->pcontext = g_value_get_object (value);
|
priv->pcontext = g_value_get_object (value);
|
||||||
g_object_ref (priv->pcontext);
|
g_object_ref (priv->pcontext);
|
||||||
break;
|
break;
|
||||||
case PROP_STYLE_CONTEXT:
|
|
||||||
priv->scontext = g_value_get_object (value);
|
|
||||||
g_object_ref (priv->scontext);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -571,15 +566,33 @@ eek_renderer_class_init (EekRendererClass *klass)
|
|||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_PCONTEXT,
|
PROP_PCONTEXT,
|
||||||
pspec);
|
pspec);
|
||||||
|
}
|
||||||
|
|
||||||
pspec = g_param_spec_object ("style-context",
|
|
||||||
"GTK Style Context",
|
static GType new_type(char *name) {
|
||||||
"GTK Style Context",
|
GTypeInfo info = {0};
|
||||||
GTK_TYPE_STYLE_CONTEXT,
|
info.class_size = sizeof(GtkWidgetClass);
|
||||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
info.instance_size = sizeof(GtkWidget);
|
||||||
g_object_class_install_property (gobject_class,
|
|
||||||
PROP_STYLE_CONTEXT,
|
return g_type_register_static(GTK_TYPE_WIDGET, name, &info,
|
||||||
pspec);
|
G_TYPE_FLAG_ABSTRACT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GType layout_type() {
|
||||||
|
static GType type = 0;
|
||||||
|
if (!type) {
|
||||||
|
type = new_type("layout");
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GType button_type() {
|
||||||
|
static GType type = 0;
|
||||||
|
if (!type) {
|
||||||
|
type = new_type("button");
|
||||||
|
}
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -623,17 +636,23 @@ eek_renderer_init (EekRenderer *self)
|
|||||||
"/sm/puri/squeekboard/style.css");
|
"/sm/puri/squeekboard/style.css");
|
||||||
|
|
||||||
/* Create a style context for keys */
|
/* Create a style context for keys */
|
||||||
priv->key_context = gtk_style_context_new ();
|
GtkWidgetPath *path = gtk_widget_path_new();
|
||||||
gtk_style_context_add_class (priv->key_context, "key");
|
gtk_widget_path_append_type(path, layout_type());
|
||||||
gtk_style_context_add_provider (priv->key_context,
|
|
||||||
|
priv->layout_context = gtk_style_context_new();
|
||||||
|
gtk_style_context_set_path(priv->layout_context, path);
|
||||||
|
gtk_style_context_add_provider (priv->layout_context,
|
||||||
GTK_STYLE_PROVIDER(priv->css_provider),
|
GTK_STYLE_PROVIDER(priv->css_provider),
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||||
|
|
||||||
g_autoptr (GtkWidgetPath) path = NULL;
|
gtk_widget_path_append_type(path, button_type());
|
||||||
path = gtk_widget_path_new ();
|
priv->button_context = gtk_style_context_new ();
|
||||||
gtk_widget_path_append_type (path, GTK_TYPE_BUTTON);
|
gtk_style_context_set_path(priv->button_context, path);
|
||||||
gtk_style_context_set_path (priv->key_context, path);
|
gtk_style_context_set_state (priv->button_context, GTK_STATE_FLAG_NORMAL);
|
||||||
gtk_style_context_set_state (priv->key_context, GTK_STATE_FLAG_NORMAL);
|
gtk_style_context_add_provider (priv->button_context,
|
||||||
|
GTK_STYLE_PROVIDER(priv->css_provider),
|
||||||
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||||
|
gtk_widget_path_unref(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -655,12 +674,10 @@ invalidate (EekRenderer *renderer)
|
|||||||
|
|
||||||
EekRenderer *
|
EekRenderer *
|
||||||
eek_renderer_new (LevelKeyboard *keyboard,
|
eek_renderer_new (LevelKeyboard *keyboard,
|
||||||
PangoContext *pcontext,
|
PangoContext *pcontext)
|
||||||
GtkStyleContext *scontext)
|
|
||||||
{
|
{
|
||||||
EekRenderer *renderer = g_object_new (EEK_TYPE_RENDERER,
|
EekRenderer *renderer = g_object_new (EEK_TYPE_RENDERER,
|
||||||
"pango-context", pcontext,
|
"pango-context", pcontext,
|
||||||
"style-context", scontext,
|
|
||||||
NULL);
|
NULL);
|
||||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
|
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
|
||||||
priv->keyboard = keyboard;
|
priv->keyboard = keyboard;
|
||||||
@ -754,7 +771,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer,
|
|||||||
|
|
||||||
min = points[2];
|
min = points[2];
|
||||||
max = points[0];
|
max = points[0];
|
||||||
for (uint i = 0; i < G_N_ELEMENTS(points); i++) {
|
for (unsigned i = 0; i < G_N_ELEMENTS(points); i++) {
|
||||||
eek_point_rotate (&points[i], angle);
|
eek_point_rotate (&points[i], angle);
|
||||||
if (points[i].x < min.x)
|
if (points[i].x < min.x)
|
||||||
min.x = points[i].x;
|
min.x = points[i].x;
|
||||||
@ -922,7 +939,7 @@ eek_are_bounds_inside (EekBounds bounds, EekPoint point, EekPoint origin, int32_
|
|||||||
points[3].x = points[0].x;
|
points[3].x = points[0].x;
|
||||||
points[3].y = points[2].y;
|
points[3].y = points[2].y;
|
||||||
|
|
||||||
for (uint i = 0; i < G_N_ELEMENTS(points); i++) {
|
for (unsigned i = 0; i < G_N_ELEMENTS(points); i++) {
|
||||||
eek_point_rotate (&points[i], angle);
|
eek_point_rotate (&points[i], angle);
|
||||||
points[i].x += origin.x;
|
points[i].x += origin.x;
|
||||||
points[i].y += origin.y;
|
points[i].y += origin.y;
|
||||||
|
|||||||
@ -57,8 +57,7 @@ struct _EekRendererClass
|
|||||||
|
|
||||||
GType eek_renderer_get_type (void) G_GNUC_CONST;
|
GType eek_renderer_get_type (void) G_GNUC_CONST;
|
||||||
EekRenderer *eek_renderer_new (LevelKeyboard *keyboard,
|
EekRenderer *eek_renderer_new (LevelKeyboard *keyboard,
|
||||||
PangoContext *pcontext,
|
PangoContext *pcontext);
|
||||||
GtkStyleContext *scontext);
|
|
||||||
void eek_renderer_set_allocation_size
|
void eek_renderer_set_allocation_size
|
||||||
(EekRenderer *renderer,
|
(EekRenderer *renderer,
|
||||||
gdouble width,
|
gdouble width,
|
||||||
|
|||||||
Reference in New Issue
Block a user