More options available in zathurarc

This commit makes much more settings available in the
zathurarc file.
This commit is contained in:
Moritz Lipp 2010-06-15 12:50:43 +02:00
parent a27d31d9b5
commit 4b62f58b31
2 changed files with 98 additions and 71 deletions

View file

@ -1,11 +1,11 @@
/* settings */ /* settings */
static const int DEFAULT_WIDTH = 800; int default_width = 800;
static const int DEFAULT_HEIGHT = 600; int default_height = 600;
static const float ZOOM_STEP = 10; float zoom_step = 10;
static const float ZOOM_MIN = 10; float zoom_min = 10;
static const float ZOOM_MAX = 400; float zoom_max = 400;
static const float SCROLL_STEP = 40; float scroll_step = 40;
static const float TRANSPARENCY = 0.4; float transparency = 0.4;
/* completion */ /* completion */
static const char FORMAT_COMMAND[] = "<b>%s</b>"; static const char FORMAT_COMMAND[] = "<b>%s</b>";
@ -45,19 +45,18 @@ char* search_highlight = "#9FBC00";
char* select_text = "#000000"; char* select_text = "#000000";
/* statusbar */ /* statusbar */
static const char DEFAULT_TEXT[] = "[No Name]"; char* default_text = "[No Name]";
/* printing */ /* printing */
#define LIST_PRINTER_COMMAND "lpstat -v | sed -n '/^.*device for \\(.*\\): .*$/s//\\1/p'" char* list_printer_command = "lpstat -v | sed -n '/^.*device for \\(.*\\): .*$/s//\\1/p'";
#define PRINT_COMMAND "lp -d '%s' -P %s '%s'" /* printer / pages / file */ char* print_command = "lp -d '%s' -P %s '%s'"; /* printer / pages / file */
/* open uri */ /* open uri */
#define URI_COMMAND "firefox '%s'" /* uri */ char* uri_command = "firefox '%s'"; /* uri */
/* additional settings */ /* additional settings */
#define SHOW_SCROLLBARS 0 gboolean show_scrollbars = FALSE;
#define ADJUST_OPEN ADJUST_BESTFIT #define ADJUST_OPEN ADJUST_BESTFIT
#define RECOLOR_OPEN 0
#define SELECTION_STYLE POPPLER_SELECTION_GLYPH #define SELECTION_STYLE POPPLER_SELECTION_GLYPH
#define GOTO_MODE GOTO_LABELS /* GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET */ #define GOTO_MODE GOTO_LABELS /* GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET */
@ -184,28 +183,41 @@ SpecialCommand special_commands[] = {
/* settings */ /* settings */
Setting settings[] = { Setting settings[] = {
/* name, variable, type, render, re-init, description */ /* name, variable, type, render, re-init, description */
{"recolor", &(Zathura.Global.recolor), 'b', TRUE, FALSE, "Invert the image" }, {"browser", &(uri_command), 's', FALSE, FALSE, "Command to open URIs"},
{"offset", &(Zathura.PDF.page_offset), 'i', FALSE, FALSE, "Optional page offset" }, {"completion_bgcolor", &(completion_bgcolor), 's', FALSE, TRUE, "Completion background color"},
{"font", &(font), 's', FALSE, TRUE, "The used font" }, {"completion_fgcolor", &(completion_fgcolor), 's', FALSE, TRUE, "Completion foreground color"},
{"default_bgcolor", &(default_bgcolor), 's', FALSE, TRUE, "Default background color"}, {"completion_g_bgcolor", &(completion_g_bgcolor), 's', FALSE, TRUE, "Completion (group) background color"},
{"default_fgcolor", &(default_fgcolor), 's', FALSE, TRUE, "Default foreground color"}, {"completion_g_fgcolor", &(completion_g_fgcolor), 's', FALSE, TRUE, "Completion (group) foreground color"},
{"inputbar_bgcolor", &(inputbar_bgcolor), 's', FALSE, TRUE, "Inputbar background color"}, {"completion_hl_bgcolor", &(completion_hl_bgcolor), 's', FALSE, TRUE, "Completion (highlight) background color"},
{"inputbar_fgcolor", &(inputbar_fgcolor), 's', FALSE, TRUE, "Inputbar foreground color"}, {"completion_hl_fgcolor", &(completion_hl_fgcolor), 's', FALSE, TRUE, "Completion (highlight) foreground color"},
{"statusbar_bgcolor", &(statusbar_bgcolor), 's', FALSE, TRUE, "Statusbar background color"}, {"default_bgcolor", &(default_bgcolor), 's', FALSE, TRUE, "Default background color"},
{"statusbar_fgcolor", &(statusbar_fgcolor), 's', FALSE, TRUE, "Statusbar foreground color"}, {"default_fgcolor", &(default_fgcolor), 's', FALSE, TRUE, "Default foreground color"},
{"completion_bgcolor", &(completion_bgcolor), 's', FALSE, TRUE, "Completion background color"}, {"default_text", &(default_text), 's', FALSE, FALSE, "Default text"},
{"completion_fgcolor", &(completion_fgcolor), 's', FALSE, TRUE, "Completion foreground color"}, {"font", &(font), 's', FALSE, TRUE, "The used font" },
{"completion_g_bgcolor", &(completion_g_bgcolor), 's', FALSE, TRUE, "Completion (group) background color"}, {"height", &(default_height), 'i', FALSE, FALSE, "Default window height"},
{"completion_g_fgcolor", &(completion_g_fgcolor), 's', FALSE, TRUE, "Completion (group) foreground color"}, {"inputbar_bgcolor", &(inputbar_bgcolor), 's', FALSE, TRUE, "Inputbar background color"},
{"completion_hl_bgcolor", &(completion_hl_bgcolor), 's', FALSE, TRUE, "Completion (highlight) background color"}, {"inputbar_fgcolor", &(inputbar_fgcolor), 's', FALSE, TRUE, "Inputbar foreground color"},
{"completion_hl_fgcolor", &(completion_hl_fgcolor), 's', FALSE, TRUE, "Completion (highlight) foreground color"}, {"labels", &(Zathura.Global.enable_labelmode), 'b', FALSE, TRUE, "Allow label mode"},
{"notification_e_bgcolor", &(notification_e_bgcolor), 's', FALSE, TRUE, "Notification (error) background color"}, {"list_printer_command", &(list_printer_command), 's', FALSE, FALSE, "Command to list printers"},
{"notification_e_fgcolor", &(notification_e_fgcolor), 's', FALSE, TRUE, "Notification (error) foreground color"}, {"notification_e_bgcolor", &(notification_e_bgcolor), 's', FALSE, TRUE, "Notification (error) background color"},
{"notification_w_bgcolor", &(notification_w_bgcolor), 's', FALSE, TRUE, "Notification (warning) background color"}, {"notification_e_fgcolor", &(notification_e_fgcolor), 's', FALSE, TRUE, "Notification (error) foreground color"},
{"notification_w_fgcolor", &(notification_w_fgcolor), 's', FALSE, TRUE, "Notification (warning) foreground color"}, {"notification_w_bgcolor", &(notification_w_bgcolor), 's', FALSE, TRUE, "Notification (warning) background color"},
{"recolor_darkcolor", &(recolor_darkcolor), 's', FALSE, TRUE, "Recoloring (dark color)"}, {"notification_w_fgcolor", &(notification_w_fgcolor), 's', FALSE, TRUE, "Notification (warning) foreground color"},
{"recolor_lightcolor", &(recolor_lightcolor), 's', FALSE, TRUE, "Recoloring (light color)"}, {"offset", &(Zathura.PDF.page_offset), 'i', FALSE, FALSE, "Optional page offset" },
{"search_highlight", &(search_highlight), 's', FALSE, TRUE, "Highlighted results"}, {"print_command", &(print_command), 's', FALSE, FALSE, "Command to print"},
{"select_text", &(select_text), 's', FALSE, TRUE, "Rectangle of the selected text"}, {"recolor", &(Zathura.Global.recolor), 'b', TRUE, FALSE, "Invert the image" },
{"recolor_darkcolor", &(recolor_darkcolor), 's', FALSE, TRUE, "Recoloring (dark color)"},
{"recolor_lightcolor", &(recolor_lightcolor), 's', FALSE, TRUE, "Recoloring (light color)"},
{"scroll_step", &(scroll_step), 'f', FALSE, FALSE, "Scroll step"},
{"scrollbars", &(show_scrollbars), 'b', FALSE, TRUE, "Show scrollbars"},
{"search_highlight", &(search_highlight), 's', FALSE, TRUE, "Highlighted results"},
{"select_text", &(select_text), 's', FALSE, TRUE, "Rectangle of the selected text"},
{"statusbar_bgcolor", &(statusbar_bgcolor), 's', FALSE, TRUE, "Statusbar background color"},
{"statusbar_fgcolor", &(statusbar_fgcolor), 's', FALSE, TRUE, "Statusbar foreground color"},
{"transparency", &(transparency), 'f', FALSE, FALSE, "Transparency of rectangles"},
{"width", &(default_width), 'i', FALSE, FALSE, "Default window width"},
{"zoom_max", &(zoom_max), 'f', FALSE, FALSE, "Zoom maximum"},
{"zoom_min", &(zoom_min), 'f', FALSE, FALSE, "Zoom minimum"},
{"zoom_step", &(zoom_step), 'f', FALSE, FALSE, "Zoom step"},
}; };

View file

@ -285,8 +285,9 @@ struct
} Zathura; } Zathura;
/* function declarations */ /* function declarations */
void init_colors(); void init_look();
void init_directories(); void init_directories();
void init_settings();
void init_zathura(); void init_zathura();
void add_marker(int); void add_marker(int);
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*); void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
@ -390,7 +391,7 @@ gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointe
/* function implementation */ /* function implementation */
void void
init_colors() init_look()
{ {
/* parse */ /* parse */
gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg)); gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg));
@ -434,7 +435,11 @@ init_colors()
gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_fg)); gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_fg));
gtk_widget_modify_font(GTK_WIDGET(Zathura.UI.inputbar), Zathura.Style.font); gtk_widget_modify_font(GTK_WIDGET(Zathura.UI.inputbar), Zathura.Style.font);
/* scrollbars */
if(show_scrollbars)
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
else
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
} }
void void
@ -468,6 +473,14 @@ init_directories()
g_free(bookmarks); g_free(bookmarks);
} }
void
init_settings()
{
Zathura.State.filename = (char*) default_text;
gtk_window_set_default_size(Zathura.UI.window, default_width, default_height);
}
void void
init_zathura() init_zathura()
{ {
@ -481,12 +494,11 @@ init_zathura()
/* other */ /* other */
Zathura.Global.mode = NORMAL; Zathura.Global.mode = NORMAL;
Zathura.Global.viewing_mode = NORMAL; Zathura.Global.viewing_mode = NORMAL;
Zathura.Global.recolor = RECOLOR_OPEN; Zathura.Global.recolor = 0;
Zathura.Global.adjust_mode = ADJUST_OPEN; Zathura.Global.adjust_mode = ADJUST_OPEN;
Zathura.Global.goto_mode = GOTO_MODE; Zathura.Global.goto_mode = GOTO_MODE;
Zathura.Global.show_index = FALSE; Zathura.Global.show_index = FALSE;
Zathura.State.filename = (char*) DEFAULT_TEXT;
Zathura.State.pages = g_strdup_printf(""); Zathura.State.pages = g_strdup_printf("");
Zathura.State.scroll_percentage = 0; Zathura.State.scroll_percentage = 0;
@ -517,7 +529,6 @@ init_zathura()
gtk_window_set_title(Zathura.UI.window, "zathura"); gtk_window_set_title(Zathura.UI.window, "zathura");
GdkGeometry hints = { 1, 1 }; GdkGeometry hints = { 1, 1 };
gtk_window_set_geometry_hints(Zathura.UI.window, NULL, &hints, GDK_HINT_MIN_SIZE); gtk_window_set_geometry_hints(Zathura.UI.window, NULL, &hints, GDK_HINT_MIN_SIZE);
gtk_window_set_default_size(Zathura.UI.window, DEFAULT_WIDTH, DEFAULT_HEIGHT);
g_signal_connect(G_OBJECT(Zathura.UI.window), "destroy", G_CALLBACK(cb_destroy), NULL); g_signal_connect(G_OBJECT(Zathura.UI.window), "destroy", G_CALLBACK(cb_destroy), NULL);
/* box */ /* box */
@ -544,12 +555,6 @@ init_zathura()
gtk_container_add(GTK_CONTAINER(Zathura.UI.view), GTK_WIDGET(Zathura.UI.viewport)); gtk_container_add(GTK_CONTAINER(Zathura.UI.view), GTK_WIDGET(Zathura.UI.viewport));
gtk_viewport_set_shadow_type(Zathura.UI.viewport, GTK_SHADOW_NONE); gtk_viewport_set_shadow_type(Zathura.UI.viewport, GTK_SHADOW_NONE);
#if SHOW_SCROLLBARS
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
#else
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
#endif
/* drawing area */ /* drawing area */
gtk_widget_show(Zathura.UI.drawing_area); gtk_widget_show(Zathura.UI.drawing_area);
g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL); g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL);
@ -877,7 +882,7 @@ highlight_result(int page_id, PopplerRectangle* rectangle)
PopplerRectangle* trect = poppler_rectangle_copy(rectangle); PopplerRectangle* trect = poppler_rectangle_copy(rectangle);
cairo_t *cairo = cairo_create(Zathura.PDF.surface); cairo_t *cairo = cairo_create(Zathura.PDF.surface);
cairo_set_source_rgba(cairo, Zathura.Style.search_highlight.red, Zathura.Style.search_highlight.green, cairo_set_source_rgba(cairo, Zathura.Style.search_highlight.red, Zathura.Style.search_highlight.green,
Zathura.Style.search_highlight.blue, TRANSPARENCY); Zathura.Style.search_highlight.blue, transparency);
recalcRectangle(page_id, trect); recalcRectangle(page_id, trect);
cairo_rectangle(cairo, trect->x1, trect->y1, (trect->x2 - trect->x1), (trect->y2 - trect->y1)); cairo_rectangle(cairo, trect->x1, trect->y1, (trect->x2 - trect->x1), (trect->y2 - trect->y1));
@ -1095,7 +1100,7 @@ open_file(char* path, char* password)
void open_uri(char* uri) void open_uri(char* uri)
{ {
char* uri_cmd = g_strdup_printf(URI_COMMAND, uri); char* uri_cmd = g_strdup_printf(uri_command, uri);
system(uri_cmd); system(uri_cmd);
g_free(uri_cmd); g_free(uri_cmd);
} }
@ -1670,13 +1675,13 @@ sc_scroll(Argument* argument)
else if(argument->n == HALF_DOWN) else if(argument->n == HALF_DOWN)
gtk_adjustment_set_value(adjustment, (value + (view_size / 2)) > max ? max : (value + (view_size / 2))); gtk_adjustment_set_value(adjustment, (value + (view_size / 2)) > max ? max : (value + (view_size / 2)));
else if((argument->n == LEFT) || (argument->n == UP)) else if((argument->n == LEFT) || (argument->n == UP))
gtk_adjustment_set_value(adjustment, (value - SCROLL_STEP) < 0 ? 0 : (value - SCROLL_STEP)); gtk_adjustment_set_value(adjustment, (value - scroll_step) < 0 ? 0 : (value - scroll_step));
else if(argument->n == TOP) else if(argument->n == TOP)
gtk_adjustment_set_value(adjustment, 0); gtk_adjustment_set_value(adjustment, 0);
else if(argument->n == BOTTOM) else if(argument->n == BOTTOM)
gtk_adjustment_set_value(adjustment, max); gtk_adjustment_set_value(adjustment, max);
else else
gtk_adjustment_set_value(adjustment, (value + SCROLL_STEP) > max ? max : (value + SCROLL_STEP)); gtk_adjustment_set_value(adjustment, (value + scroll_step) > max ? max : (value + scroll_step));
update_status(); update_status();
} }
@ -2398,7 +2403,7 @@ cmd_close(int argc, char** argv)
gtk_window_set_title(Zathura.UI.window, "zathura"); gtk_window_set_title(Zathura.UI.window, "zathura");
Zathura.State.pages = g_strdup_printf(""); Zathura.State.pages = g_strdup_printf("");
Zathura.State.filename = (char*) DEFAULT_TEXT; Zathura.State.filename = (char*) default_text;
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
Zathura.PDF.document = NULL; Zathura.PDF.document = NULL;
@ -2709,11 +2714,11 @@ cmd_print(int argc, char** argv)
char* printer = argv[0]; char* printer = argv[0];
char* sites = (argc == 2) ? g_strdup(argv[1]) : g_strdup_printf("1-%i", Zathura.PDF.number_of_pages); char* sites = (argc == 2) ? g_strdup(argv[1]) : g_strdup_printf("1-%i", Zathura.PDF.number_of_pages);
char* print_command = g_strdup_printf(PRINT_COMMAND, printer, sites, Zathura.PDF.file); char* command = g_strdup_printf(print_command, printer, sites, Zathura.PDF.file);
system(print_command); system(command);
g_free(sites); g_free(sites);
g_free(print_command); g_free(command);
return TRUE; return TRUE;
} }
@ -2758,6 +2763,15 @@ cmd_set(int argc, char** argv)
if(argv[1]) if(argv[1])
*x = atoi(argv[1]); *x = atoi(argv[1]);
} }
else if(settings[i].type == 'f')
{
if(argc != 2)
return FALSE;
float *x = (float*) (settings[i].variable);
if(argv[1])
*x = atof(argv[1]);
}
else if(settings[i].type == 's') else if(settings[i].type == 's')
{ {
if(argc < 2) if(argc < 2)
@ -2789,7 +2803,7 @@ cmd_set(int argc, char** argv)
/* re-init */ /* re-init */
if(settings[i].reinit) if(settings[i].reinit)
init_colors(); init_look();
/* render */ /* render */
if(settings[i].render) if(settings[i].render)
@ -3009,7 +3023,7 @@ cc_print(char* input)
int count = 0; int count = 0;
FILE *fp; FILE *fp;
fp = popen(LIST_PRINTER_COMMAND, "r"); fp = popen(list_printer_command, "r");
if(!fp) if(!fp)
{ {
@ -3160,17 +3174,17 @@ bcmd_zoom(char* buffer, Argument* argument)
if(argument->n == ZOOM_IN) if(argument->n == ZOOM_IN)
{ {
if((Zathura.PDF.scale + ZOOM_STEP) <= ZOOM_MAX) if((Zathura.PDF.scale + zoom_step) <= zoom_max)
Zathura.PDF.scale += ZOOM_STEP; Zathura.PDF.scale += zoom_step;
else else
Zathura.PDF.scale = ZOOM_MAX; Zathura.PDF.scale = zoom_max;
} }
else if(argument->n == ZOOM_OUT) else if(argument->n == ZOOM_OUT)
{ {
if((Zathura.PDF.scale - ZOOM_STEP) >= ZOOM_MIN) if((Zathura.PDF.scale - zoom_step) >= zoom_min)
Zathura.PDF.scale -= ZOOM_STEP; Zathura.PDF.scale -= zoom_step;
else else
Zathura.PDF.scale = ZOOM_MIN; Zathura.PDF.scale = zoom_min;
} }
else if(argument->n == ZOOM_SPECIFIC) else if(argument->n == ZOOM_SPECIFIC)
{ {
@ -3179,10 +3193,10 @@ bcmd_zoom(char* buffer, Argument* argument)
return; return;
int value = atoi(g_strndup(buffer, b_length - 1)); int value = atoi(g_strndup(buffer, b_length - 1));
if(value <= ZOOM_MIN) if(value <= zoom_min)
Zathura.PDF.scale = ZOOM_MIN; Zathura.PDF.scale = zoom_min;
else if(value >= ZOOM_MAX) else if(value >= zoom_max)
Zathura.PDF.scale = ZOOM_MAX; Zathura.PDF.scale = zoom_max;
else else
Zathura.PDF.scale = value; Zathura.PDF.scale = value;
} }
@ -3610,7 +3624,7 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
/* draw selection rectangle */ /* draw selection rectangle */
cairo = cairo_create(Zathura.PDF.surface); cairo = cairo_create(Zathura.PDF.surface);
cairo_set_source_rgba(cairo, Zathura.Style.select_text.red, Zathura.Style.select_text.green, cairo_set_source_rgba(cairo, Zathura.Style.select_text.red, Zathura.Style.select_text.green,
Zathura.Style.select_text.blue, TRANSPARENCY); Zathura.Style.select_text.blue, transparency);
cairo_rectangle(cairo, rectangle.x1 - offset_x, rectangle.y1 - offset_y, cairo_rectangle(cairo, rectangle.x1 - offset_x, rectangle.y1 - offset_y,
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1)); (rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
cairo_fill(cairo); cairo_fill(cairo);
@ -3735,7 +3749,8 @@ int main(int argc, char* argv[])
init_zathura(); init_zathura();
read_configuration(); read_configuration();
init_colors(); init_settings();
init_look();
init_directories(); init_directories();
if(argc >= 2) if(argc >= 2)