Re: [dev] [dwm] Obtain focused monitor

From: Tom Schwindl <schwindl_AT_posteo.de>
Date: Sun, 08 Jan 2023 13:00:51 +0000

Hi,

On Sun Jan 8, 2023 at 11:40 AM CET, A Farzat wrote:
> 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

selmon isn't a command. It's a variable in the source code located at
dwm.c:269 (upstream). You could write a function like the following to dump
its value to stdout/stderr. Now you have to figure out where to call it.

--
Best Regards,
Tom Schwindl
diff --git a/dwm.c b/dwm.c
index 03baf42b3502..4fa8253c91e0 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -234,6 +234,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
 static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
+static void dumpmon(void);
 
 /* variables */
 static const char broken[] = "broken";
_AT_@ -276,6 +277,13 @@ static Window root, wmcheckwin;
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
 /* function implementations */
+static void
+dumpmon(void)
+{
+	if (selmon)
+		fprintf(stdout, "%d\n", selmon->num);
+}
+
 void
 applyrules(Client *c)
 {
Received on Sun Jan 08 2023 - 14:00:51 CET

This archive was generated by hypermail 2.3.0 : Sun Jan 08 2023 - 14:12:08 CET