You are not logged in.

#276 2010-06-12 04:42:21

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: zathura - a PDF viewer

wirr wrote:

yesterday i did some copy-pasting from surf.c.
With this patch i can embed zathura in tabbed:

http://pastebin.com/24gMNarT

Awesome, I love it. FYI I got a malformed patch error when I first ran it, had to change line 49 to '@@ -3647,16 +3654,30 @@'. It works well with the patch I posted above to change the window title to the filename.


I wrote a quick script using zenity to open new files from within tabbed, here it is for anybody interested.

#!/bin/bash

if [ $1 == '-e' ]; then
    shift
fi
WINID=$1

FILES=( $(zenity --file-selection --multiple --title="Open file" | tr ' ' '@' | tr '|' ' ') )

for FILE in "${FILES[@]//@/ }"; do
    if [ -e "$FILE" ]; then
        zathura -e $WINID "$FILE" &
    fi
done

You need to change tabbed's config.h to spawn this script instead of surf on C-S-Return. Works with multiple files and files with a space in the name (hence the name mangling with @).

Last edited by quigybo (2010-06-12 04:44:59)

Offline

#277 2010-06-12 09:06:11

jelly
Administrator
From: /dev/null
Registered: 2008-06-10
Posts: 714

Re: zathura - a PDF viewer

quigybo wrote:
wirr wrote:

yesterday i did some copy-pasting from surf.c.
With this patch i can embed zathura in tabbed:

http://pastebin.com/24gMNarT

Awesome, I love it. FYI I got a malformed patch error when I first ran it, had to change line 49 to '@@ -3647,16 +3654,30 @@'. It works well with the patch I posted above to change the window title to the filename.


I wrote a quick script using zenity to open new files from within tabbed, here it is for anybody interested.

#!/bin/bash

if [ $1 == '-e' ]; then
    shift
fi
WINID=$1

FILES=( $(zenity --file-selection --multiple --title="Open file" | tr ' ' '@' | tr '|' ' ') )

for FILE in "${FILES[@]//@/ }"; do
    if [ -e "$FILE" ]; then
        zathura -e $WINID "$FILE" &
    fi
done

You need to change tabbed's config.h to spawn this script instead of surf on C-S-Return. Works with multiple files and files with a space in the name (hence the name mangling with @).

Ok nice another feature that apvlv has too now in zathura big_smile

I though about another feature, when you press 'O'  when you have a PDF open, you get the open promt with the dir where your opened pdf is in.

So:   press 'o'   /home/jelle/Documents/PDF/linux.pdf
press 'O'   then you get  /home/jelle/Documents/PDF/
and then i can select my next pdf linux2.pdf for example

*jelly really needs to start hacking zathura in the summer!

Offline

#278 2010-06-12 10:44:53

escherdragon
Member
Registered: 2010-06-12
Posts: 8

Re: zathura - a PDF viewer

neldoreth wrote:
pedro-kun wrote:

Also, I make heavy use of pdf for slides and as such, I assigned j and k to navigation (the default is J and K). However, wouldn't it be possible for j an k (on scrolling behaviour) to navigate through pages when there is no more scrolling to be done?

Yes, I guess someone above wrote a patch for that. Anyway I wanted to implement a optional continious view.

Really? I looked around and couldn't find anything like that, so I wrote my own smile
Actually I've already sent this patch to mail@pwmt.org, but it seems noone is checking that box. It adds page-wise scrolling (using "b" for up and spc for down), with automatic navigation to the previous/next page on the borders. Moving to the previous page this way leaves you at the bottom of the page. This is actually the way I like most to read PDF docs, instead of continuous scrolling (which I tend to disallow anyway in other viewers).

At least until a proper continuous view is in place, I think this patch would make life easier for Army (#241), quigybo (#258, "concerns about having a separate key to move to the end of a page") and pedro-kun.

IMHO Zathura is already the best PDF viewer around, thanks for this great little piece of code ;-)

(apply with patch -p0 from the zathura compilation directory)

diff -Naur config.def.h config.def.h
--- config.def.h    2010-06-10 20:38:30.000000000 +0000
+++ config.def.h    2010-06-10 20:40:59.000000000 +0000
@@ -79,7 +79,8 @@
   {GDK_MOD1_MASK,      GDK_Right,         sc_navigate,          NORMAL,     { NEXT } },
   {GDK_MOD1_MASK,      GDK_Left,          sc_navigate,          NORMAL,     { PREVIOUS } },
   {0,                  GDK_O,             sc_switch_goto_mode,  NORMAL,     {0} },
-  {0,                  GDK_space,         sc_navigate,          NORMAL,     { NEXT } },
+  {0,                  GDK_b,             sc_scroll,            NORMAL,     { PREVIOUS } },
+  {0,                  GDK_space,         sc_scroll,            NORMAL,     { NEXT } },
   {0,                  GDK_Escape,        sc_abort,             -1,         {0} },
   {0,                  GDK_i,             sc_change_mode,       NORMAL,     { INSERT } },
   {0,                  GDK_v,             sc_change_mode,       NORMAL,     { VISUAL } },
diff -Naur zathura.c zathura.c
--- zathura.c    2010-06-10 20:38:30.000000000 +0000
+++ zathura.c    2010-06-10 20:11:50.000000000 +0000
@@ -1538,6 +1538,17 @@
 }
 
 void
+sc_scroll_navigate(Argument* argument)
+{
+  sc_navigate(argument);
+  if(argument->n == PREVIOUS) {
+    Argument argument;
+    argument.n = BOTTOM;
+    sc_scroll(&argument);
+  }
+}
+
+void
 sc_recolor(Argument* argument)
 {
   Zathura.Global.recolor = !Zathura.Global.recolor;
@@ -1596,6 +1607,7 @@
 
   gdouble view_size  = gtk_adjustment_get_page_size(adjustment);
   gdouble value      = gtk_adjustment_get_value(adjustment);
+  gdouble page       = gtk_adjustment_get_page_increment(adjustment);
   gdouble max        = gtk_adjustment_get_upper(adjustment) - view_size;
 
   if( (argument->n == LEFT) || (argument->n == UP))
@@ -1604,6 +1616,12 @@
     gtk_adjustment_set_value(adjustment, 0);
   else if(argument->n == BOTTOM)
     gtk_adjustment_set_value(adjustment, max);
+  else if( (argument->n == PREVIOUS && value == 0) || (argument->n == NEXT && value == max) )
+    sc_scroll_navigate(argument);
+  else if( (argument->n == PREVIOUS) && (value > 0) )
+    gtk_adjustment_set_value(adjustment, (value - page) < 0 ? 0 : (value - page));
+  else if( (argument->n == NEXT) && (value < max) )
+    gtk_adjustment_set_value(adjustment, (value + page) > max ? max : (value + page));
   else
     gtk_adjustment_set_value(adjustment, (value + SCROLL_STEP) > max ? max : (value + SCROLL_STEP));
 
@@ -3657,6 +3675,7 @@
   update_status();
 
   gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window));
+  gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar));
 
   gdk_threads_enter();
   gtk_main();

Last edited by escherdragon (2010-06-12 10:55:52)


José Alfredo Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)

Offline

#279 2010-06-13 14:37:30

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

Thanks for the patches - I changed the scroll behaviour now so that it navigates to the next/previous page when pressing up/down on the border of the page.

Best regards


pwmt.org : programs with movie titles

Offline

#280 2010-06-13 15:05:40

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: zathura - a PDF viewer

Very nice :-)

Offline

#281 2010-06-13 19:24:25

escherdragon
Member
Registered: 2010-06-12
Posts: 8

Re: zathura - a PDF viewer

neldoreth wrote:

Hello,

Thanks for the patches - I changed the scroll behaviour now so that it navigates to the next/previous page when pressing up/down on the border of the page.

Best regards

Cool. But wouldn't it be nice to have also the ability to scroll up and down by one whole viewport-length, and not only line by line? That's what I was talking about when I wrote "page-wise scrolling" (sorry if I didn't make myself clear enough before). Personally, when reading I definitely prefer to press just one key from time to time (and preferably the space bar) to jump to the next chunk of text instead of keep pressing jjjjjjjj, or the down arrow key to keep moving one line at a time (or is it just me?). Anyway, using gtk_adjustment_get_page_increment this is a breeze.

Cheers,

Last edited by escherdragon (2010-06-13 19:25:15)


José Alfredo Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)

Offline

#282 2010-06-13 23:19:00

escherdragon
Member
Registered: 2010-06-12
Posts: 8

Re: zathura - a PDF viewer

pedro-kun wrote:

Would it be possible to assign mouse buttons to navigation commands? left button for previous page, right button for next page.

I also wanted to have this in FULLSCREEN mode (F5), so I wrote it. Here's the patch against 0.0.6:

(apply with path -p0 from the compilation directory of zathura)

diff -Naur config.def.h config.def.h
--- config.def.h    2010-06-13 22:49:14.000000000 +0000
+++ config.def.h    2010-06-13 22:51:08.000000000 +0000
@@ -130,6 +130,13 @@
   {GDK_CONTROL_MASK,   GDK_w,             isc_string_manipulation,   { DELETE_LAST_WORD } },
 };
 
+/* mouse navigation */
+Shortcut mouse_shortcuts[] = {
+  /* mask, button, function,    mode,   argument */
+  {0,      1,      sc_navigate, FULLSCREEN, { NEXT } },
+  {0,      3,      sc_navigate, FULLSCREEN, { PREVIOUS } },
+};
+
 /* mouse settings */
 MouseScrollEvent mouse_scroll_events[] = {
   /* direction,      function,  argument */
diff -Naur zathura.c zathura.c
--- zathura.c    2010-06-13 22:49:14.000000000 +0000
+++ zathura.c    2010-06-13 22:51:31.000000000 +0000
@@ -3507,6 +3507,18 @@
   if(!Zathura.PDF.document)
     return FALSE;
 
+  int i;
+  for(i = 0; i < LENGTH(mouse_shortcuts); i++)
+  {
+    if (event->button == mouse_shortcuts[i].key &&
+      (((event->state & mouse_shortcuts[i].mask) == mouse_shortcuts[i].mask) || mouse_shortcuts[i].mask == 0)
+      && (Zathura.Global.mode == mouse_shortcuts[i].mode || mouse_shortcuts[i].mode == -1))
+    {
+      mouse_shortcuts[i].function(&(mouse_shortcuts[i].argument));
+      return TRUE;
+    }
+  }
+
   /* clean page */
   draw(Zathura.PDF.page_number);
   g_static_mutex_lock(&(Zathura.Lock.select_lock));

Only one caveat: you have to move manually the cursor to (0,0) before using the mouse buttons for navigation to avoid unintendedly selecting areas of the document -- I can live with that, though, at least until someone here comes out with a better solution ;-)

BTW. I have put together a fork of zathura in github with this and other small changes I've made: git://github.com/escherdragon/zathura.git

Cheers,


José Alfredo Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)

Offline

#283 2010-06-14 06:54:48

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: zathura - a PDF viewer

Wow, patches are coming in fast smile

Offline

#284 2010-06-14 07:29:26

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

escherdragon wrote:

But wouldn't it be nice to have also the ability to scroll up and down by one whole viewport-length, and not only line by line?

Yes, but that makes only sense (at least for me) when we have the ability of continious pages and not when it is only possible to show one page at a time, but I think I get now what you mean.

Best regards


pwmt.org : programs with movie titles

Offline

#285 2010-06-14 08:14:44

escherdragon
Member
Registered: 2010-06-12
Posts: 8

Re: zathura - a PDF viewer

neldoreth wrote:

Hello,

escherdragon wrote:

But wouldn't it be nice to have also the ability to scroll up and down by one whole viewport-length, and not only line by line?

Yes, but that makes only sense (at least for me) when we have the ability of continious pages and not when it is only possible to show one page at a time

And that's precisely the point! When reading on a laptop, I agree, I usually display the document in fullscreen, one whole page at a time rotated 90 degrees clockwise, just like I were reading a book (in those cases lightly tapping the touchpad to jump to the next page is wicked), but when reading on desktops, where the display is usually wider than taller and more often than not you can't rotate the screen, I mostly read only half-page at a time, so each logical "page" is one viewport high. In those cases, whether there is continuous page scrolling or not is not really important (I got used to disable continuous scrolling anyway, since in older viewers it used to take lots of resources for very little additional value).

Cheers,


José Alfredo Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)

Offline

#286 2010-06-14 11:09:26

wirr
Member
Registered: 2009-10-25
Posts: 70

Re: zathura - a PDF viewer

quigybo wrote:

I think I have found a bug in reloading a document, specifically if the document is damaged. If I open a healthy file in zathura, then damage/corrupt/delete the file in some way zathura tries to reload it (as it has changed) and gives an error "Can not open file: PDF document is damaged" in the status bar and "Error: Couldn't read xref table" etc on stderr. Although zathura still responds to some commands (ex commands etc) the viewing window is unresponsive and does not redraw. If I try to scroll now it crashes with "Floating point exception" on stderr. Even if I restore the file to its healthy state zathura will not reload it (automatically or manually). The only course of action is a restart. Ideally it should continue on with the document in memory, or at least remain responsive enough to reload the document once the version on disk has been restored.

In the function sc_reload change the line:

open_file(path, password)

to lol

while(!open_file(path, password))
{
        cmd_close(0,NULL);
}

This isn't proper errorhandling too, but if you make tex errors, you don't have to reload the pdf.

Last edited by wirr (2010-06-14 11:16:28)

Offline

#287 2010-06-14 14:31:41

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: zathura - a PDF viewer

neldoreth wrote:
escherdragon wrote:

But wouldn't it be nice to have also the ability to scroll up and down by one whole viewport-length, and not only line by line?

Yes, but that makes only sense (at least for me) when we have the ability of continious pages and not when it is only possible to show one page at a time, but I think I get now what you mean.

Best regards

I agree with escherdragon on this one, the ability to scroll a viewport or a half page at a time would be handy. When reading a document I am often zoomed in such that I only see half the page at a time, and it would be nice to be able to scroll to the next half (or the end of the page). I prefer single page over continuous view, but would still find this useful.



wirr wrote:

In the function sc_reload change the line:

open_file(path, password)

to lol

while(!open_file(path, password))
{
        cmd_close(0,NULL);
}

This isn't proper errorhandling too, but if you make tex errors, you don't have to reload the pdf.

To be perfectly honest I am not a fan of this fix (even as a temporary fix), as it continuously calls the open_file function until the pdf is repaired resulting in 100% CPU and blocks any further calls or keypresses to zathura. Ideally it should use inotify to wait for a change in the file (as zathura already does), and until that happens use the version of the document already loaded in memory.

Offline

#288 2010-06-14 15:19:43

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

quigybo wrote:

I agree with escherdragon on this one, the ability to scroll a viewport or a half page at a time would be handy.

Check the git repository.

Best regards


pwmt.org : programs with movie titles

Offline

#289 2010-06-14 19:03:36

wirr
Member
Registered: 2009-10-25
Posts: 70

Re: zathura - a PDF viewer

Did you try it? I do not see 100% CPU wink

without the while:

if(open_file(path, password))
{
    Zathura.PDF.scale  = scale;
    Zathura.PDF.rotate = rotate;

    draw(page);
}

Offline

#290 2010-06-15 03:57:31

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: zathura - a PDF viewer

@wirr: It doesn't really matter how you call open_file, once cmd_close is called the document is not in memory anymore. FYI cmd_close is also called in open_file, so even if you remove it from sc_reload it will still be called before the new file is opened. open_file needs to be restructured in order for this to work, there is no quick fix, especially not in sc_reload.

@neldoreth: thanks, works well, just what I was looking for.

Offline

#291 2010-06-15 07:48:30

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

quigybo wrote:

@wirr: It doesn't really matter how you call open_file, once cmd_close is called the document is not in memory anymore. FYI cmd_close is also called in open_file, so even if you remove it from sc_reload it will still be called before the new file is opened. open_file needs to be restructured in order for this to work, there is no quick fix, especially not in sc_reload.

I have commited a fix for this in the master branch. - For your information the poppler library does not read the whole pdf document into the memory. From this it follows that if the document is damaged zathura can not render any page of the previous version of the file. The new behaviour is now, that zathura does not close the whole document session, but still listens on any changes on the document. Now the pages occur blank etc, but I am thinking of >closing the document<, but having the GFileMonitor listening on any events in the background.

In addition may someone wants to try out the zathurarc branch, it should be now possible to define at least the font and all the colors with simple set commands in the ~/.zathura/zathurarc (default location). E.g.: "set font 22" or "set statusbar_bgcolor red". Maybe someone has time to test this a little bit.

Best regards


pwmt.org : programs with movie titles

Offline

#292 2010-06-15 08:18:48

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello again,

OK, I now changed the behaviour of the reload functionality: If zathura can not re-open the document, it closes the current session, but it still listens on events on the file to reopen it later on.

Best regards


pwmt.org : programs with movie titles

Offline

#293 2010-06-15 11:01:25

wirr
Member
Registered: 2009-10-25
Posts: 70

Re: zathura - a PDF viewer

Hi neldoreth,

thanks for fixing this correct.

Did anyone try poppler-0.14?

Offline

#294 2010-06-15 11:21:44

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

wirr wrote:

Did anyone try poppler-0.14?

Works fine with zathura.

Best regards


pwmt.org : programs with movie titles

Offline

#295 2010-06-15 17:30:17

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: zathura - a PDF viewer

I had a play with commit d5e2749c42, and at first thought that this was exactly what I was looking for, until I tried to change page sad. Now I see what you mean about how poppler works, not loading the entire document into memory. In hindsight this makes sense, as the document could be extremely large. Commit bf7fdad3be works fine for now, it is not ideal but at least zathura doesnt crash anymore smile. Considering how poppler works I'm not sure this funtionality can be improved on further. Thanks for looking into it though.

BTW the git version is looking good, nice to see that you have incorporated the scrolling and window title patches. Good work big_smile.

Offline

#296 2010-06-16 18:25:57

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

wirr wrote:

yesterday i did some copy-pasting from surf.c.
With this patch i can embed zathura in tabbed:

I patched zathura now to do that - Thanks.

Best regards


pwmt.org : programs with movie titles

Offline

#297 2010-06-16 22:56:26

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

In addition to the set function it is now also possible to map key bindings to shortcuts in the zathurarc file. You can also specify the argument and the mode:

* map g quit
* map g scroll up
* map g scroll down index

I merged it now into the master branch - I would be happy if some of you can test this!

Best regards


pwmt.org : programs with movie titles

Offline

#298 2010-06-17 23:04:26

escherdragon
Member
Registered: 2010-06-12
Posts: 8

Re: zathura - a PDF viewer

neldoreth wrote:

I merged it now into the master branch - I would be happy if some of you can test this!

I've found one small bug: if you add a few empty lines at the end of your zathurarc file and launch zathura, it will crash with a segmentation fault. The following patch fixes that:

--- zathura.c    2010-06-18 00:53:55.000000000 +0200
+++ zathura.c    2010-06-18 00:54:12.000000000 +0200
@@ -1321,6 +1321,8 @@
       int i;
       for(i = 0; i < n; i++)
       {
+        if(strlen(lines[i]) < 2)
+          continue;
         gchar **tokens = g_strsplit(lines[i], " ", -1);
         int     length = g_strv_length(tokens);

Besides that, seems to be working OK here smile

Cheers,


José Alfredo Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)

Offline

#299 2010-06-18 05:44:59

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: zathura - a PDF viewer

I have had a play with e34bd62d02 and so far I like it. Most of what I patch is just some colours and keybindings in config.h, so soon I will be able to do it all with zathurarc won't need to compile at all. Good work (as usual).

A few things that I'm sure you will get to eventually, but I cant seem to do right now is:

1. set ADJUST_OPEN to ADJUST_WIDTH

2. map special keys such as GDK_Next and GDK_Prior (PgUp and PgDn) or GDK_Left, GDK_Right (arrow keys) etc.

3. map keys to the zoom function.

Offline

#300 2010-06-18 11:04:38

neldoreth
Member
From: AT
Registered: 2009-02-01
Posts: 212

Re: zathura - a PDF viewer

Hello,

First of all I want to thank you for testing it and for the patch (escherdragon). All of the following should work with the latest git version:

quigybo wrote:

1. set ADJUST_OPEN to ADJUST_WIDTH

set adjust_open width
set adjust_open bestfit

Note: There has been no option to set adjust_open.

quigybo wrote:

2. map special keys such as GDK_Next and GDK_Prior (PgUp and PgDn) or GDK_Left, GDK_Right (arrow keys) etc.

map <Space> quit
map <C-<PageUp>> quit
map g quit
map <C-g> quit

Note: It was not possible to define special keys. This can be done now in the config.def.h (Maybe there is an better solution than hard code all of them?).

quigybo wrote:

3. map keys to the zoom function.

map g zoom in

Note: There has not been a shortcut (only a buffered command) for the zoom function.

Best regards


pwmt.org : programs with movie titles

Offline

Board footer

Powered by FluxBB