Commit 2354b3f7 authored by David King's avatar David King
Browse files

Apply the system monospace font to log messages

Monitor the monospace-font-name key from gsettings-desktop-schemas and
update the font if it changes.
parent 643c9f41
GNOME Logs is a log viewer for the systemd journal
https://wiki.gnome.org/Apps/Logs
It depends on GTK+ 3.10 or above and libsystemd-journal at build time, and
gsettings-desktop-schemas at runtime.
......@@ -34,6 +34,11 @@ IT_PROG_INTLTOOL([0.50.0])
AC_SUBST([GETTEXT_PACKAGE], [AC_PACKAGE_TARNAME])
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [gettext package name])
dnl GSettings schemas
PKG_CHECK_EXISTS([gsettings-desktop-schemas],
[],
[AC_MSG_WARN([gsettings-desktop-schemas is required at runtime])])
dnl Libraries
GTK_REQUIRED="gtk+-3.0 >= 3.9.6"
SYSTEMD_JOURNAL_REQUIRED="libsystemd-journal"
......
......@@ -24,9 +24,19 @@
#include "gl-categorylist.h"
#include "gl-eventtoolbar.h"
#include "gl-eventview.h"
#include "gl-util.h"
#include "gl-window.h"
G_DEFINE_TYPE (GlApplication, gl_application, GTK_TYPE_APPLICATION)
typedef struct
{
GSettings *desktop;
gchar *monospace_font;
} GlApplicationPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GlApplication, gl_application, GTK_TYPE_APPLICATION)
static const gchar DESKTOP_SCHEMA[] = "org.gnome.desktop.interface";
static const gchar DESKTOP_MONOSPACE_FONT_NAME[] = "monospace-font-name";
static void
on_new_window (GSimpleAction *action,
......@@ -78,6 +88,44 @@ on_quit (GSimpleAction *action,
g_application_quit (application);
}
static void
on_monospace_font_name_changed (GSettings *settings,
const gchar *key,
GlApplicationPrivate *priv)
{
gchar *font_name;
font_name = g_settings_get_string (settings, key);
if (g_strcmp0 (font_name, priv->monospace_font) != 0)
{
GtkCssProvider *provider;
gchar *css_fragment;
g_free (priv->monospace_font);
priv->monospace_font = font_name;
css_fragment = g_strconcat (".event-monospace { font: ", font_name,
"; }", NULL);
provider = gtk_css_provider_new ();
g_signal_connect (provider, "parsing-error",
G_CALLBACK (gl_util_on_css_provider_parsing_error),
NULL);
gtk_css_provider_load_from_data (provider, css_fragment, -1, NULL);
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_free (css_fragment);
g_object_unref (provider);
}
else
{
g_free (font_name);
}
}
static GActionEntry actions[] = {
{ "new-window", on_new_window },
{ "about", on_about },
......@@ -123,6 +171,7 @@ static void
gl_application_activate (GApplication *application)
{
GtkWidget *window;
GlApplicationPrivate *priv;
window = gl_window_new (GTK_APPLICATION (application));
gtk_widget_show (window);
......@@ -130,18 +179,54 @@ gl_application_activate (GApplication *application)
"<Primary>w", "win.close", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (application),
"<Primary>f", "win.search", NULL);
priv = gl_application_get_instance_private (GL_APPLICATION (application));
on_monospace_font_name_changed (priv->desktop, DESKTOP_MONOSPACE_FONT_NAME,
priv);
}
static void
gl_application_finalize (GObject *object)
{
GlApplication *application;
GlApplicationPrivate *priv;
application = GL_APPLICATION (object);
priv = gl_application_get_instance_private (application);
g_clear_object (&priv->desktop);
g_clear_pointer (&priv->monospace_font, g_free);
}
static void
gl_application_init (GlApplication *application)
{
GlApplicationPrivate *priv;
gchar *changed_font;
priv = gl_application_get_instance_private (application);
priv->monospace_font = NULL;
priv->desktop = g_settings_new (DESKTOP_SCHEMA);
changed_font = g_strconcat ("changed::", DESKTOP_MONOSPACE_FONT_NAME, NULL);
g_signal_connect (priv->desktop, changed_font,
G_CALLBACK (on_monospace_font_name_changed),
priv);
g_free (changed_font);
}
static void
gl_application_class_init (GlApplicationClass *klass)
{
GObjectClass *gobject_class;
GApplicationClass *app_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = gl_application_finalize;
app_class = G_APPLICATION_CLASS (klass);
app_class->activate = gl_application_activate;
app_class->startup = gl_application_startup;
......
......@@ -36,7 +36,7 @@ typedef struct
} GlApplicationClass;
#define GL_TYPE_APPLICATION (gl_application_get_type ())
#define GL_APPLICATION(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_APPLICATION, GlApplication)
#define GL_APPLICATION(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_APPLICATION, GlApplication))
GType gl_application_get_type (void);
GtkApplication * gl_application_new (void);
......
......@@ -105,7 +105,7 @@ on_listbox_row_activated (GtkListBox *listbox,
gchar *time;
GtkWidget *grid;
GtkWidget *label;
GtkStyleContext *style;
GtkStyleContext *context;
GtkStack *stack;
priv = gl_event_view_get_instance_private (view);
......@@ -121,8 +121,8 @@ on_listbox_row_activated (GtkListBox *listbox,
grid = gtk_grid_new ();
label = gtk_label_new (result->comm);
style = gtk_widget_get_style_context (label);
gtk_style_context_add_class (style, "detail-comm");
context = gtk_widget_get_style_context (label);
gtk_style_context_add_class (context, "detail-comm");
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
datetime = g_date_time_new_from_unix_utc (result->timestamp
......@@ -148,8 +148,8 @@ on_listbox_row_activated (GtkListBox *listbox,
gtk_widget_set_hexpand (label, TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
style = gtk_widget_get_style_context (label);
gtk_style_context_add_class (style, "detail-time");
context = gtk_widget_get_style_context (label);
gtk_style_context_add_class (context, "detail-time");
gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
g_free (time);
......@@ -157,15 +157,16 @@ on_listbox_row_activated (GtkListBox *listbox,
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
style = gtk_widget_get_style_context (label);
gtk_style_context_add_class (style, "detail-message");
context = gtk_widget_get_style_context (label);
gtk_style_context_add_class (context, "detail-message");
gtk_style_context_add_class (context, "event-monospace");
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 2, 1);
label = gtk_label_new (result->catalog);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
style = gtk_widget_get_style_context (label);
gtk_style_context_add_class (style, "detail-catalog");
context = gtk_widget_get_style_context (label);
gtk_style_context_add_class (context, "detail-catalog");
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 2, 1);
gtk_widget_show_all (grid);
......@@ -414,6 +415,8 @@ insert_journal_query_devices (GlJournal *journal,
gtk_container_add (GTK_CONTAINER (row), grid);
label = gtk_label_new (result.message);
context = gtk_widget_get_style_context (GTK_WIDGET (label));
gtk_style_context_add_class (context, "event-monospace");
gtk_widget_set_hexpand (label, TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
......@@ -486,6 +489,8 @@ insert_journal_query_security (GlJournal *journal,
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
label = gtk_label_new (result.message);
context = gtk_widget_get_style_context (GTK_WIDGET (label));
gtk_style_context_add_class (context, "event-monospace");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
......@@ -540,6 +545,8 @@ insert_journal_query_simple (GlJournal *journal,
gtk_container_add (GTK_CONTAINER (row), grid);
label = gtk_label_new (result.message);
context = gtk_widget_get_style_context (GTK_WIDGET (label));
gtk_style_context_add_class (context, "event-monospace");
gtk_widget_set_hexpand (label, TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
......@@ -578,7 +585,7 @@ insert_journal_query_cmdline (GlJournal *journal,
for (l = results; l != NULL; l = g_list_next (l))
{
GtkWidget *row;
GtkStyleContext *style;
GtkStyleContext *context;
GtkWidget *grid;
gchar *markup;
GtkWidget *label;
......@@ -587,8 +594,8 @@ insert_journal_query_cmdline (GlJournal *journal,
GlJournalResult result = *(GlJournalResult *)(l->data);
row = gtk_list_box_row_new ();
style = gtk_widget_get_style_context (GTK_WIDGET (row));
gtk_style_context_add_class (style, "event");
context = gtk_widget_get_style_context (GTK_WIDGET (row));
gtk_style_context_add_class (context, "event");
g_object_set_data_full (G_OBJECT (row), "cursor",
g_strdup (result.cursor), g_free);
grid = gtk_grid_new ();
......@@ -605,6 +612,8 @@ insert_journal_query_cmdline (GlJournal *journal,
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
label = gtk_label_new (result.message);
context = gtk_widget_get_style_context (GTK_WIDGET (label));
gtk_style_context_add_class (context, "event-monospace");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment