Brightness & colour temperature control for desktop PCs

Window managers, icon programs, widgets, etc.
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#61 Post by MochiMoppel »

greengeek wrote:Also - the script does not work the same way my usual method does
And what is your usual method?
the script seems to alter the gamma instead of backlight intensity
The script alters brightness as sensed by xrandr which AFAIK is not the same as the physical backlight intensity of the monitor. A value of 1.0 seems to be relative of the physical backlight intensity.

The script always resets gamma to 1.0 for all 3 colors. So yes, your gamma will be altered if it was set to different values. Reducing brightness results in washed out colors and IMO increasing gamma would result in a more pleasant and sharp display but that's not for me to decide.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#62 Post by greengeek »

Mike Walsh wrote: install this one instead:-

ScreenControl-v1.3-i686

Usage:-

You'll need to re-start 'X', first of all, since this is tray-based. That will place a black/yellow 'split-circle' icon in the tray.
Thanks - this works very well. One question though - I can't figure out how you get the icon into the tray. I expected your pet to incorporate a pinstall.sh which modified .jwmrc-tray, but i see nothing like that.

I'd like to understand how the icon gets where it does...

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#63 Post by greengeek »

MochiMoppel wrote:And what is your usual method?.
Well now that you ask, I realise that it uses xbacklight which I see Mike says is not a solution for desktops anyway.

(I had previously thought I was using a script to echo values to /sys/class/backlight/intel_backlight/brightness but that must have been a previous version)

Anyway, this is the relevant addition to my /root.jwmrc-tray:

Code: Select all

		<TrayButton popup="BacklightUP" icon="/usr/local/lib/X11/pixmaps/brightup24.png" border="true">exec:xbacklight +15</TrayButton>
		<TrayButton popup="BacklightDWN" icon="/usr/local/lib/X11/pixmaps/brightdwn24.png" border="true">exec:xbacklight -10</TrayButton>
		<TrayButton label="◑">exec:/usr/bin/mm_brightness_slider</TrayButton>
		<TrayButton popup="XVkbd" icon="/usr/local/lib/X11/pixmaps/kbd24.png" border="true">exec:xvkbdstart</TrayButton>
		<Pager/>
I don't understand why xbacklight would not work for desktops though.

EDIT : Turns out my original script did not use:
# echo [numeric_value] >sys/class/backlight/intel_backlight/brightness,
instead it used
# echo [numeric_value] > /sys/class/backlight/toshiba/brightness

I don't know why my system shows the "intel_backlight/brightness" as well as the "toshiba/brightness".

EDIT2 : It also shows:
/sys/class/backlight/acpi_video0/brightness

In order to determine valid values for [numeric_value] I use the following syntax to see what max brightness values are permissible:

Code: Select all

# cat /sys/class/backlight/toshiba/max_brightness
7
#
(The weird thing is that intel_backlight/brightness has a max permissible value of 1 but toshiba/brightness and acpi_video0/brightness have max permissible values of 7)

This max permissible value is not always the same on every system. I recall finding some useful scripts on the Arch forum for tailoring the [numeric_value] appropriately for each different system.

Found it:

Code: Select all

#https://bbs.archlinux.org/viewtopic.php?id=134972

#!/bin/bash

# base dir for backlight class
basedir="/sys/class/backlight/"

# get the backlight handler
handler=$basedir$(ls $basedir)"/"

# get current brightness
old_brightness=$(cat $handler"brightness")

# get max brightness
max_brightness=$(cat $handler"max_brightness")

# get current brightness %
old_brightness_p=$(( 100 * $old_brightness / $max_brightness ))

# calculate new brightness % 
new_brightness_p=$(($old_brightness_p $1))

# calculate new brightness value
new_brightness=$(( $max_brightness * $new_brightness_p / 100 ))

# set the new brightness value
sudo chmod 666 $handler"brightness"
echo $new_brightness > $handler"brightness"
Last edited by greengeek on Wed 10 Oct 2018, 09:09, edited 2 times in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#64 Post by MochiMoppel »

greengeek wrote:Well now that you ask, I realise that it uses xbacklight which I see Mike says is not a solution for desktops anyway.
Shouldn't bother you as you seem to use a laptop. I've never used xbacklight so I don't know what is is capable of.

Since you complained about lost gamma: What are your gamma values? Does xbacklight retain those values? The funny thing with xrandr is that when only brightness is set, gamma is reset, and when only gamma is set, brightness is reset (to 1.0). I found that in order to keep the values, both brightness and gamma need to be set at the same time by a single xrandr command. Can be done but I'm not sure if anyone really needs it.

I'm also not sure if it is really necessary to directly change values in /sys/class/backlight. So far I assumed that xrandr would do this.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#65 Post by greengeek »

MochiMoppel wrote: What are your gamma values? .
To be honest I can't see how to display those at the moment. Will research more tomorrow.

EDIT : Just found the xgamma command:

Code: Select all

# xgamma
-> Red  1.000, Green  1.000, Blue  1.000
#
Based on your comments I just tried tweaking gamma via xrandr and can see the blue tint appear (found a comment saying that xrandr "brightness alterations only adjust the 3 gamma values equally rather than changing backlight")

What do you see if you enter:
xrandr --verbose

does it show any comments about "backlight"?

See the last post here:
https://unix.stackexchange.com/question ... brightness

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#66 Post by Mike Walsh »

MochiMoppel wrote:@Mike Walsh: Sorry for the intrusion into your thread. I tried to respond to a request and didn't realize that such a small script can trigger so many issues. I just don't want to leave a mess. :lol:
No worries, Mochi. It all relates, in a roundabout way, to the original subject matter. That's OK by me. I've always maintained that I don't care if we do have lots of different ways available to do the same thing, as not everyone will wish to do stuff in the same fashion.

Choice is a good thing.


Mike. :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#67 Post by MochiMoppel »

greengeek wrote:I can't see how to display those at the moment.
xrandr --verbose | grep Gamma
found a comment saying that xrandr "brightness alterations only adjust the 3 gamma values equally rather than changing backlight"
Hmmm... if so there wouldn't be any need for brightness control and gamma control would be sufficient, but I see that they do different things.
What do you see if you enter:
xrandr --verbose
does it show any comments about "backlight"?
Backlight: 0 (0x00000000) range: (0,10)

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#68 Post by Mike Walsh »

greengeek wrote:
Mike Walsh wrote: install this one instead:-

ScreenControl-v1.3-i686

Usage:-

You'll need to re-start 'X', first of all, since this is tray-based. That will place a black/yellow 'split-circle' icon in the tray.
Thanks - this works very well. One question though - I can't figure out how you get the icon into the tray. I expected your pet to incorporate a pinstall.sh which modified .jwmrc-tray, but i see nothing like that.

I'd like to understand how the icon gets where it does...
Glad it works for you, GG.

As to how it places the icon into the tray.....well, I'm not too clear about that myself! If you open /root/my-applications/bin/ScreenControl.sh with Geany, you have this:-

Code: Select all

#!/bin/sh
#
#YAD 'one-liner' from musher0 / fredx181, to place executable tray icon in notification area
#
yad --notification --text="Brightness and tint" --command='/usr/local/bin/BrightSelect.sh' --image='/usr/local/lib/X11/pixmaps/Bright.png' 2>/dev/null
When I was trying to sort out a way to implement a GUI for a 'permissions changer' (for the current Chromes, which run-as-spot), that triggered from the tray, Fred and musher0 between them came up with a quick, easy way to place the icon there.

Most of it's self-explanatory. The action is handled by the YAD '--notifications' command. (See smokey01's excellent YAD tutorial for more in-depth explanations of YAD's various functions. Probably aided by the fact that, as I understand it, ROX/JWM between them just treat the tray as another 'panel'?)

'--text' gives you the tooltip.

'--command' allows you to implement whatever function you want to employ when you click on it (in this case, calling a YAD script to display a GUI box.....which then lets you select further functions by calling additional scripts).

'--image' lets you choose the icon to use (in the tray).

But I'm really not certain exactly what the

Code: Select all

2>/dev/null
.....actually does. Perhaps some web research would throw light on that particular function; maybe Mochi could tell us.....he's light-years ahead of me when it comes to understanding what various items of code will do. It worked at the time, so I didn't question it.....and I've since used it in various other scripts for this & that, where I want an icon in the notification area, as opposed to a 'launcher' or a .desktop Menu entry.


Mike. :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#69 Post by MochiMoppel »

Mike Walsh wrote:As to how it places the icon into the tray.....well, I'm not too clear about that myself!
The window manager has an area for applications that request to run in the tray (in JWM this area is called <Dock/>, normally placed left of the clock). Applications that are designed to run in the tray or request to do so, like yad with its --notification option, "find" this area. If there are already applications in the "Dock", a newcomer is normally placed left of them.
But I'm really not certain exactly what the

Code: Select all

2>/dev/null
.....actually does.
IMO does the wrong thing here and should be removed. It suppresses error messages, but since yad is a GUI application you wouldn't see them anyway, and when yad doesn't work as expected and you start it from a console, you definitely do want to see any error messages.

BTW: For changing color temperature is redshift really necessary? Your slider values range between 2400K and 6500K. These seem to correspond to gamma values between 1.0:1.7:3.0 and 1.0:1.0:1.0. Though this doesn't look like a linear correlation, someone with a math mind may figure out the formula. The rest can be done by xrandr. No extra tools needed.

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#70 Post by Mike Walsh »

Thanks for the explanation, Mochi.

No explanation was forthcoming about that

Code: Select all

2>/dev/null
...at the time. As I said, I didn't question it, simply because it 'worked' (and did what I wanted). Perhaps I should learn to be a wee bit more inquisitive!

The one thing I do know about /dev/null is that it's more or less a 'black hole'; a means to dispose of extraneous code you don't want hanging around, so you pipe it to /dev/null & it 'disappears' into thin air.

Is that a reasonable analogy? :lol:

Cheers.


Mike. :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#71 Post by MochiMoppel »

Mike Walsh wrote:Is that a reasonable analogy? :lol::
I'm afraid not.
Black holes exist but for devices that can "dispose of extraneous code" we may still have to wait a couple of years :wink:

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#72 Post by greengeek »

@Mike - my question about how the icon appears in the tray is actually aimed at trying to get rid of the need to restart X (which ditches any open windows)

My method of getting icons into the tray is to add appropriate code to /root/.jwmrc-tray and then restarting the WM (JWM in my case). This method minimises disruption to the user.

However - it is only my assumption that the restartX required by your pet is for the purposes of getting the icon in place - I am probably wrong and it may be for other reasons.

If there was a way to get rid of the need to restartX the pet would be much better. (My system has no persistence so I rely on pets that can be loaded on the fly as needed - and reboots or X restarts are problematic for me as they trash my "current running environment").

I will see if I can rearrange your pet to avoid X restart.

cheers!

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#73 Post by greengeek »

MochiMoppel wrote:
greengeek wrote:What do you see if you enter:
xrandr --verbose
does it show any comments about "backlight"?
Backlight: 0 (0x00000000) range: (0,10)
What happens if you try the following commands (substituting your xrandr display identifier for LVDS1)?

Code: Select all

xrandr --output LVDS1 --set BACKLIGHT 5

Code: Select all

xrandr --output LVDS1 --set BACKLIGHT 10
("BACKLIGHT" must be uppercase)


EDIT : Reminder to self:- make a trial script using:

Code: Select all

xrandr | grep " connected " | awk '{ print$1 }'
to identify display for xrandr to control BACKLIGHT on.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#74 Post by fredx181 »

greengeek wrote:However - it is only my assumption that the restartX required by your pet is for the purposes of getting the icon in place - I am probably wrong and it may be for other reasons.
The restart X is needed to execute /root/Startup/ScreenControl.sh
(as all scripts in /root/Startup/ will be executed at login)
But you can run in terminal:

Code: Select all

/root/Startup/ScreenControl.sh
Instead of restarting X
(or just click on /root/Startup/ScreenControl.sh will do also)
Of course the .pet can include pinstall.sh executing /root/Startup/ScreenControl.sh but doing above is easy enough IMO.
I cannot understand btw, what can be the problem when restarting X, but apparently for you there's some issue with that.

Fred

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#75 Post by Mike Walsh »

greengeek wrote:@Mike - my question about how the icon appears in the tray is actually aimed at trying to get rid of the need to restart X (which ditches any open windows)

My method of getting icons into the tray is to add appropriate code to /root/.jwmrc-tray and then restarting the WM (JWM in my case). This method minimises disruption to the user.

However - it is only my assumption that the restartX required by your pet is for the purposes of getting the icon in place - I am probably wrong and it may be for other reasons.

If there was a way to get rid of the need to restartX the pet would be much better. (My system has no persistence so I rely on pets that can be loaded on the fly as needed - and reboots or X restarts are problematic for me as they trash my "current running environment").

I will see if I can rearrange your pet to avoid X restart.

cheers!
Mmm..

Frankly, I don't see how you can.....unless there's a location for JWM stuff that I don't yet know about.

/root/.jwmrc-tray gives definite locations for 'Launcher' items; for positioning of the pager; for the 'Dock.....and for the location of the 'notification area' (but not the contents of same.)

/root/.jwm deals with themes'n'stuff.

/etc/xdg/templates/_root_.jwmrc, AFAIK, deals with WM 'settings' and configuration of 'Menu' stuff. This is where changes are written to before running 'fixmenus', after which you re-start 'X' to complete the changes.

Does anybody know where the script dealing with the contents of the notification area resides? Be interesting to find out, actually.


Mike. :wink:
Last edited by Mike Walsh on Wed 10 Oct 2018, 18:26, edited 1 time in total.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#76 Post by greengeek »

fredx181 wrote:I cannot understand btw, what can be the problem when restarting X, but apparently for you there's some issue with that.
Yes, X restart is problematic for me - I will try to explain:

I try to keep my system small and "lean" - so I often use software by loading pets during a session - rather than having those pets permanently loaded into a savefile (I have no savefile).

Imagine the situation where I have a number of windows open (browser , word processor etc) and I decide the screen is too bright so I load Mikes pet to control gamma and brightness - if I am forced to restart X to get the pet working, then all of those windows will close and I will be back to a blank desktop and I will have to start my session all over again.

(Restart WM does not cause window loss)

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#77 Post by fabrice_035 »

greengeek wrote:

Code: Select all

xrandr --output LVDS1 --set BACKLIGHT 5

Code: Select all

xrandr --output LVDS1 --set BACKLIGHT 10
("BACKLIGHT" must be uppercase)
.

Code: Select all

root# xrandr | grep " connected " | awk '{ print$1 }'
HDMI-0
LVDS

root# xrandr --output LVDS --set BACKLIGHT 5
X Error of failed request:  BadName (named color or font does not exist)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  11 (RRQueryOutputProperty)
  Serial number of failed request:  33
  Current serial number in output stream:  33
root# 


User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#78 Post by greengeek »

Mike Walsh wrote:Does anybody know where the script dealing with the contents of the notification area resides? Be interesting to find out, actually.:
Hi Mike,

I am no expert at this but hopefully I can show one method to position tray icons:

If you are using JWM as your WM, open the hidden file /root/.jwmrc-tray
Here is mine:

Code: Select all

<JWM>
	<Tray  autohide="false" insert="right" x="0" y="-1" border="1" height="28" >
		<!-- Additional TrayButton attribute: label -->
		<TrayButton label="Menu" icon="logo-mini.png" border="true">root:3</TrayButton>
		<TrayButton popup="Show Desktop" icon="mini-desktop.xpm" border="true">showdesktop</TrayButton>
		<TrayButton popup="Terminal" icon="/usr/local/lib/X11/pixmaps/console24.png" border="true">exec:urxvt</TrayButton>
		<TrayButton popup="Files" icon="/usr/local/lib/X11/pixmaps/folder24.png" border="true">exec:rox</TrayButton>
		<TrayButton popup="Browser" icon="/usr/local/lib/X11/pixmaps/www24.png" border="true">exec:defaultbrowser</TrayButton>
		<TrayButton popup="Leafpad" icon="/usr/local/lib/X11/mini-icons/leafpad.png" border="true">exec:leafpad</TrayButton>
		<TrayButton popup="BacklightUP" icon="/usr/local/lib/X11/pixmaps/brightup24.png" border="true">exec:xbacklight +15</TrayButton>
		<TrayButton popup="BacklightDWN" icon="/usr/local/lib/X11/pixmaps/brightdwn24.png" border="true">exec:xbacklight -10</TrayButton>
		
		<TrayButton popup="XVkbd" icon="/usr/local/lib/X11/pixmaps/kbd24.png" border="true">exec:xvkbdstart</TrayButton>
		<Pager/>
		<!-- Additional TaskList attribute: maxwidth -->
		<TaskList maxwidth="200"/>
		<Dock/>
		<!-- Additional Swallow attribute: height -->
	<!--	<Swallow name="blinky">
			blinkydelayed -bg "#DCDAD5"
		</Swallow> -->
	<!--	<Swallow name="xtmix-launcher">
			xtmix -launch
		</Swallow> -->
	<!--	<Swallow name="asapm">
			asapmshell -u 4
		</Swallow> -->
			<!--	<Swallow name="freememapplet" width="34">
			freememappletshell
		</Swallow> -->
	<!--	<Swallow name="freememapplet" width="34">
			freememappletshell
		</Swallow> -->
		<Swallow name="xload" width="32">
			xload -nolabel -bg "#888888" -fg red -hl white
		</Swallow>
		<Clock format="%H:%M">minixcal</Clock>
	</Tray>
</JWM>
I can now add in the line that Mochi was using to position his unicode symbol as a tray icon eg:

Code: Select all

<TrayButton label="◑">exec:/usr/bin/mm_brightness_slider</TrayButton>
If I put that line in the "TrayButton" area (eg in the blank space that I left above the "XVKBD" tray button declaration) then that icon will appear on the left hand side of the menu tray, with the icons sitting to the right of the menu button.

If I put that line somewhere in the "swallow" declarations then it will appear in the tray area near the clock

To activate the change all I need to do is:

Code: Select all

jwm -restart
and the icon appears without losing all of my open windows (as would happen with a restart X)

(I am sure Mochi and others will correct my fundamental misunderstandings about this :-) )

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#79 Post by greengeek »

fabrice_035 wrote:root# xrandr --output LVDS --set BACKLIGHT 5
X Error of failed request: BadName (named color or font does not exist)
Major opcode of failed request: 140 (RANDR)
Minor opcode of failed request: 11 (RRQueryOutputProperty)
Serial number of failed request: 33
Current serial number in output stream: 33
root#

[/code]
Hi Fabrice, can you post the output of the following command please?

Code: Select all

xrandr --verbose | grep Backlight
(must use capital B for Backlight)

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#80 Post by fredx181 »

@greengeek

Following MochiMoppel's brightness slider example for adding to ~/.jwmrc:

Code: Select all

<TrayButton label="◑">exec:/usr/bin/mm_brightness_slider</TrayButton>
Then:
For Mike's BrightSelect.sh script, add in ~/.jwmrc

Code: Select all

<TrayButton label="◑">exec:/usr/local/bin/BrightSelect.sh</TrayButton>
Then: "jwm -restart" should do.

But then maybe better remove /root/Startup/ScreenControl.sh
(to avoid displaying the yad icon (will be duplicate), in case you do restart X or reboot with save)
xrandr --verbose | grep Backlight
This gives no output for me.

Fred

Post Reply