Commit d1ee4e06 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Updated interface from zjui project

The whole project files have been replaced by the first version
of zjui, a side project for the user interface. Additionally there
has been an update of the Makefile and the configuration.

Mentionable features:
  * Buffered commands
  * Statusbar
  * Advanced completion
  * Notification system
  * Modes and mode-depending shortcuts
parent 58dcfb00
Copyright (c) 2009 ML, JY
Copyright (c) 2009 ML, JY - pwmt.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
......@@ -8,14 +8,13 @@ Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
LIBS = gtk+-2.0 poppler poppler-glib
FLAGS = `pkg-config --cflags --libs $(LIBS)`
SOURCE = zathura.c
TARGET = zathura
# See LICENSE file for license and copyright information
# zathura - user interface
all: $(TARGET)
include config.mk
$(TARGET): zathura.c config.h
gcc $(FLAGS) -Wall -o $(TARGET) $(SOURCE)
PROJECT = zathura
SOURCE = zathura.c
OBJECTS = ${SOURCE:.c=.o}
DOBJECTS = ${SOURCE:.c=.do}
all: options ${PROJECT}
options:
@echo ${PROJECT} buld options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "DFLAGS = ${DFLAGS}"
@echo "CC = ${CC}"
%.o: %.c
@echo CC $<
@${CC} -c ${CFLAGS} -o $@ $<
%.do: %.c
@echo CC $<
@${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $<
${OBJECTS}: config.h config.mk
${DOBJECTS}: config.h config.mk
config.h:
@cp config.def.h $@
${PROJECT}: ${OBJECTS}
@echo CC -o $@
@${CC} -o $@ ${OBJECTS} ${LDFLAGS}
clean:
rm -f $(TARGET)
@rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
${DOBJECTS} ${PROJECT}-debug
${PROJECT}-debug: ${DOBJECTS}
@echo CC -o ${PROJECT}-debug
@${CC} -o ${PROJECT}-debug ${DOBJECTS} ${LDFLAGS}
debug:
gcc $(FLAGS) -Wall -o $(TARGET) $(SOURCE) -g
debug: ${PROJECT}-debug
valgrind: debug
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./${TARGET}
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \
./${PROJECT}-debug
gdb: debug
cgdb ${PROJECT}-debug
dist: clean
@mkdir -p ${PROJECT}-${VERSION}
@cp -R LICENSE Makefile config.mk config.def.h README \
${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION}
@tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION}
@gzip ${PROJECT}-${VERSION}.tar
@rm -rf ${PROJECT}-${VERSION}
install: all
@echo installing executeable to /usr/bin
@mkdir -p /usr/bin
@cp -f ${TARGET} /usr/bin
@chmod 755 /usr/bin/${TARGET}
@echo installing executeable file
@mkdir -p ${PREFIX}/bin
@cp -f ${PROJECT} ${PREFIX}/bin
@chmod 755 ${PROJECT} ${PREFIX}/bin/${PROJECT}
@echo installing manual page
@mkdir -p ${MANPREFIX}/man1
@sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${MANPREFIX}/man1/${PROJECT}.1
@chmod 644 ${MANPREFIX}/man1/${PROJECT}.1
uninstall:
@echo removing executeable from /usr/bin
@rm -f /usr/bin/${TARGET}
@echo removing executeable file
@rm -f ${MANPREFIX}/bin/${PROJECT}
@echo removing manual page
@rm -f ${MANPREFIX}/man1/${PROJECT}.1
/* settings */
static const int DEFAULT_WIDTH = 800;
static const int DEFAULT_HEIGHT = 600;
/* completion */
static const char FORMAT_COMMAND[] = "<b>%s</b>";
static const char FORMAT_DESCRIPTION[] = "<i>%s</i>";
/* look */
static const char font[] = "monospace normal 9";
static const char default_bgcolor[] = "#000000";
static const char default_fgcolor[] = "#DDDDDD";
static const char inputbar_bgcolor[] = "#141414";
static const char inputbar_fgcolor[] = "#9FBC00";
static const char statusbar_bgcolor[] = "#000000";
static const char statusbar_fgcolor[] = "#FFFFFF";
static const char completion_fgcolor[] = "#DDDDDD";
static const char completion_bgcolor[] = "#232323";
static const char completion_g_fgcolor[] = "#DEDEDE";
static const char completion_g_bgcolor[] = "#FF00FF";
static const char completion_hl_fgcolor[] = "#232323";
static const char completion_hl_bgcolor[] = "#9FBC00";
static const char notification_e_bgcolor[] = "#FF1212";
static const char notification_e_fgcolor[] = "#FFFFFF";
static const char notification_w_bgcolor[] = "#FFF712";
static const char notification_w_fgcolor[] = "#000000";
/* shortcuts */
Shortcut shortcuts[] = {
/* mask, key, function, mode, argument */
{0, GDK_i, sc_change_mode, NORMAL, { INSERT } },
{0, GDK_v, sc_change_mode, NORMAL, { VISUAL } },
{GDK_CONTROL_MASK, GDK_q, sc_quit, -1, {0} },
{GDK_SHIFT_MASK, GDK_slash, sc_focus_inputbar, -1, { .data = "/" } },
{GDK_SHIFT_MASK, GDK_question, sc_focus_inputbar, -1, { .data = "?" } },
{0, GDK_colon, sc_focus_inputbar, -1, { .data = ":" } },
{0, GDK_Escape, sc_abort, -1, {0} },
};
/* inputbar shortcuts */
InputbarShortcut inputbar_shortcuts[] = {
/* mask, key, function, argument */
{0, GDK_Escape, isc_abort, {0} },
{0, GDK_Up, isc_command_history, {0} },
{0, GDK_Down, isc_command_history, {0} },
{0, GDK_Tab, isc_completion, { NEXT } },
{GDK_CONTROL_MASK, GDK_Tab, isc_completion, { NEXT_GROUP } },
{0, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS } },
{GDK_CONTROL_MASK, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS_GROUP } },
{GDK_CONTROL_MASK, GDK_w, isc_string_manipulation, { DELETE_LAST_WORD } },
};
/* commands */
Command commands[] = {
/* command, abbreviation, function, completion, description */
{"open", "o", cmd_quit, cc_open, "Open a file" },
{"quit", "q", cmd_quit, 0, "Quit zjui" },
};
/* buffer commands */
BufferCommand buffer_commands[] = {
/* regex, function, argument */
{"^gg$", bcmd_goto, { TOP } },
{"^[0-9]+G$", bcmd_goto, {0} },
};
/* special commands */
SpecialCommand special_commands[] = {
/* identifier, function, a, argument */
{'/', scmd_search, 1, { DOWN } },
{'?', scmd_search, 1, { UP } },
};
/* settings */
static const float ZOOM_STEP = 0.1;
static const float SCROLL_STEP = 40;
static const float HL_TRANSPARENCY = 0.4;
static const int SHOW_NOTIFICATION = 5;
static const int DEFAULT_WIDTH = 800;
static const int DEFAULT_HEIGHT = 600;
static const int MIN_INDEX_WIDTH = 200;
static const char BROWSER[] = "firefox %s";
static const char *PRINTER[] = { "PRINTER_1",
"PRINTER_2",
"PRINTER_3"
};
/* look */
static const char font[] = "monospace normal 9";
static const char default_bgcolor[] = "#000000";
static const char default_fgcolor[] = "#DDDDDD";
static const char notification_fgcolor[] = "#0F0F0F";
static const char notification_bgcolor[] = "#F9F9F9";
static const char notification_warning_fgcolor[] = "DDDDDDC";
static const char notification_warning_bgcolor[] = "#D0C54D";
static const char notification_error_fgcolor[] = "#FFFFFF";
static const char notification_error_bgcolor[] = "#BC2800";
static const char inputbar_bgcolor[] = "#141414";
static const char inputbar_fgcolor[] = "#9FBC00";
static const char completion_fgcolor[] = "#DDDDDD";
static const char completion_bgcolor[] = "#232323";
static const char completion_hl_fgcolor[] = "#232323";
static const char completion_hl_bgcolor[] = "#9FBC00";
static const char search_highlight[] = "#9FBC00";
/* additional settings */
#define SHOW_SCROLLBARS 0
#define INCREMENTAL_SEARCH 0
/* shortcuts */
Shortcut shortcuts[] = {
// mask, key, function, argument
{GDK_CONTROL_MASK, GDK_f, sc_navigate, { NEXT } },
{GDK_CONTROL_MASK, GDK_b, sc_navigate, { PREVIOUS } },
{GDK_CONTROL_MASK, GDK_plus, sc_zoom, { ZOOM_IN } },
{GDK_CONTROL_MASK, GDK_minus, sc_zoom, { ZOOM_OUT } },
{GDK_CONTROL_MASK, GDK_0, sc_zoom, { ZOOM_ORIGINAL } },
{GDK_CONTROL_MASK, GDK_r, sc_rotate, { RIGHT } },
{GDK_CONTROL_MASK, GDK_e, sc_rotate, { LEFT } },
{GDK_CONTROL_MASK, GDK_p, sc_focus_inputbar, { .data = ":print all" } },
{GDK_CONTROL_MASK, GDK_q, sc_quit, {0} },
{GDK_CONTROL_MASK, GDK_i, sc_toggle_index, {0} },
{GDK_CONTROL_MASK, GDK_m, sc_toggle_inputbar, {0} },
{0, GDK_n, sc_search, { FORWARD } },
{0, GDK_N, sc_search, { BACKWARD } },
{0, GDK_h, sc_scroll, { LEFT } },
{0, GDK_j, sc_scroll, { UP } },
{0, GDK_k, sc_scroll, { DOWN } },
{0, GDK_l, sc_scroll, { RIGHT } },
{0, GDK_Page_Up, sc_scroll, { TOP } },
{0, GDK_Page_Down, sc_scroll, { BOTTOM } },
{0, GDK_i, sc_adjust_window, { ADJUST_BESTFIT } },
{0, GDK_u, sc_adjust_window, { ADJUST_WIDTH } },
{0, GDK_colon, sc_focus_inputbar, { .data = ":" } },
{0, GDK_o, sc_focus_inputbar, { .data = ":open " } },
{0, GDK_r, sc_focus_inputbar, { .data = ":rotate " } },
{0, GDK_z, sc_focus_inputbar, { .data = ":zoom " } },
{0, GDK_g, sc_focus_inputbar, { .data = ":goto " } },
{0, GDK_slash, sc_focus_inputbar, { .data = "/" } },
{0, GDK_Up, sc_focus_inputbar, {0} },
{0, GDK_Down, sc_focus_inputbar, {0} },
};
/* commands */
Command commands[] = {
// command, function
{"export", cmd_export},
{"e", cmd_export},
{"form", cmd_form},
{"f", cmd_form},
{"goto", cmd_goto},
{"g", cmd_goto},
{"info", cmd_info},
{"i", cmd_info},
{"links", cmd_links},
{"l", cmd_links},
{"open", cmd_open},
{"o", cmd_open},
{"print", cmd_print},
{"p", cmd_print},
{"rotate", cmd_rotate},
{"r", cmd_rotate},
{"save", cmd_save},
{"s", cmd_save},
{"quit", cmd_quit},
{"q", cmd_quit},
{"zoom", cmd_zoom},
{"z", cmd_zoom},
};
# See LICENSE file for license and copyright information
# zathura make config
VERSION = 0.0.1
# paths
PREFIX = /usr
MANPREFIX = ${PREFIX}/share/man
# libs
GTK_INC = $(shell pkg-config --cflags gtk+-2.0)
GTK_LIB = $(shell pkg-config --libs gtk+-2.0)
INCS = -I. -I/usr/include ${GTK_INC}
LIBS = -L/usr/lib -lc ${GTK_LIB}
# flags
CFLAGS = -std=c99 -pedantic -Wall $(INCS)
LDFLAGS = ${LIBS}
# debug
DFLAGS = -g
# compiler
CC = gcc
/* See LICENSE file for license and copyright information */
#include <regex.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <poppler/glib/poppler.h>
#include <cairo.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
......@@ -12,56 +11,90 @@
#define LENGTH(x) sizeof(x)/sizeof((x)[0])
/* enums */
enum { UP, DOWN, LEFT, RIGHT, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL,
NEXT, PREVIOUS, HIDE, ERROR, WARNING, DEFAULT, TOP, BOTTOM,
ADJUST_BESTFIT, ADJUST_WIDTH, FORWARD, BACKWARD };
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN,
BOTTOM, TOP, HIDE, NORMAL, HIGHLIGHT,
INSERT, VISUAL, DELETE_LAST_WORD, DEFAULT,
ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP };
/* zathura */
struct
{
GtkWindow *window;
GtkBox *vbox;
GtkBox *hbox;
GtkScrolledWindow *view;
GtkWidget *drawing_area;
GtkBox *notification;
GtkEntry *inputbar;
GList *history;
GtkWidget *index;
struct
{
GtkWindow *window;
GtkBox *box;
GtkScrolledWindow *view;
GtkWidget *statusbar;
GtkBox *statusbar_entries;
GtkEntry *inputbar;
} UI;
struct
{
GdkColor default_fg;
GdkColor default_bg;
GdkColor inputbar_fg;
GdkColor inputbar_bg;
GdkColor notification_fg;
GdkColor notification_bg;
GdkColor notification_wn_fg;
GdkColor notification_wn_bg;
GdkColor notification_er_fg;
GdkColor notification_er_bg;
GdkColor completion_fg;
GdkColor completion_bg;
GdkColor completion_hl_fg;
GdkColor completion_hl_bg;
GdkColor search_highlight;
GdkColor default_fg;
GdkColor default_bg;
GdkColor inputbar_fg;
GdkColor inputbar_bg;
GdkColor statusbar_fg;
GdkColor statusbar_bg;
GdkColor completion_fg;
GdkColor completion_bg;
GdkColor completion_g_bg;
GdkColor completion_g_fg;
GdkColor completion_hl_fg;
GdkColor completion_hl_bg;
GdkColor notification_e_fg;
GdkColor notification_e_bg;
GdkColor notification_w_fg;
GdkColor notification_w_bg;
PangoFontDescription *font;
} Settings;
} Style;
struct
{
PopplerDocument *document;
PopplerPage *page;
char *file;
cairo_surface_t *surface;
int page_number;
int number_of_pages;
double scale;
int rotate;
} PDF;
GString *buffer;
GList *history;
int mode;
GtkLabel *status_text;
GtkLabel *status_buffer;
GtkLabel *status_state;
} Global;
} Zathura;
/* typedefs */
struct CElement
{
char *value;
char *description;
struct CElement *next;
};
typedef struct CElement CompletionElement;
struct CGroup
{
char *value;
CompletionElement *elements;
struct CGroup *next;
};
typedef struct CGroup CompletionGroup;
typedef struct
{
CompletionGroup* groups;
} Completion;
typedef struct
{
char* command;
char* description;
int command_id;
gboolean is_group;
GtkWidget* row;
} CompletionRow;
typedef struct
{
int n;
......@@ -73,1563 +106,899 @@ typedef struct
int mask;
int key;
void (*function)(Argument*);
int mode;
Argument argument;
} Shortcut;
typedef struct
{
char *command;
int mask;
int key;
void (*function)(Argument*);
Argument argument;
} InputbarShortcut;
typedef struct
{
char* command;
char* abbr;
void (*function)(int, char**);
Completion* (*completion)(char*);
char* description;
} Command;
typedef struct
{
char* regex;
void (*function)(char*, Argument*);
Argument argument;
} BufferCommand;
typedef struct
{
char identifier;
void (*function)(char*, Argument*);
int always;
Argument argument;
} SpecialCommand;
/* function declarations */
void init();
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
void history(int);
void update_title();
void update_status();
void set_page(int);
void draw();
void highlight_result(PopplerRectangle*);
void open_link(char*);
void save_images(int, char*);
void save_attachments(char*);
gboolean complete(Argument*);
gboolean delete_widget(gpointer);
GtkWidget* notify(int, char*);
GtkWidget* update_notification(GtkWidget*, int, char*);
PopplerRectangle* recalcRectangle(PopplerRectangle*);
void init_zathura();
void change_mode(int);
void notify(int, char*);
void update_status(char*, char*);
void setCompletionRowColor(GtkBox*, int, int);
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
/* shortcut declarations */
void sc_abort(Argument*);
void sc_change_mode(Argument*);
void sc_focus_inputbar(Argument*);
void sc_scroll(Argument*);
void sc_navigate(Argument*);
void sc_zoom(Argument*);
void sc_adjust_window(Argument*);
void sc_rotate(Argument*);
void sc_search(Argument*);
void sc_toggle_index(Argument*);
void sc_toggle_inputbar(Argument*);
void sc_quit(Argument*);
/* inputbar shortcut declarations */
void isc_abort(Argument*);
void isc_command_history(Argument*);
void isc_completion(Argument*);
void isc_string_manipulation(Argument*);
/* command declarations */
void cmd_export(int, char**);
void cmd_form(int, char**);
void cmd_goto(int, char**);
void cmd_info(int, char**);
void cmd_links(int, char**);
void cmd_open(int, char**);
void cmd_print(int, char**);
void cmd_rotate(int, char**);
void cmd_save(int, char**);
void cmd_quit(int, char**);
void cmd_zoom(int, char**);
/* callbacks declarations */
void cb_draw(GtkWidget*, gpointer);
void cb_destroy(GtkWidget*, gpointer);
void cb_inputbar_activate(GtkEntry*, gpointer);
void cb_inputbar_button_pressed(GtkWidget*, GdkEventButton*, gpointer);
void cb_drawing_area_button_pressed(GtkWidget*, GdkEventButton*, gpointer);
void cb_index_selection_changed(GtkTreeSelection*, GtkWidget*);
/* completion commands */
Completion* cc_open(char*);
/* buffer command declarations */
void bcmd_goto(char*, Argument*);
gboolean cb_label_open_link(GtkLabel*, gchar*, gpointer);
gboolean cb_inputbar_key_pressed(GtkEntry*, GdkEventKey*, gpointer);
gboolean cb_inputbar_key_released(GtkEntry*, GdkEventKey*, gpointer);
gboolean cb_view_key_pressed(GtkWidget*, GdkEventKey*, gpointer);
/* special command delcarations */
void scmd_search(char*, Argument*);
/* callback declarations */
gboolean cb_destroy(GtkWidget*, gpointer);
gboolean cb_view_kb_pressed(GtkWidget*, GdkEventKey*, gpointer);
gboolean cb_inputbar_kb_pressed(GtkWidget*, GdkEventKey*, gpointer);
gboolean cb_inputbar_activate(GtkEntry*, gpointer);
/* configuration */
#include "config.h"
/* function implementations */
/* function implementation */
void
init()
{
/* settings */
gdk_color_parse(default_fgcolor, &(Zathura.Settings.default_fg));
gdk_color_parse(default_bgcolor, &(Zathura.Settings.default_bg));
gdk_color_parse(inputbar_fgcolor, &(Zathura.Settings.inputbar_fg));
gdk_color_parse(inputbar_bgcolor, &(Zathura.Settings.inputbar_bg));
gdk_color_parse(notification_fgcolor, &(Zathura.Settings.notification_fg));
gdk_color_parse(notification_bgcolor, &(Zathura.Settings.notification_bg));
gdk_color_parse(notification_warning_fgcolor, &(Zathura.Settings.notification_wn_fg));
gdk_color_parse(notification_warning_bgcolor, &(Zathura.Settings.notification_wn_bg));
gdk_color_parse(notification_error_fgcolor, &(Zathura.Settings.notification_er_fg));
gdk_color_parse(notification_error_bgcolor, &(Zathura.Settings.notification_er_bg));
gdk_color_parse(completion_fgcolor, &(Zathura.Settings.completion_fg));
gdk_color_parse(completion_bgcolor, &(Zathura.Settings.completion_bg));
gdk_color_parse(completion_hl_fgcolor, &(Zathura.Settings.completion_hl_fg));
gdk_color_parse(completion_hl_bgcolor, &(Zathura.Settings.completion_hl_bg));
gdk_color_parse(search_highlight, &(Zathura.Settings.search_highlight));
Zathura.Settings.font = pango_font_description_from_string(font);
/* variables */
Zathura.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
Zathura.vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
Zathura.hbox = GTK_BOX(gtk_hbox_new(FALSE, 0));
Zathura.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
Zathura.drawing_area = gtk_drawing_area_new();
Zathura.notification = GTK_BOX(gtk_vbox_new(FALSE, 0));