A Simple Guide to Customize X on OpenBSD 6.4
HOME » NOTEBOOK

Intro.

This page contains my log of customize X on OpenBSD 6.4 with a brief explanation. I always use cwm(1) and tmux(1), So if you wanted the information of a desktop environment such as XFce, Unfortunately, You may got nothing from here. I assume you already installed OpenBSD with enable xenodm!

1. Install packages.

First of all, You need ...

You can install those packages with the following one command.

$ doas pkg_add feh-2.27.tgz hermit-font-1.21p1.tgz transset-df-6p3.tgz \
           xsel-1.2.0p2.tgz conky-1.9.0p16.tgz
doas (***) password:
------------------------------------- snip -------------------------------------
$

2. Get ready for an image file.

You can prepare an image file you like. The image file will be set on the background, So you should looking for it that fits your monitor resolution. When you're good and ready and move it to your specific directory such as ~/.img. Here are some examples.

$ cd
$ mkdir -p .img
$ cd .img
$ wget -q https://***.com/foo.png        # require: doas pkg_add wget-1.19.5.tgz
$

Bye the way, I like The Milky Way Galaxy :)

3. Set the image file on the background.

Let's set the image file you prepared earlier on the background. You can easily do it with feh as follows.

$ feh --bg-center ~/.img/foo.png 

The above command will be written at a file called .xsession.

4. Set a new font to xterm.

You can set a new font called hermit to xterm as follows.

$ xterm -fa Hermit:style=medium &

Additionally, In case of me, I needed yet another double-width font that support to display Japanese letters.

$ doas pkg_add mixfont-mplus-ipa-20060520p7.tgz
------------------------------------- snip -------------------------------------
$ xterm -fa Hermit:style=medium -fd M+1P+IPAG:style=regular

And you can show the list of all fonts available with fc-list.

$ fc-list
/usr/X11R6/lib/X11/fonts/100dpi/courBO12.pcf.gz: Courier:style=Bold Oblique
/usr/X11R6/lib/X11/fonts/75dpi/ncenI14.pcf.gz: New Century Schoolbook:style=Italic
/usr/local/share/fonts/noto/Cousine-Italic.ttf: Cousine:style=Italic
------------------------------------- snip -------------------------------------
/usr/X11R6/lib/X11/fonts/100dpi/UTRG__10-ISO8859-1.pcf.gz: Utopia:style=Regular
/usr/X11R6/lib/X11/fonts/100dpi/lutRS18-ISO8859-1.pcf.gz: LucidaTypewriter:style=Sans
/usr/X11R6/lib/X11/fonts/100dpi/UTRG__14-ISO8859-1.pcf.gz: Utopia:style=Regular
$

The following makes it more readable with awk.

$ fc-list | awk '!($1 = "")'
 Courier:style=Bold Oblique
 New Century Schoolbook:style=Italic
 Cousine:style=Italic
------------------------------------- snip -------------------------------------
 Utopia:style=Regular
 LucidaTypewriter:style=Sans
 Utopia:style=Regular
$

5. Make xterm transparent with transset-df.

Let's move forward one step at a time! I recommended you run xcompmgr as follows, because it's necessary to make window transparent.

$ xcompmgr -c -o.2 &

Then you are good and ready to make window transparent with transset-df. Let's give it a try :) After you are run the following command, your mouse cursor changes to like plus mark, click any window to transparent it.

$ transset-df 0.75
******************* (click any window to transparent it...) ********************
Set Property to 0.75
$

The closer to zero, transparent is more light. The closer to one, transparent is more dark. Other than that, the transset-df have some of way to select the window.

$ transset-df --help 2>&1 | grep select
    -c, --click          select by clicking on window (default)
    -p, --point          select the window currently under the cursor
    -a, --actual         select the actual window
    -n, --name NAME      select by name, NAME is matched as regular expression
    -i, --id             select by window id
$

For example, you can select by WN_NAME which can show using xprop command as follows.

$ xprop
**************** (click any window to display its property...) *****************
------------------------------------- snip -------------------------------------
WM_NAME(STRING) = "XTerm_25369"
$ transset-df --name "XTerm_25369" 0.85
Set Property to 0.85 on
XTerm_25369
$

Because I want a unique WM_NAME each xterm, I use PID of the shell. But It's not absolutely unique sure :(

$ echo "XTerm_$$"
XTerm_25369
$

And I wanted to run ksh and tmux on xterm at same time for use with cwm later.

$ _PROGRAM="exec ksh -c 'tmux -2'"
$ xterm -e "${_PROGRAM}"

Moreover, I added transset-df to there for make window transparent.

$ _PROGRAM="transset-df 0.75 --name XTerm_$$ --no-regex >/dev/null; exec ksh -c 'tmux -2'"
$ xterm -title XTerm_$$ -e "${_PROGRAM}"

Making a summary of my log above, the goal is to make a new terminal transparent each one, which spawn by cwm. And the new terminal run ksh and tmux on xterm automatically.

Reference file:

When I want to spawn a new terminal decorated like the image which top of this page, I always use the shortcut key of CM-Return by cwm. See the manual cwm(1) and cwmrc(5) for details.

Reference file:

Finally, the .xsession file that the startup of feh, xcompmgr, cwm, and conky.

Reference file:

6. Set up to share clipboard between xterm and other X with xsel and tmux.

To begin with, There is a plain command that pass the Clipboard any string from xterm.

$ echo "hello, world" | xsel --clipboard --input

And now, you are already to can paste "hello, world" into Firefox, Chromium, etc from the Clipboard directly using right click paste or Ctrl-V. Then the following command pass xterm any string from the Clipboard such as Firefox's right click copy.

$ echo $(xsel --clipboard --output)
any string1 from right click copy
any string2 from right click copy
...
$

It's the following that the way to share any string with xsel and tmux between xterm and other X using the keyboard or the mouse. See the manual tmux(1) for details.

set-option -g mouse on

key="'xsel --clipboard --input'"
if-shell "which xsel" "bind-key -T copy-mode C-w               send-keys -X copy-pipe-and-cancel $key"
if-shell "which xsel" "bind-key -T copy-mode M-w               send-keys -X copy-pipe-and-cancel $key"
if-shell "which xsel" "bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel $key"

data="\"$(xsel --clipboard --output)\""
if-shell "which xsel" "bind-key    ]              run-shell 'tmux set-buffer $data; tmux paste-buffer'"
if-shell "which xsel" "bind-key -n MouseDown2Pane run-shell 'tmux set-buffer $data; tmux paste-buffer'"

Reference file:

7. Display a system monitor as part of background with conky.

In the end, I added a system monitor tool called conky :) The conky may have the problem that high cpu usage. But, in my case, the problem was just caused by config file and could avoided it. Note that you probably need to modify a part of the file. In my case, those two names correspond as follows.

$ ifconfig
------------------------------------- snip -------------------------------------
em0: flags=8843 mtu 1500
------------------------------------- snip -------------------------------------
$ grep em0 .conkyrc
  Up      ${upspeed em0} ${alignr} ${totalup em0} total
  Down    ${downspeed em0} ${alignr} ${totaldown em0} total
$

For example, in your case, if the name is not em0, but fxp0, you need to modify it. Here are some examples.

$ ifconfig
------------------------------------- snip -------------------------------------
fxp0: flags=8843 mtu 1500
------------------------------------- snip -------------------------------------
$ grep em0 .conkyrc
  Up      ${upspeed em0} ${alignr} ${totalup em0} total
  Down    ${downspeed em0} ${alignr} ${totaldown em0} total
$ sed -i 's/em0/fxp0/g' .conkyrc
$ grep fxp0 .conkyrc
  Up      ${upspeed fxp0} ${alignr} ${totalup fxp0} total
  Down    ${downspeed fxp0} ${alignr} ${totaldown fxp0} total
$

You probably more need to modify a part of the file in the same way as above such as about the number of CPU, the layout of filesystem, etc. See the manual conky(1) for details.

Reference file:

This guide end here :) Thank you for reading!

~/.xsession

Please download from here: .xsession

# display background image
feh --bg-center $HOME/.img/galaxy1920x1080.png &

# used to create transparent window
xcompmgr -c -o.2 &

# display system monitor
conky --config=~/.conkyrc &

# start my best window manager
cwm

~/sh/xterm.sh

Please download from here: xterm.sh

#!/bin/ksh

# xterm.sh - to spawn a new terminal for use with cwm

# Require Packages:
#   transset-df-6p3.tgz
#   hermit-font-1.21p1.tgz
#   mixfont-mplus-ipa-20060520p7.tgz

#-------------------------------------------------------------------------------
_OPACITY=0.75
_FONT_SIZE=12
_FG_COLOR=white
_BG_COLOR=black
#-------------------------------------------------------------------------------
_US_FONT=Hermit:style=medium
_JP_FONT=M+1P+IPAG:style=regular

fc-list | grep -q ${_US_FONT}
[[ $? -eq 1 ]] && _US_FONT=""
fc-list | grep -q ${_JP_FONT}
[[ $? -eq 1 ]] && _JP_FONT=""
#-------------------------------------------------------------------------------
_TITLE="XTerm_$$"
_PROGRAM="exec ksh -c 'tmux -2'"

pgrep -q xcompmgr
[[ $? -eq 0 ]] && _PROGRAM="transset-df ${_OPACITY} --name ${_TITLE} \
                      --no-regex >/dev/null; ${_PROGRAM}"
#-------------------------------------------------------------------------------
xterm -fa ${_US_FONT} -fd ${_JP_FONT} -fg ${_FG_COLOR} -bg ${_BG_COLOR} \
    -fs ${_FONT_SIZE} -title ${_TITLE} +sb -e "${_PROGRAM}"

~/.cwmrc

Please download from here: .cwmrc

sticky yes

fontname "Hermit:style=medium"

borderwidth             1
color activeborder      grey
color inactiveborder    black

color menubg    "#878787"
color menufg    "#a5a5a5"
color font      "#1c1c1c"
color selfont   "#1c1c1c"

gap 0 0 0 0

moveamount 10

bind-key CM-Return /home/hajime/sh/xterm.sh

command chrome  /home/hajime/sh/chrome.sh
command emacs   /usr/local/bin/emacs
command firefox /usr/local/bin/firefox
command gimp    /usr/local/bin/gimp
command scrot   "/usr/local/bin/scrot -d 1"
command xterm   /usr/X11R6/bin/xterm
command screencapture:start "/home/hajime/sh/screencapture start"
command screencapture:stop "/home/hajime/sh/screencapture stop"

autogroup 2     "xterm,XTerm"
autogroup 3     "chromium-browser,Chromium-browser"
autogroup 4     "Navigator,Firefox"
autogroup 5     "gimp,Gimp"

bind-key M-1 group-only-1
bind-key M-2 group-only-2
bind-key M-3 group-only-3
bind-key M-4 group-only-4
bind-key M-5 group-only-5

bind-key 4-comma        "mixerctl outputs.spkr=-5"
bind-key 4-period       "mixerctl outputs.spkr=+5"

bind-key 4-h    window-htile
bind-key 4-v    window-vtile

bind-key 4-y    window-snap-left
bind-key 4-u    window-snap-down
bind-key 4-i    window-snap-up
bind-key 4-o    window-snap-right

~/.tmux.conf

Please download from here: .tmux.conf

# change prefix of C-b to C-l

unbind-key C-b
set-option -g prefix C-l
bind-key C-l send-prefix

# change status bar position

set-option -g status-position top

# change count index

set-option -g base-index 1
set-window-option -g pane-base-index 1

# change display panes time

set-option -g display-panes-time 10000

# change repeat time

set-option -g repeat-time 1000

# set to move pane with hjkl keys

bind-key -r h select-pane -L
bind-key -r j select-pane -D
bind-key -r k select-pane -U
bind-key -r l select-pane -R

# set to resize pane with HJKL keys

bind-key -r H resize-pane -L 5
bind-key -r J resize-pane -D 5
bind-key -r K resize-pane -U 5
bind-key -r L resize-pane -R 5

# set up to share clipboard between terminal and others

set-option -g mouse on

key="'xsel --clipboard --input'"
if-shell "which xsel" "bind-key -T copy-mode C-w               send-keys -X copy-pipe-and-cancel $key"
if-shell "which xsel" "bind-key -T copy-mode M-w               send-keys -X copy-pipe-and-cancel $key"
if-shell "which xsel" "bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel $key"

data="\"$(xsel --clipboard --output)\""
if-shell "which xsel" "bind-key    ]              run-shell 'tmux set-buffer $data; tmux paste-buffer'"
if-shell "which xsel" "bind-key -n MouseDown2Pane run-shell 'tmux set-buffer $data; tmux paste-buffer'"

# set to reload with r key

bind-key r source-file ~/.tmux.conf \; display-message " reload done."

# change history limit

set-option -g history-limit 8192

# set message line color

set-option -g message-bg colour124
set-option -g message-fg yellow

# set up status bar color and format line

set-option -g status-left-bg colour250
set-option -g status-left-fg colour232
set -g status-left-length 15
set -g status-left " #S "

set-option -g status-bg colour124
set-option -g status-fg white

set-window-option -g window-status-current-fg colour124
set-window-option -g window-status-current-bg white

set-option -g status-right-length 50
set-option -g status-right-bg colour250
set-option -g status-right-fg colour232

set-option -g status-right " #(set -- `uptime | sed 's/^.*averages: //'`; echo $*) | %R "

~/.conkyrc

Please download from here: .conkyrc

background      yes
update_interval 1
double_buffer   yes
no_buffers      yes
#-------------------------------------------------------------------------------
gap_x                  5
gap_y                  5
minimum_size           1920 1080
maximum_width          370
alignment              top_left
own_window             yes
own_window_transparent yes
own_window_type        override
own_window_argb_visual yes
own_window_hints       undecorated,below,sticky,skip_taskbar,skip_pager
#-------------------------------------------------------------------------------
draw_shades           no
draw_outline          no
draw_borders          no
draw_graph_borders    yes
default_color         lightslategrey
default_shade_color   000000
default_outline_color 888888
#-------------------------------------------------------------------------------
use_xft              yes
xftfont              Hermit:size=11:antialias=true
xftalpha             1
uppercase            no
override_utf8_locale yes
#-------------------------------------------------------------------------------
TEXT
${color indianred3}CPU1: ${color}${cpu cpu0}%
${color}${cpubar cpu0 3}
${color indianred3}CPU2: ${color}${cpu cpu1}%
${color}${cpubar cpu1 3}
${color indianred3}CPU3: ${color}${cpu cpu2}%
${color}${cpubar cpu2 3}
${color indianred3}CPU3: ${color}${cpu cpu3}%
${color}${cpubar cpu3 3}
${color indianred3}Processes:          PID     ${alignr}CPU  ${color}
  ${top name 1}  ${top pid 1} ${alignr} ${top cpu 1}%
  ${top name 2}  ${top pid 2} ${alignr} ${top cpu 2}%
  ${top name 3}  ${top pid 3} ${alignr} ${top cpu 3}%
  ${top name 4}  ${top pid 4} ${alignr} ${top cpu 4}%
  ${top name 5}  ${top pid 5} ${alignr} ${top cpu 5}%
  ${top name 6}  ${top pid 6} ${alignr} ${top cpu 6}%
  ${top name 7}  ${top pid 7} ${alignr} ${top cpu 7}%
  ${top name 8}  ${top pid 8} ${alignr} ${top cpu 8}%
  ${top name 9}  ${top pid 9} ${alignr} ${top cpu 9}%

${color indianred3}Memory: ${color}$mem/$memmax
${color}${membar 3}${color}
${color indianred3}Processes:          PID     ${alignr} MEM  ${color}
  ${top_mem name 1}  ${top_mem pid 1} ${alignr} ${top_mem mem 1}%
  ${top_mem name 2}  ${top_mem pid 2} ${alignr} ${top_mem mem 2}%
  ${top_mem name 3}  ${top_mem pid 3} ${alignr} ${top_mem mem 3}%
  ${top_mem name 4}  ${top_mem pid 4} ${alignr} ${top_mem mem 4}%
  ${top_mem name 5}  ${top_mem pid 5} ${alignr} ${top_mem mem 5}%
  ${top_mem name 6}  ${top_mem pid 6} ${alignr} ${top_mem mem 6}%
  ${top_mem name 7}  ${top_mem pid 7} ${alignr} ${top_mem mem 7}%
  ${top_mem name 8}  ${top_mem pid 8} ${alignr} ${top_mem mem 8}%
  ${top_mem name 9}  ${top_mem pid 9} ${alignr} ${top_mem mem 9}%

${color indianred3}Network:${color}
  Up      ${upspeed em0} ${alignr} ${totalup em0} total
  Down    ${downspeed em0} ${alignr} ${totaldown em0} total

${color indianred3}Disk:${color}
  ${color}/          ${fs_bar 3,80 /} ${alignr} ${fs_used /}/${fs_size /}
  ${color}/home      ${fs_bar 3,80 /home} ${alignr} ${fs_used /home}/${fs_size /home}
  ${color}/tmp       ${fs_bar 3,80 /tmp} ${alignr} ${fs_used /tmp}/${fs_size /tmp}
  ${color}/usr       ${fs_bar 3,80 /usr} ${alignr} ${fs_used /usr}/${fs_size /usr}
  ${color}/usr/X11R6 ${fs_bar 3,80 /usr/X11R6} ${alignr} ${fs_used /usr/X11R6}/${fs_size /usr/X11R6}
  ${color}/usr/local ${fs_bar 3,80 /usr/local} ${alignr} ${fs_used /usr/local}/${fs_size /usr/local}
  ${color}/usr/obj   ${fs_bar 3,80 /usr/obj} ${alignr} ${fs_used /usr/obj}/${fs_size /usr/obj}
  ${color}/usr/src   ${fs_bar 3,80 /usr/src} ${alignr} ${fs_used /usr/src}/${fs_size /usr/src}
  ${color}/var       ${fs_bar 3,80 /var} ${alignr} ${fs_used /var}/${fs_size /var}