callbacks.c 3.13 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1
/* See LICENSE file for license and copyright information */
Moritz Lipp's avatar
Moritz Lipp committed
2
3

#include <girara.h>
Moritz Lipp's avatar
Moritz Lipp committed
4
#include <stdlib.h>
5
#include <gtk/gtk.h>
Moritz Lipp's avatar
Moritz Lipp committed
6

Sebastian Ramacher's avatar
Sebastian Ramacher committed
7
#include "callbacks.h"
Moritz Lipp's avatar
Moritz Lipp committed
8
#include "zathura.h"
Moritz Lipp's avatar
Moritz Lipp committed
9
#include "render.h"
10
#include "document.h"
Moritz Lipp's avatar
Moritz Lipp committed
11
#include "utils.h"
Moritz Lipp's avatar
Moritz Lipp committed
12
13

gboolean
14
cb_destroy(GtkWidget* UNUSED(widget), gpointer UNUSED(data))
Moritz Lipp's avatar
Moritz Lipp committed
15
16
17
{
  return TRUE;
}
Moritz Lipp's avatar
Moritz Lipp committed
18
19
20
21
22

void
buffer_changed(girara_session_t* session)
{
  g_return_if_fail(session != NULL);
Moritz Lipp's avatar
Moritz Lipp committed
23
24
25
  g_return_if_fail(session->global.data != NULL);

  zathura_t* zathura = session->global.data;
Moritz Lipp's avatar
Moritz Lipp committed
26
27
28

  char* buffer = girara_buffer_get(session);

Moritz Lipp's avatar
Moritz Lipp committed
29
  if (buffer) {
Moritz Lipp's avatar
Moritz Lipp committed
30
    girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, buffer);
Moritz Lipp's avatar
Moritz Lipp committed
31
    free(buffer);
Moritz Lipp's avatar
Moritz Lipp committed
32
  } else {
Moritz Lipp's avatar
Moritz Lipp committed
33
    girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, "");
34
  }
Moritz Lipp's avatar
Moritz Lipp committed
35
}
36
37
38
39

void
cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
Moritz Lipp's avatar
Moritz Lipp committed
40
  zathura_t* zathura = data;
Moritz Lipp's avatar
Update    
Moritz Lipp committed
41
  if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_view) {
42
43
44
45
    return;
  }

  /* get current adjustment values */
46
47
  gdouble lower = gtk_adjustment_get_value(adjustment);
  gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
48
49

  /* find page that fits */
Moritz Lipp's avatar
Moritz Lipp committed
50
  for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++)
51
  {
Moritz Lipp's avatar
Moritz Lipp committed
52
    zathura_page_t* page = zathura->document->pages[page_id];
Moritz Lipp's avatar
Moritz Lipp committed
53

54
55
56
57
58
59
60
61
    page_offset_t* offset = page_calculate_offset(page);
    if (offset == NULL) {
      continue;
    }

    double begin = offset->y;
    double end   = offset->y + page->height;

Moritz Lipp's avatar
Moritz Lipp committed
62
    if (   ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/
63
64
65
        || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* [> end of the page is in viewport <] */
        || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* [> begin of the page is in viewport <] */
      ) {
66
      page->visible = true;
Moritz Lipp's avatar
Moritz Lipp committed
67
68
69
      if (page->surface == NULL) {
        render_page(zathura->sync.render_thread, page);
      }
70
71
72
73
    } else {
      page->visible = false;
      cairo_surface_destroy(page->surface);
      page->surface = NULL;
74
    }
75

76
    free(offset);
77
78
  }
}
79
80

void
81
cb_pages_per_row_value_changed(girara_session_t* UNUSED(session), girara_setting_t* setting)
82
83
84
85
{
  int pages_per_row = setting->value.i;
  zathura_t* zathura = setting->data;

Moritz Lipp's avatar
Moritz Lipp committed
86
  if (pages_per_row < 1) {
87
    pages_per_row = 1;
Moritz Lipp's avatar
Moritz Lipp committed
88
  }
89
90
91

  page_view_set_mode(zathura, pages_per_row);
}
92
93

void
Moritz Lipp's avatar
Moritz Lipp committed
94
cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    GtkTreeViewColumn* column, zathura_t* zathura)
{
  if (tree_view == NULL || zathura == NULL || zathura->ui.session == NULL) {
    return;
  }

  GtkTreeModel  *model;
  GtkTreeIter   iter;

  g_object_get(tree_view, "model", &model, NULL);

  if(gtk_tree_model_get_iter(model, &iter, path))
  {
    zathura_index_element_t* index_element;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
109
    gtk_tree_model_get(model, &iter, 2, &index_element, -1);
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

    if (index_element == NULL) {
      return;
    }

    if (index_element->type == ZATHURA_LINK_TO_PAGE) {
      page_set(zathura, index_element->target.page_number);
      sc_toggle_index(zathura->ui.session, NULL, 0);
    } else if (index_element->type == ZATHURA_LINK_EXTERNAL) {
      // TODO
    }
  }

  g_object_unref(model);
}