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.

All options are detailed below:

Option Description Possible values
sort_by Criteria to sort the list of windows
  • "none": unordered (WM client list order)
  • "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 (int)
name Which X window property is considered window name (label for a window)
  • "class": WM_CLASS
  • "title": WM_NAME
name_case Text case for window names
  • "none": don't change capitalization
  • "lowercase": all lowercase
  • "uppercase": all uppercase
name_max_length Maximum length for a window name before it's truncated with number (int)
name_padding How many spaces to add before and after a window name number (int)
separator_string String displayed between window names any string
empty_desktop_string String to show when no windows are open any string
active_window_left_click
active_window_middle_click
active_window_right_click
active_window_scroll_up
active_window_scroll_down
inactive_window_left_click
inactive_window_middle_click
inactive_window_right_click
inactive_window_scroll_up
inactive_window_scroll_down
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.
  • "none": no action
  • name of script (string)
active_window_fg_color inactive_window_fg_color separator_fg_color empty_desktop_fg_color overflow_fg_color Foreground colors for:
  • Currently focused window
  • Windows not in focus
  • The separator_string
  • The empty_desktop_string
  • The string shown when max_windows exceeded
  • "none": default polybar fg
  • hex color (string)
*_bg_color All of the foreground colors have a background color counterpart, e.g. active_window_bg_color
  • "none": no background color
  • 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
  • hex color (string)
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
window_nicknames A window name can be substituted with a custom name using key value pairs. The keys are matched case insensitively. table of string key-value pairs

Note: polybar must be reset before changes take effect.

Defaults

Check the config.toml in this repo, the options set there are the default values.

You can also remove any key and it will fall back to the default value.

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 list of EWMH compliant window managers: 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

  •  
  •  
  •  
  •