mirror of
https://codeberg.org/adnano/wmenu.git
synced 2025-10-29 05:40:20 -04:00
add center flag
This commit is contained in:
parent
0a38d45abb
commit
c417daa0a0
3 changed files with 28 additions and 8 deletions
9
menu.c
9
menu.c
|
|
@ -85,14 +85,17 @@ static bool parse_color(const char *color, uint32_t *result) {
|
||||||
// Parse menu options from command line arguments.
|
// Parse menu options from command line arguments.
|
||||||
void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
||||||
const char *usage =
|
const char *usage =
|
||||||
"Usage: wmenu [-biPv] [-f font] [-l lines] [-o output] [-p prompt]\n"
|
"Usage: wmenu [-bciPv] [-f font] [-l lines] [-o output] [-p prompt]\n"
|
||||||
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
|
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
|
while ((opt = getopt(argc, argv, "bchiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'b':
|
case 'b':
|
||||||
menu->bottom = true;
|
menu->position = POSITION_BOTTOM;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
menu->position = POSITION_CENTER;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
menu->strncmp = strncasecmp;
|
menu->strncmp = strncasecmp;
|
||||||
|
|
|
||||||
10
menu.h
10
menu.h
|
|
@ -27,10 +27,18 @@ struct page {
|
||||||
struct page *next; // next page
|
struct page *next; // next page
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum e_position {
|
||||||
|
POSITION_TOP,
|
||||||
|
POSITION_BOTTOM,
|
||||||
|
POSITION_CENTER,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum e_position POSITION;
|
||||||
|
|
||||||
// Menu state.
|
// Menu state.
|
||||||
struct menu {
|
struct menu {
|
||||||
// Whether the menu appears at the bottom of the screen
|
// Whether the menu appears at the bottom of the screen
|
||||||
bool bottom;
|
POSITION position;
|
||||||
// The function used to match menu items
|
// The function used to match menu items
|
||||||
int (*strncmp)(const char *, const char *, size_t);
|
int (*strncmp)(const char *, const char *, size_t);
|
||||||
// Whether the input is a password
|
// Whether the input is a password
|
||||||
|
|
|
||||||
17
wayland.c
17
wayland.c
|
|
@ -448,10 +448,19 @@ int menu_run(struct menu *menu) {
|
||||||
|
|
||||||
uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
if (menu->bottom) {
|
|
||||||
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
switch (menu->position) {
|
||||||
} else {
|
|
||||||
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
case POSITION_BOTTOM:
|
||||||
|
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||||
|
break;
|
||||||
|
case POSITION_TOP:
|
||||||
|
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
||||||
|
break;
|
||||||
|
case POSITION_CENTER:
|
||||||
|
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||||
|
// we will handle this in rendering.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
|
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue