Laptop contrast function keys

0

On my glossy narrow viewing angle LCD laptop, in addition to brightness, I would like to be able to adjust the contrast by pressing a function key.

At the console command prompt:

 ~ $ xgamma                     

returns:

 Red  0.900, Green  0.900, Blue  0.900

I would like to construct a command line that takes the last returned field of 0.900 multiply it by 1.1 (to get 0.990) and use that result as input value to:

~ $  xgamma -gamma 0.990 

A command line along the lines of:

~$ xgamma | last / 1.1 | xgamma -gamma

Then using my keyboard layout as an example, and using the distro dependent: Control Center > Keyboard Shortcuts, we can define a more contrast ShiftF5 function key above the existing brightness function key FnF5. For less contrast multiply by 1.1

eromana

Posted 2017-02-12T20:25:26.253

Reputation: 102

Answers

0

The Fortran solution.

From the Linux home directory make a subdirectory /mygamma/

The mygamma directory contains six files: 2 fortran program scripts: contrastdown.f90 and contrastup.f90, their executables gammadown and gammaup, and a shebang file xgammasave that saves the current xgamma value to a text file xgammaval.txt

The xgammasave file looks like this:

#!/bin/bash

xgamma |& tee ~/mygamma/xgammaval.txt

The contrastup.f90 file looks like this:

program contrastup

 character(len=20):: string,string2,string3 ! variable type declarations

 real(kind(1.0)) :: x

 call system('/home/my_name/mygamma/xgammasave') ! write the xgamma value to a file

 open(unit=2,file='/home/my_name/mygamma/xgammaval.txt',action='read',status='old')

 read(unit=2,fmt=*)string,string2,string3 ! read the file

 read(string3,*)x            ! make a real from a string

 x=x/1.2                     ! change the contrast

  if (x .le. 0.1) goto 10    ! xgamma value can not be less than 0.1

 write(string,*)x            ! make a string from a real

 string2='xgamma -gamma ' // trim(string) ! concatenate 2 strings

 call system(string2)        ! pass the string to the command line

10 close(unit=2)

end program contrastup

and contrastdown.f90

program contrastdown

 character(len=20):: string,string2,string3 ! variable type declarations

 real(kind(1.0)) :: x

 call system('/home/my_name/mygamma/xgammasave')  ! write xgamma value to a file

 open(unit=2,file='/home/my_name/mygamma/xgammaval.txt',action='read',status='old')

 read(unit=2,fmt=*)string,string2,string3 ! read the record

 read(string3,*)x             ! make a real from a string

 x=x*1.2                      ! change the contrast

  if (x .ge. 10.0) goto 10   ! xgamma value can not be greater than 10.0

 write(string,*)x             ! make a string from a real

 string2='xgamma -gamma ' // trim(string) ! concatenate two strings

 call system(string2)         ! pass the string to the command line

10 close(unit=2)

end program contrastdown

Make the Fortran executable files gammaup and gammadown:

~/mygamma $ gfortran contrastup.f90 -o gammaup  

~/mygamma $ gfortran contrastdown.f90 -o gammadown 

Depending on Linux flavor, from Control Center > Keyboard Shortcuts, under 'Custom Shortcuts', select 'add', in the name field enter the shortcut key name 'raise gamma' and in the command box enter /home/my_name/mygamma/gammaup and likewise for the 'lower contrast' key with command /home/my_name/mygamma/gammadown

On my laptop FnF6 and FnF5 are the default brightness up/down keys, now above them the newly defined ShiftF6 and ShiftF5 are the contrast up/down keys. Vintage black and white movies now look nice on the glossy screen :)

Can the Fortran solution be Code Golf to less lines.

eromana

Posted 2017-02-12T20:25:26.253

Reputation: 102