From be0d50002465ac90b8c9328bcfe54d69efb85016 Mon Sep 17 00:00:00 2001 From: bellrise Date: Mon, 16 May 2022 09:54:39 +0200 Subject: [PATCH] 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. --- rose.c | 21 +++++++++++---------- rose.h | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rose.c b/rose.c index ed9980a..55765ba 100644 --- a/rose.c +++ b/rose.c @@ -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) diff --git a/rose.h b/rose.h index 99ea26c..192d3dc 100644 --- a/rose.h +++ b/rose.h @@ -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);