[gnome-builder] line-spacing: add line-spacing plugin



commit c8041a2f3e09d26d56397ba46286ae0febe0bdb9
Author: Christian Hergert <chergert redhat com>
Date:   Tue Feb 26 18:28:55 2019 -0800

    line-spacing: add line-spacing plugin
    
    This adds a new line-spacing plugin which will draw a number of
    pixels above and below a given line. The only real way to do
    this with Gtk is to set pixels-above-lines/pixels-below-lines.
    
    We need to keep them symmetrical because otherwise drawing the
    highlight line isn't synchronized.
    
    Fixes #832

 .../gsettings/org.gnome.builder.editor.gschema.xml |   6 +
 src/libide/gui/ide-preferences-builtin.c           |   1 +
 .../line-spacing/gbp-line-spacing-buffer-addin.c   | 157 +++++++++++++++++++++
 .../line-spacing/gbp-line-spacing-buffer-addin.h   |  31 ++++
 src/plugins/line-spacing/line-spacing-plugin.c     |  36 +++++
 .../line-spacing/line-spacing.gresource.xml        |   6 +
 src/plugins/line-spacing/line-spacing.plugin       |  10 ++
 src/plugins/line-spacing/meson.build               |  12 ++
 src/plugins/meson.build                            |   1 +
 src/plugins/omni-gutter/gbp-omni-gutter-renderer.c |   9 ++
 10 files changed, 269 insertions(+)
---
diff --git a/data/gsettings/org.gnome.builder.editor.gschema.xml 
b/data/gsettings/org.gnome.builder.editor.gschema.xml
index 24aa5ced8..b6107013a 100644
--- a/data/gsettings/org.gnome.builder.editor.gschema.xml
+++ b/data/gsettings/org.gnome.builder.editor.gschema.xml
@@ -118,6 +118,12 @@
       <summary>Completion Row Count</summary>
       <description>The number of completion rows to display to the user.</description>
     </key>
+    <key name="line-spacing" type="i">
+      <default>0</default>
+      <range min="0" max="32"/>
+      <summary>Line Spacing</summary>
+      <description>The number of pixels to include above and below lines in the editor.</description>
+    </key>
     <key name="interactive-completion" type="b">
       <default>true</default>
       <summary>Interactive Completion</summary>
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index 1fdee4849..a3eec206d 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -104,6 +104,7 @@ ide_preferences_builtin_register_appearance (DzlPreferences *preferences)
 
   dzl_preferences_add_list_group (preferences, "appearance", "font", _("Font"), GTK_SELECTION_NONE, 10);
   dzl_preferences_add_font_button (preferences, "appearance", "font", "org.gnome.builder.editor", 
"font-name", _("Editor"), C_("Keywords", "editor font monospace"), 0);
+  dzl_preferences_add_spin_button (preferences, "appearance", "font", "org.gnome.builder.editor", 
"line-spacing", NULL, _("Line Spacing"), _("Number of pixels above and below editor lines"), C_("Keywords", 
"editor line spacing font monospace"), 0);
   /* XXX: This belongs in terminal addin */
   dzl_preferences_add_font_button (preferences, "appearance", "font", "org.gnome.builder.terminal", 
"font-name", _("Terminal"), C_("Keywords", "terminal font monospace"), 1);
   dzl_preferences_add_switch (preferences, "appearance", "font", "org.gnome.builder.terminal", "allow-bold", 
NULL, NULL, _("Bold text in terminals"), _("If terminals are allowed to display bold text"), C_("Keywords", 
"terminal allow bold"), 2);
diff --git a/src/plugins/line-spacing/gbp-line-spacing-buffer-addin.c 
b/src/plugins/line-spacing/gbp-line-spacing-buffer-addin.c
new file mode 100644
index 000000000..9a2ec2033
--- /dev/null
+++ b/src/plugins/line-spacing/gbp-line-spacing-buffer-addin.c
@@ -0,0 +1,157 @@
+/* gbp-line-spacing-buffer-addin.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-line-spacing-buffer-addin"
+
+#include "config.h"
+
+#include <libide-code.h>
+
+#include "gbp-line-spacing-buffer-addin.h"
+
+struct _GbpLineSpacingBufferAddin
+{
+  GObject     parent_instance;
+  IdeBuffer  *buffer;
+  GtkTextTag *tag;
+  GSettings  *settings;
+};
+
+static void
+gbp_line_spacing_buffer_addin_apply (GbpLineSpacingBufferAddin *self)
+{
+  GtkTextIter begin;
+  GtkTextIter end;
+
+  g_assert (IDE_IS_BUFFER (self->buffer));
+  g_assert (GTK_IS_TEXT_TAG (self->tag));
+
+  gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (self->buffer), &begin, &end);
+  gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (self->buffer), self->tag, &begin, &end);
+}
+
+static void
+on_buffer_changed_cb (GbpLineSpacingBufferAddin *self,
+                      IdeBuffer                 *buffer)
+{
+  g_assert (GBP_IS_LINE_SPACING_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  if (self->tag != NULL)
+    gbp_line_spacing_buffer_addin_apply (self);
+}
+
+static void
+on_line_spacing_changed_cb (GbpLineSpacingBufferAddin *self,
+                            const gchar               *key,
+                            GSettings                 *settings)
+{
+  gint spacing;
+
+  g_assert (GBP_IS_LINE_SPACING_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (self->buffer));
+  g_assert (G_IS_SETTINGS (settings));
+
+  if (self->tag != NULL)
+    {
+      GtkTextTagTable *table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (self->buffer));
+      gtk_text_tag_table_remove (table, self->tag);
+      self->tag = NULL;
+    }
+
+  spacing = g_settings_get_int (settings, "line-spacing");
+
+  if (spacing > 0)
+    {
+      self->tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self->buffer), NULL,
+                                              "pixels-above-lines", spacing,
+                                              "pixels-below-lines", spacing,
+                                              NULL);
+      gbp_line_spacing_buffer_addin_apply (self);
+    }
+}
+
+static void
+gbp_line_spacing_buffer_addin_load (IdeBufferAddin *addin,
+                                    IdeBuffer      *buffer)
+{
+  GbpLineSpacingBufferAddin *self = (GbpLineSpacingBufferAddin *)addin;
+
+  g_assert (GBP_IS_LINE_SPACING_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  self->buffer = buffer;
+  self->settings = g_settings_new ("org.gnome.builder.editor");
+
+  g_signal_connect_object (self->settings,
+                           "changed::line-spacing",
+                           G_CALLBACK (on_line_spacing_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  on_line_spacing_changed_cb (self, NULL, self->settings);
+
+  g_signal_connect_object (self->buffer,
+                           "changed",
+                           G_CALLBACK (on_buffer_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+}
+
+static void
+gbp_line_spacing_buffer_addin_unload (IdeBufferAddin *addin,
+                                      IdeBuffer      *buffer)
+{
+  GbpLineSpacingBufferAddin *self = (GbpLineSpacingBufferAddin *)addin;
+
+  g_assert (GBP_IS_LINE_SPACING_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  g_signal_handlers_disconnect_by_func (self->settings,
+                                        G_CALLBACK (on_line_spacing_changed_cb),
+                                        self);
+
+  g_signal_handlers_disconnect_by_func (self->buffer,
+                                        G_CALLBACK (on_buffer_changed_cb),
+                                        self);
+
+  g_clear_object (&self->settings);
+  self->buffer = NULL;
+}
+
+static void
+buffer_addin_iface_init (IdeBufferAddinInterface *iface)
+{
+  iface->load = gbp_line_spacing_buffer_addin_load;
+  iface->unload = gbp_line_spacing_buffer_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpLineSpacingBufferAddin, gbp_line_spacing_buffer_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_BUFFER_ADDIN, buffer_addin_iface_init))
+
+static void
+gbp_line_spacing_buffer_addin_class_init (GbpLineSpacingBufferAddinClass *klass)
+{
+}
+
+static void
+gbp_line_spacing_buffer_addin_init (GbpLineSpacingBufferAddin *self)
+{
+}
diff --git a/src/plugins/line-spacing/gbp-line-spacing-buffer-addin.h 
b/src/plugins/line-spacing/gbp-line-spacing-buffer-addin.h
new file mode 100644
index 000000000..38f5e77de
--- /dev/null
+++ b/src/plugins/line-spacing/gbp-line-spacing-buffer-addin.h
@@ -0,0 +1,31 @@
+/* gbp-line-spacing-buffer-addin.h
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_LINE_SPACING_BUFFER_ADDIN (gbp_line_spacing_buffer_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpLineSpacingBufferAddin, gbp_line_spacing_buffer_addin, GBP, 
LINE_SPACING_BUFFER_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/line-spacing/line-spacing-plugin.c b/src/plugins/line-spacing/line-spacing-plugin.c
new file mode 100644
index 000000000..5fd87e7b7
--- /dev/null
+++ b/src/plugins/line-spacing/line-spacing-plugin.c
@@ -0,0 +1,36 @@
+/* line-spacing-plugin.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "line-spacing-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-code.h>
+
+#include "gbp-line-spacing-buffer-addin.h"
+
+_IDE_EXTERN void
+_gbp_line_spacing_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUFFER_ADDIN,
+                                              GBP_TYPE_LINE_SPACING_BUFFER_ADDIN);
+}
diff --git a/src/plugins/line-spacing/line-spacing.gresource.xml 
b/src/plugins/line-spacing/line-spacing.gresource.xml
new file mode 100644
index 000000000..639a1fa9f
--- /dev/null
+++ b/src/plugins/line-spacing/line-spacing.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/line-spacing">
+    <file>line-spacing.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/line-spacing/line-spacing.plugin b/src/plugins/line-spacing/line-spacing.plugin
new file mode 100644
index 000000000..8e19cfad5
--- /dev/null
+++ b/src/plugins/line-spacing/line-spacing.plugin
@@ -0,0 +1,10 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2019 Christian Hergert
+Depends=editor;
+Description=Line spacing support for the editor
+Embedded=_gbp_line_spacing_register_types
+Hidden=true
+Module=line-spacing
+Name=Line Spacing
diff --git a/src/plugins/line-spacing/meson.build b/src/plugins/line-spacing/meson.build
new file mode 100644
index 000000000..3a6dc5b35
--- /dev/null
+++ b/src/plugins/line-spacing/meson.build
@@ -0,0 +1,12 @@
+plugins_sources += files([
+  'line-spacing-plugin.c',
+  'gbp-line-spacing-buffer-addin.c',
+])
+
+plugin_line_spacing_resources = gnome.compile_resources(
+  'gbp-line-spacing-resources',
+  'line-spacing.gresource.xml',
+  c_name: 'gbp_line_spacing',
+)
+
+plugins_sources += plugin_line_spacing_resources[0]
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 217f8e3f6..f2beb26b8 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -80,6 +80,7 @@ subdir('html-completion')
 subdir('html-preview')
 subdir('jedi')
 subdir('jhbuild')
+subdir('line-spacing')
 subdir('ls')
 subdir('make')
 subdir('maven')
diff --git a/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c 
b/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c
index 6b8fefe70..5c53df819 100644
--- a/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c
+++ b/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c
@@ -68,6 +68,9 @@ struct _GbpOmniGutterRenderer
 {
   GtkSourceGutterRenderer parent_instance;
 
+  GSettings *settings;
+  gint line_spacing;
+
   IdeDebuggerBreakpoints *breakpoints;
 
   GArray *lines;
@@ -722,6 +725,8 @@ gbp_omni_gutter_renderer_begin (GtkSourceGutterRenderer *renderer,
   g_assert (begin != NULL);
   g_assert (end != NULL);
 
+  self->line_spacing = g_settings_get_int (self->settings, "line-spacing");
+
   /*
    * This is the start of our draw process. The first thing we want to
    * do is collect as much information as we'll need when doing the
@@ -1237,6 +1242,7 @@ gbp_omni_gutter_renderer_draw (GtkSourceGutterRenderer      *renderer,
           if (state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR)
             bold |= self->current.bold;
 
+          cairo_move_to (cr, cell_area->x, cell_area->y + self->line_spacing);
           pango_layout_set_attributes (self->layout, bold ? self->bold_attrs : NULL);
           pango_cairo_show_layout (cr, self->layout);
         }
@@ -1495,6 +1501,8 @@ gbp_omni_gutter_renderer_constructed (GObject *object)
 
   view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (self));
   dzl_signal_group_set_target (self->view_signals, view);
+
+  self->settings = g_settings_new ("org.gnome.builder.editor");
 }
 
 static void
@@ -1504,6 +1512,7 @@ gbp_omni_gutter_renderer_dispose (GObject *object)
 
   dzl_clear_source (&self->resize_source);
 
+  g_clear_object (&self->settings);
   g_clear_object (&self->breakpoints);
   g_clear_pointer (&self->lines, g_array_unref);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]