Compare commits
6 Commits
c8ff246cc2
...
ed76b7e9e7
Author | SHA1 | Date | |
---|---|---|---|
ed76b7e9e7 | |||
18ac2627ad | |||
cbc9d35811 | |||
e322621698 | |||
5097a1982b | |||
978c7ca1cc |
2
config.h
2
config.h
|
@ -18,7 +18,7 @@
|
||||||
#define SEARCH "https://search.brave.com/search?q=%s"
|
#define SEARCH "https://search.brave.com/search?q=%s"
|
||||||
// #define SEARCH "https://search.nunosempere.com/search?q=%s"
|
// #define SEARCH "https://search.nunosempere.com/search?q=%s"
|
||||||
// #define SEARCH "https://lite.duckduckgo.com/html/?q=%s"
|
// #define SEARCH "https://lite.duckduckgo.com/html/?q=%s"
|
||||||
#define HOME ""
|
#define HOME "https://search.brave.com/search?q=%s"
|
||||||
// ^ Could also be a website ("https://search.nunosempere.com"), or a file ("file:///opt/rose/homepage.png")
|
// ^ Could also be a website ("https://search.nunosempere.com"), or a file ("file:///opt/rose/homepage.png")
|
||||||
// #define HOME "https://search.nunosempere.com/"
|
// #define HOME "https://search.nunosempere.com/"
|
||||||
// #define HOME "file:///opt/rosenrot/rose.png"
|
// #define HOME "file:///opt/rosenrot/rose.png"
|
||||||
|
|
2
makefile
2
makefile
|
@ -19,7 +19,7 @@ include plugins/plugins.mk
|
||||||
# PLUGINS=./plugins/stand_in/stand_in.c
|
# PLUGINS=./plugins/stand_in/stand_in.c
|
||||||
|
|
||||||
## Formatter
|
## Formatter
|
||||||
STYLE_BLUEPRINT=webkit
|
STYLE_BLUEPRINT="{BasedOnStyle: webkit, AllowShortIfStatementsOnASingleLine: true, IndentCaseLabels: true, AllowShortEnumsOnASingleLine: true}"
|
||||||
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
|
||||||
# Runtime files
|
# Runtime files
|
||||||
|
|
|
@ -1,21 +1,18 @@
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "str_init.h"
|
#include "../strings/strings.h"
|
||||||
#include "str_replace_start.h"
|
|
||||||
|
|
||||||
#define LIBRE_N 50
|
#define LIBRE_N 50
|
||||||
|
|
||||||
/* Inspired by https://libredirect.github.io/, but in C. */
|
/* Inspired by https://libredirect.github.io/, but in C. */
|
||||||
|
|
||||||
int libre_redirect(const char* uri, char* output)
|
int libre_redirect(const char* uri, char* output)
|
||||||
{
|
{
|
||||||
int len_uri = strlen(uri);
|
int len_uri = strlen(uri);
|
||||||
int len_output = strlen(output);
|
int len_output = strlen(output);
|
||||||
|
|
||||||
if ((len_output - len_uri) < LIBRE_N) {
|
if ((len_output - len_uri) < LIBRE_N) {
|
||||||
printf("Not enough memory\n");
|
fprintf(stderr, "Not enough memory\n");
|
||||||
return 1; // not enough memory.
|
return 1; // not enough memory.
|
||||||
} else {
|
} else {
|
||||||
char* annoying_sites[] = {
|
char* annoying_sites[] = {
|
||||||
|
@ -53,14 +50,14 @@ int libre_redirect(const char* uri, char* output)
|
||||||
case 0: // no match found
|
case 0: // no match found
|
||||||
break;
|
break;
|
||||||
case 1: // str_replace_start somehow failed
|
case 1: // str_replace_start somehow failed
|
||||||
printf("str_replace_start failed\n");
|
fprintf(stderr, "str_replace_start failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 2: // match succeeded
|
case 2: // match succeeded
|
||||||
return 2;
|
return 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Unreachable state");
|
fprintf(stderr, "Unreachable state\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcpy(output, uri);
|
strcpy(output, uri);
|
||||||
|
|
|
@ -3,4 +3,3 @@
|
||||||
#define LIBRE_N 50
|
#define LIBRE_N 50
|
||||||
|
|
||||||
int libre_redirect(const char* uri, char* uri_filtered);
|
int libre_redirect(const char* uri, char* uri_filtered);
|
||||||
void str_init(char* str, int n);
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
void str_init(char* str, int n)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
str[i] = ' ';
|
|
||||||
str[n] = '\0';
|
|
||||||
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
|
|
|
@ -1 +0,0 @@
|
||||||
void str_init(char* str, int n);
|
|
|
@ -1,65 +0,0 @@
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define DEBUG false
|
|
||||||
|
|
||||||
/*
|
|
||||||
See also:
|
|
||||||
* <https://web.archive.org/web/20160201212501/coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring>
|
|
||||||
* https://github.com/irl/la-cucina/blob/master/str_replace.c
|
|
||||||
*/
|
|
||||||
|
|
||||||
int str_replace_start(const char* string, const char* target, const char* replacement, char* output)
|
|
||||||
{
|
|
||||||
int l1 = strlen(string);
|
|
||||||
int l2 = strlen(target);
|
|
||||||
int l3 = strlen(replacement);
|
|
||||||
int l4 = strlen(output);
|
|
||||||
if (DEBUG)
|
|
||||||
printf("%d,%d,%d,%d\n", l1, l2, l3, l4);
|
|
||||||
// if(DEBUG) printf("%s,%s,%s,%s\n", string, target, replacement, output);
|
|
||||||
|
|
||||||
if ((l4 < (l1 - l2 + l3)) || l4 < l1) {
|
|
||||||
// Not enough memory in output string.
|
|
||||||
if (DEBUG)
|
|
||||||
printf("String not long enough.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/* else if(l1 < l2){
|
|
||||||
// Not even possible that there is a match.
|
|
||||||
if(DEBUG) printf("Target larger than string.\n");
|
|
||||||
strcpy(output, string);
|
|
||||||
} */
|
|
||||||
else {
|
|
||||||
if (DEBUG)
|
|
||||||
printf("Looking for a match for %s in %s.\n", target, string);
|
|
||||||
int match = true;
|
|
||||||
for (int i = 0; i < l2; i++) {
|
|
||||||
if (string[i] != target[i]) {
|
|
||||||
match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (match) {
|
|
||||||
if (DEBUG)
|
|
||||||
printf("Found match.\n");
|
|
||||||
for (int i = 0; i < l3; i++) {
|
|
||||||
output[i] = replacement[i];
|
|
||||||
}
|
|
||||||
int counter = l3;
|
|
||||||
for (int i = l2; i < l1; i++) {
|
|
||||||
output[counter] = string[i];
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
output[counter] = '\0';
|
|
||||||
return 2; // success
|
|
||||||
} else {
|
|
||||||
if (DEBUG)
|
|
||||||
printf("Did not find match.\n");
|
|
||||||
strcpy(output, string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
int str_replace_start(const char* string, const char* target,
|
|
||||||
const char* replacement, char* output);
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "strings/strings.h"
|
||||||
#include "libre_redirect/libre_redirect.h"
|
#include "libre_redirect/libre_redirect.h"
|
||||||
#include "readability/readability.h"
|
#include "readability/readability.h"
|
||||||
#include "shortcuts/shortcuts.h"
|
#include "shortcuts/shortcuts.h"
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
|
## Shared
|
||||||
|
COMMON_CODE=./plugins/strings/strings.c
|
||||||
|
|
||||||
## Plugins
|
## Plugins
|
||||||
CUSTOM_STYLES=./plugins/style/style.c
|
CUSTOM_STYLES=./plugins/style/style.c
|
||||||
SHORTCUTS=./plugins/shortcuts/shortcuts.c
|
SHORTCUTS=./plugins/shortcuts/shortcuts.c
|
||||||
READABILITY=./plugins/readability/readability.c
|
READABILITY=./plugins/readability/readability.c
|
||||||
LIBRE_REDIRECT=./plugins/libre_redirect/libre_redirect.c ./plugins/libre_redirect/str_replace_start.c ./plugins/libre_redirect/str_init.c
|
LIBRE_REDIRECT=./plugins/libre_redirect/libre_redirect.c
|
||||||
|
|
||||||
ADBLOCK='-L/usr/lib/wyebrowser/adblock.so' # optional adblocking; depends on https://github.com/jun7/wyebadblock
|
ADBLOCK='-L/usr/lib/wyebrowser/adblock.so' # optional adblocking; depends on https://github.com/jun7/wyebadblock
|
||||||
|
|
||||||
STAND_IN=./plugins/stand_in/stand_in.c # gives function definitions for the above, which do nothing
|
STAND_IN=./plugins/stand_in/stand_in.c # gives function definitions for the above, which do nothing
|
||||||
|
|
||||||
PLUGINS=$(CUSTOM_STYLES) $(SHORTCUTS) $(READABILITY) $(LIBRE_REDIRECT)
|
PLUGINS=$(COMMON_CODE) $(CUSTOM_STYLES) $(SHORTCUTS) $(READABILITY) $(LIBRE_REDIRECT)
|
||||||
# PLUGINS=$(STAND_IN)
|
# PLUGINS=$(STAND_IN)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#ifndef READABILITY
|
#pragma once
|
||||||
#define READABILITY
|
|
||||||
|
|
||||||
#define READABILITY_N 88067 + 1000
|
#define READABILITY_N 88067 + 1000
|
||||||
|
|
||||||
void read_readability_js(char* string);
|
void read_readability_js(char* string);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -2,34 +2,21 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../libre_redirect/str_init.h"
|
#include "../strings/strings.h"
|
||||||
#include "../libre_redirect/str_replace_start.h"
|
|
||||||
|
|
||||||
#define SHORTCUT_N 41
|
#define SHORTCUT_N 41
|
||||||
|
#define DEBUG false
|
||||||
/* Uncomment for debug */
|
|
||||||
/* #define DEBUG */
|
|
||||||
|
|
||||||
/* Inspired by https://duckduckgo.com/bangs */
|
/* Inspired by https://duckduckgo.com/bangs */
|
||||||
|
|
||||||
int shortcut_expand(const char* uri, char* output)
|
int shortcut_expand(const char* uri, char* output)
|
||||||
{
|
{
|
||||||
printf("SHORTCUT EXPAND!\n");
|
int len_uri = strlen(uri);
|
||||||
int l1 = strlen(uri);
|
int len_output = strlen(output);
|
||||||
int l2 = strlen(output);
|
|
||||||
int len;
|
|
||||||
char tmp_uri[l2++];
|
|
||||||
char tmp_output[l2++];
|
|
||||||
|
|
||||||
if ((l2 - l1) < SHORTCUT_N) {
|
if ((len_output - len_uri) < SHORTCUT_N) {
|
||||||
#ifdef DEBUG
|
fprintf(stderr, "Not enough memory\n");
|
||||||
printf("Not enough memory\n");
|
|
||||||
#endif
|
|
||||||
return 1; // not enough memory.
|
return 1; // not enough memory.
|
||||||
} else {
|
} else {
|
||||||
strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0'
|
|
||||||
strcpy(tmp_output, output);
|
|
||||||
|
|
||||||
char* shortcuts[] = {
|
char* shortcuts[] = {
|
||||||
"!aa",
|
"!aa",
|
||||||
"!blog",
|
"!blog",
|
||||||
|
@ -51,30 +38,28 @@ int shortcut_expand(const char* uri, char* output)
|
||||||
};
|
};
|
||||||
|
|
||||||
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);
|
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);
|
||||||
len = sizeof(shortcuts) / sizeof(char*);
|
int len = sizeof(shortcuts) / sizeof(char*);
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
int replace_check = str_replace_start(tmp_uri, shortcuts[i],
|
str_init(output, len_output);
|
||||||
|
int replace_check = str_replace_start(uri, shortcuts[i],
|
||||||
expansions[i], output);
|
expansions[i], output);
|
||||||
if (replace_check == 2) {
|
switch (replace_check) {
|
||||||
#ifdef DEBUG
|
case 0: // no match found
|
||||||
printf("tmp_uri: %s\n", tmp_uri);
|
break;
|
||||||
printf("output: %s\n", output);
|
case 1: // str_replace_start somehow failed
|
||||||
#endif
|
fprintf(stderr, "str_replace_start failed\n");
|
||||||
return 2;
|
|
||||||
} else if (replace_check == 1) {
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf("replace_check failed\n");
|
|
||||||
#endif
|
|
||||||
return 1;
|
return 1;
|
||||||
|
break;
|
||||||
|
case 2: // match succeeded
|
||||||
|
return 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Unreachable state\n");
|
||||||
}
|
}
|
||||||
strcpy(tmp_uri, output);
|
|
||||||
str_init(output, l2);
|
|
||||||
}
|
}
|
||||||
strcpy(output, tmp_uri);
|
strcpy(output, uri);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
if (DEBUG) printf("No match found\n\n");
|
||||||
printf("No match found\n\n");
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
61
plugins/strings/strings.c
Normal file
61
plugins/strings/strings.c
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define DEBUG false
|
||||||
|
|
||||||
|
// String manipulation
|
||||||
|
void str_init(char* str, int n)
|
||||||
|
{
|
||||||
|
// could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
str[i] = ' ';
|
||||||
|
str[n] = '\0';
|
||||||
|
}
|
||||||
|
int str_replace_start(const char* string, const char* target, const char* replacement, char* output)
|
||||||
|
{
|
||||||
|
int l1 = strlen(string);
|
||||||
|
int l2 = strlen(target);
|
||||||
|
int l3 = strlen(replacement);
|
||||||
|
int l4 = strlen(output);
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
printf("string: %s, target: %s, replacement: %s, output: %s\n", string, target, replacement, output);
|
||||||
|
printf("%d,%d,%d,%d\n", l1, l2, l3, l4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((l4 < (l1 - l2 + l3)) || l4 < l1) {
|
||||||
|
printf("Not enough memory in output string.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int match = true;
|
||||||
|
for (int i = 0; i < l2; i++) {
|
||||||
|
if (string[i] != target[i]) {
|
||||||
|
match = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (match) {
|
||||||
|
if (DEBUG) printf("Found match.\n");
|
||||||
|
for (int i = 0; i < l3; i++) {
|
||||||
|
output[i] = replacement[i];
|
||||||
|
}
|
||||||
|
int counter = l3;
|
||||||
|
for (int i = l2; i < l1; i++) {
|
||||||
|
output[counter] = string[i];
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
output[counter] = '\0';
|
||||||
|
return 2; // success
|
||||||
|
} else {
|
||||||
|
if (DEBUG) printf("Did not find match.\n");
|
||||||
|
strcpy(output, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
See also:
|
||||||
|
* <https://web.archive.org/web/20160201212501/coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring>
|
||||||
|
* https://github.com/irl/la-cucina/blob/master/str_replace.c
|
||||||
|
*/
|
4
plugins/strings/strings.h
Normal file
4
plugins/strings/strings.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void str_init(char* str, int n);
|
||||||
|
int str_replace_start(const char* string, const char* target, const char* replacement, char* output);
|
|
@ -19,12 +19,3 @@ void read_style_js(char* string)
|
||||||
string[i] = '\0';
|
string[i] = '\0';
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int main(){
|
|
||||||
char* readability_js = malloc(STYLE_N+1);
|
|
||||||
read_readability_js(readability_js);
|
|
||||||
printf("%s", readability_js);
|
|
||||||
free(readability_js);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#ifndef STYLE
|
#pragma once
|
||||||
#define STYLE
|
|
||||||
|
|
||||||
#define STYLE_N 7624 + 1000
|
#define STYLE_N 7624 + 1000
|
||||||
|
|
||||||
void read_style_js(char* string);
|
void read_style_js(char* string);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
81
rosenrot.c
81
rosenrot.c
|
@ -13,22 +13,22 @@ static struct {
|
||||||
GtkHeaderBar* widget;
|
GtkHeaderBar* widget;
|
||||||
GtkEntry* line;
|
GtkEntry* line;
|
||||||
GtkEntryBuffer* line_text;
|
GtkEntryBuffer* line_text;
|
||||||
enum { _SEARCH,
|
enum { _SEARCH, _FIND, _HIDDEN } entry_mode;
|
||||||
_FIND,
|
|
||||||
_HIDDEN } entry_mode;
|
|
||||||
} bar;
|
} bar;
|
||||||
static int num_tabs = 0;
|
static int num_tabs = 0;
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
void toggle_bar(GtkNotebook* notebook);
|
||||||
|
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri);
|
||||||
|
|
||||||
/* Utils */
|
/* Utils */
|
||||||
WebKitWebView* notebook_get_webview(GtkNotebook* notebook)
|
WebKitWebView* notebook_get_webview(GtkNotebook* notebook)
|
||||||
{
|
{
|
||||||
return WEBKIT_WEB_VIEW(gtk_notebook_get_nth_page(
|
return WEBKIT_WEB_VIEW(gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)));
|
||||||
notebook, gtk_notebook_get_current_page(notebook)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load content*/
|
/* Load content*/
|
||||||
|
|
||||||
void toggle_bar(GtkNotebook* notebook);
|
|
||||||
void load_uri(WebKitWebView* view, const char* uri)
|
void load_uri(WebKitWebView* view, const char* uri)
|
||||||
{
|
{
|
||||||
if (strlen(uri) == 0) {
|
if (strlen(uri) == 0) {
|
||||||
|
@ -41,7 +41,6 @@ void load_uri(WebKitWebView* view, const char* uri)
|
||||||
char tmp[strlen("https://") + strlen(uri)];
|
char tmp[strlen("https://") + strlen(uri)];
|
||||||
snprintf(tmp, sizeof(tmp), "https://%s", uri);
|
snprintf(tmp, sizeof(tmp), "https://%s", uri);
|
||||||
webkit_web_view_load_uri(view, tmp);
|
webkit_web_view_load_uri(view, tmp);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Check for shortcuts
|
// Check for shortcuts
|
||||||
int l = SHORTCUT_N + strlen(uri) + 1;
|
int l = SHORTCUT_N + strlen(uri) + 1;
|
||||||
|
@ -68,10 +67,7 @@ void redirect_if_annoying(WebKitWebView* view, const char* uri)
|
||||||
str_init(uri_filtered, l);
|
str_init(uri_filtered, l);
|
||||||
|
|
||||||
int check = libre_redirect(uri, uri_filtered);
|
int check = libre_redirect(uri, uri_filtered);
|
||||||
|
if (check == 2) webkit_web_view_load_uri(view, uri_filtered);
|
||||||
if (check == 2) {
|
|
||||||
webkit_web_view_load_uri(view, uri_filtered);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void set_custom_style(WebKitWebView* view)
|
void set_custom_style(WebKitWebView* view)
|
||||||
|
@ -87,19 +83,13 @@ void handle_signal_load_changed(WebKitWebView* self, WebKitLoadEvent load_event,
|
||||||
GtkNotebook* notebook)
|
GtkNotebook* notebook)
|
||||||
{
|
{
|
||||||
switch (load_event) {
|
switch (load_event) {
|
||||||
/* see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html>
|
// see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html>
|
||||||
*/
|
|
||||||
case WEBKIT_LOAD_STARTED:
|
case WEBKIT_LOAD_STARTED:
|
||||||
|
case WEBKIT_LOAD_COMMITTED:
|
||||||
set_custom_style(self);
|
set_custom_style(self);
|
||||||
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
|
||||||
break;
|
|
||||||
case WEBKIT_LOAD_REDIRECTED:
|
case WEBKIT_LOAD_REDIRECTED:
|
||||||
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
||||||
break;
|
break;
|
||||||
case WEBKIT_LOAD_COMMITTED:
|
|
||||||
redirect_if_annoying(self, webkit_web_view_get_uri(self));
|
|
||||||
set_custom_style(self);
|
|
||||||
break;
|
|
||||||
case WEBKIT_LOAD_FINISHED: {
|
case WEBKIT_LOAD_FINISHED: {
|
||||||
/* Add gtk tab title */
|
/* Add gtk tab title */
|
||||||
const char* webpage_title = webkit_web_view_get_title(self);
|
const char* webpage_title = webkit_web_view_get_title(self);
|
||||||
|
@ -114,7 +104,6 @@ void handle_signal_load_changed(WebKitWebView* self, WebKitLoadEvent load_event,
|
||||||
}
|
}
|
||||||
tab_title[max_length] = '\0';
|
tab_title[max_length] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
|
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
|
||||||
webpage_title == NULL ? "—" : tab_title);
|
webpage_title == NULL ? "—" : tab_title);
|
||||||
// gtk_widget_hide(GTK_WIDGET(bar));
|
// gtk_widget_hide(GTK_WIDGET(bar));
|
||||||
|
@ -123,10 +112,6 @@ void handle_signal_load_changed(WebKitWebView* self, WebKitLoadEvent load_event,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create new tabs */
|
/* Create new tabs */
|
||||||
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri);
|
|
||||||
// handle_signal_create_new_tab is bound to a signal inside notebook_create_new_tab
|
|
||||||
// and itself calls notebook_create_new_tab
|
|
||||||
// therefore we need to do a forward declaration for one of them.
|
|
||||||
GtkWidget* handle_signal_create_new_tab(WebKitWebView* self,
|
GtkWidget* handle_signal_create_new_tab(WebKitWebView* self,
|
||||||
WebKitNavigationAction* navigation_action,
|
WebKitNavigationAction* navigation_action,
|
||||||
GtkNotebook* notebook)
|
GtkNotebook* notebook)
|
||||||
|
@ -137,11 +122,10 @@ GtkWidget* handle_signal_create_new_tab(WebKitWebView* self,
|
||||||
printf("Creating new window: %s\n", uri);
|
printf("Creating new window: %s\n", uri);
|
||||||
notebook_create_new_tab(notebook, uri);
|
notebook_create_new_tab(notebook, uri);
|
||||||
gtk_notebook_set_show_tabs(notebook, true);
|
gtk_notebook_set_show_tabs(notebook, true);
|
||||||
return NULL;
|
|
||||||
} else {
|
} else {
|
||||||
webkit_web_view_evaluate_javascript(self, "alert('Too many tabs, not opening a new one')", -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
|
webkit_web_view_evaluate_javascript(self, "alert('Too many tabs, not opening a new one')", -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
/*
|
/*
|
||||||
WebKitGTK documentation recommends returning the new webview.
|
WebKitGTK documentation recommends returning the new webview.
|
||||||
I imagine that this might allow e.g., to go back in a new tab
|
I imagine that this might allow e.g., to go back in a new tab
|
||||||
|
@ -166,30 +150,24 @@ WebKitWebView* create_new_webview()
|
||||||
"like Gecko) Chrome/110.0.0.0 Safari/537.36");
|
"like Gecko) Chrome/110.0.0.0 Safari/537.36");
|
||||||
// See: <https://www.useragents.me/> for some common user agents
|
// See: <https://www.useragents.me/> for some common user agents
|
||||||
}
|
}
|
||||||
web_context = webkit_web_context_new_with_website_data_manager(
|
web_context = webkit_web_context_new_with_website_data_manager(webkit_website_data_manager_new(DATA_MANAGER_OPTS, NULL));
|
||||||
webkit_website_data_manager_new(DATA_MANAGER_OPTS, NULL));
|
|
||||||
contentmanager = webkit_user_content_manager_new();
|
contentmanager = webkit_user_content_manager_new();
|
||||||
cookiemanager = webkit_web_context_get_cookie_manager(web_context);
|
cookiemanager = webkit_web_context_get_cookie_manager(web_context);
|
||||||
|
|
||||||
webkit_cookie_manager_set_persistent_storage(
|
webkit_cookie_manager_set_persistent_storage(cookiemanager, DATA_DIR "/cookies.sqlite", WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
|
||||||
cookiemanager, DATA_DIR "/cookies.sqlite",
|
|
||||||
WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
|
|
||||||
|
|
||||||
webkit_cookie_manager_set_accept_policy(cookiemanager,
|
webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
|
||||||
WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
|
|
||||||
|
|
||||||
if (g_file_get_contents("~/.config/rose/style.css", &style, NULL, NULL))
|
if (g_file_get_contents("~/.config/rose/style.css", &style, NULL, NULL)) {
|
||||||
webkit_user_content_manager_add_style_sheet(
|
webkit_user_content_manager_add_style_sheet(
|
||||||
contentmanager, webkit_user_style_sheet_new(style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL));
|
contentmanager, webkit_user_style_sheet_new(style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
return g_object_new(WEBKIT_TYPE_WEB_VIEW, "settings", settings, "web-context",
|
return g_object_new(WEBKIT_TYPE_WEB_VIEW, "settings", settings, "web-context", web_context, "user-content-manager", contentmanager, NULL);
|
||||||
web_context, "user-content-manager", contentmanager,
|
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
|
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
|
||||||
{
|
{
|
||||||
if (num_tabs < MAX_NUM_TABS || MAX_NUM_TABS == 0) {
|
if (num_tabs < MAX_NUM_TABS || MAX_NUM_TABS == 0) {
|
||||||
|
|
||||||
WebKitWebView* view = create_new_webview();
|
WebKitWebView* view = create_new_webview();
|
||||||
|
|
||||||
g_signal_connect(view, "load_changed", G_CALLBACK(handle_signal_load_changed), notebook);
|
g_signal_connect(view, "load_changed", G_CALLBACK(handle_signal_load_changed), notebook);
|
||||||
|
@ -208,8 +186,8 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
|
||||||
webkit_web_view_set_zoom_level(view, ZOOM);
|
webkit_web_view_set_zoom_level(view, ZOOM);
|
||||||
num_tabs += 1;
|
num_tabs += 1;
|
||||||
} else {
|
} else {
|
||||||
|
webkit_web_view_evaluate_javascript(notebook_get_webview(notebook), "alert('Too many tabs, not opening a new one')",
|
||||||
webkit_web_view_evaluate_javascript(notebook_get_webview(notebook), "alert('Too many tabs, not opening a new one')", -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
|
-1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,19 +215,15 @@ void toggle_bar(GtkNotebook* notebook)
|
||||||
gtk_window_set_focus(window, GTK_WIDGET(bar.line));
|
gtk_window_set_focus(window, GTK_WIDGET(bar.line));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
// fallthrough
|
|
||||||
case _HIDDEN:
|
case _HIDDEN:
|
||||||
gtk_widget_hide(GTK_WIDGET(bar.widget));
|
gtk_widget_hide(GTK_WIDGET(bar.widget));
|
||||||
break; // not needed now, but might reorder
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handle what happens when the user is on the bar and presses enter
|
// Handle what happens when the user is on the bar and presses enter
|
||||||
void handle_signal_bar_press_enter(GtkEntry* self, GtkNotebook* notebook)
|
void handle_signal_bar_press_enter(GtkEntry* self, GtkNotebook* notebook)
|
||||||
{
|
{
|
||||||
if (bar.entry_mode == _SEARCH)
|
if (bar.entry_mode == _SEARCH)
|
||||||
load_uri(notebook_get_webview(notebook),
|
load_uri(notebook_get_webview(notebook), gtk_entry_buffer_get_text(bar.line_text));
|
||||||
gtk_entry_buffer_get_text(bar.line_text));
|
|
||||||
else if (bar.entry_mode == _FIND)
|
else if (bar.entry_mode == _FIND)
|
||||||
webkit_find_controller_search(
|
webkit_find_controller_search(
|
||||||
webkit_web_view_get_find_controller(notebook_get_webview(notebook)),
|
webkit_web_view_get_find_controller(notebook_get_webview(notebook)),
|
||||||
|
@ -292,12 +266,10 @@ int handle_shortcut(func id, GtkNotebook* notebook)
|
||||||
webkit_web_view_set_zoom_level(view,
|
webkit_web_view_set_zoom_level(view,
|
||||||
(zoom += ZOOM_VAL));
|
(zoom += ZOOM_VAL));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case zoomout:
|
case zoomout:
|
||||||
webkit_web_view_set_zoom_level(view,
|
webkit_web_view_set_zoom_level(view,
|
||||||
(zoom -= ZOOM_VAL));
|
(zoom -= ZOOM_VAL));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case zoom_reset:
|
case zoom_reset:
|
||||||
webkit_web_view_set_zoom_level(view,
|
webkit_web_view_set_zoom_level(view,
|
||||||
(zoom = ZOOM));
|
(zoom = ZOOM));
|
||||||
|
@ -310,14 +282,12 @@ int handle_shortcut(func id, GtkNotebook* notebook)
|
||||||
int l = (n + k - 1) % n;
|
int l = (n + k - 1) % n;
|
||||||
gtk_notebook_set_current_page(notebook, l);
|
gtk_notebook_set_current_page(notebook, l);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case next_tab:;
|
case next_tab:;
|
||||||
int m = gtk_notebook_get_n_pages(notebook);
|
int m = gtk_notebook_get_n_pages(notebook);
|
||||||
int i = gtk_notebook_get_current_page(notebook);
|
int i = gtk_notebook_get_current_page(notebook);
|
||||||
int j = (i + 1) % m;
|
int j = (i + 1) % m;
|
||||||
gtk_notebook_set_current_page(notebook, j);
|
gtk_notebook_set_current_page(notebook, j);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case close_tab:
|
case close_tab:
|
||||||
gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
|
gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
|
||||||
num_tabs -= 1;
|
num_tabs -= 1;
|
||||||
|
@ -338,7 +308,6 @@ int handle_shortcut(func id, GtkNotebook* notebook)
|
||||||
gtk_window_unfullscreen(window);
|
gtk_window_unfullscreen(window);
|
||||||
else
|
else
|
||||||
gtk_window_fullscreen(window);
|
gtk_window_fullscreen(window);
|
||||||
|
|
||||||
is_fullscreen = !is_fullscreen;
|
is_fullscreen = !is_fullscreen;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -346,20 +315,16 @@ int handle_shortcut(func id, GtkNotebook* notebook)
|
||||||
bar.entry_mode = _SEARCH;
|
bar.entry_mode = _SEARCH;
|
||||||
toggle_bar(notebook);
|
toggle_bar(notebook);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case show_finder:
|
case show_finder:
|
||||||
bar.entry_mode = _FIND;
|
bar.entry_mode = _FIND;
|
||||||
toggle_bar(notebook);
|
toggle_bar(notebook);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case finder_next:
|
case finder_next:
|
||||||
webkit_find_controller_search_next(
|
webkit_find_controller_search_next(webkit_web_view_get_find_controller(view));
|
||||||
webkit_web_view_get_find_controller(view));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case finder_prev:
|
case finder_prev:
|
||||||
webkit_find_controller_search_previous(
|
webkit_find_controller_search_previous(webkit_web_view_get_find_controller(view));
|
||||||
webkit_web_view_get_find_controller(view));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case new_tab:
|
case new_tab:
|
||||||
|
@ -462,9 +427,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
/* Show to user */
|
/* Show to user */
|
||||||
gtk_widget_show_all(GTK_WIDGET(window));
|
gtk_widget_show_all(GTK_WIDGET(window));
|
||||||
if (argc != 0) {
|
if (argc != 0) gtk_widget_hide(GTK_WIDGET(bar.widget));
|
||||||
gtk_widget_hide(GTK_WIDGET(bar.widget));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Deal with more tabs */
|
/* Deal with more tabs */
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user