Qball's Weblog

Beati pauperes spiritu

Rofi Getting Popular? We Need a Logo!

| Comments

For reasons yet unknown to me, Rofi seems to be getting more attention lately. Having almost 100 stars at GitHub (pathetic I know, but it is a niche product.).

So any decent programs needs an icon, Right? Given I am the world shittiest artist, see my creation:

ARGH my eyes

So If anybody feels like making one; I am looking for a nice Rofi icon!

Wallpaper

PWM on Udoo Using the i.MX6 - Update

| Comments

A small update on the previous blog post.

In the previous post I actually forgot to mention how to enable the high resolution clock for PWM. There are two ways to do this.

Fiddling with registers

The clock can be enabled in the CCM_CCGR4 register. Bit 22 and 23, these can be configured to be:

  • 00 Clock is off during all modes. Stop enter hardware handshake is disabled.
  • 01 Clock is on in run mode, but off in WAIT and STOP modes
  • 10 Not applicable (Reserved).
  • 11 Clock is on during all modes, except STOP mode.

So we want to set these to 11.

1
2
$devregs CCM_CCGR4
CCM_CCGR4:0x020c4078    =0x0000c300

Now we want to enable bit 22-23 so we or it with 0x00c00000

So to enable it we set:

1
$devregs CCM_CCGR4 0x00c0c300

And the clocks are running! However this might be risky, if you screw up you might enable or disable a clock. There is a nice ‘hack’ to accomplish the same!

The hack

Let the ½ working PWM driver do it for us!

1
2
3
echo 0 > /sys/class/pwm/pwmchip3/export
echo 1 > /sys/class/pwm/pwmchip3/pwm0/enable
echo 0 > /sys/class/pwm/pwmchip3/unexport

After this, everything works as expected.

PWM on Udoo Using the i.MX6

| Comments

I have been very bad, not writing blog post. I guess that will be habit I am never going to break.

This blog post is a quick write down what I did to get pwm output working on the Udoo.

Out of the box

Out of the box PWM the only usable PWM is the one on the Atmel, but I did not want to use that, it feels wrong (also it is arduino based, so getting a decent PWM requires hacking, etc.). The Freescale has it, so why not use that See pinout. So looking around on the install I did see a nice /sys/class/pwm/ directory with the 4 pwm generators, however this was completely non working for two reasons:

  1. The pinmux is wrong
  2. The entries do not seem to setup the right registers.

So looking around, I found this post basically the only one I could find that talked about setting up PWM on the Udoo. But it gave a nice starting point. Lets first try to compile that imx-utils repository. This failed, it is setup for cross-compilation, and tries to link against framebuffer device. ( I only want the devregs tool.) A quick hack to the make file fixed this, the whole makefile now looks like:

1
2
3
all: devregs

devregs: devregs.cpp

The second problem when trying to get the tool to work is the processor detection, under ArchLinux (running 3.17 kernel) the right Revision is not exposed. A quick hack of the code to always load the imx6 version made things work. I might post this version later, mail me if interested.

So lets start setting up the PWM, first thing we need to do is setup the right pinmux. BEWARE THAT THIS PIN SHOULD NOT BE AN OUTPUT ON THE ATMEL, IF YOU DO THIS WILL DESTROY THE BOARD

1
   devregs IOMUXC_SW_MUX_CTL_PAD_SD4_DAT2 2

This sets GPIO42 to PWM4 output. Check the pinout. Then I followed the steps from the forum post, setting up the PWM:

1
2
3
4
devregs PWM4_PWMCR 0x0003fff0   # clocksource = 32kHz, div by 4096 = 8 Hz
devregs PWM4_PWMPR 6            # set period (6 + 2 = 8 cycles)
devregs PWM4_PWMSAR 1           # set duty cycle to 1/8
devregs PWM4_PWMCR 0x0003fff1   # enable PWM output

While I got some output from the PWM, it looked like utter sh??. It has a lot of high frequency components, and the output looks fully random. What could this be? (Sorry I forgot to take a photo of the output). Looking at the freescale manual IMX6DQRM.pdf it mentions several settings related to power? management: STOPEN stop mode enabled, DOZEN doze mode, WAITEN wait mode. By default if we hit any of these modes the PWM is stopped. I am not sure what Linux is doing, but lets be on the safe side and disable these.

1
devregs PWM4_PWMCR 0x0383fff0

And this instantly cleared up the PWM signal:

Plot

It is not perfect, there is still a lot of high frequency scruff on the signal, but it is clean enough. Now lets see if we can get a bit higher frequency going. Looking again at the datasheet, it looks like we can switch to highfreq clock,

1
devregs PWM4_PWMCR 0x0382fff0

And indeed the frequency goes up, now lets play with the prescaler a bit:

1
devregs PWM4_PWMCR 0x03824000

This gave me a nice stable 64kHz clock. (half from what I would expect based on the documentation, but that is an investigation for another time).

So to tie things together (I also inversed the PWM because my LED driver also inverts):

1
2
3
4
5
6
7
8
9
10
## Set pinmux
devregs IOMUXC_SW_MUX_CTL_PAD_SD4_DAT2 2
## Set high freq clock, inverse polairty, disable power  down modes etc.
devregs PWM4_PWMCR         0x03864000
## Set period to 255
devregs PWM4_PWMPR         0xfe
## Lights off
devregs PWM4_PWMSAR        0x00
## Enable clock
devregs PWM4_PWMCR         0x03864001

Now if I want to change the Light strength I call:

1
devregs PWM4_PWMSAR $HEX_LIGHT

Changing the duty cycle.

There is one small thing we still need to tweak, the PWM has a 4 element queue before the ‘SAR’ (duty cycle) register, we need to make sure this fifo is not full before we insert an element. We can do this by checking the Status Register: (PWM4_PWMSR4). The lower 3 bits indicate the remaining space. Luckely, I never manage to hit this, so will fix this at a later stage when making a dedicated PWM application instead of using devregs. Maybe even a kernel driver?

This now gives me a very nice controllable PWM. I need to play a bit with improving ‘fading’ effects. Currently it takes 9 seconds to go from low to high.

Some scripts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env bash

declare -i LIGHT=$@

if [ -z "$LIGHT" ]
then
        LIGHT=0
fi

if [ $LIGHT -gt 255 ]
then
        LIGHT=255
fi 


HEX_LIGHT=$(printf "%X" $LIGHT)

devregs PWM4_PWMSAR $HEX_LIGHT
1
2
3
4
#!/usr/bin/env bash

STRENGTH=$(devregs PWM4_PWMSAR | awk -F= '{print strtonum($2)}')
echo $STRENGTH

and fading:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash

declare -i LIGHT=$@

if [ -z "$LIGHT" ]
then
        LIGHT=0
fi

if [ $LIGHT -gt 255 ]
then
        LIGHT=255
fi 

START=$(get_light.sh)

echo Going from $START to $LIGHT
if [ $START -gt $LIGHT ]
then

for a in `seq $START -1 $LIGHT`
do
        HEX_LIGHT=$(printf "%X" $a)
        devregs PWM4_PWMSAR $HEX_LIGHT > /dev/null
done

else

for a in `seq $START 1 $LIGHT`
do
        HEX_LIGHT=$(printf "%X" $a)
        devregs PWM4_PWMSAR $HEX_LIGHT > /dev/null

done

fi

Netflix, Rofi and More

| Comments

Netflix

Yesterday somebody made a nice post mentioning that we might be able to get native (so no wine running silverlight) Netflix working under linux. This uses html-5 DRM enabled video playback. It requires the latest chrome beta, specific libraries and user-agent tweaking. For some reason I had a very hard time to get the latest part working, this is also why I am making this blog, to keep this one around:

1
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2114.2 Safari/537.36

The big change is the chrome version (from previous link):

1
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36

Do not ask me why, I had to do this a couple of times before Netflix took it… It works now, not touching it anymore.

The playback is pretty stable and my aging pc seems to have little problems with it.

Rofi 0.14.8

Also yesterday I released Rofi 0.14.8. I won’t repeat the previous blog posts, but in short the changes are:

  • Pango support: Switching to pango gives us correct fallback fonts, fixing issue #69.
  • RTL support: Pango also fixed this bug: issue #70
  • RTL entering: Rafi confirmed this is now working correctly.
  • Correct UTF-8 collating of strings. Rofi now converts the strings to a case insensitive form, then creates collating keys. (using glib).
  • Improved dmenu support and minor extensions. This improves clerk.
  • Custom modi support using simple bash scripts.
  • A first throw at cleaning up the keybindings, thanks to lolilolicon. Issue: #73.
  • Cleanups.

I have probably forgotten ½ the changes.

You can download the latest version here.

Others

Trying out hoedown for Notes.CC. Hoedown only produces a body, not the rest of the HTML page and CSS. So I am going to need a nice template to fill in. So far it seems to be working fine, it seems to be actively developed. If anybody is willing to make a nice looking template?

So what is Notes.CC? It is a rewrite of Notes.txt in C++. It tries to be faster and more integrated then the previous bash hack. It uses libgit2 to handle the git repository and hoedown/discount for parsing the markdown file. I will release the thing when it is mostly feature full and reliable.

Fixing Monitor

| Comments

For the past few years, my Samsung 740BF been acting up a bit. When turning it on, or waking up from standby it would go give a garbled image. However turning it off and on fixed it. However the last few weeks it been failing all around, until today it decided to fail completely.

Experience learns that in most cases monitors and other devices die because of bad capacitors. This must be true, because there is a wikipedia article.

So opening it up, I must say, Samsung nicely constructed this. It nicely clicks together and only a few screws are needed to hold everything firmly in place. So I opened it up and took out the power supply.

Power Supply Before

If you take a good look you see that one capacitors is swollen. The 3rd capacitor in the lower left corner. So with a bit of careful soldering I took the capacitor out, a 16V 1000µF one. Replaced it by a new one with exactly identical specifications I had in my collection. Though I am not sure that it is of better quality, but never hurts to replace it. So after a few minutes of soldering:

Power Supply After

A fresh new capacitor in place. A quick assembly later, it worked like new. It now turns on without an issue and wakes up from standby. So using a € 0.03 capacitor I gave my (ancient) monitor a new life, a very dutch thing for me to do.

Rofi Updates

| Comments

Rofi recently got some nice updates. They are mostly tweaks to make things work just a bit better but in total they are a good improvement.

Custom Modi’s

In Rofi you can switch between the following modi’s: window switcher, run dialog, ssh dialog. The latest changes allow you to specify the set of active modi, so if you do not use the ssh dialog you can disable it. Simple change, but very useful. In addition I made an option to add switchers using simple bash scripts. It is like the dmenu mode, but then more integrated.

Say I want to add a modi that allows me to quickly switch between the available i3 desktops (instead of windows). You first specify (either via Xresources or command line) the new switcher:

1
rofi.switchers: window,run,ssh,Workspace:i3_switch_workspace_script.sh

Workspace is the name it shows as prompt, i3_switch_workspace_script.sh is the script that gets called.

The i3_switch_workspace_script.sh is as follow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

if [ -z $@ ]
then
function gen_workspaces()
{
    i3-msg -t get_workspaces | tr ',' '\n' | grep "name" | sed 's/"name":"\(.*\)"/\1/g' | sort -n
}


echo empty; gen_workspaces
else
    WORKSPACE=$@

    if [ x"empty" = x"${WORKSPACE}" ]
    then
        i3_empty_workspace.sh >/dev/null
    elif [ -n "${WORKSPACE}" ]
    then
        i3-msg workspace "${WORKSPACE}" >/dev/null
    fi
fi

Rofi will first call the script with no arguments, this will make it generate the list of available workspaces. Once the user selected an entry, Rofi calls the script again and passes the selected item as argument. (the above script can be found in Rofi’s git Examples/ directory).

More advanced scripts can be made that have sub-menu’s, an example of this is the domo_rofi_script.sh in the repository. If you the user selects a command, the script returns a new set of options, Rofi will list this until the script returns nothing, indicating it is done.

To quicker switch between the different modi, the user can press alt-4 to switch to the 4th modi directly.

Pango support

This is a change that won’t affect much for most users, but fixes a lot of issues people had that uses ‘complex’ character sets. Because of the switch to pango the following things now work as they should:

  • Fallback fonts: If some characters are not supported by the font, it will now fallback (using fontconfig) to a font that has it. This way everything is shown as expected.

  • RTL fonts: Right to left fonts are now correctly displayed and correctly aligned.

  • Entering RTL: Rafi confirmed he is capable of entering RTL text, moving through the text and matching text this way.

  • Ellipsize: The strings are nicely ellipsized this looks better then being cut off.

There are of course some downsides:

  • It is slower then using Xft directly. But nothing problematic. Benefits far outweighs the costs IMHO.

  • The font-string has slightly changed, the dash between font name and size should now be a space.

A video demonstrating (made by Rafi) can be found here

Other fixes and additions

Dmenu compatibility.

Disable levenshtein sorting when in dmenu mode.

Dmenu incompatibility

I also broke dmenu compatibly by added a shift-enter mode. This outputs the selected line, but redraws the menu with the next entry selected. This way a script can make the user select multiple items more efficiently. Clerk uses this.

UI

Several small (1 pixel) offsets and other issues where fixed. So the overall look should be a bit better.

No Documentation Can Be Better Then Some Documentation

| Comments

I like documentation, even though I am not very good creating it myself (and hate myself for it). But I try to do better with Rofi and generally it feels good once it is done. But in some cases, why did the developer even bother creating something?

This one especially annoyed me today, and would have been better with no documentation at all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FcNameParse(3)                                                                                        FcNameParse(3)

NAME
       FcNameParse - Parse a pattern string

SYNOPSIS
       #include <fontconfig/fontconfig.h>

       FcPattern * FcNameParse (const FcChar8 *name);

DESCRIPTION
       Converts name from the standard text format described above into a pattern.

VERSION
       Fontconfig version 2.11.0

                                                    11 10 2013                                      FcNameParse(3)

What explanation above? Is this a joke? So I entered the thing into a search engine and the first hit was this. Helpful the same bloody thing. Lets hit the up button, because that is above isn’t it? No description.

At that point, I was so annoyed, I gave up. Another day another shot at it.

Rofi - Updates

| Comments

Although Rofi is in a good place and is mostly feature complete, I did manage to fix several small annoyances and added several new features. I will list the most important ones below. I hope to make a new release in the coming weeks. It would be nice if I could promote Rofi a bit more. If you have ideas for this, please let me know.

Pasting support

You can now paste the current clipboard (both primary as secondary) to the search entry box.

  • Insert or Ctrl-v: Pastes the primary clipboard.

  • Shift-Insert or Ctrl-Shift-v: Pastes the secondary clipboard.

Disabling History

On request it is now possible to disable the history function. People who use Rofi to enter a lot of manual commands might find this useful.

Levenshtein Distance Sorting

When you start typing to filter the list, initially the results where sorted alphabetically. I have added an option that allows you to sort it by Levenshtein distance. This should allow you to find your desired option more quickly.

Many small fixes

Several small sizing and drawing bugs have been fixed, making things look just that little bit better.

Screenshot

Every blog post needs atleast one image, so here we go.

Screenshot rofi popup mode

Ducky 2108 Under Linux

| Comments

Ducky DK2108 (Image from Mechanical Keyboards Holland)

I know I haven't blogged in a long time, yet I probably have enough things to talk about that
others might find interesting. Like Rofi search updates, notes.sh rewrite in C++, etc.
I will try to catch-up in the coming months. But for now my latest GmG.

After many years of typing on crappy keyboards and wearing them out in no-time at all, I decided to get a real keyboard again. I used to be a big fan of the old IBM Model-M keyboards and still mourn the day my stash got lost (they where nice ones with detachable cables and all). So I got a mechanical keyboard, the Ducky DK2108 with Blue Switches and the only thing I can say is: I should have done this years ago! The feel is lovely, the sound is heavenly and the overall typing experience is paradise.

However paradise never lasts, I noticed that when typing command lines I often noticed I wound up with this: some command |\ grep <keyword>.

This happens when I press shift \ and release the shift earlier then the \ key (for my feeling I release them at exactly the same time). After some fiddling around, I noticed that it only happens with N-Key Rollover enabled. After firing up xev and taking a closer look this is what I saw:

  • KeyPress: Shift
  • KeyPress: | (keycode 51)
  • KeyRelease | (keycode 51)
  • KeyRelease Shift
  • KeyPress: \ (keycode 51)
  • KeyRelease \ (keycode 51)

While I get without NKRO or old keyboard and would expect the following:

  • KeyPress: Shift
  • KeyPress: | (keycode 51)
  • KeyRelease Shift
  • KeyRelease \ (keycode 51)

First thinking my keyboard might be buggy, or there being a problem with NKRO anyway, I decided to try it on a windows box. Here it works as expected………

The whole problem is mostly academic, I really do not need N-Key Rollover, I do not play games, so it is very doubtful I will press more then 6 keys at the time. If (and that is a big if) I would play a game where I have to press more then 6 keys, I can enable NKRO without issues given it only goes wrong with the \. I would be very pleased if I could fix the issue, so if anybody has a clue on how to do this? Please let me know.

While typing this I got an E-mail from MKH with a firmware update (but no guarantees that it fixes it). So far the service of the shop has been very good, they where quick with sending the keyboard, it was well packaged (the original box in a 2nd box with wrapping) and there support response time is impressing (even in the weekend).

Rofi Now Has a Website

| Comments

Rofi now has an official website, this is a first step towards making a release.

Currently the following is left to do:

  • Extend command-line options to cover all options.
  • Update documentation.
  • Provide some configuration examples on the website.

The second point will take the most time, help is always welcome.

Some recent tweaks to Rofi include:

  • Abstract out history code that was duplicate between ssh/run dialog. This fixes a bug with loosing history.
  • Allow more fine-grain tweaking of window position, allowing it to behave like a dropdown.
  • Fix small font rendering issue.
  • When no result is matched, double-tab will switch to next dialog. Allowing for a more fluent work-flow.

The rofi website is made using Jekyll, and I do like it. It did not take a lot of effort to tweak the theme so it did what I wanted. It seems octopress is kinda dead (no release for years now), so maybe someday I will try to strip off the octopress part and just use jekyll directly.