From 58932060cce965cd9083467f5804be9781a26a56 Mon Sep 17 00:00:00 2001 From: bellrise Date: Mon, 16 May 2022 10:46:42 +0200 Subject: [PATCH] rose+window: Fix warnings & global variables --- config.def.h | 14 +++++++------- keyconf.h | 3 --- rose.c | 15 +++++++++------ rose.h | 20 +++++++++++++------- window.c | 11 +++++++---- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/config.def.h b/config.def.h index 5df0e03..acd6497 100644 --- a/config.def.h +++ b/config.def.h @@ -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 }, diff --git a/keyconf.h b/keyconf.h index 26a124c..3c25969 100644 --- a/keyconf.h +++ b/keyconf.h @@ -18,9 +18,6 @@ #define DARKMODE 2 #define SCROLLBARS 3 -#define KEYBINDS static inline Key keys[] -#define APPERANCE static inline int appearance[] -#define OPTIONS static inline char *options[] typedef struct { unsigned modkey; diff --git a/rose.c b/rose.c index 55765ba..f0d759e 100644 --- a/rose.c +++ b/rose.c @@ -3,13 +3,16 @@ #define MSGBUFSZ 8 #define LENGTH(x) (sizeof(x) / sizeof(x[0])) -static Display *glob_dpy; +Display *glob_dpy; /* defined in rose.h */ + static guint glob_xid; +static Atom glob_atoms[AtomLast]; + void setatom(int a, const char *v) { XChangeProperty(glob_dpy, glob_xid, - atoms[a], atoms[AtomUTF8], 8, PropModeReplace, + glob_atoms[a], glob_atoms[AtomUTF8], 8, PropModeReplace, (unsigned char *)v, strlen(v) + 1); XSync(glob_dpy, False); } @@ -24,7 +27,7 @@ const char* getatom(int a) XSync(glob_dpy, False); XGetWindowProperty(glob_dpy, glob_xid, - atoms[a], 0L, BUFSIZ, False, atoms[AtomUTF8], + glob_atoms[a], 0L, BUFSIZ, False, glob_atoms[AtomUTF8], &adummy, &idummy, &ldummy, &ldummy, &p); if (p) strncpy(buf, (char *)p, LENGTH(buf) - 1); @@ -42,9 +45,9 @@ static void setup() exit(1); } - atoms[AtomFind] = XInternAtom(glob_dpy, "_ROSE_FIND", False); - atoms[AtomGo] = XInternAtom(glob_dpy, "_ROSE_GO", False); - atoms[AtomUri] = XInternAtom(glob_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) diff --git a/rose.h b/rose.h index 192d3dc..8a56410 100644 --- a/rose.h +++ b/rose.h @@ -5,17 +5,23 @@ #include "config.h" #include +#include #include #include -#include -#include -#include #include -#include -#include #include +#include +#include + +enum { + AtomFind, + AtomGo, + AtomUri, + AtomUTF8, + AtomLast +}; + +extern Display *glob_dpy; /* declared in rose.c */ -enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast }; -static Atom atoms[AtomLast]; const char* getatom(int a); void setatom(int a, const char *v); diff --git a/window.c b/window.c index 364f20e..8d1190a 100644 --- a/window.c +++ b/window.c @@ -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); @@ -91,8 +93,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); @@ -205,6 +207,7 @@ static void rose_window_init(RoseWindow *window) static void destroy(RoseWindow *window) { + (void) window; exit(0); }