2022-05-09 21:03:14 +00:00
|
|
|
#include "rose.h"
|
2022-05-10 21:47:17 +00:00
|
|
|
|
|
|
|
#define MSGBUFSZ 8
|
|
|
|
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
|
|
|
|
2022-05-16 07:54:39 +00:00
|
|
|
static Display *glob_dpy;
|
|
|
|
static guint glob_xid;
|
2022-05-10 21:47:17 +00:00
|
|
|
|
2022-05-13 10:30:15 +00:00
|
|
|
void setatom(int a, const char *v)
|
2022-05-10 21:47:17 +00:00
|
|
|
{
|
2022-05-16 07:54:39 +00:00
|
|
|
XChangeProperty(glob_dpy, glob_xid,
|
2022-05-15 09:13:45 +00:00
|
|
|
atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
|
|
|
|
(unsigned char *)v, strlen(v) + 1);
|
2022-05-16 07:54:39 +00:00
|
|
|
XSync(glob_dpy, False);
|
2022-05-10 21:47:17 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 10:30:15 +00:00
|
|
|
const char* getatom(int a)
|
2022-05-10 21:47:17 +00:00
|
|
|
{
|
|
|
|
static char buf[BUFSIZ];
|
|
|
|
Atom adummy;
|
|
|
|
int idummy;
|
|
|
|
unsigned long ldummy;
|
|
|
|
unsigned char *p = NULL;
|
|
|
|
|
2022-05-16 07:54:39 +00:00
|
|
|
XSync(glob_dpy, False);
|
|
|
|
XGetWindowProperty(glob_dpy, glob_xid,
|
2022-05-10 21:47:17 +00:00
|
|
|
atoms[a], 0L, BUFSIZ, False, atoms[AtomUTF8],
|
|
|
|
&adummy, &idummy, &ldummy, &ldummy, &p);
|
|
|
|
if (p)
|
|
|
|
strncpy(buf, (char *)p, LENGTH(buf) - 1);
|
|
|
|
else
|
|
|
|
buf[0] = '\0';
|
|
|
|
XFree(p);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup()
|
|
|
|
{
|
2022-05-16 07:54:39 +00:00
|
|
|
if (!(glob_dpy = XOpenDisplay(NULL))) {
|
2022-05-10 21:47:17 +00:00
|
|
|
puts("Can't open default display");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2022-05-16 07:54:39 +00:00
|
|
|
atoms[AtomFind] = XInternAtom(glob_dpy, "_ROSE_FIND", False);
|
|
|
|
atoms[AtomGo] = XInternAtom(glob_dpy, "_ROSE_GO", False);
|
|
|
|
atoms[AtomUri] = XInternAtom(glob_dpy, "_ROSE_URI", False);
|
2022-05-10 21:47:17 +00:00
|
|
|
}
|
2022-05-09 21:03:14 +00:00
|
|
|
|
|
|
|
static void run(GtkApplication *app)
|
|
|
|
{
|
2022-05-10 15:35:37 +00:00
|
|
|
RoseWindow *window = rose_window_new(app);
|
2022-05-09 21:03:14 +00:00
|
|
|
|
2022-05-13 16:41:48 +00:00
|
|
|
if (appearance[DARKMODE])
|
2022-05-10 15:35:37 +00:00
|
|
|
g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", true, NULL);
|
2022-05-09 21:03:14 +00:00
|
|
|
|
2022-05-13 16:41:48 +00:00
|
|
|
if (!options[HOMEPAGE])
|
|
|
|
options[HOMEPAGE] = "https://duckduckgo.com";
|
|
|
|
|
2022-05-16 07:54:39 +00:00
|
|
|
glob_xid = rose_window_show(app, window, options[HOMEPAGE]);
|
2022-05-09 21:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2022-05-10 17:52:56 +00:00
|
|
|
if (argc == 2) {
|
2022-05-13 16:41:48 +00:00
|
|
|
options[HOMEPAGE] = argv[1];
|
2022-05-10 17:52:56 +00:00
|
|
|
argv++; argc--;
|
|
|
|
}
|
2022-05-10 21:47:17 +00:00
|
|
|
setup();
|
2022-05-10 18:28:39 +00:00
|
|
|
GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_NON_UNIQUE);
|
2022-05-09 21:03:14 +00:00
|
|
|
g_signal_connect(app, "activate", G_CALLBACK(run), NULL);
|
|
|
|
g_application_run(G_APPLICATION(app), argc, argv);
|
2022-05-12 22:45:02 +00:00
|
|
|
g_object_unref(app);
|
2022-05-09 21:03:14 +00:00
|
|
|
}
|