Skip to content
GTK menu for sway and i3
Python
Branch: master
Clone or download
Latest commit 0c24d26 Jan 17, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist path adjusted to the new repository name Jan 11, 2020
examples basic css styling Jan 13, 2020
screenshots more screenshots Jan 15, 2020
sgtk-menu Don't show in taskbar on floating WMs Jan 17, 2020
.gitignore Add an option to offset the menu from the edge of the screen. Jan 12, 2020
LICENSE Create LICENSE Jan 5, 2020
README.md help updated Jan 17, 2020
setup.py bump to 0.5.0 Jan 17, 2020

README.md

sgtk-menu

This project is an attempt to create a simple menu, that behaves decently on sway, but also on i3 window manager. It uses pygobject to create a themeable, searchable gtk3-based system menu w/ some optional features.

Features

  • .desktop entries-based system menu;
  • search box to find what you need quickly;
  • favourites (most frequently used entries) menu above (optional [-f | -fn FN] argument);
  • user-defined menu below (optional [-a | -af AF] argument).

As the script searches .desktop files only, it may be used as a replacement to wofi/rofi --drun, but not for --dmenu mode.

screenshot The menu in Arc-Dark GTK theme w/ Aqatix icons

Background

Well, I didn't even think that sway needed a menu, being happy with wofi and dmenu-wayland. I started coding just to find out what the freedesktop Desktop Menu Specification looks like, and also to learn some more pygobject. The best menu I know, however, does not (yet?) behave well on sway. So, I thought to share the code, which has already taken me more time that I had ever expected.

This code by Johan Malm helped me understand how to make use of .desktop entries. Many thanks!

Usage

$ sgtk-menu -h
usage: sgtk-menu [-h] [-b | -c | -m] [-f | -fn FN] [-a | -af AF] [-n] [-l L] [-s S] [-w W] [-d D] [-o O]
               [-t T] [-y Y]

GTK menu for sway and i3

optional arguments:
  -h, --help        show this help message and exit
  -b, --bottom      display menu at the bottom
  -c, --center      center menu on the screen
  -m, --mouse       display at mouse pointer (floating WMs only)
  -f, --favourites  prepend 5 most used items
  -fn FN            prepend <FN> most used items
  -a, --append      append custom menu from /home/piotr/.config/sgtk-menu/appendix
  -af AF            append custom menu from /home/piotr/.config/sgtk-menu/<AF>
  -n, --no-menu     skip menu, display appendix only
  -l L              force language (e.g. "de" for German)
  -s S              menu icon size (min: 16, max: 48, default: 20)
  -w W              menu width in px (integer, default: screen width / 8)
  -d D              menu delay in milliseconds (default: 100)
  -o O              overlay opacity (min: 0.0, max: 1.0, default: 0.3)
  -t T              sway submenu lines limit (default: 30)
  -y Y              y offset from edge to display menu at

Sample sway key binding:

bindsym mod1+F1 exec sgtk-menu -f -a

or sample i3 key binding:

bindsym Mod1+F1 exec --no-startup-id sgtk-menu -f -a

displays menu prepended with the default number of favourites, appended with the default ~/.config/sgtk-menu/appendix file. Use sgtk-menu -f -af <custom_menu_file> to append your custom menu. Copy and edit the default appendix file (in the same location).

Installation

For now the only available package is sgtk-menu [AUR] for Arch linux. However, you may simply clone the repository and launch the menu.py file, instead of sgtk-menu command.

Dependencies

  • sway or i3
  • gtk3
  • python (python3)
  • python-gobject
  • python-cairo | python-cairocffi
  • python-i3ipc

How it works?

The problem to resolve was, that the Gtk.Menu class behaves differently / unexpectedly when open over Wayland and X11 windows. To work it around, the script opens the menu over a (semi-)transparent, floating window, that covers all the screen.

Styling

You may use the ~/.config/sgtk-menu/style.css file to override some theme settings, e.g.:

#menu {
    font: 14px Sans;
    font-weight: 400;
}

#separator {
    margin: 10px;
}

Widgets are named as below:

css-styling

i3 support

Even if there exist plenty of good X11 menus, with the most excellent jgmenu on top, I'm doing my best to make sgtk-menu i3-compatible. See below to resolve issues, if any.

Troubleshooting

Menu does not position properly in the screen corner

Try increasing the delay length. The default value is 100 milliseconds, and on my laptop it works well down to 30. Slower machines, however, may require higher values. E.g. try using -d 200 argument.

Overlay behind the menu is not (semi)transparent on i3

You need compton or equivalent X11 compositor.

Overlay first displays as a tiled window on i3

Add this to your ~/.config/i3/config file:

for_window [title="~sgtk-menu"] border none, floating enable

TODO

  • On next sway / GTK release, check if the overflowed menus issue on sway is fixed; remove 50 SLOC long workaround if so;
  • testing;
  • more testing.
You can’t perform that action at this time.