Skip to content

Commit

Permalink
Always return the upper window in the stacking order if querying wind…
Browse files Browse the repository at this point in the history
…ow under the cursor
  • Loading branch information
Julian committed May 7, 2016
1 parent 6194cab commit eac3f2d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/neuro/action.c
Expand Up @@ -409,7 +409,8 @@ void NeuroActionHandlerFocusPtrClient(NeuroArg clientSelectorFn_arg) {

// Select the monitor where the pointer is
NeuroPoint p;
const NeuroMonitor *const m = NeuroMonitorFindPointed(NeuroSystemGetPointerLocation(&p));
NeuroSystemGetPointerWindowLocation(&p, NULL);
const NeuroMonitor *const m = NeuroMonitorFindPointed(&p);
for (NeuroIndex ws = NeuroCoreGetHeadStack(); ws < NeuroCoreGetSize(); ++ws) {
if (NeuroCoreStackGetMonitor(ws) == m) {
NeuroWorkspaceUnfocus(NeuroCoreGetCurrStack());
Expand All @@ -420,7 +421,8 @@ void NeuroActionHandlerFocusPtrClient(NeuroArg clientSelectorFn_arg) {
}

// Focus the client under the pointer
process_client(NeuroWorkspaceClientFocus, NeuroClientFindPointed(&p), NEURO_ARG_CSF_GET(clientSelectorFn_arg), NULL);
process_client(NeuroWorkspaceClientFocus, NeuroClientGetPointedByPointer(), NEURO_ARG_CSF_GET(clientSelectorFn_arg),
NULL);
}

void NeuroActionHandlerFreeMovePtrClient(NeuroArg clientSelectorFn_arg) {
Expand Down
25 changes: 15 additions & 10 deletions src/neuro/client.c
Expand Up @@ -342,8 +342,8 @@ void NeuroClientFloatMove(NeuroClientPtrPtr c, const void *data) {
NeuroRectangle *const r = &client->float_region, cr;
memmove(&cr, r, sizeof(NeuroRectangle));
NeuroPoint p;
process_xmotion(r, client->ws, &cr, NeuroSystemGetPointerLocation(&p), xmotion_move,
NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_MOVE));
NeuroSystemGetPointerWindowLocation(&p, NULL);
process_xmotion(r, client->ws, &cr, &p, xmotion_move, NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_MOVE));
}

void NeuroClientFloatResize(NeuroClientPtrPtr c, const void *data) {
Expand All @@ -363,8 +363,8 @@ void NeuroClientFloatResize(NeuroClientPtrPtr c, const void *data) {
NeuroRectangle *const r = &client->float_region, cr;
memmove(&cr, r, sizeof(NeuroRectangle));
NeuroPoint p;
process_xmotion(r, client->ws, &cr, NeuroSystemGetPointerLocation(&p), xmotion_resize,
NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_RESIZE));
NeuroSystemGetPointerWindowLocation(&p, NULL);
process_xmotion(r, client->ws, &cr, &p, xmotion_resize, NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_RESIZE));
}

void NeuroClientFreeMove(NeuroClientPtrPtr c, const void *free_setter_fn) {
Expand All @@ -378,9 +378,10 @@ void NeuroClientFreeMove(NeuroClientPtrPtr c, const void *free_setter_fn) {
// Free move the client
NeuroRectangle *const r = NeuroCoreClientGetRegion(c), cr;
memmove(&cr, r, sizeof(NeuroRectangle));
NeuroClient *const client = NEURO_CLIENT_PTR(c);
NeuroPoint p;
process_xmotion(r, NEURO_CLIENT_PTR(c)->ws, &cr, NeuroSystemGetPointerLocation(&p), xmotion_move,
NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_MOVE));
NeuroSystemGetPointerWindowLocation(&p, NULL);
process_xmotion(r, client->ws, &cr, &p, xmotion_move, NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_MOVE));
}

void NeuroClientFreeResize(NeuroClientPtrPtr c, const void *free_setter_fn) {
Expand All @@ -394,9 +395,10 @@ void NeuroClientFreeResize(NeuroClientPtrPtr c, const void *free_setter_fn) {
// Free resize the client
NeuroRectangle *const r = NeuroCoreClientGetRegion(c), cr;
memmove(&cr, r, sizeof(NeuroRectangle));
NeuroClient *const client = NEURO_CLIENT_PTR(c);
NeuroPoint p;
process_xmotion(r, NEURO_CLIENT_PTR(c)->ws, &cr, NeuroSystemGetPointerLocation(&p), xmotion_resize,
NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_RESIZE));
NeuroSystemGetPointerWindowLocation(&p, NULL);
process_xmotion(r, client->ws, &cr, &p, xmotion_resize, NeuroSystemGetCursor(NEURO_SYSTEM_CURSOR_RESIZE));
}

// Find
Expand All @@ -412,6 +414,8 @@ NeuroClientPtrPtr NeuroClientFindFixed(void) {
return NeuroCoreFindClient(NeuroClientTesterFixed, NULL);
}

// Note: This might return a lower window in the stacking order, use NeuroClientGetPointedByPointer() to always get
// the upper window in the stacking order
NeuroClientPtrPtr NeuroClientFindPointed(const NeuroPoint *p) {
return NeuroCoreFindClient(NeuroClientTesterPointed, (const void *)p);
}
Expand All @@ -426,8 +430,9 @@ NeuroClientPtrPtr NeuroClientGetFocused(void) {
}

NeuroClientPtrPtr NeuroClientGetPointedByPointer(void) {
NeuroPoint p;
return NeuroClientFindPointed(NeuroSystemGetPointerLocation(&p));
Window w;
NeuroSystemGetPointerWindowLocation(NULL, &w);
return NeuroClientFindWindow(w);
}

// Client Testers
Expand Down
10 changes: 5 additions & 5 deletions src/neuro/system.c
Expand Up @@ -234,13 +234,13 @@ const int *NeuroSystemGetHiddenGaps(void) {
return hidden_gaps_;
}

NeuroPoint *NeuroSystemGetPointerLocation(NeuroPoint *p) {
if (!p)
return NULL;
void NeuroSystemGetPointerWindowLocation(NeuroPoint *p, Window *w) {
Window root_win = 0UL, child_win = 0UL;
int xc = 0, yc = 0;
int px = 0, py = 0, xc = 0, yc = 0;
unsigned int state = 0;
return XQueryPointer(display_, root_, &root_win, &child_win, &p->x, &p->y, &xc, &yc, &state) ? p : NULL;
if (!XQueryPointer(display_, root_, &root_win, w ? w : &child_win, p ? &p->x : &px, p ? &p->y : &py, &xc, &yc,
&state) ? p : NULL)
NeuroSystemError("NeuroSystemGetPointerWindowLocation - Could not query pointer");
}

Cursor NeuroSystemGetCursor(NeuroSystemCursor c) {
Expand Down
2 changes: 1 addition & 1 deletion src/neuro/system.h
Expand Up @@ -82,7 +82,7 @@ int NeuroSystemGetScreen(void);
const NeuroRectangle *NeuroSystemGetScreenRegion(void);
const NeuroRectangle *NeuroSystemGetHiddenRegion(void);
const int *NeuroSystemGetHiddenGaps(void);
NeuroPoint *NeuroSystemGetPointerLocation(NeuroPoint *p);
void NeuroSystemGetPointerWindowLocation(NeuroPoint *p, Window *w);
Cursor NeuroSystemGetCursor(NeuroSystemCursor c);
Atom NeuroSystemGetWmAtom(NeuroSystemWmatom a);
Atom NeuroSystemGetNetAtom(NeuroSystemNetatom a);
Expand Down
1 change: 1 addition & 0 deletions src/neuro/workspace.c
Expand Up @@ -227,6 +227,7 @@ NeuroClientPtrPtr NeuroWorkspaceClientFindFixed(NeuroIndex ws) {
return NeuroCoreStackFindClient(ws, NeuroClientTesterFixed, NULL);
}

// Note: This might return a lower window in the stacking order
NeuroClientPtrPtr NeuroWorkspaceClientFindPointed(NeuroIndex ws, const NeuroPoint *p) {
return NeuroCoreStackFindClient(ws, NeuroClientTesterPointed, (const void *)p);
}
Expand Down

0 comments on commit eac3f2d

Please sign in to comment.