Showing posts with label X11. Show all posts
Showing posts with label X11. Show all posts

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

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.

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.

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).