[vte] app: Add option to load extra CSS from a file
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] app: Add option to load extra CSS from a file
- Date: Sat, 18 Jul 2020 11:54:09 +0000 (UTC)
commit d552d64c0e218566f076ef2cd47a45275620b576
Author: Christian Persch <chpe src gnome org>
Date: Sat Jul 18 13:52:55 2020 +0200
app: Add option to load extra CSS from a file
https://gitlab.gnome.org/GNOME/vte/-/issues/268
src/app/app.cc | 28 ++++++++++++++++++++++++++++
src/app/meson.build | 2 +-
src/meson.build | 7 +++++--
3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/src/app/app.cc b/src/app/app.cc
index 470438b5..d8bfe9e1 100644
--- a/src/app/app.cc
+++ b/src/app/app.cc
@@ -40,6 +40,7 @@
#include "glib-glue.hh"
#include "libc-glue.hh"
+#include "refptr.hh"
/* options */
@@ -110,6 +111,7 @@ public:
VteCursorBlinkMode cursor_blink_mode{VTE_CURSOR_BLINK_SYSTEM};
VteCursorShape cursor_shape{VTE_CURSOR_SHAPE_BLOCK};
VteTextBlinkMode text_blink_mode{VTE_TEXT_BLINK_ALWAYS};
+ vte::glib::RefPtr<GtkCssProvider> css{};
~Options() {
g_clear_object(&background_pixbuf);
@@ -355,6 +357,19 @@ private:
return that->parse_color(value, &that->bg_color, &set, error);
}
+ static gboolean
+ parse_css_file(char const* option, char const* value, void* data, GError** error)
+ {
+ Options* that = static_cast<Options*>(data);
+
+ auto css = vte::glib::take_ref(gtk_css_provider_new());
+ if (!gtk_css_provider_load_from_path(css.get(), value, error))
+ return false;
+
+ that->css = std::move(css);
+ return true;
+ }
+
static gboolean
parse_fd(char const* option, char const* value, void* data, GError** error)
{
@@ -486,6 +501,8 @@ public:
"Enable a colored cursor foreground", "COLOR" },
{ "cursor-shape", 0, 0, G_OPTION_ARG_CALLBACK, (void*)parse_cursor_shape,
"Set cursor shape (block|underline|ibeam)", nullptr },
+ { "css-file", 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK,
(void*)parse_css_file,
+ "Load CSS from FILE", "FILE" },
{ "dingu", 'D', 0, G_OPTION_ARG_STRING_ARRAY, &dingus,
"Add regex highlight", nullptr },
{ "debug", 'd', 0,G_OPTION_ARG_NONE, &debug,
@@ -921,6 +938,8 @@ vteapp_search_popover_class_init(VteappSearchPopoverClass* klass)
gtk_widget_class_bind_template_child(widget_class, VteappSearchPopover, entire_word_checkbutton);
gtk_widget_class_bind_template_child(widget_class, VteappSearchPopover, regex_checkbutton);
gtk_widget_class_bind_template_child(widget_class, VteappSearchPopover, wrap_around_checkbutton);
+
+ gtk_widget_class_set_css_name(widget_class, "vteapp-search-popover");
}
static GtkWidget*
@@ -1073,6 +1092,8 @@ vteapp_terminal_class_init(VteappTerminalClass *klass)
widget_class->unrealize = vteapp_terminal_unrealize;
widget_class->draw = vteapp_terminal_draw;
widget_class->style_updated = vteapp_terminal_style_updated;
+
+ gtk_widget_class_set_css_name(widget_class, "vteapp-terminal");
}
static void
@@ -2224,6 +2245,7 @@ vteapp_window_class_init(VteappWindowClass* klass)
widget_class->window_state_event = vteapp_window_state_event;
gtk_widget_class_set_template_from_resource(widget_class, "/org/gnome/vte/app/ui/window.ui");
+ gtk_widget_class_set_css_name(widget_class, "vteapp-window");
gtk_widget_class_bind_template_child(widget_class, VteappWindow, window_box);
gtk_widget_class_bind_template_child(widget_class, VteappWindow, scrollbar);
@@ -2333,6 +2355,12 @@ vteapp_application_init(VteappApplication* application)
"gtk-menu-bar-accel", nullptr,
nullptr);
+ if (options.css) {
+ gtk_style_context_add_provider_for_screen(gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER(options.css.get()),
+ GTK_STYLE_PROVIDER_PRIORITY_USER);
+ }
+
if (options.feed_stdin) {
g_unix_set_fd_nonblocking(STDIN_FILENO, true, nullptr);
application->input_source = g_unix_fd_add(STDIN_FILENO,
diff --git a/src/app/meson.build b/src/app/meson.build
index fcf30aa6..406e1707 100644
--- a/src/app/meson.build
+++ b/src/app/meson.build
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <https://www.gnu.org/licenses/>.
-app_sources = glib_glue_sources + libc_glue_sources + files(
+app_sources = glib_glue_sources + libc_glue_sources + refptr_sources + files(
'app.cc',
)
diff --git a/src/meson.build b/src/meson.build
index 6162458e..087831fa 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -78,6 +78,10 @@ pty_sources = files(
'vteptyinternal.hh',
)
+refptr_sources = files(
+ 'refptr.hh',
+)
+
regex_sources = files(
'regex.cc',
'regex.hh'
@@ -93,7 +97,7 @@ utf8_sources = files(
'utf8.hh',
)
-libvte_common_sources = debug_sources + glib_glue_sources + libc_glue_sources + modes_sources +
parser_sources + pty_sources + regex_sources + utf8_sources + files(
+libvte_common_sources = debug_sources + glib_glue_sources + libc_glue_sources + modes_sources +
parser_sources + pty_sources + refptr_sources + regex_sources + utf8_sources + files(
'attr.hh',
'bidi.cc',
'bidi.hh',
@@ -118,7 +122,6 @@ libvte_common_sources = debug_sources + glib_glue_sources + libc_glue_sources +
'missing.hh',
'reaper.cc',
'reaper.hh',
- 'refptr.hh',
'ring.cc',
'ring.hh',
'ringview.cc',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]