shortcuts.c 15.5 KB
Newer Older
1
2
/* See LICENSE file for license and copyright information */

3
4
5
6
#include <girara/session.h>
#include <girara/settings.h>
#include <girara/datastructures.h>
#include <girara/shortcuts.h>
Moritz Lipp's avatar
Moritz Lipp committed
7
8
9
#include <gtk/gtk.h>

#include "callbacks.h"
10
#include "shortcuts.h"
11
#include "document.h"
Moritz Lipp's avatar
Moritz Lipp committed
12
#include "zathura.h"
13
#include "render.h"
14
#include "utils.h"
15

Moritz Lipp's avatar
Moritz Lipp committed
16
bool
17
18
sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
    unsigned int UNUSED(t))
19
{
Moritz Lipp's avatar
Moritz Lipp committed
20
21
  g_return_val_if_fail(session != NULL, false);

Moritz Lipp's avatar
Moritz Lipp committed
22
  girara_mode_set(session, session->modes.normal);
Moritz Lipp's avatar
Moritz Lipp committed
23

Moritz Lipp's avatar
Moritz Lipp committed
24
  return false;
25
26
}

Moritz Lipp's avatar
Moritz Lipp committed
27
bool
Moritz Lipp's avatar
Moritz Lipp committed
28
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
29
    unsigned int UNUSED(t))
30
{
Moritz Lipp's avatar
Moritz Lipp committed
31
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
32
33
34
35
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);

Moritz Lipp's avatar
Moritz Lipp committed
36
  unsigned int* pages_per_row = girara_setting_get(session, "pages-per-row");
Moritz Lipp's avatar
Moritz Lipp committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

  if (zathura->ui.page_view == NULL || zathura->document == NULL || pages_per_row == NULL) {
    goto error_ret;
  }

  /* get window size */
  /* TODO: Get correct size of the view widget */
  gint width;
  gint height;
  gtk_window_get_size(GTK_WINDOW(session->gtk.window), &width, &height);

  /* calculate total width and max-height */
  double total_width = 0;
  double max_height = 0;

  for (unsigned int page_id = 0; page_id < *pages_per_row; page_id++) {
    if (page_id == zathura->document->number_of_pages) {
      break;
    }

    zathura_page_t* page = zathura->document->pages[page_id];
    if (page == NULL) {
      goto error_free;
    }

    if (page->height > max_height) {
      max_height = page->height;
    }

    total_width += page->width;
  }

  if (argument->n == ADJUST_WIDTH) {
    zathura->document->scale = width / total_width;
  } else if (argument->n == ADJUST_BESTFIT) {
    zathura->document->scale = height / max_height;
  } else {
    goto error_free;
  }

  /* re-render all pages */
  render_all(zathura);

error_free:

  /* cleanup */
83
  g_free(pages_per_row);
Moritz Lipp's avatar
Moritz Lipp committed
84
85

error_ret:
Moritz Lipp's avatar
Moritz Lipp committed
86

Moritz Lipp's avatar
Moritz Lipp committed
87
  return false;
88
89
}

Moritz Lipp's avatar
Moritz Lipp committed
90
bool
91
92
sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned
    int UNUSED(t))
93
{
Moritz Lipp's avatar
Moritz Lipp committed
94
95
96
97
  g_return_val_if_fail(session != NULL, false);

  girara_mode_set(session, argument->n);

Moritz Lipp's avatar
Moritz Lipp committed
98
  return false;
99
100
}

Moritz Lipp's avatar
Moritz Lipp committed
101
bool
102
103
sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
    unsigned int UNUSED(t))
104
{
Moritz Lipp's avatar
Moritz Lipp committed
105
106
  g_return_val_if_fail(session != NULL, false);

Moritz Lipp's avatar
Moritz Lipp committed
107
108
  return false;
}
109

Moritz Lipp's avatar
Moritz Lipp committed
110
bool
111
sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t)
Moritz Lipp's avatar
Moritz Lipp committed
112
{
Moritz Lipp's avatar
Moritz Lipp committed
113
114
115
116
117
  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(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);
118
119

  if (argument->n == TOP) {
Moritz Lipp's avatar
Moritz Lipp committed
120
    page_set(zathura, 0);
121
122
  } else {
    if (t == 0) {
Moritz Lipp's avatar
Moritz Lipp committed
123
      page_set(zathura, zathura->document->number_of_pages - 1);
124
      return true;
Moritz Lipp's avatar
Moritz Lipp committed
125
126
    } else {
      page_set(zathura, t - 1);
127
128
129
    }
  }

Moritz Lipp's avatar
Moritz Lipp committed
130
  return false;
131
132
}

Moritz Lipp's avatar
Moritz Lipp committed
133
bool
134
sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int
135
    t)
136
{
Moritz Lipp's avatar
Moritz Lipp committed
137
138
139
140
141
  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(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
142

Moritz Lipp's avatar
Moritz Lipp committed
143
144
  unsigned int number_of_pages = zathura->document->number_of_pages;
  unsigned int new_page        = zathura->document->current_page_number;
Moritz Lipp's avatar
Moritz Lipp committed
145

146
  t = (t == 0) ? 1 : t;
Moritz Lipp's avatar
Moritz Lipp committed
147
  if (argument->n == NEXT) {
148
    new_page = (new_page + t) % number_of_pages;
Moritz Lipp's avatar
Moritz Lipp committed
149
  } else if (argument->n == PREVIOUS) {
150
    new_page = (new_page + number_of_pages - t) % number_of_pages;
Moritz Lipp's avatar
Moritz Lipp committed
151
152
  }

153
  page_set(zathura, new_page);
Moritz Lipp's avatar
Moritz Lipp committed
154

Moritz Lipp's avatar
Moritz Lipp committed
155
  return false;
156
157
}

Moritz Lipp's avatar
Moritz Lipp committed
158
bool
159
160
sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument),
    unsigned int UNUSED(t))
161
{
Moritz Lipp's avatar
Moritz Lipp committed
162
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
163
164
165
166
167
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  zathura->global.recolor = !zathura->global.recolor;
  render_all(zathura);
Moritz Lipp's avatar
Moritz Lipp committed
168

Moritz Lipp's avatar
Moritz Lipp committed
169
  return false;
170
171
}

Moritz Lipp's avatar
Moritz Lipp committed
172
bool
173
174
sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
    unsigned int UNUSED(t))
175
{
Moritz Lipp's avatar
Moritz Lipp committed
176
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  if (zathura->document == NULL || zathura->document->file_path == NULL) {
    return false;
  }

  /* save current document path and password */
  char* path     = g_strdup(zathura->document->file_path);
  char* password = zathura->document->password ? g_strdup(zathura->document->password) : NULL;

  /* close current document */
  document_close(zathura);

  /* reopen document */
  document_open(zathura, path, password);

  /* clean up */
  g_free(path);
  g_free(password);
Moritz Lipp's avatar
Moritz Lipp committed
197

Moritz Lipp's avatar
Moritz Lipp committed
198
  return false;
199
200
}

Moritz Lipp's avatar
Moritz Lipp committed
201
bool
202
203
sc_rotate(girara_session_t* session, girara_argument_t* UNUSED(argument),
    unsigned int UNUSED(t))
204
{
Moritz Lipp's avatar
Moritz Lipp committed
205
206
207
208
  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);
Moritz Lipp's avatar
Moritz Lipp committed
209
210

  /* update rotate value */
Moritz Lipp's avatar
Moritz Lipp committed
211
  zathura->document->rotate  = (zathura->document->rotate + 90) % 360;
Moritz Lipp's avatar
Moritz Lipp committed
212
213

  /* render all pages again */
214
  /* XXX: we don't need to rerender, only to resize the widgets and redraw */
215
  render_all(zathura);
Moritz Lipp's avatar
Moritz Lipp committed
216

Moritz Lipp's avatar
Moritz Lipp committed
217
  return false;
218
219
}

Moritz Lipp's avatar
Moritz Lipp committed
220
bool
221
222
sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int
    UNUSED(t))
223
{
Moritz Lipp's avatar
Moritz Lipp committed
224
225
226
227
  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(argument != NULL, false);
228
229
230
  if (zathura->document == NULL) {
    return false;
  }
Moritz Lipp's avatar
Moritz Lipp committed
231

Moritz Lipp's avatar
Moritz Lipp committed
232
  GtkAdjustment* adjustment = NULL;
Moritz Lipp's avatar
Moritz Lipp committed
233
  if ( (argument->n == LEFT) || (argument->n == RIGHT) ) {
Moritz Lipp's avatar
Moritz Lipp committed
234
    adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
Moritz Lipp's avatar
Moritz Lipp committed
235
  } else {
Moritz Lipp's avatar
Moritz Lipp committed
236
    adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
Moritz Lipp's avatar
Moritz Lipp committed
237
  }
Moritz Lipp's avatar
Moritz Lipp committed
238

Moritz Lipp's avatar
Moritz Lipp committed
239
240
241
  gdouble view_size   = gtk_adjustment_get_page_size(adjustment);
  gdouble value       = gtk_adjustment_get_value(adjustment);
  gdouble max         = gtk_adjustment_get_upper(adjustment) - view_size;
Moritz Lipp's avatar
Moritz Lipp committed
242
  gdouble scroll_step = 40;
Moritz Lipp's avatar
Moritz Lipp committed
243
  float* tmp = girara_setting_get(session, "scroll-step");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
244
245
246
247
  if (tmp != NULL) {
    scroll_step = *tmp;
    g_free(tmp);
  }
248
  gdouble new_value;
Moritz Lipp's avatar
Moritz Lipp committed
249

Moritz Lipp's avatar
Moritz Lipp committed
250
  switch(argument->n) {
Moritz Lipp's avatar
Moritz Lipp committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    case FULL_UP:
      new_value = (value - view_size) < 0 ? 0 : (value - view_size);
      break;
    case FULL_DOWN:
      new_value = (value + view_size) > max ? max : (value + view_size);
      break;
    case HALF_UP:
      new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2));
      break;
    case HALF_DOWN:
      new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2));
      break;
    case LEFT:
    case UP:
      new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step);
      break;
    case RIGHT:
    case DOWN:
      new_value = (value + scroll_step) > max ? max : (value + scroll_step);
      break;
    case TOP:
      new_value = 0;
      break;
    case BOTTOM:
      new_value = max;
      break;
    default:
Moritz Lipp's avatar
Moritz Lipp committed
278
      new_value = value;
Moritz Lipp's avatar
Moritz Lipp committed
279
280
281
282
  }

  gtk_adjustment_set_value(adjustment, new_value);

Moritz Lipp's avatar
Moritz Lipp committed
283
  return false;
284
285
}

Moritz Lipp's avatar
Moritz Lipp committed
286
bool
287
288
sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int
    UNUSED(t))
289
{
Moritz Lipp's avatar
Moritz Lipp committed
290
291
292
293
294
295
  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(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);

Moritz Lipp's avatar
Moritz Lipp committed
296
  return false;
297
298
}

Moritz Lipp's avatar
Moritz Lipp committed
299
bool
300
301
sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
    unsigned int UNUSED(t))
302
{
Moritz Lipp's avatar
Moritz Lipp committed
303
304
305
306
307
308
  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(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);

Moritz Lipp's avatar
Moritz Lipp committed
309
310
311
312
313
314
315
316
  if(zathura->ui.index == NULL) {
    return false;
  }

  GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
  GtkTreePath *path;

  gtk_tree_view_get_cursor(tree_view, &path, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
317
  if (path == NULL) {
Moritz Lipp's avatar
Moritz Lipp committed
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
    return false;
  }

  GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
  GtkTreeIter   iter;
  GtkTreeIter   child_iter;

  gboolean is_valid_path = TRUE;

  switch(argument->n) {
    case UP:
      if(gtk_tree_path_prev(path) == FALSE) {
        is_valid_path = gtk_tree_path_up(path);
      } else { /* row above */
        while(gtk_tree_view_row_expanded(tree_view, path)) {
          gtk_tree_model_get_iter(model, &iter, path);
          /* select last child */
          gtk_tree_model_iter_nth_child(model, &child_iter, &iter,
            gtk_tree_model_iter_n_children(model, &iter)-1);
          gtk_tree_path_free(path);
          path = gtk_tree_model_get_path(model, &child_iter);
        }
      }
      break;
    case COLLAPSE:
      if(!gtk_tree_view_collapse_row(tree_view, path)
        && gtk_tree_path_get_depth(path) > 1) {
        gtk_tree_path_up(path);
        gtk_tree_view_collapse_row(tree_view, path);
      }
      break;
    case DOWN:
      if(gtk_tree_view_row_expanded(tree_view, path)) {
        gtk_tree_path_down(path);
      } else {
        do {
          gtk_tree_model_get_iter(model, &iter, path);
          if (gtk_tree_model_iter_next(model, &iter)) {
            path = gtk_tree_model_get_path(model, &iter);
            break;
          }
        } while((is_valid_path = (gtk_tree_path_get_depth(path) > 1))
          && gtk_tree_path_up(path));
      }
      break;
    case EXPAND:
      if(gtk_tree_view_expand_row(tree_view, path, FALSE)) {
        gtk_tree_path_down(path);
      }
      break;
    case SELECT:
      cb_index_row_activated(tree_view, path, NULL, zathura);
      return false;
  }

  if (is_valid_path) {
    gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
  }

  gtk_tree_path_free(path);

Moritz Lipp's avatar
Moritz Lipp committed
379
  return false;
380
381
}

Moritz Lipp's avatar
Moritz Lipp committed
382
bool
383
384
sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
    unsigned int UNUSED(t))
385
{
Moritz Lipp's avatar
Moritz Lipp committed
386
387
388
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
389
390
391
  if (zathura->document == NULL) {
    return false;
  }
392
393
394
395
396

  girara_tree_node_t* document_index = NULL;
  GtkWidget* treeview                = NULL;
  GtkTreeModel* model                = NULL;
  GtkCellRenderer* renderer          = NULL;
397
  GtkCellRenderer* renderer2         = NULL;
398

399
  if (zathura->ui.index == NULL) {
400
    /* create new index widget */
401
    zathura->ui.index = gtk_scrolled_window_new(NULL, NULL);
402

403
    if (zathura->ui.index == NULL) {
404
405
406
      goto error_ret;
    }

407
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.index),
408
409
410
      GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    /* create index */
Moritz Lipp's avatar
Moritz Lipp committed
411
    document_index = zathura_document_index_generate(zathura->document);
412
413
414
415
416
    if (document_index == NULL) {
      // TODO: Error message
      goto error_free;
    }

Sebastian Ramacher's avatar
Sebastian Ramacher committed
417
    model = GTK_TREE_MODEL(gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
    if (model == NULL) {
      goto error_free;
    }

    treeview = gtk_tree_view_new_with_model(model);
    if (treeview == NULL) {
      goto error_free;
    }

    g_object_unref(model);

    renderer = gtk_cell_renderer_text_new();
    if (renderer == NULL) {
      goto error_free;
    }

434
435
436
437
438
    renderer2 = gtk_cell_renderer_text_new();
    if (renderer2 == NULL) {
      goto error_free;
    }

439
440
441
442
443
    document_index_build(model, NULL, document_index);
    girara_node_free(document_index);

    /* setup widget */
    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", renderer, "markup", 0, NULL);
444
    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 1, "Target", renderer2, "text", 1, NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
445

446
447
448
    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
    g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
    g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
449
    gtk_tree_view_column_set_alignment(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 1), 1.0f);
450
    gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE);
451
    g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), zathura);
452

453
    gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview);
454
455
456
    gtk_widget_show(treeview);
  }

457
  if (gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))) {
458
    girara_set_view(session, zathura->ui.page_view_alignment);
459
    gtk_widget_hide(GTK_WIDGET(zathura->ui.index));
460
    girara_mode_set(zathura->ui.session, zathura->modes.normal);
461
  } else {
462
463
    girara_set_view(session, zathura->ui.index);
    gtk_widget_show(GTK_WIDGET(zathura->ui.index));
464
    girara_mode_set(zathura->ui.session, zathura->modes.index);
465
466
467
468
469
470
  }

  return false;

error_free:

471
472
473
  if (zathura->ui.index != NULL) {
    g_object_ref_sink(zathura->ui.index);
    zathura->ui.index = NULL;
474
475
476
477
478
  }

  if (document_index != NULL) {
    girara_node_free(document_index);
  }
Moritz Lipp's avatar
Moritz Lipp committed
479

480
481
error_ret:

Moritz Lipp's avatar
Moritz Lipp committed
482
  return false;
483
484
}

Moritz Lipp's avatar
Moritz Lipp committed
485
bool
486
487
sc_toggle_fullscreen(girara_session_t* session, girara_argument_t*
    UNUSED(argument), unsigned int UNUSED(t))
488
{
Moritz Lipp's avatar
Moritz Lipp committed
489
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
490

Moritz Lipp's avatar
Moritz Lipp committed
491
492
  static bool fullscreen   = false;
  static int pages_per_row = 1;
Moritz Lipp's avatar
Moritz Lipp committed
493

Moritz Lipp's avatar
Moritz Lipp committed
494
495
496
497
498
499
500
501
502

  if (fullscreen == true) {
    /* reset pages per row */
    girara_setting_set(session, "pages-per-row", &pages_per_row);

    /* show status bar */
    gtk_widget_show(GTK_WIDGET(session->gtk.statusbar));

    /* set full screen */
Moritz Lipp's avatar
Moritz Lipp committed
503
504
    gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window));
  } else {
Moritz Lipp's avatar
Moritz Lipp committed
505
506
507
508
    /* backup pages per row */
    int* tmp = girara_setting_get(session, "pages-per-row");
    if (tmp != NULL) {
      pages_per_row = *tmp;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
509
      g_free(tmp);
Moritz Lipp's avatar
Moritz Lipp committed
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
    }

    /* set single view */
    int int_value = 1;
    girara_setting_set(session, "pages-per-row", &int_value);

    /* adjust window */
    girara_argument_t argument = { ADJUST_BESTFIT, NULL };
    sc_adjust_window(session, &argument, 0);

    /* hide status and inputbar */
    gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar));
    gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar));

    /* set full screen */
Moritz Lipp's avatar
Moritz Lipp committed
525
526
527
528
529
    gtk_window_fullscreen(GTK_WINDOW(session->gtk.window));
  }

  fullscreen = fullscreen ? false : true;

Moritz Lipp's avatar
Moritz Lipp committed
530
  return false;
531
532
}

Moritz Lipp's avatar
Moritz Lipp committed
533
bool
534
535
sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument), unsigned
    int UNUSED(t))
536
{
Moritz Lipp's avatar
Moritz Lipp committed
537
538
  g_return_val_if_fail(session != NULL, false);

Moritz Lipp's avatar
Moritz Lipp committed
539
  girara_argument_t arg = { GIRARA_HIDE, NULL };
540
  girara_isc_completion(session, &arg, 0);
Moritz Lipp's avatar
Moritz Lipp committed
541
542

  cb_destroy(NULL, NULL);
543

Moritz Lipp's avatar
Moritz Lipp committed
544
  return false;
545
546
}

Moritz Lipp's avatar
Moritz Lipp committed
547
bool
548
549
sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int
    UNUSED(t))
550
{
Moritz Lipp's avatar
Moritz Lipp committed
551
552
553
554
555
  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(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);
556
557

  /* retreive zoom step value */
Moritz Lipp's avatar
Moritz Lipp committed
558
  int* value = girara_setting_get(zathura->ui.session, "zoom-step");
559
560
561
562
563
  if (value == NULL) {
    return false;
  }

  float zoom_step = *value / 100.0f;
564
  g_free(value);
565
566

  if (argument->n == ZOOM_IN) {
Moritz Lipp's avatar
Moritz Lipp committed
567
    zathura->document->scale += zoom_step;
568
  } else if (argument->n == ZOOM_OUT) {
Moritz Lipp's avatar
Moritz Lipp committed
569
    zathura->document->scale -= zoom_step;
570
  } else {
Moritz Lipp's avatar
Moritz Lipp committed
571
    zathura->document->scale = 1.0;
572
573
  }

574
  render_all(zathura);
575

Moritz Lipp's avatar
Moritz Lipp committed
576
  return false;
577
}
578