diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-06-09 21:52:14 +0200 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-06-25 20:45:21 +0200 |
commit | 06f9083bdeb085b7b9de762fa029f6519e142dbe (patch) | |
tree | b3efca1e52e04f11a2087696d643d3ccfb84993d /src/uicmd.cc | |
parent | 52d9a4726da51b78bc5ed445588efb17f5f4e637 (diff) |
Add support for zoom factor
Allows zooming in and out of pages by changing the size of all elements,
including font size, images and tables. The initial zoom is specified in
the "zoom_factor" option of dillorc.
Use the new shortcuts Ctrl+ and Ctrl- to adjust the zoom of the current
page and Ctrl 0 to reset it to 100%. When a new tab or window is opened,
the current zoom factor is inherited. Each tab retains its own zoom
factor.
Fixes: https://github.com/dillo-browser/dillo/issues/21
Diffstat (limited to 'src/uicmd.cc')
-rw-r--r-- | src/uicmd.cc | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/src/uicmd.cc b/src/uicmd.cc index d7822e47..d289df0c 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -576,9 +576,13 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, new_bw = UIcmd_tab_new(DilloTabs, old_ui, focus); win->show(); - if (old_bw == NULL && prefs.xpos >= 0 && prefs.ypos >= 0) { - // position the first window according to preferences - DilloTabs->window()->position(prefs.xpos, prefs.ypos); + if (old_bw == NULL) { + new_bw->zoom = prefs.zoom_factor; + + if (prefs.xpos >= 0 && prefs.ypos >= 0) { + // position the first window according to preferences + DilloTabs->window()->position(prefs.xpos, prefs.ypos); + } } win->callback(win_cb, DilloTabs); @@ -799,6 +803,8 @@ void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url) a_UIcmd_get_wh(bw, &w, &h); new_bw = a_UIcmd_browser_window_new(w, h, 0, bw); + /* Preserve same zoom factor in new window */ + new_bw->zoom = bw->zoom; UIcmd_open_url_nbw(new_bw, url); } @@ -810,6 +816,8 @@ void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus) BrowserWindow *bw = (BrowserWindow *)vbw; BrowserWindow *new_bw = UIcmd_tab_new(BW2UI(bw)->tabs(), bw ? BW2UI(bw) : NULL, focus); + /* Preserve same zoom factor in new tab */ + new_bw->zoom = bw->zoom; UIcmd_open_url_nbw(new_bw, url); } @@ -878,6 +886,51 @@ void a_UIcmd_redirection0(void *vbw, const DilloUrl *url) } /* + * Zoom in + */ +void a_UIcmd_zoom_in(void *vbw) +{ + BrowserWindow *bw = (BrowserWindow*) vbw; + bw->zoom += 0.10; + + if (bw->zoom > 10.0) + bw->zoom = 10.0; + + a_UIcmd_set_msg(bw, "Zoom set to %.0f%%", bw->zoom * 100.0); + + a_Nav_repush((BrowserWindow*)vbw); +} + +/* + * Zoom out + */ +void a_UIcmd_zoom_out(void *vbw) +{ + BrowserWindow *bw = (BrowserWindow*) vbw; + bw->zoom -= 0.10; + + if (bw->zoom < 0.10) + bw->zoom = 0.10; + + a_UIcmd_set_msg(bw, "Zoom set to %.0f%%", bw->zoom * 100.0); + + a_Nav_repush((BrowserWindow*)vbw); +} + +/* + * Zoom reset + */ +void a_UIcmd_zoom_reset(void *vbw) +{ + BrowserWindow *bw = (BrowserWindow*) vbw; + bw->zoom = 1.0; + + a_UIcmd_set_msg(bw, "Zoom set to %.0f%%", bw->zoom * 100.0); + + a_Nav_repush((BrowserWindow*)vbw); +} + +/* * Return a suitable filename for a given URL path. */ static char *UIcmd_make_save_filename(const DilloUrl *url) |