Merge branch 'master' of github.com:mini-rose/rose

This commit is contained in:
fenze 2022-05-16 10:53:15 +02:00
commit cebd950c66
8 changed files with 53 additions and 39 deletions

View File

@ -1,17 +1,17 @@
#include "keyconf.h"
OPTIONS {
[CACHE] = DEFAULT,
[HOMEPAGE] = DEFAULT,
static const char *options[] = {
[CACHE] = DEFAULT, /* DEFAULT = "~/.cache/rose" */
[HOMEPAGE] = DEFAULT, /* DEFAULT = "https://duckduckgo.com" */
};
APPERANCE {
[HEIGHT] = DEFAULT,
[WIDTH] = DEFAULT,
static int appearance[] = {
[HEIGHT] = DEFAULT, /* DEFAULT = 720 */
[WIDTH] = DEFAULT, /* DEFAULT = 1280 */
[DARKMODE] = TRUE
};
KEYBINDS {
static const Key keys[] = {
{ MODKEY, GDK_KEY_h, goback },
{ MODKEY, GDK_KEY_l, goforward },
{ MODKEY, GDK_KEY_y, copy_url },

View File

@ -18,9 +18,12 @@
#define DARKMODE 2
#define SCROLLBARS 3
<<<<<<< HEAD
#define KEYBINDS static Key keys[]
#define APPERANCE static int appearance[]
#define OPTIONS static char *options[]
=======
>>>>>>> 1d622de7971b8439866dfb2873d0b33004437431
typedef struct {
unsigned modkey;

View File

@ -26,7 +26,12 @@ rose:
strip ./rose
debug:
<<<<<<< HEAD
$(CC) -fPIC -o rose *.c $(CFLAGS) $(LIBS) -Wall -Wextra
=======
$(CC) -fPIC -o rose *.c $(CFLAGS) $(LIBS) $(OPTIONS) -Wall -Wextra \
-Wno-unused-variable
>>>>>>> 1d622de7971b8439866dfb2873d0b33004437431
config.h:
[ -f "$@" ] || cp config.def.h $@
@ -47,5 +52,5 @@ clean-all: clean
flags:
echo $(CFLAGS) | sed 's/ /\n/g' > compile_flags.txt
.PHONY: all clean clean-all install uninstall flags config.h
.SILENT: all clean clean-all install uninstall flags config.h
.PHONY: all rose clean clean-all install uninstall flags config.h
.SILENT: all rose clean clean-all install uninstall flags config.h

28
rose.c
View File

@ -3,14 +3,18 @@
#define MSGBUFSZ 8
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
guint xid;
Display *glob_dpy; /* defined in rose.h */
static guint glob_xid;
static Atom glob_atoms[AtomLast];
void setatom(int a, const char *v)
{
XChangeProperty(dpy, xid,
atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
XChangeProperty(glob_dpy, glob_xid,
glob_atoms[a], glob_atoms[AtomUTF8], 8, PropModeReplace,
(unsigned char *)v, strlen(v) + 1);
XSync(dpy, False);
XSync(glob_dpy, False);
}
const char* getatom(int a)
@ -21,9 +25,9 @@ const char* getatom(int a)
unsigned long ldummy;
unsigned char *p = NULL;
XSync(dpy, False);
XGetWindowProperty(dpy, xid,
atoms[a], 0L, BUFSIZ, False, atoms[AtomUTF8],
XSync(glob_dpy, False);
XGetWindowProperty(glob_dpy, glob_xid,
glob_atoms[a], 0L, BUFSIZ, False, glob_atoms[AtomUTF8],
&adummy, &idummy, &ldummy, &ldummy, &p);
if (p)
strncpy(buf, (char *)p, LENGTH(buf) - 1);
@ -36,14 +40,14 @@ const char* getatom(int a)
static void setup()
{
if (!(dpy = XOpenDisplay(NULL))) {
if (!(glob_dpy = XOpenDisplay(NULL))) {
puts("Can't open default display");
exit(1);
}
atoms[AtomFind] = XInternAtom(dpy, "_ROSE_FIND", False);
atoms[AtomGo] = XInternAtom(dpy, "_ROSE_GO", False);
atoms[AtomUri] = XInternAtom(dpy, "_ROSE_URI", False);
glob_atoms[AtomFind] = XInternAtom(glob_dpy, "_ROSE_FIND", False);
glob_atoms[AtomGo] = XInternAtom(glob_dpy, "_ROSE_GO", False);
glob_atoms[AtomUri] = XInternAtom(glob_dpy, "_ROSE_URI", False);
}
static void run(GtkApplication *app)
@ -56,7 +60,7 @@ static void run(GtkApplication *app)
if (!options[HOMEPAGE])
options[HOMEPAGE] = "https://duckduckgo.com";
xid = rose_window_show(app, window, options[HOMEPAGE]);
glob_xid = rose_window_show(app, window, options[HOMEPAGE]);
}
int main(int argc, char **argv)

21
rose.h
View File

@ -5,18 +5,23 @@
#include "config.h"
#include <gtk/gtk.h>
#include <gdk/x11/gdkx.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <signal.h>
#include <X11/Xatom.h>
#include <gdk/x11/gdkx.h>
#include <webkit2/webkit2.h>
#include <stdlib.h>
#include <webkit2/webkit2.h>
#include <sys/wait.h>
enum {
AtomFind,
AtomGo,
AtomUri,
AtomUTF8,
AtomLast
};
extern Display *glob_dpy; /* declared in rose.c */
enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast };
static Atom atoms[AtomLast];
static Display *dpy;
const char* getatom(int a);
void setatom(int a, const char *v);

View File

@ -5,8 +5,6 @@
#include <webkit2/webkit2.h>
#include <gdk/gdk.h>
G_BEGIN_DECLS
#define ROSE_TYPE_WEBVIEW rose_webview_get_type()
G_DECLARE_FINAL_TYPE(RoseWebView, rose_webview, ROSE, WEBVIEW, WebKitWebView)

View File

@ -38,6 +38,8 @@ static gboolean key_press_callback(RoseWindow *window,
guint keycode,
GdkModifierType state)
{
(void) keycode;
for (int i = 0; i < LENGTH(keys); i++) {
if (keys[i].modkey == state
&& keys[i].keycod == keyval) {
@ -74,8 +76,8 @@ static gboolean key_press_callback(RoseWindow *window,
case search: {
int id = fork();
if (id == 0) {
if (dpy)
close(ConnectionNumber(dpy));
if (glob_dpy)
close(ConnectionNumber(glob_dpy));
setsid();
char* argument_list[] = { "/bin/sh", "-c", "dmenu_rose", NULL};
execvp("/bin/sh", argument_list);
@ -92,8 +94,8 @@ static gboolean key_press_callback(RoseWindow *window,
case find: {
int id = fork();
if (id == 0) {
if (dpy)
close(ConnectionNumber(dpy));
if (glob_dpy)
close(ConnectionNumber(glob_dpy));
setsid();
char* argument_list[] = { "/bin/sh", "-c", "dmenu_rose\tfind", NULL};
execvp("/bin/sh", argument_list);
@ -206,6 +208,7 @@ static void rose_window_init(RoseWindow *window)
static void destroy()
{
(void) window;
exit(0);
}

View File

@ -5,8 +5,6 @@
#include <gtk/gtk.h>
#include <gdk/x11/gdkx.h>
G_BEGIN_DECLS
#define ROSE_TYPE_WINDOW rose_window_get_type()
G_DECLARE_FINAL_TYPE(RoseWindow, rose_window, ROSE, WINDOW, GtkApplicationWindow)
@ -19,5 +17,3 @@ void rose_window_set_webview(RoseWindow *window, GtkWidget *webview);
GActionGroup* rose_window_get_action_group(RoseWindow *window,
const char *prefix);
G_END_DECLS