xDroid's Blog

跳入 i3 的大坑

好吧,因爲上一次 gnome 莫名其妙掛了,想試一下 i3 能不能啓動,於是就掉進了大坑。這裏記錄一下我的使用習慣和相關配置。

終端

  1. 將終端調整爲 gnome-terminal(在 ~/i3/config 中)
    bindsym $mod+Return exec gnome-terminal
  2. 對於字體,不知道爲什麼原來好好的 Ubuntu Mono 等一系列字體全都 fallback 到一個奇怪的繁體字體上(其實 UI 也有這個問題)。后来发现只是搜狗输入法没切成简体……

應用

  1. 啓動菜單使用 synapse
  2. 不知爲啥 nautilus 不能用了,改用 thunar

快捷鍵

鍵位 說明
$ Return 終端
$ shift q 關閉窗口
$ s 應用菜單
$ ↑/↓/←/→ 切換焦點
$ shift ↑/↓/←/→ 移動焦點窗口
$ f 全屏(免打擾~)
$ d/w/e 棧疊/標籤/分裂模式
$ shift space 切換浮動狀態
$ [n] 進入工作區 [n]
$ shift [n] 移動焦點處的窗口到工作區 [n]
$ shift c/r/e 重載配置/重啓 i3 /退出

控制鍵

  1. 原來的控制鍵不能用了,於是要註冊一下( ~/.config/i3/config
    # Brightness
    bindsym XF86MonBrightnessUp exec xbacklight -inc 10
    bindsym XF86MonBrightnessDown exec xbacklight -dec 10
    
    # Audio
    bindsym XF86AudioRaiseVolume exec pamixer --increase 10
    bindsym XF86AudioLowerVolume exec pamixer --decrease 10
    bindsym XF86AudioMute exec pamixer -t
  2. 像截屏一類的比較難搞,本來好好的 gnome-screenshot 在 i3 下水土不服,只好默認開 -i
    # PrintScreen
    bindsym Print exec gnome-screenshot
    bindsym $mod+Print exec gnome-screenshot -i

狀態欄

首先安裝一堆依賴

sudo pacman -S i3blocks acpi sysstat

然后……一通瞎搞,直接贴代码吧

command=/usr/lib/i3blocks/$BLOCK_NAME
separator_block_width=15
markup=none

# Volume indicator
#
# The first parameter sets the step (and units to display)
# The second parameter overrides the mixer selection
# See the script for details.
[volume]
command=~/.i3/bin/volume
interval=once
signal=10
separator=false

[battery]
command=~/.i3/bin/battery
interval=30

# ---

[iface]
label=
#instance=wlan0
color=#00FF00
interval=10
separator=false

[wifi]
instance=wlp3s0
interval=10

[proxy]
command=~/.i3/bin/proxy
color=#00FF00
interval=10
separator=true

# ---

[cpu_usage]
interval=1
min_width=99.99%
align=right
separator=false

[memory]
label=
interval=30

# ---

[time]
command=date '+%Y-%m-%d %H:%M:%S'
interval=1

依赖几个小脚本

  • battery
    #!/bin/perl
    
    use strict;
    use warnings;
    use utf8;
    
    my $acpi;
    my $status;
    my $percent;
    my $ac_adapt;
    my $full_text;
    my $short_text;
    my $bat_number = $ENV{BLOCK_INSTANCE} || 0;
    
    # read the first line of the "acpi" command output
    open (ACPI, "acpi -b | grep 'Battery $bat_number' |") or die;
    $acpi = <ACPI>;
    close(ACPI);
    
    # fail on unexpected output
    if ($acpi !~ /: (\w+), (\d+)%/) {
    	die "$acpi\n";
    }
    
    $status = $1;
    $percent = $2;
    $full_text = "";
    
    if ($status eq 'Discharging') {
    	$full_text .= '';
    } elsif ($status eq 'Charging') {
    	$full_text .= '';
    } elsif ($status eq 'Unknown') {
    	open (AC_ADAPTER, "acpi -a |") or die;
    	$ac_adapt = <AC_ADAPTER>;
    	close(AC_ADAPTER);
    
    	if ($ac_adapt =~ /: ([\w-]+)/) {
    		$ac_adapt = $1;
    
    		if ($ac_adapt eq 'on-line') {
    			$full_text .= '';
    		} elsif ($ac_adapt eq 'off-line') {
    			$full_text .= '';
    		}
    	}
    }
    
    $short_text = $full_text;
    
    if ($acpi =~ /(\d\d:\d\d):/) {
    	$full_text .= " ($1)";
    }
    
    $full_text .= " $percent%";
    
    # print text
    print "$full_text\n";
    print "$short_text\n";
    
    # consider color and urgent flag only on discharge
    if ($status eq 'Discharging') {
    
    	if ($percent < 20) {
    		print "#FF0000\n";
    	} elsif ($percent < 40) {
    		print "#FFAE00\n";
    	} elsif ($percent < 60) {
    		print "#FFF600\n";
    	} elsif ($percent < 85) {
    		print "#A8FF00\n";
    	}
    
    	if ($percent < 5) {
    		exit(33);
    	}
    }
    
    exit(0);
  • proxy
    #!/bin/bash
    target="www.google.com"
    timeout=1
    
    res=`proxychains -f /etc/proxychain.conf.test curl ${target} -m ${timeout} -I -s -w %{http_code} 2>/dev/null | tail -n1`
    
    icon=""
    
    if [ "x${res}" = "x200" ]
    then
        echo $icon
        echo $icon
        echo \#2F8DFF
    else
        echo $icon
        echo $icon
        echo \#CD101E
    fi
  • volume
    #!/bin/bash
    ismute=`pamixer --get-mute`
    if [ $ismute = "true" ]
    then
        # mute
        muteicon=""
        echo $muteicon
        echo $muteicon
        echo \#777777
    else
        # not mute
        volume=`pamixer --get-volume`
        icon=""
        echo $icon $volume
        echo $icon $volume
        echo \#FFFF00
    fi
    超有趣。

其他

  1. 有趣的配置,見 i3-config
  2. 全局字體換爲 DejaVu (在 ~/i3/config 中)
    font pango:DejaVu Sans Mono, Noto Sans Mono CJK SC 8
  3. $mod 爲 Windows 徽
    set $mod Mod4
  4. 自啓動 fcitx
    exec --no-startup-id fcitx