Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland menu for Sway? #1367

Closed
ghost opened this issue Sep 23, 2017 · 39 comments
Closed

Wayland menu for Sway? #1367

ghost opened this issue Sep 23, 2017 · 39 comments

Comments

@ghost
Copy link

ghost commented Sep 23, 2017

Hi.
Is there any application launcher for Sway that doesn't require xwayland?

@bearcatsandor
Copy link

bearcatsandor commented Sep 23, 2017 via email

@ddevault
Copy link
Member

There's bemenu but it has some issues.

@ghost
Copy link
Author

ghost commented Sep 23, 2017

Thanks. We should wait then.

@Zer0-One
Copy link
Contributor

@gnidorah see the wayland branch of https://github.com/michaelforney/dmenu

@ddevault
Copy link
Member

That is swc-specific, does not work on Sway.

@Zer0-One
Copy link
Contributor

oh, well shoot

@ghost
Copy link
Author

ghost commented Sep 24, 2017

@bearcatsandor Funny solution, thanks. Would be nice to find .desktop files parser for that to get something similar to i3-dmenu-desktop/j4-dmenu-desktop

@ddevault
Copy link
Member

i3-dmenu-desktop works on sway.

@ghost
Copy link
Author

ghost commented Sep 24, 2017

@SirCmpwn That's what I currently use, but It uses dmenu which requires xwayland

@jbg
Copy link

jbg commented Sep 28, 2017

I use compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec launched in a terminal with a specific window class, and configure sway to float and position that window. it works pretty well.

@bearcatsandor
Copy link

For what it's worth, i'm no longer having focus issues with rofi after upgrading to 1.4.1.

@alexryndin
Copy link

still have focus issue with rofi 1.5.1 and sway 0.15

@alexryndin
Copy link

@jbg could you explain your solution a bit?

@jbg
Copy link

jbg commented Jul 10, 2018

compgen -c lists commands on your PATH, sort -u gets rid of duplicates and puts it in alphabetical order, fzf shows an interactive interface to select one of those commands and outputs the selected command on stdout, xargs -r swaymsg -t command exec tells sway to run the selected command. if you bind a key to run this pipeline in a terminal with a specific window class, you can style that terminal in your sway configuration. i make it floating and small

@alexryndin
Copy link

alexryndin commented Jul 10, 2018

@jbg Thank you. This part is still unclear for me:

terminal with a specific window class

How can I change window style in wayland/sway?

@Shusek
Copy link

Shusek commented Sep 5, 2018

@alexryndin In 1.0 version albert (simmilar to rofi) is alive so maybe so maybe rofi will also work without any problem.

@ddevault
Copy link
Member

ddevault commented Sep 5, 2018

Yeah I think rofi works fine on sway master.

@KubqoA
Copy link

KubqoA commented Sep 23, 2018

@jbg Hi, I am curious about your solution. However, I can not figure out how to launch a terminal window with a specific class in sway. Any help appreciated

@PumbaPe
Copy link
Contributor

PumbaPe commented Sep 28, 2018

@alexryndin @KubqoA I don't think there is an easy way to change window classes, but you can use specific criteria of that window to customize it. See the Criteria section on sway's man page. I thought the best way would be to mark that terminal window upon launch and then use [con_mark="whatevermark"], but unfortunately that doesn't work since for some reason it is always the previously focussed window that is being marked instead of the new one. I've worked around this by launching the terminal window with a specific title (I guess most terminals support this) and then using that title as a criterion for customization commands. So my full command with gnome-terminal looks like this:
set $menu gnome-terminal --title Menu --hide-menubar --command "bash -c 'compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec'", for_window [app_id="gnome-terminal-server" title="Menu"] border pixel 0, for_window [app_id="gnome-terminal-server" title="Menu"] floating enable
(You can see the attributes of all open windows with swaymsg -t get_tree)

@RyanDwyer
Copy link
Member

RyanDwyer commented Sep 28, 2018

How can I change window style in wayland/sway?

I can not figure out how to launch a terminal window with a specific class in sway. Any help appreciated

I don't think there is an easy way to change window classes

Classes (and instances) are specific to X11. Wayland has a similar thing called app_id. The good news is on Sway we can see all three of them and apply criteria to all of them too. As for how to set the class, you need to check the man page for the terminal you're running, but it's usually --class or --classname or --name. Note that some terminals, when running on Wayland, will take the class argument and set it as the app_id instead. Again, check the man page of the terminal you're running.

I thought the best way would be to mark that terminal window upon launch and then use [con_mark="whatevermark"], but unfortunately that doesn't work since for some reason it is always the previously focused window that is being marked instead of the new one.

I don't understand the steps you're doing. How are you marking the window? You shouldn't need to mark the window in this case anyway.

set $menu gnome-terminal --title Menu --hide-menubar --command "bash -c 'compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec'", for_window [app_id="gnome-terminal-server" title="Menu"] border pixel 0, for_window [app_id="gnome-terminal-server" title="Menu"] floating enable

That's not really how it should be done. for_window adds a rule for windows matching the given criteria, and they exist until Sway exits or is reloaded. You're adding a new for_window rule every time you open your launcher.

This is how I'm doing it with termite:

bindsym $mod+r exec termite --name=launcher -e "bash -c 'compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec'"
for_window [app_id="^launcher$"] floating enable, border none

@PumbaPe
Copy link
Contributor

PumbaPe commented Sep 28, 2018

I don't understand the steps you're doing. How are you marking the window? You shouldn't need to mark the window in this case anyway.

I was marking it with swaymsg mark whatever and I was trying to do so to have a command that works with any terminal. Because for example with gnome-terminal --name and --class have no effect, only --title changes the name. Whereas with Tilix it is the other way around.

That's not really how it should be done. for_window adds a rule for windows matching the given criteria, and they exist until Sway exits or is reloaded. You're adding a new for_window rule every time you open your launcher.

Yes, you're right. I wasn't aware of that, makes much more sense to define the customization outside of the menu command.

@psnszsn
Copy link
Contributor

psnszsn commented Oct 3, 2018

This is how I'm doing it with termite:

bindsym $mod+r exec termite --name=launcher -e "bash -c 'compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec'"
for_window [app_id="^launcher$"] floating enable, border none

I modified this so it lets you select from the .desktop files at /usr/share/applications and launch them with gtk-launch:

bindsym $mod+n exec termite --name=launcher -e "bash -c 'find /usr/share/applications -name *.desktop | xargs basename -s .desktop -a | fzf | xargs -r swaymsg -t command exec gtk-launch'"

It works for most apps, but some, like dconf-editor, do not launch properly.

@joenye
Copy link

joenye commented Nov 26, 2018

This is how I'm doing it with termite:

bindsym $mod+r exec termite --name=launcher -e "bash -c 'compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec'"
for_window [app_id="^launcher$"] floating enable, border none

I modified this so you can also execute arbitrary commands, like you can with dmenu/rofi:

bindsym $mod+r exec termite --name=launcher -e "bash -c 'compgen -c | sort -u | fzf --no-extended --print-query | tail -n1 | xargs -r swaymsg -t command exec'"
for_window [app_id="^launcher$"] floating enable, border none

If fzf finds a match, this will be executed. Else, what you typed will be executed.

@FlyingWombat
Copy link

FlyingWombat commented Jan 1, 2019

I modified this so you can also execute arbitrary commands, like you can with dmenu/rofi:

bindsym $mod+r exec termite --name=launcher -e "bash -c 'compgen -c | sort -u | fzf --no-extended --print-query | tail -n1 | xargs -r swaymsg -t command exec'"
for_window [app_id="^launcher$"] floating enable, border none

If fzf finds a match, this will be executed. Else, what you typed will be executed.

If anyone is interested, I made a script based on this (still uses fzf).
The difference is that this script keeps a command history sorted by usage.
You can get it in my GitLab repo.

@bojankajfes
Copy link

Bemenu can be used in combination with j4-dmenu-desktop (or maybe even with i3-dmenu-desktop) for getting similar result like with dmenu (-i => ignore case switch is mandatory for bemenu to work like expected) :

set $menu j4-dmenu-desktop --dmenu="bemenu -i" --no-generic --term=kitty

@alexryndin
Copy link

Indeed there is no any focus issues with rofi on latest sway beta with wlroots. It actually doesn't have anything to do with rofi and still reproduces with latest, not beta sway with wlc.

@the-isz
Copy link

the-isz commented Apr 18, 2019

Thanks to all of you for your great examples!

Just in case anyone's interested, here's my take, based partly on the examples in this thread:

I've written a script that launches a terminal in which the fzf-based completion takes place, depending on what mode the script was launched in.

In my sway config, I have the following:

bindsym $mod+r exec --no-startup-id bash -c '~/.config/sway/alacritty_menu commands | xargs -r swaymsg -t command exec'
for_window [app_id="alacritty-menu"] floating enable, resize set width 1000 px height 250 px

I have decided to go that route so that I have the terminal launching and completion in one, reusable place.

Best regards!

@sherter
Copy link

sherter commented Apr 19, 2019

Another solution which takes history into account:

bindsym $mod+x exec termite --name=launcher -e ~/bin/launcher
for_window [app_id="^launcher$"] floating enable, border none
#!/bin/bash

HISTFILE="${XDG_CACHE_HOME:-$HOME/.cache}/launch_history"
HISTSIZE=30

touch "$HISTFILE"
compgen -c | sort --unique | awk '
  { if (ARGIND == 1) valid[$1]=1 } 
  { sum[$1]+=1 }
  END { for (i in sum) { if (valid[i]) print sum[i],i }}' - "$HISTFILE" | \
  sort --numeric-sort --reverse --key=1,1 | awk '{ print $2 }' | \
  fzf --no-extended --print-query --tiebreak=index | tail --lines=1 | \
  xargs -I % sh -c "swaymsg -t command exec % && echo % >> '$HISTFILE'"

echo "$(tail --lines=$HISTSIZE "$HISTFILE")" > "$HISTFILE"

@ghost
Copy link

ghost commented Apr 28, 2019

Thanks @sherter! A few issues I would like to see if you have a solution for... first I really like your idea of using fzf. However, there isn't a shortcut to delete history items like with rofi. Also, if I click off the menu then it doesn't close. I also can't figure out how to get it to work with scripts or arguments. I miss my ssh quick access too. Any thoughts or suggestions for those? I know they most of it can be done with a terminal and fzf. I would also like to integrate something like emoji support too. I was using this before:

https://github.com/Mange/rofi-emoji

I know that is piling a lot on there. I think your idea of using termite though is great, or something like alacritty, which both look great with transparency.

@emersion
Copy link
Member

Suggestion: write a rofi patch to add Wayland support.

@ghost
Copy link

ghost commented Apr 28, 2019

Suggestion: write a rofi patch to add Wayland support.

I'll see what I can do. I would like to contribute more. I am so glad I finally switched, and the nouveau drivers aren't as bad as I thought they'd be.

@mcoffin
Copy link
Contributor

mcoffin commented May 23, 2019

bindsym $mod+r exec --no-startup-id bash -c '~/.config/sway/alacritty_menu commands | xargs -r swaymsg -t command exec'
for_window [app_id="alacritty-menu"] floating enable, resize set width 1000 px height 250 px

Just for those reading that don't want their window in the middle of their screen, and would like it on an edge more similar to dmenu, here's my modification of the for_window line, using jwilm/alacritty as the terminal.

bindsym $mod+d exec alacritty --class 'launcher' --command bash -c 'compgen -c | sort -u | fzf | xargs -r swaymsg -t command exec'
for_window [app_id="^launcher$"] floating enable, border none, resize set width 25 ppt height 100 ppt, move position 0 px 0 px

@blaggacao
Copy link
Contributor

Seen out there: https://hg.sr.ht/~scoopta/wofi

@edrex
Copy link
Contributor

edrex commented Jan 17, 2020

I've been testing out wofi since @blaggacao mentioned it, and can recommend it as as a fast, functional cairogtk3-based dmenu replacement now that wofi/#37 is fixed (lack of cache invalidation clogging dynamic scripts) . I think we can close this as a community meta-issue 😄, thanks ~scoopta! 🚀

@friederbluemle
Copy link

wofi works amazingly well.

Step 1

Install wofi, e.g. on Arch Linux from the AUR using yay:

yay -S wofi

Step 2

Update Sway config:

set $menu dmenu_path | wofi --show drun -i | xargs swaymsg exec --

@pirj
Copy link

pirj commented Sep 1, 2020

https://github.com/Cloudef/bemenu is just as easy:

pacman -S bemenu-wlroots
set $menu bemenu-run | xargs swaymsg exec --

@rileyrg
Copy link

rileyrg commented May 19, 2021

I modified this so you can also execute arbitrary commands, like you can with dmenu/rofi:

bindsym $mod+r exec termite --name=launcher -e "bash -c 'compgen -c | sort -u | fzf --no-extended --print-query | tail -n1 | xargs -r swaymsg -t command exec'"
for_window [app_id="^launcher$"] floating enable, border none

If fzf finds a match, this will be executed. Else, what you typed will be executed.

If anyone is interested, I made a script based on this (still uses fzf).
The difference is that this script keeps a command history sorted by usage.
You can get it in my GitLab repo.

Nice.

@ghost
Copy link

ghost commented Apr 17, 2022

There is now also a dmenu clone for wayland called wmenu

Some things are missing, like dmenu_path - but it works well. I use it daily like this:

set $menu dmenu_path | wmenu -p "Run:" -l 10 | xargs swaymsg exec
bindsym $mod+p exec $menu

Contributing works via email, so you mail your commits with git send-email to the devel mailinglist. See https://git-send-email.io/ how that works.

I like this a lot, it makes drive-by commits much easier, as you do not need to have forks around as in github.

@ackerleytng
Copy link

Thanks everyone who gave tips on configuring sway above! Here's a configuration for foot:

set $menu foot --title launch --app-id fzf-launcher bash -c 'compgen -c | sort -u | fzf | xargs swaymsg exec --'
for_window [app_id="^fzf-launcher$"] floating enable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests