aboutsummaryrefslogtreecommitdiff
path: root/sb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sb.cpp')
-rw-r--r--sb.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/sb.cpp b/sb.cpp
index 0c5bdd7..e35f987 100644
--- a/sb.cpp
+++ b/sb.cpp
@@ -29,6 +29,9 @@ void goto_end(bool end);
void get_window_id();
void history_move(bool back);
void reload();
+void find();
+void find_next();
+void find_previous();
uint32_t parent_id = 0;
#include "webengine.hpp"
@@ -38,13 +41,15 @@ uint32_t parent_id = 0;
QWebEngineView * web;
QMainWindow * view;
Display * dpy;
+std::string findexp;
+
class WindowCreateEventFilter : public QObject
{
public:
bool eventFilter(QObject *obj, QEvent *event)
{
- if (obj->isWindowType() && event->type() == QEvent::Show) {
+ if (obj->isWindowType() && event->type() == QEvent::Show && parent_id) {
QWindow *win = (QWindow*)obj;
XReparentWindow(dpy, win->winId(), parent_id, win->position().x(), win->position().y());
XFlush(dpy);
@@ -53,6 +58,7 @@ class WindowCreateEventFilter : public QObject
}
};
+
bool is_valid_url(const std::string & url) {
std::regex r(".*://.*\\..*");
std::smatch m;
@@ -61,10 +67,10 @@ bool is_valid_url(const std::string & url) {
}
-std::string read_from_dmenu() {
+std::string read_from_dmenu(std::string prompt) {
std::string output;
- std::string cmd = std::string("printf '' | dmenu -p 'open: ' ") + dmenu_args + " -w ";
+ std::string cmd = "printf '' | dmenu -p '" + prompt + ": ' " + dmenu_args + " -w ";
cmd += std::to_string(view->winId());
FILE * f = popen(cmd.c_str(), "r");
@@ -81,10 +87,12 @@ std::string read_from_dmenu() {
return output;
}
+
inline void __web_load(const std::string &url) {
web->load(QString::fromStdString(url));
}
+
void open_url(const std::string & url) {
if (url.empty())
return;
@@ -102,16 +110,19 @@ void open_url(const std::string & url) {
__web_load(search_engine + url);
}
+
void search() {
- auto url = read_from_dmenu();
+ auto url = read_from_dmenu("Open");
open_url(url);
}
+
void page_scroll(int scroll) {
std::string js = "window.scrollBy({ top: " + std::to_string(scroll) + ", behavior: 'smooth' });";
web->page()->runJavaScript(QString::fromStdString(js));
}
+
void goto_end(bool end) {
std::string js;
if (end) js = "window.scroll({ top: document.body.scrollHeight, behavior: 'smooth' })";
@@ -119,6 +130,7 @@ void goto_end(bool end) {
web->page()->runJavaScript(QString::fromStdString(js));
}
+
void history_move(bool back) {
if (back)
web->back();
@@ -126,10 +138,28 @@ void history_move(bool back) {
web->forward();
}
+
void reload() {
web->reload();
}
+
+void find() {
+ findexp = read_from_dmenu("Find");
+ web->findText(QString::fromStdString(findexp));
+}
+
+
+void find_next() {
+ web->findText(QString::fromStdString(findexp));
+}
+
+
+void find_previous() {
+ web->findText(QString::fromStdString(findexp), QWebEnginePage::FindBackward);
+}
+
+
void help(char *arg0) {
std::cout << arg0;
std::cout << " [url] [-e <xid>]\n";