config.phundrak.com/docs/stumpwm/theme.org
Lucien Cartier-Tilet 87b3deeed3
All checks were successful
deploy / build (push) Successful in 2m27s
feat: restore sidebar's table of contents for nested pages
2024-01-28 09:06:40 +01:00

203 lines
8.2 KiB
Org Mode
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#+title: Theme
#+setupfile: ../headers
#+property: header-args:emacs-lisp :tangle no :exports results :cache yes :noweb yes
* Theme
** Theme
:PROPERTIES:
:header-args:lisp: :mkdirp yes :tangle ~/.stumpwm.d/theme.lisp :noweb yes
:END:
As in the modeline file, the first thing well do is to load our
colours.
#+begin_src lisp
(load "~/.stumpwm.d/colors.lisp")
#+end_src
We can now go onto more serious business.
*** Fonts
This gave me quite the headache when I tried to set this up: in order
to use TTF fonts (note: it is not possible to use OTF fonts, see
below), we need to use the ~ttf-fonts~ module which relies on the
~clx-truetype~ library. A few years back, it should have been possible
to get it installed with a call to src_lisp[:exports
code]{(ql:quickload :clx-truetype)}, but it is no longer available!
Theres a quickfix available while we wait for ~clx-truetype~ to be once
again available: clone it in quicklisps local projects. You will
obviously need to have quicklisp installed (for that, follow the
[[https://www.quicklisp.org/beta/#installation][official instructions]]), then execute the following shell commands:
#+begin_src sh :dir ~/quicklisp/local-projects
cd ~/quicklisp/local-projects/
git clone https://github.com/lihebi/clx-truetype.git
#+end_src
This will make ~clx-truetype~ available to quicklisp, and you can run
again src_lisp[:exports code]{(ql:quickload :clx-truetype)} without an
issue (running it again is necessary to install its dependencies).
In order for it to work, install [[https://www.quicklisp.org/beta/][quicklisp]] and dont forget to run
src_lisp[:exports code]{(ql:add-to-init-file)} so it is loaded each
time you start your Lisp interpreter. ~SBCL~ should be your CommonLisp
interpreter of choice since StumpWM is generally compiled with it. The
main advantage is also that SBCL supports multithreading, unlike
CLisp. In case StumpWM doesnt find your font, spin up SBCL and
execute the following lines:
#+begin_src lisp :tangle no
(ql:quickload :clx-truetype)
(xft:cache-fonts)
#+end_src
If you want a list of font families available, you can execute the
following:
#+begin_src lisp :tangle no
(clx-truetype:get-font-families)
#+end_src
If you want to know the subfamilies of a certain family, you can
execute this:
#+begin_src lisp :tangle no
(clx-truetype:get-font-subfamilies "Family Name")
#+end_src
Now that this is out of the way, lets add two lines so we can use TTF
fonts:
#+begin_src lisp
(ql:quickload :clx-truetype)
(load-module "ttf-fonts")
#+end_src
The documentation says we should be able to also use OTF fonts, but so
far Ive had no luck loading one.
Loading more than one font to use
some fallback fonts also doesnt seem to work, unlike specified in the
documentation (I wanted to use a CJK font, but it doesnt appear to
work), we need to manually change the font used which isnt very
user-friendly, especially if you might have CJK characters appear in
otherwise regular text.
Something that didnt click immediately for me (and I think StumpWMs
documentation on this could be improved) is that ~set-font~ can be used
to set either one main font for StumpWM, as one might guess reading
the documentation --- or you can set a list of them! And this is
great, since my main font does not support some characters I regularly
have in my windows title, such as CJK characters! However, be aware
*the second font and further arent fallback fonts*. They are additional
fonts you can switch to manually through the use of ~^f<n>~ (~<n>~ being
the desireds font index in the 0-indexed font list). But if a font
cannot render a character, it will simply display an empty rectangle
instead of falling back to another font. Thats annoying… Here is my
list of fonts I want loaded:
#+name: list-fonts
| Family | Subfamily | Size |
|----------------------------------+-----------+------|
| Unifont-JP | Regular | 10 |
| DejaVu Sans Mono for Powerline | Book | 8.5 |
| siji | Medium | 10 |
| FantasqueSansMono Nerd Font Mono | Regular | 9.5 |
#+name: gen-fonts
#+header: :wrap src lisp
#+begin_src emacs-lisp :var fonts=list-fonts
(format "(set-font `(%s))"
(mapconcat (lambda (font)
(let ((family (nth 0 font))
(subfamily (nth 1 font))
(size (nth 2 font)))
(format ",%s" `(make-instance 'xft:font
:family ,(format "\"%s\"" family)
:subfamily ,(format "\"%s\"" subfamily)
:size ,size
:antialias t))))
fonts
"\n "))
#+end_src
The code equivalent of this table can be seen below:
#+RESULTS[1693001a9a9c0e274a9b7097665e9795783ae8a2]: gen-fonts
#+begin_src lisp
(set-font `(,(make-instance 'xft:font :family "Unifont-JP" :subfamily "Regular" :size 10 :antialias t)
,(make-instance 'xft:font :family "DejaVu Sans Mono for Powerline" :subfamily "Book" :size 8.5 :antialias t)
,(make-instance 'xft:font :family "siji" :subfamily "Medium" :size 10 :antialias t)
,(make-instance 'xft:font :family "FantasqueSansMono Nerd Font Mono" :subfamily "Regular" :size 9.5 :antialias t)))
#+end_src
As far as I know, Unifont is the only font Ive tested that displays
monospaced Japanese characters in StumpWM. I tried DejaVu, IBM Plex,
and a couple of others but only this one works correctly. DejaVu is
here for the Powerline separator. If you know of another monospaced
font that displays Japanese characters, or even better CJK characters,
please tell me! My email address is at the bottom of this webpage.
*** Colors
We can now set a couple of colors for StumpWM. Not that we will see
them often since I dont like borders on my windows, but in case I
want to get them back, theyll be nice to have.
#+begin_src lisp
(set-border-color phundrak-nord1)
(set-focus-color phundrak-nord1)
(set-unfocus-color phundrak-nord3)
(set-float-focus-color phundrak-nord1)
(set-float-unfocus-color phundrak-nord3)
#+end_src
Lets also set the colours of the message and input windows:
#+begin_src lisp
(set-fg-color phundrak-nord4)
(set-bg-color phundrak-nord1)
#+end_src
As I said, I dont like borders, so Ill remove them. Ill still keep
the windows title bar available when its floating, and this is also
where I can set the format of its title: its number as well as its
name, limited to thirty characters.
#+begin_src lisp
(setf *normal-border-width* 0
,*float-window-border* 0
,*float-window-title-height* 15
,*window-border-style* :none
,*window-format* "%n:%t")
#+end_src
I also have a [[https://github.com/Phundrak/stumpwm/tree/feature/no-hardcoded-which-key-format][StumpWM fork]] that introduces two new variables for
customizing which-key keybindings. I submitted a [[https://github.com/stumpwm/stumpwm/pull/931][pull request]], so it
might come one day to StumpWM.
#+begin_src lisp
(setf *key-seq-color* "^2")
(setf *which-key-format* (concat *key-seq-color* "*~5a^n ~a"))
#+end_src
*** Message and Input Windows
The Input windows as well as the message windows should both be at the
top of my screen. And I believe a padding of five pixels for the
message windows is good.
#+begin_src lisp
(setf *input-window-gravity* :top
,*message-window-padding* 10
,*message-window-y-padding* 10
,*message-window-gravity* :top)
#+end_src
*** Gaps Between Frames
I love gaps. When I was using i3, I used the ~i3-gaps~ package, not just
plain ~i3~. In Awesome, I still have gaps. And in StumpWM, I shall still
use gaps. In order to use them, lets load a module dedicated to gaps
in StumpWM:
#+begin_src lisp
(load-module "swm-gaps")
#+end_src
Now that this is done, I can now set some variables bound to this
package.
#+begin_src lisp
(setf swm-gaps:*head-gaps-size* 0
swm-gaps:*inner-gaps-size* 5
swm-gaps:*outer-gaps-size* 40)
#+end_src
Finally, lets enable our gaps:
#+begin_src lisp
(when *initializing*
(swm-gaps:toggle-gaps))
#+end_src