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
gnidorah opened this issue Sep 23, 2017 · 32 comments

Comments

Projects
None yet
@gnidorah
Copy link

commented Sep 23, 2017

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

@bearcatsandor

This comment has been minimized.

Copy link

commented Sep 23, 2017

@ddevault

This comment has been minimized.

Copy link
Member

commented Sep 23, 2017

There's bemenu but it has some issues.

@gnidorah

This comment has been minimized.

Copy link
Author

commented Sep 23, 2017

Thanks. We should wait then.

@Zer0-One

This comment has been minimized.

Copy link
Contributor

commented Sep 23, 2017

@ddevault

This comment has been minimized.

Copy link
Member

commented Sep 23, 2017

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

@Zer0-One

This comment has been minimized.

Copy link
Contributor

commented Sep 23, 2017

oh, well shoot

@gnidorah

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

commented Sep 24, 2017

i3-dmenu-desktop works on sway.

@gnidorah

This comment has been minimized.

Copy link
Author

commented Sep 24, 2017

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

@jbg

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Oct 5, 2017

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

@ddevault ddevault closed this Oct 7, 2017

@gnidorah gnidorah referenced this issue Dec 26, 2017

Merged

rootston module: better defaults #33085

7 of 12 tasks complete
@alexryndin

This comment has been minimized.

Copy link

commented Jun 9, 2018

still have focus issue with rofi 1.5.1 and sway 0.15

@alexryndin

This comment has been minimized.

Copy link

commented Jun 9, 2018

@jbg could you explain your solution a bit?

@jbg

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

commented Sep 5, 2018

Yeah I think rofi works fine on sway master.

@KubqoA

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Mar 12, 2019

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

This comment has been minimized.

Copy link

commented Mar 12, 2019

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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"
@braderhart

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

Suggestion: write a rofi patch to add Wayland support.

@braderhart

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.