feat: spawn layer shells on correct output

This commit is contained in:
2026-05-04 19:50:06 +02:00
parent cb3b7bf392
commit e7a1a2c0ee
2 changed files with 30 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ from fabric.widgets.label import Label
from fabric.widgets.wayland import WaylandWindow as Window
from gi.repository import Gdk, Gtk
from sims.services.fenster import focused_output_index
class LauncherProvider(Protocol):
def items(self) -> list[Any]: ...
@@ -118,6 +120,7 @@ class FuzzyMenu(Window):
self._selected_index = 0
self._scroll_offset = 0
self._refresh_viewport("")
self.monitor = focused_output_index()
super().show()
self.search_entry.grab_focus()

View File

@@ -5,7 +5,7 @@ Provides a singleton I3 connection configured for Fenster's SWAYSOCK.
"""
import os
from sims.services.i3 import I3
from sims.services.i3 import I3, I3MessageType
_connection: I3 | None = None
@@ -27,3 +27,29 @@ def get_i3_connection() -> I3:
I3.SOCKET_PATH = fallback
_connection = I3()
return _connection
def focused_output_index() -> int:
"""Index of the currently focused output in active GET_OUTPUTS order.
Matches the indexing main.spawn_bars uses for `monitor=` so layer-shell
windows opened with the same index land on the focused output. Returns 0
on any IPC failure or if the focused output cannot be located.
"""
ws_reply = I3.send_command("", I3MessageType.GET_WORKSPACES)
if not (ws_reply.is_ok and isinstance(ws_reply.reply, list)):
return 0
focused_output = next(
(ws.get("output") for ws in ws_reply.reply if ws.get("focused")),
None,
)
if not focused_output:
return 0
out_reply = I3.send_command("", I3MessageType.GET_OUTPUTS)
if not (out_reply.is_ok and isinstance(out_reply.reply, list)):
return 0
active = [o for o in out_reply.reply if o.get("active")]
for i, o in enumerate(active):
if o.get("name") == focused_output:
return i
return 0