mirror of
https://github.com/Cloudef/bemenu
synced 2025-02-15 14:16:50 +00:00
add -c center mode on wayland
This commit is contained in:
parent
a84eeb770e
commit
a42fa97a49
@ -192,6 +192,7 @@ usage(FILE *out, const char *name)
|
|||||||
" (...) At end of help indicates the backend support for option.\n\n"
|
" (...) At end of help indicates the backend support for option.\n\n"
|
||||||
|
|
||||||
" -b, --bottom appears at the bottom of the screen. (wx)\n"
|
" -b, --bottom appears at the bottom of the screen. (wx)\n"
|
||||||
|
" -c, --center appears at the center of the screen. (w)\n"
|
||||||
" -f, --grab show the menu before reading stdin. (wx)\n"
|
" -f, --grab show the menu before reading stdin. (wx)\n"
|
||||||
" -n, --no-overlap adjust geometry to not overlap with panels. (w)\n"
|
" -n, --no-overlap adjust geometry to not overlap with panels. (w)\n"
|
||||||
" -m, --monitor index of monitor where menu will appear. (wx)\n"
|
" -m, --monitor index of monitor where menu will appear. (wx)\n"
|
||||||
@ -244,6 +245,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
|
|||||||
{ "filter", required_argument, 0, 'F' },
|
{ "filter", required_argument, 0, 'F' },
|
||||||
{ "wrap", no_argument, 0, 'w' },
|
{ "wrap", no_argument, 0, 'w' },
|
||||||
{ "list", required_argument, 0, 'l' },
|
{ "list", required_argument, 0, 'l' },
|
||||||
|
{ "center", no_argument, 0, 'c' },
|
||||||
{ "prompt", required_argument, 0, 'p' },
|
{ "prompt", required_argument, 0, 'p' },
|
||||||
{ "index", required_argument, 0, 'I' },
|
{ "index", required_argument, 0, 'I' },
|
||||||
{ "prefix", required_argument, 0, 'P' },
|
{ "prefix", required_argument, 0, 'P' },
|
||||||
@ -286,7 +288,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
|
|||||||
for (optind = 0;;) {
|
for (optind = 0;;) {
|
||||||
int32_t opt;
|
int32_t opt;
|
||||||
|
|
||||||
if ((opt = getopt_long(*argc, *argv, "hviwxl:I:p:P:I:bfm:H:n", opts, NULL)) < 0)
|
if ((opt = getopt_long(*argc, *argv, "hviwxcl:I:p:P:I:bfm:H:n", opts, NULL)) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
@ -309,6 +311,9 @@ do_getopt(struct client *client, int *argc, char **argv[])
|
|||||||
case 'l':
|
case 'l':
|
||||||
client->lines = strtol(optarg, NULL, 10);
|
client->lines = strtol(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
client->center = true;
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
client->title = optarg;
|
client->title = optarg;
|
||||||
break;
|
break;
|
||||||
@ -433,13 +438,18 @@ menu_with_options(struct client *client)
|
|||||||
bm_menu_set_filter_mode(menu, client->filter_mode);
|
bm_menu_set_filter_mode(menu, client->filter_mode);
|
||||||
bm_menu_set_lines(menu, client->lines);
|
bm_menu_set_lines(menu, client->lines);
|
||||||
bm_menu_set_wrap(menu, client->wrap);
|
bm_menu_set_wrap(menu, client->wrap);
|
||||||
bm_menu_set_bottom(menu, client->bottom);
|
|
||||||
bm_menu_set_monitor(menu, client->monitor);
|
bm_menu_set_monitor(menu, client->monitor);
|
||||||
bm_menu_set_monitor_name(menu, client->monitor_name);
|
bm_menu_set_monitor_name(menu, client->monitor_name);
|
||||||
bm_menu_set_scrollbar(menu, client->scrollbar);
|
bm_menu_set_scrollbar(menu, client->scrollbar);
|
||||||
bm_menu_set_panel_overlap(menu, !client->no_overlap);
|
bm_menu_set_panel_overlap(menu, !client->no_overlap);
|
||||||
bm_menu_set_password(menu, client->password);
|
bm_menu_set_password(menu, client->password);
|
||||||
|
|
||||||
|
if (client->center) {
|
||||||
|
bm_menu_set_center(menu, client->center);
|
||||||
|
} else if (client->bottom) {
|
||||||
|
bm_menu_set_bottom(menu, client->bottom);
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < BM_COLOR_LAST; ++i)
|
for (uint32_t i = 0; i < BM_COLOR_LAST; ++i)
|
||||||
bm_menu_set_color(menu, i, client->colors[i]);
|
bm_menu_set_color(menu, i, client->colors[i]);
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ struct client {
|
|||||||
uint32_t selected;
|
uint32_t selected;
|
||||||
uint32_t monitor;
|
uint32_t monitor;
|
||||||
bool bottom;
|
bool bottom;
|
||||||
|
bool center;
|
||||||
bool grab;
|
bool grab;
|
||||||
bool wrap;
|
bool wrap;
|
||||||
bool ifne;
|
bool ifne;
|
||||||
|
@ -483,6 +483,15 @@ BM_PUBLIC void bm_menu_set_scrollbar(struct bm_menu *menu, enum bm_scrollbar_mod
|
|||||||
*/
|
*/
|
||||||
BM_PUBLIC enum bm_scrollbar_mode bm_menu_get_scrollbar(struct bm_menu *menu);
|
BM_PUBLIC enum bm_scrollbar_mode bm_menu_get_scrollbar(struct bm_menu *menu);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display menu at center of the screen.
|
||||||
|
* This may be no-op on some renderers (curses, wayland)
|
||||||
|
*
|
||||||
|
* @param menu bm_menu instance to set center mode for.
|
||||||
|
* @param center true for center mode, false for top mode.
|
||||||
|
*/
|
||||||
|
BM_PUBLIC void bm_menu_set_center(struct bm_menu *menu, bool center);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display menu at bottom of the screen.
|
* Display menu at bottom of the screen.
|
||||||
* This may be no-op on some renderers (curses, wayland)
|
* This may be no-op on some renderers (curses, wayland)
|
||||||
|
@ -79,6 +79,11 @@ struct render_api {
|
|||||||
*/
|
*/
|
||||||
void (*set_bottom)(const struct bm_menu *menu, bool bottom);
|
void (*set_bottom)(const struct bm_menu *menu, bool bottom);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set menu to appear from center of the screen.
|
||||||
|
*/
|
||||||
|
void (*set_center)(const struct bm_menu *menu, bool center);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set monitor indeax where menu will appear
|
* Set monitor indeax where menu will appear
|
||||||
*/
|
*/
|
||||||
@ -311,6 +316,11 @@ struct bm_menu {
|
|||||||
*/
|
*/
|
||||||
bool wrap;
|
bool wrap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is menu shown from center?
|
||||||
|
*/
|
||||||
|
bool center;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is menu shown from bottom?
|
* Is menu shown from bottom?
|
||||||
*/
|
*/
|
||||||
|
14
lib/menu.c
14
lib/menu.c
@ -340,6 +340,20 @@ bm_menu_get_scrollbar(struct bm_menu *menu)
|
|||||||
return menu->scrollbar;
|
return menu->scrollbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bm_menu_set_center(struct bm_menu *menu, bool center)
|
||||||
|
{
|
||||||
|
assert(menu);
|
||||||
|
|
||||||
|
if (menu->center == center)
|
||||||
|
return;
|
||||||
|
|
||||||
|
menu->center = center;
|
||||||
|
|
||||||
|
if (menu->renderer->api.set_center)
|
||||||
|
menu->renderer->api.set_center(menu, center);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bm_menu_set_bottom(struct bm_menu *menu, bool bottom)
|
bm_menu_set_bottom(struct bm_menu *menu, bool bottom)
|
||||||
{
|
{
|
||||||
|
@ -240,6 +240,18 @@ set_bottom(const struct bm_menu *menu, bool bottom)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_center(const struct bm_menu *menu, bool center)
|
||||||
|
{
|
||||||
|
struct wayland *wayland = menu->renderer->internal;
|
||||||
|
assert(wayland);
|
||||||
|
|
||||||
|
struct window *window;
|
||||||
|
wl_list_for_each(window, &wayland->windows, link) {
|
||||||
|
bm_wl_window_set_center(window, wayland->display, center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
grab_keyboard(const struct bm_menu *menu, bool grab)
|
grab_keyboard(const struct bm_menu *menu, bool grab)
|
||||||
{
|
{
|
||||||
@ -432,6 +444,7 @@ register_renderer(struct render_api *api)
|
|||||||
api->get_displayed_count = get_displayed_count;
|
api->get_displayed_count = get_displayed_count;
|
||||||
api->poll_key = poll_key;
|
api->poll_key = poll_key;
|
||||||
api->render = render;
|
api->render = render;
|
||||||
|
api->set_center = set_center;
|
||||||
api->set_bottom = set_bottom;
|
api->set_bottom = set_bottom;
|
||||||
api->grab_keyboard = grab_keyboard;
|
api->grab_keyboard = grab_keyboard;
|
||||||
api->set_overlap = set_overlap;
|
api->set_overlap = set_overlap;
|
||||||
|
@ -88,6 +88,7 @@ struct window {
|
|||||||
uint32_t displayed;
|
uint32_t displayed;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
bool bottom;
|
bool bottom;
|
||||||
|
bool center;
|
||||||
bool render_pending;
|
bool render_pending;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -129,6 +130,7 @@ void bm_wl_registry_destroy(struct wayland *wayland);
|
|||||||
void bm_wl_window_schedule_render(struct window *window);
|
void bm_wl_window_schedule_render(struct window *window);
|
||||||
void bm_wl_window_render(struct window *window, struct wl_display *display, const struct bm_menu *menu);
|
void bm_wl_window_render(struct window *window, struct wl_display *display, const struct bm_menu *menu);
|
||||||
void bm_wl_window_set_bottom(struct window *window, struct wl_display *display, bool bottom);
|
void bm_wl_window_set_bottom(struct window *window, struct wl_display *display, bool bottom);
|
||||||
|
void bm_wl_window_set_center(struct window *window, struct wl_display *display, bool center);
|
||||||
void bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab);
|
void bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab);
|
||||||
void bm_wl_window_set_overlap(struct window *window, struct wl_display *display, bool overlap);
|
void bm_wl_window_set_overlap(struct window *window, struct wl_display *display, bool overlap);
|
||||||
bool bm_wl_window_create(struct window *window, struct wl_display *display, struct wl_shm *shm, struct wl_output *output, struct zwlr_layer_shell_v1 *layer_shell, struct wl_surface *surface);
|
bool bm_wl_window_create(struct window *window, struct wl_display *display, struct wl_shm *shm, struct wl_output *output, struct zwlr_layer_shell_v1 *layer_shell, struct wl_surface *surface);
|
||||||
|
@ -240,7 +240,7 @@ bm_wl_window_render(struct window *window, struct wl_display *display, const str
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
window->height = result.height / window->scale;
|
window->height = result.height / window->scale;
|
||||||
zwlr_layer_surface_v1_set_size(window->layer_surface, 0, window->height);
|
zwlr_layer_surface_v1_set_size(window->layer_surface, window->width, window->height);
|
||||||
wl_surface_commit(window->surface);
|
wl_surface_commit(window->surface);
|
||||||
wl_display_roundtrip(display);
|
wl_display_roundtrip(display);
|
||||||
destroy_buffer(buffer);
|
destroy_buffer(buffer);
|
||||||
@ -304,6 +304,20 @@ bm_wl_window_set_bottom(struct window *window, struct wl_display *display, bool
|
|||||||
wl_display_roundtrip(display);
|
wl_display_roundtrip(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bm_wl_window_set_center(struct window *window, struct wl_display *display, bool center)
|
||||||
|
{
|
||||||
|
if (window->center == center)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window->center = center;
|
||||||
|
|
||||||
|
zwlr_layer_surface_v1_set_anchor(window->layer_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
|
||||||
|
zwlr_layer_surface_v1_set_size(window->layer_surface, 3 * window->width / 4, window->height);
|
||||||
|
wl_surface_commit(window->surface);
|
||||||
|
wl_display_roundtrip(display);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab)
|
bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user