16 March 2018
Capture audio input + output with pulseaudio
Solution is courtesy to this youtube video and for own use I made a script out of it.
03 May 2016
Make 'Open class' dialogue of IntelliJ IDEA behave under Awesome WM
Recently it was demystified for me with the help of Jetbrains developers and support and the community. There appeared to be a long-hanging issue regarding this weird behaviour IDEA-65043. And once it gained some more attention at least exact conditions triggering the issue were discovered.
The problem was caused by sloppy focus (AKA focus-follows-mouse) which is the default in some environments among which Awesome WM is. Now it can easily be solved!
I'm using default configuration of Awesome WM 3.5.9 as a base (which can be found in /etc/xdg/awesome/rc.lua).
Somewhere in the bottom there is a snippet we're looking for
-- {{{ Signals -- Signal function to execute when a new client appears. client.connect_signal("manage", function (c, startup) -- Enable sloppy focus c:connect_signal("mouse::enter", function(c) if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier and awful.client.focus.filter(c) then client.focus = c end end)This is the sloppy focus implementation. Need to introduce a flag to switch it on\off. Change it to:
-- {{{ Signals -- Signal function to execute when a new client appears. sloppyFocus = true client.connect_signal("manage", function (c, startup) -- Enable sloppy focus c:connect_signal("mouse::enter", function(c) if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier and awful.client.focus.filter(c) and sloppyFocus then client.focus = c end end)
Now we have a switch, and we need to turn it off while we're working with IDEA (or WebStorm, etc) and the turn back on when we're off it. Find awfule.rules section in your config (for me it's right above the sloppy focus implementation snippet) and add a new rule:
{ rule = { class = "jetbrains-%w+" }, callback = function(c) c:connect_signal("focus", function (client) sloppyFocus = false end) c:connect_signal("unfocus", function (client) sloppyFocus = true end) end },This matches any window of virtually any Jetbrains' product and switches sloppy focus off while it's focused, then switches sloppy back on when focus leaves IDE.
Thanks awesome Awesome developers for allowing patterns in rule preconditions! :-)
22 October 2015
Pulseaudio server in Docker container
In short here it is:
Now everything one by one:
- docker run --rm -ti - run non-persistent docker and prepare it as interactive (shell) run
- --device=.... make local sound devices available in container. This feature is quite new in docker, so make sure you have recent version (mine is 1.8)
- -p 4713:4713 set up port forwarding between host and container to make pulse server available to clients
- rpi-deb-pulse is my docker image built from armbuild/debian by running system upgrade and install pulseaudio
- /bin/bash -c "..." is command to run inside container, more on this below
- groupadd --gid $(...) alsadev create a group inside container named alsadev and having same id as group of /dev/snd/controlC0 device. We need this to allow pulse to access native alsa devices.
- $(ls -l /dev/snd/controlC0 | cut -d' ' -f4 | xargs getent group | cut -d: -f3) this subshell is executed on host, not in container and prints group id of /dev/snd/controlC0
- gpasswd -a pulse alsadev adds user pulse to our new group alsadev
- pulseaudio ... run pulseaudio
- -L 'module-alsa-sink device=hw:0,0' explicitly load alsa sink and specify which output to use
- -L 'module-native-protocol-tcp auth-ip-acl=10.2.0.0/24' load tcp protocol listener and (optionally) configure ip-acl to only accept connections from given subnet
- pactl load-module module-tunnel-sink server=10.2.0.1
- in pavucontrol on Playback tab select desired sink for a stream
- list of devices may be replaced with another subshell to not specify each dev manually
- add systemd unit to start container automatically
- tune pulseaudio since sound over tcp tunnel is worse then playing locally
09 March 2015
Seesu.me, dwb & vk.com
The story
seesu.me is an awesome online media player or radio or whatever you call it. Just give it try.dwb is a minimalistic vim-imsnpired browser.
And vk.com is popular (at least in xUSSR countries) social network.
What brings them all here is that there is large music collection available on vk.com which can be very nicely listened to with seesu.me. But me problem was that vk login button wasn't working in dwb browser.
The solution
In short i needed to do the following:- open dev console (dwb is based in webkit, so there is on) to find the login button
- check if clicking on it programatically would work
- if yes, all done - i'll login to vk, login will be remembered and nothing to worry about
After that dev console popped up on :wi command, but unfortunately each time it shows up it crashes the whole browser.
I had to pick firefox to check if triggering click programmatically would do the trick and it really did. Invoking $('.sign-in-to-vk').click() in dev console was at least triggering popup blocker and then i was able to reach the popup (BTW popup blocker was veeery important here).
Back to dwb i needed a way to execute arbitrary JS on a page which was quickly and easily found in already opened man page. So on seesu page i typed :js $('.sign-in-to-vk').click() and nothing happened again. Here i remembered about popup blocker and (quickly again) found and option javascript-can-open-windows-automatically which was set to true with ss javascript-can-open-windows-automatically true
After that repeating JS snipped worked like a charm.
12 January 2015
Adventures with Asus P8H61-M LE/USB3 and UEFI boot
My PC booted in UEFI mode from Achlinux USB pendrive i've brought from home, but i rejected to boot from HDD.
I don't know how much time would i spent with this, but fortunately our sysadmin guys passed through and noticed me messing about BIOS. That appeared to be a know issue of my motherboard. The version i had was 0306.
I won't provide you with detailed instruction on how to upgrade you BIOS! The only hint i may give you - prior to doing this do reset all setting to defaults.
Now all works for me :)
06 January 2013
LXDM PostLogout script to shutdown user's apps
I don't really like this, but I wanted DM to show list of users instead of simple prompt. Arch wiki suggests just to killall --user $USER which would also kill all your background processes they may be running (torrent, screen, etc).
Enough words - here goes the script:
$ cat /etc/lxdm/PostLogout #!/bin/sh # # Note: this is a sample and will not be run as is. current_windows=`xlsclients -al | grep Window | cut -d' ' -f2 | sed -e 's/:$//'` for wid in $current_windows do pid=`xprop -id ${wid} _NET_WM_PID | awk -F ' = ' '{ print $2 }'` wmname=`xprop -id ${wid} WM_CLASS | cut -d= -f2 | cut -d, -f2 | sed -e 's/[ "]//g'` if [ "p${pid}" != "p" ] then echo "Killing ${wmname} (${pid})" kill ${pid} else echo "No PID found for ${wmname}" fi done # for some reason PID for conky cannot be determined killall --user $USER conkyIt requires xlsclients and xprop. Some apps (like conky) are special case and they don't show their PID in X11 properties of a window, so they are killed separately.
05 November 2012
Archlinux moves to systemd. My own remarks.
After some reading I rebooted, edited kernel loading line in my Grub2 with init param pointing to systemd and booted into my Arhclinux. What was noticable that I received to GUI :) Though I was aware that systemd ignores /etc/inittab (my SLiM used to start from inittab) and I wasn't that surprised. I did sudo systemctl enable slim.service (along with couple of other services which made sense for me) and rebooted again (needed not to forget to put init kernel param in place again).
Basically everything went smooth except just a few points, which weren't clear from documentation and which made me post this writing :)
Here I'm talking about pure systemd installations.
1. systemd-sysvcompat
Documentation from Archwiki states that you must not remove this package or you won't be able to boot any more. Though this package doesn't seem to contain any things I may need now (file list for systemd-sysvcompat). And it appeared to be true - if you want to remove this package you need to do the following (instructions for Grub2 loader):- edit /etc/default/grub and make sure you have init kernel param present, like this:
GRUB_CMDLINE_LINUX_DEFAULT="init=/usr/lib/systemd/systemd" - regenerate grub.cfg with sudo grub-mkconfig -o /boot/grub/grub.cfg
- now when everything went fine you could remove unnecessary things:
sudo pacman -Rcs sysvinit-tools
this should remove sysvinit-tools, initscripts, sysvinit and systemd-sysvcompat.
2. PCManFM doesn't show removable drives
While some other tools may show them. If not check documentation first. For me problem was that udisks daemon was inactive. So simple sudo systemctl enable udisks.service fixed this for me.These seem to be all the troubles with systemd for me, which I find pretty painless! :) And instead of conclusion: if you want to know what else services you could enable (or disable) use systemctl list-unit-files
Update 12.01.2015
After quite some time i concluded that having a /sbin/init makes way more sense in terms of compatibility and stability then having an init= kernel option configured in a boot loader. I just switched to UEFI and had to specify init= again. This time i just symlinked systemd to /sbin/init to end up this fight:ls -s '../lib/systemd/systemd' /usr/bin/init
28 June 2012
X11 session login with SLiM and no password
I'm not going to dig into security considerations regarding passwordless users here.
So firstly let's create a user for my mum and deprive it a password:
# useradd -m -U username
# passwd -d username
Explanation:
-m force home directory creation
-U automatically creates a group with same name as username and assigns it as primary group for new user
passwd -d removes password from given account
Now you should be able to login with new user into physical terminal session. Though this depends on PAM configuration in your distro (I'm using ArchLinux). You won't be able to su to this user or login into SLiM yet.
To allow SLiM login you with empty password you need to edit /etc/pam.d/slim:
find
auth required pam_unix.so
and change to
auth required pam_unix.so nullok
That's it. Same instructions should apply to any login manager, not only SLiM.
24 April 2012
Screensharing in Linux with GoToMeeting
These two were no the case for the event I needed to share my screen for :). Ideally I needed GoToMeeting and made it to share my screen! This instructions should work with most (if not any) of available screensharing solution for Windows.
Prerequisites:
In parenthesis I referred to software I was using.- Windows running on either virtual machine (even non-virtual would work if you have spare one) (Windows XP on VirtualBox)
- VNC server running on your Linux desktop (x11vnc)
- VNC client on your Windows PC (TightVNC)
Basic idea:
You should have guessed what I'm going to do next :) I explain if not. You share the screen of you Windows PC with screensharing tool of your choice. But what the screen will display is fullscreen VNC client connected to your Linux desktop. I suppose there might be some video issues with the way how VNC client draws the picture and the way screensharing tool captures the screen, that's why I mentioned what software I was using.Setup:
For sharing my desktop on Linux I ran x11vnc like that:$ x11vnc -display :0 -auth ~/.Xauthority -forever -nap -noxdamage
$ startx -- :1
Variations:
- On dual-screen setup you could share only one screen with
$ x11vnc -display :0 -auth ~/.Xauthority -forever -nap -noxdamage -clip 1680x1050+0+0
and thus you may try to avoid switching between different XServer by running VirtualBox instance on second screen. - Gnome users may use vino instead of x11vnc, though I haven't tried this.
06 October 2011
[Ubuntu] Reverting upgrade from thir party PPA
I got new hardware for my PC at work (i3-2100 with integrated Intel HD Graphics 2000). My Ubuntu 10.10 installed didn't feature proper drivers for this GPU, but some folks over the Web advised to add xorg-edgers PPA which hosts bleeding edge version of Xorg and drivers.
It's worth saying that I my Xorg rejected to extend my desktop to both monitors after this upgrade :)
Task
So I started searching for the way to revert this update :)
Solution
Finally Synaptic saved me! I'll appreciate if somebody will teach me how to do the same from command line.
So:
- open Synaptic
- select group by Origin (bottom left corner)
- in the list on the left find the source repo you did the upgrade from
- now select installed packages (from this repo) one by one and for each to Package - Force Version... (Ctrl + E)
Some more helpful info is available at https://help.ubuntu.com/community/CleanUpgrade
01 June 2011
Some more useful Skype scripts
- Toggle Skype main window I wrote earlier in my blog
- Answer\Hangup a call page in Russian
- Mute (or Answer) Skype Calls with BT Headset Button in Linux
Happy Skyping :)
21 November 2010
How to restore Linux loader after installing Windows without Live-CD
C:\GRBLDR="GRUB4DOS"Now you just need to reboot the PC, boot your Linux distro and reinstall GRUB On my ArchLinux I did the following:
$ sudo grub-install --root-directory=/ \(hd0\)This installed GRUB to the MBR of my first hard drive and put staging files under /boot/grub directory.
08 May 2010
Using D-Bus to shutdown the machine
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \ /org/freedesktop/Hal/devices/computer \ org.freedesktop.Hal.Device.SystemPowerManagement.ShutdownIf you will try to execute it, you may receive and error saying that you don't have permissions to send messages to org.freedesktop.Hal.devices.computer interface. If you did, you should open hal.conf from system config directory of D-Bus (mine is /etc/dbus-1/system.d/hal.conf) and add the following policy:
<policy group="shutdown"> <allow send_destination="org.freedesktop.Hal" send_interface="org.freedesktop.Hal.Device.SystemPowerManagement"/> </policy>Now all the members of group shutdown will be able to switch off the computer by D-Bus. You just have to create the group:
# groupadd shutdownAnd add your user to this group:
# gpasswd -a user shutdownFinally you may want to create a script or desktop entry:
[Desktop Entry] Icon=system-shutdown Name=Shutdown Exec=dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
15 March 2010
IE Developer Toolbar for IEs4Linux
So this post is about how to install the toolbar anyway! :)
The point is that IEs4Linux runs IE in wine environment with Win 98 version (at least for IE6 this is true), that why developer toolbar doesn't installs. To fix this, execute:
$ cat `which ie6` | grep WINEPREFIX
export WINEPREFIX="/opt/.ies4linux/ie6"
You will most probably see other path instead of /opt/.ies4linux/ie6. So now we know where the wine environment for wine is located. The next thing to do is to run winecfg for this environment and change target Win version:
$ WINEPREFIX="/opt/.ies4linux/ie6" winecfg
A dialog window will appear and in drop-down in the bottom of the window select Windows XP and press OK.
With this changes your IE won't run. So, download MSI of developer toolbar to your home directory with your favourite browser and install it to your wine environment with the following:
$ cd ~
$ WINEPREFIX="/opt/.ies4linux/ie6" msiexec /i IEDevToolBarSetup.msi
After installing the toolbar, run winecfg just like we previously did and switch Win version back to Windows 98.
Voila, we have IE with developer toolbar :)
17 February 2010
Analogue of FreeBSD watch for Linux
Though the most watch-like of them seem to be snoop, other also may be worth trying. I have yet tried nothing of them, so comments are appreciated.
And before the end I would mention well-known screen.
04 October 2009
Toggle Skype main window with keyboard
Using is again simple: save the source to some file (lets say skype-toggle.py), make it executable (chmod 755 skype-toggle.py) and add a hotkey to your window manager to run this script. That's all! :)
#!/usr/bin/env python import dbus import os remote_bus = dbus.SessionBus() out_connection = remote_bus.get_object('com.Skype.API', '/com/Skype') out_connection.Invoke('NAME SkypeToggler') out_connection.Invoke('PROTOCOL 5') wnd_state = out_connection.Invoke('GET WINDOWSTATE') if 'WINDOWSTATE NORMAL' == wnd_state: print 'Hide' out_connection.Invoke('MINIMIZE') elif 'WINDOWSTATE HIDDEN' == wnd_state: print 'Show' out_connection.Invoke('FOCUS') wId = os.popen('wmctrl -lp | grep Skype | sort -n | head -n 1 | awk "{print $1}"').read() print wId os.system('wmctrl -ia ' + wId)
03 October 2009
xkbswitch - simple keyboard layout switcher for X11
I've been thinking of what to post here for a long time and couldn't find anything interesting, useful and at the same time that is not copy-pasted from somewhere else in Internet. Today I was just searching for a source of one my tiny utility and realized that firstly it is useful (as I'm searching for it after a year passed when I wrote it) and secondly it cannot be a duplicate of anything from the Internet because I have written it by myself :)
So here is the prehistory: I am trying to build a handy and lightweight desktop environment based on Linux (or FreeBSD) at home long since. So I am not the one using Gnome, KDE and even XFCE. Now I am pretty satisfied with Arch Linux and Openbox with a few utilities (I can write separate post about my environment if someone would be interested. Just for info my desktop uses 68 Mb of RAM when it starts). Another aspect of my non-standard requirements is that I'm used to switch keyboard layouts using separate hotkeys for each layout. (For example I am using Ctrl+Shift+1 for English, Ctrl+Shift+2 for Russian and Ctrl+Shift+3 for Ukrainian.) Xxkb cannot handle such things, so the only way is some kind of thirdparty tool. I know two programs that can behave the way I need (well... the first one I am actively using and the second one should also handle different hotkeys, but I haven't checked it personally), they are xneur and kkbswitch. I like xneur very much but it stucks in Arch and further keyboard input is impossible until xneur is restarted. I am using it at work on Ubuntu 9.10 and everything is ok, so I don't know whether it is a bug of xneur or Arch's one. Kkbswitch is designed for KDE and depends on it's libraries, that is why I haven't even tried it.
Been stuck with all this for some time I opened sources off xxkb and taken the "engine" of it. (I just needed xxkb because I have never dealt with Xlib and wanted to get something working ASAP.) So the idea was to make a command line tool which would enable the layout given as it's argument. What for? To use it with hotkeys handled by your window manager :). Almost any WM allows you to define custom hotkeys. Given the above it is very easy to achieve the behavior I wanted. Here is the source of layout switching utility:
#include <stdlib.h> #include <stdio.h> #include <err.h> #include <X11/Xlib.h> #include <X11/XKBlib.h> void PrintUsage(); int main(int argc, char **argv) { int xkbGroup; if (argc < 2 || (xkbGroup = atoi(argv[1])) < 0 || xkbGroup > 3) { PrintUsage(); exit(0); } int xkbEventType, xkbError, xkbReason; int mjr = XkbMajorVersion, mnr = XkbMinorVersion; Display *display = NULL; display = XkbOpenDisplay(NULL, &xkbEventType, &xkbError, &mjr, &mnr, &xkbReason); if (NULL == display) { warnx("Cannot open X display %s", XDisplayName(NULL)); switch (xkbReason) { case XkbOD_BadServerVersion: case XkbOD_BadLibraryVersion: warnx("Incomatible versions of client and server xkb libraries"); break; case XkbOD_ConnectionRefused: warnx("Connection to X server refused"); break; case XkbOD_NonXkbServer: warnx("XKB extension is not present"); break; default: warnx("Unknown error from XkbOpenDisplay: %d", xkbReason); break; } exit(1); } Bool status = XkbLockGroup(display, XkbUseCoreKbd, xkbGroup); XCloseDisplay(display); return status ? 0 : 1; } void PrintUsage() { printf("Usage: xkbswitch [0-3] sets keyboard layout\n"); }
Use cc -I/usr/include -L/usr/lib -lX11 -o xkbswitch xkbswitch.c to compile it. Using it is simple and straightforward too: xxkbswitch 0 enables layout with index 0 (in my case Ctrl+Shift+1 executes xkbswitch 0 and sets English layout, xkbswitch 1 and sets Russian).