Skip to content

Polybar custom module - List all open windows, click to switch focus or minimize

License

Notifications You must be signed in to change notification settings

tuurep/windowlist

Repository files navigation

windowlist

screenshot

Began as a fork of my favorite Polybar script polywins

Windowlist has been fully rewritten in C using the relevant parts of the source code from wmctrl and xprop.

Improvements over polywins

  • Fixed a bug where names would not be correct if WM_CLASS contains spaces or dots
  • Option to sort the window list:
    • By horizontal position on the screen
    • By the application name
  • Ability to set nicknames for windows if a window has a bad default name
  • More flexible styling
  • Configurable click actions

Installation

Project directory should be in ~/.config/polybar/scripts/

In ~/.config/polybar/scripts/windowlist/ run make

Add module in ~/.config/polybar/config.ini:

[module/windowlist]
type = custom/script
exec = ~/.config/polybar/scripts/windowlist/main 2> /dev/null
tail = true

Add module windowlist in any of modules-left, modules-center or modules-right

Configuration

Windowlist can be configured in config.toml in the root of the project.

If config.toml doesn't already exist, it will be created as a copy of config-default.toml when running make. It will not be overwritten if it exists.

Keys can be removed or commented out from config.toml, they will fall back to the default values in that case.

All options are detailed below:

Option Description Possible values
sort_by Criteria to sort the list of windows.
  • "none": no sort, WM client list order (default)
  • "position": sort based on horizontal position on the screen
  • "application": sort alphabetically based on the application class
max_windows How many windows can be visible on the list. Number of windows that did not fit will be shown e.g. "(+3)". number (default: 13)
all_desktops List windows from all desktops, instead of the current desktop only. boolean (default: false)
name Which X window property is considered window name (label for a window).
  • "class": WM_CLASS (default)
  • "title": WM_NAME
name_case Text case for window names.
  • "lowercase": all lowercase (default)
  • "uppercase": all uppercase
  • "none": don't change capitalization
name_max_length Maximum length for a window name before it's truncated with "‥". number (default: 30)
name_padding How many spaces to add before and after a window name. number (default: 1)
separator_string String displayed between window names. any string (default: "·")
empty_desktop_string String to show when no windows are open. any string (default: "")
active_window_left_click
Click actions for window names can be set as "raise", "minimize" or "close", or a custom script/program in the click-actions directory. Window currently in focus (active) and unfocused windows (inactive) are configurable separately.
  • script name (default: "minimize")
  • "none": no action
inactive_window_left_click
This is the main reason inactive window click actions can have a separate click action: it only makes sense to raise a window when it's not the active window.
  • script name (default: "raise")
  • "none": no action
active_window_right_click
inactive_window_right_click
Right click is an example that has the same action regardless of active status, by default.
  • "none": no action
  • script name (default: "close")
active_window_middle_click
active_window_scroll_up
active_window_scroll_down
inactive_window_middle_click
inactive_window_scroll_up
inactive_window_scroll_down
These are all the rest of the click actions that Polybar allows (TODO: doubleclick actions #33). They do nothing by default, but if you have an idea, see section about scripting.
  • "none": no action (default)
  • script name
active_window_fg_color empty_desktop_fg_color overflow_fg_color Foreground colors for:
  • Currently focused window
  • The empty_desktop_string
  • The string shown when max_windows exceeded
  • "none": use fg color defined in your config.ini (default)
  • hex color string
inactive_window_fg_color separator_fg_color Foreground colors for:
  • Windows not in focus
  • The separator_string
You may want to set the color as your foreground-alt from your config.ini to best match your colorscheme. Unfortunately I couldn't make it use that directly because of reasons explained here.
  • "none": use fg color defined in your config.ini
  • hex color string (default: "#808080")
*_bg_color All of the foreground colors have a background color counterpart, e.g. active_window_bg_color.
  • "none": no background color (default)
  • hex color string
*_ul_color All colors also have an underline color counterpart, e.g. active_window_ul_color.

Note that line-size must be set to 1 or higher in your Polybar config.ini, otherwise underline isn't visible.
  • "none": no underline (default)
  • hex color string
*_font All elements can be set to use an alternative font defined in your Polybar config.ini. For example, to use font-1 for the active window name, set active_window_font = 1.

To use a bold variant of a font, set e.g. font-1 = DejaVu Sans:weight=bold in config.ini.

See here for more details.
number (default: 0)
ignored_classes Windows with a WM_CLASS in this array will not be shown on the bar. Strings are matched case insensitively. array of strings (default: empty)
window_nicknames A window name can be substituted with a custom name using key value pairs. The keys are matched case insensitively.

The key should be double quoted in case the window class contains special characters like dots (.).
table of string key-value pairs (default: empty)

Note

Polybar must be reset before changes take effect.

Scripting click actions

The most convenient way is to write a shell script in the click-actions directory. Any language could be used, though. There are three "default" actions as small C programs: raise, minimize and close.

You can write a new action as a script such as:

click-actions/foo.sh

#!/bin/sh

window_id="$1"

# Do something with the window id of the window that has been clicked/scrolled on

Set the script as executable: chmod +x click-actions/foo.sh

Then in config.toml:

active_window_middle_click = "foo.sh"

Window id is always given as arg $1. Tools I know that could be used to make something happen with a window id:

Dependencies

Requires an EWMH compliant window manager

  • Wikipedia table to see if a window manager is EWMH compliant: link

About

Polybar custom module - List all open windows, click to switch focus or minimize

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •