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

Initial try on functions for sway/wayland #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zauster
Copy link

@zauster zauster commented Jun 26, 2024

Hey,

I have a basic implementation of the needed functions for sway/wayland that mostly works. ydotoold has to run to be able to use this code. It mainly uses the commands proposed by msin32 here: #50 (comment)

What does not work:

  • mark a region, call (emacs-everywhere), modify that text and paste it back: nothing is pasted back into the input field
  • repeatedly calling (emacs-everywhere) in the same input field does not always paste the text

@zauster zauster mentioned this pull request Jun 26, 2024
@tecosaur
Copy link
Owner

tecosaur commented Jul 9, 2024

This looks like something I'll be happy to merge, thanks @zauster! At a glance, three comments come to mind:

  • Since availability of particular wayland do-style tools is spotty across distros/repositories (for now at least), I think it would be good to try to support ydotool just prefer dotool, as opposed to switching them out.
  • I don't like the shell call swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true)', can't we process the json ourselves without too much difficulty?
  • There seem to be some unrelated whitespace changes

@zauster
Copy link
Author

zauster commented Jul 9, 2024

Hey,
I adapted the PR according to your points 1 and 3.

I agree that it would be nicer to do the json parsing in elisp. But my
elisp is still quite rudimentary, so it might take a while until I
have something like that ready.

@tecosaur
Copy link
Owner

tecosaur commented Jul 9, 2024

I don't have dotool conveniently packaged, could you share some example JSON output?

@zauster
Copy link
Author

zauster commented Jul 9, 2024

Sure, here you go:
swaymsg_tree.json

@lkirkwood
Copy link

Writing this using the PR - works beautifully! It does require $XDG_CURRENT_DESKTOP to be set which Sway does not do on its own.

(let* ((json-string (emacs-everywhere--call "sh" "-c" "swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true)'"))
(json-object (json-read-from-string json-string))
(window-id (number-to-string (cdr (assoc 'id json-object))))
(app-name (cdr (assoc 'app_id json-object)))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using this branch I noticed that not all applications have an app_id on my system, leading to a Wrong type argument: stringp, nil in *Messages*.

I think the ones running with Xwayland do not have one (Slack in my case). They have window_properties['class'] set though, so I could get them to work with this change:

Suggested change
(app-name (cdr (assoc 'app_id json-object)))
(app-name (cdr (assoc 'app_id json-object)))
(app-name (if app-name app-name (cdr (assoc 'class (cdr (assoc 'window_properties json-object))))))

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.

5 participants