code cleanup
This commit is contained in:
parent
95b420944c
commit
01388390aa
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
void prepare_window_size(void) {
|
void prepare_window_size(void) {
|
||||||
// set horizontal and vertical padding
|
// set horizontal and vertical padding
|
||||||
sp = menupaddingh;
|
sp = menupaddingh;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
static void create_window(int x, int y, int w, int h);
|
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 get_width(int numwidthchecks, unsigned int minstrlen, unsigned int curstrlen);
|
||||||
static void prepare_window_size(void);
|
static void prepare_window_size(void);
|
||||||
|
|
10
libs/x11/inc.c
Normal file
10
libs/x11/inc.c
Normal file
|
@ -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"
|
9
libs/x11/inc.h
Normal file
9
libs/x11/inc.h
Normal file
|
@ -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"
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
void setupdisplay(void) {
|
void setupdisplay(void) {
|
||||||
int x, y, i;
|
int x, y, i;
|
||||||
#if USEXINERAMA
|
#if USEXINERAMA
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
static Atom clip, utf8, types, dock;
|
static Atom clip, utf8, types, dock;
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
static Window root, parentwin, win;
|
static Window root, parentwin, win;
|
||||||
|
|
20
libs/x11/lib.h
Normal file
20
libs/x11/lib.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
// include libraries
|
||||||
|
#include <X11/XKBlib.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xatom.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/Xproto.h>
|
||||||
|
#include <X11/extensions/Xrender.h>
|
||||||
|
|
||||||
|
// include xinerama
|
||||||
|
#if USEXINERAMA
|
||||||
|
#include <X11/extensions/Xinerama.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// include xresources
|
||||||
|
#if USEXRESOURCES
|
||||||
|
#include <X11/Xresource.h>
|
||||||
|
#endif
|
17
libs/x11/mod.c
Normal file
17
libs/x11/mod.c
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
4
libs/x11/mod.h
Normal file
4
libs/x11/mod.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
static int get_locale(char *modifier_list);
|
||||||
|
static int supports_locale();
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
void open_xim(void) {
|
void open_xim(void) {
|
||||||
XIM xim;
|
XIM xim;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
static XIC xic;
|
static XIC xic;
|
||||||
|
|
||||||
static void open_xim(void);
|
static void open_xim(void);
|
||||||
|
|
65
spmenu.c
65
spmenu.c
|
@ -80,32 +80,6 @@
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <Imlib2.h>
|
#include <Imlib2.h>
|
||||||
#include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
// 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 <X11/extensions/Xinerama.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// include X11 headers
|
|
||||||
#include <X11/XKBlib.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xatom.h>
|
|
||||||
#include <X11/keysym.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
#include <X11/Xproto.h>
|
|
||||||
#include <X11/extensions/Xrender.h>
|
|
||||||
|
|
||||||
// include xresources
|
|
||||||
#if USEXRESOURCES
|
|
||||||
#include <X11/Xresource.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// include pango used for markup
|
|
||||||
#if USEPANGO
|
|
||||||
#include <pango/pango.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// include macros and other defines
|
// include macros and other defines
|
||||||
|
@ -119,22 +93,17 @@ static int allowkeys; // whether or not to interpret a keypress as an insertion
|
||||||
// various headers
|
// various headers
|
||||||
#include "libs/libdrw/drw.h"
|
#include "libs/libdrw/drw.h"
|
||||||
#include "libs/sl/main.h"
|
#include "libs/sl/main.h"
|
||||||
#include "libs/x11/init.h"
|
|
||||||
#include "libs/draw.h"
|
#include "libs/draw.h"
|
||||||
#include "libs/stream.h"
|
#include "libs/stream.h"
|
||||||
#include "libs/schemes.h"
|
#include "libs/schemes.h"
|
||||||
#include "libs/arg.h"
|
#include "libs/arg.h"
|
||||||
#include "libs/x11/xrdb.h"
|
#include "libs/x11/inc.h" // include x11
|
||||||
#include "libs/x11/xim.h"
|
|
||||||
#include "libs/x11/key.h"
|
|
||||||
#include "libs/x11/mouse.h"
|
|
||||||
#include "libs/sort.h"
|
#include "libs/sort.h"
|
||||||
#include "libs/history.h"
|
#include "libs/history.h"
|
||||||
|
|
||||||
// text
|
// text
|
||||||
static char text[BUFSIZ] = "";
|
static char text[BUFSIZ] = "";
|
||||||
static char numbers[NUMBERSBUFSIZE] = "";
|
static char numbers[NUMBERSBUFSIZE] = "";
|
||||||
static char *embed; // x11 embed
|
|
||||||
|
|
||||||
// keybinds
|
// keybinds
|
||||||
static int numlockmask = 0;
|
static int numlockmask = 0;
|
||||||
|
@ -158,9 +127,11 @@ static int hplength = 0; // high priority
|
||||||
static char **hpitems = NULL; // high priority
|
static char **hpitems = NULL; // high priority
|
||||||
static int *sel_index = NULL;
|
static int *sel_index = NULL;
|
||||||
static unsigned int sel_size = 0;
|
static unsigned int sel_size = 0;
|
||||||
static int screen;
|
|
||||||
static int itemn = 0; // item number
|
static int itemn = 0; // item number
|
||||||
|
|
||||||
|
static char *embed; // X11 embed
|
||||||
|
static int screen; // screen
|
||||||
|
|
||||||
// item struct
|
// item struct
|
||||||
struct item {
|
struct item {
|
||||||
char *text;
|
char *text;
|
||||||
|
@ -230,6 +201,9 @@ static void appenditem(struct item *item, struct item **list, struct item **last
|
||||||
static void xinitvisual(void);
|
static void xinitvisual(void);
|
||||||
static int max_textw(void);
|
static int max_textw(void);
|
||||||
static size_t nextrune(int inc);
|
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 char **list;
|
||||||
static size_t listsize;
|
static size_t listsize;
|
||||||
|
@ -241,47 +215,35 @@ static int listchanged = 0;
|
||||||
#include "keybinds.h"
|
#include "keybinds.h"
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
|
|
||||||
// xresources/color arrays
|
|
||||||
#include "libs/x11/xresources.h"
|
|
||||||
#include "libs/colors.h"
|
|
||||||
|
|
||||||
static char *fonts[] = { font };
|
static char *fonts[] = { font };
|
||||||
|
|
||||||
|
// color array
|
||||||
|
#include "libs/colors.h"
|
||||||
|
|
||||||
// config file
|
// config file
|
||||||
#if USECONFIG
|
#if USECONFIG
|
||||||
#include "libs/conf/config.h"
|
#include "libs/conf/config.h"
|
||||||
#include "libs/conf/config.c"
|
#include "libs/conf/config.c"
|
||||||
#endif
|
#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 functions
|
||||||
#include "libs/img.h"
|
#include "libs/img.h"
|
||||||
#include "libs/img.c"
|
#include "libs/img.c"
|
||||||
#include "libs/rtl.h"
|
#include "libs/rtl.h"
|
||||||
#include "libs/rtl.c"
|
#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/sort.c"
|
||||||
#include "libs/draw.c"
|
#include "libs/draw.c"
|
||||||
#include "libs/schemes.c"
|
#include "libs/schemes.c"
|
||||||
#include "libs/argv.h"
|
#include "libs/argv.h"
|
||||||
#include "libs/argv.c"
|
#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.h"
|
||||||
#include "libs/match.c"
|
#include "libs/match.c"
|
||||||
|
#include "libs/x11/inc.c" // include x11
|
||||||
#include "libs/history.c"
|
#include "libs/history.c"
|
||||||
#include "libs/arg.c"
|
#include "libs/arg.c"
|
||||||
#include "libs/stream.c"
|
#include "libs/stream.c"
|
||||||
#include "libs/event.h"
|
#include "libs/event.h"
|
||||||
#include "libs/event.c"
|
#include "libs/event.c"
|
||||||
#include "libs/x11/init.c"
|
|
||||||
|
|
||||||
int is_selected(size_t index) {
|
int is_selected(size_t index) {
|
||||||
for (int i = 0; i < sel_size; i++) {
|
for (int i = 0; i < sel_size; i++) {
|
||||||
|
@ -572,11 +534,12 @@ int main(int argc, char *argv[]) {
|
||||||
strcpy(modetext, normtext);
|
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
|
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);
|
fputs("warning: no locale modifiers support\n", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(dpy = XOpenDisplay(NULL)))
|
if (!(dpy = XOpenDisplay(NULL)))
|
||||||
die("spmenu: cannot open display"); // failed to open display
|
die("spmenu: cannot open display"); // failed to open display
|
||||||
|
|
Loading…
Reference in a new issue