[gnome-panel] handle: use custom symbolic icon
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] handle: use custom symbolic icon
- Date: Mon, 26 Apr 2021 22:06:28 +0000 (UTC)
commit 101c8760a67098cf0e4b588df0d13d6508cc7310
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Apr 26 23:20:53 2021 +0300
handle: use custom symbolic icon
data/theme/Makefile.am | 1 +
data/theme/common.css | 15 +++++
data/theme/gp-handle-symbolic.svg | 1 +
gnome-panel/gp-handle.c | 118 +++++++++++++++++++++++++++++---------
gnome-panel/panel.gresource.xml | 1 +
5 files changed, 108 insertions(+), 28 deletions(-)
---
diff --git a/data/theme/Makefile.am b/data/theme/Makefile.am
index ca0c59acb..5ba798999 100644
--- a/data/theme/Makefile.am
+++ b/data/theme/Makefile.am
@@ -9,6 +9,7 @@ SUBDIRS = \
EXTRA_DIST = \
common.css \
fallback.css \
+ gp-handle-symbolic.svg \
$(NULL)
-include $(top_srcdir)/git.mk
diff --git a/data/theme/common.css b/data/theme/common.css
index 9bd3599bb..c1f63c3de 100644
--- a/data/theme/common.css
+++ b/data/theme/common.css
@@ -93,6 +93,21 @@ gp-arrow-button {
min-height: 20px;
}
+gp-handle {
+ -gtk-icon-source: -gtk-recolor(url("/org/gnome/gnome-panel/theme/gp-handle-symbolic.svg"));
+ min-width: 16px;
+ min-height: 16px;
+}
+
+.horizontal gp-handle {
+ margin: 0 -3px;
+}
+
+.vertical gp-handle {
+ -gtk-icon-transform: rotate(90deg);
+ margin: -3px 0;
+}
+
.context-row {
padding: 4px 10px;
}
diff --git a/data/theme/gp-handle-symbolic.svg b/data/theme/gp-handle-symbolic.svg
new file mode 100644
index 000000000..d3a8c149e
--- /dev/null
+++ b/data/theme/gp-handle-symbolic.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><g fill="#bebebe"
fill-rule="evenodd"><path d="M6 15h1v1H6zM9 15h1v1H9zM6 12h1v1H6zM9 12h1v1H9zM6 9h1v1H6zM9 9h1v1H9zM6
6h1v1H6zM9 6h1v1H9zM6 3h1v1H6zM9 3h1v1H9zM6 0h1v1H6zM9 0h1v1H9z"/></g></svg>
\ No newline at end of file
diff --git a/gnome-panel/gp-handle.c b/gnome-panel/gp-handle.c
index dcc532b70..1bd1ee60e 100644
--- a/gnome-panel/gp-handle.c
+++ b/gnome-panel/gp-handle.c
@@ -21,8 +21,6 @@
#include "panel-enums-gsettings.h"
#include "panel-typebuiltins.h"
-#define HANDLE_SIZE 10
-
struct _GpHandle
{
GtkWidget parent;
@@ -93,15 +91,43 @@ gp_handle_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (gtk_widget_get_toplevel (widget));
-
- gtk_render_handle (context,
- cr,
- 0,
- 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
+ GtkStateFlags flags;
+ int width;
+ int height;
+ GtkBorder margin;
+ GtkBorder border;
+ GtkBorder padding;
+ int handle_width;
+ int handle_height;
+
+ context = gtk_widget_get_style_context (widget);
+ flags = gtk_style_context_get_state (context);
+
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+
+ gtk_render_background (context, cr, 0, 0, width, height);
+ gtk_render_frame (context, cr, 0, 0, width, height);
+
+ gtk_style_context_get_margin (context, flags, &margin);
+ gtk_style_context_get_border (context, flags, &border);
+ gtk_style_context_get_padding (context, flags, &padding);
+
+ gtk_style_context_get (context,
+ flags,
+ "min-height", &handle_height,
+ "min-width", &handle_width,
+ NULL);
+
+ width -= margin.left + border.left + padding.left + padding.right + border.right + margin.right;
+ height -= margin.top + border.top + padding.top + padding.bottom + border.bottom + margin.bottom;
+
+ gtk_render_check (context,
+ cr,
+ margin.left + border.left + padding.left + (width - handle_width) / 2,
+ margin.top + border.top + padding.top + (height - handle_height) / 2,
+ handle_width,
+ handle_height);
return FALSE;
}
@@ -111,14 +137,27 @@ gp_handle_get_preferred_height (GtkWidget *widget,
gint *minimum_height,
gint *natural_height)
{
- GpHandle *self;
-
- self = GP_HANDLE (widget);
-
- if (self->orientation & PANEL_VERTICAL_MASK)
- *minimum_height = *natural_height = HANDLE_SIZE;
- else
- *minimum_height = *natural_height = 0;
+ GtkStyleContext *context;
+ GtkStateFlags flags;
+ GtkBorder margin;
+ GtkBorder border;
+ GtkBorder padding;
+ int handle_height;
+ int height;
+
+ context = gtk_widget_get_style_context (widget);
+ flags = gtk_style_context_get_state (context);
+
+ gtk_style_context_get_margin (context, flags, &margin);
+ gtk_style_context_get_border (context, flags, &border);
+ gtk_style_context_get_padding (context, flags, &padding);
+ gtk_style_context_get (context, flags, "min-height", &handle_height, NULL);
+
+ height = margin.top + border.top + padding.top;
+ height += handle_height;
+ height += padding.bottom + border.bottom + margin.bottom;
+
+ *minimum_height = *natural_height = height;
}
static void
@@ -126,14 +165,27 @@ gp_handle_get_preferred_width (GtkWidget *widget,
gint *minimum_width,
gint *natural_width)
{
- GpHandle *self;
-
- self = GP_HANDLE (widget);
-
- if (self->orientation & PANEL_HORIZONTAL_MASK)
- *minimum_width = *natural_width = HANDLE_SIZE;
- else
- *minimum_width = *natural_width = 0;
+ GtkStyleContext *context;
+ GtkStateFlags flags;
+ GtkBorder margin;
+ GtkBorder border;
+ GtkBorder padding;
+ int handle_width;
+ int width;
+
+ context = gtk_widget_get_style_context (widget);
+ flags = gtk_style_context_get_state (context);
+
+ gtk_style_context_get_margin (context, flags, &margin);
+ gtk_style_context_get_border (context, flags, &border);
+ gtk_style_context_get_padding (context, flags, &padding);
+ gtk_style_context_get (context, flags, "min-width", &handle_width, NULL);
+
+ width = margin.left + border.left + padding.left;
+ width += handle_width;
+ width += padding.right + border.right + margin.right;
+
+ *minimum_width = *natural_width = width;
}
static void
@@ -171,12 +223,22 @@ gp_handle_class_init (GpHandleClass *self_class)
widget_class->get_preferred_width = gp_handle_get_preferred_width;
install_properties (object_class);
+
+ gtk_widget_class_set_css_name (widget_class, "gp-handle");
}
static void
gp_handle_init (GpHandle *self)
{
- gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+ GtkWidget *widget;
+ GtkStyleContext *context;
+
+ widget = GTK_WIDGET (self);
+
+ gtk_widget_set_has_window (widget, FALSE);
+
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_add_class (context, "gp-text-color");
}
GtkWidget *
diff --git a/gnome-panel/panel.gresource.xml b/gnome-panel/panel.gresource.xml
index e455a157c..e97864aed 100644
--- a/gnome-panel/panel.gresource.xml
+++ b/gnome-panel/panel.gresource.xml
@@ -8,6 +8,7 @@
<file alias="Yaru/gnome-panel.css">../data/theme/Yaru/gnome-panel.css</file>
<file alias="common.css">../data/theme/common.css</file>
<file alias="fallback.css">../data/theme/fallback.css</file>
+ <file alias="gp-handle-symbolic.svg">../data/theme/gp-handle-symbolic.svg</file>
</gresource>
<gresource prefix="/org/gnome/panel">
<file compressed="true">gp-properties-dialog.ui</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]