Fixes GTK4 Layer Shell and Ollama integration issues

Addresses multiple issues related to GTK4 Layer Shell initialization and Ollama integration.

- Reorders initialization to ensure the layer shell is set up before window properties.
- Adds error detection for layer shell initialization failures.
- Implements a focus event handler to prevent focus-out warnings.
- Introduces a launcher script to activate the virtual environment, force native Wayland, and preload the GTK4 Layer Shell library.
- Warns users of incorrect GDK_BACKEND settings.
- Updates the Ollama client to handle responses from both older and newer versions of the Ollama SDK.

These changes improve the application's stability, compatibility, and functionality on Wayland systems.
This commit is contained in:
Melvin Ragusa
2025-10-25 21:23:32 +02:00
parent da57c43e69
commit 1a80358ffc
10 changed files with 638 additions and 8 deletions

View File

@@ -25,6 +25,10 @@ class SidebarWindow(Gtk.ApplicationWindow):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
# CRITICAL: Layer shell must be initialized BEFORE any window properties
self._setup_layer_shell()
self.set_default_size(360, 720)
self.set_title("Niri AI Sidebar")
self.set_hide_on_close(False)
@@ -33,7 +37,6 @@ class SidebarWindow(Gtk.ApplicationWindow):
self._ollama_client = OllamaClient()
self._current_model = self._ollama_client.default_model
self._setup_layer_shell()
self._build_ui()
self._populate_initial_messages()
@@ -44,6 +47,11 @@ class SidebarWindow(Gtk.ApplicationWindow):
return
Gtk4LayerShell.init_for_window(self)
# Verify initialization succeeded before configuring layer shell properties
if not Gtk4LayerShell.is_layer_window(self):
return
Gtk4LayerShell.set_namespace(self, "niri-ai-sidebar")
Gtk4LayerShell.set_layer(self, Gtk4LayerShell.Layer.TOP)
Gtk4LayerShell.set_anchor(self, Gtk4LayerShell.Edge.LEFT, True)
@@ -99,6 +107,12 @@ class SidebarWindow(Gtk.ApplicationWindow):
self._entry.set_placeholder_text("Ask a question…")
self._entry.connect("activate", self._on_submit)
# Add focus event controller to properly handle focus-out events
# The handler must return False to propagate the event to GTK's default handler
focus_controller = Gtk.EventControllerFocus()
focus_controller.connect("leave", lambda c: False)
self._entry.add_controller(focus_controller)
self._send_button = Gtk.Button(label="Send")
self._send_button.connect("clicked", self._on_submit)