elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.11k stars 377 forks source link

[FEATURE] Dismiss window on key press or click outside #472

Open hucancode opened 2 years ago

hucancode commented 2 years ago

Description of the requested feature

Hi elkowar, thanks for the tool, it's amazing. I am on my way to replace polybar and rofi with eww and I am pretty succesful on polybar. On rofi I am able to bind ESC key to dismiss drun window, plus click outside of the window also close it. Press the triggering key again also does the job. On eww, I'm binding my key (super + x) to

eww open --toggle powermenu

and I am able to open and close power menu with super + x.

Proposed configuration syntax

(defwindow 
  :onkeypressed (keyevent :key "esc" :command "eww close powermenu") 
  :onlostfocus "eww close powermenu")

Additional context

No response

elkowar commented 2 years ago

I'm not a bit fan of adding keyboard input stuff into eww -- I'd think that it would make more sense to have a separate tool to just create temporary hotkey bindings, I'll probably start working on something like that soon-ish. about clicking outside of the window to close it: Not sure how trivial that is to do directly -- what some people have done is just create a separate, transparent widget in the background that fills the entire screen and closes the widgets when clicked -- that works pretty well.

Vermoot commented 2 years ago

Here's what I'm doing to have the "close on click outside" behaviour. It's exactly what Elk is describing.

(defwidget closer [window]
  (eventbox :onclick "eww close ${window} && eww close ${window}-closer"))

(defwindow menu-closer
  :monitor 0
  :geometry (geometry :width "100%" :height "100%")
  :stacking "fg"
  :focusable false
  (closer :window "menu"))

This accompanies my "menu" window, but I've made it modular enough that it could be used with other windows as well, given that the closer window is named XXX-closer.

Abous your configuration syntax, while it might work with a :onlostfocus property, keep in mind that not all windows you'd want to use this with are focusable. My global menu, for example, doesn't grab focus, and reacts to which window currently has focus.

hucancode commented 2 years ago

Yeah I think my problem with clicking outside are solved. About keyboard input, I'm using openbox, it doesn't support adding new keyboard shortcut on the fly. For that I would need to create a new configuration set and reload when an eww window open, load the default config back when window close. I'm lazy I wouldn't do that lol. Using sxhkd reduce the pain a little bit, but still, switching between 2, or 3, 4 configuration sets is not so elegant I think.

elkowar commented 2 years ago

yea, that's why I'm saying, there should be some tool that would be explicitly made for such temporary keybinds, so you could just

tmpbindkey --once esc "eww close dashboard" &

which would just bind that keyboard shortcut for as long as that process is running, until it's hit once

elkowar commented 2 years ago

that's what I'll probably be working on soon

AlecsFerra commented 2 years ago

What about focussing the next clickable element with tab?

AlecsFerra commented 2 years ago

What about focussing the next clickable element with tab?

I've implemented this

imgurbot12 commented 2 years ago

I just designed my first widget with eww as an "application launcher". Having the option to keyboard-only navigate menus through some sort of temporary keybinding system would be awesome.

Widget Gif

@AlecsFerra, I don't see a PR for the changes you've made on tab navigation. Any chance you could make one we can get those into the latest release?

AlecsFerra commented 2 years ago

@AlecsFerra, I don't see a PR for the changes you've made on tab navigation. Any chance you could make one we can get those into the latest release?

Right now I don't have time, but you can try my fork at https://github.com/AlecsFerra/eww