-
Notifications
You must be signed in to change notification settings - Fork 27
feat!(NiriService): move to GObject-based objects #181
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
Conversation
Hmmm, as I see it, |
Good idea, I think it would make sense to generalise it. |
|
Thanks 👍 I've pushed a commit that implements this for NiriService |
I guess you forgot to mention the new classes in docs. .. autoclass:: ignis.services.niri.NiriKeyboardLayouts
:members:
.. autoclass:: ignis.services.niri.NiriOutput
:members:
.. autoclass:: ignis.services.niri.NiriWindow
:members:
.. autoclass:: ignis.services.niri.NiriWorkspace
:members: |
Thanks, added now. |
Any idea why the mypy check keeps failing? I can't see anything wrong here.
|
It happens because
|
…_output`, no need to separately sync output data
I guess this is ready to be reviewed. Of course it's still possible to add more features, in particular I considered adding a |
Co-authored-by: Link <127321188+linkfrg@users.noreply.github.com>
Co-authored-by: Link <127321188+linkfrg@users.noreply.github.com>
Co-authored-by: Link <127321188+linkfrg@users.noreply.github.com>
fix: use type instead of instances for `obj_type` type hint in `__update_niri_obj`
I think there is some issue caused by relying on event stream during initialization. from ignis.services.niri import NiriService
niri = NiriService.get_default()
print(niri.keyboard_layouts.current_name) The example bar works great, because other services/widgets/etc are initialized before niri objects are needed, therefore |
Right, good catch. It looks like KeyboardLayouts is actually always the last event to be reported during initialization of the Niri event stream. What about adding something like this after while self._keyboard_layouts.current_idx == -1:
time.sleep(0.01) |
Looks kinda hacky with that Hmm, if |
I agree, it was more intended as a starting point for a discussion :)
That sounds much better. I'll see what I can come up with, in a way that will minimize code duplication |
Hmm, looks good for me. @regenman is this ready to be merged? |
Great. It's working well on my side, and I don't have more to add at the moment, so I'd say go ahead and merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your work!
Along the lines of #171, this is a refactor introducing GObjects for the Niri Service.
New classes:
NiriKeyboardLayouts
NiriOutput
NiriWindow
NiriWorkspace
In contrast to #171, I've strived to more comprehensively use the data of events received in the IPC event stream to update the GObjects, instead of triggering an additional IPC request to synchronize the state, thus reducing overhead. This is possible since Niri's IPC makes the promise to be verbose about it's state.
Some parts of the logic are inspired by the Niri Waybar module.
A few notes:
NiriService.kb_layout
is removed,insteadNiriService.keyboard_layouts
exposes a list of configured layouts (NiriService.keyboard_layouts.names
) and the id of the currently active layout (NiriService.keyboard_layouts.current_idx
)use
NiriService.keyboard_layouts.current_name
instead.NiriService.active_workspaces
has been dropped, to avoid introducing a separate data structure (list) that needs to be kept up to date. Active workspaces can still be extracted fromNiriService.workspaces
(eachNiriWorkspace
object exposes theis_active
property). I'm open for discussion on this point, and would appreciate any feedback, it does potentially add a burden of complexity for the user.NiriService.send_command
now performs json serialization of thecmd
argument and adds a trailing newline ("\n") to the resulting string, thus eliminating the need to pre-process any argument passed to this method.The PR is in a working state already, I've labeled it WIP since it's a big refactor and minor changes might still be needed.