diff --git a/config.def.h b/config.def.h index f2913e0..be2be7d 100644 --- a/config.def.h +++ b/config.def.h @@ -1,11 +1,11 @@ /* settings */ -static const int DEFAULT_WIDTH = 800; -static const int DEFAULT_HEIGHT = 600; -static const float ZOOM_STEP = 10; -static const float ZOOM_MIN = 10; -static const float ZOOM_MAX = 400; -static const float SCROLL_STEP = 40; -static const float TRANSPARENCY = 0.4; +int default_width = 800; +int default_height = 600; +float zoom_step = 10; +float zoom_min = 10; +float zoom_max = 400; +float scroll_step = 40; +float transparency = 0.4; /* completion */ static const char FORMAT_COMMAND[] = "%s"; @@ -45,19 +45,18 @@ char* search_highlight = "#9FBC00"; char* select_text = "#000000"; /* statusbar */ -static const char DEFAULT_TEXT[] = "[No Name]"; +char* default_text = "[No Name]"; /* printing */ -#define 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* list_printer_command = "lpstat -v | sed -n '/^.*device for \\(.*\\): .*$/s//\\1/p'"; +char* print_command = "lp -d '%s' -P %s '%s'"; /* printer / pages / file */ /* open uri */ -#define URI_COMMAND "firefox '%s'" /* uri */ +char* uri_command = "firefox '%s'"; /* uri */ /* additional settings */ -#define SHOW_SCROLLBARS 0 +gboolean show_scrollbars = FALSE; #define ADJUST_OPEN ADJUST_BESTFIT -#define RECOLOR_OPEN 0 #define SELECTION_STYLE POPPLER_SELECTION_GLYPH #define GOTO_MODE GOTO_LABELS /* GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET */ @@ -184,28 +183,41 @@ SpecialCommand special_commands[] = { /* settings */ Setting settings[] = { - /* name, variable, type, render, re-init, description */ - {"recolor", &(Zathura.Global.recolor), 'b', TRUE, FALSE, "Invert the image" }, - {"offset", &(Zathura.PDF.page_offset), 'i', FALSE, FALSE, "Optional page offset" }, - {"font", &(font), 's', FALSE, TRUE, "The used font" }, - {"default_bgcolor", &(default_bgcolor), 's', FALSE, TRUE, "Default background color"}, - {"default_fgcolor", &(default_fgcolor), 's', FALSE, TRUE, "Default foreground color"}, - {"inputbar_bgcolor", &(inputbar_bgcolor), 's', FALSE, TRUE, "Inputbar background color"}, - {"inputbar_fgcolor", &(inputbar_fgcolor), 's', FALSE, TRUE, "Inputbar foreground color"}, - {"statusbar_bgcolor", &(statusbar_bgcolor), 's', FALSE, TRUE, "Statusbar background color"}, - {"statusbar_fgcolor", &(statusbar_fgcolor), 's', FALSE, TRUE, "Statusbar foreground color"}, - {"completion_bgcolor", &(completion_bgcolor), 's', FALSE, TRUE, "Completion background color"}, - {"completion_fgcolor", &(completion_fgcolor), 's', FALSE, TRUE, "Completion foreground color"}, - {"completion_g_bgcolor", &(completion_g_bgcolor), 's', FALSE, TRUE, "Completion (group) background color"}, - {"completion_g_fgcolor", &(completion_g_fgcolor), 's', FALSE, TRUE, "Completion (group) foreground color"}, - {"completion_hl_bgcolor", &(completion_hl_bgcolor), 's', FALSE, TRUE, "Completion (highlight) background color"}, - {"completion_hl_fgcolor", &(completion_hl_fgcolor), 's', FALSE, TRUE, "Completion (highlight) foreground color"}, - {"notification_e_bgcolor", &(notification_e_bgcolor), 's', FALSE, TRUE, "Notification (error) background color"}, - {"notification_e_fgcolor", &(notification_e_fgcolor), 's', FALSE, TRUE, "Notification (error) foreground color"}, - {"notification_w_bgcolor", &(notification_w_bgcolor), 's', FALSE, TRUE, "Notification (warning) background color"}, - {"notification_w_fgcolor", &(notification_w_fgcolor), 's', FALSE, TRUE, "Notification (warning) foreground color"}, - {"recolor_darkcolor", &(recolor_darkcolor), 's', FALSE, TRUE, "Recoloring (dark color)"}, - {"recolor_lightcolor", &(recolor_lightcolor), 's', FALSE, TRUE, "Recoloring (light color)"}, - {"search_highlight", &(search_highlight), 's', FALSE, TRUE, "Highlighted results"}, - {"select_text", &(select_text), 's', FALSE, TRUE, "Rectangle of the selected text"}, + /* name, variable, type, render, re-init, description */ + {"browser", &(uri_command), 's', FALSE, FALSE, "Command to open URIs"}, + {"completion_bgcolor", &(completion_bgcolor), 's', FALSE, TRUE, "Completion background color"}, + {"completion_fgcolor", &(completion_fgcolor), 's', FALSE, TRUE, "Completion foreground color"}, + {"completion_g_bgcolor", &(completion_g_bgcolor), 's', FALSE, TRUE, "Completion (group) background color"}, + {"completion_g_fgcolor", &(completion_g_fgcolor), 's', FALSE, TRUE, "Completion (group) foreground color"}, + {"completion_hl_bgcolor", &(completion_hl_bgcolor), 's', FALSE, TRUE, "Completion (highlight) background color"}, + {"completion_hl_fgcolor", &(completion_hl_fgcolor), 's', FALSE, TRUE, "Completion (highlight) foreground color"}, + {"default_bgcolor", &(default_bgcolor), 's', FALSE, TRUE, "Default background color"}, + {"default_fgcolor", &(default_fgcolor), 's', FALSE, TRUE, "Default foreground color"}, + {"default_text", &(default_text), 's', FALSE, FALSE, "Default text"}, + {"font", &(font), 's', FALSE, TRUE, "The used font" }, + {"height", &(default_height), 'i', FALSE, FALSE, "Default window height"}, + {"inputbar_bgcolor", &(inputbar_bgcolor), 's', FALSE, TRUE, "Inputbar background color"}, + {"inputbar_fgcolor", &(inputbar_fgcolor), 's', FALSE, TRUE, "Inputbar foreground color"}, + {"labels", &(Zathura.Global.enable_labelmode), 'b', FALSE, TRUE, "Allow label mode"}, + {"list_printer_command", &(list_printer_command), 's', FALSE, FALSE, "Command to list printers"}, + {"notification_e_bgcolor", &(notification_e_bgcolor), 's', FALSE, TRUE, "Notification (error) background color"}, + {"notification_e_fgcolor", &(notification_e_fgcolor), 's', FALSE, TRUE, "Notification (error) foreground color"}, + {"notification_w_bgcolor", &(notification_w_bgcolor), 's', FALSE, TRUE, "Notification (warning) background color"}, + {"notification_w_fgcolor", &(notification_w_fgcolor), 's', FALSE, TRUE, "Notification (warning) foreground color"}, + {"offset", &(Zathura.PDF.page_offset), 'i', FALSE, FALSE, "Optional page offset" }, + {"print_command", &(print_command), 's', FALSE, FALSE, "Command to print"}, + {"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"}, }; diff --git a/zathura.c b/zathura.c index 286a3ad..a9391e8 100644 --- a/zathura.c +++ b/zathura.c @@ -285,8 +285,9 @@ struct } Zathura; /* function declarations */ -void init_colors(); +void init_look(); void init_directories(); +void init_settings(); void init_zathura(); void add_marker(int); void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*); @@ -390,7 +391,7 @@ gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointe /* function implementation */ void -init_colors() +init_look() { /* parse */ 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_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 @@ -468,6 +473,14 @@ init_directories() 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 init_zathura() { @@ -481,12 +494,11 @@ init_zathura() /* other */ Zathura.Global.mode = NORMAL; Zathura.Global.viewing_mode = NORMAL; - Zathura.Global.recolor = RECOLOR_OPEN; + Zathura.Global.recolor = 0; Zathura.Global.adjust_mode = ADJUST_OPEN; Zathura.Global.goto_mode = GOTO_MODE; Zathura.Global.show_index = FALSE; - Zathura.State.filename = (char*) DEFAULT_TEXT; Zathura.State.pages = g_strdup_printf(""); Zathura.State.scroll_percentage = 0; @@ -517,7 +529,6 @@ init_zathura() gtk_window_set_title(Zathura.UI.window, "zathura"); GdkGeometry hints = { 1, 1 }; 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); /* box */ @@ -544,12 +555,6 @@ init_zathura() gtk_container_add(GTK_CONTAINER(Zathura.UI.view), GTK_WIDGET(Zathura.UI.viewport)); 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 */ gtk_widget_show(Zathura.UI.drawing_area); 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); cairo_t *cairo = cairo_create(Zathura.PDF.surface); 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); 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) { - char* uri_cmd = g_strdup_printf(URI_COMMAND, uri); + char* uri_cmd = g_strdup_printf(uri_command, uri); system(uri_cmd); g_free(uri_cmd); } @@ -1670,13 +1675,13 @@ sc_scroll(Argument* argument) else if(argument->n == HALF_DOWN) gtk_adjustment_set_value(adjustment, (value + (view_size / 2)) > max ? max : (value + (view_size / 2))); 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) gtk_adjustment_set_value(adjustment, 0); else if(argument->n == BOTTOM) gtk_adjustment_set_value(adjustment, max); 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(); } @@ -2398,7 +2403,7 @@ cmd_close(int argc, char** argv) gtk_window_set_title(Zathura.UI.window, "zathura"); 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)); Zathura.PDF.document = NULL; @@ -2709,11 +2714,11 @@ cmd_print(int argc, char** argv) char* printer = argv[0]; 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); - system(print_command); + char* command = g_strdup_printf(print_command, printer, sites, Zathura.PDF.file); + system(command); g_free(sites); - g_free(print_command); + g_free(command); return TRUE; } @@ -2758,6 +2763,15 @@ cmd_set(int argc, char** argv) if(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') { if(argc < 2) @@ -2789,7 +2803,7 @@ cmd_set(int argc, char** argv) /* re-init */ if(settings[i].reinit) - init_colors(); + init_look(); /* render */ if(settings[i].render) @@ -3009,7 +3023,7 @@ cc_print(char* input) int count = 0; FILE *fp; - fp = popen(LIST_PRINTER_COMMAND, "r"); + fp = popen(list_printer_command, "r"); if(!fp) { @@ -3160,17 +3174,17 @@ bcmd_zoom(char* buffer, Argument* argument) if(argument->n == ZOOM_IN) { - if((Zathura.PDF.scale + ZOOM_STEP) <= ZOOM_MAX) - Zathura.PDF.scale += ZOOM_STEP; + if((Zathura.PDF.scale + zoom_step) <= zoom_max) + Zathura.PDF.scale += zoom_step; else - Zathura.PDF.scale = ZOOM_MAX; + Zathura.PDF.scale = zoom_max; } else if(argument->n == ZOOM_OUT) { - if((Zathura.PDF.scale - ZOOM_STEP) >= ZOOM_MIN) - Zathura.PDF.scale -= ZOOM_STEP; + if((Zathura.PDF.scale - zoom_step) >= zoom_min) + Zathura.PDF.scale -= zoom_step; else - Zathura.PDF.scale = ZOOM_MIN; + Zathura.PDF.scale = zoom_min; } else if(argument->n == ZOOM_SPECIFIC) { @@ -3179,10 +3193,10 @@ bcmd_zoom(char* buffer, Argument* argument) return; int value = atoi(g_strndup(buffer, b_length - 1)); - if(value <= ZOOM_MIN) - Zathura.PDF.scale = ZOOM_MIN; - else if(value >= ZOOM_MAX) - Zathura.PDF.scale = ZOOM_MAX; + if(value <= zoom_min) + Zathura.PDF.scale = zoom_min; + else if(value >= zoom_max) + Zathura.PDF.scale = zoom_max; else Zathura.PDF.scale = value; } @@ -3610,7 +3624,7 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data) /* draw selection rectangle */ cairo = cairo_create(Zathura.PDF.surface); 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, (rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1)); cairo_fill(cairo); @@ -3735,7 +3749,8 @@ int main(int argc, char* argv[]) init_zathura(); read_configuration(); - init_colors(); + init_settings(); + init_look(); init_directories(); if(argc >= 2)