My Lenovo laptop has a nifty button, Fn-F5, to toggle wi-fi and bluetooth
on and off. Works fine, and the indicator lights (of which the Lenovo
has many -- it's quite nice that way) obligingly go off or on.
But when I suspend and resume, the settings aren't remembered.
The machine always comes up with wireless active, even if it wasn't
before suspending.
Since wireless can be a drain on battery life, as well as a potential
security issue, I don't want it on when I'm not actually using it.
So I wanted a way to turn it off programmatically.
The answer, it turns out, is rfkill.
$ rfkill list
0: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: yes
Hard blocked: no
0: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: no
tells you what hardware is currently enabled or disabled.
To toggle something off,
$ rfkill block bluetooth
$ rfkill block wifi
Type rfkill -h for more details on arguments you can use.
Fn-F5 still works to enable or disable them together.
I think this is being controlled by /etc/acpi/ibm-wireless.sh,
though I can't find where it's tied to Fn-F5.
You can make it automatic by creating /etc/pm/sleep.d/.
(That's on Ubuntu; of course, the exact file location may vary with distro
and version.) To disable wireless on resume, do this:
#! /bin/sh
case "$1" in
resume)
rfkill block bluetooth
rfkill block wifi
;;
esac
exit $?
Of course, you can also tie that into other things, like your current
network scheme, or what wireless networks are visible (which you can
get with iwlist wlan0 scan).
Tags: linux, ubuntu, laptop, tip
[
18:46 Mar 04, 2013
More linux/laptop |
permalink to this entry |
comments
]
In setting up a laptop
-- Debian "Squeeze" with a Gnome 2 desktop --
for an invalid who will be doing most of her computing from bed,
we hit a snag. Two snags, actually: both related to the switching
between the trackpad and an external trackball.
Disabling and re-enabling the trackpad
First, the trackpad gets in the way when she's typing. "Disable
touchpad while typing" was already set, but it doesn't actually
work -- the mouse was always moving when her palm brushed against it.
On her desktop computer, she's always used a Logitech trackball --
never really got the hang of mice, but that trackball always worked
well for her. And fortunately, unlike a mouse, a trackball works just
fine from bed.
Once the trackball is working, there's really no need to have the
trackpad enabled. So why not just turn it off when the external trackball
is there? I thought I'd once seen a preference like that ... but
it was nowhere to be found in the Gnome 2 desktop.
It turns out the easiest way to disable a trackpad is this:
synclient TouchpadOff=1
Using 0 instead of 1 turns it back on.
So we gave her shell aliases for both these commands.
A web search will show various approaches to writing udev rules to run
something like that automatically, but she felt it was easy enough to
type a command when she switches modes, so we're going with that for now.
Emulate the middle button on an external mouse or trackball
We thought we were done -- until we tried to paste that alias into her
shell and discovered that 2-button paste doesn't work for
external mice in Squeeze.
Usually, when you have a mouse-like device that has only two buttons,
you can click the left and right buttons together to emulate a middle
click. She'd been using that on her old Ubuntu Lucid install, and it
works on pretty much every trackpad I've used.
But it didn't work with the USB trackball on Squeeze.
Gnome used to have a preference for middle button emulation,
but it's gone now.
There's a program you can install called
gpointing-device-settings that offers a 2-button emulation setting
... but it doesn't save the settings anywhere.
And since it's a GUI program you can't make it part of your login or
boot process -- you'd have to go through and click to set it every time.
Not happening.
2-buttom emulation is an X setting -- one of the settings that used to be
specified in Xorg.conf, and now wanders around to different places
on every distro. A little web searching didn't turn up a likely
candidate for Squeeze, but it did turn up a way that's probably
more distro independent: the xinput command.
After installing xinput, you need the X ID of the external mouse or trackball.
xinput list
should show you something like this (plus more stuff for keyboards
and possibly other devices):
$ xinput list
Virtual core pointer id=2 [master pointer (3)]
Virtual core XTEST pointer id=4 [slave pointer (2)]
SynPS/2 Synaptics TouchPad id=10 [slave pointer (2)]
Kensington Kensington USB/PS2 Orbit id=13 [slave pointer (2)]
Once you have the id of the external device, list its properties:
$ xinput list-props 13 ~ 9:01PM
Device 'Kensington Kensington USB/PS2 Orbit':
Device Enabled (132): 1
... long list of other properties ...
Evdev Middle Button Emulation (303): 0
Evdev Middle Button Timeout (304): 50
... more properties ...
You can see that middle button emulation is disabled (0).
So turn it on:
$ xinput --set-prop 13 "Evdev Middle Button Emulation" 1
Click both buttons together, and sure enough -- a middle button paste!
I added that to the alias that turns the trackpad off -- though of course,
it could also be added to a udev rule that fires automatically
when the mouse is plugged in.
Tags: linux, laptop
[
14:34 Sep 08, 2012
More linux/install |
permalink to this entry |
comments
]