From a9ee831159d5586b6efb8660c977deb9a45d625c Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 5 Jun 2023 17:16:26 +0200 Subject: [PATCH] add X11 toggle, so now Xlib, Xinerama and Xrender aren't dependencies if you only use Wayland --- keybinds.h | 2 ++ libs/arg.c | 2 ++ libs/argv.c | 9 +++++ libs/conf/config.c | 40 ++++++++++++++++++++++ libs/conf/config.h | 21 +++++++----- libs/draw.c | 4 +++ libs/img.c | 18 +++++++++- libs/img.h | 3 ++ libs/libdrw/drw.c | 27 ++++++++++++++- libs/wl/wayland.h | 9 ++++- libs/x11/client.c | 31 ----------------- libs/x11/client.h | 2 -- libs/x11/inc.c | 2 ++ libs/x11/inc.h | 2 ++ libs/x11/key.h | 1 - libs/x11/mouse.h | 14 -------- meson.build | 12 ++++--- meson.options | 21 ++++++++---- mouse.h | 4 ++- scripts/make/build.sh | 14 +++----- spmenu.c | 79 ++++++++++++++++++++++++++++++++++++------- 21 files changed, 223 insertions(+), 94 deletions(-) diff --git a/keybinds.h b/keybinds.h index 59582c2..7884114 100644 --- a/keybinds.h +++ b/keybinds.h @@ -6,6 +6,7 @@ */ /* X11 hardcoded keybinds */ +#if USEX static Key keys[] = { /* mode modifier key function argument * @@ -79,6 +80,7 @@ static Key keys[] = { /* insert mode */ { 1, 0, XK_Escape, switchmode, {0} }, }; +#endif /* Wayland hardcoded keybinds */ #if USEWAYLAND diff --git a/libs/arg.c b/libs/arg.c index d2a0d90..a996b16 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -159,9 +159,11 @@ void moveend(Arg *arg) { } void paste(Arg *arg) { +#if USEX if (!protocol) { paste_x11(arg->i); } +#endif } void viewhist(Arg *arg) { diff --git a/libs/argv.c b/libs/argv.c index 071da18..033249b 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -64,13 +64,16 @@ void readargs(int argc, char *argv[]) { } } +#if USEWAYLAND if (protocol) { if (connect_display(&state)) { protocol = 0; } } +#endif // init/read xrdb +#if USEX if (xresources && !protocol) { #if USEXRESOURCES XrmInitialize(); @@ -79,6 +82,7 @@ void readargs(int argc, char *argv[]) { ; // avoids a warning #endif } +#endif // no arguments for (i = 1; i < argc; i++) @@ -367,7 +371,9 @@ void readargs(int argc, char *argv[]) { imageheight = imagewidth; } else if (!strcmp(argv[i], "-w") || (!strcmp(argv[i], "--embed"))) { // embedding window id +#if USEX embed = argv[++i]; +#endif } else if (!strcmp(argv[i], "-n") || (!strcmp(argv[i], "--preselect"))) { // preselected item preselected = atoi(argv[++i]); @@ -492,6 +498,9 @@ void readargs(int argc, char *argv[]) { else fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]); +#if !USEX + protocol = 1; +#endif #if !USEWAYLAND protocol = 0; #endif diff --git a/libs/conf/config.c b/libs/conf/config.c index 6bb3ee5..6282616 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -568,11 +568,13 @@ void conf_init(void) { // look up config_setting_lookup_string(conf, "modifier", &dest); +#if USEX for (int j = 0; j < LENGTH(ml); j++) { if (!strcmp(ml[j].mod, strdup(dest))) { ckeys[i].mod = ml[j].modifier; } } +#endif #if USEWAYLAND for (int j = 0; j < LENGTH(wml); j++) { @@ -583,7 +585,9 @@ void conf_init(void) { #endif if (config_setting_lookup_int(conf, "mode", &nmode)) { +#if USEX ckeys[i].mode = nmode; +#endif #if USEWAYLAND wl_ckeys[i].mode = nmode; #endif @@ -591,11 +595,13 @@ void conf_init(void) { config_setting_lookup_string(conf, "key", &dest); +#if USEX for (int j = 0; j < LENGTH(kl); j++) { if (!strcmp(kl[j].key, strdup(dest))) { ckeys[i].keysym = kl[j].keysym; } } +#endif #if USEWAYLAND for (int j = 0; j < LENGTH(wkl); j++) { @@ -609,7 +615,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(fl); j++) { if (!strcmp(fl[j].function, strdup(dest))) { +#if USEX ckeys[i].func = fl[j].func; +#endif #if USEWAYLAND wl_ckeys[i].func = fl[j].func; #endif @@ -620,7 +628,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(al); j++) { if (!strcmp(al[j].argument, strdup(dest))) { +#if USEX ckeys[i].arg = al[j].arg; +#endif #if USEWAYLAND wl_ckeys[i].arg = al[j].arg; #endif @@ -641,7 +651,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(ctp); j++) { if (!strcmp(ctp[j].tclick, strdup(dest))) { +#if USEX cbuttons[i].click = ctp[j].click; +#endif #if USEWAYLAND wl_cbuttons[i].click = ctp[j].click; #endif @@ -650,11 +662,13 @@ void conf_init(void) { config_setting_lookup_string(conf, "button", &dest); +#if USEX for (int j = 0; j < LENGTH(btp); j++) { if (!strcmp(btp[j].click, strdup(dest))) { cbuttons[i].button = btp[j].button; } } +#endif #if USEWAYLAND for (int j = 0; j < LENGTH(w_btp); j++) { @@ -668,7 +682,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(fl); j++) { if (!strcmp(fl[j].function, strdup(dest))) { +#if USEX cbuttons[i].func = fl[j].func; +#endif #if USEWAYLAND wl_cbuttons[i].func = fl[j].func; #endif @@ -679,7 +695,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(al); j++) { if (!strcmp(al[j].argument, strdup(dest))) { +#if USEX cbuttons[i].arg = al[j].arg; +#endif #if USEWAYLAND wl_cbuttons[i].arg = al[j].arg; #endif @@ -743,7 +761,9 @@ void conf_init(void) { if (key_bind != NULL && loadbinds) { int nmode = 0; +#if USEX memset(ckeys, '\0', LENGTH(ckeys)-1); +#endif #if USEWAYLAND memset(wl_ckeys, '\0', LENGTH(wl_ckeys)-1); #endif @@ -753,11 +773,13 @@ void conf_init(void) { // look up config_setting_lookup_string(conf, "modifier", &dest); +#if USEX for (int j = 0; j < LENGTH(ml); j++) { if (!strcmp(ml[j].mod, strdup(dest))) { ckeys[i].mod = ml[j].modifier; } } +#endif #if USEWAYLAND for (int j = 0; j < LENGTH(wml); j++) { @@ -768,7 +790,9 @@ void conf_init(void) { #endif if (config_setting_lookup_int(conf, "mode", &nmode)) { +#if USEX ckeys[i].mode = nmode; +#endif #if USEWAYLAND wl_ckeys[i].mode = nmode; #endif @@ -776,11 +800,13 @@ void conf_init(void) { config_setting_lookup_string(conf, "key", &dest); +#if USEX for (int j = 0; j < LENGTH(kl); j++) { if (!strcmp(kl[j].key, strdup(dest))) { ckeys[i].keysym = kl[j].keysym; } } +#endif #if USEWAYLAND for (int j = 0; j < LENGTH(wkl); j++) { @@ -794,7 +820,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(fl); j++) { if (!strcmp(fl[j].function, strdup(dest))) { +#if USEX ckeys[i].func = fl[j].func; +#endif #if USEWAYLAND wl_ckeys[i].func = fl[j].func; #endif @@ -805,7 +833,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(al); j++) { if (!strcmp(al[j].argument, strdup(dest))) { +#if USEX ckeys[i].arg = al[j].arg; +#endif #if USEWAYLAND wl_ckeys[i].arg = al[j].arg; #endif @@ -819,7 +849,9 @@ void conf_init(void) { // load options binds.mouse config_setting_t *mouse_bind = config_lookup(&bind, "bind.mouse"); if (mouse_bind != NULL && loadbinds) { +#if USEX memset(cbuttons, '\0', LENGTH(cbuttons)-1); +#endif for (unsigned int i = 0; i < config_setting_length(mouse_bind); ++i) { config_setting_t *conf = config_setting_get_elem(mouse_bind, i); @@ -827,7 +859,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(ctp); j++) { if (!strcmp(ctp[j].tclick, strdup(dest))) { +#if USEX cbuttons[i].click = ctp[j].click; +#endif #if USEWAYLAND wl_cbuttons[i].click = ctp[j].click; #endif @@ -836,11 +870,13 @@ void conf_init(void) { config_setting_lookup_string(conf, "button", &dest); +#if USEX for (int j = 0; j < LENGTH(btp); j++) { if (!strcmp(btp[j].click, strdup(dest))) { cbuttons[i].button = btp[j].button; } } +#endif #if USEWAYLAND for (int j = 0; j < LENGTH(w_btp); j++) { @@ -854,7 +890,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(fl); j++) { if (!strcmp(fl[j].function, strdup(dest))) { +#if USEX cbuttons[i].func = fl[j].func; +#endif #if USEWAYLAND wl_cbuttons[i].func = fl[j].func; #endif @@ -865,7 +903,9 @@ void conf_init(void) { for (int j = 0; j < LENGTH(al); j++) { if (!strcmp(al[j].argument, strdup(dest))) { +#if USEX cbuttons[i].arg = al[j].arg; +#endif #if USEWAYLAND wl_cbuttons[i].arg = al[j].arg; #endif diff --git a/libs/conf/config.h b/libs/conf/config.h index d16d3a8..5aca5b1 100644 --- a/libs/conf/config.h +++ b/libs/conf/config.h @@ -1,10 +1,12 @@ /* See LICENSE file for copyright and license details. */ #include "../theme/theme.h" +#if USEX typedef struct { char *key; KeySym keysym; } KeyList; +#endif #if USEWAYLAND typedef struct { @@ -13,10 +15,12 @@ typedef struct { } WlKeyList; #endif +#if USEX typedef struct { char *mod; unsigned int modifier; } ModList; +#endif #if USEWAYLAND typedef struct { @@ -353,7 +357,6 @@ static FuncList fl[] = { { "moveprev", moveprev }, { "moveitem", moveitem }, { "paste", paste }, - { "pastesel", paste }, { "restoresel", restoresel }, { "clear", clear }, { "clearins", clearins }, @@ -391,6 +394,7 @@ static FuncList fl[] = { }; // list of modifiers that can be used in the config file +#if USEX static ModList ml[] = { { "Ctrl+Shift", ShiftMask|ControlMask }, { "Ctrl+Shift+Super", ShiftMask|ControlMask|Mod4Mask }, @@ -409,6 +413,7 @@ static ModList ml[] = { { "None", 0 }, { "0", 0 }, }; +#endif #if USEWAYLAND static WlModList wml[] = { @@ -431,6 +436,7 @@ static WlModList wml[] = { // list of keys that can be used in the config file // expand this array if you want more +#if USEX static KeyList kl[] = { { "None", 0 }, { "Space", XK_space }, @@ -532,6 +538,7 @@ static KeyList kl[] = { { "Next", XK_Next }, { "Prior", XK_Prior }, }; +#endif // list of keys that can be used in the config file // expand this array if you want more @@ -639,23 +646,18 @@ static WlKeyList wkl[] = { }; #endif +# typedef struct { char *click; unsigned int button; } ButtonType; -#if USEWAYLAND -typedef struct { - char *click; - unsigned int button; -} WlButtonType; -#endif - typedef struct { char *tclick; unsigned int click; } ClickType; +#if USEX static ButtonType btp[] = { { "Left Click", Button1 }, { "Middle Click", Button2 }, @@ -663,9 +665,10 @@ static ButtonType btp[] = { { "Scroll Up", Button4 }, { "Scroll Down", Button5 }, }; +#endif #if USEWAYLAND -static WlButtonType w_btp[] = { +static ButtonType w_btp[] = { { "Left Click", WL_Left }, { "Middle Click", WL_Middle }, { "Right Click", WL_Right }, diff --git a/libs/draw.c b/libs/draw.c index e4d5c9e..1bd54b3 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -547,12 +547,14 @@ void drawmenu_layer(void) { mh = (lines + 1) * bh - bh + 2 * menumarginv; if (!protocol) { +#if USEX if (!win) { return; } XResizeWindow(dpy, win, mw - 2 * sp - 2 * borderwidth, mh); drw_resize(drw, mw - 2 * sp - 2 * borderwidth, mh); +#endif } else { resizeclient(); } @@ -603,5 +605,7 @@ void drawmenu_layer(void) { drawcaps(mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w); } +#if USEX drw_map(drw, win, 0, 0, mw, mh); +#endif } diff --git a/libs/img.c b/libs/img.c index c91d9af..7bba09e 100644 --- a/libs/img.c +++ b/libs/img.c @@ -131,6 +131,7 @@ void drawimage(void) { } } +#if USEX void setimageopts(void) { imlib_set_cache_size(8192 * 1024); imlib_context_set_blend(1); @@ -141,6 +142,7 @@ void setimageopts(void) { imlib_context_set_colormap(cmap); imlib_context_set_drawable(win); } +#endif void createifnexist(const char *dir) { // exists, so return @@ -336,6 +338,7 @@ void jumptoindex(unsigned int index) { } void resizetoimageheight(int imageheight) { +#if USEX int omh = mh, olines = lines; lines = reallines; int wtr = 0; @@ -424,7 +427,9 @@ void resizetoimageheight(int imageheight) { } } - if (!win || omh == mh) { + if ( + !win || + omh == mh) { return; } @@ -443,5 +448,16 @@ void resizetoimageheight(int imageheight) { } drawmenu(); +#endif +} + +void store_image_vars(void) { + longestedge = MAX(imagewidth, imageheight); + + if (!imagew || !imageh || !imageg) { + imagew = imagewidth; + imageh = imageheight; + imageg = imagegaps; + } } #endif diff --git a/libs/img.h b/libs/img.h index bae9f63..714275f 100644 --- a/libs/img.h +++ b/libs/img.h @@ -7,7 +7,9 @@ #include static void setimagesize(int width, int height); +#if USEX static void setimageopts(void); +#endif static void cleanupimage(void); static void drawimage(void); static void rotateimage(void); @@ -15,6 +17,7 @@ static void flipimage(void); static void loadimage(const char *file, int *width, int *height); static void loadimagecache(const char *file, int *width, int *height); static void resizetoimageheight(int imageheight); +static void store_image_vars(void); static Imlib_Image image = NULL; #endif diff --git a/libs/libdrw/drw.c b/libs/libdrw/drw.c index 84720ae..756104e 100644 --- a/libs/libdrw/drw.c +++ b/libs/libdrw/drw.c @@ -11,6 +11,18 @@ #include "drw.h" #include "../sl/main.h" +#ifndef X11 +#define USEX 0 +#else +#define USEX 1 +#endif + +#ifndef WAYLAND +#define USEWAYLAND 0 +#else +#define USEWAYLAND 1 +#endif + void cairo_set_source_hex(cairo_t* cr, const char *col, int alpha) { unsigned int hex; @@ -23,6 +35,7 @@ void cairo_set_source_hex(cairo_t* cr, const char *col, int alpha) { cairo_set_source_rgba(cr, r, g, b, alpha / 255.0); } +#if USEX Drw *drw_create_x11(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap, int protocol) { Drw *drw = ecalloc(1, sizeof(Drw)); @@ -41,7 +54,9 @@ Drw *drw_create_x11(Display *dpy, int screen, Window root, unsigned int w, unsig return drw; } +#endif +#if USEWAYLAND Drw *drw_create_wl(int protocol) { Drw *drw = ecalloc(1, sizeof(Drw)); @@ -57,6 +72,7 @@ void drw_create_surface_wl(Drw *drw, void *data, int32_t w, int32_t h) { drw->surface = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4); drw->d = cairo_create(drw->surface); } +#endif void drw_resize(Drw *drw, unsigned int w, unsigned int h) { if (!drw) @@ -65,18 +81,21 @@ void drw_resize(Drw *drw, unsigned int w, unsigned int h) { drw->w = w; drw->h = h; +#if USEX if (drw->drawable) XFreePixmap(drw->dpy, drw->drawable); drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth); +#endif } void drw_free(Drw *drw) { - +#if USEX if (!drw->protocol) { XFreePixmap(drw->dpy, drw->drawable); XFreeGC(drw->dpy, drw->gc); } +#endif drw_font_free(drw->font); free(drw); @@ -292,10 +311,12 @@ void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) if (!drw) return; +#if USEX if (!drw->protocol) { XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); XSync(drw->dpy, False); } +#endif } unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup) { @@ -338,17 +359,21 @@ Cur * drw_cur_create(Drw *drw, int shape) { if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) return NULL; +#if USEX cur->cursor = XCreateFontCursor(drw->dpy, shape); +#endif return cur; } void drw_cur_free(Drw *drw, Cur *cursor) { +#if USEX if (!cursor) return; XFreeCursor(drw->dpy, cursor->cursor); free(cursor); +#endif } unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n, Bool markup) { diff --git a/libs/wl/wayland.h b/libs/wl/wayland.h index d54de54..4b361d7 100644 --- a/libs/wl/wayland.h +++ b/libs/wl/wayland.h @@ -33,8 +33,15 @@ typedef struct { Arg arg; } WlKey; +typedef struct { + unsigned int click; + unsigned int button; + void (*func)(Arg *arg); + Arg arg; +} WlMouse; + static WlKey wl_ckeys[256]; -static Mouse wl_cbuttons[256]; +static WlMouse wl_cbuttons[256]; #define WL_CtrlShift "CtrlShift" #define WL_CtrlShiftSuper "CtrlShiftSuper" diff --git a/libs/x11/client.c b/libs/x11/client.c index 26656d2..04a1a95 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -10,37 +10,6 @@ void hexconv(const char *hex, unsigned short *r, unsigned short *g, unsigned sho *b = col & 0xFF; } -void store_image_vars(void) { -#if USEIMAGE - longestedge = MAX(imagewidth, imageheight); - - if (!imagew || !imageh || !imageg) { - imagew = imagewidth; - imageh = imageheight; - imageg = imagegaps; - } -#endif -} - -void set_mode(void) { - if (!type) { // no typing allowed, require normal mode - mode = 0; - } - - // set default mode, must be done before the event loop or keybindings will not work - if (mode) { - curMode = 1; - allowkeys = 1; - - strcpy(modetext, instext); - } else { - curMode = 0; - allowkeys = !curMode; - - strcpy(modetext, normtext); - } -} - void create_window_x11(int x, int y, int w, int h) { XSetWindowAttributes swa; diff --git a/libs/x11/client.h b/libs/x11/client.h index ffdedae..3b052d8 100644 --- a/libs/x11/client.h +++ b/libs/x11/client.h @@ -5,6 +5,4 @@ static void create_window_x11(int x, int y, int w, int h); static void set_window_x11(void); static void set_prop_x11(void); static void resizeclient_x11(void); -static void store_image_vars(void); -static void set_mode(void); static void xinitvisual(void); diff --git a/libs/x11/inc.c b/libs/x11/inc.c index 38bfa1e..641daf9 100644 --- a/libs/x11/inc.c +++ b/libs/x11/inc.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ +#if USEX #include "xim.c" #include "key.c" #include "mouse.c" @@ -11,3 +12,4 @@ #include "init.c" #include "focus.c" #include "clipboard.c" +#endif diff --git a/libs/x11/inc.h b/libs/x11/inc.h index aa11b19..d182c6a 100644 --- a/libs/x11/inc.h +++ b/libs/x11/inc.h @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#if USEX #include "lib.h" #include "def.h" @@ -10,3 +11,4 @@ #include "mouse.h" #include "focus.h" #include "clipboard.h" +#endif diff --git a/libs/x11/key.h b/libs/x11/key.h index 27fab9b..7a75eeb 100644 --- a/libs/x11/key.h +++ b/libs/x11/key.h @@ -22,5 +22,4 @@ static void grabkeyboard_x11(void); static void getcapsstate(void); static Key ckeys[256]; -static char capstext[16]; static Key hkeys[1] = { { -1, Ctrl|Alt|Shift, XK_Delete, quit, {0} } }; diff --git a/libs/x11/mouse.h b/libs/x11/mouse.h index cdf352f..629305b 100644 --- a/libs/x11/mouse.h +++ b/libs/x11/mouse.h @@ -1,19 +1,5 @@ /* See LICENSE file for copyright and license details. */ -// clicks -enum { - ClickWindow, - ClickPrompt, - ClickInput, - ClickLArrow, - ClickItem, - ClickSelItem, - ClickRArrow, - ClickNumber, - ClickCaps, - ClickMode, -}; - typedef struct { unsigned int click; unsigned int button; diff --git a/meson.build b/meson.build index 2350a57..0fccbc0 100644 --- a/meson.build +++ b/meson.build @@ -14,8 +14,6 @@ project_source_files = [ ] project_dependencies = [ - dependency('x11'), - dependency('xrender'), dependency('cairo'), dependency('pango'), dependency('pangocairo'), @@ -38,6 +36,12 @@ build_args = [ '-Wno-sign-compare', ] +if get_option('x11') + project_dependencies += [ dependency('x11') ] + project_dependencies += [ dependency('xrender') ] + build_args += [ '-DX11' ] +endif + if get_option('wayland') project_dependencies += [ dependency('wayland-client') ] project_dependencies += [ dependency('wayland-scanner') ] @@ -53,7 +57,7 @@ if get_option('wayland') run_command('scripts/make/generate-headers.sh', check : false) endif -if get_option('imlib2') and get_option('openssl') +if get_option('imlib2') and get_option('openssl') and get_option('x11') project_dependencies += [ dependency('imlib2') ] project_dependencies += [ dependency('openssl') ] build_args += [ '-DIMAGE' ] @@ -64,7 +68,7 @@ if get_option('fribidi') build_args += [ '-DRTL' ] endif -if get_option('xinerama') +if get_option('xinerama') and get_option('x11') project_dependencies += [ dependency('xinerama') ] build_args += [ '-DXINERAMA' ] endif diff --git a/meson.options b/meson.options index 8129f7a..a70b01f 100644 --- a/meson.options +++ b/meson.options @@ -5,6 +5,20 @@ option( description : 'Enable Wayland support' ) +option( + 'x11', + type : 'boolean', + value : true, + description : 'Enable X11 support' +) + +option( + 'xinerama', + type : 'boolean', + value : true, + description : 'Enable multi-monitor support using libXinerama' +) + option( 'imlib2', type : 'boolean', @@ -39,10 +53,3 @@ option( value : true, description : 'Enable configuration file support' ) - -option( - 'xinerama', - type : 'boolean', - value : true, - description : 'Enable multi-monitor support using libXinerama' -) diff --git a/mouse.h b/mouse.h index c3f47ea..f8c1321 100644 --- a/mouse.h +++ b/mouse.h @@ -6,6 +6,7 @@ */ /* Only applies to X11 */ +#if USEX static Mouse buttons[] = { { ClickInput, Button1, clear, {0} }, { ClickPrompt, Button1, clear, {0} }, @@ -13,10 +14,11 @@ static Mouse buttons[] = { { ClickNumber, Button1, viewhist, {0} }, { ClickSelItem, Button1, NULL, {0} }, }; +#endif /* Only applies to Wayland */ #if USEWAYLAND -static Mouse wl_buttons[] = { +static WlMouse wl_buttons[] = { { ClickInput, WL_Left, clear, {0} }, { ClickPrompt, WL_Left, clear, {0} }, { ClickMode, WL_Left, switchmode, {0} }, diff --git a/scripts/make/build.sh b/scripts/make/build.sh index a400ef7..232d8d1 100755 --- a/scripts/make/build.sh +++ b/scripts/make/build.sh @@ -14,19 +14,13 @@ loadconf() { [ ! -f spmenu.c ] && printf "You're probably in the wrong directory.\n" && exit 1 [ -x "buildconf" ] && [ ! -x "buildconf_dev" ] && source buildconf [ -x "buildconf_dev" ] && source buildconf_dev - - # mandatory deps - [ "$freetype" = "false" ] && printf "Freetype not found. Install it.\n" && exit 1 - [ "$openssl" = "false" ] && [ "$imlib2" = "true" ] && printf "OpenSSL not found. Install it.\n" && exit 1 - [ "$xrender" = "false" ] && printf "libXrender not found. Install it.\n" && exit 1 - [ "$x11" = "false" ] && printf "libX11 not found. Install it.\n" && exit 1 - [ "$xft" = "false" ] && printf "libXft not found. Install it.\n" && exit 1 } build() { [ ! -f "meson.build" ] && printf "meson.build does not exist.\n" && exit 1 [ "$gen_manual" != "false" ] && [ -x "$(command -v pandoc)" ] && scripts/make/generate-docs.sh [ -z "$wayland" ] && wayland=true + [ -z "$x11" ] && x11=true cp -f meson.build meson.build.orig @@ -45,8 +39,9 @@ build() { -Dopenssl="$openssl" \ -Dlibconfig="$libconfig" \ -Dwayland="$wayland" \ + -Dx11="$x11" \ --prefix "$prefix" \ - build + build || exit 1 else meson setup \ -Dxresources="$xresources" $STATIC \ @@ -56,8 +51,9 @@ build() { -Dopenssl="$openssl" \ -Dlibconfig="$libconfig" \ -Dwayland="$wayland" \ + -Dx11="$x11" \ --prefix "$prefix" \ - build + build || exit 1 fi ninja -C build diff --git a/spmenu.c b/spmenu.c index e0c1846..b4d0b71 100644 --- a/spmenu.c +++ b/spmenu.c @@ -1,15 +1,4 @@ /* spmenu - fancy dynamic menu - * - * If you're looking for functions used to draw text, see 'libs/draw.c' - * If you're looking for wrapper functions used inside the draw functions, see 'libs/libdrw/drw.c' - * If you're looking for functions used to draw images, see 'libs/img.c' - * If you're looking for the .Xresources array, see 'libs/x11/xresources.h' - * - * You don't need to edit spmenu.c if you aren't making big changes to the software. - * - * After making changes, run `./build.sh` to attempt to build the software. - * `scripts/make/generate-docs.sh` will generate a man page from 'docs/docs.md', which is a Markdown document. Run this before commiting. - * * See LICENSE file for copyright and license details. */ #include @@ -71,6 +60,13 @@ #define USEWAYLAND 1 #endif +// check if we should enable X11 support +#ifndef X11 +#define USEX 0 +#else +#define USEX 1 +#endif + // include fribidi used for right to left language support #if USERTL #include @@ -109,7 +105,9 @@ static char text[BUFSIZ] = ""; static char numbers[NUMBERSBUFSIZE] = ""; // keybinds +#if USEX static int numlockmask = 0; +#endif static int capslockstate = 0; static int bh, mw, mh; // height of each item, menu width, menu height @@ -133,8 +131,10 @@ static unsigned int sel_size = 0; static int protocol_override = 0; static int itemn = 0; // item number +#if USEX static char *embed; // X11 embed static int screen; // screen +#endif // item struct struct item { @@ -184,10 +184,12 @@ static int ignoreconfmouse = 0; // same for mouse static int ignoreglobalmouse = 0; // same for mouse // colors +#if USEX static int useargb; static int depth; static Visual *visual; static Colormap cmap; +#endif static Drw *drw; // declare functions @@ -197,10 +199,13 @@ static void recalculatenumbers(void); static void insert(const char *str, ssize_t n); static void cleanup(void); static void navigatehistfile(int dir); +#if USEX static void pastesel(void); +static void grabfocus(void); +#endif static void resizeclient(void); static void get_width(void); -static void grabfocus(void); +static void set_mode(void); static void handle(void); static void appenditem(struct item *item, struct item **list, struct item **last); static int max_textw(void); @@ -214,11 +219,26 @@ static size_t listsize; static int listcount; static int listchanged = 0; +// clicks +enum { + ClickWindow, + ClickPrompt, + ClickInput, + ClickLArrow, + ClickItem, + ClickSelItem, + ClickRArrow, + ClickNumber, + ClickCaps, + ClickMode, +}; + // user configuration #include "options.h" #include "keybinds.h" #include "mouse.h" +static char capstext[16]; static char *fonts[] = { font }; // color array @@ -361,9 +381,11 @@ void cleanup(void) { // free drawing and close the display drw_free(drw); +#if USEX if (!protocol) { cleanup_x11(dpy); } +#endif free(sel_index); } @@ -385,9 +407,11 @@ char * cistrstr(const char *h, const char *n) { return NULL; } +#if USEX void grabfocus(void) { grabfocus_x11(); } +#endif void insert(const char *str, ssize_t n) { if (strlen(text) + n > sizeof text - 1) @@ -423,20 +447,24 @@ size_t nextrune(int inc) { return n; } +#if USEX void pastesel(void) { if (!protocol) { pastesel_x11(); } } +#endif void resizeclient(void) { #if USEWAYLAND if (protocol) { resizeclient_wl(&state); } else { +#if USEX resizeclient_x11(); +#endif } -#else +#elif USEX resizeclient_x11(); #endif } @@ -445,8 +473,28 @@ void get_width(void) { inputw = mw / 3; } +void set_mode(void) { + if (!type) { // no typing allowed, require normal mode + mode = 0; + } + + // set default mode, must be done before the event loop or keybindings will not work + if (mode) { + curMode = 1; + allowkeys = 1; + + strcpy(modetext, instext); + } else { + curMode = 0; + allowkeys = !curMode; + + strcpy(modetext, normtext); + } +} + void handle(void) { if (!protocol) { +#if USEX handle_x11(); if (!drw_font_create(drw, fonts, LENGTH(fonts))) { @@ -454,7 +502,9 @@ void handle(void) { } loadhistory(); // read history entries +#if USEX store_image_vars(); +#endif // fast (-f) means we grab keyboard before reading standard input if (fast && !isatty(0)) { @@ -470,10 +520,13 @@ void handle(void) { init_appearance(); // init colorschemes by reading arrays setupdisplay_x11(); // set up display and create window eventloop_x11(); // function is a loop which checks X11 events and calls other functions accordingly +#endif #if USEWAYLAND } else { loadhistory(); +#if USEIMAGE store_image_vars(); +#endif // Disable some X11 only features menupaddingv = menupaddingh = 0;