================================================================
day1[7 oct] (~45 mins)
================================================================
-> Tried beginning from main.c but there is no main function 🥲
-> used grep -E "rotat" zathura/*.h:
rotat will include rotate and rotation both
files found were
* adjustment.h
* document.h
* database.h
* shortcuts.h
* utils.h
-> going through adjustment.h file
page height, width, position calculation funcitons found
-> trying to read in adjustment.c file
if rotate bool for calculation is true it does calculation based on result given by
" zathura_document_get_rotation " function in document.c
-> moving to document.h
found the rotation getter and setter functions for the document
noted that "ZATHURA_PLUGIN_API" is macro for "GIRARA_VISIBLE" defined in macro.h
tracking further meaning of macro took me to uncharted territories of girara
I did not sign up for this!
So rotation is tied with zathura_document_t object and document.h defines the changes possible
checking origins of zathura_document_t in types.h it is a typedef for zathura_document_s
zathura_document_s struct is defined in document.c
Why are _s and _t different ???
-> reading document.c
Now the "zathura_document_s" object has an unsigned int rotate attribute
all the get! set! rotate! seem to be good, but I think they will need page wise counter parts
-> reading database.h
There is struct called zathura_fileinfo_s with rotation attribute?
due to some reason database.c has nothing about rotation
-> reading shortcuts.h
function found "sc_rotate" that must do the rotation
will have to add similar one for pagewise?
-> going through utils.c
there is a rectangle rotation function that must do the magic
it uses something called a zathura_rectangle_t typedef for zathura_rectangle_s
why are _t and _s different ???
ok so the rectangle is just coordinates the opposite points
note that the function is used by recalc_rectangle declared in utils.h
observations to work on:
* what is zathura_fileinfo_s?
* try adding page wise getter setters for rotation
* add rotate function in shortcuts.h and .c
* use grep command on .c files
================================================================
day2[8 oct] (~2 hrs)
================================================================
-> I think I should first learn more about meson and ninja
A short youtube tutorial will do(Why can't people just use Makefile)
Wansn't much useful 😑, I'll just read the file line by line
-> The meson.build skirmish(biggest 1 hr time waste)
I just made a new log file for that(meson analysis) and understood line by line
Just putting LEFT tages for lines I dont get and so left them
Took me long but I think I understand meson better now
-> Running the grep on .c files
files to search
* adjustment.c(day1)
* config.c
* database-sqlite.c
* document.c(day1)
* links.c
* page-widget.c
* shortcuts.c
* synctex.c
* utils.c(day1)
* zathura.c
-> going for config.c
line 350 onwards tonnes of shortcuts are defined
so this is where key bindings happen, will have to add the alt R here
important to note that the shortcuts seem to be one key press, no multiple keys found
there is also a mapping added below in line 625 with some other meaning,
maybe maps action rotate to function, seems unecessary, will have to go through actual function usage
-> sqlite.c SKIP
I dont know about sqlite and will have to learn about it
-> links.c, just used in comments to mark racalculation of dimentions of link cell, document.c function used
observations to work on:
* what is zathura_fileinfo_s?
* try adding page wise getter setters for rotation
* add rotate function in shortcuts.h and .c
* add a shortcut in config.c
* look into girara shortcut adding functions in config.c
* learn about sqlite
* look into page-widget onward .c files for rotate
================================================================
day3[9 oct] (~1 hr)
================================================================
-> finding rotate in page-widget.c
zathura_page_widget_draw is definitely important for rotation
same is the case for rotate_point function but that is more of a util
cb_zathura_page_widget_button_press_event and cb_zathura_page_widget_motion_notify have something to do with it too
-> looking into shortcuts.c
The sc_rotate seems to be important function to rotate the doc however it rotates entire doc
will need a counterpart fr pagewise rotation.
-> syctex.c has not role in rotation as of now
-> zathura.c
this is where actual declarations happen, need to add for all pages?
maybe default newly rendered pages to file rotation
-> now that I have seen most points where rotate is useful, Lets try following important data elements in zathura.h
I just added ROTATE_CW_PG and ROTATE_CCW_PG in the enum in zathura.h, it did not break 🥳
page_number in girara_statusbar_item_t might be required, the statusbar struct in ui struct(I didnt knew we could define struct inside a struct)
zathura_s is the major object
important parts in line 181 zathura_document_t
rest are all functions in zathura.h
-> Entire doc is controlled by zathura_document_t so lets read about zathura_document_s
(now I know why they are different, kind of privatizing the zathura_document attributes to functions using _t)
VERY important it has current_page_number, and also the zathura_page_t** pages which holds the pages
-> looking into zathura_page_s
it seems to have a pointer to parent
added unsigned int rotate and everything works!
zathura_page_new() seems to be its constructor, trying to find it using grep
only used in document.c when opening, so this is the constructor
adding value of rotate to get from parent in zathura_page_new() and nothing broke
-> Now lets try adding getter setters for rotation in pages
easily copy pasted getter setters like width and height
interestingly there comes a design choice should rotate recalculate the width and height of page?
it seems adjustment.c takes care of calculation(page_calc_position()) the new height and width, I need to see who all uses it, grep again
weirdly only links.c uses it? so how is doc rotated? Need to check design choice in document
something to do with page_calc_position(), lets grep and see who uses it...and only links.c does
I though links.c handled hyprlinks and stuff does it do more?
-> found a function defined in "WITH_SANDBOX"
why didnt I find it before! It will make testing so much better
-> importantly document.c defines the document to have differrent cell dimentions and viewport dimensions
maybe same should be done with pages?
observations to work on:
* what is zathura_fileinfo_s?
* try adding page wise getter setters for rotation
* add rotate function in shortcuts.h and .c
* add a shortcut in config.c
* look into girara shortcut adding functions in config.c
* learn about sqlite
* default rotation of pages should be taken from file
* what exacltly does links.c do?
* should I add different view and fix cell dimensions in page?
imp to note:
* current_page_number is part of zathura_document_s struct
================================================================
day4[11 oct] (~45 mins)
================================================================
-> Today's most important step will be to get the debugger working
I think I will need help of some llm, lets see
It works !!! Thank you VScode, no ai needed.
-> back to links.c
page_calc_position() is not at all used in rotation or resizing debugger says so
hence adjustment.c function is used only by links.c
-> functions in adjustment.c
page_calc_height_width() is used by render.c, document.c and zathura.c this is important
* document.c uses it for getting cell size
* zathrua.c it is called for each and every page
wait wait wait there is actually a todo for page_calc_height_width() to handle page wise sizes
I think I must first work on this and then proceed
I'll just stash the old changes and pop them when I am back
-> page_calc_height_width() skirmish
adjustment.h file has its documentation
ok so zathura.c iterates over all pages calling it
so let's just pass the page to funciton so that it can help us when we add rotate
configured it in adjustment.h .c and zathura.c
compiler shouts at me for not updating funciton in other files 🥲
but I have no access to page in other parts of world like documment.c
let's try by giving document->pages[document->current_page_number]
this doesnt work in render.c I dont get what is going on here
Oh nvm there is a page there. yaaayyyyy!
What I feared seems to be true, adjustment.h does not have page functions included
However reluctant I am to change it but I add #include "page.h" to adjustment.h
It worksssss, yes it doessssss !!!!!!!
Hmm let's try getting a merge request here
-> Sent in the pull request, lets wait and see what happens
observations to work on:
* what is zathura_fileinfo_s?
* try adding page wise getter setters for rotation
* add rotate function in shortcuts.h and .c
* add a shortcut in config.c
* look into girara shortcut adding functions in config.c
* learn about sqlite
* default rotation of pages should be taken from file
* refactor page_calc_height_width function to use page rotation and not doc
imp to note:
* current_page_number is part of zathura_document_s struct
================================================================
day5[12 nov] (~15 mins)
================================================================
-> Endsems are going on so, just responding to a pr comment
-> My idea does not work
all pages are in max page size widget so returning actual size breaks scrolling logic
will have to fix either the scrolling logic(overkill for now)
or I will have to make all the widgets of max page size's max dim X max dim
closing the PR for now, will come back with other ideas after university exams are over
Thanks to jschild0 for the comment and help
================================================================
day6[2 dec] (~3.5 hrs)
================================================================
-> git pull seems to have broken something build commands fail
as suspected my Girara version is old, need to update
finally it works now
-> So I am working with the idea that rotate passed on to page_calc_height_width should be if that page is rotated
in that case we need to add a method to get rotation of page
zathura_document_get_rotation is defined in document.c
it returns document's rotate attribute
I remember these changes so just git stash pop
Now adjustment.c should use page rotation for page_calc_height_width
-> just wrote new function for page_rotate:
bool page_rotate(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int t) {
g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data;
g_return_val_if_fail(zathura->document != NULL, false);
const unsigned int page_number = zathura_document_get_current_page_number(zathura->document);
int angle = 90;
if (argument != NULL && argument->n == ROTATE_CCW) {
angle = 270;
}
/* update rotate value */
t = (t == 0) ? 1 : t;
zathura_page_t* current_page = zathura_document_get_page(zathura->document, page_number);
unsigned int rotation = zathura_page_get_rotation(current_page);
zathura_page_set_rotation(current_page, (rotation + angle * t) % 360);
/* update scale */
girara_argument_t new_argument = {.n = zathura_document_get_adjust_mode(zathura->document), .data = NULL};
sc_adjust_window(zathura->ui.session, &new_argument, NULL, 0);
/* render all pages again */
render_all(zathura);
page_set(zathura, page_number);
return false;
}
-> Need to find adding shortcut for it in config.c
Added a shortcut for keypad* to test
It broke and compilation fails need to traceback
Had to traceback completely, need to build recursively
Need to add changes section in logs
added page rotate finction in shortcut.c however adding it to header throws errors
nvm it was syntax error(semicolons :|)
ok all changes back, it compiles and staar causes page_rotate to be called(checked using gdb)
-> Now I need to look into normal rendering as state has been changed
so we need to look into updating scale, rendering all page or just one, page set can be left I guess
-> Updating scale: first observe how it happens in sc_rotate
the adjust mode of best-fit/width is kept in document, it is best if the function does not change here
we need to adust window as per mode, this takes us to sc_adjust_window followed by adjust view in zathura.c
all looks good here too, if render_all and refresh_view are properly adjusted, we should be good
-> Stepping into biggest chunk of render_all in render.
first add page.h to adjustment.h so that I can define a indiviual page_calc_height_width
dont want to break document rotation so need to add rotations
interestingly it compiles now that I use individual rotation
now rotation changes the dimensions but it seems the content is not rotated
looks like there must be an API function for that girara calls when r is pressed for rotation
that API function rotates ever page?
using gdb to see where code goes if I use normal rotation, after some calls in girara code goes into static lib of gtk and no update happens later
now I must find where gtk is told what to print(this must be related with extensions like pdf poppler)
-> digging deeper into render logic
documentation from render.h clearly says that render_all just marks all pages as not rendered, so there is a renderer that renders unrendered pages at end of a cycle
these lines are where it must happen:
gtk_widget_set_size_request(widget, page_width, page_height);
gtk_widget_queue_resize(widget);
they are gtk library functions, that take in a widget and I think add them to some draw queue, I just need to trace where gtk gets data to render
ahhh data must lie in page widget object, on to utils.c for zathura_page_get_widget
-> the widget skirmish:
hmm the widget is simply stored in an array of zathura object of pages
Now I must look at where all it is changed or initialized as it stores state of page
I got to know about find all references in VScode, such a useful thing to see where all it is accessed
accesses:
* zathura.c mostly accesses it at document close and open, I dont think will be useful
* utils.c the g_object_set seems to be of importance but is a part of glib which is in static lib, and I have no plan of analysing
interestingly c++ syntax has eliplses, I never knew that, lemme just try to understand this function from header
some internet surfing and I get that it sets "draw-search-results" flag of a widget
this function of document_draw_search_results is used only by soem search functions so not needed by me
* synctex.c uses it for some highlighting
* document-widget.c seems to put it in a gtk grid for rendering I think. That is how it should work, print lot of widgets on a global widget that is displayed on screen? seems like pygame
* callbacks.c this seems to be it, refresh view, it would be called every cycle if page is dirty
quite sure something here will be useful -- continue next day
-> looking at my logs AI suggested me to look for cairo rotate and I got zathura_page_widget_draw in page-widget.c
changing rotation in it to:
const unsigned int rotation = (zathura_document_get_rotation(document)+zathura_page_get_rotation(priv->page))%360;
made it work!!
there is some incosistancy in page spacing, though not sure
BUT IT WORKS
-> Just some apparant bugs:
* obviously the rotation of pages is not remembered for next session
* from random testing I got that if one page of a vertical long pdf is rotated and we scroll down there is some error
we can infinitely go right with each tick the page reset to position it was at
* looks like page fit mode and width mode have problems need more checking
DONE CHANGES:
* added rotation attribute and getter setter functions for page(both page.c and page.h)
* added page rotate finction in shortcut.c and header
* added ROTATE_CCW_PG and ROTATE_CW_PG in zathura.h enum
* added some lines in config.c all similar to normal rotate
* added the individual_page_calc_height_width
* added shortcut to test pagewise rotation and some other things copied as rotate
* added page rotation to cairo rotate
================================================================
day7[3 dec] (~2 hrs)
================================================================
-> first look in the page scroll logic that breaks, likely tthat size of page needs to be set max(max_haight, max_width)
looking at config.c scroll logic it is sc_scroll that does it
spending some time on gdb scrolling and looking in code, the doc_width changes only with full rotation but not individual
looking into what exactly is doc_width, it is scaled document cells size
I think during initialization if the cell height/width is set to max then it will be carried all the way
finding all references to cell width, the function zathura_document_set_cell_size is responsible
in zathura.c document_open sets the page size and document_open_page_max_size gives it the max of height and width
these two lines make it work 🥳:
*width = MAX(*width, *height);
*height = MAX(*height, *width);
this seems illegal, there should be a check based on if page is rotated, but that will take much more changes
-> there seem to be no problem with the mode adjustment, just that taking max size introduces some padding in horizontal direction,
wait, does rotation of all pages change these values, if yes I can do same in page_rotate
checking who all uses get rotation for zathura document
see who uses page_calc_height_width and if individual whould be better
looking on and on it seems doing something where only on rotation the file size changes will be painful
I think it is impossible to determine without iterating through the pages what width to use so setting max at initialization seems best
interesting observation is if I do rotate all then cell size seems to change to accomodate a rectangle and on indivial rotation then it goes back to being a square
then another single rotation to same page goes back to rectangle