Compare commits

...

4 Commits

Author SHA1 Message Date
90fef3b468 refactor bar variable names 2024-02-11 14:08:19 +01:00
d8522eb827 remove stdbool from rose.c, as already in config.h 2024-02-11 13:59:44 +01:00
31f26f7540 rationalize config.h a bit 2024-02-11 13:58:38 +01:00
9113aac957 some code simplification
- don't have main and "setup" as two separate functions
- declare all global variables at the same time
2024-02-11 13:52:38 +01:00
6 changed files with 74 additions and 76 deletions

View File

@ -1,32 +1,42 @@
#include <gdk/gdkkeysyms.h>
#include <stdbool.h>
/* See more:
* https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html
*
*/
#define WEBKIT_DEFAULT_SETTINGS \
"enable-back-forward-navigation-gestures", true, "enable-developer-extras", true, \
"enable-smooth-scrolling", false, \
"default-charset", "utf-8"
#define GTK "gtk-application-prefer-dark-theme", false, "gtk-enable-animations", false
#define ROSE_HOMEPAGE false
#define SEARCH "https://lite.duckduckgo.com/html/?q=%s" // "https://search.nunosempere.com/search?q=%s"
#define HOME ROSE_HOMEPAGE ? "file:///home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/user-scripts/ubuntu-20.04/rose-images/rose-homepage.png" : "https://search.nunosempere.com/"
// #define HOME ROSE_HOMEPAGE ? "file:///home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/user-scripts/ubuntu-20.04/rose-images/rose-homepage.png" : "https://search.nunosempere.com/"
#define CACHE_DIR "/home/loki/.cache/rose"
// Key user config
#define WIDTH 1920 // 960 for half-width, 1920 for full width
#define HEIGHT 1080
#define SEARCH_BAR_SIZE 1000
#define KEY(x) GDK_KEY_##x
#define BAR_SIZE 1000
// More user config
#define ZOOM 1.6 /* Starting zoom level.*/
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
#define BG_COLOR "#FEFEFE" /* "FEFEFE", "#1E1E2E" */
#define DEBUG false
#define MAX_NUM_TABS 8 // set to 0 or false if you want unlimited tabs, or look at the relevant rose.c code.
#define ROSE_HOMEPAGE false
#define SEARCH "https://lite.duckduckgo.com/html/?q=%s" // "https://search.nunosempere.com/search?q=%s"
#define HOME ROSE_HOMEPAGE ? "file:///home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/user-scripts/ubuntu-20.04/rose-images/rose-homepage.png" : "https://search.nunosempere.com/"
// Webkit settings
// See: https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html
#define WEBKIT_DEFAULT_SETTINGS \
"enable-back-forward-navigation-gestures", true, "enable-developer-extras", true, \
"enable-smooth-scrolling", false, \
"default-charset", "utf-8"
/* CACHE */
#define CACHE_DIR "/home/loki/.cache/rose"
#define CACHE \
"base-cache-directory", CACHE_DIR, "base-data-directory", CACHE_DIR, \
"disk-cache-directory", CACHE_DIR, "dom-cache-directory", CACHE_DIR, \
"hsts-cache-directory", CACHE_DIR, "indexeddb-directory", CACHE_DIR, \
"itp-directory", CACHE_DIR, "local-storage-directory", CACHE_DIR, \
"offline-application-cache-directory", CACHE_DIR, \
"service-worker-registrations-directory", CACHE_DIR
// GTK
#define GTK "gtk-application-prefer-dark-theme", false, "gtk-enable-animations", false
#define KEY(x) GDK_KEY_##x
// Shortcuts
typedef enum {
goback,
goforward,
@ -103,3 +113,4 @@ static struct {
{ CTRL, KEY(p), prettify }
};
*/

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define READABILITY_N 88023 + 1000
#define READABILITY_N 88067 + 1000
void read_readability_js(char* string)
{

View File

@ -1,7 +1,7 @@
#ifndef READABILITY
#define READABILITY
#define READABILITY_N 88023 + 1000
#define READABILITY_N 88067 + 1000
void read_readability_js(char* string);

View File

@ -2615,12 +2615,13 @@ var style_sheet_simple = `
<style type="text/css">
body {
padding: 40px 200px 40px 200px;
padding: 40px 200px 40px 200px !important;
font-size: 18px;
font: 18px/1.5 Roboto;
line-height: 1.6;
background-color: #FEFEFE !important;
color: #444 !important;
max-width: 99% !important;
}
#readOverlay {

BIN
rose

Binary file not shown.

96
rose.c
View File

@ -1,23 +1,30 @@
#include <stdbool.h>
#include <stdlib.h> // necessary for free, malloc.
#include <stdlib.h>
#include <string.h>
#include <webkit2/webkit2.h>
#include "config.h"
#include "plugins/libre_redirect/libre_redirect.h"
#include "plugins/readability/readability.h"
#include "plugins/shortcuts/shortcuts.h"
#include "plugins/style/style.h"
// #include "plugins/stand_in/stand_in.h"
/* Global declarations */
static GtkNotebook* notebook;
static GtkWindow* window;
// Search, find and url bar
static GtkHeaderBar* bar;
static GtkEntry* bar_line; // widget
static GtkEntryBuffer* bar_line_text;
static int bar_entry_mode;
enum { _SEARCH, _FIND, _HIDDEN };
/* Plugins */
// #include "plugins/stand_in/stand_in.h"
int LIBRE_REDIRECT_ENABLED = true;
int READABILITY_ENABLED = true;
int CUSTOM_STYLE_ENABLED = true;
int CUSTOM_USER_AGENT = false;
int NUM_TABS = 0;
// to enable plugins,
// 1. Enable them:
// - uncomment their #include statement
@ -29,24 +36,6 @@ int NUM_TABS = 0;
// - In the make file, include the stand_in.c file and exclude the
// relevant plugin
#define CACHE \
"base-cache-directory", CACHE_DIR, "base-data-directory", CACHE_DIR, \
"disk-cache-directory", CACHE_DIR, "dom-cache-directory", CACHE_DIR, \
"hsts-cache-directory", CACHE_DIR, "indexeddb-directory", CACHE_DIR, \
"itp-directory", CACHE_DIR, "local-storage-directory", CACHE_DIR, \
"offline-application-cache-directory", CACHE_DIR, \
"service-worker-registrations-directory", CACHE_DIR
enum { _SEARCH,
_FIND,
_HIDDEN };
static int entry_mode;
static GtkWindow* window;
static GtkHeaderBar* bar;
static GtkEntryBuffer* search_buf;
static GtkEntry* search;
WebKitWebView* webview_new()
{
char* style;
@ -256,24 +245,24 @@ void notebook_append(GtkNotebook* notebook, const char* uri)
void show_bar(GtkNotebook* notebook)
{
if (entry_mode == _SEARCH) {
if (bar_entry_mode == _SEARCH) {
const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook));
gtk_entry_set_placeholder_text(search, "Search");
gtk_entry_buffer_set_text(search_buf, url, strlen(url));
gtk_entry_set_placeholder_text(bar_line, "Search");
gtk_entry_buffer_set_text(bar_line_text, url, strlen(url));
gtk_widget_show(GTK_WIDGET(bar));
gtk_window_set_focus(window, GTK_WIDGET(search));
} else if (entry_mode == _HIDDEN) {
gtk_window_set_focus(window, GTK_WIDGET(bar_line));
} else if (bar_entry_mode == _HIDDEN) {
gtk_widget_hide(GTK_WIDGET(bar));
} else {
const char* search_text = webkit_find_controller_get_search_text(
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
if (search_text != NULL)
gtk_entry_buffer_set_text(search_buf, search_text, strlen(search_text));
gtk_entry_buffer_set_text(bar_line_text, search_text, strlen(search_text));
gtk_entry_set_placeholder_text(search, "Find");
gtk_entry_set_placeholder_text(bar_line, "Find");
gtk_widget_show(GTK_WIDGET(bar));
gtk_window_set_focus(window, GTK_WIDGET(search));
gtk_window_set_focus(window, GTK_WIDGET(bar_line));
}
}
@ -356,12 +345,12 @@ int handle_key(func id, GtkNotebook* notebook)
break;
case show_searchbar:
entry_mode = _SEARCH;
bar_entry_mode = _SEARCH;
show_bar(notebook);
break;
case show_finder:
entry_mode = _FIND;
bar_entry_mode = _FIND;
show_bar(notebook);
break;
@ -378,12 +367,12 @@ int handle_key(func id, GtkNotebook* notebook)
case new_tab:
notebook_append(notebook, NULL);
gtk_notebook_set_show_tabs(notebook, true);
entry_mode = _SEARCH;
bar_entry_mode = _SEARCH;
show_bar(notebook);
break;
case hide_bar:
entry_mode = _HIDDEN;
bar_entry_mode = _HIDDEN;
show_bar(notebook);
break;
@ -423,13 +412,13 @@ int keypress(void* self, GdkEvent* e, GtkNotebook* notebook)
void search_activate(GtkEntry* self, GtkNotebook* notebook)
{
if (entry_mode == _SEARCH)
if (bar_entry_mode == _SEARCH)
load_uri(notebook_get_webview(notebook),
gtk_entry_buffer_get_text(search_buf));
else if (entry_mode == _FIND)
gtk_entry_buffer_get_text(bar_line_text));
else if (bar_entry_mode == _FIND)
webkit_find_controller_search(
webkit_web_view_get_find_controller(notebook_get_webview(notebook)),
gtk_entry_buffer_get_text(search_buf),
gtk_entry_buffer_get_text(bar_line_text),
WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND,
G_MAXUINT);
@ -444,11 +433,11 @@ void window_init(GtkNotebook* notebook)
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER(css), 800);
gtk_entry_buffer_new("", 0);
gtk_entry_set_alignment(search, 0.48);
gtk_widget_set_size_request(GTK_WIDGET(search), SEARCH_BAR_SIZE, -1);
gtk_header_bar_set_custom_title(bar, GTK_WIDGET(search));
gtk_entry_set_alignment(bar_line, 0.48);
gtk_widget_set_size_request(GTK_WIDGET(bar_line), BAR_SIZE, -1);
gtk_header_bar_set_custom_title(bar, GTK_WIDGET(bar_line));
gtk_window_set_titlebar(window, GTK_WIDGET(bar));
g_signal_connect(search, "activate", G_CALLBACK(search_activate), notebook);
g_signal_connect(bar_line, "activate", G_CALLBACK(search_activate), notebook);
g_signal_connect(window, "key-press-event", G_CALLBACK(keypress), notebook);
g_signal_connect(window, "destroy", G_CALLBACK(exit), notebook);
}
@ -460,15 +449,18 @@ void notebook_init(GtkNotebook* notebook, const char* uri)
notebook_append(notebook, uri);
}
void setup(GtkNotebook* notebook, int argc, char** argv)
int main(int argc, char** argv)
{
// Define GTK entities
// <https://docs.gtk.org/gtk3/func.init.html>
gtk_init(NULL, NULL);
// Define GTK entities. These are declared globally
window = GTK_WINDOW(gtk_window_new(0));
notebook = GTK_NOTEBOOK(gtk_notebook_new());
bar = GTK_HEADER_BAR(gtk_header_bar_new());
search_buf = GTK_ENTRY_BUFFER(gtk_entry_buffer_new("", 0));
search = GTK_ENTRY(gtk_entry_new_with_buffer(search_buf));
bar_line_text = GTK_ENTRY_BUFFER(gtk_entry_buffer_new("", 0));
bar_line = GTK_ENTRY(gtk_entry_new_with_buffer(bar_line_text));
gtk_window_set_default_size(window, WIDTH, HEIGHT);
notebook = GTK_NOTEBOOK(gtk_notebook_new());
window_init(notebook);
// Initialize with first uri
@ -488,13 +480,7 @@ void setup(GtkNotebook* notebook, int argc, char** argv)
notebook_append(notebook, argv[i]);
}
}
}
int main(int argc, char** argv)
{
GtkNotebook* notebook = NULL;
gtk_init(NULL, NULL);
setup(notebook, argc, argv);
gtk_main();
// this point is never reached, since gtk_main(); never exits.
}