Sunday 6 October 2024

Screen Brightness

OpenSUSE Leap 15.5 on ThinkPad X250

I used the X250 with older versions of OpenSUSE without major problems at work in about 2016–2019 (well, I never made the headset microphone work, but that’s another story).

When the Covid pandemic started, I got a new laptop at work and let my daughter use the old one. In 2024, she needed a more modern one, so the old X250 returned to me—and it was just in time, as my old Acer TravelMate had just died.

When installing missing software on the X250 and updating its configuration to my twenties’ likings, I discovered the brightness keys didn’t work.

I decided to fix them manually: It should be easy enough to write a script that changes the brightness and bind it to a XF86MonBrightnessDown and XF86MonBrightnessUp, right? The internet advised to use the xbacklight command, but surprisingly, it’s output was unhelpful:

No outputs have backlight property

After some more googling, I discovered /sys/class/backlight/intel_backlight/ which contained two interesting files: max_brightness and brightness. When I changed the value in the latter, it directly affected the monitor brightness.

So I wrote the following script:

#!/usr/bin/perl
use warnings;
use strict;

my $PATH = '/sys/class/backlight/intel_backlight/';

sub load {
    my ($file) = @_;
    open my $in, '<', $PATH . $file or die "$file: $!";
    my $value = <$in>;
    chomp $value;
    return $value
}

my $change = shift;
my $current = load('brightness');
my $max = load('max_brightness');
$current += $change;
if ($current < 0) {
    $current = 0;
} else {
    $current = $max if $current > $max;
}
open my $out, '>', $PATH . 'brightness';
print {$out} $current;
close $out;
exec 'notify-send', '-t', 500, 'Brightness',
sprintf '%d%%', 100 * $current / $max

notify-send comes from the libnotify-tools package, but it also needs some notify daemon to be running. I used mate-notification-daemon.

The next problem was the brightness file was only writable by root. When I ran chmod a+w on it, it only lasted up to a shutdown. I needed something to change the file permissions on every start, so I created a systemd service:

[Unit]
Description=Backlight service
After=graphical.target

[Service]
Type=simple
User=root
ExecStart=/root/bin/backlight-writable

[Install]
WantedBy=graphical.target

And the script contained a simple chmod.

Now I can change the brightness on my X250 by simply pressing a button again.

Sunday 18 June 2017

Competing polkit authentication agents

I'm running OpenSUSE Leap 42.2 on my desktop and both my notebooks. After the last system update, one of the notebooks started to show the following Error dialog after logging into LXDE:

GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: An authentication agent already exists for the given subject

Googling for the message didn't help much, so I had to start experimenting myself. Comparing the output of ps -eo euser,pid,cmd | grep [p]olkit on different devices showed the notebook had one more line there:

polkitd 1657 /usr/lib/polkit-1/polkitd --no-debug
choroba 2283 lxpolkit
choroba 2308 /usr/lib/polkit-gnome-authentication-agent-1

The extra line was the last one.

I had no idea who started the gnome agent, and I wasn't able to find out quicky: pstree shows systemd as its parent.

Nevertheless, I was able to prevent it from running. In the file /etc/xdg/autostart/polkit-gnome-authentication-agent-1.desktop, I changed the line

NotShownIn=KDE;

to

NotShownIn=KDE;LXDE;

The error is gone.

Tuesday 11 April 2017

Close emacs buffer regardless of it being a server file

Emacs client

I use Emacs for text editing, which in my case means code, articles, web pages, notes, and short stories. Sometimes, I open files directly from emacs using \C-x \C-f, sometimes I use emacsclient from the command line. It opens the given file in an already running emacs window, avoiding the dreaded long startup time.

What bothered me for years was the way how to close a buffer. A file opened via file-find or through emacs filename can be closed by kill-buffer or \C-x k, but a server file complains about an existing client and needs a confirmation to be closed. One can use server-edit mapped to \C-x #, but the problem was I usually didn't remember how I opened a file - I just wanted to close its damned buffer.

The key to the solution was the server-buffer-clients variable which is buffer-local and defined only in server buffers. So, the solution was to bind a new function to  \C-x k:

(defun server-edit-or-close (buf)
  "Close the buffer regardless of whether it's a server file or not."
  (interactive "bKill/finish buffer: ")
  (if (and (featurep 'server)
           server-buffer-clients)
      (progn
        (switch-to-buffer buf)
        (server-edit))
    (kill-buffer)))

Update: Added the (featurep 'server) to make it work even if the server hasn't been started.

Saturday 2 March 2013

Upgrading to openSUSE 12.2 with LXDE.

I upgraded my home computer to openSUSE 12.2. I use LXDE as my desktop environment. So far, I noticed two annoying bugs, but fortunately found workarounds for both of them.

1. It is not possible to logout from LXDE properly. Or, better to say, after the logout, the X server is not restarted. You have to switch to a text console and rerun lxdm manually as root. I was not able to find a simple fix, so I switched to lightdm which does not have the problem.

2. Firefox was showing a warning each time I started it: it was not able to connect to the DBus. After some googling and hacking, I discovered a rather simple solution. Just prepend the following line to your
~/.config/lxsession/LXDE/autostart:

    export `dbus-launch`

Tuesday 17 January 2012

Farewell, my second hyper thread

I finally updated my desktop from openSUSE 11.2 to openSUSE 12.1. At first sight everything was more or less working, but when switching the machine off, I discovered it cannot be done without manually pushing the case button. All possible combinations of poweroff, shutdown and similar led just to the system halt, but the screen was showing the last messages and the fans were working on. Only the reset button could restart the machine.

The new init environment, systemd, was my first suspect. I started playing with it -- but only to discover only one of my CPUs is enabled (I have D865PERL motherboard with Pentium 4 with hyper-threading) . I identified the acpi=off option in the grub menu and removed the restriction... only to find that I can no longer even boot. The system froze during startup, each time at a slightly different time with a slightly different message (e.g. "BUG: unable to handle kernel initcall acpi_processor_init +0x0/0x100 [processor] returned with preemption imbalance", or "BUG: unable to handle paging request", or "scheduling with atomic", or just plain SIGSEGV or kernel panic).

I tried switching to different kernels (default, desktop, and vanilla), but the behaviour was the same. Even switching to systemv-init did not help.

I am currently running with hyper threading disabled at BIOS level. Therefore, I can boot with full acpi support and turn my machine off. However, I am running only one thread.

Update:
Googling for more information, I stumbled upon this thread:
http://ubuntuforums.org/showthread.php?t=1871247
Using their recommendation, namely adding processor.nocst=1 to boot options, solved the issue. Yay!

Another update:
I bought a new computer. It has an Intel Core i5-2400 chip and boots without problems :-)

Sunday 25 December 2011

Dell Inspiron N5010 and DIR-652 D-Link Router

A hard disk in my wife's laptop was damaged. Windows 7 did not boot. After confirming the damage from Linux (openSUSE 12.1 install CD and AVG Rescue Disc) we called Dell's Support and got a new disk. There was no system on it and I found our "rescue" DVD did not work, so I tried to install Linux on the empty disk.

I already had openSUSE 12.1 NET installation CD, so I tried it. The problem was I was not able to connect to the internet: I used a RJ 45 ethernet cable to our D-Link router DIR-652. I was able to ping the router, I was able to browse its web interface, I was able to ping other computers in LAN, but when trying to connect to the WAN, there was no success. When pinging for a long time, one packet got through occassionaly, ping reporting about 97% packet loss. I gave up.

The next day a guy from Dell brought us Windows 7 installation disk. To my surprise, after installing the system, I was not able to connect to the internet either - and the symptoms were exactly the same as before in Linux. I was not able to use wireless connection, because the driver was not present on the installation disk (nor on the Dell drivers disk, either). I tried various things: switching the cables, changing the setup of the router, but to no avail.

Then, at last, I tried to bypass the router and connected the laptop directly to the cable coming from the wall. And lo and behold! I was connected. I ran the updates, got the driver for wifi and prepared the computer for normal work.

But I still wonder why it did not connect to the internet through the router by the ethernet cable.

Sunday 18 December 2011

Crackling Sound on HP Mini 5102 on Shutdown (openSUSE 12.1)

I upgraded my HP Mini from openSUSE 11.2 to 12.1. Everything went smoothly; I have discovered just one problem so far: when shutting the computer down, it emits a crackling sound for 1-2 seconds. I spent several hours googling for solutions and trying them.

The only working solution I have found so far is adding the following line to /etc/modprobe.d/50-sound.conf :
options snd-hda-intel single_cmd=1
The documentation says:
single_cmd  - Use single immediate commands to communicate
with codecs (for debugging only)

OK. I am debugging my sound card until I find a better solution.