Compare commits

..

3 commits

72 changed files with 161 additions and 808 deletions

14
.gitignore vendored
View file

@ -7,12 +7,12 @@ spmenu
spmenu-*[.]PKGBUILD
buildconf*
build
./*.ebuild*
*.ebuild*
PKGBUILD
src/wl/wlr-layer-shell-unstable-v1-client-protocol.h
src/wl/wlr-layer-shell-unstable-v1-protocol.c
src/wl/xdg-output-unstable-v1-protocol.c
src/wl/xdg-output-unstable-v1-client-protocol.h
src/wl/xdg-shell-client-protocol.h
src/wl/xdg-shell-protocol.c
libs/wl/wlr-layer-shell-unstable-v1-client-protocol.h
libs/wl/wlr-layer-shell-unstable-v1-protocol.c
libs/wl/xdg-output-unstable-v1-protocol.c
libs/wl/xdg-output-unstable-v1-client-protocol.h
libs/wl/xdg-shell-client-protocol.h
libs/wl/xdg-shell-protocol.c

View file

@ -11,7 +11,7 @@ MIT/X Consortium License
© 2013 Jari Vetoniemi <mailroxas@gmail.com>
© 2014-2022 Hiltjo Posthuma <hiltjo@codemadness.org>
© 2015-2019 Quentin Rameau <quinq@fifth.space>
© 2021-2024 speedie <speedie@speedie.site>
© 2021-2023 speedie <speedie@speedie.site>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),

View file

@ -102,9 +102,8 @@ Configure the build by running these commands:
`mkdir -p build/ # Create a build/ directory, Meson will use this as the working
directory`
`meson setup build --prefix=/usr # This will check to make sure all
dependencies are found. If you're recompiling you may want to pass
--reconfigure as an argument`
`meson setup build # This will check to make sure all dependencies are found.
If you're recompiling you may want to pass --reconfigure as an argument`
This is where you can enable/disable certain features, as well as set
compiler options.
@ -142,7 +141,7 @@ directory**. If you want to generate a pacman package, run
When creating a release, do the following:
1. Bump version in meson.build and src/libspmenu/meson.build (optional)
1. Bump version in meson.build (optional)
2. Run `scripts/spmenu_make docs`. This will generate new documentation.
3. `git commit -a` to bump version
4. Run `scripts/spmenu_make dist`. This will generate a tarball, along

View file

@ -1,92 +0,0 @@
/* binds-vim.conf
*
* This is a binds.conf file which replaces the spmenu dmenu like bindings with Vim inspired keybinds/
* It is included as an option for more advanced users, or those who like Vim style bindings, because it reenables normal mode.
*/
bind = {
/* Mouse bindings
*
* See https://spmenu.speedie.site/Configurable+keybindings for a list of valid options.
*/
mouse = (
/* Click Button Function Argument */
{ click = "ClickInput"; button = "Left Click"; function = "clear"; argument = "0"; }, // Left click on input: Clear the input
{ click = "ClickPrompt"; button = "Left Click"; function = "clear"; argument = "0"; }, // Left click on prompt: Clear the input
{ click = "ClickMode"; button = "Left Click"; function = "switchmode"; argument = "0"; }, // Left click on the mode indicator: Toggle mode
{ click = "ClickNumber"; button = "Left Click"; function = "viewhist"; argument = "0"; }, // Click on the match count: Toggle viewing history buffer
{ click = "ClickItem"; button = "Left Click"; function = "selecthover"; argument = "0"; }, // Left click on an item: Select it
{ click = "ClickItem"; button = "Right Click"; function = "markhover"; argument = "0"; }, // Right click on an item: Mark it
{ click = "None"; button = "Scroll Up"; function = "moveprev"; argument = "0"; }, // Scroll Up: Move to the previous page
{ click = "None"; button = "Scroll Down"; function = "movenext"; argument = "0"; }, // Scroll Down: Move to the next page
{
scrolldistance = 512; // Distance to scroll for a scroll action to count. Wayland only (num)
ignoreglobalmouse = 1; // Ignore hardcoded mouse binds (0/1)
} );
/* Keys
*
* It is strongly recommended that you do NOT unbind any switchmode or quit
* function keybinds unless you know exactly what you're doing.
* If you ignore this warning and find that you can't exit spmenu,
* press Ctrl+Alt+Delete. Doing so will exit spmenu, even if no key is bound.
*
* Please note that at least on the US standard keyboard layout,
* `key` will differ if Shift is held down and the key is a number or symbol.
*
* See https://spmenu.speedie.site/Configurable+keybindings for a list of valid options.
*/
keys = (
/* Mode Modifier Key Function Argument */
{ mode = -1; modifier = "None"; key = "Enter"; function = "selectitem"; argument = "+1"; }, // Enter: Select item
{ mode = -1; modifier = "Shift"; key = "Enter"; function = "selectitem"; argument = "0"; }, // Shift+Enter: Select input
{ mode = -1; modifier = "Ctrl"; key = "Enter"; function = "markitem"; argument = "0"; }, // Ctrl+Enter: Mark input
{ mode = -1; modifier = "None"; key = "Tab"; function = "complete"; argument = "0"; }, // Tab: Tab complete
{ mode = -1; modifier = "Ctrl"; key = "v"; function = "paste"; argument = "2"; }, // Ctrl+v: Paste from clipboard
{ mode = -1; modifier = "Ctrl+Shift"; key = "v"; function = "paste"; argument = "1"; }, // Ctrl+Shift+v: Paste from selection
{ mode = -1; modifier = "None"; key = "Backspace"; function = "backspace"; argument = "0"; }, // Backspace: Backspace
{ mode = -1; modifier = "Ctrl"; key = "Backspace"; function = "deleteword"; argument = "0"; }, // Ctrl+Backspace: Delete word
{ mode = -1; modifier = "Ctrl"; key = "Left"; function = "moveword"; argument = "-1"; }, // Ctrl+Left: Move caret (cursor) one word to the left
{ mode = -1; modifier = "Ctrl"; key = "Right"; function = "moveword"; argument = "+1"; }, // Ctrl+Right: Move caret (cursor) one word to the right
{ mode = -1; modifier = "None"; key = "Left"; function = "movecursor"; argument = "-1"; }, // Left: Move caret (cursor) one character to the left
{ mode = -1; modifier = "None"; key = "Right"; function = "movecursor"; argument = "+1"; }, // Right: Move caret (cursor) one character to the right
{ mode = -1; modifier = "Ctrl"; key = "k"; function = "setlines"; argument = "+1"; }, // Ctrl+k: Increase lines by 1
{ mode = -1; modifier = "Ctrl"; key = "j"; function = "setlines"; argument = "-1"; }, // Ctrl+j: Decrease lines by 1
{ mode = -1; modifier = "Ctrl"; key = "l"; function = "setcolumns"; argument = "+1"; }, // Ctrl+l: Increase columns by 1
{ mode = -1; modifier = "Ctrl"; key = "h"; function = "setcolumns"; argument = "-1"; }, // Ctrl+h: Decrease columns by 1
{ mode = -1; modifier = "Ctrl+Shift"; key = "p"; function = "setprofile"; argument = "0"; }, // Ctrl+Shift+p: Open profile menu
{ mode = -1; modifier = "None"; key = "PrintScr"; function = "screenshot"; argument = "0"; }, // Print Screen: Screenshot spmenu
{ mode = 1; modifier = "None"; key = "Esc"; function = "switchmode"; argument = "0"; }, // Escape: Switch mode
{ mode = 1; modifier = "Ctrl"; key = "r"; function = "toggleregex"; argument = "0"; }, // Ctrl+r: Toggle regex matching
{ mode = 0; modifier = "None"; key = "i"; function = "switchmode"; argument = "0"; }, // i: Switch mode
{ mode = 0; modifier = "Ctrl"; key = "="; function = "setimgsize"; argument = "+10"; }, // Ctrl+=: Increase image size by 10
{ mode = 0; modifier = "Ctrl"; key = "-"; function = "setimgsize"; argument = "-10"; }, // Ctrl+-: Decrease image size by 10
{ mode = 0; modifier = "Shift"; key = ")"; function = "defaultimg"; argument = "0"; }, // Shift+0: Set image size to the default
{ mode = 0; modifier = "None"; key = "o"; function = "setimgpos"; argument = "+1"; }, // o: Toggle image position
{ mode = 0; modifier = "None"; key = "p"; function = "paste"; argument = "2"; }, // p: Paste from clipboard
{ mode = 0; modifier = "Ctrl"; key = "1"; function = "setimggaps"; argument = "-10"; }, // Ctrl+1: Decrease image gaps by 10
{ mode = 0; modifier = "Ctrl"; key = "2"; function = "setimggaps"; argument = "+10"; }, // Ctrl+2: Increase image gaps by 10
{ mode = 0; modifier = "None"; key = "t"; function = "toggleimg"; argument = "0"; }, // t: Toggle image
{ mode = 0; modifier = "None"; key = "q"; function = "flipimg"; argument = "1"; }, // q: Flip image horizontally
{ mode = 0; modifier = "None"; key = "w"; function = "flipimg"; argument = "0"; }, // w: Flip image vertically
{ mode = 0; modifier = "None"; key = "k"; function = "moveup"; argument = "0"; }, // k: Move up 1 item
{ mode = 0; modifier = "None"; key = "j"; function = "movedown"; argument = "0"; }, // j: Move down 1 item
{ mode = 0; modifier = "None"; key = "h"; function = "moveleft"; argument = "0"; }, // h: Move left 1 item
{ mode = 0; modifier = "None"; key = "l"; function = "moveright"; argument = "0"; }, // l: Move right 1 item
{ mode = 0; modifier = "Ctrl"; key = "u"; function = "moveup"; argument = "5"; }, // Ctrl+u: Move up 5 items
{ mode = 0; modifier = "Ctrl"; key = "d"; function = "movedown"; argument = "5"; }, // Ctrl+d: Move down 5 items
{ mode = 0; modifier = "None"; key = "u"; function = "togglehighlight"; argument = "0"; }, // u: Toggle highlighting
{ mode = 0; modifier = "Shift"; key = "h"; function = "viewhist"; argument = "0"; }, // Shift+h: Toggle viewing history buffer
{ mode = 0; modifier = "None"; key = "d"; function = "clear"; argument = "0"; }, // d: Clear the input
{ mode = 0; modifier = "Shift"; key = "d"; function = "clearins"; argument = "0"; }, // Shift+d: Clear the input and enter insert mode
{ mode = 0; modifier = "None"; key = "Esc"; function = "quit"; argument = "0"; }, // Esc: Exit
{ mode = 0; modifier = "None"; key = "g"; function = "movestart"; argument = "0"; }, // g: Move to the start
{ mode = 0; modifier = "Shift"; key = "g"; function = "moveend"; argument = "0"; }, // Shift+g: Move to the end
{ mode = 0; modifier = "Ctrl"; key = "p"; function = "navhistory"; argument = "-1"; }, // Ctrl+p: Navigate to the previous entry in the history buffer
{ mode = 0; modifier = "Ctrl"; key = "n"; function = "navhistory"; argument = "+1"; }, // Ctrl+n: Navigate to the next entry in the history buffer
{ ignoreglobalkeys = 1; // Ignore hardcoded keybinds (0/1)
forceinsertmode = 0; // Force insert mode, disabling normal mode (0/1)
} ),
};

View file

@ -283,9 +283,6 @@ in the config files.
`-sin, --show-input`
: Show input
`-spt, --show-pretext`
: Show pretext
`-spl, --show-powerline`
: Show powerline
@ -376,12 +373,6 @@ in the config files.
`-nwm, --unmanaged`
: Don't spawn spmenu as a window manager controlled client/window (X11 only)
`-gk, --grab-keyboard`
: Grab keyboard on runtime
`-ngk, --no-grab-keyboard`
: Grab keyboard on runtime
`-cf, --config-file file`
: Set config file to load to file
@ -614,7 +605,9 @@ regex can be used as well.
## Modes
There are two modes. Normal mode and Insert mode. These modes are of
course similar to Vim.
course similar to Vim. While modes are used by default, it is possible
to move all keybinds to Insert mode, restoring the original dmenu
behavior.
Normal mode is the mode spmenu starts in unless a mode argument is specified
or another mode is set in the configuration file. Note that if `forceinsertmode`

View file

@ -21,7 +21,6 @@ spmenu = {
padding-horizontal = 0; // Outer horizontal padding (px)
width = 0; // Width when X and/or Y offset is set, 0 is the default (px)
managed = 0; // Allow your window manager to manage spmenu as a window (0/1)
grabkeyboard = 1; // Grab keyboard on runtime (0/1)
alpha = 1; // Enable alpha/transparency (0/1)
x = 0; // X position offset (px)
y = 0; // Y position offset (px)
@ -384,10 +383,10 @@ spmenu = {
{ mode = -1; modifier = "Ctrl+Shift"; key = "p"; function = "setprofile"; argument = "0"; }, // Ctrl+Shift+p: Open profile menu
{ mode = -1; modifier = "Ctrl"; key = "="; function = "setimgsize"; argument = "+10"; }, // Ctrl+=: Increase image size by 10
{ mode = -1; modifier = "Ctrl"; key = "-"; function = "setimgsize"; argument = "-10"; }, // Ctrl+-: Decrease image size by 10
{ mode = -1; modifier = "None"; key = "Up"; function = "moveup"; argument = "0"; }, // Up: Move up 1 item
{ mode = -1; modifier = "None"; key = "Down"; function = "movedown"; argument = "0"; }, // Down: Move down 1 item
{ mode = -1; modifier = "None"; key = "Left"; function = "moveleft"; argument = "0"; }, // Left: Move left 1 item
{ mode = -1; modifier = "None"; key = "Right"; function = "moveright"; argument = "0"; }, // Right: Move right 1 item
{ mode = -1; modifier = "None"; key = "Up"; function = "moveup"; argument = "0"; }, // k: Move up 1 item
{ mode = -1; modifier = "None"; key = "Down"; function = "movedown"; argument = "0"; }, // j: Move down 1 item
{ mode = -1; modifier = "None"; key = "Left"; function = "moveleft"; argument = "0"; }, // h: Move left 1 item
{ mode = -1; modifier = "None"; key = "Right"; function = "moveright"; argument = "0"; }, // l: Move right 1 item
{ mode = -1; modifier = "Ctrl"; key = "u"; function = "moveup"; argument = "5"; }, // Ctrl+u: Move up 5 items
{ mode = -1; modifier = "Ctrl"; key = "d"; function = "movedown"; argument = "5"; }, // Ctrl+d: Move down 5 items
{ mode = -1; modifier = "Ctrl"; key = "h"; function = "viewhist"; argument = "0"; }, // Ctrl+h: Toggle viewing history buffer

View file

@ -564,7 +564,7 @@ void defaultimg(Arg *arg) {
}
void setlines(Arg *arg) {
if (!overridelines || (hideprompt && hideinput && hidemode && hidematchcount && hidecaps)) return;
if (!overridelines) return;
insert(NULL, 0 - sp.cursor);
selecteditem = currentitem = matches;
@ -587,7 +587,7 @@ void setlines(Arg *arg) {
}
void setcolumns(Arg *arg) {
if (!overridecolumns || (hideprompt && hideinput && hidemode && hidematchcount && hidecaps)) return;
if (!overridecolumns) return;
columns += arg->i;

View file

@ -181,10 +181,6 @@ void readargs(int argc, char *argv[]) {
managed = 1;
} else if (!strcmp(argv[i], "-nwm") || (!strcmp(argv[i], "--unmanaged"))) { // don't display as managed wm window
managed = 0;
} else if (!strcmp(argv[i], "-gk") || (!strcmp(argv[i], "--grab-keyboard"))) { // grab keyboard
grabkeyboard = 1;
} else if (!strcmp(argv[i], "-ngk") || (!strcmp(argv[i], "--no-grab-keyboard"))) { // don't grab keyboard
grabkeyboard = 0;
} else if (!strcmp(argv[i], "-na") || (!strcmp(argv[i], "--no-alpha"))) { // disable alpha
alpha = 0;
} else if (!strcmp(argv[i], "-a") || (!strcmp(argv[i], "--alpha"))) { // alpha
@ -228,15 +224,13 @@ void readargs(int argc, char *argv[]) {
} else if (!strcmp(argv[i], "-hpr") || (!strcmp(argv[i], "--hide-prompt"))) { // hide prompt
hideprompt = 1;
} else if (!strcmp(argv[i], "-hpt") || (!strcmp(argv[i], "--hide-pretext"))) { // hide pretext
hidepretext = 1;
hideprompt = 1;
} else if (!strcmp(argv[i], "-hpl") || (!strcmp(argv[i], "--hide-powerline"))) { // hide powerline
hidepowerline = 1;
} else if (!strcmp(argv[i], "-hip") || (!strcmp(argv[i], "--hide-input"))) { // hide input
} else if (!strcmp(argv[i], "-hin") || (!strcmp(argv[i], "--hide-input"))) { // hide input
hideinput = 1;
} else if (!strcmp(argv[i], "-spr") || (!strcmp(argv[i], "--show-prompt"))) { // show prompt
hideprompt = 0;
} else if (!strcmp(argv[i], "-spt") || (!strcmp(argv[i], "--show-pretext"))) { // show pretext
hidepretext = 0;
} else if (!strcmp(argv[i], "-spl") || (!strcmp(argv[i], "--show-powerline"))) { // show prompt
hidepowerline = 0;
} else if (!strcmp(argv[i], "-sin") || (!strcmp(argv[i], "--show-input"))) { // show input
@ -708,7 +702,6 @@ void usage(int status) {
"spmenu -sra, --show-right-arrow Show right arrow\n"
"spmenu -sit, --show-item Show items\n"
"spmenu -spr, --show-prompt Show prompt\n"
"spmenu -spt, --show-pretext Show pretext\n"
"spmenu -sin, --show-input Show input\n"
"spmenu -spl, --show-powerline Show powerline\n"
"spmenu -sc, --show-caret, --show-cursor Show caret\n"
@ -748,19 +741,6 @@ void usage(int status) {
fputs(
"spmenu -wm, --managed, --x11-client Spawn spmenu as a window manager controlled client/window (X11 only)\n"
"spmenu -nwm, --unmanaged Don't spawn spmenu as a window manager controlled client/window (X11 only)\n"
"spmenu -gk, --grab-keyboard Grab keyboard on runtime\n"
"spmenu -ngk, --no-grab-keyboard Don't grab keyboard on runtime\n"
"spmenu -cf, --config-file <file> Set config file to load to <file>\n"
"spmenu -lcfg, --load-config Load spmenu configuration (~/.config/spmenu/spmenu.conf)\n"
"spmenu -ncfg, --no-load-config Don't load spmenu configuration (~/.config/spmenu/spmenu.conf)\n"
"spmenu -bf, --bind-file <file> Exclusively load binds from <file>\n"
"spmenu -lbi, --load-binds Load spmenu binds (~/.config/spmenu/binds.conf)\n"
"spmenu -nlbi, --no-load-binds Don't load spmenu binds (~/.config/spmenu/binds.conf)\n"
"spmenu -tm, --theme <theme> Load theme <theme>\n"
"spmenu -ltm, --load-theme Load theme\n"
"spmenu -nltm, --no-load-theme Don't load theme\n"
"spmenu -x11, --x11 Run spmenu in X11 mode\n"
"spmenu -wl, --wayland Run spmenu in Wayland mode\n"
"spmenu -cf, --config-file <file> Set config file to load to <file>\n"
"spmenu -lcfg, --load-config Load spmenu configuration (~/.config/spmenu/spmenu.conf)\n"
"spmenu -ncfg, --no-load-config Don't load spmenu configuration (~/.config/spmenu/spmenu.conf)\n"

View file

@ -286,7 +286,6 @@ void conf_init(void) {
config_setting_lookup_int(conf, "width", &menuwidth); // spmenu.window.width
config_setting_lookup_int(conf, "border", &borderwidth); // spmenu.window.border
config_setting_lookup_int(conf, "managed", &managed); // spmenu.window.managed
config_setting_lookup_int(conf, "grabkeyboard", &grabkeyboard); // spmenu.window.grabkeyboard
config_setting_lookup_int(conf, "monitor", &mon); // spmenu.window.monitor
config_setting_lookup_int(conf, "alpha", &alpha); // spmenu.window.alpha

View file

@ -468,7 +468,7 @@ int drawinput(int x, int y, int w) {
fh = sp.bh - sp.lrpad / 4;
}
if (passwd && !hideinput) {
if (passwd) {
censort = ecalloc(1, sizeof(tx.text));
for (int i = 0; i < strlen(tx.text); i++)
@ -481,7 +481,7 @@ int drawinput(int x, int y, int w) {
free(censort);
} else if (!passwd) {
if (strlen(tx.text) && !hideinput) {
if (strlen(tx.text)) {
char ptext[BUFSIZ];
char *p;
@ -500,16 +500,16 @@ int drawinput(int x, int y, int w) {
curpos = TEXTW(ptext) - TEXTW(&ptext[sp.cursor]);
} else if (pretext != NULL) {
if (hidepretext) {
pretext = "";
}
if (hidepretext) {
pretext = "";
}
apply_fribidi(pretext);
draw_text(draw, x + fw, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : pretext, 0, pango_pretext ? True : False, col_pretextfg, col_pretextbg, alpha_pretextfg, alpha_pretextbg);
}
}
if ((curpos += sp.lrpad / 2 - 1) < w && !hidecaret && !hideinput) {
if ((curpos += sp.lrpad / 2 - 1) < w && !hidecaret) {
curpos += fp;
draw_rect(draw, x + curpos, 2 + (sp.bh - fh) / 2 + y, fw, fh - 4, 1, 0, col_caretfg, col_caretbg, alpha_caretfg, alpha_caretbg);
}
@ -736,8 +736,10 @@ void drawmenu_layer(void) {
x = drawprompt(x, y + (nh ? lines ? itemposition ? (sp.mh - sp.bh) : 0 : 0 : 0), w);
}
w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw;
x = drawinput(x, y + (nh ? lines ? itemposition ? (sp.mh - sp.bh) : 0 : 0 : 0), w);
if (!hideinput) {
w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw;
x = drawinput(x, y + (nh ? lines ? itemposition ? (sp.mh - sp.bh) : 0 : 0 : 0), w);
}
// draw the items, this function also calls drawrarrow() and drawlarrow()
if (!hideitem) {

View file

@ -404,7 +404,7 @@ void draw_set_img(Draw_t *draw, void *data, int w, int h) {
}
void draw_img(Draw_t *draw, int x, int y) {
if (!draw || !draw->img_surface) {
if (!draw) {
return;
}

View file

@ -362,11 +362,11 @@ void resizetoimageheight_x11(int imageheight) {
if (menuposition == 2) { // centered
sp.mw = MIN(MAX(max_textw() + sp.promptw, centerwidth), mo.output_width);
x = mo.output_xpos + ((mo.output_width - sp.mw) / 2 + xpos);
y = mo.output_ypos + ((mo.output_height - sp.mh) / 2 - ypos);
x = (mo.output_width - sp.mw) / 2 + xpos;
y = (mo.output_height - sp.mh) / 2 - ypos;
} else { // top or bottom
x = mo.output_xpos + xpos;
y = mo.output_ypos + menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos);
x = xpos;
y = menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos);
sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width);
}
@ -437,9 +437,9 @@ void resizetoimageheight_wl(int imageheight) {
drawmenu();
wl_surface_set_buffer_scale(state.surface, 1);
wl_surface_attach(state.surface, state.buffer, 0, 0);
wl_surface_damage(state.surface, 0, 0, state.width, state.height);
wl_surface_commit(state.surface);
wl_surface_attach(state.surface, state.buffer, 0, 0);
wl_surface_damage(state.surface, 0, 0, state.width, state.height);
wl_surface_commit(state.surface);
}
#endif

View file

@ -12,7 +12,6 @@ static int loadtheme = 1; /* Load theme (~/.config/spmenu/them
static int loadbinds = 1; /* Load keybind file (~/.config/spmenu/binds.conf) on runtime */
static int mon = -1; /* Monitor to run spmenu on */
static int managed = 0; /* Let your window manager manage spmenu? */
static int grabkeyboard = 1; /* Grab keyboard/general input */
/* Wayland options */
static int scrolldistance = 512; /* Distance to scroll for a scroll action to count */

View file

@ -51,7 +51,7 @@ void handle_wl(void) {
anchor_layer(&state, menuposition);
set_exclusive_zone(&state, -1);
set_keyboard(&state, grabkeyboard ? 1 : 0);
set_keyboard(&state, 1);
add_layer_listener(&state);
set_visible_layer(&state);

View file

@ -20,7 +20,7 @@ void create_window_x11(int x, int y, int w, int h) {
ExposureMask | // mapping the drawing
KeyPressMask | // keypresses
VisibilityChangeMask | // whether or not client is visible
ButtonPressMask | // see buttonpress in mouse.c for usage
ButtonPressMask | // see buttonpress in libs/mouse.c for usage
PointerMotionMask; // we need pointer for selecting entries using the mouse
// create client
@ -94,11 +94,11 @@ void resizeclient_x11(void) {
if (menuposition == 2) { // centered
sp.mw = MIN(MAX(max_textw() + sp.promptw, centerwidth), mo.output_width);
x = mo.output_xpos + ((mo.output_width - sp.mw) / 2 + xpos);
y = mo.output_ypos + ((mo.output_height - sp.mh) / 2 - ypos);
x = (mo.output_width - sp.mw) / 2 + xpos;
y = (mo.output_height - sp.mh) / 2 - ypos;
} else { // top or bottom
x = mo.output_xpos + xpos;
y = mo.output_ypos + menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos);
x = xpos;
y = menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos);
sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width);
}

View file

@ -51,8 +51,6 @@ void setupdisplay_x11(void) {
mo.output_width = info[i].width;
mo.output_height = info[i].height;
mo.output_xpos = info[i].x_org;
mo.output_ypos = info[i].y_org;
XFree(info);
} else
@ -70,15 +68,14 @@ void setupdisplay_x11(void) {
if (menuposition == 2) { // centered
sp.mw = MIN(MAX(max_textw() + sp.promptw, centerwidth), mo.output_width);
x = mo.output_xpos + ((mo.output_width - sp.mw) / 2 + xpos);
y = mo.output_ypos + ((mo.output_height - sp.mh) / 2 - ypos);
x = (mo.output_width - sp.mw) / 2 + xpos;
y = (mo.output_height - sp.mh) / 2 - ypos;
} else { // top or bottom
x = mo.output_xpos + xpos;
y = mo.output_ypos + menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos);
x = xpos;
y = menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos);
sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width);
}
// create menu window and set properties for it
create_window_x11(
x + sp.sp,

View file

@ -1,15 +1,15 @@
project(
'spmenu',
'c',
version : '"3.5.0"',
version : '"3.4"',
default_options : ['warning_level=3']
)
cc = meson.get_compiler('c')
project_source_files = [
'src/draw/draw.c',
'src/spmenu.c',
'libs/draw/draw.c',
'spmenu.c',
]
project_dependencies = [
@ -40,12 +40,12 @@ if get_option('wayland')
run_command('protocols/generate.sh', check : true)
project_source_files += [ 'src/wl/wlr-layer-shell-unstable-v1-client-protocol.h' ]
project_source_files += [ 'src/wl/wlr-layer-shell-unstable-v1-protocol.c' ]
project_source_files += [ 'src/wl/xdg-output-unstable-v1-client-protocol.h' ]
project_source_files += [ 'src/wl/xdg-output-unstable-v1-protocol.c' ]
project_source_files += [ 'src/wl/xdg-shell-client-protocol.h' ]
project_source_files += [ 'src/wl/xdg-shell-protocol.c' ]
project_source_files += [ 'libs/wl/wlr-layer-shell-unstable-v1-client-protocol.h' ]
project_source_files += [ 'libs/wl/wlr-layer-shell-unstable-v1-protocol.c' ]
project_source_files += [ 'libs/wl/xdg-output-unstable-v1-client-protocol.h' ]
project_source_files += [ 'libs/wl/xdg-output-unstable-v1-protocol.c' ]
project_source_files += [ 'libs/wl/xdg-shell-client-protocol.h' ]
project_source_files += [ 'libs/wl/xdg-shell-protocol.c' ]
build_args += [ '-DWAYLAND' ]
endif
@ -100,6 +100,7 @@ endif
if get_option('docs')
install_data(sources : 'docs/spmenu.conf', install_dir : 'share/spmenu')
install_data(sources : 'docs/binds-vim.conf', install_dir : 'share/spmenu')
install_data(sources : 'docs/spmenu_run.desktop', install_dir : 'share/applications')
install_data(sources : 'docs/spmenu_desktop.desktop', install_dir : 'share/applications')
install_data(sources : 'docs/spmenu_filemanager.desktop', install_dir : 'share/applications')

View file

@ -1,44 +0,0 @@
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit toolchain-funcs meson
DESCRIPTION="C++ library for spmenu"
HOMEPAGE="https://spmenu.speedie.site"
if [[ ${PV} == 9999 ]]; then
inherit git-r3
EGIT_REPO_URI="https://git.speedie.site/speedie/spmenu"
else
KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ppc ~ppc64 ~riscv ~x86"
SRC_URI="https://ls.speedie.site/spmenu-${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/spmenu-${PV}"
fi
EMESON_SOURCE="${S}/src/libspmenu"
LICENSE="MIT"
SLOT="0"
IUSE=""
RDEPEND="x11-misc/spmenu"
DEPEND="${RDEPEND}"
BDEPEND="virtual/pkgconfig"
src_prepare() {
default
}
src_configure() {
meson_src_configure
}
src_compile() {
meson_src_compile
}
src_install() {
meson_install
}

View file

@ -1,7 +1,6 @@
# Maintainer: speedie <speedie@speedie.site>
pkgname=('spmenu' 'libspmenu')
pkgbase="spmenu"
pkgname=spmenu
pkgver=VERSION
pkgrel=1
pkgdesc="Fancy dynamic menu for X11 and Wayland, compatible with dmenu!"
@ -30,13 +29,15 @@ makedepends=(
optdepends=(
'wl-clipboard: Clipboard support on Wayland'
'libspmenu: C++ library for spmenu'
)
provides=($pkgname)
conflicts=($pkgname)
source=(
"$pkgbase-$pkgver.tar.gz"
"$pkgbase-$pkgver.tar.gz.sig"
"$pkgname-$pkgver.tar.gz"
"$pkgname-$pkgver.tar.gz.sig"
#"https://ls.speedie.site/releases/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz"
#"https://ls.speedie.site/releases/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz.sig"
)
md5sums=(
@ -49,19 +50,15 @@ sha256sums=(
'SKIP'
)
package_spmenu() {
cd "$pkgbase-$pkgver"
build(){
cd $pkgname-$pkgver
mkdir -p build/
meson setup --reconfigure --prefix=${pkgdir}/usr build
cd build/
meson install
ninja -C build
}
package_libspmenu() {
pkgdesc="C++ library for spmenu"
optdepends=()
package() {
cd "$pkgname-$pkgver"
cd "$pkgbase-$pkgver/src/libspmenu"
meson setup --reconfigure --prefix=${pkgdir}/usr build
cd build/
meson install
meson install -C build
}

View file

@ -33,7 +33,6 @@ RDEPEND="
imlib2? ( media-libs/imlib2 )
ssl? ( dev-libs/openssl )
fribidi? ( dev-libs/fribidi )
config? ( dev-libs/libconfig )
x11-libs/pango
x11-libs/cairo
"

View file

@ -142,9 +142,9 @@ print_desktop_list() {
mapfile -t it_display < "$DISPLAYFILE"
mapfile -t it_only < "$ONLYFILE"
mapfile -t it_comment < "$COMMENTFILE"
# TODO test this code if it mimic old sorting behavior
d_print_array | \
sort -k 2 "${sort_args[@]}" | \
sort "${sort_args[@]}" | \
uniq "${uniq_args[@]}" | \
grep -vE "$HIDDEN_ENTRY_KEYWORDS" | \
grep -E "$ENTRY_KEYWORDS"

View file

@ -11,20 +11,19 @@ wayland=${wayland:-true}
x11=${x11:-true}
regex=${regex:-true}
fifo=${fifo:-true}
library=${library:-true}
prefix="${prefix:-/usr}"
reconfigure=${reconfigure:-true}
reconfigure=${reconfigure:-false}
static=${static:-false}
clean() {
clean_headers
rm -rf ./*.zst* ./*.tar* ./*.sig* *.PKGBUILD *.ebuild *.ebuild* build/ PKGBUILD
rm -rf ./*.zst* ./*.tar* ./*.sig* *.PKGBUILD *.ebuild *.ebuild* build/
}
check_correct_dir() {
[ ! -f "src/spmenu.c" ] && printf "Incorrect directory.\n" && exit 1
[ ! -f "spmenu.c" ] && printf "Incorrect directory.\n" && exit 1
}
gen_arg_list() {
@ -66,42 +65,42 @@ headers() {
wayland-scanner \
client-header \
protocols/wlr-layer-shell-unstable-v1.xml \
src/wl/wlr-layer-shell-unstable-v1-client-protocol.h
libs/wl/wlr-layer-shell-unstable-v1-client-protocol.h
wayland-scanner \
client-header \
protocols/xdg-shell.xml \
src/wl/xdg-shell-client-protocol.h
libs/wl/xdg-shell-client-protocol.h
wayland-scanner \
client-header \
protocols/xdg-output-unstable-v1.xml \
src/wl/xdg-output-unstable-v1-client-protocol.h
libs/wl/xdg-output-unstable-v1-client-protocol.h
wayland-scanner \
public-code \
protocols/wlr-layer-shell-unstable-v1.xml \
src/wl/wlr-layer-shell-unstable-v1-protocol.c
libs/wl/wlr-layer-shell-unstable-v1-protocol.c
wayland-scanner \
public-code \
protocols/xdg-shell.xml \
src/wl/xdg-shell-protocol.c
libs/wl/xdg-shell-protocol.c
wayland-scanner \
public-code \
protocols/xdg-output-unstable-v1.xml \
src/wl/xdg-output-unstable-v1-protocol.c
libs/wl/xdg-output-unstable-v1-protocol.c
}
clean_headers() {
rm -f \
src/wl/xdg-output-unstable-v1-protocol.c \
src/wl/xdg-shell-protocol.c \
src/wl/wlr-layer-shell-unstable-v1-protocol.c \
src/wl/xdg-output-unstable-v1-client-protocol.h \
src/wl/xdg-shell-client-protocol.h \
src/wl/wlr-layer-shell-unstable-v1-client-protocol.h
libs/wl/xdg-output-unstable-v1-protocol.c \
libs/wl/xdg-shell-protocol.c \
libs/wl/wlr-layer-shell-unstable-v1-protocol.c \
libs/wl/xdg-output-unstable-v1-client-protocol.h \
libs/wl/xdg-shell-client-protocol.h \
libs/wl/wlr-layer-shell-unstable-v1-client-protocol.h
}
gen_pkg() {
@ -111,33 +110,25 @@ gen_pkg() {
rm -f spmenu spmenu-${version}.tar.gz spmenu-${version}.PKGBUILD *.o *zst*
mkdir -p spmenu-${version}
cp -rf \
LICENSE \
meson.build \
meson_options.txt \
spmenu.1 \
spmenu_run.1 \
spmenu_test.1 \
scripts/ \
docs/ \
src/ \
protocols/ \
packaging \
"spmenu-${version}"
LICENSE \
meson.build \
meson_options.txt \
*.c \
spmenu.1 \
spmenu_run.1 \
spmenu_test.1 \
scripts/ \
docs/ \
libs/ \
protocols/ \
packaging \
"spmenu-${version}"
tar -cf spmenu-${version}.tar spmenu-${version}
gzip spmenu-${version}.tar
rm -rf spmenu-${version}
USER="$(whoami)"
printf "Is your GPG key '$(whoami)'?\n"
select yn in "Yes" "No"; do
case $yn in
Yes) USER="$(whoami)"; break ;;
No) printf "\n> "; read -r USER; break ;;
esac
done
if [ -x "$(command -v gpg)" ]; then
gpg --detach-sign --yes --local-user "${USER}" spmenu-${version}.tar.gz
gpg --detach-sign --yes --local-user $(whoami) spmenu-${version}.tar.gz
fi
if [ -x "$(command -v md5sum)" ]; then
@ -153,20 +144,11 @@ gen_gentoo_pkg() {
[ "$(id -u)" = "0" ] && printf "Do not run as root.\n" && exit 1
version="$(grep "version : '" meson.build | awk '{ print $3 }' | sed "s/'\"//g; s/\"',//g")"
USER="$(whoami)"
printf "Is your GPG key '$(whoami)'?\n"
select yn in "Yes" "No"; do
case $yn in
Yes) USER="$(whoami)"; break ;;
No) printf "\n> "; read -r USER; break ;;
esac
done
if [ -f "packaging/spmenu.ebuild" ]; then
cp packaging/spmenu.ebuild spmenu-${version}.ebuild
if [ -x "$(command -v gpg)" ]; then
gpg --detach-sign --yes --local-user "${USER}" spmenu-${version}.ebuild
gpg --detach-sign --yes --local-user $(whoami) spmenu-${version}.ebuild
fi
if [ -x "$(command -v md5sum)" ]; then
@ -177,27 +159,12 @@ gen_gentoo_pkg() {
sha256sum spmenu-${version}.ebuild | cut -d ' ' -f 1 > spmenu-${version}.ebuild.sha256
fi
fi
if [ -f "packaging/libspmenu.ebuild" ] && [ "$library" != "false" ]; then
cp packaging/libspmenu.ebuild libspmenu-${version}.ebuild
if [ -x "$(command -v gpg)" ]; then
gpg --detach-sign --yes --local-user "${USER}" libspmenu-${version}.ebuild
fi
if [ -x "$(command -v md5sum)" ]; then
md5sum libspmenu-${version}.ebuild | cut -d ' ' -f 1 > libspmenu-${version}.ebuild.md5
fi
if [ -x "$(command -v sha256sum)" ]; then
sha256sum libspmenu-${version}.ebuild | cut -d ' ' -f 1 > libspmenu-${version}.ebuild.sha256
fi
fi
}
gen_arch_pkg() {
[ "$(id -u)" = "0" ] && printf "Do not run as root.\n" && exit 1
[ ! -x "$(command -v makepkg)" ] && printf "makepkg required for this action.\n" && exit 1
[ -f "packaging/spmenu.PKGBUILD" ] || exit 1
rm -f PKGBUILD
@ -215,42 +182,36 @@ gen_arch_pkg() {
makepkg -sfr --sign || exit 1
rm -rf pkg/ src/spmenu-${version}.tar.gz src/spmenu-${version}.tar.gz.sig src/spmenu-${version}
rm -rf src/ pkg/
mv PKGBUILD spmenu-${version}.PKGBUILD
# generate MD5 checksum
[ -x "$(command -v md5sum)" ] && \
if [ -x "$(command -v md5sum)" ]; then
md5sum spmenu-${version}-1-x86_64.pkg.tar.zst | cut -d ' ' -f 1 > spmenu-${version}-1-x86_64.pkg.tar.zst.md5
[ -x "$(command -v md5sum)" ] && \
md5sum libspmenu-${version}-1-x86_64.pkg.tar.zst | cut -d ' ' -f 1 > libspmenu-${version}-1-x86_64.pkg.tar.zst.md5
fi
# generate SHA256 checksum
[ -x "$(command -v sha256sum)" ] && \
if [ -x "$(command -v sha256sum)" ]; then
sha256sum spmenu-${version}-1-x86_64.pkg.tar.zst | cut -d ' ' -f 1 > spmenu-${version}-1-x86_64.pkg.tar.zst.sha256
[ -x "$(command -v sha256sum)" ] && \
sha256sum libspmenu-${version}-1-x86_64.pkg.tar.zst | cut -d ' ' -f 1 > libspmenu-${version}-1-x86_64.pkg.tar.zst.sha256
fi
}
generate_theme() {
declare -a color
color=()
declare -a color
read_colors() {
i=1
color=()
[ ! -f "$1" ] && printf "File does not exist.\n" && exit 1
[ "$(grep -c "" "$1")" != "18" ] && printf "Color list is not 18 lines long.\n" && exit 1
# assign colors to variables
while true; do
color[i]="$(sed -n ${i},${i}p $1)"
ccol="${color[i]}"
[ "${#ccol}" != "7" ] || [ "${ccol:0:1}" != "#" ] && color[i]="#000000"
[ "$i" = "18" ] && break
i=$((i+1))
done
}
write_array() {
cat << EOF
/* spmenu colorscheme generated from ${1:-None} */
theme = {
@ -313,6 +274,13 @@ theme = {
EOF
}
[ ! -f "$1" ] && printf "File does not exist.\n" && exit 1
[ "$(grep -c "" "$1")" != "18" ] && printf "Color list is not 18 lines long.\n" && exit 1
read_colors "$1"
write_array "$1"
}
build() {
[ -x "buildconf" ] && [ ! -x "buildconf_dev" ] && source buildconf
[ -x "buildconf_dev" ] && source buildconf_dev
@ -325,6 +293,8 @@ build() {
mkdir -p build/
chown -R $(whoami) build/ || exit 1
[ "$static" = "true" ] && STATIC="--prefer-static"
if [ "$reconfigure" = "true" ]; then
@ -361,13 +331,6 @@ build() {
[ "$cp_build" = "true" ] && cp meson.build meson.build.used
mv -f meson.build.orig meson.build
if [ "$library" != "false" ]; then
cd src/libspmenu/ || exit 1
meson setup --prefix "$prefix" build || exit 1
ninja -C build
cd ../../ || exit 1
fi
}
install() {
@ -378,14 +341,6 @@ install() {
cd .. || exit 1
[ "$reconfigure" = "true" ] && rm -rf build/
[ "$reconfigure" = "true" ] && clean_headers
if [ "$library" != "false" ]; then
cd src/libspmenu/build/ || exit 1
meson install
cd ..
[ "$reconfigure" = "true" ] && rm -rf build/
cd ../../
fi
}
help() {
@ -413,7 +368,7 @@ main() {
"dist") action="dist" ;;
"arglist") action="arglist" ;;
"pkg_arch") action="arch" ;;
"pkg_gentoo") action="gentoo" ;;
"pkg_gentoo") action="gentoo" ;;
"help") action="help" ;;
"install") action="install" ;;
"theme") action="theme" ;;
@ -435,7 +390,7 @@ main() {
"build") build ;;
"install") install ;;
"arch") gen_arch_pkg ;;
"gentoo") gen_gentoo_pkg ;;
"gentoo") gen_gentoo_pkg ;;
"theme") generate_theme "$2" ;;
"help") help ;;
"arglist") gen_arg_list ;;

View file

@ -1,5 +1,5 @@
'\" t
.\" Automatically generated by Pandoc 2.17.1.1
.\" Automatically generated by Pandoc 3.1.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
@ -15,7 +15,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "spmenu" "1" "" "3.5.0" "fancy dynamic menu"
.TH "spmenu" "1" "" "3.4" "fancy dynamic menu"
.hy
.SH spmenu
.PP
@ -311,9 +311,6 @@ Show prompt
\f[V]-sin, --show-input\f[R]
Show input
.TP
\f[V]-spt, --show-pretext\f[R]
Show pretext
.TP
\f[V]-spl, --show-powerline\f[R]
Show powerline
.TP
@ -405,12 +402,6 @@ Spawn spmenu as a window manager controlled client/window (X11 only)
Don\[cq]t spawn spmenu as a window manager controlled client/window (X11
only)
.TP
\f[V]-gk, --grab-keyboard\f[R]
Grab keyboard on runtime
.TP
\f[V]-ngk, --no-grab-keyboard\f[R]
Grab keyboard on runtime
.TP
\f[V]-cf, --config-file file\f[R]
Set config file to load to file
.TP
@ -650,6 +641,8 @@ Of course, more advanced regex can be used as well.
There are two modes.
Normal mode and Insert mode.
These modes are of course similar to Vim.
While modes are used by default, it is possible to move all keybinds to
Insert mode, restoring the original dmenu behavior.
.PP
Normal mode is the mode spmenu starts in unless a mode argument is
specified or another mode is set in the configuration file.
@ -745,7 +738,7 @@ This allows something similar to the emoji highlight patch on the
suckless website, except even more useful.
.PP
Example:
\f[V]printf \[dq]\[rs]033[0;44m\[u1F600]\[rs]033[0m Emoji highlighting\[rs]n\[dq] | spmenu --columns 1\f[R]
\f[V]printf \[dq]\[rs]033[0;44m😀\[rs]033[0m Emoji highlighting\[rs]n\[dq] | spmenu --columns 1\f[R]
.PP
It should be noted that font sequences are not yet supported.
See `SGR sequences' for more information.

View file

@ -9,9 +9,9 @@
#include <locale.h>
#include <math.h>
#include <unistd.h>
#include "main.c"
#include "libs/main.c"
#include "draw/draw.h"
#include "libs/draw/draw.h"
#ifndef VERSION
#define VERSION "unknown"
@ -76,8 +76,6 @@ struct sp {
struct mo {
int output_width; // output width
int output_height; // output height
int output_xpos; // output x position
int output_ypos; // output y position
};
#if IMAGE
@ -174,28 +172,28 @@ static char **list;
static size_t listsize;
// various headers
#include "options.h"
#include "draw.h"
#include "arg.h"
#include "libs/options.h"
#include "libs/draw.h"
#include "libs/arg.h"
#include "x11/inc.h"
#include "wl/inc.h"
#include "libs/x11/inc.h"
#include "libs/wl/inc.h"
static char *fonts[] = { font };
#include "img.c"
#include "icon.c"
#include "rtl.c"
#include "sort.c"
#include "match.c"
#include "schemes.c"
#include "stream.c"
#include "draw.c"
#include "conf/config.c"
#include "argv.c"
#include "history.c"
#include "arg.c"
#include "fifo.c"
#include "libs/img.c"
#include "libs/icon.c"
#include "libs/rtl.c"
#include "libs/sort.c"
#include "libs/match.c"
#include "libs/schemes.c"
#include "libs/stream.c"
#include "libs/draw.c"
#include "libs/conf/config.c"
#include "libs/argv.c"
#include "libs/history.c"
#include "libs/arg.c"
#include "libs/fifo.c"
#if X11
static Key keys[] = {
@ -273,8 +271,8 @@ static WlMouse wl_buttons[] = {
};
#endif
#include "x11/inc.c"
#include "wl/inc.c"
#include "libs/x11/inc.c"
#include "libs/wl/inc.c"
int is_selected(size_t index) {
for (int i = 0; i < sel_size; i++) {
@ -550,17 +548,11 @@ void handle(void) {
#endif
if (fast && !isatty(0)) {
if (grabkeyboard) {
grabkeyboard_x11();
}
grabkeyboard_x11();
readstdin();
} else {
readstdin();
if (grabkeyboard) {
grabkeyboard_x11();
}
grabkeyboard_x11();
}
set_mode();

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.17.1.1
.\" Automatically generated by Pandoc 3.1.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "spmenu_run" "1" "" "3.5.0" "$PATH/.desktop launcher and file manager"
.TH "spmenu_run" "1" "" "3.4" "$PATH/.desktop launcher and file manager"
.hy
.SH spmenu_run
.PP

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.17.1.1
.\" Automatically generated by Pandoc 3.1.2
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "spmenu_test" "1" "" "3.5.0" "spmenu test script"
.TH "spmenu_test" "1" "" "3.4" "spmenu test script"
.hy
.SH spmenu_test
.PP

View file

@ -1,231 +0,0 @@
/* libspmenu
* spmenu C++ library
*
* See LICENSE file for copyright and license details.
*/
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <array>
#include <cstring>
#include "libspmenu.h"
std::string spmenu::addArgument(std::string Argument, std::string Value) {
return " " + Argument + " \"" + Value + "\"";
}
std::string spmenu::addArgument(std::string enabledArgument, std::string disabledArgument, std::string Value) {
if (disabledArgument.empty() || enabledArgument.empty()) {
return "";
} else if (Value.compare("True") && Value.compare("true") && Value.compare("False") && Value.compare("false") && Value.compare("0") && Value.compare("1")) {
return "";
}
return " " + ((!Value.compare("True") || !Value.compare("true") || !Value.compare("1")) ? enabledArgument : disabledArgument);
}
std::string spmenu::generateArguments(spmenu::spmenuSettings *settings) {
std::string argList;
argList += (settings->promptText.empty()) ? "" : (spmenu::addArgument("--prompt", settings->promptText));
argList += (settings->preText.empty()) ? "" : (spmenu::addArgument("--pretext", settings->preText));
argList += (settings->inputText.empty()) ? "" : (spmenu::addArgument("--input", settings->inputText));
argList += (settings->normalModeText.empty()) ? "" : (spmenu::addArgument("--normal-mode-text", settings->normalModeText));
argList += (settings->insertModeText.empty()) ? "" : (spmenu::addArgument("--insert-mode-text", settings->insertModeText));
argList += (settings->capsLockOnText.empty()) ? "" : (spmenu::addArgument("--caps-lock-on-text", settings->capsLockOnText));
argList += (settings->capsLockOffText.empty()) ? "" : (spmenu::addArgument("--caps-lock-off-text", settings->capsLockOffText));
argList += (settings->leftArrowText.empty()) ? "" : (spmenu::addArgument("--left-arrow-symbol", settings->leftArrowText));
argList += (settings->rightArrowText.empty()) ? "" : (spmenu::addArgument("--right-arrow-symbol", settings->rightArrowText));
argList += (settings->lineHeight.empty()) ? "" : (spmenu::addArgument("--line-height", settings->lineHeight));
argList += (settings->centerWidth.empty()) ? "" : (spmenu::addArgument("--center-width", settings->centerWidth));
argList += (settings->Lines.empty()) ? "" : (spmenu::addArgument("--lines", settings->Lines));
argList += (settings->Columns.empty()) ? "" : (spmenu::addArgument("--columns", settings->Columns));
argList += (settings->minLines.empty()) ? "" : (spmenu::addArgument("--min-lines", settings->minLines));
argList += spmenu::addArgument("--generate-cache", "--no-generate-cache", settings->generateCache);
argList += (settings->maxCache.empty()) ? "" : (spmenu::addArgument("--max-cache", settings->maxCache));
argList += (settings->cacheDir.empty()) ? "" : (spmenu::addArgument("--cache-dir", settings->cacheDir));
argList += spmenu::addArgument("--print-index", "--no-print-index", settings->printIndex);
argList += spmenu::addArgument("--fast", "", settings->Fast);
argList += spmenu::addArgument("--incremental", "--no-incremental", settings->Incremental);
argList += spmenu::addArgument("--require-match", "--no-require-match", settings->requireMatch);
argList += spmenu::addArgument("--mark-items", "--no-mark-items", settings->markItems);
argList += spmenu::addArgument("--fuzzy", "--no-fuzzy", settings->Fuzzy);
argList += spmenu::addArgument("--regex", "--no-regex", settings->Regex);
argList += spmenu::addArgument("--password", "--no-password", settings->Password);
argList += spmenu::addArgument("--indent", "--no-indent", settings->Indent);
argList += spmenu::addArgument("--color-items", "--no-color-items", settings->colorItems);
argList += spmenu::addArgument("--sgr", "--no-sgr", settings->Sgr);
argList += spmenu::addArgument("--alpha", "--no-alpha", settings->Alpha);
argList += spmenu::addArgument("--allow-typing", "--no-allow-typing", settings->allowTyping);
argList += spmenu::addArgument("--override-lines", "--no-override-lines", settings->allowOverrideLines);
argList += spmenu::addArgument("--override-columns", "--no-override-columns", settings->allowOverrideColumns);
argList += (settings->X.empty()) ? "" : (spmenu::addArgument("--x-position", settings->X));
argList += (settings->Y.empty()) ? "" : (spmenu::addArgument("--y-position", settings->Y));
argList += (settings->W.empty()) ? "" : (spmenu::addArgument("--width", settings->W));
argList += (settings->H.empty()) ? "" : (spmenu::addArgument("--min-lines", settings->H));
argList += (settings->Preselect.empty()) ? "" : (spmenu::addArgument("--preselect", settings->Preselect));
argList += (settings->borderWidth.empty()) ? "" : (spmenu::addArgument("--border-width", settings->borderWidth));
argList += spmenu::addArgument("--sort", "--no-sort", settings->Sort);
argList += (settings->Priority.empty()) ? "" : (spmenu::addArgument("--priority", settings->Priority));
argList += spmenu::addArgument("--case-sensitive", "--case-insensitive", settings->caseSensitive);
argList += spmenu::addArgument("--normal", "--insert", settings->defaultMode);
argList += spmenu::addArgument("--hide-mode", "--show-mode", settings->hideMode);
argList += spmenu::addArgument("--hide-match-count", "--show-match-count", settings->hideMatchCount);
argList += spmenu::addArgument("--hide-left-arrow", "--show-left-arrow", settings->hideLeftArrow);
argList += spmenu::addArgument("--hide-right-arrow", "--show-right-arrow", settings->hideRightArrow);
argList += spmenu::addArgument("--hide-item", "--show-item", settings->hideItem);
argList += spmenu::addArgument("--hide-prompt", "--show-prompt", settings->hidePrompt);
argList += spmenu::addArgument("--hide-pretext", "--show-pretext", settings->hidePretext);
argList += spmenu::addArgument("--hide-input", "--show-input", settings->hideInput);
argList += spmenu::addArgument("--hide-powerline", "--show-powerline", settings->hidePowerline);
argList += spmenu::addArgument("--hide-caret", "--show-caret", settings->hideCaret);
argList += spmenu::addArgument("--hide-highlighting", "--show-highlighting", settings->hideHighlighting);
argList += spmenu::addArgument("--hide-image", "--show-image", settings->hideImage);
argList += spmenu::addArgument("--hide-caps", "--show-caps", settings->hideCaps);
argList += spmenu::addArgument("--xrdb", "--no-xrdb", settings->Xrdb);
argList += (settings->Monitor.empty()) ? "" : (spmenu::addArgument("--monitor", settings->Monitor));
argList += (settings->Embed.empty()) ? "" : (spmenu::addArgument("--embed", settings->Embed));
argList += (settings->histFile.empty()) ? "" : (spmenu::addArgument("--hist-file", settings->histFile));
argList += (settings->listFile.empty()) ? "" : (spmenu::addArgument("--list-file", settings->listFile));
argList += (settings->configFile.empty()) ? "" : (spmenu::addArgument("--config-file", settings->configFile));
argList += (settings->bindsFile.empty()) ? "" : (spmenu::addArgument("--bind-file", settings->bindsFile));
argList += (settings->themeFile.empty()) ? "" : (spmenu::addArgument("--theme-file", settings->themeFile));
argList += (settings->imageGaps.empty()) ? "" : (spmenu::addArgument("--image-gaps", settings->imageGaps));
argList += (settings->imageSize.empty()) ? "" : (spmenu::addArgument("--image-size", settings->imageSize));
argList += spmenu::addArgument("--display-image", "--display-icons", settings->imageType);
argList += spmenu::addArgument("--image-resize", "--no-image-resize", settings->imageResize);
argList += (settings->textPadding.empty()) ? "" : (spmenu::addArgument("--text-padding", settings->textPadding));
argList += (settings->verticalPadding.empty()) ? "" : (spmenu::addArgument("--vertical-padding", settings->verticalPadding));
argList += (settings->horizontalPadding.empty()) ? "" : (spmenu::addArgument("--horizontal-padding", settings->horizontalPadding));
argList += (settings->verticalMargin.empty()) ? "" : (spmenu::addArgument("--vertical-margin", settings->verticalMargin));
argList += (settings->horizontalMargin.empty()) ? "" : (spmenu::addArgument("--horizontal-margin", settings->horizontalMargin));
argList += spmenu::addArgument("--managed", "--unmanaged", settings->Managed);
argList += spmenu::addArgument("--wayland", "-x11", settings->displayProtocol);
argList += spmenu::addArgument("--load-config", "--no-load-config", settings->loadConfig);
argList += spmenu::addArgument("--load-binds", "--no-load-binds", settings->loadBinds);
argList += spmenu::addArgument("--load-theme", "--no-load-theme", settings->loadTheme);
argList += (settings->Font.empty()) ? "" : (spmenu::addArgument("--font", settings->Font));
argList += (settings->normalItemForegroundColor.empty()) ? "" : (spmenu::addArgument("--normal-item-foreground", settings->normalItemForegroundColor));
argList += (settings->normalItemBackgroundColor.empty()) ? "" : (spmenu::addArgument("--normal-item-background", settings->normalItemBackgroundColor));
argList += (settings->selectedItemForegroundColor.empty()) ? "" : (spmenu::addArgument("--selected-item-foreground", settings->selectedItemForegroundColor));
argList += (settings->selectedItemBackgroundColor.empty()) ? "" : (spmenu::addArgument("--selected-item-background", settings->selectedItemBackgroundColor));
argList += (settings->normalNextItemForegroundColor.empty()) ? "" : (spmenu::addArgument("--normal-next-item-foreground", settings->normalNextItemForegroundColor));
argList += (settings->normalNextItemBackgroundColor.empty()) ? "" : (spmenu::addArgument("--normal-next-item-background", settings->normalNextItemBackgroundColor));
argList += (settings->normalItemPriorityForegroundColor.empty()) ? "" : (spmenu::addArgument("--normal-item-priority-foreground", settings->normalItemPriorityForegroundColor));
argList += (settings->normalItemPriorityBackgroundColor.empty()) ? "" : (spmenu::addArgument("--normal-item-priority-background", settings->normalItemPriorityBackgroundColor));
argList += (settings->selectedItemPriorityForegroundColor.empty()) ? "" : (spmenu::addArgument("--selected-item-priority-foreground", settings->selectedItemPriorityForegroundColor));
argList += (settings->selectedItemPriorityBackgroundColor.empty()) ? "" : (spmenu::addArgument("--selected-item-priority-background", settings->selectedItemPriorityBackgroundColor));
argList += (settings->promptForegroundColor.empty()) ? "" : (spmenu::addArgument("--prompt-foreground", settings->promptForegroundColor));
argList += (settings->promptBackgroundColor.empty()) ? "" : (spmenu::addArgument("--prompt-background", settings->promptBackgroundColor));
argList += (settings->inputForegroundColor.empty()) ? "" : (spmenu::addArgument("--input-foreground", settings->inputForegroundColor));
argList += (settings->inputBackgroundColor.empty()) ? "" : (spmenu::addArgument("--input-background", settings->inputBackgroundColor));
argList += (settings->preTextForegroundColor.empty()) ? "" : (spmenu::addArgument("--preText-foreground", settings->preTextForegroundColor));
argList += (settings->preTextBackgroundColor.empty()) ? "" : (spmenu::addArgument("--preText-background", settings->preTextBackgroundColor));
argList += (settings->windowColor.empty()) ? "" : (spmenu::addArgument("--menu-background", settings->windowColor));
argList += (settings->normalHighlightForegroundColor.empty()) ? "" : (spmenu::addArgument("--normal-highlight-foreground", settings->normalHighlightForegroundColor));
argList += (settings->normalHighlightBackgroundColor.empty()) ? "" : (spmenu::addArgument("--normal-highlight-background", settings->normalHighlightBackgroundColor));
argList += (settings->selectedHighlightForegroundColor.empty()) ? "" : (spmenu::addArgument("--selected-highlight-foreground", settings->selectedHighlightForegroundColor));
argList += (settings->selectedHighlightBackgroundColor.empty()) ? "" : (spmenu::addArgument("--selected-highlight-background", settings->selectedHighlightBackgroundColor));
argList += (settings->numberForegroundColor.empty()) ? "" : (spmenu::addArgument("--number-foreground", settings->numberForegroundColor));
argList += (settings->numberBackgroundColor.empty()) ? "" : (spmenu::addArgument("--number-background", settings->numberBackgroundColor));
argList += (settings->modeForegroundColor.empty()) ? "" : (spmenu::addArgument("--mode-foreground", settings->modeForegroundColor));
argList += (settings->modeBackgroundColor.empty()) ? "" : (spmenu::addArgument("--mode-background", settings->modeBackgroundColor));
argList += (settings->leftArrowForegroundColor.empty()) ? "" : (spmenu::addArgument("--left-arrow-foreground", settings->leftArrowForegroundColor));
argList += (settings->leftArrowBackgroundColor.empty()) ? "" : (spmenu::addArgument("--left-arrow-background", settings->leftArrowBackgroundColor));
argList += (settings->rightArrowForegroundColor.empty()) ? "" : (spmenu::addArgument("--right-arrow-foreground", settings->rightArrowForegroundColor));
argList += (settings->rightArrowBackgroundColor.empty()) ? "" : (spmenu::addArgument("--right-arrow-background", settings->rightArrowBackgroundColor));
argList += (settings->caretForegroundColor.empty()) ? "" : (spmenu::addArgument("--caret-foreground", settings->caretForegroundColor));
argList += (settings->caretBackgroundColor.empty()) ? "" : (spmenu::addArgument("--caret-background", settings->caretBackgroundColor));
argList += (settings->borderColor.empty()) ? "" : (spmenu::addArgument("--border-background", settings->borderColor));
argList += (settings->sgr0Color.empty()) ? "" : (spmenu::addArgument("--sgr0", settings->sgr0Color));
argList += (settings->sgr1Color.empty()) ? "" : (spmenu::addArgument("--sgr1", settings->sgr1Color));
argList += (settings->sgr2Color.empty()) ? "" : (spmenu::addArgument("--sgr2", settings->sgr2Color));
argList += (settings->sgr3Color.empty()) ? "" : (spmenu::addArgument("--sgr3", settings->sgr3Color));
argList += (settings->sgr4Color.empty()) ? "" : (spmenu::addArgument("--sgr4", settings->sgr4Color));
argList += (settings->sgr5Color.empty()) ? "" : (spmenu::addArgument("--sgr5", settings->sgr5Color));
argList += (settings->sgr6Color.empty()) ? "" : (spmenu::addArgument("--sgr6", settings->sgr6Color));
argList += (settings->sgr7Color.empty()) ? "" : (spmenu::addArgument("--sgr7", settings->sgr7Color));
argList += (settings->sgr8Color.empty()) ? "" : (spmenu::addArgument("--sgr8", settings->sgr8Color));
argList += (settings->sgr9Color.empty()) ? "" : (spmenu::addArgument("--sgr9", settings->sgr9Color));
argList += (settings->sgr10Color.empty()) ? "" : (spmenu::addArgument("--sgr10", settings->sgr10Color));
argList += (settings->sgr11Color.empty()) ? "" : (spmenu::addArgument("--sgr11", settings->sgr11Color));
argList += (settings->sgr12Color.empty()) ? "" : (spmenu::addArgument("--sgr12", settings->sgr12Color));
argList += (settings->sgr13Color.empty()) ? "" : (spmenu::addArgument("--sgr13", settings->sgr13Color));
argList += (settings->sgr14Color.empty()) ? "" : (spmenu::addArgument("--sgr14", settings->sgr14Color));
argList += (settings->sgr15Color.empty()) ? "" : (spmenu::addArgument("--sgr15", settings->sgr15Color));
if (!settings->windowPosition.empty()) {
std::string argument = "";
if (!settings->windowPosition.compare("Top")) {
argument = "--top";
} else if (!settings->windowPosition.compare("Bottom")) {
argument = "--bottom";
} else if (!settings->windowPosition.compare("Center")) {
argument = "--center";
}
argList += " " + argument;
}
if (!settings->itemPosition.empty()) {
std::string argument = "";
if (!settings->itemPosition.compare("Top")) {
argument = "--item-top";
} else if (!settings->itemPosition.compare("Bottom")) {
argument = "--item-bottom";
}
argList += " " + argument;
}
if (!settings->imagePosition.empty()) {
std::string argument = "";
if (!settings->imagePosition.compare("Top")) {
argument = "--image-top";
} else if (!settings->imagePosition.compare("Bottom")) {
argument = "--image-bottom";
} else if (!settings->imagePosition.compare("Center")) {
argument = "--image-center";
} else if (!settings->imagePosition.compare("Top Center")) {
argument = "--image-topcenter";
}
argList += " " + argument;
}
return argList;
}
std::string spmenu::Run(spmenu::spmenuSettings *settings) {
const int bufferSize{ sizeof(settings->standardInput) };
std::ostringstream command;
std::string ret;
std::array<char, bufferSize> buf;
std::string Arguments;
Arguments = spmenu::generateArguments(settings);
command << "printf \"" << settings->standardInput << "\" | spmenu " << Arguments << " " << settings->userArguments;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.str().c_str(), "r"), pclose);
if (!pipe) {
std::cerr << "Failed to popen()\n";
return ret;
}
while (fgets(buf.data(), buf.size(), pipe.get()) != NULL) {
size_t len = strlen(buf.data());
if (len > 0 && buf[len - 1] == '\n') {
ret += std::string(buf.data(), len - 1);
} else {
ret += buf.data();
}
}
return ret;
}

View file

@ -1,152 +0,0 @@
#ifndef LIBSPMENU_HPP
#define LIBSPMENU_HPP
#include <iostream>
namespace spmenu {
using Integer = std::string;
using String = std::string;
using Bool = std::string;
class spmenuSettings {
public:
String userArguments{};
String standardInput{};
String promptText{}; // -p
String preText{}; // -pt
String inputText{}; // -It
String normalModeText{}; // -nmt
String insertModeText{}; // -imt
String capsLockOnText{}; // -clon
String capsLockOffText{}; // -clof
String leftArrowText{}; // -la
String rightArrowText{}; // -ra
Integer lineHeight; // -mh
Integer centerWidth; // -cw
Integer Lines; // -l
Integer Columns; // -g
Integer minLines; // -ml
Bool generateCache; // -gc, -ngc
Integer maxCache; // -mc
String cacheDir{}; // -cd
Bool printIndex; // -ix, -nix
Bool Fast; // -f
Bool Incremental; // -r, -nr
Bool requireMatch; // -rm, -nrm
Bool markItems; // -ma, -nma
Bool Fuzzy; // -F, -NF
Bool Regex; // -R, -NR
Bool Password; // -P, -nP
Bool Indent; // -ip, -nip
Bool colorItems; // -ci, -nci
Bool Sgr; // -sgr, -nsgr
Bool Alpha; // -a, -na
Bool allowTyping; // -tp, -nt
Bool allowOverrideLines; // -ol, -nol
Bool allowOverrideColumns; // -oc, -noc
Integer X; // -x
Integer Y; // -y
Integer W; // -z
Integer H; // -ml
Integer Preselect; // -n
Integer borderWidth; // -bw
Bool Sort; // -so, -nso
String Priority{}; // -pri
Bool caseSensitive; // -s, -ns
Bool defaultMode; // -nm, -im
Integer windowPosition; // -t, -b, -c
Integer itemPosition; // -itt, -itb
Integer imagePosition; // -it, -ib, -ic, -itc
Bool hideMode; // -hm
Bool hideMatchCount; // -hmc
Bool hideLeftArrow; // -hla
Bool hideRightArrow; // -hra
Bool hideItem; // -hit
Bool hidePrompt; // -hpr
Bool hidePretext; // -hpt
Bool hideInput; // -hip
Bool hidePowerline; // -hpl
Bool hideCaret; // -hc
Bool hideHighlighting; // -hhl
Bool hideImage; // -hi
Bool hideCaps; // -hcl
Bool Xrdb; // -xrdb, -nxrdb
Integer Monitor; // -m
Integer Embed; // -w
String histFile{}; // -H
String listFile{}; // -lf
String configFile{}; // -cf
String bindsFile{}; // -bf
String themeFile{}; // -tm
Integer imageGaps; // -ig
Integer imageSize; // -is
Bool imageType; // -di, -df
Bool imageResize; // -ir, -nir
Integer textPadding; // -txp
Integer verticalPadding; // -lp
Integer horizontalPadding; // -hp
Integer verticalMargin; // -vem
Integer horizontalMargin; // -hom
Bool Managed; // -wm, -nwm
Bool displayProtocol; // -x11, -wl
Bool loadConfig; // -lcfg, -ncfg
Bool loadBinds; // -lbi, -nlbi
Bool loadTheme; // -ltm, -nltm
String Font; // -fn
String normalItemForegroundColor{}; // -nif
String normalItemBackgroundColor{}; // -nib
String normalNextItemForegroundColor{}; // -nnif
String normalNextItemBackgroundColor{}; // -nnib
String selectedItemForegroundColor{}; // -sif
String selectedItemBackgroundColor{}; // -sib
String normalItemPriorityForegroundColor{}; // -npf
String normalItemPriorityBackgroundColor{}; // -npb
String selectedItemPriorityForegroundColor{}; // -spf
String selectedItemPriorityBackgroundColor{}; // -spb
String promptForegroundColor{}; // -pfg
String promptBackgroundColor{}; // -pbg
String inputForegroundColor{}; // -ifg
String inputBackgroundColor{}; // -ibg
String preTextForegroundColor{}; // -ptfg
String preTextBackgroundColor{}; // -ptbg
String windowColor{}; // -mnbg
String normalHighlightForegroundColor{}; // -nhf
String normalHighlightBackgroundColor{}; // -nhb
String selectedHighlightForegroundColor{}; // -shf
String selectedHighlightBackgroundColor{}; // -shb
String numberForegroundColor{}; // -nfg
String numberBackgroundColor{}; // -nbg
String modeForegroundColor{}; // -mfg
String modeBackgroundColor{}; // -mbg
String leftArrowForegroundColor{}; // -laf
String leftArrowBackgroundColor{}; // -lab
String rightArrowForegroundColor{}; // -raf
String rightArrowBackgroundColor{}; // -rab
String caretForegroundColor{}; // -cfc
String caretBackgroundColor{}; // -cbg
String borderColor{}; // -bc
String sgr0Color{}; // -sgr0
String sgr1Color{}; // -sgr1
String sgr2Color{}; // -sgr2
String sgr3Color{}; // -sgr3
String sgr4Color{}; // -sgr4
String sgr5Color{}; // -sgr5
String sgr6Color{}; // -sgr6
String sgr7Color{}; // -sgr7
String sgr8Color{}; // -sgr8
String sgr9Color{}; // -sgr9
String sgr10Color{}; // -sgr10
String sgr11Color{}; // -sgr11
String sgr12Color{}; // -sgr12
String sgr13Color{}; // -sgr13
String sgr14Color{}; // -sgr14
String sgr15Color{}; // -sgr15
};
std::string Run(spmenuSettings *settings);
std::string generateArguments(spmenuSettings *settings);
std::string addArgument(std::string Argument, std::string Value);
std::string addArgument(std::string enabledArgument, std::string disabledArgument, std::string Value);
}
#endif

View file

@ -1,19 +0,0 @@
# libspmenu
project('spmenu', 'cpp', version : '3.4')
cc = meson.get_compiler('cpp')
project_source_files = [
'libspmenu.cpp',
]
project_dependencies = [
]
build_args = [
'-DVERSION=' + meson.project_version(),
]
so_version = meson.project_version()
install_headers('libspmenu.h', subdir : 'libspmenu')
lib_shared = shared_library('spmenu', project_source_files, version : so_version, install : true)

View file

@ -1,14 +0,0 @@
/* g++ test.cpp -o test -lspmenu */
#include <iostream>
#include <libspmenu/libspmenu.h>
int main() {
spmenu::spmenuSettings settings;
settings.promptText = "libspmenu test";
settings.windowPosition = "Bottom";
settings.itemPosition = "Top";
settings.standardInput = "Item1\nItem2\nItem3\n";
std::cout << spmenu::Run(&settings);
}