Skip to content

Commit 8b8db53

Browse files
authored
Merge pull request #4 from alexmohr/dev
Dev
2 parents 92febc9 + 14b3ca9 commit 8b8db53

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(thinkpad_keyboard_backlight)
3-
set(CMAKE_INSTALL_PREFIX /usr/local/bin)
3+
set(CMAKE_INSTALL_PREFIX /usr/bin)
44

55

66
set(CMAKE_CXX_STANDARD 17)
@@ -30,6 +30,8 @@ set(CMAKE_CXX_FLAGS "${OPTIMIZATION_LEVEL} \
3030
-Wpedantic \
3131
-Wextra")
3232

33+
set(SERVICE_TARGET_PATH /etc/systemd/system/keyboard_backlight.service)
34+
set(APP_TARGET_PATH ${CMAKE_INSTALL_PREFIX}/keyboard_backlight)
3335

3436
find_package (Threads)
3537

@@ -40,10 +42,12 @@ target_link_libraries (keyboard_backlight ${CMAKE_THREAD_LIBS_INIT})
4042

4143
install(TARGETS keyboard_backlight DESTINATION ${CMAKE_INSTALL_PREFIX})
4244

43-
44-
# Add custom features to build hex, bin or lst files.
4545
add_custom_target(service
4646
DEPENDS keyboard_backlight
4747
COMMAND sudo cp ${CMAKE_CURRENT_SOURCE_DIR}/keyboard_backlight.service /etc/systemd/system &&
4848
sudo systemctl enable --now keyboard_backlight.service
49-
)
49+
)
50+
51+
add_custom_target(uninstall
52+
COMMAND sudo rm -f ${SERVICE_TARGET_PATH} ${APP_TARGET_PATH}
53+
)

PKGBUILD

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Maintainer: Alexander Mohr keyboard_backlight at mohr dot io
2+
3+
pkgname=tp-kb-backlight-git
4+
pkgver=1.0
5+
pkgrel=1
6+
pkgdesc='Automated keyboard backlight'
7+
arch=('x86_64')
8+
url='https://github.com/alexmohr/keyboard-backlight'
9+
license=('MIT')
10+
depends=('libinput')
11+
makedepends=('git' 'cmake' 'gcc')
12+
13+
source=("git+https://github.com/alexmohr/keyboard-backlight")
14+
sha512sums=('SKIP')
15+
16+
17+
build() {
18+
cd "keyboard-backlight"
19+
mkdir build -p
20+
cd build
21+
cmake ..
22+
make
23+
}
24+
25+
package() {
26+
appname='keyboard_backlight'
27+
install -Dm 755 "keyboard-backlight/build/${appname}" "${pkgdir}/usr/bin/${appname}"
28+
install -Dm 644 "keyboard-backlight/keyboard_backlight.service" "${pkgdir}/etc/systemd/system/keyboard_backlight.service"
29+
30+
echo "Please enable the systemd service via 'sudo systemctl enable --now keyboard_backlight.service"
31+
echo "The service file can be used for configuration."
32+
echo "See 'keyboard_backlight -h' for options".
33+
}

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ backlight of a keyboard. It's only tested for thinkpads but may work on
66
other devices as well
77

88
## Installation
9+
10+
### Arch Linux
11+
The package is in the AUR and called ``tp-kb-backlight-git``
12+
13+
### Install from source
914
To build the binary run
1015
````
1116
mkdir build
@@ -19,6 +24,32 @@ to install the service and enable the systemd service.
1924

2025
Make sure to run ``make install`` BEFORE ``make service``
2126

27+
### Binary (not recommended)
28+
Download the latest package from github. Extract it an run the following commands.
29+
30+
````
31+
sudo cp keyboard_backlight /usr/bin
32+
sudo cp keyboard_backlight.service /etc/systemd/sytem
33+
sudo systemctl enable --now keyboard_backlight.service
34+
````
35+
36+
37+
# Uninstall
38+
For automated removal run the command below in the cmake folder
39+
````
40+
make uninstall
41+
````
42+
43+
To manually delete the files
44+
````
45+
sudo systemctl disable --now keyboard_backlight.service
46+
sudo rm /etc/systemd/system/keyboard_backlight.service
47+
sudo rm /usr/bin/keyboard_backlight
48+
````
49+
50+
51+
52+
2253
## Configuration
2354
````
2455
tp_kbd_backlight help

kbd_backlight.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ int main(int argc, char **argv) {
331331
if (!file_read_uint64(brightnessPath, &originalBrightness_)
332332
|| !file_write_uint64(brightnessPath, originalBrightness_)
333333
) {
334-
std::cout << "failed to get/set brightness " << std::endl;
334+
std::cout << "Write access to brightness device descriptor failed.\n"
335+
"Please run with root privileges" << std::endl;
335336
exit(EXIT_FAILURE);
336337
}
337338
currentBrightness_ = originalBrightness_;

keyboard_backlight.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Description=Controls the backlight of the keyboard
44
[Service]
55
Type=forking
66
# Options can be passed via command line
7-
ExecStart=/usr/local/bin/keyboard_backlight -t 5
7+
ExecStart=/usr/bin/keyboard_backlight -t 5
88

99
[Install]
1010
WantedBy=default.target

0 commit comments

Comments
 (0)