aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2025-04-26 23:27:07 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2025-04-27 00:03:00 +0200
commitdd1ce83521403d81ebfe46f7815a10220e4f3a96 (patch)
tree51499260024d34c616f956a99a9c1aadf8a821d3 /src
parentdb361d8fdf487066eb9b1f480ff386c619eaac09 (diff)
Add about:keys to show keyboard shortcuts
Fixes: https://github.com/dillo-browser/dillo/issues/66
Diffstat (limited to 'src')
-rw-r--r--src/IO/about.c11
-rw-r--r--src/cache.c7
-rw-r--r--src/cache.h13
-rw-r--r--src/dillo.cc4
-rw-r--r--src/keys.cc115
-rw-r--r--src/keys.hh4
6 files changed, 144 insertions, 10 deletions
diff --git a/src/IO/about.c b/src/IO/about.c
index 83cb2b4d..360441bc 100644
--- a/src/IO/about.c
+++ b/src/IO/about.c
@@ -2,7 +2,7 @@
* File: about.c
*
* Copyright (C) 1999-2007 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,6 +32,11 @@ const char *const AboutSplash=
" p { margin-top: 1em; }\n"
" ul { margin-left: 1em; }\n"
" li { margin-top: 0.5em; }\n"
+" kbd {\n"
+" display: inline-block;\n"
+" border: solid 1px #999;\n"
+" padding: 1px 3px;\n"
+" }\n"
" </style>\n"
"</head>\n"
"<body>\n"
@@ -40,12 +45,12 @@ const char *const AboutSplash=
"<h1>Quickstart</h1>\n"
"\n"
"<p>Welcome to Dillo " VERSION ", a small and fast graphical web browser. To\n"
-"access the help click the question mark button <code>?</code> in the top\n"
+"access the help click the question mark button <code><kbd>?</kbd></code> in the top\n"
"right corner at any time. Here are some tips to get you started:</p>\n"
"\n"
"<ul>\n"
" <li>The main configuration file is at <code>~/.dillo/dillorc</code>.</li>\n"
-" <li>Most actions can also be done by using the <em>keyboard</em>.</li>\n"
+" <li>Most actions can also be done by using the <a href='about:keys'>keyboard</a>.</li>\n"
" <li>Cookies are <em>disabled by default</em>.</li>\n"
" <li>Several Dillo plugins are available.</li>\n"
"</ul>\n"
diff --git a/src/cache.c b/src/cache.c
index 8c05c0eb..d2827e65 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -2,7 +2,7 @@
* File: cache.c
*
* Copyright 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -89,7 +89,6 @@ static uint_t DelayedQueueIdleId = 0;
static CacheEntry_t *Cache_process_queue(CacheEntry_t *entry);
static void Cache_delayed_process_queue(CacheEntry_t *entry);
static void Cache_auth_entry(CacheEntry_t *entry, BrowserWindow *bw);
-static void Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds);
/**
* Determine if two cache entries are equal (used by CachedURLs)
@@ -125,7 +124,7 @@ void a_Cache_init(void)
{
DilloUrl *url = a_Url_new("about:splash", NULL);
Dstr *ds = dStr_new(AboutSplash);
- Cache_entry_inject(url, ds);
+ a_Cache_entry_inject(url, ds);
dStr_free(ds, 1);
a_Url_free(url);
}
@@ -266,7 +265,7 @@ static CacheEntry_t *Cache_entry_add(const DilloUrl *Url)
* Inject full page content directly into the cache.
* Used for "about:splash". May be used for "about:cache" too.
*/
-static void Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds)
+void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds)
{
CacheEntry_t *entry;
diff --git a/src/cache.h b/src/cache.h
index 72ed2196..1b850a2d 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -1,3 +1,15 @@
+/*
+ * File: cache.c
+ *
+ * Copyright 2000-2009 Jorge Arellano Cid <jcid@dillo.org>
+ * Copyright 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ */
+
#ifndef __CACHE_H__
#define __CACHE_H__
@@ -60,6 +72,7 @@ struct CacheClient {
* Function prototypes
*/
void a_Cache_init(void);
+void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds);
int a_Cache_open_url(void *Web, CA_Callback_t Call, void *CbData);
int a_Cache_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize);
void a_Cache_unref_buf(const DilloUrl *Url);
diff --git a/src/dillo.cc b/src/dillo.cc
index 40740118..0b04e804 100644
--- a/src/dillo.cc
+++ b/src/dillo.cc
@@ -2,7 +2,7 @@
* Dillo web browser
*
* Copyright 1999-2007 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -496,6 +496,8 @@ int main(int argc, char **argv)
a_UIcmd_init();
StyleEngine::init();
+ Keys::genAboutKeys();
+
dw::core::Widget::setAdjustMinWidth (prefs.adjust_min_width);
dw::Table::setAdjustTableMinWidth (prefs.adjust_table_min_width);
dw::Textblock::setPenaltyHyphen (prefs.penalty_hyphen);
diff --git a/src/keys.cc b/src/keys.cc
index 7346706e..bbbd30bb 100644
--- a/src/keys.cc
+++ b/src/keys.cc
@@ -2,7 +2,7 @@
* Key parser
*
* Copyright (C) 2009 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,6 +20,8 @@
#include "keys.hh"
#include "utf8.hh"
#include "msg.h"
+#include "cache.h"
+#include "misc.h"
/*
* Local data types
@@ -260,6 +262,26 @@ int Keys::getKeyCode(char *keyName)
return -1;
}
+const char *Keys::getKeyName(int key)
+{
+ static char buf[128];
+
+ uint_t i;
+ for (i = 0; i < sizeof(keyNames) / sizeof(keyNames[0]); i++) {
+ if (keyNames[i].value == key)
+ return keyNames[i].name;
+ }
+
+ if (d_isascii(key)) {
+ sprintf(buf, "%c", key);
+ } else {
+ /* Otherwise print hexadecimal */
+ sprintf(buf, "0x%x", key);
+ }
+
+ return buf;
+}
+
/**
* Takes a command name and searches it in the mapping table.
* Return value: command code if found, -1 otherwise
@@ -398,3 +420,94 @@ void Keys::parse(FILE *fp)
}
fclose(fp);
}
+
+void Keys::genAboutKeys(void)
+{
+ int len = dList_length(bindings);
+ Dstr *table = dStr_new("");
+
+ dStr_sprintfa(table,
+ "<!DOCTYPE HTML>\n"
+ "<html>\n"
+ "<head>\n"
+ " <title>Keyboard shortcuts</title>\n"
+ " <style>\n"
+ " body {\n"
+ " background: white;\n"
+ " margin: 3em;\n"
+ " font-size: 16px;\n"
+ " font-family: sans-serif;\n"
+ " line-height: 1.4em;\n"
+ " }\n"
+ " .main { max-width: 40em; }\n"
+ " p { margin-top: 1em; }\n"
+ " table {\n"
+ " border-collapse: collapse;\n"
+ " }\n"
+ " th,td {\n"
+ " padding: 0.25em;\n"
+ " padding: 0.25em;\n"
+ " border-spacing: 0px;\n"
+ " border-top: solid 1px #ccc;\n"
+ " border-bottom: solid 1px #ccc;\n"
+ " }\n"
+ " td.key {\n"
+ " min-width: 15em;\n"
+ " }\n"
+ " td.action {\n"
+ " min-width: 10em;\n"
+ " }\n"
+ " th {\n"
+ " background-color: #eee;\n"
+ " }\n"
+ " kbd {\n"
+ " display: inline-block;\n"
+ " border: solid 1px #aaa;\n"
+ " padding: 1px 5px;\n"
+ " }\n"
+ " kbd.mod {\n"
+ " background: #f5f5f5;\n"
+ " }\n"
+ " </style>\n"
+ "</head>\n"
+ "<body>\n"
+ "<div class=\"main\">\n"
+ "\n"
+ "<h1>Keyboard shortcuts</h1>\n"
+ "\n"
+ "<p>The following table contains the current key bindings in Dillo.\n"
+ "To change them, edit the configuration file <code>~/.dillo/keysrc</code> \n"
+ "and restart the browser.</p>\n"
+ "<table>\n"
+ "<tr><th>Shortcut<th>Action</tr>\n");
+
+ for (int i = 0; i < len; i++) {
+ KeyBinding_t *node = (KeyBinding_t*)dList_nth_data(bindings, i);
+ const char *key = Keys::getKeyName(node->key);
+
+ dStr_sprintfa(table, "<tr><td class=key><code>");
+
+ for (uint_t j = 0; j < sizeof(modifierNames) / sizeof(modifierNames[0]); j++) {
+ if (modifierNames[j].value & node->modifier) {
+ dStr_sprintfa(table, "<kbd class=mod>%s</kbd> ",
+ modifierNames[j].name);
+ }
+ }
+
+ dStr_sprintfa(table, "<kbd class=key>%s</kbd></code></td>", key);
+ dStr_sprintfa(table, "<td class=action><code>%s</code></td>", node->name);
+ dStr_sprintfa(table, "</tr>\n");
+ }
+
+ dStr_sprintfa(table,
+ "</table>\n"
+ "</div>\n"
+ "</body>\n"
+ "</html>\n");
+
+ /* inject keymaps after loading them */
+ DilloUrl *url = a_Url_new("about:keys", NULL);
+ a_Cache_entry_inject(url, table);
+ dStr_free(table, 1);
+ a_Url_free(url);
+}
diff --git a/src/keys.hh b/src/keys.hh
index 22c337ac..40c01718 100644
--- a/src/keys.hh
+++ b/src/keys.hh
@@ -2,7 +2,7 @@
* Key parser
*
* Copyright (C) 2009 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -62,12 +62,14 @@ private:
static int getKeyCode(char *keyName);
static int getModifier(char *modifierName);
static void parseKey(char *key, char *symbol);
+ static const char *getKeyName(int key);
public:
static void init();
static void free();
static void parse(FILE *fp);
static KeysCommand_t getKeyCmd(void);
static int getShortcut(KeysCommand_t cmd);
+ static void genAboutKeys(void);
};