Showing posts with label desktop. Show all posts
Showing posts with label desktop. Show all posts

16 March 2018

Capture audio input + output with pulseaudio

I just wanted to capture a hangouts talk with my friend and got back to an old problem - how to properly record a call so that both myself and my companion can be heard.

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

There is a quite well known [in narrow circles]  problem in IntelliJ IDEA (as well as other Jetbrains products) with 'Open class'\'Open file' dialogues (AKA Ctrl+N\Ctrl+Shift+N): in some environments the dialogue tend to often disappear\close as you type. For other environments this problem just never happens.

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! :-)

09 March 2015

Seesu.me, dwb & vk.com

Rather a useless post, but it was fun for me to find all these out.

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:
  1. open dev console (dwb is based in webkit, so there is on) to find the login button
  2. check if clicking on it programatically would work
  3. if yes, all done - i'll login to vk, login will be remembered and nothing to worry about
Pressing standard Ctrl+Shift+I didn't worked. With google on my hands i found man 1 dwb which states that enable-developer-extras need to be enabled. I had no idea what it was, playing with command completion in dwb itself didn't helped as well. Again googling i found that option in ~/.config/dwb/settings (close dwb, then edit and save the file, then run browser again).

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.

06 January 2013

LXDM PostLogout script to shutdown user's apps

LXDM is a bit strange in it's behaviour to not to kill your apps running when you log out. After logging out my deadbeef continues to play music and conky is still drawn on top of LXDM greeter. Look funny heh :)
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 conky
It 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 notice that systemd is now default in new installations I realised that sooner or later I'll be forced to migrate disregarding whether I like this idea or not :)
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):
  1. edit /etc/default/grub and make sure you have init kernel param present, like this:
    GRUB_CMDLINE_LINUX_DEFAULT="init=/usr/lib/systemd/systemd"
  2. regenerate grub.cfg with
    sudo grub-mkconfig -o /boot/grub/grub.cfg
  3. 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

Basically task is to allow my mum login to home Linux-box and not to bother her with a password (or I would have to install Windoze again). At same time I want to still have access to same box with my own passworded account and to be able to login (with SLiM) to a X11 session.

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

Screensharing appears to be a weak part of Linux desktop. Among solutions that do work I have successful experience with TeamViewer and Mikogo. Both of them are not perfect, but they run more or less natively on Linux.
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.
  1. Windows running on either virtual machine (even non-virtual would work if you have spare one) (Windows XP on VirtualBox)
  2. VNC server running on your Linux desktop (x11vnc)
  3. 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

Then I had to start another XServer instance to avoid effect of 'endless refraction' (e.g. VNC client shows your desktop running virtual machine with Windows with VNC client showing you desktop...) using:
$ startx -- :1

On the second XServer I ran VirtualBox, started my virtual Windows PC, ran TightVNC and connected to my host Linux box. (At this stage you VNC may not work smoothly, looks like XServer detects that it's not active at the moment and does not update the screen when you try to move windows from within VNC client.) Now start you screen sharing session and once it's started enter fullscreen mode in your VNC client. Now you could minimize you virtual PC window and switch to first XServer (Ctrl+Alt+F7 in my case, your may differ).
That's it and you may lead your presentation :)

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.

08 May 2010

Using D-Bus to shutdown the machine

I don't know why I don't like using /sbin/shutdown to switch off the computer :) But that is the fact! I am not using Gnome\KDE\XFCE\whatever_else_complete_DE. I'm running Archlinux with Openbox and several tools. So I wanted to allow non-privileged user to be able to shutdown the computer by a single click. Firstly I had to find out, what should I send over D-Bus (and whom to) to make my PC shutdown. Crawling the web I found an utility which allowed me to find what I needed in a few minutes. It's called DBus-Inspector. So having a message and destination it just remained to send it using dbus-send:
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
If 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 shutdown
And add your user to this group:
# gpasswd -a user shutdown
Finally 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