add option to set exclusive zone

This commit is contained in:
Fouad 2025-03-16 01:02:54 +00:00
parent fc69aa6e2b
commit 937c0c4e77
4 changed files with 17 additions and 4 deletions

View file

@ -6,7 +6,7 @@ wmenu - dynamic menu for Wayland
# SYNOPSIS
*wmenu* [-biPv] \
*wmenu* [-bxiPv] \
[-f _font_] \
[-l _lines_] \
[-o _output_] \
@ -32,6 +32,9 @@ $PATH and runs the result.
*-b*
wmenu appears at the bottom of the screen.
*-x*
wmenu avoids overlapping panels and occluding other exclusive surfaces.
*-i*
wmenu matches menu items case insensitively.

7
menu.c
View file

@ -85,15 +85,18 @@ static bool parse_color(const char *color, uint32_t *result) {
// Parse menu options from command line arguments.
void menu_getopts(struct menu *menu, int argc, char *argv[]) {
const char *usage =
"Usage: wmenu [-biPv] [-f font] [-l lines] [-o output] [-p prompt]\n"
"Usage: wmenu [-bxiPv] [-f font] [-l lines] [-o output] [-p prompt]\n"
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
int opt;
while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
while ((opt = getopt(argc, argv, "bxhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
switch (opt) {
case 'b':
menu->bottom = true;
break;
case 'x':
menu->exclusive = true;
break;
case 'i':
menu->strncmp = strncasecmp;
break;

2
menu.h
View file

@ -31,6 +31,8 @@ struct page {
struct menu {
// Whether the menu appears at the bottom of the screen
bool bottom;
// Set exclusive zone
bool exclusive;
// The function used to match menu items
int (*strncmp)(const char *, const char *, size_t);
// Whether the input is a password

View file

@ -454,9 +454,14 @@ int menu_run(struct menu *menu) {
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
}
if (menu->exclusive) {
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, 0);
} else {
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, -1);
}
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
zwlr_layer_surface_v1_set_size(layer_surface, 0, menu->height);
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, -1);
zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface, true);
zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, context);