Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
8960b6e8
Commit
8960b6e8
authored
Apr 18, 2011
by
Moritz Lipp
Browse files
Updated zathura.h/zathura.c
parent
cfb2580b
Changes
3
Show whitespace changes
Inline
Side-by-side
callbacks.c
View file @
8960b6e8
...
...
@@ -12,14 +12,7 @@
gboolean
cb_destroy
(
GtkWidget
*
widget
,
gpointer
data
)
{
if
(
Zathura
.
UI
.
session
)
{
girara_session_destroy
(
Zathura
.
UI
.
session
);
}
document_close
();
/* free registered plugins */
zathura_document_plugins_free
();
zathura_free
(
data
);
return
TRUE
;
}
...
...
zathura.c
View file @
8960b6e8
...
...
@@ -12,59 +12,65 @@
#include "utils.h"
/* function implementation */
bool
init_
zathura
(
)
zathura_t
*
zathura
_init
(
int
argc
,
char
*
argv
[]
)
{
zathura_t
*
zathura
=
malloc
(
sizeof
(
zathura_t
));
if
(
zathura
==
NULL
)
{
return
NULL
;
}
/* UI */
if
(
!
(
Z
athura
.
UI
.
session
=
girara_session_create
()))
{
if
(
(
z
athura
->
ui
.
session
=
girara_session_create
())
==
NULL
)
{
goto
error_out
;
}
if
(
!
girara_session_init
(
Z
athura
.
UI
.
session
))
{
if
(
girara_session_init
(
z
athura
->
ui
.
session
)
==
false
)
{
goto
error_out
;
}
Z
athura
.
UI
.
statusbar
.
file
=
NULL
;
Z
athura
.
UI
.
statusbar
.
buffer
=
NULL
;
Z
athura
.
UI
.
statusbar
.
page_number
=
NULL
;
Z
athura
.
UI
.
page_view
=
NULL
;
Z
athura
.
UI
.
index
=
NULL
;
z
athura
->
ui
.
statusbar
.
file
=
NULL
;
z
athura
->
ui
.
statusbar
.
buffer
=
NULL
;
z
athura
->
ui
.
statusbar
.
page_number
=
NULL
;
z
athura
->
ui
.
page_view
=
NULL
;
z
athura
->
ui
.
index
=
NULL
;
/* page view */
Z
athura
.
UI
.
page_view
=
gtk_vbox_new
(
FALSE
,
0
);
if
(
!
Z
athura
.
UI
.
page_view
)
{
z
athura
->
ui
.
page_view
=
gtk_vbox_new
(
FALSE
,
0
);
if
(
!
z
athura
->
ui
.
page_view
)
{
goto
error_free
;
}
gtk_widget_show
(
Z
athura
.
UI
.
page_view
);
gtk_box_set_spacing
(
GTK_BOX
(
Z
athura
.
UI
.
page_view
),
0
);
gtk_widget_show
(
z
athura
->
ui
.
page_view
);
gtk_box_set_spacing
(
GTK_BOX
(
z
athura
->
ui
.
page_view
),
0
);
/* statusbar */
Z
athura
.
UI
.
statusbar
.
file
=
girara_statusbar_item_add
(
Z
athura
.
UI
.
session
,
TRUE
,
TRUE
,
TRUE
,
NULL
);
if
(
!
Z
athura
.
UI
.
statusbar
.
file
)
{
z
athura
->
ui
.
statusbar
.
file
=
girara_statusbar_item_add
(
z
athura
->
ui
.
session
,
TRUE
,
TRUE
,
TRUE
,
NULL
);
if
(
z
athura
->
ui
.
statusbar
.
file
==
NULL
)
{
goto
error_free
;
}
Z
athura
.
UI
.
statusbar
.
buffer
=
girara_statusbar_item_add
(
Z
athura
.
UI
.
session
,
FALSE
,
FALSE
,
FALSE
,
NULL
);
if
(
!
Z
athura
.
UI
.
statusbar
.
buffer
)
{
z
athura
->
ui
.
statusbar
.
buffer
=
girara_statusbar_item_add
(
z
athura
->
ui
.
session
,
FALSE
,
FALSE
,
FALSE
,
NULL
);
if
(
z
athura
->
ui
.
statusbar
.
buffer
==
NULL
)
{
goto
error_free
;
}
Z
athura
.
UI
.
statusbar
.
page_number
=
girara_statusbar_item_add
(
Z
athura
.
UI
.
session
,
FALSE
,
FALSE
,
FALSE
,
NULL
);
if
(
!
Z
athura
.
UI
.
statusbar
.
page_number
)
{
z
athura
->
ui
.
statusbar
.
page_number
=
girara_statusbar_item_add
(
z
athura
->
ui
.
session
,
FALSE
,
FALSE
,
FALSE
,
NULL
);
if
(
!
z
athura
->
ui
.
statusbar
.
page_number
)
{
goto
error_free
;
}
girara_statusbar_item_set_text
(
Z
athura
.
UI
.
session
,
Z
athura
.
UI
.
statusbar
.
file
,
"[No Name]"
);
girara_statusbar_item_set_text
(
z
athura
->
ui
.
session
,
z
athura
->
ui
.
statusbar
.
file
,
"[No Name]"
);
/* signals */
g_signal_connect
(
G_OBJECT
(
Z
athura
.
UI
.
session
->
gtk
.
window
),
"destroy"
,
G_CALLBACK
(
cb_destroy
),
NULL
);
g_signal_connect
(
G_OBJECT
(
z
athura
->
ui
.
session
->
gtk
.
window
),
"destroy"
,
G_CALLBACK
(
cb_destroy
),
NULL
);
GtkAdjustment
*
view_vadjustment
=
gtk_scrolled_window_get_vadjustment
(
GTK_SCROLLED_WINDOW
(
Z
athura
.
UI
.
session
->
gtk
.
view
));
GtkAdjustment
*
view_vadjustment
=
gtk_scrolled_window_get_vadjustment
(
GTK_SCROLLED_WINDOW
(
z
athura
->
ui
.
session
->
gtk
.
view
));
g_signal_connect
(
G_OBJECT
(
view_vadjustment
),
"value-changed"
,
G_CALLBACK
(
cb_view_vadjustment_value_changed
),
NULL
);
/* girara events */
Z
athura
.
UI
.
session
->
events
.
buffer_changed
=
buffer_changed
;
z
athura
->
ui
.
session
->
events
.
buffer_changed
=
buffer_changed
;
/* load plugins */
zathura_document_plugins_load
();
...
...
@@ -72,23 +78,40 @@ init_zathura()
/* configuration */
config_load_default
();
return
true
;
return
zathura
;
error_free:
if
(
Z
athura
.
UI
.
page_view
)
{
g_object_unref
(
Z
athura
.
UI
.
page_view
);
if
(
z
athura
->
ui
.
page_view
)
{
g_object_unref
(
z
athura
->
ui
.
page_view
);
}
girara_session_destroy
(
Z
athura
.
UI
.
session
);
girara_session_destroy
(
z
athura
->
ui
.
session
);
error_out:
return
false
;
return
NULL
;
}
void
zathura_free
(
zathura_t
*
zathura
)
{
if
(
zathura
==
NULL
)
{
return
;
}
if
(
zathura
->
ui
.
session
!=
NULL
)
{
girara_session_destroy
(
zathura
->
ui
.
session
);
}
document_close
(
zathura
);
/* free registered plugins */
zathura_document_plugins_free
();
}
bool
document_open
(
const
char
*
path
,
const
char
*
password
)
document_open
(
zathura_t
*
zathura
,
const
char
*
path
,
const
char
*
password
)
{
if
(
!
path
)
{
goto
error_out
;
...
...
@@ -100,30 +123,30 @@ document_open(const char* path, const char* password)
goto
error_out
;
}
Z
athura
.
document
=
document
;
z
athura
->
document
=
document
;
/* init view */
if
(
create_blank_pages
()
==
false
)
{
if
(
create_blank_pages
(
zathura
)
==
false
)
{
return
false
;
}
/* view mode */
int
*
value
=
girara_setting_get
(
Z
athura
.
UI
.
session
,
"pages-per-row"
);
int
*
value
=
girara_setting_get
(
z
athura
->
ui
.
session
,
"pages-per-row"
);
int
pages_per_row
=
(
value
)
?
*
value
:
1
;
free
(
value
);
page_view_set_mode
(
pages_per_row
);
page_view_set_mode
(
zathura
,
pages_per_row
);
girara_set_view
(
Z
athura
.
UI
.
session
,
Z
athura
.
UI
.
page_view
);
girara_set_view
(
z
athura
->
ui
.
session
,
z
athura
->
ui
.
page_view
);
/* threads */
Z
athura
.
S
ync
.
render_thread
=
render_init
();
z
athura
->
s
ync
.
render_thread
=
render_init
();
if
(
!
Z
athura
.
S
ync
.
render_thread
)
{
if
(
!
z
athura
->
s
ync
.
render_thread
)
{
goto
error_free
;
}
/* first page */
if
(
!
page_set
(
0
))
{
if
(
!
page_set
(
zathura
,
0
))
{
goto
error_free
;
}
...
...
@@ -139,47 +162,47 @@ error_out:
}
bool
document_close
()
document_close
(
zathura_t
*
zathura
)
{
if
(
!
Z
athura
.
document
)
{
if
(
!
z
athura
->
document
)
{
return
false
;
}
if
(
Z
athura
.
S
ync
.
render_thread
)
{
render_free
(
Z
athura
.
S
ync
.
render_thread
);
if
(
z
athura
->
s
ync
.
render_thread
)
{
render_free
(
z
athura
->
s
ync
.
render_thread
);
}
zathura_document_free
(
Z
athura
.
document
);
zathura_document_free
(
z
athura
->
document
);
return
true
;
}
bool
page_set
(
unsigned
int
page_id
)
page_set
(
zathura_t
*
zathura
,
unsigned
int
page_id
)
{
if
(
!
Z
athura
.
document
||
!
Z
athura
.
document
->
pages
)
{
if
(
!
z
athura
->
document
||
!
z
athura
->
document
->
pages
)
{
goto
error_out
;
}
if
(
page_id
>=
Z
athura
.
document
->
number_of_pages
)
{
if
(
page_id
>=
z
athura
->
document
->
number_of_pages
)
{
goto
error_out
;
}
/* render page */
zathura_page_t
*
page
=
Z
athura
.
document
->
pages
[
page_id
];
zathura_page_t
*
page
=
z
athura
->
document
->
pages
[
page_id
];
if
(
!
page
)
{
goto
error_out
;
}
GtkAdjustment
*
view_vadjustment
=
gtk_scrolled_window_get_vadjustment
(
GTK_SCROLLED_WINDOW
(
Z
athura
.
UI
.
session
->
gtk
.
view
));
GtkAdjustment
*
view_vadjustment
=
gtk_scrolled_window_get_vadjustment
(
GTK_SCROLLED_WINDOW
(
z
athura
->
ui
.
session
->
gtk
.
view
));
cb_view_vadjustment_value_changed
(
view_vadjustment
,
NULL
);
/* update page number */
Z
athura
.
document
->
current_page_number
=
page_id
;
z
athura
->
document
->
current_page_number
=
page_id
;
char
*
page_number
=
g_strdup_printf
(
"[%d/%d]"
,
page_id
+
1
,
Z
athura
.
document
->
number_of_pages
);
girara_statusbar_item_set_text
(
Z
athura
.
UI
.
session
,
Z
athura
.
UI
.
statusbar
.
page_number
,
page_number
);
char
*
page_number
=
g_strdup_printf
(
"[%d/%d]"
,
page_id
+
1
,
z
athura
->
document
->
number_of_pages
);
girara_statusbar_item_set_text
(
z
athura
->
ui
.
session
,
z
athura
->
ui
.
statusbar
.
page_number
,
page_number
);
g_free
(
page_number
);
return
true
;
...
...
@@ -190,42 +213,42 @@ error_out:
}
void
page_view_set_mode
(
unsigned
int
pages_per_row
)
page_view_set_mode
(
zathura_t
*
zathura
,
unsigned
int
pages_per_row
)
{
/* empty page view */
GList
*
container
=
gtk_container_get_children
(
GTK_CONTAINER
(
Z
athura
.
UI
.
page_view
));
GList
*
container
=
gtk_container_get_children
(
GTK_CONTAINER
(
z
athura
->
ui
.
page_view
));
for
(
GList
*
child
=
container
;
child
;
child
=
g_list_next
(
child
))
{
gtk_container_remove
(
GTK_CONTAINER
(
Z
athura
.
UI
.
page_view
),
child
->
data
);
gtk_container_remove
(
GTK_CONTAINER
(
z
athura
->
ui
.
page_view
),
child
->
data
);
}
GtkWidget
*
row
=
NULL
;
/* create blank pages */
for
(
unsigned
int
i
=
0
;
i
<
Z
athura
.
document
->
number_of_pages
;
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
z
athura
->
document
->
number_of_pages
;
i
++
)
{
if
(
i
%
pages_per_row
==
0
)
{
row
=
gtk_hbox_new
(
FALSE
,
0
);
}
/* pack row */
gtk_box_pack_start
(
GTK_BOX
(
row
),
Z
athura
.
document
->
pages
[
i
]
->
event_box
,
FALSE
,
FALSE
,
1
);
gtk_box_pack_start
(
GTK_BOX
(
row
),
z
athura
->
document
->
pages
[
i
]
->
event_box
,
FALSE
,
FALSE
,
1
);
/* pack row to page view */
if
((
i
+
1
)
%
pages_per_row
==
0
)
{
gtk_box_pack_start
(
GTK_BOX
(
Z
athura
.
UI
.
page_view
),
row
,
FALSE
,
FALSE
,
1
);
gtk_box_pack_start
(
GTK_BOX
(
z
athura
->
ui
.
page_view
),
row
,
FALSE
,
FALSE
,
1
);
}
}
gtk_widget_show_all
(
Z
athura
.
UI
.
page_view
);
gtk_widget_show_all
(
z
athura
->
ui
.
page_view
);
}
bool
create_blank_pages
()
create_blank_pages
(
zathura_t
*
zathura
)
{
/* create blank pages */
for
(
unsigned
int
i
=
0
;
i
<
Z
athura
.
document
->
number_of_pages
;
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
z
athura
->
document
->
number_of_pages
;
i
++
)
{
zathura_page_t
*
page
=
Z
athura
.
document
->
pages
[
i
];
zathura_page_t
*
page
=
z
athura
->
document
->
pages
[
i
];
g_static_mutex_lock
(
&
(
page
->
lock
));
cairo_t
*
cairo
=
gdk_cairo_create
(
page
->
drawing_area
->
window
);
...
...
@@ -254,13 +277,14 @@ int main(int argc, char* argv[])
gdk_threads_init
();
gtk_init
(
&
argc
,
&
argv
);
if
(
!
init_zathura
())
{
zathura_t
*
zathura
=
zathura_init
(
argc
,
argv
);
if
(
zathura
==
NULL
)
{
printf
(
"error: coult not initialize zathura
\n
"
);
return
-
1
;
}
if
(
argc
>
1
)
{
if
(
!
document_open
(
argv
[
1
],
NULL
))
{
if
(
!
document_open
(
zathura
,
argv
[
1
],
NULL
))
{
printf
(
"error: could not open document
\n
"
);
return
-
1
;
}
...
...
zathura.h
View file @
8960b6e8
...
...
@@ -24,7 +24,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
#define NORMAL (1 << 3)
#define INSERT (1 << 4)
struct
typedef
struct
zathura_s
{
struct
{
...
...
@@ -39,59 +39,73 @@ struct
GtkWidget
*
page_view
;
/**> Widget that contains all rendered pages */
GtkWidget
*
index
;
/**> Widget to show the index of the document */
}
UI
;
}
ui
;
struct
{
render_thread_t
*
render_thread
;
/**> The thread responsible for rendering the pages */
}
S
ync
;
}
s
ync
;
zathura_document_t
*
document
;
/**> The current document */
}
Z
athura
;
}
z
athura
_t
;
/**
* Initializes zathura
*
* @return If no error occured true, otherwise false, is returned.
* @param argc Number of arguments
* @param argv Values of arguments
* @return Zathura zathura object or NULL if zathura could not been initialized
*/
zathura_t
*
zathura_init
(
int
argc
,
char
*
argv
[]);
/**
* Free zathura zathura
*
* @param zathura The zathura zathura
*/
bool
init_zathura
(
);
void
zathura_free
(
zathura_t
*
zathura
);
/**
* Opens a file
*
* @param zathura The zathura zathura
* @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
);
bool
document_open
(
zathura_t
*
zathura
,
const
char
*
path
,
const
char
*
password
);
/**
* Closes the current opened document
*
* @param zathura The zathura zathura
* @return If no error occured true, otherwise false, is returned.
*/
bool
document_close
();
bool
document_close
(
zathura_t
*
zathura
);
/**
* Opens the page with the given number
*
* @param zathura The zathura zathura
* @return If no error occured true, otherwise false, is returned.
*/
bool
page_set
(
unsigned
int
page_id
);
bool
page_set
(
zathura_t
*
zathura
,
unsigned
int
page_id
);
/**
* Builds the box structure to show the rendered pages
*
* @param zathura The zathura zathura
* @param pages_per_row Number of shown pages per row
*/
void
page_view_set_mode
(
unsigned
int
pages_per_row
);
void
page_view_set_mode
(
zathura_t
*
zathura
,
unsigned
int
pages_per_row
);
/**
* Create blank pages
*
* @param zathura The zathura zathura
* @return false if an error occured, otherwise true
*/
bool
create_blank_pages
();
bool
create_blank_pages
(
zathura_t
*
zathura
);
#endif // ZATHURA_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment