mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-02-27 14:34:39 +01:00
Set page
This commit is contained in:
parent
2cfe3f86b8
commit
3d027dd773
3 changed files with 101 additions and 14 deletions
16
shortcuts.c
16
shortcuts.c
|
@ -72,6 +72,22 @@ sc_goto(girara_session_t* session, girara_argument_t* argument)
|
||||||
bool
|
bool
|
||||||
sc_navigate(girara_session_t* session, girara_argument_t* argument)
|
sc_navigate(girara_session_t* session, girara_argument_t* argument)
|
||||||
{
|
{
|
||||||
|
if(!session || !argument || !Zathura.document) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int number_of_pages = Zathura.document->number_of_pages;
|
||||||
|
unsigned int new_page = Zathura.document->current_page_number;
|
||||||
|
|
||||||
|
if(argument->n == NEXT) {
|
||||||
|
new_page = (new_page + 1) % number_of_pages;
|
||||||
|
}
|
||||||
|
else if(argument->n == PREVIOUS) {
|
||||||
|
new_page = (new_page + number_of_pages - 1) % number_of_pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
page_set(new_page);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
69
zathura.c
69
zathura.c
|
@ -51,6 +51,60 @@ init_zathura()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
document_open(const char* path, const char* password)
|
||||||
|
{
|
||||||
|
if(!path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_document_t* document = zathura_document_open(path, password);
|
||||||
|
|
||||||
|
if(!document) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Zathura.document = document;
|
||||||
|
|
||||||
|
if(!page_set(0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
document_close()
|
||||||
|
{
|
||||||
|
if(!Zathura.document) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_document_free(Zathura.document);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
page_set(unsigned int page_id)
|
||||||
|
{
|
||||||
|
if(!Zathura.document) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(page_id >= Zathura.document->number_of_pages) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Zathura.document->current_page_number = page_id;
|
||||||
|
|
||||||
|
char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, Zathura.document->number_of_pages);
|
||||||
|
girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.page_number, page_number);
|
||||||
|
g_free(page_number);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* main function */
|
/* main function */
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -64,21 +118,10 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc > 1) {
|
if(argc > 1) {
|
||||||
zathura_document_t* document = zathura_document_open(argv[1], NULL);
|
if(!document_open(argv[1], NULL)) {
|
||||||
|
printf("error: could not open document\n");
|
||||||
if(!document) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_page_t* page = zathura_page_get(document, 0);
|
|
||||||
|
|
||||||
if(!page) {
|
|
||||||
zathura_document_free(document);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
zathura_page_free(page);
|
|
||||||
zathura_document_free(document);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gdk_threads_enter();
|
gdk_threads_enter();
|
||||||
|
|
28
zathura.h
28
zathura.h
|
@ -6,6 +6,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <girara.h>
|
#include <girara.h>
|
||||||
|
|
||||||
|
#include "ft/document.h"
|
||||||
|
|
||||||
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
|
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
|
||||||
DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP,
|
DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP,
|
||||||
PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD,
|
PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD,
|
||||||
|
@ -34,6 +36,8 @@ struct
|
||||||
girara_statusbar_item_t* page_number; /**> page number statusbar entry */
|
girara_statusbar_item_t* page_number; /**> page number statusbar entry */
|
||||||
} statusbar;
|
} statusbar;
|
||||||
} UI;
|
} UI;
|
||||||
|
|
||||||
|
zathura_document_t* document; /**> The current document */
|
||||||
} Zathura;
|
} Zathura;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,4 +48,28 @@ struct
|
||||||
|
|
||||||
bool init_zathura();
|
bool init_zathura();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a file
|
||||||
|
*
|
||||||
|
* @param path The path to the file
|
||||||
|
* @param password The password of the file
|
||||||
|
*
|
||||||
|
* @return If no error occured true, otherwise false, is returned.
|
||||||
|
*/
|
||||||
|
bool document_open(const char* path, const char* password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the current opened document
|
||||||
|
*
|
||||||
|
* @return If no error occured true, otherwise false, is returned.
|
||||||
|
*/
|
||||||
|
bool document_close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the page with the given number
|
||||||
|
*
|
||||||
|
* @return If no error occured true, otherwise false, is returned.
|
||||||
|
*/
|
||||||
|
bool page_set(unsigned int page_id);
|
||||||
|
|
||||||
#endif // ZATHURA_H
|
#endif // ZATHURA_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue