[dev] [dwm] Set input focus to barwin on empty monitors

2023-01-29 Thread A Farzat
I sent this email two weeks ago over the weekend to no reply. I'm
sending it again now (just in case the timing was bad last time).

Stein wrote in the commit message of commit c2b748e:
> The edge case scenario that dmenu does not handle on its own, and the
> effect of removing this mechanism, is that if the user trigger
> focusmon via keybindings to change focus to another monitor that has
> no clients, then dmenu will open on the monitor containing the window
> with input focus (or the monitor with the mouse cursor if no windows
> have input focus).
>
> If this edge case is important to cover then this can be addressed by
> setting input focus to selmon->barwin in the focus function if there
> is no client to give focus to (rather than giving focus back to the
> root window).

Even though the commit has been reverted, I am still interested in
implementing this, as it enables other programs to know which monitor is
currently focused (I had asked about this like a week ago, and this
seems like a good solution).

I'm not sure though how to implement it. My guess is that the command
`XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);`[line 808]
in the focus function becomes
`XSetInputFocus(dpy, selmon->barwin, RevertToPointerRoot, CurrentTime);`
I'm not sure about the next line though: does the command
`XDeleteProperty(dpy, root, netatom[NetActiveWindow]);` stay as it is?
Or do I need to change it somehow?

Maybe this can even be posted as a patch on the wiki? Sounds like
something other might find helpful as well.

Thanks for the help.

Farzat


signature.asc
Description: PGP signature


[dev] [dwm] Set input focus to barwin on empty monitors

2023-01-20 Thread A Farzat
Stein wrote in the commit message of commit c2b748e:
> The edge case scenario that dmenu does not handle on its own, and the
> effect of removing this mechanism, is that if the user trigger
> focusmon via keybindings to change focus to another monitor that has
> no clients, then dmenu will open on the monitor containing the window
> with input focus (or the monitor with the mouse cursor if no windows
> have input focus).
>
> If this edge case is important to cover then this can be addressed by
> setting input focus to selmon->barwin in the focus function if there
> is no client to give focus to (rather than giving focus back to the
> root window).

Even though the commit has been reverted, I am still interested in
implementing this, as it enables other programs to know which monitor is
currently focused (I had asked about this like a week ago, and this
seems like a good solution).

I'm not sure though how to implement it. My guess is that the command
`XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);`[line 808]
in the focus function becomes
`XSetInputFocus(dpy, selmon->barwin, RevertToPointerRoot, CurrentTime);`
I'm not sure about the next line though: does the command
`XDeleteProperty(dpy, root, netatom[NetActiveWindow]);` stay as it is?
Or do I need to change it somehow?

Maybe this can even be posted as a patch on the wiki? Sounds like
something other might find helpful as well.

Thanks for the help.

Farzat


signature.asc
Description: PGP signature


Re: [SPAM Warning!][dev] [dwm] view() and toggleview() functions

2023-01-16 Thread A Farzat
On 23/01/16 12:10pm, NRK wrote:
> On Sun, Jan 15, 2023 at 06:28:55PM +0900, A Farzat wrote:
> > 2- In the view() function, there is this line:
> > ```c
> > selmon->seltags ^= 1; /* toggle sel tagset */
> > ```
> > What is the purpose of this line? In fact, what is the purpose of having
> > two tagsets in the first place? From what I see, all the tag
> > functionality can be achieved using only one tagset.
> 
> It's for going back to the previous layout via `MODKEY+TAB`.
> 
> - NRK

I see, so that's why it is outside the if statement.

Btw, on the email subject it says [SPAM Warning!]. Is it anything I need
to be concerned with?

Thanks for clarifying!

- Farzat


signature.asc
Description: PGP signature


[dev] [dwm] view() and toggleview() functions

2023-01-15 Thread A Farzat
I am trying to modify dwm so that the tags on all monitors are synced.
Basically something like the [switch all monitor tags
patch](http://dwm.suckless.org/patches/switch_all_monitor_tags/) but
more extreme. It is simple to implement but I wanted to make sure of two
things first:

1- In the view() and toggleview() functions, focus(NULL) is called first
and then arrange(selmon). In the patch however, arrange() is called on
all the monitors before calling focus(NULL). Is that OK, or is there a
significance to the order of calling these functions?

2- In the view() function, there is this line:
```c
selmon->seltags ^= 1; /* toggle sel tagset */
```
What is the purpose of this line? In fact, what is the purpose of having
two tagsets in the first place? From what I see, all the tag
functionality can be achieved using only one tagset.

Thanks in advance for your help.

Regards,
Farzat


signature.asc
Description: PGP signature


Re: [dev] [dwm] Obtain focused monitor

2023-01-13 Thread A Farzat
On 23/01/12 11:35am, Gauthier Östervall wrote:
> On Sun, 8 Jan 2023 at 11:21, A Farzat  wrote:
> >
> > Is there a way to obtain the currently focused monitor in dwm? I want to
> > use it in my script to control which monitor gets its brightness
> > modified.
> 
> Do you mean obtain from outside the dwm process? Not directly, that I
> am aware of. But you could try and query X for that. This SO answer
> might be of interest: https://unix.stackexchange.com/a/677884
> 
> selmon is not a command, it's a global variable. It's not accessible
> outside the dwm process, if you don't make it accessible by modifying
> dwm. It also points to a dwm monitor struct, it holds data for the
> internals of dwm. You could probably use it to find out what you need,
> but I'm not sure it would be the simplest way.

Thank you for your elaboration. Yes, querying X is much simpler and more
portable, but the best answers I found tell you on which monitor your
cursor is, which in dwm is not necessarily your focused monitor.

I was actually thinking about doing what you suggested in your second
paragraph. My plan was to make dwm listen for a signal, at which it
writes the value of the current monitor to a file. The problem is that
is too complex for such a simple function. There is also the question of
portability.

My other approach would be trying to copy what dmenu does - it checks
the position of the currently focused window, or the cursor if no window
is focused. Not fool-proof but much simpler and more portable. The
problem is I hardly know anything about X. I tried copying the code from
dmenu and removing the extra parts, and this is what I got:

```c
#include 
#include 
#include 
#include 

#define MAX(A, B)   ((A) > (B) ? (A) : (B))
#define MIN(A, B)   ((A) < (B) ? (A) : (B))
#define INTERSECT(x,y,w,h,r)  (MAX(0, MIN((x)+(w),(r).x_org+(r).width)  - \
MAX((x),(r).x_org)) * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - \
MAX((y),(r).y_org)))

static int screen;
static Display *dpy;
static Window root;

int main(void)
{
if (!(dpy = XOpenDisplay(NULL))) {
fputs("cannot open display\n", stderr);
return 1;
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
int x, y, i, j;
unsigned int du;
Window w, dw, *dws;
XWindowAttributes wa;
XineramaScreenInfo *info;
Window pw;
int a, di, n, area = 0;

i = 0;
if ((info = XineramaQueryScreens(dpy, ))) {
XGetInputFocus(dpy, , );
if (w != root && w != PointerRoot && w != None) {
/* find top-level window containing current input focus */
do {
if (XQueryTree(dpy, (pw = w), , , , ) && dws)
XFree(dws);
} while (w != root && w != pw);
/* find xinerama screen with which the window intersects most */
if (XGetWindowAttributes(dpy, pw, ))
for (j = 0; j < n; j++)
if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, 
info[j])) > area) {
area = a;
i = j;
}
}
/* no focused window is on screen, so use pointer location instead */
if (!area && XQueryPointer(dpy, root, , , , , , , ))
for (i = 0; i < n; i++)
if (INTERSECT(x, y, 1, 1, info[i]))
break;

XFree(info);
}

printf("Monitor: %d\n", i);
}
```

If there is any improvement I can do, I would be grateful for letting me
know.

> What's not clear is what format you need for your script. What does
> the script need, in order to work? If you only need stuff from X,
> asking X directly is probably simpler, there's already an API. It also
> would make your tool more agnostic, it would probably work with other
> WM using X.

What I need is the number of the focused monitor, so that when I press
my keybinding, the script adjusts the current monitor instead of all the
monitors. I call also use the program to obtain the correct brightness
for the statusbar based on which monitor it is currently appearing on.

I'm sorry for making this bigger than it is supposed to be, but I think
this is also an oppurtunity for me to learn a thing or two about how
these programs work.

Best regards,
Farzat


signature.asc
Description: PGP signature


Re: [dev] [dwm] Obtain focused monitor

2023-01-08 Thread A Farzat
On 23/01/08 11:32am, Hiltjo Posthuma wrote:
> On Sun, Jan 08, 2023 at 07:19:10PM +0900, A Farzat wrote:
> > Is there a way to obtain the currently focused monitor in dwm? I want to
> > use it in my script to control which monitor gets its brightness
> > modified.
> > 
> > Regards,
> > Farzat
> 
> selmon
> 
> -- 
> Kind regards,
> Hiltjo
> 

And how do I access that command? If possible I want to access it from
a shell script.

I am open to modifying the dwm source code if necessary.

Regards,
Farzat


signature.asc
Description: PGP signature


[dev] [dwm] Obtain focused monitor

2023-01-08 Thread A Farzat
Is there a way to obtain the currently focused monitor in dwm? I want to
use it in my script to control which monitor gets its brightness
modified.

Regards,
Farzat


signature.asc
Description: PGP signature