9 Commits

5 changed files with 126 additions and 11 deletions
@@ -1,17 +1,17 @@
# Implementation Plan: Custom Shader and Window Frame Support # Implementation Plan: Custom Shader and Window Frame Support
## Phase 1: Investigation & Architecture Prototyping ## Phase 1: Investigation & Architecture Prototyping [checkpoint: 815ee55]
- [ ] Task: Investigate `imgui-bundle` and Dear PyGui capabilities for injecting raw custom shaders (OpenGL/D3D11) vs extending ImDrawList batching. - [x] Task: Investigate imgui-bundle and Dear PyGui capabilities for injecting raw custom shaders (OpenGL/D3D11) vs extending ImDrawList batching. [5f4da36]
- [ ] Task: Investigate Python ecosystem capabilities for overloading OS window frames (e.g., `pywin32` for DWM vs ImGui borderless mode). - [x] Task: Investigate Python ecosystem capabilities for overloading OS window frames (e.g., `pywin32` for DWM vs ImGui borderless mode). [5f4da36]
- [ ] Task: Draft architectural design document (`docs/guide_shaders_and_window.md`) detailing the chosen shader injection method and window frame overloading strategy. - [x] Task: Draft architectural design document (`docs/guide_shaders_and_window.md`) detailing the chosen shader injection method and window frame overloading strategy. [5f4da36]
- [ ] Task: Conductor - User Manual Verification 'Phase 1: Investigation & Architecture Prototyping' (Protocol in workflow.md) - [x] Task: Conductor - User Manual Verification 'Phase 1: Investigation & Architecture Prototyping' (Protocol in workflow.md) [815ee55]
## Phase 2: Custom OS Window Frame Implementation ## Phase 2: Custom OS Window Frame Implementation [checkpoint: b9ca69f]
- [ ] Task: Write Tests: Verify the application window launches with the custom frame/borderless mode active. - [x] Task: Write Tests: Verify the application window launches with the custom frame/borderless mode active. [02fca1f]
- [ ] Task: Implement: Integrate custom window framing logic into the main GUI loop (`src/gui_2.py` / Dear PyGui setup). - [x] Task: Implement: Integrate custom window framing logic into the main GUI loop (`src/gui_2.py` / Dear PyGui setup). [59d7368]
- [ ] Task: Write Tests: Verify standard window controls (minimize, maximize, close, drag) function correctly with the new frame. - [x] Task: Write Tests: Verify standard window controls (minimize, maximize, close, drag) function correctly with the new frame. [59d7368]
- [ ] Task: Implement: Add custom title bar and window controls matching the application's theme. - [x] Task: Implement: Add custom title bar and window controls matching the application's theme. [59d7368]
- [ ] Task: Conductor - User Manual Verification 'Phase 2: Custom OS Window Frame Implementation' (Protocol in workflow.md) - [x] Task: Conductor - User Manual Verification 'Phase 2: Custom OS Window Frame Implementation' (Protocol in workflow.md) [b9ca69f]
## Phase 3: Core Shader Pipeline Integration ## Phase 3: Core Shader Pipeline Integration
- [ ] Task: Write Tests: Verify the shader manager class initializes without errors and can load a basic shader program. - [ ] Task: Write Tests: Verify the shader manager class initializes without errors and can load a basic shader program.
+33
View File
@@ -0,0 +1,33 @@
# Custom Shaders and Window Frame Architecture
## 1. Shader Injection Strategy
### Evaluation
* **Dear PyGui (Legacy):** Does not natively support raw GLSL/HLSL shader injection into the UI layer. It relies heavily on fixed-function vertex/fragment shaders compiled into the C++ core. Faux-shaders via DrawList are the only viable path without modifying the DPG source.
* **imgui-bundle (Current):** `imgui-bundle` utilizes `hello_imgui` as its application runner, which provides robust lifecycle callbacks (e.g., `callbacks.custom_background`, `callbacks.post_init`). Because `hello_imgui` exposes the underlying OpenGL context, we can use `PyOpenGL` alongside it to execute raw GLSL shaders.
### Chosen Approach: Hybrid Faux-Shader & PyOpenGL FBO
Given the Python environment, we will adopt a hybrid approach:
1. **Faux-Shaders (ImDrawList Batching):** Continue using `imgui.ImDrawList` primitives for simple effects like soft shadows, glows, and basic gradients (as seen in `src/shaders.py`). This is highly performant for UI elements and requires no external dependencies.
2. **True GPU Shaders (PyOpenGL + FBO):** For complex post-processing (CRT curvature, bloom, dynamic noise backgrounds), we will integrate `PyOpenGL`.
* We will compile GLSL shaders during `post_init`.
* We will render the effect into a Framebuffer Object (FBO).
* We will display the resulting texture ID using `imgui.image()` or inject it into the `custom_background` callback.
*Note: This approach introduces `PyOpenGL` as a dependency, which is standard for advanced Python graphics.*
## 2. Custom Window Frame Strategy
### Evaluation
* **Native DWM Overloading (PyWin32):** It is possible to use `pywin32` to subclass the application window, intercept `WM_NCHITTEST`, and return `HTCAPTION` for a custom ImGui-drawn title bar region. This preserves Windows snap layouts and native drop shadows. However, it is strictly Windows-only and can conflict with GLFW/SDL2 event loops used by `hello_imgui`.
* **Borderless Window Mode (ImGui/GLFW):** `hello_imgui` allows configuring the main window as borderless/undecorated (`runner_params.app_window_params.borderless = True`). We must then manually draw the title bar, minimize/maximize/close buttons, and handle window dragging by updating the OS window position based on ImGui mouse drag deltas.
### Chosen Approach: Pure ImGui Borderless Implementation
To ensure cross-platform compatibility and avoid brittle Win32 hook collisions with `hello_imgui`, we will use the **Borderless Window Mode** approach.
1. **Initialization:** Configure `hello_imgui.RunnerParams` to disable OS window decorations.
2. **Title Bar Rendering:** Dedicate the top ~30 pixels of the ImGui workspace to a custom title bar that matches the current theme (e.g., NERV or standard).
3. **Window Controls:** Implement custom ImGui buttons for `_`, `[]`, and `X`, which will call native window management functions exposed by `hello_imgui` or `glfw`.
4. **Drag Handling:** Detect `imgui.is_mouse_dragging()` on the title bar region and dynamically adjust the application window position.
## 3. Integration with Event Metrics
Both the shader uniforms (time, resolution) and window control events will be hooked into the existing `dag_engine` and `events` systems to ensure minimal performance overhead and centralized configuration via `config.toml`.
+36
View File
@@ -29,6 +29,8 @@ from src import mcp_client
from src import markdown_helper from src import markdown_helper
from src import bg_shader from src import bg_shader
import re import re
import win32gui
import win32con
from pydantic import BaseModel from pydantic import BaseModel
from imgui_bundle import imgui, hello_imgui, immapp, imgui_node_editor as ed from imgui_bundle import imgui, hello_imgui, immapp, imgui_node_editor as ed
@@ -364,7 +366,40 @@ class App:
self.ai_status = f"error: {e}" self.ai_status = f"error: {e}"
imgui.end_menu() imgui.end_menu()
def _render_custom_title_bar(self) -> None:
hwnd = imgui.get_main_viewport().platform_handle
if not hwnd: return
bar_height = 30
imgui.set_next_window_pos((0, 0))
imgui.set_next_window_size((imgui.get_io().display_size.x, bar_height))
flags = (imgui.WindowFlags_.no_title_bar | imgui.WindowFlags_.no_resize |
imgui.WindowFlags_.no_move | imgui.WindowFlags_.no_scrollbar |
imgui.WindowFlags_.no_saved_settings | imgui.WindowFlags_.no_bring_to_front_on_focus)
imgui.push_style_var(imgui.StyleVar_.window_rounding, 0)
imgui.push_style_var(imgui.StyleVar_.window_border_size, 0)
imgui.push_style_var(imgui.StyleVar_.window_padding, (10, 5))
if imgui.begin("##custom_title_bar", None, flags):
imgui.text("manual slop")
if imgui.is_window_hovered() and imgui.is_mouse_dragging(0):
win32gui.ReleaseCapture()
win32gui.SendMessage(hwnd, win32con.WM_NCLBUTTONDOWN, win32con.HTCAPTION, 0)
btn_w = 40
spacing = imgui.get_style().item_spacing.x
right_x = imgui.get_window_width() - (btn_w * 3 + spacing * 2 + 10)
imgui.same_line(right_x)
if imgui.button("_", (btn_w, 20)):
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
imgui.same_line()
if imgui.button("[]", (btn_w, 20)):
win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
imgui.same_line()
if imgui.button("X", (btn_w, 20)):
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
imgui.end()
imgui.pop_style_var(3)
def _gui_func(self) -> None: def _gui_func(self) -> None:
self._render_custom_title_bar()
pushed_prior_tint = False pushed_prior_tint = False
# Render background shader # Render background shader
bg = bg_shader.get_bg() bg = bg_shader.get_bg()
@@ -3928,6 +3963,7 @@ def hello():
theme.load_from_config(self.config) theme.load_from_config(self.config)
self.runner_params = hello_imgui.RunnerParams() self.runner_params = hello_imgui.RunnerParams()
self.runner_params.app_window_params.window_title = "manual slop" self.runner_params.app_window_params.window_title = "manual slop"
self.runner_params.app_window_params.borderless = True
self.runner_params.app_window_params.window_geometry.size = (1680, 1200) self.runner_params.app_window_params.window_geometry.size = (1680, 1200)
self.runner_params.imgui_window_params.enable_viewports = getattr(self, "ui_multi_viewport", False) self.runner_params.imgui_window_params.enable_viewports = getattr(self, "ui_multi_viewport", False)
self.runner_params.imgui_window_params.remember_theme = True self.runner_params.imgui_window_params.remember_theme = True
+15
View File
@@ -0,0 +1,15 @@
import pytest
from unittest.mock import patch
from src.gui_2 import App
@patch("src.gui_2.immapp.run")
@patch("src.gui_2.session_logger.close_session")
@patch("src.gui_2.imgui.save_ini_settings_to_disk")
@patch("sys.argv", ["gui_2.py"])
def test_app_window_is_borderless(mock_save_ini, mock_close, mock_run):
app = App()
app.run()
assert app.runner_params is not None
# This assertion will fail initially because we haven't implemented it yet
assert getattr(app.runner_params.app_window_params, 'borderless', False) is True, "Window should be borderless"
+31
View File
@@ -0,0 +1,31 @@
import pytest
from unittest.mock import patch, MagicMock
from imgui_bundle import imgui
def test_gui_window_controls_minimize_maximize_close():
# We will test the logic of the title bar controls that we are about to implement.
from src.gui_2 import App
app = App()
with patch("src.gui_2.win32gui") as mock_win32gui, \
patch("src.gui_2.win32con") as mock_win32con, \
patch("src.gui_2.imgui") as mock_imgui:
# Setup mock for HWND
mock_viewport = MagicMock()
mock_viewport.platform_handle = 12345
mock_imgui.get_main_viewport.return_value = mock_viewport
# Setup mock for buttons to simulate clicks
# Let's say _render_custom_title_bar uses imgui.button
# We will test the close button logic
# Since it's UI code, we just simulate the conditions
mock_imgui.button.return_value = True # Simulate all buttons being clicked
# Call the method (to be implemented)
app._render_custom_title_bar()
# Verify that win32gui calls are made for minimize, maximize, close
# Since all buttons returned True, all actions should be triggered in this dummy test
assert mock_win32gui.ShowWindow.called
assert mock_win32gui.PostMessage.called