From 01388390aa394d48625fcb6f8ff5a0ccf8036742 Mon Sep 17 00:00:00 2001 From: speedie Date: Tue, 23 May 2023 22:14:24 +0200 Subject: [PATCH] code cleanup --- libs/x11/client.c | 1 + libs/x11/client.h | 1 + libs/x11/inc.c | 10 ++++++++ libs/x11/inc.h | 9 +++++++ libs/x11/init.c | 1 + libs/x11/init.h | 2 ++ libs/x11/lib.h | 20 +++++++++++++++ libs/x11/mod.c | 17 +++++++++++++ libs/x11/mod.h | 4 +++ libs/x11/xim.c | 2 ++ libs/x11/xim.h | 2 ++ spmenu.c | 65 ++++++++++------------------------------------- 12 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 libs/x11/inc.c create mode 100644 libs/x11/inc.h create mode 100644 libs/x11/lib.h create mode 100644 libs/x11/mod.c create mode 100644 libs/x11/mod.h diff --git a/libs/x11/client.c b/libs/x11/client.c index a84fd4e..29d6bd9 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ + void prepare_window_size(void) { // set horizontal and vertical padding sp = menupaddingh; diff --git a/libs/x11/client.h b/libs/x11/client.h index 61c29f8..180939a 100644 --- a/libs/x11/client.h +++ b/libs/x11/client.h @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ + static void create_window(int x, int y, int w, int h); static void get_width(int numwidthchecks, unsigned int minstrlen, unsigned int curstrlen); static void prepare_window_size(void); diff --git a/libs/x11/inc.c b/libs/x11/inc.c new file mode 100644 index 0000000..817422e --- /dev/null +++ b/libs/x11/inc.c @@ -0,0 +1,10 @@ +/* See LICENSE file for copyright and license details. */ +#include "xim.c" +#include "key.c" +#include "mouse.c" +#include "xresources.h" +#include "xrdb.c" +#include "client.h" +#include "client.c" +#include "init.c" +#include "mod.c" diff --git a/libs/x11/inc.h b/libs/x11/inc.h new file mode 100644 index 0000000..95694ef --- /dev/null +++ b/libs/x11/inc.h @@ -0,0 +1,9 @@ +/* See LICENSE file for copyright and license details. */ +#include "lib.h" + +#include "init.h" +#include "mod.h" +#include "xrdb.h" +#include "xim.h" +#include "key.h" +#include "mouse.h" diff --git a/libs/x11/init.c b/libs/x11/init.c index 885ffe4..add194e 100644 --- a/libs/x11/init.c +++ b/libs/x11/init.c @@ -1,3 +1,4 @@ +/* See LICENSE file for copyright and license details. */ void setupdisplay(void) { int x, y, i; #if USEXINERAMA diff --git a/libs/x11/init.h b/libs/x11/init.h index 755752d..f67f5c3 100644 --- a/libs/x11/init.h +++ b/libs/x11/init.h @@ -1,3 +1,5 @@ +/* See LICENSE file for copyright and license details. */ + static Atom clip, utf8, types, dock; static Display *dpy; static Window root, parentwin, win; diff --git a/libs/x11/lib.h b/libs/x11/lib.h new file mode 100644 index 0000000..8f7ca2b --- /dev/null +++ b/libs/x11/lib.h @@ -0,0 +1,20 @@ +/* See LICENSE file for copyright and license details. */ + +// include libraries +#include +#include +#include +#include +#include +#include +#include + +// include xinerama +#if USEXINERAMA +#include +#endif + +// include xresources +#if USEXRESOURCES +#include +#endif diff --git a/libs/x11/mod.c b/libs/x11/mod.c new file mode 100644 index 0000000..ffce2f0 --- /dev/null +++ b/libs/x11/mod.c @@ -0,0 +1,17 @@ +/* See LICENSE file for copyright and license details. */ + +int get_locale(char *modifier_list) { + if (XSetLocaleModifiers(modifier_list)) { + return 0; + } else { + return 1; + } +} + +int supports_locale() { + if (XSupportsLocale()) { + return 0; + } else { + return 1; + } +} diff --git a/libs/x11/mod.h b/libs/x11/mod.h new file mode 100644 index 0000000..312e68e --- /dev/null +++ b/libs/x11/mod.h @@ -0,0 +1,4 @@ +/* See LICENSE file for copyright and license details. */ + +static int get_locale(char *modifier_list); +static int supports_locale(); diff --git a/libs/x11/xim.c b/libs/x11/xim.c index 1d1340d..57b68a9 100644 --- a/libs/x11/xim.c +++ b/libs/x11/xim.c @@ -1,3 +1,5 @@ +/* See LICENSE file for copyright and license details. */ + void open_xim(void) { XIM xim; diff --git a/libs/x11/xim.h b/libs/x11/xim.h index e2392d9..826fa35 100644 --- a/libs/x11/xim.h +++ b/libs/x11/xim.h @@ -1,3 +1,5 @@ +/* See LICENSE file for copyright and license details. */ + static XIC xic; static void open_xim(void); diff --git a/spmenu.c b/spmenu.c index 42f5880..e1d451a 100644 --- a/spmenu.c +++ b/spmenu.c @@ -80,32 +80,6 @@ #include #include #include -// openssl is used to generate a checksum, used for caching -// TODO: remove this dependency by doing it some other way -#endif - -// include xinerama used for multi monitor support -#if USEXINERAMA -#include -#endif - -// include X11 headers -#include -#include -#include -#include -#include -#include -#include - -// include xresources -#if USEXRESOURCES -#include -#endif - -// include pango used for markup -#if USEPANGO -#include #endif // include macros and other defines @@ -119,22 +93,17 @@ static int allowkeys; // whether or not to interpret a keypress as an insertion // various headers #include "libs/libdrw/drw.h" #include "libs/sl/main.h" -#include "libs/x11/init.h" #include "libs/draw.h" #include "libs/stream.h" #include "libs/schemes.h" #include "libs/arg.h" -#include "libs/x11/xrdb.h" -#include "libs/x11/xim.h" -#include "libs/x11/key.h" -#include "libs/x11/mouse.h" +#include "libs/x11/inc.h" // include x11 #include "libs/sort.h" #include "libs/history.h" // text static char text[BUFSIZ] = ""; static char numbers[NUMBERSBUFSIZE] = ""; -static char *embed; // x11 embed // keybinds static int numlockmask = 0; @@ -158,9 +127,11 @@ static int hplength = 0; // high priority static char **hpitems = NULL; // high priority static int *sel_index = NULL; static unsigned int sel_size = 0; -static int screen; static int itemn = 0; // item number +static char *embed; // X11 embed +static int screen; // screen + // item struct struct item { char *text; @@ -230,6 +201,9 @@ static void appenditem(struct item *item, struct item **list, struct item **last static void xinitvisual(void); static int max_textw(void); static size_t nextrune(int inc); +static char * cistrstr(const char *s, const char *sub); +static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp; +static char *(*fstrstr)(const char *, const char *) = cistrstr; static char **list; static size_t listsize; @@ -241,47 +215,35 @@ static int listchanged = 0; #include "keybinds.h" #include "mouse.h" -// xresources/color arrays -#include "libs/x11/xresources.h" -#include "libs/colors.h" - static char *fonts[] = { font }; +// color array +#include "libs/colors.h" + // config file #if USECONFIG #include "libs/conf/config.h" #include "libs/conf/config.c" #endif -// matching -static char * cistrstr(const char *s, const char *sub); -static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp; -static char *(*fstrstr)(const char *, const char *) = cistrstr; - // include functions #include "libs/img.h" #include "libs/img.c" #include "libs/rtl.h" #include "libs/rtl.c" -#include "libs/x11/xim.c" -#include "libs/x11/key.c" -#include "libs/x11/mouse.c" #include "libs/sort.c" #include "libs/draw.c" #include "libs/schemes.c" #include "libs/argv.h" #include "libs/argv.c" -#include "libs/x11/xrdb.c" -#include "libs/x11/client.h" -#include "libs/x11/client.c" #include "libs/match.h" #include "libs/match.c" +#include "libs/x11/inc.c" // include x11 #include "libs/history.c" #include "libs/arg.c" #include "libs/stream.c" #include "libs/event.h" #include "libs/event.c" -#include "libs/x11/init.c" int is_selected(size_t index) { for (int i = 0; i < sel_size; i++) { @@ -572,11 +534,12 @@ int main(int argc, char *argv[]) { strcpy(modetext, normtext); } - if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) + if (!setlocale(LC_CTYPE, "") || !supports_locale()) fputs("warning: no locale support\n", stderr); // invalid locale, so notify the user about it - if (!XSetLocaleModifiers("")) + if (!get_locale("")) { fputs("warning: no locale modifiers support\n", stderr); + } if (!(dpy = XOpenDisplay(NULL))) die("spmenu: cannot open display"); // failed to open display