Coder Social home page Coder Social logo

yoohooyoo / auto-backlight-for-thinkpad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pspatel321/auto-backlight-for-thinkpad

0.0 0.0 0.0 232 KB

Automation for certain Lenovo Thinkpad laptops (ex. X1c, X1e, P1) to control the keyboard backlight on Windows installations using a system-tray application. Those laptops do not save the backlight state across power events (Suspend, display off, lid close). This behavior can be undesirable to some users, so this project provides a convenient fix.

License: Apache License 2.0

C# 97.68% Python 2.32%

auto-backlight-for-thinkpad's Introduction

Auto Backlight for ThinkPad

Automation tool for certain Lenovo ThinkPad laptops (ex. X1c, X1e, P1) to control the keyboard backlight and lcd screen brightness (backlight) on Windows installations using a system-tray application. These laptops do not come with an automatic control mechanism for either. Additional behaviors added by this program mimic some automations found on other devices. Keyboard backlight control is triggerred by a user-activity timeout, and screen backlight control samples the ambient light level using the integrated camera.

Overview

This project provides a background Windows system tray application that augments the keyboard and lcd screen backlight controls through software. Settings supporting these two features are configurable through the GUI context menu (right-click) on the system tray. They can be individually disabled or enabled.

The keyboard backlight is automatically illuminated whenever the user interacts with the built-in keyboard/mouse hardware. After an adjustable inactivity timeout, the backlight is darkened. The keyboard brightness level changes along with the existing "Fn+Space" keyboard shortcut for backlight level. Settings are persisted across power events (sleep/wake, display on/off) for a hands-off experience, unlike the stock factory behavior which resets backlight across power events.

The screen backlight is automatically illuminated by sampling the integrated camera to mimic an ambient light sensor. A basic-low resolution snapshot is taken and the average intensity level is computed to use as the proxy for ambient light level. The level is mapped to a screen brightness percentage using a configurable calibration curve. The sampling and updating process will be triggered by a power event (sleep/wake, display on/off) or by user activity timeout on the built-in keyboard/mouse. This keeps the backlight ready on first-use. Optionally, a periodic sampling interval can be specified. However, this can be distracting due to the activity LED built-in on the camera. This application will only sample the camera at predicatable events (power events, user activity timeout) to minimize the distraction. A configurable hotkey (default: Alt-Space) can also trigger screen backlight refresh, for when the user is moving to different lighting conditions.

Quick install

Go to the releases section and download the latest Windows installer. It will add "Auto Backlight for ThinkPad" to the startup applications to begin automatically with user Log-In. It can be uninstalled easily through "Add or Remove programs" or other similar methods.

If you wish to disable Lenovo on-screen display popups, there is a checkbox "Enable on-screen display" buried in Settings on Windows 10. Access it through Settings-->System-->Display-->Advanced display settings-->Display adapter properties for Display 1-->Screen configurations. See image.

The guts

The project is built from Visual Studio 2019 C# WPF project template and Windows Setup project template to create the installer. C# on Microsoft .NET framework was chosen for high-compatibility code without external dependencies, using only the installed framework. Communication to the keyboard is done through Windows IO calls to IbmPmDrv (Lenovo/IBM power management driver), which should be available on these laptops. The camera interface is through third-party Accord.NET image processing libraries which uses Microsoft DirectShow under the hood.

The application hooks to various Windows Win32 Power Management events like Suspend, Resume, Display On/Off, Lid Close/Open to trigger special handling of the backlight state around these events. These events cause update of the keyboard backlight and/or screen backlight. Windows Win32 Raw Input is used to notify the app based on user activity for certain hardware devices (laptop built-in keyboard and mouse). These activity events trigger illumination of the backlight, which is subsequently reset after a timeout. The frequent input events are quickly muted to preserve battery life (cpu usage) when not needed. CPU usage was tested during app development to keep it minimal as a background application.

Building from source

The Visual Studio solution contains both a C# project (the application itself) and a Windows Setup project (the installer). As long as the core dependency is met on Microsoft .NET Framework, all should build out-of-box on Visual Studio 2019. This project is kept simple and mostly standard/default settings. One trick in use is the redirection of external dll references. These dll files (from included NuGet packages) would normally appear beside the application in the file explorer but most have been embedded inside the executable as part of the build process.

License

This project is licensed under the Apache-2.0 license. See LICENSE file for full text. See NOTICE file for attributions.

auto-backlight-for-thinkpad's People

Contributors

pspatel321 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.