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

contrib: add python layout #394

Merged
merged 3 commits into from
Oct 6, 2021
Merged

Conversation

Leon-Plickat
Copy link
Member

No description provided.

contrib/layout.py Outdated Show resolved Hide resolved
contrib/layout.py Outdated Show resolved Hide resolved
contrib/layout.py Outdated Show resolved Hide resolved
Copy link
Member

@ifreund ifreund left a comment

Choose a reason for hiding this comment

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

This looks pretty neat, could I get a TLDR on how to get pywayland to scan the river-layout protocol so I can test this? Probably would be worth adding that to the comment at the top as well, similar to the build instructions for contrib/layout.c.

@Leon-Plickat
Copy link
Member Author

TBH I have no idea how pywaylands scanner is supposed to work.

I got it to scan the protocol and generate bindings by copying it to /usr/share/wayland-protocols/river-layout-v3/river-layout-v3.xml and running this command once:

sudo python3 -m pywayland.scanner --with-protocols 

@Leon-Plickat
Copy link
Member Author

@ifreund I have found out how to make the scanning work.

mkdir protocols
python -m pywayland.scanner -o protocols -i /usr/share/wayland/wayland.xml ../protocols/river-layout-v3.xml

The scanner finds wayland.xml automatically by default, but when using -i you do not add additional protocol files to scan, you bypass the automatic path finding. So wayland.xml apparently needs to be specified explicitly. Pretty unintuitive, but it works.

Now I only need to figure out how to make python import the local bindings.

@Leon-Plickat
Copy link
Member Author

Leon-Plickat commented Aug 12, 2021

Ok, I give up. I don't think pywayland supports using local bindings. It seems like all bindings have to be part of the actual package, which means the only two options I see are either having a local copy of pywayland with the bindings, or adding the bindings to the global pywayland package.

The command to add the bindings to the global package:

sudo python3 -m pywayland.scanner --with-protocols -i /usr/share/wayland/wayland.xml river-layout-v3.xml

That command probably also works for local packages, sans the sudo, since pywaylands scanner apparently knows where the package lives. This is not documented however (the docs say the default output is ./pywayland/protocols, which is false).

@Leon-Plickat
Copy link
Member Author

I added the instructions for generating the bindings into the layout. They will be automatically printed if importing the river-layout bindings fails.

If we don't find python wayland bindings that are nicer to use, this will not get any better than it is now I am afraid.

contrib/layout.py Outdated Show resolved Hide resolved
@ifreund ifreund mentioned this pull request Sep 5, 2021
@Leon-Plickat
Copy link
Member Author

Are there still any blockers, other than pywayland being unwieldy?

@ifreund
Copy link
Member

ifreund commented Oct 4, 2021

Are there still any blockers, other than pywayland being unwieldy?

Nope, I just need to find time to deal with setting up pywayland to test.

This avoids needing to run pwayland's scanner with root privileges and
install the river-layout bindings to system directories.
Copy link
Member

@ifreund ifreund left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@ifreund ifreund enabled auto-merge (rebase) October 6, 2021 10:15
@ifreund ifreund merged commit 3b24e7f into riverwm:master Oct 6, 2021
@ifreund
Copy link
Member

ifreund commented Oct 6, 2021

Note: I found that one can avoid running the pywayland scanner as root by using a virtual environment, which is a lot cleaner. I added a commit recommending this instead.

For example:

cd contrib
python -m venv fooenv
source ./fooenv/bin/activate
pip install pywayland
python -m pywayland.scanner -i /usr/share/wayland/wayland.xml ../protocol/river-layout-v3.xml
python layout.py

@Leon-Plickat Leon-Plickat deleted the python-layout branch October 6, 2021 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants