mirror of
https://github.com/vale981/spectrwm
synced 2025-03-05 09:51:38 -05:00
Take input focus into consideration when determining active region.
Change screen_next and screen_prev to no longer warp mouse pointer.
This commit is contained in:
parent
e6a9b61ffe
commit
36e10e1dfb
1 changed files with 28 additions and 27 deletions
55
spectrwm.c
55
spectrwm.c
|
@ -2446,9 +2446,11 @@ restart(struct swm_region *r, union arg *args)
|
||||||
struct swm_region *
|
struct swm_region *
|
||||||
root_to_region(xcb_window_t root)
|
root_to_region(xcb_window_t root)
|
||||||
{
|
{
|
||||||
|
struct ws_win *cfw;
|
||||||
struct swm_region *r = NULL;
|
struct swm_region *r = NULL;
|
||||||
int i, num_screens;
|
int i, num_screens;
|
||||||
xcb_query_pointer_reply_t *qpr;
|
xcb_query_pointer_reply_t *qpr;
|
||||||
|
xcb_get_input_focus_reply_t *gifr;
|
||||||
|
|
||||||
DNPRINTF(SWM_D_MISC, "root_to_region: window: 0x%x\n", root);
|
DNPRINTF(SWM_D_MISC, "root_to_region: window: 0x%x\n", root);
|
||||||
|
|
||||||
|
@ -2457,20 +2459,33 @@ root_to_region(xcb_window_t root)
|
||||||
if (screens[i].root == root)
|
if (screens[i].root == root)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
qpr = xcb_query_pointer_reply(conn, xcb_query_pointer(conn,
|
/* Try to find an actively focused window */
|
||||||
screens[i].root), NULL);
|
gifr = xcb_get_input_focus_reply(conn, xcb_get_input_focus(conn), NULL);
|
||||||
|
if (gifr) {
|
||||||
|
cfw = find_window(gifr->focus);
|
||||||
|
if (cfw && cfw->ws->r)
|
||||||
|
r = cfw->ws->r;
|
||||||
|
|
||||||
if (qpr) {
|
free(gifr);
|
||||||
DNPRINTF(SWM_D_MISC, "root_to_region: pointer: (%d,%d)\n",
|
|
||||||
qpr->root_x, qpr->root_y);
|
|
||||||
/* choose a region based on pointer location */
|
|
||||||
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
|
||||||
if (X(r) <= qpr->root_x && qpr->root_x < MAX_X(r) &&
|
|
||||||
Y(r) <= qpr->root_y && qpr->root_y < MAX_Y(r))
|
|
||||||
break;
|
|
||||||
free(qpr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (r == NULL) {
|
||||||
|
/* No region with an active focus; try to use pointer. */
|
||||||
|
qpr = xcb_query_pointer_reply(conn, xcb_query_pointer(conn,
|
||||||
|
screens[i].root), NULL);
|
||||||
|
|
||||||
|
if (qpr) {
|
||||||
|
DNPRINTF(SWM_D_MISC, "root_to_region: pointer: (%d,%d)\n",
|
||||||
|
qpr->root_x, qpr->root_y);
|
||||||
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
||||||
|
if (X(r) <= qpr->root_x && qpr->root_x < MAX_X(r) &&
|
||||||
|
Y(r) <= qpr->root_y && qpr->root_y < MAX_Y(r))
|
||||||
|
break;
|
||||||
|
free(qpr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Last resort. */
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
r = TAILQ_FIRST(&screens[i].rl);
|
r = TAILQ_FIRST(&screens[i].rl);
|
||||||
|
|
||||||
|
@ -2956,7 +2971,7 @@ void
|
||||||
cyclescr(struct swm_region *r, union arg *args)
|
cyclescr(struct swm_region *r, union arg *args)
|
||||||
{
|
{
|
||||||
struct swm_region *rr = NULL;
|
struct swm_region *rr = NULL;
|
||||||
int i, x, y, num_screens;
|
int i, num_screens;
|
||||||
|
|
||||||
num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
|
num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
|
||||||
/* do nothing if we don't have more than one screen */
|
/* do nothing if we don't have more than one screen */
|
||||||
|
@ -2981,21 +2996,7 @@ cyclescr(struct swm_region *r, union arg *args)
|
||||||
if (rr == NULL)
|
if (rr == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* move mouse to region */
|
focus_win(get_region_focus(rr));
|
||||||
x = X(rr) + 1;
|
|
||||||
y = Y(rr) + 1 + (bar_enabled ? bar_height : 0);
|
|
||||||
xcb_warp_pointer(conn, XCB_WINDOW_NONE, rr->s[i].root, 0, 0, 0, 0,
|
|
||||||
x, y);
|
|
||||||
|
|
||||||
rr->ws->focus = get_region_focus(rr);
|
|
||||||
|
|
||||||
if (rr->ws->focus) {
|
|
||||||
/* move to focus window */
|
|
||||||
x = X(rr->ws->focus) + 1;
|
|
||||||
y = Y(rr->ws->focus) + 1;
|
|
||||||
xcb_warp_pointer(conn, XCB_WINDOW_NONE, rr->s[i].root, 0, 0, 0,
|
|
||||||
0, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
focus_flush();
|
focus_flush();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue