code: Remove global variables from rose.h

Global variables in headers may not work the way you think, so it's
safer to make a static local one.
This commit is contained in:
bellrise 2022-05-16 09:54:39 +02:00
parent 76e48c89f9
commit be0d500024
2 changed files with 11 additions and 11 deletions

21
rose.c
View File

@ -3,14 +3,15 @@
#define MSGBUFSZ 8
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
guint xid;
static Display *glob_dpy;
static guint glob_xid;
void setatom(int a, const char *v)
{
XChangeProperty(dpy, xid,
XChangeProperty(glob_dpy, glob_xid,
atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
(unsigned char *)v, strlen(v) + 1);
XSync(dpy, False);
XSync(glob_dpy, False);
}
const char* getatom(int a)
@ -21,8 +22,8 @@ const char* getatom(int a)
unsigned long ldummy;
unsigned char *p = NULL;
XSync(dpy, False);
XGetWindowProperty(dpy, xid,
XSync(glob_dpy, False);
XGetWindowProperty(glob_dpy, glob_xid,
atoms[a], 0L, BUFSIZ, False, atoms[AtomUTF8],
&adummy, &idummy, &ldummy, &ldummy, &p);
if (p)
@ -36,14 +37,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);
atoms[AtomFind] = XInternAtom(glob_dpy, "_ROSE_FIND", False);
atoms[AtomGo] = XInternAtom(glob_dpy, "_ROSE_GO", False);
atoms[AtomUri] = XInternAtom(glob_dpy, "_ROSE_URI", False);
}
static void run(GtkApplication *app)
@ -56,7 +57,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)

1
rose.h
View File

@ -17,6 +17,5 @@
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);