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

allow use of global_variables in defwindow #1004

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dragonnn
Copy link
Contributor

Description

Allow the usage of global variables from defwindow like in :monitor

Usage

Main use case is workaround current Wayland/Gdk limitation of picking up monitor the point is currently under (I tried to make it worked but failed). With this PR user can define in eww stuff like that:

(defwindow control_center
  :monitor {active_monitor}
  :stacking "overlay"
  :geometry (geometry
    :anchor "bottom right"
    :width "2px"
    :height "2px"
  )
  :namespace "eww"
  (control_center)
)

(deflisten active_monitor :initial 0 "scripts/get_active_monitor.sh")

with two scripts that are need for hyprland to make it work.

#!/usr/bin/env bash
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

hyprctl monitors -j | jq '.[] | select(.focused) | .id'

socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - |
  stdbuf -o0 awk -F '>>|,'-e '/^focusedmon>>/ {print $2}' |
  stdbuf -o0 awk -F',' '{print $1}' |
  stdbuf -o0 $script_dir/filter_active_monitor.sh

#!/usr/bin/env bash

monitors=($(echo $(hyprctl monitors -j | jq '.[] | "\(.id):\(.name)"') | tr ' ' '\n'))

while read -r line; do
  for monitor in "${monitors[@]}"; do
      monitor=${monitor%\"}
      monitor=${monitor#\"}
      monitor_number="${monitor%%:*}"
      monitor_name="${monitor#*:}"

      if [ "$line" = "$monitor_name" ]; then
        echo "$monitor_number"
        break
      fi
    done
done

Could be done in one script but I didn't find a way to do it yet.
With this way user can have a window that opens on the current active monitor instead of a fixed one.
Even that it is a workaround adding something like "" monitor definition it still can be useful for other stuff in defwindow like for example making the geometry dynamic (for example to always open a menu under the mouse).

Additional Notes

Currently with this PR eww doesn't pick up that the variables is used in defwindow. Hope someone could give me some guidance where to put that. I already found out how the variables scopes are picked up in eww, but no idea yet how to bring that into WindowInitiator::new to register variables used by a window open.
Maybe this should be done not at open but at eww startup so the variable used in defwindow is always updated?

Checklist

  • Add variables used in defwindow to be pick up in scopes to run the right scripts always when a defwindows uses a deflisten/defpool variable
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

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

Successfully merging this pull request may close these issues.

1 participant