Skip to content

new lib: niri #70

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

new lib: niri #70

wants to merge 19 commits into from

Conversation

sameoldlab
Copy link

@sameoldlab sameoldlab commented Nov 10, 2024

Adds support for niri's ipc (closes #8). I took the library started by @spazzylemons, included event values in the signals, and added active and focused window/workspace tracking as properties. This covers all current messages in the event-stream but still planning to add:

  • output tracking (would need help testing this, as I only have one screen)
  • get windows by workspace
  • workspaces by output
  • ability to send actions to niri
  • add objects as properties instead of just their ids (Done! Thanks to @viceav for most of the changes)

@zobernost
Copy link

happy to help test output tracking once you get there; have niri + multiple monitors.

@phaer
Copy link

phaer commented Jan 17, 2025

@sameoldlab Great work, thank you! Are you planning to continue working on this? I think a read-only view of windows (and maybe workspaces) would already be very useful to create some bars, even if actions and state management were still missing IMO.

@sameoldlab
Copy link
Author

@phaer thanks, yes. I could mark what I have now as ready for review if that would be useful to people. I avoided it earlier because I wasn't sure if the variable names would change, but I think future updates should be possible now without any breaking changes

@sameoldlab sameoldlab marked this pull request as ready for review January 19, 2025 17:32
@sameoldlab
Copy link
Author

Posting object issues here in case anyone with better Vala knowledge has an idea. This is how to track the current title currently:

const Current = () => {
	const niri = Niri.get_default()
	const current_title: Variable<string> = Variable(niri.get_window(niri.focused_window_id)?.title ?? '')
	niri.connect('window-focus-changed', (_, w_id /* number */) => current_title
		.set(niri.get_window(w_id)?.title ?? ''))
	return new Widget.Label({ label: current_title().as(t => t.slice(0, 150)) })
}

Ideally it could be something similar to:

const Current = () => {
	const niri = Niri.get_default()
	return new Widget.Label({ label: niri.focused_window.title() })
}

While testing I still needed a variable and signal to track changed on niri.focused_window and things would break if it was ever null. The best I could figure out was a "0 object" Window {title: "", id: -1, app_id: "", workspace_id: -1, ...}. That would never be null and could change to always have the same value as the actual focused, but it would not reference the same object as niri.get_window(niri.focused_window_id).

I don't think it'd be worth the extra code if using it still needed a variable and signal, but would like to know if there's anything that might work better.

@bandithedoge
Copy link

How do you plan on tackling multi-monitor setups in GTK3? Niri identifies monitors by connector name (eg. DP-1) but gdk_monitor_get_connector() is only available in GDK4.

@sameoldlab
Copy link
Author

@bandithedoge need to look at this more. The Output object has additional info which is available in gtk3 (make, model, logical.x, logical.y). They aren't being 'saved' yet because it needs additional messages than just reading the event stream.

The full object would make comparisons possible. For most people with just logical.x but not predictably enough to add an extra HashMap to the library.

@witttccchhher
Copy link

We really need this! @Aylur, when do you plan to merge it?

@viceav
Copy link

viceav commented Apr 10, 2025

Hi, @sameoldlab i've been testing this out and im getting a problem where if i call AstalNiri.get_default().workspaces i get null instead of Workspace[].

I dont' really know what it could be to be honest, since calling AstalNiri.get_default().get_workspaces() works perfectly fine.

Any help is appreciated :)

@sameoldlab
Copy link
Author

@viceav I think that's (somewhat) normal for using the libraries in javascript. .get_thing gives you a Thing js object while .thing has a raw GObject<Thing> inside.

null does seem a bit odd. I could take a look but generally would say you should be using the .get_ version instead.

@sameoldlab sameoldlab force-pushed the feat/niri branch 2 times, most recently from c2c12ed to 3887b18 Compare April 11, 2025 18:57
@viceav
Copy link

viceav commented Apr 11, 2025

@sameoldlab found this Error: Can't convert non-null pointer to JS value ,
So probably can be fixed by adding this in the workaround

await suppress(import("gi://AstalNiri"), ({ Niri }) => {
  patch(Niri.prototype, "workspaces")
  patch(Niri.prototype, "windows")
  patch(Niri.prototype, "outputs")
})

Edit: It works :)

@sameoldlab
Copy link
Author

Thanks! Do you want to make a PR @viceav? I'll just copy it in a few hours if not

@viceav
Copy link

viceav commented Apr 11, 2025

@sameoldlab Thanks! I'm gonna check if there's any other property that should be added and i'll make the PR

viceav and others added 4 commits April 14, 2025 18:53
…focused_window handle all window focus logic
 - For the `on_windows_changed` function ensure `focused_window` gets updated
 - For the `update_focused_window` handle when the `new_focused` window is `null`
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.

niri ipc support
8 participants