x11: Align -m argument interpretation with dmenu

With dmenu, monitor indices start at 0 and a value of -1 (the default)
is used to spawn dmenu on the current monitor. While bemenu strives to
be compatible with dmenu, bemenu monitor indices previously started at 1
and a value of 0 (the default) was used to spawn on the current monitor.

This commit aligns the behaviour of bemenu's x11 backend with dmenu. For
this purposes, the affected code in the x11 backend is synced with the
current dmenu implementation. While doing so the monitor type has also
been switched from a uint32_t to a int32_t.
This commit is contained in:
Sören Tempel 2021-04-04 14:25:06 +02:00 committed by Jari Vetoniemi
parent 9f2ad2dde0
commit 2e922503e8
7 changed files with 20 additions and 21 deletions

View File

@ -502,13 +502,13 @@ BM_PUBLIC bool bm_menu_get_bottom(struct bm_menu *menu);
/**
* Display menu at monitor index.
* Indices start from 1, pass 0 for active monitor (default).
* Indices start at 0, a value of -1 can be passed for the active monitor (default).
* If index is more than amount of monitors, the monitor with highest index will be selected.
*
* @param menu bm_menu instance to set monitor for.
* @param monitor Monitor index starting from 1.
* @param monitor Monitor index starting from 0, or -1 for the active monitor.
*/
BM_PUBLIC void bm_menu_set_monitor(struct bm_menu *menu, uint32_t monitor);
BM_PUBLIC void bm_menu_set_monitor(struct bm_menu *menu, int32_t monitor);
/**
* Display menu with monitor_name.

View File

@ -82,7 +82,7 @@ struct render_api {
/**
* Set monitor indeax where menu will appear
*/
void (*set_monitor)(const struct bm_menu *menu, uint32_t monitor);
void (*set_monitor)(const struct bm_menu *menu, int32_t monitor);
/**
* Set monitor name where menu will appear
@ -289,7 +289,7 @@ struct bm_menu {
/**
* Current monitor.
*/
uint32_t monitor;
int32_t monitor;
/**
* Current monitor name. Wayland only.

View File

@ -362,7 +362,7 @@ bm_menu_get_bottom(struct bm_menu *menu)
}
void
bm_menu_set_monitor(struct bm_menu *menu, uint32_t monitor)
bm_menu_set_monitor(struct bm_menu *menu, int32_t monitor)
{
assert(menu);

View File

@ -276,16 +276,16 @@ recreate_windows(const struct bm_menu *menu, struct wayland *wayland)
{
destroy_windows(wayland);
uint32_t monitors = 0;
int32_t monitors = 0;
struct output *output;
wl_list_for_each(output, &wayland->outputs, link)
monitors++;
uint32_t monitor = 0;
int32_t monitor = 0;
wl_list_for_each(output, &wayland->outputs, link) {
if (!menu->monitor_name) {
if (menu->monitor != (uint32_t)-1) {
if (menu->monitor != -1) {
if (menu->monitor < monitors && monitor != menu->monitor) {
++monitor;
continue;
@ -318,7 +318,7 @@ recreate_windows(const struct bm_menu *menu, struct wayland *wayland)
window->max_height = output->height;
window->render_pending = true;
wl_list_insert(&wayland->windows, &window->link);
if (menu->monitor != (uint32_t)-1) break;
if (menu->monitor != -1) break;
}
set_overlap(menu, menu->overlap);
@ -332,7 +332,7 @@ fail:
}
static void
set_monitor(const struct bm_menu *menu, uint32_t monitor)
set_monitor(const struct bm_menu *menu, int32_t monitor)
{
(void)monitor;
struct wayland *wayland = menu->renderer->internal;

View File

@ -131,7 +131,7 @@ bm_x11_window_destroy(struct window *window)
}
void
bm_x11_window_set_monitor(struct window *window, uint32_t monitor)
bm_x11_window_set_monitor(struct window *window, int32_t monitor)
{
if (window->monitor == monitor)
return;
@ -151,10 +151,9 @@ bm_x11_window_set_monitor(struct window *window, uint32_t monitor)
XWindowAttributes wa;
XGetInputFocus(window->display, &w, &di);
if (monitor > 0)
i = ((int32_t)monitor > n ? n : (int32_t)monitor) - 1;
if (monitor == 0 && w != root && w != PointerRoot && w != None) {
if (monitor >= 0 && monitor < n)
i = monitor;
else if (w != root && w != PointerRoot && w != None) {
/* find top-level window containing current input focus */
do {
if (XQueryTree(window->display, (pw = w), &dw, &w, &dws, &du) && dws)
@ -172,7 +171,7 @@ bm_x11_window_set_monitor(struct window *window, uint32_t monitor)
}
/* no focused window is on screen, so use pointer location instead */
if (monitor == 0 && !area && XQueryPointer(window->display, root, &dw, &dw, &x, &y, &di, &di, &du)) {
if (monitor < 0 && !area && XQueryPointer(window->display, root, &dw, &dw, &x, &y, &di, &di, &du)) {
for (i = 0; i < n; i++) {
if (INTERSECT(x, y, 1, 1, info[i]) > 0)
break;

View File

@ -204,11 +204,11 @@ set_bottom(const struct bm_menu *menu, bool bottom)
}
static void
set_monitor(const struct bm_menu *menu, uint32_t monitor)
set_monitor(const struct bm_menu *menu, int32_t monitor)
{
struct x11 *x11 = menu->renderer->internal;
assert(x11);
bm_x11_window_set_monitor(&x11->window, (monitor != (uint32_t)-1 ? monitor : 0));
bm_x11_window_set_monitor(&x11->window, monitor);
}
static void

View File

@ -33,7 +33,7 @@ struct window {
uint32_t x, y, width, height, max_height;
uint32_t displayed;
uint32_t monitor;
int32_t monitor;
bool bottom;
struct {
@ -48,7 +48,7 @@ struct x11 {
void bm_x11_window_render(struct window *window, const struct bm_menu *menu);
void bm_x11_window_key_press(struct window *window, XKeyEvent *ev);
void bm_x11_window_set_monitor(struct window *window, uint32_t monitor);
void bm_x11_window_set_monitor(struct window *window, int32_t monitor);
void bm_x11_window_set_bottom(struct window *window, bool bottom);
bool bm_x11_window_create(struct window *window, Display *display);
void bm_x11_window_destroy(struct window *window);