Dim inactive monitor in dual head configuration

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Dim inactive monitor in dual head configuration

Dimitri Minaev
Hello again.

I've configured Stumpwm to run on a dual head configuration. But I
always forget which monitor is currently active and start typing in a
wrong window. I found a Python script that dims the inactive monitor a
bit (See
http://askubuntu.com/questions/665155/how-to-highlight-current-screen-or-window).
It runs in a loop, sleeping for a 0.5 second after every run. Feels very
sluggish, so I thought I could write a Lisp function that would dim the
inactive monitor every time I move focus to and fro.

Here's what I've come up with:

(ql:quickload "cl-utilities")
(defun parse-xrandr ()
   (loop for i in (split-string (run-shell-command "xrandr" t))
      when (search " connected" i)
      collect (car (cl-utilities:split-sequence #\Space i))))

(defun dim-inactive-head (arg1 arg2)
   (let* ((heads (parse-xrandr))
         (brighthead (slot-value (current-head) 'number))
         (dimhead (if (eql brighthead 0) 1 0)))
     (run-shell-command
      (format nil "/usr/bin/xrandr --output ~d --brightness 1.0" (nth
brighthead heads)))
     (run-shell-command
      (format nil "/usr/bin/xrandr --output ~d --brightness 0.6" (nth
dimhead heads)))))

(add-hook *focus-frame-hook* 'dim-inactive-head)
(add-hook *focus-group-hook* 'dim-inactive-head)

The function uses cl-utilities:split-sequence, hence ql:quickload call
in the beginning. Is there an alternative that doesn't have any
dependencies?

It kinda works. I'm a bit worried by the fact that on one occasion the
call to xrandr got stuck and didn't return, effectively putting the
whole Stumpwm to stop. Besides I'm not sure if the hook is triggered
when window placement rules switch groups. It would be nice if someone
helped with testing and especially with fixing this straightforward
implementation :)

In the beginning I used a wrong hook, *focus-window-hook*, but for some
reason it didn't let me open any new window. Every time I tried to open
xterm or anything else, Stumpwm stuck up. Strange, I thought that tiny
function might be called any time, any place. It shouldn't have any
harmful side effects.

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

David Bjergaard
Hi Dimitri,

Two notes: If collect-output-p is nil when run-shell-command is called, it will
not wait for xrandr to finish.  See:
https://stumpwm.github.io/git/stumpwm-git_10.html#index-run_002dshell_002dcommand

Another option to background the process is:
(run-shell-command "command &> /dev/null &")

I'm glad that you are enjoying the hacking experience.  All of my ideas are
beyond my technical ability to execute ;)

    David
   

Dimitri Minaev <[hidden email]> writes:

> Hello again.
>
> I've configured Stumpwm to run on a dual head configuration. But I
> always forget which monitor is currently active and start typing in a
> wrong window. I found a Python script that dims the inactive monitor a
> bit (See
> http://askubuntu.com/questions/665155/how-to-highlight-current-screen-or-window). It
> runs in a loop, sleeping for a 0.5 second after every run. Feels very
> sluggish, so I thought I could write a Lisp function that would dim
> the inactive monitor every time I move focus to and fro.
>
> Here's what I've come up with:
>
> (ql:quickload "cl-utilities")
> (defun parse-xrandr ()
>   (loop for i in (split-string (run-shell-command "xrandr" t))
>      when (search " connected" i)
>      collect (car (cl-utilities:split-sequence #\Space i))))
>
> (defun dim-inactive-head (arg1 arg2)
>   (let* ((heads (parse-xrandr))
> (brighthead (slot-value (current-head) 'number))
> (dimhead (if (eql brighthead 0) 1 0)))
>     (run-shell-command
>      (format nil "/usr/bin/xrandr --output ~d --brightness 1.0" (nth
> brighthead heads)))
>     (run-shell-command
>      (format nil "/usr/bin/xrandr --output ~d --brightness 0.6" (nth
> dimhead heads)))))
>
> (add-hook *focus-frame-hook* 'dim-inactive-head)
> (add-hook *focus-group-hook* 'dim-inactive-head)
>
> The function uses cl-utilities:split-sequence, hence ql:quickload call
> in the beginning. Is there an alternative that doesn't have any
> dependencies?
>
> It kinda works. I'm a bit worried by the fact that on one occasion the
> call to xrandr got stuck and didn't return, effectively putting the
> whole Stumpwm to stop. Besides I'm not sure if the hook is triggered
> when window placement rules switch groups. It would be nice if someone
> helped with testing and especially with fixing this straightforward
> implementation :)
>
> In the beginning I used a wrong hook, *focus-window-hook*, but for
> some reason it didn't let me open any new window. Every time I tried
> to open xterm or anything else, Stumpwm stuck up. Strange, I thought
> that tiny function might be called any time, any place. It shouldn't
> have any harmful side effects.
>
> _______________________________________________
> Stumpwm-devel mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Joram Schrijver
In reply to this post by Dimitri Minaev
Hi Dimitri,

On Thu, Jun 2, 2016, at 03:02 PM, Dimitri Minaev wrote:

> Hello again.
>
> I've configured Stumpwm to run on a dual head configuration. But I
> always forget which monitor is currently active and start typing in a
> wrong window. I found a Python script that dims the inactive monitor a
> bit (See
> http://askubuntu.com/questions/665155/how-to-highlight-current-screen-or-window).
> It runs in a loop, sleeping for a 0.5 second after every run. Feels very
> sluggish, so I thought I could write a Lisp function that would dim the
> inactive monitor every time I move focus to and fro.
>
> Here's what I've come up with:
>
> (ql:quickload "cl-utilities")
> (defun parse-xrandr ()
>    (loop for i in (split-string (run-shell-command "xrandr" t))
>       when (search " connected" i)
>       collect (car (cl-utilities:split-sequence #\Space i))))
>
> (defun dim-inactive-head (arg1 arg2)
>    (let* ((heads (parse-xrandr))
> (brighthead (slot-value (current-head) 'number))
> (dimhead (if (eql brighthead 0) 1 0)))
>      (run-shell-command
>       (format nil "/usr/bin/xrandr --output ~d --brightness 1.0" (nth
> brighthead heads)))
>      (run-shell-command
>       (format nil "/usr/bin/xrandr --output ~d --brightness 0.6" (nth
> dimhead heads)))))
>
> (add-hook *focus-frame-hook* 'dim-inactive-head)
> (add-hook *focus-group-hook* 'dim-inactive-head)
>
> The function uses cl-utilities:split-sequence, hence ql:quickload call
> in the beginning. Is there an alternative that doesn't have any
> dependencies?

The alternative provided by StumpWM is right above it in your code:
`SPLIT-STRING`. By default it splits on a number of different whitespace
characters, but you can tell it what to split on. `(split-string i "
")`.

>
> It kinda works. I'm a bit worried by the fact that on one occasion the
> call to xrandr got stuck and didn't return, effectively putting the
> whole Stumpwm to stop. Besides I'm not sure if the hook is triggered
> when window placement rules switch groups. It would be nice if someone
> helped with testing and especially with fixing this straightforward
> implementation :)

There is also the problem that there is absolutely no guarantee that
xrandr and StumpWM will list heads in the same order. In fact, for me,
it's the other way around right now.

>
> In the beginning I used a wrong hook, *focus-window-hook*, but for some
> reason it didn't let me open any new window. Every time I tried to open
> xterm or anything else, Stumpwm stuck up. Strange, I thought that tiny
> function might be called any time, any place. It shouldn't have any
> harmful side effects.
>
> _______________________________________________
> Stumpwm-devel mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

--
  Joram

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Dimitri Minaev
In reply to this post by David Bjergaard

On 06/02/2016 06:43 PM, David Bjergaard wrote:
>
> Two notes: If collect-output-p is nil when run-shell-command is called, it will
> not wait for xrandr to finish.  See:
> https://stumpwm.github.io/git/stumpwm-git_10.html#index-run_002dshell_002dcommand

Thanks for the comment, David. I thought I had set collect-output-p to
the right values. When I need the output of xrandr, the argument is t.
When all I need is the side-effect of xrandr, it is nil and the command
shouldn't lock the window manager.

Today I saw Stumpwm to lock once again. No idea why, but xrandr didn't
return, so I thought the explicit query for information might help and
changed the xrandr call to 'xrandr -q'.

> I'm glad that you are enjoying the hacking experience.  All of my ideas are
> beyond my technical ability to execute ;)

Necessity is the mother of invention :) I just had to find a way to cope
with the two monitors.

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Dimitri Minaev
In reply to this post by Joram Schrijver
On 06/02/2016 10:59 PM, Joram Schrijver wrote:

>> The function uses cl-utilities:split-sequence, hence ql:quickload call
>> in the beginning. Is there an alternative that doesn't have any
>> dependencies?
>
> The alternative provided by StumpWM is right above it in your code:
> `SPLIT-STRING`. By default it splits on a number of different whitespace
> characters, but you can tell it what to split on. `(split-string i "
> ")`.

Oops... I should've checked the function definition. I thought it only
splits on newline.

> There is also the problem that there is absolutely no guarantee that
> xrandr and StumpWM will list heads in the same order. In fact, for me,
> it's the other way around right now.

But Stumpwm gets the list of head from `xdpyinfo -ext XINERAMA', right?
I could replace `xrandr' with the `xdpyinfo', too.

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Dimitri Minaev


On 06/03/2016 09:28 AM, Dimitri Minaev wrote:
> On 06/02/2016 10:59 PM, Joram Schrijver wrote:

>> There is also the problem that there is absolutely no guarantee that
>> xrandr and StumpWM will list heads in the same order. In fact, for me,
>> it's the other way around right now.
>
> But Stumpwm gets the list of head from `xdpyinfo -ext XINERAMA', right?
> I could replace `xrandr' with the `xdpyinfo', too.

Silly me. I'll have to use xrandr to set the brightness level.

Well, the other option might be to copy that Python script: get the
current window id, get its coordinates and find the monitor where these
coordinates are located. Very awkward :(

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

David Bjergaard
Dimitri Minaev <[hidden email]> writes:

> On 06/03/2016 09:28 AM, Dimitri Minaev wrote:
>> On 06/02/2016 10:59 PM, Joram Schrijver wrote:
>
>>> There is also the problem that there is absolutely no guarantee that
>>> xrandr and StumpWM will list heads in the same order. In fact, for me,
>>> it's the other way around right now.
>>
>> But Stumpwm gets the list of head from `xdpyinfo -ext XINERAMA', right?
>> I could replace `xrandr' with the `xdpyinfo', too.
>
> Silly me. I'll have to use xrandr to set the brightness level.
>
> Well, the other option might be to copy that Python script: get the
> current window id, get its coordinates and find the monitor where
> these coordinates are located. Very awkward :(
This should be "baked in" to stumpwm.  It shouldn't be as awkward as the python
script.  I use two monitors, and I've never been annoyed enough by not knowing
which has focus to need to dim one.  You could also change the window border
width and color to be something more bright.  It defaults to white.  This might
help make things more visible.  

    David
   

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Joseph Mingrone
David Bjergaard <[hidden email]> writes:
> You could also change the window border width and color to be something more
> bright.  It defaults to white.  This might help make things more visible.

That works for me.

-------------------------------------------------------------
(setf *colors* (append *colors* (list "Orange2" "Gray52")))
(setf *normal-border-width* 5)

(update-color-map (current-screen))
(set-focus-color "Orange2")
------------------------------------------------------------- [1]

The advantage I see is that I often want to see what's going on in the unfocused
window(s).  Maybe your dimming isn't so dark though?

[1] I think that's all the applicable code.  I can't restart to test ATM and I
don't have the luxury of hacking in real time due to an OS-specific bug/crash in
either SBCL or StumpWM, triggered when swank is started.

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

signature.asc (834 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Dimitri Minaev
On 06/04/2016 08:33 PM, Joseph Mingrone wrote:

>
> That works for me.
>
> -------------------------------------------------------------
> (setf *colors* (append *colors* (list "Orange2" "Gray52")))
> (setf *normal-border-width* 5)
>
> (update-color-map (current-screen))
> (set-focus-color "Orange2")
> ------------------------------------------------------------- [1]

Indeed, that works, and works reliably. Thanks for the snippet. But when
there's more than one window on the screen, it might take some time to
find the active one, while a dim screen leaps to the eye immediately.

> The advantage I see is that I often want to see what's going on in the unfocused
> window(s).  Maybe your dimming isn't so dark though?

No, it's not. And the level may be easily adapted.

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Dimitri Minaev
In reply to this post by Dimitri Minaev


On 06/03/2016 09:28 AM, Dimitri Minaev wrote:
>
>> There is also the problem that there is absolutely no guarantee that
>> xrandr and StumpWM will list heads in the same order. In fact, for me,
>> it's the other way around right now.
>
> But Stumpwm gets the list of head from `xdpyinfo -ext XINERAMA', right?
> I could replace `xrandr' with the `xdpyinfo', too.

I'm wise as king Solomon. And in my wisdom, I proclaim: render unto the
user the thing that is user's. May he provides the list of heads in the
correct order:

(setf *xrandr-heads* '("HDMI1" "VGA1"))

(defun dim-inactive-head (arg1 arg2)
   (let* ((brighthead (slot-value (current-head) 'number))
         (dimhead (if (eql brighthead 0) 1 0)))
     (run-shell-command
      (format nil "/usr/bin/xrandr --output ~d --brightness 1.0" (nth
brighthead *xrandr-heads*)))
     (run-shell-command
      (format nil "/usr/bin/xrandr --output ~d --brightness 0.7" (nth
dimhead *xrandr-heads*)))))

That'll "fix" the problem of the stuck xrandr, too ;)

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

David Bjergaard
It occurs to me, I have the following in my .Xresources and it dims the
unfocused terminal when not selected:
> *background:            S_base03
> *foreground:            S_base0
> *fading:                40
> *fadeColor:             S_base03
> *cursorColor:           S_base1
> *pointerColorBackground:S_base01
> *pointerColorForeground:S_base1

The S_base* colors are defined earlier.  It works well.  I only ever confuse
active windows when its firefox or emacs that have focus.  I'm sure you could
find a dimmer for emacs... Firefox wouldn't be as simple.

Here's a neat idea if you have xcompmgr installed. It comes with transset, so
you can map over the non-focused windows and set their transparancy be
transparent, and the focused window to have opacity 1.  I don't have time to
hack up the lisp, but if it were packaged in a module I'd probably use it.  I
like it better than messing with xrandr since that feels like a bit of overkill
(but I only have two monitors, some people have 4-5).  Also, it would show the
exact window focused, and not just the monitor the window is on.

    David
   

Dimitri Minaev <[hidden email]> writes:

> On 06/03/2016 09:28 AM, Dimitri Minaev wrote:
>>
>>> There is also the problem that there is absolutely no guarantee that
>>> xrandr and StumpWM will list heads in the same order. In fact, for me,
>>> it's the other way around right now.
>>
>> But Stumpwm gets the list of head from `xdpyinfo -ext XINERAMA', right?
>> I could replace `xrandr' with the `xdpyinfo', too.
>
> I'm wise as king Solomon. And in my wisdom, I proclaim: render unto
> the user the thing that is user's. May he provides the list of heads
> in the correct order:
>
> (setf *xrandr-heads* '("HDMI1" "VGA1"))
>
> (defun dim-inactive-head (arg1 arg2)
>   (let* ((brighthead (slot-value (current-head) 'number))
> (dimhead (if (eql brighthead 0) 1 0)))
>     (run-shell-command
>      (format nil "/usr/bin/xrandr --output ~d --brightness 1.0" (nth
> brighthead *xrandr-heads*)))
>     (run-shell-command
>      (format nil "/usr/bin/xrandr --output ~d --brightness 0.7" (nth
> dimhead *xrandr-heads*)))))
>
> That'll "fix" the problem of the stuck xrandr, too ;)
>
> _______________________________________________
> Stumpwm-devel mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

David Bjergaard
Hi,

Here's some POC that might get you started, it wouldn't take much to generalize
and get the hooks right:
> (run-shell-command (format nil "transset -t --id ~a" (window-id (first
> (visible-windows)))))
One could imagine mapping over the visible windows and toggling their
transparancy as long as it didn't have focus.

If I get further inspired I'll hack this into a module later (unless you'd like
to Dimitri :))

    David
   
David Bjergaard <[hidden email]> writes:

> It occurs to me, I have the following in my .Xresources and it dims the
> unfocused terminal when not selected:
>> *background:            S_base03
>> *foreground:            S_base0
>> *fading:                40
>> *fadeColor:             S_base03
>> *cursorColor:           S_base1
>> *pointerColorBackground:S_base01
>> *pointerColorForeground:S_base1
>
> The S_base* colors are defined earlier.  It works well.  I only ever confuse
> active windows when its firefox or emacs that have focus.  I'm sure you could
> find a dimmer for emacs... Firefox wouldn't be as simple.
>
> Here's a neat idea if you have xcompmgr installed. It comes with transset, so
> you can map over the non-focused windows and set their transparancy be
> transparent, and the focused window to have opacity 1.  I don't have time to
> hack up the lisp, but if it were packaged in a module I'd probably use it.  I
> like it better than messing with xrandr since that feels like a bit of overkill
> (but I only have two monitors, some people have 4-5).  Also, it would show the
> exact window focused, and not just the monitor the window is on.
>
>     David
>    
>
> Dimitri Minaev <[hidden email]> writes:
>
>> On 06/03/2016 09:28 AM, Dimitri Minaev wrote:
>>>
>>>> There is also the problem that there is absolutely no guarantee that
>>>> xrandr and StumpWM will list heads in the same order. In fact, for me,
>>>> it's the other way around right now.
>>>
>>> But Stumpwm gets the list of head from `xdpyinfo -ext XINERAMA', right?
>>> I could replace `xrandr' with the `xdpyinfo', too.
>>
>> I'm wise as king Solomon. And in my wisdom, I proclaim: render unto
>> the user the thing that is user's. May he provides the list of heads
>> in the correct order:
>>
>> (setf *xrandr-heads* '("HDMI1" "VGA1"))
>>
>> (defun dim-inactive-head (arg1 arg2)
>>   (let* ((brighthead (slot-value (current-head) 'number))
>> (dimhead (if (eql brighthead 0) 1 0)))
>>     (run-shell-command
>>      (format nil "/usr/bin/xrandr --output ~d --brightness 1.0" (nth
>> brighthead *xrandr-heads*)))
>>     (run-shell-command
>>      (format nil "/usr/bin/xrandr --output ~d --brightness 0.7" (nth
>> dimhead *xrandr-heads*)))))
>>
>> That'll "fix" the problem of the stuck xrandr, too ;)
>>
>> _______________________________________________
>> Stumpwm-devel mailing list
>> [hidden email]
>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

Dimitri Minaev
On 06/06/2016 09:52 PM, David Bjergaard wrote:

> Hi,
>
> Here's some POC that might get you started, it wouldn't take much to generalize
> and get the hooks right:
>> (run-shell-command (format nil "transset -t --id ~a" (window-id (first
>> (visible-windows)))))
> One could imagine mapping over the visible windows and toggling their
> transparancy as long as it didn't have focus.
>
> If I get further inspired I'll hack this into a module later (unless you'd like
> to Dimitri :))

Hmm. Will inactive windows be completely transparent? Doesn't look like
my ideal desktop. At least, this time your idea is completely within
your technical competence :) I'll definitely try it out when you
implement it.

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dim inactive monitor in dual head configuration

scottjad
In reply to this post by David Bjergaard
On Mon, Jun 6, 2016 at 10:42 AM, David Bjergaard <[hidden email]> wrote:
> Also, it would show the
> exact window focused, and not just the monitor the window is on.

FYI compton, an improved version of xcompmgr, has an option
inactive-dim that will dim all but the active window.

Scott

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel