Style index mode with CSS

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2014-04-26 23:32:38 +02:00
parent 9a0ff4b79b
commit 8f61583af7
6 changed files with 45 additions and 2 deletions

View File

@ -77,7 +77,7 @@ dbus-interface-definitions.c: data/org.pwmt.zathura.xml
css-definitions.c: data/zathura.css_t css-definitions.c: data/zathura.css_t
$(QUIET)echo '#include "css-definitions.h"' > $@.tmp $(QUIET)echo '#include "css-definitions.h"' > $@.tmp
$(QUIET)echo 'const char* CSS_TEMPLATE =' >> $@.tmp $(QUIET)echo 'const char* CSS_TEMPLATE_INDEX =' >> $@.tmp
$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp $(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp
$(QUIET)echo ';' >> $@.tmp $(QUIET)echo ';' >> $@.tmp
$(QUIET)mv $@.tmp $@ $(QUIET)mv $@.tmp $@

View File

@ -174,6 +174,11 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "render-loading-fg", NULL, STRING, false, _("'Loading ...' foreground color"), cb_color_change, NULL); girara_setting_add(gsession, "render-loading-fg", NULL, STRING, false, _("'Loading ...' foreground color"), cb_color_change, NULL);
girara_setting_set(gsession, "render-loading-fg", "#000000"); girara_setting_set(gsession, "render-loading-fg", "#000000");
girara_setting_add(gsession, "index-fg", "#DDDDDD", STRING, true, _("Index mode foreground color"), NULL, NULL);
girara_setting_add(gsession, "index-bg", "#232323", STRING, true, _("Index mode background color"), NULL, NULL);
girara_setting_add(gsession, "index-active-fg", "#232323", STRING, true, _("Index mode foreground color (active element)"), NULL, NULL);
girara_setting_add(gsession, "index-active-bg", "#9FBC00", STRING, true, _("Index mode background color (active element)"), NULL, NULL);
bool_value = false; bool_value = false;
girara_setting_add(gsession, "recolor", &bool_value, BOOLEAN, false, _("Recolor pages"), cb_setting_recolor_change, NULL); girara_setting_add(gsession, "recolor", &bool_value, BOOLEAN, false, _("Recolor pages"), cb_setting_recolor_change, NULL);
bool_value = false; bool_value = false;

View File

@ -3,6 +3,6 @@
#ifndef GIRARA_CSS_DEFINITIONS_H #ifndef GIRARA_CSS_DEFINITIONS_H
#define GIRARA_CSS_DEFINITIONS_H #define GIRARA_CSS_DEFINITIONS_H
extern const char* CSS_TEMPLATE; extern const char* CSS_TEMPLATE_INDEX;
#endif #endif

View File

@ -1,3 +1,5 @@
/* Index mode colors */
#@session@ .indexmode { #@session@ .indexmode {
color: @index-fg@; color: @index-fg@;
background-color: @index-bg@; background-color: @index-bg@;

View File

@ -1128,6 +1128,9 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
goto error_free; goto error_free;
} }
gtk_style_context_add_class(gtk_widget_get_style_context(treeview),
"indexmode");
g_object_unref(model); g_object_unref(model);
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();

View File

@ -14,6 +14,7 @@
#include <girara/statusbar.h> #include <girara/statusbar.h>
#include <girara/settings.h> #include <girara/settings.h>
#include <girara/shortcuts.h> #include <girara/shortcuts.h>
#include <girara/template.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
@ -39,6 +40,7 @@
#include "plugin.h" #include "plugin.h"
#include "adjustment.h" #include "adjustment.h"
#include "dbus-interface.h" #include "dbus-interface.h"
#include "css-definitions.h"
typedef struct zathura_document_info_s { typedef struct zathura_document_info_s {
zathura_t* zathura; zathura_t* zathura;
@ -245,6 +247,37 @@ zathura_init(zathura_t* zathura)
zathura->jumplist.size = 0; zathura->jumplist.size = 0;
zathura->jumplist.cur = NULL; zathura->jumplist.cur = NULL;
/* CSS for index mode */
GiraraTemplate* csstemplate = girara_session_get_template(zathura->ui.session);
static const char* index_settings[] = {
"index-fg",
"index-bg",
"index-active-fg",
"index-active-bg"
};
for (size_t s = 0; s < LENGTH(index_settings); ++s) {
girara_template_add_variable(csstemplate, index_settings[s]);
char* tmp_value = NULL;
GdkRGBA rgba = { 0, 0, 0, 0 };
girara_setting_get(zathura->ui.session, index_settings[s], &tmp_value);
if (tmp_value != NULL) {
gdk_rgba_parse(&rgba, tmp_value);
g_free(tmp_value);
}
char* color = gdk_rgba_to_string(&rgba);
girara_template_set_variable_value(csstemplate,
index_settings[s], color);
g_free(color);
}
char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), CSS_TEMPLATE_INDEX);
girara_template_set_base(csstemplate, css);
g_free(css);
/* Start D-Bus service */ /* Start D-Bus service */
bool dbus = true; bool dbus = true;
girara_setting_get(zathura->ui.session, "dbus-service", &dbus); girara_setting_get(zathura->ui.session, "dbus-service", &dbus);