You are not logged in.

#1 2016-05-15 16:32:30

ghorvath
Member
Registered: 2015-10-01
Posts: 161

Bunsenlabs Hydrogen on a Samsung Series 9 NP900X3C laptop

This post sums up most of my experience installing linux (specifically Bunsenlabs Hydrogen) on my Samsung Series 9 laptop (see http://www.samsung.com/us/support/owner … 2US-search for specifications).

First of all: do not use UEFI with this laptop, because it can brick your laptop. First it happened with someone trying to boot an Ubuntu live CD, but later it became clear that one can brick their laptop from windows because of the faulty BIOS. For more information, see http://mjg59.dreamwidth.org/22855.html and go from there. The Linux kernel people solved the issue by blacklisting the samsung kernel module when booted from UEFI mode. The proper solution of course would be that samsung developers fix the bug in the BIOS, but that did not happen in the past 3 years....

Bottom line: do not use UEFI, use old style BIOS or compatibility mode, or whatever it is called. At least with this laptop, otherwise you will not be able to use some of its capabilities.

The install went without any hiccups (I used the RC2 installer), I used this partitioning scheme for my ssd drive: https://wiki.debian.org/Multi%20HDD/SSD … n%20Scheme (without the RAID stuff, as I only have one ssd in this laptop).

I changed /etc/default/grub due to mostly this post http://pixelchaos.net/2013/01/30/debian … ultrabook/

GRUB_CMDLINE_LINUX_DEFAULT="quiet acpi_backlight=native i915.enable_fbc=1 i915.lvds_downclock=1"
# acpi_backlight=native or none needed for kernel 4.2, ignored by kernel 3.16
# i915.enable_rc6=3 already by reading from chip

To change the ssd-scheduler to deadline, I created the file /etc/udev/rules.d/60-ssd-scheduler.rules with

# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"

For less swapping (this laptop has 4GB memory, so I would not want to use the ssd drive for writing on it unnecessarily) I have the file /etc/sysctl.d/local.conf with

#vm.swappiness=0
vm.swappiness=1

For using the multitouch settings, I used the debian page https://wiki.debian.org/SynapticsTouchpad to create /etc/X11/xorg.conf.d/synaptics.conf with

# Copied from https://wiki.debian.org/SynapticsTouchpad
# All entries already existing by default configuration are commented out

Section "InputClass"
        Identifier      "Touchpad"                      # required
        MatchIsTouchpad "yes"                           # required
        Driver          "synaptics"                     # required
#        Option          "MinSpeed"              "0.5"
#        Option          "MaxSpeed"              "1.0"
#        Option          "AccelFactor"           "0.075"
#        Option          "TapButton1"            "1"
        Option          "TapButton2"            "2"     # multitouch
        Option          "TapButton3"            "3"     # multitouch
#        Option          "VertTwoFingerScroll"   "1"     # multitouch
        Option          "HorizTwoFingerScroll"  "1"     # multitouch
#        Option          "VertEdgeScroll"        "1"
#        Option          "CoastingSpeed"         "8"
        Option          "CornerCoasting"        "1"
        Option          "CircularScrolling"     "1"
        Option          "CircScrollTrigger"     "7"
# EdgeMotion is not available on the Samsung touchpad
#        Option          "EdgeMotionUseAlways"   "1"
        Option          "LBCornerButton"        "8"     # browser "back" btn
        Option          "RBCornerButton"        "9"     # browser "forward" btn
EndSection

While we are at it, the touchpad is too sensitive for my taste, so I changed the syndaemon settings in ~/.config/openbox/autostart (it may not be necessary with stable bunsen)

## Run syndaemon for touchpad tapping waiting 1.5 seconds
## (instead of the default 2.0 seconds) after last keypress
(sleep 2s && syndaemon -d -k -R -t -i 1.5) &

For the nicer systray icon, I purged fdpowermon and installed xfce4-power-manager from the bunsenlabs jessie backports. This, I believe is now handled automatically by the bl-welcome script. Also, this allows the use of presentation mode. BTW, I forked the original lightsOn script https://github.com/iye/lightsOn to use this presentation mode, see https://github.com/hungaborhorvath/lightsOn if interested. I cloned it to my ~/bin directory, and added

## Run lightsOn script
(sleep 2s && /home/ghorvath/bin/lightsOn/lightsOn.sh) &

into my ~/.config/openbox/autostart file. Further, to toggle presentation mode with Win+P, I added the following into my ~/.config/openbox/rc.xml file

    <keybind key="W-p">
      <action name="Execute">
        <startupnotify>
          <enabled>false</enabled>
          <name>Presentation mode</name>
        </startupnotify>
        <command>xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -T</command>
      </action>
    </keybind>

Note, that the 3.16 kernel does not handle closing the lid properly. That is, it sleeps only after about 10 seconds of closing the lid, instead of immediately. This has been fixed in 3.19, I think, so one needs to use a newer kernel. I decided to use the backported kernel, and I always install it manually, to keep the existing stable 3.16 kernel, in case something goes haywire. So currently, I would do (after bl-welcome put the jessie backports into /etc/apt/sources.list.d/ )

sudo apt-get -t jessie-backports install linux-image-4.5.0-0.bpo.1-amd64
sudo apt-get -t jessie-backports install firmware-iwlwifi
sudo apt-get -t jessie-backports install firmware-realtek

(I update the wifi and network firmware, as well, just in case.)

I have a set of samsung specific scripts. The following are put into /usr/local/sbin, because these all require root priviliges.
This is for activating the BIOS setting battery life extension, which does not let the battery to be charged over 80%. This is supposed to lengthen the life cycle of the battery. I keep this on, unless I know I will be without a power source for a long time (e.g. flights, long train trips), then I turn it off and charge for 100% of my battery. The code is written in such a way that a dbus-notification appears when toggled.

## samsung_battery_life_extender
#!/bin/bash
BATT_EXT_file="/sys/devices/platform/samsung/battery_life_extender"
BATT_EXT_status="$(cat $BATT_EXT_file)"
ICON="notification-battery-"

notify_current_status() {
if [[ "$(acpi -b | grep -c 'ischarging')" -ge 1 ]]
then
  AC=""
else
  AC="-plugged"
fi
if [[ "$BATT_EXT_status" -eq 0 ]] ; then
  VALUE=100
  PRE=""
  STATUS="off"
else
  VALUE=80
  PRE="0"
  STATUS="on"
fi
echo "Current status: ${STATUS^^} (max ${VALUE}% battery capacity)"
while read USER in
do
  PIDFILE="/tmp/samsung_battery_life_extender_notification_$USER.pid"
  if [[ -e "$PIDFILE" ]] ; then
    if [[ "$(cat $PIDFILE)" =~ ^-?[0-9]+$ ]] ; then
      PID="$(cat $PIDFILE)"
    else
      PID="0"
    fi
  else
    su "$USER" -c "touch $PIDFILE"
    PID="0"
  fi
  PID=$(su "$USER" -c "notify-send  \
  -p -r $PID                        \
  -i ${ICON}${PRE}${VALUE}${AC}     \
  'Battery life extension'          \
  \"${STATUS^^} (max ${VALUE}%)\"")
#  "${STATUS} (max $(echo ${PRE} | sed 's/0/ /')${VALUE}% battery capacity)")
#  -u low
#  -t 800
su "$USER" -c "echo $PID > $PIDFILE"
done< <(who | grep ":0 " | sed 's/ .*//')
}

case $1 in
  [oO][fF][fF])
    echo "0" > $BATT_EXT_file
    BATT_EXT_status=0
    notify_current_status
    ;;
  [oO][nN])
    echo "1" > $BATT_EXT_file
    BATT_EXT_status=1
    notify_current_status
    ;;
  [tT][oO][gG][gG][lL][eE])
    if [ $BATT_EXT_status -eq 0 ] ; then
      echo "1" > $BATT_EXT_file
      BATT_EXT_status=1
    else
      echo "0" > $BATT_EXT_file
      BATT_EXT_status=0
    fi
    notify_current_status
    ;;
  *)
    echo "Usage, as root: $(basename $0) {on|off|toggle}"
    notify_current_status
    ;;
esac

The following is turning the bluetooth on and off. This probably could be done without root priviliges with the proper program (I did it with the wlan), but I do not use it, so I just turn it off always at reboot with crontab (see later).

## samsung_bluetooth
#!/bin/bash
BT_name_file="$(grep -l 'samsung-bluetooth' /sys/devices/platform/samsung/rfkill/rfkill*/name)"
if [[ -f "$BT_name_file" ]]; then
  BT_soft_file="$(echo $BT_name_file | sed 's/name$/soft/')"
fi
BT_soft_value="$(cat $BT_soft_file)"
case $1 in
  on)
    echo "0" > $BT_soft_file
    ;;
  off)
    echo "1" > $BT_soft_file
    ;;
  toggle)
    if [[ $BT_soft_value -eq 0 ]]; then
      echo "1" > $BT_soft_file
    else
      echo "0" > $BT_soft_file
    fi
    ;;
  *)
    echo "Usage, as root: $(basename $0) {on|off|toggle}"
    if [ $BT_soft_value -eq 0 ] ; then
      echo 'Current status: on'
    else
      echo 'Current status: off'
    fi
    ;;
esac

I had a lot of trouble with the lcd, because the linux kernel has two backlight files: one for the RAW file and one for the firmware file. The following script takes an argument between 0-100 and sets the lcd backlight to that percentage. This probably should be rewritten using the appropriate dbus calls, but whatever.

## samsung_lcd
#!/bin/bash
FIRMWARE_file="/sys/class/backlight/acpi_video0/brightness"
RAW_file="/sys/class/backlight/intel_backlight/brightness"
RAW_max_file="/sys/class/backlight/intel_backlight/max_brightness"
if [ -f $FIRMWARE_file ]
then
  FIRMWARE_brightness="$(cat $FIRMWARE_file)"
elif [ -f $RAW_file ] && [ -f $RAW_max_file ]
then
  RAW_brightness="$(cat $RAW_file)"
  RAW_max_brightness="$(cat $RAW_max_file)"
  # this is how kernel 4.2 decreases brightness using Fn+F2
  RAW_new_brightness="$(($RAW_max_brightness-$RAW_max_brightness/10*(100-$1)/10))"
  #RAW_new_brightness="$(($RAW_max_brightness-$RAW_max_brightness/100*(100-$1)))"
  #RAW_new_brightness="$(($RAW_max_brightness-$RAW_max_brightness*(100-$1)/100))"
  #RAW_new_brightness="$(($RAW_max_brightness/100*$1))"
  #RAW_new_brightness="$(($RAW_max_brightness*$1/100))"
else
  echo "Did not find video backlight brightness or max_brightness files."
  exit 1
fi
case $1 in
  [0-9]|[1-9][0-9]|100)
    # just to make really sure that $1 is an integer between 0 and 100
    if [ "$1" -ge 0 ] && [ "$1" -le 100 ]
    then
      if [ -f $FIRMWARE_file ]
      then
        if [ "$1" == "$FIRMWARE_brightness" ]
        then
          # 6 is the minimum amount that changes the RAW value for kernel 4.2
          if [ "$1" == 6 ]
          then
            echo "7" > $FIRMWARE_file
            echo "$1" > $FIRMWARE_file
          else
            echo "6" > $FIRMWARE_file
            echo "$1" > $FIRMWARE_file
          fi
        else
          echo "$1" > $FIRMWARE_file
        fi
      else
        echo "$RAW_new_brightness" > $RAW_file
      fi
    else
      echo "Usage, as root: $(basename $0) [0-100]"
      if [ -f $FIRMWARE_file ]
      then
        echo "Current status: $FIRMWARE_brightness"
      else
        echo "Current status: $((100*$RAW_brightness/$RAW_max_brightness))"
      fi
    fi
    ;;
  *)
    echo "Usage, as root: $(basename $0) [0-100]"
    if [ -f $FIRMWARE_file ]
    then
      echo "Current status: $FIRMWARE_brightness"
    else
      echo "Current status: $((100*$RAW_brightness/$RAW_max_brightness))"
    fi
    ;;
esac

The following sets the proper lid handling if kernel version is at least 3.19. I set it on at every reboot using a cron job (see later).

## samsung_lid
#!/bin/bash
LID_file="/sys/devices/platform/samsung/lid_handling"
LID_status="$(cat $LID_file)"
case $1 in
  off)
    echo "0" > $LID_file
    ;;
  on)
    echo "1" > $LID_file
    ;;
  toggle)
    if [ $LID_status -eq 0 ] ; then
      echo "1" > $LID_file
    else
      echo "0" > $LID_file
    fi
    ;;
  *)
    echo "Usage, as root: $(basename $0) {on|off|toggle}"
    if [ $LID_status -eq 0 ] ; then
      echo 'Current status: off (not waking up if opening lid)'
    else
      echo 'Current status: on (waking up if opening lid)'
    fi
    ;;
esac

This is one of the coolest features of this laptop. One can turn off the fan completely (even though it is very silent with the fans on, as well), and force the CPU into its lowest power consumption state. The code is written in such a way that a dbus-notification appears when toggled. (I have two icons specifically modified for this purpose by GIMP, they toggle really nicely, but I have no idea how to upload images....)

## samsung_silent_mode
#!/bin/bash
## according to documentation, there is a third option called "overclock"
PERF_LEVEL_file="/sys/devices/platform/samsung/performance_level"
PERF_LEVEL_status="$(cat $PERF_LEVEL_file)"

notify_current_status() {
if [ "$PERF_LEVEL_status" == "silent" ] ; then
  STATUS="on"
  ICON="silver-fan-stopped"
else
  STATUS="off"
  ICON="silver-fan"
fi
#echo "Current status: ${STATUS^^}"
echo "Current status: ${STATUS^^} (${PERF_LEVEL_status} mode)"
while read USER in
do
  PIDFILE="/tmp/samsung_silent_mode_notification_$USER.pid"
  if [[ -e "$PIDFILE" ]] ; then
    if [[ "$(cat $PIDFILE)" =~ ^-?[0-9]+$ ]] ; then
      PID="$(cat $PIDFILE)"
    else
      PID="0"
    fi
  else
    su "$USER" -c "touch $PIDFILE"
    PID="0"
  fi
  PID=$(su "$USER" -c "notify-send \
  -p -r $PID                       \
  -i ${ICON}                       \
  'Silent mode'                    \
  \"${STATUS^^}\"")
#  \"${STATUS^^} (${PERF_LEVEL_status} mode)\"")
#    -u low
#    -t 800
su "$USER" -c "echo $PID > $PIDFILE"
done< <(who | grep ":0 " | sed 's/ .*//')
}

case $1 in
  off)
    echo "normal" > $PERF_LEVEL_file
    PERF_LEVEL_status="$normal"
    notify_current_status
    ;;
  on)
    echo "silent" > $PERF_LEVEL_file
    PERF_LEVEL_status="$silent"
    notify_current_status
    ;;
  toggle)
    if [ $PERF_LEVEL_status == "silent" ] ; then
      echo "normal" > $PERF_LEVEL_file
      PERF_LEVEL_status="normal"
    else
      echo "silent" > $PERF_LEVEL_file
      PERF_LEVEL_status="silent"
    fi
    notify_current_status
    ;;
  *)
    echo "Usage, as root: $(basename $0) {on|off|toggle}"
    notify_current_status
    ;;
esac

The following turns on or off usb charging if in sleep mode. The code is written in such a way that a dbus-notification appears when toggled.

## samsung_usb_charge
#!/bin/bash
USB_CHARGE_file="/sys/devices/platform/samsung/usb_charge"
USB_CHARGE_status="$(cat $USB_CHARGE_file)"

notify_current_status() {
if [ $USB_CHARGE_status -eq 1 ] ; then
  STATUS="on"
  charging=""
  ICON="drive-harddisk-usb"
else
  STATUS="off"
  charging="not "
  ICON="drive-removable-media-usb"
fi
echo "Current status: ${STATUS^^} (${charging}charging USB3 when powered down)"
while read USER in
do
  PIDFILE="/tmp/samsung_usb_charge_notification_$USER.pid"
  if [[ -e "$PIDFILE" ]] ; then
    if [[ "$(cat $PIDFILE)" =~ ^-?[0-9]+$ ]] ; then
      PID="$(cat $PIDFILE)"
    else
      PID="0"
    fi
  else
    su "$USER" -c "touch $PIDFILE"
    PID="0"
  fi
  PID=$(su "$USER" -c "notify-send \
  -p -r $PID                       \
  -i ${ICON}                       \
  'USB3 charge'                    \
  \"${STATUS^^}\"")
#    -u low
#    -t 800
su "$USER" -c "echo $PID > $PIDFILE"
done< <(who | grep ":0 " | sed 's/ .*//')
}

case $1 in
  off)
    echo "0" > $USB_CHARGE_file
    USB_CHARGE_status="0"
    notify_current_status
    ;;
  on)
    echo "1" > $USB_CHARGE_file
    USB_CHARGE_status="1"
    notify_current_status
    ;;
  toggle)
    if [ $USB_CHARGE_status -eq 0 ] ; then
      echo "1" > $USB_CHARGE_file
      USB_CHARGE_status="1"
    else
      echo "0" > $USB_CHARGE_file
      USB_CHARGE_status="0"
    fi
    notify_current_status
    ;;
  *)
    echo "Usage, as root: $(basename $0) {on|off|toggle}"
    notify_current_status
    ;;
esac

Finally, this enables that the wlan led to be turned on or off depending on whether the wlan is on or off. I found that it was enough to enable it once, and then the wlan led works as expected. (Without this script, wlan led was always on.)

## samsung_wlan_led
#!/bin/bash
WLAN_LED_file="/sys/class/leds/phy0-led/brightness"
WLAN_LED_status="$(cat $WLAN_LED_file)"
case $1 in
  off)
    echo "0" > $WLAN_LED_file
    ;;
  on)
    echo "1" > $WLAN_LED_file
    ;;
  toggle)
    if [ $WLAN_LED_status -eq 0 ] ; then
      echo "1" > $WLAN_LED_file
    else
      echo "0" > $WLAN_LED_file
    fi
    ;;
  *)
    echo "Usage, as root: $(basename $0) {on|off|toggle}"
    if [ $WLAN_LED_status -eq 0 ] ; then
      echo 'Current status: off'
    else
      echo 'Current status: on'
    fi
    ;;
esac

As superuser I set up a cron job to start some of these at a specific setting at every reboot:

sudo crontab -e

Then have

@reboot /usr/local/sbin/samsung_bluetooth off ; /usr/local/sbin/samsung_lid on
# /usr/local/sbin/samsung_wlan_led off

For the above to work nicely with the dbus-notifications, I downloaded https://github.com/vlevit/notify-send.sh into /usr/local/bin/notify-send (with the version shipped with jessie the closing of existing notifications would not work).
For toggling the wlan I added /usr/local/bin/wlan which does not require root priviliges:

## wlan
#!/bin/bash
WLAN_status=$(nmcli -t -f WIFI r)
case $1 in
  on)
    nmcli r wifi on
    ;;
  off)
    nmcli r wifi off
    ;;
  toggle)
    if [ $WLAN_status = "letiltva" ] ; then
      nmcli r wifi on
    else
      nmcli r wifi off
    fi
    ;;
  *)
    echo "Usage: $(basename $0) {on|off|toggle}"
    if [ $WLAN_status = "letiltva" ] ; then
      echo 'Current status: off'
    else
      echo "Current status: on"
    fi
    ;;
esac

(Here, 'letiltva' means 'disabled' in Hungarian.)

For keyboard backlight changing, I added the following to /usr/local/bin (this script I downloaded from https://keramida.wordpress.com/2013/03/ … -from-cli/ )

## kbd_backlight
#!/bin/bash
## downloaded from
## https://keramida.wordpress.com/2013/03/28/controlling-the-keyboard-backlight-from-cli/
## depends on notify-send.sh downloaded from
## https://github.com/vlevit/notify-send.sh

# backlight_get
#       Print current keyboard brightness from UPower to stdout.
backlight_get()
{
    dbus-send --type=method_call --print-reply=literal --system         \
        --dest='org.freedesktop.UPower'                                 \
        '/org/freedesktop/UPower/KbdBacklight'                          \
        'org.freedesktop.UPower.KbdBacklight.GetBrightness'             \
        | awk '{print $2}'
}

# backlight_get_max
#       Print the maximum keyboard brightness from UPower to stdout.
backlight_get_max()
{
    dbus-send --type=method_call --print-reply=literal --system       \
        --dest='org.freedesktop.UPower'                               \
        '/org/freedesktop/UPower/KbdBacklight'                        \
        'org.freedesktop.UPower.KbdBacklight.GetMaxBrightness'        \
        | awk '{print $2}'
}

# backlight_set NUMBER
#       Set the current backlight brighness to NUMBER, through UPower
backlight_set()
{
    value="$1"
    if test -z "${value}" ; then
        echo "Invalid backlight value ${value}"
    fi

    dbus-send --type=method_call --print-reply=literal --system       \
        --dest='org.freedesktop.UPower'                               \
        '/org/freedesktop/UPower/KbdBacklight'                        \
        'org.freedesktop.UPower.KbdBacklight.SetBrightness'           \
        "int32:${value}}"
}

#
notify_of_backlight_change()
{
VALUE="$1"
MAX=$( backlight_get_max )
ICON="xfpm-brightness-keyboard"
if [[ "$(whoami)" == "root" ]]
then
  while read USER in
  do
    PIDFILE="/tmp/kbd_backlight_notification_$USER.pid"
    if [[ -e "$PIDFILE" ]] ; then
      if [[ "$(cat $PIDFILE)" =~ ^-?[0-9]+$ ]] ; then
        PID="$(cat $PIDFILE)"
      else
        PID="0"
      fi
    else
      su "$USER" -c "touch $PIDFILE"
      PID="0"
    fi
    PID=$(su "$USER" -c "notify-send \
    -p -r $PID                       \
    -i $ICON                         \
    -h int:value:$((100*VALUE/MAX))  \
    'Keyboard brightness'")
#    -u low
#    -t 800
    su "$USER" -c "echo $PID > $PIDFILE"
  done< <(who | grep ":0 " | sed 's/ .*//')
else
  PIDFILE="/tmp/kbd_backlight_notification_$(whoami).pid"
  if [[ -e "$PIDFILE" ]] && [[ "$(cat $PIDFILE)" =~ ^-?[0-9]+$ ]] ; then
    PID="$(cat $PIDFILE)"
  else
    PID="0"
  fi
  PID="$(notify-send              \
  -p -r $PID                      \
  -i $ICON                        \
  -h int:value:$((100*VALUE/MAX)) \
  'Keyboard brightness')"
#  -u low
#  -t 800
echo "$PID" > "$PIDFILE"
fi
}

# backlight_change [ UP | DOWN | NUMBER ]
#       Change the current backlight value upwards or downwards, or
#       set it to a specific numeric value.
backlight_change()
{
    change="$1"
    if test -z "${change}" ; then
        echo "Invalid backlight change ${change}."                    \
            "Should be 'up' or 'down'." >&2
        return 1
    fi

    case ${change} in
    [1234567890]|[[1234567890][[1234567890])
        current=$( backlight_get )
        max=$( backlight_get_max )
        value=$( expr ${change} + 0 )
        if test ${value} -lt 0 || test ${value} -gt ${max} ; then
            echo "Invalid backlight value ${value}."                  \
                "Should be a number between 0 .. ${max}" >&2
            return 1
        else
            backlight_set "${value}"
            notify_of_backlight_change "${value}"
#            notify-send -t 800 -i /usr/share/icons/hicolor/scalable/status/xfpm-brightness-keyboard.svg "Keyboard brightness set to ${value}"
        fi
        ;;

    [uU][pP])
        current=$( backlight_get )
        max=$( backlight_get_max )
        if test "${current}" -lt "${max}" ; then
            value=$(( ${current} + 1 ))
            backlight_set "${value}"
            notify_of_backlight_change "${value}"
#            notify-send -t 800 -i /usr/share/icons/hicolor/scalable/status/xfpm-brightness-keyboard.svg "Keyboard brightness set to ${value}"
        fi
        ;;

    [dD][oO][wW][nN])
        current=$( backlight_get )
        if test "${current}" -gt 0 ; then
            value=$(( ${current}  - 1 ))
            backlight_set "${value}"
            notify_of_backlight_change "${value}"
#            notify-send -t 800 -i /usr/share/icons/hicolor/scalable/status/xfpm-brightness-keyboard.svg "Keyboard brightness set to ${value}"
        fi
        ;;

    *)
        echo "Invalid backlight change ${change}." >&2
        echo "Should be 'up' or 'down' or a number between"           \
            "1 .. $( backlight_get_max )" >&2
        return 1
        ;;
    esac
}

if test $# -eq 0 ; then
    current_brightness=$( backlight_get )
    notify_of_backlight_change "${current_brightness}"
#    notify-send -t 800 -i /usr/share/icons/hicolor/scalable/status/xfpm-brightness-keyboard.svg "Keyboard brightness set to ${value}"
    echo "$current_brightness"
else
    # Handle multiple backlight changes, e.g.:
    #   backlight.sh up up down down up
    for change in "$@" ; do
        backlight_change "${change}"
    done
fi

I also wanted a keyboard backlight daemon, which turns off the backlight after some time of inactivity (e.g. when one watches a movie or something). For this, one needs the xprintidle package.

sudo apt-get install xprintidle

Then I added the following to /usr/local/bin

## kbd_backlight_daemon
#!/bin/bash

# Wanted trigger timeout in milliseconds.
IDLE_TIME_AC=$((60*1000))
IDLE_TIME_BAT=$((30*1000))
SLEEP_TIME_IN_IDLE_AC=$((3*1000))
SLEEP_TIME_IN_IDLE_BAT=$((6*1000))

# Get current keyboard brightness, and normalize to max out in 4
backlight_get()
{
    dbus-send --type=method_call --print-reply=literal --system         \
        --dest='org.freedesktop.UPower'                                 \
        '/org/freedesktop/UPower/KbdBacklight'                          \
        'org.freedesktop.UPower.KbdBacklight.GetBrightness'             \
        | awk '{print $2}'
}
get_kbd_brightness() {
KBD_brightness="$(backlight_get)"
if [ "$KBD_brightness" -ge 4 ]
then
  KBD_brightness=4
fi
}
get_kbd_brightness

set_idle_time() {
if [ "$(acpi -b | grep -c 'ischarging')" -ge 1 ]
then
  IDLE_TIME=$IDLE_TIME_BAT
  SLEEP_TIME_IN_IDLE=$SLEEP_TIME_IN_IDLE_BAT
else
  IDLE_TIME=$IDLE_TIME_AC
  SLEEP_TIME_IN_IDLE=$SLEEP_TIME_IN_IDLE_AC
fi
}

set_sleep_time() {
if $idle_triggered
then
  sleep_time="$SLEEP_TIME_IN_IDLE"
else
  sleep_time="$((IDLE_TIME-idle))"
fi
}

# Sequence to execute when timeout triggers.
idle_cmd() {
  get_kbd_brightness
  if [ $KBD_brightness -ne 0 ] ; then
    kbd_backlight 0
  fi
}

# Sequence to execute when not in idle mode
non_idle_cmd() {
  if [[ "$(backlight_get)" -eq 0 && "$KBD_brightness" -ne 0 ]]
  then
    kbd_backlight "$KBD_brightness"
  else
    get_kbd_brightness
  fi
}

idle=$(xprintidle)
set_idle_time
#sleep_time=$IDLE_TIME
idle_triggered=false
set_sleep_time

# ceil() instead of floor()
while sleep $(((sleep_time+999)/1000)); do
  idle=$(xprintidle)
  if [ $idle -ge $IDLE_TIME ]; then
      set_idle_time
      set_sleep_time
    if ! $idle_triggered; then
      idle_cmd
      idle_triggered=true
      set_idle_time
#      sleep_time=$IDLE_TIME
      set_sleep_time
    fi
  else
    set_idle_time
    set_sleep_time
    if $idle_triggered; then
      non_idle_cmd
      idle_triggered=false
      set_idle_time
      # Give 100 ms buffer to avoid frantic loops shortly before triggers.
#      sleep_time=$((IDLE_TIME-idle+100))
      set_sleep_time
    fi
  fi
done

For this to work nicely, I have modified ~/.config/openbox/autostart with

## Run kbd_backlight_daemon
(sleep 2s && /usr/local/bin/kbd_backlight_daemon) &

Now, some of the above scripts I added to particular keypresses. This can be done by adding some lines to ~/.config/openbox/rc.xml

    <keybind key="XF86WLAN">
      <action name="Execute">
        <command>wlan toggle</command>
      </action>
    </keybind>
    <keybind key="XF86Launch1">
      <action name="Execute">
        <command>sudo samsung_battery_life_extender toggle</command>
      </action>
    </keybind>
    <keybind key="XF86Launch3">
      <action name="Execute">
        <command>sudo samsung_silent_mode toggle</command>
      </action>
    </keybind>

Of course, those requiring root priviliges would not work without being in the sudoers file:

## Fn+F1 battery life extender & Fn+F11 silent mode
sudo visudo

and then add the following:

Cmnd_Alias SAMSUNG_CMDS = /usr/local/sbin/samsung_battery_life_extender,/usr/local/sbin/samsung_silent_mode
ghorvath ALL=(ALL) NOPASSWD: SAMSUNG_CMDS

(My login is ghorvath, and in fact I already was a sudo, this is just for not asking for passwords every time I run these files.)

The other keys worked fine for me (screen backlight +/-, touchpad on/off, volume +/-) The mute button works because Bunsenlabs added this already into rc.xml. Note, however, that Fn+F4 (putting the screen to the external monitor) does not seem to work, one probably should define that with xrandr or something. (Putting stuff on the external screen does work using Preferences/Display/ARandR from the bunsen main menu.) Note, that the mute led does not work, because even kernel 4.5 does not recognize this led.

One more important thing is to install laptop-mode-tools. This I explained here https://forums.bunsenlabs.org/viewtopic.php?id=1919
The only thing missing from that description is what I used in /etc/laptop-mode/conf.d/lcd-brightness.conf

BATT_BRIGHTNESS_COMMAND="samsung_lcd 0"
LM_AC_BRIGHTNESS_COMMAND="samsung_lcd 100"
NOLM_AC_BRIGHTNESS_COMMAND="samsung_lcd 100"
BRIGHTNESS_OUTPUT="/dev/null"

With 100% battery time it is possible to use the laptop for about 5 hours while on battery (for work, and not for watching fullscreen youtube videos). It is not as much as was possible with the preinstalled windows 8 on it, but of course time decreased the maximum capacity of the battery, and some people say that windows always gives you more battery time than linux.

Finally, let me mention a few problems I had with this laptop. Suspend never was an issue, but hibernation may have been broken with some kernels. I am not entirely sure, because I do not really use that feature. Once I entertained the idea of waking the laptop from suspend automatically after some hours and hibernate it to conserve battery power, but I never had the time to do this. (And of course with a broken hibernate command, it is not really advisable to do so, either.)

Further, it might be that xfce4-power-manager cannot suspend it properly. I never really diagnosed this, but I think when on battery and it reaches the limit set for suspend, then it does not really suspend because it asks for the sudo password. I am not entirely sure what is going on, and I also know that basic dpms settings can mess with xfce4-power-manager (not to mention laptop-mode-tools, but at least I turned that off for dpms). Anyway, if I ever figure it out, I will post about it.

Last edited by ghorvath (2016-05-16 06:20:29)

Offline

Board footer

Powered by FluxBB