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

hide or show a program #2318

Open
Nosirus opened this issue Apr 6, 2024 · 13 comments
Open

hide or show a program #2318

Nosirus opened this issue Apr 6, 2024 · 13 comments
Labels
enhancement external-feature Plugins and features which are intended to not be part of the main wayfire repository

Comments

@Nosirus
Copy link

Nosirus commented Apr 6, 2024

and is it possible to show or hide an application, for example a terminal?

I would like to ideally reproduce hdrop (or tdrop) with foot or alacritty.

@ammen99
Copy link
Member

ammen99 commented Apr 7, 2024

You could minimize or restore an animation, is that what you're looking for?

@Nosirus
Copy link
Author

Nosirus commented Apr 7, 2024

no not entirely, I really like drop-down terminals, on hyprland I was able to use hdrop.
It hides the window, it doesn't minimize it, practical for quickly calling a terminal, letting it run without it remaining displayed

@ammen99
Copy link
Member

ammen99 commented Apr 7, 2024

Ok, I see, you'll have to write a custom plugin for that. It shouldn't be too hard to implement, though.

@ammen99 ammen99 added the external-feature Plugins and features which are intended to not be part of the main wayfire repository label Apr 7, 2024
@Nosirus
Copy link
Author

Nosirus commented Apr 23, 2024

Well, I didn't succeed at the moment.
is there a possibility to start hiding a terminal and with a key to minimize or display?
I would just have to hide the terminal in waybar taskbar.

it would be practical to be able to write the IPC rules more simply for noobs like me 😅

@ammen99
Copy link
Member

ammen99 commented Apr 23, 2024

Well, I didn't succeed at the moment. is there a possibility to start hiding a terminal and with a key to minimize or display? I would just have to hide the terminal in waybar taskbar.

it would be practical to be able to write the IPC rules more simply for noobs like me 😅

Do you use the minimization feature in general?

@Nosirus
Copy link
Author

Nosirus commented Apr 24, 2024

very little, but it is present and works

@ammen99
Copy link
Member

ammen99 commented Apr 24, 2024

I think in general it would be cool to have a proper plugin which does this, in the meantime I hacked together a script to kind-of achieve what you want. The catch: in order to be able to easily recognize the terminal, make sure to use a terminal for the drop down that you don't usually use (in this example I used foot, feel free to customize the script):

#!/usr/bin/python3
import json

import subprocess
import os
import time
from wayfire_socket import *

addr = os.getenv('WAYFIRE_SOCKET')
sock = WayfireSocket(addr)

TERMINAL_APPID = "foot"
TERMINAL_CMD = "foot"

def find_view():
    hidden_view = None
    shown_view = None
    # First look for a view which is minimized and matches
    views = sock.list_views()
    for v in views:
        if v['app-id'] == TERMINAL_APPID and v['minimized']:
            hidden_view = v
        elif v['app-id'] == TERMINAL_APPID:
            shown_view = v

    return hidden_view, shown_view

def show_view(hidden_view):
    print("Showing view ", hidden_view)
    # We have our view, just bring it to the front and center it
    msg = get_msg_template('wm-actions/set-minimized')
    msg['data']['view_id'] = hidden_view['id']
    msg['data']['state'] = False
    print(sock.send_json(msg))

    msg = get_msg_template('window-rules/get-focused-output')
    output = sock.send_json(msg)['info']
    print(output)

    msg = get_msg_template('window-rules/configure-view')
    msg['data']['id'] = hidden_view['id']
    msg['data']['output_id'] = output['id']

    # Center on current output
    msg['data']['geometry'] = {}
    msg['data']['geometry']['x'] = output['workarea']['x'] + output['workarea']['width'] // 2 - hidden_view['geometry']['width'] // 2
    msg['data']['geometry']['y'] = output['workarea']['y'] + output['workarea']['height'] // 2 - hidden_view['geometry']['height'] // 2
    msg['data']['geometry']['width'] = hidden_view['geometry']['width']
    msg['data']['geometry']['height'] = hidden_view['geometry']['height']
    print("want to configure with ", json.dumps(msg,indent=4))
    print(output['workarea'])
    print(sock.send_json(msg))

def hide_view(shown_view):
    print("Hiding view ", shown_view)
    # Hide existing view
    # We have our view, just bring it to the front and center it
    msg = get_msg_template('wm-actions/set-minimized')
    msg['data']['view_id'] = shown_view['id']
    msg['data']['state'] = True
    sock.send_json(msg)

hidden_view, shown_view = find_view()
if not shown_view and not hidden_view:
    print("Starting a new view")
    subprocess.Popen(TERMINAL_CMD, start_new_session=True)
    time.sleep(1)
    hidden_view, shown_view = find_view()
    if shown_view:
        show_view(shown_view)
    else:
        print("Failed to start new terminal!")
elif shown_view:
    hide_view(shown_view)
else:
    show_view(hidden_view)

You also need the ipc-scripts/wayfire_socket.py file, put it in the same directory as this script, and you can bind it to a keybinding with the command plugin (make sure to enable wm-actions, ipc-rules and ipc for this to work though!)

The script does the following:

  • It searches for a minimized view matching the app-id of the terminal. If it finds it, then it restores the terminal on the current output and centers it on the screen.
  • If a terminal with matching app-id is open but not minimized, it is minimized.
  • If neither, a new terminal is opened and centered.

@Nosirus
Copy link
Author

Nosirus commented Apr 24, 2024

oh this looks exactly like what I was looking for and my terminal happens to be foot

I will try this as soon as possible, thank you very much 🤩

@Nosirus
Copy link
Author

Nosirus commented Apr 24, 2024

already a little feedback, I couldn't wait to try.
That's exactly what I wanted ! I hide icon foot from waybar.

On the other hand, it only opens on the first workspace, maybe add a sticky option?
But yes, a plugin would do great things !

@marcusbritanicus
Copy link
Contributor

marcusbritanicus commented Apr 24, 2024

A little bit of shameless self-promotion here. While you develop the plugin, may be you can use the app I have built: DesQ Dropdown + DesQ Term.

You can add a command+binding to wayfire config:

binding_dropdown = KEY_F12
command_dropdown = /usr/bin/desq-dd

PS: If you're interested, I can also combine the two and make a single app for you without many extra dependencies

@Nosirus
Copy link
Author

Nosirus commented Apr 24, 2024

I just had to add to fix the problem and it's totally functional

msg = get_msg_template('wm-actions/set-sticky')
msg['data']['view_id'] = hidden_view['id']
msg['data']['state'] = True
print(sock.send_json(msg))

I don't know if wlroots allows it, but for future plugins add the possibility of not displaying an icon, would allow others not to touch the waybar or other config and maybe also being able to deactivate the window decoration could be useful

@ammen99
Copy link
Member

ammen99 commented Apr 25, 2024

I don't know if wlroots allows it, but for future plugins add the possibility of not displaying an icon, would allow others not to touch the waybar or other config and maybe also being able to deactivate the window decoration could be useful

Yeah if done with a plugin it will make it sticky by default and also won't show up in the taskbar, that's certain.

About removing decoration, I would say that decorations are kind-of orthogonal issue, but the built-in decoration plugin has an option to disable decorations for a particular windows with a criteria, maybe take a look at that.

@mark-herbert42
Copy link

I use tilda-wayland (fork of tilda) a s a dropdown terminal and it manages to do it well, without any effort from wayfire.

https://github.com/shih-liang/tilda-wayland

To make it look nice - adding config lines added in wayfire.ini for tilda only

[animate]
zoom_enabled_for = ( app_id contains "tilda" )

[firedecor] (hopefully same can be done with any other decorator as well)
ignore_views = ( app_id contains "tilda" & type is "toplevel" )

[window-rules] (adjust to the position you want)
rule_4 = on created if ( app_id contains "tilda" & type is "toplevel" ) then move 100 36

Also for toggle hide-unhide map key combination in [command ] section to the following command

dbus-send --session --type=method_call --dest=com.github.lanoxx.tilda.Actions0 /com/github/lanoxx/tilda/Actions0 com.github.lanoxx.tilda.Actions.Toggle

This fork is behind the main tilda tree - but it has Xorg stripped out and native wayland programmed in - so works very nice with all dropdown terminal features, tabs, nice customization options. And it is normal C program, not he python wrapper around something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement external-feature Plugins and features which are intended to not be part of the main wayfire repository
Projects
None yet
Development

No branches or pull requests

4 participants