initial tabs
This commit is contained in:
parent
99d16fa506
commit
78a46bd5b5
24
compile_flags.txt
Normal file
24
compile_flags.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
-I/usr/include/gtk-4.0
|
||||
-I/usr/include/pango-1.0
|
||||
-I/usr/include/glib-2.0
|
||||
-I/usr/lib/glib-2.0/include
|
||||
-I/usr/include/sysprof-4
|
||||
-I/usr/include/harfbuzz
|
||||
-I/usr/include/freetype2
|
||||
-I/usr/include/libpng16
|
||||
-I/usr/include/libmount
|
||||
-I/usr/include/blkid
|
||||
-I/usr/include/fribidi
|
||||
-I/usr/include/cairo
|
||||
-I/usr/include/lzo
|
||||
-I/usr/include/pixman-1
|
||||
-I/usr/include/gdk-pixbuf-2.0
|
||||
-I/usr/include/graphene-1.0
|
||||
-I/usr/lib/graphene-1.0/include
|
||||
-I/usr/include/gio-unix-2.0
|
||||
-I/usr/include/webkitgtk-5.0
|
||||
-mfpmath=sse
|
||||
-msse
|
||||
-msse2
|
||||
-I/usr/include/libsoup-3.0
|
||||
-pthread
|
|
@ -4,7 +4,7 @@
|
|||
#include <gdk/gdkkeysyms.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define CTRLKEY
|
||||
#define ALTKEY GDK_ALT_MASK
|
||||
#define MODKEY GDK_CONTROL_MASK
|
||||
#define MODSFT 5
|
||||
#define NOMODK 0
|
||||
|
@ -45,5 +45,7 @@ enum {
|
|||
reloadforce,
|
||||
history,
|
||||
gotop,
|
||||
gobottom
|
||||
gobottom,
|
||||
tabnext,
|
||||
tabprev
|
||||
};
|
||||
|
|
2
makefile
2
makefile
|
@ -26,7 +26,7 @@ rose:
|
|||
strip ./rose
|
||||
|
||||
debug:
|
||||
$(CC) -fPIC -o rose *.c $(CFLAGS) $(LIBS) -Wall -Wextra
|
||||
$(CC) -fPIC -o rose *.c $(CFLAGS) $(LIBS) -Wall -Wextra -fsanitize=address -DG_DISABLE_CAST_CHECKS
|
||||
|
||||
config.h:
|
||||
[ -f "$@" ] || cp config.def.h $@
|
||||
|
|
152
window.c
152
window.c
|
@ -5,10 +5,14 @@
|
|||
struct _RoseWindow {
|
||||
GtkApplicationWindow parent_instance;
|
||||
guint xid;
|
||||
|
||||
GtkWindow *window;
|
||||
WebKitWebView *webview;
|
||||
GtkApplication *app;
|
||||
|
||||
WebKitWebView *webview[9];
|
||||
WebKitWebInspector *inspector;
|
||||
WebKitFindOptions *findopts;
|
||||
|
||||
GHashTable *action_groups;
|
||||
GHashTable *action_labels;
|
||||
};
|
||||
|
@ -18,6 +22,7 @@ enum {
|
|||
};
|
||||
|
||||
static float zoom = 1.0;
|
||||
static unsigned tabid = 0;
|
||||
|
||||
G_DEFINE_TYPE(RoseWindow, rose_window, GTK_TYPE_APPLICATION_WINDOW)
|
||||
|
||||
|
@ -32,6 +37,54 @@ static void read_clipboard(GObject *object,
|
|||
);
|
||||
}
|
||||
|
||||
static void new_tab(RoseWindow *window, unsigned id)
|
||||
{
|
||||
window->webview[id] = WEBKIT_WEB_VIEW(webkit_web_view_new());
|
||||
|
||||
if (!options[HOMEPAGE])
|
||||
options[HOMEPAGE] = "https://duckduckgo.com";
|
||||
|
||||
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(window->webview[id]),
|
||||
options[HOMEPAGE]);
|
||||
|
||||
/* gtk_widget_hide(GTK_WIDGET(window->webview[id])); */
|
||||
|
||||
gtk_window_set_child(
|
||||
GTK_WINDOW(
|
||||
gtk_widget_get_root(
|
||||
GTK_WIDGET(
|
||||
window->webview[tabid++]
|
||||
)
|
||||
)
|
||||
),
|
||||
GTK_WIDGET(window->webview[id])
|
||||
);
|
||||
|
||||
gtk_widget_show(GTK_WIDGET(window->webview[tabid]));
|
||||
}
|
||||
|
||||
static void goto_tab(RoseWindow *window, unsigned id)
|
||||
{
|
||||
if (!window->webview[id]) {
|
||||
new_tab(window, id);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_window_set_child(
|
||||
GTK_WINDOW(
|
||||
gtk_widget_get_root(
|
||||
GTK_WIDGET(
|
||||
window->webview[tabid]
|
||||
)
|
||||
)
|
||||
),
|
||||
GTK_WIDGET(window->webview[id])
|
||||
);
|
||||
|
||||
/* gtk_widget_hide(GTK_WIDGET(window->webview[tabid])); */
|
||||
gtk_widget_show(GTK_WIDGET(window->webview[id]));
|
||||
}
|
||||
|
||||
static gboolean key_press_callback(RoseWindow *window,
|
||||
guint keyval,
|
||||
guint keycode,
|
||||
|
@ -44,32 +97,32 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
&& keys[i].keycod == keyval) {
|
||||
switch (keys[i].funcid) {
|
||||
case goback:
|
||||
webkit_web_view_go_back(window->webview);
|
||||
webkit_web_view_go_back(window->webview[tabid]);
|
||||
break;
|
||||
|
||||
case goforward:
|
||||
webkit_web_view_go_forward(window->webview);
|
||||
webkit_web_view_go_forward(window->webview[tabid]);
|
||||
break;
|
||||
|
||||
case copy_url: {
|
||||
GdkDisplay *dpy = gdk_display_get_default();
|
||||
gdk_clipboard_set_text(
|
||||
gdk_display_get_clipboard(dpy),
|
||||
webkit_web_view_get_uri(window->webview)
|
||||
webkit_web_view_get_uri(window->webview[tabid])
|
||||
);
|
||||
} break;
|
||||
|
||||
case paste_url: {
|
||||
GdkDisplay *dpy = gdk_display_get_default();
|
||||
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
||||
gdk_clipboard_read_text_async(clipboard, NULL, read_clipboard, window->webview);
|
||||
gdk_clipboard_read_text_async(clipboard, NULL, read_clipboard, window->webview[tabid]);
|
||||
} break;
|
||||
|
||||
case fullscreen:
|
||||
if (gtk_window_is_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview)))))
|
||||
gtk_window_unfullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
|
||||
if (gtk_window_is_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview[tabid])))))
|
||||
gtk_window_unfullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview[tabid]))));
|
||||
else
|
||||
gtk_window_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
|
||||
gtk_window_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview[tabid]))));
|
||||
break;
|
||||
|
||||
case search: {
|
||||
|
@ -86,7 +139,7 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
wait(&id);
|
||||
char *uri;
|
||||
if (strcmp((uri = (char*)getatom(AtomGo)), ""))
|
||||
rose_webview_load_url(window->webview, uri);
|
||||
rose_webview_load_url(window->webview[tabid], uri);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -102,7 +155,7 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
exit(1);
|
||||
} else {
|
||||
wait(&id);
|
||||
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview);
|
||||
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview[tabid]);
|
||||
webkit_find_controller_search(
|
||||
finder,
|
||||
getatom(AtomFind),
|
||||
|
@ -112,32 +165,32 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
} break;
|
||||
|
||||
case findnext: {
|
||||
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview);
|
||||
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview[tabid]);
|
||||
webkit_find_controller_search_next(finder);
|
||||
} break;
|
||||
|
||||
case findprev: {
|
||||
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview);
|
||||
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview[tabid]);
|
||||
webkit_find_controller_search_previous(finder);
|
||||
} break;
|
||||
|
||||
case zoomin:
|
||||
zoom += 0.1;
|
||||
webkit_web_view_set_zoom_level(window->webview, zoom);
|
||||
webkit_web_view_set_zoom_level(window->webview[tabid], zoom);
|
||||
break;
|
||||
|
||||
case zoomout:
|
||||
zoom -= 0.1;
|
||||
webkit_web_view_set_zoom_level(window->webview, zoom);
|
||||
webkit_web_view_set_zoom_level(window->webview[tabid], zoom);
|
||||
break;
|
||||
|
||||
case zoomreset:
|
||||
zoom = 1;
|
||||
webkit_web_view_set_zoom_level(window->webview, zoom);
|
||||
webkit_web_view_set_zoom_level(window->webview[tabid], zoom);
|
||||
break;
|
||||
|
||||
case inspector:
|
||||
window->inspector = webkit_web_view_get_inspector(window->webview);
|
||||
window->inspector = webkit_web_view_get_inspector(window->webview[tabid]);
|
||||
if (webkit_web_inspector_is_attached(window->inspector))
|
||||
webkit_web_inspector_close(window->inspector);
|
||||
else
|
||||
|
@ -146,19 +199,19 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
break;
|
||||
|
||||
case up:
|
||||
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,-100);", NULL, NULL, NULL);
|
||||
webkit_web_view_run_javascript(window->webview[tabid], "window.scrollBy(0,-100);", NULL, NULL, NULL);
|
||||
break;
|
||||
|
||||
case down:
|
||||
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,100);", NULL, NULL, NULL);
|
||||
webkit_web_view_run_javascript(window->webview[tabid], "window.scrollBy(0,100);", NULL, NULL, NULL);
|
||||
break;
|
||||
|
||||
case reload:
|
||||
webkit_web_view_reload(window->webview);
|
||||
webkit_web_view_reload(window->webview[tabid]);
|
||||
break;
|
||||
|
||||
case reloadforce:
|
||||
webkit_web_view_reload_bypass_cache(window->webview);
|
||||
webkit_web_view_reload_bypass_cache(window->webview[tabid]);
|
||||
break;
|
||||
|
||||
case history: {
|
||||
|
@ -173,20 +226,36 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
wait(&id);
|
||||
char *uri;
|
||||
if (strcmp((uri = (char*)getatom(AtomGo)), ""))
|
||||
rose_webview_load_url(window->webview, uri);
|
||||
rose_webview_load_url(window->webview[tabid], uri);
|
||||
}
|
||||
} break;
|
||||
|
||||
case gotop: {
|
||||
webkit_web_view_run_javascript(window->webview, "window.scrollTo(0,0);", NULL, NULL, NULL);
|
||||
webkit_web_view_run_javascript(window->webview[tabid], "window.scrollTo(0,0);", NULL, NULL, NULL);
|
||||
} break;
|
||||
|
||||
case gobottom: {
|
||||
webkit_web_view_run_javascript(
|
||||
window->webview,
|
||||
window->webview[tabid],
|
||||
"window.scrollTo(0, document.body.scrollHeight);",
|
||||
NULL, NULL, NULL);
|
||||
} break;
|
||||
|
||||
case tabnext: {
|
||||
if (tabid + 1 > 9)
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
|
||||
goto_tab(window, tabid + 1);
|
||||
printf("%i\n", tabid);
|
||||
} break;
|
||||
|
||||
case tabprev: {
|
||||
if (!tabid)
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
|
||||
goto_tab(window, tabid - 1);
|
||||
printf("%i\n", tabid);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +271,7 @@ static void rose_window_constructed(GObject *object)
|
|||
|
||||
static void rose_window_init(RoseWindow *window)
|
||||
{
|
||||
window->window = GTK_WINDOW(gtk_window_new());
|
||||
(void) window;
|
||||
}
|
||||
|
||||
static void destroy()
|
||||
|
@ -212,26 +281,23 @@ static void destroy()
|
|||
|
||||
guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url)
|
||||
{
|
||||
GtkWidget *w = gtk_application_window_new(app);
|
||||
window->app = app;
|
||||
window->window = GTK_WINDOW(gtk_application_window_new(window->app));
|
||||
|
||||
gtk_application_set_menubar(app, FALSE);
|
||||
GtkWidget *webview = rose_webview_new();
|
||||
gtk_widget_set_has_tooltip(webview, FALSE);
|
||||
gtk_widget_has_default(webview);
|
||||
gtk_window_set_destroy_with_parent(GTK_WINDOW(w), TRUE);
|
||||
window->webview = WEBKIT_WEB_VIEW(webview);
|
||||
/* gtk_application_set_menubar(window->app, FALSE); */
|
||||
window->webview[tabid] = WEBKIT_WEB_VIEW(rose_webview_new());
|
||||
|
||||
g_signal_connect(G_OBJECT(w), "destroy",
|
||||
g_signal_connect(G_OBJECT(window->window), "destroy",
|
||||
G_CALLBACK(destroy), NULL);
|
||||
|
||||
g_signal_connect(G_OBJECT(window->webview), "web-process-terminated",
|
||||
g_signal_connect(G_OBJECT(window->webview[tabid]), "web-process-terminated",
|
||||
G_CALLBACK(destroy), NULL);
|
||||
|
||||
g_signal_connect(G_OBJECT(window->webview), "load-changed",
|
||||
G_CALLBACK(rose_load_changed_callback), window);
|
||||
g_signal_connect(G_OBJECT(window->webview[tabid]), "load-changed",
|
||||
G_CALLBACK(rose_load_changed_callback), window->webview[tabid]);
|
||||
|
||||
if (url) {
|
||||
rose_webview_load_url(WEBKIT_WEB_VIEW(webview), url);
|
||||
rose_webview_load_url(WEBKIT_WEB_VIEW(window->webview[tabid]), url);
|
||||
setatom(AtomUri, url);
|
||||
}
|
||||
|
||||
|
@ -240,24 +306,24 @@ guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url)
|
|||
appearance[HEIGHT] = 720;
|
||||
}
|
||||
|
||||
gtk_window_set_default_size(GTK_WINDOW(w), appearance[WIDTH], appearance[HEIGHT]);
|
||||
gtk_window_set_default_size(GTK_WINDOW(window->window), appearance[WIDTH], appearance[HEIGHT]);
|
||||
|
||||
gtk_window_set_child(GTK_WINDOW(w), GTK_WIDGET(webview));
|
||||
gtk_window_set_child(GTK_WINDOW(window->window), GTK_WIDGET(window->webview[tabid]));
|
||||
|
||||
/* Keyboard shortcuts */
|
||||
GtkEventController *controller;
|
||||
controller = gtk_event_controller_key_new();
|
||||
g_signal_connect_swapped(controller, "key-pressed", G_CALLBACK(key_press_callback), window);
|
||||
gtk_widget_add_controller(GTK_WIDGET(w), controller);
|
||||
gtk_widget_add_controller(GTK_WIDGET(window->window), controller);
|
||||
|
||||
gtk_widget_show(w);
|
||||
gtk_widget_show(GTK_WIDGET(window->window));
|
||||
gtk_widget_show(GTK_WIDGET(window->webview[tabid]));
|
||||
|
||||
return gdk_x11_surface_get_xid(gtk_native_get_surface(GTK_NATIVE(w)));
|
||||
return 12;
|
||||
}
|
||||
|
||||
void rose_window_set_webview(RoseWindow *window, GtkWidget *webview)
|
||||
{
|
||||
window->webview = WEBKIT_WEB_VIEW(webview);
|
||||
window->webview[tabid] = WEBKIT_WEB_VIEW(webview);
|
||||
}
|
||||
|
||||
static void rose_window_class_init(RoseWindowClass *class)
|
||||
|
|
Loading…
Reference in New Issue
Block a user