LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2016, 07:30 AM   #1
Johnny_Metal
Member
 
Registered: Feb 2016
Posts: 41

Rep: Reputation: Disabled
Openbox Custom Keybinds


Hello everyone,

I am using BunsenLabs Linux, which, as you may know, uses the OpenBox window manager.

It happens that i cannot change the brightness of the screen either through the xfce-power-manager or xbacklight. xrandr only works for but a few seconds. However, there appears to be this specific file

Quote:
/sys/class/backlight/acpi_video0/brightness
which contains within it a number which specifies the screen brightness. I decided to create 2 C programs, which read the number on the file, calculate a new value, and replace the previous value with the more recent one. One program increases the value, while the other decreases it.

Code:
#include <stdio.h>
#include <stdlib.h>

main(int argc, char **argv)
{
FILE *fp;
int old_brightness, new_brightness;

fp = fopen ("brightness", "r");
fscanf (fp, "%d", &old_brightness);
fclose (fp);

new_brightness = old_brightness - 2;

fp = fopen ("brightness", "w");
fprintf (fp, "%i", new_brightness);
fclose (fp);

return 0;
}
In the other program, there is a sum instead of a subtraction.

For this to work, i created the programs, allong with a symbolic link to the brightness file, on the following folder

Quote:
~/Brightness_Settings
The program seems to run absolutely fine. I then decided to create keybinds, so i edited the rc.xml file in

Quote:
~/.config/openbox
and added the following lines

Code:
<keybind key="C-Up">
  <action name="Execute">
    <command>~/Brightness_Settings/brightness_up.out</command>
  </action>
</keybind>
<keybind key="C-Down">
  <action name="Execute">
    <command>~/Brightness_Settings/brightness_down.out</command>
  </action>
</keybind>
Yesterday it was working fine, but not today, although the programs still run just fine when executed from a terminal window. Any ideas?
 
Old 05-16-2016, 08:24 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
Quote:
Originally Posted by Johnny_Metal View Post
Any ideas?
Hi!

This is exactly that, just an idea. I run Openbox on my Arch system, but since I am away at the moment I cannot test myself.

Anyway...

My idea (or guess if you will) is that perhaps Openbox can't handle relative paths?
So maybe instead of:
Code:
    <command>~/Brightness_Settings/brightness_up.out</command>
You could try an absolute path:
Code:
    <command>/home/YOURUSERNAME/Brightness_Settings/brightness_up.out</command>
This is just a guess mind you.

Best regards,
HMW
 
Old 05-16-2016, 08:36 AM   #3
Johnny_Metal
Member
 
Registered: Feb 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
Tried out your suggestion, but it didn't work.

However, i found out something interesting. I tried running the programs not from within the folder in which they're contained, but from my home folder, like so:

Quote:
Brightness_Settings/brightness_up.out
It returned "Segmentation fault".

I imagine that this is precisely what's happening when I issue the command through a keybind. Must have something to do with file pointers and the like. As things are now, I can only run the programs from within the folder in which they are contained, which is also the folder which contains the brightness file itself. I guess if I could write a program which specifies the location of the file to edit I could fix this.

I'll try to solve this on my own, although any suggestions are very much welcome.
 
Old 05-16-2016, 08:52 AM   #4
Johnny_Metal
Member
 
Registered: Feb 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
Solved it.

I didn't know this was possible, but i specified the path to the file that was to be read and written in the C programs. I thought it would just write out the name of the file as its whole path, but it doesn't. Everything is working wonderfully now

Thank you very much for your help!
 
1 members found this post helpful.
Old 05-16-2016, 11:55 AM   #5
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
Thank YOU for posting your solution.

I thought you could simply do an:
Code:
echo -n 22 > /sys/class/backlight/acpi_video0/brightness
...but I was apparently wrong. I get permission denied wether as normal user or root. Strange, I could have sworn that way worked in the past. At least it doesn't now (currently in front of my Debian 8 system).

So it was a clever approach to write your own program in C!

Best regards,
HMW

Edit 1:
Yes, you could do as I said above, at least in 2012!:
https://www.linuxquestions.org/quest...ss-4175427876/

Edit2:
You can still change the value (as root) with this command:
Code:
sudo tee /sys/class/backlight/acpi_video0/brightness <<< 24
Can someone who is more in the know than I explain when this changed, and why?

Last edited by HMW; 05-16-2016 at 12:05 PM.
 
Old 05-16-2016, 12:44 PM   #6
Johnny_Metal
Member
 
Registered: Feb 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
Since we're at it, let me just ask,

despite the fact that you are running the echo command as root, doesn't the file permission remain the same? Maybe changing the file permission will do the trick.

I would have used the echo command if I knew how to make it add or subtract to the current value of brightness. Does the code you posted do that? The way I understand it, it simply writes 22.


Regards
 
Old 05-16-2016, 02:05 PM   #7
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
Quote:
Originally Posted by Johnny_Metal View Post
Since we're at it, let me just ask,

despite the fact that you are running the echo command as root, doesn't the file permission remain the same? Maybe changing the file permission will do the trick.
Yep. It probably would, but I'd rather not change those permissions. My guess is that they are there for a reason, and since I don't need to, I will refrain. But yes, the permissions stay the same after an echo.
Quote:
Originally Posted by Johnny_Metal View Post
I would have used the echo command if I knew how to make it add or subtract to the current value of brightness. Does the code you posted do that? The way I understand it, it simply writes 22.
Yes. That was just an example. But you can use bash to subtract or add to a value. Like this:
Code:
currentValue=$(cat /sys/class/backlight/acpi_video0/brightness)
echo $currentValue
24
And then you can do:
Code:
sudo tee /sys/class/backlight/acpi_video0/brightness <<< $((currentValue-2))
Best regards,
HMW
 
1 members found this post helpful.
Old 05-16-2016, 02:12 PM   #8
Johnny_Metal
Member
 
Registered: Feb 2016
Posts: 41

Original Poster
Rep: Reputation: Disabled
Alright. Thanks a lot!

By the way, there is a flaw with the way i'm trying to change the brightness. I need to change the file permissions everytime i start a session, because at every restart they go back to their defaults. Would you happen to know of a way to make the changes permanent? Or perhaps create a script to change the permissions every session startup?

I started a thread on that right here:

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Openbox: Custom menu-entry ignored l0p3n Linux - Desktop 2 06-11-2015 10:53 PM
Custom Openbox setup - help with Zenity --progress creeper3d Programming 1 04-30-2013 12:48 PM
[SOLVED] "Permission denied" when Openbox tries to execute autostart.sh in ~/.config/openbox alarazr Linux - Software 4 10-04-2012 04:50 PM
Openbox autostart.sh and setting alias on openbox start Jelloir Linux - Desktop 1 07-03-2011 04:56 AM
Can't create custom menu.xml for openbox LogicNZ Linux - Newbie 6 07-19-2008 11:37 AM


All times are GMT -5. The time now is 10:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration