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

Question: implementing custom protocol on the server side. #97

Open
Shinyzenith opened this issue Jul 1, 2022 · 3 comments
Open

Question: implementing custom protocol on the server side. #97

Shinyzenith opened this issue Jul 1, 2022 · 3 comments
Labels
question Q+A request

Comments

@Shinyzenith
Copy link
Contributor

I was trying to bind a protocol I am developing but I've never done this in python so all of this is pretty much a guess.

import logging
from typing import Any

# TODO: Figure out why this breaks mypy.
from pywayland.protocol.next_control_v1 import NextControlV1  # ignore: type
from pywayland.protocol_core.globals import Global
from pywayland.protocol_core.resource import Resource
from pywayland.server import Display
from pywayland.server.client import Client

log = logging.getLogger("Next: Control")

class Control(Global):
    def __init__(self, display: Display) -> None:
        self.interface = NextControlV1

        self._callback_info = {"interface": self.interface, "bind_func": self.bind}
        super().__init__(display, 1)

        self.bind_func(self.bind)
        log.info("Created next_control_v1 global")

    def bind(self, client: Client, data: Any = None, version: int=0, id: int=1) -> None:
        NextControlV1.resource_class(client)

    def destroy(self) -> None:
        super().destroy()

this is the gist of what I came up with but the bind function doesn't seem to return a client which tells me I'm implementing the bind func incorrectly, @m-col. Is there any example I can maybe look at?

@m-col
Copy link
Collaborator

m-col commented Jul 1, 2022

Sorry, I don't know, I'm not aware of any examples with pywlroots and I've never done anything with globals or custom protocols so can't help here :/

@flacjacket
Copy link
Owner

Hmm, interesting. Is the protocol defined in xml or are you doing it purely in Python? If it were, you could use the pywayland scanner to generate the protocol. I'm honestly not sure what it'd mean to define one Python alone, a lot of the functionality was setup to be built up from xml. There is a reasonable amount of things that are done in some of the automagic decorators and cffi cdata generation that might need to be setup manually here.

@Shinyzenith
Copy link
Contributor Author

Hmm, interesting. Is the protocol defined in xml or are you doing it purely in Python? If it were, you could use the pywayland scanner to generate the protocol. I'm honestly not sure what it'd mean to define one Python alone, a lot of the functionality was setup to be built up from xml. There is a reasonable amount of things that are done in some of the automagic decorators and cffi cdata generation that might need to be setup manually here.

It's this protocol https://github.com/Shinyzenith/NextWM/blob/master/protocols/next-control-v1.xml
Hence the following import: from pywayland.protocol.next_control_v1 import NextControlV1 # ignore: type

@flacjacket flacjacket added the question Q+A request label Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Q+A request
Projects
None yet
Development

No branches or pull requests

3 participants