-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwbl.cpp
More file actions
47 lines (39 loc) · 971 Bytes
/
twbl.cpp
File metadata and controls
47 lines (39 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main(int argc, char** argv)
{
/**
* Edit here with the proper path to your backlight.
*/
std::string fname{"/sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight/brightness"};
if (argc < 2)
{
std::cerr << "Usage: " << argv[0] << " {,+,-}N\n";
return 1;
}
std::istringstream iss{argv[1]};
int val{};
if (!(iss >> val))
{
std::cerr << "Argument " << argv[1] << " is not a valid number.\n";
return 1;
}
std::ifstream ifs{fname};
int curr{};
if (!(ifs >> curr))
{
std::cerr << "Could not read current brightness value.\n";
return 1;
}
ifs.close();
val += curr;
std::ofstream ofs{fname};
if (!(ofs << std::to_string(val)))
{
std::cerr << "Could not write new brightness value.\n";
return 1;
}
return 0;
}