Re: [dev] [dwm] autoraise floating windows when gaining focus

From: Κρακ Άουτ <krackout_AT_gmx.com>
Date: Fri, 26 Jul 2024 10:17:58 +0300

On 2024-07-25 15:44 Κρακ Άουτ <krackout_AT_gmx.com> wrote:

> On 2024-06-18 14:10 Κρακ Άουτ <krackout_AT_gmx.com> wrote:
>
>> On 2024-06-18 13:52 Anthony wrote:
>>
>>> On 6/18/24 8:25 AM, Κρακ Άουτ wrote:
>>>> Hello to all,
>>>
>>> Hi.
>>>
>>>> I'd like to autoraise floating windows when gaining focus. The
>>>> current behaviour is, windows gets focus on mouse pointer hover,
>>>> but
>>>> needs modkey press + left button mouse click to raise. I searched
>>>> but did not locate any such patch. Is there perhaps, or could you
>>>> give me any advice on how to achieve this?
>>>
>>> I'm not a regular user of DWM anymore, but I just rapidly tried
>>> with
>>> the last version and this feature seems to work. Maybe you have an
>>> outdated version (probably not, I think this has been there since
>>> 2009) or perhaps another patch is blocking this?
>>>
>>> Regards.
>>
>> In that case, a patch that I've added must have changed the
>> behaviour
>> (about ten added). I'll try a stock installation of dwm to see.
>>
>> Thank you.
>
> I tried the stock dwm, just downloaded from git.suckless.org/dwm. It
> does not autoraise floating windows when gaining focus.
>
> So my initial question remains, any advice on how to achieve this?
>

Let me clarify that autoraise does not happen when hovering mouse pointer over a floating window, when in floating mode or between windows that are set as floating.
It is autoraised if switching window using key shortcut.

I made this change in dwm.c and now it works to my preference:

In function `void focus(Client *c)` I added this `XRaiseWindow(dpy, c->win);` after `setfocus(c);`

Here is the altered function:

```
void
focus(Client *c)
{
        if (!c || !ISVISIBLE(c))
                for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
        if (selmon->sel && selmon->sel != c)
                unfocus(selmon->sel, 0);
        if (c) {
                if (c->mon != selmon)
                        selmon = c->mon;
                if (c->isurgent)
                        seturgent(c, 0);
                detachstack(c);
                attachstack(c);
                grabbuttons(c, 1);
                XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
                setfocus(c);
                XRaiseWindow(dpy, c->win); // THIS is added to autoraise after focus with mouse pointer
        } else {
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
                XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
        }
        selmon->sel = c;
        drawbars();
}
```

If it's tested by others also, I'll consider making a patch.
I think it's a bit risky to publish it if tested by me only.

Regards.
Received on Fri Jul 26 2024 - 09:17:58 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 26 2024 - 09:24:09 CEST