# -*- org-confirm-babel-evaluate: nil -*- #+TITLE: Polybar config #+INCLUDE: headers #+OPTIONS: auto-id:t #+HTML_HEAD_EXTRA: #+HTML_HEAD_EXTRA: #+HTML_HEAD_EXTRA: #+PROPERTY: header-args :exports none #+PROPERTY: header-args:python :results output #+PROPERTY: header-args:emacs-lisp :tangle no :exports none #+PROPERTY: header-args:conf-windows :tangle ~/.config/polybar/config :noweb yes :exports code #+STARTUP: content * Table of Contents :TOC_4_gh:noexport: :PROPERTIES: :CUSTOM_ID: Table_of_Contents-21ef28f2 :END: - [[#presentation][Presentation]] - [[#general-settings][General settings]] - [[#colors-declaration-for-polybar][Colors declaration for polybar]] - [[#declaration-of-the-bars][Declaration of the bars]] - [[#top-bar-declaration][Top bar declaration]] - [[#positioning][Positioning]] - [[#colors-and-display][Colors and display]] - [[#fonts-and-locale][Fonts and locale]] - [[#modules][Modules]] - [[#bottom-bar-declaration][Bottom bar declaration]] - [[#positioning-1][Positioning]] - [[#colors-and-display-1][Colors and display]] - [[#fonts-and-locale-1][Fonts and locale]] - [[#modules-1][Modules]] - [[#modules-2][Modules]] - [[#hardware][Hardware]] - [[#battery][Battery]] - [[#filesystem][Filesystem]] - [[#xbacklight][Xbacklight]] - [[#acpi-backlight][ACPI backlight]] - [[#cpu][CPU]] - [[#memory][Memory]] - [[#wlan][Wlan]] - [[#ethernet][Ethernet]] - [[#volume][Volume]] - [[#temperature][Temperature]] - [[#software][Software]] - [[#window-title][Window title]] - [[#i3][i3]] - [[#workspace-icons][Workspace icons]] - [[#focused-workspaces][Focused workspaces]] - [[#visible-workspaces][Visible workspaces]] - [[#unfocused-workspaces][Unfocused workspaces]] - [[#urgent-workspaces][Urgent workspaces]] - [[#mpd][Mpd]] - [[#date][Date]] - [[#footnotes][Footnotes]] * Presentation :PROPERTIES: :CUSTOM_ID: Presentation-4e723f32 :END: Polybar is a desktop utility for displaying various information in form of bars for GNU/Linux systems. It is often used as a replacement for native bars available in window managers, such as i3. In my case, I use two instances of polybar in order to get two bars displayed on each screen. The information displayed is either related to i3 itself, or it is system information, such as CPU or disk usage. More information will be given and explained below. If you want to learn more about how to configure Polybar, you can go to its [[https://github.com/jaagr/polybar][official repository on Github]]. #+BEGIN_EXPORT latex Be aware that this PDF documents suffers from a couple of issues with some characters such as emojis. If you wish to see everything correctly, I would suggest you to take a look at the online HTML version of this document. #+END_EXPORT * General settings :PROPERTIES: :CUSTOM_ID: General_settings-e02fb78c :END: Some general settings are available for Polybar, and they are declared under the ~[settings]~ section. #+BEGIN_SRC conf-windows [settings] #+END_SRC Only one setting is used in this configuration though: the ability to relauch polybar on a configuration file rewrite. #+BEGIN_SRC conf-windows screenchange-reload = true #+END_SRC Some global settings are also available in order to adjust the ~_NET_WM_STRUT_PARTIAL~ top and bottom values: #+BEGIN_SRC conf-windows [global/wm] margin-top = 32 margin-bottom = 22 #+END_SRC * Colors declaration for polybar :PROPERTIES: :CUSTOM_ID: Colors_declaration_for_polybar-75ee0b65 :END: #+BEGIN_SRC conf-windows :exports none ; -*- mode: conf-windows -*- #+END_SRC Like most status bars available, we can declare custom colors to be used in polybar. This part of the configuration file is declared with the following header: #+BEGIN_SRC conf-windows [colors] #+END_SRC As I use pywal as a color scheme generator based on the color of my wallpaper, I need to tell polybar to fetch the colors it will use from xrdb. If such color cannot be used, other colors will be used as fallback colors. First, let’s declare our default background and foreground colors with their alternative option. #+BEGIN_SRC conf-windows background = ${xrdb:color1:#50000000} background-alt = ${xrdb:color2:#444} foreground = ${xrdb:color7:#dfdfdf} foreground-alt = ${xrdb:color6:#555} #+END_SRC Now, we can also declare our primary and secondary colors. #+BEGIN_SRC conf-windows primary = #ffb52a secondary = #e60053 #+END_SRC Polybar is also aware of alerts sent by window managers such as i3 when a window opens in an unfocused workspace. For that, let’s declare an alert color. #+BEGIN_SRC conf-windows alert = #bd2c40 #+END_SRC * Declaration of the bars :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-a95135a3 :END: It is possible in i3 to declare as many bars as we wish, and each of these bars will be named. Naming the bar is done in its module declaration like so: #+BEGIN_SRC conf-windows :tangle no [bar/nameofthebar] #+END_SRC In my configuration, I use two of such bars, one atop of my screen, and one at the bottom. ** Top bar declaration :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Top_bar_declaration-fc0cd977 :END: As unimaginative as it might seem, I went for a rather explicit name for my bars. The top one is simply named ~top~, as shown below. #+BEGIN_SRC conf-windows [bar/top] #+END_SRC *** Positioning :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Top_bar_declaration-Positioning-2505760c :END: We need to set on which screen the bar is to be displayed. Indeed, it is possible to display a bar on only one specific screen if we wish to. Actually, it is even the default behavior of polybar, but as we will see later with the launching script, it is possible to launch bars on multiple outputs at the same time. Here, we simply get the value of the variable ~monitor~ from the launch environment. #+NAME: monitor-bar #+BEGIN_SRC conf-windows monitor = ${env:MONITOR} #+END_SRC We have a few position-related variables that need to be set. We can specify whether or not we want our bar at the bottom of the screen —which is the default behavior of polybar—, its width, its height, the radius for the rounding of its corners and whether the bar should be centered or not. In my case, my bars are rather small height-wise, and it occupies most of the width of my screens. There is some gaps between this bar and the border of the screen, but this is due to a border around the bar itself which acts not only on the width of the bar itself, but also on its height. #+BEGIN_SRC conf-windows bottom = false border-size = 5 <> #+END_SRC #+NAME: position-bar-top #+BEGIN_SRC conf-windows :exports none :tangle no width = 100% height = 22 radius = 10.0 fixed-center = true #+END_SRC We also want to add some padding to our bar so our modules are not too close to its edges, especially due to the rounding of the top bar. #+NAME: padding-bar #+BEGIN_SRC conf-windows padding-left = 2 padding-right = 4 #+END_SRC Each module will have some padding around it, so that modules aren’t glued together and instead have some room to breathe. The padding on the left is a bit less than the padding on the right for aesthetic reasons. #+NAME: module-margin-bar #+BEGIN_SRC conf-windows module-margin-left = 1 module-margin-right = 2 #+END_SRC The top bar doesn’t include any system tray, so let’s disable that. #+BEGIN_SRC conf-windows tray-position = none #+END_SRC *** Colors and display :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Top_bar_declaration-Colors_and_display-30f12652 :END: As explained above, we declared some global variables when it comes to colors, and this is where they will be used. The bar’s background will be of the same color as the main background color declared earlier, and the same goes for the foreground. #+NAME: bar-colors #+BEGIN_SRC conf-windows background = ${colors.background} foreground = ${colors.foreground} #+END_SRC If we wanted, we could also declare a default color for the underlines under the various modules that will be included in the bar, but in our case this variable is unused. So we will simply add this commented line as a memento this is possible, but it won’t have any effect with this current configuration of polybar. Same goes for the border around the bar, it is a useless variable in this configuration since we want the border to be transparent. #+NAME: line-border-color #+BEGIN_SRC conf-windows line-color = #f00 ; border-color = #00000000 #+END_SRC Although the variable for the default line color is not used, we still have to set the default width of the underline of our modules. By default, their underline will be three pixels thick. #+NAME: line-size-bar #+BEGIN_SRC conf-windows line-size = 3 #+END_SRC *** Fonts and locale :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Top_bar_declaration-Fonts_and_locale-70a25466 :END: Now we can chose which font fill be used in order to display text in this bar, as well as the locale we want. The locale will be useful for displaying information such as date and time, which is a module we will have in this top bar. First, the declaration of the locale is done like so: #+NAME: locale-bar #+BEGIN_SRC conf-windows locale = ja_JP.UTF-8 #+END_SRC Now, we can declare the fonts we want to use in Polybar. It is possible to declare several of them, the first one is the one which gets the absolute priority, and the next ones with a larger index are fallback fonts. Font declaration accepts the fontconfig format as well as possible offset[fn:1]. Five fonts are used in my polybar config: #+NAME: fonts-polybar | Font | fontconfig | Vertical offset | Why it’s used | |--------------+----------------------------------------------------+-----------------+-----------------------| | Fira Sans | Fira Sans Book:style=Book:pixelsize=10 | 1 | Text display | | IPA Mincho | IPAMincho:style=regular:pixelsize=6 | 0 | Japanese text display | | Unifont | unifont:fontformat=truetype:size=6:antialias=false | 0 | Fallback font | | NotoEmoji | NotoEmoji:style=Book:scale=16 | 0 | Emoji display | | Siji | Siji:pixelsize=8 | 0 | Symbol display | | Default font | fixed:pixelsize=8 | 0 | Fallback font | #+NAME: font-config #+BEGIN_SRC python :var table=fonts-polybar :cache yes for i in range(0, len(table)): print("font-{0} = {1};{2}".format(i, table[i][1], table[i][2])) #+END_SRC #+RESULTS[a055f871fdabec995b015a8f083a77b0096a9c7f]: font-config : font-0 = Fira Sans Book:style=Book:pixelsize=10;1 : font-1 = IPAMincho:style=regular:pixelsize=6;0 : font-2 = unifont:fontformat=truetype:size=6:antialias=false;0 : font-3 = NotoEmoji:scale=12:style=Book;0 : font-4 = Siji:pixelsize=8;0 : font-5 = fixed:pixelsize=8;0 Here’s the font configuration: #+BEGIN_SRC conf-windows <> #+END_SRC Note that only Fira Sans get a small offset due to the size of the font and the height of the bar itself. *** Modules :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Top_bar_declaration-Modules-18979638 :END: Finally, arguably one of the most important parts of our bar configuration: the module selection. Modules can be positioned in three different parts of our bar: to the right, in middle or to the left. On the left, we want our workspace indicator for i3. In the middle, we’ll get the title of the focused window, and to the left we’ll have the date and time. #+NAME: modules-generate #+BEGIN_SRC python :var table=[] :results value :cache yes left = 'modules-left = ' center = 'modules-center = ' right = 'modules-right = ' for line in table: if line[1] == 'left': left += line[0] + ' ' elif line[1] == 'center': center += line[0] + ' ' else: right += line[0] + ' ' return left + '\n' + center + '\n' + right #+END_SRC Here is the list of modules used: #+NAME: top-modules | Module name | Position | Brief description | |-------------+----------+----------------------------| | i3 | left | i3 workspace indicator | | xwindow | center | Name of the focused window | | date | right | Date and time | #+BEGIN_SRC conf-windows :cache yes <> #+END_SRC Each module will be described in details later in this document. ** Bottom bar declaration :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Bottom_bar_declaration-8504b5ec :END: As described above, we will once again have to declare our bar with an equally unimaginative but explicit name. #+BEGIN_SRC conf-windows [bar/bottom] #+END_SRC *** Positioning :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Bottom_bar_declaration-Positioning-b1883756 :END: The variables are the same as above, but two of them will be slightly modified: #+BEGIN_SRC conf-windows bottom = true border-size = 0 <> #+END_SRC #+NAME: position-bar-bottom #+BEGIN_SRC conf-windows :exports none :tangle no width = 100% height = 22 radius = 0.0 fixed-center = true #+END_SRC When it comes to the bottom bar, I prefer to have it fit my outputs, without any margin around it. And of course, I have to declare it as being at the bottom of the screen, hence these modifications. As regards the padding of our modules, their own margins, and the screen output, they aren’t modified. #+BEGIN_SRC conf-windows <> <> <> #+END_SRC However, we do display the system tray on this bottom bar at its right. It has no padding and it is not detached from the bar (this allows the bar to be displayed under the icons of the system tray), and their maximum size was chosen so they are well visible without being too big. #+BEGIN_SRC conf-windows tray-position = right tray-padding = 0 tray-detached = false tray-maxsize = 15 #+END_SRC *** Colors and display :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Bottom_bar_declaration-Colors_and_display-854aae82 :END: Nothing changes from the top bar, all the variables stay with the same values. See [[#h-9f83a6fd-652a-45ca-894b-0a0e0d3f0084][Colors and display]] of the top bar for more information. #+BEGIN_SRC conf-windows <> <> <> #+END_SRC *** Fonts and locale :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Bottom_bar_declaration-Fonts_and_locale-67459d62 :END: Again, nothing changes from the top bar, so for more info on what’s going on, see [[#h-c5660945-4785-40f7-b89e-f9f31b85a062][Fonts and locale]] of the top bar. #+BEGIN_SRC conf-windows <> <> #+END_SRC *** Modules :PROPERTIES: :CUSTOM_ID: Declaration_of_the_bars-Bottom_bar_declaration-Modules-702b21fc :END: Now, we can get to something interesting again: modules. This bar has a lot more modules than the top bar. Here is the list of the modules we have on the bottom bar: #+NAME: table-modules-bottom | Module name | Position | Brief description | |----------------+----------+---------------------------------| | mpd | left | MPD status indicator | | filesystem | right | Free storage in our filesystem | | wlan | right | Name of the active WiFi network | | eth | right | Local address on Ethernet | | volume | right | System volume | | backlight-acpi | right | Screen backlight | | cpu | right | CPU usage | | memory | right | RAM usage | | temperature | right | CPU temperature | | custom-battery | right | Battery usage | Here’s the corresponding configuration: #+ATTR_LATEX: :options breaklines #+BEGIN_SRC conf-windows <> #+END_SRC All these modules will be explained below. As you may have noticed, no modules will be displayed in the middle of this bar. * Modules :PROPERTIES: :CUSTOM_ID: Modules-2e1a51bc :END: Before we begin to describe the different modules, I would like to point out something that will be repeated multiple times if I don’t talk about it right now: for each module, it is possible to declare the foreground and background color of the prefix of the modules, as well as the underline color and the padding of the module. I like these parameters to be rather consistent, so the code block you will see below will often be reused. The colors refer to the colors declared earlier, and the padding is minimal. #+NAME: mod-prefix-col #+BEGIN_SRC conf-windows :tangle no format-prefix-foreground = ${colors.foreground-alt} format-prefix-underline = ${colors.secondary} format-underline = ${colors.secondary} format-padding = 1 #+END_SRC ** Hardware :PROPERTIES: :CUSTOM_ID: Modules-Hardware-26426ebd :END: *** Battery :PROPERTIES: :CUSTOM_ID: Modules-Hardware-Battery-299f2e42 :END: This module allows the user to get a battery widget among the polybar modules that will also send a notification to the user if the battery level drops below a certain value. This module relies on ~polybar-another-battery~ ([[https://github.com/drdeimos/polybar_another_battery][link]]) and its generated binary ~polybar-ab~ which should be in the ~$PATH~. The first line of the module declaration lets the user name the module however they want. In this case, the name is ~custom-battery~. #+BEGIN_SRC conf-windows [module/custom-battery] #+END_SRC Since it is not a core module, we have to declare it as a custom script so polybar knows what to do with it. #+BEGIN_SRC conf-windows type = custom/script #+END_SRC We now can specify the script execution, and whether or not the script will be continuously outputting something. In our case, the answer to this last question is yes. #+BEGIN_SRC conf-windows exec = polybar-ab -polybar -thr 10 tail = true #+END_SRC The ~-thr 10~ specifies the threshold for polybar-ab at which it should warn the user about the battery level of the computer. Of course, users on desktop computers won’t need this module which is aimed at laptop users. Feel free to remove it if you do not need it. *** Filesystem :PROPERTIES: :CUSTOM_ID: Modules-Hardware-Filesystem-26f0a3c6 :END: This module allows to display information about our filesystem, including (and this is what I use this module for) displaying the used space and remaining space on different mount points. This module is an internal module to polybar, so let’s declare it as such: #+BEGIN_SRC conf-windows [module/filesystem] type = internal/fs #+END_SRC We can specify how often the filesystem is to be checked with the variable ~interval~. I prefer it not to check it too often in order to not ping too often my drives, but I want it to be often enough so it is somewhat responsive. This is why I settled on a 20 seconds interval. #+BEGIN_SRC conf-windows interval = 20 #+END_SRC We now have to indicate where our different filesystems are mounted. In the case of my main computer /Marpa/, I have two partitions, the root partition and the home partition. But on my travel laptop, I only have the root partition, hence the usage of the below Elisp code that determines based on the computer it is running whether or not the second mount point to my home partition should be included. #+NAME: include-home-partition #+BEGIN_SRC emacs-lisp :tangle no :exports code (if (string= system-name "Marpa") "mount-1 = /home") #+END_SRC #+BEGIN_SRC conf-windows mount-0 = / <> #+END_SRC Now we can set the format of our module. There are two mains formats, one for mounted and one for unmounted mountpoints. For both, we’ll simply use their label. #+BEGIN_SRC conf-windows format-mounted = format-unmounted = #+END_SRC When it comes to the mounted partition, we want to display the name of the mountpoint and how used it is, both in terms of gigabytes and percentage. #+BEGIN_SRC conf-windows label-mounted = 💽 %mountpoint%: %used%/%total% (%percentage_used%%) label-mounted-foreground = ${colors.foreground} label-mounted-underline = ${colors.secondary} #+END_SRC If the volume is unmounted (which should be worrying considering the mountpoints chosen), then we’ll simply have a message telling us about that, and the foreground color will use the alternative foreground color described earlier. #+BEGIN_SRC conf-windows label-unmounted = %mountpoint% not mounted label-unmounted-foreground = ${colors.foreground-alt} #+END_SRC *** Xbacklight :PROPERTIES: :CUSTOM_ID: Modules-Hardware-Xbacklight-2901c504 :END: This module is used in order to display the level of brightness of a screen. It is not used by itself, but rather by other modules, such as [[#h-9adad94d-961c-44a7-aed1-91a8f22b4eef][ACPI backlight]]. First of all, this module is an internal module for xbacklight. It will also display the brightness percentage, prefixed by a sun emoji. Lastly, it will be underlined by a green line. #+BEGIN_SRC conf-windows [module/xbacklight] type = internal/xbacklight format =