(gdb) break *0x972

Debugging, GNU± Linux and WebHosting and ... and ...

i3 named workspaces

Monday, September 19, 2016 - No comments

I recently improved my i3-wm configuration regarding the handling of workspaces. The idea is to have a quicker access to Firefox and Emacs, the main GUI tools I use for working. I initially added bindings to Urxvt terminal, but I happen to use it too much, so I cannot bind it to a particular workspace, they have to appear where ever I am :-)

Workspace names

set $wp_web 1: web
set $wp_edit 2: emacs
set $wp_work 3: work

set $wp_1 1: web # cannot use $variable here ...
set $wp_2 2: emacs
set $wp_3 3: work

assign [class="Firefox"] ? $wp_web
assign [class="^Emacs$"] ? $wp_edit

Switching workspace

# Win+1, Win+2 ...
bindcode Mod4+10 workspace $wp_1
bindcode Mod4+11 workspace $wp_2
bindcode Mod4+12 workspace $wp_3
bindcode Mod4+13 workspace 4

# quick Fn accesses
# F1 is Firefox, always focus to it during quick switches. 
# Same for F2 and emacs
bindsym F1 workspace $wp_1 ; [class="Firefox"] focus 
bindsym F2 workspace $wp_2 ; [class="Emacs"] focus
bindsym F3 workspace $wp_3
bindsym F4 workspace 4
# skip F5 (refresh in Firefox)

# quick back-and-forth with special key
bindsym Menu workspace back_and_forth # I would prefer a back-and-forth *on output*

# win-left/right
bindcode Mod4+86 workspace next
bindcode Mod4+82 workspace prev

# Mouse switch 1: left  2: middle  3: right
bindsym --whole-window Mod4+button1 workspace prev_on_output
bindsym --whole-window Mod4+button2 workspace back_and_forth
bindsym --whole-window Mod4+button3 workspace next_on_output

Moving workspaces and windows

# quick move
bindsym Shift+F1 move workspace $wp_1
bindsym Shift+F2 move workspace $wp_2
bindsym Shift+F3 move workspace $wp_3
bindsym Shift+F4 move workspace 4

# MOVE+Next/Prior keys to move the workspace
bindsym $Mod_move+Next move workspace next
bindsym $Mod_move+Prior move workspace prev

# Special key (UP/X) to move only window
bindcode $Mod_move+66 move window to output right;focus output right

# F12/F11 to move to hidden scratchpad / show it 
bindsym F12 move scratchpad
bindsym F11 scratchpad show

Quiting ZSH not too quickly

Friday, December 18, 2015 - No comments

This posts is for zsh shell only.

If you often use command-line tools such as GDB, you certainly know the hotkey ^d (EOF) to quickly quit the CLI. But sometimes, that's too sensitive! If you hit it twice in GDB, you do quit GDB, but also its parent shell!

set -o ignoreeof  # 10*^d exits zsh

Okay, we're a bit better now, we won't quit zsh by mistake ... but we cannot close it rapidely on purpose either. So let's improve it: 3 is a better threshold (and zle is zsh line editor):

set -o ignoreeof  # 10*^d exits zsh
function zle_quit () {exit}
zle -N zle-quit zle_quit
bindkey "^d^d^d" zle-quit

We simply bind the key sequence ^d^d^d to the quit function! (you have to do it quickly enough, otherwise it won't work)

For emacs fan, this works as well:

bindkey "^x^d" zle-quit

[Dev-tool configuration] i3 Window Manager

Tuesday, December 09, 2014 - No comments

Since a few years, I stopped using a traditional desktop manager like Gnome or KDE (maybe when Gnome switch to version 3?). I'm now addicted to my tiling window manager, i3. I3 manages only the windows on my screen, but not the desktop. Hence, when there's no window on my screen ... it's black! That could be improved, but most of the time, I have a window, so it doesn't matter. But no clickable icon, no clickable toolbar, just windows!

A tiling window manager (WM) gives the maximum room to each window, either by tabbing them, like in firefox, or by splitting (and sub-spliting) the screen horizontally or vertically:

Caught working hard

As there are no icons or clickable toolbar, everything is done with keyboard shortcuts. The learning curve, at the beginning, is a bit steep I admit! But one you get it, it's really nice to use!

Let's dive step-by-step into my configuration file:

Mod4 is 'Windows' key

Start applications

  • Mod4+Shift is the prefix to start applications. Mod4+Control is for alternative starts

    # Application shortcuts
    set $Mod_app Mod4+Shift
    set $Mod_app_alt Mod4+Control
  • Common tools:

    bindsym $Mod_app+f exec firefox
    bindsym $Mod_app+t exec thunderbird
    bindsym $Mod_app+m exec emacsclient -c # emacsclient needs an `emacs --daemon`
    bindsym $Mod_app_alt+m exec emacs # safe start, but takes longer
    # Start a terminal (urxvt client)
    bindsym $Mod_app+Return exec urxvtc # needs `urxvtd`
    bindsym $Mod_app_alt+Return exec urxvt # failsafe terminal
  • Force floating window (I guess these window don't respect all the protocols, so they are seen as primary windows, instead of floating boxes):

    for_window [class="Nautilus" instance="file_progress"] floating enable
    for_window [class="Xmessage"] floating enable
    for_window [title="Find"] floating enable
  • Helpers:

    bindsym Mod4+l exec i3lock -i /home/kevin/.i3/lock.png # locks the screen with a background image
    bindsym Mod4+F2 exec dmenu_run
    # Kill the current window
    bindsym $Mod_app+q kill # close the current 

See also dmenu_run, i3lock. I'll explain urxvtc and emacsclient in another post.

Window management

  • Window layout

    # Stacking / Tabbed / Default layout
    workspace_layout tabbed
    bindsym Mod4+s layout stacking
    bindsym Mod4+t layout tabbed
    bindsym Mod4+d layout default
  • Splitting windows

    default_orientation vertical
    # Split horizonally or vertically a window
    # *I can't help but consider than vertical split means that the window split should be vertical,
    # and the sub-windows side-by-side*, so I reversed h and v
    bindsym Mod4+h split vertical
    bindsym Mod4+v split horizontal
  • Moving windows

    set $Mod_move Mod4+Shift
    bindsym $Mod_move+Left move left
    bindsym $Mod_move+Right move right
    bindsym $Mod_move+Down move down
    bindsym $Mod_move+Up move up
    bindsym Mod4+f fullscreen
    bindsym Mod4+Mod1+f fullscreen global # on all screens
    # Toggle tiling/floating of the current window
    bindsym $Mod_move+space floating toggle
  • Changing the focus

    bindsym Mod4+Left focus left
    bindsym Mod4+Right focus right
    bindsym Mod4+Down focus down
    bindsym Mod4+Up focus up
  • Scratchpad (=invisible place)

    bindsym F12 move scratchpad
    bindsym F11 scratchpad show
  • Workspaces

    bindcode $Mod_move+10 move workspace 1 # touch 1
    bindcode $Mod_move+11 move workspace 2 # code for touch n = 9+n
    bindcode $Mod_move+86 move workspace next # touch +, found with `xev`
    bindcode $Mod_move+82 move workspace prev # touch -
  • Window resize

    # Window resize (although mouse is more convenient!)
    mode "resize" {
      bindsym Left resize grow left 10 px
      bindsym Shift+Left resize shrink left 10 px
      bindsym Down resize grow down 10 px
      bindsym Shift+Down resize shrink down 10 px
      bindsym Up resize grow up 10 px
      bindsym Shift+Up resize shrink up 10 px
      bindsym Right resize grow right 10 px
      bindsym Shift+Right resize shrink right 10 px
      #Enter to return to default
      bindsym Return mode "default"


  • Sound configuration

    set $Mod_sound Mod4+Mod1 #Win+Alt
    bindsym  $Mod_sound+m  exec amixer sset Master toggle
    bindcode $Mod_sound+82 exec amixer set Master 1%- # touch +
    bindcode $Mod_sound+86 exec amixer set Master 1%+ # touch -
    bindsym  XF86AudioMute exec amixer sset Master toggle # laptop multimedia keys
    bindsym  XF86AudioLowerVolume exec amixer set Master 1%-
    bindsym  XF86AudioRaiseVolume exec amixer set Master 1%+
    exec amixer sset Master mute # set to mute after boot sequence
  • Keyboard map (lang) configuration

    bindsym Mod4+Ctrl+f exec setxkbmap fr
    bindsym Mod4+Ctrl+u exec setxkbmap us
  • Borderless window or not

    hide_edge_borders both # by default, no side borders
    bindsym Mod4+p border normal
    bindsym Mod4+o border none # includes no window title
  • Restart and reload i3

    set $Mod_sys Mod4+Shift+Control
    bindsym $Mod_sys+e restart
    bindsym $Mod_sys+r reload
  • Home-made status bar (I'll put it online and explain it later)

    bindsym Mod4+Shift+w exec ~/.i3/i3status.py --kill --ws2
    bindsym Mod4+Ctrl+w exec ~/.i3/i3status.py --kill --ws1
    bar {
        position bottom
        mode hide
    exec ~/.i3/i3status.py

Enjoy, i3 is a great tool, especially for development with multiple screens!

[Dev-tools configuration] GDB's .gdbinit

Thursday, December 04, 2014 - 1 comment

In the next posts, I'll share the configuration files of my development and debugging tool. I think having a nice dev environment is key to good quality programming. At least, it makes your experience better. It's also verrrry nice for the people that will have to interact with you and your code!

I'll start with my .gdbinit:

  • No window size, we can scroll:

    set height 0
    set width 0
  • Allow pending breakpoints, we know what we're doing:

    (gdb) break foobar Function "foobar" not defined. Breakpoint 9 (foobar) pending.

    means that there is no "foobar" currently loaded, but maybe you know it will appear later.

    set breakpoint pending on
  • We're doing python development, so print the full stack trace when it crashes:

    set python print-stack full
  • GDB, please don't complain, I know what I'm doing! ... but beware, you may loose your session if you enter start in the middle of your debugging

    set confirm off
  • Structure easier to read:

    set print pretty
  • Save history, up-arrow and ctrl-r can save a lot of time:

    set history filename ~/.gdb_history
    set history save

We can also add a little bit of Python shortcut commands:

import gdb
  • quickly print Python objects pp instead of py print:

    class pp(gdb.Command):
        """Python print its arg"""
        def __init__(self):
            gdb.Command.__init__ (self, "pp", gdb.COMMAND_DATA,
        def invoke (self, arg, from_tty):
            gdb.execute("python print %s" % arg)
  • quickly list attributes of a Python object: ppd

    class ppd(gdb.Command):
        """Python print dir() of its arg"""
        def __init__(self):
            gdb.Command.__init__ (self, "ppd", gdb.COMMAND_DATA, completer_class=gdb.COMPLETE_SYMBOL)
        def invoke (self, arg, from_tty):
            gdb.execute("python print dir(%s)" % arg)

And finally a code I retrieved from ratmice@gitorious, an extended prompt for GDB, which shows the current source file, line and function, all that with colors (my version is here):

(src/ls.c:1242 main gdb)